Factor out date-timestamp* calculations to org-store-link-props

* lisp/org.el (org-store-link-props): Rewrite function to get
  date-timestamp* calculations.
* lisp/org-gnus.el:
* lisp/org-mhe.el:
* lisp/org-rmail.el:
* contrib/lisp/org-mew.el:
* contrib/lisp/org-vm.el:
* contrib/lisp/org-wl.el: Remove date-timestamp* copy-paste.
* doc/org.texi: Fix `org-capture-templates' documentation.
This commit is contained in:
Jan Malakhovski 2015-12-27 14:54:16 +00:00 committed by Nicolas Goaziou
parent 0b6e63008a
commit d1f42e7f32
8 changed files with 25 additions and 73 deletions

View File

@ -167,19 +167,10 @@ with \"t\" key."
(from (mew-header-get-value "From:"))
(to (mew-header-get-value "To:"))
(date (mew-header-get-value "Date:"))
(date-ts (and date (format-time-string
(org-time-stamp-format t)
(date-to-time date))))
(date-ts-ia (and date (format-time-string
(org-time-stamp-format t t)
(date-to-time date))))
(subject (mew-header-get-value "Subject:"))
desc link)
(org-store-link-props :type "mew" :from from :to to
(org-store-link-props :type "mew" :from from :to to :date date
:subject subject :message-id message-id)
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
(setq message-id (org-remove-angle-brackets message-id))
(setq desc (org-email-link-description))
(setq link (concat "mew:" folder-name "#" message-id))

View File

@ -77,12 +77,6 @@
(message-id (vm-su-message-id message))
(link-type (if (vm-imap-folder-p) "vm-imap" "vm"))
(date (vm-get-header-contents message "Date"))
(date-ts (and date (format-time-string
(org-time-stamp-format t)
(date-to-time date))))
(date-ts-ia (and date (format-time-string
(org-time-stamp-format t t)
(date-to-time date))))
folder desc link)
(if (vm-imap-folder-p)
(let ((spec (vm-imap-find-spec-for-buffer (current-buffer))))
@ -95,10 +89,7 @@
(setq folder (replace-match "" t t folder)))))
(setq message-id (org-remove-angle-brackets message-id))
(org-store-link-props :type link-type :from from :to to :subject subject
:message-id message-id)
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
:message-id message-id :date date)
(setq desc (org-email-link-description))
(setq link (concat (concat link-type ":") folder "#" message-id))
(org-add-link-props :link link :description desc)

View File

@ -198,12 +198,6 @@ ENTITY is a message entity."
(xref (org-wl-message-field 'xref wl-message-entity))
(subject (org-wl-message-field 'subject wl-message-entity))
(date (org-wl-message-field 'date wl-message-entity))
(date-ts (and date (format-time-string
(org-time-stamp-format t)
(date-to-time date))))
(date-ts-ia (and date (format-time-string
(org-time-stamp-format t t)
(date-to-time date))))
desc link)
;; remove text properties of subject string to avoid possible bug
@ -243,9 +237,7 @@ ENTITY is a message entity."
(setq desc (org-email-link-description))
(setq link (concat "wl:" folder-name "#" message-id-no-brackets))
(org-add-link-props :link link :description desc)))
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
(org-add-link-props :date date)
(or link xref)))))))
(defun org-wl-open-nntp (path)

View File

@ -7303,8 +7303,8 @@ Link type | Available keywords
---------------------------------+----------------------------------------------
bbdb | %:name %:company
irc | %:server %:port %:nick
vm, vm-imap, wl, mh, mew, rmail | %:type %:subject %:message-id
| %:from %:fromname %:fromaddress
vm, vm-imap, wl, mh, mew, rmail, | %:type %:subject %:message-id
gnus | %:from %:fromname %:fromaddress
| %:to %:toname %:toaddress
| %:date @r{(message date header field)}
| %:date-timestamp @r{(date as active timestamp)}

View File

@ -159,16 +159,6 @@ If `org-store-link' was called with a prefix arg the meaning of
(from (mail-header-from header))
(message-id (org-remove-angle-brackets (mail-header-id header)))
(date (org-trim (mail-header-date header)))
(date-ts (and date
(ignore-errors
(format-time-string
(org-time-stamp-format t)
(date-to-time date)))))
(date-ts-ia (and date
(ignore-errors
(format-time-string
(org-time-stamp-format t t)
(date-to-time date)))))
(subject (copy-sequence (mail-header-subject header)))
(to (cdr (assq 'To (mail-header-extra header))))
newsgroups x-no-archive desc link)
@ -190,11 +180,8 @@ If `org-store-link' was called with a prefix arg the meaning of
(setq to (or to (gnus-fetch-original-field "To"))
newsgroups (gnus-fetch-original-field "Newsgroups")
x-no-archive (gnus-fetch-original-field "x-no-archive")))
(org-store-link-props :type "gnus" :from from :subject subject
(org-store-link-props :type "gnus" :from from :date date :subject subject
:message-id message-id :group group :to to)
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
(setq desc (org-email-link-description)
link (org-gnus-article-link
group newsgroups message-id x-no-archive))

View File

@ -88,17 +88,9 @@ supported by MH-E."
(message-id (org-mhe-get-header "Message-Id:"))
(subject (org-mhe-get-header "Subject:"))
(date (org-mhe-get-header "Date:"))
(date-ts (and date (format-time-string
(org-time-stamp-format t) (date-to-time date))))
(date-ts-ia (and date (format-time-string
(org-time-stamp-format t t)
(date-to-time date))))
link desc)
(org-store-link-props :type "mh" :from from :to to
(org-store-link-props :type "mh" :from from :to to :date date
:subject subject :message-id message-id)
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
(setq desc (org-email-link-description))
(setq link (concat "mhe:" (org-mhe-get-message-real-folder) "#"
(org-remove-angle-brackets message-id)))

View File

@ -65,19 +65,10 @@
(to (mail-fetch-field "to"))
(subject (mail-fetch-field "subject"))
(date (mail-fetch-field "date"))
(date-ts (and date (format-time-string
(org-time-stamp-format t)
(date-to-time date))))
(date-ts-ia (and date (format-time-string
(org-time-stamp-format t t)
(date-to-time date))))
desc link)
(org-store-link-props
:type "rmail" :from from :to to
:type "rmail" :from from :to to :date date
:subject subject :message-id message-id)
(when date
(org-add-link-props :date date :date-timestamp date-ts
:date-timestamp-inactive date-ts-ia))
(setq message-id (org-remove-angle-brackets message-id))
(setq desc (org-email-link-description))
(setq link (concat "rmail:" folder "#" message-id))

View File

@ -9922,16 +9922,24 @@ active region."
(car org-stored-links))))))
(defun org-store-link-props (&rest plist)
"Store link properties, extract names and addresses."
(let (x adr)
(when (setq x (plist-get plist :from))
(setq adr (mail-extract-address-components x))
"Store link properties, extract names, addresses and dates."
(when x
(let ((adr (mail-extract-address-components x)))
(setq plist (plist-put plist :fromname (car adr)))
(setq plist (plist-put plist :fromaddress (nth 1 adr))))
(when (setq x (plist-get plist :to))
(setq adr (mail-extract-address-components x))
(setq plist (plist-put plist :toname (car adr)))
(setq plist (plist-put plist :toaddress (nth 1 adr)))))
(setq plist (plist-put plist :fromaddress (nth 1 adr)))))
(let ((x (plist-get plist :to)))
(when x
(let ((adr (mail-extract-address-components x)))
(setq plist (plist-put plist :toname (car adr)))
(setq plist (plist-put plist :toaddress (nth 1 adr))))))
(let ((x (ignore-errors (date-to-time (plist-get plist :date)))))
(when x
(setq plist (plist-put plist :date-timestamp
(format-time-string
(org-time-stamp-format t) x)))
(setq plist (plist-put plist :date-timestamp-inactive
(format-time-string
(org-time-stamp-format t t) x)))))
(let ((from (plist-get plist :from))
(to (plist-get plist :to)))
(when (and from to org-from-is-user-regexp)