1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software; you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation; either version 2, or (at your option)
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs; see the file COPYING. If not, write to the
23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
24 ;; Boston, MA 02110-1301, USA.
30 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
31 ;; New features include attribute and keyword support, message
32 ;; selection by dispatch table, summary by attributes and keywords,
33 ;; expunging by dispatch table, sticky options for file commands.
35 ;; Extended by Bob Weiner of Motorola
36 ;; New features include: rmail and rmail-summary buffers remain
37 ;; synchronized and key bindings basically operate the same way in both
38 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
39 ;; variable, and a bury rmail buffer (wipe) command.
43 (eval-when-compile (require 'mule-util
)) ; for detect-coding-with-priority
46 (defvar font-lock-fontified
)
47 (defvar mail-abbrev-syntax-table
)
49 (defvar messages-head
)
50 (defvar rmail-use-spam-filter
)
52 (defvar rsf-sleep-after-message
)
53 (defvar total-messages
)
55 ; These variables now declared in paths.el.
56 ;(defvar rmail-spool-directory "/usr/spool/mail/"
57 ; "This is the name of the directory used by the system mailer for\n\
58 ;delivering new mail. Its name should end with a slash.")
59 ;(defvar rmail-file-name
60 ; (expand-file-name "~/RMAIL")
64 "Mail reader for Emacs."
67 (defgroup rmail-retrieve nil
68 "Rmail retrieval options."
72 (defgroup rmail-files nil
77 (defgroup rmail-headers nil
78 "Rmail header options."
82 (defgroup rmail-reply nil
83 "Rmail reply options."
87 (defgroup rmail-summary nil
88 "Rmail summary options."
90 :prefix
"rmail-summary-"
93 (defgroup rmail-output nil
94 "Output message to a file."
95 :prefix
"rmail-output-"
99 (defgroup rmail-edit nil
101 :prefix
"rmail-edit-"
104 (defgroup rmail-obsolete nil
105 "Rmail obsolete customization variables."
108 (defcustom rmail-movemail-program nil
109 "If non-nil, the file name of the `movemail' program."
110 :group
'rmail-retrieve
111 :type
'(choice (const nil
) string
))
113 (defcustom rmail-pop-password nil
114 "*Password to use when reading mail from POP server.
115 Please use `rmail-remote-password' instead."
116 :type
'(choice (string :tag
"Password")
117 (const :tag
"Not Required" nil
))
118 :group
'rmail-obsolete
)
120 (defcustom rmail-pop-password-required nil
121 "*Non-nil if a password is required when reading mail from a POP server.
122 Please use rmail-remote-password-required instead."
124 :group
'rmail-obsolete
)
126 (defcustom rmail-remote-password nil
127 "*Password to use when reading mail from a remote server.
128 This setting is ignored for mailboxes whose URL already contains a password."
129 :type
'(choice (string :tag
"Password")
130 (const :tag
"Not Required" nil
))
131 :set-after
'(rmail-pop-password)
132 :set
#'(lambda (symbol value
)
135 (boundp 'rmail-pop-password
)
139 (setq rmail-pop-password nil
))
140 :group
'rmail-retrieve
143 (defcustom rmail-remote-password-required nil
144 "*Non-nil if a password is required when reading mail from a remote server."
146 :set-after
'(rmail-pop-password-required)
147 :set
#'(lambda (symbol value
)
150 (boundp 'rmail-pop-password-required
)
151 rmail-pop-password-required
)
152 rmail-pop-password-required
154 (setq rmail-pop-password-required nil
))
155 :group
'rmail-retrieve
158 (defcustom rmail-movemail-flags nil
159 "*List of flags to pass to movemail.
160 Most commonly used to specify `-g' to enable GSS-API authentication
161 or `-k' to enable Kerberos authentication."
162 :type
'(repeat string
)
163 :group
'rmail-retrieve
166 (defvar rmail-remote-password-error
"invalid usercode or password\\|
167 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
168 "Regular expression matching incorrect-password POP or IMAP server error
170 If you get an incorrect-password error that this expression does not match,
171 please report it with \\[report-emacs-bug].")
173 (defvar rmail-encoded-remote-password nil
)
175 (defcustom rmail-preserve-inbox nil
176 "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
178 :group
'rmail-retrieve
)
180 (defcustom rmail-movemail-search-path nil
181 "*List of directories to search for movemail (in addition to `exec-path')."
182 :group
'rmail-retrieve
183 :type
'(repeat (directory)))
185 (defun rmail-probe (prog)
186 "Determine what flavor of movemail PROG is.
187 We do this by executing it with `--version' and analyzing its output."
189 (let ((tbuf (current-buffer)))
190 (buffer-disable-undo tbuf
)
191 (call-process prog nil tbuf nil
"--version")
192 (if (not (buffer-modified-p tbuf
))
193 ;; Should not happen...
195 (goto-char (point-min))
197 ((looking-at ".*movemail: invalid option")
198 'emacs
) ;; Possibly...
199 ((looking-at "movemail (GNU Mailutils .*)")
205 (defun rmail-autodetect ()
206 "Determine and return the file name of the `movemail' program.
207 If `rmail-movemail-program' is non-nil, use it.
208 Otherwise, look for `movemail' in the directories in
209 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
210 (if rmail-movemail-program
211 (rmail-probe rmail-movemail-program
)
213 (dolist (dir (append rmail-movemail-search-path exec-path
214 (list exec-directory
)))
215 (when (and dir
(file-accessible-directory-p dir
))
216 (let ((progname (expand-file-name "movemail" dir
)))
217 (when (and (not (file-directory-p progname
))
218 (file-executable-p progname
))
219 (let ((x (rmail-probe progname
)))
221 (setq rmail-movemail-program progname
)
222 (throw 'scan x
))))))))))
224 (defvar rmail-movemail-variant-in-use nil
225 "The movemail variant currently in use. Known variants are:
227 `emacs' Means any implementation, compatible with the native Emacs one.
229 `mailutils' Means GNU mailutils implementation, capable of handling full
230 mail URLs as the source mailbox;")
233 (defun rmail-movemail-variant-p (&rest variants
)
234 "Return t if the current movemail variant is any of VARIANTS.
235 Currently known variants are 'emacs and 'mailutils."
236 (when (not rmail-movemail-variant-in-use
)
238 (setq rmail-movemail-variant-in-use
(rmail-autodetect)))
239 (not (null (member rmail-movemail-variant-in-use variants
))))
242 (defcustom rmail-dont-reply-to-names nil
"\
243 *A regexp specifying addresses to prune from a reply message.
244 A value of nil means exclude your own email address as an address
245 plus whatever is specified by `rmail-default-dont-reply-to-names'."
246 :type
'(choice regexp
(const :tag
"Your Name" nil
))
250 (defvar rmail-default-dont-reply-to-names
"\\`info-" "\
251 A regular expression specifying part of the default value of the
252 variable `rmail-dont-reply-to-names', for when the user does not set
253 `rmail-dont-reply-to-names' explicitly. (The other part of the default
254 value is the user's email address and name.)
255 It is useful to set this variable in the site customization file.")
258 (defcustom rmail-ignored-headers
259 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
260 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
261 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
262 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
263 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
264 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
265 "\\|^content-transfer-encoding:\\|^x-coding-system:"
266 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
267 "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
268 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
269 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
270 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
271 "\\|^mbox-line:\\|^cancel-lock:"
272 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
275 "*Regexp to match header fields that Rmail should normally hide.
276 \(See also `rmail-nonignored-headers', which overrides this regexp.)
277 This variable is used for reformatting the message header,
278 which normally happens once for each message,
279 when you view the message for the first time in Rmail.
280 To make a change in this variable take effect
281 for a message that you have already viewed,
282 go to that message and type \\[rmail-toggle-header] twice."
284 :group
'rmail-headers
)
286 (defcustom rmail-nonignored-headers
"^x-spam-status:"
287 "*Regexp to match X header fields that Rmail should show.
288 This regexp overrides `rmail-ignored-headers'; if both this regexp
289 and that one match a certain header field, Rmail shows the field.
291 This variable is used for reformatting the message header,
292 which normally happens once for each message,
293 when you view the message for the first time in Rmail.
294 To make a change in this variable take effect
295 for a message that you have already viewed,
296 go to that message and type \\[rmail-toggle-header] twice."
298 :group
'rmail-headers
)
301 (defcustom rmail-displayed-headers nil
302 "*Regexp to match Header fields that Rmail should display.
303 If nil, display all header fields except those matched by
304 `rmail-ignored-headers'."
305 :type
'(choice regexp
(const :tag
"All"))
306 :group
'rmail-headers
)
309 (defcustom rmail-retry-ignored-headers
"^x-authentication-warning:" "\
310 *Headers that should be stripped when retrying a failed message."
311 :type
'(choice regexp
(const nil
:tag
"None"))
312 :group
'rmail-headers
)
315 (defcustom rmail-highlighted-headers
"^From:\\|^Subject:" "\
316 *Regexp to match Header fields that Rmail should normally highlight.
317 A value of nil means don't highlight.
318 See also `rmail-highlight-face'."
320 :group
'rmail-headers
)
323 (defcustom rmail-highlight-face nil
"\
324 *Face used by Rmail for highlighting headers."
325 :type
'(choice (const :tag
"Default" nil
)
327 :group
'rmail-headers
)
330 (defcustom rmail-delete-after-output nil
"\
331 *Non-nil means automatically delete a message that is copied to a file."
336 (defcustom rmail-primary-inbox-list nil
"\
337 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
338 nil means the default, which is (\"/usr/spool/mail/$USER\")
339 \(the name varies depending on the operating system,
340 and the value of the environment variable MAIL overrides it)."
341 ;; Don't use backquote here, because we don't want to need it
343 :type
(list 'choice
'(const :tag
"Default" nil
)
344 (list 'repeat
':value
(list (or (getenv "MAIL")
345 (concat "/var/spool/mail/"
348 :group
'rmail-retrieve
352 (defcustom rmail-mail-new-frame nil
353 "*Non-nil means Rmail makes a new frame for composing outgoing mail.
354 This is handy if you want to preserve the window configuration of
355 the frame where you have the RMAIL buffer displayed."
360 (defcustom rmail-secondary-file-directory
"~/"
361 "*Directory for additional secondary Rmail files."
365 (defcustom rmail-secondary-file-regexp
"\\.xmail$"
366 "*Regexp for which files are secondary Rmail files."
371 (defcustom rmail-confirm-expunge
'y-or-n-p
372 "*Whether and how to ask for confirmation before expunging deleted messages."
373 :type
'(choice (const :tag
"No confirmation" nil
)
374 (const :tag
"Confirm with y-or-n-p" y-or-n-p
)
375 (const :tag
"Confirm with yes-or-no-p" yes-or-no-p
))
380 (defvar rmail-mode-hook nil
381 "List of functions to call when Rmail is invoked.")
384 (defvar rmail-get-new-mail-hook nil
385 "List of functions to call when Rmail has retrieved new mail.")
388 (defcustom rmail-show-message-hook nil
389 "List of functions to call when Rmail displays a message."
391 :options
'(goto-address)
395 (defvar rmail-quit-hook nil
396 "List of functions to call when quitting out of Rmail.")
399 (defvar rmail-delete-message-hook nil
400 "List of functions to call when Rmail deletes a message.
401 When the hooks are called, the message has been marked deleted but is
402 still the current message in the Rmail buffer.")
404 ;; These may be altered by site-init.el to match the format of mmdf files
405 ;; delimiting used on a given host (delim1 and delim2 from the config
408 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
409 "Regexp marking the start of an mmdf message.")
410 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
411 "Regexp marking the end of an mmdf message.")
413 (defcustom rmail-message-filter nil
414 "If non-nil, a filter function for new messages in RMAIL.
415 Called with region narrowed to the message, including headers,
416 before obeying `rmail-ignored-headers'."
417 :group
'rmail-headers
420 (defcustom rmail-automatic-folder-directives nil
421 "List of directives specifying where to put a message.
422 Each element of the list is of the form:
424 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
426 Where FOLDERNAME is the name of a BABYL format folder to put the
427 message. If any of the field regexp's are nil, then it is ignored.
429 If FOLDERNAME is \"/dev/null\", it is deleted.
430 If FOLDERNAME is nil then it is deleted, and skipped.
432 FIELD is the plain text name of a field in the message, such as
433 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
434 all text from the \"cc\" field as well.
436 REGEXP is an expression to match in the preceeding specified FIELD.
437 FIELD/REGEXP pairs continue in the list.
440 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
441 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
444 :type
'(repeat (sexp :tag
"Directive")))
446 (defvar rmail-reply-prefix
"Re: "
447 "String to prepend to Subject line when replying to a message.")
449 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
450 ;; This pattern should catch all the common variants. The pattern
451 ;; also ignores mailing list identifiers sometimes added in square
452 ;; brackets at the beginning of subject lines.
453 (defvar rmail-reply-regexp
"\\`\\(\\[.+?\\] \\)?\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
454 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
456 (defcustom rmail-display-summary nil
457 "*If non-nil, Rmail always displays the summary buffer."
458 :group
'rmail-summary
461 (defvar rmail-inbox-list nil
)
462 (put 'rmail-inbox-list
'permanent-local t
)
464 (defvar rmail-keywords nil
)
465 (put 'rmail-keywords
'permanent-local t
)
467 (defvar rmail-buffer nil
468 "The RMAIL buffer related to the current buffer.
469 In an RMAIL buffer, this holds the RMAIL buffer itself.
470 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
471 (put 'rmail-buffer
'permanent-local t
)
473 ;; Message counters and markers. Deleted flags.
475 (defvar rmail-current-message nil
)
476 (put 'rmail-current-message
'permanent-local t
)
478 (defvar rmail-total-messages nil
)
479 (put 'rmail-total-messages
'permanent-local t
)
481 (defvar rmail-message-vector nil
)
482 (put 'rmail-message-vector
'permanent-local t
)
484 (defvar rmail-deleted-vector nil
)
485 (put 'rmail-deleted-vector
'permanent-local t
)
487 (defvar rmail-msgref-vector nil
488 "In an Rmail buffer, a vector whose Nth element is a list (N).
489 When expunging renumbers messages, these lists are modified
490 by substituting the new message number into the existing list.")
491 (put 'rmail-msgref-vector
'permanent-local t
)
493 (defvar rmail-overlay-list nil
)
494 (put 'rmail-overlay-list
'permanent-local t
)
496 ;; These are used by autoloaded rmail-summary.
498 (defvar rmail-summary-buffer nil
)
499 (put 'rmail-summary-buffer
'permanent-local t
)
500 (defvar rmail-summary-vector nil
)
501 (put 'rmail-summary-vector
'permanent-local t
)
503 (defvar rmail-view-buffer nil
504 "Buffer which holds RMAIL message for MIME displaying.")
505 (put 'rmail-view-buffer
'permanent-local t
)
507 ;; `Sticky' default variables.
509 ;; Last individual label specified to a or k.
510 (defvar rmail-last-label nil
)
511 (put 'rmail-last-label
'permanent-local t
)
513 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
514 (defvar rmail-last-multi-labels nil
)
516 (defvar rmail-last-regexp nil
)
517 (put 'rmail-last-regexp
'permanent-local t
)
519 (defcustom rmail-default-file
"~/xmail"
520 "*Default file name for \\[rmail-output]."
523 (defcustom rmail-default-rmail-file
"~/XMAIL"
524 "*Default file name for \\[rmail-output-to-rmail-file]."
527 (defcustom rmail-default-body-file
"~/mailout"
528 "*Default file name for \\[rmail-output-body-to-file]."
533 ;; Mule and MIME related variables.
536 (defvar rmail-file-coding-system nil
537 "Coding system used in RMAIL file.
539 This is set to nil by default.")
542 (defcustom rmail-enable-mime nil
543 "*If non-nil, RMAIL uses MIME feature.
544 If the value is t, RMAIL automatically shows MIME decoded message.
545 If the value is neither t nor nil, RMAIL does not show MIME decoded message
546 until a user explicitly requires it."
547 :type
'(choice (const :tag
"on" t
)
548 (const :tag
"off" nil
)
549 (other :tag
"when asked" ask
))
552 (defvar rmail-enable-mime-composing nil
553 "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
556 (defvar rmail-show-mime-function nil
557 "Function to show MIME decoded message of RMAIL file.
558 This function is called when `rmail-enable-mime' is non-nil.
559 It is called with no argument.")
562 (defvar rmail-insert-mime-forwarded-message-function nil
563 "Function to insert a message in MIME format so it can be forwarded.
564 This function is called if `rmail-enable-mime' or
565 `rmail-enable-mime-composing' is non-nil.
566 It is called with one argument FORWARD-BUFFER, which is a
567 buffer containing the message to forward. The current buffer
568 is the outgoing mail buffer.")
571 (defvar rmail-insert-mime-resent-message-function nil
572 "Function to insert a message in MIME format so it can be resent.
573 This function is called if `rmail-enable-mime' is non-nil.
574 It is called with one argument FORWARD-BUFFER, which is a
575 buffer containing the message to forward. The current buffer
576 is the outgoing mail buffer.")
579 (defvar rmail-search-mime-message-function nil
580 "Function to check if a regexp matches a MIME message.
581 This function is called if `rmail-enable-mime' is non-nil.
582 It is called with two arguments MSG and REGEXP, where
583 MSG is the message number, REGEXP is the regular expression.")
586 (defvar rmail-search-mime-header-function nil
587 "Function to check if a regexp matches a header of MIME message.
588 This function is called if `rmail-enable-mime' is non-nil.
589 It is called with three arguments MSG, REGEXP, and LIMIT, where
590 MSG is the message number,
591 REGEXP is the regular expression,
592 LIMIT is the position specifying the end of header.")
595 (defvar rmail-mime-feature
'rmail-mime
596 "Feature to require to load MIME support in Rmail.
597 When starting Rmail, if `rmail-enable-mime' is non-nil,
598 this feature is required with `require'.")
601 (defvar rmail-decode-mime-charset t
602 "*Non-nil means a message is decoded by MIME's charset specification.
603 If this variable is nil, or the message has not MIME specification,
604 the message is decoded as normal way.
606 If the variable `rmail-enable-mime' is non-nil, this variables is
607 ignored, and all the decoding work is done by a feature specified by
608 the variable `rmail-mime-feature'.")
611 (defvar rmail-mime-charset-pattern
612 "^content-type:[ ]*text/plain;[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?"
613 "Regexp to match MIME-charset specification in a header of message.
614 The first parenthesized expression should match the MIME-charset name.")
617 ;;; Regexp matching the delimiter of messages in UNIX mail format
618 ;;; (UNIX From lines), minus the initial ^. Note that if you change
619 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
620 ;;; that knows the exact ordering of the \\( \\) subexpressions.
621 (defvar rmail-unix-mail-delimiter
622 (let ((time-zone-regexp
623 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
624 "\\|[-+]?[0-9][0-9][0-9][0-9]"
630 ;; Many things can happen to an RFC 822 mailbox before it is put into
631 ;; a `From' line. The leading phrase can be stripped, e.g.
632 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
633 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
634 ;; can be removed, e.g.
635 ;; From: joe@y.z (Joe K
637 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
640 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
641 ;; The mailbox can be removed or be replaced by white space, e.g.
642 ;; From: "Joe User"{space}{tab}
644 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
645 ;; where {space} and {tab} represent the Ascii space and tab characters.
646 ;; We want to match the results of any of these manglings.
647 ;; The following regexp rejects names whose first characters are
648 ;; obviously bogus, but after that anything goes.
649 "\\([^\0-\b\n-\r\^?].*\\)? "
651 ;; The time the message was sent.
652 "\\([^\0-\r \^?]+\\) +" ; day of the week
653 "\\([^\0-\r \^?]+\\) +" ; month
654 "\\([0-3]?[0-9]\\) +" ; day of month
655 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
657 ;; Perhaps a time zone, specified by an abbreviation, or by a
662 " \\([0-9][0-9]+\\) *"
664 ;; On some systems the time zone can appear after the year, too.
668 "\\(remote from .*\\)?"
673 (defvar rmail-font-lock-keywords
674 ;; These are all matched case-insensitively.
676 (let* ((cite-chars "[>|}]")
678 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
679 (list '("^\\(From\\|Sender\\|Resent-From\\):"
680 . font-lock-function-name-face
)
681 '("^Reply-To:.*$" . font-lock-function-name-face
)
682 '("^Subject:" . font-lock-comment-face
)
683 '("^X-Spam-Status:" . font-lock-keyword-face
)
684 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
685 . font-lock-keyword-face
)
686 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
688 (,(concat "\\=[ \t]*"
689 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
690 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
692 (beginning-of-line) (end-of-line)
693 (1 font-lock-comment-delimiter-face nil t
)
694 (5 font-lock-comment-face nil t
)))
695 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
696 . font-lock-string-face
))))
697 "Additional expressions to highlight in Rmail mode.")
699 ;; Perform BODY in the summary buffer
700 ;; in such a way that its cursor is properly updated in its own window.
701 (defmacro rmail-select-summary
(&rest body
)
702 `(let ((total rmail-total-messages
))
703 (if (rmail-summary-displayed)
704 (let ((window (selected-window)))
708 (pop-to-buffer rmail-summary-buffer
)
709 ;; rmail-total-messages is a buffer-local var
710 ;; in the rmail buffer.
711 ;; This way we make it available for the body
712 ;; even tho the rmail buffer is not current.
713 (let ((rmail-total-messages total
))
715 (select-window window
))))
717 (set-buffer rmail-summary-buffer
)
718 (let ((rmail-total-messages total
))
720 (rmail-maybe-display-summary)))
722 ;;;; *** Rmail Mode ***
724 ;; This variable is dynamically bound. The defvar is here to placate
725 ;; the byte compiler.
727 (defvar rmail-enable-multibyte nil
)
730 (defun rmail-require-mime-maybe ()
731 "Require `rmail-mime-feature' if that is non-nil.
732 Signal an error and set `rmail-mime-feature' to nil if the feature
734 (when rmail-enable-mime
736 (require rmail-mime-feature
)
738 (message "Feature `%s' not provided" rmail-mime-feature
)
740 (setq rmail-enable-mime nil
)))))
744 (defun rmail (&optional file-name-arg
)
745 "Read and edit incoming mail.
746 Moves messages into file named by `rmail-file-name' (a babyl format file)
747 and edits that file in RMAIL Mode.
748 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
750 May be called with file name as argument; then performs rmail editing on
751 that file, but does not copy any new mail into the file.
752 Interactively, if you supply a prefix argument, then you
753 have a chance to specify a file name with the minibuffer.
755 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
756 (interactive (if current-prefix-arg
757 (list (read-file-name "Run rmail on RMAIL file: "))))
758 (rmail-require-mime-maybe)
759 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
760 ;; Use find-buffer-visiting, not get-file-buffer, for those users
761 ;; who have find-file-visit-truename set to t.
762 (existed (find-buffer-visiting file-name
))
763 ;; This binding is necessary because we must decide if we
764 ;; need code conversion while the buffer is unibyte
765 ;; (i.e. enable-multibyte-characters is nil).
766 (rmail-enable-multibyte
768 (with-current-buffer existed enable-multibyte-characters
)
769 (default-value 'enable-multibyte-characters
)))
770 ;; Since the file may contain messages of different encodings
771 ;; at the tail (non-BYBYL part), we can't decode them at once
772 ;; on reading. So, at first, we read the file without text
773 ;; code conversion, then decode the messages one by one by
774 ;; rmail-decode-babyl-format or
775 ;; rmail-convert-to-babyl-format.
776 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
777 run-mail-hook msg-shown
)
778 ;; Like find-file, but in the case where a buffer existed
779 ;; and the file was reverted, recompute the message-data.
780 ;; We used to bind enable-local-variables to nil here,
781 ;; but that should not be needed now that rmail-mode
782 ;; sets it locally to nil.
783 ;; (Binding a variable locally with let is not safe if it has
784 ;; buffer-local bindings.)
785 (if (and existed
(not (verify-visited-file-modtime existed
)))
787 (find-file file-name
)
788 (if (and (verify-visited-file-modtime existed
)
789 (eq major-mode
'rmail-mode
))
790 (progn (rmail-forget-messages)
791 (rmail-set-message-counters))))
793 (let ((enable-local-variables nil
))
794 (find-file-noselect file-name
))))
795 (if (eq major-mode
'rmail-edit-mode
)
796 (error "Exit Rmail Edit mode before getting new mail"))
797 (if (and existed
(> (buffer-size) 0))
798 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
799 (or (eq major-mode
'rmail-mode
)
800 (progn (rmail-mode-2)
801 (setq run-mail-hook t
)))
802 (setq run-mail-hook t
)
804 ;; Convert all or part to Babyl file if possible.
806 (goto-char (point-max)))
807 ;; As we have read a file by raw-text, the buffer is set to
808 ;; unibyte. We must make it multibyte if necessary.
809 (if (and rmail-enable-multibyte
810 (not enable-multibyte-characters
))
811 (set-buffer-multibyte t
))
812 ;; If necessary, scan to find all the messages.
813 (rmail-maybe-set-message-counters)
815 (unless (and (not file-name-arg
)
816 (rmail-get-new-mail))
817 (rmail-show-message (rmail-first-unseen-message)))
819 (if rmail-display-summary
(rmail-summary))
820 (rmail-construct-io-menu)
822 (run-hooks 'rmail-mode-hook
))))))
824 ;; Given the value of MAILPATH, return a list of inbox file names.
825 ;; This is turned off because it is not clear that the user wants
826 ;; all these inboxes to feed into the primary rmail file.
827 ; (defun rmail-convert-mailpath (string)
829 ; (while (setq idx (string-match "[%:]" string))
830 ; (let ((this (substring string 0 idx)))
831 ; (setq string (substring string (1+ idx)))
832 ; (setq list (cons (if (string-match "%" this)
833 ; (substring this 0 (string-match "%" this))
838 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
839 ; will not cause emacs 18.55 problems.
841 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
843 (defun rmail-convert-file ()
846 (goto-char (point-min))
847 ;; If file doesn't start like a Babyl file,
848 ;; convert it to one, by adding a header and converting each message.
849 (cond ((looking-at "BABYL OPTIONS:"))
850 ((looking-at "Version: 5\n")
851 ;; Losing babyl file made by old version of Rmail.
852 ;; Just fix the babyl file header; don't make a new one,
853 ;; so we don't lose the Labels: file attribute, etc.
854 (let ((buffer-read-only nil
))
855 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
856 ((equal (point-min) (point-max))
857 ;; Empty RMAIL file. Just insert the header.
858 (rmail-insert-rmail-file-header))
860 ;; Non-empty file in non-RMAIL format. Add header and convert.
862 (rmail-insert-rmail-file-header)))
863 ;; If file was not a Babyl file or if there are
864 ;; Unix format messages added at the end,
865 ;; convert file as necessary.
868 (goto-char (point-max))
869 (search-backward "\n\^_")
871 (looking-at "\n*From ")))
872 (let ((buffer-read-only nil
))
873 (message "Converting to Babyl format...")
874 ;; If file needs conversion, convert it all,
875 ;; except for the BABYL header.
876 ;; (rmail-convert-to-babyl-format would delete the header.)
877 (goto-char (point-min))
878 (search-forward "\n\^_" nil t
)
879 (narrow-to-region (point) (point-max))
880 (rmail-convert-to-babyl-format)
881 (message "Converting to Babyl format...done"))
882 (if (and (not rmail-enable-mime
)
883 rmail-enable-multibyte
)
884 ;; We still have to decode BABYL part.
885 (rmail-decode-babyl-format)))))
887 (defun rmail-insert-rmail-file-header ()
888 (let ((buffer-read-only nil
))
889 ;; -*-rmail-*- is here so that visiting the file normally
890 ;; recognizes it as an Rmail file.
891 (insert "BABYL OPTIONS: -*- rmail -*-
894 Note: This is the header of an rmail file.
895 Note: If you are seeing it in rmail,
896 Note: it means the file has no messages in it.\n\^_")))
898 ;; Decode Babyl formatted part at the head of current buffer by
899 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
901 (defun rmail-decode-babyl-format ()
902 (let ((modifiedp (buffer-modified-p))
903 (buffer-read-only nil
)
904 (coding-system rmail-file-coding-system
)
906 (goto-char (point-min))
907 (search-forward "\n\^_" nil t
) ; Skip BABYL header.
909 (goto-char (point-max))
910 (search-backward "\n\^_" from
'mv
)
912 (unless (and coding-system
913 (coding-system-p coding-system
))
915 ;; If rmail-file-coding-system is nil, Emacs 21 writes
916 ;; RMAIL files in emacs-mule, Emacs 22 in utf-8, but
917 ;; earlier versions did that with the current buffer's
918 ;; encoding. So we want to favor detection of emacs-mule
919 ;; (whose normal priority is quite low) and utf-8, but
920 ;; still allow detection of other encodings if they won't
921 ;; fit. The call to with-coding-priority below achieves
923 (with-coding-priority '(emacs-mule utf-8
)
924 (detect-coding-region from to
'highest
))))
925 (unless (eq (coding-system-type coding-system
) 'undecided
)
926 (set-buffer-modified-p t
) ; avoid locking when decoding
927 (let ((buffer-undo-list t
))
928 (decode-coding-region from to coding-system
))
929 (setq coding-system last-coding-system-used
))
930 (set-buffer-modified-p modifiedp
)
931 (setq buffer-file-coding-system nil
)
932 (setq save-buffer-coding-system
933 (or coding-system
'undecided
))))
935 (defvar rmail-mode-map nil
)
938 (setq rmail-mode-map
(make-keymap))
939 (suppress-keymap rmail-mode-map
)
940 (define-key rmail-mode-map
"a" 'rmail-add-label
)
941 (define-key rmail-mode-map
"b" 'rmail-bury
)
942 (define-key rmail-mode-map
"c" 'rmail-continue
)
943 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
944 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
945 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
946 (define-key rmail-mode-map
"f" 'rmail-forward
)
947 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
948 (define-key rmail-mode-map
"h" 'rmail-summary
)
949 (define-key rmail-mode-map
"i" 'rmail-input
)
950 (define-key rmail-mode-map
"j" 'rmail-show-message
)
951 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
952 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
953 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
954 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
955 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
956 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
957 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
958 (define-key rmail-mode-map
"m" 'rmail-mail
)
959 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
960 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
961 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
962 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
963 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
964 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
965 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
966 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
967 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
968 (define-key rmail-mode-map
"q" 'rmail-quit
)
969 (define-key rmail-mode-map
"r" 'rmail-reply
)
970 ;; I find I can't live without the default M-r command -- rms.
971 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
972 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
973 (define-key rmail-mode-map
"\es" 'rmail-search
)
974 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
975 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
976 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
977 (define-key rmail-mode-map
"x" 'rmail-expunge
)
978 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
979 (define-key rmail-mode-map
"/" 'rmail-end-of-message
)
980 (define-key rmail-mode-map
"<" 'rmail-first-message
)
981 (define-key rmail-mode-map
">" 'rmail-last-message
)
982 (define-key rmail-mode-map
" " 'scroll-up
)
983 (define-key rmail-mode-map
"\177" 'scroll-down
)
984 (define-key rmail-mode-map
"?" 'describe-mode
)
985 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
986 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
987 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
988 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
989 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
990 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
991 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
992 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
993 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
996 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
998 (define-key rmail-mode-map
[menu-bar classify
]
999 (cons "Classify" (make-sparse-keymap "Classify")))
1001 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1004 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1007 (define-key rmail-mode-map
[menu-bar classify output-body
]
1008 '("Output body to file..." . rmail-output-body-to-file
))
1010 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
1011 '("Output (inbox)..." . rmail-output
))
1013 (define-key rmail-mode-map
[menu-bar classify output
]
1014 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
1016 (define-key rmail-mode-map
[menu-bar classify kill-label
]
1017 '("Kill Label..." . rmail-kill-label
))
1019 (define-key rmail-mode-map
[menu-bar classify add-label
]
1020 '("Add Label..." . rmail-add-label
))
1022 (define-key rmail-mode-map
[menu-bar summary
]
1023 (cons "Summary" (make-sparse-keymap "Summary")))
1025 (define-key rmail-mode-map
[menu-bar summary senders
]
1026 '("By Senders..." . rmail-summary-by-senders
))
1028 (define-key rmail-mode-map
[menu-bar summary labels
]
1029 '("By Labels..." . rmail-summary-by-labels
))
1031 (define-key rmail-mode-map
[menu-bar summary recipients
]
1032 '("By Recipients..." . rmail-summary-by-recipients
))
1034 (define-key rmail-mode-map
[menu-bar summary topic
]
1035 '("By Topic..." . rmail-summary-by-topic
))
1037 (define-key rmail-mode-map
[menu-bar summary regexp
]
1038 '("By Regexp..." . rmail-summary-by-regexp
))
1040 (define-key rmail-mode-map
[menu-bar summary all
]
1041 '("All" . rmail-summary
))
1043 (define-key rmail-mode-map
[menu-bar mail
]
1044 (cons "Mail" (make-sparse-keymap "Mail")))
1046 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
1047 '("Get New Mail" . rmail-get-new-mail
))
1049 (define-key rmail-mode-map
[menu-bar mail lambda
]
1052 (define-key rmail-mode-map
[menu-bar mail continue
]
1053 '("Continue" . rmail-continue
))
1055 (define-key rmail-mode-map
[menu-bar mail resend
]
1056 '("Re-send..." . rmail-resend
))
1058 (define-key rmail-mode-map
[menu-bar mail forward
]
1059 '("Forward" . rmail-forward
))
1061 (define-key rmail-mode-map
[menu-bar mail retry
]
1062 '("Retry" . rmail-retry-failure
))
1064 (define-key rmail-mode-map
[menu-bar mail reply
]
1065 '("Reply" . rmail-reply
))
1067 (define-key rmail-mode-map
[menu-bar mail mail
]
1068 '("Mail" . rmail-mail
))
1070 (define-key rmail-mode-map
[menu-bar delete
]
1071 (cons "Delete" (make-sparse-keymap "Delete")))
1073 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
1074 '("Expunge/Save" . rmail-expunge-and-save
))
1076 (define-key rmail-mode-map
[menu-bar delete expunge
]
1077 '("Expunge" . rmail-expunge
))
1079 (define-key rmail-mode-map
[menu-bar delete undelete
]
1080 '("Undelete" . rmail-undelete-previous-message
))
1082 (define-key rmail-mode-map
[menu-bar delete delete
]
1083 '("Delete" . rmail-delete-forward
))
1085 (define-key rmail-mode-map
[menu-bar move
]
1086 (cons "Move" (make-sparse-keymap "Move")))
1088 (define-key rmail-mode-map
[menu-bar move search-back
]
1089 '("Search Back..." . rmail-search-backwards
))
1091 (define-key rmail-mode-map
[menu-bar move search
]
1092 '("Search..." . rmail-search
))
1094 (define-key rmail-mode-map
[menu-bar move previous
]
1095 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1097 (define-key rmail-mode-map
[menu-bar move next
]
1098 '("Next Nondeleted" . rmail-next-undeleted-message
))
1100 (define-key rmail-mode-map
[menu-bar move last
]
1101 '("Last" . rmail-last-message
))
1103 (define-key rmail-mode-map
[menu-bar move first
]
1104 '("First" . rmail-first-message
))
1106 (define-key rmail-mode-map
[menu-bar move previous
]
1107 '("Previous" . rmail-previous-message
))
1109 (define-key rmail-mode-map
[menu-bar move next
]
1110 '("Next" . rmail-next-message
))
1112 ;; Rmail mode is suitable only for specially formatted data.
1113 (put 'rmail-mode
'mode-class
'special
)
1115 (defun rmail-mode-kill-summary ()
1116 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1119 (defun rmail-mode ()
1120 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1121 All normal editing commands are turned off.
1122 Instead, these commands are available:
1124 \\[rmail-beginning-of-message] Move point to front of this message.
1125 \\[rmail-end-of-message] Move point to bottom of this message.
1126 \\[scroll-up] Scroll to next screen of this message.
1127 \\[scroll-down] Scroll to previous screen of this message.
1128 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1129 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1130 \\[rmail-next-message] Move to Next message whether deleted or not.
1131 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1132 \\[rmail-first-message] Move to the first message in Rmail file.
1133 \\[rmail-last-message] Move to the last message in Rmail file.
1134 \\[rmail-show-message] Jump to message specified by numeric position in file.
1135 \\[rmail-search] Search for string and show message it is found in.
1136 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1137 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1138 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1139 till a deleted message is found.
1140 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1141 \\[rmail-expunge] Expunge deleted messages.
1142 \\[rmail-expunge-and-save] Expunge and save the file.
1143 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1144 \\[save-buffer] Save without expunging.
1145 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1146 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1147 \\[rmail-continue] Continue composing outgoing message started before.
1148 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1149 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1150 \\[rmail-forward] Forward this message to another user.
1151 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
1152 \\[rmail-output] Output this message to a Unix-format mail file (append it).
1153 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1154 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1155 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1156 \\[rmail-kill-label] Kill label. Remove a label from current message.
1157 \\[rmail-next-labeled-message] Move to Next message with specified label
1158 (label defaults to last one specified).
1159 Standard labels: filed, unseen, answered, forwarded, deleted.
1160 Any other label is present only if you add it with \\[rmail-add-label].
1161 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1162 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1163 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1164 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1165 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1166 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1167 \\[rmail-toggle-header] Toggle display of complete header."
1169 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1171 (when (and finding-rmail-file
1172 (null coding-system-for-read
)
1173 default-enable-multibyte-characters
)
1174 (let ((rmail-enable-multibyte t
))
1175 (rmail-require-mime-maybe)
1176 (rmail-convert-file)
1177 (goto-char (point-max))
1178 (set-buffer-multibyte t
)))
1179 (rmail-set-message-counters)
1180 (rmail-show-message rmail-total-messages
)
1181 (when finding-rmail-file
1182 (when rmail-display-summary
1184 (rmail-construct-io-menu))
1185 (run-mode-hooks 'rmail-mode-hook
)))
1187 (defun rmail-mode-2 ()
1188 (kill-all-local-variables)
1190 (rmail-perm-variables)
1193 (defun rmail-mode-1 ()
1194 (setq major-mode
'rmail-mode
)
1195 (setq mode-name
"RMAIL")
1196 (setq buffer-read-only t
)
1197 ;; No need to auto save RMAIL files in normal circumstances
1198 ;; because they contain no info except attribute changes
1199 ;; and deletion of messages.
1200 ;; The one exception is when messages are copied into an Rmail mode buffer.
1201 ;; rmail-output-to-rmail-file enables auto save when you do that.
1202 (setq buffer-auto-save-file-name nil
)
1203 (setq mode-line-modified
"--")
1204 (use-local-map rmail-mode-map
)
1205 (set-syntax-table text-mode-syntax-table
)
1206 (setq local-abbrev-table text-mode-abbrev-table
))
1208 ;; Set up the permanent locals associated with an Rmail file.
1209 (defun rmail-perm-variables ()
1210 (make-local-variable 'rmail-last-label
)
1211 (make-local-variable 'rmail-last-regexp
)
1212 (make-local-variable 'rmail-deleted-vector
)
1213 (make-local-variable 'rmail-buffer
)
1214 (setq rmail-buffer
(current-buffer))
1215 (make-local-variable 'rmail-view-buffer
)
1216 (setq rmail-view-buffer rmail-buffer
)
1217 (make-local-variable 'rmail-summary-buffer
)
1218 (make-local-variable 'rmail-summary-vector
)
1219 (make-local-variable 'rmail-current-message
)
1220 (make-local-variable 'rmail-total-messages
)
1221 (make-local-variable 'rmail-overlay-list
)
1222 (setq rmail-overlay-list nil
)
1223 (make-local-variable 'rmail-message-vector
)
1224 (make-local-variable 'rmail-msgref-vector
)
1225 (make-local-variable 'rmail-inbox-list
)
1226 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
1227 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1228 (and (null rmail-inbox-list
)
1229 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1230 (equal buffer-file-truename
1231 (abbreviate-file-name (file-truename rmail-file-name
))))
1232 (setq rmail-inbox-list
1233 (or rmail-primary-inbox-list
1234 (list (or (getenv "MAIL")
1235 (concat rmail-spool-directory
1236 (user-login-name)))))))
1237 (make-local-variable 'rmail-keywords
)
1238 ;; this gets generated as needed
1239 (setq rmail-keywords nil
))
1241 ;; Set up the non-permanent locals associated with Rmail mode.
1242 (defun rmail-variables ()
1243 (make-local-variable 'save-buffer-coding-system
)
1244 ;; If we don't already have a value for save-buffer-coding-system,
1245 ;; get it from buffer-file-coding-system, and clear that
1246 ;; because it should be determined in rmail-show-message.
1247 (unless save-buffer-coding-system
1248 (setq save-buffer-coding-system
(or buffer-file-coding-system
'undecided
))
1249 (setq buffer-file-coding-system nil
))
1250 ;; Don't let a local variables list in a message cause confusion.
1251 (make-local-variable 'local-enable-local-variables
)
1252 (setq local-enable-local-variables nil
)
1253 (make-local-variable 'revert-buffer-function
)
1254 (setq revert-buffer-function
'rmail-revert
)
1255 (make-local-variable 'font-lock-defaults
)
1256 (setq font-lock-defaults
1257 '(rmail-font-lock-keywords
1259 (font-lock-maximum-size . nil
)
1260 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1261 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1262 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1263 (make-local-variable 'require-final-newline
)
1264 (setq require-final-newline nil
)
1265 (make-local-variable 'version-control
)
1266 (setq version-control
'never
)
1267 (make-local-variable 'kill-buffer-hook
)
1268 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1269 (make-local-variable 'file-precious-flag
)
1270 (setq file-precious-flag t
)
1271 (make-local-variable 'desktop-save-buffer
)
1272 (setq desktop-save-buffer t
))
1274 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1275 (defun rmail-revert (arg noconfirm
)
1276 (set-buffer rmail-buffer
)
1277 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1278 (rmail-enable-multibyte enable-multibyte-characters
)
1279 ;; See similar code in `rmail'.
1280 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
)))
1281 ;; Call our caller again, but this time it does the default thing.
1282 (if (revert-buffer arg noconfirm
)
1283 ;; If the user said "yes", and we changed something,
1284 ;; reparse the messages.
1286 (set-buffer rmail-buffer
)
1288 ;; Convert all or part to Babyl file if possible.
1289 (rmail-convert-file)
1290 ;; We have read the file as raw-text, so the buffer is set to
1291 ;; unibyte. Make it multibyte if necessary.
1292 (if (and rmail-enable-multibyte
1293 (not enable-multibyte-characters
))
1294 (set-buffer-multibyte t
))
1295 (goto-char (point-max))
1296 (rmail-set-message-counters)
1297 (rmail-show-message rmail-total-messages
)
1298 (run-hooks 'rmail-mode-hook
)))))
1300 ;; Return a list of files from this buffer's Mail: option.
1301 ;; Does not assume that messages have been parsed.
1302 ;; Just returns nil if buffer does not look like Babyl format.
1303 (defun rmail-parse-file-inboxes ()
1308 (cond ((looking-at "BABYL OPTIONS:")
1309 (search-forward "\n\^_" nil
'move
)
1310 (narrow-to-region 1 (point))
1312 (if (search-forward "\nMail:" nil t
)
1314 (narrow-to-region (point) (progn (end-of-line) (point)))
1315 (goto-char (point-min))
1316 (mail-parse-comma-list))))))))
1318 (defun rmail-expunge-and-save ()
1319 "Expunge and save RMAIL file."
1322 (set-buffer rmail-buffer
)
1324 (if (rmail-summary-exists)
1325 (rmail-select-summary (set-buffer-modified-p nil
))))
1327 (defun rmail-quit ()
1329 Hook `rmail-quit-hook' is run after expunging."
1331 (rmail-expunge-and-save)
1332 (when (boundp 'rmail-quit-hook
)
1333 (run-hooks 'rmail-quit-hook
))
1334 ;; Don't switch to the summary buffer even if it was recently visible.
1335 (when rmail-summary-buffer
1336 (replace-buffer-in-windows rmail-summary-buffer
)
1337 (bury-buffer rmail-summary-buffer
))
1338 (if rmail-enable-mime
1339 (let ((obuf rmail-buffer
)
1340 (ovbuf rmail-view-buffer
))
1341 (set-buffer rmail-view-buffer
)
1343 (replace-buffer-in-windows ovbuf
)
1344 (replace-buffer-in-windows obuf
)
1346 (let ((obuf (current-buffer)))
1348 (replace-buffer-in-windows obuf
))))
1350 (defun rmail-bury ()
1351 "Bury current Rmail buffer and its summary buffer."
1353 ;; This let var was called rmail-buffer, but that interfered
1354 ;; with the buffer-local var used in summary buffers.
1355 (let ((buffer-to-bury (current-buffer)))
1356 (if (rmail-summary-exists)
1358 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1359 (quit-window nil window
))
1360 (bury-buffer rmail-summary-buffer
)))
1363 (defun rmail-duplicate-message ()
1364 "Create a duplicated copy of the current message.
1365 The duplicate copy goes into the Rmail file just after the
1369 (let ((buffer-read-only nil
)
1370 (number rmail-current-message
)
1371 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
1372 (rmail-msgend rmail-current-message
))))
1373 (goto-char (rmail-msgend rmail-current-message
))
1375 (rmail-forget-messages)
1376 (rmail-show-message number
)
1377 (message "Message duplicated")))
1380 (defun rmail-input (filename)
1381 "Run Rmail on file FILENAME."
1382 (interactive "FRun rmail on RMAIL file: ")
1386 ;; This used to scan subdirectories recursively, but someone pointed out
1387 ;; that if the user wants that, person can put all the files in one dir.
1388 ;; And the recursive scan was slow. So I took it out.
1390 (defun rmail-find-all-files (start)
1391 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1392 (if (file-accessible-directory-p start
)
1394 (let* ((case-fold-search t
)
1395 (files (directory-files start t rmail-secondary-file-regexp
)))
1396 ;; Sort here instead of in directory-files
1397 ;; because this list is usually much shorter.
1398 (sort files
'string
<))))
1400 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1401 (let ((menu (make-sparse-keymap menu-name
)))
1403 (function (lambda (item)
1408 (rmail-list-to-menu (car item
) (cdr item
)
1411 (concat full-name
"/"
1414 (setq name
(car item
)))
1418 (list 'lambda
() '(interactive)
1422 (concat full-name
"/" item
)
1424 rmail-secondary-file-directory
))))))
1425 (define-key menu
(vector (intern name
))
1426 (cons name command
)))))
1430 ;; This command is always "disabled" when it appears in a menu.
1431 (put 'rmail-disable-menu
'menu-enable
''nil
)
1433 (defun rmail-construct-io-menu ()
1434 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1437 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1438 (cons "Input Rmail File"
1439 (rmail-list-to-menu "Input Rmail File"
1442 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1443 (cons "Output Rmail File"
1444 (rmail-list-to-menu "Output Rmail File"
1446 'rmail-output-to-rmail-file
))))
1448 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1449 '("Input Rmail File" . rmail-disable-menu
))
1450 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1451 '("Output Rmail File" . rmail-disable-menu
)))))
1454 ;;;; *** Rmail input ***
1456 ;; RLK feature not added in this version:
1457 ;; argument specifies inbox file or files in various ways.
1459 (defun rmail-get-new-mail (&optional file-name
)
1460 "Move any new mail from this RMAIL file's inbox files.
1461 The inbox files can be specified with the file's Mail: option. The
1462 variable `rmail-primary-inbox-list' specifies the inboxes for your
1463 primary RMAIL file if it has no Mail: option. By default, this is
1464 your /usr/spool/mail/$USER.
1466 You can also specify the file to get new mail from. In this case, the
1467 file of new mail is not changed or deleted. Noninteractively, you can
1468 pass the inbox file name as an argument. Interactively, a prefix
1469 argument causes us to read a file name and use that file as the inbox.
1471 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1472 always be left in inbox files rather than deleted.
1474 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1475 It returns t if it got any new messages."
1477 (list (if current-prefix-arg
1478 (read-file-name "Get new mail from file: "))))
1479 (run-hooks 'rmail-before-get-new-mail-hook
)
1480 ;; If the disk file has been changed from under us,
1481 ;; revert to it before we get new mail.
1482 (or (verify-visited-file-modtime (current-buffer))
1483 (find-file (buffer-file-name)))
1484 (set-buffer rmail-buffer
)
1485 (rmail-maybe-set-message-counters)
1487 ;; Get rid of all undo records for this buffer.
1488 (or (eq buffer-undo-list t
)
1489 (setq buffer-undo-list nil
))
1490 (let ((all-files (if file-name
(list file-name
)
1492 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1497 (let ((opoint (point))
1499 (rsf-number-of-spam 0)
1501 ;; If buffer has not changed yet, and has not been saved yet,
1502 ;; don't replace the old backup file now.
1503 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1504 (buffer-read-only nil
)
1505 ;; Don't make undo records for what we do in getting mail.
1506 (buffer-undo-list t
)
1508 ;; Files to insert this time around.
1510 ;; Last names of those files.
1512 ;; Pull files off all-files onto files
1513 ;; as long as there is no name conflict.
1514 ;; A conflict happens when two inbox file names
1515 ;; have the same last component.
1516 (while (and all-files
1517 (not (member (file-name-nondirectory (car all-files
))
1519 (setq files
(cons (car all-files
) files
)
1521 (cons (file-name-nondirectory (car all-files
)) files
))
1522 (setq all-files
(cdr all-files
)))
1523 ;; Put them back in their original order.
1524 (setq files
(nreverse files
))
1526 (goto-char (point-max))
1527 (skip-chars-backward " \t\n") ; just in case of brain damage
1528 (delete-region (point) (point-max)) ; caused by require-final-newline
1531 (narrow-to-region (point) (point))
1532 ;; Read in the contents of the inbox files,
1533 ;; renaming them as necessary,
1534 ;; and adding to the list of files to delete eventually.
1536 (rmail-insert-inbox-text files nil
)
1537 (setq delete-files
(rmail-insert-inbox-text files t
)))
1538 ;; Scan the new text and convert each message to babyl format.
1539 (goto-char (point-min))
1542 (setq new-messages
(rmail-convert-to-babyl-format)
1544 ;; Try to delete the garbage just inserted.
1545 (or success
(delete-region (point-min) (point-max)))
1546 ;; If we could not convert the file's inboxes,
1547 ;; rename the files we tried to read
1548 ;; so we won't over and over again.
1549 (if (and (not file-name
) (not success
))
1550 (let ((delfiles delete-files
)
1553 (while (file-exists-p (format "RMAILOSE.%d" count
))
1554 (setq count
(1+ count
)))
1555 (rename-file (car delfiles
)
1556 (format "RMAILOSE.%d" count
))
1557 (setq delfiles
(cdr delfiles
))))))
1558 (or (zerop new-messages
)
1561 (search-backward "\n\^_" nil t
)
1562 (narrow-to-region (point) (point-max))
1563 (goto-char (1+ (point-min)))
1564 (rmail-count-new-messages)
1565 (run-hooks 'rmail-get-new-mail-hook
)
1567 ;; Delete the old files, now that babyl file is saved.
1570 ;; First, try deleting.
1572 (delete-file (car delete-files
))
1574 ;; If we can't delete it, truncate it.
1575 (write-region (point) (point) (car delete-files
))))
1577 (setq delete-files
(cdr delete-files
)))))
1578 (if (= new-messages
0)
1579 (progn (goto-char opoint
)
1580 (if (or file-name rmail-inbox-list
)
1581 (message "(No new mail has arrived)")))
1582 ;; check new messages to see if any of them is spam:
1583 (if (and (featurep 'rmail-spam-filter
)
1584 rmail-use-spam-filter
)
1586 ((old-messages (- rmail-total-messages new-messages
))
1587 (rsf-scanned-message-number (1+ old-messages
))
1588 ;; save deletion flags of old messages: vector starts
1589 ;; at zero (is one longer that no of messages),
1590 ;; therefore take 1+ old-messages
1592 (substring rmail-deleted-vector
0 (1+
1594 ;; set all messages to undeleted
1595 (setq rmail-deleted-vector
1596 (make-string (1+ rmail-total-messages
) ?\
))
1597 (while (<= rsf-scanned-message-number
1598 rmail-total-messages
)
1600 (if (not (rmail-spam-filter rsf-scanned-message-number
))
1601 (progn (setq rsf-number-of-spam
(1+ rsf-number-of-spam
)))
1603 (setq rsf-scanned-message-number
(1+ rsf-scanned-message-number
))
1605 (if (> rsf-number-of-spam
0)
1607 (when (rmail-expunge-confirmed)
1608 (rmail-only-expunge t
))
1610 (setq rmail-deleted-vector
1613 (make-string (- rmail-total-messages old-messages
)
1616 (if (rmail-summary-exists)
1617 (rmail-select-summary
1618 (rmail-update-summary)))
1619 (message "%d new message%s read%s"
1620 new-messages
(if (= 1 new-messages
) "" "s")
1621 ;; print out a message on number of spam messages found:
1622 (if (and (featurep 'rmail-spam-filter
)
1623 rmail-use-spam-filter
1624 (> rsf-number-of-spam
0))
1625 (if (= 1 new-messages
)
1626 ", and found to be a spam message"
1627 (if (> rsf-number-of-spam
1)
1628 (format ", %d of which found to be spam messages"
1630 ", one of which found to be a spam message"))
1632 (if (and (featurep 'rmail-spam-filter
)
1633 rmail-use-spam-filter
1634 (> rsf-number-of-spam
0))
1635 (progn (if rsf-beep
(beep t
))
1636 (sleep-for rsf-sleep-after-message
)))
1638 ;; Move to the first new message
1639 ;; unless we have other unseen messages before it.
1640 (rmail-show-message (rmail-first-unseen-message))
1641 (run-hooks 'rmail-after-get-new-mail-hook
)
1644 ;; Don't leave the buffer screwed up if we get a disk-full error.
1645 (or found
(rmail-show-message)))))
1647 (defun rmail-parse-url (file)
1648 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1649 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1650 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1651 a remote mailbox, PASSWORD is the password if it should be
1652 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1653 is non-nil if the user has supplied the password interactively.
1656 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1657 (let (got-password supplied-password
1658 (proto (match-string 1 file
))
1659 (user (match-string 3 file
))
1660 (pass (match-string 5 file
))
1661 (host (substring file
(or (match-end 2)
1662 (+ 3 (match-end 1))))))
1665 (when rmail-remote-password-required
1666 (setq got-password
(not (rmail-have-password)))
1667 (setq supplied-password
(rmail-get-remote-password
1668 (string-equal proto
"imap")))))
1670 (if (rmail-movemail-variant-p 'emacs
)
1671 (if (string-equal proto
"pop")
1672 (list (concat "po:" user
":" host
)
1674 (or pass supplied-password
)
1676 (error "Emacs movemail does not support %s protocol" proto
))
1678 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1682 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1683 (let (got-password supplied-password
1685 (user (match-string 1 file
))
1686 (host (match-string 3 file
)))
1688 (when rmail-remote-password-required
1689 (setq got-password
(not (rmail-have-password)))
1690 (setq supplied-password
(rmail-get-remote-password nil
)))
1692 (list file
"pop" supplied-password got-password
)))
1695 (list file nil nil nil
))))
1697 (defun rmail-insert-inbox-text (files renamep
)
1698 ;; Detect a locked file now, so that we avoid moving mail
1699 ;; out of the real inbox file. (That could scare people.)
1700 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1701 (error "RMAIL file %s is locked"
1702 (file-name-nondirectory buffer-file-name
)))
1703 (let (file tofile delete-files movemail popmail got-password password
)
1705 ;; Handle remote mailbox names specially; don't expand as filenames
1706 ;; in case the userid contains a directory separator.
1707 (setq file
(car files
))
1708 (let ((url-data (rmail-parse-url file
)))
1709 (setq file
(nth 0 url-data
))
1710 (setq popmail
(nth 1 url-data
))
1711 (setq password
(nth 2 url-data
))
1712 (setq got-password
(nth 3 url-data
)))
1716 (setq file
(file-truename
1717 (substitute-in-file-name (expand-file-name file
)))))
1718 (setq tofile
(expand-file-name
1719 ;; Generate name to move to from inbox name,
1720 ;; in case of multiple inboxes that need moving.
1722 (file-name-nondirectory
1723 (if (memq system-type
'(windows-nt cygwin
))
1724 ;; cannot have "po:" in file name
1727 ;; Use the directory of this rmail file
1728 ;; because it's a nuisance to use the homedir
1729 ;; if that is on a full disk and this rmail
1731 (file-name-directory
1732 (expand-file-name buffer-file-name
))))
1733 ;; Always use movemail to rename the file,
1734 ;; since there can be mailboxes in various directories.
1737 ;; On some systems, /usr/spool/mail/foo is a directory
1738 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1739 (if (file-directory-p file
)
1740 (setq file
(expand-file-name (user-login-name)
1743 (message "Getting mail from the remote server ..."))
1744 ((and (file-exists-p tofile
)
1745 (/= 0 (nth 7 (file-attributes tofile
))))
1746 (message "Getting mail from %s..." tofile
))
1747 ((and (file-exists-p file
)
1748 (/= 0 (nth 7 (file-attributes file
))))
1749 (message "Getting mail from %s..." file
)))
1750 ;; Set TOFILE if have not already done so, and
1751 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1752 (cond ((not renamep
)
1754 ((or (file-exists-p tofile
) (and (not popmail
)
1755 (not (file-exists-p file
))))
1759 (let ((errors (current-buffer)))
1760 (buffer-disable-undo errors
)
1763 (list (or rmail-movemail-program
1764 (expand-file-name "movemail"
1767 (if rmail-preserve-inbox
1770 (if (rmail-movemail-variant-p 'mailutils
)
1771 (append (list "--emacs") rmail-movemail-flags
)
1772 rmail-movemail-flags
)
1774 (if password
(list password
) nil
))))
1775 (apply 'call-process args
))
1776 (if (not (buffer-modified-p errors
))
1777 ;; No output => movemail won
1780 (subst-char-in-region (point-min) (point-max)
1782 (goto-char (point-max))
1783 (skip-chars-backward " \t")
1784 (delete-region (point) (point-max))
1785 (goto-char (point-min))
1786 (if (looking-at "movemail: ")
1787 (delete-region (point-min) (match-end 0)))
1789 ;; If we just read the password, most likely it is
1790 ;; wrong. Otherwise, see if there is a specific
1791 ;; reason to think that the problem is a wrong passwd.
1792 (if (or got-password
1793 (re-search-forward rmail-remote-password-error
1795 (rmail-set-remote-password nil
))
1797 ;; If using Mailutils, remove initial error code
1799 (when (rmail-movemail-variant-p 'mailutils
)
1800 (goto-char (point-min))
1801 (when (looking-at "[A-Z][A-Z0-9_]*:")
1802 (delete-region (point-min) (match-end 0))))
1804 (message "movemail: %s"
1805 (buffer-substring (point-min)
1811 ;; At this point, TOFILE contains the name to read:
1812 ;; Either the alternate name (if we renamed)
1813 ;; or the actual inbox (if not renaming).
1814 (if (file-exists-p tofile
)
1815 (let ((coding-system-for-read 'no-conversion
)
1817 (goto-char (point-max))
1818 (setq size
(nth 1 (insert-file-contents tofile
)))
1819 (goto-char (point-max))
1820 (or (= (preceding-char) ?
\n)
1823 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1824 (setq delete-files
(cons tofile delete-files
)))))
1826 (setq files
(cdr files
)))
1829 ;; Decode the region specified by FROM and TO by CODING.
1830 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1831 (defun rmail-decode-region (from to coding
)
1832 (if (or (not coding
) (not (coding-system-p coding
)))
1833 (setq coding
'undecided
))
1834 ;; Use -dos decoding, to remove ^M characters left from base64 or
1835 ;; rogue qp-encoded text.
1836 (decode-coding-region from to
1837 (coding-system-change-eol-conversion coding
1))
1838 ;; Don't reveal the fact we used -dos decoding, as users generally
1839 ;; will not expect the RMAIL buffer to use DOS EOL format.
1840 (setq buffer-file-coding-system
1841 (setq last-coding-system-used
1842 (coding-system-change-eol-conversion coding
0))))
1844 ;; the rmail-break-forwarded-messages feature is not implemented
1845 (defun rmail-convert-to-babyl-format ()
1846 (let ((count 0) start
1847 (case-fold-search nil
)
1848 (invalid-input-resync
1849 (function (lambda ()
1850 (message "Invalid Babyl format in inbox!")
1852 ;; Try to get back in sync with a real message.
1853 (if (re-search-forward
1854 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1856 (goto-char (point-max)))))))
1857 (goto-char (point-min))
1860 (setq start
(point))
1861 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1862 (if (search-forward "\n\^_" nil t
)
1863 ;; If we find the proper terminator, delete through there.
1864 (delete-region (point-min) (point))
1865 (funcall invalid-input-resync
)
1866 (delete-region (point-min) (point))))
1867 ;; Babyl format message
1869 (or (search-forward "\n\^_" nil t
)
1870 (funcall invalid-input-resync
))
1871 (setq count
(1+ count
))
1872 ;; Make sure there is no extra white space after the ^_
1873 ;; at the end of the message.
1874 ;; Narrowing will make sure that whatever follows the junk
1875 ;; will be treated properly.
1876 (delete-region (point)
1878 (skip-chars-forward " \t\n")
1886 (if (looking-at "0")
1890 (narrow-to-region (point) (point-max))
1893 (case-fold-search t
)
1894 (quoted-printable-header-field-end
1898 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1900 (base64-header-field-end
1904 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
1906 (if quoted-printable-header-field-end
1909 (mail-unquote-printable-region header-end
(point) nil t t
)
1910 (message "Malformed MIME quoted-printable message"))
1911 ;; Change "quoted-printable" to "8bit",
1912 ;; to reflect the decoding we just did.
1913 (goto-char quoted-printable-header-field-end
)
1914 (delete-region (point) (search-backward ":"))
1916 (if base64-header-field-end
1921 (base64-decode-region (1+ header-end
)
1925 ;; Change "base64" to "8bit", to reflect the
1926 ;; decoding we just did.
1927 (goto-char base64-header-field-end
)
1928 (delete-region (point) (search-backward ":"))
1929 (insert ": 8bit"))))
1930 (setq last-coding-system-used nil
)
1931 (or rmail-enable-mime
1932 (not rmail-enable-multibyte
)
1934 (if (and rmail-decode-mime-charset
1937 (search-forward "\n\n" nil t
)
1938 (let ((case-fold-search t
))
1940 rmail-mime-charset-pattern
1942 (intern (downcase (match-string 1))))))
1943 (rmail-decode-region start
(point) mime-charset
)))))
1944 ;; Add an X-Coding-System: header if we don't have one.
1948 (if (looking-at "0")
1951 (or (save-restriction
1952 (narrow-to-region (point) (point-max))
1954 (goto-char (point-min))
1955 (re-search-forward "^X-Coding-System:" nil t
))
1956 (insert "X-Coding-System: "
1957 (symbol-name last-coding-system-used
)
1959 (narrow-to-region (point) (point-max))
1960 (and (= 0 (% count
10))
1961 (message "Converting to Babyl format...%d" count
)))
1963 ((let ((case-fold-search t
))
1964 (looking-at rmail-mmdf-delim1
))
1965 (let ((case-fold-search t
))
1966 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1967 (re-search-forward rmail-mmdf-delim2 nil t
)
1968 (replace-match "\^_"))
1971 (narrow-to-region start
(1- (point)))
1972 (goto-char (point-min))
1973 (while (search-forward "\n\^_" nil t
); single char "\^_"
1974 (replace-match "\n^_")))); 2 chars: "^" and "_"
1975 (setq last-coding-system-used nil
)
1976 (or rmail-enable-mime
1977 (not rmail-enable-multibyte
)
1978 (decode-coding-region start
(point) 'undecided
))
1982 (insert "X-Coding-System: "
1983 (symbol-name last-coding-system-used
)
1985 (narrow-to-region (point) (point-max))
1986 (setq count
(1+ count
))
1987 (and (= 0 (% count
10))
1988 (message "Converting to Babyl format...%d" count
)))
1990 ((looking-at "^From ")
1991 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1992 (rmail-nuke-pinhead-header)
1993 ;; If this message has a Content-Length field,
1994 ;; skip to the end of the contents.
1995 (let* ((header-end (save-excursion
1996 (and (re-search-forward "\n\n" nil t
)
1998 (case-fold-search t
)
1999 (quoted-printable-header-field-end
2002 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
2004 (base64-header-field-end
2007 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
2010 ;; Get the numeric value from the Content-Length field.
2012 ;; Back up to end of prev line,
2013 ;; in case the Content-Length field comes first.
2015 (and (search-forward "\ncontent-length: "
2018 (eol (progn (end-of-line) (point))))
2019 (string-to-number (buffer-substring beg eol
)))))))
2021 (if (and (natnump size
)
2022 (<= (+ header-end size
) (point-max))
2023 ;; Make sure this would put us at a position
2024 ;; that we could continue from.
2026 (goto-char (+ header-end size
))
2027 (skip-chars-forward "\n")
2029 (and (looking-at "BABYL OPTIONS:")
2030 (search-forward "\n\^_" nil t
))
2031 (and (looking-at "\^L")
2032 (search-forward "\n\^_" nil t
))
2033 (let ((case-fold-search t
))
2034 (looking-at rmail-mmdf-delim1
))
2035 (looking-at "From "))))
2036 (goto-char (+ header-end size
))
2037 (message "Ignoring invalid Content-Length field")
2039 (if (let ((case-fold-search nil
))
2041 (concat "^[\^_]?\\("
2042 rmail-unix-mail-delimiter
2044 rmail-mmdf-delim1
"\\|"
2045 "^BABYL OPTIONS:\\|"
2046 "\^L\n[01],\\)") nil t
))
2047 (goto-char (match-beginning 1))
2048 (goto-char (point-max)))
2049 (setq count
(1+ count
))
2050 (if quoted-printable-header-field-end
2053 (mail-unquote-printable-region header-end
(point) nil t t
)
2054 (message "Malformed MIME quoted-printable message"))
2055 ;; Change "quoted-printable" to "8bit",
2056 ;; to reflect the decoding we just did.
2057 (goto-char quoted-printable-header-field-end
)
2058 (delete-region (point) (search-backward ":"))
2060 (if base64-header-field-end
2065 (base64-decode-region
2068 ;; Prevent base64-decode-region
2069 ;; from removing newline characters.
2070 (skip-chars-backward "\n\t ")
2074 ;; Change "base64" to "8bit", to reflect the
2075 ;; decoding we just did.
2076 (goto-char base64-header-field-end
)
2077 (delete-region (point) (search-backward ":"))
2078 (insert ": 8bit")))))
2082 (narrow-to-region start
(point))
2083 (goto-char (point-min))
2084 (while (search-forward "\n\^_" nil t
); single char
2085 (replace-match "\n^_")))); 2 chars: "^" and "_"
2086 ;; This is for malformed messages that don't end in newline.
2087 ;; There shouldn't be any, but some users say occasionally
2089 (or (bolp) (newline))
2091 (setq last-coding-system-used nil
)
2092 (or rmail-enable-mime
2093 (not rmail-enable-multibyte
)
2095 (if (and rmail-decode-mime-charset
2098 (search-forward "\n\n" nil t
)
2099 (let ((case-fold-search t
))
2101 rmail-mime-charset-pattern
2103 (intern (downcase (match-string 1))))))
2104 (rmail-decode-region start
(point) mime-charset
)))
2108 (insert "X-Coding-System: "
2109 (symbol-name last-coding-system-used
)
2111 (narrow-to-region (point) (point-max))
2112 (and (= 0 (% count
10))
2113 (message "Converting to Babyl format...%d" count
)))
2115 ;; This kludge is because some versions of sendmail.el
2116 ;; insert an extra newline at the beginning that shouldn't
2117 ;; be there. sendmail.el has been fixed, but old versions
2118 ;; may still be in use. -- rms, 7 May 1993.
2119 ((eolp) (delete-char 1))
2120 (t (error "Cannot convert to babyl format")))))
2123 ;; Delete the "From ..." line, creating various other headers with
2124 ;; information from it if they don't already exist. Now puts the
2125 ;; original line into a mail-from: header line for debugging and for
2126 ;; use by the rmail-output function.
2127 (defun rmail-nuke-pinhead-header ()
2130 (let ((start (point))
2133 (search-forward "\n\n")
2135 (goto-char (point-max))
2139 (narrow-to-region start end
)
2140 (let ((case-fold-search t
))
2142 (setq has-from
(search-forward "\nFrom:" nil t
))
2144 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
2146 (let ((case-fold-search nil
))
2147 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
2151 ;; Keep and reformat the date if we don't
2152 ;; have a Date: field.
2156 "Date: \\2, \\4 \\3 \\9 \\5 "
2158 ;; The timezone could be matched by group 7 or group 10.
2159 ;; If neither of them matched, assume EST, since only
2160 ;; Easterners would be so sloppy.
2161 ;; It's a shame the substitution can't use "\\10".
2163 ((/= (match-beginning 7) (match-end 7)) "\\7")
2164 ((/= (match-beginning 10) (match-end 10))
2165 (buffer-substring (match-beginning 10)
2169 ;; Keep and reformat the sender if we don't
2170 ;; have a From: field.
2176 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2178 (defun rmail-reformat-message (beg end
)
2181 (if (/= (following-char) ?
0)
2182 (error "Bad format in RMAIL file"))
2183 (let ((inhibit-read-only t
)
2184 (delta (- (buffer-size) end
)))
2188 (let ((case-fold-search t
))
2189 (while (looking-at "Summary-line:\\|Mail-From:")
2191 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
2192 (delete-region (point)
2193 (progn (forward-line 1) (point))))
2194 (let ((str (buffer-substring (point)
2195 (save-excursion (search-forward "\n\n" end
'move
)
2197 (insert str
"*** EOOH ***\n")
2198 (narrow-to-region (point) (- (buffer-size) delta
)))
2199 (goto-char (point-min))
2200 (if rmail-message-filter
(funcall rmail-message-filter
))
2201 (if (or rmail-displayed-headers rmail-ignored-headers
)
2202 (rmail-clear-headers))))
2204 (defun rmail-clear-headers (&optional ignored-headers
)
2205 "Delete all header fields that Rmail should not show.
2206 If the optional argument IGNORED-HEADERS is non-nil,
2207 delete all header fields whose names match that regexp.
2208 Otherwise, if `rmail-displayed-headers' is non-nil,
2209 delete all header fields *except* those whose names match that regexp.
2210 Otherwise, delete all header fields whose names match `rmail-ignored-headers'
2211 unless they also match `rmail-nonignored-headers'."
2212 (when (search-forward "\n\n" nil t
)
2214 (let ((case-fold-search t
)
2215 (buffer-read-only nil
))
2216 (if (and rmail-displayed-headers
(null ignored-headers
))
2218 (narrow-to-region (point-min) (point))
2220 (goto-char (point-min))
2221 (while (and (not (eobp))
2223 (if (re-search-forward "\n[^ \t]" nil t
)
2224 (setq lim
(match-beginning 0)
2226 (setq lim nil next
(point-max)))))
2228 (re-search-forward rmail-displayed-headers lim t
))
2230 (delete-region (point) next
))))
2231 (goto-char (point-min)))
2232 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2234 (narrow-to-region (point-min) (point))
2235 (goto-char (point-min))
2236 (while (and ignored-headers
2237 (re-search-forward ignored-headers nil t
))
2239 (if (looking-at rmail-nonignored-headers
)
2241 (delete-region (point)
2243 (if (re-search-forward "\n[^ \t]" nil t
)
2245 (point-max)))))))))))
2247 (defun rmail-msg-is-pruned ()
2248 (rmail-maybe-set-message-counters)
2250 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2252 (goto-char (point-min))
2254 (= (following-char) ?
1))))
2256 (defun rmail-msg-restore-non-pruned-header ()
2257 (let ((old-point (point))
2260 (inhibit-read-only t
))
2262 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2263 (goto-char (point-min))
2268 ;; Insert new EOOH line at the proper place.
2270 (let ((case-fold-search t
))
2271 (while (looking-at "Summary-Line:\\|Mail-From:")
2273 (insert "*** EOOH ***\n")
2274 (setq new-start
(point))
2275 ;; Delete the old reformatted header.
2277 (search-forward "\n*** EOOH ***\n")
2279 (let ((start (point)))
2280 (search-forward "\n\n")
2281 (if (and (<= start old-point
)
2282 (<= old-point
(point)))
2283 (setq new-point new-start
))
2284 (delete-region start
(point)))
2285 ;; Narrow to after the new EOOH line.
2286 (narrow-to-region new-start
(point-max)))
2288 (goto-char new-point
))))
2290 (defun rmail-msg-prune-header ()
2292 (= (point) (point-min))))
2294 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2295 (rmail-reformat-message (point-min) (point-max)))
2297 (goto-char (point-min)))))
2299 (defun rmail-toggle-header (&optional arg
)
2300 "Show original message header if pruned header currently shown, or vice versa.
2301 With argument ARG, show the message header pruned if ARG is greater than zero;
2302 otherwise, show it in full."
2304 (let* ((pruned (with-current-buffer rmail-buffer
2305 (rmail-msg-is-pruned)))
2307 (> (prefix-numeric-value arg
) 0)
2309 (if (eq pruned prune
)
2311 (set-buffer rmail-buffer
)
2312 (rmail-maybe-set-message-counters)
2313 (if rmail-enable-mime
2314 (let ((buffer-read-only nil
))
2316 (rmail-msg-restore-non-pruned-header)
2317 (rmail-msg-prune-header))
2318 (funcall rmail-show-mime-function
))
2319 (let* ((buffer-read-only nil
)
2320 (window (get-buffer-window (current-buffer)))
2321 (at-point-min (= (point) (point-min)))
2322 (all-headers-visible (= (window-start window
) (point-min)))
2325 (and (not (search-backward "\n\n" nil t
))
2328 (re-search-backward "^[-A-Za-z0-9]+:" nil t
))
2331 (rmail-count-screen-lines (window-start window
) (point))))
2333 (rmail-msg-restore-non-pruned-header)
2334 (rmail-msg-prune-header))
2336 (goto-char (point-min)))
2338 (goto-char (point-min))
2339 (search-forward "\n\n")
2340 (or (re-search-backward
2341 (concat "^" (regexp-quote on-header
)) nil t
)
2342 (goto-char (point-min))))
2344 (save-selected-window
2345 (select-window window
)
2346 (recenter old-screen-line
)
2347 (if (and all-headers-visible
2348 (not (= (window-start) (point-min))))
2349 (recenter (- (window-height) 2))))))))
2350 (rmail-highlight-headers))))
2352 (defun rmail-narrow-to-non-pruned-header ()
2353 "Narrow to the whole (original) header of the current message."
2355 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2356 (goto-char (point-min))
2358 (if (= (following-char) ?
1)
2361 (setq start
(point))
2362 (search-forward "*** EOOH ***\n")
2363 (setq end
(match-beginning 0)))
2365 (setq start
(point))
2366 (search-forward "\n\n")
2367 (setq end
(1- (point))))
2368 (narrow-to-region start end
)
2371 ;; Lifted from repos-count-screen-lines.
2372 ;; Return number of screen lines between START and END.
2373 (defun rmail-count-screen-lines (start end
)
2376 (narrow-to-region start end
)
2377 (goto-char (point-min))
2378 (vertical-motion (- (point-max) (point-min))))))
2380 ;;;; *** Rmail Attributes and Keywords ***
2382 ;; Make a string describing current message's attributes and keywords
2383 ;; and set it up as the name of a minor mode
2384 ;; so it will appear in the mode line.
2385 (defun rmail-display-labels ()
2386 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
2391 (goto-char (rmail-msgbeg rmail-current-message
))
2393 (if (looking-at "[01],")
2395 (narrow-to-region (point) (progn (end-of-line) (point)))
2396 ;; Truly valid BABYL format requires a space before each
2397 ;; attribute or keyword name. Put them in if missing.
2398 (let (buffer-read-only)
2399 (goto-char (point-min))
2400 (while (search-forward "," nil t
)
2401 (or (looking-at "[ ,]") (eobp)
2403 (goto-char (point-max))
2404 (if (search-backward ",," nil
'move
)
2406 (if (> (point) (1+ (point-min)))
2407 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
2408 (if (> (- (point-max) (point)) 2)
2412 (buffer-substring (+ (point) 3)
2413 (1- (point-max)))))))))))
2414 ;; Note: we don't use save-restriction because that does not work right
2415 ;; if changes are made outside the saved restriction
2416 ;; before that restriction is restored.
2417 (narrow-to-region beg end
)
2418 (set-marker beg nil
)
2419 (set-marker end nil
)))
2420 (while (string-match " +," blurb
)
2421 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2422 (substring blurb
(match-end 0)))))
2423 (while (string-match ", +" blurb
)
2424 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2425 (substring blurb
(match-end 0)))))
2426 (setq mode-line-process
2428 rmail-current-message rmail-total-messages blurb
))
2429 ;; If rmail-enable-mime is non-nil, we may have to update
2430 ;; `mode-line-process' of rmail-view-buffer too.
2431 (if (and rmail-enable-mime
2432 (not (eq (current-buffer) rmail-view-buffer
))
2433 (buffer-live-p rmail-view-buffer
))
2434 (let ((mlp mode-line-process
))
2435 (with-current-buffer rmail-view-buffer
2436 (setq mode-line-process mlp
))))))
2438 ;; Turn an attribute of a message on or off according to STATE.
2439 ;; ATTR is the name of the attribute, as a string.
2440 ;; MSGNUM is message number to change; nil means current message.
2441 (defun rmail-set-attribute (attr state
&optional msgnum
)
2442 (set-buffer rmail-buffer
)
2443 (let ((omax (point-max-marker))
2444 (omin (point-min-marker))
2445 (buffer-read-only nil
))
2446 (or msgnum
(setq msgnum rmail-current-message
))
2451 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
2454 (null (search-backward (concat ", " attr
",")
2455 (prog1 (point) (end-of-line)) t
)))))
2456 (or (eq curstate
(not (not state
)))
2458 (delete-region (point) (1- (match-end 0)))
2461 (insert " " attr
","))))
2462 (if (string= attr
"deleted")
2463 (rmail-set-message-deleted-p msgnum state
)))
2464 ;; Note: we don't use save-restriction because that does not work right
2465 ;; if changes are made outside the saved restriction
2466 ;; before that restriction is restored.
2467 (narrow-to-region omin omax
)
2468 (set-marker omin nil
)
2469 (set-marker omax nil
)
2470 (if (= msgnum rmail-current-message
)
2471 (rmail-display-labels))))))
2473 ;; Return t if the attributes/keywords line of msg number MSG
2474 ;; contains a match for the regexp LABELS.
2475 (defun rmail-message-labels-p (msg labels
)
2479 (goto-char (rmail-msgbeg msg
))
2481 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
2483 ;;;; *** Rmail Message Selection And Support ***
2485 (defun rmail-msgend (n)
2486 (marker-position (aref rmail-message-vector
(1+ n
))))
2488 (defun rmail-msgbeg (n)
2489 (marker-position (aref rmail-message-vector n
)))
2491 (defun rmail-widen-to-current-msgbeg (function)
2492 "Call FUNCTION with point at start of internal data of current message.
2493 Assumes that bounds were previously narrowed to display the message in Rmail.
2494 The bounds are widened enough to move point where desired, then narrowed
2497 FUNCTION may not change the visible text of the message, but it may
2498 change the invisible header text."
2502 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2504 (goto-char (point-min))
2506 ;; Note: we don't use save-restriction because that does not work right
2507 ;; if changes are made outside the saved restriction
2508 ;; before that restriction is restored.
2509 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2510 (rmail-msgend rmail-current-message
)))))
2512 (defun rmail-forget-messages ()
2514 (if (vectorp rmail-message-vector
)
2516 (v rmail-message-vector
)
2519 (move-marker (aref v i
) nil
)
2521 (setq rmail-message-vector nil
)
2522 (setq rmail-msgref-vector nil
)
2523 (setq rmail-deleted-vector nil
)))
2525 (defun rmail-maybe-set-message-counters ()
2526 (if (not (and rmail-deleted-vector
2527 rmail-message-vector
2528 rmail-current-message
2529 rmail-total-messages
))
2530 (rmail-set-message-counters)))
2532 (defun rmail-count-new-messages (&optional nomsg
)
2533 (let* ((case-fold-search nil
)
2537 (or nomsg
(message "Counting new messages..."))
2538 (goto-char (point-max))
2539 ;; Put at the end of messages-head
2540 ;; the entry for message N+1, which marks
2541 ;; the end of message N. (N = number of messages).
2542 (search-backward "\n\^_")
2544 (setq messages-head
(list (point-marker)))
2545 (rmail-set-message-counters-counter (point-min))
2546 (setq rmail-current-message
(1+ rmail-total-messages
))
2547 (setq rmail-total-messages
2548 (+ rmail-total-messages total-messages
))
2549 (setq rmail-message-vector
2550 (vconcat rmail-message-vector
(cdr messages-head
)))
2551 (aset rmail-message-vector
2552 rmail-current-message
(car messages-head
))
2553 (setq rmail-deleted-vector
2554 (concat rmail-deleted-vector deleted-head
))
2555 (setq rmail-summary-vector
2556 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2557 (setq rmail-msgref-vector
2558 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2559 ;; Fill in the new elements of rmail-msgref-vector.
2560 (let ((i (1+ (- rmail-total-messages total-messages
))))
2561 (while (<= i rmail-total-messages
)
2562 (aset rmail-msgref-vector i
(list i
))
2564 (goto-char (point-min))
2565 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2567 (defun rmail-set-message-counters ()
2568 (rmail-forget-messages)
2572 (let* ((point-save (point))
2574 (messages-after-point)
2575 (case-fold-search nil
)
2578 (message "Counting messages...")
2579 (goto-char (point-max))
2580 ;; Put at the end of messages-head
2581 ;; the entry for message N+1, which marks
2582 ;; the end of message N. (N = number of messages).
2583 (search-backward "\n\^_" nil t
)
2584 (if (/= (point) (point-max)) (forward-char 1))
2585 (setq messages-head
(list (point-marker)))
2586 (rmail-set-message-counters-counter (min (point) point-save
))
2587 (setq messages-after-point total-messages
)
2588 (rmail-set-message-counters-counter)
2589 (setq rmail-total-messages total-messages
)
2590 (setq rmail-current-message
2592 (max 1 (- total-messages messages-after-point
))))
2593 (setq rmail-message-vector
2594 (apply 'vector
(cons (point-min-marker) messages-head
))
2595 rmail-deleted-vector
(concat "0" deleted-head
)
2596 rmail-summary-vector
(make-vector rmail-total-messages nil
)
2597 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2599 (while (<= i rmail-total-messages
)
2600 (aset rmail-msgref-vector i
(list i
))
2602 (message "Counting messages...done")))))
2604 (defun rmail-set-message-counters-counter (&optional stop
)
2605 (let ((start (point))
2607 (while (search-backward "\n\^_\^L" stop t
)
2608 ;; Detect messages that have been added with DOS line endings and
2609 ;; convert the line endings for such messages.
2611 (if (looking-at "\n\^_\^L\r\n")
2612 (let ((buffer-read-only nil
)
2614 (message "Counting messages...(converting line endings)")
2617 (while (search-backward "\r\n" next t
)
2621 (setq messages-head
(cons (point-marker) messages-head
))
2624 (cons (if (search-backward ", deleted,"
2630 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
2631 (message "Counting messages...%d" total-messages
)))))
2633 (defun rmail-beginning-of-message ()
2634 "Show current message starting from the beginning."
2636 (let ((rmail-show-message-hook
2637 (list (function (lambda ()
2638 (goto-char (point-min)))))))
2639 (rmail-show-message rmail-current-message
)))
2641 (defun rmail-end-of-message ()
2642 "Show bottom of current message."
2644 (let ((rmail-show-message-hook
2645 (list (function (lambda ()
2646 (goto-char (point-max))
2647 (recenter (1- (window-height))))))))
2648 (rmail-show-message rmail-current-message
)))
2650 (defun rmail-unknown-mail-followup-to ()
2651 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2652 Ask the user whether to add that list name to `mail-mailing-lists'."
2654 (rmail-narrow-to-non-pruned-header)
2655 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2656 (when mail-followup-to
2659 (mail-strip-quoted-names mail-followup-to
)
2660 ",[[:space:]]+" t
)))
2661 (dolist (addr addresses
)
2662 (when (and (not (member addr mail-mailing-lists
))
2664 ;; taken from rmailsum.el
2666 (or rmail-user-mail-address-regexp
2668 (regexp-quote (user-login-name))
2671 (or user-mail-address
2672 (concat (user-login-name) "@"
2673 (or mail-host-address
2678 (format "Add `%s' to `mail-mailing-lists'? "
2680 (customize-save-variable 'mail-mailing-lists
2681 (cons addr mail-mailing-lists
)))))))))
2683 (defun rmail-show-message (&optional n no-summary
)
2684 "Show message number N (prefix argument), counting from start of file.
2685 If summary buffer is currently displayed, update current message there also."
2687 (or (eq major-mode
'rmail-mode
)
2688 (switch-to-buffer rmail-buffer
))
2689 (rmail-maybe-set-message-counters)
2691 (if (zerop rmail-total-messages
)
2692 (progn (narrow-to-region (point-min) (1- (point-max)))
2693 (goto-char (point-min))
2694 (setq mode-line-process nil
))
2695 (let (blurb coding-system
)
2697 (setq n rmail-current-message
)
2700 rmail-current-message
1
2701 blurb
"No previous message"))
2702 ((> n rmail-total-messages
)
2703 (setq n rmail-total-messages
2704 rmail-current-message rmail-total-messages
2705 blurb
"No following message"))
2707 (setq rmail-current-message n
))))
2708 (let ((beg (rmail-msgbeg n
)))
2712 (let ((end (rmail-msgend n
)))
2714 (if (prog1 (= (following-char) ?
0)
2716 ;; If there's a Summary-line in the (otherwise empty)
2717 ;; header, we didn't yet get past the EOOH line.
2718 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2720 (narrow-to-region (point) end
))
2722 (search-forward "\n*** EOOH ***\n" end t
))
2723 (narrow-to-region beg
(point))
2724 (goto-char (point-min))
2725 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2726 (let ((coding-system (intern (match-string 1))))
2729 (check-coding-system coding-system
)
2730 (setq buffer-file-coding-system coding-system
))
2732 (setq buffer-file-coding-system nil
))))
2733 (setq buffer-file-coding-system nil
)))))
2734 ;; Clear the "unseen" attribute when we show a message.
2735 (rmail-set-attribute "unseen" nil
)
2736 (let ((end (rmail-msgend n
)))
2737 ;; Reformat the header, or else find the reformatted header.
2738 (if (= (following-char) ?
0)
2739 (rmail-reformat-message beg end
)
2740 (search-forward "\n*** EOOH ***\n" end t
)
2741 (narrow-to-region (point) end
)))
2742 (goto-char (point-min))
2744 (function (lambda (window)
2745 (if (eq (window-buffer window
) (current-buffer))
2746 (set-window-point window
(point)))))
2748 (rmail-display-labels)
2749 (if (eq rmail-enable-mime t
)
2750 (funcall rmail-show-mime-function
)
2751 (setq rmail-view-buffer rmail-buffer
))
2752 (when mail-mailing-lists
2753 (rmail-unknown-mail-followup-to))
2754 (rmail-highlight-headers)
2755 (if transient-mark-mode
(deactivate-mark))
2756 (run-hooks 'rmail-show-message-hook
)
2757 ;; If there is a summary buffer, try to move to this message
2758 ;; in that buffer. But don't complain if this message
2759 ;; is not mentioned in the summary.
2760 ;; Don't do this at all if we were called on behalf
2761 ;; of cursor motion in the summary buffer.
2762 (and (rmail-summary-exists) (not no-summary
)
2763 (let ((curr-msg rmail-current-message
))
2764 (rmail-select-summary
2765 (rmail-summary-goto-msg curr-msg t t
))))
2766 (with-current-buffer rmail-buffer
2769 (message blurb
))))))
2771 (defun rmail-redecode-body (coding)
2772 "Decode the body of the current message using coding system CODING.
2773 This is useful with mail messages that have malformed or missing
2776 This function assumes that the current message is already decoded
2777 and displayed in the RMAIL buffer, but the coding system used to
2778 decode it was incorrect. It then encodes the message back to its
2779 original form, and decodes it again, using the coding system CODING.
2781 Note that if Emacs erroneously auto-detected one of the iso-2022
2782 encodings in the message, this function might fail because the escape
2783 sequences that switch between character sets and also single-shift and
2784 locking-shift codes are impossible to recover. This function is meant
2785 to be used to fix messages encoded with 8-bit encodings, such as
2786 iso-8859, koi8-r, etc."
2787 (interactive "zCoding system for re-decoding this message: ")
2788 (when (not rmail-enable-mime
)
2789 (or (eq major-mode
'rmail-mode
)
2790 (switch-to-buffer rmail-buffer
))
2792 (let ((pruned (rmail-msg-is-pruned)))
2794 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2795 (msgend (rmail-msgend rmail-current-message
))
2797 ;; We need the message headers pruned (we later restore
2798 ;; the pruned stat to what it was, see the end of
2799 ;; unwind-protect form).
2801 (rmail-toggle-header 1))
2802 (narrow-to-region msgbeg msgend
)
2803 (goto-char (point-min))
2804 (when (search-forward "\n*** EOOH ***\n" (point-max) t
)
2805 (narrow-to-region msgbeg
(point)))
2806 (goto-char (point-min))
2807 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2808 (let ((old-coding (intern (match-string 1)))
2809 (buffer-read-only nil
))
2810 (check-coding-system old-coding
)
2811 ;; Make sure the new coding system uses the same EOL
2812 ;; conversion, to prevent ^M characters from popping
2813 ;; up all over the place.
2815 (coding-system-change-eol-conversion
2817 (coding-system-eol-type old-coding
)))
2818 (setq x-coding-header
(point-marker))
2819 (narrow-to-region msgbeg msgend
)
2820 (encode-coding-region (point) msgend old-coding
)
2821 (decode-coding-region (point) msgend coding
)
2822 (setq last-coding-system-used coding
)
2823 ;; Rewrite the coding-system header according
2825 (goto-char x-coding-header
)
2826 (delete-region (point)
2830 (insert "X-Coding-System: "
2831 (symbol-name last-coding-system-used
))
2832 (set-marker x-coding-header nil
)
2833 (rmail-show-message))
2834 (error "No X-Coding-System header found")))
2836 (rmail-toggle-header 0)))))))
2838 ;; Find all occurrences of certain fields, and highlight them.
2839 (defun rmail-highlight-headers ()
2840 ;; Do this only if the system supports faces.
2841 (if (and (fboundp 'internal-find-face
)
2842 rmail-highlighted-headers
)
2844 (search-forward "\n\n" nil
'move
)
2846 (narrow-to-region (point-min) (point))
2847 (let ((case-fold-search t
)
2848 (inhibit-read-only t
)
2849 ;; Highlight with boldface if that is available.
2850 ;; Otherwise use the `highlight' face.
2851 (face (or rmail-highlight-face
2852 (if (face-differs-from-default-p 'bold
)
2854 ;; List of overlays to reuse.
2855 (overlays rmail-overlay-list
))
2856 (goto-char (point-min))
2857 (while (re-search-forward rmail-highlighted-headers nil t
)
2858 (skip-chars-forward " \t")
2861 (while (progn (forward-line 1)
2862 (looking-at "[ \t]")))
2863 ;; Back up over newline, then trailing spaces or tabs
2865 (while (member (preceding-char) '(? ?
\t))
2868 ;; Reuse an overlay we already have.
2870 (setq overlay
(car overlays
)
2871 overlays
(cdr overlays
))
2872 (overlay-put overlay
'face face
)
2873 (move-overlay overlay beg
(point)))
2874 ;; Make a new overlay and add it to
2875 ;; rmail-overlay-list.
2876 (setq overlay
(make-overlay beg
(point)))
2877 (overlay-put overlay
'face face
)
2878 (setq rmail-overlay-list
2879 (cons overlay rmail-overlay-list
))))))))))
2881 (defun rmail-auto-file ()
2882 "Automatically move a message into a sub-folder based on criteria.
2883 Called when a new message is displayed."
2884 (if (or (rmail-message-labels-p rmail-current-message
"filed")
2885 (not (string= (buffer-file-name)
2886 (expand-file-name rmail-file-name
))))
2887 ;; Do nothing if it's already been filed.
2889 ;; Find out some basics (common fields)
2890 (let ((from (mail-fetch-field "from"))
2891 (subj (mail-fetch-field "subject"))
2892 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2893 (d rmail-automatic-folder-directives
)
2894 (directive-loop nil
)
2897 (setq folder
(car (car d
))
2898 directive-loop
(cdr (car d
)))
2899 (while (and (car directive-loop
)
2901 ((string= (car directive-loop
) "from") from
)
2902 ((string= (car directive-loop
) "to") to
)
2903 ((string= (car directive-loop
) "subject") subj
)
2904 (t (mail-fetch-field (car directive-loop
))))))
2905 (and f
(string-match (car (cdr directive-loop
)) f
))))
2906 (setq directive-loop
(cdr (cdr directive-loop
))))
2907 ;; If there are no directives left, then it was a complete match.
2908 (if (null directive-loop
)
2910 (rmail-delete-forward)
2911 (if (string= "/dev/null" folder
)
2912 (rmail-delete-message)
2913 (rmail-output-to-rmail-file folder
1 t
)
2915 (setq d
(cdr d
))))))
2917 (defun rmail-next-message (n)
2918 "Show following message whether deleted or not.
2919 With prefix arg N, moves forward N messages, or backward if N is negative."
2921 (set-buffer rmail-buffer
)
2922 (rmail-maybe-set-message-counters)
2923 (rmail-show-message (+ rmail-current-message n
)))
2925 (defun rmail-previous-message (n)
2926 "Show previous message whether deleted or not.
2927 With prefix arg N, moves backward N messages, or forward if N is negative."
2929 (rmail-next-message (- n
)))
2931 (defun rmail-next-undeleted-message (n)
2932 "Show following non-deleted message.
2933 With prefix arg N, moves forward N non-deleted messages,
2934 or backward if N is negative.
2936 Returns t if a new message is being shown, nil otherwise."
2938 (set-buffer rmail-buffer
)
2939 (rmail-maybe-set-message-counters)
2940 (let ((lastwin rmail-current-message
)
2941 (current rmail-current-message
))
2942 (while (and (> n
0) (< current rmail-total-messages
))
2943 (setq current
(1+ current
))
2944 (if (not (rmail-message-deleted-p current
))
2945 (setq lastwin current n
(1- n
))))
2946 (while (and (< n
0) (> current
1))
2947 (setq current
(1- current
))
2948 (if (not (rmail-message-deleted-p current
))
2949 (setq lastwin current n
(1+ n
))))
2950 (if (/= lastwin rmail-current-message
)
2951 (progn (rmail-show-message lastwin
)
2954 (message "No previous nondeleted message"))
2956 (message "No following nondeleted message"))
2959 (defun rmail-previous-undeleted-message (n)
2960 "Show previous non-deleted message.
2961 With prefix argument N, moves backward N non-deleted messages,
2962 or forward if N is negative."
2964 (rmail-next-undeleted-message (- n
)))
2966 (defun rmail-first-message ()
2967 "Show first message in file."
2969 (rmail-maybe-set-message-counters)
2970 (rmail-show-message 1))
2972 (defun rmail-last-message ()
2973 "Show last message in file."
2975 (rmail-maybe-set-message-counters)
2976 (rmail-show-message rmail-total-messages
))
2978 (defun rmail-what-message ()
2979 (let ((where (point))
2981 (high rmail-total-messages
)
2982 (mid (/ rmail-total-messages
2)))
2983 (while (> (- high low
) 1)
2984 (if (>= where
(rmail-msgbeg mid
))
2987 (setq mid
(+ low
(/ (- high low
) 2))))
2988 (if (>= where
(rmail-msgbeg high
)) high low
)))
2990 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
2992 (goto-char (rmail-msgbeg msg
))
2993 (search-forward "\n*** EOOH ***\n")
2994 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
2995 (or (string-match recipients
(or (mail-fetch-field "To") ""))
2996 (string-match recipients
(or (mail-fetch-field "From") ""))
2997 (if (not primary-only
)
2998 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
3000 (defun rmail-message-regexp-p (n regexp
)
3001 "Return t, if for message number N, regexp REGEXP matches in the header."
3002 (let ((beg (rmail-msgbeg n
))
3003 (end (rmail-msgend n
)))
3008 (if (prog1 (= (following-char) ?
0)
3010 ;; If there's a Summary-line in the (otherwise empty)
3011 ;; header, we didn't yet get past the EOOH line.
3012 (when (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
3015 (narrow-to-region (point) end
))
3020 (search-forward "\n*** EOOH ***\n" end t
)
3021 (setq end
(1+ (match-beginning 0)))))
3023 (if rmail-enable-mime
3024 (funcall rmail-search-mime-header-function n regexp end
)
3025 (re-search-forward regexp end t
)))))
3027 (defun rmail-search-message (msg regexp
)
3028 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3029 (goto-char (rmail-msgbeg msg
))
3030 (if rmail-enable-mime
3031 (funcall rmail-search-mime-message-function msg regexp
)
3032 (re-search-forward regexp
(rmail-msgend msg
) t
)))
3034 (defvar rmail-search-last-regexp nil
)
3035 (defun rmail-search (regexp &optional n
)
3036 "Show message containing next match for REGEXP (but not the current msg).
3037 Prefix argument gives repeat count; negative argument means search
3038 backwards (through earlier messages).
3039 Interactively, empty argument means use same regexp used last time."
3041 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3043 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3047 (if rmail-search-last-regexp
3048 (concat ", default "
3049 rmail-search-last-regexp
"): ")
3051 (setq regexp
(read-string prompt
))
3052 (cond ((not (equal regexp
""))
3053 (setq rmail-search-last-regexp regexp
))
3054 ((not rmail-search-last-regexp
)
3055 (error "No previous Rmail search string")))
3056 (list rmail-search-last-regexp
3057 (prefix-numeric-value current-prefix-arg
))))
3059 (message "%sRmail search for %s..."
3060 (if (< n
0) "Reverse " "")
3062 (set-buffer rmail-buffer
)
3063 (rmail-maybe-set-message-counters)
3064 (let ((omin (point-min))
3069 (msg rmail-current-message
))
3074 ;; Check messages one by one, advancing message number up or down
3075 ;; but searching forward through each message.
3077 (while (and (null win
) (> msg
1))
3079 win
(rmail-search-message msg regexp
)))
3080 (while (and (null win
) (< msg rmail-total-messages
))
3082 win
(rmail-search-message msg regexp
))))
3083 (setq n
(+ n
(if reversep
1 -
1)))))
3086 (rmail-show-message msg
)
3087 ;; Search forward (if this is a normal search) or backward
3088 ;; (if this is a reverse search) through this message to
3089 ;; position point. This search may fail because REGEXP
3090 ;; was found in the hidden portion of this message. In
3091 ;; that case, move point to the beginning of visible
3095 (goto-char (point-max))
3096 (re-search-backward regexp nil
'move
))
3097 (goto-char (point-min))
3098 (re-search-forward regexp nil t
))
3099 (message "%sRmail search for %s...done"
3100 (if reversep
"Reverse " "")
3103 (narrow-to-region omin omax
)
3105 (message "Search failed: %s" regexp
)))))
3107 (defun rmail-search-backwards (regexp &optional n
)
3108 "Show message containing previous match for REGEXP.
3109 Prefix argument gives repeat count; negative argument means search
3110 forward (through later messages).
3111 Interactively, empty argument means use same regexp used last time."
3113 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3115 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3119 (if rmail-search-last-regexp
3120 (concat ", default "
3121 rmail-search-last-regexp
"): ")
3123 (setq regexp
(read-string prompt
))
3124 (cond ((not (equal regexp
""))
3125 (setq rmail-search-last-regexp regexp
))
3126 ((not rmail-search-last-regexp
)
3127 (error "No previous Rmail search string")))
3128 (list rmail-search-last-regexp
3129 (prefix-numeric-value current-prefix-arg
))))
3130 (rmail-search regexp
(- (or n
1))))
3132 ;; Show the first message which has the `unseen' attribute.
3133 (defun rmail-first-unseen-message ()
3134 (rmail-maybe-set-message-counters)
3139 (while (and (not found
) (<= current rmail-total-messages
))
3140 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
3141 (setq found current
))
3142 (setq current
(1+ current
))))
3143 ;; Let the caller show the message.
3145 ;; (rmail-show-message found))
3148 (defun rmail-current-subject ()
3149 "Return the current subject.
3150 The subject is stripped of leading and trailing whitespace, and
3151 of typical reply prefixes such as Re:."
3152 (let ((subject (or (mail-fetch-field "Subject") "")))
3153 (if (string-match "\\`[ \t]+" subject
)
3154 (setq subject
(substring subject
(match-end 0))))
3155 (if (string-match rmail-reply-regexp subject
)
3156 (setq subject
(substring subject
(match-end 0))))
3157 (if (string-match "[ \t]+\\'" subject
)
3158 (setq subject
(substring subject
0 (match-beginning 0))))
3161 (defun rmail-current-subject-regexp ()
3162 "Return a regular expression matching the current subject.
3163 The regular expression matches the subject header line of
3164 messages about the same subject. The subject itself is stripped
3165 of leading and trailing whitespace, of typical reply prefixes
3166 such as Re: and whitespace within the subject is replaced by a
3167 regular expression matching whitespace in general in order to
3168 take into account that subject header lines may include newlines
3169 and more whitespace. The returned regular expressions contains
3170 `rmail-reply-regexp' and ends with a newline."
3171 (let ((subject (rmail-current-subject)))
3172 ;; If Subject is long, mailers will break it into several lines at
3173 ;; arbitrary places, so replace whitespace with a regexp that will
3174 ;; match any sequence of spaces, TABs, and newlines.
3175 (setq subject
(regexp-quote subject
))
3177 (replace-regexp-in-string "[ \t\n]+" "[ \t\n]+" subject t t
))
3178 (concat "^Subject: "
3179 (if (string= "\\`" (substring rmail-reply-regexp
0 2))
3180 (substring rmail-reply-regexp
2)
3182 subject
"[ \t]*\n")))
3184 (defun rmail-next-same-subject (n)
3185 "Go to the next mail message having the same subject header.
3186 With prefix argument N, do this N times.
3187 If N is negative, go backwards instead."
3189 (let ((search-regexp (rmail-current-subject-regexp))
3191 (i rmail-current-message
)
3192 (case-fold-search t
)
3197 (while (and (/= n
0)
3199 (< i rmail-total-messages
)
3202 (while (and (not done
)
3204 (< i rmail-total-messages
)
3206 (setq i
(if forward
(1+ i
) (1- i
)))
3207 (goto-char (rmail-msgbeg i
))
3208 (search-forward "\n*** EOOH ***\n")
3209 (let ((beg (point)) end
)
3210 (search-forward "\n\n")
3213 (setq done
(re-search-forward search-regexp end t
))))
3214 (if done
(setq found i
)))
3215 (setq n
(if forward
(1- n
) (1+ n
))))))
3217 (rmail-show-message found
)
3218 (error "No %s message with same subject"
3219 (if forward
"following" "previous")))))
3221 (defun rmail-previous-same-subject (n)
3222 "Go to the previous mail message having the same subject header.
3223 With prefix argument N, do this N times.
3224 If N is negative, go forwards instead."
3226 (rmail-next-same-subject (- n
)))
3228 ;;;; *** Rmail Message Deletion Commands ***
3230 (defun rmail-message-deleted-p (n)
3231 (= (aref rmail-deleted-vector n
) ?D
))
3233 (defun rmail-set-message-deleted-p (n state
)
3234 (aset rmail-deleted-vector n
(if state ?D ?\
)))
3236 (defun rmail-delete-message ()
3237 "Delete this message and stay on it."
3239 (rmail-set-attribute "deleted" t
)
3240 (run-hooks 'rmail-delete-message-hook
))
3242 (defun rmail-undelete-previous-message ()
3243 "Back up to deleted message, select it, and undelete it."
3245 (set-buffer rmail-buffer
)
3246 (let ((msg rmail-current-message
))
3247 (while (and (> msg
0)
3248 (not (rmail-message-deleted-p msg
)))
3249 (setq msg
(1- msg
)))
3251 (error "No previous deleted message")
3252 (if (/= msg rmail-current-message
)
3253 (rmail-show-message msg
))
3254 (rmail-set-attribute "deleted" nil
)
3255 (if (rmail-summary-exists)
3257 (set-buffer rmail-summary-buffer
)
3258 (rmail-summary-mark-undeleted msg
)))
3259 (rmail-maybe-display-summary))))
3261 (defun rmail-delete-forward (&optional backward
)
3262 "Delete this message and move to next nondeleted one.
3263 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3264 With prefix argument, delete and move backward.
3266 Returns t if a new message is displayed after the delete, or nil otherwise."
3268 (rmail-set-attribute "deleted" t
)
3269 (run-hooks 'rmail-delete-message-hook
)
3270 (let ((del-msg rmail-current-message
))
3271 (if (rmail-summary-exists)
3272 (rmail-select-summary
3273 (rmail-summary-mark-deleted del-msg
)))
3274 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3275 (rmail-maybe-display-summary))))
3277 (defun rmail-delete-backward ()
3278 "Delete this message and move to previous nondeleted one.
3279 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3281 (rmail-delete-forward t
))
3283 ;; Compute the message number a given message would have after expunging.
3284 ;; The present number of the message is OLDNUM.
3285 ;; DELETEDVEC should be rmail-deleted-vector.
3286 ;; The value is nil for a message that would be deleted.
3287 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3288 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3293 (if (/= (aref deletedvec i
) ?D
)
3294 (setq newnum
(1+ newnum
)))
3298 (defun rmail-expunge-confirmed ()
3299 "Return t if deleted message should be expunged. If necessary, ask the user.
3300 See also user-option `rmail-confirm-expunge'."
3301 (set-buffer rmail-buffer
)
3302 (or (not (stringp rmail-deleted-vector
))
3303 (not (string-match "D" rmail-deleted-vector
))
3304 (null rmail-confirm-expunge
)
3305 (funcall rmail-confirm-expunge
3306 "Erase deleted messages from Rmail file? ")))
3308 (defun rmail-only-expunge (&optional dont-show
)
3309 "Actually erase all deleted messages in the file."
3311 (set-buffer rmail-buffer
)
3312 (message "Expunging deleted messages...")
3313 ;; Discard all undo records for this buffer.
3314 (or (eq buffer-undo-list t
)
3315 (setq buffer-undo-list nil
))
3316 (rmail-maybe-set-message-counters)
3317 (let* ((omax (- (buffer-size) (point-max)))
3318 (omin (- (buffer-size) (point-min)))
3319 (opoint (if (and (> rmail-current-message
0)
3320 (rmail-message-deleted-p rmail-current-message
))
3322 (if rmail-enable-mime
3323 (with-current-buffer rmail-view-buffer
3324 (- (point)(point-min)))
3325 (- (point) (point-min)))))
3326 (messages-head (cons (aref rmail-message-vector
0) nil
))
3327 (messages-tail messages-head
)
3328 ;; Don't make any undo records for the expunging.
3329 (buffer-undo-list t
)
3334 (goto-char (point-min))
3337 (total rmail-total-messages
)
3338 (new-message-number rmail-current-message
)
3340 (new-msgref (list (list 0)))
3341 (rmailbuf (current-buffer))
3342 (buffer-read-only nil
)
3343 (messages rmail-message-vector
)
3344 (deleted rmail-deleted-vector
)
3345 (summary rmail-summary-vector
))
3346 (setq rmail-total-messages nil
3347 rmail-current-message nil
3348 rmail-message-vector nil
3349 rmail-deleted-vector nil
3350 rmail-summary-vector nil
)
3352 (while (<= number total
)
3353 (if (= (aref deleted number
) ?D
)
3356 (marker-position (aref messages number
))
3357 (marker-position (aref messages
(1+ number
))))
3358 (move-marker (aref messages number
) nil
)
3359 (if (> new-message-number counter
)
3360 (setq new-message-number
(1- new-message-number
))))
3361 (setq counter
(1+ counter
))
3363 (setcdr messages-tail
3364 (cons (aref messages number
) nil
)))
3366 (cons (if (= counter number
) (aref summary
(1- number
)))
3369 (cons (aref rmail-msgref-vector number
)
3371 (setcar (car new-msgref
) counter
))
3372 (if (zerop (%
(setq number
(1+ number
)) 20))
3373 (message "Expunging deleted messages...%d" number
)))
3375 (setcdr messages-tail
3376 (cons (aref messages number
) nil
)))
3377 (setq rmail-current-message new-message-number
3378 rmail-total-messages counter
3379 rmail-message-vector
(apply 'vector messages-head
)
3380 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
3381 rmail-summary-vector
(vconcat (nreverse new-summary
))
3382 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3384 (message "Expunging deleted messages...done")
3386 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3389 (if (zerop rmail-current-message
) 1 nil
)))
3390 (if rmail-enable-mime
3391 (goto-char (+ (point-min) opoint
))
3392 (goto-char (+ (point) opoint
))))))
3394 (defun rmail-expunge ()
3395 "Erase deleted messages from Rmail file and summary buffer."
3397 (when (rmail-expunge-confirmed)
3398 (rmail-only-expunge)
3399 (if (rmail-summary-exists)
3400 (rmail-select-summary (rmail-update-summary)))))
3402 ;;;; *** Rmail Mailing Commands ***
3404 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3405 replybuffer sendactions same-window others
)
3408 (setq yank-action
(list 'insert-buffer replybuffer
)))
3409 (setq others
(cons (cons "cc" cc
) others
))
3410 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
3412 (compose-mail to subject others
3414 yank-action sendactions
)
3415 (if rmail-mail-new-frame
3417 (compose-mail to subject others
3418 noerase
'switch-to-buffer-other-frame
3419 yank-action sendactions
)
3420 ;; This is not a standard frame parameter;
3421 ;; nothing except sendmail.el looks at it.
3422 (modify-frame-parameters (selected-frame)
3423 '((mail-dedicated-frame . t
))))
3424 (compose-mail to subject others
3425 noerase
'switch-to-buffer-other-window
3426 yank-action sendactions
)))))
3428 (defun rmail-mail ()
3429 "Send mail in another window.
3430 While composing the message, use \\[mail-yank-original] to yank the
3431 original message into it."
3433 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
3435 (defun rmail-continue ()
3436 "Continue composing outgoing message previously being composed."
3438 (rmail-start-mail t
))
3440 (defun rmail-reply (just-sender)
3441 "Reply to the current message.
3442 Normally include CC: to all other recipients of original message;
3443 prefix argument means ignore them. While composing the reply,
3444 use \\[mail-yank-original] to yank the original message into it."
3446 (let (from reply-to cc subject date to message-id references
3447 resent-to resent-cc resent-reply-to
3448 (msgnum rmail-current-message
))
3451 (if rmail-enable-mime
3453 (goto-char (point-min))
3454 (if (search-forward "\n\n" nil
'move
)
3455 (1+ (match-beginning 0))
3458 (goto-char (rmail-msgbeg rmail-current-message
))
3460 (if (= (following-char) ?
0)
3462 (progn (forward-line 2)
3464 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
3467 (narrow-to-region (point)
3468 (progn (search-forward "\n*** EOOH ***\n")
3469 (beginning-of-line) (point)))))
3470 (setq from
(mail-fetch-field "from")
3471 reply-to
(or (mail-fetch-field "mail-reply-to" nil t
)
3472 (mail-fetch-field "reply-to" nil t
)
3474 subject
(mail-fetch-field "subject")
3475 date
(mail-fetch-field "date")
3476 message-id
(mail-fetch-field "message-id")
3477 references
(mail-fetch-field "references" nil nil t
)
3478 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3479 resent-cc
(and (not just-sender
)
3480 (mail-fetch-field "resent-cc" nil t
))
3481 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
3482 ;;; resent-subject (mail-fetch-field "resent-subject")
3483 ;;; resent-date (mail-fetch-field "resent-date")
3484 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3487 (if (mail-fetch-field "mail-followup-to" nil t
)
3488 ;; If this header field is present, use it instead of the To and CC fields.
3489 (setq to
(mail-fetch-field "mail-followup-to" nil t
))
3490 (setq cc
(or (mail-fetch-field "cc" nil t
) "")
3491 to
(or (mail-fetch-field "to" nil t
) ""))))
3495 ;; Merge the resent-to and resent-cc into the to and cc.
3496 (if (and resent-to
(not (equal resent-to
"")))
3497 (if (not (equal to
""))
3498 (setq to
(concat to
", " resent-to
))
3499 (setq to resent-to
)))
3500 (if (and resent-cc
(not (equal resent-cc
"")))
3501 (if (not (equal cc
""))
3502 (setq cc
(concat cc
", " resent-cc
))
3503 (setq cc resent-cc
)))
3504 ;; Add `Re: ' to subject if not there already.
3505 (and (stringp subject
)
3507 (concat rmail-reply-prefix
3508 (if (let ((case-fold-search t
))
3509 (string-match rmail-reply-regexp subject
))
3510 (substring subject
(match-end 0))
3514 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3515 ;; since they can handle the names unstripped.
3516 ;; I don't know whether there are other mailers that still
3517 ;; need the names to be stripped.
3518 ;;; (mail-strip-quoted-names reply-to)
3519 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3520 ;; header causes all the names in it to wind up in reply-to, not
3521 ;; in cc. But if what's left is an empty list, use the original.
3522 (let* ((reply-to-list (rmail-dont-reply-to reply-to
)))
3523 (if (string= reply-to-list
"") reply-to reply-to-list
))
3525 (rmail-make-in-reply-to-field from date message-id
)
3528 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
3530 (let* ((cc-list (rmail-dont-reply-to
3531 (mail-strip-quoted-names
3532 (if (null cc
) to
(concat to
", " cc
))))))
3533 (if (string= cc-list
"") nil cc-list
)))
3535 (list (list 'rmail-mark-message
3537 (with-current-buffer rmail-buffer
3538 (aref rmail-msgref-vector msgnum
))
3541 (list (cons "References" (concat (mapconcat 'identity references
" ")
3542 " " message-id
))))))
3544 (defun rmail-mark-message (buffer msgnum-list attribute
)
3545 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3546 This is use in the send-actions for message buffers.
3547 MSGNUM-LIST is a list of the form (MSGNUM)
3548 which is an element of rmail-msgref-vector."
3551 (if (car msgnum-list
)
3552 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3554 (defun rmail-make-in-reply-to-field (from date message-id
)
3561 (let ((tem (car (rfc822-addresses from
))))
3565 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3567 (match-beginning 0))
3570 ;; missing From, or Message-ID is sufficiently informative
3572 (concat message-id
" (" tem
")"))
3573 ;; Copy TEM, discarding text properties.
3574 (setq tem
(copy-sequence tem
))
3575 (set-text-properties 0 (length tem
) nil tem
)
3576 (setq tem
(copy-sequence tem
))
3577 ;; Use prin1 to fake RFC822 quoting
3578 (let ((field (prin1-to-string tem
)))
3580 (concat field
"'s message of " date
)
3582 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3583 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3584 ;; These strings both match all non-ASCII characters.
3585 (or (string-match (concat "\\`[ \t]*\\(" bar
3586 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3587 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3589 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3590 bar
"\\))[ \t]*\\'")
3591 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3593 (let ((start (match-beginning 1))
3594 (end (match-end 1)))
3595 ;; Trim whitespace which above regexp match allows
3596 (while (and (< start end
)
3597 (memq (aref from start
) '(?
\t ?\
)))
3598 (setq start
(1+ start
)))
3599 (while (and (< start end
)
3600 (memq (aref from
(1- end
)) '(?
\t ?\
)))
3601 (setq end
(1- end
)))
3602 (let ((field (substring from start end
)))
3603 (if date
(setq field
(concat "message from " field
" on " date
)))
3605 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3606 (concat message-id
" (" field
")")
3609 ;; If we can't kludge it simply, do it correctly
3610 (let ((mail-use-rfc822 t
))
3611 (rmail-make-in-reply-to-field from date message-id
)))))
3613 (defun rmail-forward (resend)
3614 "Forward the current message to another user.
3615 With prefix argument, \"resend\" the message instead of forwarding it;
3616 see the documentation of `rmail-resend'."
3619 (call-interactively 'rmail-resend
)
3620 (let ((forward-buffer rmail-buffer
)
3621 (msgnum rmail-current-message
)
3622 (subject (concat "["
3623 (let ((from (or (mail-fetch-field "From")
3624 (mail-fetch-field ">From"))))
3626 (concat (mail-strip-quoted-names from
) ": ")
3628 (or (mail-fetch-field "Subject") "")
3630 (if (rmail-start-mail
3631 nil nil subject nil nil nil
3632 (list (list 'rmail-mark-message
3634 (with-current-buffer rmail-buffer
3635 (aref rmail-msgref-vector msgnum
))
3637 ;; If only one window, use it for the mail buffer.
3638 ;; Otherwise, use another window for the mail buffer
3639 ;; so that the Rmail buffer remains visible
3640 ;; and sending the mail will get back to it.
3641 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3642 ;; The mail buffer is now current.
3644 ;; Insert after header separator--before signature if any.
3645 (goto-char (mail-text-start))
3646 (if (or rmail-enable-mime rmail-enable-mime-composing
)
3647 (funcall rmail-insert-mime-forwarded-message-function
3649 (insert "------- Start of forwarded message -------\n")
3650 ;; Quote lines with `- ' if they start with `-'.
3651 (let ((beg (point)) end
)
3652 (setq end
(point-marker))
3653 (set-marker-insertion-type end t
)
3654 (insert-buffer-substring forward-buffer
)
3656 (while (re-search-forward "^-" end t
)
3661 (skip-chars-backward "\n")
3664 (delete-region (point) end
)
3665 (set-marker end nil
))
3666 (insert "------- End of forwarded message -------\n"))
3669 (defun rmail-resend (address &optional from comment mail-alias-file
)
3670 "Resend current message to ADDRESSES.
3671 ADDRESSES should be a single address, a string consisting of several
3672 addresses separated by commas, or a list of addresses.
3674 Optional FROM is the address to resend the message from, and
3675 defaults from the value of `user-mail-address'.
3676 Optional COMMENT is a string to insert as a comment in the resent message.
3677 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3678 typically for purposes of moderating a list."
3679 (interactive "sResend to: ")
3681 (require 'mailalias
)
3682 (unless (or (eq rmail-view-buffer
(current-buffer))
3683 (eq rmail-buffer
(current-buffer)))
3684 (error "Not an Rmail buffer"))
3685 (if (not from
) (setq from user-mail-address
))
3686 (let ((tembuf (generate-new-buffer " sendmail temp"))
3687 (case-fold-search nil
)
3688 (mail-personal-alias-file
3689 (or mail-alias-file mail-personal-alias-file
))
3690 (mailbuf rmail-buffer
))
3692 (with-current-buffer tembuf
3693 ;;>> Copy message into temp buffer
3694 (if rmail-enable-mime
3695 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3696 (insert-buffer-substring mailbuf
))
3697 (goto-char (point-min))
3698 ;; Delete any Sender field, since that's not specifiable.
3699 ; Only delete Sender fields in the actual header.
3700 (re-search-forward "^$" nil
'move
)
3701 ; Using "while" here rather than "if" because some buggy mail
3702 ; software may have inserted multiple Sender fields.
3703 (while (re-search-backward "^Sender:" nil t
)
3707 (while (looking-at "[ \t]")
3709 (delete-region beg
(point))))
3710 ; Go back to the beginning of the buffer so the Resent- fields
3711 ; are inserted there.
3712 (goto-char (point-min))
3713 ;;>> Insert resent-from:
3714 (insert "Resent-From: " from
"\n")
3715 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3716 ;;>> Insert resent-to: and bcc if need be.
3717 (let ((before (point)))
3719 (insert "Resent-Bcc: " (user-login-name) "\n"))
3720 (insert "Resent-To: " (if (stringp address
)
3722 (mapconcat 'identity address
",\n\t"))
3724 ;; Expand abbrevs in the recipients.
3726 (if (featurep 'mailabbrev
)
3727 (let ((end (point-marker))
3728 (local-abbrev-table mail-abbrevs
)
3729 (old-syntax-table (syntax-table)))
3730 (if (and (not (vectorp mail-abbrevs
))
3731 (file-exists-p mail-personal-alias-file
))
3732 (build-mail-abbrevs))
3733 (unless mail-abbrev-syntax-table
3734 (mail-abbrev-make-syntax-table))
3735 (set-syntax-table mail-abbrev-syntax-table
)
3737 (while (and (< (point) end
)
3738 (progn (forward-word 1)
3741 (set-syntax-table old-syntax-table
))
3742 (expand-mail-aliases before
(point)))))
3743 ;;>> Set up comment, if any.
3744 (if (and (sequencep comment
) (not (zerop (length comment
))))
3745 (let ((before (point))
3748 (or (eolp) (insert "\n"))
3749 (setq after
(point))
3751 (while (< (point) after
)
3752 (insert "Resent-Comment: ")
3754 ;; Don't expand aliases in the destination fields
3755 ;; of the original message.
3757 (funcall send-mail-function
)))
3758 (kill-buffer tembuf
))
3759 (with-current-buffer rmail-buffer
3760 (rmail-set-attribute "resent" t rmail-current-message
))))
3762 (defvar mail-unsent-separator
3763 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3764 "^ *---+ +Returned message +---+ *$\\|"
3765 "^ *---+ *Returned mail follows *---+ *$\\|"
3766 "^Start of returned message$\\|"
3767 "^---+ Below this line is a copy of the message.$\\|"
3768 "^ *---+ +Original message +---+ *$\\|"
3769 "^ *--+ +begin message +--+ *$\\|"
3770 "^ *---+ +Original message follows +---+ *$\\|"
3771 "^ *---+ +Your message follows +---+ *$\\|"
3772 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3773 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3774 "A regexp that matches the separator before the text of a failed message.")
3776 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3777 "A regexp that matches the header of a MIME body part with a failed message.")
3779 (defun rmail-retry-failure ()
3780 "Edit a mail message which is based on the contents of the current message.
3781 For a message rejected by the mail system, extract the interesting headers and
3782 the body of the original message.
3783 If the failed message is a MIME multipart message, it is searched for a
3784 body part with a header which matches the variable `mail-mime-unsent-header'.
3785 Otherwise, the variable `mail-unsent-separator' should match the string that
3786 delimits the returned original message.
3787 The variable `rmail-retry-ignored-headers' is a regular expression
3788 specifying headers which should not be copied into the new message."
3790 (require 'mail-utils
)
3791 (let ((rmail-this-buffer (current-buffer))
3792 (msgnum rmail-current-message
)
3793 bounce-start bounce-end bounce-indent resending
3794 ;; Fetch any content-type header in current message
3795 ;; Must search thru the whole unpruned header.
3799 (rmail-narrow-to-non-pruned-header)
3800 (mail-fetch-field "Content-Type") ))))
3802 (goto-char (point-min))
3803 (let ((case-fold-search t
))
3804 (if (and content-type
3806 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3808 ;; Handle a MIME multipart bounce message.
3811 (substring content-type
(match-beginning 1)
3813 (unless (re-search-forward mail-mime-unsent-header nil t
)
3814 (error "Cannot find beginning of header in failed message"))
3815 (unless (search-forward "\n\n" nil t
)
3816 (error "Cannot find start of Mime data in failed message"))
3817 (setq bounce-start
(point))
3818 (if (search-forward codestring nil t
)
3819 (setq bounce-end
(match-beginning 0))
3820 (setq bounce-end
(point-max))))
3822 (or (re-search-forward mail-unsent-separator nil t
)
3823 (error "Cannot parse this as a failure message"))
3824 (skip-chars-forward "\n")
3825 ;; Support a style of failure message in which the original
3826 ;; message is indented, and included within lines saying
3827 ;; `Start of returned message' and `End of returned message'.
3828 (if (looking-at " +Received:")
3830 (setq bounce-start
(point))
3831 (skip-chars-forward " ")
3832 (setq bounce-indent
(- (current-column)))
3833 (goto-char (point-max))
3834 (re-search-backward "^End of returned message$" nil t
)
3835 (setq bounce-end
(point)))
3836 ;; One message contained a few random lines before
3837 ;; the old message header. The first line of the
3838 ;; message started with two hyphens. A blank line
3839 ;; followed these random lines. The same line
3840 ;; beginning with two hyphens was possibly marking
3841 ;; the end of the message.
3842 (if (looking-at "^--")
3843 (let ((boundary (buffer-substring-no-properties
3845 (progn (end-of-line) (point)))))
3846 (search-forward "\n\n")
3847 (skip-chars-forward "\n")
3848 (setq bounce-start
(point))
3849 (goto-char (point-max))
3850 (search-backward (concat "\n\n" boundary
) bounce-start t
)
3851 (setq bounce-end
(point)))
3852 (setq bounce-start
(point)
3853 bounce-end
(point-max)))
3854 (unless (search-forward "\n\n" nil t
)
3855 (error "Cannot find end of header in failed message"))))))
3856 ;; We have found the message that bounced, within the current message.
3857 ;; Now start sending new message; default header fields from original.
3858 ;; Turn off the usual actions for initializing the message body
3859 ;; because we want to get only the text from the failure message.
3860 (let (mail-signature mail-setup-hook
)
3861 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3862 (list (list 'rmail-mark-message
3864 (aref rmail-msgref-vector msgnum
)
3866 ;; Insert original text as initial text of new draft message.
3867 ;; Bind inhibit-read-only since the header delimiter
3868 ;; of the previous message was probably read-only.
3869 (let ((inhibit-read-only t
)
3870 rmail-displayed-headers
3871 rmail-ignored-headers
)
3873 (insert-buffer-substring rmail-this-buffer
3874 bounce-start bounce-end
)
3875 (goto-char (point-min))
3877 (indent-rigidly (point-min) (point-max) bounce-indent
))
3878 (rmail-clear-headers rmail-retry-ignored-headers
)
3879 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:")
3880 (mail-sendmail-delimit-header)
3882 (narrow-to-region (point-min) (mail-header-end))
3883 (setq resending
(mail-fetch-field "resent-to"))
3886 (insert "Resent-Bcc: " (user-login-name) "\n")
3887 (insert "BCC: " (user-login-name) "\n"))))
3888 (goto-char (point-min))
3889 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
3891 (defun rmail-summary-exists ()
3892 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
3893 In fact, the non-nil value returned is the summary buffer itself."
3894 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3895 rmail-summary-buffer
))
3897 (defun rmail-summary-displayed ()
3898 "t iff in RMAIL buffer and an associated summary buffer is displayed."
3899 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
3901 (defcustom rmail-redisplay-summary nil
3902 "*Non-nil means Rmail should show the summary when it changes.
3903 This has an effect only if a summary buffer exists."
3905 :group
'rmail-summary
)
3907 (defcustom rmail-summary-window-size nil
3908 "*Non-nil means specify the height for an Rmail summary window."
3909 :type
'(choice (const :tag
"Disabled" nil
) integer
)
3910 :group
'rmail-summary
)
3912 ;; Put the summary buffer back on the screen, if user wants that.
3913 (defun rmail-maybe-display-summary ()
3914 (let ((selected (selected-window))
3916 ;; If requested, make sure the summary is displayed.
3917 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3918 rmail-redisplay-summary
3919 (if (get-buffer-window rmail-summary-buffer
0)
3920 ;; It's already in some frame; show that one.
3921 (let ((frame (window-frame
3922 (get-buffer-window rmail-summary-buffer
0))))
3923 (make-frame-visible frame
)
3924 (raise-frame frame
))
3925 (display-buffer rmail-summary-buffer
)))
3926 ;; If requested, set the height of the summary window.
3927 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3928 rmail-summary-window-size
3929 (setq window
(get-buffer-window rmail-summary-buffer
))
3930 ;; Don't try to change the size if just one window in frame.
3931 (not (eq window
(frame-root-window (window-frame window
))))
3934 (select-window window
)
3935 (enlarge-window (- rmail-summary-window-size
(window-height))))
3936 (select-window selected
)))))
3938 ;;;; *** Rmail Local Fontification ***
3940 (defun rmail-fontify-buffer-function ()
3941 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3942 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
3943 ;; If we're already showing a message, fontify it now.
3944 (if rmail-current-message
(rmail-fontify-message))
3945 ;; Prevent Font Lock mode from kicking in.
3946 (setq font-lock-fontified t
))
3948 (defun rmail-unfontify-buffer-function ()
3949 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
3950 (let ((modified (buffer-modified-p))
3951 (buffer-undo-list t
) (inhibit-read-only t
)
3952 before-change-functions after-change-functions
3953 buffer-file-name buffer-file-truename
)
3956 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
3957 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
3958 (font-lock-default-unfontify-buffer)
3959 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
3961 (defun rmail-fontify-message ()
3962 ;; Fontify the current message if it is not already fontified.
3963 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
3964 (let ((modified (buffer-modified-p))
3965 (buffer-undo-list t
) (inhibit-read-only t
)
3966 before-change-functions after-change-functions
3967 buffer-file-name buffer-file-truename
)
3970 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
3971 (font-lock-fontify-region (point-min) (point-max))
3972 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
3974 ;;; Speedbar support for RMAIL files.
3975 (eval-when-compile (require 'speedbar
))
3977 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
3978 "*This regex is used to match folder names to be displayed in speedbar.
3979 Enabling this will permit speedbar to display your folders for easy
3980 browsing, and moving of messages.")
3982 (defvar rmail-speedbar-last-user nil
3983 "The last user to be displayed in the speedbar.")
3985 (defvar rmail-speedbar-key-map nil
3986 "Keymap used when in rmail display mode.")
3988 (defun rmail-install-speedbar-variables ()
3989 "Install those variables used by speedbar to enhance rmail."
3990 (if rmail-speedbar-key-map
3992 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
3994 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
3995 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
3996 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
3997 (define-key rmail-speedbar-key-map
"M"
3998 'rmail-speedbar-move-message-to-folder-on-line
)))
4000 (defvar rmail-speedbar-menu-items
4001 '(["Read Folder" speedbar-edit-line t
]
4002 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4003 (save-excursion (beginning-of-line)
4004 (looking-at "<M> "))])
4005 "Additional menu-items to add to speedbar frame.")
4007 ;; Make sure our special speedbar major mode is loaded
4008 (if (featurep 'speedbar
)
4009 (rmail-install-speedbar-variables)
4010 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
4012 (defun rmail-speedbar-buttons (buffer)
4013 "Create buttons for BUFFER containing rmail messages.
4014 Click on the address under Reply to: to reply to this person.
4015 Under Folders: Click a name to read it, or on the <M> to move the
4016 current message into that RMAIL folder."
4020 (goto-char (point-min))
4021 (if (not (re-search-forward "^Reply-To: " nil t
))
4022 (if (not (re-search-forward "^From:? " nil t
))
4026 (setq from
(buffer-substring (point) (save-excursion
4029 (goto-char (point-min))
4030 (if (and (looking-at "Reply to:")
4031 (equal from rmail-speedbar-last-user
))
4033 (setq rmail-speedbar-last-user from
)
4035 (insert "Reply To:\n")
4037 (speedbar-insert-button from
'speedbar-directory-face
'highlight
4038 'rmail-speedbar-button
'rmail-reply
))
4039 (insert "Folders:\n")
4040 (let* ((case-fold-search nil
)
4041 (df (directory-files (save-excursion (set-buffer buffer
)
4043 nil rmail-speedbar-match-folder-regexp
)))
4045 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
4046 'rmail-speedbar-move-message
(car df
))
4047 (speedbar-insert-button (car df
) 'speedbar-file-face
'highlight
4048 'rmail-speedbar-find-file nil t
)
4049 (setq df
(cdr df
)))))))
4051 (defun rmail-speedbar-button (text token indent
)
4052 "Execute an rmail command specified by TEXT.
4053 The command used is TOKEN. INDENT is not used."
4054 (speedbar-with-attached-buffer
4057 (defun rmail-speedbar-find-file (text token indent
)
4058 "Load in the rmail file TEXT.
4059 TOKEN and INDENT are not used."
4060 (speedbar-with-attached-buffer
4061 (message "Loading in RMAIL file %s..." text
)
4064 (defun rmail-speedbar-move-message-to-folder-on-line ()
4065 "If the current line is a folder, move current message to it."
4069 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t
)
4072 (speedbar-do-function-pointer)))))
4074 (defun rmail-speedbar-move-message (text token indent
)
4075 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4076 TEXT and INDENT are not used."
4077 (speedbar-with-attached-buffer
4078 (message "Moving message to %s" token
)
4079 (rmail-output-to-rmail-file token
)))
4081 ; Functions for setting, getting and encoding the POP password.
4082 ; The password is encoded to prevent it from being easily accessible
4083 ; to "prying eyes." Obviously, this encoding isn't "real security,"
4084 ; nor is it meant to be.
4087 (defun rmail-set-remote-password (password)
4088 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4089 (interactive "sPassword: ")
4091 (setq rmail-encoded-remote-password
4092 (rmail-encode-string password
(emacs-pid)))
4093 (setq rmail-remote-password nil
)
4094 (setq rmail-encoded-remote-password nil
)))
4096 (defun rmail-get-remote-password (imap)
4097 "Get the password for retrieving mail from a POP or IMAP server. If none
4098 has been set, then prompt the user for one."
4099 (when (not rmail-encoded-remote-password
)
4100 (if (not rmail-remote-password
)
4101 (setq rmail-remote-password
4102 (read-passwd (if imap
4104 "POP password: "))))
4105 (rmail-set-remote-password rmail-remote-password
)
4106 (setq rmail-remote-password nil
))
4107 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4109 (defun rmail-have-password ()
4110 (or rmail-remote-password rmail-encoded-remote-password
))
4112 (defun rmail-encode-string (string mask
)
4113 "Encode STRING with integer MASK, by taking the exclusive OR of the
4114 lowest byte in the mask with the first character of string, the
4115 second-lowest-byte with the second character of the string, etc.,
4116 restarting at the lowest byte of the mask whenever it runs out.
4117 Returns the encoded string. Calling the function again with an
4118 encoded string (and the same mask) will decode the string."
4119 (setq mask
(abs mask
)) ; doesn't work if negative
4120 (let* ((string-vector (string-to-vector string
)) (i 0)
4121 (len (length string-vector
)) (curmask mask
) charmask
)
4124 (setq curmask mask
))
4125 (setq charmask
(% curmask
256))
4126 (setq curmask
(lsh curmask -
8))
4127 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4129 (concat string-vector
)))
4131 ;;;; Desktop support
4133 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4135 desktop-buffer-misc
)
4136 "Restore an rmail buffer specified in a desktop file."
4137 (condition-case error
4139 (rmail-input desktop-buffer-file-name
)
4140 (if (eq major-mode
'rmail-mode
)
4144 (kill-buffer (current-buffer))
4147 (add-to-list 'desktop-buffer-mode-handlers
4148 '(rmail-mode . rmail-restore-desktop-buffer
))
4152 ;;; arch-tag: cff0a950-57fe-4f73-a86e-91ff75afd06c
4153 ;;; rmail.el ends here