X-Git-Url: https://fleuret.org/cgi-bin/gitweb/gitweb.cgi?p=mymail.git;a=blobdiff_plain;f=mymail-vm.el;h=840bd93026187344c4ce623ff506b8c72497f153;hp=1795834c3ff26b3fcc6d55ef600f99499d57c689;hb=7b9e0f6566b6a597dc83f79dd405e0ddd520a7ff;hpb=11819e767975e5e98828e34f4b3130fd2ce50c57 diff --git a/mymail-vm.el b/mymail-vm.el index 1795834..840bd93 100644 --- a/mymail-vm.el +++ b/mymail-vm.el @@ -1,37 +1,86 @@ -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; -;; This program is free software: you can redistribute it and/or modify ;; -;; it under the terms of the version 3 of the GNU General Public License ;; -;; as published by the Free Software Foundation. ;; -;; ;; -;; This program is distributed in the hope that it will be useful, but ;; -;; WITHOUT ANY WARRANTY; without even the implied warranty of ;; -;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ;; -;; General Public License for more details. ;; -;; ;; -;; You should have received a copy of the GNU General Public License ;; -;; along with this program. If not, see . ;; -;; ;; -;; Written by and Copyright (C) Francois Fleuret ;; -;; Contact for comments & bug reports ;; -;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; - -;; mymail-el - -(setq mymail-history-file ("~/.mymail-el-history")) - -;; (setq mymail-history '("p francois.fleuret,f 2013")) +;; Copyright (c) 2013 Francois Fleuret +;; Written by Francois Fleuret +;; +;; This file is part of mymail. +;; +;; mymail is free software: you can redistribute it and/or modify it +;; under the terms of the GNU General Public License version 3 as +;; published by the Free Software Foundation. +;; +;; mymail is distributed in the hope that it will be useful, but +;; WITHOUT ANY WARRANTY; without even the implied warranty of +;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU +;; General Public License for more details. +;; +;; You should have received a copy of the GNU General Public License +;; along with mymail. If not, see . + +;; You may want to add +;; +;; (add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox") +;; +;; to your .emacs + +(defgroup mymail () + "Command to visit a folder build on-the-fly with mymail" + :version "0.9.5") + +(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 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-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) + + (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) ",")) + ))) - ;; (interactive "smymail search: ") + ) - (interactive (list (read-string "mymail search: " nil 'mymail-history))) + (while (get-file-buffer (setq mbox-name (format "/tmp/mymail-vm-%d.mbox" n))) + (setq n (+ n 1))) - (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") - ) + (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")) + ))