annotate lisp/net/mairix.el @ 109283:1fea8c5cd259

Font lock fix for batch mode (Bug#5719). * generic-x.el (bat-generic-mode): Fix regexp for command line switches (Bug#5719).
author Chong Yidong <cyd@stupidchicken.com>
date Sun, 27 Jun 2010 14:43:34 -0400
parents b86e6346b4a8
children cc035ccb9275 376148b31b5e
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
106815
1d1d5d9bd884 Add 2010 to copyright years.
Glenn Morris <rgm@gnu.org>
parents: 105813
diff changeset
3 ;; Copyright (C) 2008, 2009, 2010 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)
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101809
diff changeset
263 (with-current-buffer rmail-buffer
101809
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
264 (save-restriction
c47e321c9092 (rmail-buffer): Remove unneeded eval-when-compile.
Glenn Morris <rgm@gnu.org>
parents: 100908
diff changeset
265 ;; 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
266 (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
267 (mail-fetch-field field)))))
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
268
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
269 ;;; Gnus
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
270 (eval-when-compile
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
271 (defvar gnus-article-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
272 (autoload 'gnus-summary-toggle-header "gnus-sum")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
273 (autoload 'gnus-buffer-exists-p "gnus-util")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
274 (autoload 'message-field-value "message")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
275 (autoload 'gnus-group-read-ephemeral-group "gnus-group")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
276 (autoload 'gnus-alive-p "gnus-util"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
277
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
278 ;; Display function:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
279 (defun mairix-gnus-ephemeral-nndoc (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
280 "Create ephemeral nndoc group for reading mbox file FOLDER in Gnus."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
281 (unless (gnus-alive-p)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
282 (error "Gnus is not running"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
283 (gnus-group-read-ephemeral-group
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
284 ;; add randomness to group string to prevent Gnus from using a
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
285 ;; cached version
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
286 (format "mairix.%s" (number-to-string (random 10000)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
287 `(nndoc "mairix"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
288 (nndoc-address ,folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
289 (nndoc-article-type mbox))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
290
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
291 ;; Fetching mail header field:
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
292 (defun mairix-gnus-fetch-field (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
293 "Get mail header FIELD for current message using Gnus."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
294 (unless (gnus-alive-p)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
295 (error "Gnus is not running"))
105813
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101809
diff changeset
296 (unless (gnus-buffer-exists-p gnus-article-buffer)
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101809
diff changeset
297 (error "No article buffer available"))
df4934f25eef * textmodes/two-column.el (2C-split):
Stefan Monnier <monnier@iro.umontreal.ca>
parents: 101809
diff changeset
298 (with-current-buffer gnus-article-buffer
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
299 (gnus-summary-toggle-header 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
300 (message-field-value field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
301
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
302 ;;; VM
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
303 ;;; written by Ulrich Mueller
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
304
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
305 (eval-when-compile
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
306 (autoload 'vm-quit "vm-folder")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
307 (autoload 'vm-visit-folder "vm")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
308 (autoload 'vm-select-folder-buffer "vm-macro")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
309 (autoload 'vm-check-for-killed-summary "vm-misc")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
310 (autoload 'vm-get-header-contents "vm-summary")
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-error-if-folder-empty "vm-misc")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
313 (autoload 'vm-select-marked-or-prefixed-messages "vm-folder"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
314
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
315 ;; Display function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
316 (defun mairix-vm-display (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
317 "Display mbox file FOLDER with VM."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
318 (require 'vm)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
319 ;; check if folder is already open and if so, kill it
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
320 (let ((buf (get-file-buffer folder)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
321 (when buf
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
322 (set-buffer buf)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
323 (set-buffer-modified-p nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
324 (condition-case nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
325 (vm-quit t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
326 (error nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
327 (kill-buffer buf)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
328 (vm-visit-folder folder t))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
329
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
330 ;; Fetching mail header field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
331 (defun mairix-vm-fetch-field (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
332 "Get mail header FIELD for current message using VM."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
333 (save-excursion
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
334 (vm-select-folder-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
335 (vm-check-for-killed-summary)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
336 (vm-error-if-folder-empty)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
337 (vm-get-header-contents
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
338 (car (vm-select-marked-or-prefixed-messages 1)) field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
339
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
340 ;;;; Main interactive functions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
341
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
342 (defun mairix-search (search threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
343 "Call Mairix with SEARCH.
106855
b86e6346b4a8 * net/mairix.el (mairix-widget-send-query): Send -1 instead of nil
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
344 If THREADS is non-nil, also display whole threads of found
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
345 messages. Results will be put into the default search file."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
346 (interactive
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
347 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
348 (read-string "Query: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
349 (y-or-n-p "Include threads? ")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
350 (when (mairix-call-mairix
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
351 (split-string search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
352 nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
353 threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
354 (mairix-show-folder mairix-search-file)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
355
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
356 (defun mairix-use-saved-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
357 "Use a saved search for querying Mairix."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
358 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
359 (let* ((completions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
360 (mapcar (lambda (el) (list (car el))) mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
361 (search (completing-read "Name of search: " completions))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
362 (query (assoc search mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
363 (folder (nth 2 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
364 (when (not folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
365 (setq folder mairix-search-file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
366 (when query
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
367 (mairix-call-mairix
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
368 (split-string (nth 1 query))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
369 folder
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
370 (car (last query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
371 (mairix-show-folder folder))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
372
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
373 (defun mairix-save-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
374 "Save the last search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
375 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
376 (let* ((name (read-string "Name of the search: "))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
377 (exist (assoc name mairix-saved-searches)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
378 (if (not exist)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
379 (add-to-list 'mairix-saved-searches
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
380 (append (list name) mairix-last-search))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
381 (when
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
382 (y-or-n-p
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
383 "There is already a search with this name. \
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
384 Overwrite existing entry? ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
385 (setcdr (assoc name mairix-saved-searches) mairix-last-search))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
386 (mairix-select-save))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
387
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
388 (defun mairix-edit-saved-searches-customize ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
389 "Edit the list of saved searches in a customization buffer."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
390 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
391 (custom-buffer-create (list (list 'mairix-saved-searches 'custom-variable))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
392 "*Customize Mairix Query*"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
393 (concat "\n\n" (make-string 65 ?=)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
394 "\nYou can now customize your saved Mairix searches by modifying\n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
395 the variable mairix-saved-searches. Don't forget to save your\nchanges \
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
396 in your .emacs by pressing 'Save for Future Sessions'.\n"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
397 (make-string 65 ?=) "\n")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
398
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
399 (autoload 'mail-strip-quoted-names "mail-utils")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
400 (defun mairix-search-from-this-article (threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
401 "Search messages from sender of the current article.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
402 This is effectively a shortcut for calling `mairix-search' with
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
403 f:current_from. If prefix THREADS is non-nil, include whole
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
404 threads."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
405 (interactive "P")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
406 (let ((get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
407 (cadr (assq mairix-mail-program mairix-get-mail-header-functions))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
408 (if get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
409 (mairix-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
410 (format "f:%s"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
411 (mail-strip-quoted-names
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
412 (funcall get-mail-header "from")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
413 threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
414 (error "No function for obtaining mail header specified"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
415
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
416 (defun mairix-search-thread-this-article ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
417 "Search thread for the current article.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
418 This is effectively a shortcut for calling `mairix-search'
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
419 with m:msgid of the current article and enabled threads."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
420 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
421 (let ((get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
422 (cadr (assq mairix-mail-program mairix-get-mail-header-functions)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
423 mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
424 (unless get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
425 (error "No function for obtaining mail header specified"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
426 (setq mid (funcall get-mail-header "message-id"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
427 (while (string-match "[<>]" mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
428 (setq mid (replace-match "" t t mid)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
429 ;; mairix somehow does not like '$' in message-id
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
430 (when (string-match "\\$" mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
431 (setq mid (concat mid "=")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
432 (while (string-match "\\$" mid)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
433 (setq mid (replace-match "=," t t mid)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
434 (mairix-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
435 (format "m:%s" mid) t)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
436
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
437 (defun mairix-widget-search-based-on-article ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
438 "Create mairix query based on current article using widgets."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
439 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
440 (mairix-widget-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
441 (mairix-widget-get-values)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
442
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
443 (defun mairix-edit-saved-searches ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
444 "Edit current mairix searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
445 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
446 (switch-to-buffer mairix-saved-searches-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
447 (erase-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
448 (setq mairix-searches-changed nil)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
449 (mairix-build-search-list)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
450 (mairix-searches-mode)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
451 (hl-line-mode))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
452
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
453 (defvar mairix-widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
454
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
455 (defun mairix-widget-search (&optional mvalues)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
456 "Create mairix query interactively using graphical widgets.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
457 MVALUES may contain values from current article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
458 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
459 ;; Select window for mairix customization
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
460 (funcall mairix-widget-select-window-function)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
461 ;; generate widgets
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
462 (mairix-widget-create-query mvalues)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
463 ;; generate Buttons
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
464 (widget-create 'push-button
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
465 :notify
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
466 (lambda (&rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
467 (mairix-widget-send-query mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
468 "Send Query")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
469 (widget-insert " ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
470 (widget-create 'push-button
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
471 :notify
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
472 (lambda (&rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
473 (mairix-widget-save-search mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
474 "Save search")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
475 (widget-insert " ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
476 (widget-create 'push-button
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
477 :notify (lambda (&rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
478 (kill-buffer mairix-customize-query-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
479 "Cancel")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
480 (use-local-map widget-keymap)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
481 (widget-setup)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
482 (goto-char (point-min)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
483
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
484 (defun mairix-update-database ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
485 "Call mairix for updating the database for SERVERS.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
486 Mairix will be called asynchronously unless
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
487 `mairix-synchronous-update' is t. Mairix will be called with
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
488 `mairix-update-options'."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
489 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
490 (let ((commandsplit (split-string mairix-command))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
491 args)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
492 (if mairix-synchronous-update
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
493 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
494 (setq args (append (list (car commandsplit) nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
495 (get-buffer-create mairix-output-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
496 nil)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
497 (if (> (length commandsplit) 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
498 (setq args (append args
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
499 (cdr commandsplit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
500 mairix-update-options))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
501 (setq args (append args mairix-update-options)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
502 (apply 'call-process args))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
503 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
504 (message "Updating mairix database...")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
505 (setq args (append (list "mairixupdate" (get-buffer-create mairix-output-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
506 (car commandsplit))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
507 (if (> (length commandsplit) 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
508 (setq args (append args (cdr commandsplit) mairix-update-options))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
509 (setq args (append args mairix-update-options)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
510 (set-process-sentinel
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
511 (apply 'start-process args)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
512 'mairix-sentinel-mairix-update-finished)))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
513
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
514
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
515 ;;;; Helper functions
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
516
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
517 (defun mairix-show-folder (folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
518 "Display mail FOLDER with mail program.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
519 The mail program is given by `mairix-mail-program'."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
520 (let ((display-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
521 (cadr (assq mairix-mail-program mairix-display-functions))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
522 (if display-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
523 (funcall display-function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
524 (concat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
525 (file-name-as-directory
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
526 (expand-file-name mairix-file-path))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
527 folder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
528 (error "No mail program set"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
529
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
530 (defun mairix-call-mairix (query file threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
531 "Call Mairix with QUERY and output FILE.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
532 If FILE is nil, use default. If THREADS is non-nil, also return
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
533 whole threads. Function returns t if messages were found."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
534 (let* ((commandsplit (split-string mairix-command))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
535 (args (cons (car commandsplit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
536 `(nil ,(get-buffer-create mairix-output-buffer) nil)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
537 rval)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
538 (with-current-buffer mairix-output-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
539 (erase-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
540 (when (> (length commandsplit) 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
541 (setq args (append args (cdr commandsplit))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
542 (when threads
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
543 (setq args (append args '("-t"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
544 (when (stringp query)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
545 (setq query (split-string query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
546 (setq mairix-last-search (list (mapconcat 'identity query " ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
547 file threads))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
548 (when (not file)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
549 (setq file mairix-search-file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
550 (setq file
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
551 (concat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
552 (file-name-as-directory
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
553 (expand-file-name
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
554 mairix-file-path))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
555 file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
556 (setq rval
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
557 (apply 'call-process
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
558 (append args (list "-o" file) query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
559 (if (zerop rval)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
560 (with-current-buffer mairix-output-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
561 (goto-char (point-min))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
562 (re-search-forward "^Matched.*messages")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
563 (message (match-string 0)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
564 (if (and (= rval 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
565 (with-current-buffer mairix-output-buffer
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
566 (goto-char (point-min))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
567 (looking-at "^Matched 0 messages")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
568 (message "No messages found")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
569 (error "Error running Mairix. See buffer %s for details"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
570 mairix-output-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
571 (zerop rval)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
572
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
573 (defun mairix-replace-illegal-chars (header)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
574 "Replace illegal characters in HEADER for mairix query."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
575 (when header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
576 (while (string-match "[^-.@/,& [:alnum:]]" header)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
577 (setq header (replace-match "" t t header)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
578 (while (string-match "[& ]" 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 header))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
581
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
582 (defun mairix-sentinel-mairix-update-finished (proc status)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
583 "Sentinel for mairix update process PROC with STATUS."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
584 (if (equal status "finished\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
585 (message "Updating mairix database... done")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
586 (error "There was an error updating the mairix database. \
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
587 See %s for details" mairix-output-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
588
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
589
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
590 ;;;; Widget stuff
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
591
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
592
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
593
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
594 (defun mairix-widget-send-query (widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
595 "Send query from WIDGETS to mairix binary."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
596 (mairix-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
597 (mairix-widget-make-query-from-widgets widgets)
106855
b86e6346b4a8 * net/mairix.el (mairix-widget-send-query): Send -1 instead of nil
Chong Yidong <cyd@stupidchicken.com>
parents: 106815
diff changeset
598 (if (widget-value (cadr (assoc "Threads" widgets))) t))
97093
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
599 (kill-buffer mairix-customize-query-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
600
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
601 (defun mairix-widget-save-search (widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
602 "Save search based on WIDGETS for future use."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
603 (let ((mairix-last-search
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
604 `( ,(mairix-widget-make-query-from-widgets widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
605 nil
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
606 ,(widget-value (cadr (assoc "Threads" widgets))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
607 (mairix-save-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
608 (kill-buffer mairix-customize-query-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
609
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
610 (defun mairix-widget-make-query-from-widgets (widgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
611 "Create mairix query from widget values WIDGETS."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
612 (let (query temp flag)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
613 ;; first we do the editable fields
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
614 (dolist (cur mairix-widget-fields-list)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
615 ;; See if checkbox is checked
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
616 (when (widget-value
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
617 (cadr (assoc (concat "c" (car (cddr cur))) widgets)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
618 ;; create query for the field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
619 (push
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
620 (concat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
621 (nth 1 cur)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
622 ":"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
623 (mairix-replace-illegal-chars
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
624 (widget-value
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
625 (cadr (assoc (concat "e" (car (cddr cur))) widgets)))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
626 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
627 ;; Flags
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
628 (when (member 'flags mairix-widget-other)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
629 (setq flag
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
630 (mapconcat
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
631 (function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
632 (lambda (flag)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
633 (setq temp
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
634 (widget-value (cadr (assoc (car flag) mairix-widgets))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
635 (if (string= "yes" temp)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
636 (cadr flag)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
637 (if (string= "no" temp)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
638 (concat "-" (cadr flag))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
639 '(("seen" "s") ("replied" "r") ("flagged" "f")) ""))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
640 (when (not (zerop (length flag)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
641 (push (concat "F:" flag) query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
642 ;; return query string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
643 (mapconcat 'identity query " ")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
644
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
645 (defun mairix-widget-create-query (&optional values)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
646 "Create widgets for creating mairix queries.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
647 Fill in VALUES if based on an article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
648 (let (allwidgets)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
649 (when (get-buffer mairix-customize-query-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
650 (kill-buffer mairix-customize-query-buffer))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
651 (switch-to-buffer mairix-customize-query-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
652 (kill-all-local-variables)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
653 (erase-buffer)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
654 (widget-insert
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
655 "Specify your query for Mairix (check boxes for activating fields):\n\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
656 (widget-insert
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
657 "(Whitespaces will be converted to ',' (i.e. AND). Use '/' for OR.)\n\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
658 (setq mairix-widgets (mairix-widget-build-editable-fields values))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
659 (when (member 'flags mairix-widget-other)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
660 (widget-insert "\nFlags:\n Seen: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
661 (mairix-widget-add "seen"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
662 'menu-choice
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
663 :value "ignore"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
664 '(item "yes") '(item "no") '(item "ignore"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
665 (widget-insert " Replied: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
666 (mairix-widget-add "replied"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
667 'menu-choice
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
668 :value "ignore"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
669 '(item "yes") '(item "no") '(item "ignore"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
670 (widget-insert " Ticked: ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
671 (mairix-widget-add "flagged"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
672 'menu-choice
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
673 :value "ignore"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
674 '(item "yes") '(item "no") '(item "ignore")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
675 (when (member 'threads mairix-widget-other)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
676 (widget-insert "\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
677 (mairix-widget-add "Threads" 'checkbox nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
678 (widget-insert " Show full threads\n\n")))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
679
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
680 (defun mairix-widget-build-editable-fields (values)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
681 "Build editable field widgets in `nnmairix-widget-fields-list'.
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
682 VALUES may contain values for editable fields from current article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
683 (let ((ret))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
684 (mapc
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
685 (function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
686 (lambda (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
687 (setq field (car (cddr field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
688 (setq
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
689 ret
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
690 (nconc
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
691 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
692 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
693 (concat "c" field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
694 (widget-create 'checkbox
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
695 :tag field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
696 :notify (lambda (widget &rest ignore)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
697 (mairix-widget-toggle-activate widget))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
698 nil)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
699 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
700 (list
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
701 (concat "e" field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
702 (widget-create 'editable-field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
703 :size 60
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
704 :format (concat " " field ":"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
705 (make-string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
706 (- 11 (length field)) ?\ )
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
707 "%v")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
708 :value (or (cadr (assoc field values)) ""))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
709 ret))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
710 (widget-insert "\n")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
711 ;; Deactivate editable field
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
712 (widget-apply (cadr (nth 1 ret)) :deactivate)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
713 mairix-widget-fields-list)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
714 ret))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
715
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
716 (defun mairix-widget-add (name &rest args)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
717 "Add a widget NAME with optional ARGS."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
718 (push
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
719 (list name
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
720 (apply 'widget-create args))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
721 mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
722
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
723 (defun mairix-widget-toggle-activate (widget)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
724 "Toggle activation status of WIDGET depending on checkbox value."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
725 (let ((field (widget-get widget :tag)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
726 (if (widget-value widget)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
727 (widget-apply
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
728 (cadr (assoc (concat "e" field) mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
729 :activate)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
730 (widget-apply
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
731 (cadr (assoc (concat "e" field) mairix-widgets))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
732 :deactivate)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
733 (widget-setup))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
734
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
735
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
736 ;;;; Major mode for editing/deleting/saving searches
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
737
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
738 (defvar mairix-searches-mode-map nil "'mairix-searches-mode' keymap.")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
739
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
740 ;; Keymap
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
741 (if (not mairix-searches-mode-map)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
742 (let ((map (make-keymap)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
743 (define-key map [(return)] 'mairix-select-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
744 (define-key map [(down)] 'mairix-next-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
745 (define-key map [(up)] 'mairix-previous-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
746 (define-key map [(right)] 'mairix-next-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
747 (define-key map [(left)] 'mairix-previous-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
748 (define-key map "\C-p" 'mairix-previous-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
749 (define-key map "\C-n" 'mairix-next-search)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
750 (define-key map [(q)] 'mairix-select-quit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
751 (define-key map [(e)] 'mairix-select-edit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
752 (define-key map [(d)] 'mairix-select-delete)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
753 (define-key map [(s)] 'mairix-select-save)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
754 (setq mairix-searches-mode-map map)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
755
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
756 (defvar mairix-searches-mode-font-lock-keywords)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
757
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
758 (defun mairix-searches-mode ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
759 "Major mode for editing mairix searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
760 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
761 (kill-all-local-variables)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
762 (setq major-mode 'mairix-searches-mode)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
763 (setq mode-name "mairix-searches")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
764 (set-syntax-table text-mode-syntax-table)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
765 (use-local-map mairix-searches-mode-map)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
766 (make-local-variable 'font-lock-defaults)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
767 (setq mairix-searches-mode-font-lock-keywords
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
768 (list (list "^\\([0-9]+\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
769 '(1 font-lock-constant-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
770 (list "^[0-9 ]+\\(Name:\\) \\(.*\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
771 '(1 font-lock-keyword-face) '(2 font-lock-string-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
772 (list "^[ ]+\\(Query:\\) \\(.*\\) , "
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
773 '(1 font-lock-keyword-face) '(2 font-lock-string-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
774 (list ", \\(Threads:\\) \\(.*\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
775 '(1 font-lock-keyword-face) '(2 font-lock-constant-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
776 (list "^\\([A-Z].*\\)$"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
777 '(1 font-lock-comment-face))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
778 (list "^[ ]+\\(Folder:\\) \\(.*\\)"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
779 '(1 font-lock-keyword-face) '(2 font-lock-string-face))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
780 (setq font-lock-defaults '(mairix-searches-mode-font-lock-keywords)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
781
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
782 (defun mairix-build-search-list ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
783 "Display saved searches in current buffer."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
784 (insert "These are your current saved mairix searches.\n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
785 You may use the following keys in this buffer: \n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
786 Return: execute search, e: edit, d: delete, s: save, q: quit\n\
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
787 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
788 (let ((num 0)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
789 (beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
790 current)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
791 (while (< num (length mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
792 (setq current (nth num mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
793 (setq num (1+ num))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
794 (mairix-insert-search-line num current)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
795 (insert "\n"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
796 (goto-char beg)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
797
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
798 (defun mairix-insert-search-line (number field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
799 "Insert new mairix query with NUMBER and values FIELD in buffer."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
800 (insert
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
801 (format "%d Name: %s\n Query: %s , Threads: %s\n Folder: %s\n"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
802 number
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
803 (car field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
804 (nth 1 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
805 (if (nth 3 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
806 "Yes"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
807 "No")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
808 (if (nth 2 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
809 (nth 2 field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
810 "Default"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
811
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
812 (defun mairix-select-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
813 "Call mairix with currently selected search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
814 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
815 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
816 (if (not (looking-at "[0-9]+ Name"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
817 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
818 (ding)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
819 (message "Put cursor on a line with a search name first"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
820 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
821 (let* ((query (nth
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
822 (1- (read (current-buffer)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
823 mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
824 (folder (nth 2 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
825 (when (not folder)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
826 (setq folder mairix-search-file))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
827 (mairix-call-mairix
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
828 (split-string (nth 1 query))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
829 folder
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
830 (car (last query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
831 (mairix-select-quit)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
832 (mairix-show-folder folder)))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
833
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
834 (defun mairix-next-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
835 "Jump to next search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
836 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
837 (if (search-forward-regexp "^[0-9]+"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
838 (point-max)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
839 t
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
840 2)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
841 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
842 (ding)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
843
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
844 (defun mairix-previous-search ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
845 "Jump to previous search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
846 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
847 (if (search-backward-regexp "^[0-9]+"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
848 (point-min)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
849 t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
850 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
851 (ding)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
852
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
853 (defun mairix-select-quit ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
854 "Quit mairix search mode."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
855 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
856 (when mairix-searches-changed
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
857 (mairix-select-save))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
858 (kill-buffer nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
859
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
860 (defun mairix-select-save ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
861 "Save current mairix searches."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
862 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
863 (when (y-or-n-p "Save mairix searches permanently in your .emacs? ")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
864 (customize-save-variable 'mairix-saved-searches mairix-saved-searches)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
865
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
866 (defun mairix-select-edit ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
867 "Edit currently selected mairix search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
868 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
869 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
870 (if (not (looking-at "[0-9]+ Name"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
871 (error "Put cursor on a line with a search name first")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
872 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
873 (let* ((number (1- (read (current-buffer))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
874 (query (nth number mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
875 (folder (nth 2 query))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
876 newname newquery newfolder threads)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
877 (backward-char)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
878 (setq newname (read-string "Name of the search: " (car query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
879 (when (assoc newname (remq (nth number mairix-saved-searches)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
880 mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
881 (error "This name does already exist"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
882 (setq newquery (read-string "Query: " (nth 1 query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
883 (setq threads (y-or-n-p "Include whole threads? "))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
884 (setq newfolder
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
885 (read-string "Mail folder (use empty string for default): "
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
886 folder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
887 (when (zerop (length newfolder))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
888 (setq newfolder nil))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
889 ;; set new values
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
890 (setcar (nth number mairix-saved-searches) newname)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
891 (setcdr (nth number mairix-saved-searches)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
892 (list newquery newfolder threads))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
893 (setq mairix-searches-changed t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
894 (let ((beg (point)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
895 (forward-line 3)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
896 (end-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
897 (delete-region beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
898 (mairix-insert-search-line (1+ number)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
899 (nth number mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
900 (goto-char beg))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
901
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
902 (defun mairix-select-delete ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
903 "Delete currently selected mairix search."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
904 (interactive)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
905 (if (not (looking-at "[0-9]+ Name"))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
906 (error "Put cursor on a line with a search name first")
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
907 (progn
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
908 (let* ((number (1- (read (current-buffer))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
909 (query (nth number mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
910 beg)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
911 (backward-char)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
912 (when (y-or-n-p (format "Delete search %s ? " (car query)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
913 (setq mairix-saved-searches
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
914 (delq query mairix-saved-searches))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
915 (setq mairix-searches-changed t)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
916 (setq beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
917 (forward-line 4)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
918 (beginning-of-line)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
919 (delete-region beg (point))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
920 (while (search-forward-regexp "^[0-9]+"
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
921 (point-max)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
922 t
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
923 1)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
924 (replace-match (number-to-string
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
925 (setq number (1+ number)))))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
926 (beginning-of-line))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
927
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
928 (defun mairix-widget-get-values ()
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
929 "Create values for editable fields from current article."
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
930 (let ((get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
931 (cadr (assq mairix-mail-program mairix-get-mail-header-functions))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
932 (if get-mail-header
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
933 (save-excursion
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
934 (save-restriction
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
935 (mapcar
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
936 (function
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
937 (lambda (field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
938 (list (car (cddr field))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
939 (if (car field)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
940 (mairix-replace-illegal-chars
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
941 (funcall get-mail-header (car field)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
942 nil))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
943 mairix-widget-fields-list)))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
944 (error "No function for obtaining mail header specified"))))
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
945
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
946
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
947 (provide 'mairix)
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
948
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
949 ;;; mairix.el ends here
1f61c691b0c0 New file.
Chong Yidong <cyd@stupidchicken.com>
parents:
diff changeset
950
97106
2abff4e5c97f Add arch tagline
Miles Bader <miles@gnu.org>
parents: 97093
diff changeset
951 ;; arch-tag: 787ab678-fcd5-4c50-9295-01c2ee5124a6