annotate lisp/net/mairix.el @ 103782:c5225871ee78

* net/tramp.el (tramp-set-file-uid-gid): Handle the case the remote user is root, on the local host. (tramp-local-host-p): Either the local user or the remote user must be root.
author Michael Albinus <michael.albinus@gmx.de>
date Wed, 08 Jul 2009 12:40:58 +0000
parents c47e321c9092
children df4934f25eef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
1 ;;; mairix.el --- Mairix interface for Emacs
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
2
100908
a9dc0e7c3f2b Add 2009 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 99522
diff changeset
3 ;; Copyright (C) 2008, 2009 Free Software Foundation, Inc.
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
4
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
5 ;; Author: David Engster <dengste@eml.cc>
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
6 ;; Keywords: mail searching
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
7
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
8 ;; This file is part of GNU Emacs.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
9
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
11 ;; it under the terms of the GNU General Public License as published by
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
12 ;; the Free Software Foundation, either version 3 of the License, or
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
13 ;; (at your option) any later version.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
14
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
15 ;; GNU Emacs is distributed in the hope that it will be useful,
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
18 ;; GNU General Public License for more details.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
19
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
20 ;; You should have received a copy of the GNU General Public License
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
22
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
23 ;;; Commentary:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
24
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
25 ;; This is an interface to the mairix mail search engine. Mairix is
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
26 ;; written by Richard Curnow and is licensed under the GPL. See the
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
27 ;; home page for details:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
28 ;;
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
29 ;; http://www.rpcurnow.force9.co.uk/mairix/
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
30 ;;
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
31 ;; Features of mairix.el:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
32 ;;
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
33 ;; * Query mairix with a search term.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
34 ;; * Currently supported Emacs mail programs: RMail, Gnus (mbox only),
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
35 ;; and VM.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
36 ;; * Generate search queries using graphical widgets.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
37 ;; * Generate search queries based on currently displayed mail.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
38 ;; * Save regularly used searches in your .emacs customize section.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
39 ;; * Major mode for viewing, editing and querying saved searches.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
40 ;; * Update mairix database.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
41 ;;
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
42 ;; Please note: There are currently no pre-defined key bindings, since
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
43 ;; I guess these would depend on the used mail program. See the docs
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
44 ;; for an overview of the provided interactive functions.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
45 ;;
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
46 ;; Attention Gnus users: If you use Gnus with maildir or nnml, you
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
47 ;; should use the native Gnus back end nnmairix.el instead, since it
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
48 ;; has more features and is better integrated with Gnus. This
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
49 ;; interface is essentially a stripped down version of nnmairix.el.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
50 ;;
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
51 ;; Currently, RMail, Gnus (with mbox files), and VM are supported as
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
52 ;; mail programs, but it is pretty easy to interface it with other
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
53 ;; ones as well. Please see the docs and the source for details.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
54 ;; In a nutshell: include your favourite mail program in
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
55 ;; `mairix-mail-program' and write functions for
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
56 ;; `mairix-display-functions' and `mairix-get-mail-header-functions'.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
57 ;; If you have written such functions for your Emacs mail program of
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
58 ;; choice, please let me know, so that I can eventually include them
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
59 ;; in future version of mairix.el.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
60
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
61 ;;; History:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
62
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
63 ;; 07/28/2008: version 0.2. Added VM interface, written by Ulrich
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
64 ;; Mueller.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
65
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
66 ;; 07/14/2008: Initial release
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
67
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
68 ;;; Code:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
69
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
70 (require 'widget)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
71 (require 'cus-edit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
72
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
73 (eval-when-compile
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
74 (require 'cl))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
75
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
76 ;;; Keymappings
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
77
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
78 ;; (currently none - please create them yourself)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
79
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
80 ;;; Customizable variables
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
81
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
82 (defgroup mairix nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
83 "Mairix interface for Emacs."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
84 :group 'mail)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
85
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
86 (defcustom mairix-file-path "~/"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
87 "Path where output files produced by Mairix should be stored."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
88 :type 'directory
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
89 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
90
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
91 (defcustom mairix-search-file "mairixsearch.mbox"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
92 "Name of the default file for storing the searches.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
93 Note that this will be prefixed by `mairix-file-path'."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
94 :type 'string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
95 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
96
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
97 (defcustom mairix-command "mairix"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
98 "Command for calling mairix.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
99 You can add further options here if you want to, but better use
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
100 `mairix-update-options' instead."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
101 :type 'string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
102 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
103
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
104 (defcustom mairix-output-buffer "*mairix output*"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
105 "Name of the buffer for the output of the mairix binary."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
106 :type 'string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
107 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
108
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
109 (defcustom mairix-customize-query-buffer "*mairix query*"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
110 "Name of the buffer for customizing a search query."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
111 :type 'string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
112 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
113
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
114 (defcustom mairix-saved-searches-buffer "*mairix searches*"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
115 "Name of the buffer for displaying saved searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
116 :type 'string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
117 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
118
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
119 (defcustom mairix-update-options '("-F" "-Q")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
120 "Options when calling mairix for updating the database.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
121 The default is '-F' and '-Q' for making updates faster. You
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
122 should call mairix without these options from time to
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
123 time (e.g. via cron job)."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
124 :type '(repeat string)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
125 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
126
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
127 (defcustom mairix-search-options '("-Q")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
128 "Options when calling mairix for searching.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
129 The default is '-Q' for making searching faster."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
130 :type '(repeat string)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
131 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
132
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
133 (defcustom mairix-synchronous-update nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
134 "Defines if Emacs should wait for the mairix database update."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
135 :type 'boolean
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
136 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
137
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
138 (defcustom mairix-saved-searches nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
139 "Saved mairix searches.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
140 The entries are: Name of the search, Mairix query string, Name of
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
141 the file (nil: use `mairix-search-file' as default), Search whole
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
142 threads (nil or t). Note that the file will be prefixed by
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
143 `mairix-file-path'."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
144 :type '(repeat (list (string :tag "Name")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
145 (string :tag "Query")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
146 (choice :tag "File"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
147 (const :tag "default")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
148 file)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
149 (boolean :tag "Threads")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
150 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
151
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
152 (defcustom mairix-mail-program 'rmail
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
153 "Mail program used to display search results.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
154 Currently RMail, Gnus (mbox), and VM are supported. If you use Gnus
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
155 with maildir, use nnmairix.el instead."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
156 :type '(choice (const :tag "RMail" rmail)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
157 (const :tag "Gnus mbox" gnus)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
158 (const :tag "VM" vm))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
159 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
160
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
161 (defcustom mairix-display-functions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
162 '((rmail mairix-rmail-display)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
163 (gnus mairix-gnus-ephemeral-nndoc)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
164 (vm mairix-vm-display))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
165 "Specifies which function should be called for displaying search results.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
166 This is an alist where each entry consists of a symbol from
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
167 `mairix-mail-program' and the corresponding function for
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
168 displaying the search results. The function will be called with
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
169 the mailbox file produced by mairix as the single argument."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
170 :type '(repeat (list (symbol :tag "Mail program")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
171 (function)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
172 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
173
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
174 (defcustom mairix-get-mail-header-functions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
175 '((rmail mairix-rmail-fetch-field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
176 (gnus mairix-gnus-fetch-field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
177 (vm mairix-vm-fetch-field))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
178 "Specifies function for obtaining a header field from the current mail.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
179 This is an alist where each entry consists of a symbol from
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
180 `mairix-mail-program' and the corresponding function for
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
181 obtaining a header field from the current displayed mail. The
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
182 function will be called with the mail header string as single
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
183 argument. You can use nil if you do not have such a function for
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
184 your mail program, but then searches based on the current mail
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
185 won't work."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
186 :type '(repeat (list (symbol :tag "Mail program")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
187 (choice :tag "Header function"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
188 (const :tag "none")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
189 function)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
190 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
191
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
192 (defcustom mairix-widget-select-window-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
193 (lambda () (select-window (get-largest-window)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
194 "Function for selecting the window for customizing the mairix query.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
195 The default chooses the largest window in the current frame."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
196 :type 'function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
197 :group 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
198
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
199 ;; Other variables
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
200
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
201 (defvar mairix-widget-fields-list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
202 '(("from" "f" "From") ("to" "t" "To") ("cc" "c" "Cc")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
203 ("subject" "s" "Subject") ("to" "tc" "To or Cc")
99522
01e562636dff Henry Weller <hweller0 at gmail.com> (tiny change)
Glenn Morris <rgm@gnu.org>
parents: 97106
diff changeset
204 ("from" "a" "Address") (nil "b" "Body") (nil "n" "Attachment")
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
205 ("Message-ID" "m" "Message ID") (nil "s" "Size") (nil "d" "Date"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
206 "Fields that should be editable during interactive query customization.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
207 Header, corresponding mairix command and description for editable
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
208 fields in interactive query customization. The header specifies
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
209 which header contents should be inserted into the editable field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
210 when creating a Mairix query based on the current message (can be
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
211 nil for disabling this).")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
212
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
213 (defvar mairix-widget-other
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
214 '(threads flags)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
215 "Other editable mairix commands when using customization widgets.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
216 Currently there are 'threads and 'flags.")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
217
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
218 ;;;; Internal variables
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
219
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
220 (defvar mairix-last-search nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
221 (defvar mairix-searches-changed nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
222
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
223 ;;;; Interface functions for Emacs mail programs
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
224
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
225 ;;; RMail
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
226
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
227 ;; Display function:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
228 (autoload 'rmail "rmail")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
229 (autoload 'rmail-summary-displayed "rmail")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
230 (autoload 'rmail-summary "rmailsum")
101809
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
231 (defvar rmail-buffer)
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
232
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
233 (defun mairix-rmail-display (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
234 "Display mbox file FOLDER with RMail."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
235 (let (show-summary)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
236 ;; If it exists, select existing RMail window
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
237 (when (and (boundp 'rmail-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
238 rmail-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
239 (set-buffer rmail-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
240 (when (get-buffer-window rmail-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
241 (select-window (get-buffer-window rmail-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
242 (setq show-summary (rmail-summary-displayed))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
243 ;; check if folder is already open and if so, kill it
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
244 (when (get-buffer (file-name-nondirectory folder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
245 (set-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
246 (get-buffer (file-name-nondirectory folder)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
247 (set-buffer-modified-p nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
248 (kill-buffer nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
249 (rmail folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
250 ;; Update summary if necessary
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
251 (when show-summary
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
252 (rmail-summary))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
253
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
254 ;; Fetching mail header field:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
255 (defun mairix-rmail-fetch-field (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
256 "Get mail header FIELD for current message using RMail."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
257 (unless (and (boundp 'rmail-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
258 rmail-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
259 (error "No RMail buffer available"))
101809
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
260 ;; At this point, we are in rmail mode, so the rmail funcs are loaded.
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
261 (if (fboundp 'rmail-get-header) ; Emacs 23
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
262 (rmail-get-header field)
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
263 (save-excursion
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
264 (set-buffer rmail-buffer)
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
265 (save-restriction
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
266 ;; Don't warn about this when compiling Emacs 23.
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
267 (with-no-warnings (rmail-narrow-to-non-pruned-header))
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
268 (mail-fetch-field field)))))
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
269
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
270 ;;; Gnus
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
271 (eval-when-compile
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
272 (defvar gnus-article-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
273 (autoload 'gnus-summary-toggle-header "gnus-sum")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
274 (autoload 'gnus-buffer-exists-p "gnus-util")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
275 (autoload 'message-field-value "message")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
276 (autoload 'gnus-group-read-ephemeral-group "gnus-group")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
277 (autoload 'gnus-alive-p "gnus-util"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
278
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
279 ;; Display function:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
280 (defun mairix-gnus-ephemeral-nndoc (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
281 "Create ephemeral nndoc group for reading mbox file FOLDER in Gnus."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
282 (unless (gnus-alive-p)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
283 (error "Gnus is not running"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
284 (gnus-group-read-ephemeral-group
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
285 ;; add randomness to group string to prevent Gnus from using a
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
286 ;; cached version
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
287 (format "mairix.%s" (number-to-string (random 10000)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
288 `(nndoc "mairix"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
289 (nndoc-address ,folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
290 (nndoc-article-type mbox))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
291
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
292 ;; Fetching mail header field:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
293 (defun mairix-gnus-fetch-field (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
294 "Get mail header FIELD for current message using Gnus."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
295 (unless (gnus-alive-p)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
296 (error "Gnus is not running"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
297 (save-excursion
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
298 (unless (gnus-buffer-exists-p gnus-article-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
299 (error "No article buffer available"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
300 (set-buffer gnus-article-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
301 (gnus-summary-toggle-header 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
302 (message-field-value field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
303
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
304 ;;; VM
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
305 ;;; written by Ulrich Mueller
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
306
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
307 (eval-when-compile
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
308 (autoload 'vm-quit "vm-folder")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
309 (autoload 'vm-visit-folder "vm")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
310 (autoload 'vm-select-folder-buffer "vm-macro")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
311 (autoload 'vm-check-for-killed-summary "vm-misc")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
312 (autoload 'vm-get-header-contents "vm-summary")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
313 (autoload 'vm-check-for-killed-summary "vm-misc")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
314 (autoload 'vm-error-if-folder-empty "vm-misc")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
315 (autoload 'vm-select-marked-or-prefixed-messages "vm-folder"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
316
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
317 ;; Display function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
318 (defun mairix-vm-display (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
319 "Display mbox file FOLDER with VM."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
320 (require 'vm)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
321 ;; check if folder is already open and if so, kill it
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
322 (let ((buf (get-file-buffer folder)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
323 (when buf
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
324 (set-buffer buf)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
325 (set-buffer-modified-p nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
326 (condition-case nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
327 (vm-quit t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
328 (error nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
329 (kill-buffer buf)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
330 (vm-visit-folder folder t))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
331
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
332 ;; Fetching mail header field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
333 (defun mairix-vm-fetch-field (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
334 "Get mail header FIELD for current message using VM."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
335 (save-excursion
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
336 (vm-select-folder-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
337 (vm-check-for-killed-summary)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
338 (vm-error-if-folder-empty)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
339 (vm-get-header-contents
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
340 (car (vm-select-marked-or-prefixed-messages 1)) field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
341
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
342 ;;;; Main interactive functions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
343
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
344 (defun mairix-search (search threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
345 "Call Mairix with SEARCH.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
346 If THREADS is t, also display whole threads of found
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
347 messages. Results will be put into the default search file."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
348 (interactive
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
349 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
350 (read-string "Query: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
351 (y-or-n-p "Include threads? ")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
352 (when (mairix-call-mairix
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
353 (split-string search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
354 nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
355 threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
356 (mairix-show-folder mairix-search-file)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
357
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
358 (defun mairix-use-saved-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
359 "Use a saved search for querying Mairix."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
360 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
361 (let* ((completions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
362 (mapcar (lambda (el) (list (car el))) mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
363 (search (completing-read "Name of search: " completions))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
364 (query (assoc search mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
365 (folder (nth 2 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
366 (when (not folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
367 (setq folder mairix-search-file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
368 (when query
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
369 (mairix-call-mairix
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
370 (split-string (nth 1 query))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
371 folder
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
372 (car (last query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
373 (mairix-show-folder folder))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
374
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
375 (defun mairix-save-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
376 "Save the last search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
377 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
378 (let* ((name (read-string "Name of the search: "))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
379 (exist (assoc name mairix-saved-searches)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
380 (if (not exist)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
381 (add-to-list 'mairix-saved-searches
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
382 (append (list name) mairix-last-search))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
383 (when
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
384 (y-or-n-p
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
385 "There is already a search with this name. \
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
386 Overwrite existing entry? ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
387 (setcdr (assoc name mairix-saved-searches) mairix-last-search))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
388 (mairix-select-save))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
389
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
390 (defun mairix-edit-saved-searches-customize ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
391 "Edit the list of saved searches in a customization buffer."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
392 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
393 (custom-buffer-create (list (list 'mairix-saved-searches 'custom-variable))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
394 "*Customize Mairix Query*"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
395 (concat "\n\n" (make-string 65 ?=)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
396 "\nYou can now customize your saved Mairix searches by modifying\n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
397 the variable mairix-saved-searches. Don't forget to save your\nchanges \
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
398 in your .emacs by pressing 'Save for Future Sessions'.\n"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
399 (make-string 65 ?=) "\n")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
400
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
401 (autoload 'mail-strip-quoted-names "mail-utils")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
402 (defun mairix-search-from-this-article (threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
403 "Search messages from sender of the current article.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
404 This is effectively a shortcut for calling `mairix-search' with
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
405 f:current_from. If prefix THREADS is non-nil, include whole
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
406 threads."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
407 (interactive "P")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
408 (let ((get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
409 (cadr (assq mairix-mail-program mairix-get-mail-header-functions))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
410 (if get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
411 (mairix-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
412 (format "f:%s"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
413 (mail-strip-quoted-names
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
414 (funcall get-mail-header "from")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
415 threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
416 (error "No function for obtaining mail header specified"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
417
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
418 (defun mairix-search-thread-this-article ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
419 "Search thread for the current article.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
420 This is effectively a shortcut for calling `mairix-search'
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
421 with m:msgid of the current article and enabled threads."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
422 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
423 (let ((get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
424 (cadr (assq mairix-mail-program mairix-get-mail-header-functions)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
425 mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
426 (unless get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
427 (error "No function for obtaining mail header specified"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
428 (setq mid (funcall get-mail-header "message-id"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
429 (while (string-match "[<>]" mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
430 (setq mid (replace-match "" t t mid)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
431 ;; mairix somehow does not like '$' in message-id
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
432 (when (string-match "\\$" mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
433 (setq mid (concat mid "=")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
434 (while (string-match "\\$" mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
435 (setq mid (replace-match "=," t t mid)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
436 (mairix-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
437 (format "m:%s" mid) t)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
438
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
439 (defun mairix-widget-search-based-on-article ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
440 "Create mairix query based on current article using widgets."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
441 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
442 (mairix-widget-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
443 (mairix-widget-get-values)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
444
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
445 (defun mairix-edit-saved-searches ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
446 "Edit current mairix searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
447 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
448 (switch-to-buffer mairix-saved-searches-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
449 (erase-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
450 (setq mairix-searches-changed nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
451 (mairix-build-search-list)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
452 (mairix-searches-mode)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
453 (hl-line-mode))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
454
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
455 (defvar mairix-widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
456
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
457 (defun mairix-widget-search (&optional mvalues)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
458 "Create mairix query interactively using graphical widgets.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
459 MVALUES may contain values from current article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
460 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
461 ;; Select window for mairix customization
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
462 (funcall mairix-widget-select-window-function)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
463 ;; generate widgets
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
464 (mairix-widget-create-query mvalues)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
465 ;; generate Buttons
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
466 (widget-create 'push-button
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
467 :notify
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
468 (lambda (&rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
469 (mairix-widget-send-query mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
470 "Send Query")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
471 (widget-insert " ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
472 (widget-create 'push-button
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
473 :notify
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
474 (lambda (&rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
475 (mairix-widget-save-search mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
476 "Save search")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
477 (widget-insert " ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
478 (widget-create 'push-button
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
479 :notify (lambda (&rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
480 (kill-buffer mairix-customize-query-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
481 "Cancel")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
482 (use-local-map widget-keymap)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
483 (widget-setup)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
484 (goto-char (point-min)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
485
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
486 (defun mairix-update-database ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
487 "Call mairix for updating the database for SERVERS.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
488 Mairix will be called asynchronously unless
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
489 `mairix-synchronous-update' is t. Mairix will be called with
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
490 `mairix-update-options'."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
491 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
492 (let ((commandsplit (split-string mairix-command))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
493 args)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
494 (if mairix-synchronous-update
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
495 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
496 (setq args (append (list (car commandsplit) nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
497 (get-buffer-create mairix-output-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
498 nil)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
499 (if (> (length commandsplit) 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
500 (setq args (append args
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
501 (cdr commandsplit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
502 mairix-update-options))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
503 (setq args (append args mairix-update-options)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
504 (apply 'call-process args))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
505 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
506 (message "Updating mairix database...")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
507 (setq args (append (list "mairixupdate" (get-buffer-create mairix-output-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
508 (car commandsplit))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
509 (if (> (length commandsplit) 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
510 (setq args (append args (cdr commandsplit) mairix-update-options))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
511 (setq args (append args mairix-update-options)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
512 (set-process-sentinel
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
513 (apply 'start-process args)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
514 'mairix-sentinel-mairix-update-finished)))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
515
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
516
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
517 ;;;; Helper functions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
518
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
519 (defun mairix-show-folder (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
520 "Display mail FOLDER with mail program.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
521 The mail program is given by `mairix-mail-program'."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
522 (let ((display-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
523 (cadr (assq mairix-mail-program mairix-display-functions))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
524 (if display-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
525 (funcall display-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
526 (concat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
527 (file-name-as-directory
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
528 (expand-file-name mairix-file-path))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
529 folder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
530 (error "No mail program set"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
531
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
532 (defun mairix-call-mairix (query file threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
533 "Call Mairix with QUERY and output FILE.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
534 If FILE is nil, use default. If THREADS is non-nil, also return
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
535 whole threads. Function returns t if messages were found."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
536 (let* ((commandsplit (split-string mairix-command))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
537 (args (cons (car commandsplit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
538 `(nil ,(get-buffer-create mairix-output-buffer) nil)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
539 rval)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
540 (with-current-buffer mairix-output-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
541 (erase-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
542 (when (> (length commandsplit) 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
543 (setq args (append args (cdr commandsplit))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
544 (when threads
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
545 (setq args (append args '("-t"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
546 (when (stringp query)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
547 (setq query (split-string query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
548 (setq mairix-last-search (list (mapconcat 'identity query " ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
549 file threads))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
550 (when (not file)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
551 (setq file mairix-search-file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
552 (setq file
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
553 (concat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
554 (file-name-as-directory
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
555 (expand-file-name
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
556 mairix-file-path))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
557 file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
558 (setq rval
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
559 (apply 'call-process
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
560 (append args (list "-o" file) query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
561 (if (zerop rval)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
562 (with-current-buffer mairix-output-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
563 (goto-char (point-min))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
564 (re-search-forward "^Matched.*messages")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
565 (message (match-string 0)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
566 (if (and (= rval 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
567 (with-current-buffer mairix-output-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
568 (goto-char (point-min))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
569 (looking-at "^Matched 0 messages")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
570 (message "No messages found")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
571 (error "Error running Mairix. See buffer %s for details"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
572 mairix-output-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
573 (zerop rval)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
574
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
575 (defun mairix-replace-illegal-chars (header)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
576 "Replace illegal characters in HEADER for mairix query."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
577 (when header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
578 (while (string-match "[^-.@/,& [:alnum:]]" header)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
579 (setq header (replace-match "" t t header)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
580 (while (string-match "[& ]" header)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
581 (setq header (replace-match "," t t header)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
582 header))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
583
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
584 (defun mairix-sentinel-mairix-update-finished (proc status)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
585 "Sentinel for mairix update process PROC with STATUS."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
586 (if (equal status "finished\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
587 (message "Updating mairix database... done")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
588 (error "There was an error updating the mairix database. \
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
589 See %s for details" mairix-output-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
590
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
591
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
592 ;;;; Widget stuff
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
593
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
594
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
595
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
596 (defun mairix-widget-send-query (widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
597 "Send query from WIDGETS to mairix binary."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
598 (mairix-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
599 (mairix-widget-make-query-from-widgets widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
600 (if (widget-value (cadr (assoc "Threads" widgets)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
601 t
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
602 -1))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
603 (kill-buffer mairix-customize-query-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
604
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
605 (defun mairix-widget-save-search (widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
606 "Save search based on WIDGETS for future use."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
607 (let ((mairix-last-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
608 `( ,(mairix-widget-make-query-from-widgets widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
609 nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
610 ,(widget-value (cadr (assoc "Threads" widgets))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
611 (mairix-save-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
612 (kill-buffer mairix-customize-query-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
613
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
614 (defun mairix-widget-make-query-from-widgets (widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
615 "Create mairix query from widget values WIDGETS."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
616 (let (query temp flag)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
617 ;; first we do the editable fields
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
618 (dolist (cur mairix-widget-fields-list)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
619 ;; See if checkbox is checked
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
620 (when (widget-value
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
621 (cadr (assoc (concat "c" (car (cddr cur))) widgets)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
622 ;; create query for the field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
623 (push
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
624 (concat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
625 (nth 1 cur)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
626 ":"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
627 (mairix-replace-illegal-chars
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
628 (widget-value
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
629 (cadr (assoc (concat "e" (car (cddr cur))) widgets)))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
630 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
631 ;; Flags
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
632 (when (member 'flags mairix-widget-other)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
633 (setq flag
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
634 (mapconcat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
635 (function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
636 (lambda (flag)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
637 (setq temp
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
638 (widget-value (cadr (assoc (car flag) mairix-widgets))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
639 (if (string= "yes" temp)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
640 (cadr flag)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
641 (if (string= "no" temp)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
642 (concat "-" (cadr flag))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
643 '(("seen" "s") ("replied" "r") ("flagged" "f")) ""))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
644 (when (not (zerop (length flag)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
645 (push (concat "F:" flag) query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
646 ;; return query string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
647 (mapconcat 'identity query " ")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
648
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
649 (defun mairix-widget-create-query (&optional values)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
650 "Create widgets for creating mairix queries.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
651 Fill in VALUES if based on an article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
652 (let (allwidgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
653 (when (get-buffer mairix-customize-query-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
654 (kill-buffer mairix-customize-query-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
655 (switch-to-buffer mairix-customize-query-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
656 (kill-all-local-variables)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
657 (erase-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
658 (widget-insert
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
659 "Specify your query for Mairix (check boxes for activating fields):\n\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
660 (widget-insert
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
661 "(Whitespaces will be converted to ',' (i.e. AND). Use '/' for OR.)\n\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
662 (setq mairix-widgets (mairix-widget-build-editable-fields values))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
663 (when (member 'flags mairix-widget-other)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
664 (widget-insert "\nFlags:\n Seen: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
665 (mairix-widget-add "seen"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
666 'menu-choice
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
667 :value "ignore"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
668 '(item "yes") '(item "no") '(item "ignore"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
669 (widget-insert " Replied: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
670 (mairix-widget-add "replied"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
671 'menu-choice
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
672 :value "ignore"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
673 '(item "yes") '(item "no") '(item "ignore"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
674 (widget-insert " Ticked: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
675 (mairix-widget-add "flagged"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
676 'menu-choice
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
677 :value "ignore"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
678 '(item "yes") '(item "no") '(item "ignore")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
679 (when (member 'threads mairix-widget-other)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
680 (widget-insert "\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
681 (mairix-widget-add "Threads" 'checkbox nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
682 (widget-insert " Show full threads\n\n")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
683
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
684 (defun mairix-widget-build-editable-fields (values)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
685 "Build editable field widgets in `nnmairix-widget-fields-list'.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
686 VALUES may contain values for editable fields from current article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
687 (let ((ret))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
688 (mapc
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
689 (function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
690 (lambda (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
691 (setq field (car (cddr field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
692 (setq
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
693 ret
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
694 (nconc
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
695 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
696 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
697 (concat "c" field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
698 (widget-create 'checkbox
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
699 :tag field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
700 :notify (lambda (widget &rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
701 (mairix-widget-toggle-activate widget))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
702 nil)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
703 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
704 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
705 (concat "e" field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
706 (widget-create 'editable-field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
707 :size 60
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
708 :format (concat " " field ":"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
709 (make-string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
710 (- 11 (length field)) ?\ )
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
711 "%v")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
712 :value (or (cadr (assoc field values)) ""))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
713 ret))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
714 (widget-insert "\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
715 ;; Deactivate editable field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
716 (widget-apply (cadr (nth 1 ret)) :deactivate)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
717 mairix-widget-fields-list)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
718 ret))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
719
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
720 (defun mairix-widget-add (name &rest args)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
721 "Add a widget NAME with optional ARGS."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
722 (push
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
723 (list name
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
724 (apply 'widget-create args))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
725 mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
726
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
727 (defun mairix-widget-toggle-activate (widget)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
728 "Toggle activation status of WIDGET depending on checkbox value."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
729 (let ((field (widget-get widget :tag)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
730 (if (widget-value widget)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
731 (widget-apply
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
732 (cadr (assoc (concat "e" field) mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
733 :activate)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
734 (widget-apply
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
735 (cadr (assoc (concat "e" field) mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
736 :deactivate)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
737 (widget-setup))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
738
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
739
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
740 ;;;; Major mode for editing/deleting/saving searches
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
741
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
742 (defvar mairix-searches-mode-map nil "'mairix-searches-mode' keymap.")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
743
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
744 ;; Keymap
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
745 (if (not mairix-searches-mode-map)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
746 (let ((map (make-keymap)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
747 (define-key map [(return)] 'mairix-select-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
748 (define-key map [(down)] 'mairix-next-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
749 (define-key map [(up)] 'mairix-previous-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
750 (define-key map [(right)] 'mairix-next-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
751 (define-key map [(left)] 'mairix-previous-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
752 (define-key map "\C-p" 'mairix-previous-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
753 (define-key map "\C-n" 'mairix-next-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
754 (define-key map [(q)] 'mairix-select-quit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
755 (define-key map [(e)] 'mairix-select-edit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
756 (define-key map [(d)] 'mairix-select-delete)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
757 (define-key map [(s)] 'mairix-select-save)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
758 (setq mairix-searches-mode-map map)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
759
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
760 (defvar mairix-searches-mode-font-lock-keywords)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
761
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
762 (defun mairix-searches-mode ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
763 "Major mode for editing mairix searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
764 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
765 (kill-all-local-variables)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
766 (setq major-mode 'mairix-searches-mode)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
767 (setq mode-name "mairix-searches")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
768 (set-syntax-table text-mode-syntax-table)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
769 (use-local-map mairix-searches-mode-map)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
770 (make-local-variable 'font-lock-defaults)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
771 (setq mairix-searches-mode-font-lock-keywords
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
772 (list (list "^\\([0-9]+\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
773 '(1 font-lock-constant-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
774 (list "^[0-9 ]+\\(Name:\\) \\(.*\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
775 '(1 font-lock-keyword-face) '(2 font-lock-string-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
776 (list "^[ ]+\\(Query:\\) \\(.*\\) , "
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
777 '(1 font-lock-keyword-face) '(2 font-lock-string-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
778 (list ", \\(Threads:\\) \\(.*\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
779 '(1 font-lock-keyword-face) '(2 font-lock-constant-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
780 (list "^\\([A-Z].*\\)$"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
781 '(1 font-lock-comment-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
782 (list "^[ ]+\\(Folder:\\) \\(.*\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
783 '(1 font-lock-keyword-face) '(2 font-lock-string-face))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
784 (setq font-lock-defaults '(mairix-searches-mode-font-lock-keywords)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
785
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
786 (defun mairix-build-search-list ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
787 "Display saved searches in current buffer."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
788 (insert "These are your current saved mairix searches.\n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
789 You may use the following keys in this buffer: \n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
790 Return: execute search, e: edit, d: delete, s: save, q: quit\n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
791 Use cursor keys or C-n,C-p to select next/previous search.\n\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
792 (let ((num 0)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
793 (beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
794 current)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
795 (while (< num (length mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
796 (setq current (nth num mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
797 (setq num (1+ num))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
798 (mairix-insert-search-line num current)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
799 (insert "\n"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
800 (goto-char beg)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
801
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
802 (defun mairix-insert-search-line (number field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
803 "Insert new mairix query with NUMBER and values FIELD in buffer."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
804 (insert
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
805 (format "%d Name: %s\n Query: %s , Threads: %s\n Folder: %s\n"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
806 number
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
807 (car field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
808 (nth 1 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
809 (if (nth 3 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
810 "Yes"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
811 "No")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
812 (if (nth 2 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
813 (nth 2 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
814 "Default"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
815
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
816 (defun mairix-select-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
817 "Call mairix with currently selected search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
818 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
819 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
820 (if (not (looking-at "[0-9]+ Name"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
821 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
822 (ding)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
823 (message "Put cursor on a line with a search name first"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
824 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
825 (let* ((query (nth
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
826 (1- (read (current-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
827 mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
828 (folder (nth 2 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
829 (when (not folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
830 (setq folder mairix-search-file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
831 (mairix-call-mairix
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
832 (split-string (nth 1 query))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
833 folder
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
834 (car (last query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
835 (mairix-select-quit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
836 (mairix-show-folder folder)))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
837
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
838 (defun mairix-next-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
839 "Jump to next search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
840 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
841 (if (search-forward-regexp "^[0-9]+"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
842 (point-max)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
843 t
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
844 2)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
845 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
846 (ding)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
847
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
848 (defun mairix-previous-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
849 "Jump to previous search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
850 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
851 (if (search-backward-regexp "^[0-9]+"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
852 (point-min)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
853 t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
854 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
855 (ding)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
856
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
857 (defun mairix-select-quit ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
858 "Quit mairix search mode."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
859 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
860 (when mairix-searches-changed
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
861 (mairix-select-save))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
862 (kill-buffer nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
863
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
864 (defun mairix-select-save ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
865 "Save current mairix searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
866 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
867 (when (y-or-n-p "Save mairix searches permanently in your .emacs? ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
868 (customize-save-variable 'mairix-saved-searches mairix-saved-searches)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
869
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
870 (defun mairix-select-edit ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
871 "Edit currently selected mairix search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
872 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
873 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
874 (if (not (looking-at "[0-9]+ Name"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
875 (error "Put cursor on a line with a search name first")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
876 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
877 (let* ((number (1- (read (current-buffer))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
878 (query (nth number mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
879 (folder (nth 2 query))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
880 newname newquery newfolder threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
881 (backward-char)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
882 (setq newname (read-string "Name of the search: " (car query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
883 (when (assoc newname (remq (nth number mairix-saved-searches)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
884 mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
885 (error "This name does already exist"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
886 (setq newquery (read-string "Query: " (nth 1 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
887 (setq threads (y-or-n-p "Include whole threads? "))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
888 (setq newfolder
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
889 (read-string "Mail folder (use empty string for default): "
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
890 folder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
891 (when (zerop (length newfolder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
892 (setq newfolder nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
893 ;; set new values
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
894 (setcar (nth number mairix-saved-searches) newname)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
895 (setcdr (nth number mairix-saved-searches)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
896 (list newquery newfolder threads))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
897 (setq mairix-searches-changed t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
898 (let ((beg (point)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
899 (forward-line 3)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
900 (end-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
901 (delete-region beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
902 (mairix-insert-search-line (1+ number)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
903 (nth number mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
904 (goto-char beg))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
905
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
906 (defun mairix-select-delete ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
907 "Delete currently selected mairix search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
908 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
909 (if (not (looking-at "[0-9]+ Name"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
910 (error "Put cursor on a line with a search name first")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
911 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
912 (let* ((number (1- (read (current-buffer))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
913 (query (nth number mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
914 beg)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
915 (backward-char)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
916 (when (y-or-n-p (format "Delete search %s ? " (car query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
917 (setq mairix-saved-searches
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
918 (delq query mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
919 (setq mairix-searches-changed t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
920 (setq beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
921 (forward-line 4)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
922 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
923 (delete-region beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
924 (while (search-forward-regexp "^[0-9]+"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
925 (point-max)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
926 t
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
927 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
928 (replace-match (number-to-string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
929 (setq number (1+ number)))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
930 (beginning-of-line))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
931
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
932 (defun mairix-widget-get-values ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
933 "Create values for editable fields from current article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
934 (let ((get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
935 (cadr (assq mairix-mail-program mairix-get-mail-header-functions))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
936 (if get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
937 (save-excursion
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
938 (save-restriction
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
939 (mapcar
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
940 (function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
941 (lambda (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
942 (list (car (cddr field))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
943 (if (car field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
944 (mairix-replace-illegal-chars
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
945 (funcall get-mail-header (car field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
946 nil))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
947 mairix-widget-fields-list)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
948 (error "No function for obtaining mail header specified"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
949
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
950
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
951 (provide 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
952
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
953 ;;; mairix.el ends here
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
954
97106
2abff4e5c97f Add arch tagline
Miles Bader <miles@gnu.org>
parents: 97093
diff changeset
955 ;; arch-tag: 787ab678-fcd5-4c50-9295-01c2ee5124a6