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-vars)
|
||||
(require 'mu4e-proc)
|
||||
(require 'mu4e-view)
|
||||
|
||||
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
|
||||
(defun mu4e--cite-original (msg)
|
||||
"Cite the body text of MSG, with a \"On %s, %s wrote:\"
|
||||
line (with the %s's replaced with the date of MSG and the name
|
||||
or e-mail address of its sender (or 'someone' if nothing
|
||||
else)), followed of the quoted body of MSG, constructed by by
|
||||
prepending `mu4e-citation-prefix' to each line. If there is
|
||||
no body in MSG, return nil."
|
||||
(let* ((from (plist-get msg :from))
|
||||
(body (mu4e-body-text msg)))
|
||||
(when body
|
||||
(concat
|
||||
(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)))))
|
||||
"Return a cited version of the original message MSG (ie., the
|
||||
plist). This function use gnus' `message-cite-function', and as
|
||||
such all its settings apply."
|
||||
(with-temp-buffer
|
||||
(insert (mu4e-view-message-text msg))
|
||||
(goto-char (point-min))
|
||||
(push-mark (point-max))
|
||||
(funcall message-cite-function)
|
||||
(pop-mark)
|
||||
(buffer-string)))
|
||||
|
||||
|
||||
(defun mu4e--header (hdr val)
|
||||
"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"
|
||||
(concat
|
||||
;; if there's no Re: yet, prepend it
|
||||
(if (string-match (concat "^" mu4e-reply-prefix) subject)
|
||||
"" mu4e-reply-prefix)
|
||||
(if (string-match "^Re:" subject) "" "Re:")
|
||||
subject))
|
||||
"\n\n"
|
||||
(mu4e--cite-original origmsg))))
|
||||
|
@ -263,9 +256,8 @@ are more than 1 (based on ORIGMSG)."
|
|||
(mu4e--header "References" (mu4e--refererences-construct origmsg))
|
||||
(mu4e--header "Subject"
|
||||
(concat
|
||||
;; if there's no Re: yet, prepend it
|
||||
(if (string-match (concat "^" mu4e-forward-prefix) subject)
|
||||
"" mu4e-forward-prefix)
|
||||
;; if there's no Fwd: yet, prepend it
|
||||
(if (string-match "^Fwd:" subject) "" "Fwd:")
|
||||
subject))
|
||||
"\n\n"
|
||||
(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)
|
||||
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
|
||||
(defgroup mu4e-folders nil
|
||||
"Special folders."
|
||||
|
@ -265,22 +260,7 @@ display with `mu4e-view-toggle-hide-cited (default keybinding:
|
|||
(defgroup mu4e-compose nil
|
||||
"Customizations for composing/sending messages."
|
||||
: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
|
||||
"The Reply-To address (if this, for some reason, is not equal to
|
||||
the From: address.)"
|
||||
|
@ -307,7 +287,6 @@ sent folder."
|
|||
|
||||
|
||||
;; Faces
|
||||
|
||||
(defgroup mu4e-faces nil
|
||||
"Type faces (fonts) used in mu4e."
|
||||
:group 'mu4e
|
||||
|
|
|
@ -43,6 +43,53 @@
|
|||
wanting to show specific messages - for example, `mu4e-org'."
|
||||
(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)
|
||||
"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
|
||||
|
@ -59,50 +106,8 @@ marking if it still had that."
|
|||
(setq mu4e-view-buffer buf)
|
||||
(setq mu4e-attach-map nil) ;; clear any old attachment stuff
|
||||
(erase-buffer)
|
||||
(insert
|
||||
(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))
|
||||
|
||||
(insert (mu4e-view-message-text msg))
|
||||
|
||||
;; initialize view-mode
|
||||
(mu4e-view-mode)
|
||||
(setq ;; these are buffer-local
|
||||
|
@ -110,7 +115,7 @@ marking if it still had that."
|
|||
mu4e-current-msg msg
|
||||
mu4e-hdrs-buffer hdrsbuf
|
||||
mu4e-link-map (make-hash-table :size 32 :rehash-size 2 :weakness nil))
|
||||
|
||||
|
||||
(switch-to-buffer buf)
|
||||
(goto-char (point-min))
|
||||
|
||||
|
@ -125,11 +130,13 @@ marking if it still had that."
|
|||
(progn
|
||||
(when mu4e-view-wrap-lines (mu4e-view-wrap-lines))
|
||||
(when mu4e-view-hide-cited (mu4e-view-hide-cited))))
|
||||
|
||||
|
||||
;; no use in trying to set flags again
|
||||
(unless update
|
||||
(mu4e-view-mark-as-read-maybe)))))
|
||||
|
||||
|
||||
|
||||
(defun mu4e-view-header (key val &optional dont-propertize-val)
|
||||
"Show header FIELD for MSG with KEY. ie. <KEY>: value-of-FIELD."
|
||||
(if val
|
||||
|
|
Loading…
Reference in New Issue