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