0
|
1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs.
|
|
2
|
70
|
3 ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994
|
|
4 ;;; Free Software Foundation, Inc.
|
0
|
5
|
|
6 ;; Maintainer: FSF
|
|
7 ;; Keywords: mail
|
|
8
|
|
9 ;; This file is part of XEmacs.
|
|
10
|
|
11 ;; XEmacs is free software; you can redistribute it and/or modify it
|
|
12 ;; under the terms of the GNU General Public License as published by
|
|
13 ;; the Free Software Foundation; either version 2, or (at your option)
|
|
14 ;; any later version.
|
|
15
|
|
16 ;; XEmacs is distributed in the hope that it will be useful, but
|
|
17 ;; WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
19 ;; General Public License for more details.
|
|
20
|
|
21 ;; You should have received a copy of the GNU General Public License
|
70
|
22 ;; along with XEmacs; see the file COPYING. If not, write to the
|
|
23 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330,
|
|
24 ;; Boston, MA 02111-1307, USA.
|
0
|
25
|
|
26 ;;; Code:
|
|
27
|
|
28 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
|
|
29 ;; New features include attribute and keyword support, message
|
|
30 ;; selection by dispatch table, summary by attributes and keywords,
|
|
31 ;; expunging by dispatch table, sticky options for file commands.
|
|
32
|
|
33 ;; Extended by Bob Weiner of Motorola
|
|
34 ;; New features include: rmail and rmail-summary buffers remain
|
|
35 ;; synchronized and key bindings basically operate the same way in both
|
|
36 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
|
|
37 ;; variable, and a bury rmail buffer (wipe) command.
|
|
38 ;;
|
|
39
|
|
40 (require 'mail-utils)
|
|
41
|
|
42 ;; For Emacs V18 compatibility
|
|
43 (and (not (fboundp 'user-original-login-name))
|
|
44 (fboundp 'user-real-login-name)
|
|
45 (defalias 'user-original-login-name 'user-real-login-name))
|
|
46 (and (not (fboundp 'buffer-disable-undo))
|
|
47 (fboundp 'buffer-flush-undo)
|
|
48 (defalias 'buffer-disable-undo 'buffer-flush-undo))
|
|
49
|
|
50 ; These variables now declared in paths.el.
|
|
51 ;(defvar rmail-spool-directory "/usr/spool/mail/"
|
|
52 ; "This is the name of the directory used by the system mailer for\n\
|
|
53 ;delivering new mail. It's name should end with a slash.")
|
|
54 ;(defvar rmail-file-name
|
|
55 ; (expand-file-name "~/RMAIL")
|
|
56 ; "")
|
|
57
|
|
58 ;;;###autoload
|
|
59 (defvar rmail-dont-reply-to-names nil "\
|
|
60 *A regexp specifying names to prune of reply to messages.
|
|
61 A value of nil means exclude your own name only.")
|
|
62
|
|
63 ;;;###autoload
|
|
64 (defvar rmail-default-dont-reply-to-names "info-" "\
|
|
65 A regular expression specifying part of the value of the default value of
|
|
66 the variable `rmail-dont-reply-to-names', for when the user does not set
|
|
67 `rmail-dont-reply-to-names' explicitly. (The other part of the default
|
|
68 value is the user's name.)
|
|
69 It is useful to set this variable in the site customization file.")
|
|
70
|
|
71 ;;; XEmacs change: moved rmail-ignored-headers to sendmail.el for the
|
|
72 ;;; benefit of automatically generated autoloads.
|
|
73 ;;;minimalist FSF version
|
70
|
74 ;(defvar rmail-ignored-headers "^via:\\|^mail-from:\\|^origin:\\|^status:\\|^received:\\|^message-id:\\|^summary-line:" "\
|
0
|
75 ;*Gubbish headers one would rather not see.")
|
|
76
|
|
77 ;;;###autoload
|
|
78 (defvar rmail-delete-after-output nil "\
|
|
79 *Non-nil means automatically delete a message that is copied to a file.")
|
|
80
|
|
81 ;;;###autoload
|
|
82 (defvar rmail-primary-inbox-list nil "\
|
|
83 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
|
|
84 `nil' means the default, which is (\"/usr/spool/mail/$USER\")
|
|
85 \(the name varies depending on the operating system,
|
|
86 and the value of the environment variable MAIL overrides it).")
|
|
87
|
|
88 ;;;###autoload
|
|
89 (defvar rmail-mail-new-frame nil
|
|
90 "*Non-nil means Rmail makes a new frame for composing outgoing mail.")
|
|
91
|
|
92 ;;;###autoload
|
|
93 (defvar rmail-retry-setup-hook nil
|
|
94 "Hook that `rmail-retry-failure' uses in place of `mail-setup-hook'.")
|
|
95
|
|
96 ;; These may be altered by site-init.el to match the format of mmdf files
|
|
97 ;; delimiting used on a given host (delim1 and delim2 from the config
|
|
98 ;; files).
|
|
99
|
|
100 (defvar mmdf-delim1 "^\001\001\001\001\n"
|
|
101 "Regexp marking the start of an mmdf message")
|
|
102 (defvar mmdf-delim2 "^\001\001\001\001\n"
|
|
103 "Regexp marking the end of an mmdf message")
|
|
104
|
|
105 (defvar rmail-message-filter nil
|
|
106 "If non nil, is a filter function for new headers in RMAIL.
|
|
107 Called with region narrowed to unformatted header.")
|
|
108
|
|
109 (defvar rmail-reply-prefix "Re: "
|
|
110 "String to prepend to Subject line when replying to a message.")
|
|
111
|
|
112 (defvar rmail-mode-map nil)
|
|
113
|
|
114 (defvar rmail-inbox-list nil)
|
|
115 (defvar rmail-keywords nil)
|
|
116
|
|
117 ;; Message counters and markers. Deleted flags.
|
|
118
|
|
119 (defvar rmail-current-message nil)
|
|
120 (defvar rmail-total-messages nil)
|
|
121 (defvar rmail-message-vector nil)
|
|
122 (defvar rmail-deleted-vector nil)
|
|
123
|
|
124 ;; These are used by autoloaded rmail-summary.
|
|
125
|
|
126 (defvar rmail-summary-buffer nil)
|
|
127 (defvar rmail-summary-vector nil)
|
|
128
|
|
129 ;; `Sticky' default variables.
|
|
130
|
|
131 ;; Last individual label specified to a or k.
|
|
132 (defvar rmail-last-label nil)
|
|
133 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
|
|
134 (defvar rmail-last-multi-labels nil)
|
|
135 ;;;###autoload
|
|
136 (defvar rmail-last-file nil)
|
|
137 (defvar rmail-last-regexp nil)
|
|
138 (defvar rmail-last-rmail-file (expand-file-name "~/XMAIL"))
|
|
139
|
|
140 ;;; Regexp matching the delimiter of messages in UNIX mail format
|
|
141 ;;; (UNIX From lines), minus the initial ^. Note that if you change
|
|
142 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
|
|
143 ;;; that knows the exact ordering of the \\( \\) subexpressions.
|
|
144 (defvar rmail-unix-mail-delimiter
|
|
145 (let ((time-zone-regexp
|
|
146 (concat "\\([A-Z]?[A-Z][A-Z][A-Z]\\( DST\\)?"
|
|
147 "\\|[-+]?[0-9][0-9][0-9][0-9]"
|
|
148 "\\|"
|
|
149 "\\) *")))
|
|
150 (concat
|
|
151 "From "
|
|
152
|
|
153 ;; Username, perhaps with a quoted section that can contain spaces.
|
|
154 "\\("
|
|
155 "[^ \n]*"
|
|
156 "\\(\\|\".*\"[^ \n]*\\)"
|
|
157 "\\) ?"
|
|
158
|
|
159 ;; The time the message was sent.
|
|
160 "\\([^ \n]*\\) *" ; day of the week
|
|
161 "\\([^ ]*\\) *" ; month
|
|
162 "\\([0-9]*\\) *" ; day of month
|
|
163 "\\([0-9:]*\\) *" ; time of day
|
|
164
|
|
165 ;; Perhaps a time zone, specified by an abbreviation, or by a
|
|
166 ;; numeric offset.
|
|
167 time-zone-regexp
|
|
168
|
|
169 ;; The year.
|
|
170 " [0-9][0-9]\\([0-9]*\\) *"
|
|
171
|
|
172 ;; On some systems the time zone can appear after the year, too.
|
|
173 time-zone-regexp
|
|
174
|
|
175 ;; I'm not sure what this is.
|
|
176 "\\(remote from [^\n]*\\)?"
|
|
177
|
|
178 "\n"))
|
|
179 )
|
|
180
|
|
181 ;; Perform BODY in the summary buffer
|
|
182 ;; in such a way that its cursor is properly updated in its own window.
|
|
183 (defmacro rmail-select-summary (&rest body)
|
|
184 (` (progn (if (rmail-summary-displayed)
|
|
185 (let ((window (selected-window)))
|
|
186 (save-excursion
|
|
187 (unwind-protect
|
|
188 (progn
|
|
189 (pop-to-buffer rmail-summary-buffer)
|
|
190 (,@ body))
|
|
191 (select-window window))))
|
|
192 (save-excursion
|
|
193 (set-buffer rmail-summary-buffer)
|
|
194 (progn (,@ body))))
|
|
195 (rmail-maybe-display-summary))))
|
|
196
|
|
197 ;;;; *** Rmail Mode ***
|
|
198
|
|
199 ;;;###autoload
|
|
200 (defun rmail (&optional file-name-arg)
|
|
201 "Read and edit incoming mail.
|
|
202 Moves messages into file named by `rmail-file-name' (a babyl format file)
|
|
203 and edits that file in RMAIL Mode.
|
|
204 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
|
|
205
|
|
206 May be called with filename as argument; then performs rmail editing on
|
|
207 that file, but does not copy any new mail into the file."
|
|
208 (interactive (if current-prefix-arg
|
|
209 (list (read-file-name "Run rmail on RMAIL file: "
|
|
210 nil nil t))))
|
|
211 (if (string-match "XEmacs" emacs-version)
|
2
|
212 (require 'rmail-xemacs))
|
0
|
213 (or rmail-last-file
|
|
214 (setq rmail-last-file (expand-file-name "~/xmail")))
|
|
215 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
|
|
216 (existed (get-file-buffer file-name)))
|
|
217 ;; Like find-file, but in the case where a buffer existed
|
|
218 ;; and the file was reverted, recompute the message-data.
|
|
219 (if (and existed (not (verify-visited-file-modtime existed)))
|
|
220 (progn
|
|
221 ;; Don't be confused by apparent local-variables spec
|
|
222 ;; in the last message in the RMAIL file.
|
|
223 (let ((enable-local-variables nil))
|
|
224 (find-file file-name))
|
|
225 (if (and (verify-visited-file-modtime existed)
|
|
226 (eq major-mode 'rmail-mode))
|
|
227 (progn (rmail-forget-messages)
|
|
228 (rmail-set-message-counters))))
|
|
229 (let ((enable-local-variables nil))
|
|
230 (find-file file-name)))
|
|
231 (if (eq major-mode 'rmail-edit-mode)
|
|
232 (error "Exit Rmail Edit mode before getting new mail."))
|
|
233 (if (and existed (> (buffer-size) 0))
|
|
234 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
|
|
235 (or (eq major-mode 'rmail-mode)
|
|
236 (rmail-mode-2))
|
|
237 (rmail-mode-2)
|
|
238 ;; Convert all or part to Babyl file if possible.
|
|
239 (rmail-convert-file)
|
|
240 (goto-char (point-max))
|
|
241 (if (null rmail-inbox-list)
|
|
242 (progn
|
|
243 (rmail-set-message-counters)
|
|
244 (rmail-show-message))))
|
|
245 (let ((existing-unseen (rmail-first-unseen-message)))
|
|
246 (or file-name-arg
|
|
247 (rmail-get-new-mail))
|
|
248 ;; Show the first unseen message, which might be from a previous session
|
|
249 ;; or might have been just read in by rmail-get-new-mail. Must
|
|
250 ;; determine already unseen messages first, as rmail-get-new-mail
|
|
251 ;; positions on the first new message, thus marking it as seen.
|
|
252 (rmail-show-message existing-unseen))))
|
|
253
|
|
254 ;; Given the value of MAILPATH, return a list of inbox file names.
|
|
255 ;; This is turned off because it is not clear that the user wants
|
|
256 ;; all these inboxes to feed into the primary rmail file.
|
|
257 ; (defun rmail-convert-mailpath (string)
|
|
258 ; (let (idx list)
|
|
259 ; (while (setq idx (string-match "[%:]" string))
|
|
260 ; (let ((this (substring string 0 idx)))
|
|
261 ; (setq string (substring string (1+ idx)))
|
|
262 ; (setq list (cons (if (string-match "%" this)
|
|
263 ; (substring this 0 (string-match "%" this))
|
|
264 ; this)
|
|
265 ; list))))
|
|
266 ; list))
|
|
267
|
|
268 ;; Someone said:
|
|
269 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
|
|
270 ; will not cause emacs 18.55 problems.
|
|
271 ;; To which jwz responds: maybe so but it's damned annoying so don't do it.
|
|
272
|
|
273 (defun rmail-convert-file ()
|
|
274 (let (convert)
|
|
275 (widen)
|
|
276 (goto-char (point-min))
|
|
277 ;; If file doesn't start like a Babyl file,
|
|
278 ;; convert it to one, by adding a header and converting each message.
|
|
279 (cond ((looking-at "BABYL OPTIONS:"))
|
|
280 ((looking-at "Version: 5\n")
|
|
281 ;; Losing babyl file made by old version of Rmail.
|
|
282 ;; Just fix the babyl file header; don't make a new one,
|
|
283 ;; so we don't lose the Labels: file attribute, etc.
|
|
284 (let ((buffer-read-only nil))
|
|
285 ;; NO NO NO
|
|
286 ;;(insert "BABYL OPTIONS: -*- rmail -*-\n")
|
|
287 (insert "BABYL OPTIONS:\n")))
|
|
288 ((equal (point-min) (point-max))
|
|
289 ;; Empty RMAIL file. Just insert the header.
|
|
290 (rmail-insert-rmail-file-header))
|
|
291 (t
|
|
292 ;; Non-empty file in non-RMAIL format. Add header and convert.
|
|
293 (setq convert t)
|
|
294 (rmail-insert-rmail-file-header)))
|
|
295 ;; If file was not a Babyl file or if there are
|
|
296 ;; Unix format messages added at the end,
|
|
297 ;; convert file as necessary.
|
|
298 (if (or convert
|
|
299 (save-excursion
|
|
300 (goto-char (point-max))
|
|
301 (search-backward "\^_")
|
|
302 (forward-char 1)
|
|
303 (looking-at "\n*From ")))
|
|
304 (let ((buffer-read-only nil))
|
|
305 (message "Converting to Babyl format...")
|
|
306 ;; If file needs conversion, convert it all,
|
|
307 ;; except for the BABYL header.
|
|
308 ;; (rmail-convert-to-babyl-format would delete the header.)
|
|
309 (goto-char (point-min))
|
|
310 (search-forward "\n\^_" nil t)
|
|
311 (narrow-to-region (point) (point-max))
|
|
312 (rmail-convert-to-babyl-format)
|
|
313 (message "Converting to Babyl format...done")))))
|
|
314
|
|
315 ;;; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
|
|
316 ;;; will not cause emacs 18.55 problems.
|
|
317 ;;; (Whatever, see above. -jwz)
|
|
318
|
|
319 (defun rmail-insert-rmail-file-header ()
|
|
320 (let ((buffer-read-only nil))
|
|
321 ;; NO NO NO a thousand times NO
|
|
322 ;; (insert "BABYL OPTIONS: -*- rmail -*-
|
|
323 (insert "BABYL OPTIONS:
|
|
324 Version: 5
|
|
325 Labels:
|
|
326 Note: This is the header of an rmail file.
|
|
327 Note: If you are seeing it in rmail,
|
|
328 Note: it means the file has no messages in it.\n\^_")))
|
|
329
|
|
330 (if rmail-mode-map
|
|
331 nil
|
|
332 (setq rmail-mode-map (make-keymap))
|
|
333 (suppress-keymap rmail-mode-map)
|
|
334 (define-key rmail-mode-map "a" 'rmail-add-label)
|
|
335 (define-key rmail-mode-map "b" 'rmail-bury)
|
|
336 (define-key rmail-mode-map "c" 'rmail-continue)
|
|
337 (define-key rmail-mode-map "d" 'rmail-delete-forward)
|
|
338 (define-key rmail-mode-map "\C-d" 'rmail-delete-backward)
|
|
339 (define-key rmail-mode-map "e" 'rmail-edit-current-message)
|
|
340 (define-key rmail-mode-map "f" 'rmail-forward)
|
|
341 (define-key rmail-mode-map "g" 'rmail-get-new-mail)
|
|
342 (define-key rmail-mode-map "h" 'rmail-summary)
|
|
343 (define-key rmail-mode-map "i" 'rmail-input)
|
|
344 (define-key rmail-mode-map "j" 'rmail-show-message)
|
|
345 (define-key rmail-mode-map "k" 'rmail-kill-label)
|
|
346 (define-key rmail-mode-map "l" 'rmail-summary-by-labels)
|
|
347 (define-key rmail-mode-map "\e\C-h" 'rmail-summary)
|
|
348 (define-key rmail-mode-map "\e\C-l" 'rmail-summary-by-labels)
|
|
349 (define-key rmail-mode-map "\e\C-r" 'rmail-summary-by-recipients)
|
|
350 (define-key rmail-mode-map "\e\C-s" 'rmail-summary-by-regexp)
|
|
351 (define-key rmail-mode-map "\e\C-t" 'rmail-summary-by-topic)
|
|
352 (define-key rmail-mode-map "m" 'rmail-mail)
|
|
353 (define-key rmail-mode-map "\em" 'rmail-retry-failure)
|
|
354 (define-key rmail-mode-map "n" 'rmail-next-undeleted-message)
|
|
355 (define-key rmail-mode-map "\en" 'rmail-next-message)
|
|
356 (define-key rmail-mode-map "\e\C-n" 'rmail-next-labeled-message)
|
|
357 (define-key rmail-mode-map "o" 'rmail-output-to-rmail-file)
|
|
358 (define-key rmail-mode-map "\C-o" 'rmail-output)
|
|
359 (define-key rmail-mode-map "p" 'rmail-previous-undeleted-message)
|
|
360 (define-key rmail-mode-map "\ep" 'rmail-previous-message)
|
|
361 (define-key rmail-mode-map "\e\C-p" 'rmail-previous-labeled-message)
|
|
362 (define-key rmail-mode-map "q" 'rmail-quit)
|
|
363 (define-key rmail-mode-map "r" 'rmail-reply)
|
|
364 ;; I find I can't live without the default M-r command -- rms.
|
|
365 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
|
|
366 (define-key rmail-mode-map "s" 'rmail-expunge-and-save)
|
|
367 (define-key rmail-mode-map "\es" 'rmail-search)
|
|
368 (define-key rmail-mode-map "t" 'rmail-toggle-header)
|
|
369 (define-key rmail-mode-map "u" 'rmail-undelete-previous-message)
|
|
370 (define-key rmail-mode-map "w" 'rmail-edit-current-message)
|
|
371 (define-key rmail-mode-map "x" 'rmail-expunge)
|
|
372 (define-key rmail-mode-map "." 'rmail-beginning-of-message)
|
|
373 (define-key rmail-mode-map "<" 'rmail-first-message)
|
|
374 (define-key rmail-mode-map ">" 'rmail-last-message)
|
|
375 (define-key rmail-mode-map " " 'scroll-up)
|
|
376 (define-key rmail-mode-map "\177" 'scroll-down)
|
|
377 (define-key rmail-mode-map "?" 'describe-mode)
|
|
378 (define-key rmail-mode-map "\C-c\C-s\C-d" 'rmail-sort-by-date)
|
|
379 (define-key rmail-mode-map "\C-c\C-s\C-s" 'rmail-sort-by-subject)
|
|
380 (define-key rmail-mode-map "\C-c\C-s\C-a" 'rmail-sort-by-author)
|
|
381 (define-key rmail-mode-map "\C-c\C-s\C-r" 'rmail-sort-by-recipient)
|
|
382 (define-key rmail-mode-map "\C-c\C-s\C-c" 'rmail-sort-by-correspondent)
|
|
383 (define-key rmail-mode-map "\C-c\C-s\C-l" 'rmail-sort-by-lines)
|
|
384 )
|
|
385
|
|
386 ;(define-key rmail-mode-map [menu-bar] (make-sparse-keymap))
|
|
387 ;
|
|
388 ;(define-key rmail-mode-map [menu-bar classify]
|
|
389 ; (cons "Classify" (make-sparse-keymap "Classify")))
|
|
390 ;
|
|
391 ;(define-key rmail-mode-map [menu-bar classify output-inbox]
|
|
392 ; '("Output (inbox)" . rmail-output))
|
|
393 ;
|
|
394 ;(define-key rmail-mode-map [menu-bar classify output]
|
|
395 ; '("Output (Rmail)" . rmail-output-to-rmail-file))
|
|
396 ;
|
|
397 ;(define-key rmail-mode-map [menu-bar classify kill-label]
|
|
398 ; '("Kill Label" . rmail-kill-label))
|
|
399 ;
|
|
400 ;(define-key rmail-mode-map [menu-bar classify add-label]
|
|
401 ; '("Add Label" . rmail-add-label))
|
|
402 ;
|
|
403 ;(define-key rmail-mode-map [menu-bar summary]
|
|
404 ; (cons "Summary" (make-sparse-keymap "Summary")))
|
|
405 ;
|
|
406 ;(define-key rmail-mode-map [menu-bar summary labels]
|
|
407 ; '("By Labels" . rmail-summary-by-labels))
|
|
408 ;
|
|
409 ;(define-key rmail-mode-map [menu-bar summary recipients]
|
|
410 ; '("By Recipients" . rmail-summary-by-recipients))
|
|
411 ;
|
|
412 ;(define-key rmail-mode-map [menu-bar summary topic]
|
|
413 ; '("By Topic" . rmail-summary-by-topic))
|
|
414 ;
|
|
415 ;(define-key rmail-mode-map [menu-bar summary regexp]
|
|
416 ; '("By Regexp" . rmail-summary-by-regexp))
|
|
417 ;
|
|
418 ;(define-key rmail-mode-map [menu-bar summary all]
|
|
419 ; '("All" . rmail-summary))
|
|
420 ;
|
|
421 ;(define-key rmail-mode-map [menu-bar mail]
|
|
422 ; (cons "Mail" (make-sparse-keymap "Mail")))
|
|
423 ;
|
|
424 ;(define-key rmail-mode-map [menu-bar mail continue]
|
|
425 ; '("Continue" . rmail-continue))
|
|
426 ;
|
|
427 ;(define-key rmail-mode-map [menu-bar mail forward]
|
|
428 ; '("Forward" . rmail-forward))
|
|
429 ;
|
|
430 ;(define-key rmail-mode-map [menu-bar mail retry]
|
|
431 ; '("Retry" . rmail-retry-failure))
|
|
432 ;
|
|
433 ;(define-key rmail-mode-map [menu-bar mail reply]
|
|
434 ; '("Reply" . rmail-reply))
|
|
435 ;
|
|
436 ;(define-key rmail-mode-map [menu-bar mail mail]
|
|
437 ; '("Mail" . rmail-mail))
|
|
438 ;
|
|
439 ;(define-key rmail-mode-map [menu-bar delete]
|
|
440 ; (cons "Delete" (make-sparse-keymap "Delete")))
|
|
441 ;
|
|
442 ;(define-key rmail-mode-map [menu-bar delete expunge/save]
|
|
443 ; '("Expunge/Save" . rmail-expunge-and-save))
|
|
444 ;
|
|
445 ;(define-key rmail-mode-map [menu-bar delete expunge]
|
|
446 ; '("Expunge" . rmail-expunge))
|
|
447 ;
|
|
448 ;(define-key rmail-mode-map [menu-bar delete undelete]
|
|
449 ; '("Undelete" . rmail-undelete-previous-message))
|
|
450 ;
|
|
451 ;(define-key rmail-mode-map [menu-bar delete delete]
|
|
452 ; '("Delete" . rmail-delete-forward))
|
|
453 ;
|
|
454 ;(define-key rmail-mode-map [menu-bar move]
|
|
455 ; (cons "Move" (make-sparse-keymap "Move")))
|
|
456 ;
|
|
457 ;(define-key rmail-mode-map [menu-bar move search-back]
|
|
458 ; '("Search Back" . rmail-search-backward))
|
|
459 ;
|
|
460 ;(define-key rmail-mode-map [menu-bar move search]
|
|
461 ; '("Search" . rmail-search))
|
|
462 ;
|
|
463 ;(define-key rmail-mode-map [menu-bar move previous]
|
|
464 ; '("Previous Nondeleted" . rmail-previous-undeleted-message))
|
|
465 ;
|
|
466 ;(define-key rmail-mode-map [menu-bar move next]
|
|
467 ; '("Next Nondeleted" . rmail-next-undeleted-message))
|
|
468 ;
|
|
469 ;(define-key rmail-mode-map [menu-bar move last]
|
|
470 ; '("Last" . rmail-last-message))
|
|
471 ;
|
|
472 ;(define-key rmail-mode-map [menu-bar move first]
|
|
473 ; '("First" . rmail-first-message))
|
|
474 ;
|
|
475 ;(define-key rmail-mode-map [menu-bar move previous]
|
|
476 ; '("Previous" . rmail-previous-message))
|
|
477 ;
|
|
478 ;(define-key rmail-mode-map [menu-bar move next]
|
|
479 ; '("Next" . rmail-next-message))
|
|
480
|
|
481 ;; Rmail mode is suitable only for specially formatted data.
|
|
482 (put 'rmail-mode 'mode-class 'special)
|
|
483
|
|
484 ;;;###autoload
|
|
485 (defun rmail-mode ()
|
|
486 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
|
|
487 All normal editing commands are turned off.
|
|
488 Instead, these commands are available:
|
|
489
|
|
490 \\[rmail-beginning-of-message] Move point to front of this message (same as \\[beginning-of-buffer]).
|
|
491 \\[scroll-up] Scroll to next screen of this message.
|
|
492 \\[scroll-down] Scroll to previous screen of this message.
|
|
493 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
|
|
494 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
|
|
495 \\[rmail-next-message] Move to Next message whether deleted or not.
|
|
496 \\[rmail-previous-message] Move to Previous message whether deleted or not.
|
|
497 \\[rmail-first-message] Move to the first message in Rmail file.
|
|
498 \\[rmail-last-message] Move to the last message in Rmail file.
|
|
499 \\[rmail-show-message] Jump to message specified by numeric position in file.
|
|
500 \\[rmail-search] Search for string and show message it is found in.
|
|
501 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
|
|
502 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
|
|
503 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
|
|
504 till a deleted message is found.
|
|
505 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
|
|
506 \\[rmail-expunge] Expunge deleted messages.
|
|
507 \\[rmail-expunge-and-save] Expunge and save the file.
|
|
508 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
|
|
509 \\[save-buffer] Save without expunging.
|
|
510 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
|
|
511 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
|
|
512 \\[rmail-continue] Continue composing outgoing message started before.
|
|
513 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
|
|
514 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
|
|
515 \\[rmail-forward] Forward this message to another user.
|
|
516 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
|
|
517 \\[rmail-output] Output this message to a Unix-format mail file (append it).
|
|
518 \\[rmail-input] Input Rmail file. Run Rmail on that file.
|
|
519 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
|
|
520 \\[rmail-kill-label] Kill label. Remove a label from current message.
|
|
521 \\[rmail-next-labeled-message] Move to Next message with specified label
|
|
522 (label defaults to last one specified).
|
|
523 Standard labels: filed, unseen, answered, forwarded, deleted.
|
|
524 Any other label is present only if you add it with \\[rmail-add-label].
|
|
525 \\[rmail-previous-labeled-message] Move to Previous message with specified label
|
|
526 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
|
|
527 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
|
|
528 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
|
|
529 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
|
|
530 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
|
|
531 \\[rmail-toggle-header] Toggle display of complete header."
|
|
532 (interactive)
|
|
533 (rmail-mode-2)
|
|
534 (rmail-set-message-counters)
|
|
535 (rmail-show-message rmail-total-messages))
|
|
536
|
|
537 (defun rmail-mode-2 ()
|
|
538 (kill-all-local-variables)
|
|
539 (rmail-mode-1)
|
|
540 (rmail-variables)
|
|
541 (run-hooks 'rmail-mode-hook))
|
|
542
|
|
543 (defun rmail-mode-1 ()
|
|
544 (setq major-mode 'rmail-mode)
|
|
545 (setq mode-name "RMAIL")
|
|
546 (setq buffer-read-only t)
|
|
547 ;; No need to auto save RMAIL files.
|
|
548 ;; says who??? (asks jwz)
|
|
549 ;; (setq buffer-auto-save-file-name nil)
|
|
550 (if (boundp 'mode-line-modified)
|
|
551 (setq mode-line-modified "--- ")
|
|
552 (setq mode-line-format
|
|
553 (cons "--- " (cdr (default-value 'mode-line-format)))))
|
|
554 (use-local-map rmail-mode-map)
|
|
555 (set-syntax-table text-mode-syntax-table)
|
|
556 (setq local-abbrev-table text-mode-abbrev-table))
|
|
557
|
|
558 (defun rmail-variables ()
|
|
559 (make-local-variable 'revert-buffer-function)
|
|
560 (setq revert-buffer-function 'rmail-revert)
|
|
561 (make-local-variable 'rmail-last-label)
|
|
562 (make-local-variable 'rmail-last-regexp)
|
|
563 (make-local-variable 'rmail-deleted-vector)
|
|
564 (make-local-variable 'rmail-summary-buffer)
|
|
565 (make-local-variable 'rmail-summary-vector)
|
|
566 (make-local-variable 'rmail-current-message)
|
|
567 (make-local-variable 'rmail-total-messages)
|
|
568 (make-local-variable 'require-final-newline)
|
|
569 (setq require-final-newline nil)
|
|
570 (make-local-variable 'version-control)
|
|
571 (setq version-control 'never)
|
|
572 (make-local-variable 'file-precious-flag)
|
|
573 (setq file-precious-flag t)
|
|
574 (make-local-variable 'rmail-message-vector)
|
|
575 (make-local-variable 'rmail-last-file)
|
|
576 (make-local-variable 'rmail-inbox-list)
|
|
577 (setq rmail-inbox-list (rmail-parse-file-inboxes))
|
|
578 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
|
|
579 (and (null rmail-inbox-list)
|
|
580 (or (equal buffer-file-name (expand-file-name rmail-file-name))
|
|
581 (equal buffer-file-truename
|
|
582 (abbreviate-file-name (file-truename rmail-file-name))))
|
|
583 (setq rmail-inbox-list
|
|
584 (or rmail-primary-inbox-list
|
|
585 ;; XEmacs change: FSF had removed "~/mbox" from this list,
|
|
586 ;; but users expect that to work and don't understand why
|
|
587 ;; it changed.
|
|
588 (list "~/mbox"
|
|
589 (or (getenv "MAIL")
|
|
590 (concat rmail-spool-directory
|
|
591 (user-original-login-name)))))))
|
|
592 (make-local-variable 'rmail-keywords)
|
|
593 ;; this gets generated as needed
|
|
594 (setq rmail-keywords nil))
|
|
595
|
|
596 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
|
|
597 (defun rmail-revert (arg noconfirm)
|
|
598 (let (revert-buffer-function)
|
|
599 ;; Call our caller again, but this time it does the default thing.
|
|
600 (if (revert-buffer arg noconfirm)
|
|
601 ;; If the user said "yes", and we changed something,
|
|
602 ;; reparse the messages.
|
|
603 (progn
|
|
604 (rmail-convert-file)
|
|
605 (goto-char (point-max))
|
|
606 (rmail-set-message-counters)
|
|
607 (rmail-show-message)))))
|
|
608
|
|
609 ;; Return a list of files from this buffer's Mail: option.
|
|
610 ;; Does not assume that messages have been parsed.
|
|
611 ;; Just returns nil if buffer does not look like Babyl format.
|
|
612 (defun rmail-parse-file-inboxes ()
|
|
613 (save-excursion
|
|
614 (save-restriction
|
|
615 (widen)
|
|
616 (goto-char 1)
|
|
617 (cond ((looking-at "BABYL OPTIONS:")
|
|
618 (search-forward "\n\^_" nil 'move)
|
|
619 (narrow-to-region 1 (point))
|
|
620 (goto-char 1)
|
|
621 (if (search-forward "\nMail:" nil t)
|
|
622 (progn
|
|
623 (narrow-to-region (point) (progn (end-of-line) (point)))
|
|
624 (goto-char (point-min))
|
|
625 (mail-parse-comma-list))))))))
|
|
626
|
|
627 (defun rmail-expunge-and-save ()
|
|
628 "Expunge and save RMAIL file."
|
|
629 (interactive)
|
|
630 (rmail-expunge)
|
|
631 (save-buffer))
|
|
632
|
|
633 (defun rmail-quit ()
|
|
634 "Quit out of RMAIL."
|
|
635 (interactive)
|
|
636 (rmail-expunge-and-save)
|
|
637 ;; Don't switch to the summary buffer even if it was recently visible.
|
|
638 (if (rmail-summary-exists)
|
|
639 (bury-buffer rmail-summary-buffer))
|
|
640 (let ((obuf (current-buffer)))
|
|
641 (switch-to-buffer (other-buffer))
|
|
642 (bury-buffer obuf)))
|
|
643
|
|
644 ;;;###autoload
|
|
645 (defun rmail-input (filename)
|
|
646 "Run Rmail on file FILENAME."
|
|
647 (interactive "FRun rmail on RMAIL file: ")
|
|
648 (rmail filename))
|
|
649
|
|
650
|
|
651 ;;;; *** Rmail input ***
|
|
652
|
|
653 ;; RLK feature not added in this version:
|
|
654 ;; argument specifies inbox file or files in various ways.
|
|
655
|
|
656 (defun rmail-get-new-mail (&optional file-name)
|
|
657 "Move any new mail from this RMAIL file's inbox files.
|
|
658 The inbox files can be specified with the file's Mail: option. The
|
|
659 variable `rmail-primary-inbox-list' specifies the inboxes for your
|
|
660 primary RMAIL file if it has no Mail: option. By default, this is
|
|
661 your /usr/spool/mail/$USER.
|
|
662
|
|
663 You can also specify the file to get new mail from. In this case, the
|
|
664 file of new mail is not changed or deleted. Noninteractively, you can
|
|
665 pass the inbox file name as an argument. Interactively, a prefix
|
|
666 argument causes us to read a file name and use that file as the inbox."
|
|
667 (interactive
|
|
668 (list (if current-prefix-arg
|
|
669 (read-file-name "Get new mail from file: "))))
|
|
670 (or (verify-visited-file-modtime (current-buffer))
|
|
671 (progn
|
|
672 (find-file (buffer-file-name))
|
|
673 (setq buffer-read-only t)
|
|
674 (if (verify-visited-file-modtime (current-buffer))
|
|
675 (rmail-forget-messages))))
|
|
676 (rmail-maybe-set-message-counters)
|
|
677 (widen)
|
|
678 ;; Get rid of all undo records for this buffer.
|
|
679 (or (eq buffer-undo-list t)
|
|
680 (setq buffer-undo-list nil))
|
|
681 (unwind-protect
|
|
682 (let ((opoint (point))
|
|
683 (new-messages 0)
|
|
684 (delete-files ())
|
|
685 ;; If buffer has not changed yet, and has not been saved yet,
|
|
686 ;; don't replace the old backup file now.
|
|
687 (make-backup-files (and make-backup-files (buffer-modified-p)))
|
|
688 (buffer-read-only nil)
|
|
689 ;; Don't make undo records for what we do in getting mail.
|
|
690 (buffer-undo-list t))
|
|
691 (goto-char (point-max))
|
|
692 (skip-chars-backward " \t\n") ; just in case of brain damage
|
|
693 (delete-region (point) (point-max)) ; caused by require-final-newline
|
|
694 (save-excursion
|
|
695 (save-restriction
|
|
696 (narrow-to-region (point) (point))
|
|
697 ;; Read in the contents of the inbox files,
|
|
698 ;; renaming them as necessary,
|
|
699 ;; and adding to the list of files to delete eventually.
|
|
700 (if file-name
|
|
701 (rmail-insert-inbox-text (list file-name) nil)
|
|
702 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t)))
|
|
703 ;; Scan the new text and convert each message to babyl format.
|
|
704 (goto-char (point-min))
|
|
705 (save-excursion
|
|
706 (setq new-messages (rmail-convert-to-babyl-format)))
|
|
707 (or (zerop new-messages)
|
|
708 (progn ;;let (success)
|
|
709 (widen)
|
|
710 (search-backward "\n\^_")
|
|
711 (narrow-to-region (point) (point-max))
|
|
712 (goto-char (1+ (point-min)))
|
|
713 (rmail-count-new-messages)
|
|
714 (save-buffer)))
|
|
715 ;; Delete the old files, now that babyl file is saved.
|
|
716 (while delete-files
|
|
717 (condition-case ()
|
|
718 ;; First, try deleting.
|
|
719 (condition-case ()
|
|
720 (delete-file (car delete-files))
|
|
721 (file-error
|
|
722 ;; If we can't delete it, truncate it.
|
|
723 (write-region (point) (point) (car delete-files))))
|
|
724 (file-error nil))
|
|
725 (setq delete-files (cdr delete-files)))))
|
|
726 (if (= new-messages 0)
|
|
727 (progn (goto-char opoint)
|
|
728 (if (or file-name rmail-inbox-list)
|
|
729 (message "(No new mail has arrived)")))
|
|
730 (if (rmail-summary-exists)
|
|
731 (rmail-select-summary
|
|
732 (rmail-update-summary)))
|
|
733 (message "%d new message%s read"
|
|
734 new-messages (if (= 1 new-messages) "" "s"))
|
|
735 ;; #### BOGUS! Run a hook here instead and let time.el do it.
|
|
736 (and (boundp 'display-time-string)
|
|
737 display-time-string
|
|
738 (string-match " Mail" display-time-string)
|
|
739 (setq display-time-string
|
|
740 (concat
|
|
741 (substring display-time-string 0 (match-beginning 0))
|
|
742 (substring display-time-string (match-end 0))))
|
|
743 (force-mode-line-update 'all))))
|
|
744 ;; Don't leave the buffer screwed up if we get a disk-full error.
|
|
745 (rmail-show-message)))
|
|
746
|
|
747 (defun rmail-insert-inbox-text (files renamep)
|
|
748 (let (file tofile delete-files movemail popmail)
|
|
749 (while files
|
|
750 (setq file (expand-file-name (substitute-in-file-name (car files)))
|
|
751 ;;>> un*x specific <<
|
|
752 ;; The "+" used to be "~", which is an extremely poor choice;
|
|
753 ;; it might accidentally be deleted when space is low
|
|
754 ;; (as happened to me!).
|
|
755 tofile (concat file "+"))
|
|
756 ;; If getting from mail spool directory,
|
|
757 ;; use movemail to move rather than just renaming,
|
|
758 ;; so as to interlock with the mailer.
|
|
759 (setq movemail (equal (file-name-directory file) rmail-spool-directory)
|
|
760 popmail (string-match "^po:" (file-name-nondirectory file)))
|
|
761 (if popmail (setq file (file-name-nondirectory file)
|
|
762 renamep t))
|
|
763 (if movemail
|
|
764 (progn
|
|
765 (setq tofile (expand-file-name
|
|
766 ;; Generate name to move to from inbox name,
|
|
767 ;; in case of multiple inboxes that need moving.
|
|
768 (concat ".newmail-" (file-name-nondirectory file))
|
|
769 ;; Use the directory of this rmail file
|
|
770 ;; because it's a nuisance to use the homedir
|
|
771 ;; if that is on a full disk and this rmail
|
|
772 ;; file isn't.
|
|
773 (file-name-directory
|
|
774 (expand-file-name buffer-file-name))))
|
|
775 ;; On some systems, /usr/spool/mail/foo is a directory
|
|
776 ;; and the actual inbox is /usr/spool/mail/foo/foo.
|
|
777 (if (file-directory-p file)
|
|
778 (setq file (expand-file-name (user-original-login-name)
|
|
779 file)))))
|
|
780 (if popmail
|
|
781 (message "Getting mail from post office ...")
|
|
782 (if (or (and (file-exists-p tofile)
|
|
783 (/= 0 (nth 7 (file-attributes tofile))))
|
|
784 (and (file-exists-p file)
|
|
785 (/= 0 (nth 7 (file-attributes file)))))
|
|
786 (message "Getting mail from %s..." file)))
|
|
787 ;; Set TOFILE if have not already done so, and
|
|
788 ;; rename or copy the file FILE to TOFILE if and as appropriate.
|
|
789 (cond ((not renamep)
|
|
790 (setq tofile file))
|
|
791 ((or (file-exists-p tofile) (and (not popmail)
|
|
792 (not (file-exists-p file))))
|
|
793 nil)
|
|
794 ((and (not movemail) (not popmail))
|
|
795 ;; Try copying. If that fails (perhaps no space),
|
|
796 ;; rename instead.
|
|
797 (condition-case nil
|
|
798 (copy-file file tofile nil)
|
|
799 (error
|
|
800 (rename-file file tofile nil)))
|
|
801 ;; Make the real inbox file empty.
|
|
802 ;; Leaving it deleted could cause lossage
|
|
803 ;; because mailers often won't create the file.
|
|
804 (condition-case ()
|
|
805 (write-region (point) (point) file)
|
|
806 (file-error nil)))
|
|
807 (t
|
|
808 (let ((errors nil))
|
|
809 (unwind-protect
|
|
810 (save-excursion
|
|
811 (setq errors (generate-new-buffer " *rmail loss*"))
|
|
812 (buffer-disable-undo errors)
|
|
813 (call-process
|
|
814 (expand-file-name "movemail" exec-directory)
|
|
815 nil errors nil file tofile)
|
|
816 (if (not (buffer-modified-p errors))
|
|
817 ;; No output => movemail won
|
|
818 nil
|
|
819 (set-buffer errors)
|
|
820 (subst-char-in-region (point-min) (point-max)
|
|
821 ?\n ?\ )
|
|
822 (goto-char (point-max))
|
|
823 (skip-chars-backward " \t")
|
|
824 (delete-region (point) (point-max))
|
|
825 (goto-char (point-min))
|
|
826 (if (looking-at "movemail: ")
|
|
827 (delete-region (point-min) (match-end 0)))
|
|
828 (beep t)
|
|
829 (message (concat "movemail: "
|
|
830 (buffer-substring (point-min)
|
|
831 (point-max))))
|
|
832 (sit-for 3)
|
|
833 nil))
|
|
834 (if errors (kill-buffer errors))))))
|
|
835 ;; At this point, TOFILE contains the name to read:
|
|
836 ;; Either the alternate name (if we renamed)
|
|
837 ;; or the actual inbox (if not renaming).
|
|
838 (if (file-exists-p tofile)
|
|
839 (let (size)
|
|
840 (goto-char (point-max))
|
|
841 (if (not (featurep 'mule))
|
|
842 (setq size (nth 1 (insert-file-contents tofile)))
|
|
843 ;; At first, read the file without converting coding-system.
|
|
844 (setq size (nth 1 (let (file-coding-system-for-read)
|
|
845 (insert-file-contents tofile))))
|
|
846 ;; Then, convert the contents if necessary.
|
|
847 (if (> size 0)
|
|
848 (cond
|
|
849 ((looking-at "^From ")
|
|
850 ;; New mails. Since the contents may be a mixture
|
|
851 ;; of various coding-systems, we must decode one
|
|
852 ;; mail by one.
|
|
853 (while (null (eobp))
|
|
854 (let ((from (point)))
|
|
855 (re-search-forward "^From " nil 'mv)
|
|
856 (rmail-decode-coding-system from (point)))))
|
|
857 ((looking-at "BABYL OPTIONS:\\|\^L")
|
|
858 ;; Babyl format, i.e. not a new mail. We had better
|
|
859 ;; not to convert large region at once.
|
|
860 (while (null (eobp))
|
|
861 (let ((max-size (* 1024 1024))
|
|
862 (from (point)))
|
|
863 (goto-char (+ from max-size))
|
|
864 (re-search-forward "\^_" nil 'mv)
|
|
865 (rmail-decode-coding-system from (point)))))
|
|
866 (t
|
|
867 ;; Perhaps, MMDF format. Since I don't know how to
|
|
868 ;; deal with it, convert all data at once.
|
|
869 (rmail-decode-coding-system (point) (point-max))))))
|
|
870 (goto-char (point-max))
|
|
871 (or (= (preceding-char) ?\n)
|
|
872 (zerop size)
|
|
873 (insert ?\n))
|
|
874 (setq delete-files (cons tofile delete-files))))
|
|
875 (message "")
|
|
876 (setq files (cdr files)))
|
|
877 delete-files))
|
|
878
|
|
879 (if (not (featurep 'mule)) nil
|
|
880
|
|
881 (defvar mail-coding-system '*junet*)
|
|
882
|
|
883 (defun rmail-decode-coding-system (from to)
|
|
884 (let (coding-system)
|
|
885 ;; At first, detect the coding-system of the region and set it to
|
|
886 ;; `coding-sytem'.
|
|
887 (let ((detected-coding-system (code-detect-region from to))
|
|
888 (coding (get-code mail-coding-system)))
|
|
889 (if (listp detected-coding-system)
|
|
890 ;; Something other than ASCII was found. If a coding-system
|
|
891 ;; of which information is same as `mail-coding-system' is
|
|
892 ;; in the list of detected coding-systems, use it, else use
|
|
893 ;; the coding-system of the highest priority in the list.
|
|
894 (let ((l detected-coding-system))
|
|
895 (while (and l
|
|
896 (null (eq (get-code (car l)) coding)))
|
|
897 (setq l (cdr l)))
|
|
898 (setq coding-system (car (or l detected-coding-system))))))
|
|
899 ;; Then, decode the region.
|
|
900 (if coding-system
|
|
901 (save-restriction
|
|
902 (narrow-to-region from to)
|
|
903 (code-convert from to coding-system '*internal*)
|
|
904 (goto-char (point-max))))))
|
|
905
|
|
906 ) ; (featurep 'mule)
|
|
907
|
|
908 ;; the rmail-break-forwarded-messages feature is not implemented
|
|
909 (defun rmail-convert-to-babyl-format ()
|
|
910 (let ((count 0) start
|
|
911 (case-fold-search nil)
|
|
912 (invalid-input-resync
|
|
913 (function (lambda ()
|
|
914 (message "Invalid Babyl format in inbox!")
|
|
915 (sit-for 1)
|
|
916 ;; Try to get back in sync with a real message.
|
|
917 (if (re-search-forward
|
|
918 (concat mmdf-delim1 "\\|^From") nil t)
|
|
919 (beginning-of-line)
|
|
920 (goto-char (point-max)))))))
|
|
921 (goto-char (point-min))
|
|
922 (save-restriction
|
|
923 (while (not (eobp))
|
|
924 (cond ((looking-at "BABYL OPTIONS:");Babyl header
|
|
925 (if (search-forward "\n\^_" nil t)
|
|
926 ;; If we find the proper terminator, delete through there.
|
|
927 (delete-region (point-min) (point))
|
|
928 (funcall invalid-input-resync)
|
|
929 (delete-region (point-min) (point))))
|
|
930 ;; Babyl format message
|
|
931 ((looking-at "\^L")
|
|
932 (or (search-forward "\n\^_" nil t)
|
|
933 (funcall invalid-input-resync))
|
|
934 (setq count (1+ count))
|
|
935 ;; Make sure there is no extra white space after the ^_
|
|
936 ;; at the end of the message.
|
|
937 ;; Narrowing will make sure that whatever follows the junk
|
|
938 ;; will be treated properly.
|
|
939 (delete-region (point)
|
|
940 (save-excursion
|
|
941 (skip-chars-forward " \t\n")
|
|
942 (point)))
|
|
943 (narrow-to-region (point) (point-max)))
|
|
944 ;;*** MMDF format
|
|
945 ((let ((case-fold-search t))
|
|
946 (looking-at mmdf-delim1))
|
|
947 (let ((case-fold-search t))
|
|
948 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
|
|
949 (setq start (point))
|
|
950 (re-search-forward mmdf-delim2 nil t)
|
|
951 (replace-match "\^_"))
|
|
952 (save-excursion
|
|
953 (save-restriction
|
|
954 (narrow-to-region start (1- (point)))
|
|
955 (goto-char (point-min))
|
|
956 (while (search-forward "\n\^_" nil t); single char "\^_"
|
|
957 (replace-match "\n^_")))); 2 chars: "^" and "_"
|
|
958 (narrow-to-region (point) (point-max))
|
|
959 (setq count (1+ count)))
|
|
960 ;;*** Mail format
|
|
961 ((looking-at "^From ")
|
|
962 (setq start (point))
|
|
963 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
|
|
964 (rmail-nuke-pinhead-header)
|
|
965 ;; If this message has a Content-Length field,
|
|
966 ;; skip to the end of the contents.
|
|
967 (let* ((header-end (save-excursion
|
|
968 (and (re-search-forward "\n\n" nil t)
|
|
969 (point))))
|
|
970 (case-fold-search t)
|
|
971 (size
|
|
972 ;; Get the numeric value from the Content-Length field.
|
|
973 (save-excursion
|
|
974 ;; Back up to end of prev line,
|
|
975 ;; in case the Content-Length field comes first.
|
|
976 (forward-char -1)
|
|
977 (and (search-forward "\ncontent-length: "
|
|
978 header-end t)
|
|
979 (let ((beg (point))
|
|
980 (eol (progn (end-of-line) (point))))
|
|
981 (read (buffer-substring beg eol)))))))
|
|
982 (and size (numberp size) (>= size 0)
|
|
983 (goto-char (+ header-end size))))
|
|
984
|
|
985 (if (re-search-forward
|
|
986 (concat "^[\^_]?\\("
|
|
987 rmail-unix-mail-delimiter
|
|
988 "\\|"
|
|
989 mmdf-delim1 "\\|"
|
|
990 "^BABYL OPTIONS:\\|"
|
|
991 "\^L\n[01],\\)") nil t)
|
|
992 (goto-char (match-beginning 1))
|
|
993 (goto-char (point-max)))
|
|
994 (setq count (1+ count))
|
|
995 (save-excursion
|
|
996 (save-restriction
|
|
997 (narrow-to-region start (point))
|
|
998 (goto-char (point-min))
|
|
999 (while (search-forward "\n\^_" nil t); single char
|
|
1000 (replace-match "\n^_")))); 2 chars: "^" and "_"
|
|
1001 (insert ?\^_)
|
|
1002 (narrow-to-region (point) (point-max)))
|
|
1003 ;;
|
|
1004 ;; This kludge is because some versions of sendmail.el
|
|
1005 ;; insert an extra newline at the beginning that shouldn't
|
|
1006 ;; be there. sendmail.el has been fixed, but old versions
|
|
1007 ;; may still be in use. -- rms, 7 May 1993.
|
|
1008 ((eolp) (delete-char 1))
|
|
1009 (t (error "Cannot convert to babyl format")))))
|
|
1010 count))
|
|
1011
|
|
1012 ;; Delete the "From ..." line, creating various other headers with
|
|
1013 ;; information from it if they don't already exist. Now puts the
|
|
1014 ;; original line into a mail-from: header line for debugging and for
|
|
1015 ;; use by the rmail-output function.
|
|
1016 (defun rmail-nuke-pinhead-header ()
|
|
1017 (save-excursion
|
|
1018 (save-restriction
|
|
1019 (let ((start (point))
|
|
1020 (end (progn
|
|
1021 (condition-case ()
|
|
1022 (search-forward "\n\n")
|
|
1023 (error
|
|
1024 (goto-char (point-max))
|
|
1025 (insert "\n\n")))
|
|
1026 (point)))
|
|
1027 has-from has-date)
|
|
1028 (narrow-to-region start end)
|
|
1029 (let ((case-fold-search t))
|
|
1030 (goto-char start)
|
|
1031 (setq has-from (search-forward "\nFrom:" nil t))
|
|
1032 (goto-char start)
|
|
1033 (setq has-date (and (search-forward "\nDate:" nil t) (point)))
|
|
1034 (goto-char start))
|
|
1035 (let ((case-fold-search nil))
|
|
1036 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter) nil t)
|
|
1037 (replace-match
|
|
1038 (concat
|
|
1039 "Mail-from: \\&"
|
|
1040 ;; Keep and reformat the date if we don't
|
|
1041 ;; have a Date: field.
|
|
1042 (if has-date
|
|
1043 ""
|
|
1044 (concat
|
|
1045 "Date: \\3, \\5 \\4 \\9 \\6 "
|
|
1046
|
|
1047 ;; The timezone could be matched by group 7 or group 10.
|
|
1048 ;; If neither of them matched, assume EST, since only
|
|
1049 ;; Easterners would be so sloppy.
|
|
1050 ;; It's a shame the substitution can't use "\\10".
|
|
1051 (cond
|
|
1052 ((/= (match-beginning 7) (match-end 7)) "\\7")
|
|
1053 ((/= (match-beginning 10) (match-end 10))
|
|
1054 (buffer-substring (match-beginning 10)
|
|
1055 (match-end 10)))
|
|
1056 (t "EST"))
|
|
1057 "\n"))
|
|
1058 ;; Keep and reformat the sender if we don't
|
|
1059 ;; have a From: field.
|
|
1060 (if has-from
|
|
1061 ""
|
|
1062 "From: \\1\n"))
|
|
1063 t)))))))
|
|
1064
|
|
1065 ;;;; *** Rmail Message Formatting and Header Manipulation ***
|
|
1066
|
|
1067 (defun rmail-reformat-message (beg end)
|
|
1068 (goto-char beg)
|
|
1069 (forward-line 1)
|
|
1070 (if (/= (following-char) ?0)
|
|
1071 (error "Bad format in RMAIL file."))
|
|
1072 (let ((buffer-read-only nil)
|
|
1073 (delta (- (buffer-size) end)))
|
|
1074 (delete-char 1)
|
|
1075 (insert ?1)
|
|
1076 (forward-line 1)
|
|
1077 (let ((case-fold-search t))
|
|
1078 (while (looking-at "Summary-line:\\|Mail-From:")
|
|
1079 (forward-line 1)))
|
|
1080 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
|
|
1081 (delete-region (point)
|
|
1082 (progn (forward-line 1) (point))))
|
|
1083 (let ((str (buffer-substring (point)
|
|
1084 (save-excursion (search-forward "\n\n" end 'move)
|
|
1085 (point)))))
|
|
1086 (insert str "*** EOOH ***\n")
|
|
1087 (narrow-to-region (point) (- (buffer-size) delta)))
|
|
1088 (goto-char (point-min))
|
|
1089 (if rmail-ignored-headers (rmail-clear-headers))
|
|
1090 (if rmail-message-filter (funcall rmail-message-filter))))
|
|
1091
|
|
1092 (defun rmail-clear-headers ()
|
|
1093 (if (search-forward "\n\n" nil t)
|
|
1094 (save-restriction
|
|
1095 (narrow-to-region (point-min) (point))
|
|
1096 (let ((buffer-read-only nil))
|
|
1097 (while (let ((case-fold-search t))
|
|
1098 (goto-char (point-min))
|
|
1099 (re-search-forward rmail-ignored-headers nil t))
|
|
1100 (beginning-of-line)
|
|
1101 (delete-region (point)
|
|
1102 (progn (re-search-forward "\n[^ \t]")
|
|
1103 (forward-char -1)
|
|
1104 (point))))))))
|
|
1105
|
|
1106 (defun rmail-toggle-header ()
|
|
1107 "Show original message header if pruned header currently shown, or vice versa."
|
|
1108 (interactive)
|
|
1109 (rmail-maybe-set-message-counters)
|
|
1110 (narrow-to-region (rmail-msgbeg rmail-current-message) (point-max))
|
|
1111 (let ((buffer-read-only nil))
|
|
1112 (goto-char (point-min))
|
|
1113 (forward-line 1)
|
|
1114 (if (= (following-char) ?1)
|
|
1115 (progn (delete-char 1)
|
|
1116 (insert ?0)
|
|
1117 (forward-line 1)
|
|
1118 (let ((case-fold-search t))
|
|
1119 (while (looking-at "Summary-Line:\\|Mail-From:")
|
|
1120 (forward-line 1)))
|
|
1121 (insert "*** EOOH ***\n")
|
|
1122 (forward-char -1)
|
|
1123 (search-forward "\n*** EOOH ***\n")
|
|
1124 (forward-line -1)
|
|
1125 (let ((temp (point)))
|
|
1126 (and (search-forward "\n\n" nil t)
|
|
1127 (delete-region temp (point))))
|
|
1128 (goto-char (point-min))
|
|
1129 (search-forward "\n*** EOOH ***\n")
|
|
1130 (narrow-to-region (point) (point-max)))
|
|
1131 (rmail-reformat-message (point-min) (point-max)))))
|
|
1132
|
|
1133 ;;;; *** Rmail Attributes and Keywords ***
|
|
1134
|
|
1135 ;; Make a string describing current message's attributes and keywords
|
|
1136 ;; and set it up as the name of a minor mode
|
|
1137 ;; so it will appear in the mode line.
|
|
1138 (defun rmail-display-labels ()
|
|
1139 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
|
|
1140 (save-excursion
|
|
1141 (unwind-protect
|
|
1142 (progn
|
|
1143 (widen)
|
|
1144 (goto-char (rmail-msgbeg rmail-current-message))
|
|
1145 (forward-line 1)
|
|
1146 (if (looking-at "[01],")
|
|
1147 (progn
|
|
1148 (narrow-to-region (point) (progn (end-of-line) (point)))
|
|
1149 ;; Truly valid BABYL format requires a space before each
|
|
1150 ;; attribute or keyword name. Put them in if missing.
|
|
1151 (let (buffer-read-only)
|
|
1152 (goto-char (point-min))
|
|
1153 (while (search-forward "," nil t)
|
|
1154 (or (looking-at "[ ,]") (eobp)
|
|
1155 (insert " "))))
|
|
1156 (goto-char (point-max))
|
|
1157 (if (search-backward ",," nil 'move)
|
|
1158 (progn
|
|
1159 (if (> (point) (1+ (point-min)))
|
|
1160 (setq blurb (buffer-substring (+ 1 (point-min)) (point))))
|
|
1161 (if (> (- (point-max) (point)) 2)
|
|
1162 (setq blurb
|
|
1163 (concat blurb
|
|
1164 ";"
|
|
1165 (buffer-substring (+ (point) 3)
|
|
1166 (1- (point-max)))))))))))
|
|
1167 ;; Note: we don't use save-restriction because that does not work right
|
|
1168 ;; if changes are made outside the saved restriction
|
|
1169 ;; before that restriction is restored.
|
|
1170 (narrow-to-region beg end)
|
|
1171 (set-marker beg nil)
|
|
1172 (set-marker end nil)))
|
|
1173 (while (string-match " +," blurb)
|
|
1174 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
|
|
1175 (substring blurb (match-end 0)))))
|
|
1176 (while (string-match ", +" blurb)
|
|
1177 (setq blurb (concat (substring blurb 0 (match-beginning 0)) ","
|
|
1178 (substring blurb (match-end 0)))))
|
|
1179 (setq mode-line-process
|
|
1180 (format " %d/%d%s" rmail-current-message rmail-total-messages
|
|
1181 blurb))))
|
|
1182
|
|
1183 ;; Turn an attribute of a message on or off according to STATE.
|
|
1184 ;; ATTR is the name of the attribute, as a string.
|
|
1185 ;; MSGNUM is message number to change; nil means current message.
|
|
1186 (defun rmail-set-attribute (attr state &optional msgnum)
|
|
1187 (let ((omax (point-max-marker))
|
|
1188 (omin (point-min-marker))
|
|
1189 (buffer-read-only nil))
|
|
1190 (or msgnum (setq msgnum rmail-current-message))
|
|
1191 (if (> msgnum 0)
|
|
1192 (unwind-protect
|
|
1193 (save-excursion
|
|
1194 (widen)
|
|
1195 (goto-char (+ 3 (rmail-msgbeg msgnum)))
|
|
1196 (let ((curstate
|
|
1197 (not
|
|
1198 (null (search-backward (concat ", " attr ",")
|
|
1199 (prog1 (point) (end-of-line)) t)))))
|
|
1200 (or (eq curstate (not (not state)))
|
|
1201 (if curstate
|
|
1202 (delete-region (point) (1- (match-end 0)))
|
|
1203 (beginning-of-line)
|
|
1204 (forward-char 2)
|
|
1205 (insert " " attr ","))))
|
|
1206 (if (string= attr "deleted")
|
|
1207 (rmail-set-message-deleted-p msgnum state)))
|
|
1208 ;; Note: we don't use save-restriction because that does not work right
|
|
1209 ;; if changes are made outside the saved restriction
|
|
1210 ;; before that restriction is restored.
|
|
1211 (narrow-to-region omin omax)
|
|
1212 (set-marker omin nil)
|
|
1213 (set-marker omax nil)
|
|
1214 (if (= msgnum rmail-current-message)
|
|
1215 (rmail-display-labels))))))
|
|
1216
|
|
1217 ;; Return t if the attributes/keywords line of msg number MSG
|
|
1218 ;; contains a match for the regexp LABELS.
|
|
1219 (defun rmail-message-labels-p (msg labels)
|
|
1220 (save-excursion
|
|
1221 (save-restriction
|
|
1222 (widen)
|
|
1223 (goto-char (rmail-msgbeg msg))
|
|
1224 (forward-char 3)
|
|
1225 (re-search-backward labels (prog1 (point) (end-of-line)) t))))
|
|
1226
|
|
1227 ;;;; *** Rmail Message Selection And Support ***
|
|
1228
|
|
1229 (defun rmail-msgend (n)
|
|
1230 (marker-position (aref rmail-message-vector (1+ n))))
|
|
1231
|
|
1232 (defun rmail-msgbeg (n)
|
|
1233 (marker-position (aref rmail-message-vector n)))
|
|
1234
|
|
1235 (defun rmail-widen-to-current-msgbeg (function)
|
|
1236 "Call FUNCTION with point at start of internal data of current message.
|
|
1237 Assumes that bounds were previously narrowed to display the message in Rmail.
|
|
1238 The bounds are widened enough to move point where desired, then narrowed
|
|
1239 again afterward.
|
|
1240
|
|
1241 FUNCTION may not change the visible text of the message, but it may
|
|
1242 change the invisible header text."
|
|
1243 (save-excursion
|
|
1244 (let ((obeg (- (point-max) (point-min))))
|
|
1245 (unwind-protect
|
|
1246 (progn
|
|
1247 (narrow-to-region (rmail-msgbeg rmail-current-message)
|
|
1248 (point-max))
|
|
1249 (goto-char (point-min))
|
|
1250 (funcall function))
|
|
1251 ;; Note: we don't use save-restriction because that does not work right
|
|
1252 ;; if changes are made outside the saved restriction
|
|
1253 ;; before that restriction is restored.
|
|
1254 ;; Here we assume that changes made by FUNCTION
|
|
1255 ;; occur before the visible region of the message.
|
|
1256 (narrow-to-region (- (point-max) obeg) (point-max))))))
|
|
1257
|
|
1258 (defun rmail-forget-messages ()
|
|
1259 (unwind-protect
|
|
1260 (if (vectorp rmail-message-vector)
|
|
1261 (let* ((i 0)
|
|
1262 (v rmail-message-vector)
|
|
1263 (n (length v)))
|
|
1264 (while (< i n)
|
|
1265 (move-marker (aref v i) nil)
|
|
1266 (setq i (1+ i)))))
|
|
1267 (setq rmail-message-vector nil)
|
|
1268 (setq rmail-deleted-vector nil)))
|
|
1269
|
|
1270 (defun rmail-maybe-set-message-counters ()
|
|
1271 (if (not (and rmail-deleted-vector
|
|
1272 rmail-message-vector
|
|
1273 rmail-current-message
|
|
1274 rmail-total-messages))
|
|
1275 (rmail-set-message-counters)))
|
|
1276
|
|
1277 (defun rmail-count-new-messages (&optional nomsg)
|
|
1278 (let* ((case-fold-search nil)
|
|
1279 (total-messages 0)
|
|
1280 (messages-head nil)
|
|
1281 (deleted-head nil))
|
|
1282 (or nomsg (message "Counting new messages..."))
|
|
1283 (goto-char (point-max))
|
|
1284 ;; Put at the end of messages-head
|
|
1285 ;; the entry for message N+1, which marks
|
|
1286 ;; the end of message N. (N = number of messages).
|
|
1287 (search-backward "\n\^_")
|
|
1288 (forward-char 1)
|
|
1289 (setq messages-head (list (point-marker)))
|
|
1290 (rmail-set-message-counters-counter (point-min))
|
|
1291 (setq rmail-current-message (1+ rmail-total-messages))
|
|
1292 (setq rmail-total-messages
|
|
1293 (+ rmail-total-messages total-messages))
|
|
1294 (setq rmail-message-vector
|
|
1295 (vconcat rmail-message-vector (cdr messages-head)))
|
|
1296 (aset rmail-message-vector
|
|
1297 rmail-current-message (car messages-head))
|
|
1298 (setq rmail-deleted-vector
|
|
1299 (concat rmail-deleted-vector deleted-head))
|
|
1300 (setq rmail-summary-vector
|
|
1301 (vconcat rmail-summary-vector (make-vector total-messages nil)))
|
|
1302 (goto-char (point-min))
|
|
1303 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
|
|
1304
|
|
1305 (defun rmail-set-message-counters ()
|
|
1306 (rmail-forget-messages)
|
|
1307 (save-excursion
|
|
1308 (save-restriction
|
|
1309 (widen)
|
|
1310 (let* ((point-save (point))
|
|
1311 (total-messages 0)
|
|
1312 (messages-after-point)
|
|
1313 (case-fold-search nil)
|
|
1314 (messages-head nil)
|
|
1315 (deleted-head nil))
|
|
1316 (message "Counting messages...")
|
|
1317 (goto-char (point-max))
|
|
1318 ;; Put at the end of messages-head
|
|
1319 ;; the entry for message N+1, which marks
|
|
1320 ;; the end of message N. (N = number of messages).
|
|
1321 (search-backward "\n\^_")
|
|
1322 (forward-char 1)
|
|
1323 (setq messages-head (list (point-marker)))
|
|
1324 (rmail-set-message-counters-counter (min (point) point-save))
|
|
1325 (setq messages-after-point total-messages)
|
|
1326 (rmail-set-message-counters-counter)
|
|
1327 (setq rmail-total-messages total-messages)
|
|
1328 (setq rmail-current-message
|
|
1329 (min total-messages
|
|
1330 (max 1 (- total-messages messages-after-point))))
|
|
1331 (setq rmail-message-vector
|
|
1332 (apply 'vector (cons (point-min-marker) messages-head))
|
|
1333 rmail-deleted-vector (concat "D" deleted-head)
|
|
1334 rmail-summary-vector (make-vector rmail-total-messages nil))
|
|
1335 (message "Counting messages...done")))))
|
|
1336
|
|
1337 (defun rmail-set-message-counters-counter (&optional stop)
|
|
1338 (while (search-backward "\n\^_\^L\n" stop t)
|
|
1339 (forward-char 1)
|
|
1340 (setq messages-head (cons (point-marker) messages-head))
|
|
1341 (save-excursion
|
|
1342 (setq deleted-head
|
|
1343 (cons (if (search-backward ", deleted,"
|
|
1344 (prog1 (point)
|
|
1345 (forward-line 2))
|
|
1346 t)
|
|
1347 ?D ?\ )
|
|
1348 deleted-head)))
|
|
1349 (if (zerop (% (setq total-messages (1+ total-messages)) 20))
|
|
1350 (message "Counting messages...%d" total-messages))))
|
|
1351
|
|
1352 (defun rmail-beginning-of-message ()
|
|
1353 "Show current message starting from the beginning."
|
|
1354 (interactive)
|
|
1355 (rmail-show-message rmail-current-message))
|
|
1356
|
|
1357 (defun rmail-show-message (&optional n)
|
|
1358 "Show message number N (prefix argument), counting from start of file.
|
|
1359 If summary buffer is currently displayed, update current message there also."
|
|
1360 (interactive "p")
|
|
1361 (rmail-maybe-set-message-counters)
|
|
1362 (widen)
|
|
1363 (if (zerop rmail-total-messages)
|
|
1364 (progn (narrow-to-region (point-min) (1- (point-max)))
|
|
1365 (goto-char (point-min))
|
|
1366 (setq mode-line-process nil))
|
|
1367 (let (blurb)
|
|
1368 (if (not n)
|
|
1369 (setq n rmail-current-message)
|
|
1370 (cond ((<= n 0)
|
|
1371 (setq n 1
|
|
1372 rmail-current-message 1
|
|
1373 blurb "No previous message"))
|
|
1374 ((> n rmail-total-messages)
|
|
1375 (setq n rmail-total-messages
|
|
1376 rmail-current-message rmail-total-messages
|
|
1377 blurb "No following message"))
|
|
1378 (t
|
|
1379 (setq rmail-current-message n))))
|
|
1380 (let ((beg (rmail-msgbeg n))
|
|
1381 (end (rmail-msgend n)))
|
|
1382 (goto-char beg)
|
|
1383 (forward-line 1)
|
|
1384 (if (= (following-char) ?0)
|
|
1385 (progn
|
|
1386 (rmail-reformat-message beg end)
|
|
1387 (rmail-set-attribute "unseen" nil))
|
|
1388 (search-forward "\n*** EOOH ***\n" end t)
|
|
1389 (narrow-to-region (point) end))
|
|
1390 (goto-char (point-min))
|
|
1391 (rmail-display-labels)
|
|
1392 (run-hooks 'rmail-show-message-hook)
|
|
1393 ;; If there is a summary buffer, try to move to this message
|
|
1394 ;; in that buffer. But don't complain if this message
|
|
1395 ;; is not mentioned in the summary.
|
|
1396 (if (rmail-summary-exists)
|
|
1397 (let ((curr-msg rmail-current-message))
|
|
1398 (rmail-select-summary
|
|
1399 (rmail-summary-goto-msg curr-msg t t))))
|
|
1400 (if blurb
|
|
1401 (message blurb))))))
|
|
1402
|
|
1403 (defun rmail-next-message (n)
|
|
1404 "Show following message whether deleted or not.
|
|
1405 With prefix arg N, moves forward N messages, or backward if N is negative."
|
|
1406 (interactive "p")
|
|
1407 (rmail-maybe-set-message-counters)
|
|
1408 (rmail-show-message (+ rmail-current-message n)))
|
|
1409
|
|
1410 (defun rmail-previous-message (n)
|
|
1411 "Show previous message whether deleted or not.
|
|
1412 With prefix arg N, moves backward N messages, or forward if N is negative."
|
|
1413 (interactive "p")
|
|
1414 (rmail-next-message (- n)))
|
|
1415
|
|
1416 (defun rmail-next-undeleted-message (n)
|
|
1417 "Show following non-deleted message.
|
|
1418 With prefix arg N, moves forward N non-deleted messages,
|
|
1419 or backward if N is negative.
|
|
1420
|
|
1421 Returns t if a new message is being shown, nil otherwise."
|
|
1422 (interactive "p")
|
|
1423 (rmail-maybe-set-message-counters)
|
|
1424 (let ((lastwin rmail-current-message)
|
|
1425 (current rmail-current-message))
|
|
1426 (while (and (> n 0) (< current rmail-total-messages))
|
|
1427 (setq current (1+ current))
|
|
1428 (if (not (rmail-message-deleted-p current))
|
|
1429 (setq lastwin current n (1- n))))
|
|
1430 (while (and (< n 0) (> current 1))
|
|
1431 (setq current (1- current))
|
|
1432 (if (not (rmail-message-deleted-p current))
|
|
1433 (setq lastwin current n (1+ n))))
|
|
1434 (if (/= lastwin rmail-current-message)
|
|
1435 (progn (rmail-show-message lastwin)
|
|
1436 t)
|
|
1437 (if (< n 0)
|
|
1438 (message "No previous nondeleted message"))
|
|
1439 (if (> n 0)
|
|
1440 (message "No following nondeleted message"))
|
|
1441 nil)))
|
|
1442
|
|
1443 (defun rmail-previous-undeleted-message (n)
|
|
1444 "Show previous non-deleted message.
|
|
1445 With prefix argument N, moves backward N non-deleted messages,
|
|
1446 or forward if N is negative."
|
|
1447 (interactive "p")
|
|
1448 (rmail-next-undeleted-message (- n)))
|
|
1449
|
|
1450 (defun rmail-first-message ()
|
|
1451 "Show first message in file."
|
|
1452 (interactive)
|
|
1453 (rmail-maybe-set-message-counters)
|
|
1454 (rmail-show-message 1))
|
|
1455
|
|
1456 (defun rmail-last-message ()
|
|
1457 "Show last message in file."
|
|
1458 (interactive)
|
|
1459 (rmail-maybe-set-message-counters)
|
|
1460 (rmail-show-message rmail-total-messages))
|
|
1461
|
|
1462 (defun rmail-what-message ()
|
|
1463 (let ((where (point))
|
|
1464 (low 1)
|
|
1465 (high rmail-total-messages)
|
|
1466 (mid (/ rmail-total-messages 2)))
|
|
1467 (while (> (- high low) 1)
|
|
1468 (if (>= where (rmail-msgbeg mid))
|
|
1469 (setq low mid)
|
|
1470 (setq high mid))
|
|
1471 (setq mid (+ low (/ (- high low) 2))))
|
|
1472 (if (>= where (rmail-msgbeg high)) high low)))
|
|
1473
|
|
1474 (defun rmail-message-recipients-p (msg recipients &optional primary-only)
|
|
1475 (save-restriction
|
|
1476 (goto-char (rmail-msgbeg msg))
|
|
1477 (search-forward "\n*** EOOH ***\n")
|
|
1478 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
|
|
1479 (or (string-match recipients (or (mail-fetch-field "To") ""))
|
|
1480 (string-match recipients (or (mail-fetch-field "From") ""))
|
|
1481 (if (not primary-only)
|
|
1482 (string-match recipients (or (mail-fetch-field "Cc") ""))))))
|
|
1483
|
|
1484 (defun rmail-message-regexp-p (msg regexp)
|
|
1485 "Return t, if for message number MSG, regexp REGEXP matches in the header."
|
|
1486 (goto-char (rmail-msgbeg msg))
|
|
1487 (let ((end
|
|
1488 (save-excursion
|
|
1489 (search-forward "*** EOOH ***" (point-max)) (point))))
|
|
1490 (re-search-forward regexp end t)))
|
|
1491
|
|
1492 (defvar rmail-search-last-regexp nil) ; jwz: moved this up
|
|
1493 (defun rmail-search-backward (regexp &optional n)
|
|
1494 "Show message containing next match for REGEXP.
|
|
1495 Prefix argument gives repeat count; negative argument means search
|
|
1496 backwards (through earlier messages).
|
|
1497 Interactively, empty argument means use same regexp used last time."
|
|
1498 (interactive
|
|
1499 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
|
|
1500 (prompt
|
|
1501 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
|
|
1502 regexp)
|
|
1503 (if rmail-search-last-regexp
|
|
1504 (setq prompt (concat prompt
|
|
1505 "(default "
|
|
1506 rmail-search-last-regexp
|
|
1507 ") ")))
|
|
1508 (setq regexp (read-string prompt))
|
|
1509 (cond ((not (equal regexp ""))
|
|
1510 (setq rmail-search-last-regexp regexp))
|
|
1511 ((not rmail-search-last-regexp)
|
|
1512 (error "No previous Rmail search string")))
|
|
1513 (list rmail-search-last-regexp
|
|
1514 (prefix-numeric-value current-prefix-arg))))
|
|
1515 (rmail-search regexp (- n)))
|
|
1516
|
|
1517 (defun rmail-search (regexp &optional n)
|
|
1518 "Show message containing next match for REGEXP.
|
|
1519 Prefix argument gives repeat count; negative argument means search
|
|
1520 backwards (through earlier messages).
|
|
1521 Interactively, empty argument means use same regexp used last time."
|
|
1522 (interactive
|
|
1523 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
|
|
1524 (prompt
|
|
1525 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
|
|
1526 regexp)
|
|
1527 (if rmail-search-last-regexp
|
|
1528 (setq prompt (concat prompt
|
|
1529 "(default "
|
|
1530 rmail-search-last-regexp
|
|
1531 ") ")))
|
|
1532 (setq regexp (read-string prompt))
|
|
1533 (cond ((not (equal regexp ""))
|
|
1534 (setq rmail-search-last-regexp regexp))
|
|
1535 ((not rmail-search-last-regexp)
|
|
1536 (error "No previous Rmail search string")))
|
|
1537 (list rmail-search-last-regexp
|
|
1538 (prefix-numeric-value current-prefix-arg))))
|
|
1539 (or n (setq n 1))
|
|
1540 (message "%sRmail search for %s..."
|
|
1541 (if (< n 0) "Reverse " "")
|
|
1542 regexp)
|
|
1543 (rmail-maybe-set-message-counters)
|
|
1544 (let ((omin (point-min))
|
|
1545 (omax (point-max))
|
|
1546 (opoint (point))
|
|
1547 win
|
|
1548 (reversep (< n 0))
|
|
1549 (msg rmail-current-message))
|
|
1550 (unwind-protect
|
|
1551 (progn
|
|
1552 (widen)
|
|
1553 (while (/= n 0)
|
|
1554 ;; Check messages one by one, advancing message number up or down
|
|
1555 ;; but searching forward through each message.
|
|
1556 (if reversep
|
|
1557 (while (and (null win) (> msg 1))
|
|
1558 (goto-char (rmail-msgbeg (setq msg (1- msg))))
|
|
1559 (setq win (re-search-forward
|
|
1560 regexp (rmail-msgend msg) t)))
|
|
1561 (while (and (null win) (< msg rmail-total-messages))
|
|
1562 (goto-char (rmail-msgbeg (setq msg (1+ msg))))
|
|
1563 (setq win (re-search-forward regexp (rmail-msgend msg) t))))
|
|
1564 (setq n (+ n (if reversep 1 -1)))))
|
|
1565 (if win
|
|
1566 (progn
|
|
1567 ;; If this is a reverse search and we found a message,
|
|
1568 ;; search backward thru this message to position point.
|
|
1569 (if reversep
|
|
1570 (progn
|
|
1571 (goto-char (rmail-msgend msg))
|
|
1572 (re-search-backward
|
|
1573 regexp (rmail-msgbeg msg) t)))
|
|
1574 (setq win (point))
|
|
1575 (rmail-show-message msg)
|
|
1576 (message "%sRmail search for %s...done"
|
|
1577 (if reversep "Reverse " "")
|
|
1578 regexp)
|
|
1579 (goto-char win))
|
|
1580 (goto-char opoint)
|
|
1581 (narrow-to-region omin omax)
|
|
1582 (ding)
|
|
1583 (message "Search failed: %s" regexp)))))
|
|
1584
|
|
1585 (defun rmail-search-backwards (regexp &optional n)
|
|
1586 "Show message containing previous match for REGEXP.
|
|
1587 Prefix argument gives repeat count; negative argument means search
|
|
1588 forward (through later messages).
|
|
1589 Interactively, empty argument means use same regexp used last time."
|
|
1590 (interactive
|
|
1591 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
|
|
1592 (prompt
|
|
1593 (concat (if reversep "Reverse " "") "Rmail search (regexp): "))
|
|
1594 regexp)
|
|
1595 (if rmail-search-last-regexp
|
|
1596 (setq prompt (concat prompt
|
|
1597 "(default "
|
|
1598 rmail-search-last-regexp
|
|
1599 ") ")))
|
|
1600 (setq regexp (read-string prompt))
|
|
1601 (cond ((not (equal regexp ""))
|
|
1602 (setq rmail-search-last-regexp regexp))
|
|
1603 ((not rmail-search-last-regexp)
|
|
1604 (error "No previous Rmail search string")))
|
|
1605 (list rmail-search-last-regexp
|
|
1606 (prefix-numeric-value current-prefix-arg))))
|
|
1607 (rmail-search regexp (- (or n -1))))
|
|
1608
|
|
1609 ;; Show the first message which has the `unseen' attribute.
|
|
1610 (defun rmail-first-unseen-message ()
|
|
1611 (rmail-maybe-set-message-counters)
|
|
1612 (let ((current 1)
|
|
1613 found)
|
|
1614 (save-restriction
|
|
1615 (widen)
|
|
1616 (while (and (not found) (< current rmail-total-messages))
|
|
1617 (if (rmail-message-labels-p current ", ?\\(unseen\\),")
|
|
1618 (setq found current))
|
|
1619 (setq current (1+ current))))
|
|
1620 ;; Let the caller show the message.
|
|
1621 ;; (if found
|
|
1622 ;; (rmail-show-message found))
|
|
1623 found))
|
|
1624
|
|
1625 ;;;; *** Rmail Message Deletion Commands ***
|
|
1626
|
|
1627 (defun rmail-message-deleted-p (n)
|
|
1628 (= (aref rmail-deleted-vector n) ?D))
|
|
1629
|
|
1630 (defun rmail-set-message-deleted-p (n state)
|
|
1631 (aset rmail-deleted-vector n (if state ?D ?\ )))
|
|
1632
|
|
1633 (defun rmail-delete-message ()
|
|
1634 "Delete this message and stay on it."
|
|
1635 (interactive)
|
|
1636 (rmail-set-attribute "deleted" t))
|
|
1637
|
|
1638 (defun rmail-undelete-previous-message ()
|
|
1639 "Back up to deleted message, select it, and undelete it."
|
|
1640 (interactive)
|
|
1641 (let ((msg rmail-current-message))
|
|
1642 (while (and (> msg 0)
|
|
1643 (not (rmail-message-deleted-p msg)))
|
|
1644 (setq msg (1- msg)))
|
|
1645 (if (= msg 0)
|
|
1646 (error "No previous deleted message")
|
|
1647 (if (/= msg rmail-current-message)
|
|
1648 (rmail-show-message msg))
|
|
1649 (rmail-set-attribute "deleted" nil)
|
|
1650 (if (rmail-summary-exists)
|
|
1651 (save-excursion
|
|
1652 (set-buffer rmail-summary-buffer)
|
|
1653 (rmail-summary-mark-undeleted msg)))
|
|
1654 (rmail-maybe-display-summary))))
|
|
1655
|
|
1656 (defun rmail-delete-forward (&optional backward)
|
|
1657 "Delete this message and move to next nondeleted one.
|
|
1658 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
|
|
1659 With prefix argument, delete and move backward.
|
|
1660
|
|
1661 Returns t if a new message is displayed after the delete, or nil otherwise."
|
|
1662 (interactive "P")
|
|
1663 (rmail-set-attribute "deleted" t)
|
|
1664 (let ((del-msg rmail-current-message))
|
|
1665 (if (rmail-summary-exists)
|
|
1666 (save-excursion
|
|
1667 (set-buffer rmail-summary-buffer)
|
|
1668 (rmail-summary-mark-deleted del-msg)))
|
|
1669 (prog1 (rmail-next-undeleted-message (if backward -1 1))
|
|
1670 (rmail-maybe-display-summary))))
|
|
1671
|
|
1672 (defun rmail-delete-backward ()
|
|
1673 "Delete this message and move to previous nondeleted one.
|
|
1674 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
|
|
1675 (interactive)
|
|
1676 (rmail-delete-forward t))
|
|
1677
|
|
1678 (defun rmail-only-expunge ()
|
|
1679 "Actually erase all deleted messages in the file."
|
|
1680 (interactive)
|
|
1681 (message "Expunging deleted messages...")
|
|
1682 ;; Discard all undo records for this buffer.
|
|
1683 (or (eq buffer-undo-list t)
|
|
1684 (setq buffer-undo-list nil))
|
|
1685 (rmail-maybe-set-message-counters)
|
|
1686 (let* ((omax (- (buffer-size) (point-max)))
|
|
1687 (omin (- (buffer-size) (point-min)))
|
|
1688 (opoint (if (and (> rmail-current-message 0)
|
|
1689 (= ?D (aref rmail-deleted-vector rmail-current-message)))
|
|
1690 0 (- (point) (point-min))))
|
|
1691 (messages-head (cons (aref rmail-message-vector 0) nil))
|
|
1692 (messages-tail messages-head)
|
|
1693 ;; Don't make any undo records for the expunging.
|
|
1694 (buffer-undo-list t)
|
|
1695 (win))
|
|
1696 (unwind-protect
|
|
1697 (save-excursion
|
|
1698 (widen)
|
|
1699 (goto-char (point-min))
|
|
1700 (let ((counter 0)
|
|
1701 (number 1)
|
|
1702 (total rmail-total-messages)
|
|
1703 (new-message-number rmail-current-message)
|
|
1704 (new-summary nil)
|
|
1705 (buffer-read-only nil)
|
|
1706 (messages rmail-message-vector)
|
|
1707 (deleted rmail-deleted-vector)
|
|
1708 (summary rmail-summary-vector))
|
|
1709 (setq rmail-total-messages nil
|
|
1710 rmail-current-message nil
|
|
1711 rmail-message-vector nil
|
|
1712 rmail-deleted-vector nil
|
|
1713 rmail-summary-vector nil)
|
|
1714 (while (<= number total)
|
|
1715 (if (= (aref deleted number) ?D)
|
|
1716 (progn
|
|
1717 (delete-region
|
|
1718 (marker-position (aref messages number))
|
|
1719 (marker-position (aref messages (1+ number))))
|
|
1720 (move-marker (aref messages number) nil)
|
|
1721 (if (> new-message-number counter)
|
|
1722 (setq new-message-number (1- new-message-number))))
|
|
1723 (setq counter (1+ counter))
|
|
1724 (setq messages-tail
|
|
1725 (setcdr messages-tail
|
|
1726 (cons (aref messages number) nil)))
|
|
1727 (setq new-summary
|
|
1728 (cons (if (= counter number) (aref summary (1- number)))
|
|
1729 new-summary)))
|
|
1730 (if (zerop (% (setq number (1+ number)) 20))
|
|
1731 (message "Expunging deleted messages...%d" number)))
|
|
1732 (setq messages-tail
|
|
1733 (setcdr messages-tail
|
|
1734 (cons (aref messages number) nil)))
|
|
1735 (setq rmail-current-message new-message-number
|
|
1736 rmail-total-messages counter
|
|
1737 rmail-message-vector (apply 'vector messages-head)
|
|
1738 rmail-deleted-vector (make-string (1+ counter) ?\ )
|
|
1739 rmail-summary-vector (vconcat (nreverse new-summary))
|
|
1740 win t)))
|
|
1741 (message "Expunging deleted messages...done")
|
|
1742 (if (not win)
|
|
1743 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
|
|
1744 (rmail-show-message
|
|
1745 (if (zerop rmail-current-message) 1 nil))
|
|
1746 (forward-char opoint))))
|
|
1747
|
|
1748 (defun rmail-expunge ()
|
|
1749 "Erase deleted messages from Rmail file and summary buffer."
|
|
1750 (interactive)
|
|
1751 (rmail-only-expunge)
|
|
1752 (if (rmail-summary-exists)
|
|
1753 (rmail-select-summary
|
|
1754 (rmail-update-summary))))
|
|
1755
|
|
1756 ;;;; *** Rmail Mailing Commands ***
|
|
1757
|
|
1758 (defun rmail-start-mail (&rest args)
|
|
1759 (if (and window-system rmail-mail-new-frame)
|
|
1760 (prog1
|
|
1761 (apply 'mail-other-frame args)
|
|
1762 (modify-frame-parameters (selected-frame)
|
|
1763 '((dedicated . t))))
|
|
1764 (apply 'mail-other-window args)))
|
|
1765
|
|
1766 (defun rmail-mail ()
|
|
1767 "Send mail in another window.
|
|
1768 While composing the message, use \\[mail-yank-original] to yank the
|
|
1769 original message into it."
|
|
1770 (interactive)
|
|
1771 (rmail-start-mail nil nil nil nil nil (current-buffer)))
|
|
1772
|
|
1773 (defun rmail-continue ()
|
|
1774 "Continue composing outgoing message previously being composed."
|
|
1775 (interactive)
|
|
1776 (rmail-start-mail t))
|
|
1777
|
|
1778 (defun rmail-reply (just-sender)
|
|
1779 "Reply to the current message.
|
|
1780 Normally include CC: to all other recipients of original message;
|
|
1781 prefix argument means ignore them. While composing the reply,
|
|
1782 use \\[mail-yank-original] to yank the original message into it."
|
|
1783 (interactive "P")
|
|
1784 (let (from reply-to cc subject date to message-id resent-reply-to)
|
|
1785 (save-excursion
|
|
1786 (save-restriction
|
|
1787 (widen)
|
|
1788 (goto-char (rmail-msgbeg rmail-current-message))
|
|
1789 (forward-line 1)
|
|
1790 (if (= (following-char) ?0)
|
|
1791 (narrow-to-region
|
|
1792 (progn (forward-line 2)
|
|
1793 (point))
|
|
1794 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message)
|
|
1795 'move)
|
|
1796 (point)))
|
|
1797 (narrow-to-region (point)
|
|
1798 (progn (search-forward "\n*** EOOH ***\n")
|
|
1799 (beginning-of-line) (point))))
|
|
1800 (setq resent-reply-to (mail-fetch-field "resent-reply-to" t)
|
|
1801 from (mail-fetch-field "from")
|
|
1802 reply-to (or resent-reply-to
|
|
1803 (mail-fetch-field "reply-to" nil t)
|
|
1804 from)
|
|
1805 cc (cond (just-sender nil)
|
|
1806 (resent-reply-to (mail-fetch-field "resent-cc" t))
|
|
1807 (t (mail-fetch-field "cc" nil t)))
|
|
1808 subject (or (and resent-reply-to
|
|
1809 (mail-fetch-field "resent-subject" t))
|
|
1810 (mail-fetch-field "subject"))
|
|
1811 date (cond (resent-reply-to
|
|
1812 (mail-fetch-field "resent-date" t))
|
|
1813 ((mail-fetch-field "date")))
|
|
1814 to (cond (resent-reply-to
|
|
1815 (mail-fetch-field "resent-to" t))
|
|
1816 ((mail-fetch-field "to" nil t))
|
|
1817 ;((mail-fetch-field "apparently-to")) ack gag barf
|
|
1818 (t ""))
|
|
1819 message-id (cond (resent-reply-to
|
|
1820 (mail-fetch-field "resent-message-id" t))
|
|
1821 ((mail-fetch-field "message-id"))))))
|
|
1822 (and (stringp subject)
|
|
1823 (or (string-match (concat "\\`" (regexp-quote rmail-reply-prefix))
|
|
1824 subject)
|
|
1825 (setq subject (concat rmail-reply-prefix subject))))
|
|
1826 (rmail-start-mail nil
|
|
1827 (mail-strip-quoted-names reply-to)
|
|
1828 subject
|
|
1829 (rmail-make-in-reply-to-field from date message-id)
|
|
1830 (if just-sender
|
|
1831 nil
|
|
1832 (let* ((cc-list (rmail-dont-reply-to
|
|
1833 (mail-strip-quoted-names
|
|
1834 (if (null cc) to (concat to ", " cc))))))
|
|
1835 (if (string= cc-list "") nil cc-list)))
|
|
1836 (current-buffer)
|
|
1837 (list (list '(lambda (buf msgnum)
|
|
1838 (save-excursion
|
|
1839 (set-buffer buf)
|
|
1840 (rmail-set-attribute "answered" t msgnum)))
|
|
1841 (current-buffer) rmail-current-message)))))
|
|
1842
|
|
1843 (defun rmail-make-in-reply-to-field (from date message-id)
|
|
1844 (cond ((not from)
|
|
1845 (if message-id
|
|
1846 message-id
|
|
1847 nil))
|
|
1848 (mail-use-rfc822
|
|
1849 (require 'rfc822)
|
|
1850 (let ((tem (car (rfc822-addresses from))))
|
|
1851 (if message-id
|
|
1852 (if (string-match
|
|
1853 (regexp-quote (if (string-match "@[^@]*\\'" tem)
|
|
1854 (substring tem 0 (match-beginning 0))
|
|
1855 tem))
|
|
1856 message-id)
|
|
1857 ;; Message-ID is sufficiently informative
|
|
1858 message-id
|
|
1859 (concat message-id " (" tem ")"))
|
|
1860 ;; Use prin1 to fake RFC822 quoting
|
|
1861 (let ((field (prin1-to-string tem)))
|
|
1862 (if date
|
|
1863 (concat field "'s message of " date)
|
|
1864 field)))))
|
|
1865 ((let* ((foo "[^][\000-\037\177-\377()<>@,;:\\\" ]+")
|
|
1866 (bar "[^][\000-\037\177-\377()<>@,;:\\\"]+"))
|
|
1867 ;; Can't use format because format loses on \000 (unix *^&%*^&%$!!)
|
|
1868 (or (string-match (concat "\\`[ \t]*\\(" bar
|
|
1869 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
|
|
1870 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
|
|
1871 from)
|
|
1872 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
|
|
1873 bar "\\))[ \t]*\\'")
|
|
1874 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
|
|
1875 from)))
|
|
1876 (let ((start (match-beginning 1))
|
|
1877 (end (match-end 1)))
|
|
1878 ;; Trim whitespace which above regexp match allows
|
|
1879 (while (and (< start end)
|
|
1880 (memq (aref from start) '(?\t ?\ )))
|
|
1881 (setq start (1+ start)))
|
|
1882 (while (and (< start end)
|
|
1883 (memq (aref from (1- end)) '(?\t ?\ )))
|
|
1884 (setq end (1- end)))
|
|
1885 (let ((field (substring from start end)))
|
|
1886 (if date (setq field (concat "message from " field " on " date)))
|
|
1887 (if message-id
|
|
1888 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
|
|
1889 (concat message-id " (" field ")")
|
|
1890 field))))
|
|
1891 (t
|
|
1892 ;; If we can't kludge it simply, do it correctly
|
|
1893 (let ((mail-use-rfc822 t))
|
|
1894 (rmail-make-in-reply-to-field from date message-id)))))
|
|
1895
|
|
1896 (defun rmail-forward (resend)
|
|
1897 "Forward the current message to another user.
|
|
1898 With prefix argument, \"resend\" the message instead of forwarding it;
|
|
1899 see the documentation of `rmail-resend'."
|
|
1900 (interactive "P")
|
|
1901 (if resend
|
|
1902 (call-interactively 'rmail-resend)
|
|
1903 (let ((forward-buffer (current-buffer))
|
|
1904 (subject (concat "["
|
|
1905 (let ((from (or (mail-fetch-field "From")
|
|
1906 (mail-fetch-field ">From"))))
|
|
1907 (if from
|
|
1908 (concat (mail-strip-quoted-names from) ": ")
|
|
1909 ""))
|
|
1910 (or (mail-fetch-field "Subject") "")
|
|
1911 "]")))
|
|
1912 ;; If only one window, use it for the mail buffer.
|
|
1913 ;; Otherwise, use another window for the mail buffer
|
|
1914 ;; so that the Rmail buffer remains visible
|
|
1915 ;; and sending the mail will get back to it.
|
|
1916 (if (funcall (if (and (not rmail-mail-new-frame) (one-window-p t))
|
|
1917 (function mail)
|
|
1918 (function rmail-start-mail))
|
|
1919 nil nil subject nil nil nil
|
|
1920 (list (list (function (lambda (buf msgnum)
|
|
1921 (save-excursion
|
|
1922 (set-buffer buf)
|
|
1923 (rmail-set-attribute
|
|
1924 "forwarded" t msgnum))))
|
|
1925 (current-buffer)
|
|
1926 rmail-current-message)))
|
|
1927 (save-excursion
|
|
1928 ;; Insert after header separator--before signature if any.
|
|
1929 (goto-char (point-min))
|
|
1930 (search-forward-regexp
|
|
1931 (concat "^" (regexp-quote mail-header-separator)))
|
|
1932 (forward-line 1)
|
|
1933 (insert-buffer forward-buffer))))))
|
|
1934
|
|
1935 (defun rmail-resend (address &optional from comment mail-alias-file)
|
|
1936 "Resend current message to ADDRESSES.
|
|
1937 ADDRESSES should be a single address, a a string consisting of several
|
|
1938 addresses separated by commas, or a list of addresses.
|
|
1939
|
|
1940 Optional FROM is the address to resend the message from, and
|
|
1941 defaults to the username of the person redistributing the message.
|
|
1942 Optional COMMENT is a string that will be inserted as a comment in the
|
|
1943 resent message.
|
|
1944 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
|
|
1945 typically for purposes of moderating a list."
|
|
1946 (interactive "sResend to: ")
|
|
1947 (require 'sendmail)
|
|
1948 ;;(require 'mailalias)
|
|
1949 (if (not from) (setq from (user-login-name)))
|
|
1950 (let ((tembuf (generate-new-buffer " sendmail temp"))
|
|
1951 (mail-header-separator "")
|
|
1952 (case-fold-search nil)
|
|
1953 (mailbuf (current-buffer)))
|
|
1954 (unwind-protect
|
|
1955 (save-excursion
|
|
1956 ;;>> Copy message into temp buffer
|
|
1957 (set-buffer tembuf)
|
|
1958 (insert-buffer-substring mailbuf)
|
|
1959 (goto-char (point-min))
|
|
1960 ;; Delete any Sender field, since that's not specifyable.
|
|
1961 (if (re-search-forward "^Sender:" nil t)
|
|
1962 (let (beg)
|
|
1963 (beginning-of-line)
|
|
1964 (setq beg (point))
|
|
1965 (forward-line 1)
|
|
1966 (while (looking-at "[ \t]")
|
|
1967 (forward-line 1))
|
|
1968 (delete-region beg (point))))
|
|
1969 ;;>> Insert resent-from:
|
|
1970 (insert "Resent-From: " from "\n")
|
|
1971 (insert "Resent-Date: " (mail-rfc822-date) "\n")
|
|
1972 ;;>> Insert resent-to: and bcc if need be.
|
|
1973 (progn ;;let ((before (point)))
|
|
1974 (if mail-self-blind
|
|
1975 (insert "Resent-Bcc: " (user-login-name) "\n"))
|
|
1976 (insert "Resent-To: " (if (stringp address)
|
|
1977 address
|
|
1978 (mapconcat 'identity address ",\n\t"))
|
|
1979 "\n")
|
|
1980 ;; lose this loser. -jwz
|
|
1981 ;;(expand-mail-aliases before (point))
|
|
1982 )
|
|
1983 ;;>> Set up comment, if any.
|
|
1984 (if (and (sequencep comment) (not (zerop (length comment))))
|
|
1985 (let ((before (point))
|
|
1986 after)
|
|
1987 (insert comment)
|
|
1988 (or (eolp) (insert "\n"))
|
|
1989 (setq after (point))
|
|
1990 (goto-char before)
|
|
1991 (while (< (point) after)
|
|
1992 (insert "Resent-Comment: ")
|
|
1993 (forward-line 1))))
|
|
1994 ;; Don't expand aliases in the destination fields
|
|
1995 ;; of the original message.
|
|
1996 (let (mail-aliases)
|
|
1997 (sendmail-send-it)))
|
|
1998 (kill-buffer tembuf))
|
|
1999 (rmail-set-attribute "resent" t rmail-current-message)))
|
|
2000
|
|
2001 (defvar mail-unsent-separator
|
|
2002 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
|
|
2003 "^ *---+ +Returned message +---+ *$\\|"
|
|
2004 "^ *---+ +Original message +---+ *$\\|"
|
|
2005 "^ *--+ +begin message +--+ *$\\|"
|
|
2006 "^ *---+ +Original message follows +---+ *$\\|"
|
|
2007 "^|? *---+ +Message text follows: +---+ *|?$"))
|
|
2008
|
|
2009 (defun rmail-retry-failure ()
|
|
2010 "Edit a mail message which is based on the contents of the current message.
|
|
2011 For a message rejected by the mail system, extract the interesting headers and
|
|
2012 the body of the original message; otherwise copy the current message."
|
|
2013 (interactive)
|
|
2014 (require 'mail-utils)
|
|
2015 (let (to subj irp2 cc orig-message)
|
|
2016 (save-excursion
|
|
2017 ;; Narrow down to just the quoted original message
|
|
2018 (rmail-beginning-of-message)
|
|
2019 (let ((case-fold-search t))
|
|
2020 (or (re-search-forward mail-unsent-separator nil t)
|
|
2021 (error "Cannot parse this as a failure message")))
|
|
2022 (save-restriction
|
|
2023 (narrow-to-region (point) (point-max))
|
|
2024 ;; Now mail-fetch-field will get from headers of the original message,
|
|
2025 ;; not from the headers of the rejection.
|
|
2026 (setq to (mail-fetch-field "To")
|
|
2027 subj (mail-fetch-field "Subject")
|
|
2028 irp2 (mail-fetch-field "In-reply-to")
|
|
2029 cc (mail-fetch-field "Cc"))
|
|
2030 ;; Get the entire text (not headers) of the original message.
|
|
2031 (setq orig-message
|
|
2032 (buffer-substring
|
|
2033 (progn (search-forward "\n\n") (point))
|
|
2034 (point-max)))))
|
|
2035 ;; Start sending a new message; default header fields from the original.
|
|
2036 ;; Turn off the usual actions for initializing the message body
|
|
2037 ;; because we want to get only the text from the failure message.
|
|
2038 (let (mail-signature
|
|
2039 (mail-setup-hook rmail-retry-setup-hook))
|
|
2040 (if (rmail-start-mail nil to subj irp2 cc (current-buffer))
|
|
2041 ;; Insert original text as initial text of new draft message.
|
|
2042 (progn
|
|
2043 (goto-char (point-max))
|
|
2044 (insert orig-message)
|
|
2045 (goto-char (point-min))
|
|
2046 (end-of-line))))))
|
|
2047
|
|
2048 (defun rmail-bury ()
|
|
2049 "Bury current Rmail buffer and its summary buffer."
|
|
2050 (interactive)
|
|
2051 (let ((rmail-buffer (current-buffer)))
|
|
2052 (if (rmail-summary-exists)
|
|
2053 (let (window)
|
|
2054 (while (setq window (get-buffer-window rmail-summary-buffer))
|
|
2055 (set-window-buffer window (other-buffer rmail-summary-buffer)))
|
|
2056 (bury-buffer rmail-summary-buffer)))
|
|
2057 (switch-to-buffer (other-buffer (current-buffer)))
|
|
2058 (bury-buffer rmail-buffer)))
|
|
2059
|
|
2060 (defun rmail-summary-exists ()
|
|
2061 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
|
|
2062 Non-nil value returned is the summary buffer."
|
|
2063 (and rmail-summary-buffer (buffer-name rmail-summary-buffer)
|
|
2064 rmail-summary-buffer))
|
|
2065
|
|
2066 (defun rmail-summary-displayed ()
|
|
2067 "t iff in RMAIL buffer and an associated summary buffer is displayed."
|
|
2068 (and (rmail-summary-exists) (get-buffer-window rmail-summary-buffer)))
|
|
2069
|
|
2070 (defvar rmail-redisplay-summary nil
|
|
2071 "*Non-nil means Rmail should show the summary when it changes.
|
|
2072 This has an effect only if a summary buffer exists.")
|
|
2073
|
|
2074 ;; Put the summary buffer back on the screen, if user wants that.
|
|
2075 (defun rmail-maybe-display-summary ()
|
|
2076 (and (rmail-summary-exists)
|
|
2077 rmail-redisplay-summary
|
|
2078 (display-buffer rmail-summary-buffer)))
|
|
2079
|
|
2080 ;;;; *** Rmail Specify Inbox Files ***
|
|
2081
|
|
2082 (autoload 'set-rmail-inbox-list "rmailmsc"
|
|
2083 "Set the inbox list of the current RMAIL file to FILE-NAME.
|
|
2084 This may be a list of file names separated by commas.
|
|
2085 If FILE-NAME is empty, remove any inbox list."
|
|
2086 t)
|
|
2087
|
|
2088 ;;;; *** Rmail Commands for Labels ***
|
|
2089
|
|
2090 (autoload 'rmail-add-label "rmailkwd"
|
|
2091 "Add LABEL to labels associated with current RMAIL message.
|
|
2092 Completion is performed over known labels when reading."
|
|
2093 t)
|
|
2094
|
|
2095 (autoload 'rmail-kill-label "rmailkwd"
|
|
2096 "Remove LABEL from labels associated with current RMAIL message.
|
|
2097 Completion is performed over known labels when reading."
|
|
2098 t)
|
|
2099
|
|
2100 (autoload 'rmail-next-labeled-message "rmailkwd"
|
|
2101 "Show next message with LABEL. Defaults to last label used.
|
|
2102 With prefix argument N moves forward N messages with this label."
|
|
2103 t)
|
|
2104
|
|
2105 (autoload 'rmail-previous-labeled-message "rmailkwd"
|
|
2106 "Show previous message with LABEL. Defaults to last label used.
|
|
2107 With prefix argument N moves backward N messages with this label."
|
|
2108 t)
|
|
2109
|
|
2110 (autoload 'rmail-read-label "rmailkwd"
|
|
2111 "PROMPT and read with completion an Rmail message label."
|
|
2112 t)
|
|
2113
|
|
2114 ;;;; *** Rmail Edit Mode ***
|
|
2115
|
|
2116 (autoload 'rmail-edit-current-message "rmailedit"
|
|
2117 "Edit the contents of the current message"
|
|
2118 t)
|
|
2119
|
|
2120 ;;;; *** Rmail Sorting ***
|
|
2121
|
|
2122 (autoload 'rmail-sort-by-date "rmailsort"
|
|
2123 "Sort messages of current Rmail file by date.
|
|
2124 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
|
|
2125
|
|
2126 (autoload 'rmail-sort-by-subject "rmailsort"
|
|
2127 "Sort messages of current Rmail file by subject.
|
|
2128 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
|
|
2129
|
|
2130 (autoload 'rmail-sort-by-author "rmailsort"
|
|
2131 "Sort messages of current Rmail file by author.
|
|
2132 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
|
|
2133
|
|
2134 (autoload 'rmail-sort-by-recipient "rmailsort"
|
|
2135 "Sort messages of current Rmail file by recipient.
|
|
2136 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
|
|
2137
|
|
2138 (autoload 'rmail-sort-by-correspondent "rmailsort"
|
|
2139 "Sort messages of current Rmail file by other correspondent.
|
|
2140 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
|
|
2141
|
|
2142 (autoload 'rmail-sort-by-lines "rmailsort"
|
|
2143 "Sort messages of current Rmail file by number of lines.
|
|
2144 If prefix argument REVERSE is non-nil, sort them in reverse order." t)
|
|
2145
|
|
2146 ;;;; *** Rmail Summary Mode ***
|
|
2147
|
|
2148 (autoload 'rmail-summary "rmailsum"
|
|
2149 "Display a summary of all messages, one line per message."
|
|
2150 t)
|
|
2151
|
|
2152 (autoload 'rmail-summary-by-labels "rmailsum"
|
|
2153 "Display a summary of all messages with one or more LABELS.
|
|
2154 LABELS should be a string containing the desired labels, separated by commas."
|
|
2155 t)
|
|
2156
|
|
2157 (autoload 'rmail-summary-by-recipients "rmailsum"
|
|
2158 "Display a summary of all messages with the given RECIPIENTS.
|
|
2159 Normally checks the To, From and Cc fields of headers; but if PRIMARY-ONLY
|
|
2160 is non-nil (prefix arg given), only look in the To and From fields.
|
|
2161 RECIPIENTS is a string of regexps separated by commas."
|
|
2162 t)
|
|
2163
|
|
2164 (autoload 'rmail-summary-by-regexp "rmailsum"
|
|
2165 "Display a summary of all messages according to regexp REGEXP.
|
|
2166 If the regular expression is found in the header of the message
|
|
2167 \(including in the date and other lines, as well as the subject line),
|
|
2168 Emacs will list the header line in the RMAIL-summary."
|
|
2169 t)
|
|
2170
|
|
2171 (autoload 'rmail-summary-by-topic "rmailsum"
|
|
2172 "Display a summary of all messages with the given SUBJECT.
|
|
2173 Normally checks the Subject field of headers;
|
|
2174 but if WHOLE-MESSAGE is non-nil (prefix arg given),
|
|
2175 look in the whole message.
|
|
2176 SUBJECT is a string of regexps separated by commas."
|
|
2177 t)
|
|
2178
|
|
2179 ;;;; *** Rmail output messages to files ***
|
|
2180
|
|
2181 (autoload 'rmail-output-to-rmail-file "rmailout"
|
|
2182 "Append the current message to an Rmail file named FILE-NAME.
|
|
2183 If the file does not exist, ask if it should be created.
|
|
2184 If file is being visited, the message is appended to the Emacs
|
|
2185 buffer visiting that file."
|
|
2186 t)
|
|
2187
|
|
2188 (autoload 'rmail-output "rmailout"
|
|
2189 "Append this message to Unix mail file named FILE-NAME."
|
|
2190 t)
|
|
2191
|
|
2192 ;;;; *** Rmail undigestification ***
|
|
2193
|
|
2194 (autoload 'undigestify-rmail-message "undigest"
|
|
2195 "Break up a digest message into its constituent messages.
|
|
2196 Leaves original message, deleted, before the undigestified messages."
|
|
2197 t)
|
|
2198
|
|
2199 (provide 'rmail)
|
|
2200
|
|
2201 ;;; rmail.el ends here
|