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, 2006, 2007, 2008
5 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software; you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation; either version 3, or (at your option)
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs; see the file COPYING. If not, write to the
24 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
25 ;; Boston, MA 02110-1301, USA.
31 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
32 ;; New features include attribute and keyword support, message
33 ;; selection by dispatch table, summary by attributes and keywords,
34 ;; expunging by dispatch table, sticky options for file commands.
36 ;; Extended by Bob Weiner of Motorola
37 ;; New features include: rmail and rmail-summary buffers remain
38 ;; synchronized and key bindings basically operate the same way in both
39 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
40 ;; variable, and a bury rmail buffer (wipe) command.
44 (eval-when-compile (require 'mule-util
)) ; for detect-coding-with-priority
47 (defvar font-lock-fontified
)
48 (defvar mail-abbrev-syntax-table
)
50 (defvar messages-head
)
51 (defvar rmail-use-spam-filter
)
53 (defvar rsf-sleep-after-message
)
54 (defvar total-messages
)
57 ; These variables now declared in paths.el.
58 ;(defvar rmail-spool-directory "/usr/spool/mail/"
59 ; "This is the name of the directory used by the system mailer for\n\
60 ;delivering new mail. Its name should end with a slash.")
61 ;(defvar rmail-file-name
62 ; (expand-file-name "~/RMAIL")
66 "Mail reader for Emacs."
69 (defgroup rmail-retrieve nil
70 "Rmail retrieval options."
74 (defgroup rmail-files nil
79 (defgroup rmail-headers nil
80 "Rmail header options."
84 (defgroup rmail-reply nil
85 "Rmail reply options."
89 (defgroup rmail-summary nil
90 "Rmail summary options."
92 :prefix
"rmail-summary-"
95 (defgroup rmail-output nil
96 "Output message to a file."
97 :prefix
"rmail-output-"
101 (defgroup rmail-edit nil
103 :prefix
"rmail-edit-"
106 (defgroup rmail-obsolete nil
107 "Rmail obsolete customization variables."
110 (defcustom rmail-movemail-program nil
111 "If non-nil, the file name of the `movemail' program."
112 :group
'rmail-retrieve
113 :type
'(choice (const nil
) string
))
115 (defcustom rmail-pop-password nil
116 "*Password to use when reading mail from POP server.
117 Please use `rmail-remote-password' instead."
118 :type
'(choice (string :tag
"Password")
119 (const :tag
"Not Required" nil
))
120 :group
'rmail-obsolete
)
122 (defcustom rmail-pop-password-required nil
123 "*Non-nil if a password is required when reading mail from a POP server.
124 Please use rmail-remote-password-required instead."
126 :group
'rmail-obsolete
)
128 (defcustom rmail-remote-password nil
129 "*Password to use when reading mail from a remote server.
130 This setting is ignored for mailboxes whose URL already contains a password."
131 :type
'(choice (string :tag
"Password")
132 (const :tag
"Not Required" nil
))
133 :set-after
'(rmail-pop-password)
134 :set
#'(lambda (symbol value
)
137 (boundp 'rmail-pop-password
)
141 (setq rmail-pop-password nil
))
142 :group
'rmail-retrieve
145 (defcustom rmail-remote-password-required nil
146 "*Non-nil if a password is required when reading mail from a remote server."
148 :set-after
'(rmail-pop-password-required)
149 :set
#'(lambda (symbol value
)
152 (boundp 'rmail-pop-password-required
)
153 rmail-pop-password-required
)
154 rmail-pop-password-required
156 (setq rmail-pop-password-required nil
))
157 :group
'rmail-retrieve
160 (defcustom rmail-movemail-flags nil
161 "*List of flags to pass to movemail.
162 Most commonly used to specify `-g' to enable GSS-API authentication
163 or `-k' to enable Kerberos authentication."
164 :type
'(repeat string
)
165 :group
'rmail-retrieve
168 (defvar rmail-remote-password-error
"invalid usercode or password\\|
169 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
170 "Regular expression matching incorrect-password POP or IMAP server error
172 If you get an incorrect-password error that this expression does not match,
173 please report it with \\[report-emacs-bug].")
175 (defvar rmail-encoded-remote-password nil
)
177 (defcustom rmail-preserve-inbox nil
178 "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
180 :group
'rmail-retrieve
)
182 (defcustom rmail-movemail-search-path nil
183 "*List of directories to search for movemail (in addition to `exec-path')."
184 :group
'rmail-retrieve
185 :type
'(repeat (directory)))
187 (defun rmail-probe (prog)
188 "Determine what flavor of movemail PROG is.
189 We do this by executing it with `--version' and analyzing its output."
191 (let ((tbuf (current-buffer)))
192 (buffer-disable-undo tbuf
)
193 (call-process prog nil tbuf nil
"--version")
194 (if (not (buffer-modified-p tbuf
))
195 ;; Should not happen...
197 (goto-char (point-min))
199 ((looking-at ".*movemail: invalid option")
200 'emacs
) ;; Possibly...
201 ((looking-at "movemail (GNU Mailutils .*)")
207 (defun rmail-autodetect ()
208 "Determine and return the file name of the `movemail' program.
209 If `rmail-movemail-program' is non-nil, use it.
210 Otherwise, look for `movemail' in the directories in
211 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
212 (if rmail-movemail-program
213 (rmail-probe rmail-movemail-program
)
215 (dolist (dir (append rmail-movemail-search-path exec-path
216 (list exec-directory
)))
217 (when (and dir
(file-accessible-directory-p dir
))
218 ;; Previously, this didn't have to work on Windows, because
219 ;; rmail-insert-inbox-text before r1.439 fell back to using
220 ;; (expand-file-name "movemail" exec-directory) and just
221 ;; assuming it would work.
222 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2008-02/msg00087.html
223 (let ((progname (expand-file-name
225 (if (memq system-type
'(ms-dos windows-nt
))
227 (when (and (not (file-directory-p progname
))
228 (file-executable-p progname
))
229 (let ((x (rmail-probe progname
)))
231 (setq rmail-movemail-program progname
)
232 (throw 'scan x
))))))))))
234 (defvar rmail-movemail-variant-in-use nil
235 "The movemail variant currently in use. Known variants are:
237 `emacs' Means any implementation, compatible with the native Emacs one.
239 `mailutils' Means GNU mailutils implementation, capable of handling full
240 mail URLs as the source mailbox.")
243 (defun rmail-movemail-variant-p (&rest variants
)
244 "Return t if the current movemail variant is any of VARIANTS.
245 Currently known variants are 'emacs and 'mailutils."
246 (when (not rmail-movemail-variant-in-use
)
248 (setq rmail-movemail-variant-in-use
(rmail-autodetect)))
249 (not (null (member rmail-movemail-variant-in-use variants
))))
251 ;; Call for effect, to set rmail-movemail-program (if not set by the
252 ;; user), and rmail-movemail-variant-in-use. Used by various functions.
253 ;; I'm not sure if M-x rmail is the only entry point to this package.
254 ;; If so, this can be moved there.
255 (rmail-movemail-variant-p)
258 (defcustom rmail-dont-reply-to-names nil
"\
259 *A regexp specifying addresses to prune from a reply message.
260 A value of nil means exclude your own email address as an address
261 plus whatever is specified by `rmail-default-dont-reply-to-names'."
262 :type
'(choice regexp
(const :tag
"Your Name" nil
))
266 (defvar rmail-default-dont-reply-to-names
"\\`info-" "\
267 A regular expression specifying part of the default value of the
268 variable `rmail-dont-reply-to-names', for when the user does not set
269 `rmail-dont-reply-to-names' explicitly. (The other part of the default
270 value is the user's email address and name.)
271 It is useful to set this variable in the site customization file.")
274 (defcustom rmail-ignored-headers
275 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
276 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
277 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
278 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
279 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
280 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
281 "\\|^content-transfer-encoding:\\|^x-coding-system:"
282 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
283 "\\|^precedence:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
284 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
285 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
286 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
287 "\\|^mbox-line:\\|^cancel-lock:\\|^DomainKey-Signature:"
288 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
291 "*Regexp to match header fields that Rmail should normally hide.
292 \(See also `rmail-nonignored-headers', which overrides this regexp.)
293 This variable is used for reformatting the message header,
294 which normally happens once for each message,
295 when you view the message for the first time in Rmail.
296 To make a change in this variable take effect
297 for a message that you have already viewed,
298 go to that message and type \\[rmail-toggle-header] twice."
300 :group
'rmail-headers
)
302 (defcustom rmail-nonignored-headers
"^x-spam-status:"
303 "*Regexp to match X header fields that Rmail should show.
304 This regexp overrides `rmail-ignored-headers'; if both this regexp
305 and that one match a certain header field, Rmail shows the field.
307 This variable is used for reformatting the message header,
308 which normally happens once for each message,
309 when you view the message for the first time in Rmail.
310 To make a change in this variable take effect
311 for a message that you have already viewed,
312 go to that message and type \\[rmail-toggle-header] twice."
314 :group
'rmail-headers
)
317 (defcustom rmail-displayed-headers nil
318 "*Regexp to match Header fields that Rmail should display.
319 If nil, display all header fields except those matched by
320 `rmail-ignored-headers'."
321 :type
'(choice regexp
(const :tag
"All"))
322 :group
'rmail-headers
)
325 (defcustom rmail-retry-ignored-headers
"^x-authentication-warning:" "\
326 *Headers that should be stripped when retrying a failed message."
327 :type
'(choice regexp
(const nil
:tag
"None"))
328 :group
'rmail-headers
)
331 (defcustom rmail-highlighted-headers
"^From:\\|^Subject:" "\
332 *Regexp to match Header fields that Rmail should normally highlight.
333 A value of nil means don't highlight.
334 See also `rmail-highlight-face'."
336 :group
'rmail-headers
)
338 (defface rmail-highlight
339 '((t (:inherit highlight
)))
340 "Face to use for highlighting the most important header fields."
341 :group
'rmail-headers
345 (defcustom rmail-highlight-face
'rmail-highlight
"\
346 *Face used by Rmail for highlighting headers."
347 :type
'(choice (const :tag
"Default" nil
)
349 :group
'rmail-headers
)
352 (defcustom rmail-delete-after-output nil
"\
353 *Non-nil means automatically delete a message that is copied to a file."
358 (defcustom rmail-primary-inbox-list nil
"\
359 *List of files which are inboxes for user's primary mail file `~/RMAIL'.
360 nil means the default, which is (\"/usr/spool/mail/$USER\")
361 \(the name varies depending on the operating system,
362 and the value of the environment variable MAIL overrides it)."
363 ;; Don't use backquote here, because we don't want to need it
365 :type
(list 'choice
'(const :tag
"Default" nil
)
366 (list 'repeat
':value
(list (or (getenv "MAIL")
367 (concat "/var/spool/mail/"
370 :group
'rmail-retrieve
374 (defcustom rmail-mail-new-frame nil
375 "*Non-nil means Rmail makes a new frame for composing outgoing mail.
376 This is handy if you want to preserve the window configuration of
377 the frame where you have the RMAIL buffer displayed."
382 (defcustom rmail-secondary-file-directory
"~/"
383 "*Directory for additional secondary Rmail files."
387 (defcustom rmail-secondary-file-regexp
"\\.xmail$"
388 "*Regexp for which files are secondary Rmail files."
393 (defcustom rmail-confirm-expunge
'y-or-n-p
394 "*Whether and how to ask for confirmation before expunging deleted messages."
395 :type
'(choice (const :tag
"No confirmation" nil
)
396 (const :tag
"Confirm with y-or-n-p" y-or-n-p
)
397 (const :tag
"Confirm with yes-or-no-p" yes-or-no-p
))
402 (defvar rmail-mode-hook nil
403 "List of functions to call when Rmail is invoked.")
406 (defvar rmail-get-new-mail-hook nil
407 "List of functions to call when Rmail has retrieved new mail.")
410 (defcustom rmail-show-message-hook nil
411 "List of functions to call when Rmail displays a message."
413 :options
'(goto-address)
417 (defvar rmail-quit-hook nil
418 "List of functions to call when quitting out of Rmail.")
421 (defvar rmail-delete-message-hook nil
422 "List of functions to call when Rmail deletes a message.
423 When the hooks are called, the message has been marked deleted but is
424 still the current message in the Rmail buffer.")
426 ;; These may be altered by site-init.el to match the format of mmdf files
427 ;; delimiting used on a given host (delim1 and delim2 from the config
430 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
431 "Regexp marking the start of an mmdf message.")
432 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
433 "Regexp marking the end of an mmdf message.")
435 (defcustom rmail-message-filter nil
436 "If non-nil, a filter function for new messages in RMAIL.
437 Called with region narrowed to the message, including headers,
438 before obeying `rmail-ignored-headers'."
439 :group
'rmail-headers
440 :type
'(choice (const nil
) function
))
442 (defcustom rmail-automatic-folder-directives nil
443 "List of directives specifying where to put a message.
444 Each element of the list is of the form:
446 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
448 Where FOLDERNAME is the name of a BABYL format folder to put the
449 message. If any of the field regexp's are nil, then it is ignored.
451 If FOLDERNAME is \"/dev/null\", it is deleted.
452 If FOLDERNAME is nil then it is deleted, and skipped.
454 FIELD is the plain text name of a field in the message, such as
455 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
456 all text from the \"cc\" field as well.
458 REGEXP is an expression to match in the preceeding specified FIELD.
459 FIELD/REGEXP pairs continue in the list.
462 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
463 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
466 :type
'(repeat (sexp :tag
"Directive")))
468 (defvar rmail-reply-prefix
"Re: "
469 "String to prepend to Subject line when replying to a message.")
471 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
472 ;; This pattern should catch all the common variants.
473 ;; rms: I deleted the change to delete tags in square brackets
474 ;; because they mess up RT tags.
475 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
476 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
478 (defcustom rmail-display-summary nil
479 "*If non-nil, Rmail always displays the summary buffer."
480 :group
'rmail-summary
483 (defvar rmail-inbox-list nil
)
484 (put 'rmail-inbox-list
'permanent-local t
)
486 (defvar rmail-keywords nil
)
487 (put 'rmail-keywords
'permanent-local t
)
489 (defvar rmail-buffer nil
490 "The RMAIL buffer related to the current buffer.
491 In an RMAIL buffer, this holds the RMAIL buffer itself.
492 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
493 (put 'rmail-buffer
'permanent-local t
)
495 ;; Message counters and markers. Deleted flags.
497 (defvar rmail-current-message nil
)
498 (put 'rmail-current-message
'permanent-local t
)
500 (defvar rmail-total-messages nil
)
501 (put 'rmail-total-messages
'permanent-local t
)
503 (defvar rmail-message-vector nil
)
504 (put 'rmail-message-vector
'permanent-local t
)
506 (defvar rmail-deleted-vector nil
)
507 (put 'rmail-deleted-vector
'permanent-local t
)
509 (defvar rmail-msgref-vector nil
510 "In an Rmail buffer, a vector whose Nth element is a list (N).
511 When expunging renumbers messages, these lists are modified
512 by substituting the new message number into the existing list.")
513 (put 'rmail-msgref-vector
'permanent-local t
)
515 (defvar rmail-overlay-list nil
)
516 (put 'rmail-overlay-list
'permanent-local t
)
518 ;; These are used by autoloaded rmail-summary.
520 (defvar rmail-summary-buffer nil
)
521 (put 'rmail-summary-buffer
'permanent-local t
)
522 (defvar rmail-summary-vector nil
)
523 (put 'rmail-summary-vector
'permanent-local t
)
525 (defvar rmail-view-buffer nil
526 "Buffer which holds RMAIL message for MIME displaying.")
527 (put 'rmail-view-buffer
'permanent-local t
)
529 ;; `Sticky' default variables.
531 ;; Last individual label specified to a or k.
532 (defvar rmail-last-label nil
)
533 (put 'rmail-last-label
'permanent-local t
)
535 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
536 (defvar rmail-last-multi-labels nil
)
538 (defvar rmail-last-regexp nil
)
539 (put 'rmail-last-regexp
'permanent-local t
)
541 (defcustom rmail-default-file
"~/xmail"
542 "*Default file name for \\[rmail-output]."
545 (defcustom rmail-default-rmail-file
"~/XMAIL"
546 "*Default file name for \\[rmail-output-to-rmail-file]."
549 (defcustom rmail-default-body-file
"~/mailout"
550 "*Default file name for \\[rmail-output-body-to-file]."
555 ;; Mule and MIME related variables.
558 (defvar rmail-file-coding-system nil
559 "Coding system used in RMAIL file.
561 This is set to nil by default.")
564 (defcustom rmail-enable-mime nil
565 "*If non-nil, RMAIL uses MIME feature.
566 If the value is t, RMAIL automatically shows MIME decoded message.
567 If the value is neither t nor nil, RMAIL does not show MIME decoded message
568 until a user explicitly requires it.
570 Even if the value is non-nil, you can't use MIME feature
571 if the feature specified by `rmail-mime-feature' is not available
573 :type
'(choice (const :tag
"on" t
)
574 (const :tag
"off" nil
)
575 (other :tag
"when asked" ask
))
578 (defvar rmail-enable-mime-composing nil
579 "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
582 (defvar rmail-show-mime-function nil
583 "Function to show MIME decoded message of RMAIL file.
584 This function is called when `rmail-enable-mime' is non-nil.
585 It is called with no argument.")
588 (defvar rmail-insert-mime-forwarded-message-function nil
589 "Function to insert a message in MIME format so it can be forwarded.
590 This function is called if `rmail-enable-mime' or
591 `rmail-enable-mime-composing' is non-nil.
592 It is called with one argument FORWARD-BUFFER, which is a
593 buffer containing the message to forward. The current buffer
594 is the outgoing mail buffer.")
597 (defvar rmail-insert-mime-resent-message-function nil
598 "Function to insert a message in MIME format so it can be resent.
599 This function is called if `rmail-enable-mime' is non-nil.
600 It is called with one argument FORWARD-BUFFER, which is a
601 buffer containing the message to forward. The current buffer
602 is the outgoing mail buffer.")
605 (defvar rmail-search-mime-message-function nil
606 "Function to check if a regexp matches a MIME message.
607 This function is called if `rmail-enable-mime' is non-nil.
608 It is called with two arguments MSG and REGEXP, where
609 MSG is the message number, REGEXP is the regular expression.")
612 (defvar rmail-search-mime-header-function nil
613 "Function to check if a regexp matches a header of MIME message.
614 This function is called if `rmail-enable-mime' is non-nil.
615 It is called with three arguments MSG, REGEXP, and LIMIT, where
616 MSG is the message number,
617 REGEXP is the regular expression,
618 LIMIT is the position specifying the end of header.")
621 (defvar rmail-mime-feature
'rmail-mime
622 "Feature to require to load MIME support in Rmail.
623 When starting Rmail, if `rmail-enable-mime' is non-nil,
624 this feature is required with `require'.
626 The default value is `rmail-mime'. This feature is provided by
627 the rmail-mime package available at <http://www.m17n.org/rmail-mime/>.")
630 (defvar rmail-decode-mime-charset t
631 "*Non-nil means a message is decoded by MIME's charset specification.
632 If this variable is nil, or the message has not MIME specification,
633 the message is decoded as normal way.
635 If the variable `rmail-enable-mime' is non-nil, this variables is
636 ignored, and all the decoding work is done by a feature specified by
637 the variable `rmail-mime-feature'.")
640 (defvar rmail-mime-charset-pattern
641 (concat "^content-type:[ \t]*text/plain;"
642 "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
643 "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
644 "Regexp to match MIME-charset specification in a header of message.
645 The first parenthesized expression should match the MIME-charset name.")
648 ;;; Regexp matching the delimiter of messages in UNIX mail format
649 ;;; (UNIX From lines), minus the initial ^. Note that if you change
650 ;;; this expression, you must change the code in rmail-nuke-pinhead-header
651 ;;; that knows the exact ordering of the \\( \\) subexpressions.
652 (defvar rmail-unix-mail-delimiter
653 (let ((time-zone-regexp
654 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
655 "\\|[-+]?[0-9][0-9][0-9][0-9]"
661 ;; Many things can happen to an RFC 822 mailbox before it is put into
662 ;; a `From' line. The leading phrase can be stripped, e.g.
663 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
664 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
665 ;; can be removed, e.g.
666 ;; From: joe@y.z (Joe K
668 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
671 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
672 ;; The mailbox can be removed or be replaced by white space, e.g.
673 ;; From: "Joe User"{space}{tab}
675 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
676 ;; where {space} and {tab} represent the Ascii space and tab characters.
677 ;; We want to match the results of any of these manglings.
678 ;; The following regexp rejects names whose first characters are
679 ;; obviously bogus, but after that anything goes.
680 "\\([^\0-\b\n-\r\^?].*\\)? "
682 ;; The time the message was sent.
683 "\\([^\0-\r \^?]+\\) +" ; day of the week
684 "\\([^\0-\r \^?]+\\) +" ; month
685 "\\([0-3]?[0-9]\\) +" ; day of month
686 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
688 ;; Perhaps a time zone, specified by an abbreviation, or by a
693 " \\([0-9][0-9]+\\) *"
695 ;; On some systems the time zone can appear after the year, too.
699 "\\(remote from .*\\)?"
704 (defvar rmail-font-lock-keywords
705 ;; These are all matched case-insensitively.
707 (let* ((cite-chars "[>|}]")
709 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
710 (list '("^\\(From\\|Sender\\|Resent-From\\):"
711 . font-lock-function-name-face
)
712 '("^Reply-To:.*$" . font-lock-function-name-face
)
713 '("^Subject:" . font-lock-comment-face
)
714 '("^X-Spam-Status:" . font-lock-keyword-face
)
715 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
716 . font-lock-keyword-face
)
717 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
719 (,(concat "\\=[ \t]*"
720 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
721 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
723 (beginning-of-line) (end-of-line)
724 (1 font-lock-comment-delimiter-face nil t
)
725 (5 font-lock-comment-face nil t
)))
726 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
727 . font-lock-string-face
))))
728 "Additional expressions to highlight in Rmail mode.")
730 ;; Perform BODY in the summary buffer
731 ;; in such a way that its cursor is properly updated in its own window.
732 (defmacro rmail-select-summary
(&rest body
)
733 `(let ((total rmail-total-messages
))
734 (if (rmail-summary-displayed)
735 (let ((window (selected-window)))
739 (pop-to-buffer rmail-summary-buffer
)
740 ;; rmail-total-messages is a buffer-local var
741 ;; in the rmail buffer.
742 ;; This way we make it available for the body
743 ;; even tho the rmail buffer is not current.
744 (let ((rmail-total-messages total
))
746 (select-window window
))))
748 (set-buffer rmail-summary-buffer
)
749 (let ((rmail-total-messages total
))
751 (rmail-maybe-display-summary)))
753 ;;;; *** Rmail Mode ***
755 ;; This variable is dynamically bound. The defvar is here to placate
756 ;; the byte compiler.
758 (defvar rmail-enable-multibyte nil
)
761 (defun rmail-require-mime-maybe ()
762 "Require `rmail-mime-feature' if that is non-nil.
763 Signal an error and set `rmail-mime-feature' to nil if the feature
765 (when rmail-enable-mime
767 (require rmail-mime-feature
)
771 (format "Although MIME support is requested
772 by setting `rmail-enable-mime' to non-nil, the required feature
773 `%s' (the value of `rmail-mime-feature')
774 is not available in the current session.
775 So, the MIME support is turned off for the moment."
777 (setq rmail-enable-mime nil
)))))
781 (defun rmail (&optional file-name-arg
)
782 "Read and edit incoming mail.
783 Moves messages into file named by `rmail-file-name' (a babyl format file)
784 and edits that file in RMAIL Mode.
785 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
787 May be called with file name as argument; then performs rmail editing on
788 that file, but does not copy any new mail into the file.
789 Interactively, if you supply a prefix argument, then you
790 have a chance to specify a file name with the minibuffer.
792 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
793 (interactive (if current-prefix-arg
794 (list (read-file-name "Run rmail on RMAIL file: "))))
795 (rmail-require-mime-maybe)
796 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
797 ;; Use find-buffer-visiting, not get-file-buffer, for those users
798 ;; who have find-file-visit-truename set to t.
799 (existed (find-buffer-visiting file-name
))
800 ;; This binding is necessary because we must decide if we
801 ;; need code conversion while the buffer is unibyte
802 ;; (i.e. enable-multibyte-characters is nil).
803 (rmail-enable-multibyte
805 (with-current-buffer existed enable-multibyte-characters
)
806 (default-value 'enable-multibyte-characters
)))
807 ;; Since the file may contain messages of different encodings
808 ;; at the tail (non-BYBYL part), we can't decode them at once
809 ;; on reading. So, at first, we read the file without text
810 ;; code conversion, then decode the messages one by one by
811 ;; rmail-decode-babyl-format or
812 ;; rmail-convert-to-babyl-format.
813 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
814 run-mail-hook msg-shown
)
815 ;; Like find-file, but in the case where a buffer existed
816 ;; and the file was reverted, recompute the message-data.
817 ;; We used to bind enable-local-variables to nil here,
818 ;; but that should not be needed now that rmail-mode
819 ;; sets it locally to nil.
820 ;; (Binding a variable locally with let is not safe if it has
821 ;; buffer-local bindings.)
822 (if (and existed
(not (verify-visited-file-modtime existed
)))
824 (find-file file-name
)
825 (if (and (verify-visited-file-modtime existed
)
826 (eq major-mode
'rmail-mode
))
827 (progn (rmail-forget-messages)
828 (rmail-set-message-counters))))
830 (let ((enable-local-variables nil
))
831 (find-file-noselect file-name
))))
832 (if (eq major-mode
'rmail-edit-mode
)
833 (error "Exit Rmail Edit mode before getting new mail"))
834 (if (and existed
(> (buffer-size) 0))
835 ;; Buffer not new and not empty; ensure in proper mode, but that's all.
836 (or (eq major-mode
'rmail-mode
)
837 (progn (rmail-mode-2)
838 (setq run-mail-hook t
)))
839 (setq run-mail-hook t
)
841 ;; Convert all or part to Babyl file if possible.
843 (goto-char (point-max)))
844 ;; As we have read a file by raw-text, the buffer is set to
845 ;; unibyte. We must make it multibyte if necessary.
846 (if (and rmail-enable-multibyte
847 (not enable-multibyte-characters
))
848 (set-buffer-multibyte t
))
849 ;; If necessary, scan to find all the messages.
850 (rmail-maybe-set-message-counters)
852 (unless (and (not file-name-arg
)
853 (rmail-get-new-mail))
854 (rmail-show-message (rmail-first-unseen-message)))
856 (if rmail-display-summary
(rmail-summary))
857 (rmail-construct-io-menu)
859 (run-hooks 'rmail-mode-hook
))))))
861 ;; Given the value of MAILPATH, return a list of inbox file names.
862 ;; This is turned off because it is not clear that the user wants
863 ;; all these inboxes to feed into the primary rmail file.
864 ; (defun rmail-convert-mailpath (string)
866 ; (while (setq idx (string-match "[%:]" string))
867 ; (let ((this (substring string 0 idx)))
868 ; (setq string (substring string (1+ idx)))
869 ; (setq list (cons (if (string-match "%" this)
870 ; (substring this 0 (string-match "%" this))
875 ; I have checked that adding "-*- rmail -*-" to the BABYL OPTIONS line
876 ; will not cause emacs 18.55 problems.
878 ;; This calls rmail-decode-babyl-format if the file is already Babyl.
880 (defun rmail-convert-file ()
883 (goto-char (point-min))
884 ;; If file doesn't start like a Babyl file,
885 ;; convert it to one, by adding a header and converting each message.
886 (cond ((looking-at "BABYL OPTIONS:"))
887 ((looking-at "Version: 5\n")
888 ;; Losing babyl file made by old version of Rmail.
889 ;; Just fix the babyl file header; don't make a new one,
890 ;; so we don't lose the Labels: file attribute, etc.
891 (let ((buffer-read-only nil
))
892 (insert "BABYL OPTIONS: -*- rmail -*-\n")))
893 ((equal (point-min) (point-max))
894 ;; Empty RMAIL file. Just insert the header.
895 (rmail-insert-rmail-file-header))
897 ;; Non-empty file in non-RMAIL format. Add header and convert.
899 (rmail-insert-rmail-file-header)))
900 ;; If file was not a Babyl file or if there are
901 ;; Unix format messages added at the end,
902 ;; convert file as necessary.
905 (goto-char (point-max))
906 (search-backward "\n\^_")
908 (looking-at "\n*From ")))
909 (let ((buffer-read-only nil
))
910 (message "Converting to Babyl format...")
911 ;; If file needs conversion, convert it all,
912 ;; except for the BABYL header.
913 ;; (rmail-convert-to-babyl-format would delete the header.)
914 (goto-char (point-min))
915 (search-forward "\n\^_" nil t
)
916 (narrow-to-region (point) (point-max))
917 (rmail-convert-to-babyl-format)
918 (message "Converting to Babyl format...done"))
919 (if (and (not rmail-enable-mime
)
920 rmail-enable-multibyte
)
921 ;; We still have to decode BABYL part.
922 (rmail-decode-babyl-format)))))
924 (defun rmail-insert-rmail-file-header ()
925 (let ((buffer-read-only nil
))
926 ;; -*-rmail-*- is here so that visiting the file normally
927 ;; recognizes it as an Rmail file.
928 (insert "BABYL OPTIONS: -*- rmail -*-
931 Note: This is the header of an rmail file.
932 Note: If you are seeing it in rmail,
933 Note: it means the file has no messages in it.\n\^_")))
935 ;; Decode Babyl formatted part at the head of current buffer by
936 ;; rmail-file-coding-system, or if it is nil, do auto conversion.
938 (defun rmail-decode-babyl-format ()
939 (let ((modifiedp (buffer-modified-p))
940 (buffer-read-only nil
)
941 (coding-system rmail-file-coding-system
)
943 (goto-char (point-min))
944 (search-forward "\n\^_" nil t
) ; Skip BABYL header.
946 (goto-char (point-max))
947 (search-backward "\n\^_" from
'mv
)
949 (unless (and coding-system
950 (coding-system-p coding-system
))
952 ;; Emacs 21.1 and later writes RMAIL files in emacs-mule, but
953 ;; earlier versions did that with the current buffer's encoding.
954 ;; So we want to favor detection of emacs-mule (whose normal
955 ;; priority is quite low), but still allow detection of other
956 ;; encodings if emacs-mule won't fit. The call to
957 ;; detect-coding-with-priority below achieves that.
958 (car (detect-coding-with-priority
960 '((coding-category-emacs-mule . emacs-mule
))))))
961 (unless (memq coding-system
962 '(undecided undecided-unix
))
963 (set-buffer-modified-p t
) ; avoid locking when decoding
964 (let ((buffer-undo-list t
))
965 (decode-coding-region from to coding-system
))
966 (setq coding-system last-coding-system-used
))
967 (set-buffer-modified-p modifiedp
)
968 (setq buffer-file-coding-system nil
)
969 (setq save-buffer-coding-system
970 (or coding-system
'undecided
))))
972 (defvar rmail-mode-map nil
)
975 (setq rmail-mode-map
(make-keymap))
976 (suppress-keymap rmail-mode-map
)
977 (define-key rmail-mode-map
"a" 'rmail-add-label
)
978 (define-key rmail-mode-map
"b" 'rmail-bury
)
979 (define-key rmail-mode-map
"c" 'rmail-continue
)
980 (define-key rmail-mode-map
"d" 'rmail-delete-forward
)
981 (define-key rmail-mode-map
"\C-d" 'rmail-delete-backward
)
982 (define-key rmail-mode-map
"e" 'rmail-edit-current-message
)
983 (define-key rmail-mode-map
"f" 'rmail-forward
)
984 (define-key rmail-mode-map
"g" 'rmail-get-new-mail
)
985 (define-key rmail-mode-map
"h" 'rmail-summary
)
986 (define-key rmail-mode-map
"i" 'rmail-input
)
987 (define-key rmail-mode-map
"j" 'rmail-show-message
)
988 (define-key rmail-mode-map
"k" 'rmail-kill-label
)
989 (define-key rmail-mode-map
"l" 'rmail-summary-by-labels
)
990 (define-key rmail-mode-map
"\e\C-h" 'rmail-summary
)
991 (define-key rmail-mode-map
"\e\C-l" 'rmail-summary-by-labels
)
992 (define-key rmail-mode-map
"\e\C-r" 'rmail-summary-by-recipients
)
993 (define-key rmail-mode-map
"\e\C-s" 'rmail-summary-by-regexp
)
994 (define-key rmail-mode-map
"\e\C-t" 'rmail-summary-by-topic
)
995 (define-key rmail-mode-map
"m" 'rmail-mail
)
996 (define-key rmail-mode-map
"\em" 'rmail-retry-failure
)
997 (define-key rmail-mode-map
"n" 'rmail-next-undeleted-message
)
998 (define-key rmail-mode-map
"\en" 'rmail-next-message
)
999 (define-key rmail-mode-map
"\e\C-n" 'rmail-next-labeled-message
)
1000 (define-key rmail-mode-map
"o" 'rmail-output-to-rmail-file
)
1001 (define-key rmail-mode-map
"\C-o" 'rmail-output
)
1002 (define-key rmail-mode-map
"p" 'rmail-previous-undeleted-message
)
1003 (define-key rmail-mode-map
"\ep" 'rmail-previous-message
)
1004 (define-key rmail-mode-map
"\e\C-p" 'rmail-previous-labeled-message
)
1005 (define-key rmail-mode-map
"q" 'rmail-quit
)
1006 (define-key rmail-mode-map
"r" 'rmail-reply
)
1007 ;; I find I can't live without the default M-r command -- rms.
1008 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
1009 (define-key rmail-mode-map
"s" 'rmail-expunge-and-save
)
1010 (define-key rmail-mode-map
"\es" 'rmail-search
)
1011 (define-key rmail-mode-map
"t" 'rmail-toggle-header
)
1012 (define-key rmail-mode-map
"u" 'rmail-undelete-previous-message
)
1013 (define-key rmail-mode-map
"w" 'rmail-output-body-to-file
)
1014 (define-key rmail-mode-map
"x" 'rmail-expunge
)
1015 (define-key rmail-mode-map
"." 'rmail-beginning-of-message
)
1016 (define-key rmail-mode-map
"/" 'rmail-end-of-message
)
1017 (define-key rmail-mode-map
"<" 'rmail-first-message
)
1018 (define-key rmail-mode-map
">" 'rmail-last-message
)
1019 (define-key rmail-mode-map
" " 'scroll-up
)
1020 (define-key rmail-mode-map
"\177" 'scroll-down
)
1021 (define-key rmail-mode-map
"?" 'describe-mode
)
1022 (define-key rmail-mode-map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
1023 (define-key rmail-mode-map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
1024 (define-key rmail-mode-map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
1025 (define-key rmail-mode-map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
1026 (define-key rmail-mode-map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
1027 (define-key rmail-mode-map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
1028 (define-key rmail-mode-map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
1029 (define-key rmail-mode-map
"\C-c\C-n" 'rmail-next-same-subject
)
1030 (define-key rmail-mode-map
"\C-c\C-p" 'rmail-previous-same-subject
)
1033 (define-key rmail-mode-map
[menu-bar
] (make-sparse-keymap))
1035 (define-key rmail-mode-map
[menu-bar classify
]
1036 (cons "Classify" (make-sparse-keymap "Classify")))
1038 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1041 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1044 (define-key rmail-mode-map
[menu-bar classify output-body
]
1045 '("Output body to file..." . rmail-output-body-to-file
))
1047 (define-key rmail-mode-map
[menu-bar classify output-inbox
]
1048 '("Output (inbox)..." . rmail-output
))
1050 (define-key rmail-mode-map
[menu-bar classify output
]
1051 '("Output (Rmail)..." . rmail-output-to-rmail-file
))
1053 (define-key rmail-mode-map
[menu-bar classify kill-label
]
1054 '("Kill Label..." . rmail-kill-label
))
1056 (define-key rmail-mode-map
[menu-bar classify add-label
]
1057 '("Add Label..." . rmail-add-label
))
1059 (define-key rmail-mode-map
[menu-bar summary
]
1060 (cons "Summary" (make-sparse-keymap "Summary")))
1062 (define-key rmail-mode-map
[menu-bar summary senders
]
1063 '("By Senders..." . rmail-summary-by-senders
))
1065 (define-key rmail-mode-map
[menu-bar summary labels
]
1066 '("By Labels..." . rmail-summary-by-labels
))
1068 (define-key rmail-mode-map
[menu-bar summary recipients
]
1069 '("By Recipients..." . rmail-summary-by-recipients
))
1071 (define-key rmail-mode-map
[menu-bar summary topic
]
1072 '("By Topic..." . rmail-summary-by-topic
))
1074 (define-key rmail-mode-map
[menu-bar summary regexp
]
1075 '("By Regexp..." . rmail-summary-by-regexp
))
1077 (define-key rmail-mode-map
[menu-bar summary all
]
1078 '("All" . rmail-summary
))
1080 (define-key rmail-mode-map
[menu-bar mail
]
1081 (cons "Mail" (make-sparse-keymap "Mail")))
1083 (define-key rmail-mode-map
[menu-bar mail rmail-get-new-mail
]
1084 '("Get New Mail" . rmail-get-new-mail
))
1086 (define-key rmail-mode-map
[menu-bar mail lambda
]
1089 (define-key rmail-mode-map
[menu-bar mail continue
]
1090 '("Continue" . rmail-continue
))
1092 (define-key rmail-mode-map
[menu-bar mail resend
]
1093 '("Re-send..." . rmail-resend
))
1095 (define-key rmail-mode-map
[menu-bar mail forward
]
1096 '("Forward" . rmail-forward
))
1098 (define-key rmail-mode-map
[menu-bar mail retry
]
1099 '("Retry" . rmail-retry-failure
))
1101 (define-key rmail-mode-map
[menu-bar mail reply
]
1102 '("Reply" . rmail-reply
))
1104 (define-key rmail-mode-map
[menu-bar mail mail
]
1105 '("Mail" . rmail-mail
))
1107 (define-key rmail-mode-map
[menu-bar delete
]
1108 (cons "Delete" (make-sparse-keymap "Delete")))
1110 (define-key rmail-mode-map
[menu-bar delete expunge
/save
]
1111 '("Expunge/Save" . rmail-expunge-and-save
))
1113 (define-key rmail-mode-map
[menu-bar delete expunge
]
1114 '("Expunge" . rmail-expunge
))
1116 (define-key rmail-mode-map
[menu-bar delete undelete
]
1117 '("Undelete" . rmail-undelete-previous-message
))
1119 (define-key rmail-mode-map
[menu-bar delete delete
]
1120 '("Delete" . rmail-delete-forward
))
1122 (define-key rmail-mode-map
[menu-bar move
]
1123 (cons "Move" (make-sparse-keymap "Move")))
1125 (define-key rmail-mode-map
[menu-bar move search-back
]
1126 '("Search Back..." . rmail-search-backwards
))
1128 (define-key rmail-mode-map
[menu-bar move search
]
1129 '("Search..." . rmail-search
))
1131 (define-key rmail-mode-map
[menu-bar move previous
]
1132 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1134 (define-key rmail-mode-map
[menu-bar move next
]
1135 '("Next Nondeleted" . rmail-next-undeleted-message
))
1137 (define-key rmail-mode-map
[menu-bar move last
]
1138 '("Last" . rmail-last-message
))
1140 (define-key rmail-mode-map
[menu-bar move first
]
1141 '("First" . rmail-first-message
))
1143 (define-key rmail-mode-map
[menu-bar move previous
]
1144 '("Previous" . rmail-previous-message
))
1146 (define-key rmail-mode-map
[menu-bar move next
]
1147 '("Next" . rmail-next-message
))
1150 (defvar rmail-tool-bar-map
1151 (if (display-graphic-p)
1152 (let ((map (make-sparse-keymap)))
1153 (tool-bar-local-item-from-menu 'rmail-get-new-mail
"mail/inbox"
1155 (tool-bar-local-item-from-menu 'rmail-next-undeleted-message
"right-arrow"
1157 (tool-bar-local-item-from-menu 'rmail-previous-undeleted-message
"left-arrow"
1159 (tool-bar-local-item-from-menu 'rmail-search
"search"
1161 (tool-bar-local-item-from-menu 'rmail-input
"open"
1163 (tool-bar-local-item-from-menu 'rmail-mail
"mail/compose"
1165 (tool-bar-local-item-from-menu 'rmail-reply
"mail/reply-all"
1167 (tool-bar-local-item-from-menu 'rmail-forward
"mail/forward"
1169 (tool-bar-local-item-from-menu 'rmail-delete-forward
"close"
1171 (tool-bar-local-item-from-menu 'rmail-output
"mail/move"
1173 (tool-bar-local-item-from-menu 'rmail-output-body-to-file
"mail/save"
1175 (tool-bar-local-item-from-menu 'rmail-expunge
"delete"
1181 ;; Rmail mode is suitable only for specially formatted data.
1182 (put 'rmail-mode
'mode-class
'special
)
1184 (defun rmail-mode-kill-summary ()
1185 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1188 (defun rmail-mode ()
1189 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1190 All normal editing commands are turned off.
1191 Instead, these commands are available:
1193 \\[rmail-beginning-of-message] Move point to front of this message.
1194 \\[rmail-end-of-message] Move point to bottom of this message.
1195 \\[scroll-up] Scroll to next screen of this message.
1196 \\[scroll-down] Scroll to previous screen of this message.
1197 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1198 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1199 \\[rmail-next-message] Move to Next message whether deleted or not.
1200 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1201 \\[rmail-first-message] Move to the first message in Rmail file.
1202 \\[rmail-last-message] Move to the last message in Rmail file.
1203 \\[rmail-show-message] Jump to message specified by numeric position in file.
1204 \\[rmail-search] Search for string and show message it is found in.
1205 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1206 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1207 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1208 till a deleted message is found.
1209 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1210 \\[rmail-expunge] Expunge deleted messages.
1211 \\[rmail-expunge-and-save] Expunge and save the file.
1212 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1213 \\[save-buffer] Save without expunging.
1214 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1215 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1216 \\[rmail-continue] Continue composing outgoing message started before.
1217 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1218 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1219 \\[rmail-forward] Forward this message to another user.
1220 \\[rmail-output-to-rmail-file] Output this message to an Rmail file (append it).
1221 \\[rmail-output] Output this message to a Unix-format mail file (append it).
1222 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1223 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1224 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1225 \\[rmail-kill-label] Kill label. Remove a label from current message.
1226 \\[rmail-next-labeled-message] Move to Next message with specified label
1227 (label defaults to last one specified).
1228 Standard labels: filed, unseen, answered, forwarded, deleted.
1229 Any other label is present only if you add it with \\[rmail-add-label].
1230 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1231 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1232 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1233 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1234 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1235 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1236 \\[rmail-toggle-header] Toggle display of complete header."
1238 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1240 (when (and finding-rmail-file
1241 (null coding-system-for-read
)
1242 default-enable-multibyte-characters
)
1243 (let ((rmail-enable-multibyte t
))
1244 (rmail-require-mime-maybe)
1245 (rmail-convert-file)
1246 (goto-char (point-max))
1247 (set-buffer-multibyte t
)))
1248 (rmail-set-message-counters)
1249 (rmail-show-message rmail-total-messages
)
1250 (when finding-rmail-file
1251 (when rmail-display-summary
1253 (rmail-construct-io-menu))
1254 (run-mode-hooks 'rmail-mode-hook
)))
1256 (defun rmail-mode-2 ()
1257 (kill-all-local-variables)
1259 (rmail-perm-variables)
1262 (defun rmail-mode-1 ()
1263 (setq major-mode
'rmail-mode
)
1264 (setq mode-name
"RMAIL")
1265 (setq buffer-read-only t
)
1266 ;; No need to auto save RMAIL files in normal circumstances
1267 ;; because they contain no info except attribute changes
1268 ;; and deletion of messages.
1269 ;; The one exception is when messages are copied into an Rmail mode buffer.
1270 ;; rmail-output-to-rmail-file enables auto save when you do that.
1271 (setq buffer-auto-save-file-name nil
)
1272 (setq mode-line-modified
"--")
1273 (use-local-map rmail-mode-map
)
1274 (set-syntax-table text-mode-syntax-table
)
1275 (setq local-abbrev-table text-mode-abbrev-table
))
1277 ;; Set up the permanent locals associated with an Rmail file.
1278 (defun rmail-perm-variables ()
1279 (make-local-variable 'rmail-last-label
)
1280 (make-local-variable 'rmail-last-regexp
)
1281 (make-local-variable 'rmail-deleted-vector
)
1282 (make-local-variable 'rmail-buffer
)
1283 (setq rmail-buffer
(current-buffer))
1284 (make-local-variable 'rmail-view-buffer
)
1285 (setq rmail-view-buffer rmail-buffer
)
1286 (make-local-variable 'rmail-summary-buffer
)
1287 (make-local-variable 'rmail-summary-vector
)
1288 (make-local-variable 'rmail-current-message
)
1289 (make-local-variable 'rmail-total-messages
)
1290 (make-local-variable 'rmail-overlay-list
)
1291 (setq rmail-overlay-list nil
)
1292 (make-local-variable 'rmail-message-vector
)
1293 (make-local-variable 'rmail-msgref-vector
)
1294 (make-local-variable 'rmail-inbox-list
)
1295 (setq rmail-inbox-list
(rmail-parse-file-inboxes))
1296 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1297 (and (null rmail-inbox-list
)
1298 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1299 (equal buffer-file-truename
1300 (abbreviate-file-name (file-truename rmail-file-name
))))
1301 (setq rmail-inbox-list
1302 (or rmail-primary-inbox-list
1303 (list (or (getenv "MAIL")
1304 (concat rmail-spool-directory
1305 (user-login-name)))))))
1306 (make-local-variable 'rmail-keywords
)
1307 (set (make-local-variable 'tool-bar-map
) rmail-tool-bar-map
)
1308 ;; this gets generated as needed
1309 (setq rmail-keywords nil
))
1311 ;; Set up the non-permanent locals associated with Rmail mode.
1312 (defun rmail-variables ()
1313 (make-local-variable 'save-buffer-coding-system
)
1314 ;; If we don't already have a value for save-buffer-coding-system,
1315 ;; get it from buffer-file-coding-system, and clear that
1316 ;; because it should be determined in rmail-show-message.
1317 (unless save-buffer-coding-system
1318 (setq save-buffer-coding-system
(or buffer-file-coding-system
'undecided
))
1319 (setq buffer-file-coding-system nil
))
1320 ;; Don't let a local variables list in a message cause confusion.
1321 (make-local-variable 'local-enable-local-variables
)
1322 (setq local-enable-local-variables nil
)
1323 (make-local-variable 'revert-buffer-function
)
1324 (setq revert-buffer-function
'rmail-revert
)
1325 (make-local-variable 'font-lock-defaults
)
1326 (setq font-lock-defaults
1327 '(rmail-font-lock-keywords
1329 (font-lock-maximum-size . nil
)
1330 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1331 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1332 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1333 (make-local-variable 'require-final-newline
)
1334 (setq require-final-newline nil
)
1335 (make-local-variable 'version-control
)
1336 (setq version-control
'never
)
1337 (make-local-variable 'kill-buffer-hook
)
1338 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1339 (make-local-variable 'file-precious-flag
)
1340 (setq file-precious-flag t
)
1341 (make-local-variable 'desktop-save-buffer
)
1342 (setq desktop-save-buffer t
))
1344 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1345 (defun rmail-revert (arg noconfirm
)
1346 (set-buffer rmail-buffer
)
1347 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1348 (rmail-enable-multibyte enable-multibyte-characters
)
1349 ;; See similar code in `rmail'.
1350 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
)))
1351 ;; Call our caller again, but this time it does the default thing.
1352 (if (revert-buffer arg noconfirm
)
1353 ;; If the user said "yes", and we changed something,
1354 ;; reparse the messages.
1356 (set-buffer rmail-buffer
)
1358 ;; Convert all or part to Babyl file if possible.
1359 (rmail-convert-file)
1360 ;; We have read the file as raw-text, so the buffer is set to
1361 ;; unibyte. Make it multibyte if necessary.
1362 (if (and rmail-enable-multibyte
1363 (not enable-multibyte-characters
))
1364 (set-buffer-multibyte t
))
1365 (goto-char (point-max))
1366 (rmail-set-message-counters)
1367 (rmail-show-message rmail-total-messages
)
1368 (run-hooks 'rmail-mode-hook
)))))
1370 ;; Return a list of files from this buffer's Mail: option.
1371 ;; Does not assume that messages have been parsed.
1372 ;; Just returns nil if buffer does not look like Babyl format.
1373 (defun rmail-parse-file-inboxes ()
1378 (cond ((looking-at "BABYL OPTIONS:")
1379 (search-forward "\n\^_" nil
'move
)
1380 (narrow-to-region 1 (point))
1382 (if (search-forward "\nMail:" nil t
)
1384 (narrow-to-region (point) (progn (end-of-line) (point)))
1385 (goto-char (point-min))
1386 (mail-parse-comma-list))))))))
1388 (defun rmail-expunge-and-save ()
1389 "Expunge and save RMAIL file."
1392 (set-buffer rmail-buffer
)
1394 (if (rmail-summary-exists)
1395 (rmail-select-summary (set-buffer-modified-p nil
))))
1397 (defun rmail-quit ()
1399 Hook `rmail-quit-hook' is run after expunging."
1401 (rmail-expunge-and-save)
1402 (when (boundp 'rmail-quit-hook
)
1403 (run-hooks 'rmail-quit-hook
))
1404 ;; Don't switch to the summary buffer even if it was recently visible.
1405 (when rmail-summary-buffer
1406 (replace-buffer-in-windows rmail-summary-buffer
)
1407 (bury-buffer rmail-summary-buffer
))
1408 (if rmail-enable-mime
1409 (let ((obuf rmail-buffer
)
1410 (ovbuf rmail-view-buffer
))
1411 (set-buffer rmail-view-buffer
)
1413 (replace-buffer-in-windows ovbuf
)
1414 (replace-buffer-in-windows obuf
)
1416 (let ((obuf (current-buffer)))
1418 (replace-buffer-in-windows obuf
))))
1420 (defun rmail-bury ()
1421 "Bury current Rmail buffer and its summary buffer."
1423 ;; This let var was called rmail-buffer, but that interfered
1424 ;; with the buffer-local var used in summary buffers.
1425 (let ((buffer-to-bury (current-buffer)))
1426 (if (rmail-summary-exists)
1428 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1429 (quit-window nil window
))
1430 (bury-buffer rmail-summary-buffer
)))
1433 (defun rmail-duplicate-message ()
1434 "Create a duplicated copy of the current message.
1435 The duplicate copy goes into the Rmail file just after the
1439 (let ((buffer-read-only nil
)
1440 (number rmail-current-message
)
1441 (string (buffer-substring (rmail-msgbeg rmail-current-message
)
1442 (rmail-msgend rmail-current-message
))))
1443 (goto-char (rmail-msgend rmail-current-message
))
1445 (rmail-forget-messages)
1446 (rmail-show-message number
)
1447 (message "Message duplicated")))
1450 (defun rmail-input (filename)
1451 "Run Rmail on file FILENAME."
1452 (interactive "FRun rmail on RMAIL file: ")
1456 ;; This used to scan subdirectories recursively, but someone pointed out
1457 ;; that if the user wants that, person can put all the files in one dir.
1458 ;; And the recursive scan was slow. So I took it out.
1460 (defun rmail-find-all-files (start)
1461 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1462 (if (file-accessible-directory-p start
)
1464 (let* ((case-fold-search t
)
1465 (files (directory-files start t rmail-secondary-file-regexp
)))
1466 ;; Sort here instead of in directory-files
1467 ;; because this list is usually much shorter.
1468 (sort files
'string
<))))
1470 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1471 (let ((menu (make-sparse-keymap menu-name
)))
1473 (function (lambda (item)
1478 (rmail-list-to-menu (car item
) (cdr item
)
1481 (concat full-name
"/"
1484 (setq name
(car item
)))
1488 (list 'lambda
() '(interactive)
1492 (concat full-name
"/" item
)
1494 rmail-secondary-file-directory
))))))
1495 (define-key menu
(vector (intern name
))
1496 (cons name command
)))))
1500 ;; This command is always "disabled" when it appears in a menu.
1501 (put 'rmail-disable-menu
'menu-enable
''nil
)
1503 (defun rmail-construct-io-menu ()
1504 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1507 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1508 (cons "Input Rmail File"
1509 (rmail-list-to-menu "Input Rmail File"
1512 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1513 (cons "Output Rmail File"
1514 (rmail-list-to-menu "Output Rmail File"
1516 'rmail-output-to-rmail-file
))))
1518 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1519 '("Input Rmail File" . rmail-disable-menu
))
1520 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1521 '("Output Rmail File" . rmail-disable-menu
)))))
1524 ;;;; *** Rmail input ***
1526 ;; RLK feature not added in this version:
1527 ;; argument specifies inbox file or files in various ways.
1529 (defun rmail-get-new-mail (&optional file-name
)
1530 "Move any new mail from this RMAIL file's inbox files.
1531 The inbox files can be specified with the file's Mail: option. The
1532 variable `rmail-primary-inbox-list' specifies the inboxes for your
1533 primary RMAIL file if it has no Mail: option. By default, this is
1534 your /usr/spool/mail/$USER.
1536 You can also specify the file to get new mail from. In this case, the
1537 file of new mail is not changed or deleted. Noninteractively, you can
1538 pass the inbox file name as an argument. Interactively, a prefix
1539 argument causes us to read a file name and use that file as the inbox.
1541 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1542 always be left in inbox files rather than deleted.
1544 This function runs `rmail-get-new-mail-hook' before saving the updated file.
1545 It returns t if it got any new messages."
1547 (list (if current-prefix-arg
1548 (read-file-name "Get new mail from file: "))))
1549 (run-hooks 'rmail-before-get-new-mail-hook
)
1550 ;; If the disk file has been changed from under us,
1551 ;; revert to it before we get new mail.
1552 (or (verify-visited-file-modtime (current-buffer))
1553 (find-file (buffer-file-name)))
1554 (set-buffer rmail-buffer
)
1555 (rmail-maybe-set-message-counters)
1557 ;; Get rid of all undo records for this buffer.
1558 (or (eq buffer-undo-list t
)
1559 (setq buffer-undo-list nil
))
1560 (let ((all-files (if file-name
(list file-name
)
1562 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1567 (let ((opoint (point))
1569 (rsf-number-of-spam 0)
1571 ;; If buffer has not changed yet, and has not been saved yet,
1572 ;; don't replace the old backup file now.
1573 (make-backup-files (and make-backup-files
(buffer-modified-p)))
1574 (buffer-read-only nil
)
1575 ;; Don't make undo records for what we do in getting mail.
1576 (buffer-undo-list t
)
1578 ;; Files to insert this time around.
1580 ;; Last names of those files.
1582 ;; Pull files off all-files onto files
1583 ;; as long as there is no name conflict.
1584 ;; A conflict happens when two inbox file names
1585 ;; have the same last component.
1586 (while (and all-files
1587 (not (member (file-name-nondirectory (car all-files
))
1589 (setq files
(cons (car all-files
) files
)
1591 (cons (file-name-nondirectory (car all-files
)) files
))
1592 (setq all-files
(cdr all-files
)))
1593 ;; Put them back in their original order.
1594 (setq files
(nreverse files
))
1596 (goto-char (point-max))
1597 (skip-chars-backward " \t\n") ; just in case of brain damage
1598 (delete-region (point) (point-max)) ; caused by require-final-newline
1601 (narrow-to-region (point) (point))
1602 ;; Read in the contents of the inbox files,
1603 ;; renaming them as necessary,
1604 ;; and adding to the list of files to delete eventually.
1606 (rmail-insert-inbox-text files nil
)
1607 (setq delete-files
(rmail-insert-inbox-text files t
)))
1608 ;; Scan the new text and convert each message to babyl format.
1609 (goto-char (point-min))
1612 (setq new-messages
(rmail-convert-to-babyl-format)
1614 ;; Try to delete the garbage just inserted.
1615 (or success
(delete-region (point-min) (point-max)))
1616 ;; If we could not convert the file's inboxes,
1617 ;; rename the files we tried to read
1618 ;; so we won't over and over again.
1619 (if (and (not file-name
) (not success
))
1620 (let ((delfiles delete-files
)
1623 (while (file-exists-p (format "RMAILOSE.%d" count
))
1624 (setq count
(1+ count
)))
1625 (rename-file (car delfiles
)
1626 (format "RMAILOSE.%d" count
))
1627 (setq delfiles
(cdr delfiles
))))))
1628 (or (zerop new-messages
)
1631 (search-backward "\n\^_" nil t
)
1632 (narrow-to-region (point) (point-max))
1633 (goto-char (1+ (point-min)))
1634 (rmail-count-new-messages)
1635 (run-hooks 'rmail-get-new-mail-hook
)
1637 ;; Delete the old files, now that babyl file is saved.
1640 ;; First, try deleting.
1642 (delete-file (car delete-files
))
1644 ;; If we can't delete it, truncate it.
1645 (write-region (point) (point) (car delete-files
))))
1647 (setq delete-files
(cdr delete-files
)))))
1648 (if (= new-messages
0)
1649 (progn (goto-char opoint
)
1650 (if (or file-name rmail-inbox-list
)
1651 (message "(No new mail has arrived)")))
1652 ;; check new messages to see if any of them is spam:
1653 (if (and (featurep 'rmail-spam-filter
)
1654 rmail-use-spam-filter
)
1656 ((old-messages (- rmail-total-messages new-messages
))
1657 (rsf-scanned-message-number (1+ old-messages
))
1658 ;; save deletion flags of old messages: vector starts
1659 ;; at zero (is one longer that no of messages),
1660 ;; therefore take 1+ old-messages
1662 (substring rmail-deleted-vector
0 (1+
1664 ;; set all messages to undeleted
1665 (setq rmail-deleted-vector
1666 (make-string (1+ rmail-total-messages
) ?\
))
1667 (while (<= rsf-scanned-message-number
1668 rmail-total-messages
)
1670 (if (not (rmail-spam-filter rsf-scanned-message-number
))
1671 (progn (setq rsf-number-of-spam
(1+ rsf-number-of-spam
)))
1673 (setq rsf-scanned-message-number
(1+ rsf-scanned-message-number
))
1675 (if (> rsf-number-of-spam
0)
1677 (when (rmail-expunge-confirmed)
1678 (rmail-only-expunge t
))
1680 (setq rmail-deleted-vector
1683 (make-string (- rmail-total-messages old-messages
)
1686 (if (rmail-summary-exists)
1687 (rmail-select-summary
1688 (rmail-update-summary)))
1689 (message "%d new message%s read%s"
1690 new-messages
(if (= 1 new-messages
) "" "s")
1691 ;; print out a message on number of spam messages found:
1692 (if (and (featurep 'rmail-spam-filter
)
1693 rmail-use-spam-filter
1694 (> rsf-number-of-spam
0))
1695 (cond ((= 1 new-messages
)
1696 ", and appears to be spam")
1697 ((= rsf-number-of-spam new-messages
)
1698 ", and all appear to be spam")
1699 ((> rsf-number-of-spam
1)
1700 (format ", and %d appear to be spam"
1701 rsf-number-of-spam
))
1703 ", and 1 appears to be spam"))
1705 (if (and (featurep 'rmail-spam-filter
)
1706 rmail-use-spam-filter
1707 (> rsf-number-of-spam
0))
1708 (progn (if rsf-beep
(beep t
))
1709 (sleep-for rsf-sleep-after-message
)))
1711 ;; Move to the first new message
1712 ;; unless we have other unseen messages before it.
1713 (rmail-show-message (rmail-first-unseen-message))
1714 (run-hooks 'rmail-after-get-new-mail-hook
)
1717 ;; Don't leave the buffer screwed up if we get a disk-full error.
1718 (or found
(rmail-show-message)))))
1720 (defun rmail-parse-url (file)
1721 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1722 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1723 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1724 a remote mailbox, PASSWORD is the password if it should be
1725 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1726 is non-nil if the user has supplied the password interactively.
1729 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1730 (let (got-password supplied-password
1731 (proto (match-string 1 file
))
1732 (user (match-string 3 file
))
1733 (pass (match-string 5 file
))
1734 (host (substring file
(or (match-end 2)
1735 (+ 3 (match-end 1))))))
1738 (when rmail-remote-password-required
1739 (setq got-password
(not (rmail-have-password)))
1740 (setq supplied-password
(rmail-get-remote-password
1741 (string-equal proto
"imap")))))
1743 (if (rmail-movemail-variant-p 'emacs
)
1744 (if (string-equal proto
"pop")
1745 (list (concat "po:" user
":" host
)
1747 (or pass supplied-password
)
1749 (error "Emacs movemail does not support %s protocol" proto
))
1751 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1755 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1756 (let (got-password supplied-password
1758 (user (match-string 1 file
))
1759 (host (match-string 3 file
)))
1761 (when rmail-remote-password-required
1762 (setq got-password
(not (rmail-have-password)))
1763 (setq supplied-password
(rmail-get-remote-password nil
)))
1765 (list file
"pop" supplied-password got-password
)))
1768 (list file nil nil nil
))))
1770 (defun rmail-insert-inbox-text (files renamep
)
1771 ;; Detect a locked file now, so that we avoid moving mail
1772 ;; out of the real inbox file. (That could scare people.)
1773 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1774 (error "RMAIL file %s is locked"
1775 (file-name-nondirectory buffer-file-name
)))
1776 (let (file tofile delete-files movemail popmail got-password password
)
1778 ;; Handle remote mailbox names specially; don't expand as filenames
1779 ;; in case the userid contains a directory separator.
1780 (setq file
(car files
))
1781 (let ((url-data (rmail-parse-url file
)))
1782 (setq file
(nth 0 url-data
))
1783 (setq popmail
(nth 1 url-data
))
1784 (setq password
(nth 2 url-data
))
1785 (setq got-password
(nth 3 url-data
)))
1789 (setq file
(file-truename
1790 (substitute-in-file-name (expand-file-name file
)))))
1791 (setq tofile
(expand-file-name
1792 ;; Generate name to move to from inbox name,
1793 ;; in case of multiple inboxes that need moving.
1795 (file-name-nondirectory
1796 (if (memq system-type
'(windows-nt cygwin
))
1797 ;; cannot have "po:" in file name
1800 ;; Use the directory of this rmail file
1801 ;; because it's a nuisance to use the homedir
1802 ;; if that is on a full disk and this rmail
1804 (file-name-directory
1805 (expand-file-name buffer-file-name
))))
1806 ;; Always use movemail to rename the file,
1807 ;; since there can be mailboxes in various directories.
1810 ;; On some systems, /usr/spool/mail/foo is a directory
1811 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1812 (if (file-directory-p file
)
1813 (setq file
(expand-file-name (user-login-name)
1816 (message "Getting mail from the remote server ..."))
1817 ((and (file-exists-p tofile
)
1818 (/= 0 (nth 7 (file-attributes tofile
))))
1819 (message "Getting mail from %s..." tofile
))
1820 ((and (file-exists-p file
)
1821 (/= 0 (nth 7 (file-attributes file
))))
1822 (message "Getting mail from %s..." file
)))
1823 ;; Set TOFILE if have not already done so, and
1824 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1825 (cond ((not renamep
)
1827 ((or (file-exists-p tofile
) (and (not popmail
)
1828 (not (file-exists-p file
))))
1832 (let ((errors (current-buffer)))
1833 (buffer-disable-undo errors
)
1836 (list rmail-movemail-program nil errors nil
)
1837 (if rmail-preserve-inbox
1840 (if (rmail-movemail-variant-p 'mailutils
)
1841 (append (list "--emacs") rmail-movemail-flags
)
1842 rmail-movemail-flags
)
1844 (if password
(list password
) nil
))))
1845 (apply 'call-process args
))
1846 (if (not (buffer-modified-p errors
))
1847 ;; No output => movemail won
1850 (subst-char-in-region (point-min) (point-max)
1852 (goto-char (point-max))
1853 (skip-chars-backward " \t")
1854 (delete-region (point) (point-max))
1855 (goto-char (point-min))
1856 (if (looking-at "movemail: ")
1857 (delete-region (point-min) (match-end 0)))
1859 ;; If we just read the password, most likely it is
1860 ;; wrong. Otherwise, see if there is a specific
1861 ;; reason to think that the problem is a wrong passwd.
1862 (if (or got-password
1863 (re-search-forward rmail-remote-password-error
1865 (rmail-set-remote-password nil
))
1867 ;; If using Mailutils, remove initial error code
1869 (when (rmail-movemail-variant-p 'mailutils
)
1870 (goto-char (point-min))
1871 (when (looking-at "[A-Z][A-Z0-9_]*:")
1872 (delete-region (point-min) (match-end 0))))
1874 (message "movemail: %s"
1875 (buffer-substring (point-min)
1881 ;; At this point, TOFILE contains the name to read:
1882 ;; Either the alternate name (if we renamed)
1883 ;; or the actual inbox (if not renaming).
1884 (if (file-exists-p tofile
)
1885 (let ((coding-system-for-read 'no-conversion
)
1887 (goto-char (point-max))
1888 (setq size
(nth 1 (insert-file-contents tofile
)))
1889 (goto-char (point-max))
1890 (or (= (preceding-char) ?
\n)
1893 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
1894 (setq delete-files
(cons tofile delete-files
)))))
1896 (setq files
(cdr files
)))
1899 ;; Decode the region specified by FROM and TO by CODING.
1900 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1901 (defun rmail-decode-region (from to coding
)
1902 (if (or (not coding
) (not (coding-system-p coding
)))
1903 (setq coding
'undecided
))
1904 ;; Use -dos decoding, to remove ^M characters left from base64 or
1905 ;; rogue qp-encoded text.
1906 (decode-coding-region from to
1907 (coding-system-change-eol-conversion coding
1))
1908 ;; Don't reveal the fact we used -dos decoding, as users generally
1909 ;; will not expect the RMAIL buffer to use DOS EOL format.
1910 (setq buffer-file-coding-system
1911 (setq last-coding-system-used
1912 (coding-system-change-eol-conversion coding
0))))
1914 ;; the rmail-break-forwarded-messages feature is not implemented
1915 (defun rmail-convert-to-babyl-format ()
1916 (let ((count 0) start
1917 (case-fold-search nil
)
1918 (buffer-undo-list t
)
1919 (invalid-input-resync
1920 (function (lambda ()
1921 (message "Invalid Babyl format in inbox!")
1923 ;; Try to get back in sync with a real message.
1924 (if (re-search-forward
1925 (concat rmail-mmdf-delim1
"\\|^From") nil t
)
1927 (goto-char (point-max)))))))
1928 (goto-char (point-min))
1931 (setq start
(point))
1932 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1933 (if (search-forward "\n\^_" nil t
)
1934 ;; If we find the proper terminator, delete through there.
1935 (delete-region (point-min) (point))
1936 (funcall invalid-input-resync
)
1937 (delete-region (point-min) (point))))
1938 ;; Babyl format message
1940 (or (search-forward "\n\^_" nil t
)
1941 (funcall invalid-input-resync
))
1942 (setq count
(1+ count
))
1943 ;; Make sure there is no extra white space after the ^_
1944 ;; at the end of the message.
1945 ;; Narrowing will make sure that whatever follows the junk
1946 ;; will be treated properly.
1947 (delete-region (point)
1949 (skip-chars-forward " \t\n")
1957 (if (looking-at "0")
1961 (narrow-to-region (point) (point-max))
1964 (case-fold-search t
)
1965 (quoted-printable-header-field-end
1969 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
1971 (base64-header-field-end
1974 ;; Don't try to decode non-text data.
1975 (and (re-search-forward
1976 "^content-type:\\(\n?[\t ]\\)\\(text\\|message\\)/"
1980 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
1982 (if quoted-printable-header-field-end
1985 (mail-unquote-printable-region header-end
(point) nil t t
)
1986 (message "Malformed MIME quoted-printable message"))
1987 ;; Change "quoted-printable" to "8bit",
1988 ;; to reflect the decoding we just did.
1989 (goto-char quoted-printable-header-field-end
)
1990 (delete-region (point) (search-backward ":"))
1992 (if base64-header-field-end
1997 (base64-decode-region (1+ header-end
)
2001 ;; Change "base64" to "8bit", to reflect the
2002 ;; decoding we just did.
2003 (goto-char base64-header-field-end
)
2004 (delete-region (point) (search-backward ":"))
2005 (insert ": 8bit"))))
2006 (setq last-coding-system-used nil
)
2007 (or rmail-enable-mime
2008 (not rmail-enable-multibyte
)
2010 (if (and rmail-decode-mime-charset
2013 (search-forward "\n\n" nil t
)
2014 (let ((case-fold-search t
))
2016 rmail-mime-charset-pattern
2018 (intern (downcase (match-string 1))))))
2019 (rmail-decode-region start
(point) mime-charset
)))))
2020 ;; Add an X-Coding-System: header if we don't have one.
2024 (if (looking-at "0")
2027 (or (save-restriction
2028 (narrow-to-region (point) (point-max))
2030 (goto-char (point-min))
2031 (re-search-forward "^X-Coding-System:" nil t
))
2032 (insert "X-Coding-System: "
2033 (symbol-name last-coding-system-used
)
2035 (narrow-to-region (point) (point-max))
2036 (and (= 0 (% count
10))
2037 (message "Converting to Babyl format...%d" count
)))
2039 ((let ((case-fold-search t
))
2040 (looking-at rmail-mmdf-delim1
))
2041 (let ((case-fold-search t
))
2042 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
2043 (re-search-forward rmail-mmdf-delim2 nil t
)
2044 (replace-match "\^_"))
2047 (narrow-to-region start
(1- (point)))
2048 (goto-char (point-min))
2049 (while (search-forward "\n\^_" nil t
); single char "\^_"
2050 (replace-match "\n^_")))); 2 chars: "^" and "_"
2051 (setq last-coding-system-used nil
)
2052 (or rmail-enable-mime
2053 (not rmail-enable-multibyte
)
2054 (decode-coding-region start
(point) 'undecided
))
2058 (insert "X-Coding-System: "
2059 (symbol-name last-coding-system-used
)
2061 (narrow-to-region (point) (point-max))
2062 (setq count
(1+ count
))
2063 (and (= 0 (% count
10))
2064 (message "Converting to Babyl format...%d" count
)))
2066 ((looking-at "^From ")
2067 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
2068 (rmail-nuke-pinhead-header)
2069 ;; If this message has a Content-Length field,
2070 ;; skip to the end of the contents.
2071 (let* ((header-end (save-excursion
2072 (and (re-search-forward "\n\n" nil t
)
2074 (case-fold-search t
)
2075 (quoted-printable-header-field-end
2078 "^content-transfer-encoding:\\(\n?[\t ]\\)*quoted-printable\\(\n?[\t ]\\)*"
2080 (base64-header-field-end
2082 ;; Don't decode non-text data.
2085 "^content-type:\\(\n?[\t ]\\)\\(text\\|message\\)/"
2089 "^content-transfer-encoding:\\(\n?[\t ]\\)*base64\\(\n?[\t ]\\)*"
2092 ;; Get the numeric value from the Content-Length field.
2094 ;; Back up to end of prev line,
2095 ;; in case the Content-Length field comes first.
2097 (and (search-forward "\ncontent-length: "
2100 (eol (progn (end-of-line) (point))))
2101 (string-to-number (buffer-substring beg eol
)))))))
2103 (if (and (natnump size
)
2104 (<= (+ header-end size
) (point-max))
2105 ;; Make sure this would put us at a position
2106 ;; that we could continue from.
2108 (goto-char (+ header-end size
))
2109 (skip-chars-forward "\n")
2111 (and (looking-at "BABYL OPTIONS:")
2112 (search-forward "\n\^_" nil t
))
2113 (and (looking-at "\^L")
2114 (search-forward "\n\^_" nil t
))
2115 (let ((case-fold-search t
))
2116 (looking-at rmail-mmdf-delim1
))
2117 (looking-at "From "))))
2118 (goto-char (+ header-end size
))
2119 (message "Ignoring invalid Content-Length field")
2121 (if (let ((case-fold-search nil
))
2123 (concat "^[\^_]?\\("
2124 rmail-unix-mail-delimiter
2126 rmail-mmdf-delim1
"\\|"
2127 "^BABYL OPTIONS:\\|"
2128 "\^L\n[01],\\)") nil t
))
2129 (goto-char (match-beginning 1))
2130 (goto-char (point-max)))
2131 (setq count
(1+ count
))
2132 (if quoted-printable-header-field-end
2135 (mail-unquote-printable-region header-end
(point) nil t t
)
2136 (message "Malformed MIME quoted-printable message"))
2137 ;; Change "quoted-printable" to "8bit",
2138 ;; to reflect the decoding we just did.
2139 (goto-char quoted-printable-header-field-end
)
2140 (delete-region (point) (search-backward ":"))
2142 (if base64-header-field-end
2147 (base64-decode-region
2150 ;; Prevent base64-decode-region
2151 ;; from removing newline characters.
2152 (skip-chars-backward "\n\t ")
2156 ;; Change "base64" to "8bit", to reflect the
2157 ;; decoding we just did.
2158 (goto-char base64-header-field-end
)
2159 (delete-region (point) (search-backward ":"))
2160 (insert ": 8bit")))))
2164 (narrow-to-region start
(point))
2165 (goto-char (point-min))
2166 (while (search-forward "\n\^_" nil t
); single char
2167 (replace-match "\n^_")))); 2 chars: "^" and "_"
2168 ;; This is for malformed messages that don't end in newline.
2169 ;; There shouldn't be any, but some users say occasionally
2171 (or (bolp) (newline))
2173 (setq last-coding-system-used nil
)
2174 (or rmail-enable-mime
2175 (not rmail-enable-multibyte
)
2177 (if (and rmail-decode-mime-charset
2180 (search-forward "\n\n" nil t
)
2181 (let ((case-fold-search t
))
2183 rmail-mime-charset-pattern
2185 (intern (downcase (match-string 1))))))
2186 (rmail-decode-region start
(point) mime-charset
)))
2190 (insert "X-Coding-System: "
2191 (symbol-name last-coding-system-used
)
2193 (narrow-to-region (point) (point-max))
2194 (and (= 0 (% count
10))
2195 (message "Converting to Babyl format...%d" count
)))
2197 ;; This kludge is because some versions of sendmail.el
2198 ;; insert an extra newline at the beginning that shouldn't
2199 ;; be there. sendmail.el has been fixed, but old versions
2200 ;; may still be in use. -- rms, 7 May 1993.
2201 ((eolp) (delete-char 1))
2202 (t (error "Cannot convert to babyl format")))))
2203 (setq buffer-undo-list nil
)
2206 ;; Delete the "From ..." line, creating various other headers with
2207 ;; information from it if they don't already exist. Now puts the
2208 ;; original line into a mail-from: header line for debugging and for
2209 ;; use by the rmail-output function.
2210 (defun rmail-nuke-pinhead-header ()
2213 (let ((start (point))
2216 (search-forward "\n\n")
2218 (goto-char (point-max))
2222 (narrow-to-region start end
)
2223 (let ((case-fold-search t
))
2225 (setq has-from
(search-forward "\nFrom:" nil t
))
2227 (setq has-date
(and (search-forward "\nDate:" nil t
) (point)))
2229 (let ((case-fold-search nil
))
2230 (if (re-search-forward (concat "^" rmail-unix-mail-delimiter
) nil t
)
2234 ;; Keep and reformat the date if we don't
2235 ;; have a Date: field.
2239 "Date: \\2, \\4 \\3 \\9 \\5 "
2241 ;; The timezone could be matched by group 7 or group 10.
2242 ;; If neither of them matched, assume EST, since only
2243 ;; Easterners would be so sloppy.
2244 ;; It's a shame the substitution can't use "\\10".
2246 ((/= (match-beginning 7) (match-end 7)) "\\7")
2247 ((/= (match-beginning 10) (match-end 10))
2248 (buffer-substring (match-beginning 10)
2252 ;; Keep and reformat the sender if we don't
2253 ;; have a From: field.
2259 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2261 (defun rmail-reformat-message (beg end
)
2264 (if (/= (following-char) ?
0)
2265 (error "Bad format in RMAIL file"))
2266 (let ((inhibit-read-only t
)
2267 (delta (- (buffer-size) end
)))
2271 (let ((case-fold-search t
))
2272 (while (looking-at "Summary-line:\\|Mail-From:")
2274 (if (looking-at "\\*\\*\\* EOOH \\*\\*\\*\n")
2275 (delete-region (point)
2276 (progn (forward-line 1) (point))))
2277 (let ((str (buffer-substring (point)
2278 (save-excursion (search-forward "\n\n" end
'move
)
2280 (insert str
"*** EOOH ***\n")
2281 (narrow-to-region (point) (- (buffer-size) delta
)))
2282 (goto-char (point-min))
2283 (if rmail-message-filter
(funcall rmail-message-filter
))
2284 (if (or rmail-displayed-headers rmail-ignored-headers
)
2285 (rmail-clear-headers))))
2287 (defun rmail-clear-headers (&optional ignored-headers
)
2288 "Delete all header fields that Rmail should not show.
2289 If the optional argument IGNORED-HEADERS is non-nil,
2290 delete all header fields whose names match that regexp.
2291 Otherwise, if `rmail-displayed-headers' is non-nil,
2292 delete all header fields *except* those whose names match that regexp.
2293 Otherwise, delete all header fields whose names match `rmail-ignored-headers'
2294 unless they also match `rmail-nonignored-headers'."
2295 (when (search-forward "\n\n" nil t
)
2297 (let ((case-fold-search t
)
2298 (buffer-read-only nil
))
2299 (if (and rmail-displayed-headers
(null ignored-headers
))
2301 (narrow-to-region (point-min) (point))
2303 (goto-char (point-min))
2304 (while (and (not (eobp))
2306 (if (re-search-forward "\n[^ \t]" nil t
)
2307 (setq lim
(match-beginning 0)
2309 (setq lim nil next
(point-max)))))
2311 (re-search-forward rmail-displayed-headers lim t
))
2313 (delete-region (point) next
))))
2314 (goto-char (point-min)))
2315 (or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2317 (narrow-to-region (point-min) (point))
2318 (goto-char (point-min))
2319 (while (and ignored-headers
2320 (re-search-forward ignored-headers nil t
))
2322 (if (looking-at rmail-nonignored-headers
)
2324 (delete-region (point)
2326 (if (re-search-forward "\n[^ \t]" nil t
)
2328 (point-max)))))))))))
2330 (defun rmail-msg-is-pruned ()
2331 (rmail-maybe-set-message-counters)
2333 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2335 (goto-char (point-min))
2337 (= (following-char) ?
1))))
2339 (defun rmail-msg-restore-non-pruned-header ()
2340 (let ((old-point (point))
2343 (inhibit-read-only t
))
2345 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2346 (goto-char (point-min))
2351 ;; Insert new EOOH line at the proper place.
2353 (let ((case-fold-search t
))
2354 (while (looking-at "Summary-Line:\\|Mail-From:")
2356 (insert "*** EOOH ***\n")
2357 (setq new-start
(point))
2358 ;; Delete the old reformatted header.
2360 (search-forward "\n*** EOOH ***\n")
2362 (let ((start (point)))
2363 (search-forward "\n\n")
2364 (if (and (<= start old-point
)
2365 (<= old-point
(point)))
2366 (setq new-point new-start
))
2367 (delete-region start
(point)))
2368 ;; Narrow to after the new EOOH line.
2369 (narrow-to-region new-start
(point-max)))
2371 (goto-char new-point
))))
2373 (defun rmail-msg-prune-header ()
2375 (= (point) (point-min))))
2377 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2378 (rmail-reformat-message (point-min) (point-max)))
2380 (goto-char (point-min)))))
2382 (defun rmail-toggle-header (&optional arg
)
2383 "Show original message header if pruned header currently shown, or vice versa.
2384 With argument ARG, show the message header pruned if ARG is greater than zero;
2385 otherwise, show it in full."
2387 (let* ((pruned (with-current-buffer rmail-buffer
2388 (rmail-msg-is-pruned)))
2390 (> (prefix-numeric-value arg
) 0)
2392 (if (eq pruned prune
)
2394 (set-buffer rmail-buffer
)
2395 (rmail-maybe-set-message-counters)
2396 (if rmail-enable-mime
2397 (let ((buffer-read-only nil
))
2399 (rmail-msg-restore-non-pruned-header)
2400 (rmail-msg-prune-header))
2401 (funcall rmail-show-mime-function
))
2402 (let* ((buffer-read-only nil
)
2403 (window (get-buffer-window (current-buffer)))
2404 (at-point-min (= (point) (point-min)))
2405 (all-headers-visible (= (window-start window
) (point-min)))
2408 (and (not (search-backward "\n\n" nil t
))
2411 (re-search-backward "^[-A-Za-z0-9]+:" nil t
))
2414 (rmail-count-screen-lines (window-start window
) (point))))
2416 (rmail-msg-restore-non-pruned-header)
2417 (rmail-msg-prune-header))
2419 (goto-char (point-min)))
2421 (goto-char (point-min))
2422 (search-forward "\n\n")
2423 (or (re-search-backward
2424 (concat "^" (regexp-quote on-header
)) nil t
)
2425 (goto-char (point-min))))
2427 (save-selected-window
2428 (select-window window
)
2429 (recenter old-screen-line
)
2430 (if (and all-headers-visible
2431 (not (= (window-start) (point-min))))
2432 (recenter (- (window-height) 2))))))))
2433 (rmail-highlight-headers))))
2435 (defun rmail-narrow-to-non-pruned-header ()
2436 "Narrow to the whole (original) header of the current message."
2438 (narrow-to-region (rmail-msgbeg rmail-current-message
) (point-max))
2439 (goto-char (point-min))
2441 (if (= (following-char) ?
1)
2444 (setq start
(point))
2445 (search-forward "*** EOOH ***\n")
2446 (setq end
(match-beginning 0)))
2448 (setq start
(point))
2449 (search-forward "\n\n")
2450 (setq end
(1- (point))))
2451 (narrow-to-region start end
)
2454 ;; Lifted from repos-count-screen-lines.
2455 ;; Return number of screen lines between START and END.
2456 (defun rmail-count-screen-lines (start end
)
2459 (narrow-to-region start end
)
2460 (goto-char (point-min))
2461 (vertical-motion (- (point-max) (point-min))))))
2463 ;;;; *** Rmail Attributes and Keywords ***
2465 ;; Make a string describing current message's attributes and keywords
2466 ;; and set it up as the name of a minor mode
2467 ;; so it will appear in the mode line.
2468 (defun rmail-display-labels ()
2469 (let ((blurb "") (beg (point-min-marker)) (end (point-max-marker)))
2474 (goto-char (rmail-msgbeg rmail-current-message
))
2476 (if (looking-at "[01],")
2478 (narrow-to-region (point) (progn (end-of-line) (point)))
2479 ;; Truly valid BABYL format requires a space before each
2480 ;; attribute or keyword name. Put them in if missing.
2481 (let (buffer-read-only)
2482 (goto-char (point-min))
2483 (while (search-forward "," nil t
)
2484 (or (looking-at "[ ,]") (eobp)
2486 (goto-char (point-max))
2487 (if (search-backward ",," nil
'move
)
2489 (if (> (point) (1+ (point-min)))
2490 (setq blurb
(buffer-substring (+ 1 (point-min)) (point))))
2491 (if (> (- (point-max) (point)) 2)
2495 (buffer-substring (+ (point) 3)
2496 (1- (point-max)))))))))))
2497 ;; Note: we don't use save-restriction because that does not work right
2498 ;; if changes are made outside the saved restriction
2499 ;; before that restriction is restored.
2500 (narrow-to-region beg end
)
2501 (set-marker beg nil
)
2502 (set-marker end nil
)))
2503 (while (string-match " +," blurb
)
2504 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2505 (substring blurb
(match-end 0)))))
2506 (while (string-match ", +" blurb
)
2507 (setq blurb
(concat (substring blurb
0 (match-beginning 0)) ","
2508 (substring blurb
(match-end 0)))))
2509 (setq mode-line-process
2511 rmail-current-message rmail-total-messages blurb
))
2512 ;; If rmail-enable-mime is non-nil, we may have to update
2513 ;; `mode-line-process' of rmail-view-buffer too.
2514 (if (and rmail-enable-mime
2515 (not (eq (current-buffer) rmail-view-buffer
))
2516 (buffer-live-p rmail-view-buffer
))
2517 (let ((mlp mode-line-process
))
2518 (with-current-buffer rmail-view-buffer
2519 (setq mode-line-process mlp
))))))
2521 ;; Turn an attribute of a message on or off according to STATE.
2522 ;; ATTR is the name of the attribute, as a string.
2523 ;; MSGNUM is message number to change; nil means current message.
2524 (defun rmail-set-attribute (attr state
&optional msgnum
)
2525 (set-buffer rmail-buffer
)
2526 (let ((omax (point-max-marker))
2527 (omin (point-min-marker))
2528 (buffer-read-only nil
))
2529 (or msgnum
(setq msgnum rmail-current-message
))
2534 (goto-char (+ 3 (rmail-msgbeg msgnum
)))
2537 (null (search-backward (concat ", " attr
",")
2538 (prog1 (point) (end-of-line)) t
)))))
2539 (or (eq curstate
(not (not state
)))
2541 (delete-region (point) (1- (match-end 0)))
2544 (insert " " attr
","))))
2545 (if (string= attr
"deleted")
2546 (rmail-set-message-deleted-p msgnum state
)))
2547 ;; Note: we don't use save-restriction because that does not work right
2548 ;; if changes are made outside the saved restriction
2549 ;; before that restriction is restored.
2550 (narrow-to-region omin omax
)
2551 (set-marker omin nil
)
2552 (set-marker omax nil
)
2553 (if (= msgnum rmail-current-message
)
2554 (rmail-display-labels))))))
2556 ;; Return t if the attributes/keywords line of msg number MSG
2557 ;; contains a match for the regexp LABELS.
2558 (defun rmail-message-labels-p (msg labels
)
2562 (goto-char (rmail-msgbeg msg
))
2564 (re-search-backward labels
(prog1 (point) (end-of-line)) t
))))
2566 ;;;; *** Rmail Message Selection And Support ***
2568 (defun rmail-msgend (n)
2569 (marker-position (aref rmail-message-vector
(1+ n
))))
2571 (defun rmail-msgbeg (n)
2572 (marker-position (aref rmail-message-vector n
)))
2574 (defun rmail-widen-to-current-msgbeg (function)
2575 "Call FUNCTION with point at start of internal data of current message.
2576 Assumes that bounds were previously narrowed to display the message in Rmail.
2577 The bounds are widened enough to move point where desired, then narrowed
2580 FUNCTION may not change the visible text of the message, but it may
2581 change the invisible header text."
2585 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2587 (goto-char (point-min))
2589 ;; Note: we don't use save-restriction because that does not work right
2590 ;; if changes are made outside the saved restriction
2591 ;; before that restriction is restored.
2592 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2593 (rmail-msgend rmail-current-message
)))))
2595 (defun rmail-forget-messages ()
2597 (if (vectorp rmail-message-vector
)
2599 (v rmail-message-vector
)
2602 (move-marker (aref v i
) nil
)
2604 (setq rmail-message-vector nil
)
2605 (setq rmail-msgref-vector nil
)
2606 (setq rmail-deleted-vector nil
)))
2608 (defun rmail-maybe-set-message-counters ()
2609 (if (not (and rmail-deleted-vector
2610 rmail-message-vector
2611 rmail-current-message
2612 rmail-total-messages
))
2613 (rmail-set-message-counters)))
2615 (defun rmail-count-new-messages (&optional nomsg
)
2616 (let* ((case-fold-search nil
)
2620 (or nomsg
(message "Counting new messages..."))
2621 (goto-char (point-max))
2622 ;; Put at the end of messages-head
2623 ;; the entry for message N+1, which marks
2624 ;; the end of message N. (N = number of messages).
2625 (search-backward "\n\^_")
2627 (setq messages-head
(list (point-marker)))
2628 (rmail-set-message-counters-counter (point-min))
2629 (setq rmail-current-message
(1+ rmail-total-messages
))
2630 (setq rmail-total-messages
2631 (+ rmail-total-messages total-messages
))
2632 (setq rmail-message-vector
2633 (vconcat rmail-message-vector
(cdr messages-head
)))
2634 (aset rmail-message-vector
2635 rmail-current-message
(car messages-head
))
2636 (setq rmail-deleted-vector
2637 (concat rmail-deleted-vector deleted-head
))
2638 (setq rmail-summary-vector
2639 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2640 (setq rmail-msgref-vector
2641 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2642 ;; Fill in the new elements of rmail-msgref-vector.
2643 (let ((i (1+ (- rmail-total-messages total-messages
))))
2644 (while (<= i rmail-total-messages
)
2645 (aset rmail-msgref-vector i
(list i
))
2647 (goto-char (point-min))
2648 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2650 (defun rmail-set-message-counters ()
2651 (rmail-forget-messages)
2655 (let* ((point-save (point))
2657 (messages-after-point)
2658 (case-fold-search nil
)
2661 (message "Counting messages...")
2662 (goto-char (point-max))
2663 ;; Put at the end of messages-head
2664 ;; the entry for message N+1, which marks
2665 ;; the end of message N. (N = number of messages).
2666 (search-backward "\n\^_" nil t
)
2667 (if (/= (point) (point-max)) (forward-char 1))
2668 (setq messages-head
(list (point-marker)))
2669 (rmail-set-message-counters-counter (min (point) point-save
))
2670 (setq messages-after-point total-messages
)
2671 (rmail-set-message-counters-counter)
2672 (setq rmail-total-messages total-messages
)
2673 (setq rmail-current-message
2675 (max 1 (- total-messages messages-after-point
))))
2676 (setq rmail-message-vector
2677 (apply 'vector
(cons (point-min-marker) messages-head
))
2678 rmail-deleted-vector
(concat "0" deleted-head
)
2679 rmail-summary-vector
(make-vector rmail-total-messages nil
)
2680 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2682 (while (<= i rmail-total-messages
)
2683 (aset rmail-msgref-vector i
(list i
))
2685 (message "Counting messages...done")))))
2687 (defun rmail-set-message-counters-counter (&optional stop
)
2688 (let ((start (point))
2690 (while (search-backward "\n\^_\^L" stop t
)
2691 ;; Detect messages that have been added with DOS line endings and
2692 ;; convert the line endings for such messages.
2694 (if (looking-at "\n\^_\^L\r\n")
2695 (let ((buffer-read-only nil
)
2697 (message "Counting messages...(converting line endings)")
2700 (while (search-backward "\r\n" next t
)
2704 (setq messages-head
(cons (point-marker) messages-head
))
2707 (cons (if (search-backward ", deleted,"
2713 (if (zerop (%
(setq total-messages
(1+ total-messages
)) 20))
2714 (message "Counting messages...%d" total-messages
)))))
2716 (defun rmail-beginning-of-message ()
2717 "Show current message starting from the beginning."
2719 (let ((rmail-show-message-hook
2720 (list (function (lambda ()
2721 (goto-char (point-min)))))))
2722 (rmail-show-message rmail-current-message
)))
2724 (defun rmail-end-of-message ()
2725 "Show bottom of current message."
2727 (let ((rmail-show-message-hook
2728 (list (function (lambda ()
2729 (goto-char (point-max))
2730 (recenter (1- (window-height))))))))
2731 (rmail-show-message rmail-current-message
)))
2733 (defun rmail-unknown-mail-followup-to ()
2734 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2735 Ask the user whether to add that list name to `mail-mailing-lists'."
2737 (rmail-narrow-to-non-pruned-header)
2738 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2739 (when mail-followup-to
2742 (mail-strip-quoted-names mail-followup-to
)
2743 ",[[:space:]]+" t
)))
2744 (dolist (addr addresses
)
2745 (when (and (not (member addr mail-mailing-lists
))
2747 ;; taken from rmailsum.el
2749 (or rmail-user-mail-address-regexp
2751 (regexp-quote (user-login-name))
2754 (or user-mail-address
2755 (concat (user-login-name) "@"
2756 (or mail-host-address
2761 (format "Add `%s' to `mail-mailing-lists'? "
2763 (customize-save-variable 'mail-mailing-lists
2764 (cons addr mail-mailing-lists
)))))))))
2766 (defun rmail-show-message (&optional n no-summary
)
2767 "Show message number N (prefix argument), counting from start of file.
2768 If summary buffer is currently displayed, update current message there also."
2770 (or (eq major-mode
'rmail-mode
)
2771 (switch-to-buffer rmail-buffer
))
2772 (rmail-maybe-set-message-counters)
2774 (if (zerop rmail-total-messages
)
2775 (progn (narrow-to-region (point-min) (1- (point-max)))
2776 (goto-char (point-min))
2777 (setq mode-line-process nil
))
2778 (let (blurb coding-system
)
2780 (setq n rmail-current-message
)
2783 rmail-current-message
1
2784 blurb
"No previous message"))
2785 ((> n rmail-total-messages
)
2786 (setq n rmail-total-messages
2787 rmail-current-message rmail-total-messages
2788 blurb
"No following message"))
2790 (setq rmail-current-message n
))))
2791 (let ((beg (rmail-msgbeg n
)))
2795 (let ((end (rmail-msgend n
)))
2797 (if (prog1 (= (following-char) ?
0)
2799 ;; If there's a Summary-line in the (otherwise empty)
2800 ;; header, we didn't yet get past the EOOH line.
2801 (if (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
2803 (narrow-to-region (point) end
))
2805 (search-forward "\n*** EOOH ***\n" end t
))
2806 (narrow-to-region beg
(point))
2807 (goto-char (point-min))
2808 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2809 (let ((coding-system (intern (match-string 1))))
2812 (check-coding-system coding-system
)
2813 (setq buffer-file-coding-system coding-system
))
2815 (setq buffer-file-coding-system nil
))))
2816 (setq buffer-file-coding-system nil
)))))
2817 ;; Clear the "unseen" attribute when we show a message.
2818 (rmail-set-attribute "unseen" nil
)
2819 (let ((end (rmail-msgend n
)))
2820 ;; Reformat the header, or else find the reformatted header.
2821 (if (= (following-char) ?
0)
2822 (rmail-reformat-message beg end
)
2823 (search-forward "\n*** EOOH ***\n" end t
)
2824 (narrow-to-region (point) end
)))
2825 (goto-char (point-min))
2827 (function (lambda (window)
2828 (if (eq (window-buffer window
) (current-buffer))
2829 (set-window-point window
(point)))))
2831 (rmail-display-labels)
2832 (if (eq rmail-enable-mime t
)
2833 (funcall rmail-show-mime-function
)
2834 (setq rmail-view-buffer rmail-buffer
))
2835 (when mail-mailing-lists
2836 (rmail-unknown-mail-followup-to))
2837 (rmail-highlight-headers)
2838 (if transient-mark-mode
(deactivate-mark))
2839 (run-hooks 'rmail-show-message-hook
)
2840 ;; If there is a summary buffer, try to move to this message
2841 ;; in that buffer. But don't complain if this message
2842 ;; is not mentioned in the summary.
2843 ;; Don't do this at all if we were called on behalf
2844 ;; of cursor motion in the summary buffer.
2845 (and (rmail-summary-exists) (not no-summary
)
2846 (let ((curr-msg rmail-current-message
))
2847 (rmail-select-summary
2848 (rmail-summary-goto-msg curr-msg t t
))))
2849 (with-current-buffer rmail-buffer
2852 (message blurb
))))))
2854 (defun rmail-redecode-body (coding &optional raw
)
2855 "Decode the body of the current message using coding system CODING.
2856 This is useful with mail messages that have malformed or missing
2859 This function assumes that the current message is already decoded
2860 and displayed in the RMAIL buffer, but the coding system used to
2861 decode it was incorrect. It then encodes the message back to its
2862 original form, and decodes it again, using the coding system CODING.
2864 Optional argument RAW, if non-nil, means don't encode the message
2865 before decoding it with the new CODING. This is useful if the current
2866 message text was produced by some function which invokes `insert',
2867 since `insert' leaves unibyte character codes 128 through 255 unconverted
2868 to multibyte. One example of such a situation is when the text was
2869 produced by `base64-decode-region'.
2871 Interactively, invoke the function with a prefix argument to set RAW
2874 Note that if Emacs erroneously auto-detected one of the iso-2022
2875 encodings in the message, this function might fail because the escape
2876 sequences that switch between character sets and also single-shift and
2877 locking-shift codes are impossible to recover. This function is meant
2878 to be used to fix messages encoded with 8-bit encodings, such as
2879 iso-8859, koi8-r, etc."
2880 (interactive "zCoding system for re-decoding this message: ")
2881 (when (not rmail-enable-mime
)
2882 (or (eq major-mode
'rmail-mode
)
2883 (switch-to-buffer rmail-buffer
))
2885 (let ((pruned (rmail-msg-is-pruned))
2886 (raw (or raw current-prefix-arg
)))
2888 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2889 (msgend (rmail-msgend rmail-current-message
))
2891 ;; We need the message headers pruned (we later restore
2892 ;; the pruned stat to what it was, see the end of
2893 ;; unwind-protect form).
2895 (rmail-toggle-header 1))
2896 (narrow-to-region msgbeg msgend
)
2897 (goto-char (point-min))
2898 (when (search-forward "\n*** EOOH ***\n" (point-max) t
)
2899 (narrow-to-region msgbeg
(point)))
2900 (goto-char (point-min))
2901 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2902 (let ((old-coding (intern (match-string 1)))
2903 (buffer-read-only nil
))
2904 (check-coding-system old-coding
)
2905 ;; Make sure the new coding system uses the same EOL
2906 ;; conversion, to prevent ^M characters from popping
2907 ;; up all over the place.
2909 (coding-system-change-eol-conversion
2911 (coding-system-eol-type old-coding
)))
2912 ;; If old-coding is `undecided', encode-coding-region
2913 ;; will not encode the text at all. Find a proper
2914 ;; non-trivial encoding to use.
2915 (if (memq (coding-system-base old-coding
) '(nil undecided
))
2917 (car (find-coding-systems-region msgbeg msgend
))))
2918 (setq x-coding-header
(point-marker))
2919 (narrow-to-region msgbeg msgend
)
2921 ;; If old and new encoding are the same, it
2922 ;; clearly doesn't make sense to encode.
2923 (not (coding-system-equal
2924 (coding-system-base old-coding
)
2925 (coding-system-base coding
)))
2926 ;; If the body includes only eight-bit-*
2927 ;; characters, encoding might fail, e.g. with
2928 ;; UTF-8, and isn't needed anyway.
2929 (> (length (delq 'ascii
2930 (delq 'eight-bit-graphic
2931 (delq 'eight-bit-control
2932 (find-charset-region
2935 (encode-coding-region (point) msgend old-coding
))
2936 (decode-coding-region (point) msgend coding
)
2937 (setq last-coding-system-used coding
)
2938 ;; Rewrite the coding-system header according
2940 (goto-char x-coding-header
)
2941 (delete-region (point)
2945 (insert "X-Coding-System: "
2946 (symbol-name last-coding-system-used
))
2947 (set-marker x-coding-header nil
)
2948 (rmail-show-message))
2949 (error "No X-Coding-System header found")))
2951 (rmail-toggle-header 0)))))))
2953 ;; Find all occurrences of certain fields, and highlight them.
2954 (defun rmail-highlight-headers ()
2955 ;; Do this only if the system supports faces.
2956 (if (and (fboundp 'internal-find-face
)
2957 rmail-highlighted-headers
)
2959 (search-forward "\n\n" nil
'move
)
2961 (narrow-to-region (point-min) (point))
2962 (let ((case-fold-search t
)
2963 (inhibit-read-only t
)
2964 ;; Highlight with boldface if that is available.
2965 ;; Otherwise use the `highlight' face.
2966 (face (or rmail-highlight-face
2967 (if (face-differs-from-default-p 'bold
)
2969 ;; List of overlays to reuse.
2970 (overlays rmail-overlay-list
))
2971 (goto-char (point-min))
2972 (while (re-search-forward rmail-highlighted-headers nil t
)
2973 (skip-chars-forward " \t")
2976 (while (progn (forward-line 1)
2977 (looking-at "[ \t]")))
2978 ;; Back up over newline, then trailing spaces or tabs
2980 (while (member (preceding-char) '(? ?
\t))
2983 ;; Reuse an overlay we already have.
2985 (setq overlay
(car overlays
)
2986 overlays
(cdr overlays
))
2987 (overlay-put overlay
'face face
)
2988 (move-overlay overlay beg
(point)))
2989 ;; Make a new overlay and add it to
2990 ;; rmail-overlay-list.
2991 (setq overlay
(make-overlay beg
(point)))
2992 (overlay-put overlay
'face face
)
2993 (setq rmail-overlay-list
2994 (cons overlay rmail-overlay-list
))))))))))
2996 (defun rmail-auto-file ()
2997 "Automatically move a message into a sub-folder based on criteria.
2998 Called when a new message is displayed."
2999 (if (or (rmail-message-labels-p rmail-current-message
"filed")
3000 (not (string= (buffer-file-name)
3001 (expand-file-name rmail-file-name
))))
3002 ;; Do nothing if it's already been filed.
3004 ;; Find out some basics (common fields)
3005 (let ((from (mail-fetch-field "from"))
3006 (subj (mail-fetch-field "subject"))
3007 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
3008 (d rmail-automatic-folder-directives
)
3009 (directive-loop nil
)
3012 (setq folder
(car (car d
))
3013 directive-loop
(cdr (car d
)))
3014 (while (and (car directive-loop
)
3016 ((string= (car directive-loop
) "from") from
)
3017 ((string= (car directive-loop
) "to") to
)
3018 ((string= (car directive-loop
) "subject") subj
)
3019 (t (mail-fetch-field (car directive-loop
))))))
3020 (and f
(string-match (car (cdr directive-loop
)) f
))))
3021 (setq directive-loop
(cdr (cdr directive-loop
))))
3022 ;; If there are no directives left, then it was a complete match.
3023 (if (null directive-loop
)
3025 (rmail-delete-forward)
3026 (if (string= "/dev/null" folder
)
3027 (rmail-delete-message)
3028 (rmail-output-to-rmail-file folder
1 t
)
3030 (setq d
(cdr d
))))))
3032 (defun rmail-next-message (n)
3033 "Show following message whether deleted or not.
3034 With prefix arg N, moves forward N messages, or backward if N is negative."
3036 (set-buffer rmail-buffer
)
3037 (rmail-maybe-set-message-counters)
3038 (rmail-show-message (+ rmail-current-message n
)))
3040 (defun rmail-previous-message (n)
3041 "Show previous message whether deleted or not.
3042 With prefix arg N, moves backward N messages, or forward if N is negative."
3044 (rmail-next-message (- n
)))
3046 (defun rmail-next-undeleted-message (n)
3047 "Show following non-deleted message.
3048 With prefix arg N, moves forward N non-deleted messages,
3049 or backward if N is negative.
3051 Returns t if a new message is being shown, nil otherwise."
3053 (set-buffer rmail-buffer
)
3054 (rmail-maybe-set-message-counters)
3055 (let ((lastwin rmail-current-message
)
3056 (current rmail-current-message
))
3057 (while (and (> n
0) (< current rmail-total-messages
))
3058 (setq current
(1+ current
))
3059 (if (not (rmail-message-deleted-p current
))
3060 (setq lastwin current n
(1- n
))))
3061 (while (and (< n
0) (> current
1))
3062 (setq current
(1- current
))
3063 (if (not (rmail-message-deleted-p current
))
3064 (setq lastwin current n
(1+ n
))))
3065 (if (/= lastwin rmail-current-message
)
3066 (progn (rmail-show-message lastwin
)
3069 (message "No previous nondeleted message"))
3071 (message "No following nondeleted message"))
3074 (defun rmail-previous-undeleted-message (n)
3075 "Show previous non-deleted message.
3076 With prefix argument N, moves backward N non-deleted messages,
3077 or forward if N is negative."
3079 (rmail-next-undeleted-message (- n
)))
3081 (defun rmail-first-message ()
3082 "Show first message in file."
3084 (rmail-maybe-set-message-counters)
3085 (rmail-show-message 1))
3087 (defun rmail-last-message ()
3088 "Show last message in file."
3090 (rmail-maybe-set-message-counters)
3091 (rmail-show-message rmail-total-messages
))
3093 (defun rmail-what-message ()
3094 (let ((where (point))
3096 (high rmail-total-messages
)
3097 (mid (/ rmail-total-messages
2)))
3098 (while (> (- high low
) 1)
3099 (if (>= where
(rmail-msgbeg mid
))
3102 (setq mid
(+ low
(/ (- high low
) 2))))
3103 (if (>= where
(rmail-msgbeg high
)) high low
)))
3105 (defun rmail-message-recipients-p (msg recipients
&optional primary-only
)
3107 (goto-char (rmail-msgbeg msg
))
3108 (search-forward "\n*** EOOH ***\n")
3109 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
3110 (or (string-match recipients
(or (mail-fetch-field "To") ""))
3111 (string-match recipients
(or (mail-fetch-field "From") ""))
3112 (if (not primary-only
)
3113 (string-match recipients
(or (mail-fetch-field "Cc") ""))))))
3115 (defun rmail-message-regexp-p (n regexp
)
3116 "Return t, if for message number N, regexp REGEXP matches in the header."
3117 (let ((beg (rmail-msgbeg n
))
3118 (end (rmail-msgend n
)))
3123 (if (prog1 (= (following-char) ?
0)
3125 ;; If there's a Summary-line in the (otherwise empty)
3126 ;; header, we didn't yet get past the EOOH line.
3127 (when (looking-at "^\\*\\*\\* EOOH \\*\\*\\*\n")
3130 (narrow-to-region (point) end
))
3135 (search-forward "\n*** EOOH ***\n" end t
)
3136 (setq end
(1+ (match-beginning 0)))))
3138 (if rmail-enable-mime
3139 (funcall rmail-search-mime-header-function n regexp end
)
3140 (re-search-forward regexp end t
)))))
3142 (defun rmail-search-message (msg regexp
)
3143 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3144 (goto-char (rmail-msgbeg msg
))
3145 (if rmail-enable-mime
3146 (funcall rmail-search-mime-message-function msg regexp
)
3147 (re-search-forward regexp
(rmail-msgend msg
) t
)))
3149 (defvar rmail-search-last-regexp nil
)
3150 (defun rmail-search (regexp &optional n
)
3151 "Show message containing next match for REGEXP (but not the current msg).
3152 Prefix argument gives repeat count; negative argument means search
3153 backwards (through earlier messages).
3154 Interactively, empty argument means use same regexp used last time."
3156 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3158 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3162 (if rmail-search-last-regexp
3163 (concat ", default "
3164 rmail-search-last-regexp
"): ")
3166 (setq regexp
(read-string prompt
))
3167 (cond ((not (equal regexp
""))
3168 (setq rmail-search-last-regexp regexp
))
3169 ((not rmail-search-last-regexp
)
3170 (error "No previous Rmail search string")))
3171 (list rmail-search-last-regexp
3172 (prefix-numeric-value current-prefix-arg
))))
3174 (message "%sRmail search for %s..."
3175 (if (< n
0) "Reverse " "")
3177 (set-buffer rmail-buffer
)
3178 (rmail-maybe-set-message-counters)
3179 (let ((omin (point-min))
3184 (msg rmail-current-message
))
3189 ;; Check messages one by one, advancing message number up or down
3190 ;; but searching forward through each message.
3192 (while (and (null win
) (> msg
1))
3194 win
(rmail-search-message msg regexp
)))
3195 (while (and (null win
) (< msg rmail-total-messages
))
3197 win
(rmail-search-message msg regexp
))))
3198 (setq n
(+ n
(if reversep
1 -
1)))))
3201 (rmail-show-message msg
)
3202 ;; Search forward (if this is a normal search) or backward
3203 ;; (if this is a reverse search) through this message to
3204 ;; position point. This search may fail because REGEXP
3205 ;; was found in the hidden portion of this message. In
3206 ;; that case, move point to the beginning of visible
3210 (goto-char (point-max))
3211 (re-search-backward regexp nil
'move
))
3212 (goto-char (point-min))
3213 (re-search-forward regexp nil t
))
3214 (message "%sRmail search for %s...done"
3215 (if reversep
"Reverse " "")
3218 (narrow-to-region omin omax
)
3220 (message "Search failed: %s" regexp
)))))
3222 (defun rmail-search-backwards (regexp &optional n
)
3223 "Show message containing previous match for REGEXP.
3224 Prefix argument gives repeat count; negative argument means search
3225 forward (through later messages).
3226 Interactively, empty argument means use same regexp used last time."
3228 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3230 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3234 (if rmail-search-last-regexp
3235 (concat ", default "
3236 rmail-search-last-regexp
"): ")
3238 (setq regexp
(read-string prompt
))
3239 (cond ((not (equal regexp
""))
3240 (setq rmail-search-last-regexp regexp
))
3241 ((not rmail-search-last-regexp
)
3242 (error "No previous Rmail search string")))
3243 (list rmail-search-last-regexp
3244 (prefix-numeric-value current-prefix-arg
))))
3245 (rmail-search regexp
(- (or n
1))))
3247 ;; Show the first message which has the `unseen' attribute.
3248 (defun rmail-first-unseen-message ()
3249 (rmail-maybe-set-message-counters)
3254 (while (and (not found
) (<= current rmail-total-messages
))
3255 (if (rmail-message-labels-p current
", ?\\(unseen\\),")
3256 (setq found current
))
3257 (setq current
(1+ current
))))
3258 ;; Let the caller show the message.
3260 ;; (rmail-show-message found))
3263 (defun rmail-current-subject ()
3264 "Return the current subject.
3265 The subject is stripped of leading and trailing whitespace, and
3266 of typical reply prefixes such as Re:."
3267 (let ((subject (or (mail-fetch-field "Subject") "")))
3268 (if (string-match "\\`[ \t]+" subject
)
3269 (setq subject
(substring subject
(match-end 0))))
3270 (if (string-match rmail-reply-regexp subject
)
3271 (setq subject
(substring subject
(match-end 0))))
3272 (if (string-match "[ \t]+\\'" subject
)
3273 (setq subject
(substring subject
0 (match-beginning 0))))
3276 (defun rmail-current-subject-regexp ()
3277 "Return a regular expression matching the current subject.
3278 The regular expression matches the subject header line of
3279 messages about the same subject. The subject itself is stripped
3280 of leading and trailing whitespace, of typical reply prefixes
3281 such as Re: and whitespace within the subject is replaced by a
3282 regular expression matching whitespace in general in order to
3283 take into account that subject header lines may include newlines
3284 and more whitespace. The returned regular expressions contains
3285 `rmail-reply-regexp' and ends with a newline."
3286 (let ((subject (rmail-current-subject)))
3287 ;; If Subject is long, mailers will break it into several lines at
3288 ;; arbitrary places, so replace whitespace with a regexp that will
3289 ;; match any sequence of spaces, TABs, and newlines.
3290 (setq subject
(regexp-quote subject
))
3292 (replace-regexp-in-string "[ \t\n]+" "[ \t\n]+" subject t t
))
3293 ;; Some mailers insert extra spaces after "Subject:", so allow any
3295 (concat "^Subject:[ \t]+"
3296 (if (string= "\\`" (substring rmail-reply-regexp
0 2))
3297 (substring rmail-reply-regexp
2)
3299 subject
"[ \t]*\n")))
3301 (defun rmail-next-same-subject (n)
3302 "Go to the next mail message having the same subject header.
3303 With prefix argument N, do this N times.
3304 If N is negative, go backwards instead."
3306 (let ((search-regexp (rmail-current-subject-regexp))
3308 (i rmail-current-message
)
3309 (case-fold-search t
)
3314 (while (and (/= n
0)
3316 (< i rmail-total-messages
)
3319 (while (and (not done
)
3321 (< i rmail-total-messages
)
3323 (setq i
(if forward
(1+ i
) (1- i
)))
3324 (goto-char (rmail-msgbeg i
))
3325 (search-forward "\n*** EOOH ***\n")
3326 (let ((beg (point)) end
)
3327 (search-forward "\n\n")
3330 (setq done
(re-search-forward search-regexp end t
))))
3331 (if done
(setq found i
)))
3332 (setq n
(if forward
(1- n
) (1+ n
))))))
3334 (rmail-show-message found
)
3335 (error "No %s message with same subject"
3336 (if forward
"following" "previous")))))
3338 (defun rmail-previous-same-subject (n)
3339 "Go to the previous mail message having the same subject header.
3340 With prefix argument N, do this N times.
3341 If N is negative, go forwards instead."
3343 (rmail-next-same-subject (- n
)))
3345 ;;;; *** Rmail Message Deletion Commands ***
3347 (defun rmail-message-deleted-p (n)
3348 (= (aref rmail-deleted-vector n
) ?D
))
3350 (defun rmail-set-message-deleted-p (n state
)
3351 (aset rmail-deleted-vector n
(if state ?D ?\
)))
3353 (defun rmail-delete-message ()
3354 "Delete this message and stay on it."
3356 (rmail-set-attribute "deleted" t
)
3357 (run-hooks 'rmail-delete-message-hook
))
3359 (defun rmail-undelete-previous-message ()
3360 "Back up to deleted message, select it, and undelete it."
3362 (set-buffer rmail-buffer
)
3363 (let ((msg rmail-current-message
))
3364 (while (and (> msg
0)
3365 (not (rmail-message-deleted-p msg
)))
3366 (setq msg
(1- msg
)))
3368 (error "No previous deleted message")
3369 (if (/= msg rmail-current-message
)
3370 (rmail-show-message msg
))
3371 (rmail-set-attribute "deleted" nil
)
3372 (if (rmail-summary-exists)
3374 (set-buffer rmail-summary-buffer
)
3375 (rmail-summary-mark-undeleted msg
)))
3376 (rmail-maybe-display-summary))))
3378 (defun rmail-delete-forward (&optional backward
)
3379 "Delete this message and move to next nondeleted one.
3380 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3381 With prefix argument, delete and move backward.
3383 Returns t if a new message is displayed after the delete, or nil otherwise."
3385 (rmail-set-attribute "deleted" t
)
3386 (run-hooks 'rmail-delete-message-hook
)
3387 (let ((del-msg rmail-current-message
))
3388 (if (rmail-summary-exists)
3389 (rmail-select-summary
3390 (rmail-summary-mark-deleted del-msg
)))
3391 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3392 (rmail-maybe-display-summary))))
3394 (defun rmail-delete-backward ()
3395 "Delete this message and move to previous nondeleted one.
3396 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3398 (rmail-delete-forward t
))
3400 ;; Compute the message number a given message would have after expunging.
3401 ;; The present number of the message is OLDNUM.
3402 ;; DELETEDVEC should be rmail-deleted-vector.
3403 ;; The value is nil for a message that would be deleted.
3404 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3405 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3410 (if (/= (aref deletedvec i
) ?D
)
3411 (setq newnum
(1+ newnum
)))
3415 (defun rmail-expunge-confirmed ()
3416 "Return t if deleted message should be expunged. If necessary, ask the user.
3417 See also user-option `rmail-confirm-expunge'."
3418 (set-buffer rmail-buffer
)
3419 (or (not (stringp rmail-deleted-vector
))
3420 (not (string-match "D" rmail-deleted-vector
))
3421 (null rmail-confirm-expunge
)
3422 (funcall rmail-confirm-expunge
3423 "Erase deleted messages from Rmail file? ")))
3425 (defun rmail-only-expunge (&optional dont-show
)
3426 "Actually erase all deleted messages in the file."
3428 (set-buffer rmail-buffer
)
3429 (message "Expunging deleted messages...")
3430 ;; Discard all undo records for this buffer.
3431 (or (eq buffer-undo-list t
)
3432 (setq buffer-undo-list nil
))
3433 (rmail-maybe-set-message-counters)
3434 (let* ((omax (- (buffer-size) (point-max)))
3435 (omin (- (buffer-size) (point-min)))
3436 (opoint (if (and (> rmail-current-message
0)
3437 (rmail-message-deleted-p rmail-current-message
))
3439 (if rmail-enable-mime
3440 (with-current-buffer rmail-view-buffer
3441 (- (point)(point-min)))
3442 (- (point) (point-min)))))
3443 (messages-head (cons (aref rmail-message-vector
0) nil
))
3444 (messages-tail messages-head
)
3445 ;; Don't make any undo records for the expunging.
3446 (buffer-undo-list t
)
3451 (goto-char (point-min))
3454 (total rmail-total-messages
)
3455 (new-message-number rmail-current-message
)
3457 (new-msgref (list (list 0)))
3458 (rmailbuf (current-buffer))
3459 (buffer-read-only nil
)
3460 (messages rmail-message-vector
)
3461 (deleted rmail-deleted-vector
)
3462 (summary rmail-summary-vector
))
3463 (setq rmail-total-messages nil
3464 rmail-current-message nil
3465 rmail-message-vector nil
3466 rmail-deleted-vector nil
3467 rmail-summary-vector nil
)
3469 (while (<= number total
)
3470 (if (= (aref deleted number
) ?D
)
3473 (marker-position (aref messages number
))
3474 (marker-position (aref messages
(1+ number
))))
3475 (move-marker (aref messages number
) nil
)
3476 (if (> new-message-number counter
)
3477 (setq new-message-number
(1- new-message-number
))))
3478 (setq counter
(1+ counter
))
3480 (setcdr messages-tail
3481 (cons (aref messages number
) nil
)))
3483 (cons (if (= counter number
) (aref summary
(1- number
)))
3486 (cons (aref rmail-msgref-vector number
)
3488 (setcar (car new-msgref
) counter
))
3489 (if (zerop (%
(setq number
(1+ number
)) 20))
3490 (message "Expunging deleted messages...%d" number
)))
3492 (setcdr messages-tail
3493 (cons (aref messages number
) nil
)))
3494 (setq rmail-current-message new-message-number
3495 rmail-total-messages counter
3496 rmail-message-vector
(apply 'vector messages-head
)
3497 rmail-deleted-vector
(make-string (1+ counter
) ?\
)
3498 rmail-summary-vector
(vconcat (nreverse new-summary
))
3499 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3501 (message "Expunging deleted messages...done")
3503 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3506 (if (zerop rmail-current-message
) 1 nil
)))
3507 (if rmail-enable-mime
3508 (goto-char (+ (point-min) opoint
))
3509 (goto-char (+ (point) opoint
))))))
3511 (defun rmail-expunge ()
3512 "Erase deleted messages from Rmail file and summary buffer."
3514 (when (rmail-expunge-confirmed)
3515 (rmail-only-expunge)
3516 (if (rmail-summary-exists)
3517 (rmail-select-summary (rmail-update-summary)))))
3519 ;;;; *** Rmail Mailing Commands ***
3521 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3522 replybuffer sendactions same-window others
)
3525 (setq yank-action
(list 'insert-buffer replybuffer
)))
3526 (setq others
(cons (cons "cc" cc
) others
))
3527 (setq others
(cons (cons "in-reply-to" in-reply-to
) others
))
3529 (compose-mail to subject others
3531 yank-action sendactions
)
3532 (if rmail-mail-new-frame
3534 (compose-mail to subject others
3535 noerase
'switch-to-buffer-other-frame
3536 yank-action sendactions
)
3537 ;; This is not a standard frame parameter;
3538 ;; nothing except sendmail.el looks at it.
3539 (modify-frame-parameters (selected-frame)
3540 '((mail-dedicated-frame . t
))))
3541 (compose-mail to subject others
3542 noerase
'switch-to-buffer-other-window
3543 yank-action sendactions
)))))
3545 (defun rmail-mail ()
3546 "Send mail in another window.
3547 While composing the message, use \\[mail-yank-original] to yank the
3548 original message into it."
3550 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
3552 (defun rmail-continue ()
3553 "Continue composing outgoing message previously being composed."
3555 (rmail-start-mail t
))
3557 (defun rmail-reply (just-sender)
3558 "Reply to the current message.
3559 Normally include CC: to all other recipients of original message;
3560 prefix argument means ignore them. While composing the reply,
3561 use \\[mail-yank-original] to yank the original message into it."
3563 (let (from reply-to cc subject date to message-id references
3564 resent-to resent-cc resent-reply-to
3565 (msgnum rmail-current-message
))
3568 (if rmail-enable-mime
3570 (goto-char (point-min))
3571 (if (search-forward "\n\n" nil
'move
)
3572 (1+ (match-beginning 0))
3575 (goto-char (rmail-msgbeg rmail-current-message
))
3577 (if (= (following-char) ?
0)
3579 (progn (forward-line 2)
3581 (progn (search-forward "\n\n" (rmail-msgend rmail-current-message
)
3584 (narrow-to-region (point)
3585 (progn (search-forward "\n*** EOOH ***\n")
3586 (beginning-of-line) (point)))))
3587 (setq from
(mail-fetch-field "from")
3588 reply-to
(or (mail-fetch-field "mail-reply-to" nil t
)
3589 (mail-fetch-field "reply-to" nil t
)
3591 subject
(mail-fetch-field "subject")
3592 date
(mail-fetch-field "date")
3593 message-id
(mail-fetch-field "message-id")
3594 references
(mail-fetch-field "references" nil nil t
)
3595 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3596 resent-cc
(and (not just-sender
)
3597 (mail-fetch-field "resent-cc" nil t
))
3598 resent-to
(or (mail-fetch-field "resent-to" nil t
) "")
3599 ;;; resent-subject (mail-fetch-field "resent-subject")
3600 ;;; resent-date (mail-fetch-field "resent-date")
3601 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3604 (if (mail-fetch-field "mail-followup-to" nil t
)
3605 ;; If this header field is present, use it instead of the To and CC fields.
3606 (setq to
(mail-fetch-field "mail-followup-to" nil t
))
3607 (setq cc
(or (mail-fetch-field "cc" nil t
) "")
3608 to
(or (mail-fetch-field "to" nil t
) ""))))
3612 ;; Merge the resent-to and resent-cc into the to and cc.
3613 (if (and resent-to
(not (equal resent-to
"")))
3614 (if (not (equal to
""))
3615 (setq to
(concat to
", " resent-to
))
3616 (setq to resent-to
)))
3617 (if (and resent-cc
(not (equal resent-cc
"")))
3618 (if (not (equal cc
""))
3619 (setq cc
(concat cc
", " resent-cc
))
3620 (setq cc resent-cc
)))
3621 ;; Add `Re: ' to subject if not there already.
3622 (and (stringp subject
)
3624 (concat rmail-reply-prefix
3625 (if (let ((case-fold-search t
))
3626 (string-match rmail-reply-regexp subject
))
3627 (substring subject
(match-end 0))
3631 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3632 ;; since they can handle the names unstripped.
3633 ;; I don't know whether there are other mailers that still
3634 ;; need the names to be stripped.
3635 ;;; (mail-strip-quoted-names reply-to)
3636 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3637 ;; header causes all the names in it to wind up in reply-to, not
3638 ;; in cc. But if what's left is an empty list, use the original.
3639 (let* ((reply-to-list (rmail-dont-reply-to reply-to
)))
3640 (if (string= reply-to-list
"") reply-to reply-to-list
))
3642 (rmail-make-in-reply-to-field from date message-id
)
3645 ;; mail-strip-quoted-names is NOT necessary for rmail-dont-reply-to
3647 (let* ((cc-list (rmail-dont-reply-to
3648 (mail-strip-quoted-names
3649 (if (null cc
) to
(concat to
", " cc
))))))
3650 (if (string= cc-list
"") nil cc-list
)))
3652 (list (list 'rmail-mark-message
3654 (with-current-buffer rmail-buffer
3655 (aref rmail-msgref-vector msgnum
))
3658 (list (cons "References" (concat (mapconcat 'identity references
" ")
3659 " " message-id
))))))
3661 (defun rmail-mark-message (buffer msgnum-list attribute
)
3662 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3663 This is use in the send-actions for message buffers.
3664 MSGNUM-LIST is a list of the form (MSGNUM)
3665 which is an element of rmail-msgref-vector."
3668 (if (car msgnum-list
)
3669 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3671 (defun rmail-make-in-reply-to-field (from date message-id
)
3678 (let ((tem (car (rfc822-addresses from
))))
3682 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3684 (match-beginning 0))
3687 ;; missing From, or Message-ID is sufficiently informative
3689 (concat message-id
" (" tem
")"))
3690 ;; Copy TEM, discarding text properties.
3691 (setq tem
(copy-sequence tem
))
3692 (set-text-properties 0 (length tem
) nil tem
)
3693 (setq tem
(copy-sequence tem
))
3694 ;; Use prin1 to fake RFC822 quoting
3695 (let ((field (prin1-to-string tem
)))
3697 (concat field
"'s message of " date
)
3699 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3700 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3701 ;; These strings both match all non-ASCII characters.
3702 (or (string-match (concat "\\`[ \t]*\\(" bar
3703 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3704 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3706 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3707 bar
"\\))[ \t]*\\'")
3708 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3710 (let ((start (match-beginning 1))
3711 (end (match-end 1)))
3712 ;; Trim whitespace which above regexp match allows
3713 (while (and (< start end
)
3714 (memq (aref from start
) '(?
\t ?\
)))
3715 (setq start
(1+ start
)))
3716 (while (and (< start end
)
3717 (memq (aref from
(1- end
)) '(?
\t ?\
)))
3718 (setq end
(1- end
)))
3719 (let ((field (substring from start end
)))
3720 (if date
(setq field
(concat "message from " field
" on " date
)))
3722 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3723 (concat message-id
" (" field
")")
3726 ;; If we can't kludge it simply, do it correctly
3727 (let ((mail-use-rfc822 t
))
3728 (rmail-make-in-reply-to-field from date message-id
)))))
3730 (defun rmail-forward (resend)
3731 "Forward the current message to another user.
3732 With prefix argument, \"resend\" the message instead of forwarding it;
3733 see the documentation of `rmail-resend'."
3736 (call-interactively 'rmail-resend
)
3737 (let ((forward-buffer rmail-buffer
)
3738 (msgnum rmail-current-message
)
3739 (subject (concat "["
3740 (let ((from (or (mail-fetch-field "From")
3741 (mail-fetch-field ">From"))))
3743 (concat (mail-strip-quoted-names from
) ": ")
3745 (or (mail-fetch-field "Subject") "")
3747 (if (rmail-start-mail
3748 nil nil subject nil nil nil
3749 (list (list 'rmail-mark-message
3751 (with-current-buffer rmail-buffer
3752 (aref rmail-msgref-vector msgnum
))
3754 ;; If only one window, use it for the mail buffer.
3755 ;; Otherwise, use another window for the mail buffer
3756 ;; so that the Rmail buffer remains visible
3757 ;; and sending the mail will get back to it.
3758 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3759 ;; The mail buffer is now current.
3761 ;; Insert after header separator--before signature if any.
3762 (goto-char (mail-text-start))
3763 (if (or rmail-enable-mime rmail-enable-mime-composing
)
3764 (funcall rmail-insert-mime-forwarded-message-function
3766 (insert "------- Start of forwarded message -------\n")
3767 ;; Quote lines with `- ' if they start with `-'.
3768 (let ((beg (point)) end
)
3769 (setq end
(point-marker))
3770 (set-marker-insertion-type end t
)
3771 (insert-buffer-substring forward-buffer
)
3773 (while (re-search-forward "^-" end t
)
3778 (skip-chars-backward "\n")
3781 (delete-region (point) end
)
3782 (set-marker end nil
))
3783 (insert "------- End of forwarded message -------\n"))
3786 (defun rmail-resend (address &optional from comment mail-alias-file
)
3787 "Resend current message to ADDRESSES.
3788 ADDRESSES should be a single address, a string consisting of several
3789 addresses separated by commas, or a list of addresses.
3791 Optional FROM is the address to resend the message from, and
3792 defaults from the value of `user-mail-address'.
3793 Optional COMMENT is a string to insert as a comment in the resent message.
3794 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3795 typically for purposes of moderating a list."
3796 (interactive "sResend to: ")
3798 (require 'mailalias
)
3799 (unless (or (eq rmail-view-buffer
(current-buffer))
3800 (eq rmail-buffer
(current-buffer)))
3801 (error "Not an Rmail buffer"))
3802 (if (not from
) (setq from user-mail-address
))
3803 (let ((tembuf (generate-new-buffer " sendmail temp"))
3804 (case-fold-search nil
)
3805 (mail-personal-alias-file
3806 (or mail-alias-file mail-personal-alias-file
))
3807 (mailbuf rmail-buffer
))
3809 (with-current-buffer tembuf
3810 ;;>> Copy message into temp buffer
3811 (if rmail-enable-mime
3812 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3813 (insert-buffer-substring mailbuf
))
3814 (goto-char (point-min))
3815 ;; Delete any Sender field, since that's not specifiable.
3816 ; Only delete Sender fields in the actual header.
3817 (re-search-forward "^$" nil
'move
)
3818 ; Using "while" here rather than "if" because some buggy mail
3819 ; software may have inserted multiple Sender fields.
3820 (while (re-search-backward "^Sender:" nil t
)
3824 (while (looking-at "[ \t]")
3826 (delete-region beg
(point))))
3827 ; Go back to the beginning of the buffer so the Resent- fields
3828 ; are inserted there.
3829 (goto-char (point-min))
3830 ;;>> Insert resent-from:
3831 (insert "Resent-From: " from
"\n")
3832 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3833 ;;>> Insert resent-to: and bcc if need be.
3834 (let ((before (point)))
3836 (insert "Resent-Bcc: " (user-login-name) "\n"))
3837 (insert "Resent-To: " (if (stringp address
)
3839 (mapconcat 'identity address
",\n\t"))
3841 ;; Expand abbrevs in the recipients.
3843 (if (featurep 'mailabbrev
)
3844 (let ((end (point-marker))
3845 (local-abbrev-table mail-abbrevs
)
3846 (old-syntax-table (syntax-table)))
3847 (if (and (not (vectorp mail-abbrevs
))
3848 (file-exists-p mail-personal-alias-file
))
3849 (build-mail-abbrevs))
3850 (unless mail-abbrev-syntax-table
3851 (mail-abbrev-make-syntax-table))
3852 (set-syntax-table mail-abbrev-syntax-table
)
3854 (while (and (< (point) end
)
3855 (progn (forward-word 1)
3858 (set-syntax-table old-syntax-table
))
3859 (expand-mail-aliases before
(point)))))
3860 ;;>> Set up comment, if any.
3861 (if (and (sequencep comment
) (not (zerop (length comment
))))
3862 (let ((before (point))
3865 (or (eolp) (insert "\n"))
3866 (setq after
(point))
3868 (while (< (point) after
)
3869 (insert "Resent-Comment: ")
3871 ;; Don't expand aliases in the destination fields
3872 ;; of the original message.
3874 (funcall send-mail-function
)))
3875 (kill-buffer tembuf
))
3876 (with-current-buffer rmail-buffer
3877 (rmail-set-attribute "resent" t rmail-current-message
))))
3879 (defvar mail-unsent-separator
3880 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3881 "^ *---+ +Returned message +---+ *$\\|"
3882 "^ *---+ *Returned mail follows *---+ *$\\|"
3883 "^Start of returned message$\\|"
3884 "^---+ Below this line is a copy of the message.$\\|"
3885 "^ *---+ +Original message +---+ *$\\|"
3886 "^ *--+ +begin message +--+ *$\\|"
3887 "^ *---+ +Original message follows +---+ *$\\|"
3888 "^ *---+ +Your message follows +---+ *$\\|"
3889 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3890 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3891 "A regexp that matches the separator before the text of a failed message.")
3893 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3894 "A regexp that matches the header of a MIME body part with a failed message.")
3896 (defun rmail-retry-failure ()
3897 "Edit a mail message which is based on the contents of the current message.
3898 For a message rejected by the mail system, extract the interesting headers and
3899 the body of the original message.
3900 If the failed message is a MIME multipart message, it is searched for a
3901 body part with a header which matches the variable `mail-mime-unsent-header'.
3902 Otherwise, the variable `mail-unsent-separator' should match the string that
3903 delimits the returned original message.
3904 The variable `rmail-retry-ignored-headers' is a regular expression
3905 specifying headers which should not be copied into the new message."
3907 (require 'mail-utils
)
3908 (let ((rmail-this-buffer (current-buffer))
3909 (msgnum rmail-current-message
)
3910 bounce-start bounce-end bounce-indent resending
3911 ;; Fetch any content-type header in current message
3912 ;; Must search thru the whole unpruned header.
3916 (rmail-narrow-to-non-pruned-header)
3917 (mail-fetch-field "Content-Type") ))))
3919 (goto-char (point-min))
3920 (let ((case-fold-search t
))
3921 (if (and content-type
3923 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3925 ;; Handle a MIME multipart bounce message.
3928 (substring content-type
(match-beginning 1)
3930 (unless (re-search-forward mail-mime-unsent-header nil t
)
3931 (error "Cannot find beginning of header in failed message"))
3932 (unless (search-forward "\n\n" nil t
)
3933 (error "Cannot find start of Mime data in failed message"))
3934 (setq bounce-start
(point))
3935 (if (search-forward codestring nil t
)
3936 (setq bounce-end
(match-beginning 0))
3937 (setq bounce-end
(point-max))))
3939 (or (re-search-forward mail-unsent-separator nil t
)
3940 (error "Cannot parse this as a failure message"))
3941 (skip-chars-forward "\n")
3942 ;; Support a style of failure message in which the original
3943 ;; message is indented, and included within lines saying
3944 ;; `Start of returned message' and `End of returned message'.
3945 (if (looking-at " +Received:")
3947 (setq bounce-start
(point))
3948 (skip-chars-forward " ")
3949 (setq bounce-indent
(- (current-column)))
3950 (goto-char (point-max))
3951 (re-search-backward "^End of returned message$" nil t
)
3952 (setq bounce-end
(point)))
3953 ;; One message contained a few random lines before
3954 ;; the old message header. The first line of the
3955 ;; message started with two hyphens. A blank line
3956 ;; followed these random lines. The same line
3957 ;; beginning with two hyphens was possibly marking
3958 ;; the end of the message.
3959 (if (looking-at "^--")
3960 (let ((boundary (buffer-substring-no-properties
3962 (progn (end-of-line) (point)))))
3963 (search-forward "\n\n")
3964 (skip-chars-forward "\n")
3965 (setq bounce-start
(point))
3966 (goto-char (point-max))
3967 (search-backward (concat "\n\n" boundary
) bounce-start t
)
3968 (setq bounce-end
(point)))
3969 (setq bounce-start
(point)
3970 bounce-end
(point-max)))
3971 (unless (search-forward "\n\n" nil t
)
3972 (error "Cannot find end of header in failed message"))))))
3973 ;; We have found the message that bounced, within the current message.
3974 ;; Now start sending new message; default header fields from original.
3975 ;; Turn off the usual actions for initializing the message body
3976 ;; because we want to get only the text from the failure message.
3977 (let (mail-signature mail-setup-hook
)
3978 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
3979 (list (list 'rmail-mark-message
3981 (aref rmail-msgref-vector msgnum
)
3983 ;; Insert original text as initial text of new draft message.
3984 ;; Bind inhibit-read-only since the header delimiter
3985 ;; of the previous message was probably read-only.
3986 (let ((inhibit-read-only t
)
3987 rmail-displayed-headers
3988 rmail-ignored-headers
)
3990 (insert-buffer-substring rmail-this-buffer
3991 bounce-start bounce-end
)
3992 (goto-char (point-min))
3994 (indent-rigidly (point-min) (point-max) bounce-indent
))
3995 (rmail-clear-headers rmail-retry-ignored-headers
)
3996 (rmail-clear-headers "^sender:\\|^return-path:\\|^received:")
3997 (mail-sendmail-delimit-header)
3999 (narrow-to-region (point-min) (mail-header-end))
4000 (setq resending
(mail-fetch-field "resent-to"))
4003 (insert "Resent-Bcc: " (user-login-name) "\n")
4004 (insert "BCC: " (user-login-name) "\n"))))
4005 (goto-char (point-min))
4006 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
4008 (defun rmail-summary-exists ()
4009 "Non-nil if in an RMAIL buffer and an associated summary buffer exists.
4010 In fact, the non-nil value returned is the summary buffer itself."
4011 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4012 rmail-summary-buffer
))
4014 (defun rmail-summary-displayed ()
4015 "t if in RMAIL buffer and an associated summary buffer is displayed."
4016 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
4018 (defcustom rmail-redisplay-summary nil
4019 "*Non-nil means Rmail should show the summary when it changes.
4020 This has an effect only if a summary buffer exists."
4022 :group
'rmail-summary
)
4024 (defcustom rmail-summary-window-size nil
4025 "*Non-nil means specify the height for an Rmail summary window."
4026 :type
'(choice (const :tag
"Disabled" nil
) integer
)
4027 :group
'rmail-summary
)
4029 ;; Put the summary buffer back on the screen, if user wants that.
4030 (defun rmail-maybe-display-summary ()
4031 (let ((selected (selected-window))
4033 ;; If requested, make sure the summary is displayed.
4034 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4035 rmail-redisplay-summary
4036 (if (get-buffer-window rmail-summary-buffer
0)
4037 ;; It's already in some frame; show that one.
4038 (let ((frame (window-frame
4039 (get-buffer-window rmail-summary-buffer
0))))
4040 (make-frame-visible frame
)
4041 (raise-frame frame
))
4042 (display-buffer rmail-summary-buffer
)))
4043 ;; If requested, set the height of the summary window.
4044 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4045 rmail-summary-window-size
4046 (setq window
(get-buffer-window rmail-summary-buffer
))
4047 ;; Don't try to change the size if just one window in frame.
4048 (not (eq window
(frame-root-window (window-frame window
))))
4051 (select-window window
)
4052 (enlarge-window (- rmail-summary-window-size
(window-height))))
4053 (select-window selected
)))))
4055 ;;;; *** Rmail Local Fontification ***
4057 (defun rmail-fontify-buffer-function ()
4058 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
4059 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
4060 ;; If we're already showing a message, fontify it now.
4061 (if rmail-current-message
(rmail-fontify-message))
4062 ;; Prevent Font Lock mode from kicking in.
4063 (setq font-lock-fontified t
))
4065 (defun rmail-unfontify-buffer-function ()
4066 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
4067 (let ((modified (buffer-modified-p))
4068 (buffer-undo-list t
) (inhibit-read-only t
)
4069 before-change-functions after-change-functions
4070 buffer-file-name buffer-file-truename
)
4073 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
4074 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
4075 (font-lock-default-unfontify-buffer)
4076 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))
4078 (defun rmail-fontify-message ()
4079 ;; Fontify the current message if it is not already fontified.
4080 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
4081 (let ((modified (buffer-modified-p))
4082 (buffer-undo-list t
) (inhibit-read-only t
)
4083 before-change-functions after-change-functions
4084 buffer-file-name buffer-file-truename
)
4087 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
4088 (font-lock-fontify-region (point-min) (point-max))
4089 (and (not modified
) (buffer-modified-p) (set-buffer-modified-p nil
)))))))
4091 ;;; Speedbar support for RMAIL files.
4092 (eval-when-compile (require 'speedbar
))
4094 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
4095 "*This regex is used to match folder names to be displayed in speedbar.
4096 Enabling this will permit speedbar to display your folders for easy
4097 browsing, and moving of messages.")
4099 (defvar rmail-speedbar-last-user nil
4100 "The last user to be displayed in the speedbar.")
4102 (defvar rmail-speedbar-key-map nil
4103 "Keymap used when in rmail display mode.")
4105 (defun rmail-install-speedbar-variables ()
4106 "Install those variables used by speedbar to enhance rmail."
4107 (if rmail-speedbar-key-map
4109 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
4111 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
4112 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
4113 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
4114 (define-key rmail-speedbar-key-map
"M"
4115 'rmail-speedbar-move-message-to-folder-on-line
)))
4117 (defvar rmail-speedbar-menu-items
4118 '(["Read Folder" speedbar-edit-line t
]
4119 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4120 (save-excursion (beginning-of-line)
4121 (looking-at "<M> "))])
4122 "Additional menu-items to add to speedbar frame.")
4124 ;; Make sure our special speedbar major mode is loaded
4125 (if (featurep 'speedbar
)
4126 (rmail-install-speedbar-variables)
4127 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
4129 (defun rmail-speedbar-buttons (buffer)
4130 "Create buttons for BUFFER containing rmail messages.
4131 Click on the address under Reply to: to reply to this person.
4132 Under Folders: Click a name to read it, or on the <M> to move the
4133 current message into that RMAIL folder."
4137 (goto-char (point-min))
4138 (if (not (re-search-forward "^Reply-To: " nil t
))
4139 (if (not (re-search-forward "^From:? " nil t
))
4143 (setq from
(buffer-substring (point) (save-excursion
4146 (goto-char (point-min))
4147 (if (and (looking-at "Reply to:")
4148 (equal from rmail-speedbar-last-user
))
4150 (setq rmail-speedbar-last-user from
)
4152 (insert "Reply To:\n")
4154 (speedbar-insert-button from
'speedbar-directory-face
'highlight
4155 'rmail-speedbar-button
'rmail-reply
))
4156 (insert "Folders:\n")
4157 (let* ((case-fold-search nil
)
4158 (df (directory-files (save-excursion (set-buffer buffer
)
4160 nil rmail-speedbar-match-folder-regexp
)))
4162 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
4163 'rmail-speedbar-move-message
(car df
))
4164 (speedbar-insert-button (car df
) 'speedbar-file-face
'highlight
4165 'rmail-speedbar-find-file nil t
)
4166 (setq df
(cdr df
)))))))
4168 (defun rmail-speedbar-button (text token indent
)
4169 "Execute an rmail command specified by TEXT.
4170 The command used is TOKEN. INDENT is not used."
4171 (speedbar-with-attached-buffer
4174 (defun rmail-speedbar-find-file (text token indent
)
4175 "Load in the rmail file TEXT.
4176 TOKEN and INDENT are not used."
4177 (speedbar-with-attached-buffer
4178 (message "Loading in RMAIL file %s..." text
)
4181 (defun rmail-speedbar-move-message-to-folder-on-line ()
4182 "If the current line is a folder, move current message to it."
4186 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t
)
4189 (speedbar-do-function-pointer)))))
4191 (defun rmail-speedbar-move-message (text token indent
)
4192 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4193 TEXT and INDENT are not used."
4194 (speedbar-with-attached-buffer
4195 (message "Moving message to %s" token
)
4196 (rmail-output-to-rmail-file token
)))
4198 ; Functions for setting, getting and encoding the POP password.
4199 ; The password is encoded to prevent it from being easily accessible
4200 ; to "prying eyes." Obviously, this encoding isn't "real security,"
4201 ; nor is it meant to be.
4204 (defun rmail-set-remote-password (password)
4205 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4206 (interactive "sPassword: ")
4208 (setq rmail-encoded-remote-password
4209 (rmail-encode-string password
(emacs-pid)))
4210 (setq rmail-remote-password nil
)
4211 (setq rmail-encoded-remote-password nil
)))
4213 (defun rmail-get-remote-password (imap)
4214 "Get the password for retrieving mail from a POP or IMAP server. If none
4215 has been set, then prompt the user for one."
4216 (when (not rmail-encoded-remote-password
)
4217 (if (not rmail-remote-password
)
4218 (setq rmail-remote-password
4219 (read-passwd (if imap
4221 "POP password: "))))
4222 (rmail-set-remote-password rmail-remote-password
)
4223 (setq rmail-remote-password nil
))
4224 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4226 (defun rmail-have-password ()
4227 (or rmail-remote-password rmail-encoded-remote-password
))
4229 (defun rmail-encode-string (string mask
)
4230 "Encode STRING with integer MASK, by taking the exclusive OR of the
4231 lowest byte in the mask with the first character of string, the
4232 second-lowest-byte with the second character of the string, etc.,
4233 restarting at the lowest byte of the mask whenever it runs out.
4234 Returns the encoded string. Calling the function again with an
4235 encoded string (and the same mask) will decode the string."
4236 (setq mask
(abs mask
)) ; doesn't work if negative
4237 (let* ((string-vector (string-to-vector string
)) (i 0)
4238 (len (length string-vector
)) (curmask mask
) charmask
)
4241 (setq curmask mask
))
4242 (setq charmask
(% curmask
256))
4243 (setq curmask
(lsh curmask -
8))
4244 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4246 (concat string-vector
)))
4248 ;;;; Desktop support
4250 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4252 desktop-buffer-misc
)
4253 "Restore an rmail buffer specified in a desktop file."
4254 (condition-case error
4256 (rmail-input desktop-buffer-file-name
)
4257 (if (eq major-mode
'rmail-mode
)
4261 (kill-buffer (current-buffer))
4264 (add-to-list 'desktop-buffer-mode-handlers
4265 '(rmail-mode . rmail-restore-desktop-buffer
))
4269 ;;; arch-tag: cff0a950-57fe-4f73-a86e-91ff75afd06c
4270 ;;; rmail.el ends here