X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mymail.git;a=blobdiff_plain;f=mymail-vm.el;h=c2b96ae0fa58bd87d334e6b9e1b58c84367be3de;hp=03b52ccbbb38266f4656a4eb53de8240d0e67c71;hb=4daf9c65395d6f7f6368194d5bf32047db0eea8c;hpb=46cfbfe43243177f1522a55d8ada0935f476550e diff --git a/mymail-vm.el b/mymail-vm.el index 03b52cc..c2b96ae 100644 --- a/mymail-vm.el +++ b/mymail-vm.el @@ -16,13 +16,49 @@ ;; 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") + +(defcustom mymail/default-search-request "" + "Default request to add to any search" + :type 'string) + (defun mymail/vm-visit-folder (param) - (interactive (list (read-string "mymail-vm search: " nil 'mymail-vm-history))) - - (let ((args (mapconcat (lambda (x) (concat "-s " "\"" x "\"")) - (split-string param ",") - " "))) - (shell-command (concat "mymail " args " > /tmp/mymail.mbox")) - ) - (vm-visit-folder "/tmp/mymail.mbox") - ) + "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'. + +The string `mymail/default-search-request' is automatically +concatenated to the provided request, except if the request is +prefaced with \\." + (interactive + (list (read-string "mymail-vm: " nil 'mymail-vm-history))) + + (let ((n 1) + (mbox-name nil) + + (search-args + + (apply 'nconc + (mapcar + (lambda (searche-request) + (if (not (string= searche-request "")) + (list "-s" searche-request))) + (if (string= (substring param 0 1) "\\") + (split-string (substring param 1 nil)) + (split-string (concat param "," mymail/default-search-request) ",")) + ))) + + ) + + (while (get-file-buffer (setq mbox-name (format "/tmp/mymail-vm-%d.mbox" n))) + (setq n (+ n 1))) + + (if (= (apply 'call-process + (nconc (list "mymail" nil nil nil + "--output" mbox-name + "--default-search" "p") + search-args)) + 0) + (vm-visit-folder mbox-name t) + (message "mymail failed")) + ))