Re: timezone in notmuch

Subject: Re: timezone in notmuch

Date: Thu, 16 Apr 2020 08:37:12 +0300

To: Tomi Ollila, divan@santanas.co.za, notmuch@notmuchmail.org

Cc:

From: Teemu Likonen


Tomi Ollila [2020-04-15T23:17:32+03] wrote:

> I use this:
>
> https://github.com/domo141/nottoomuch/blob/master/build/01-date-local.patch
>
> I've been thinking if some hook could be added to notmuch-emacs so
> that such a custom date mangling can be done outside of the
> notmuch-emacs source...

Formerly I used Emacs Gnus and its hook to change the date. For this
discussion I adapted the idea to Notmuch. The code below is based on
idea that after article display there is a hook which can do anything
user wants. I wanted ISO 8601 date.



;; Add a hook for changing article's date string.
(add-hook 'some-article-display-hook 'tl-notmuch-custom-article-date)


(defmacro notmuch-narrow-to-article-headers (&rest body)
  ;; Implement macro which uses NARROW function to narrow current buffer
  ;; to article's headers only.
  `(progn ,@body))


(defun tl-notmuch-custom-article-date ()
  (save-excursion
    (save-match-data
      (notmuch-narrow-to-article-headers
       (goto-char (point-min))
       (when (re-search-forward "^Date: \\(.+\\)$" nil t)
         (let ((inhibit-read-only t))
           (replace-match (tl-message-date-string-iso
                           (match-string-no-properties 1))
                          nil t nil 1)))))))


(defun tl-message-date-string-iso (string)
  ;; Parse message date STRING and return ISO 8601 time string.
  (require 'parse-time)
  (condition-case nil
      (let* ((date-list (parse-time-string string))
             (year (nth 5 date-list))
             (month (nth 4 date-list))
             (day (nth 3 date-list))
             (hour (nth 2 date-list))
             (min (nth 1 date-list))
             (sec (nth 0 date-list))
             (tz-total-sec (nth 8 date-list)))

        (format "%04d-%02d-%02dT%02d:%02d:%02d%s"
                year month day hour min sec
                (if (not tz-total-sec)
                    ""
                  (let* ((tz-sign (if (>= tz-total-sec 0) "+" "-"))
                         (tz-hour (truncate (abs tz-total-sec) 3600))
                         (tz-min (truncate (- (abs tz-total-sec)
                                              (* tz-hour 3600))
                                           60)))
                    (cond
                     ((= tz-hour tz-min 0) "Z")
                     ((= tz-min 0)
                      (format "%s%02d" tz-sign tz-hour))
                     (t
                      (format "%s%02d:%02d" tz-sign tz-hour tz-min)))))))

    (error string)))


-- 
/// Teemu Likonen - .-.. http://www.iki.fi/tlikonen/
// OpenPGP: 4E1055DC84E9DFF613D78557719D69D324539450
signature.asc (application/pgp-signature)
_______________________________________________
notmuch mailing list
notmuch@notmuchmail.org
https://notmuchmail.org/mailman/listinfo/notmuch

Thread: