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