* mu4e-{compose,hdrs,proc}.el: updates (many!) for the changes in the backend protocol

This commit is contained in:
djcb
2012-04-15 14:21:59 +03:00
parent b06c1c8925
commit c71ccfcd65
3 changed files with 145 additions and 122 deletions

View File

@ -91,7 +91,7 @@ e-mail addresses. If LST is nil, returns nil."
(let ((name (car addrcell)) (let ((name (car addrcell))
(email (cdr addrcell))) (email (cdr addrcell)))
(if name (if name
(format "%s <%s>" name email) (format "\"%s\" <%s>" name email)
(format "%s" email)))) (format "%s" email))))
lst ", "))) lst ", ")))
@ -318,19 +318,13 @@ use the new docid. Returns the full path to the new message."
`("^References:" "^Face:" "^X-Face:" "^X-Draft-From:" `("^References:" "^Face:" "^X-Face:" "^X-Draft-From:"
"^User-agent:"))) "^User-agent:")))
(use-local-map mu4e-edit-mode-map) (use-local-map mu4e-edit-mode-map)
(message-hide-headers) (message-hide-headers)
(make-local-variable 'before-save-hook) (make-local-variable 'before-save-hook)
(make-local-variable 'after-save-hook) (make-local-variable 'after-save-hook)
(make-local-variable 'message-default-charset) (make-local-variable 'message-default-charset)
;; if the default charset is not set, use UTF-8 ;; if the default charset is not set, use UTF-8
(unless message-default-charset (unless message-default-charset
(setq message-default-charset 'utf-8)) (setq message-default-charset 'utf-8))
;; hack-hack-hack... just before saving, we remove the ;; hack-hack-hack... just before saving, we remove the
;; mail-header-separator; just after saving we restore it; thus, the ;; mail-header-separator; just after saving we restore it; thus, the
;; separator should never appear on disk ;; separator should never appear on disk
@ -340,12 +334,10 @@ use the new docid. Returns the full path to the new message."
(mu4e--set-friendly-buffer-name) (mu4e--set-friendly-buffer-name)
(mu4e--insert-mail-header-separator) (mu4e--insert-mail-header-separator)
(set-buffer-modified-p nil))) (set-buffer-modified-p nil)))
;; update the db when the file is saved...] ;; update the db when the file is saved...]
(add-hook 'after-save-hook (add-hook 'after-save-hook
(lambda() (lambda()
(mu4e-proc-add (buffer-file-name) mu4e-drafts-folder)))) (mu4e-proc-add (buffer-file-name) mu4e-drafts-folder))))
;; notify the backend that a message has been sent. The backend will respond ;; notify the backend that a message has been sent. The backend will respond
;; with (:sent ...) sexp, which is handled in `mu4e-compose-handler'. ;; with (:sent ...) sexp, which is handled in `mu4e-compose-handler'.
(add-hook 'message-sent-hook (add-hook 'message-sent-hook
@ -353,11 +345,9 @@ use the new docid. Returns the full path to the new message."
(set-buffer-modified-p t) (set-buffer-modified-p t)
(basic-save-buffer) (basic-save-buffer)
(mu4e-proc-sent (buffer-file-name) mu4e-drafts-folder))) (mu4e-proc-sent (buffer-file-name) mu4e-drafts-folder)))
;; register the function; this function will be called when the '(:sent...)' ;; register the function; this function will be called when the '(:sent...)'
;; message is received (see mu4e-proc.el) with parameters docid and path ;; message is received (see mu4e-proc.el) with parameters docid and path
(setq mu4e-sent-func 'mu4e-sent-handler) (setq mu4e-sent-func 'mu4e-sent-handler)
;; set the default directory to the user's home dir; this is probably more ;; set the default directory to the user's home dir; this is probably more
;; useful e.g. when finding an attachment file the directory the current ;; useful e.g. when finding an attachment file the directory the current
;; mail files lives in... ;; mail files lives in...
@ -419,14 +409,11 @@ using Gnus' `message-mode'."
(if (eq compose-type 'edit) (if (eq compose-type 'edit)
(plist-get original-msg :path) (plist-get original-msg :path)
(error "unsupported compose-type %S" compose-type))))) (error "unsupported compose-type %S" compose-type)))))
(find-file draft) (find-file draft)
(mu4e-edit-mode) (mu4e-edit-mode)
;; insert mail-header-separator, which is needed by message mode to separate ;; insert mail-header-separator, which is needed by message mode to separate
;; headers and body. will be removed before saving to disk ;; headers and body. will be removed before saving to disk
(mu4e--insert-mail-header-separator) (mu4e--insert-mail-header-separator)
;; include files -- e.g. when forwarding a message with attachments, ;; include files -- e.g. when forwarding a message with attachments,
;; we take those from the original. ;; we take those from the original.
(save-excursion (save-excursion
@ -444,27 +431,22 @@ using Gnus' `message-mode'."
(if (member compose-type '(new forward)) (if (member compose-type '(new forward))
(message-goto-to) (message-goto-to)
(message-goto-body)) (message-goto-body))
(mu4e--set-friendly-buffer-name compose-type) (mu4e--set-friendly-buffer-name compose-type)
;; buffer is not user-modified yet ;; buffer is not user-modified yet
(set-buffer-modified-p nil))) (set-buffer-modified-p nil)))
(defun mu4e-sent-handler (docid path) (defun mu4e-sent-handler (docid path)
"Handler function, called with DOCID and PATH for the just-sent "Handler function, called with DOCID and PATH for the just-sent
message." message."
(with-current-buffer (find-file-noselect path) (with-current-buffer(find-file-noselect path)
;; for Forward ('Passed') and Replied messages, try to set the appropriate ;; for Forward ('Passed') and Replied messages, try to set the appropriate
;; flag at the message forwarded or replied-to ;; flag at the message forwarded or replied-to
(mu4e--set-parent-flag docid path) (mu4e--set-parent-flag docid path)
;; handle the draft -- should it be moved to the send folder, or elsewhere? ;; handle the draft -- should it be moved to the sent-folder, or elsewhere?
(mu4e--save-copy-maybe docid path) (mu4e--save-copy-maybe docid path)
;; now, get rid of the buffer ;; now, get rid of the buffer
(kill-buffer))) (kill-buffer)))
(defun mu4e--save-copy-maybe (docid path) (defun mu4e--save-copy-maybe (docid path)
"Handler function, called with DOCID and PATH for the just-sent "Handler function, called with DOCID and PATH for the just-sent
message, which will move it to the sent-folder or elsewhere, message, which will move it to the sent-folder or elsewhere,
@ -474,14 +456,14 @@ Function assumes that it's executed in the context of the message
buffer." buffer."
;; first, what to do with the draft message in PATH? ;; first, what to do with the draft message in PATH?
(if (eq mu4e-sent-messages-behavior 'delete) (if (eq mu4e-sent-messages-behavior 'delete)
(mu4e-proc-remove-msg docid) ;; remove it (mu4e-proc-remove docid) ;; remove it
;; otherwise, ;; otherwise,
(progn ;; prepare the message for saving (progn ;; prepare the message for saving
(basic-save-buffer) (basic-save-buffer)
;; now either move it to trash or to sent ;; now either move it to trash or to sent
(if (eq mu4e-sent-messages-behavior 'trash) (if (eq mu4e-sent-messages-behavior 'trash)
(mu4e-proc-move-msg docid mu4e-trash-folder "+T-D+S") (mu4e-proc-move docid mu4e-trash-folder "+T-D+S")
(mu4e-proc-move-msg docid mu4e-sent-folder "-T-D+S"))))) (mu4e-proc-move docid mu4e-sent-folder "-T-D+S")))))
(defun mu4e--set-parent-flag (docid path) (defun mu4e--set-parent-flag (docid path)
"Set the 'replied' \"R\" flag on messages we replied to, and the "Set the 'replied' \"R\" flag on messages we replied to, and the
@ -516,8 +498,8 @@ buffer.
(setq forwarded-from (first refs)))))) (setq forwarded-from (first refs))))))
;; remove the <> ;; remove the <>
(when (and in-reply-to (string-match "<\\(.*\\)>" in-reply-to)) (when (and in-reply-to (string-match "<\\(.*\\)>" in-reply-to))
(mu4e-proc-flag (match-string 1 in-reply-to) "+R")) (mu4e-proc-move (match-string 1 in-reply-to) nil "+R"))
(when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from)) (when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from))
(mu4e-proc-flag (match-string 1 forwarded-from) "+P")))) (mu4e-proc-move (match-string 1 forwarded-from) nil "+P"))))
(provide 'mu4e-compose) (provide 'mu4e-compose)

View File

@ -52,8 +52,7 @@ buffer for the results. If FULL-SEARCH is non-nil return all
results, otherwise, limit number of results to results, otherwise, limit number of results to
`mu4e-search-results-limit'." `mu4e-search-results-limit'."
(let ((buf (get-buffer-create mu4e-hdrs-buffer-name)) (let ((buf (get-buffer-create mu4e-hdrs-buffer-name))
(inhibit-read-only t) (inhibit-read-only t))
(esc (replace-regexp-in-string "\"" "\\\\\"" expr))) ;; escape "\"
(with-current-buffer buf (with-current-buffer buf
(mu4e-hdrs-mode) (mu4e-hdrs-mode)
(setq (setq
@ -61,11 +60,10 @@ results, otherwise, limit number of results to
mu4e-last-expr expr mu4e-last-expr expr
mu4e-hdrs-buffer buf mu4e-hdrs-buffer buf
mode-name "mu4e-headers")) mode-name "mu4e-headers"))
(switch-to-buffer buf) (switch-to-buffer buf)
(mu4e-proc-find esc ;; '-1' means 'unlimited search' (mu4e-proc-find
(if full-search -1 mu4e-search-results-limit)) (replace-regexp-in-string "\"" "\\\\\"" expr) ;; escape "\"
(unless full-search mu4e-search-results-limit))
;;; when we're starting a new search, we also kill the ;;; when we're starting a new search, we also kill the
;;; view buffer, if any ;;; view buffer, if any
(mu4e-view-kill-buffer-and-window))) (mu4e-view-kill-buffer-and-window)))
@ -598,14 +596,14 @@ work well."
(lambda (docid val) (lambda (docid val)
(let ((marker (nth 0 val)) (mark (nth 1 val)) (target (nth 2 val))) (let ((marker (nth 0 val)) (mark (nth 1 val)) (target (nth 2 val)))
(case mark (case mark
(move (mu4e-proc-move-msg docid target)) (move (mu4e-proc-move docid target))
(read (mu4e-proc-flag docid "+S-u-N")) (read (mu4e-proc-move docid nil "+S-u-N"))
(unread (mu4e-proc-flag docid "-S+u")) (unread (mu4e-proc-move docid nil "-S+u"))
(trash (trash
(unless mu4e-trash-folder (unless mu4e-trash-folder
(error "`mu4e-trash-folder' not set")) (error "`mu4e-trash-folder' not set"))
(mu4e-proc-move-msg docid mu4e-trash-folder "+T")) (mu4e-proc-move docid mu4e-trash-folder "+T"))
(delete (mu4e-proc-remove-msg docid))))) (delete (mu4e-proc-remove docid)))))
mu4e-marks-map) mu4e-marks-map)
(mu4e-hdrs-unmark-all))) (mu4e-hdrs-unmark-all)))
@ -656,7 +654,7 @@ current window. "
(erase-buffer) (erase-buffer)
(insert (propertize "Waiting for message..." (insert (propertize "Waiting for message..."
'face 'mu4e-system-face 'intangible t))) 'face 'mu4e-system-face 'intangible t)))
(mu4e-proc-view-msg docid)))) (mu4e-proc-view docid))))
(defun mu4e-hdrs-docid-is-marked (docid) (defun mu4e-hdrs-docid-is-marked (docid)
@ -708,10 +706,9 @@ up to `mu4e-search-results-limit' much quicker."
otherwise, limit to up to `mu4e-search-results-limit'." otherwise, limit to up to `mu4e-search-results-limit'."
(interactive) (interactive)
(let ((query (mu4e-ask-bookmark "Bookmark: "))) (let ((query (mu4e-ask-bookmark "Bookmark: ")))
(when query (when (and query (mu4e-handle-marks))
(mu4e-hdrs-search query current-prefix-arg)))) (mu4e-hdrs-search query current-prefix-arg))))
(defun mu4e-search-bookmark-edit-first (expr) (defun mu4e-search-bookmark-edit-first (expr)
"Search using some bookmarked query, but allow for editing the "Search using some bookmarked query, but allow for editing the
bookmark before submitting it. With C-u prefix, show /all/ results, bookmark before submitting it. With C-u prefix, show /all/ results,
@ -719,7 +716,7 @@ otherwise, limit to up to `mu4e-search-results-limit'."
(interactive (interactive
(list (read-string "[mu] search for: " (list (read-string "[mu] search for: "
(concat (or (mu4e-ask-bookmark "Edit bookmark: ") "") " ")))) (concat (or (mu4e-ask-bookmark "Edit bookmark: ") "") " "))))
(when expr (when (and expr (mu4e-handle-marks))
(mu4e-hdrs-search expr current-prefix-arg))) (mu4e-hdrs-search expr current-prefix-arg)))
(defun mu4e-hdrs-kill-buffer-and-window () (defun mu4e-hdrs-kill-buffer-and-window ()
@ -779,11 +776,10 @@ maildir). With C-u prefix, show /all/ results, otherwise, limit to
up to `mu4e-search-results-limit'." up to `mu4e-search-results-limit'."
(interactive) (interactive)
(let ((fld (mu4e-ask-maildir "Jump to maildir: "))) (let ((fld (mu4e-ask-maildir "Jump to maildir: ")))
(when fld (when (and fld (mu4e-handle-marks))
(mu4e-hdrs-search (concat "\"maildir:" fld "\"") (mu4e-hdrs-search (concat "\"maildir:" fld "\"")
current-prefix-arg)))) current-prefix-arg))))
(defun mu4e-mark-for-move (&optional target) (defun mu4e-mark-for-move (&optional target)
"Mark message at point for moving to maildir TARGET. If target is "Mark message at point for moving to maildir TARGET. If target is
not provided, function asks for it." not provided, function asks for it."
@ -860,7 +856,7 @@ parameter NO-CONFIRMATION is is t, don't ask for confirmation."
(message nil))))) (message nil)))))
(defun mu4e-compose (&optional compose-type) (defun mu4e-compose (compose-type)
"Start composing a message of COMPOSE-TYPE, where COMPOSE-TYPE is "Start composing a message of COMPOSE-TYPE, where COMPOSE-TYPE is
a symbol, one of `reply', `forward', `edit', `new'. All but `new' a symbol, one of `reply', `forward', `edit', `new'. All but `new'
take the message at point as input. Symbol `edit' is only allowed take the message at point as input. Symbol `edit' is only allowed

View File

@ -26,7 +26,7 @@
(require 'mu4e-vars) (require 'mu4e-vars)
(require 'mu4e-utils) (require 'mu4e-utils)
(require 'mu4e-version) (require 'mu4e-version)
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; internal vars ;; internal vars
(defvar mu4e-mu-proc nil "*internal* The mu-server process") (defvar mu4e-mu-proc nil "*internal* The mu-server process")
@ -114,7 +114,7 @@ updated as well, with all processed sexp data removed."
The server output is as follows: The server output is as follows:
1. an error 1. an error
(:error 2 :error-message \"unknown command\") (:error 2 :message \"unknown command\")
;; eox ;; eox
=> this will be passed to `mu4e-error-func'. => this will be passed to `mu4e-error-func'.
@ -160,8 +160,7 @@ updated as well, with all processed sexp data removed."
=> the docid will be passed to `mu4e-remove-func' => the docid will be passed to `mu4e-remove-func'
6. a compose looks like: 6. a compose looks like:
(:compose <msg-sexp> :action <reply|forward>) => the <msg-sexp> (:compose <reply|forward|edit|new> [:original<msg-sexp>] [:include <attach>])
and either 'reply or 'forward will be passed
`mu4e-compose-func'." `mu4e-compose-func'."
(mu4e-proc-log "* Received %d byte(s)" (length str)) (mu4e-proc-log "* Received %d byte(s)" (length str))
(setq mu4e-buf (concat mu4e-buf str)) ;; update our buffer (setq mu4e-buf (concat mu4e-buf str)) ;; update our buffer
@ -206,20 +205,31 @@ updated as well, with all processed sexp data removed."
(funcall mu4e-remove-func (plist-get sexp :remove))) (funcall mu4e-remove-func (plist-get sexp :remove)))
;; start composing a new message ;; start composing a new message
((plist-get sexp :compose-type) ((plist-get sexp :compose)
(funcall mu4e-compose-func (funcall mu4e-compose-func
(plist-get sexp :compose-type) (plist-get sexp :compose)
(plist-get sexp :original) (plist-get sexp :original)
(plist-get sexp :include))) (plist-get sexp :include)))
;; do something with a temporary file
((plist-get sexp :temp)
(funcall mu4e-temp-func
(plist-get sexp :temp) ;; name of the temp file
(plist-get sexp :what) ;; what to do with it (pipe|emacs|open-with...)
(plist-get sexp :param)));; parameter for the action
;; get some info ;; get some info
((plist-get sexp :info) ((plist-get sexp :info)
(funcall mu4e-info-func sexp)) (funcall mu4e-info-func sexp))
;; receive an error ;; receive an error
((plist-get sexp :error) ((plist-get sexp :error)
(funcall mu4e-error-func sexp)) (funcall mu4e-error-func
(plist-get sexp :error)
(plist-get sexp :message)))
(t (message "Unexpected data from server [%S]" sexp))) (t (message "Unexpected data from server [%S]" sexp)))
(setq sexp (mu4e-proc-eat-sexp-from-buf))))) (setq sexp (mu4e-proc-eat-sexp-from-buf)))))
@ -270,31 +280,45 @@ terminates."
(mu4e-proc-log (concat "-> " cmd)) (mu4e-proc-log (concat "-> " cmd))
(process-send-string mu4e-mu-proc (concat cmd "\n")))) (process-send-string mu4e-mu-proc (concat cmd "\n"))))
(defun mu4e-proc-remove-msg (docid)
"Remove message identified by DOCID. The results are reporter
through either (:update ... ) or (:error ) sexp, which are handled
my `mu4e-error-func', respectively."
(mu4e-proc-send-command "remove %d" docid))
(defun mu4e--docid-msgid-param (docid-or-msgid)
"Construct a backend parameter based on DOCID-OR-MSGID."
(format
(if (stringp docid-or-msgid)
"msgid:\"%s\""
"docid:%d")
docid-or-msgid))
(defun mu4e-proc-find (expr &optional maxnum) (defun mu4e-proc-remove (docid)
"Start a database query for EXPR, getting up to MAXNUM "Remove message identified by docid.
results (or -1 for unlimited). For each result found, a function is The results are reporter through either (:update ... ) or (:error
called, depending on the kind of result. The variables ) sexp, which are handled my `mu4e-error-func', respectively."
`mu4e-error-func' contain the function (mu4e-proc-send-command "remove docid:%d" docid))
that will be called for, resp., a message (header row) or an
error."
(mu4e-proc-send-command "find \"%s\" %d"
expr (if maxnum maxnum -1)))
(defun mu4e-proc-find (query &optional maxnum)
"Start a database query for QUERY, (optionally) getting up to
MAXNUM results. For each result found, a function is called,
depending on the kind of result. The variables `mu4e-error-func'
contain the function that will be called for, resp., a
message (header row) or an error."
(mu4e-proc-send-command
"find query:\"%s\"%s" query
(if maxnum (format " maxnum:%d" maxnum) "")))
(defun mu4e-proc-move-msg (docid targetmdir &optional flags) (defun mu4e-proc-move (docid-or-msgid &optional maildir flags)
"Move message identified by DOCID to TARGETMDIR, optionally "Move message identified by DOCID-OR-MSGID. At least one of
setting FLAGS in the process. MAILDIR and FLAGS should be specified. Note, even if MAILDIR is
nil, this is still a move, since a change in flags still implies
a change in message filename.
TARGETDIR must be a maildir, that is, the part _without_ cur/ or MAILDIR (), optionally
new/ or the root-maildir-prefix. E.g. \"/archive\". This directory setting FLAGS (keyword argument :flags). optionally setting FLAGS
must already exist. in the process. If MAILDIR is nil, message will be moved within the
same maildir.
MAILDIR must be a maildir, that is, the part _without_ cur/ or new/
or the root-maildir-prefix. E.g. \"/archive\". This directory must
already exist.
The FLAGS parameter can have the following forms: The FLAGS parameter can have the following forms:
1. a list of flags such as '(passed replied seen) 1. a list of flags such as '(passed replied seen)
@ -310,70 +334,91 @@ The server reports the results for the operation through
The results are reported through either (:update ... ) The results are reported through either (:update ... )
or (:error ) sexp, which are handled my `mu4e-update-func' and or (:error ) sexp, which are handled my `mu4e-update-func' and
`mu4e-error-func', respectively." `mu4e-error-func', respectively."
(let (unless (or maildir flags)
((flagstr (if (stringp flags) flags (mu4e-flags-to-string flags))) (error "At least one of maildir and flags must be specified"))
(fullpath (concat mu4e-maildir targetmdir))) (let* ((idparam (mu4e--docid-msgid-param docid-or-msgid))
(unless (and (file-directory-p fullpath) (file-writable-p fullpath)) (flagstr
(error "Not a writable directory: %s" fullpath)) (when flags
;; note, we send the maildir, *not* the full path (concat " flags:"
(mu4e-proc-send-command "move %d \"%s\" %s" docid (if (stringp flags) flags (mu4e-flags-to-string flags)))))
targetmdir flagstr))) (path
(when maildir
(format " maildir:\"%s\"" maildir))))
(mu4e-proc-send-command "move %s %s %s"
idparam (or flagstr "") (or path ""))))
(defun mu4e-proc-flag (docid-or-msgid flags)
"Set FLAGS for the message identified by either DOCID-OR-MSGID."
(let ((flagstr (if (stringp flags) flags (mu4e-flags-to-string flags))))
(mu4e-proc-send-command "flag %S %s" docid-or-msgid flagstr)))
(defun mu4e-proc-index (maildir) (defun mu4e-proc-index (path)
"Update the message database for MAILDIR." "Update the message database for filesystem PATH, which should
(mu4e-proc-send-command "index \"%s\"" maildir)) point to some maildir directory structure."
(mu4e-proc-send-command "index path:\"%s\"" path))
(defun mu4e-proc-add (path maildir) (defun mu4e-proc-add (path maildir)
"Add the message at PATH to the database, with MAILDIR "Add the message at PATH to the database, with MAILDIR set to the
set to e.g. '/drafts'; if this works, we will receive (:info :path maildir this message resides in, e.g. '/drafts'; if this works, we
<path> :docid <docid>)." will receive (:info add :path <path> :docid <docid>)."
(mu4e-proc-send-command "add \"%s\" \"%s\"" path maildir)) (mu4e-proc-send-command "add path:\"%s\" maildir:\"%s\""
path maildir))
(defun mu4e-proc-mkdir (maildir) (defun mu4e-proc-sent (path maildir)
"Update the message database for MAILDIR." "Add the message at PATH to the database, with MAILDIR set to the
(mu4e-proc-send-command "mkdir \"%s\"" maildir)) maildir this message resides in, e.g. '/drafts'; if this works, we
will receive (:info add :path <path> :docid <docid>)."
(mu4e-proc-send-command "sent path:\"%s\" maildir:\"%s\""
path maildir))
(defun mu4e-proc-save (docid partidx path) (defun mu4e-proc-compose (type &optional docid)
"Save attachment PARTIDX from message with DOCID to PATH." "Start composing a message of certain TYPE (a symbol, either
(mu4e-proc-send-command "save %d %d \"%s\"" docid partidx path)) `forward', `reply', `edit' or `new', based on an original
message (ie, replying to, forwarding, editing) with DOCID or nil
for type `new'.
The result will be delivered to the function registered as
`mu4e-compose-func'."
(unless (member type '(forward reply edit new))
(error "Unsupported compose-type %S" type))
(unless (eq (null docid) (eq type 'new))
(error "`new' implies docid not-nil, and vice-versa"))
(mu4e-proc-send-command "compose type:%s docid:%d"
(symbol-name type) docid))
(defun mu4e-proc-mkdir (path)
"Create a new maildir-directory at filesystem PATH."
(mu4e-proc-send-command "mkdir path:\"%s\"" path))
(defun mu4e-proc-extract (action docid partidx &optional path what param)
"Extract an attachment with index PARTIDX from message with DOCID
and perform ACTION on it (as symbol, either `save', `open', `temp') which
mean:
* save: save the part to PARAM1 (a path) (non-optional for save)
* open: open the part with the default application registered for doing so
* temp: save to a temporary file, then respond with
(:temp <path> :what <what> :param <param>)."
(let ((cmd
(concat "extract "
(case action
(save
(format "action:save docid:%d index:%d path:\"%s\""
docid partidx path))
(open (format "action:open docid:%d index:%d" docid partidx))
(temp
(format "action:temp docid:%d index:%d what:%s param:\"%s\""
docid partidx what param))
(otherwise (error "Unsupported action %S" action))))))
(mu4e-proc-send-command cmd)))
(defun mu4e-proc-open (docid partidx)
"Open attachment PARTIDX from message with DOCID."
(mu4e-proc-send-command "open %d %d" docid partidx))
(defun mu4e-proc-ping () (defun mu4e-proc-ping ()
"Sends a ping to the mu server, expecting a (:pong ...) in "Sends a ping to the mu server, expecting a (:pong ...) in
response." response."
(mu4e-proc-send-command "ping")) (mu4e-proc-send-command "ping"))
(defun mu4e-proc-view (docid-or-msgid)
(defun mu4e-proc-sent (draftpath maildir) "Get one particular message based on its DOCID-OR-MSGID (keyword
"Tell the mu server that message DRAFTPATH has been send and its MAILDIR, argument). The result will be delivered to the function registered
expecting a (:sent <docid> :path <draftpath>) in response." as `mu4e-message-func'."
(mu4e-proc-send-command "sent %s %s" draftpath maildir)) (mu4e-proc-send-command "view %s"
(mu4e--docid-msgid-param docid-or-msgid)))
(defun mu4e-proc-view-msg (docid-or-msgid)
"Get one particular message based on its DOCID-OR-MSGID. The result will
be delivered to the function registered as `mu4e-message-func'."
(if (stringp docid-or-msgid)
(mu4e-proc-send-command "view %s" docid-or-msgid)
(mu4e-proc-send-command "view %d" docid-or-msgid)))
(defun mu4e-proc-compose (compose-type docid)
"Start composing a message with DOCID and COMPOSE-TYPE (a symbol,
either `forward', `reply' or `edit'.
The result will be delivered to the function registered as
`mu4e-compose-func'."
(unless (member compose-type '(forward reply edit))
(error "Unsupported compose-type %S" compose-type))
(mu4e-proc-send-command "compose %s %d" (symbol-name compose-type) docid))
(provide 'mu4e-proc) (provide 'mu4e-proc)