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