mirror of https://github.com/djcb/mu.git
* re-use the `message-mode' citation engine for generating cited messages (WIP)
This commit is contained in:
parent
57c261ef87
commit
127a9108fb
|
@ -35,27 +35,21 @@
|
||||||
(require 'mu4e-utils)
|
(require 'mu4e-utils)
|
||||||
(require 'mu4e-vars)
|
(require 'mu4e-vars)
|
||||||
(require 'mu4e-proc)
|
(require 'mu4e-proc)
|
||||||
|
(require 'mu4e-view)
|
||||||
|
|
||||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||||
(defun mu4e--cite-original (msg)
|
(defun mu4e--cite-original (msg)
|
||||||
"Cite the body text of MSG, with a \"On %s, %s wrote:\"
|
"Return a cited version of the original message MSG (ie., the
|
||||||
line (with the %s's replaced with the date of MSG and the name
|
plist). This function use gnus' `message-cite-function', and as
|
||||||
or e-mail address of its sender (or 'someone' if nothing
|
such all its settings apply."
|
||||||
else)), followed of the quoted body of MSG, constructed by by
|
(with-temp-buffer
|
||||||
prepending `mu4e-citation-prefix' to each line. If there is
|
(insert (mu4e-view-message-text msg))
|
||||||
no body in MSG, return nil."
|
(goto-char (point-min))
|
||||||
(let* ((from (plist-get msg :from))
|
(push-mark (point-max))
|
||||||
(body (mu4e-body-text msg)))
|
(funcall message-cite-function)
|
||||||
(when body
|
(pop-mark)
|
||||||
(concat
|
(buffer-string)))
|
||||||
(format "On %s, %s wrote:"
|
|
||||||
(format-time-string "%c" (plist-get msg :date))
|
|
||||||
(if (and from (car from)) ;; a list ((<name> . <email>))
|
|
||||||
(or (caar from) (cdar from) "someone")
|
|
||||||
"someone"))
|
|
||||||
"\n\n"
|
|
||||||
(replace-regexp-in-string "^"
|
|
||||||
mu4e-citation-prefix body)))))
|
|
||||||
|
|
||||||
(defun mu4e--header (hdr val)
|
(defun mu4e--header (hdr val)
|
||||||
"Return a header line of the form HDR: VAL\n. If VAL is nil,
|
"Return a header line of the form HDR: VAL\n. If VAL is nil,
|
||||||
|
@ -243,8 +237,7 @@ are more than 1 (based on ORIGMSG)."
|
||||||
(mu4e--header "Subject"
|
(mu4e--header "Subject"
|
||||||
(concat
|
(concat
|
||||||
;; if there's no Re: yet, prepend it
|
;; if there's no Re: yet, prepend it
|
||||||
(if (string-match (concat "^" mu4e-reply-prefix) subject)
|
(if (string-match "^Re:" subject) "" "Re:")
|
||||||
"" mu4e-reply-prefix)
|
|
||||||
subject))
|
subject))
|
||||||
"\n\n"
|
"\n\n"
|
||||||
(mu4e--cite-original origmsg))))
|
(mu4e--cite-original origmsg))))
|
||||||
|
@ -263,9 +256,8 @@ are more than 1 (based on ORIGMSG)."
|
||||||
(mu4e--header "References" (mu4e--refererences-construct origmsg))
|
(mu4e--header "References" (mu4e--refererences-construct origmsg))
|
||||||
(mu4e--header "Subject"
|
(mu4e--header "Subject"
|
||||||
(concat
|
(concat
|
||||||
;; if there's no Re: yet, prepend it
|
;; if there's no Fwd: yet, prepend it
|
||||||
(if (string-match (concat "^" mu4e-forward-prefix) subject)
|
(if (string-match "^Fwd:" subject) "" "Fwd:")
|
||||||
"" mu4e-forward-prefix)
|
|
||||||
subject))
|
subject))
|
||||||
"\n\n"
|
"\n\n"
|
||||||
(mu4e--cite-original origmsg))))
|
(mu4e--cite-original origmsg))))
|
||||||
|
|
|
@ -109,12 +109,7 @@ show up in the UI), and KEY is a shortcut key for the query.")
|
||||||
* anything else: don't split (show either headers or messages, not both)
|
* anything else: don't split (show either headers or messages, not both)
|
||||||
Also see `mu4e-headers-visible-lines' and `mu4e-headers-visible-columns'.")
|
Also see `mu4e-headers-visible-lines' and `mu4e-headers-visible-columns'.")
|
||||||
|
|
||||||
;; Sending
|
|
||||||
(defgroup mu4e-sending nil
|
|
||||||
"E-mail-sending related settings for mu4e."
|
|
||||||
:group 'mu4e)
|
|
||||||
|
|
||||||
|
|
||||||
;; Folders
|
;; Folders
|
||||||
(defgroup mu4e-folders nil
|
(defgroup mu4e-folders nil
|
||||||
"Special folders."
|
"Special folders."
|
||||||
|
@ -265,22 +260,7 @@ display with `mu4e-view-toggle-hide-cited (default keybinding:
|
||||||
(defgroup mu4e-compose nil
|
(defgroup mu4e-compose nil
|
||||||
"Customizations for composing/sending messages."
|
"Customizations for composing/sending messages."
|
||||||
:group 'mu4e)
|
:group 'mu4e)
|
||||||
|
|
||||||
(defcustom mu4e-citation-prefix " > "
|
|
||||||
"String to prefix cited message parts with."
|
|
||||||
:type 'string
|
|
||||||
:group 'mu4e-compose)
|
|
||||||
|
|
||||||
(defcustom mu4e-reply-prefix "Re: "
|
|
||||||
"String to prefix the subject of replied messages with."
|
|
||||||
:type 'string
|
|
||||||
:group 'mu4e-compose)
|
|
||||||
|
|
||||||
(defcustom mu4e-forward-prefix "Fwd: "
|
|
||||||
"String to prefix the subject of forwarded messages with."
|
|
||||||
:type 'string
|
|
||||||
:group 'mu4e-compose)
|
|
||||||
|
|
||||||
(defcustom mu4e-reply-to-address nil
|
(defcustom mu4e-reply-to-address nil
|
||||||
"The Reply-To address (if this, for some reason, is not equal to
|
"The Reply-To address (if this, for some reason, is not equal to
|
||||||
the From: address.)"
|
the From: address.)"
|
||||||
|
@ -307,7 +287,6 @@ sent folder."
|
||||||
|
|
||||||
|
|
||||||
;; Faces
|
;; Faces
|
||||||
|
|
||||||
(defgroup mu4e-faces nil
|
(defgroup mu4e-faces nil
|
||||||
"Type faces (fonts) used in mu4e."
|
"Type faces (fonts) used in mu4e."
|
||||||
:group 'mu4e
|
:group 'mu4e
|
||||||
|
|
|
@ -43,6 +43,53 @@
|
||||||
wanting to show specific messages - for example, `mu4e-org'."
|
wanting to show specific messages - for example, `mu4e-org'."
|
||||||
(mu4e-proc-view msgid))
|
(mu4e-proc-view msgid))
|
||||||
|
|
||||||
|
(defun mu4e-view-message-text (msg)
|
||||||
|
"Return the message to display (as a string), based on the MSG
|
||||||
|
plist."
|
||||||
|
(concat
|
||||||
|
(mapconcat
|
||||||
|
(lambda (field)
|
||||||
|
(let ((fieldname (cdr (assoc field mu4e-header-names)))
|
||||||
|
(fieldval (plist-get msg field)))
|
||||||
|
(case field
|
||||||
|
(:subject (mu4e-view-header fieldname fieldval))
|
||||||
|
(:path (mu4e-view-header fieldname fieldval))
|
||||||
|
(:maildir (mu4e-view-header fieldname fieldval))
|
||||||
|
(:flags (mu4e-view-header fieldname
|
||||||
|
(if fieldval (format "%S" fieldval) "")))
|
||||||
|
;; contact fields
|
||||||
|
(:to (mu4e-view-contacts msg field))
|
||||||
|
(:from (mu4e-view-contacts msg field))
|
||||||
|
(:cc (mu4e-view-contacts msg field))
|
||||||
|
(:bcc (mu4e-view-contacts msg field))
|
||||||
|
|
||||||
|
;; if we (`user-mail-address' are the From, show To, otherwise,
|
||||||
|
;; show From
|
||||||
|
(:from-or-to
|
||||||
|
(let* ((from (plist-get msg :from))
|
||||||
|
(from (and from (cdar from))))
|
||||||
|
(if (and from (string-match mu4e-user-mail-address-regexp from))
|
||||||
|
(mu4e-view-contacts msg :to)
|
||||||
|
(mu4e-view-contacts msg :from))))
|
||||||
|
;; date
|
||||||
|
(:date
|
||||||
|
(let ((datestr
|
||||||
|
(when fieldval (format-time-string mu4e-view-date-format
|
||||||
|
fieldval))))
|
||||||
|
(if datestr (mu4e-view-header fieldname datestr) "")))
|
||||||
|
;; size
|
||||||
|
(:size
|
||||||
|
(let* (size (mu4e-view-size msg)
|
||||||
|
(sizestr (when size (format "%d bytes" size))))
|
||||||
|
(if sizestr (mu4e-view-header fieldname sizestr))))
|
||||||
|
;; attachments
|
||||||
|
(:attachments (mu4e-view-attachments msg))
|
||||||
|
(t (error "Unsupported field: %S" field)))))
|
||||||
|
mu4e-view-fields "")
|
||||||
|
"\n"
|
||||||
|
(mu4e-body-text msg)))
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-view (msg hdrsbuf &optional update)
|
(defun mu4e-view (msg hdrsbuf &optional update)
|
||||||
"Display the message MSG in a new buffer, and keep in sync with HDRSBUF.
|
"Display the message MSG in a new buffer, and keep in sync with HDRSBUF.
|
||||||
'In sync' here means that moving to the next/previous message in
|
'In sync' here means that moving to the next/previous message in
|
||||||
|
@ -59,50 +106,8 @@ marking if it still had that."
|
||||||
(setq mu4e-view-buffer buf)
|
(setq mu4e-view-buffer buf)
|
||||||
(setq mu4e-attach-map nil) ;; clear any old attachment stuff
|
(setq mu4e-attach-map nil) ;; clear any old attachment stuff
|
||||||
(erase-buffer)
|
(erase-buffer)
|
||||||
(insert
|
(insert (mu4e-view-message-text msg))
|
||||||
(mapconcat
|
|
||||||
(lambda (field)
|
|
||||||
(let ((fieldname (cdr (assoc field mu4e-header-names)))
|
|
||||||
(fieldval (plist-get msg field)))
|
|
||||||
(case field
|
|
||||||
(:subject (mu4e-view-header fieldname fieldval))
|
|
||||||
(:path (mu4e-view-header fieldname fieldval))
|
|
||||||
(:maildir (mu4e-view-header fieldname fieldval))
|
|
||||||
(:flags (mu4e-view-header fieldname
|
|
||||||
(if fieldval (format "%S" fieldval) "")))
|
|
||||||
;; contact fields
|
|
||||||
(:to (mu4e-view-contacts msg field))
|
|
||||||
(:from (mu4e-view-contacts msg field))
|
|
||||||
(:cc (mu4e-view-contacts msg field))
|
|
||||||
(:bcc (mu4e-view-contacts msg field))
|
|
||||||
|
|
||||||
;; if we (`user-mail-address' are the From, show To, otherwise,
|
|
||||||
;; show From
|
|
||||||
(:from-or-to
|
|
||||||
(let* ((from (plist-get msg :from))
|
|
||||||
(from (and from (cdar from))))
|
|
||||||
(if (and from (string-match mu4e-user-mail-address-regexp from))
|
|
||||||
(mu4e-view-contacts msg :to)
|
|
||||||
(mu4e-view-contacts msg :from))))
|
|
||||||
|
|
||||||
;; date
|
|
||||||
(:date
|
|
||||||
(let ((datestr
|
|
||||||
(when fieldval (format-time-string mu4e-view-date-format
|
|
||||||
fieldval))))
|
|
||||||
(if datestr (mu4e-view-header fieldname datestr) "")))
|
|
||||||
;; size
|
|
||||||
(:size
|
|
||||||
(let* (size (mu4e-view-size msg)
|
|
||||||
(sizestr (when size (format "%d bytes" size))))
|
|
||||||
(if sizestr (mu4e-view-header fieldname sizestr))))
|
|
||||||
;; attachments
|
|
||||||
(:attachments (mu4e-view-attachments msg))
|
|
||||||
(t (error "Unsupported field: %S" field)))))
|
|
||||||
mu4e-view-fields "")
|
|
||||||
"\n"
|
|
||||||
(mu4e-body-text msg))
|
|
||||||
|
|
||||||
;; initialize view-mode
|
;; initialize view-mode
|
||||||
(mu4e-view-mode)
|
(mu4e-view-mode)
|
||||||
(setq ;; these are buffer-local
|
(setq ;; these are buffer-local
|
||||||
|
@ -110,7 +115,7 @@ marking if it still had that."
|
||||||
mu4e-current-msg msg
|
mu4e-current-msg msg
|
||||||
mu4e-hdrs-buffer hdrsbuf
|
mu4e-hdrs-buffer hdrsbuf
|
||||||
mu4e-link-map (make-hash-table :size 32 :rehash-size 2 :weakness nil))
|
mu4e-link-map (make-hash-table :size 32 :rehash-size 2 :weakness nil))
|
||||||
|
|
||||||
(switch-to-buffer buf)
|
(switch-to-buffer buf)
|
||||||
(goto-char (point-min))
|
(goto-char (point-min))
|
||||||
|
|
||||||
|
@ -125,11 +130,13 @@ marking if it still had that."
|
||||||
(progn
|
(progn
|
||||||
(when mu4e-view-wrap-lines (mu4e-view-wrap-lines))
|
(when mu4e-view-wrap-lines (mu4e-view-wrap-lines))
|
||||||
(when mu4e-view-hide-cited (mu4e-view-hide-cited))))
|
(when mu4e-view-hide-cited (mu4e-view-hide-cited))))
|
||||||
|
|
||||||
;; no use in trying to set flags again
|
;; no use in trying to set flags again
|
||||||
(unless update
|
(unless update
|
||||||
(mu4e-view-mark-as-read-maybe)))))
|
(mu4e-view-mark-as-read-maybe)))))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
||||||
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
|
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
|
||||||
(if val
|
(if val
|
||||||
|
|
Loading…
Reference in New Issue