Prompt cosmetics.
[mymail.git] / mymail-vm.el
1
2 ;; Copyright (c) 2013 Francois Fleuret
3 ;; Written by Francois Fleuret <francois@fleuret.org>
4 ;;
5 ;; This file is part of mymail.
6 ;;
7 ;; mymail is free software: you can redistribute it and/or modify it
8 ;; under the terms of the GNU General Public License version 3 as
9 ;; published by the Free Software Foundation.
10 ;;
11 ;; mymail is distributed in the hope that it will be useful, but
12 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
14 ;; General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with mymail.  If not, see <http://www.gnu.org/licenses/>.
18
19 (add-to-list 'recentf-exclude "/tmp/mymail-vm-.*\.mbox")
20
21 (defcustom mymail/default-search-request ""
22   "Default request to add to any search"
23   :type 'string)
24
25 (defun mymail/vm-visit-folder (param)
26   "Read a comma-separated list of search requests for mymail,
27 create a temporary mbox with the resulting mails, and open it in
28 vm with `vm-visit-folder'.
29
30 The string `mymail/default-search-request' is automatically
31 concatenated to the provided request, except if the request is
32 prefaced with \\."
33   (interactive
34    (list (read-string "mymail-vm: " nil 'mymail-vm-history)))
35
36   (let ((n 1)
37         (mbox-name nil)
38
39         (search-args
40
41          (apply 'nconc
42           (mapcar
43            (lambda (searche-request)
44              (if (not (string= searche-request ""))
45                  (list "-s" searche-request)))
46            (if (string= (substring param 0 1) "\\")
47                (split-string (substring param 1 nil))
48              (split-string (concat param "," mymail/default-search-request) ","))
49            )))
50
51         )
52
53     (while (get-file-buffer (setq mbox-name (format "/tmp/mymail-vm-%d.mbox" n)))
54       (setq n (+ n 1)))
55
56     (if (= (apply 'call-process
57                   (nconc (list "mymail" nil nil nil
58                                "--output" mbox-name
59                                "--default-search" "p")
60                          search-args))
61            0)
62         (vm-visit-folder mbox-name t)
63       (message "mymail failed"))
64   ))