From 2c26c4dca2d779384546a464562d65db869cb1f8 Mon Sep 17 00:00:00 2001 From: "Dirk-Jan C. Binnema" Date: Tue, 9 Aug 2011 07:52:15 +0300 Subject: [PATCH] * mua updates --- toys/mua/mua-common.el | 49 ++++++++++++++++++++++++++++++++++++++---- toys/mua/mua-msg.el | 15 ------------- toys/mua/mua-view.el | 14 ++++++------ toys/mua/mua.el | 3 --- 4 files changed, 51 insertions(+), 30 deletions(-) diff --git a/toys/mua/mua-common.el b/toys/mua/mua-common.el index 9317b8a5..20640ae6 100644 --- a/toys/mua/mua-common.el +++ b/toys/mua/mua-common.el @@ -83,12 +83,53 @@ maildir" (chosen (ido-completing-read prompt showfolders))) (concat (if fullpath mua/maildir "") chosen))) +(defun mua/mu-run (&rest args) + "Run 'mu' synchronously with ARGS as command-line argument;, +where is the exit code of the program, or 1 if the +process was killed. contains whatever the command wrote on +standard output/error, or nil if there was none or in case of +error. Basically, `mua/mu-run' is like `shell-command-to-string', +but with better possibilities for error handling" + (let* ((rv) + (str (with-output-to-string + (with-current-buffer standard-output ;; but we also get stderr... + (setq rv (apply 'call-process mua/mu-binary nil t nil + args)))))) + `(,(if (numberp rv) rv 1) . ,str))) + (defun mua/mu-binary-version () - "Get the version of the mu binary." - (let ((cmd (concat mua/mu-binary - " --version | head -1 | sed 's/.*version //'"))) - (substring (shell-command-to-string cmd) 0 -1))) + "Get the version string of the mu binary, or nil if we failed +to get it" + (let ((rv (mua/mu-run "--version"))) + (if (and (= (car rv) 0) (string-match "version \\(.*\\)$" (cdr rv))) + (match-string 1 (cdr rv)) + (mua/warn "Failed to get version string")))) +(defun mua/mu-mv (src target &optional flags)) + +(defun mua/mu-add (src target &optional flags)) + +(defun mua/mu-remove (path) + "Remove message at PATH from the database" + + + ) + +(defun mua/mu-mv (src target &optional flags)) + + +(defun mua/mu-view-sexp (path) + "Return a string with an s-expression representing the message +at PATH; the format is described in `mua/msg-from-string', and +that function converts the string into a Lisp object (plist)" + (if (not (file-readable-p path)) + (mua/warn "Path is note a readable file") + (let* ((rv (mua/mu-run "view" "--format=sexp" path)) + (code (car rv)) (str (cdr rv))) + (if (= code 0) + str + (mua/warn "mu view failed (%d): %s" + code (if str str "error")))))) (provide 'mua-common) diff --git a/toys/mua/mua-msg.el b/toys/mua/mua-msg.el index 975536d0..54d59c79 100644 --- a/toys/mua/mua-msg.el +++ b/toys/mua/mua-msg.el @@ -67,21 +67,6 @@ database -- at least not in a usable way." (error "Failed to parse message"))) -(defun mua/msg-from-path (path) - "Get the an s-expression (plist) describing the e-mail message -at path, or nil if it failed. This functions uses 'mu view' to -obtain the s-expression. For the format, see `mua/msg-from-string'" - (if (not (file-readable-p path)) - (progn - (mua/warn "Message is not readable") - (mua/log "not readable: %s" path)) - (condition-case nil - (progn (let* ((cmd (concat mua/mu-binary " view --format=sexp " path)) - (str (shell-command-to-string cmd))) - (mua/msg-from-string str))) - (error "Failed to read/parse message %s" path)))) - - (defun mua/msg-body-txt-or-html (msg) "Get :body-txt, or if not available, :body-html converted to text, using `html2text'." diff --git a/toys/mua/mua-view.el b/toys/mua/mua-view.el index 7e2287f7..57d4d48e 100644 --- a/toys/mua/mua-view.el +++ b/toys/mua/mua-view.el @@ -53,18 +53,16 @@ we quit from this view. Also, if PARENTBUF is a find buffer (ie., has mu-headers-mode as its major mode), this allows various commands (navigation, marking etc.) to be applied to this buffer." - (let* ((msg (mua/msg-from-path path)) - (buf (get-buffer-create mua/view-buffer-name)) - (str (mua/view-message msg))) - (when (and msg str) - - (switch-to-buffer buf) + (let* ((sexp (mua/mu-view-sexp path)) + (msg (and sexp (mua/msg-from-string sexp)))) + (when msg + (switch-to-buffer (get-buffer-create mua/view-buffer-name)) (let ((inhibit-read-only t)) (erase-buffer) - (insert str)) + (insert (mua/view-message msg))) (mua/view-mode) - + (setq ;; these are buffer-local mua/hdrs-buffer headersbuf mua/parent-buffer headersbuf) diff --git a/toys/mua/mua.el b/toys/mua/mua.el index 61de0f5a..cda516e6 100644 --- a/toys/mua/mua.el +++ b/toys/mua/mua.el @@ -66,9 +66,6 @@ quitted, it switches back to its parent buffer") (setq mua/working-folders '("/archive" "/bulkarchive" "/todo")) - - - (setq mua/header-fields '( (:date . 25) (:flags . 6)