Moved some of the non-global variables into main().
[mymail.git] / mymail-vm.el
index 03b52cc..7b2e6ea 100644 (file)
 ;; You should have received a copy of the GNU General Public License
 ;; along with mymail.  If not, see <http://www.gnu.org/licenses/>.
 
+(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)))
+  (interactive
+   (list (read-string "mymail: " nil 'mymail-vm-history)))
+
+  (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) ",")
+               " ")))
+
+    (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")
-  )
+    (shell-command (concat "mymail --quiet --output " mbox-name " " args))
+    (vm-visit-folder mbox-name t)
+  ))