diff --git a/emacs/mu-common.el b/emacs/mu-common.el index 07dc76ed..8073c95e 100644 --- a/emacs/mu-common.el +++ b/emacs/mu-common.el @@ -56,6 +56,8 @@ notation) for the mail view and in replied/forwarded message quotations") (defface mu-size-face '((t (:foreground "#889f7f"))) "") (defface mu-body-face '((t (:foreground "#dcdccc"))) "") (defface mu-flag-face '((t (:foreground "#dc56cc"))) "") +(defface mu-flag-face '((t (:foreground "#7f6677"))) "") + (defface mu-unread-face '((t (:bold t))) "") (defface mu-face '((t (:foreground "Gray" :italic t))) "") @@ -90,6 +92,13 @@ etc.)" (:subject . 40))) (setq mu-find-date-format "%x %X") +(setq mu-header-fields + '( :from + :to + :subject + :date + :path)) + (setq mu-own-address-regexp "djcb\\|diggler\\|bulkmeel") (defun mu-ask-key (prompt) @@ -104,7 +113,8 @@ e.g. 'Reply to [a]ll or [s]ender only; returns the character chosen" (let ((kar) (prompt (replace-regexp-in-string "\\[\\(.\\)\\]" - (lambda(s) (propertize (substring s 1 -1) 'face 'highlight)) + (lambda(s) + (concat "[" (propertize (substring s 1 -1) 'face 'highlight) "]")) prompt))) (while (not kar) (setq kar (read-char-exclusive prompt)) @@ -124,17 +134,39 @@ viewing a message" (unless path (message "No message at point")) path)) -(defun mu-reply () - "reply to the message at point" - (interactive) - (let ((path (mu-get-path))) - (when path (mu-message-reply path)))) -(defun mu-forward () - "forward the message at point" - (interactive) - (let ((path (mu-find-get-path))) - (when path (mu-message-forward path)))) +;; The message sexp looks something like: +;; ( +;; :from (("Donald Duck" . "donald@example.com")) +;; :to (("Mickey Mouse" . "mickey@example.com")) +;; :subject "Wicked stuff" +;; :date (20023 26572 0) +;; :size 15165 +;; :msgid "foobar32423847ef23@pluto.net" +;; :path "/home/mickey/Maildir/inbox/cur/1312254065_3.32282.pluto,4cd5bd4e9:2," +;; :priority high +;; :flags (new unread) +;; :body-txt " " +;; ) +(defun mu-get-message (path) + "use 'mu view --format=sexp' to get the message at PATH in the +form of an s-expression; parse this s-expression and return the +Lisp data as a plist. Returns nil in case of error" + (if (not (file-readable-p path)) + (progn (message "Message is not readable") nil) + (let* ((cmd (concat mu-binary " view --format=sexp " path)) + (str (shell-command-to-string cmd)) + (msglst (read-from-string str))) + (if (msglst) + (car msglist) + (progn (message "Failed to parse message") nil))))) + + +(defun mu-move-to-updated-path (path newflags) + "move msg to an updated path based on newflags" + ;; TODO + ) + ;; todo: check for unhandled marks (defun mu-quit-buffer () diff --git a/emacs/mu-find.el b/emacs/mu-find.el index 516b0b11..2dddf89e 100644 --- a/emacs/mu-find.el +++ b/emacs/mu-find.el @@ -66,6 +66,7 @@ the mu find output") (setq mu-buf (substring mu-buf (match-end 0))) (setq eom (string-match mu-eom mu-buf))))))) + (defun mu-find-process-sentinel (proc msg) "Check the mu-find process upon completion" (let ((status (process-status proc)) @@ -89,7 +90,12 @@ the mu find output") (save-excursion (goto-char (point-max)) (insert (mu-str text))))))))) - + + +;; Note, the 'mu find --format=sexp' sexp is almost the same as the ones that +;; 'mu view --format=sexp' produces (see mu-get-message), with the difference +;; that former may give more than one result, and that mu-find output comes from +;; the database rather than file, and does _not_ contain the message body (defun mu-find (expr) "search in the mu database" (interactive "s[mu] match expr: ") diff --git a/emacs/mu-message.el b/emacs/mu-message.el index 43f780b1..87815ce6 100644 --- a/emacs/mu-message.el +++ b/emacs/mu-message.el @@ -41,10 +41,6 @@ (defun mu-message-user-agent () (format "mu %s; emacs %s" (mu-binary-version) emacs-version)) - - - - (defun mu-message-attribution (msg) "get an attribution line for a quoted message" (format "On %s, %s wrote:\n" @@ -120,9 +116,15 @@ create a forwarded message. After creation, switch to the message editor" (switch-to-buffer buf)))) -(defun mu-message-reply (path) - "create a reply to the message at PATH; After creation, switch +(defun mu-message-reply () + "create a reply to the message at point; After creation, switch to the message editor" + (let ((path (mu-get-path))) + (when path + (let ()) + + + (mu-ask-key "Reply to [s]ender only or to [a]ll?") (mu-message-reply-or-forward path)) diff --git a/emacs/mu-view.el b/emacs/mu-view.el index fcf35c8f..beac3113 100644 --- a/emacs/mu-view.el +++ b/emacs/mu-view.el @@ -33,18 +33,12 @@ '( :from :to :subject - :date) + :date + :path) "list of header fields to display in the message view") (defconst mu-view-buffer-name " *mu-view*") -(defun mu-view-get (path) - "display the email message at PATH" - (let* ((cmd (concat mu-binary " view --format=sexp " path)) - (str (shell-command-to-string cmd)) - (msglst (read-from-string str))) - (when msglst (car msglst)))) - (defun mu-view-header (field val val-face) "get a header string (like 'Subject: foo')" (when val @@ -68,12 +62,12 @@ (with-temp-buffer (insert (plist-get msg :body-html)) (html2text) - (buffer-string))'face face)) + (buffer-string)) 'face face)) (t ""))) (defun mu-view-message (path) "display the email message at PATH" - (let ((msg (mu-view-get path))) + (let ((msg (mu-get-message path))) (when msg (concat (mapconcat @@ -89,6 +83,8 @@ (mu-view-header-contact "Bcc" (plist-get msg :bcc) 'mu-to-face)) (:subject (mu-view-header "Subject" (plist-get msg :subject) 'mu-subject-face)) + (:path + (mu-view-header "Path" (plist-get msg :path) 'mu-path-face)) (:date (mu-view-header "Date" (format-time-string mu-date-format-long @@ -99,7 +95,9 @@ )))) (defun mu-view (path) - "display message at PATH in a new buffer" + "display message at PATH in a new buffer; note that the action +of viewing a message may cause it to be moved/renamed; this +function returns the resulting name" (interactive) (let ((str (mu-view-message path)) (buf (get-buffer mu-view-buffer-name)))