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.
548 Even if the value is non-nil, you can't use MIME feature
549 if the feature specified by `rmail-mime-feature' is not available
551 :type
'(choice (const :tag
"on" t
)
552 (const :tag
"off" nil
)
553 (other :tag
"when asked" ask
))
556 (defvar rmail-enable-mime-composing nil
557 "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
560 (defvar rmail-show-mime-function nil
561 "Function to show MIME decoded message of RMAIL file.
562 This function is called when `rmail-enable-mime' is non-nil.
563 It is called with no argument.")
566 (defvar rmail-insert-mime-forwarded-message-function nil
567 "Function to insert a message in MIME format so it can be forwarded.
568 This function is called if `rmail-enable-mime' or
569 `rmail-enable-mime-composing' is non-nil.
570 It is called with one argument FORWARD-BUFFER, which is a
571 buffer containing the message to forward. The current buffer
572 is the outgoing mail buffer.")
575 (defvar rmail-insert-mime-resent-message-function nil
576 "Function to insert a message in MIME format so it can be resent.
577 This function is called if `rmail-enable-mime' is non-nil.
578 It is called with one argument FORWARD-BUFFER, which is a
579 buffer containing the message to forward. The current buffer
580 is the outgoing mail buffer.")
583 (defvar rmail-search-mime-message-function nil
584 "Function to check if a regexp matches a MIME message.
585 This function is called if `rmail-enable-mime' is non-nil.
586 It is called with two arguments MSG and REGEXP, where
587 MSG is the message number, REGEXP is the regular expression.")
590 (defvar rmail-search-mime-header-function nil
591 "Function to check if a regexp matches a header of MIME message.
592 This function is called if `rmail-enable-mime' is non-nil.
593 It is called with three arguments MSG, REGEXP, and LIMIT, where
594 MSG is the message number,
595 REGEXP is the regular expression,
596 LIMIT is the position specifying the end of header.")
599 (defvar rmail-mime-feature
'rmail-mime
600 "Feature to require to load MIME support in Rmail.
601 When starting Rmail, if `rmail-enable-mime' is non-nil,
602 this feature is required with `require'.
604 The default value is `rmail-mime'. This feature is provided by
605 the rmail-mime package available at <http://www.m17n.org/rmail-mime/>.")
608 (defvar rmail-decode-mime-charset t
609 "*Non-nil means a message is decoded by MIME's charset specification.
610 If this variable is nil, or the message has not MIME specification,
611 the message is decoded as normal way.
613 If the variable `rmail-enable-mime' is non-nil, this variables is
614 ignored, and all the decoding work is done by a feature specified by
615 the variable `rmail-mime-feature'.")
618 (defvar rmail-mime-charset-pattern
619 "^content-type:[ ]*text/plain;[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?"
620 "Regexp to match MIME-charset specification in a header of message.
621 The first parenthesized expression should match the MIME-charset name.")
624 ;;; Regexp matching the delimiter of messages in UNIX mail format
625 ;;; (UNIX From lines), minus the initial ^. Note that if you change
626 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
627 ;;; that knows the exact ordering of the \\( \\) subexpressions.
628 (defvar rmail-unix-mail-delimiter
629 (let ((time-zone-regexp
630 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
631 "\\|[-+]?[0-9][0-9][0-9][0-9]"
637 ;; Many things can happen to an RFC 822 mailbox before it is put into
638 ;; a `From' line. The leading phrase can be stripped, e.g.
639 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
640 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
641 ;; can be removed, e.g.
642 ;; From: joe@y.z (Joe K
644 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
647 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
648 ;; The mailbox can be removed or be replaced by white space, e.g.
649 ;; From: "Joe User"{space}{tab}
651 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
652 ;; where {space} and {tab} represent the Ascii space and tab characters.
653 ;; We want to match the results of any of these manglings.
654 ;; The following regexp rejects names whose first characters are
655 ;; obviously bogus, but after that anything goes.
656 "\\([^\0-\b\n-\r\^?].*\\)? "
658 ;; The time the message was sent.
659 "\\([^\0-\r \^?]+\\) +" ; day of the week
660 "\\([^\0-\r \^?]+\\) +" ; month
661 "\\([0-3]?[0-9]\\) +" ; day of month
662 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
664 ;; Perhaps a time zone, specified by an abbreviation, or by a
669 " \\([0-9][0-9]+\\) *"
671 ;; On some systems the time zone can appear after the year, too.
675 "\\(remote from .*\\)?"
680 (defvar rmail-font-lock-keywords
681 ;; These are all matched case-insensitively.
683 (let* ((cite-chars "[>|}]")
685 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
686 (list '("^\\(From\\|Sender\\|Resent-From\\):"
687 . font-lock-function-name-face
)
688 '("^Reply-To:.*$" . font-lock-function-name-face
)
689 '("^Subject:" . font-lock-comment-face
)
690 '("^X-Spam-Status:" . font-lock-keyword-face
)
691 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
692 . font-lock-keyword-face
)
693 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
695 (,(concat "\\=[ \t]*"
696 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
697 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
699 (beginning-of-line) (end-of-line)
700 (1 font-lock-comment-delimiter-face nil t
)
701 (5 font-lock-comment-face nil t
)))
702 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
703 . font-lock-string-face
))))
704 "Additional expressions to highlight in Rmail mode.")
706 ;; Perform BODY in the summary buffer
707 ;; in such a way that its cursor is properly updated in its own window.
708 (defmacro rmail-select-summary
(&rest body
)
709 `(let ((total rmail-total-messages
))
710 (if (rmail-summary-displayed)
711 (let ((window (selected-window)))
715 (pop-to-buffer rmail-summary-buffer
)
716 ;; rmail-total-messages is a buffer-local var
717 ;; in the rmail buffer.
718 ;; This way we make it available for the body
719 ;; even tho the rmail buffer is not current.
720 (let ((rmail-total-messages total
))
722 (select-window window
))))
724 (set-buffer rmail-summary-buffer
)
725 (let ((rmail-total-messages total
))
727 (rmail-maybe-display-summary)))
729 ;;;; *** Rmail Mode ***
731 ;; This variable is dynamically bound. The defvar is here to placate
732 ;; the byte compiler.
734 (defvar rmail-enable-multibyte nil
)
737 (defun rmail-require-mime-maybe ()
738 "Require `rmail-mime-feature' if that is non-nil.
739 Signal an error and set `rmail-mime-feature' to nil if the feature
741 (when rmail-enable-mime
743 (require rmail-mime-feature
)
747 (format "Although MIME support is requested
748 by setting `rmail-enable-mime' to non-nil, the required feature
749 `%s' (the value of `rmail-mime-feature')
750 is not available in the current session.
751 So, the MIME support is turned off for the moment."
753 (setq rmail-enable-mime nil
)))))
757 (defun rmail (&optional file-name-arg
)
758 "Read and edit incoming mail.
759 Moves messages into file named by `rmail-file-name' (a babyl format file)
760 and edits that file in RMAIL Mode.
761 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
763 May be called with file name as argument; then performs rmail editing on
764 that file, but does not copy any new mail into the file.
765 Interactively, if you supply a prefix argument, then you
766 have a chance to specify a file name with the minibuffer.
768 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
769 (interactive (if current-prefix-arg
770 (list (read-file-name "Run rmail on RMAIL file: "))))
771 (rmail-require-mime-maybe)
772 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
773 ;; Use find-buffer-visiting, not get-file-buffer, for those users
774 ;; who have find-file-visit-truename set to t.
775 (existed (find-buffer-visiting file-name
))
776 ;; This binding is necessary because we must decide if we
777 ;; need code conversion while the buffer is unibyte
778 ;; (i.e. enable-multibyte-characters is nil).
779 (rmail-enable-multibyte
781 (with-current-buffer existed enable-multibyte-characters
)
782 (default-value 'enable-multibyte-characters
)))
783 ;; Since the file may contain messages of different encodings
784 ;; at the tail (non-BYBYL part), we can't decode them at once
785 ;; on reading. So, at first, we read the file without text
786 ;; code conversion, then decode the messages one by one by
787 ;; rmail-decode-babyl-format or
788 ;; rmail-convert-to-babyl-format.
789 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
790 run-mail-hook msg-shown
)
791 ;; Like find-file, but in the case where a buffer existed
792 ;; and the file was reverted, recompute the message-data.
793 ;; We used to bind enable-local-variables to nil here,
794 ;; but that should not be needed now that rmail-mode
795 ;; sets it locally to nil.
796 ;; (Binding a variable locally with let is not safe if it has
797 ;; buffer-local bindings.)
798 (if (and existed
(not (verify-visited-file-modtime existed
)))
800 (find-file file-name
)
801 (if (and (verify-visited-file-modtime existed
)
802 (eq major-mode
'rmail-mode
))
803 (progn (rmail-forget-messages)
804 (rmail-set-message-counters))))
806 (let ((enable-local-variables nil
))
807 (find-file-noselect file-name
))))
808 (if (eq major-mode
'rmail-edit-mode
)
809 (error "Exit Rmail Edit mode before getting new mail"))
810 (if (and existed
(> (buffer-size) 0))
811 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
812 (or (eq major-mode
'rmail-mode
)
813 (progn (rmail-mode-2)
814 (setq run-mail-hook t
)))
815 (setq run-mail-hook t
)
817 ;; Convert all or part to Babyl file if possible.
819 (goto-char (point-max)))
820 ;; As we have read a file by raw-text, the buffer is set to
821 ;; unibyte. We must make it multibyte if necessary.
822 (if (and rmail-enable-multibyte
823 (not enable-multibyte-characters
))
824 (set-buffer-multibyte t
))
825 ;; If necessary, scan to find all the messages.
826 (rmail-maybe-set-message-counters)
828 (unless (and (not file-name-arg
)
829 (rmail-get-new-mail))
830 (rmail-show-message (rmail-first-unseen-message)))
832 (if rmail-display-summary
(rmail-summary))
833 (rmail-construct-io-menu)
835 (run-hooks 'rmail-mode-hook
))))))
837 ;; Given the value of MAILPATH, return a list of inbox file names.
838 ;; This is turned off because it is not clear that the user wants
839 ;; all these inboxes to feed into the primary rmail file.
840 ; (defun rmail-convert-mailpath (string)
842 ; (while (setq idx (string-match "[%:]" string))
843 ; (let ((this (substring string 0 idx)))
844 ; (setq string (substring string (1+ idx)))
845 ; (setq list (cons (if (string-match "%" this)
846 ; (substring this 0 (string-match "%" this))
851 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
852 ; will not cause emacs 18.55 problems.
854 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
856 (defun rmail-convert-file ()
859 (goto-char (point-min))
860 ;; If file doesn't start like a Babyl file,
861 ;; convert it to one, by adding a header and converting each message.
862 (cond ((looking-at "BABYL OPTIONS:"))
863 ((looking-at "Version: 5\n")
864 ;; Losing babyl file made by old version of Rmail.
865 ;; Just fix the babyl file header; don't make a new one,
866 ;; so we don't lose the Labels: file attribute, etc.
867 (let ((buffer-read-only nil
))
868 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
869 ((equal (point-min) (point-max))
870 ;; Empty RMAIL file. Just insert the header.
871 (rmail-insert-rmail-file-header))
873 ;; Non-empty file in non-RMAIL format. Add header and convert.
875 (rmail-insert-rmail-file-header)))
876 ;; If file was not a Babyl file or if there are
877 ;; Unix format messages added at the end,
878 ;; convert file as necessary.
881 (goto-char (point-max))
882 (search-backward "\n\^_")
884 (looking-at "\n*From ")))
885 (let ((buffer-read-only nil
))
886 (message "Converting to Babyl format...")
887 ;; If file needs conversion, convert it all,
888 ;; except for the BABYL header.
889 ;; (rmail-convert-to-babyl-format would delete the header.)
890 (goto-char (point-min))
891 (search-forward "\n\^_" nil t
)
892 (narrow-to-region (point) (point-max))
893 (rmail-convert-to-babyl-format)
894 (message "Converting to Babyl format...done"))
895 (if (and (not rmail-enable-mime
)
896 rmail-enable-multibyte
)
897 ;; We still have to decode BABYL part.
898 (rmail-decode-babyl-format)))))
900 (defun rmail-insert-rmail-file-header ()
901 (let ((buffer-read-only nil
))
902 ;; -*-rmail-*- is here so that visiting the file normally
903 ;; recognizes it as an Rmail file.
904 (insert "BABYL OPTIONS: -*- rmail -*-
907 Note: This is the header of an rmail file.
908 Note: If you are seeing it in rmail,
909 Note: it means the file has no messages in it.\n\^_")))
911 ;; Decode Babyl formatted part at the head of current buffer by
912 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
914 (defun rmail-decode-babyl-format ()
915 (let ((modifiedp (buffer-modified-p))
916 (buffer-read-only nil
)
917 (coding-system rmail-file-coding-system
)
919 (goto-char (point-min))
920 (search-forward "\n\^_" nil t
) ; Skip BABYL header.
922 (goto-char (point-max))
923 (search-backward "\n\^_" from
'mv
)
925 (unless (and coding-system
926 (coding-system-p coding-system
))
928 ;; If rmail-file-coding-system is nil, Emacs 21 writes
929 ;; RMAIL files in emacs-mule, Emacs 22 in utf-8, but
930 ;; earlier versions did that with the current buffer's
931 ;; encoding. So we want to favor detection of emacs-mule
932 ;; (whose normal priority is quite low) and utf-8, but
933 ;; still allow detection of other encodings if they won't
934 ;; fit. The call to with-coding-priority below achieves
936 (with-coding-priority '(emacs-mule utf-8
)
937 (detect-coding-region from to
'highest
))))
938 (unless (eq (coding-system-type coding-system
) 'undecided
)
939 (set-buffer-modified-p t
) ; avoid locking when decoding
940 (let ((buffer-undo-list t
))
941 (decode-coding-region from to coding-system
))
942 (setq coding-system last-coding-system-used
))
943 (set-buffer-modified-p modifiedp
)
944 (setq buffer-file-coding-system nil
)
945 (setq save-buffer-coding-system
946 (or coding-system
'undecided
))))
948 (defvar rmail-mode-map nil
)
951 (setq rmail-mode-map
(make-keymap))
952 (suppress-keymap rmail-mode-map
)
953 (define-key rmail-mode-map
"a" 'rmail-add-label
)
954 (define-key rmail-mode-map
"b" 'rmail-bury
)
955 (define-key rmail-mode-map
"c" 'rmail-continue
)
956 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
957 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
958 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
959 (define-key rmail-mode-map
"f" 'rmail-forward
)
960 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
961 (define-key rmail-mode-map
"h" 'rmail-summary
)
962 (define-key rmail-mode-map
"i" 'rmail-input
)
963 (define-key rmail-mode-map
"j" 'rmail-show-message
)
964 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
965 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
966 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
967 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
968 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
969 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
970 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
971 (define-key rmail-mode-map
"m" 'rmail-mail
)
972 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
973 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
974 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
975 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
976 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
977 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
978 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
979 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
980 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
981 (define-key rmail-mode-map
"q" 'rmail-quit
)
982 (define-key rmail-mode-map
"r" 'rmail-reply
)
983 ;; I find I can't live without the default M-r command -- rms.
984 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
985 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
986 (define-key rmail-mode-map
"\es" 'rmail-search
)
987 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
988 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
989 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
990 (define-key rmail-mode-map
"x" 'rmail-expunge
)
991 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
992 (define-key rmail-mode-map
"/" 'rmail-end-of-message
)
993 (define-key rmail-mode-map
"<" 'rmail-first-message
)
994 (define-key rmail-mode-map
">" 'rmail-last-message
)
995 (define-key rmail-mode-map
" " 'scroll-up
)
996 (define-key rmail-mode-map
"\177" 'scroll-down
)
997 (define-key rmail-mode-map
"?" 'describe-mode
)
998 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
999 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
1000 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
1001 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
1002 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
1003 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
1004 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
1005 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
1006 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
1009 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
1011 (define-key rmail-mode-map
[menu-bar classify
]
1012 (cons "Classify" (make-sparse-keymap "Classify")))
1014 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1017 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1020 (define-key rmail-mode-map
[menu-bar classify output-body
]
1021 '("Output body to file..." . rmail-output-body-to-file
))
1023 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
1024 '("Output (inbox)..." . rmail-output
))
1026 (define-key rmail-mode-map
[menu-bar classify output
]
1027 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
1029 (define-key rmail-mode-map
[menu-bar classify kill-label
]
1030 '("Kill Label..." . rmail-kill-label
))
1032 (define-key rmail-mode-map
[menu-bar classify add-label
]
1033 '("Add Label..." . rmail-add-label
))
1035 (define-key rmail-mode-map
[menu-bar summary
]
1036 (cons "Summary" (make-sparse-keymap "Summary")))
1038 (define-key rmail-mode-map
[menu-bar summary senders
]
1039 '("By Senders..." . rmail-summary-by-senders
))
1041 (define-key rmail-mode-map
[menu-bar summary labels
]
1042 '("By Labels..." . rmail-summary-by-labels
))
1044 (define-key rmail-mode-map
[menu-bar summary recipients
]
1045 '("By Recipients..." . rmail-summary-by-recipients
))
1047 (define-key rmail-mode-map
[menu-bar summary topic
]
1048 '("By Topic..." . rmail-summary-by-topic
))
1050 (define-key rmail-mode-map
[menu-bar summary regexp
]
1051 '("By Regexp..." . rmail-summary-by-regexp
))
1053 (define-key rmail-mode-map
[menu-bar summary all
]
1054 '("All" . rmail-summary
))
1056 (define-key rmail-mode-map
[menu-bar mail
]
1057 (cons "Mail" (make-sparse-keymap "Mail")))
1059 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
1060 '("Get New Mail" . rmail-get-new-mail
))
1062 (define-key rmail-mode-map
[menu-bar mail lambda
]
1065 (define-key rmail-mode-map
[menu-bar mail continue
]
1066 '("Continue" . rmail-continue
))
1068 (define-key rmail-mode-map
[menu-bar mail resend
]
1069 '("Re-send..." . rmail-resend
))
1071 (define-key rmail-mode-map
[menu-bar mail forward
]
1072 '("Forward" . rmail-forward
))
1074 (define-key rmail-mode-map
[menu-bar mail retry
]
1075 '("Retry" . rmail-retry-failure
))
1077 (define-key rmail-mode-map
[menu-bar mail reply
]
1078 '("Reply" . rmail-reply
))
1080 (define-key rmail-mode-map
[menu-bar mail mail
]
1081 '("Mail" . rmail-mail
))
1083 (define-key rmail-mode-map
[menu-bar delete
]
1084 (cons "Delete" (make-sparse-keymap "Delete")))
1086 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
1087 '("Expunge/Save" . rmail-expunge-and-save
))
1089 (define-key rmail-mode-map
[menu-bar delete expunge
]
1090 '("Expunge" . rmail-expunge
))
1092 (define-key rmail-mode-map
[menu-bar delete undelete
]
1093 '("Undelete" . rmail-undelete-previous-message
))
1095 (define-key rmail-mode-map
[menu-bar delete delete
]
1096 '("Delete" . rmail-delete-forward
))
1098 (define-key rmail-mode-map
[menu-bar move
]
1099 (cons "Move" (make-sparse-keymap "Move")))
1101 (define-key rmail-mode-map
[menu-bar move search-back
]
1102 '("Search Back..." . rmail-search-backwards
))
1104 (define-key rmail-mode-map
[menu-bar move search
]
1105 '("Search..." . rmail-search
))
1107 (define-key rmail-mode-map
[menu-bar move previous
]
1108 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1110 (define-key rmail-mode-map
[menu-bar move next
]
1111 '("Next Nondeleted" . rmail-next-undeleted-message
))
1113 (define-key rmail-mode-map
[menu-bar move last
]
1114 '("Last" . rmail-last-message
))
1116 (define-key rmail-mode-map
[menu-bar move first
]
1117 '("First" . rmail-first-message
))
1119 (define-key rmail-mode-map
[menu-bar move previous
]
1120 '("Previous" . rmail-previous-message
))
1122 (define-key rmail-mode-map
[menu-bar move next
]
1123 '("Next" . rmail-next-message
))
1125 ;; Rmail mode is suitable only for specially formatted data.
1126 (put 'rmail-mode
'mode-class
'special
)
1128 (defun rmail-mode-kill-summary ()
1129 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1132 (defun rmail-mode ()
1133 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1134 All normal editing commands are turned off.
1135 Instead, these commands are available:
1137 \\[rmail-beginning-of-message] Move point to front of this message.
1138 \\[rmail-end-of-message] Move point to bottom of this message.
1139 \\[scroll-up] Scroll to next screen of this message.
1140 \\[scroll-down] Scroll to previous screen of this message.
1141 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1142 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1143 \\[rmail-next-message] Move to Next message whether deleted or not.
1144 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1145 \\[rmail-first-message] Move to the first message in Rmail file.
1146 \\[rmail-last-message] Move to the last message in Rmail file.
1147 \\[rmail-show-message] Jump to message specified by numeric position in file.
1148 \\[rmail-search] Search for string and show message it is found in.
1149 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1150 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1151 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1152 till a deleted message is found.
1153 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1154 \\[rmail-expunge] Expunge deleted messages.
1155 \\[rmail-expunge-and-save] Expunge and save the file.
1156 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1157 \\[save-buffer] Save without expunging.
1158 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1159 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1160 \\[rmail-continue] Continue composing outgoing message started before.
1161 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1162 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1163 \\[rmail-forward] Forward this message to another user.
1164 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
1165 \\[rmail-output] Output this message to a Unix-format mail file (append it).
1166 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1167 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1168 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1169 \\[rmail-kill-label] Kill label. Remove a label from current message.
1170 \\[rmail-next-labeled-message] Move to Next message with specified label
1171 (label defaults to last one specified).
1172 Standard labels: filed, unseen, answered, forwarded, deleted.
1173 Any other label is present only if you add it with \\[rmail-add-label].
1174 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1175 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1176 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1177 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1178 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1179 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1180 \\[rmail-toggle-header] Toggle display of complete header."
1182 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1184 (when (and finding-rmail-file
1185 (null coding-system-for-read
)
1186 default-enable-multibyte-characters
)
1187 (let ((rmail-enable-multibyte t
))
1188 (rmail-require-mime-maybe)
1189 (rmail-convert-file)
1190 (goto-char (point-max))
1191 (set-buffer-multibyte t
)))
1192 (rmail-set-message-counters)
1193 (rmail-show-message rmail-total-messages
)
1194 (when finding-rmail-file
1195 (when rmail-display-summary
1197 (rmail-construct-io-menu))
1198 (run-mode-hooks 'rmail-mode-hook
)))
1200 (defun rmail-mode-2 ()
1201 (kill-all-local-variables)
1203 (rmail-perm-variables)
1206 (defun rmail-mode-1 ()
1207 (setq major-mode
'rmail-mode
)
1208 (setq mode-name
"RMAIL")
1209 (setq buffer-read-only t
)
1210 ;; No need to auto save RMAIL files in normal circumstances
1211 ;; because they contain no info except attribute changes
1212 ;; and deletion of messages.
1213 ;; The one exception is when messages are copied into an Rmail mode buffer.
1214 ;; rmail-output-to-rmail-file enables auto save when you do that.
1215 (setq buffer-auto-save-file-name nil
)
1216 (setq mode-line-modified
"--")
1217 (use-local-map rmail-mode-map
)
1218 (set-syntax-table text-mode-syntax-table
)
1219 (setq local-abbrev-table text-mode-abbrev-table
))
1221 ;; Set up the permanent locals associated with an Rmail file.
1222 (defun rmail-perm-variables ()
1223 (make-local-variable 'rmail-last-label
)
1224 (make-local-variable 'rmail-last-regexp
)
1225 (make-local-variable 'rmail-deleted-vector
)
1226 (make-local-variable 'rmail-buffer
)
1227 (setq rmail-buffer
(current-buffer))
1228 (make-local-variable 'rmail-view-buffer
)
1229 (setq rmail-view-buffer rmail-buffer
)
1230 (make-local-variable 'rmail-summary-buffer
)
1231 (make-local-variable 'rmail-summary-vector
)
1232 (make-local-variable 'rmail-current-message
)
1233 (make-local-variable 'rmail-total-messages
)
1234 (make-local-variable 'rmail-overlay-list
)
1235 (setq rmail-overlay-list nil
)
1236 (make-local-variable 'rmail-message-vector
)
1237 (make-local-variable 'rmail-msgref-vector
)
1238 (make-local-variable 'rmail-inbox-list
)
1239 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
1240 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1241 (and (null rmail-inbox-list
)
1242 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1243 (equal buffer-file-truename
1244 (abbreviate-file-name (file-truename rmail-file-name
))))
1245 (setq rmail-inbox-list
1246 (or rmail-primary-inbox-list
1247 (list (or (getenv "MAIL")
1248 (concat rmail-spool-directory
1249 (user-login-name)))))))
1250 (make-local-variable 'rmail-keywords
)
1251 ;; this gets generated as needed
1252 (setq rmail-keywords nil
))
1254 ;; Set up the non-permanent locals associated with Rmail mode.
1255 (defun rmail-variables ()
1256 (make-local-variable 'save-buffer-coding-system
)
1257 ;; If we don't already have a value for save-buffer-coding-system,
1258 ;; get it from buffer-file-coding-system, and clear that
1259 ;; because it should be determined in rmail-show-message.
1260 (unless save-buffer-coding-system
1261 (setq save-buffer-coding-system
(or buffer-file-coding-system
'undecided
))
1262 (setq buffer-file-coding-system nil
))
1263 ;; Don't let a local variables list in a message cause confusion.
1264 (make-local-variable 'local-enable-local-variables
)
1265 (setq local-enable-local-variables nil
)
1266 (make-local-variable 'revert-buffer-function
)
1267 (setq revert-buffer-function
'rmail-revert
)
1268 (make-local-variable 'font-lock-defaults
)
1269 (setq font-lock-defaults
1270 '(rmail-font-lock-keywords
1272 (font-lock-maximum-size . nil
)
1273 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1274 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1275 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1276 (make-local-variable 'require-final-newline
)
1277 (setq require-final-newline nil
)
1278 (make-local-variable 'version-control
)
1279 (setq version-control
'never
)
1280 (make-local-variable 'kill-buffer-hook
)
1281 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1282 (make-local-variable 'file-precious-flag
)
1283 (setq file-precious-flag t
)
1284 (make-local-variable 'desktop-save-buffer
)
1285 (setq desktop-save-buffer t
))
1287 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1288 (defun rmail-revert (arg noconfirm
)
1289 (set-buffer rmail-buffer
)
1290 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1291 (rmail-enable-multibyte enable-multibyte-characters
)
1292 ;; See similar code in `rmail'.
1293 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
)))
1294 ;; Call our caller again, but this time it does the default thing.
1295 (if (revert-buffer arg noconfirm
)
1296 ;; If the user said "yes", and we changed something,
1297 ;; reparse the messages.
1299 (set-buffer rmail-buffer
)
1301 ;; Convert all or part to Babyl file if possible.
1302 (rmail-convert-file)
1303 ;; We have read the file as raw-text, so the buffer is set to
1304 ;; unibyte. Make it multibyte if necessary.
1305 (if (and rmail-enable-multibyte
1306 (not enable-multibyte-characters
))
1307 (set-buffer-multibyte t
))
1308 (goto-char (point-max))
1309 (rmail-set-message-counters)
1310 (rmail-show-message rmail-total-messages
)
1311 (run-hooks 'rmail-mode-hook
)))))
1313 ;; Return a list of files from this buffer's Mail: option.
1314 ;; Does not assume that messages have been parsed.
1315 ;; Just returns nil if buffer does not look like Babyl format.
1316 (defun rmail-parse-file-inboxes ()
1321 (cond ((looking-at "BABYL OPTIONS:")
1322 (search-forward "\n\^_" nil
'move
)
1323 (narrow-to-region 1 (point))
1325 (if (search-forward "\nMail:" nil t
)
1327 (narrow-to-region (point) (progn (end-of-line) (point)))
1328 (goto-char (point-min))
1329 (mail-parse-comma-list))))))))
1331 (defun rmail-expunge-and-save ()
1332 "Expunge and save RMAIL file."
1335 (set-buffer rmail-buffer
)
1337 (if (rmail-summary-exists)
1338 (rmail-select-summary (set-buffer-modified-p nil
))))
1340 (defun rmail-quit ()
1342 Hook `rmail-quit-hook' is run after expunging."
1344 (rmail-expunge-and-save)
1345 (when (boundp 'rmail-quit-hook
)
1346 (run-hooks 'rmail-quit-hook
))
1347 ;; Don't switch to the summary buffer even if it was recently visible.
1348 (when rmail-summary-buffer
1349 (replace-buffer-in-windows rmail-summary-buffer
)
1350 (bury-buffer rmail-summary-buffer
))
1351 (if rmail-enable-mime
1352 (let ((obuf rmail-buffer
)
1353 (ovbuf rmail-view-buffer
))
1354 (set-buffer rmail-view-buffer
)
1356 (replace-buffer-in-windows ovbuf
)
1357 (replace-buffer-in-windows obuf
)
1359 (let ((obuf (current-buffer)))
1361 (replace-buffer-in-windows obuf
))))
1363 (defun rmail-bury ()
1364 "Bury current Rmail buffer and its summary buffer."
1366 ;; This let var was called rmail-buffer, but that interfered
1367 ;; with the buffer-local var used in summary buffers.
1368 (let ((buffer-to-bury (current-buffer)))
1369 (if (rmail-summary-exists)
1371 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1372 (quit-window nil window
))
1373 (bury-buffer rmail-summary-buffer
)))
1376 (defun rmail-duplicate-message ()
1377 "Create a duplicated copy of the current message.
1378 The duplicate copy goes into the Rmail file just after the
1382 (let ((buffer-read-only nil
)
1383 (number rmail-current-message
)
1384 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
1385 (rmail-msgend rmail-current-message
))))
1386 (goto-char (rmail-msgend rmail-current-message
))
1388 (rmail-forget-messages)
1389 (rmail-show-message number
)
1390 (message "Message duplicated")))
1393 (defun rmail-input (filename)
1394 "Run Rmail on file FILENAME."
1395 (interactive "FRun rmail on RMAIL file: ")
1399 ;; This used to scan subdirectories recursively, but someone pointed out
1400 ;; that if the user wants that, person can put all the files in one dir.
1401 ;; And the recursive scan was slow. So I took it out.
1403 (defun rmail-find-all-files (start)
1404 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1405 (if (file-accessible-directory-p start
)
1407 (let* ((case-fold-search t
)
1408 (files (directory-files start t rmail-secondary-file-regexp
)))
1409 ;; Sort here instead of in directory-files
1410 ;; because this list is usually much shorter.
1411 (sort files
'string
<))))
1413 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1414 (let ((menu (make-sparse-keymap menu-name
)))
1416 (function (lambda (item)
1421 (rmail-list-to-menu (car item
) (cdr item
)
1424 (concat full-name
"/"
1427 (setq name
(car item
)))
1431 (list 'lambda
() '(interactive)
1435 (concat full-name
"/" item
)
1437 rmail-secondary-file-directory
))))))
1438 (define-key menu
(vector (intern name
))
1439 (cons name command
)))))
1443 ;; This command is always "disabled" when it appears in a menu.
1444 (put 'rmail-disable-menu
'menu-enable
''nil
)
1446 (defun rmail-construct-io-menu ()
1447 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1450 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1451 (cons "Input Rmail File"
1452 (rmail-list-to-menu "Input Rmail File"
1455 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1456 (cons "Output Rmail File"
1457 (rmail-list-to-menu "Output Rmail File"
1459 'rmail-output-to-rmail-file
))))
1461 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1462 '("Input Rmail File" . rmail-disable-menu
))
1463 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1464 '("Output Rmail File" . rmail-disable-menu
)))))
1467 ;;;; *** Rmail input ***
1469 ;; RLK feature not added in this version:
1470 ;; argument specifies inbox file or files in various ways.
1472 (defun rmail-get-new-mail (&optional file-name
)
1473 "Move any new mail from this RMAIL file's inbox files.
1474 The inbox files can be specified with the file's Mail: option. The
1475 variable `rmail-primary-inbox-list' specifies the inboxes for your
1476 primary RMAIL file if it has no Mail: option. By default, this is
1477 your /usr/spool/mail/$USER.
1479 You can also specify the file to get new mail from. In this case, the
1480 file of new mail is not changed or deleted. Noninteractively, you can
1481 pass the inbox file name as an argument. Interactively, a prefix
1482 argument causes us to read a file name and use that file as the inbox.
1484 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1485 always be left in inbox files rather than deleted.
1487 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1488 It returns t if it got any new messages."
1490 (list (if current-prefix-arg
1491 (read-file-name "Get new mail from file: "))))
1492 (run-hooks 'rmail-before-get-new-mail-hook
)
1493 ;; If the disk file has been changed from under us,
1494 ;; revert to it before we get new mail.
1495 (or (verify-visited-file-modtime (current-buffer))
1496 (find-file (buffer-file-name)))
1497 (set-buffer rmail-buffer
)
1498 (rmail-maybe-set-message-counters)
1500 ;; Get rid of all undo records for this buffer.
1501 (or (eq buffer-undo-list t
)
1502 (setq buffer-undo-list nil
))
1503 (let ((all-files (if file-name
(list file-name
)
1505 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1510 (let ((opoint (point))
1512 (rsf-number-of-spam 0)
1514 ;; If buffer has not changed yet, and has not been saved yet,
1515 ;; don't replace the old backup file now.
1516 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1517 (buffer-read-only nil
)
1518 ;; Don't make undo records for what we do in getting mail.
1519 (buffer-undo-list t
)
1521 ;; Files to insert this time around.
1523 ;; Last names of those files.
1525 ;; Pull files off all-files onto files
1526 ;; as long as there is no name conflict.
1527 ;; A conflict happens when two inbox file names
1528 ;; have the same last component.
1529 (while (and all-files
1530 (not (member (file-name-nondirectory (car all-files
))
1532 (setq files
(cons (car all-files
) files
)
1534 (cons (file-name-nondirectory (car all-files
)) files
))
1535 (setq all-files
(cdr all-files
)))
1536 ;; Put them back in their original order.
1537 (setq files
(nreverse files
))
1539 (goto-char (point-max))
1540 (skip-chars-backward " \t\n") ; just in case of brain damage
1541 (delete-region (point) (point-max)) ; caused by require-final-newline
1544 (narrow-to-region (point) (point))
1545 ;; Read in the contents of the inbox files,
1546 ;; renaming them as necessary,
1547 ;; and adding to the list of files to delete eventually.
1549 (rmail-insert-inbox-text files nil
)
1550 (setq delete-files
(rmail-insert-inbox-text files t
)))
1551 ;; Scan the new text and convert each message to babyl format.
1552 (goto-char (point-min))
1555 (setq new-messages
(rmail-convert-to-babyl-format)
1557 ;; Try to delete the garbage just inserted.
1558 (or success
(delete-region (point-min) (point-max)))
1559 ;; If we could not convert the file's inboxes,
1560 ;; rename the files we tried to read
1561 ;; so we won't over and over again.
1562 (if (and (not file-name
) (not success
))
1563 (let ((delfiles delete-files
)
1566 (while (file-exists-p (format "RMAILOSE.%d" count
))
1567 (setq count
(1+ count
)))
1568 (rename-file (car delfiles
)
1569 (format "RMAILOSE.%d" count
))
1570 (setq delfiles
(cdr delfiles
))))))
1571 (or (zerop new-messages
)
1574 (search-backward "\n\^_" nil t
)
1575 (narrow-to-region (point) (point-max))
1576 (goto-char (1+ (point-min)))
1577 (rmail-count-new-messages)
1578 (run-hooks 'rmail-get-new-mail-hook
)
1580 ;; Delete the old files, now that babyl file is saved.
1583 ;; First, try deleting.
1585 (delete-file (car delete-files
))
1587 ;; If we can't delete it, truncate it.
1588 (write-region (point) (point) (car delete-files
))))
1590 (setq delete-files
(cdr delete-files
)))))
1591 (if (= new-messages
0)
1592 (progn (goto-char opoint
)
1593 (if (or file-name rmail-inbox-list
)
1594 (message "(No new mail has arrived)")))
1595 ;; check new messages to see if any of them is spam:
1596 (if (and (featurep 'rmail-spam-filter
)
1597 rmail-use-spam-filter
)
1599 ((old-messages (- rmail-total-messages new-messages
))
1600 (rsf-scanned-message-number (1+ old-messages
))
1601 ;; save deletion flags of old messages: vector starts
1602 ;; at zero (is one longer that no of messages),
1603 ;; therefore take 1+ old-messages
1605 (substring rmail-deleted-vector
0 (1+
1607 ;; set all messages to undeleted
1608 (setq rmail-deleted-vector
1609 (make-string (1+ rmail-total-messages
) ?\
))
1610 (while (<= rsf-scanned-message-number
1611 rmail-total-messages
)
1613 (if (not (rmail-spam-filter rsf-scanned-message-number
))
1614 (progn (setq rsf-number-of-spam
(1+ rsf-number-of-spam
)))
1616 (setq rsf-scanned-message-number
(1+ rsf-scanned-message-number
))
1618 (if (> rsf-number-of-spam
0)
1620 (when (rmail-expunge-confirmed)
1621 (rmail-only-expunge t
))
1623 (setq rmail-deleted-vector
1626 (make-string (- rmail-total-messages old-messages
)
1629 (if (rmail-summary-exists)
1630 (rmail-select-summary
1631 (rmail-update-summary)))
1632 (message "%d new message%s read%s"
1633 new-messages
(if (= 1 new-messages
) "" "s")
1634 ;; print out a message on number of spam messages found:
1635 (if (and (featurep 'rmail-spam-filter
)
1636 rmail-use-spam-filter
1637 (> rsf-number-of-spam
0))
1638 (if (= 1 new-messages
)
1639 ", and found to be a spam message"
1640 (if (> rsf-number-of-spam
1)
1641 (format ", %d of which found to be spam messages"
1643 ", one of which found to be a spam message"))
1645 (if (and (featurep 'rmail-spam-filter
)
1646 rmail-use-spam-filter
1647 (> rsf-number-of-spam
0))
1648 (progn (if rsf-beep
(beep t
))
1649 (sleep-for rsf-sleep-after-message
)))
1651 ;; Move to the first new message
1652 ;; unless we have other unseen messages before it.
1653 (rmail-show-message (rmail-first-unseen-message))
1654 (run-hooks 'rmail-after-get-new-mail-hook
)
1657 ;; Don't leave the buffer screwed up if we get a disk-full error.
1658 (or found
(rmail-show-message)))))
1660 (defun rmail-parse-url (file)
1661 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1662 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1663 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1664 a remote mailbox, PASSWORD is the password if it should be
1665 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1666 is non-nil if the user has supplied the password interactively.
1669 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1670 (let (got-password supplied-password
1671 (proto (match-string 1 file
))
1672 (user (match-string 3 file
))
1673 (pass (match-string 5 file
))
1674 (host (substring file
(or (match-end 2)
1675 (+ 3 (match-end 1))))))
1678 (when rmail-remote-password-required
1679 (setq got-password
(not (rmail-have-password)))
1680 (setq supplied-password
(rmail-get-remote-password
1681 (string-equal proto
"imap")))))
1683 (if (rmail-movemail-variant-p 'emacs
)
1684 (if (string-equal proto
"pop")
1685 (list (concat "po:" user
":" host
)
1687 (or pass supplied-password
)
1689 (error "Emacs movemail does not support %s protocol" proto
))
1691 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1695 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1696 (let (got-password supplied-password
1698 (user (match-string 1 file
))
1699 (host (match-string 3 file
)))
1701 (when rmail-remote-password-required
1702 (setq got-password
(not (rmail-have-password)))
1703 (setq supplied-password
(rmail-get-remote-password nil
)))
1705 (list file
"pop" supplied-password got-password
)))
1708 (list file nil nil nil
))))
1710 (defun rmail-insert-inbox-text (files renamep
)
1711 ;; Detect a locked file now, so that we avoid moving mail
1712 ;; out of the real inbox file. (That could scare people.)
1713 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1714 (error "RMAIL file %s is locked"
1715 (file-name-nondirectory buffer-file-name
)))
1716 (let (file tofile delete-files movemail popmail got-password password
)
1718 ;; Handle remote mailbox names specially; don't expand as filenames
1719 ;; in case the userid contains a directory separator.
1720 (setq file
(car files
))
1721 (let ((url-data (rmail-parse-url file
)))
1722 (setq file
(nth 0 url-data
))
1723 (setq popmail
(nth 1 url-data
))
1724 (setq password
(nth 2 url-data
))
1725 (setq got-password
(nth 3 url-data
)))
1729 (setq file
(file-truename
1730 (substitute-in-file-name (expand-file-name file
)))))
1731 (setq tofile
(expand-file-name
1732 ;; Generate name to move to from inbox name,
1733 ;; in case of multiple inboxes that need moving.
1735 (file-name-nondirectory
1736 (if (memq system-type
'(windows-nt cygwin
))
1737 ;; cannot have "po:" in file name
1740 ;; Use the directory of this rmail file
1741 ;; because it's a nuisance to use the homedir
1742 ;; if that is on a full disk and this rmail
1744 (file-name-directory
1745 (expand-file-name buffer-file-name
))))
1746 ;; Always use movemail to rename the file,
1747 ;; since there can be mailboxes in various directories.
1750 ;; On some systems, /usr/spool/mail/foo is a directory
1751 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1752 (if (file-directory-p file
)
1753 (setq file
(expand-file-name (user-login-name)
1756 (message "Getting mail from the remote server ..."))
1757 ((and (file-exists-p tofile
)
1758 (/= 0 (nth 7 (file-attributes tofile
))))
1759 (message "Getting mail from %s..." tofile
))
1760 ((and (file-exists-p file
)
1761 (/= 0 (nth 7 (file-attributes file
))))
1762 (message "Getting mail from %s..." file
)))
1763 ;; Set TOFILE if have not already done so, and
1764 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1765 (cond ((not renamep
)
1767 ((or (file-exists-p tofile
) (and (not popmail
)
1768 (not (file-exists-p file
))))
1772 (let ((errors (current-buffer)))
1773 (buffer-disable-undo errors
)
1776 (list (or rmail-movemail-program
1777 (expand-file-name "movemail"
1780 (if rmail-preserve-inbox
1783 (if (rmail-movemail-variant-p 'mailutils
)
1784 (append (list "--emacs") rmail-movemail-flags
)
1785 rmail-movemail-flags
)
1787 (if password
(list password
) nil
))))
1788 (apply 'call-process args
))
1789 (if (not (buffer-modified-p errors
))
1790 ;; No output => movemail won
1793 (subst-char-in-region (point-min) (point-max)
1795 (goto-char (point-max))
1796 (skip-chars-backward " \t")
1797 (delete-region (point) (point-max))
1798 (goto-char (point-min))
1799 (if (looking-at "movemail: ")
1800 (delete-region (point-min) (match-end 0)))
1802 ;; If we just read the password, most likely it is
1803 ;; wrong. Otherwise, see if there is a specific
1804 ;; reason to think that the problem is a wrong passwd.
1805 (if (or got-password
1806 (re-search-forward rmail-remote-password-error
1808 (rmail-set-remote-password nil
))
1810 ;; If using Mailutils, remove initial error code
1812 (when (rmail-movemail-variant-p 'mailutils
)
1813 (goto-char (point-min))
1814 (when (looking-at "[A-Z][A-Z0-9_]*:")
1815 (delete-region (point-min) (match-end 0))))
1817 (message "movemail: %s"
1818 (buffer-substring (point-min)
1824 ;; At this point, TOFILE contains the name to read:
1825 ;; Either the alternate name (if we renamed)
1826 ;; or the actual inbox (if not renaming).
1827 (if (file-exists-p tofile
)
1828 (let ((coding-system-for-read 'no-conversion
)
1830 (goto-char (point-max))
1831 (setq size
(nth 1 (insert-file-contents tofile
)))
1832 (goto-char (point-max))
1833 (or (= (preceding-char) ?
\n)
1836 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1837 (setq delete-files
(cons tofile delete-files
)))))
1839 (setq files
(cdr files
)))
1842 ;; Decode the region specified by FROM and TO by CODING.
1843 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1844 (defun rmail-decode-region (from to coding
)
1845 (if (or (not coding
) (not (coding-system-p coding
)))
1846 (setq coding
'undecided
))
1847 ;; Use -dos decoding, to remove ^M characters left from base64 or
1848 ;; rogue qp-encoded text.
1849 (decode-coding-region from to
1850 (coding-system-change-eol-conversion coding
1))
1851 ;; Don't reveal the fact we used -dos decoding, as users generally
1852 ;; will not expect the RMAIL buffer to use DOS EOL format.
1853 (setq buffer-file-coding-system
1854 (setq last-coding-system-used
1855 (coding-system-change-eol-conversion coding
0))))
1857 ;; the rmail-break-forwarded-messages feature is not implemented
1858 (defun rmail-convert-to-babyl-format ()
1859 (let ((count 0) start
1860 (case-fold-search nil
)
1861 (invalid-input-resync
1862 (function (lambda ()
1863 (message "Invalid Babyl format in inbox!")
1865 ;; Try to get back in sync with a real message.
1866 (if (re-search-forward
1867 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1869 (goto-char (point-max)))))))
1870 (goto-char (point-min))
1873 (setq start
(point))
1874 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1875 (if (search-forward "\n\^_" nil t
)
1876 ;; If we find the proper terminator, delete through there.
1877 (delete-region (point-min) (point))
1878 (funcall invalid-input-resync
)
1879 (delete-region (point-min) (point))))
1880 ;; Babyl format message
1882 (or (search-forward "\n\^_" nil t
)
1883 (funcall invalid-input-resync
))
1884 (setq count
(1+ count
))
1885 ;; Make sure there is no extra white space after the ^_
1886 ;; at the end of the message.
1887 ;; Narrowing will make sure that whatever follows the junk
1888 ;; will be treated properly.
1889 (delete-region (point)
1891 (skip-chars-forward " \t\n")
1899 (if (looking-at "0")
1903 (narrow-to-region (point) (point-max))
1906 (case-fold-search t
)
1907 (quoted-printable-header-field-end
1911 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1913 (base64-header-field-end
1917 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
1919 (if quoted-printable-header-field-end
1922 (mail-unquote-printable-region header-end
(point) nil t t
)
1923 (message "Malformed MIME quoted-printable message"))
1924 ;; Change "quoted-printable" to "8bit",
1925 ;; to reflect the decoding we just did.
1926 (goto-char quoted-printable-header-field-end
)
1927 (delete-region (point) (search-backward ":"))
1929 (if base64-header-field-end
1934 (base64-decode-region (1+ header-end
)
1938 ;; Change "base64" to "8bit", to reflect the
1939 ;; decoding we just did.
1940 (goto-char base64-header-field-end
)
1941 (delete-region (point) (search-backward ":"))
1942 (insert ": 8bit"))))
1943 (setq last-coding-system-used nil
)
1944 (or rmail-enable-mime
1945 (not rmail-enable-multibyte
)
1947 (if (and rmail-decode-mime-charset
1950 (search-forward "\n\n" nil t
)
1951 (let ((case-fold-search t
))
1953 rmail-mime-charset-pattern
1955 (intern (downcase (match-string 1))))))
1956 (rmail-decode-region start
(point) mime-charset
)))))
1957 ;; Add an X-Coding-System: header if we don't have one.
1961 (if (looking-at "0")
1964 (or (save-restriction
1965 (narrow-to-region (point) (point-max))
1967 (goto-char (point-min))
1968 (re-search-forward "^X-Coding-System:" nil t
))
1969 (insert "X-Coding-System: "
1970 (symbol-name last-coding-system-used
)
1972 (narrow-to-region (point) (point-max))
1973 (and (= 0 (% count
10))
1974 (message "Converting to Babyl format...%d" count
)))
1976 ((let ((case-fold-search t
))
1977 (looking-at rmail-mmdf-delim1
))
1978 (let ((case-fold-search t
))
1979 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1980 (re-search-forward rmail-mmdf-delim2 nil t
)
1981 (replace-match "\^_"))
1984 (narrow-to-region start
(1- (point)))
1985 (goto-char (point-min))
1986 (while (search-forward "\n\^_" nil t
); single char "\^_"
1987 (replace-match "\n^_")))); 2 chars: "^" and "_"
1988 (setq last-coding-system-used nil
)
1989 (or rmail-enable-mime
1990 (not rmail-enable-multibyte
)
1991 (decode-coding-region start
(point) 'undecided
))
1995 (insert "X-Coding-System: "
1996 (symbol-name last-coding-system-used
)
1998 (narrow-to-region (point) (point-max))
1999 (setq count
(1+ count
))
2000 (and (= 0 (% count
10))
2001 (message "Converting to Babyl format...%d" count
)))
2003 ((looking-at "^From ")
2004 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
2005 (rmail-nuke-pinhead-header)
2006 ;; If this message has a Content-Length field,
2007 ;; skip to the end of the contents.
2008 (let* ((header-end (save-excursion
2009 (and (re-search-forward "\n\n" nil t
)
2011 (case-fold-search t
)
2012 (quoted-printable-header-field-end
2015 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
2017 (base64-header-field-end
2020 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
2023 ;; Get the numeric value from the Content-Length field.
2025 ;; Back up to end of prev line,
2026 ;; in case the Content-Length field comes first.
2028 (and (search-forward "\ncontent-length: "
2031 (eol (progn (end-of-line) (point))))
2032 (string-to-number (buffer-substring beg eol
)))))))
2034 (if (and (natnump size
)
2035 (<= (+ header-end size
) (point-max))
2036 ;; Make sure this would put us at a position
2037 ;; that we could continue from.
2039 (goto-char (+ header-end size
))
2040 (skip-chars-forward "\n")
2042 (and (looking-at "BABYL OPTIONS:")
2043 (search-forward "\n\^_" nil t
))
2044 (and (looking-at "\^L")
2045 (search-forward "\n\^_" nil t
))
2046 (let ((case-fold-search t
))
2047 (looking-at rmail-mmdf-delim1
))
2048 (looking-at "From "))))
2049 (goto-char (+ header-end size
))
2050 (message "Ignoring invalid Content-Length field")
2052 (if (let ((case-fold-search nil
))
2054 (concat "^[\^_]?\\("
2055 rmail-unix-mail-delimiter
2057 rmail-mmdf-delim1
"\\|"
2058 "^BABYL OPTIONS:\\|"
2059 "\^L\n[01],\\)") nil t
))
2060 (goto-char (match-beginning 1))
2061 (goto-char (point-max)))
2062 (setq count
(1+ count
))
2063 (if quoted-printable-header-field-end
2066 (mail-unquote-printable-region header-end
(point) nil t t
)
2067 (message "Malformed MIME quoted-printable message"))
2068 ;; Change "quoted-printable" to "8bit",
2069 ;; to reflect the decoding we just did.
2070 (goto-char quoted-printable-header-field-end
)
2071 (delete-region (point) (search-backward ":"))
2073 (if base64-header-field-end
2078 (base64-decode-region
2081 ;; Prevent base64-decode-region
2082 ;; from removing newline characters.
2083 (skip-chars-backward "\n\t ")
2087 ;; Change "base64" to "8bit", to reflect the
2088 ;; decoding we just did.
2089 (goto-char base64-header-field-end
)
2090 (delete-region (point) (search-backward ":"))
2091 (insert ": 8bit")))))
2095 (narrow-to-region start
(point))
2096 (goto-char (point-min))
2097 (while (search-forward "\n\^_" nil t
); single char
2098 (replace-match "\n^_")))); 2 chars: "^" and "_"
2099 ;; This is for malformed messages that don't end in newline.
2100 ;; There shouldn't be any, but some users say occasionally
2102 (or (bolp) (newline))
2104 (setq last-coding-system-used nil
)
2105 (or rmail-enable-mime
2106 (not rmail-enable-multibyte
)
2108 (if (and rmail-decode-mime-charset
2111 (search-forward "\n\n" nil t
)
2112 (let ((case-fold-search t
))
2114 rmail-mime-charset-pattern
2116 (intern (downcase (match-string 1))))))
2117 (rmail-decode-region start
(point) mime-charset
)))
2121 (insert "X-Coding-System: "
2122 (symbol-name last-coding-system-used
)
2124 (narrow-to-region (point) (point-max))
2125 (and (= 0 (% count
10))
2126 (message "Converting to Babyl format...%d" count
)))
2128 ;; This kludge is because some versions of sendmail.el
2129 ;; insert an extra newline at the beginning that shouldn't
2130 ;; be there. sendmail.el has been fixed, but old versions
2131 ;; may still be in use. -- rms, 7 May 1993.
2132 ((eolp) (delete-char 1))
2133 (t (error "Cannot convert to babyl format")))))
2136 ;; Delete the "From ..." line, creating various other headers with
2137 ;; information from it if they don't already exist. Now puts the
2138 ;; original line into a mail-from: header line for debugging and for
2139 ;; use by the rmail-output function.
2140 (defun rmail-nuke-pinhead-header ()
2143 (let ((start (point))
2146 (search-forward "\n\n")
2148 (goto-char (point-max))
2152 (narrow-to-region start end
)
2153 (let ((case-fold-search t
))
2155 (setq has-from
(search-forward "\nFrom:" nil t
))
2157 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
2159 (let ((case-fold-search nil
))
2160 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
2164 ;; Keep and reformat the date if we don't
2165 ;; have a Date: field.
2169 "Date: \\2, \\4 \\3 \\9 \\5 "
2171 ;; The timezone could be matched by group 7 or group 10.
2172 ;; If neither of them matched, assume EST, since only
2173 ;; Easterners would be so sloppy.
2174 ;; It's a shame the substitution can't use "\\10".
2176 ((/= (match-beginning 7) (match-end 7)) "\\7")
2177 ((/= (match-beginning 10) (match-end 10))
2178 (buffer-substring (match-beginning 10)
2182 ;; Keep and reformat the sender if we don't
2183 ;; have a From: field.
2189 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2191 (defun rmail-reformat-message (beg end
)
2194 (if (/= (following-char) ?
0)
2195 (error "Bad format in RMAIL file"))
2196 (let ((inhibit-read-only t
)
2197 (delta (- (buffer-size) end
)))
2201 (let ((case-fold-search t
))
2202 (while (looking-at "Summary-line:\\|Mail-From:")
2204 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
2205 (delete-region (point)
2206 (progn (forward-line 1) (point))))
2207 (let ((str (buffer-substring (point)
2208 (save-excursion (search-forward "\n\n" end
'move
)
2210 (insert str
"*** EOOH ***\n")
2211 (narrow-to-region (point) (- (buffer-size) delta
)))
2212 (goto-char (point-min))
2213 (if rmail-message-filter
(funcall rmail-message-filter
))
2214 (if (or rmail-displayed-headers rmail-ignored-headers
)
2215 (rmail-clear-headers))))
2217 (defun rmail-clear-headers (&optional ignored-headers
)
2218 "Delete all header fields that Rmail should not show.
2219 If the optional argument IGNORED-HEADERS is non-nil,
2220 delete all header fields whose names match that regexp.
2221 Otherwise, if `rmail-displayed-headers' is non-nil,
2222 delete all header fields *except* those whose names match that regexp.
2223 Otherwise, delete all header fields whose names match `rmail-ignored-headers'
2224 unless they also match `rmail-nonignored-headers'."
2225 (when (search-forward "\n\n" nil t
)
2227 (let ((case-fold-search t
)
2228 (buffer-read-only nil
))
2229 (if (and rmail-displayed-headers
(null ignored-headers
))
2231 (narrow-to-region (point-min) (point))
2233 (goto-char (point-min))
2234 (while (and (not (eobp))
2236 (if (re-search-forward "\n[^ \t]" nil t
)
2237 (setq lim
(match-beginning 0)
2239 (setq lim nil next
(point-max)))))
2241 (re-search-forward rmail-displayed-headers lim t
))
2243 (delete-region (point) next
))))
2244 (goto-char (point-min)))
2245 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2247 (narrow-to-region (point-min) (point))
2248 (goto-char (point-min))
2249 (while (and ignored-headers
2250 (re-search-forward ignored-headers nil t
))
2252 (if (looking-at rmail-nonignored-headers
)
2254 (delete-region (point)
2256 (if (re-search-forward "\n[^ \t]" nil t
)
2258 (point-max)))))))))))
2260 (defun rmail-msg-is-pruned ()
2261 (rmail-maybe-set-message-counters)
2263 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2265 (goto-char (point-min))
2267 (= (following-char) ?
1))))
2269 (defun rmail-msg-restore-non-pruned-header ()
2270 (let ((old-point (point))
2273 (inhibit-read-only t
))
2275 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2276 (goto-char (point-min))
2281 ;; Insert new EOOH line at the proper place.
2283 (let ((case-fold-search t
))
2284 (while (looking-at "Summary-Line:\\|Mail-From:")
2286 (insert "*** EOOH ***\n")
2287 (setq new-start
(point))
2288 ;; Delete the old reformatted header.
2290 (search-forward "\n*** EOOH ***\n")
2292 (let ((start (point)))
2293 (search-forward "\n\n")
2294 (if (and (<= start old-point
)
2295 (<= old-point
(point)))
2296 (setq new-point new-start
))
2297 (delete-region start
(point)))
2298 ;; Narrow to after the new EOOH line.
2299 (narrow-to-region new-start
(point-max)))
2301 (goto-char new-point
))))
2303 (defun rmail-msg-prune-header ()
2305 (= (point) (point-min))))
2307 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2308 (rmail-reformat-message (point-min) (point-max)))
2310 (goto-char (point-min)))))
2312 (defun rmail-toggle-header (&optional arg
)
2313 "Show original message header if pruned header currently shown, or vice versa.
2314 With argument ARG, show the message header pruned if ARG is greater than zero;
2315 otherwise, show it in full."
2317 (let* ((pruned (with-current-buffer rmail-buffer
2318 (rmail-msg-is-pruned)))
2320 (> (prefix-numeric-value arg
) 0)
2322 (if (eq pruned prune
)
2324 (set-buffer rmail-buffer
)
2325 (rmail-maybe-set-message-counters)
2326 (if rmail-enable-mime
2327 (let ((buffer-read-only nil
))
2329 (rmail-msg-restore-non-pruned-header)
2330 (rmail-msg-prune-header))
2331 (funcall rmail-show-mime-function
))
2332 (let* ((buffer-read-only nil
)
2333 (window (get-buffer-window (current-buffer)))
2334 (at-point-min (= (point) (point-min)))
2335 (all-headers-visible (= (window-start window
) (point-min)))
2338 (and (not (search-backward "\n\n" nil t
))
2341 (re-search-backward "^[-A-Za-z0-9]+:" nil t
))
2344 (rmail-count-screen-lines (window-start window
) (point))))
2346 (rmail-msg-restore-non-pruned-header)
2347 (rmail-msg-prune-header))
2349 (goto-char (point-min)))
2351 (goto-char (point-min))
2352 (search-forward "\n\n")
2353 (or (re-search-backward
2354 (concat "^" (regexp-quote on-header
)) nil t
)
2355 (goto-char (point-min))))
2357 (save-selected-window
2358 (select-window window
)
2359 (recenter old-screen-line
)
2360 (if (and all-headers-visible
2361 (not (= (window-start) (point-min))))
2362 (recenter (- (window-height) 2))))))))
2363 (rmail-highlight-headers))))
2365 (defun rmail-narrow-to-non-pruned-header ()
2366 "Narrow to the whole (original) header of the current message."
2368 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2369 (goto-char (point-min))
2371 (if (= (following-char) ?
1)
2374 (setq start
(point))
2375 (search-forward "*** EOOH ***\n")
2376 (setq end
(match-beginning 0)))
2378 (setq start
(point))
2379 (search-forward "\n\n")
2380 (setq end
(1- (point))))
2381 (narrow-to-region start end
)
2384 ;; Lifted from repos-count-screen-lines.
2385 ;; Return number of screen lines between START and END.
2386 (defun rmail-count-screen-lines (start end
)
2389 (narrow-to-region start end
)
2390 (goto-char (point-min))
2391 (vertical-motion (- (point-max) (point-min))))))
2393 ;;;; *** Rmail Attributes and Keywords ***
2395 ;; Make a string describing current message's attributes and keywords
2396 ;; and set it up as the name of a minor mode
2397 ;; so it will appear in the mode line.
2398 (defun rmail-display-labels ()
2399 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
2404 (goto-char (rmail-msgbeg rmail-current-message
))
2406 (if (looking-at "[01],")
2408 (narrow-to-region (point) (progn (end-of-line) (point)))
2409 ;; Truly valid BABYL format requires a space before each
2410 ;; attribute or keyword name. Put them in if missing.
2411 (let (buffer-read-only)
2412 (goto-char (point-min))
2413 (while (search-forward "," nil t
)
2414 (or (looking-at "[ ,]") (eobp)
2416 (goto-char (point-max))
2417 (if (search-backward ",," nil
'move
)
2419 (if (> (point) (1+ (point-min)))
2420 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
2421 (if (> (- (point-max) (point)) 2)
2425 (buffer-substring (+ (point) 3)
2426 (1- (point-max)))))))))))
2427 ;; Note: we don't use save-restriction because that does not work right
2428 ;; if changes are made outside the saved restriction
2429 ;; before that restriction is restored.
2430 (narrow-to-region beg end
)
2431 (set-marker beg nil
)
2432 (set-marker end nil
)))
2433 (while (string-match " +," blurb
)
2434 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2435 (substring blurb
(match-end 0)))))
2436 (while (string-match ", +" blurb
)
2437 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2438 (substring blurb
(match-end 0)))))
2439 (setq mode-line-process
2441 rmail-current-message rmail-total-messages blurb
))
2442 ;; If rmail-enable-mime is non-nil, we may have to update
2443 ;; `mode-line-process' of rmail-view-buffer too.
2444 (if (and rmail-enable-mime
2445 (not (eq (current-buffer) rmail-view-buffer
))
2446 (buffer-live-p rmail-view-buffer
))
2447 (let ((mlp mode-line-process
))
2448 (with-current-buffer rmail-view-buffer
2449 (setq mode-line-process mlp
))))))
2451 ;; Turn an attribute of a message on or off according to STATE.
2452 ;; ATTR is the name of the attribute, as a string.
2453 ;; MSGNUM is message number to change; nil means current message.
2454 (defun rmail-set-attribute (attr state
&optional msgnum
)
2455 (set-buffer rmail-buffer
)
2456 (let ((omax (point-max-marker))
2457 (omin (point-min-marker))
2458 (buffer-read-only nil
))
2459 (or msgnum
(setq msgnum rmail-current-message
))
2464 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
2467 (null (search-backward (concat ", " attr
",")
2468 (prog1 (point) (end-of-line)) t
)))))
2469 (or (eq curstate
(not (not state
)))
2471 (delete-region (point) (1- (match-end 0)))
2474 (insert " " attr
","))))
2475 (if (string= attr
"deleted")
2476 (rmail-set-message-deleted-p msgnum state
)))
2477 ;; Note: we don't use save-restriction because that does not work right
2478 ;; if changes are made outside the saved restriction
2479 ;; before that restriction is restored.
2480 (narrow-to-region omin omax
)
2481 (set-marker omin nil
)
2482 (set-marker omax nil
)
2483 (if (= msgnum rmail-current-message
)
2484 (rmail-display-labels))))))
2486 ;; Return t if the attributes/keywords line of msg number MSG
2487 ;; contains a match for the regexp LABELS.
2488 (defun rmail-message-labels-p (msg labels
)
2492 (goto-char (rmail-msgbeg msg
))
2494 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
2496 ;;;; *** Rmail Message Selection And Support ***
2498 (defun rmail-msgend (n)
2499 (marker-position (aref rmail-message-vector
(1+ n
))))
2501 (defun rmail-msgbeg (n)
2502 (marker-position (aref rmail-message-vector n
)))
2504 (defun rmail-widen-to-current-msgbeg (function)
2505 "Call FUNCTION with point at start of internal data of current message.
2506 Assumes that bounds were previously narrowed to display the message in Rmail.
2507 The bounds are widened enough to move point where desired, then narrowed
2510 FUNCTION may not change the visible text of the message, but it may
2511 change the invisible header text."
2515 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2517 (goto-char (point-min))
2519 ;; Note: we don't use save-restriction because that does not work right
2520 ;; if changes are made outside the saved restriction
2521 ;; before that restriction is restored.
2522 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2523 (rmail-msgend rmail-current-message
)))))
2525 (defun rmail-forget-messages ()
2527 (if (vectorp rmail-message-vector
)
2529 (v rmail-message-vector
)
2532 (move-marker (aref v i
) nil
)
2534 (setq rmail-message-vector nil
)
2535 (setq rmail-msgref-vector nil
)
2536 (setq rmail-deleted-vector nil
)))
2538 (defun rmail-maybe-set-message-counters ()
2539 (if (not (and rmail-deleted-vector
2540 rmail-message-vector
2541 rmail-current-message
2542 rmail-total-messages
))
2543 (rmail-set-message-counters)))
2545 (defun rmail-count-new-messages (&optional nomsg
)
2546 (let* ((case-fold-search nil
)
2550 (or nomsg
(message "Counting new messages..."))
2551 (goto-char (point-max))
2552 ;; Put at the end of messages-head
2553 ;; the entry for message N+1, which marks
2554 ;; the end of message N. (N = number of messages).
2555 (search-backward "\n\^_")
2557 (setq messages-head
(list (point-marker)))
2558 (rmail-set-message-counters-counter (point-min))
2559 (setq rmail-current-message
(1+ rmail-total-messages
))
2560 (setq rmail-total-messages
2561 (+ rmail-total-messages total-messages
))
2562 (setq rmail-message-vector
2563 (vconcat rmail-message-vector
(cdr messages-head
)))
2564 (aset rmail-message-vector
2565 rmail-current-message
(car messages-head
))
2566 (setq rmail-deleted-vector
2567 (concat rmail-deleted-vector deleted-head
))
2568 (setq rmail-summary-vector
2569 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2570 (setq rmail-msgref-vector
2571 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2572 ;; Fill in the new elements of rmail-msgref-vector.
2573 (let ((i (1+ (- rmail-total-messages total-messages
))))
2574 (while (<= i rmail-total-messages
)
2575 (aset rmail-msgref-vector i
(list i
))
2577 (goto-char (point-min))
2578 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2580 (defun rmail-set-message-counters ()
2581 (rmail-forget-messages)
2585 (let* ((point-save (point))
2587 (messages-after-point)
2588 (case-fold-search nil
)
2591 (message "Counting messages...")
2592 (goto-char (point-max))
2593 ;; Put at the end of messages-head
2594 ;; the entry for message N+1, which marks
2595 ;; the end of message N. (N = number of messages).
2596 (search-backward "\n\^_" nil t
)
2597 (if (/= (point) (point-max)) (forward-char 1))
2598 (setq messages-head
(list (point-marker)))
2599 (rmail-set-message-counters-counter (min (point) point-save
))
2600 (setq messages-after-point total-messages
)
2601 (rmail-set-message-counters-counter)
2602 (setq rmail-total-messages total-messages
)
2603 (setq rmail-current-message
2605 (max 1 (- total-messages messages-after-point
))))
2606 (setq rmail-message-vector
2607 (apply 'vector
(cons (point-min-marker) messages-head
))
2608 rmail-deleted-vector
(concat "0" deleted-head
)
2609 rmail-summary-vector
(make-vector rmail-total-messages nil
)
2610 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2612 (while (<= i rmail-total-messages
)
2613 (aset rmail-msgref-vector i
(list i
))
2615 (message "Counting messages...done")))))
2617 (defun rmail-set-message-counters-counter (&optional stop
)
2618 (let ((start (point))
2620 (while (search-backward "\n\^_\^L" stop t
)
2621 ;; Detect messages that have been added with DOS line endings and
2622 ;; convert the line endings for such messages.
2624 (if (looking-at "\n\^_\^L\r\n")
2625 (let ((buffer-read-only nil
)
2627 (message "Counting messages...(converting line endings)")
2630 (while (search-backward "\r\n" next t
)
2634 (setq messages-head
(cons (point-marker) messages-head
))
2637 (cons (if (search-backward ", deleted,"
2643 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
2644 (message "Counting messages...%d" total-messages
)))))
2646 (defun rmail-beginning-of-message ()
2647 "Show current message starting from the beginning."
2649 (let ((rmail-show-message-hook
2650 (list (function (lambda ()
2651 (goto-char (point-min)))))))
2652 (rmail-show-message rmail-current-message
)))
2654 (defun rmail-end-of-message ()
2655 "Show bottom of current message."
2657 (let ((rmail-show-message-hook
2658 (list (function (lambda ()
2659 (goto-char (point-max))
2660 (recenter (1- (window-height))))))))
2661 (rmail-show-message rmail-current-message
)))
2663 (defun rmail-unknown-mail-followup-to ()
2664 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2665 Ask the user whether to add that list name to `mail-mailing-lists'."
2667 (rmail-narrow-to-non-pruned-header)
2668 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2669 (when mail-followup-to
2672 (mail-strip-quoted-names mail-followup-to
)
2673 ",[[:space:]]+" t
)))
2674 (dolist (addr addresses
)
2675 (when (and (not (member addr mail-mailing-lists
))
2677 ;; taken from rmailsum.el
2679 (or rmail-user-mail-address-regexp
2681 (regexp-quote (user-login-name))
2684 (or user-mail-address
2685 (concat (user-login-name) "@"
2686 (or mail-host-address
2691 (format "Add `%s' to `mail-mailing-lists'? "
2693 (customize-save-variable 'mail-mailing-lists
2694 (cons addr mail-mailing-lists
)))))))))
2696 (defun rmail-show-message (&optional n no-summary
)
2697 "Show message number N (prefix argument), counting from start of file.
2698 If summary buffer is currently displayed, update current message there also."
2700 (or (eq major-mode
'rmail-mode
)
2701 (switch-to-buffer rmail-buffer
))
2702 (rmail-maybe-set-message-counters)
2704 (if (zerop rmail-total-messages
)
2705 (progn (narrow-to-region (point-min) (1- (point-max)))
2706 (goto-char (point-min))
2707 (setq mode-line-process nil
))
2708 (let (blurb coding-system
)
2710 (setq n rmail-current-message
)
2713 rmail-current-message
1
2714 blurb
"No previous message"))
2715 ((> n rmail-total-messages
)
2716 (setq n rmail-total-messages
2717 rmail-current-message rmail-total-messages
2718 blurb
"No following message"))
2720 (setq rmail-current-message n
))))
2721 (let ((beg (rmail-msgbeg n
)))
2725 (let ((end (rmail-msgend n
)))
2727 (if (prog1 (= (following-char) ?
0)
2729 ;; If there's a Summary-line in the (otherwise empty)
2730 ;; header, we didn't yet get past the EOOH line.
2731 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2733 (narrow-to-region (point) end
))
2735 (search-forward "\n*** EOOH ***\n" end t
))
2736 (narrow-to-region beg
(point))
2737 (goto-char (point-min))
2738 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2739 (let ((coding-system (intern (match-string 1))))
2742 (check-coding-system coding-system
)
2743 (setq buffer-file-coding-system coding-system
))
2745 (setq buffer-file-coding-system nil
))))
2746 (setq buffer-file-coding-system nil
)))))
2747 ;; Clear the "unseen" attribute when we show a message.
2748 (rmail-set-attribute "unseen" nil
)
2749 (let ((end (rmail-msgend n
)))
2750 ;; Reformat the header, or else find the reformatted header.
2751 (if (= (following-char) ?
0)
2752 (rmail-reformat-message beg end
)
2753 (search-forward "\n*** EOOH ***\n" end t
)
2754 (narrow-to-region (point) end
)))
2755 (goto-char (point-min))
2757 (function (lambda (window)
2758 (if (eq (window-buffer window
) (current-buffer))
2759 (set-window-point window
(point)))))
2761 (rmail-display-labels)
2762 (if (eq rmail-enable-mime t
)
2763 (funcall rmail-show-mime-function
)
2764 (setq rmail-view-buffer rmail-buffer
))
2765 (when mail-mailing-lists
2766 (rmail-unknown-mail-followup-to))
2767 (rmail-highlight-headers)
2768 (if transient-mark-mode
(deactivate-mark))
2769 (run-hooks 'rmail-show-message-hook
)
2770 ;; If there is a summary buffer, try to move to this message
2771 ;; in that buffer. But don't complain if this message
2772 ;; is not mentioned in the summary.
2773 ;; Don't do this at all if we were called on behalf
2774 ;; of cursor motion in the summary buffer.
2775 (and (rmail-summary-exists) (not no-summary
)
2776 (let ((curr-msg rmail-current-message
))
2777 (rmail-select-summary
2778 (rmail-summary-goto-msg curr-msg t t
))))
2779 (with-current-buffer rmail-buffer
2782 (message blurb
))))))
2784 (defun rmail-redecode-body (coding)
2785 "Decode the body of the current message using coding system CODING.
2786 This is useful with mail messages that have malformed or missing
2789 This function assumes that the current message is already decoded
2790 and displayed in the RMAIL buffer, but the coding system used to
2791 decode it was incorrect. It then encodes the message back to its
2792 original form, and decodes it again, using the coding system CODING.
2794 Note that if Emacs erroneously auto-detected one of the iso-2022
2795 encodings in the message, this function might fail because the escape
2796 sequences that switch between character sets and also single-shift and
2797 locking-shift codes are impossible to recover. This function is meant
2798 to be used to fix messages encoded with 8-bit encodings, such as
2799 iso-8859, koi8-r, etc."
2800 (interactive "zCoding system for re-decoding this message: ")
2801 (when (not rmail-enable-mime
)
2802 (or (eq major-mode
'rmail-mode
)
2803 (switch-to-buffer rmail-buffer
))
2805 (let ((pruned (rmail-msg-is-pruned)))
2807 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2808 (msgend (rmail-msgend rmail-current-message
))
2810 ;; We need the message headers pruned (we later restore
2811 ;; the pruned stat to what it was, see the end of
2812 ;; unwind-protect form).
2814 (rmail-toggle-header 1))
2815 (narrow-to-region msgbeg msgend
)
2816 (goto-char (point-min))
2817 (when (search-forward "\n*** EOOH ***\n" (point-max) t
)
2818 (narrow-to-region msgbeg
(point)))
2819 (goto-char (point-min))
2820 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2821 (let ((old-coding (intern (match-string 1)))
2822 (buffer-read-only nil
))
2823 (check-coding-system old-coding
)
2824 ;; Make sure the new coding system uses the same EOL
2825 ;; conversion, to prevent ^M characters from popping
2826 ;; up all over the place.
2828 (coding-system-change-eol-conversion
2830 (coding-system-eol-type old-coding
)))
2831 (setq x-coding-header
(point-marker))
2832 (narrow-to-region msgbeg msgend
)
2833 (encode-coding-region (point) msgend old-coding
)
2834 (decode-coding-region (point) msgend coding
)
2835 (setq last-coding-system-used coding
)
2836 ;; Rewrite the coding-system header according
2838 (goto-char x-coding-header
)
2839 (delete-region (point)
2843 (insert "X-Coding-System: "
2844 (symbol-name last-coding-system-used
))
2845 (set-marker x-coding-header nil
)
2846 (rmail-show-message))
2847 (error "No X-Coding-System header found")))
2849 (rmail-toggle-header 0)))))))
2851 ;; Find all occurrences of certain fields, and highlight them.
2852 (defun rmail-highlight-headers ()
2853 ;; Do this only if the system supports faces.
2854 (if (and (fboundp 'internal-find-face
)
2855 rmail-highlighted-headers
)
2857 (search-forward "\n\n" nil
'move
)
2859 (narrow-to-region (point-min) (point))
2860 (let ((case-fold-search t
)
2861 (inhibit-read-only t
)
2862 ;; Highlight with boldface if that is available.
2863 ;; Otherwise use the `highlight' face.
2864 (face (or rmail-highlight-face
2865 (if (face-differs-from-default-p 'bold
)
2867 ;; List of overlays to reuse.
2868 (overlays rmail-overlay-list
))
2869 (goto-char (point-min))
2870 (while (re-search-forward rmail-highlighted-headers nil t
)
2871 (skip-chars-forward " \t")
2874 (while (progn (forward-line 1)
2875 (looking-at "[ \t]")))
2876 ;; Back up over newline, then trailing spaces or tabs
2878 (while (member (preceding-char) '(? ?
\t))
2881 ;; Reuse an overlay we already have.
2883 (setq overlay
(car overlays
)
2884 overlays
(cdr overlays
))
2885 (overlay-put overlay
'face face
)
2886 (move-overlay overlay beg
(point)))
2887 ;; Make a new overlay and add it to
2888 ;; rmail-overlay-list.
2889 (setq overlay
(make-overlay beg
(point)))
2890 (overlay-put overlay
'face face
)
2891 (setq rmail-overlay-list
2892 (cons overlay rmail-overlay-list
))))))))))
2894 (defun rmail-auto-file ()
2895 "Automatically move a message into a sub-folder based on criteria.
2896 Called when a new message is displayed."
2897 (if (or (rmail-message-labels-p rmail-current-message
"filed")
2898 (not (string= (buffer-file-name)
2899 (expand-file-name rmail-file-name
))))
2900 ;; Do nothing if it's already been filed.
2902 ;; Find out some basics (common fields)
2903 (let ((from (mail-fetch-field "from"))
2904 (subj (mail-fetch-field "subject"))
2905 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2906 (d rmail-automatic-folder-directives
)
2907 (directive-loop nil
)
2910 (setq folder
(car (car d
))
2911 directive-loop
(cdr (car d
)))
2912 (while (and (car directive-loop
)
2914 ((string= (car directive-loop
) "from") from
)
2915 ((string= (car directive-loop
) "to") to
)
2916 ((string= (car directive-loop
) "subject") subj
)
2917 (t (mail-fetch-field (car directive-loop
))))))
2918 (and f
(string-match (car (cdr directive-loop
)) f
))))
2919 (setq directive-loop
(cdr (cdr directive-loop
))))
2920 ;; If there are no directives left, then it was a complete match.
2921 (if (null directive-loop
)
2923 (rmail-delete-forward)
2924 (if (string= "/dev/null" folder
)
2925 (rmail-delete-message)
2926 (rmail-output-to-rmail-file folder
1 t
)
2928 (setq d
(cdr d
))))))
2930 (defun rmail-next-message (n)
2931 "Show following message whether deleted or not.
2932 With prefix arg N, moves forward N messages, or backward if N is negative."
2934 (set-buffer rmail-buffer
)
2935 (rmail-maybe-set-message-counters)
2936 (rmail-show-message (+ rmail-current-message n
)))
2938 (defun rmail-previous-message (n)
2939 "Show previous message whether deleted or not.
2940 With prefix arg N, moves backward N messages, or forward if N is negative."
2942 (rmail-next-message (- n
)))
2944 (defun rmail-next-undeleted-message (n)
2945 "Show following non-deleted message.
2946 With prefix arg N, moves forward N non-deleted messages,
2947 or backward if N is negative.
2949 Returns t if a new message is being shown, nil otherwise."
2951 (set-buffer rmail-buffer
)
2952 (rmail-maybe-set-message-counters)
2953 (let ((lastwin rmail-current-message
)
2954 (current rmail-current-message
))
2955 (while (and (> n
0) (< current rmail-total-messages
))
2956 (setq current
(1+ current
))
2957 (if (not (rmail-message-deleted-p current
))
2958 (setq lastwin current n
(1- n
))))
2959 (while (and (< n
0) (> current
1))
2960 (setq current
(1- current
))
2961 (if (not (rmail-message-deleted-p current
))
2962 (setq lastwin current n
(1+ n
))))
2963 (if (/= lastwin rmail-current-message
)
2964 (progn (rmail-show-message lastwin
)
2967 (message "No previous nondeleted message"))
2969 (message "No following nondeleted message"))
2972 (defun rmail-previous-undeleted-message (n)
2973 "Show previous non-deleted message.
2974 With prefix argument N, moves backward N non-deleted messages,
2975 or forward if N is negative."
2977 (rmail-next-undeleted-message (- n
)))
2979 (defun rmail-first-message ()
2980 "Show first message in file."
2982 (rmail-maybe-set-message-counters)
2983 (rmail-show-message 1))
2985 (defun rmail-last-message ()
2986 "Show last message in file."
2988 (rmail-maybe-set-message-counters)
2989 (rmail-show-message rmail-total-messages
))
2991 (defun rmail-what-message ()
2992 (let ((where (point))
2994 (high rmail-total-messages
)
2995 (mid (/ rmail-total-messages
2)))
2996 (while (> (- high low
) 1)
2997 (if (>= where
(rmail-msgbeg mid
))
3000 (setq mid
(+ low
(/ (- high low
) 2))))
3001 (if (>= where
(rmail-msgbeg high
)) high low
)))
3003 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
3005 (goto-char (rmail-msgbeg msg
))
3006 (search-forward "\n*** EOOH ***\n")
3007 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
3008 (or (string-match recipients
(or (mail-fetch-field "To") ""))
3009 (string-match recipients
(or (mail-fetch-field "From") ""))
3010 (if (not primary-only
)
3011 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
3013 (defun rmail-message-regexp-p (n regexp
)
3014 "Return t, if for message number N, regexp REGEXP matches in the header."
3015 (let ((beg (rmail-msgbeg n
))
3016 (end (rmail-msgend n
)))
3021 (if (prog1 (= (following-char) ?
0)
3023 ;; If there's a Summary-line in the (otherwise empty)
3024 ;; header, we didn't yet get past the EOOH line.
3025 (when (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
3028 (narrow-to-region (point) end
))
3033 (search-forward "\n*** EOOH ***\n" end t
)
3034 (setq end
(1+ (match-beginning 0)))))
3036 (if rmail-enable-mime
3037 (funcall rmail-search-mime-header-function n regexp end
)
3038 (re-search-forward regexp end t
)))))
3040 (defun rmail-search-message (msg regexp
)
3041 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3042 (goto-char (rmail-msgbeg msg
))
3043 (if rmail-enable-mime
3044 (funcall rmail-search-mime-message-function msg regexp
)
3045 (re-search-forward regexp
(rmail-msgend msg
) t
)))
3047 (defvar rmail-search-last-regexp nil
)
3048 (defun rmail-search (regexp &optional n
)
3049 "Show message containing next match for REGEXP (but not the current msg).
3050 Prefix argument gives repeat count; negative argument means search
3051 backwards (through earlier messages).
3052 Interactively, empty argument means use same regexp used last time."
3054 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3056 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3060 (if rmail-search-last-regexp
3061 (concat ", default "
3062 rmail-search-last-regexp
"): ")
3064 (setq regexp
(read-string prompt
))
3065 (cond ((not (equal regexp
""))
3066 (setq rmail-search-last-regexp regexp
))
3067 ((not rmail-search-last-regexp
)
3068 (error "No previous Rmail search string")))
3069 (list rmail-search-last-regexp
3070 (prefix-numeric-value current-prefix-arg
))))
3072 (message "%sRmail search for %s..."
3073 (if (< n
0) "Reverse " "")
3075 (set-buffer rmail-buffer
)
3076 (rmail-maybe-set-message-counters)
3077 (let ((omin (point-min))
3082 (msg rmail-current-message
))
3087 ;; Check messages one by one, advancing message number up or down
3088 ;; but searching forward through each message.
3090 (while (and (null win
) (> msg
1))
3092 win
(rmail-search-message msg regexp
)))
3093 (while (and (null win
) (< msg rmail-total-messages
))
3095 win
(rmail-search-message msg regexp
))))
3096 (setq n
(+ n
(if reversep
1 -
1)))))
3099 (rmail-show-message msg
)
3100 ;; Search forward (if this is a normal search) or backward
3101 ;; (if this is a reverse search) through this message to
3102 ;; position point. This search may fail because REGEXP
3103 ;; was found in the hidden portion of this message. In
3104 ;; that case, move point to the beginning of visible
3108 (goto-char (point-max))
3109 (re-search-backward regexp nil
'move
))
3110 (goto-char (point-min))
3111 (re-search-forward regexp nil t
))
3112 (message "%sRmail search for %s...done"
3113 (if reversep
"Reverse " "")
3116 (narrow-to-region omin omax
)
3118 (message "Search failed: %s" regexp
)))))
3120 (defun rmail-search-backwards (regexp &optional n
)
3121 "Show message containing previous match for REGEXP.
3122 Prefix argument gives repeat count; negative argument means search
3123 forward (through later messages).
3124 Interactively, empty argument means use same regexp used last time."
3126 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3128 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3132 (if rmail-search-last-regexp
3133 (concat ", default "
3134 rmail-search-last-regexp
"): ")
3136 (setq regexp
(read-string prompt
))
3137 (cond ((not (equal regexp
""))
3138 (setq rmail-search-last-regexp regexp
))
3139 ((not rmail-search-last-regexp
)
3140 (error "No previous Rmail search string")))
3141 (list rmail-search-last-regexp
3142 (prefix-numeric-value current-prefix-arg
))))
3143 (rmail-search regexp
(- (or n
1))))
3145 ;; Show the first message which has the `unseen' attribute.
3146 (defun rmail-first-unseen-message ()
3147 (rmail-maybe-set-message-counters)
3152 (while (and (not found
) (<= current rmail-total-messages
))
3153 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
3154 (setq found current
))
3155 (setq current
(1+ current
))))
3156 ;; Let the caller show the message.
3158 ;; (rmail-show-message found))
3161 (defun rmail-current-subject ()
3162 "Return the current subject.
3163 The subject is stripped of leading and trailing whitespace, and
3164 of typical reply prefixes such as Re:."
3165 (let ((subject (or (mail-fetch-field "Subject") "")))
3166 (if (string-match "\\`[ \t]+" subject
)
3167 (setq subject
(substring subject
(match-end 0))))
3168 (if (string-match rmail-reply-regexp subject
)
3169 (setq subject
(substring subject
(match-end 0))))
3170 (if (string-match "[ \t]+\\'" subject
)
3171 (setq subject
(substring subject
0 (match-beginning 0))))
3174 (defun rmail-current-subject-regexp ()
3175 "Return a regular expression matching the current subject.
3176 The regular expression matches the subject header line of
3177 messages about the same subject. The subject itself is stripped
3178 of leading and trailing whitespace, of typical reply prefixes
3179 such as Re: and whitespace within the subject is replaced by a
3180 regular expression matching whitespace in general in order to
3181 take into account that subject header lines may include newlines
3182 and more whitespace. The returned regular expressions contains
3183 `rmail-reply-regexp' and ends with a newline."
3184 (let ((subject (rmail-current-subject)))
3185 ;; If Subject is long, mailers will break it into several lines at
3186 ;; arbitrary places, so replace whitespace with a regexp that will
3187 ;; match any sequence of spaces, TABs, and newlines.
3188 (setq subject
(regexp-quote subject
))
3190 (replace-regexp-in-string "[ \t\n]+" "[ \t\n]+" subject t t
))
3191 (concat "^Subject: "
3192 (if (string= "\\`" (substring rmail-reply-regexp
0 2))
3193 (substring rmail-reply-regexp
2)
3195 subject
"[ \t]*\n")))
3197 (defun rmail-next-same-subject (n)
3198 "Go to the next mail message having the same subject header.
3199 With prefix argument N, do this N times.
3200 If N is negative, go backwards instead."
3202 (let ((search-regexp (rmail-current-subject-regexp))
3204 (i rmail-current-message
)
3205 (case-fold-search t
)
3210 (while (and (/= n
0)
3212 (< i rmail-total-messages
)
3215 (while (and (not done
)
3217 (< i rmail-total-messages
)
3219 (setq i
(if forward
(1+ i
) (1- i
)))
3220 (goto-char (rmail-msgbeg i
))
3221 (search-forward "\n*** EOOH ***\n")
3222 (let ((beg (point)) end
)
3223 (search-forward "\n\n")
3226 (setq done
(re-search-forward search-regexp end t
))))
3227 (if done
(setq found i
)))
3228 (setq n
(if forward
(1- n
) (1+ n
))))))
3230 (rmail-show-message found
)
3231 (error "No %s message with same subject"
3232 (if forward
"following" "previous")))))
3234 (defun rmail-previous-same-subject (n)
3235 "Go to the previous mail message having the same subject header.
3236 With prefix argument N, do this N times.
3237 If N is negative, go forwards instead."
3239 (rmail-next-same-subject (- n
)))
3241 ;;;; *** Rmail Message Deletion Commands ***
3243 (defun rmail-message-deleted-p (n)
3244 (= (aref rmail-deleted-vector n
) ?D
))
3246 (defun rmail-set-message-deleted-p (n state
)
3247 (aset rmail-deleted-vector n
(if state ?D ?\
)))
3249 (defun rmail-delete-message ()
3250 "Delete this message and stay on it."
3252 (rmail-set-attribute "deleted" t
)
3253 (run-hooks 'rmail-delete-message-hook
))
3255 (defun rmail-undelete-previous-message ()
3256 "Back up to deleted message, select it, and undelete it."
3258 (set-buffer rmail-buffer
)
3259 (let ((msg rmail-current-message
))
3260 (while (and (> msg
0)
3261 (not (rmail-message-deleted-p msg
)))
3262 (setq msg
(1- msg
)))
3264 (error "No previous deleted message")
3265 (if (/= msg rmail-current-message
)
3266 (rmail-show-message msg
))
3267 (rmail-set-attribute "deleted" nil
)
3268 (if (rmail-summary-exists)
3270 (set-buffer rmail-summary-buffer
)
3271 (rmail-summary-mark-undeleted msg
)))
3272 (rmail-maybe-display-summary))))
3274 (defun rmail-delete-forward (&optional backward
)
3275 "Delete this message and move to next nondeleted one.
3276 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3277 With prefix argument, delete and move backward.
3279 Returns t if a new message is displayed after the delete, or nil otherwise."
3281 (rmail-set-attribute "deleted" t
)
3282 (run-hooks 'rmail-delete-message-hook
)
3283 (let ((del-msg rmail-current-message
))
3284 (if (rmail-summary-exists)
3285 (rmail-select-summary
3286 (rmail-summary-mark-deleted del-msg
)))
3287 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3288 (rmail-maybe-display-summary))))
3290 (defun rmail-delete-backward ()
3291 "Delete this message and move to previous nondeleted one.
3292 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3294 (rmail-delete-forward t
))
3296 ;; Compute the message number a given message would have after expunging.
3297 ;; The present number of the message is OLDNUM.
3298 ;; DELETEDVEC should be rmail-deleted-vector.
3299 ;; The value is nil for a message that would be deleted.
3300 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3301 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3306 (if (/= (aref deletedvec i
) ?D
)
3307 (setq newnum
(1+ newnum
)))
3311 (defun rmail-expunge-confirmed ()
3312 "Return t if deleted message should be expunged. If necessary, ask the user.
3313 See also user-option `rmail-confirm-expunge'."
3314 (set-buffer rmail-buffer
)
3315 (or (not (stringp rmail-deleted-vector
))
3316 (not (string-match "D" rmail-deleted-vector
))
3317 (null rmail-confirm-expunge
)
3318 (funcall rmail-confirm-expunge
3319 "Erase deleted messages from Rmail file? ")))
3321 (defun rmail-only-expunge (&optional dont-show
)
3322 "Actually erase all deleted messages in the file."
3324 (set-buffer rmail-buffer
)
3325 (message "Expunging deleted messages...")
3326 ;; Discard all undo records for this buffer.
3327 (or (eq buffer-undo-list t
)
3328 (setq buffer-undo-list nil
))
3329 (rmail-maybe-set-message-counters)
3330 (let* ((omax (- (buffer-size) (point-max)))
3331 (omin (- (buffer-size) (point-min)))
3332 (opoint (if (and (> rmail-current-message
0)
3333 (rmail-message-deleted-p rmail-current-message
))
3335 (if rmail-enable-mime
3336 (with-current-buffer rmail-view-buffer
3337 (- (point)(point-min)))
3338 (- (point) (point-min)))))
3339 (messages-head (cons (aref rmail-message-vector
0) nil
))
3340 (messages-tail messages-head
)
3341 ;; Don't make any undo records for the expunging.
3342 (buffer-undo-list t
)
3347 (goto-char (point-min))
3350 (total rmail-total-messages
)
3351 (new-message-number rmail-current-message
)
3353 (new-msgref (list (list 0)))
3354 (rmailbuf (current-buffer))
3355 (buffer-read-only nil
)
3356 (messages rmail-message-vector
)
3357 (deleted rmail-deleted-vector
)
3358 (summary rmail-summary-vector
))
3359 (setq rmail-total-messages nil
3360 rmail-current-message nil
3361 rmail-message-vector nil
3362 rmail-deleted-vector nil
3363 rmail-summary-vector nil
)
3365 (while (<= number total
)
3366 (if (= (aref deleted number
) ?D
)
3369 (marker-position (aref messages number
))
3370 (marker-position (aref messages
(1+ number
))))
3371 (move-marker (aref messages number
) nil
)
3372 (if (> new-message-number counter
)
3373 (setq new-message-number
(1- new-message-number
))))
3374 (setq counter
(1+ counter
))
3376 (setcdr messages-tail
3377 (cons (aref messages number
) nil
)))
3379 (cons (if (= counter number
) (aref summary
(1- number
)))
3382 (cons (aref rmail-msgref-vector number
)
3384 (setcar (car new-msgref
) counter
))
3385 (if (zerop (%
(setq number
(1+ number
)) 20))
3386 (message "Expunging deleted messages...%d" number
)))
3388 (setcdr messages-tail
3389 (cons (aref messages number
) nil
)))
3390 (setq rmail-current-message new-message-number
3391 rmail-total-messages counter
3392 rmail-message-vector
(apply 'vector messages-head
)
3393 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
3394 rmail-summary-vector
(vconcat (nreverse new-summary
))
3395 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3397 (message "Expunging deleted messages...done")
3399 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3402 (if (zerop rmail-current-message
) 1 nil
)))
3403 (if rmail-enable-mime
3404 (goto-char (+ (point-min) opoint
))
3405 (goto-char (+ (point) opoint
))))))
3407 (defun rmail-expunge ()
3408 "Erase deleted messages from Rmail file and summary buffer."
3410 (when (rmail-expunge-confirmed)
3411 (rmail-only-expunge)
3412 (if (rmail-summary-exists)
3413 (rmail-select-summary (rmail-update-summary)))))
3415 ;;;; *** Rmail Mailing Commands ***
3417 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3418 replybuffer sendactions same-window others
)
3421 (setq yank-action
(list 'insert-buffer replybuffer
)))
3422 (setq others
(cons (cons "cc" cc
) others
))
3423 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
3425 (compose-mail to subject others
3427 yank-action sendactions
)
3428 (if rmail-mail-new-frame
3430 (compose-mail to subject others
3431 noerase
'switch-to-buffer-other-frame
3432 yank-action sendactions
)
3433 ;; This is not a standard frame parameter;
3434 ;; nothing except sendmail.el looks at it.
3435 (modify-frame-parameters (selected-frame)
3436 '((mail-dedicated-frame . t
))))
3437 (compose-mail to subject others
3438 noerase
'switch-to-buffer-other-window
3439 yank-action sendactions
)))))
3441 (defun rmail-mail ()
3442 "Send mail in another window.
3443 While composing the message, use \\[mail-yank-original] to yank the
3444 original message into it."
3446 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
3448 (defun rmail-continue ()
3449 "Continue composing outgoing message previously being composed."
3451 (rmail-start-mail t
))
3453 (defun rmail-reply (just-sender)
3454 "Reply to the current message.
3455 Normally include CC: to all other recipients of original message;
3456 prefix argument means ignore them. While composing the reply,
3457 use \\[mail-yank-original] to yank the original message into it."
3459 (let (from reply-to cc subject date to message-id references
3460 resent-to resent-cc resent-reply-to
3461 (msgnum rmail-current-message
))
3464 (if rmail-enable-mime
3466 (goto-char (point-min))
3467 (if (search-forward "\n\n" nil
'move
)
3468 (1+ (match-beginning 0))
3471 (goto-char (rmail-msgbeg rmail-current-message
))
3473 (if (= (following-char) ?
0)
3475 (progn (forward-line 2)
3477 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
3480 (narrow-to-region (point)
3481 (progn (search-forward "\n*** EOOH ***\n")
3482 (beginning-of-line) (point)))))
3483 (setq from
(mail-fetch-field "from")
3484 reply-to
(or (mail-fetch-field "mail-reply-to" nil t
)
3485 (mail-fetch-field "reply-to" nil t
)
3487 subject
(mail-fetch-field "subject")
3488 date
(mail-fetch-field "date")
3489 message-id
(mail-fetch-field "message-id")
3490 references
(mail-fetch-field "references" nil nil t
)
3491 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3492 resent-cc
(and (not just-sender
)
3493 (mail-fetch-field "resent-cc" nil t
))
3494 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
3495 ;;; resent-subject (mail-fetch-field "resent-subject")
3496 ;;; resent-date (mail-fetch-field "resent-date")
3497 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3500 (if (mail-fetch-field "mail-followup-to" nil t
)
3501 ;; If this header field is present, use it instead of the To and CC fields.
3502 (setq to
(mail-fetch-field "mail-followup-to" nil t
))
3503 (setq cc
(or (mail-fetch-field "cc" nil t
) "")
3504 to
(or (mail-fetch-field "to" nil t
) ""))))
3508 ;; Merge the resent-to and resent-cc into the to and cc.
3509 (if (and resent-to
(not (equal resent-to
"")))
3510 (if (not (equal to
""))
3511 (setq to
(concat to
", " resent-to
))
3512 (setq to resent-to
)))
3513 (if (and resent-cc
(not (equal resent-cc
"")))
3514 (if (not (equal cc
""))
3515 (setq cc
(concat cc
", " resent-cc
))
3516 (setq cc resent-cc
)))
3517 ;; Add `Re: ' to subject if not there already.
3518 (and (stringp subject
)
3520 (concat rmail-reply-prefix
3521 (if (let ((case-fold-search t
))
3522 (string-match rmail-reply-regexp subject
))
3523 (substring subject
(match-end 0))
3527 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3528 ;; since they can handle the names unstripped.
3529 ;; I don't know whether there are other mailers that still
3530 ;; need the names to be stripped.
3531 ;;; (mail-strip-quoted-names reply-to)
3532 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3533 ;; header causes all the names in it to wind up in reply-to, not
3534 ;; in cc. But if what's left is an empty list, use the original.
3535 (let* ((reply-to-list (rmail-dont-reply-to reply-to
)))
3536 (if (string= reply-to-list
"") reply-to reply-to-list
))
3538 (rmail-make-in-reply-to-field from date message-id
)
3541 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
3543 (let* ((cc-list (rmail-dont-reply-to
3544 (mail-strip-quoted-names
3545 (if (null cc
) to
(concat to
", " cc
))))))
3546 (if (string= cc-list
"") nil cc-list
)))
3548 (list (list 'rmail-mark-message
3550 (with-current-buffer rmail-buffer
3551 (aref rmail-msgref-vector msgnum
))
3554 (list (cons "References" (concat (mapconcat 'identity references
" ")
3555 " " message-id
))))))
3557 (defun rmail-mark-message (buffer msgnum-list attribute
)
3558 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3559 This is use in the send-actions for message buffers.
3560 MSGNUM-LIST is a list of the form (MSGNUM)
3561 which is an element of rmail-msgref-vector."
3564 (if (car msgnum-list
)
3565 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3567 (defun rmail-make-in-reply-to-field (from date message-id
)
3574 (let ((tem (car (rfc822-addresses from
))))
3578 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3580 (match-beginning 0))
3583 ;; missing From, or Message-ID is sufficiently informative
3585 (concat message-id
" (" tem
")"))
3586 ;; Copy TEM, discarding text properties.
3587 (setq tem
(copy-sequence tem
))
3588 (set-text-properties 0 (length tem
) nil tem
)
3589 (setq tem
(copy-sequence tem
))
3590 ;; Use prin1 to fake RFC822 quoting
3591 (let ((field (prin1-to-string tem
)))
3593 (concat field
"'s message of " date
)
3595 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3596 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3597 ;; These strings both match all non-ASCII characters.
3598 (or (string-match (concat "\\`[ \t]*\\(" bar
3599 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3600 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3602 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3603 bar
"\\))[ \t]*\\'")
3604 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3606 (let ((start (match-beginning 1))
3607 (end (match-end 1)))
3608 ;; Trim whitespace which above regexp match allows
3609 (while (and (< start end
)
3610 (memq (aref from start
) '(?
\t ?\
)))
3611 (setq start
(1+ start
)))
3612 (while (and (< start end
)
3613 (memq (aref from
(1- end
)) '(?
\t ?\
)))
3614 (setq end
(1- end
)))
3615 (let ((field (substring from start end
)))
3616 (if date
(setq field
(concat "message from " field
" on " date
)))
3618 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3619 (concat message-id
" (" field
")")
3622 ;; If we can't kludge it simply, do it correctly
3623 (let ((mail-use-rfc822 t
))
3624 (rmail-make-in-reply-to-field from date message-id
)))))
3626 (defun rmail-forward (resend)
3627 "Forward the current message to another user.
3628 With prefix argument, \"resend\" the message instead of forwarding it;
3629 see the documentation of `rmail-resend'."
3632 (call-interactively 'rmail-resend
)
3633 (let ((forward-buffer rmail-buffer
)
3634 (msgnum rmail-current-message
)
3635 (subject (concat "["
3636 (let ((from (or (mail-fetch-field "From")
3637 (mail-fetch-field ">From"))))
3639 (concat (mail-strip-quoted-names from
) ": ")
3641 (or (mail-fetch-field "Subject") "")
3643 (if (rmail-start-mail
3644 nil nil subject nil nil nil
3645 (list (list 'rmail-mark-message
3647 (with-current-buffer rmail-buffer
3648 (aref rmail-msgref-vector msgnum
))
3650 ;; If only one window, use it for the mail buffer.
3651 ;; Otherwise, use another window for the mail buffer
3652 ;; so that the Rmail buffer remains visible
3653 ;; and sending the mail will get back to it.
3654 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3655 ;; The mail buffer is now current.
3657 ;; Insert after header separator--before signature if any.
3658 (goto-char (mail-text-start))
3659 (if (or rmail-enable-mime rmail-enable-mime-composing
)
3660 (funcall rmail-insert-mime-forwarded-message-function
3662 (insert "------- Start of forwarded message -------\n")
3663 ;; Quote lines with `- ' if they start with `-'.
3664 (let ((beg (point)) end
)
3665 (setq end
(point-marker))
3666 (set-marker-insertion-type end t
)
3667 (insert-buffer-substring forward-buffer
)
3669 (while (re-search-forward "^-" end t
)
3674 (skip-chars-backward "\n")
3677 (delete-region (point) end
)
3678 (set-marker end nil
))
3679 (insert "------- End of forwarded message -------\n"))
3682 (defun rmail-resend (address &optional from comment mail-alias-file
)
3683 "Resend current message to ADDRESSES.
3684 ADDRESSES should be a single address, a string consisting of several
3685 addresses separated by commas, or a list of addresses.
3687 Optional FROM is the address to resend the message from, and
3688 defaults from the value of `user-mail-address'.
3689 Optional COMMENT is a string to insert as a comment in the resent message.
3690 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3691 typically for purposes of moderating a list."
3692 (interactive "sResend to: ")
3694 (require 'mailalias
)
3695 (unless (or (eq rmail-view-buffer
(current-buffer))
3696 (eq rmail-buffer
(current-buffer)))
3697 (error "Not an Rmail buffer"))
3698 (if (not from
) (setq from user-mail-address
))
3699 (let ((tembuf (generate-new-buffer " sendmail temp"))
3700 (case-fold-search nil
)
3701 (mail-personal-alias-file
3702 (or mail-alias-file mail-personal-alias-file
))
3703 (mailbuf rmail-buffer
))
3705 (with-current-buffer tembuf
3706 ;;>> Copy message into temp buffer
3707 (if rmail-enable-mime
3708 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3709 (insert-buffer-substring mailbuf
))
3710 (goto-char (point-min))
3711 ;; Delete any Sender field, since that's not specifiable.
3712 ; Only delete Sender fields in the actual header.
3713 (re-search-forward "^$" nil
'move
)
3714 ; Using "while" here rather than "if" because some buggy mail
3715 ; software may have inserted multiple Sender fields.
3716 (while (re-search-backward "^Sender:" nil t
)
3720 (while (looking-at "[ \t]")
3722 (delete-region beg
(point))))
3723 ; Go back to the beginning of the buffer so the Resent- fields
3724 ; are inserted there.
3725 (goto-char (point-min))
3726 ;;>> Insert resent-from:
3727 (insert "Resent-From: " from
"\n")
3728 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3729 ;;>> Insert resent-to: and bcc if need be.
3730 (let ((before (point)))
3732 (insert "Resent-Bcc: " (user-login-name) "\n"))
3733 (insert "Resent-To: " (if (stringp address
)
3735 (mapconcat 'identity address
",\n\t"))
3737 ;; Expand abbrevs in the recipients.
3739 (if (featurep 'mailabbrev
)
3740 (let ((end (point-marker))
3741 (local-abbrev-table mail-abbrevs
)
3742 (old-syntax-table (syntax-table)))
3743 (if (and (not (vectorp mail-abbrevs
))
3744 (file-exists-p mail-personal-alias-file
))
3745 (build-mail-abbrevs))
3746 (unless mail-abbrev-syntax-table
3747 (mail-abbrev-make-syntax-table))
3748 (set-syntax-table mail-abbrev-syntax-table
)
3750 (while (and (< (point) end
)
3751 (progn (forward-word 1)
3754 (set-syntax-table old-syntax-table
))
3755 (expand-mail-aliases before
(point)))))
3756 ;;>> Set up comment, if any.
3757 (if (and (sequencep comment
) (not (zerop (length comment
))))
3758 (let ((before (point))
3761 (or (eolp) (insert "\n"))
3762 (setq after
(point))
3764 (while (< (point) after
)
3765 (insert "Resent-Comment: ")
3767 ;; Don't expand aliases in the destination fields
3768 ;; of the original message.
3770 (funcall send-mail-function
)))
3771 (kill-buffer tembuf
))
3772 (with-current-buffer rmail-buffer
3773 (rmail-set-attribute "resent" t rmail-current-message
))))
3775 (defvar mail-unsent-separator
3776 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3777 "^ *---+ +Returned message +---+ *$\\|"
3778 "^ *---+ *Returned mail follows *---+ *$\\|"
3779 "^Start of returned message$\\|"
3780 "^---+ Below this line is a copy of the message.$\\|"
3781 "^ *---+ +Original message +---+ *$\\|"
3782 "^ *--+ +begin message +--+ *$\\|"
3783 "^ *---+ +Original message follows +---+ *$\\|"
3784 "^ *---+ +Your message follows +---+ *$\\|"
3785 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3786 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3787 "A regexp that matches the separator before the text of a failed message.")
3789 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3790 "A regexp that matches the header of a MIME body part with a failed message.")
3792 (defun rmail-retry-failure ()
3793 "Edit a mail message which is based on the contents of the current message.
3794 For a message rejected by the mail system, extract the interesting headers and
3795 the body of the original message.
3796 If the failed message is a MIME multipart message, it is searched for a
3797 body part with a header which matches the variable `mail-mime-unsent-header'.
3798 Otherwise, the variable `mail-unsent-separator' should match the string that
3799 delimits the returned original message.
3800 The variable `rmail-retry-ignored-headers' is a regular expression
3801 specifying headers which should not be copied into the new message."
3803 (require 'mail-utils
)
3804 (let ((rmail-this-buffer (current-buffer))
3805 (msgnum rmail-current-message
)
3806 bounce-start bounce-end bounce-indent resending
3807 ;; Fetch any content-type header in current message
3808 ;; Must search thru the whole unpruned header.
3812 (rmail-narrow-to-non-pruned-header)
3813 (mail-fetch-field "Content-Type") ))))
3815 (goto-char (point-min))
3816 (let ((case-fold-search t
))
3817 (if (and content-type
3819 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3821 ;; Handle a MIME multipart bounce message.
3824 (substring content-type
(match-beginning 1)
3826 (unless (re-search-forward mail-mime-unsent-header nil t
)
3827 (error "Cannot find beginning of header in failed message"))
3828 (unless (search-forward "\n\n" nil t
)
3829 (error "Cannot find start of Mime data in failed message"))
3830 (setq bounce-start
(point))
3831 (if (search-forward codestring nil t
)
3832 (setq bounce-end
(match-beginning 0))
3833 (setq bounce-end
(point-max))))
3835 (or (re-search-forward mail-unsent-separator nil t
)
3836 (error "Cannot parse this as a failure message"))
3837 (skip-chars-forward "\n")
3838 ;; Support a style of failure message in which the original
3839 ;; message is indented, and included within lines saying
3840 ;; `Start of returned message' and `End of returned message'.
3841 (if (looking-at " +Received:")
3843 (setq bounce-start
(point))
3844 (skip-chars-forward " ")
3845 (setq bounce-indent
(- (current-column)))
3846 (goto-char (point-max))
3847 (re-search-backward "^End of returned message$" nil t
)
3848 (setq bounce-end
(point)))
3849 ;; One message contained a few random lines before
3850 ;; the old message header. The first line of the
3851 ;; message started with two hyphens. A blank line
3852 ;; followed these random lines. The same line
3853 ;; beginning with two hyphens was possibly marking
3854 ;; the end of the message.
3855 (if (looking-at "^--")
3856 (let ((boundary (buffer-substring-no-properties
3858 (progn (end-of-line) (point)))))
3859 (search-forward "\n\n")
3860 (skip-chars-forward "\n")
3861 (setq bounce-start
(point))
3862 (goto-char (point-max))
3863 (search-backward (concat "\n\n" boundary
) bounce-start t
)
3864 (setq bounce-end
(point)))
3865 (setq bounce-start
(point)
3866 bounce-end
(point-max)))
3867 (unless (search-forward "\n\n" nil t
)
3868 (error "Cannot find end of header in failed message"))))))
3869 ;; We have found the message that bounced, within the current message.
3870 ;; Now start sending new message; default header fields from original.
3871 ;; Turn off the usual actions for initializing the message body
3872 ;; because we want to get only the text from the failure message.
3873 (let (mail-signature mail-setup-hook
)
3874 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3875 (list (list 'rmail-mark-message
3877 (aref rmail-msgref-vector msgnum
)
3879 ;; Insert original text as initial text of new draft message.
3880 ;; Bind inhibit-read-only since the header delimiter
3881 ;; of the previous message was probably read-only.
3882 (let ((inhibit-read-only t
)
3883 rmail-displayed-headers
3884 rmail-ignored-headers
)
3886 (insert-buffer-substring rmail-this-buffer
3887 bounce-start bounce-end
)
3888 (goto-char (point-min))
3890 (indent-rigidly (point-min) (point-max) bounce-indent
))
3891 (rmail-clear-headers rmail-retry-ignored-headers
)
3892 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:")
3893 (mail-sendmail-delimit-header)
3895 (narrow-to-region (point-min) (mail-header-end))
3896 (setq resending
(mail-fetch-field "resent-to"))
3899 (insert "Resent-Bcc: " (user-login-name) "\n")
3900 (insert "BCC: " (user-login-name) "\n"))))
3901 (goto-char (point-min))
3902 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
3904 (defun rmail-summary-exists ()
3905 "Non-nil iff in an RMAIL buffer and an associated summary buffer exists.
3906 In fact, the non-nil value returned is the summary buffer itself."
3907 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3908 rmail-summary-buffer
))
3910 (defun rmail-summary-displayed ()
3911 "t iff in RMAIL buffer and an associated summary buffer is displayed."
3912 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
3914 (defcustom rmail-redisplay-summary nil
3915 "*Non-nil means Rmail should show the summary when it changes.
3916 This has an effect only if a summary buffer exists."
3918 :group
'rmail-summary
)
3920 (defcustom rmail-summary-window-size nil
3921 "*Non-nil means specify the height for an Rmail summary window."
3922 :type
'(choice (const :tag
"Disabled" nil
) integer
)
3923 :group
'rmail-summary
)
3925 ;; Put the summary buffer back on the screen, if user wants that.
3926 (defun rmail-maybe-display-summary ()
3927 (let ((selected (selected-window))
3929 ;; If requested, make sure the summary is displayed.
3930 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3931 rmail-redisplay-summary
3932 (if (get-buffer-window rmail-summary-buffer
0)
3933 ;; It's already in some frame; show that one.
3934 (let ((frame (window-frame
3935 (get-buffer-window rmail-summary-buffer
0))))
3936 (make-frame-visible frame
)
3937 (raise-frame frame
))
3938 (display-buffer rmail-summary-buffer
)))
3939 ;; If requested, set the height of the summary window.
3940 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
3941 rmail-summary-window-size
3942 (setq window
(get-buffer-window rmail-summary-buffer
))
3943 ;; Don't try to change the size if just one window in frame.
3944 (not (eq window
(frame-root-window (window-frame window
))))
3947 (select-window window
)
3948 (enlarge-window (- rmail-summary-window-size
(window-height))))
3949 (select-window selected
)))))
3951 ;;;; *** Rmail Local Fontification ***
3953 (defun rmail-fontify-buffer-function ()
3954 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3955 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
3956 ;; If we're already showing a message, fontify it now.
3957 (if rmail-current-message
(rmail-fontify-message))
3958 ;; Prevent Font Lock mode from kicking in.
3959 (setq font-lock-fontified t
))
3961 (defun rmail-unfontify-buffer-function ()
3962 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
3963 (let ((modified (buffer-modified-p))
3964 (buffer-undo-list t
) (inhibit-read-only t
)
3965 before-change-functions after-change-functions
3966 buffer-file-name buffer-file-truename
)
3969 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
3970 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
3971 (font-lock-default-unfontify-buffer)
3972 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
3974 (defun rmail-fontify-message ()
3975 ;; Fontify the current message if it is not already fontified.
3976 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
3977 (let ((modified (buffer-modified-p))
3978 (buffer-undo-list t
) (inhibit-read-only t
)
3979 before-change-functions after-change-functions
3980 buffer-file-name buffer-file-truename
)
3983 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
3984 (font-lock-fontify-region (point-min) (point-max))
3985 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
3987 ;;; Speedbar support for RMAIL files.
3988 (eval-when-compile (require 'speedbar
))
3990 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
3991 "*This regex is used to match folder names to be displayed in speedbar.
3992 Enabling this will permit speedbar to display your folders for easy
3993 browsing, and moving of messages.")
3995 (defvar rmail-speedbar-last-user nil
3996 "The last user to be displayed in the speedbar.")
3998 (defvar rmail-speedbar-key-map nil
3999 "Keymap used when in rmail display mode.")
4001 (defun rmail-install-speedbar-variables ()
4002 "Install those variables used by speedbar to enhance rmail."
4003 (if rmail-speedbar-key-map
4005 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
4007 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
4008 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
4009 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
4010 (define-key rmail-speedbar-key-map
"M"
4011 'rmail-speedbar-move-message-to-folder-on-line
)))
4013 (defvar rmail-speedbar-menu-items
4014 '(["Read Folder" speedbar-edit-line t
]
4015 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4016 (save-excursion (beginning-of-line)
4017 (looking-at "<M> "))])
4018 "Additional menu-items to add to speedbar frame.")
4020 ;; Make sure our special speedbar major mode is loaded
4021 (if (featurep 'speedbar
)
4022 (rmail-install-speedbar-variables)
4023 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
4025 (defun rmail-speedbar-buttons (buffer)
4026 "Create buttons for BUFFER containing rmail messages.
4027 Click on the address under Reply to: to reply to this person.
4028 Under Folders: Click a name to read it, or on the <M> to move the
4029 current message into that RMAIL folder."
4033 (goto-char (point-min))
4034 (if (not (re-search-forward "^Reply-To: " nil t
))
4035 (if (not (re-search-forward "^From:? " nil t
))
4039 (setq from
(buffer-substring (point) (save-excursion
4042 (goto-char (point-min))
4043 (if (and (looking-at "Reply to:")
4044 (equal from rmail-speedbar-last-user
))
4046 (setq rmail-speedbar-last-user from
)
4048 (insert "Reply To:\n")
4050 (speedbar-insert-button from
'speedbar-directory-face
'highlight
4051 'rmail-speedbar-button
'rmail-reply
))
4052 (insert "Folders:\n")
4053 (let* ((case-fold-search nil
)
4054 (df (directory-files (save-excursion (set-buffer buffer
)
4056 nil rmail-speedbar-match-folder-regexp
)))
4058 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
4059 'rmail-speedbar-move-message
(car df
))
4060 (speedbar-insert-button (car df
) 'speedbar-file-face
'highlight
4061 'rmail-speedbar-find-file nil t
)
4062 (setq df
(cdr df
)))))))
4064 (defun rmail-speedbar-button (text token indent
)
4065 "Execute an rmail command specified by TEXT.
4066 The command used is TOKEN. INDENT is not used."
4067 (speedbar-with-attached-buffer
4070 (defun rmail-speedbar-find-file (text token indent
)
4071 "Load in the rmail file TEXT.
4072 TOKEN and INDENT are not used."
4073 (speedbar-with-attached-buffer
4074 (message "Loading in RMAIL file %s..." text
)
4077 (defun rmail-speedbar-move-message-to-folder-on-line ()
4078 "If the current line is a folder, move current message to it."
4082 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t
)
4085 (speedbar-do-function-pointer)))))
4087 (defun rmail-speedbar-move-message (text token indent
)
4088 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4089 TEXT and INDENT are not used."
4090 (speedbar-with-attached-buffer
4091 (message "Moving message to %s" token
)
4092 (rmail-output-to-rmail-file token
)))
4094 ; Functions for setting, getting and encoding the POP password.
4095 ; The password is encoded to prevent it from being easily accessible
4096 ; to "prying eyes." Obviously, this encoding isn't "real security,"
4097 ; nor is it meant to be.
4100 (defun rmail-set-remote-password (password)
4101 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4102 (interactive "sPassword: ")
4104 (setq rmail-encoded-remote-password
4105 (rmail-encode-string password
(emacs-pid)))
4106 (setq rmail-remote-password nil
)
4107 (setq rmail-encoded-remote-password nil
)))
4109 (defun rmail-get-remote-password (imap)
4110 "Get the password for retrieving mail from a POP or IMAP server. If none
4111 has been set, then prompt the user for one."
4112 (when (not rmail-encoded-remote-password
)
4113 (if (not rmail-remote-password
)
4114 (setq rmail-remote-password
4115 (read-passwd (if imap
4117 "POP password: "))))
4118 (rmail-set-remote-password rmail-remote-password
)
4119 (setq rmail-remote-password nil
))
4120 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4122 (defun rmail-have-password ()
4123 (or rmail-remote-password rmail-encoded-remote-password
))
4125 (defun rmail-encode-string (string mask
)
4126 "Encode STRING with integer MASK, by taking the exclusive OR of the
4127 lowest byte in the mask with the first character of string, the
4128 second-lowest-byte with the second character of the string, etc.,
4129 restarting at the lowest byte of the mask whenever it runs out.
4130 Returns the encoded string. Calling the function again with an
4131 encoded string (and the same mask) will decode the string."
4132 (setq mask
(abs mask
)) ; doesn't work if negative
4133 (let* ((string-vector (string-to-vector string
)) (i 0)
4134 (len (length string-vector
)) (curmask mask
) charmask
)
4137 (setq curmask mask
))
4138 (setq charmask
(% curmask
256))
4139 (setq curmask
(lsh curmask -
8))
4140 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4142 (concat string-vector
)))
4144 ;;;; Desktop support
4146 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4148 desktop-buffer-misc
)
4149 "Restore an rmail buffer specified in a desktop file."
4150 (condition-case error
4152 (rmail-input desktop-buffer-file-name
)
4153 (if (eq major-mode
'rmail-mode
)
4157 (kill-buffer (current-buffer))
4160 (add-to-list 'desktop-buffer-mode-handlers
4161 '(rmail-mode . rmail-restore-desktop-buffer
))
4165 ;;; arch-tag: cff0a950-57fe-4f73-a86e-91ff75afd06c
4166 ;;; rmail.el ends here