mu4e-server: rename from mu4e-proc

Rename mu4e-proc.el into mu4e-server.el

Rename mu4e~proc... into mu4e--server...

Update users, too.
This commit is contained in:
Dirk-Jan C. Binnema
2021-08-29 19:53:53 +03:00
parent f309e79837
commit a6514fd683
13 changed files with 165 additions and 213 deletions

View File

@ -38,7 +38,7 @@ dist_lisp_LISP= \
mu4e-message.el \ mu4e-message.el \
mu4e-meta.el \ mu4e-meta.el \
mu4e-org.el \ mu4e-org.el \
mu4e-proc.el \ mu4e-server.el \
mu4e-speedbar.el \ mu4e-speedbar.el \
mu4e-update.el \ mu4e-update.el \
mu4e-vars.el \ mu4e-vars.el \

View File

@ -45,7 +45,7 @@ mu4e_srcs=[
'mu4e-message.el', 'mu4e-message.el',
join_paths(meson.current_build_dir(), 'mu4e-meta.el'), join_paths(meson.current_build_dir(), 'mu4e-meta.el'),
'mu4e-org.el', 'mu4e-org.el',
'mu4e-proc.el', 'mu4e-server.el',
'mu4e-speedbar.el', 'mu4e-speedbar.el',
'mu4e-update.el', 'mu4e-update.el',
'mu4e-vars.el', 'mu4e-vars.el',

View File

@ -170,13 +170,13 @@ Otherwise return nil."
(if (re-search-forward regexp nil t) (if (re-search-forward regexp nil t)
(replace-match to-string nil nil))))) (replace-match to-string nil nil)))))
(declare-function mu4e~proc-add "mu4e-proc") (declare-function mu4e--server-add "mu4e-server")
(defun mu4e--refresh-message (path) (defun mu4e--refresh-message (path)
"Re-parse message at PATH. "Re-parse message at PATH.
if this works, we will if this works, we will
receive (:info add :path <path> :docid <docid>) as well as (:update receive (:info add :path <path> :docid <docid>) as well as (:update
<msg-sexp>)." <msg-sexp>)."
(mu4e~proc-add path)) (mu4e--server-add path))
(defun mu4e-action-retag-message (msg &optional retag-arg) (defun mu4e-action-retag-message (msg &optional retag-arg)
"Change tags of MSG with RETAG-ARG. "Change tags of MSG with RETAG-ARG.

View File

@ -72,7 +72,7 @@
(require 'smtpmail) (require 'smtpmail)
(require 'rfc2368) (require 'rfc2368)
(require 'mu4e-proc) (require 'mu4e-server)
(require 'mu4e-actions) (require 'mu4e-actions)
(require 'mu4e-message) (require 'mu4e-message)
(require 'mu4e-draft) (require 'mu4e-draft)
@ -153,12 +153,12 @@ If needed, set the Fcc header, and register the handler function."
(setq message-fcc-handler-function old-handler) ;; reset the fcc handler (setq message-fcc-handler-function old-handler) ;; reset the fcc handler
(let ((mdir-path (concat (mu4e-root-maildir) maildir))) (let ((mdir-path (concat (mu4e-root-maildir) maildir)))
;; Create the full maildir structure for the sent folder if it doesn't exist. ;; Create the full maildir structure for the sent folder if it doesn't exist.
;; `mu4e~proc-mkdir` runs asynchronously but no matter whether it runs before or after ;; `mu4e--server-mkdir` runs asynchronously but no matter whether it runs before or after
;; `write-file`, the sent maildir ends up in the correct state. ;; `write-file`, the sent maildir ends up in the correct state.
(unless (file-exists-p mdir-path) (unless (file-exists-p mdir-path)
(mu4e~proc-mkdir mdir-path))) (mu4e--server-mkdir mdir-path)))
(write-file file) ;; writing maildirs files is easy (write-file file) ;; writing maildirs files is easy
(mu4e~proc-add file))))))) ;; update the database (mu4e--server-add file))))))) ;; update the database
(defvar mu4e-compose-hidden-headers (defvar mu4e-compose-hidden-headers
`("^References:" "^Face:" "^X-Face:" `("^References:" "^Face:" "^X-Face:"
@ -206,7 +206,7 @@ Message-ID."
(set-buffer-modified-p nil) (set-buffer-modified-p nil)
(mu4e-message "Saved (%d lines)" (count-lines (point-min) (point-max))) (mu4e-message "Saved (%d lines)" (count-lines (point-min) (point-max)))
;; update the file on disk -- ie., without the separator ;; update the file on disk -- ie., without the separator
(mu4e~proc-add (buffer-file-name)))) (mu4e--server-add (buffer-file-name))))
;;; address completion ;;; address completion
@ -432,7 +432,7 @@ buffers; lets remap its faces so it uses the ones for mu4e."
(defun mu4e~set-sent-handler-message-sent-hook-fn () (defun mu4e~set-sent-handler-message-sent-hook-fn ()
;; mu4e~compose-mark-after-sending ;; mu4e~compose-mark-after-sending
(setq mu4e-sent-func 'mu4e-sent-handler) (setq mu4e-sent-func 'mu4e-sent-handler)
(mu4e~proc-sent (buffer-file-name))) (mu4e--server-sent (buffer-file-name)))
(defun mu4e-send-harden-newlines () (defun mu4e-send-harden-newlines ()
"Set the hard property to all newlines." "Set the hard property to all newlines."
@ -660,7 +660,7 @@ when the buffer is in `mu4e-compose-mode':
;; Remove the <> ;; Remove the <>
(when (and msg-id (string-match "<\\(.*\\)>" msg-id)) (when (and msg-id (string-match "<\\(.*\\)>" msg-id))
(save-window-excursion (save-window-excursion
(mu4e~proc-move (match-string 1 msg-id) mu4e-drafts-folder nil t) (mu4e--server-move (match-string 1 msg-id) mu4e-drafts-folder nil t)
(kill-buffer buf))))) ;; Kill previous buffer which points to wrong file (kill-buffer buf))))) ;; Kill previous buffer which points to wrong file
;; No file, just change the buffer file name ;; No file, just change the buffer file name
(setq buffer-file-name (setq buffer-file-name
@ -676,7 +676,7 @@ For Forwarded ('Passed') and Replied messages, try to set the
appropriate flag at the message forwarded or replied-to." appropriate flag at the message forwarded or replied-to."
(mu4e~compose-set-parent-flag path) (mu4e~compose-set-parent-flag path)
(when (file-exists-p path) ;; maybe the draft was not saved at all (when (file-exists-p path) ;; maybe the draft was not saved at all
(mu4e~proc-remove docid)) (mu4e--server-remove docid))
;; kill any remaining buffers for the draft file, or they will hang around... ;; kill any remaining buffers for the draft file, or they will hang around...
;; this seems a bit hamfisted... ;; this seems a bit hamfisted...
(when message-kill-buffer-on-exit (when message-kill-buffer-on-exit
@ -738,9 +738,9 @@ buffer."
(setq forwarded-from (cl-first refs)))))) (setq forwarded-from (cl-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-move (match-string 1 in-reply-to) nil "+R-N")) (mu4e--server-move (match-string 1 in-reply-to) nil "+R-N"))
(when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from)) (when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from))
(mu4e~proc-move (match-string 1 forwarded-from) nil "+P-N"))))))) (mu4e--server-move (match-string 1 forwarded-from) nil "+P-N")))))))
(defun mu4e-compose (compose-type) (defun mu4e-compose (compose-type)
"Start composing a message of COMPOSE-TYPE. "Start composing a message of COMPOSE-TYPE.
@ -778,7 +778,7 @@ Symbol `edit' is only allowed for draft messages."
(when (window-live-p viewwin) (when (window-live-p viewwin)
(select-window viewwin)))) (select-window viewwin))))
;; talk to the backend ;; talk to the backend
(mu4e~proc-compose compose-type decrypt docid))))) (mu4e--server-compose compose-type decrypt docid)))))
(defun mu4e-compose-reply () (defun mu4e-compose-reply ()
"Compose a reply for the message at point in the headers buffer." "Compose a reply for the message at point in the headers buffer."

View File

@ -215,14 +215,14 @@ For testing/debugging."
(pop-to-buffer "*mu4e-contacts-info*"))) (pop-to-buffer "*mu4e-contacts-info*")))
(declare-function mu4e~proc-contacts "mu4e-proc") (declare-function mu4e--server-contacts "mu4e-server")
(defun mu4e--request-contacts-maybe () (defun mu4e--request-contacts-maybe ()
"If `mu4e-compose-complete-addresses' is non-nil, get/update "If `mu4e-compose-complete-addresses' is non-nil, get/update
the list of contacts we use for autocompletion; otherwise, do the list of contacts we use for autocompletion; otherwise, do
nothing." nothing."
(when mu4e-compose-complete-addresses (when mu4e-compose-complete-addresses
(mu4e~proc-contacts (mu4e--server-contacts
mu4e-compose-complete-only-personal mu4e-compose-complete-only-personal
mu4e-compose-complete-only-after mu4e-compose-complete-only-after
mu4e--contacts-tstamp))) mu4e--contacts-tstamp)))

View File

@ -28,7 +28,7 @@
(require 'cl-lib) (require 'cl-lib)
(require 'mu4e-helpers) (require 'mu4e-helpers)
(require 'mu4e-context) (require 'mu4e-context)
(require 'mu4e-proc) (require 'mu4e-server)
;;; Customization ;;; Customization
(defgroup mu4e-folders nil (defgroup mu4e-folders nil
@ -234,7 +234,7 @@ an absolute path."
(cond (cond
((file-directory-p dir) t) ((file-directory-p dir) t)
((yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir)) ((yes-or-no-p (mu4e-format "%s does not exist yet. Create now?" dir))
(mu4e~proc-mkdir dir) t) (mu4e--server-mkdir dir) t)
(t nil))) (t nil)))
(defun mu4e~get-maildirs-1 (path mdir) (defun mu4e~get-maildirs-1 (path mdir)
@ -326,7 +326,7 @@ Offer to create it if it does not exist yet."
(unless (file-directory-p fullpath) (unless (file-directory-p fullpath)
(and (yes-or-no-p (and (yes-or-no-p
(mu4e-format "%s does not exist. Create now?" fullpath)) (mu4e-format "%s does not exist. Create now?" fullpath))
(mu4e~proc-mkdir fullpath))) (mu4e--server-mkdir fullpath)))
mdir)) mdir))
;; mu4e-attachment-dir is either a string or a function that takes a ;; mu4e-attachment-dir is either a string or a function that takes a

View File

@ -37,7 +37,7 @@
(require 'mu4e-update) (require 'mu4e-update)
(require 'mu4e-utils) ;; utility functions (require 'mu4e-utils) ;; utility functions
(require 'mu4e-proc) (require 'mu4e-server)
(require 'mu4e-vars) (require 'mu4e-vars)
(require 'mu4e-mark) (require 'mu4e-mark)
(require 'mu4e-context) (require 'mu4e-context)
@ -784,7 +784,7 @@ true, do *not* update the query history stack."
(switch-to-buffer buf)) (switch-to-buffer buf))
(run-hook-with-args 'mu4e-search-hook expr) (run-hook-with-args 'mu4e-search-hook expr)
(mu4e~headers-clear mu4e~search-message) (mu4e~headers-clear mu4e~search-message)
(mu4e~proc-find (mu4e--server-find
rewritten-expr rewritten-expr
mu4e-search-threads mu4e-search-threads
mu4e-headers-sort-field mu4e-headers-sort-field
@ -1546,8 +1546,6 @@ window . "
(if (functionp mu4e-view-auto-mark-as-read) (if (functionp mu4e-view-auto-mark-as-read)
(funcall mu4e-view-auto-mark-as-read msg) (funcall mu4e-view-auto-mark-as-read msg)
mu4e-view-auto-mark-as-read)) mu4e-view-auto-mark-as-read))
(decrypt nil) ;; XXX remove
(verify nil) ;; XXX remove
(viewwin (mu4e~headers-redraw-get-view-window))) (viewwin (mu4e~headers-redraw-get-view-window)))
(unless (window-live-p viewwin) (unless (window-live-p viewwin)
(mu4e-error "Cannot get a message view")) (mu4e-error "Cannot get a message view"))
@ -1568,8 +1566,8 @@ window . "
;; (if mu4e-view-use-gnus ;; (if mu4e-view-use-gnus
;; (mu4e-view msg) ;; (mu4e-view msg)
;; (mu4e~proc-view dowcid decrypt)) ;; (mu4e--server-view dowcid decrypt))
(mu4e~proc-view docid mark-as-read decrypt verify))) (mu4e--server-view docid mark-as-read)))
(defun mu4e~headers-move (lines) (defun mu4e~headers-move (lines)

View File

@ -28,7 +28,7 @@
;;; Code: ;;; Code:
(require 'cl-lib) (require 'cl-lib)
(require 'mu4e-proc) (require 'mu4e-server)
(require 'mu4e-utils) (require 'mu4e-utils)
(require 'mu4e-message) (require 'mu4e-message)
(require 'mu4e-folders) (require 'mu4e-folders)
@ -133,50 +133,50 @@ The current buffer must be either a headers or view buffer."
:prompt "refile" :prompt "refile"
:dyn-target (lambda (target msg) (mu4e-get-refile-folder msg)) :dyn-target (lambda (target msg) (mu4e-get-refile-folder msg))
:action (lambda (docid msg target) :action (lambda (docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "-N"))) (mu4e--server-move docid (mu4e~mark-check-target target) "-N")))
(delete (delete
:char ("D" . "x") :char ("D" . "x")
:prompt "Delete" :prompt "Delete"
:show-target (lambda (target) "delete") :show-target (lambda (target) "delete")
:action (lambda (docid msg target) (mu4e~proc-remove docid))) :action (lambda (docid msg target) (mu4e--server-remove docid)))
(flag (flag
:char ("+" . "") :char ("+" . "")
:prompt "+flag" :prompt "+flag"
:show-target (lambda (target) "flag") :show-target (lambda (target) "flag")
:action (lambda (docid msg target) :action (lambda (docid msg target)
(mu4e~proc-move docid nil "+F-u-N"))) (mu4e--server-move docid nil "+F-u-N")))
(move (move
:char ("m" . "") :char ("m" . "")
:prompt "move" :prompt "move"
:ask-target mu4e~mark-get-move-target :ask-target mu4e~mark-get-move-target
:action (lambda (docid msg target) :action (lambda (docid msg target)
(mu4e~proc-move docid (mu4e~mark-check-target target) "-N"))) (mu4e--server-move docid (mu4e~mark-check-target target) "-N")))
(read (read
:char ("!" . "") :char ("!" . "")
:prompt "!read" :prompt "!read"
:show-target (lambda (target) "read") :show-target (lambda (target) "read")
:action (lambda (docid msg target) (mu4e~proc-move docid nil "+S-u-N"))) :action (lambda (docid msg target) (mu4e--server-move docid nil "+S-u-N")))
(trash (trash
:char ("d" . "") :char ("d" . "")
:prompt "dtrash" :prompt "dtrash"
:dyn-target (lambda (target msg) (mu4e-get-trash-folder msg)) :dyn-target (lambda (target msg) (mu4e-get-trash-folder msg))
:action (lambda (docid msg target) (mu4e~proc-move docid :action (lambda (docid msg target) (mu4e--server-move docid
(mu4e~mark-check-target target) "+T-N"))) (mu4e~mark-check-target target) "+T-N")))
(unflag (unflag
:char ("-" . "") :char ("-" . "")
:prompt "-unflag" :prompt "-unflag"
:show-target (lambda (target) "unflag") :show-target (lambda (target) "unflag")
:action (lambda (docid msg target) (mu4e~proc-move docid nil "-F-N"))) :action (lambda (docid msg target) (mu4e--server-move docid nil "-F-N")))
(untrash (untrash
:char ("=" . "") :char ("=" . "")
:prompt "=untrash" :prompt "=untrash"
:show-target (lambda (target) "untrash") :show-target (lambda (target) "untrash")
:action (lambda (docid msg target) (mu4e~proc-move docid nil "-T"))) :action (lambda (docid msg target) (mu4e--server-move docid nil "-T")))
(unread (unread
:char ("?" . "") :char ("?" . "")
:prompt "?unread" :prompt "?unread"
:show-target (lambda (target) "unread") :show-target (lambda (target) "unread")
:action (lambda (docid msg target) (mu4e~proc-move docid nil "-S+u-N"))) :action (lambda (docid msg target) (mu4e--server-move docid nil "-S+u-N")))
(unmark (unmark
:char " " :char " "
:prompt "unmark" :prompt "unmark"
@ -299,7 +299,7 @@ The following marks are available, and the corresponding props:
(when (or (file-directory-p fulltarget) (when (or (file-directory-p fulltarget)
(and (yes-or-no-p (and (yes-or-no-p
(format "%s does not exist. Create now?" fulltarget)) (format "%s does not exist. Create now?" fulltarget))
(mu4e~proc-mkdir fulltarget))) (mu4e--server-mkdir fulltarget)))
target))) target)))
(defun mu4e~mark-ask-target (mark) (defun mu4e~mark-ask-target (mark)

View File

@ -1,6 +1,6 @@
;;; mu4e-proc.el -- part of mu4e, the mu mail user agent -*- lexical-binding: t -*- ;;; mu4e-server.el -- part of mu4e -*- lexical-binding: t -*-
;; Copyright (C) 2011-2020 Dirk-Jan C. Binnema ;; Copyright (C) 2011-2021 Dirk-Jan C. Binnema
;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ;; Author: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl> ;; Maintainer: Dirk-Jan C. Binnema <djcb@djcbsoftware.nl>
@ -76,12 +76,12 @@ better with e.g. offlineimap."
(defvar mu4e-error-func nil (defvar mu4e-error-func nil
"Function called for each error received. "Function called for each error received.
The function is passed an error plist as argument. See The function is passed an error plist as argument. See
`mu4e~proc-filter' for the format.") `mu4e--server-filter' for the format.")
(defvar mu4e-update-func nil (defvar mu4e-update-func nil
"Function called for each :update sexp returned. "Function called for each :update sexp returned.
The function is passed a msg sexp as argument. The function is passed a msg sexp as argument.
See `mu4e~proc-filter' for the format.") See `mu4e--server-filter' for the format.")
(defvar mu4e-remove-func nil (defvar mu4e-remove-func nil
"Function called for each :remove sexp returned. "Function called for each :remove sexp returned.
@ -96,29 +96,29 @@ passed the docid and the draft-path of the sent message.")
(defvar mu4e-view-func nil (defvar mu4e-view-func nil
"Function called for each single-message sexp. "Function called for each single-message sexp.
The function is passed a message sexp as argument. See The function is passed a message sexp as argument. See
`mu4e~proc-filter' for the format.") `mu4e--server-filter' for the format.")
(defvar mu4e-header-func nil (defvar mu4e-header-func nil
"Function called for each message-header received. "Function called for each message-header received.
The function is passed a msg plist as argument. See The function is passed a msg plist as argument. See
`mu4e~proc-filter' for the format.") `mu4e--server-filter' for the format.")
(defvar mu4e-found-func nil (defvar mu4e-found-func nil
"Function called for when we received a :found sexp. "Function called for when we received a :found sexp.
This happens after the headers have been returned, to report on This happens after the headers have been returned, to report on
the number of matches. See `mu4e~proc-filter' for the format.") the number of matches. See `mu4e--server-filter' for the format.")
(defvar mu4e-erase-func nil (defvar mu4e-erase-func nil
"Function called we receive an :erase sexp. "Function called we receive an :erase sexp.
This before new headers are displayed, to clear the current This before new headers are displayed, to clear the current
headers buffer. See `mu4e~proc-filter' for the format.") headers buffer. See `mu4e--server-filter' for the format.")
(defvar mu4e-compose-func nil (defvar mu4e-compose-func nil
"Function called for each compose message received. "Function called for each compose message received.
I.e., the original message that is used as basis for composing a I.e., the original message that is used as basis for composing a
new message (i.e., either a reply or a forward); the function is new message (i.e., either a reply or a forward); the function is
passed msg and a symbol (either reply or forward). See passed msg and a symbol (either reply or forward). See
`mu4e~proc-filter' for the format of <msg-plist>.") `mu4e--server-filter' for the format of <msg-plist>.")
(defvar mu4e-info-func nil (defvar mu4e-info-func nil
"Function called for each (:info type ....) sexp received. "Function called for each (:info type ....) sexp received.
@ -135,65 +135,64 @@ sexp received from the server process.")
;;; Internal vars ;;; Internal vars
(defvar mu4e~proc-buf nil (defvar mu4e--server-buf nil
"Buffer (string) for data received from the backend.") "Buffer (string) for data received from the backend.")
(defconst mu4e~proc-name " *mu4e-proc*" (defconst mu4e--server-name " *mu4e-server*"
"Name of the server process, buffer.") "Name of the server process, buffer.")
(defvar mu4e~proc-process nil (defvar mu4e--server-process nil
"The mu-server process.") "The mu-server process.")
;; dealing with the length cookie that precedes expressions ;; dealing with the length cookie that precedes expressions
(defconst mu4e~cookie-pre "\376" (defconst mu4e--server-cookie-pre "\376"
"Each expression starts with a length cookie: "Each expression starts with a length cookie:
<`mu4e~cookie-pre'><length-in-hex><`mu4e~cookie-post'>.") <`mu4e--server-cookie-pre'><length-in-hex><`mu4e--server-cookie-post'>.")
(defconst mu4e~cookie-post "\377" (defconst mu4e--server-cookie-post "\377"
"Each expression starts with a length cookie: "Each expression starts with a length cookie:
<`mu4e~cookie-pre'><length-in-hex><`mu4e~cookie-post'>.") <`mu4e--server-cookie-pre'><length-in-hex><`mu4e--server-cookie-post'>.")
(defconst mu4e~cookie-matcher-rx (defconst mu4e--server-cookie-matcher-rx
(concat mu4e~cookie-pre "\\([[:xdigit:]]+\\)" mu4e~cookie-post) (concat mu4e--server-cookie-pre "\\([[:xdigit:]]+\\)"
mu4e--server-cookie-post)
"Regular expression matching the length cookie. "Regular expression matching the length cookie.
Match 1 will be the length (in hex).") Match 1 will be the length (in hex).")
(defun mu4e-running-p () (defun mu4e-running-p ()
"Whether mu4e is running. "Whether mu4e is running.
Checks whether the server process is live." Checks whether the server process is live."
(and mu4e~proc-process (and mu4e--server-process
(memq (process-status mu4e~proc-process) (memq (process-status mu4e--server-process)
'(run open listen connect stop)) '(run open listen connect stop))
t)) t))
(defsubst mu4e~proc-eat-sexp-from-buf () (defsubst mu4e--server-eat-sexp-from-buf ()
"'Eat' the next s-expression from `mu4e~proc-buf'. "'Eat' the next s-expression from `mu4e--server-buf'.
Note: this is a string, not an emacs-buffer. `mu4e~proc-buf gets Note: this is a string, not an emacs-buffer. `mu4e--server-buf gets
its contents from the mu-servers in the following form: its contents from the mu-servers in the following form:
<`mu4e~cookie-pre'><length-in-hex><`mu4e~cookie-post'> <`mu4e--server-cookie-pre'><length-in-hex><`mu4e--server-cookie-post'>
Function returns this sexp, or nil if there was none. Function returns this sexp, or nil if there was none.
`mu4e~proc-buf' is updated as well, with all processed sexp data `mu4e--server-buf' is updated as well, with all processed sexp data
removed." removed."
(ignore-errors ;; the server may die in the middle... (ignore-errors ;; the server may die in the middle...
;; mu4e~cookie-matcher-rx: (let ((b (string-match mu4e--server-cookie-matcher-rx mu4e--server-buf))
;; (concat mu4e~cookie-pre "\\([[:xdigit:]]+\\)]" mu4e~cookie-post)
(let ((b (string-match mu4e~cookie-matcher-rx mu4e~proc-buf))
(sexp-len) (objcons)) (sexp-len) (objcons))
(when b (when b
(setq sexp-len (string-to-number (match-string 1 mu4e~proc-buf) 16)) (setq sexp-len (string-to-number (match-string 1 mu4e--server-buf) 16))
;; does mu4e~proc-buf contain the full sexp? ;; does mu4e--server-buf contain the full sexp?
(when (>= (length mu4e~proc-buf) (+ sexp-len (match-end 0))) (when (>= (length mu4e--server-buf) (+ sexp-len (match-end 0)))
;; clear-up start ;; clear-up start
(setq mu4e~proc-buf (substring mu4e~proc-buf (match-end 0))) (setq mu4e--server-buf (substring mu4e--server-buf (match-end 0)))
;; note: we read the input in binary mode -- here, we take the part ;; note: we read the input in binary mode -- here, we take the part
;; that is the sexp, and convert that to utf-8, before we interpret ;; that is the sexp, and convert that to utf-8, before we interpret
;; it. ;; it.
(setq objcons (read-from-string (setq objcons (read-from-string
(decode-coding-string (decode-coding-string
(substring mu4e~proc-buf 0 sexp-len) (substring mu4e--server-buf 0 sexp-len)
'utf-8 t))) 'utf-8 t)))
(when objcons (when objcons
(setq mu4e~proc-buf (substring mu4e~proc-buf sexp-len)) (setq mu4e--server-buf (substring mu4e--server-buf sexp-len))
(car objcons))))))) (car objcons)))))))
(defun mu4e~proc-filter (_proc str) (defun mu4e--server-filter (_proc str)
"Filter string STR from PROC. "Filter string STR from PROC.
This processes the 'mu server' output. It accumulates the This processes the 'mu server' output. It accumulates the
strings into valid sexps by checking of the ';;eox' `end-of-sexp' strings into valid sexps by checking of the ';;eox' `end-of-sexp'
@ -251,8 +250,8 @@ The server output is as follows:
(:compose <reply|forward|edit|new> [:original<msg-sexp>] [:include <attach>]) (:compose <reply|forward|edit|new> [:original<msg-sexp>] [:include <attach>])
`mu4e-compose-func'." `mu4e-compose-func'."
(mu4e-log 'misc "* Received %d byte(s)" (length str)) (mu4e-log 'misc "* Received %d byte(s)" (length str))
(setq mu4e~proc-buf (concat mu4e~proc-buf str)) ;; update our buffer (setq mu4e--server-buf (concat mu4e--server-buf str)) ;; update our buffer
(let ((sexp (mu4e~proc-eat-sexp-from-buf))) (let ((sexp (mu4e--server-eat-sexp-from-buf)))
(with-local-quit (with-local-quit
(while sexp (while sexp
(mu4e-log 'from-server "%S" sexp) (mu4e-log 'from-server "%S" sexp)
@ -321,18 +320,10 @@ The server output is as follows:
(t (mu4e-message "Unexpected data from server [%S]" sexp))) (t (mu4e-message "Unexpected data from server [%S]" sexp)))
(setq sexp (mu4e~proc-eat-sexp-from-buf)))))) (setq sexp (mu4e--server-eat-sexp-from-buf))))))
(defun mu4e~escape (str) (defun mu4e--server-start ()
"Escape string STR for transport.
Put it in quotes, and escape existing quotation. In particular,
backslashes and double-quotes."
(let ((esc (replace-regexp-in-string "\\\\" "\\\\\\\\" str)))
(format "\"%s\"" (replace-regexp-in-string "\"" "\\\\\"" esc))))
(defun mu4e~proc-start ()
"Start the mu server process." "Start the mu server process."
;; sanity-check 1 ;; sanity-check 1
(unless (and mu4e-mu-binary (file-executable-p mu4e-mu-binary)) (unless (and mu4e-mu-binary (file-executable-p mu4e-mu-binary))
(mu4e-error (mu4e-error
@ -346,47 +337,48 @@ backslashes and double-quotes."
(unless (string= version mu4e-mu-version) (unless (string= version mu4e-mu-version)
(mu4e-error (mu4e-error
(concat (concat
"Found mu version %s, but mu4e needs version %s; please set `mu4e-mu-binary' " "Found mu version %s, but mu4e needs version %s"
"; please set `mu4e-mu-binary' "
"accordingly") version mu4e-mu-version))) "accordingly") version mu4e-mu-version)))
(let* ((process-connection-type nil) ;; use a pipe (let* ((process-connection-type nil) ;; use a pipe
(args (when mu4e-mu-home `(,(format"--muhome=%s" mu4e-mu-home)))) (args (when mu4e-mu-home `(,(format"--muhome=%s" mu4e-mu-home))))
(args (if mu4e-mu-debug (cons "--debug" args) args)) (args (if mu4e-mu-debug (cons "--debug" args) args))
(args (cons "server" args))) (args (cons "server" args)))
(setq mu4e~proc-buf "") (setq mu4e--server-buf "")
(setq mu4e~proc-process (apply 'start-process (setq mu4e--server-process (apply 'start-process
mu4e~proc-name mu4e~proc-name mu4e--server-name mu4e--server-name
mu4e-mu-binary args)) mu4e-mu-binary args))
;; register a function for (:info ...) sexps ;; register a function for (:info ...) sexps
(unless mu4e~proc-process (unless mu4e--server-process
(mu4e-error "Failed to start the mu4e backend")) (mu4e-error "Failed to start the mu4e backend"))
(set-process-query-on-exit-flag mu4e~proc-process nil) (set-process-query-on-exit-flag mu4e--server-process nil)
(set-process-coding-system mu4e~proc-process 'binary 'utf-8-unix) (set-process-coding-system mu4e--server-process 'binary 'utf-8-unix)
(set-process-filter mu4e~proc-process 'mu4e~proc-filter) (set-process-filter mu4e--server-process 'mu4e--server-filter)
(set-process-sentinel mu4e~proc-process 'mu4e~proc-sentinel))) (set-process-sentinel mu4e--server-process 'mu4e--server-sentinel)))
(defun mu4e~proc-kill () (defun mu4e--server-kill ()
"Kill the mu server process." "Kill the mu server process."
(let* ((buf (get-buffer mu4e~proc-name)) (let* ((buf (get-buffer mu4e--server-name))
(proc (and (buffer-live-p buf) (get-buffer-process buf)))) (proc (and (buffer-live-p buf) (get-buffer-process buf))))
(when proc (when proc
(let ((delete-exited-processes t)) (let ((delete-exited-processes t))
(mu4e~call-mu '(quit))) (mu4e--server-call-mu '(quit)))
;; try sending SIGINT (C-c) to process, so it can exit gracefully ;; try sending SIGINT (C-c) to process, so it can exit gracefully
(ignore-errors (ignore-errors
(signal-process proc 'SIGINT)))) (signal-process proc 'SIGINT))))
(setq (setq
mu4e~proc-process nil mu4e--server-process nil
mu4e~proc-buf nil)) mu4e--server-buf nil))
;; error codes are defined in src/mu-util ;; error codes are defined in src/mu-util
;;(defconst mu4e-xapian-empty 19 "Error code: xapian is empty/non-existent") ;;(defconst mu4e-xapian-empty 19 "Error code: xapian is empty/non-existent")
(defun mu4e~proc-sentinel (proc _msg) (defun mu4e--server-sentinel (proc _msg)
"Function called when the server process PROC terminates with MSG." "Function called when the server process PROC terminates with MSG."
(let ((status (process-status proc)) (code (process-exit-status proc))) (let ((status (process-status proc)) (code (process-exit-status proc)))
(setq mu4e~proc-process nil) (setq mu4e--server-process nil)
(setq mu4e~proc-buf "") ;; clear any half-received sexps (setq mu4e--server-buf "") ;; clear any half-received sexps
(cond (cond
((eq status 'signal) ((eq status 'signal)
(cond (cond
@ -403,27 +395,21 @@ backslashes and double-quotes."
(t (t
(error "Something bad happened to the mu server process"))))) (error "Something bad happened to the mu server process")))))
(defun mu4e~call-mu (form) (defun mu4e--server-call-mu (form)
"Call 'mu' with some command." "Call the mu server with some command FORM."
(unless (mu4e-running-p) (mu4e~proc-start)) (unless (mu4e-running-p) (mu4e--server-start))
(let* ((print-length nil) (print-level nil) (let* ((print-length nil) (print-level nil)
(cmd (format "%S" form))) (cmd (format "%S" form)))
(mu4e-log 'to-server "%s" cmd) (mu4e-log 'to-server "%s" cmd)
(process-send-string mu4e~proc-process (concat cmd "\n")))) (process-send-string mu4e--server-process (concat cmd "\n"))))
(defun mu4e~docid-msgid-param (docid-or-msgid) (defun mu4e--server-add (path)
"Construct a backend parameter based on DOCID-OR-MSGID."
(if (stringp docid-or-msgid)
`(:msgid ,(mu4e~escape docid-or-msgid))
`(:docid ,docid-or-msgid)))
(defun mu4e~proc-add (path)
"Add the message at PATH to the database. "Add the message at PATH to the database.
On success, we receive `'(:info add :path <path> :docid <docid>)' On success, we receive `'(:info add :path <path> :docid <docid>)'
as well as `'(:update <msg-sexp>)`'; otherwise, we receive an error." as well as `'(:update <msg-sexp>)`'; otherwise, we receive an error."
(mu4e~call-mu `(add :path ,path))) (mu4e--server-call-mu `(add :path ,path)))
(defun mu4e~proc-compose (type decrypt &optional docid) (defun mu4e--server-compose (type decrypt &optional docid)
"Compose a message of TYPE, DECRYPT it and use DOCID. "Compose a message of TYPE, DECRYPT it and use DOCID.
TYPE is a symbol, either `forward', `reply', `edit', `resend' or TYPE is a symbol, either `forward', `reply', `edit', `resend' or
`new', based on an original message (ie, replying to, forwarding, `new', based on an original message (ie, replying to, forwarding,
@ -431,42 +417,26 @@ editing, resending) with DOCID or nil for type `new'.
The result is delivered to the function registered as The result is delivered to the function registered as
`mu4e-compose-func'." `mu4e-compose-func'."
(mu4e~call-mu `(compose (mu4e--server-call-mu
:type ,type `(compose
:decrypt ,(and decrypt t) :type ,type
:docid ,docid))) :decrypt ,(and decrypt t)
:docid ,docid)))
(defun mu4e~proc-contacts (personal after tstamp) (defun mu4e--server-contacts (personal after tstamp)
"Ask for contacts with PERSONAL AFTER TSTAMP. "Ask for contacts with PERSONAL AFTER TSTAMP.
S-expression (:contacts (<list>) :tstamp \"<tstamp>\") is expected in S-expression (:contacts (<list>) :tstamp \"<tstamp>\") is expected in
response. If PERSONAL is non-nil, only get personal contacts, if response. If PERSONAL is non-nil, only get personal contacts, if
AFTER is non-nil, get only contacts seen AFTER (the time_t AFTER is non-nil, get only contacts seen AFTER (the time_t
value)." value)."
(mu4e~call-mu `(contacts (mu4e--server-call-mu
:personal ,(and personal t) `(contacts
:after ,(or after nil) :personal ,(and personal t)
:tstamp ,(or tstamp nil)))) :after ,(or after nil)
:tstamp ,(or tstamp nil))))
(defun mu4e~proc-extract (action docid index decrypt (defun mu4e--server-find (query threads sortfield sortdir maxnum skip-dups
&optional path what param) include-related)
"Perform ACTION on part with DOCID INDEX DECRYPT PATH WHAT PARAM.
Use a message with DOCID and perform ACTION on it (as symbol,
either `save', `open', `temp') which mean:
* save: save the part to PATH (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>)."
(mu4e~call-mu `(extract
:action ,action
:docid ,docid
:index ,index
:decrypt ,(and decrypt t)
:path ,path
:what ,what
:param ,param)))
(defun mu4e~proc-find (query threads sortfield sortdir maxnum skip-dups
include-related)
"Run QUERY with THREADS SORTFIELD SORTDIR MAXNUM SKIP-DUPS INCLUDE-RELATED. "Run QUERY with THREADS SORTFIELD SORTDIR MAXNUM SKIP-DUPS INCLUDE-RELATED.
If THREADS is non-nil, show results in threaded fashion, SORTFIELD If THREADS is non-nil, show results in threaded fashion, SORTFIELD
is a symbol describing the field to sort by (or nil); see is a symbol describing the field to sort by (or nil); see
@ -482,26 +452,25 @@ For each result found, a function is called, depending on the
kind of result. The variables `mu4e-error-func' contain the kind of result. The variables `mu4e-error-func' contain the
function that will be called for, resp., a message (header row) function that will be called for, resp., a message (header row)
or an error." or an error."
(mu4e~call-mu `(find (mu4e--server-call-mu
:query ,query `(find
:threads ,threads :query ,query
:sortfield ,sortfield :threads ,threads
:descending ,(if (eq sortdir 'descending) t nil) :sortfield ,sortfield
:maxnum ,maxnum :descending ,(if (eq sortdir 'descending) t nil)
:skip-dups ,skip-dups :maxnum ,maxnum
:include-related ,include-related))) :skip-dups ,skip-dups
:include-related ,include-related)))
(defun mu4e~proc-index (&optional cleanup lazy-check) (defun mu4e--server-index (&optional cleanup lazy-check)
"Index messages with possible CLEANUP and LAZY-CHECK." "Index messages with possible CLEANUP and LAZY-CHECK."
(mu4e~call-mu `(index :cleanup ,cleanup :lazy-check ,lazy-check))) (mu4e--server-call-mu `(index :cleanup ,cleanup :lazy-check ,lazy-check)))
(defun mu4e~proc-mkdir (path) (defun mu4e--server-mkdir (path)
"Create a new maildir-directory at filesystem PATH." "Create a new maildir-directory at filesystem PATH."
;;(mu4e~proc-send-command "cmd:mkdir path:%s" (mu4e~escape path)) (mu4e--server-call-mu `(mkdir :path ,path)))
(mu4e~call-mu `(mkdir :path ,path)))
(defun mu4e--server-move (docid-or-msgid &optional maildir flags no-view)
(defun mu4e~proc-move (docid-or-msgid &optional maildir flags no-view)
"Move message identified by DOCID-OR-MSGID. "Move message identified by DOCID-OR-MSGID.
Optionally to MAILDIR and optionally setting FLAGS. If MAILDIR is Optionally to MAILDIR and optionally setting FLAGS. If MAILDIR is
nil, message will be moved within the same maildir. nil, message will be moved within the same maildir.
@ -539,60 +508,46 @@ Returns either (:update ... ) or (:error ) sexp, which are handled my
(unless (or (not maildir) (unless (or (not maildir)
(file-exists-p (concat (mu4e-root-maildir) "/" maildir "/"))) (file-exists-p (concat (mu4e-root-maildir) "/" maildir "/")))
(mu4e-error "Target dir does not exist")) (mu4e-error "Target dir does not exist"))
(mu4e~call-mu `(move (mu4e--server-call-mu
:docid ,(if (stringp docid-or-msgid) nil docid-or-msgid) `(move
:msgid ,(if (stringp docid-or-msgid) docid-or-msgid nil) :docid ,(if (stringp docid-or-msgid) nil docid-or-msgid)
:flags ,(or flags nil) :msgid ,(if (stringp docid-or-msgid) docid-or-msgid nil)
:maildir ,(or maildir nil) :flags ,(or flags nil)
:rename ,(and maildir mu4e-change-filenames-when-moving t) :maildir ,(or maildir nil)
:no-view ,(and no-view t)))) :rename ,(and maildir mu4e-change-filenames-when-moving t)
:no-view ,(and no-view t))))
(defun mu4e~proc-ping (&optional queries) (defun mu4e--server-ping (&optional queries)
"Sends a ping to the mu server, expecting a (:pong ...) in response. "Sends a ping to the mu server, expecting a (:pong ...) in response.
QUERIES is a list of queries for the number of results with read/unread status QUERIES is a list of queries for the number of results with read/unread status
are returned in the 'pong' response." are returned in the 'pong' response."
(mu4e~call-mu `(ping :queries ,queries))) (mu4e--server-call-mu `(ping :queries ,queries)))
(defun mu4e~proc-remove (docid) (defun mu4e--server-remove (docid)
"Remove message with DOCID. "Remove message with DOCID.
The results are reporter through either (:update ... ) The results are reporter through either (:update ... )
or (:error) sexp, which are handled my `mu4e-error-func', or (:error) sexp, which are handled my `mu4e-error-func',
respectively." respectively."
(mu4e~call-mu `(remove :docid ,docid))) (mu4e--server-call-mu `(remove :docid ,docid)))
(defun mu4e~proc-sent (path) (defun mu4e--server-sent (path)
"Add the message at PATH to the database. "Tell the mu server we sent a message at PATH.
If this works, we will receive (:info add :path <path> :docid
if this works, we will receive (:info add :path <path> :docid
<docid> :fcc <path>)." <docid> :fcc <path>)."
(mu4e~call-mu `(sent :path ,path))) (mu4e--server-call-mu `(sent :path ,path)))
(defun mu4e~proc-view (docid-or-msgid &optional mark-as-read decrypt verify) (defun mu4e--server-view (docid-or-msgid &optional mark-as-read)
"Get a message DOCID-OR-MSGID. "Get a message DOCID-OR-MSGID.
Optionally, if MARK-AS-READ is non-nil, the backend marks the message as Optionally, if MARK-AS-READ is non-nil, the backend marks the
read before returning, if it was not already unread. message as read before returning, if it was not already unread.
DECRYPT and VERIFY if necessary. The result will be delivered to The result will be delivered to the function registered as
the function registered as `mu4e-view-func'." `mu4e-view-func'."
(mu4e~call-mu `(view (mu4e--server-call-mu
:docid ,(if (stringp docid-or-msgid) nil docid-or-msgid) `(view
:msgid ,(if (stringp docid-or-msgid) docid-or-msgid nil) :docid ,(if (stringp docid-or-msgid) nil docid-or-msgid)
:mark-as-read ,mark-as-read :msgid ,(if (stringp docid-or-msgid) docid-or-msgid nil)
:extract-images nil ;; XXX remove :mark-as-read ,mark-as-read)))
:decrypt ,(and decrypt t) ;; XXX remove
:verify ,(and verify t)))) ;; XXX remove
(defun mu4e~proc-view-path (path &optional images decrypt verify)
"View message at PATH.. (provide 'mu4e-server)
Optionally, if IMAGES is non-nil, backend will any images ;;; mu4e-server.el ends here
attached to the message, and return them as temp files. The
result will be delivered to the function registered as
`mu4e-view-func'. Optionally DECRYPT and VERIFY."
(mu4e~call-mu `(view
:path ,path
:extract-images ,(if images t nil)
:decrypt ,(and decrypt t)
:verify ,(and verify t))))
;;; _
(provide 'mu4e-proc)
;;; mu4e-proc.el ends here

View File

@ -28,7 +28,7 @@
;;; Code: ;;; Code:
(require 'mu4e-helpers) (require 'mu4e-helpers)
(require 'mu4e-proc) (require 'mu4e-server)
;;; Customization ;;; Customization
@ -194,7 +194,7 @@ However, if `mu4e-hide-index-messages' is non-nil, do not display anything."
(defun mu4e-update-index () (defun mu4e-update-index ()
"Update the mu4e index." "Update the mu4e index."
(interactive) (interactive)
(mu4e~proc-index mu4e-index-cleanup mu4e-index-lazy-check)) (mu4e--server-index mu4e-index-cleanup mu4e-index-lazy-check))
(defun mu4e-update-index-nonlazy () (defun mu4e-update-index-nonlazy ()
"Update the mu4e index non-lazily. "Update the mu4e index non-lazily.

View File

@ -43,7 +43,7 @@
(require 'mu4e-headers) (require 'mu4e-headers)
(require 'mu4e-mark) (require 'mu4e-mark)
(require 'mu4e-message) (require 'mu4e-message)
(require 'mu4e-proc) (require 'mu4e-server)
(require 'mu4e-search) (require 'mu4e-search)
(require 'mu4e-utils) ;; utility functions (require 'mu4e-utils) ;; utility functions
(require 'mu4e-contacts) (require 'mu4e-contacts)
@ -201,7 +201,6 @@ Then, display the results."
(let ((path (mu4e-message-field (mu4e-message-at-point) :path))) (let ((path (mu4e-message-field (mu4e-message-at-point) :path)))
(mu4e-process-file-through-pipe path cmd))) (mu4e-process-file-through-pipe path cmd)))
(defmacro mu4e~view-in-headers-context (&rest body) (defmacro mu4e~view-in-headers-context (&rest body)
"Evaluate BODY in the context of the headers buffer connected to "Evaluate BODY in the context of the headers buffer connected to
this view." this view."

View File

@ -36,7 +36,7 @@
(require 'mu4e-bookmarks) (require 'mu4e-bookmarks)
(require 'mu4e-update) (require 'mu4e-update)
(require 'mu4e-main) (require 'mu4e-main)
(require 'mu4e-proc) ;; communication with backend (require 'mu4e-server) ;; communication with backend
@ -136,7 +136,7 @@ successful, call FUNC (if non-nil) afterwards."
(unless (mu4e-context-current) (unless (mu4e-context-current)
(mu4e--context-autoswitch nil mu4e-context-policy)) (mu4e--context-autoswitch nil mu4e-context-policy))
(setq mu4e-pong-func (lambda (info) (mu4e--pong-handler info func))) (setq mu4e-pong-func (lambda (info) (mu4e--pong-handler info func)))
(mu4e~proc-ping (mu4e--server-ping
(mapcar ;; send it a list of queries we'd like to see read/unread info for (mapcar ;; send it a list of queries we'd like to see read/unread info for
(lambda (bm) (lambda (bm)
(funcall (or mu4e-search-query-rewrite-function #'identity) (funcall (or mu4e-search-query-rewrite-function #'identity)
@ -158,7 +158,7 @@ successful, call FUNC (if non-nil) afterwards."
(cancel-timer mu4e--update-timer) (cancel-timer mu4e--update-timer)
(setq mu4e--update-timer nil)) (setq mu4e--update-timer nil))
(mu4e-clear-caches) (mu4e-clear-caches)
(mu4e~proc-kill) (mu4e--server-kill)
;; kill all mu4e buffers ;; kill all mu4e buffers
(mapc (mapc
(lambda (buf) (lambda (buf)

View File

@ -2287,7 +2287,7 @@ loading @t{mu4e}):
;; must come before proc-move since retag runs ;; must come before proc-move since retag runs
;; 'sed' on the file ;; 'sed' on the file
(mu4e-action-retag-message msg "-\\Inbox") (mu4e-action-retag-message msg "-\\Inbox")
(mu4e~proc-move docid nil "+S-u-N")))) (mu4e--server-move docid nil "+S-u-N"))))
@end lisp @end lisp
Adding to @code{mu4e-marks} list allows to use the mark in bulk operations Adding to @code{mu4e-marks} list allows to use the mark in bulk operations
@ -5058,15 +5058,15 @@ to provide this information (this is implemented in
@file{mu-cmd-server.c}). @file{mu-cmd-server.c}).
We start this sequence when @t{mu4e} is invoked (when the program is We start this sequence when @t{mu4e} is invoked (when the program is
started). It calls @t{mu4e-proc-ping}, and registers a (lambda) function for started). It calls @t{mu4e-server-ping}, and registers a (lambda) function for
@t{mu4e-proc-pong-func}, to handle the response. @t{mu4e-server-pong-func}, to handle the response.
@verbatim @verbatim
-> (ping) -> (ping)
<-<prefix>(:pong "mu" :props (:version "x.x.x" :doccount 78545)) <-<prefix>(:pong "mu" :props (:version "x.x.x" :doccount 78545))
@end verbatim @end verbatim
When we receive such a @t{pong} (in @file{mu4e-proc.el}), the lambda When we receive such a @t{pong} (in @file{mu4e-server.el}), the lambda
function we registered is called, and it compares the version we got function we registered is called, and it compares the version we got
from the @t{pong} with the version we expected, and raises an error if from the @t{pong} with the version we expected, and raises an error if
they differ. they differ.