From 3540abdfebd60494f45a795692f15909e5a31449 Mon Sep 17 00:00:00 2001 From: djcb Date: Thu, 19 Apr 2012 08:30:42 +0300 Subject: [PATCH] * initial support for mail-user-agent (WIP) --- emacs/mu4e-compose.el | 46 +++++++++++++++++++++++++++++++++- emacs/mu4e-proc.el | 2 +- emacs/mu4e-utils.el | 58 ++++++++++++++++++++++++++----------------- emacs/mu4e-vars.el | 1 + 4 files changed, 82 insertions(+), 25 deletions(-) diff --git a/emacs/mu4e-compose.el b/emacs/mu4e-compose.el index c99e92a3..08414c03 100644 --- a/emacs/mu4e-compose.el +++ b/emacs/mu4e-compose.el @@ -317,6 +317,11 @@ use the new docid. Returns the full path to the new message." ;; if the default charset is not set, use UTF-8 (unless message-default-charset (setq message-default-charset 'utf-8)) + + ;; make sure mu4e is started in the background (ie. we don't want to error out + ;; when sending the message; better to do it now if there's a problem) + (mu4e :hide-ui t) + ;; hack-hack-hack... just before saving, we remove the ;; mail-header-separator; just after saving we restore it; thus, the ;; separator should never appear on disk @@ -372,7 +377,7 @@ symbol, either `reply', `forward', `edit', `new'. `edit' is for editing existing messages. When COMPOSE-TYPE is `reply' or `forward', MSG should be a message -plist. If COMPOSE-TYPE is `new', MSG should be nil. +plist. If COMPOSE-TYPE is `new', ORIGINAL-MSG should be nil. Optionally (when forwarding, replying) ORIGINAL-MSG is the original message we will forward / reply to. @@ -508,4 +513,43 @@ buffer. (when (and forwarded-from (string-match "<\\(.*\\)>" forwarded-from)) (mu4e-proc-move (match-string 1 forwarded-from) nil "+P")))) + + +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; +;; mu4e-compose-func and mu4e-send-func are wrappers so we can set ourselves +;; as default emacs mailer (define-mail-user-agent etc.) + +(defun mu4e-compose-func (&optional to subject other-headers continue + switch-function yank-action send-actions + return-action) + "mu4e's implementation of `compose-mail'." + + ;; create a new draft message + (mu4e-compose-handler 'new) + + (when to ;; reset to-address, if needed + (message-goto-to) + (message-delete-line) + (insert (concat "To: " to "\n"))) + (when subject ;; reset subject, if needed + (message-goto-subject) + (message-delete-line) + (insert (concat "Subject: " subject "\n"))) + ;; add any other headers... inspired by message-mode + ;; FIXME: need to convert the headers. + ;; (when other-headers + ;; (message-add-header other-headers)) + + (if (bufferp yank-action) + (list 'insert-buffer yank-action) + yank-action)) + +;; happily, we can reuse most things from message mode +(define-mail-user-agent 'mu4e-user-agent + 'mu4e-compose-func + 'message-send-and-exit + 'message-kill-buffer + 'message-send-hook) +;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; + (provide 'mu4e-compose) diff --git a/emacs/mu4e-proc.el b/emacs/mu4e-proc.el index ee7ac5c2..8b793d12 100644 --- a/emacs/mu4e-proc.el +++ b/emacs/mu4e-proc.el @@ -29,7 +29,7 @@ ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;; internal vars -(defvar mu4e-mu-proc nil "*internal* The mu-server process") + (defvar mu4e-buf nil "*internal* Buffer for results data.") (defvar mu4e-path-docid-map diff --git a/emacs/mu4e-utils.el b/emacs/mu4e-utils.el index d4867d59..a26b0a25 100644 --- a/emacs/mu4e-utils.el +++ b/emacs/mu4e-utils.el @@ -475,33 +475,45 @@ process." (defvar mu4e-update-timer nil "*internal* The mu4e update timer.") -(defun mu4e () - "Start mu4e. We do this by sending a 'ping' to the mu server +(defun mu4e-proc-is-running () + "Whether the mu process is running." + (buffer-live-p mu4e-mu-proc)) + +(defun* mu4e (&key (hide-ui nil)) + "Start mu4e . We do this by sending a 'ping' to the mu server process, and start the main view if the 'pong' we receive from the -server has the expected values." +server has the expected values. If keyword argument :hide-ui is +non-nil, don't show the UI." (interactive) - (if (buffer-live-p (get-buffer mu4e-main-buffer-name)) - (switch-to-buffer mu4e-main-buffer-name) - (mu4e-check-requirements) - ;; explicit version checks are a bit questionable, - ;; better to check for specific features - (if (< emacs-major-version 23) + ;; if we're already running, simply go to the main view + (if (mu4e-proc-is-running) + (unless hide-ui + (mu4e-main-view)) + (progn + ;; otherwise, check whether all is okay; + (mu4e-check-requirements) + ;; explicit version checks are a bit questionable, + ;; better to check for specific features + (if (< emacs-major-version 23) (error "Emacs >= 23.x is required for mu4e") (progn - (setq mu4e-pong-func - (lambda (version doccount) - (unless (string= version mu4e-mu-version) - (error "mu server has version %s, but we need %s" - version mu4e-mu-version)) - (mu4e-main-view) - (when (and mu4e-update-interval (null mu4e-update-timer)) - (setq mu4e-update-timer - (run-at-time - 0 mu4e-update-interval - 'mu4e-update-mail))) - (message "Started mu4e with %d message%s in store" - doccount (if (= doccount 1) "" "s")))) - (mu4e-proc-ping))))) + ;; define the closure (when we receive the 'pong' + (lexical-let ((hide-ui hide-ui)) + (setq mu4e-pong-func + (lambda (version doccount) + (unless (string= version mu4e-mu-version) + (error "mu server has version %s, but we need %s" + version mu4e-mu-version)) + (unless hide-ui + (mu4e-main-view)) + (when (and mu4e-update-interval (null mu4e-update-timer)) + (setq mu4e-update-timer + (run-at-time + 0 mu4e-update-interval 'mu4e-update-mail))) + (message "Started mu4e with %d message%s in store" + doccount (if (= doccount 1) "" "s"))))) + ;; send the ping + (mu4e-proc-ping)))))) (defun mu4e-quit() "Quit the mu4e session." diff --git a/emacs/mu4e-vars.el b/emacs/mu4e-vars.el index 2ffd1222..08d49b20 100644 --- a/emacs/mu4e-vars.el +++ b/emacs/mu4e-vars.el @@ -457,6 +457,7 @@ in which case it will be equal to `:to'.)") (defconst mu4e-log-buffer-name "*mu4e-log*" "*internal* Name of the logging buffer.") +(defvar mu4e-mu-proc nil "*internal* The mu-server process")