X-Git-Url: https://www.fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mymail.git;a=blobdiff_plain;f=mymail-vm.el;h=2c9970f53f739a4fb2658cf9efeeba536cff4c90;hp=7b2e6eafc3ea0ed7942b88ac9d34765d8206215e;hb=HEAD;hpb=98d120652fe86d6507579708ace19afb4b7feced diff --git a/mymail-vm.el b/mymail-vm.el index 7b2e6ea..2c9970f 100644 --- a/mymail-vm.el +++ b/mymail-vm.el @@ -16,28 +16,92 @@ ;; You should have received a copy of the GNU General Public License ;; along with mymail. If not, see . -(add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox") +;; You may want to add +;; +;; (add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox") +;; +;; to your .emacs +;; +;; I also use +;; +;; (define-key vm-summary-mode-map "\\" 'mymail/vm-visit-folder) +;; +;; So that pressing "\" in the summary start a search with mymail + +(defgroup mymail () + "Command to visit a folder built on-the-fly with mymail" + :version "0.9.10") + +(defcustom mymail/default-additional-search-requests "" + "Comma-separated list of search requests to add to any search" + :type 'string + :group 'mymail) -(defcustom mymail/default-search-request "" - "Default request to add to any search" - :type 'string) +(defcustom mymail/default-search-request nil + "Default request to use in place of the empty search" + :type 'string + :group 'mymail) (defun mymail/vm-visit-folder (param) + "Read a comma-separated list of search requests for mymail, +create a temporary mbox with the resulting mails, and open it in +vm with `vm-visit-folder'. + +If the request string is empty, use +`mymail/default-search-request' instead. + +The string `mymail/default-additional-search-requests' is automatically +concatenated to the provided request, except if the request is +prefaced with `\\'." (interactive - (list (read-string "mymail: " nil 'mymail-vm-history))) + (list (read-string "mymail-vm: " nil 'mymail-vm-history))) + + (if (string= param "") + (if mymail/default-search-request + (setq param mymail/default-search-request) + (error "mymail error: empty search"))) (let ((n 1) (mbox-name nil) - (args (mapconcat - (lambda (searche-request) - (if (not (string= searche-request "")) - (concat "-s " "\"" searche-request "\""))) - (split-string (concat param "," mymail/default-search-request) ",") - " "))) + + (search-args + (apply 'nconc + (mapcar + (lambda (searche-request) + (if (not (string= searche-request "")) + (list "--search" searche-request))) + (if (string= (substring param 0 1) "\\") + (split-string (substring param 1 nil) ",") + (split-string (concat param "," + mymail/default-additional-search-requests) ",")) + ))) + ) (while (get-file-buffer (setq mbox-name (format "/tmp/mymail-vm-%d.mbox" n))) (setq n (+ n 1))) - (shell-command (concat "mymail --quiet --output " mbox-name " " args)) - (vm-visit-folder mbox-name t) - )) + ;; (message (prin1-to-string + ;; (nconc (list "mymail" + ;; "--output" mbox-name + ;; "--default-search" "p" + ;; "--nb-mails-max" "500") + ;; search-args)) + ;; ) + + (if (= (apply 'call-process + (nconc (list "mymail" nil '(nil "/tmp/mymail.err") nil + "--output" mbox-name + "--default-search" "p" + "--nb-mails-max" "500") + search-args)) + 0) + (vm-visit-folder mbox-name t) + + ;; (message "mymail failed. See /tmp/mymail.err")) + + (message (with-temp-buffer + (insert-file-contents "/tmp/mymail.err") + (replace-string "\n" " ") + (buffer-string))) + ) + ))