1 ;;; rmail.el --- main code of "RMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985-1988, 1993-1998, 2000-2011
4 ;; Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
28 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
29 ;; New features include attribute and keyword support, message
30 ;; selection by dispatch table, summary by attributes and keywords,
31 ;; expunging by dispatch table, sticky options for file commands.
33 ;; Extended by Bob Weiner of Motorola
34 ;; New features include: rmail and rmail-summary buffers remain
35 ;; synchronized and key bindings basically operate the same way in both
36 ;; buffers, summary by topic or by regular expression, rmail-reply-prefix
37 ;; variable, and a bury rmail buffer (wipe) command.
43 (defconst rmail-attribute-header
"X-RMAIL-ATTRIBUTES"
44 "The header that stores the Rmail attribute data.")
46 (defconst rmail-keyword-header
"X-RMAIL-KEYWORDS"
47 "The header that stores the Rmail keyword data.")
51 (defconst rmail-answered-attr-index
0
52 "The index for the `answered' attribute.")
54 (defconst rmail-deleted-attr-index
1
55 "The index for the `deleted' attribute.")
57 (defconst rmail-edited-attr-index
2
58 "The index for the `edited' attribute.")
60 (defconst rmail-filed-attr-index
3
61 "The index for the `filed' attribute.")
63 (defconst rmail-retried-attr-index
4
64 "The index for the `retried' attribute.")
66 (defconst rmail-forwarded-attr-index
5
67 "The index for the `forwarded' attribute.")
69 (defconst rmail-unseen-attr-index
6
70 "The index for the `unseen' attribute.")
72 (defconst rmail-resent-attr-index
7
73 "The index for the `resent' attribute.")
75 (defconst rmail-attr-array
84 "An array that provides a mapping between an attribute index,
85 its character representation and its display representation.")
88 (defvar font-lock-fontified
)
89 (defvar mail-abbrev-syntax-table
)
91 (defvar messages-head
)
92 (defvar total-messages
)
94 (defvar mail-encode-mml
)
96 (defvar rmail-header-style
'normal
97 "The current header display style choice, one of
98 'normal (selected headers) or 'full (all headers).")
100 ;; rmail-spool-directory and rmail-file-name are defined in paths.el.
103 "Mail reader for Emacs."
106 (defgroup rmail-retrieve nil
107 "Rmail retrieval options."
111 (defgroup rmail-files nil
116 (defgroup rmail-headers nil
117 "Rmail header options."
121 (defgroup rmail-reply nil
122 "Rmail reply options."
126 (defgroup rmail-summary nil
127 "Rmail summary options."
129 :prefix
"rmail-summary-"
132 (defgroup rmail-output nil
133 "Output message to a file."
134 :prefix
"rmail-output-"
138 (defgroup rmail-edit nil
140 :prefix
"rmail-edit-"
143 (defcustom rmail-movemail-program nil
144 "If non-nil, the file name of the `movemail' program."
145 :group
'rmail-retrieve
146 :type
'(choice (const nil
) string
))
148 (define-obsolete-variable-alias 'rmail-pop-password
149 'rmail-remote-password
"22.1")
151 (defcustom rmail-remote-password nil
152 "Password to use when reading mail from a remote server.
153 This setting is ignored for mailboxes whose URL already contains a password."
154 :type
'(choice (string :tag
"Password")
155 (const :tag
"Not Required" nil
))
156 :group
'rmail-retrieve
159 (define-obsolete-variable-alias 'rmail-pop-password-required
160 'rmail-remote-password-required
"22.1")
162 (defcustom rmail-remote-password-required nil
163 "Non-nil if a password is required when reading mail from a remote server."
165 :group
'rmail-retrieve
168 (defcustom rmail-movemail-flags nil
169 "List of flags to pass to movemail.
170 Most commonly used to specify `-g' to enable GSS-API authentication
171 or `-k' to enable Kerberos authentication."
172 :type
'(repeat string
)
173 :group
'rmail-retrieve
176 (defvar rmail-remote-password-error
"invalid usercode or password\\|
177 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
178 "Regular expression matching incorrect-password POP or IMAP server error
180 If you get an incorrect-password error that this expression does not match,
181 please report it with \\[report-emacs-bug].")
183 (defvar rmail-encoded-remote-password nil
)
185 (defcustom rmail-preserve-inbox nil
186 "Non-nil means leave incoming mail in the user's inbox--don't delete it."
188 :group
'rmail-retrieve
)
190 (defcustom rmail-movemail-search-path nil
191 "List of directories to search for movemail (in addition to `exec-path')."
192 :group
'rmail-retrieve
193 :type
'(repeat (directory)))
195 (declare-function mail-dont-reply-to
"mail-utils" (destinations))
196 (declare-function rmail-update-summary
"rmailsum" (&rest ignore
))
197 (declare-function rmail-mime-toggle-hidden
"rmailmm" ())
199 (defun rmail-probe (prog)
200 "Determine what flavor of movemail PROG is.
201 We do this by executing it with `--version' and analyzing its output."
203 (let ((tbuf (current-buffer)))
204 (buffer-disable-undo tbuf
)
205 (call-process prog nil tbuf nil
"--version")
206 (if (not (buffer-modified-p tbuf
))
207 ;; Should not happen...
209 (goto-char (point-min))
211 ((looking-at ".*movemail: invalid option")
212 'emacs
) ;; Possibly...
213 ((looking-at "movemail (GNU Mailutils .*)")
219 (defun rmail-autodetect ()
220 "Determine the file name of the `movemail' program and return its flavor.
221 If `rmail-movemail-program' is non-nil, use it.
222 Otherwise, look for `movemail' in the directories in
223 `rmail-movemail-search-path', those in `exec-path', and `exec-directory'."
224 (if rmail-movemail-program
225 (rmail-probe rmail-movemail-program
)
227 (dolist (dir (append rmail-movemail-search-path exec-path
228 (list exec-directory
)))
229 (when (and dir
(file-accessible-directory-p dir
))
230 ;; Previously, this didn't have to work on Windows, because
231 ;; rmail-insert-inbox-text before r1.439 fell back to using
232 ;; (expand-file-name "movemail" exec-directory) and just
233 ;; assuming it would work.
234 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2008-02/msg00087.html
235 (let ((progname (expand-file-name
237 (if (memq system-type
'(ms-dos windows-nt
))
239 (when (and (not (file-directory-p progname
))
240 (file-executable-p progname
))
241 (let ((x (rmail-probe progname
)))
243 (setq rmail-movemail-program progname
)
244 (throw 'scan x
))))))))))
246 (defvar rmail-movemail-variant-in-use nil
247 "The movemail variant currently in use. Known variants are:
249 `emacs' Means any implementation, compatible with the native Emacs one.
251 `mailutils' Means GNU mailutils implementation, capable of handling full
252 mail URLs as the source mailbox.")
255 (defun rmail-movemail-variant-p (&rest variants
)
256 "Return t if the current movemail variant is any of VARIANTS.
257 Currently known variants are 'emacs and 'mailutils."
258 (when (not rmail-movemail-variant-in-use
)
260 (setq rmail-movemail-variant-in-use
(rmail-autodetect)))
261 (not (null (member rmail-movemail-variant-in-use variants
))))
263 ;; Call for effect, to set rmail-movemail-program (if not set by the
264 ;; user), and rmail-movemail-variant-in-use. Used by various functions.
265 ;; I'm not sure if M-x rmail is the only entry point to this package.
266 ;; If so, this can be moved there.
267 (rmail-movemail-variant-p)
270 (defcustom rmail-user-mail-address-regexp nil
271 "Regexp matching user mail addresses.
272 If non-nil, this variable is used to identify the correspondent
273 when receiving new mail. If it matches the address of the sender,
274 the recipient is taken as correspondent of a mail.
275 If nil \(default value\), your `user-login-name' and `user-mail-address'
276 are used to exclude yourself as correspondent.
278 Usually you don't have to set this variable, except if you collect mails
279 sent by you under different user names.
280 Then it should be a regexp matching your mail addresses.
282 Setting this variable has an effect only before reading a mail."
283 :type
'(choice (const :tag
"None" nil
) regexp
)
284 :group
'rmail-retrieve
288 (defvaralias 'rmail-dont-reply-to-names
'mail-dont-reply-to-names
)
291 (defvar rmail-default-dont-reply-to-names nil
292 "Regexp specifying part of the default value of `mail-dont-reply-to-names'.
293 This is used when the user does not set `mail-dont-reply-to-names'
296 (make-obsolete-variable 'rmail-default-dont-reply-to-names
297 'mail-dont-reply-to-names
"24.1")
300 (defcustom rmail-ignored-headers
302 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
303 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
304 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
305 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
306 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
307 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
308 "\\|^content-transfer-encoding:\\|^x-coding-system:"
309 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
310 "\\|^precedence:\\|^mime-version:"
311 "\\|^list-owner:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
312 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
313 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
314 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
315 "\\|^mbox-line:\\|^cancel-lock:"
316 "\\|^DomainKey-Signature:\\|^dkim-signature:"
317 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
319 "Regexp to match header fields that Rmail should normally hide.
320 \(See also `rmail-nonignored-headers', which overrides this regexp.)
321 This variable is used for reformatting the message header,
322 which normally happens once for each message,
323 when you view the message for the first time in Rmail.
324 To make a change in this variable take effect
325 for a message that you have already viewed,
326 go to that message and type \\[rmail-toggle-header] twice."
328 :group
'rmail-headers
)
330 (defcustom rmail-nonignored-headers
"^x-spam-status:"
331 "Regexp to match X header fields that Rmail should show.
332 This regexp overrides `rmail-ignored-headers'; if both this regexp
333 and that one match a certain header field, Rmail shows the field.
334 If this is nil, ignore all header fields in `rmail-ignored-headers'.
336 This variable is used for reformatting the message header,
337 which normally happens once for each message,
338 when you view the message for the first time in Rmail.
339 To make a change in this variable take effect
340 for a message that you have already viewed,
341 go to that message and type \\[rmail-toggle-header] twice."
342 :type
'(choice (const nil
) (regexp))
343 :group
'rmail-headers
)
346 (defcustom rmail-displayed-headers nil
347 "Regexp to match Header fields that Rmail should display.
348 If nil, display all header fields except those matched by
349 `rmail-ignored-headers'."
350 :type
'(choice regexp
(const :tag
"All"))
351 :group
'rmail-headers
)
354 (defcustom rmail-retry-ignored-headers
(purecopy "^x-authentication-warning:\\|^x-detected-operating-system:\\|^x-spam[-a-z]*:\\|content-type:\\|content-transfer-encoding:\\|mime-version:\\|message-id:")
355 "Headers that should be stripped when retrying a failed message."
356 :type
'(choice regexp
(const nil
:tag
"None"))
357 :group
'rmail-headers
358 :version
"23.2") ; added x-detected-operating-system, x-spam
361 (defcustom rmail-highlighted-headers
(purecopy "^From:\\|^Subject:")
362 "Regexp to match Header fields that Rmail should normally highlight.
363 A value of nil means don't highlight. Uses the face `rmail-highlight'."
365 :group
'rmail-headers
)
367 (defface rmail-highlight
368 '((t (:inherit highlight
)))
369 "Face to use for highlighting the most important header fields.
370 The variable `rmail-highlighted-headers' specifies which headers."
371 :group
'rmail-headers
374 ;; This was removed in Emacs 23.1 with no notification, an unnecessary
375 ;; incompatible change.
376 (defcustom rmail-highlight-face
'rmail-highlight
377 "Face used by Rmail for highlighting headers."
378 ;; Note that nil doesn't actually mean use the default face, it
379 ;; means use either bold or highlight. It's not worth fixing this
380 ;; now that this is obsolete.
381 :type
'(choice (const :tag
"Default" nil
)
383 :group
'rmail-headers
)
384 (make-obsolete-variable 'rmail-highlight-face
385 "customize the face `rmail-highlight' instead."
388 (defface rmail-header-name
389 '((t (:inherit font-lock-function-name-face
)))
390 "Face to use for highlighting the header names.
391 The variable `rmail-font-lock-keywords' specifies which headers
393 :group
'rmail-headers
396 (defcustom rmail-delete-after-output nil
397 "Non-nil means automatically delete a message that is copied to a file."
402 (defcustom rmail-primary-inbox-list nil
403 "List of files that are inboxes for your primary mail file `rmail-file-name'.
404 If this is nil, uses the environment variable MAIL. If that is
405 unset, uses a file named by the function `user-login-name' in the
406 directory `rmail-spool-directory' (whose value depends on the
407 operating system). For example, \"/var/mail/USER\"."
408 ;; Don't use backquote here, because we don't want to need it at load time.
409 ;; (That must be an old comment - it's dumped these days.)
410 :type
(list 'choice
'(const :tag
"Default" nil
)
411 (list 'repeat
':value
(list (or (getenv "MAIL")
412 (concat rmail-spool-directory
415 :group
'rmail-retrieve
418 (defcustom rmail-mail-new-frame nil
419 "Non-nil means Rmail makes a new frame for composing outgoing mail.
420 This is handy if you want to preserve the window configuration of
421 the frame where you have the RMAIL buffer displayed."
426 (defcustom rmail-secondary-file-directory
(purecopy "~/")
427 "Directory for additional secondary Rmail files."
431 (defcustom rmail-secondary-file-regexp
(purecopy "\\.xmail$")
432 "Regexp for which files are secondary Rmail files."
436 (defcustom rmail-confirm-expunge
'y-or-n-p
437 "Whether and how to ask for confirmation before expunging deleted messages.
438 The value, if non-nil is a function to call with a question (string)
439 as argument, to ask the user that question."
440 :type
'(choice (const :tag
"No confirmation" nil
)
441 (const :tag
"Confirm with y-or-n-p" y-or-n-p
)
442 (const :tag
"Confirm with yes-or-no-p" yes-or-no-p
))
445 (put 'rmail-confirm-expunge
'risky-local-variable t
)
448 (defvar rmail-mode-hook nil
449 "List of functions to call when Rmail is invoked.")
451 (defvar rmail-get-new-mail-hook nil
452 "List of functions to call when Rmail has retrieved new mail.")
455 (defcustom rmail-show-message-hook nil
456 "List of functions to call when Rmail displays a message."
458 :options
'(goto-address)
461 (defvar rmail-quit-hook nil
462 "List of functions to call when quitting out of Rmail.")
464 (defvar rmail-delete-message-hook nil
465 "List of functions to call when Rmail deletes a message.
466 When the hooks are called, the message has been marked deleted but is
467 still the current message in the Rmail buffer.")
469 ;; These may be altered by site-init.el to match the format of mmdf files
470 ;; delimiting used on a given host (delim1 and delim2 from the config
473 (defvar rmail-mmdf-delim1
"^\001\001\001\001\n"
474 "Regexp marking the start of an mmdf message.")
475 (defvar rmail-mmdf-delim2
"^\001\001\001\001\n"
476 "Regexp marking the end of an mmdf message.")
478 ;; FIXME Post-mbox, this is now unused.
479 ;; In Emacs-22, this was called:
480 ;; i) the very first time a message was shown.
481 ;; ii) when toggling the headers to the normal state, every time.
482 ;; It's not clear what it should do now, since there is nothing that
483 ;; records when a message is shown for the first time (unseen is not
484 ;; necessarily the same thing).
485 (defcustom rmail-message-filter nil
486 "If non-nil, a filter function for new messages in RMAIL.
487 Called with region narrowed to the message, including headers,
488 before obeying `rmail-ignored-headers'."
489 :group
'rmail-headers
490 :type
'(choice (const nil
) function
))
492 (defcustom rmail-automatic-folder-directives nil
493 "List of directives specifying where to put a message.
494 Each element of the list is of the form:
496 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
498 Where FOLDERNAME is the name of a folder to put the message.
499 If any of the field regexp's are nil, then it is ignored.
501 If FOLDERNAME is \"/dev/null\", it is deleted.
502 If FOLDERNAME is nil then it is deleted, and skipped.
504 FIELD is the plain text name of a field in the message, such as
505 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
506 all text from the \"cc\" field as well.
508 REGEXP is an expression to match in the preceding specified FIELD.
509 FIELD/REGEXP pairs continue in the list.
512 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
513 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS.
515 Note that this is only applied in the folder specifed by `rmail-file-name'."
518 :type
'(repeat (sexp :tag
"Directive")))
520 (defvar rmail-reply-prefix
"Re: "
521 "String to prepend to Subject line when replying to a message.")
523 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
524 ;; This pattern should catch all the common variants.
525 ;; rms: I deleted the change to delete tags in square brackets
526 ;; because they mess up RT tags.
527 (defvar rmail-reply-regexp
"\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
528 "Regexp to delete from Subject line before inserting `rmail-reply-prefix'.")
530 (defcustom rmail-display-summary nil
531 "If non-nil, Rmail always displays the summary buffer."
532 :group
'rmail-summary
535 (defvar rmail-inbox-list nil
)
536 (put 'rmail-inbox-list
'permanent-local t
)
538 (defvar rmail-buffer nil
539 "The RMAIL buffer related to the current buffer.
540 In an RMAIL buffer, this holds the RMAIL buffer itself.
541 In a summary buffer, this holds the RMAIL buffer it is a summary for.")
542 (put 'rmail-buffer
'permanent-local t
)
544 (defvar rmail-was-converted nil
545 "Non-nil in an Rmail buffer that was just converted from Babyl format.")
546 (put 'rmail-was-converted
'permanent-local t
)
548 (defvar rmail-seriously-modified nil
549 "Non-nil in an Rmail buffer that has been modified in a major way.")
550 (put 'rmail-seriously-modified
'permanent-local t
)
552 ;; Message counters and markers. Deleted flags.
554 (defvar rmail-current-message nil
555 "Integer specifying the message currently being displayed in this folder.")
556 (put 'rmail-current-message
'permanent-local t
)
558 (defvar rmail-total-messages nil
559 "Integer specifying the total number of messages in this folder.
560 Includes deleted messages.")
561 (put 'rmail-total-messages
'permanent-local t
)
563 (defvar rmail-message-vector nil
564 "Vector of markers specifying the start and end of each message.
565 Element N and N+1 specify the start and end of message N.")
566 (put 'rmail-message-vector
'permanent-local t
)
568 (defvar rmail-deleted-vector nil
569 "A string of length `rmail-total-messages' plus one.
570 Character N is either a space or \"D\", according to whether
571 message N is deleted or not.")
572 (put 'rmail-deleted-vector
'permanent-local t
)
574 (defvar rmail-msgref-vector nil
575 "In an Rmail buffer, a vector whose Nth element is a list (N).
576 When expunging renumbers messages, these lists are modified
577 by substituting the new message number into the existing list.")
578 (put 'rmail-msgref-vector
'permanent-local t
)
580 (defvar rmail-overlay-list nil
)
581 (put 'rmail-overlay-list
'permanent-local t
)
583 ;; These are used by autoloaded rmail-summary.
585 (defvar rmail-summary-buffer nil
)
586 (put 'rmail-summary-buffer
'permanent-local t
)
587 (defvar rmail-summary-vector nil
588 "In an Rmail buffer, vector of (newline-terminated) strings.
589 Element N specifies the summary line for message N+1.")
590 (put 'rmail-summary-vector
'permanent-local t
)
592 ;; Rmail buffer swapping variables.
594 (defvar rmail-buffer-swapped nil
595 "If non-nil, `rmail-buffer' is swapped with `rmail-view-buffer'.")
596 (make-variable-buffer-local 'rmail-buffer-swapped
)
597 (put 'rmail-buffer-swapped
'permanent-local t
)
599 (defvar rmail-view-buffer nil
600 "Buffer which holds RMAIL message for MIME displaying.")
601 (make-variable-buffer-local 'rmail-view-buffer
)
602 (put 'rmail-view-buffer
'permanent-local t
)
604 ;; `Sticky' default variables.
606 ;; Last individual label specified to a or k.
607 (defvar rmail-last-label nil
)
609 ;; Last set of values specified to C-M-n, C-M-p, C-M-s or C-M-l.
610 (defvar rmail-last-multi-labels nil
)
612 (defvar rmail-last-regexp nil
)
613 (put 'rmail-last-regexp
'permanent-local t
)
615 (defcustom rmail-default-file
"~/xmail"
616 "Default file name for \\[rmail-output]."
619 (defcustom rmail-default-body-file
"~/mailout"
620 "Default file name for \\[rmail-output-body-to-file]."
625 ;; Mule and MIME related variables.
628 (defvar rmail-file-coding-system nil
629 "Coding system used in RMAIL file.
631 This is set to nil by default.")
633 (defcustom rmail-enable-mime t
634 "If non-nil, RMAIL automatically displays decoded MIME messages.
635 For this to work, the feature specified by `rmail-mime-feature' must
641 (defvar rmail-enable-mime-composing t
642 "*If non-nil, RMAIL uses `rmail-insert-mime-forwarded-message-function' to forward.")
644 (defvar rmail-show-mime-function nil
645 "Function of no argument called to show a decoded MIME message.
646 This function is called when `rmail-enable-mime' is non-nil.
647 The package providing MIME support should set this.")
650 (defvar rmail-insert-mime-forwarded-message-function nil
651 "Function to insert a message in MIME format so it can be forwarded.
652 This function is called if `rmail-enable-mime' or
653 `rmail-enable-mime-composing' is non-nil.
654 It is called with one argument FORWARD-BUFFER, which is a
655 buffer containing the message to forward. The current buffer
656 is the outgoing mail buffer.")
658 (defvar rmail-insert-mime-resent-message-function nil
659 "Function to insert a message in MIME format so it can be resent.
660 This function is called by `rmail-resend' if `rmail-enable-mime' is non-nil.
661 It is called with one argument FORWARD-BUFFER, which is a
662 buffer containing the message to forward. The current buffer
663 is the outgoing mail buffer.")
665 ;; FIXME one might want to pass a LIMIT, as per
666 ;; rmail-search-mime-header-function.
667 (defvar rmail-search-mime-message-function nil
668 "Function to check if a regexp matches a MIME message.
669 This function is called by `rmail-search-message' if
670 `rmail-enable-mime' is non-nil. It is called (with point at the
671 start of the message) with two arguments MSG and REGEXP, where
672 MSG is the message number, REGEXP is the regular expression.")
674 (defvar rmail-search-mime-header-function nil
675 "Function to check if a regexp matches a header of MIME message.
676 This function is called by `rmail-message-regexp-p-1' if
677 `rmail-enable-mime' is non-nil. It is called (with point at the
678 start of the header) with three arguments MSG, REGEXP, and LIMIT,
679 where MSG is the message number, REGEXP is the regular
680 expression, LIMIT is the position specifying the end of header.")
682 (defvar rmail-mime-feature
'rmailmm
683 "Feature to require for MIME support in Rmail.
684 When starting Rmail, if `rmail-enable-mime' is non-nil,
685 this feature is required with `require'.
687 The default value is `rmailmm'")
689 ;; FIXME this is unused.
690 (defvar rmail-decode-mime-charset t
691 "*Non-nil means a message is decoded by MIME's charset specification.
692 If this variable is nil, or the message has not MIME specification,
693 the message is decoded as normal way.
695 If the variable `rmail-enable-mime' is non-nil, this variable is
696 ignored, and all the decoding work is done by a feature specified by
697 the variable `rmail-mime-feature'.")
699 (defvar rmail-mime-charset-pattern
700 (concat "^content-type:[ \t]*text/plain;"
701 "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
702 "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
703 "Regexp to match MIME-charset specification in a header of message.
704 The first parenthesized expression should match the MIME-charset name.")
707 (defvar rmail-unix-mail-delimiter
708 (let ((time-zone-regexp
709 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
710 "\\|[-+]?[0-9][0-9][0-9][0-9]"
716 ;; Many things can happen to an RFC 822 mailbox before it is put into
717 ;; a `From' line. The leading phrase can be stripped, e.g.
718 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
719 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
720 ;; can be removed, e.g.
721 ;; From: joe@y.z (Joe K
723 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
726 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
727 ;; The mailbox can be removed or be replaced by white space, e.g.
728 ;; From: "Joe User"{space}{tab}
730 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
731 ;; where {space} and {tab} represent the Ascii space and tab characters.
732 ;; We want to match the results of any of these manglings.
733 ;; The following regexp rejects names whose first characters are
734 ;; obviously bogus, but after that anything goes.
735 "\\([^\0-\b\n-\r\^?].*\\)? "
737 ;; The time the message was sent.
738 "\\([^\0-\r \^?]+\\) +" ; day of the week
739 "\\([^\0-\r \^?]+\\) +" ; month
740 "\\([0-3]?[0-9]\\) +" ; day of month
741 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
743 ;; Perhaps a time zone, specified by an abbreviation, or by a
748 " \\([0-9][0-9]+\\) *"
750 ;; On some systems the time zone can appear after the year, too.
754 "\\(remote from .*\\)?"
757 "Regexp matching the delimiter of messages in UNIX mail format
758 \(UNIX From lines), minus the initial ^. Note that if you change
759 this expression, you must change the code in `rmail-nuke-pinhead-header'
760 that knows the exact ordering of the \\( \\) subexpressions.")
762 ;; FIXME the rmail-header-name headers ought to be customizable.
763 ;; It seems a bit arbitrary, for example, that all of the Date: line
765 (defvar rmail-font-lock-keywords
766 ;; These are all matched case-insensitively.
768 (let* ((cite-chars "[>|}]")
770 (cite-suffix (concat cite-prefix
"0-9_.@-`'\"")))
771 (list '("^\\(From\\|Sender\\|Resent-From\\):"
772 .
'rmail-header-name
)
773 '("^\\(Mail-\\)?Reply-To:.*$" .
'rmail-header-name
)
774 ;; FIXME Mail-Followup-To should probably be here too.
775 '("^Subject:" .
'rmail-header-name
)
776 '("^X-Spam-Status:" .
'rmail-header-name
)
777 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
778 .
'rmail-header-name
)
779 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
781 (,(concat "\\=[ \t]*"
782 "\\(\\(\\([" cite-prefix
"]+[" cite-suffix
"]*\\)?"
783 "\\(" cite-chars
"[ \t]*\\)\\)+\\)"
785 (beginning-of-line) (end-of-line)
786 (1 font-lock-comment-delimiter-face nil t
)
787 (5 font-lock-comment-face nil t
)))
788 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
789 .
'rmail-header-name
))))
790 "Additional expressions to highlight in Rmail mode.")
792 ;; Rmail does not expect horizontal splitting. (Bug#2282)
793 (defun rmail-pop-to-buffer (&rest args
)
794 "Like `pop-to-buffer', but with `split-width-threshold' set to nil."
795 (let (split-width-threshold)
796 (apply 'pop-to-buffer args
)))
798 ;; Perform BODY in the summary buffer
799 ;; in such a way that its cursor is properly updated in its own window.
800 (defmacro rmail-select-summary
(&rest body
)
801 `(let ((total rmail-total-messages
))
802 (if (rmail-summary-displayed)
803 (let ((window (selected-window)))
807 (rmail-pop-to-buffer rmail-summary-buffer
)
808 ;; rmail-total-messages is a buffer-local var
809 ;; in the rmail buffer.
810 ;; This way we make it available for the body
811 ;; even tho the rmail buffer is not current.
812 (let ((rmail-total-messages total
))
814 (select-window window
))))
815 (with-current-buffer rmail-summary-buffer
816 (let ((rmail-total-messages total
))
818 (rmail-maybe-display-summary)))
820 ;;;; *** Rmail Mode ***
822 (defun rmail-require-mime-maybe ()
823 "Require `rmail-mime-feature' if that is non-nil.
824 Signal an error and set `rmail-mime-feature' to nil if the feature
826 (when rmail-enable-mime
828 (require rmail-mime-feature
)
832 (format "Although MIME support is requested
833 through `rmail-enable-mime' being non-nil, the required feature
834 `%s' (the value of `rmail-mime-feature')
835 is not available in the current session.
836 So, MIME support is turned off for the moment."
839 (setq rmail-enable-mime nil
)))))
843 (defun rmail (&optional file-name-arg
)
844 "Read and edit incoming mail.
845 Moves messages into file named by `rmail-file-name' and edits that
847 Type \\[describe-mode] once editing that file, for a list of RMAIL commands.
849 May be called with file name as argument; then performs rmail editing on
850 that file, but does not copy any new mail into the file.
851 Interactively, if you supply a prefix argument, then you
852 have a chance to specify a file name with the minibuffer.
854 If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
855 (interactive (if current-prefix-arg
856 (list (read-file-name "Run rmail on RMAIL file: "))))
857 (rmail-require-mime-maybe)
858 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name
)))
859 ;; Use find-buffer-visiting, not get-file-buffer, for those users
860 ;; who have find-file-visit-truename set to t.
861 (existed (find-buffer-visiting file-name
))
862 run-mail-hook mail-buf msg-shown
)
863 ;; Determine if an existing mail file has been changed behind the
865 (if (and existed
(not (verify-visited-file-modtime existed
)))
866 ;; The mail file has been changed. Revisit it and reset the
867 ;; message state variables when in rmail mode.
869 (find-file file-name
)
870 (when (and (verify-visited-file-modtime existed
)
871 (eq major-mode
'rmail-mode
))
872 (rmail-swap-buffers-maybe)
873 (rmail-set-message-counters)))
874 ;; The mail file is either unchanged or not visited. Visit it.
876 (let ((enable-local-variables nil
)
877 ;; Force no-conversion by default, since that's what
878 ;; pre-mbox Rmail did with BABYL files (via
879 ;; auto-coding-regexp-alist).
880 (coding-system-for-read
881 (or coding-system-for-read
'no-conversion
)))
882 (find-file-noselect file-name
))))
883 ;; Ensure that the collection and view buffers are in sync and
884 ;; ensure that a message is not being edited.
885 (if (eq major-mode
'rmail-mode
)
886 (rmail-swap-buffers-maybe))
887 (if (eq major-mode
'rmail-edit-mode
)
888 (error "Exit Rmail Edit mode before getting new mail"))
889 (or (and existed
(> (buffer-size) 0))
890 (setq run-mail-hook t
))
891 ;; Ensure that the Rmail file is in mbox format, the buffer is in
892 ;; Rmail mode and has been scanned to find all the messages
893 ;; (setting the global message variables in the process).
894 (rmail-convert-file-maybe)
895 (unless (eq major-mode
'rmail-mode
)
897 (goto-char (point-max))
898 (rmail-maybe-set-message-counters)
899 (setq mail-buf rmail-buffer
)
900 ;; Show the first unread message and process summary mode.
902 ;; Only get new mail when there is not a file name argument.
903 (unless file-name-arg
904 (setq msg-shown
(rmail-get-new-mail)))
906 (set-buffer mail-buf
)
908 (rmail-show-message (rmail-first-unseen-message)))
909 (if rmail-display-summary
(rmail-summary))
910 (rmail-construct-io-menu)
912 (run-hooks 'rmail-mode-hook
))))))
914 (defun rmail-convert-file-maybe ()
915 "Determine if the file needs to be converted to mbox format."
917 (goto-char (point-min))
918 ;; Detect previous Babyl format files.
919 (let ((case-fold-search nil
))
920 (cond ((looking-at "BABYL OPTIONS:")
921 ;; The file is Babyl version 5. Use unrmail to convert
923 (rmail-convert-babyl-to-mbox))
924 ((looking-at "Version: 5\n")
925 ;; Losing babyl file made by old version of Rmail. Fix the
926 ;; babyl file header and use unrmail to convert to mbox
928 (let ((buffer-read-only nil
))
929 (insert "BABYL OPTIONS: -*- rmail -*-\n")
930 (rmail-convert-babyl-to-mbox)))
931 ((equal (point-min) (point-max))
932 (message "Empty Rmail file."))
933 ((looking-at "From "))
934 (t (error "Invalid mbox file")))))
936 (defun rmail-error-bad-format (&optional msgnum
)
937 "Report that the buffer is not in the mbox file format.
938 MSGNUM, if present, indicates the malformed message."
940 (error "Message %d is not a valid RFC2822 message" msgnum
)
941 (error "Message is not a valid RFC2822 message")))
943 (defun rmail-convert-babyl-to-mbox ()
944 "Convert the mail file from Babyl version 5 to mbox.
945 This function also reinitializes local variables used by Rmail."
946 (let ((old-file (make-temp-file "rmail"))
947 (new-file (make-temp-file "rmail")))
950 (kill-all-local-variables)
951 (write-region (point-min) (point-max) old-file
)
952 (unrmail old-file new-file
)
953 (message "Replacing BABYL format with mbox format...")
954 (let ((inhibit-read-only t
)
955 (coding-system-for-read 'raw-text
)
956 (buffer-undo-list t
))
958 (insert-file-contents new-file
)
959 ;; Rmail buffers need to be saved with Unix EOLs, or else
960 ;; the format will not be recognized.
961 (set-buffer-file-coding-system 'raw-text-unix
)
963 (rmail-perm-variables)
965 (setq rmail-was-converted t
)
966 (rmail-dont-modify-format)
967 (goto-char (point-max))
968 (rmail-set-message-counters))
969 (message "Replacing BABYL format with mbox format...done"))
970 (delete-file old-file
)
971 (delete-file new-file
))))
973 (defun rmail-get-coding-system ()
974 "Return a suitable coding system to use for the current mail message.
975 The buffer is expected to be narrowed to just the header of the message."
977 (goto-char (point-min))
978 (if (re-search-forward rmail-mime-charset-pattern nil t
)
979 (coding-system-from-name (match-string 1))
982 ;;; Set up Rmail mode keymaps
984 (defvar rmail-mode-map
985 (let ((map (make-keymap)))
986 (suppress-keymap map
)
987 (define-key map
"a" 'rmail-add-label
)
988 (define-key map
"b" 'rmail-bury
)
989 (define-key map
"c" 'rmail-continue
)
990 (define-key map
"d" 'rmail-delete-forward
)
991 (define-key map
"\C-d" 'rmail-delete-backward
)
992 (define-key map
"e" 'rmail-edit-current-message
)
993 ;; If you change this, change the rmail-resend menu-item's :keys.
994 (define-key map
"f" 'rmail-forward
)
995 (define-key map
"g" 'rmail-get-new-mail
)
996 (define-key map
"h" 'rmail-summary
)
997 (define-key map
"i" 'rmail-input
)
998 (define-key map
"j" 'rmail-show-message
)
999 (define-key map
"k" 'rmail-kill-label
)
1000 (define-key map
"l" 'rmail-summary-by-labels
)
1001 (define-key map
"\e\C-h" 'rmail-summary
)
1002 (define-key map
"\e\C-l" 'rmail-summary-by-labels
)
1003 (define-key map
"\e\C-r" 'rmail-summary-by-recipients
)
1004 (define-key map
"\e\C-s" 'rmail-summary-by-regexp
)
1005 (define-key map
"\e\C-f" 'rmail-summary-by-senders
)
1006 (define-key map
"\e\C-t" 'rmail-summary-by-topic
)
1007 (define-key map
"m" 'rmail-mail
)
1008 (define-key map
"\em" 'rmail-retry-failure
)
1009 (define-key map
"n" 'rmail-next-undeleted-message
)
1010 (define-key map
"\en" 'rmail-next-message
)
1011 (define-key map
"\e\C-n" 'rmail-next-labeled-message
)
1012 (define-key map
"o" 'rmail-output
)
1013 (define-key map
"\C-o" 'rmail-output-as-seen
)
1014 (define-key map
"p" 'rmail-previous-undeleted-message
)
1015 (define-key map
"\ep" 'rmail-previous-message
)
1016 (define-key map
"\e\C-p" 'rmail-previous-labeled-message
)
1017 (define-key map
"q" 'rmail-quit
)
1018 (define-key map
"r" 'rmail-reply
)
1019 ;; I find I can't live without the default M-r command -- rms.
1020 ;; (define-key rmail-mode-map "\er" 'rmail-search-backwards)
1021 (define-key map
"s" 'rmail-expunge-and-save
)
1022 (define-key map
"\es" 'rmail-search
)
1023 (define-key map
"t" 'rmail-toggle-header
)
1024 (define-key map
"u" 'rmail-undelete-previous-message
)
1025 (define-key map
"v" 'rmail-mime
)
1026 (define-key map
"w" 'rmail-output-body-to-file
)
1027 (define-key map
"\C-c\C-w" 'rmail-widen
)
1028 (define-key map
"x" 'rmail-expunge
)
1029 (define-key map
"." 'rmail-beginning-of-message
)
1030 (define-key map
"/" 'rmail-end-of-message
)
1031 (define-key map
"<" 'rmail-first-message
)
1032 (define-key map
">" 'rmail-last-message
)
1033 (define-key map
" " 'scroll-up-command
)
1034 (define-key map
"\177" 'scroll-down-command
)
1035 (define-key map
"?" 'describe-mode
)
1036 (define-key map
"\C-c\C-s\C-d" 'rmail-sort-by-date
)
1037 (define-key map
"\C-c\C-s\C-s" 'rmail-sort-by-subject
)
1038 (define-key map
"\C-c\C-s\C-a" 'rmail-sort-by-author
)
1039 (define-key map
"\C-c\C-s\C-r" 'rmail-sort-by-recipient
)
1040 (define-key map
"\C-c\C-s\C-c" 'rmail-sort-by-correspondent
)
1041 (define-key map
"\C-c\C-s\C-l" 'rmail-sort-by-lines
)
1042 (define-key map
"\C-c\C-s\C-k" 'rmail-sort-by-labels
)
1043 (define-key map
"\C-c\C-n" 'rmail-next-same-subject
)
1044 (define-key map
"\C-c\C-p" 'rmail-previous-same-subject
)
1047 (define-key map
[menu-bar
] (make-sparse-keymap))
1049 (define-key map
[menu-bar classify
]
1050 (cons "Classify" (make-sparse-keymap "Classify")))
1052 (define-key map
[menu-bar classify input-menu
]
1055 (define-key map
[menu-bar classify output-menu
]
1058 (define-key map
[menu-bar classify output-body
]
1059 '("Output body to file..." . rmail-output-body-to-file
))
1061 (define-key map
[menu-bar classify output-inbox
]
1062 '("Output..." . rmail-output
))
1064 (define-key map
[menu-bar classify output
]
1065 '("Output as seen..." . rmail-output-as-seen
))
1067 (define-key map
[menu-bar classify kill-label
]
1068 '("Kill Label..." . rmail-kill-label
))
1070 (define-key map
[menu-bar classify add-label
]
1071 '("Add Label..." . rmail-add-label
))
1073 (define-key map
[menu-bar summary
]
1074 (cons "Summary" (make-sparse-keymap "Summary")))
1076 (define-key map
[menu-bar summary senders
]
1077 '("By Senders..." . rmail-summary-by-senders
))
1079 (define-key map
[menu-bar summary labels
]
1080 '("By Labels..." . rmail-summary-by-labels
))
1082 (define-key map
[menu-bar summary recipients
]
1083 '("By Recipients..." . rmail-summary-by-recipients
))
1085 (define-key map
[menu-bar summary topic
]
1086 '("By Topic..." . rmail-summary-by-topic
))
1088 (define-key map
[menu-bar summary regexp
]
1089 '("By Regexp..." . rmail-summary-by-regexp
))
1091 (define-key map
[menu-bar summary all
]
1092 '("All" . rmail-summary
))
1094 (define-key map
[menu-bar mail
]
1095 (cons "Mail" (make-sparse-keymap "Mail")))
1097 (define-key map
[menu-bar mail rmail-get-new-mail
]
1098 '("Get New Mail" . rmail-get-new-mail
))
1100 (define-key map
[menu-bar mail lambda
]
1103 (define-key map
[menu-bar mail continue
]
1104 '("Continue" . rmail-continue
))
1106 (define-key map
[menu-bar mail resend
]
1107 '(menu-item "Resend..." rmail-resend
:keys
"C-u f"))
1109 (define-key map
[menu-bar mail forward
]
1110 '("Forward" . rmail-forward
))
1112 (define-key map
[menu-bar mail retry
]
1113 '("Retry" . rmail-retry-failure
))
1115 (define-key map
[menu-bar mail reply
]
1116 '("Reply" . rmail-reply
))
1118 (define-key map
[menu-bar mail mail
]
1119 '("Mail" . rmail-mail
))
1121 (define-key map
[menu-bar delete
]
1122 (cons "Delete" (make-sparse-keymap "Delete")))
1124 (define-key map
[menu-bar delete expunge
/save
]
1125 '("Expunge/Save" . rmail-expunge-and-save
))
1127 (define-key map
[menu-bar delete expunge
]
1128 '("Expunge" . rmail-expunge
))
1130 (define-key map
[menu-bar delete undelete
]
1131 '("Undelete" . rmail-undelete-previous-message
))
1133 (define-key map
[menu-bar delete delete
]
1134 '("Delete" . rmail-delete-forward
))
1136 (define-key map
[menu-bar move
]
1137 (cons "Move" (make-sparse-keymap "Move")))
1139 (define-key map
[menu-bar move search-back
]
1140 '("Search Back..." . rmail-search-backwards
))
1142 (define-key map
[menu-bar move search
]
1143 '("Search..." . rmail-search
))
1145 (define-key map
[menu-bar move previous
]
1146 '("Previous Nondeleted" . rmail-previous-undeleted-message
))
1148 (define-key map
[menu-bar move next
]
1149 '("Next Nondeleted" . rmail-next-undeleted-message
))
1151 (define-key map
[menu-bar move last
]
1152 '("Last" . rmail-last-message
))
1154 (define-key map
[menu-bar move first
]
1155 '("First" . rmail-first-message
))
1157 (define-key map
[menu-bar move previous
]
1158 '("Previous" . rmail-previous-message
))
1160 (define-key map
[menu-bar move next
]
1161 '("Next" . rmail-next-message
))
1164 "Keymap used in Rmail mode.")
1167 (defvar rmail-tool-bar-map
1168 (let ((map (make-sparse-keymap)))
1169 (tool-bar-local-item-from-menu 'rmail-get-new-mail
"mail/inbox"
1171 (tool-bar-local-item-from-menu 'rmail-next-undeleted-message
"right-arrow"
1173 (tool-bar-local-item-from-menu 'rmail-previous-undeleted-message
"left-arrow"
1175 (tool-bar-local-item-from-menu 'rmail-search
"search"
1177 (tool-bar-local-item-from-menu 'rmail-input
"open"
1179 (tool-bar-local-item-from-menu 'rmail-mail
"mail/compose"
1181 (tool-bar-local-item-from-menu 'rmail-reply
"mail/reply-all"
1183 (tool-bar-local-item-from-menu 'rmail-forward
"mail/forward"
1185 (tool-bar-local-item-from-menu 'rmail-delete-forward
"close"
1187 (tool-bar-local-item-from-menu 'rmail-output
"mail/move"
1189 (tool-bar-local-item-from-menu 'rmail-output-body-to-file
"mail/save"
1191 (tool-bar-local-item-from-menu 'rmail-expunge
"delete"
1197 ;; Rmail mode is suitable only for specially formatted data.
1198 (put 'rmail-mode
'mode-class
'special
)
1200 (defun rmail-mode-kill-summary ()
1201 (if rmail-summary-buffer
(kill-buffer rmail-summary-buffer
)))
1203 (defvar rmail-enable-multibyte
) ; dynamically bound
1206 (defun rmail-mode ()
1207 "Rmail Mode is used by \\<rmail-mode-map>\\[rmail] for editing Rmail files.
1208 All normal editing commands are turned off.
1209 Instead, these commands are available:
1211 \\[rmail-beginning-of-message] Move point to front of this message.
1212 \\[rmail-end-of-message] Move point to bottom of this message.
1213 \\[scroll-up] Scroll to next screen of this message.
1214 \\[scroll-down] Scroll to previous screen of this message.
1215 \\[rmail-next-undeleted-message] Move to Next non-deleted message.
1216 \\[rmail-previous-undeleted-message] Move to Previous non-deleted message.
1217 \\[rmail-next-message] Move to Next message whether deleted or not.
1218 \\[rmail-previous-message] Move to Previous message whether deleted or not.
1219 \\[rmail-first-message] Move to the first message in Rmail file.
1220 \\[rmail-last-message] Move to the last message in Rmail file.
1221 \\[rmail-show-message] Jump to message specified by numeric position in file.
1222 \\[rmail-search] Search for string and show message it is found in.
1223 \\[rmail-delete-forward] Delete this message, move to next nondeleted.
1224 \\[rmail-delete-backward] Delete this message, move to previous nondeleted.
1225 \\[rmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1226 till a deleted message is found.
1227 \\[rmail-edit-current-message] Edit the current message. \\[rmail-cease-edit] to return to Rmail.
1228 \\[rmail-expunge] Expunge deleted messages.
1229 \\[rmail-expunge-and-save] Expunge and save the file.
1230 \\[rmail-quit] Quit Rmail: expunge, save, then switch to another buffer.
1231 \\[save-buffer] Save without expunging.
1232 \\[rmail-get-new-mail] Move new mail from system spool directory into this file.
1233 \\[rmail-mail] Mail a message (same as \\[mail-other-window]).
1234 \\[rmail-continue] Continue composing outgoing message started before.
1235 \\[rmail-reply] Reply to this message. Like \\[rmail-mail] but initializes some fields.
1236 \\[rmail-retry-failure] Send this message again. Used on a mailer failure message.
1237 \\[rmail-forward] Forward this message to another user.
1238 \\[rmail-output] Output (append) this message to another mail file.
1239 \\[rmail-output-as-seen] Output (append) this message to file as it's displayed.
1240 \\[rmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1241 \\[rmail-input] Input Rmail file. Run Rmail on that file.
1242 \\[rmail-add-label] Add label to message. It will be displayed in the mode line.
1243 \\[rmail-kill-label] Kill label. Remove a label from current message.
1244 \\[rmail-next-labeled-message] Move to Next message with specified label
1245 (label defaults to last one specified).
1246 Standard labels: filed, unseen, answered, forwarded, deleted.
1247 Any other label is present only if you add it with \\[rmail-add-label].
1248 \\[rmail-previous-labeled-message] Move to Previous message with specified label
1249 \\[rmail-summary] Show headers buffer, with a one line summary of each message.
1250 \\[rmail-summary-by-labels] Summarize only messages with particular label(s).
1251 \\[rmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1252 \\[rmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1253 \\[rmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1254 \\[rmail-toggle-header] Toggle display of complete header."
1256 (let ((finding-rmail-file (not (eq major-mode
'rmail-mode
))))
1258 (when (and finding-rmail-file
1259 (null coding-system-for-read
)
1260 (default-value 'enable-multibyte-characters
))
1261 (let ((rmail-enable-multibyte t
))
1262 (rmail-require-mime-maybe)
1263 (rmail-convert-file-maybe)
1264 (goto-char (point-max))
1265 (set-buffer-multibyte t
)))
1266 (rmail-set-message-counters)
1267 (rmail-show-message rmail-total-messages
)
1268 (when finding-rmail-file
1269 (when rmail-display-summary
1271 (rmail-construct-io-menu))
1272 (run-mode-hooks 'rmail-mode-hook
)))
1274 (defun rmail-mode-2 ()
1275 (kill-all-local-variables)
1277 (rmail-perm-variables)
1280 (defun rmail-mode-1 ()
1281 (setq major-mode
'rmail-mode
)
1282 (setq mode-name
"RMAIL")
1283 (setq buffer-read-only t
)
1284 ;; No need to auto save RMAIL files in normal circumstances
1285 ;; because they contain no info except attribute changes
1286 ;; and deletion of messages.
1287 ;; The one exception is when messages are copied into another mbox buffer.
1288 ;; rmail-output enables auto save when you do that.
1289 (setq buffer-auto-save-file-name nil
)
1290 (use-local-map rmail-mode-map
)
1291 (set-syntax-table text-mode-syntax-table
)
1292 (setq local-abbrev-table text-mode-abbrev-table
)
1293 ;; Functions to support buffer swapping:
1294 (add-hook 'write-region-annotate-functions
1295 'rmail-write-region-annotate nil t
)
1296 (add-hook 'kill-buffer-hook
'rmail-mode-kill-buffer-hook nil t
)
1297 (add-hook 'change-major-mode-hook
'rmail-change-major-mode-hook nil t
))
1299 (defun rmail-generate-viewer-buffer ()
1300 "Return a reusable buffer suitable for viewing messages.
1301 Create the buffer if necessary."
1302 ;; We want to reuse any existing view buffer, so as not to create an
1303 ;; endless number of them. But we must avoid clashes if we visit
1304 ;; two different rmail files with the same basename (Bug#4593).
1305 (if (and (local-variable-p 'rmail-view-buffer
)
1306 (buffer-live-p rmail-view-buffer
))
1309 (generate-new-buffer
1310 (format " *message-viewer %s*"
1311 (file-name-nondirectory
1312 (or buffer-file-name
(buffer-name)))))))
1313 (with-current-buffer newbuf
1314 (add-hook 'kill-buffer-hook
'rmail-view-buffer-kill-buffer-hook nil t
))
1317 (defun rmail-swap-buffers ()
1318 "Swap text between current buffer and `rmail-view-buffer'.
1319 This function preserves the current buffer's modified flag, and also
1320 sets the current buffer's `buffer-file-coding-system' to that of
1321 `rmail-view-buffer'."
1322 (let ((modp-this (buffer-modified-p))
1324 (with-current-buffer rmail-view-buffer
(buffer-modified-p)))
1325 (coding-this buffer-file-coding-system
)
1327 (with-current-buffer rmail-view-buffer
1328 buffer-file-coding-system
)))
1329 (buffer-swap-text rmail-view-buffer
)
1330 (setq buffer-file-coding-system coding-that
)
1331 (with-current-buffer rmail-view-buffer
1332 (setq buffer-file-coding-system coding-this
)
1333 (restore-buffer-modified-p modp-that
))
1334 (restore-buffer-modified-p modp-this
)))
1336 (defun rmail-buffers-swapped-p ()
1337 "Return non-nil if the message collection is in `rmail-view-buffer'."
1338 ;; This is analogous to tar-data-swapped-p in tar-mode.el.
1339 (and (buffer-live-p rmail-view-buffer
)
1340 rmail-buffer-swapped
))
1342 (defun rmail-change-major-mode-hook ()
1343 ;; Bring the actual Rmail messages back into the main buffer.
1344 (when (rmail-buffers-swapped-p)
1345 (rmail-swap-buffers)
1346 (setq rmail-buffer-swapped nil
)))
1348 (defun rmail-swap-buffers-maybe ()
1349 "Determine if the Rmail buffer is showing a message.
1350 If so restore the actual mbox message collection."
1351 (with-current-buffer rmail-buffer
1352 (when (rmail-buffers-swapped-p)
1353 (rmail-swap-buffers)
1354 (setq rmail-buffer-swapped nil
))))
1356 (defun rmail-modify-format ()
1357 "Warn if important modifications would change Rmail file's format."
1358 (with-current-buffer rmail-buffer
1359 (and rmail-was-converted
1360 ;; If it's already modified, don't warn again.
1361 (not rmail-seriously-modified
)
1364 (message "After this, %s would be saved in mbox format. Proceed? "
1367 (setq rmail-seriously-modified t
)))
1369 (defun rmail-dont-modify-format ()
1370 (when (and rmail-was-converted
(not rmail-seriously-modified
))
1371 (set-buffer-modified-p nil
)
1372 (message "Marking buffer unmodified to avoid rewriting Babyl file as mbox file")))
1374 (defun rmail-mode-kill-buffer-hook ()
1375 ;; Turn off the hook on the view buffer, so we can kill it, then kill it.
1376 (if (buffer-live-p rmail-view-buffer
)
1377 (with-current-buffer rmail-view-buffer
1378 (setq kill-buffer-hook nil
)
1379 (kill-buffer rmail-view-buffer
))))
1381 (defun rmail-view-buffer-kill-buffer-hook ()
1382 (error "Can't kill message view buffer by itself"))
1384 ;; Set up the permanent locals associated with an Rmail file.
1385 (defun rmail-perm-variables ()
1386 (make-local-variable 'rmail-last-regexp
)
1387 (make-local-variable 'rmail-deleted-vector
)
1388 (make-local-variable 'rmail-buffer
)
1389 (make-local-variable 'rmail-was-converted
)
1390 (setq rmail-was-converted nil
)
1391 (make-local-variable 'rmail-seriously-modified
)
1392 (setq rmail-seriously-modified nil
)
1393 (setq rmail-buffer
(current-buffer))
1394 (set-buffer-multibyte nil
)
1395 (with-current-buffer (setq rmail-view-buffer
(rmail-generate-viewer-buffer))
1396 (setq buffer-undo-list t
)
1397 ;; Note that this does not erase the buffer. Should it?
1398 ;; It depends on how this is called. If somehow called with the
1399 ;; rmail buffers swapped, it would erase the message collection.
1400 (set (make-local-variable 'rmail-overlay-list
) nil
)
1401 (set-buffer-multibyte t
)
1402 ;; Force C-x C-s write Unix EOLs.
1403 (set-buffer-file-coding-system 'undecided-unix
))
1404 (make-local-variable 'rmail-summary-buffer
)
1405 (make-local-variable 'rmail-summary-vector
)
1406 (make-local-variable 'rmail-current-message
)
1407 (make-local-variable 'rmail-total-messages
)
1408 (setq rmail-total-messages
0)
1409 (make-local-variable 'rmail-message-vector
)
1410 (make-local-variable 'rmail-msgref-vector
)
1411 (make-local-variable 'rmail-inbox-list
)
1412 ;; Provide default set of inboxes for primary mail file ~/RMAIL.
1413 (and (null rmail-inbox-list
)
1414 (or (equal buffer-file-name
(expand-file-name rmail-file-name
))
1415 (equal buffer-file-truename
1416 (abbreviate-file-name (file-truename rmail-file-name
))))
1417 (setq rmail-inbox-list
1418 (or rmail-primary-inbox-list
1419 (list (or (getenv "MAIL")
1420 ;; FIXME expand-file-name?
1421 (concat rmail-spool-directory
1422 (user-login-name)))))))
1423 (set (make-local-variable 'tool-bar-map
) rmail-tool-bar-map
))
1425 ;; Set up the non-permanent locals associated with Rmail mode.
1426 (defun rmail-variables ()
1427 ;; Turn off undo. We turn it back on in rmail-edit.
1428 (setq buffer-undo-list t
)
1429 ;; Don't let a local variables list in a message cause confusion.
1430 (make-local-variable 'local-enable-local-variables
)
1431 (setq local-enable-local-variables nil
)
1432 ;; Don't turn off auto-saving based on the size of the buffer
1433 ;; because that code does not understand buffer-swapping.
1434 (make-local-variable 'auto-save-include-big-deletions
)
1435 (setq auto-save-include-big-deletions t
)
1436 (make-local-variable 'revert-buffer-function
)
1437 (setq revert-buffer-function
'rmail-revert
)
1438 (make-local-variable 'font-lock-defaults
)
1439 (setq font-lock-defaults
1440 '(rmail-font-lock-keywords
1442 (font-lock-maximum-size . nil
)
1443 (font-lock-fontify-buffer-function . rmail-fontify-buffer-function
)
1444 (font-lock-unfontify-buffer-function . rmail-unfontify-buffer-function
)
1445 (font-lock-inhibit-thing-lock .
(lazy-lock-mode fast-lock-mode
))))
1446 (make-local-variable 'require-final-newline
)
1447 (setq require-final-newline nil
)
1448 (make-local-variable 'version-control
)
1449 (setq version-control
'never
)
1450 (make-local-variable 'kill-buffer-hook
)
1451 (add-hook 'kill-buffer-hook
'rmail-mode-kill-summary
)
1452 (make-local-variable 'file-precious-flag
)
1453 (setq file-precious-flag t
)
1454 (make-local-variable 'desktop-save-buffer
)
1455 (setq desktop-save-buffer t
)
1456 (setq next-error-move-function
'rmail-next-error-move
))
1458 ;; Handle M-x revert-buffer done in an rmail-mode buffer.
1459 (defun rmail-revert (arg noconfirm
)
1460 (set-buffer rmail-buffer
)
1461 (let* ((revert-buffer-function (default-value 'revert-buffer-function
))
1462 (rmail-enable-multibyte enable-multibyte-characters
)
1463 ;; See similar code in `rmail'.
1464 ;; FIXME needs updating?
1465 (coding-system-for-read (and rmail-enable-multibyte
'raw-text
))
1466 (before-revert-hook 'rmail-swap-buffers-maybe
))
1467 ;; Call our caller again, but this time it does the default thing.
1468 (when (revert-buffer arg noconfirm
)
1469 ;; If the user said "yes", and we changed something,
1470 ;; reparse the messages.
1471 (set-buffer rmail-buffer
)
1473 ;; Convert all or part to Babyl file if possible.
1474 (rmail-convert-file-maybe)
1475 ;; We have read the file as raw-text, so the buffer is set to
1476 ;; unibyte. Make it multibyte if necessary.
1477 (if (and rmail-enable-multibyte
1478 (not enable-multibyte-characters
))
1479 (set-buffer-multibyte t
))
1480 (goto-char (point-max))
1481 (rmail-set-message-counters)
1482 (rmail-show-message rmail-total-messages
)
1483 (run-hooks 'rmail-mode-hook
))))
1485 (defun rmail-expunge-and-save ()
1486 "Expunge and save RMAIL file."
1488 (set-buffer rmail-buffer
)
1490 ;; No need to swap buffers: rmail-write-region-annotate takes care of it.
1491 ;; (rmail-swap-buffers-maybe)
1493 (if (rmail-summary-exists)
1494 (rmail-select-summary (set-buffer-modified-p nil
))))
1496 (defun rmail-quit ()
1498 Hook `rmail-quit-hook' is run after expunging."
1500 (set-buffer rmail-buffer
)
1503 (when (boundp 'rmail-quit-hook
)
1504 (run-hooks 'rmail-quit-hook
))
1505 ;; Don't switch to the summary buffer even if it was recently visible.
1506 (when rmail-summary-buffer
1507 (with-current-buffer rmail-summary-buffer
1508 (set-buffer-modified-p nil
))
1509 (replace-buffer-in-windows rmail-summary-buffer
)
1510 (bury-buffer rmail-summary-buffer
))
1511 (let ((obuf (current-buffer)))
1513 (replace-buffer-in-windows obuf
)))
1515 (defun rmail-bury ()
1516 "Bury current Rmail buffer and its summary buffer."
1518 ;; This let var was called rmail-buffer, but that interfered
1519 ;; with the buffer-local var used in summary buffers.
1520 (let ((buffer-to-bury (current-buffer)))
1521 (if (rmail-summary-exists)
1523 (while (setq window
(get-buffer-window rmail-summary-buffer
))
1524 (quit-window nil window
))
1525 (bury-buffer rmail-summary-buffer
)))
1528 (defun rmail-duplicate-message ()
1529 "Create a duplicated copy of the current message.
1530 The duplicate copy goes into the Rmail file just after the original."
1531 ;; If we are in a summary buffer, switch to the Rmail buffer.
1532 ;; FIXME simpler to swap the contents, not the buffers?
1533 (set-buffer rmail-buffer
)
1534 (rmail-modify-format)
1535 (let ((buff (current-buffer))
1536 (n rmail-current-message
)
1537 (beg (rmail-msgbeg rmail-current-message
))
1538 (end (rmail-msgend rmail-current-message
)))
1539 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer
))
1541 (let ((buffer-read-only nil
)
1542 (string (buffer-substring-no-properties beg end
)))
1546 (rmail-swap-buffers-maybe)
1547 (goto-char (point-max))
1548 (rmail-set-message-counters)
1549 (set-buffer-modified-p t
)
1550 (rmail-show-message-1 n
))
1551 (if (rmail-summary-exists)
1552 (rmail-select-summary (rmail-update-summary)))
1553 (message "Message duplicated"))
1556 (defun rmail-input (filename)
1557 "Run Rmail on file FILENAME."
1558 (interactive "FRun rmail on RMAIL file: ")
1561 ;; This used to scan subdirectories recursively, but someone pointed out
1562 ;; that if the user wants that, person can put all the files in one dir.
1563 ;; And the recursive scan was slow. So I took it out.
1565 (defun rmail-find-all-files (start)
1566 "Return list of file in dir START that match `rmail-secondary-file-regexp'."
1567 (if (file-accessible-directory-p start
)
1569 (let* ((case-fold-search t
)
1570 (files (directory-files start t rmail-secondary-file-regexp
)))
1571 ;; Sort here instead of in directory-files
1572 ;; because this list is usually much shorter.
1573 (sort files
'string
<))))
1575 (defun rmail-list-to-menu (menu-name l action
&optional full-name
)
1576 (let ((menu (make-sparse-keymap menu-name
))
1584 (car item
) (cdr item
) action
1586 (concat full-name
"/"
1592 (list 'lambda
() '(interactive)
1596 (concat full-name
"/" item
)
1598 rmail-secondary-file-directory
)))))
1599 (define-key menu
(vector (intern name
))
1600 (cons name command
))))
1604 ;; This command is always "disabled" when it appears in a menu.
1605 (put 'rmail-disable-menu
'menu-enable
''nil
)
1607 (defun rmail-construct-io-menu ()
1608 (let ((files (rmail-find-all-files rmail-secondary-file-directory
)))
1611 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1612 (cons "Input Rmail File"
1613 (rmail-list-to-menu "Input Rmail File"
1616 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1617 (cons "Output Rmail File"
1618 (rmail-list-to-menu "Output Rmail File"
1622 (define-key rmail-mode-map
[menu-bar classify input-menu
]
1623 '("Input Rmail File" . rmail-disable-menu
))
1624 (define-key rmail-mode-map
[menu-bar classify output-menu
]
1625 '("Output Rmail File" . rmail-disable-menu
)))))
1628 ;;;; *** Rmail input ***
1630 (declare-function rmail-summary-goto-msg
"rmailsum" (&optional n nowarn skip-rmail
))
1631 (declare-function rmail-summary-mark-undeleted
"rmailsum" (n))
1632 (declare-function rmail-summary-mark-deleted
"rmailsum" (&optional n undel
))
1633 (declare-function rfc822-addresses
"rfc822" (header-text))
1634 (declare-function mail-abbrev-make-syntax-table
"mailabbrev.el" ())
1636 ;; RLK feature not added in this version:
1637 ;; argument specifies inbox file or files in various ways.
1639 ;; In Babyl, the Mail: header in the preamble overrode rmail-inbox-list.
1640 ;; Mbox does not have this feature.
1641 (defun rmail-get-new-mail (&optional file-name
)
1642 "Move any new mail from this Rmail file's inbox files.
1643 The buffer-local variable `rmail-inbox-list' specifies the list
1644 of inbox files. By default, this is nil, except for your primary
1645 Rmail file `rmail-file-name'. In this case, when you first visit
1646 the Rmail file it is initialized using either
1647 `rmail-primary-inbox-list', or the \"MAIL\" environment variable,
1648 or the function `user-login-name' and the directory
1649 `rmail-spool-directory' (whose value depends on the operating system).
1651 The command `set-rmail-inbox-list' sets `rmail-inbox-list' to the
1654 You can also specify the file to get new mail from just for one
1655 instance of this command. In this case, the file of new mail is
1656 not changed or deleted. Noninteractively, you can pass the inbox
1657 file name as an argument. Interactively, a prefix argument
1658 causes us to read a file name and use that file as the inbox.
1660 If the variable `rmail-preserve-inbox' is non-nil, new mail will
1661 always be left in inbox files rather than deleted.
1663 Before doing anything, this runs `rmail-before-get-new-mail-hook'.
1664 Just before returning, it runs `rmail-after-get-new-mail-hook',
1665 whether or not there is new mail.
1667 If there is new mail, it runs `rmail-get-new-mail-hook', saves
1668 the updated file, and shows the first unseen message (which might
1669 not be a new one). It returns non-nil if it got any new messages."
1671 (list (if current-prefix-arg
1672 (read-file-name "Get new mail from file: "))))
1673 (run-hooks 'rmail-before-get-new-mail-hook
)
1674 ;; If the disk file has been changed from under us,
1675 ;; revert to it before we get new mail.
1676 (or (verify-visited-file-modtime (current-buffer))
1677 (find-file (buffer-file-name)))
1678 (set-buffer rmail-buffer
)
1679 (rmail-modify-format)
1680 (rmail-swap-buffers-maybe)
1681 (rmail-maybe-set-message-counters)
1683 ;; Get rid of all undo records for this buffer.
1684 (or (eq buffer-undo-list t
)
1685 (setq buffer-undo-list nil
))
1686 (let ((all-files (if file-name
(list file-name
) rmail-inbox-list
))
1687 (rmail-enable-multibyte (default-value 'enable-multibyte-characters
))
1691 ;; This loops if any members of the inbox list have the same
1692 ;; basename (see "name conflict" below).
1694 (let ((opoint (point))
1695 ;; If buffer has not changed yet, and has not been
1696 ;; saved yet, don't replace the old backup file now.
1697 (make-backup-files (and make-backup-files
1698 (buffer-modified-p)))
1699 (buffer-read-only nil
)
1700 ;; Don't make undo records while getting mail.
1701 (buffer-undo-list t
)
1702 delete-files success files file-last-names
)
1703 ;; Pull files off all-files onto files as long as there is
1704 ;; no name conflict. A conflict happens when two inbox
1705 ;; file names have the same last component.
1706 ;; The reason this careful handling is necessary seems
1707 ;; to be that rmail-insert-inbox-text uses .newmail-BASENAME.
1708 (while (and all-files
1709 (not (member (file-name-nondirectory (car all-files
))
1711 (setq files
(cons (car all-files
) files
)
1713 (cons (file-name-nondirectory (car all-files
)) files
))
1714 (setq all-files
(cdr all-files
)))
1715 ;; Put them back in their original order.
1716 (setq files
(nreverse files
))
1717 (goto-char (point-max))
1718 ;; Make sure we end with a blank line unless there are
1719 ;; no messages, as required by mbox format (Bug#9974).
1721 (while (not (looking-back "\n\n"))
1724 (rmail-get-new-mail-1 file-name files delete-files
)
1726 ;; Move to the first new message unless we have other unseen
1727 ;; messages before it.
1728 (if found
(rmail-show-message (rmail-first-unseen-message)))
1729 (run-hooks 'rmail-after-get-new-mail-hook
)
1731 ;; Don't leave the buffer screwed up if we get a disk-full error.
1732 (rmail-show-message))))
1734 (defvar rmail-use-spam-filter
)
1735 (declare-function rmail-get-new-mail-filter-spam
"rmail-spam-filter" (nnew))
1737 (defun rmail-get-new-mail-1 (file-name files delete-files
)
1738 "Return t if new messages are detected without error, nil otherwise."
1741 (let ((new-messages 0)
1742 (spam-filter-p (and (featurep 'rmail-spam-filter
)
1743 rmail-use-spam-filter
))
1745 result success suffix
)
1746 (narrow-to-region (point) (point))
1747 ;; Read in the contents of the inbox files, renaming them as
1748 ;; necessary, and adding to the list of files to delete
1751 (rmail-insert-inbox-text files nil
)
1752 (setq delete-files
(rmail-insert-inbox-text files t
)))
1753 ;; Scan the new text and convert each message to
1754 ;; Rmail/mbox format.
1755 (goto-char (point-min))
1756 (skip-chars-forward " \n")
1757 (narrow-to-region (point) (point-max))
1759 (setq new-messages
(rmail-add-mbox-headers)
1761 ;; Try to delete the garbage just inserted.
1762 (or success
(delete-region (point-min) (point-max)))
1763 ;; If we could not convert the file's inboxes, rename the
1764 ;; files we tried to read so we won't over and over again.
1765 (if (and (not file-name
) (not success
))
1766 (let ((delfiles delete-files
)
1769 (while (file-exists-p (format "RMAILOSE.%d" count
))
1770 (setq count
(1+ count
)))
1771 (rename-file (car delfiles
) (format "RMAILOSE.%d" count
))
1772 (setq delfiles
(cdr delfiles
))))))
1773 ;; Determine if there are messages.
1774 (unless (zerop new-messages
)
1775 ;; There are. Process them.
1776 (goto-char (point-min))
1777 (rmail-count-new-messages)
1778 (run-hooks 'rmail-get-new-mail-hook
)
1780 ;; Delete the old files, now that the Rmail file is saved.
1783 ;; First, try deleting.
1785 (delete-file (car delete-files
))
1787 ;; If we can't delete it, truncate it.
1788 (write-region (point) (point) (car delete-files
))))
1790 (setq delete-files
(cdr delete-files
)))
1791 (if (zerop new-messages
)
1792 (when (or file-name rmail-inbox-list
)
1793 (message "(No new mail has arrived)"))
1795 (setq blurb
(rmail-get-new-mail-filter-spam new-messages
))))
1796 (if (rmail-summary-exists)
1797 (rmail-select-summary (rmail-update-summary)))
1798 (setq suffix
(if (= 1 new-messages
) "" "s"))
1799 (message "%d new message%s read%s" new-messages suffix blurb
)
1800 ;; Establish the return value.
1801 (setq result
(> new-messages
0))
1804 (defun rmail-parse-url (file)
1805 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1806 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1807 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1808 a remote mailbox, PASSWORD is the password if it should be
1809 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1810 is non-nil if the user has supplied the password interactively.
1813 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file
)
1814 (let (got-password supplied-password
1815 (proto (match-string 1 file
))
1816 (user (match-string 3 file
))
1817 (pass (match-string 5 file
))
1818 (host (substring file
(or (match-end 2)
1819 (+ 3 (match-end 1))))))
1822 (when rmail-remote-password-required
1823 (setq got-password
(not (rmail-have-password)))
1824 (setq supplied-password
(rmail-get-remote-password
1825 (string-equal proto
"imap"))))
1826 ;; The password is embedded. Strip it out since movemail
1827 ;; does not really like it, in spite of the movemail spec.
1828 (setq file
(concat proto
"://" user
"@" host
)))
1830 (if (rmail-movemail-variant-p 'emacs
)
1831 (if (string-equal proto
"pop")
1832 (list (concat "po:" user
":" host
)
1834 (or pass supplied-password
)
1836 (error "Emacs movemail does not support %s protocol" proto
))
1838 (or (string-equal proto
"pop") (string-equal proto
"imap"))
1839 (or supplied-password pass
)
1842 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file
)
1843 (let (got-password supplied-password
1845 (user (match-string 1 file
))
1846 (host (match-string 3 file
)))
1848 (when rmail-remote-password-required
1849 (setq got-password
(not (rmail-have-password)))
1850 (setq supplied-password
(rmail-get-remote-password nil
)))
1852 (list file
"pop" supplied-password got-password
)))
1855 (list file nil nil nil
))))
1857 (defun rmail-unrmail-new-mail (from-file)
1858 "Replace newly read mail in Babyl format with equivalent mbox format.
1860 FROM-FILE is the Babyl file from which the new mail should be read."
1861 (let ((to-file (make-temp-file "rmail"))
1863 (unrmail from-file to-file
)
1864 (let ((inhibit-read-only t
)
1865 (coding-system-for-read 'raw-text
)
1866 (buffer-undo-list t
))
1867 (delete-region (point) (point-max))
1868 (setq size
(nth 1 (insert-file-contents to-file
)))
1869 (delete-file to-file
)
1872 (defun rmail-unrmail-new-mail-maybe (file size
)
1873 "If newly read mail from FILE is in Babyl format, convert it to mbox format.
1875 SIZE is the original size of the newly read mail.
1876 Value is the size of the newly read mail after conversion."
1877 ;; Detect previous Babyl format files.
1878 (let ((case-fold-search nil
)
1881 (cond ((looking-at "BABYL OPTIONS:")
1882 ;; The new mail is in Babyl version 5 format. Use unrmail
1884 (setq size
(rmail-unrmail-new-mail old-file
)))
1885 ((looking-at "Version: 5\n")
1886 ;; New mail is in Babyl format made by old version of
1887 ;; Rmail. Fix the babyl file header and use unrmail to
1889 (let ((buffer-read-only nil
)
1890 (write-region-annotate-functions nil
)
1891 (write-region-post-annotation-function nil
)
1892 (old-file (make-temp-file "rmail")))
1893 (insert "BABYL OPTIONS: -*- rmail -*-\n")
1895 (write-region (point) (point-max) old-file
)
1896 (setq size
(rmail-unrmail-new-mail old-file
))
1897 (delete-file old-file
))))
1900 (defun rmail-insert-inbox-text (files renamep
)
1901 ;; Detect a locked file now, so that we avoid moving mail
1902 ;; out of the real inbox file. (That could scare people.)
1903 (or (memq (file-locked-p buffer-file-name
) '(nil t
))
1904 (error "RMAIL file %s is locked"
1905 (file-name-nondirectory buffer-file-name
)))
1906 (let (file tofile delete-files movemail popmail got-password password
)
1908 ;; Handle remote mailbox names specially; don't expand as filenames
1909 ;; in case the userid contains a directory separator.
1910 (setq file
(car files
))
1911 (let ((url-data (rmail-parse-url file
)))
1912 (setq file
(nth 0 url-data
))
1913 (setq popmail
(nth 1 url-data
))
1914 (setq password
(nth 2 url-data
))
1915 (setq got-password
(nth 3 url-data
)))
1919 (setq file
(file-truename
1920 (substitute-in-file-name (expand-file-name file
)))))
1921 (setq tofile
(expand-file-name
1922 ;; Generate name to move to from inbox name,
1923 ;; in case of multiple inboxes that need moving.
1925 (file-name-nondirectory
1926 (if (memq system-type
'(windows-nt cygwin ms-dos
))
1927 ;; cannot have colons in file name
1928 (replace-regexp-in-string ":" "-" file
)
1930 ;; Use the directory of this rmail file
1931 ;; because it's a nuisance to use the homedir
1932 ;; if that is on a full disk and this rmail
1934 (file-name-directory
1935 (expand-file-name buffer-file-name
))))
1936 ;; Always use movemail to rename the file,
1937 ;; since there can be mailboxes in various directories.
1939 ;; On some systems, /usr/spool/mail/foo is a directory
1940 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1941 (if (file-directory-p file
)
1942 (setq file
(expand-file-name (user-login-name)
1945 (message "Getting mail from the remote server ..."))
1946 ((and (file-exists-p tofile
)
1947 (/= 0 (nth 7 (file-attributes tofile
))))
1948 (message "Getting mail from %s..." tofile
))
1949 ((and (file-exists-p file
)
1950 (/= 0 (nth 7 (file-attributes file
))))
1951 (message "Getting mail from %s..." file
)))
1952 ;; Set TOFILE if have not already done so, and
1953 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1954 (cond ((not renamep
)
1956 ((or (file-exists-p tofile
) (and (not popmail
)
1957 (not (file-exists-p file
))))
1961 (let ((errors (current-buffer)))
1962 (buffer-disable-undo errors
)
1965 (list (or rmail-movemail-program
"movemail") nil errors nil
)
1966 (if rmail-preserve-inbox
1969 (if (rmail-movemail-variant-p 'mailutils
)
1970 (append (list "--emacs") rmail-movemail-flags
)
1971 rmail-movemail-flags
)
1973 (if password
(list password
) nil
))))
1974 (apply 'call-process args
))
1975 (if (not (buffer-modified-p errors
))
1976 ;; No output => movemail won
1979 (subst-char-in-region (point-min) (point-max)
1981 (goto-char (point-max))
1982 (skip-chars-backward " \t")
1983 (delete-region (point) (point-max))
1984 (goto-char (point-min))
1985 (if (looking-at "movemail: ")
1986 (delete-region (point-min) (match-end 0)))
1988 ;; If we just read the password, most likely it is
1989 ;; wrong. Otherwise, see if there is a specific
1990 ;; reason to think that the problem is a wrong passwd.
1991 (if (or got-password
1992 (re-search-forward rmail-remote-password-error
1994 (rmail-set-remote-password nil
))
1996 ;; If using Mailutils, remove initial error code
1998 (when (rmail-movemail-variant-p 'mailutils
)
1999 (goto-char (point-min))
2000 (when (looking-at "[A-Z][A-Z0-9_]*:")
2001 (delete-region (point-min) (match-end 0))))
2003 (message "movemail: %s"
2004 (buffer-substring (point-min)
2010 ;; At this point, TOFILE contains the name to read:
2011 ;; Either the alternate name (if we renamed)
2012 ;; or the actual inbox (if not renaming).
2013 (if (file-exists-p tofile
)
2014 (let ((coding-system-for-read 'no-conversion
)
2016 (goto-char (point-max))
2018 ;; If new mail is in Babyl format, convert it to mbox.
2019 (rmail-unrmail-new-mail-maybe
2021 (nth 1 (insert-file-contents tofile
))))
2022 (goto-char (point-max))
2023 ;; Make sure the read-in mbox data properly ends with a
2024 ;; blank line unless it is of size 0.
2025 (unless (zerop size
)
2026 (while (not (looking-back "\n\n"))
2028 (if (not (and rmail-preserve-inbox
(string= file tofile
)))
2029 (setq delete-files
(cons tofile delete-files
)))))
2031 (setq files
(cdr files
)))
2034 ;; Decode the region specified by FROM and TO by CODING.
2035 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
2036 (defun rmail-decode-region (from to coding
&optional destination
)
2037 (if (or (not coding
) (not (coding-system-p coding
)))
2038 (setq coding
'undecided
))
2039 ;; Use -dos decoding, to remove ^M characters left from base64 or
2040 ;; rogue qp-encoded text.
2041 (decode-coding-region
2042 from to
(coding-system-change-eol-conversion coding
1) destination
)
2043 ;; Don't reveal the fact we used -dos decoding, as users generally
2044 ;; will not expect the RMAIL buffer to use DOS EOL format.
2047 (setq buffer-file-coding-system
2048 (setq last-coding-system-used
2049 (coding-system-change-eol-conversion coding
0))))
2050 ((bufferp destination
)
2051 (with-current-buffer destination
2052 (setq buffer-file-coding-system
2053 (setq last-coding-system-used
2054 (coding-system-change-eol-conversion coding
0)))))))
2056 (defun rmail-ensure-blank-line ()
2057 "Ensure a message ends in a blank line.
2058 Call with point at the end of the message."
2061 (unless (looking-back "\n\n")
2064 (defun rmail-add-mbox-headers ()
2065 "Validate the RFC2822 format for the new messages.
2066 Point should be at the first new message.
2067 An error is signaled if the new messages are not RFC2822
2069 Unless an Rmail attribute header already exists, add it to the
2070 new messages. Return the number of new messages."
2076 (case-fold-search nil
)
2077 (delim (concat "\n\n" rmail-unix-mail-delimiter
))
2079 ;; Detect an empty inbox file.
2080 (unless (= start
(point-max))
2081 ;; Scan the new messages to establish a count and to ensure that
2082 ;; an attribute header is present.
2083 (if (looking-at rmail-unix-mail-delimiter
)
2085 ;; Determine if a new attribute header needs to be
2086 ;; added to the message.
2087 (if (search-forward "\n\n" nil t
)
2089 (setq count
(1+ count
))
2090 (narrow-to-region start
(point))
2091 (unless (mail-fetch-field rmail-attribute-header
)
2093 (insert rmail-attribute-header
": " value
"\n"))
2095 (rmail-error-bad-format))
2096 ;; Move to the next message.
2097 (if (not (re-search-forward delim nil
'move
))
2099 (goto-char (match-beginning 0))
2101 (setq start
(point)))
2102 (rmail-error-bad-format)))
2105 (defun rmail-get-header-1 (name)
2106 "Subroutine of `rmail-get-header'.
2107 Narrow to header, call `mail-fetch-field' to find header NAME."
2108 (if (search-forward "\n\n" nil t
)
2110 (narrow-to-region (point-min) (point))
2111 (mail-fetch-field name
))
2112 (rmail-error-bad-format)))
2114 (defun rmail-get-header (name &optional msgnum
)
2115 "Return the value of message header NAME, nil if it has none.
2116 MSGNUM specifies the message number to get it from.
2117 If MSGNUM is nil, use the current message."
2118 (rmail-apply-in-message msgnum
'rmail-get-header-1 name
))
2120 (defun rmail-set-header-1 (name value
)
2121 "Subroutine of `rmail-set-header'.
2122 Narrow to header, set header NAME to VALUE, replacing existing if present.
2123 VALUE nil means to remove NAME altogether."
2124 (if (search-forward "\n\n" nil t
)
2127 (narrow-to-region (point-min) (point))
2128 (goto-char (point-min))
2129 (if (re-search-forward (concat "^" (regexp-quote name
) ":") nil
'move
)
2132 (delete-region (point) (line-end-position))
2134 (delete-region (line-beginning-position)
2135 (line-beginning-position 2)))
2136 (if value
(insert name
": " value
"\n"))))
2137 (rmail-error-bad-format)))
2139 (defun rmail-set-header (name &optional msgnum value
)
2140 "Set message header NAME to VALUE in message number MSGNUM.
2141 If MSGNUM is nil, use the current message. NAME and VALUE are strings.
2142 VALUE may also be nil, meaning to remove the header."
2143 (rmail-apply-in-message msgnum
'rmail-set-header-1 name value
)
2144 (with-current-buffer rmail-buffer
2145 ;; Ensure header changes get saved.
2146 ;; (Note replacing a header with an identical copy modifies.)
2147 (set-buffer-modified-p t
)
2148 ;; However: don't save in mbox format over a Babyl file
2149 ;; merely because of this.
2150 (rmail-dont-modify-format)))
2152 ;;;; *** Rmail Attributes and Keywords ***
2154 (defun rmail-get-attr-names (&optional msg
)
2155 "Return the message attributes in a comma separated string.
2156 MSG specifies the message number to get it from.
2157 If MSG is nil, use the current message."
2158 (let ((value (rmail-get-header rmail-attribute-header msg
))
2159 (nmax (length rmail-attr-array
))
2162 (if (> (length value
) nmax
)
2163 (message "Warning: corrupt attribute header in message")
2164 (dotimes (index (length value
))
2165 (setq temp
(and (not (= ?-
(aref value index
)))
2166 (nth 1 (aref rmail-attr-array index
)))
2169 ((and temp result
) (format "%s, %s" result temp
))
2174 (defun rmail-get-keywords (&optional msg
)
2175 "Return the message keywords in a comma separated string.
2176 MSG, if non-nil, identifies the message number to use.
2177 If nil, that means the current message."
2178 (rmail-get-header rmail-keyword-header msg
))
2180 (defun rmail-get-labels (&optional msg
)
2181 "Return a string with the labels (attributes and keywords) of msg MSG.
2182 It is put in comma-separated form.
2183 MSG, if non-nil, identifies the message number to use.
2184 If nil, that means the current message."
2185 (or msg
(setq msg rmail-current-message
))
2186 (let (attr-names keywords
)
2187 ;; Combine the message attributes and keywords
2188 ;; into a comma-separated list.
2189 (setq attr-names
(rmail-get-attr-names msg
)
2190 keywords
(rmail-get-keywords msg
))
2191 (if (string= keywords
"")
2192 (setq keywords nil
))
2194 ;; FIXME ? old rmail did not have spaces in the comma-separated lists.
2195 ((and attr-names keywords
) (concat " " attr-names
"; " keywords
))
2196 (attr-names (concat " " attr-names
))
2197 (keywords (concat " " keywords
))
2200 (defun rmail-display-labels ()
2201 "Update the current messages's attributes and keywords in mode line."
2202 (let ((blurb (rmail-get-labels)))
2203 (setq mode-line-process
2205 rmail-current-message rmail-total-messages blurb
))))
2207 (defun rmail-get-attr-value (attr state
)
2208 "Return the character value for ATTR.
2209 ATTR is a (numeric) index, an offset into the mbox attribute
2210 header value. STATE is one of nil, t, or a character value."
2212 ((numberp state
) state
)
2214 (t (nth 0 (aref rmail-attr-array attr
)))))
2216 (defun rmail-set-attribute-1 (attr state
)
2217 "Subroutine of `rmail-set-attribute'.
2218 Set Rmail attribute ATTR to STATE in `rmail-attribute-header',
2219 creating the header if necessary. Returns non-nil if a
2220 significant attribute change was made."
2221 (let ((limit (search-forward "\n\n" nil t
))
2222 (value (rmail-get-attr-value attr state
))
2223 (inhibit-read-only t
)
2225 (goto-char (point-min))
2226 (if (search-forward (concat rmail-attribute-header
": ") limit t
)
2227 ;; If this message already records attributes, just change the
2228 ;; value for this one.
2229 (let ((missing (- (+ (point) attr
) (line-end-position))))
2230 ;; Position point at this attribute, adding attributes if necessary.
2234 (insert-char ?- missing
)
2236 (forward-char attr
))
2237 ;; Change this attribute.
2238 (when (/= value
(char-after))
2242 ;; Otherwise add a header line to record the attributes and set
2243 ;; all but this one to no.
2244 (let ((header-value "--------"))
2245 (aset header-value attr value
)
2246 (goto-char (if limit
(1- limit
) (point-max)))
2247 (setq altered
(/= value ?-
))
2248 (insert rmail-attribute-header
": " header-value
"\n")))
2251 (defun rmail-set-attribute (attr state
&optional msgnum
)
2252 "Turn an attribute of a message on or off according to STATE.
2253 STATE is either nil or the character (numeric) value associated
2254 with the state (nil represents off and non-nil represents on).
2255 ATTR is either the index number of the attribute, or a string,
2256 both from `rmail-attr-array'. MSGNUM is message number to
2257 change; nil means current message."
2259 (nmax (length rmail-attr-array
)))
2260 (while (and (stringp attr
)
2262 (if (string-equal attr
(cadr (aref rmail-attr-array n
)))
2266 (error "Unknown attribute `%s'" attr
))
2267 ;; Ask for confirmation before setting any attribute except `unseen'
2268 ;; if it would force a format change.
2269 (unless (= attr rmail-unseen-attr-index
)
2270 (rmail-modify-format))
2271 (with-current-buffer rmail-buffer
2272 (or msgnum
(setq msgnum rmail-current-message
))
2274 ;; The "deleted" attribute is also stored in a special vector so
2276 (if (= attr rmail-deleted-attr-index
)
2277 (rmail-set-message-deleted-p msgnum state
))
2279 (rmail-apply-in-message msgnum
'rmail-set-attribute-1 attr state
)
2280 (if (= msgnum rmail-current-message
)
2281 (rmail-display-labels)))
2282 ;; Don't save in mbox format over a Babyl file
2283 ;; merely because of a change in `unseen' attribute.
2284 (if (= attr rmail-unseen-attr-index
)
2285 (rmail-dont-modify-format)
2286 ;; Otherwise, if we modified the file text via the view buffer,
2287 ;; mark the main buffer modified too.
2288 (set-buffer-modified-p t
))))))
2290 (defun rmail-message-attr-p (msg attrs
)
2291 "Return non-nil if message number MSG has attributes matching regexp ATTRS."
2292 (let ((value (rmail-get-header rmail-attribute-header msg
)))
2293 (and value
(string-match attrs value
))))
2295 (defun rmail-message-unseen-p (msgnum)
2296 "Return non-nil if message number MSGNUM has the unseen attribute."
2297 (rmail-message-attr-p msgnum
"......U"))
2299 ;; FIXME rmail-get-labels does some formatting (eg leading space, `;'
2300 ;; between attributes and labels), so this might not do what you want.
2301 ;; Eg see rmail-sort-by-labels. rmail-get-labels could have an
2302 ;; optional `noformat' argument.
2303 (defun rmail-message-labels-p (msg labels
)
2304 "Return non-nil if message number MSG has labels matching regexp LABELS."
2305 (string-match labels
(rmail-get-labels msg
)))
2307 ;;;; *** Rmail Message Selection And Support ***
2309 (defun rmail-msgend (n)
2310 "Return the end position for message number N."
2311 (marker-position (aref rmail-message-vector
(1+ n
))))
2313 (defun rmail-msgbeg (n)
2314 "Return the start position for message number N."
2315 (marker-position (aref rmail-message-vector n
)))
2317 (defun rmail-apply-in-message (msgnum function
&rest args
)
2318 "Call FUNCTION on ARGS while narrowed to message MSGNUM.
2319 Point is at the start of the message.
2320 This returns what the call to FUNCTION returns.
2321 If MSGNUM is nil, use the current message."
2322 (with-current-buffer rmail-buffer
2323 (or msgnum
(setq msgnum rmail-current-message
))
2325 (let (msgbeg msgend
)
2326 (setq msgbeg
(rmail-msgbeg msgnum
))
2327 (setq msgend
(rmail-msgend msgnum
))
2328 ;; All access to the rmail-buffer's local variables is now finished...
2330 ;; ... so it is ok to go to a different buffer.
2331 (if (rmail-buffers-swapped-p) (set-buffer rmail-view-buffer
))
2336 (narrow-to-region msgbeg msgend
)
2337 (apply function args
))))))))
2339 ;; Unused (save for commented out code in rmailedit.el).
2340 (defun rmail-widen-to-current-msgbeg (function)
2341 "Call FUNCTION with point at start of internal data of current message.
2342 Assumes that bounds were previously narrowed to display the message in Rmail.
2343 The bounds are widened enough to move point where desired, then narrowed
2346 FUNCTION may not change the visible text of the message, but it may
2347 change the invisible header text."
2351 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2353 (goto-char (point-min))
2355 ;; Note: we don't use save-restriction because that does not work right
2356 ;; if changes are made outside the saved restriction
2357 ;; before that restriction is restored.
2358 (narrow-to-region (rmail-msgbeg rmail-current-message
)
2359 (rmail-msgend rmail-current-message
)))))
2361 ;; Manage the message vectors and counters.
2363 (defun rmail-forget-messages ()
2365 (if (vectorp rmail-message-vector
)
2366 (let* ((v rmail-message-vector
)
2370 (move-marker (aref v i
) nil
)))))
2371 (setq rmail-message-vector nil
)
2372 (setq rmail-msgref-vector nil
)
2373 (setq rmail-deleted-vector nil
)))
2375 (defun rmail-maybe-set-message-counters ()
2376 (if (not (and rmail-deleted-vector
2377 rmail-message-vector
2378 rmail-current-message
2379 rmail-total-messages
))
2380 (rmail-set-message-counters)))
2382 (defun rmail-count-new-messages (&optional nomsg
)
2383 "Count the number of new messages.
2384 The buffer should be narrowed to include only the new messages.
2385 Output a helpful message unless NOMSG is non-nil."
2386 (let* ((case-fold-search nil
)
2390 (or nomsg
(message "Counting new messages..."))
2391 (goto-char (point-max))
2392 ;; Put at the end of messages-head
2393 ;; the entry for message N+1, which marks
2394 ;; the end of message N. (N = number of messages).
2395 (setq messages-head
(list (point-marker)))
2396 (rmail-set-message-counters-counter (point-min))
2397 (setq rmail-current-message
(1+ rmail-total-messages
))
2398 (setq rmail-total-messages
2399 (+ rmail-total-messages total-messages
))
2400 (setq rmail-message-vector
2401 (vconcat rmail-message-vector
(cdr messages-head
)))
2402 (aset rmail-message-vector
2403 rmail-current-message
(car messages-head
))
2404 (setq rmail-deleted-vector
2405 (concat rmail-deleted-vector deleted-head
))
2406 (setq rmail-summary-vector
2407 (vconcat rmail-summary-vector
(make-vector total-messages nil
)))
2408 (setq rmail-msgref-vector
2409 (vconcat rmail-msgref-vector
(make-vector total-messages nil
)))
2410 ;; Fill in the new elements of rmail-msgref-vector.
2411 (let ((i (1+ (- rmail-total-messages total-messages
))))
2412 (while (<= i rmail-total-messages
)
2413 (aset rmail-msgref-vector i
(list i
))
2415 (goto-char (point-min))
2416 (or nomsg
(message "Counting new messages...done (%d)" total-messages
))))
2418 (defun rmail-set-message-counters ()
2419 (rmail-forget-messages)
2423 (let* ((point-save (point))
2425 (messages-after-point)
2426 (case-fold-search nil
)
2429 ;; Determine how many messages follow point.
2430 (message "Counting messages...")
2431 (goto-char (point-max))
2432 ;; Put at the end of messages-head
2433 ;; the entry for message N+1, which marks
2434 ;; the end of message N. (N = number of messages).
2435 (setq messages-head
(list (point-marker)))
2436 (setq messages-after-point
2437 (or (rmail-set-message-counters-counter (min (point) point-save
))
2440 (setq rmail-total-messages total-messages
)
2441 (setq rmail-current-message
2443 (max 1 (- total-messages messages-after-point
))))
2445 ;; Make an element 0 in rmail-message-vector and rmail-deleted-vector
2446 ;; which will never be used.
2447 (push nil messages-head
)
2448 (push ?
0 deleted-head
)
2449 (setq rmail-message-vector
(apply 'vector messages-head
)
2450 rmail-deleted-vector
(concat deleted-head
))
2452 (setq rmail-summary-vector
(make-vector rmail-total-messages nil
)
2453 rmail-msgref-vector
(make-vector (1+ rmail-total-messages
) nil
))
2456 (while (<= i rmail-total-messages
)
2457 (aset rmail-msgref-vector i
(list i
))
2460 (while (<= i rmail-total-messages
)
2461 (rmail-set-message-deleted-p i
(rmail-message-attr-p i
".D"))
2463 (message "Counting messages...done")))))
2466 (defsubst rmail-collect-deleted
(message-end)
2467 "Collect the message deletion flags for each message.
2468 MESSAGE-END is the buffer position corresponding to the end of
2469 the message. Point is at the beginning of the message."
2470 ;; NOTE: This piece of code will be executed on a per-message basis.
2471 ;; In the face of thousands of messages, it has to be as fast as
2472 ;; possible, hence some brute force constant use is employed in
2473 ;; addition to inlining.
2476 (cons (if (and (search-forward (concat rmail-attribute-header
": ") message-end t
)
2479 ?\s
) deleted-head
))))
2481 (defun rmail-set-message-counters-counter (&optional spot-to-find
)
2482 "Collect the start positions of messages in list `messages-head'.
2483 Return the number of messages after the one containing SPOT-TO-FIND."
2484 (let ((start (point))
2485 messages-after-spot
)
2486 (while (search-backward "\n\nFrom " nil t
)
2488 (when (looking-at rmail-unix-mail-delimiter
)
2489 (if (and (<= (point) spot-to-find
)
2490 (null messages-after-spot
))
2491 (setq messages-after-spot total-messages
))
2492 (rmail-collect-deleted start
)
2493 (setq messages-head
(cons (point-marker) messages-head
)
2494 total-messages
(1+ total-messages
)
2496 ;; Show progress after every 20 messages or so.
2497 (if (zerop (% total-messages
20))
2498 (message "Counting messages...%d" total-messages
))))
2499 ;; Handle the first message, maybe.
2500 (goto-char (point-min))
2501 (unless (not (looking-at rmail-unix-mail-delimiter
))
2502 (if (and (<= (point) spot-to-find
)
2503 (null messages-after-spot
))
2504 (setq messages-after-spot total-messages
))
2505 (rmail-collect-deleted start
)
2506 (setq messages-head
(cons (point-marker) messages-head
)
2507 total-messages
(1+ total-messages
)))
2508 messages-after-spot
))
2510 ;; Display a message.
2512 ;;;; *** Rmail Message Formatting and Header Manipulation ***
2514 ;; This is used outside of rmail.
2515 (defun rmail-msg-is-pruned ()
2516 "Return nil if the current message is showing full headers."
2517 (with-current-buffer (if (rmail-buffers-swapped-p) rmail-view-buffer
2519 (eq rmail-header-style
'normal
)))
2521 (defun rmail-toggle-header (&optional arg
)
2522 "Toggle between showing full and normal message headers.
2523 With optional integer ARG, show the normal message header if ARG
2524 is greater than zero; otherwise, show it in full."
2526 (let ((rmail-header-style
2528 (if (> arg
0) 'normal
'full
)
2529 (if (rmail-msg-is-pruned) 'full
'normal
))))
2530 (rmail-show-message)))
2532 (defun rmail-beginning-of-message ()
2533 "Show current message starting from the beginning."
2535 (let ((rmail-show-message-hook '((lambda () (goto-char (point-min)))))
2536 (rmail-header-style (with-current-buffer (if (rmail-buffers-swapped-p)
2539 rmail-header-style
)))
2540 (rmail-show-message rmail-current-message
)))
2542 (defun rmail-end-of-message ()
2543 "Show bottom of current message."
2545 (let ((rmail-show-message-hook '((lambda ()
2546 (goto-char (point-max))
2547 (recenter (1- (window-height))))))
2548 (rmail-header-style (with-current-buffer (if (rmail-buffers-swapped-p)
2551 rmail-header-style
)))
2552 (rmail-show-message rmail-current-message
)))
2554 (defun rmail-unknown-mail-followup-to ()
2555 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2556 Ask the user whether to add that list name to `mail-mailing-lists'."
2557 ;; FIXME s-r not needed? Use rmail-get-header?
2558 ;; We have not narrowed to the headers at ths point?
2560 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t
)))
2561 (when mail-followup-to
2564 (mail-strip-quoted-names mail-followup-to
)
2565 ",[[:space:]]+" t
)))
2566 (dolist (addr addresses
)
2567 (when (and (not (member addr mail-mailing-lists
))
2569 ;; taken from rmailsum.el
2571 (or rmail-user-mail-address-regexp
2573 (regexp-quote (user-login-name))
2576 (or user-mail-address
2577 (concat (user-login-name) "@"
2578 (or mail-host-address
2583 (format "Add `%s' to `mail-mailing-lists'? "
2585 (customize-save-variable 'mail-mailing-lists
2586 (cons addr mail-mailing-lists
)))))))))
2588 (defun rmail-widen ()
2589 "Display the entire mailbox file."
2591 (rmail-swap-buffers-maybe)
2594 (defun rmail-no-mail-p ()
2595 "Return nil if there is mail, else \"No mail.\"."
2596 (if (zerop rmail-total-messages
)
2598 ;; Eg we deleted all the messages, so remove the old N/M mark.
2599 (with-current-buffer rmail-buffer
(setq mode-line-process nil
))
2600 (with-current-buffer rmail-view-buffer
2604 (defun rmail-show-message (&optional n no-summary
)
2605 "Show message number N (prefix argument), counting from start of file.
2606 If summary buffer is currently displayed, update current message there also.
2607 N defaults to the current message."
2609 (or (eq major-mode
'rmail-mode
)
2610 (switch-to-buffer rmail-buffer
))
2611 ;; FIXME: Why do we swap the raw data back in?
2612 (rmail-swap-buffers-maybe)
2613 (rmail-maybe-set-message-counters)
2615 (let ((blurb (rmail-show-message-1 n
)))
2616 (or (zerop rmail-total-messages
)
2618 (when mail-mailing-lists
2619 (rmail-unknown-mail-followup-to))
2620 (if transient-mark-mode
(deactivate-mark))
2621 ;; If there is a summary buffer, try to move to this message
2622 ;; in that buffer. But don't complain if this message is
2623 ;; not mentioned in the summary. Don't do this at all if we
2624 ;; were called on behalf of cursor motion in the summary
2626 (and (rmail-summary-exists) (not no-summary
)
2627 (let ((curr-msg rmail-current-message
))
2628 (rmail-select-summary
2629 (rmail-summary-goto-msg curr-msg t t
))))
2630 (with-current-buffer rmail-buffer
2631 (rmail-auto-file))))
2635 (defun rmail-is-text-p ()
2636 "Return t if the region contains a text message, nil otherwise."
2638 (let ((text-regexp "\\(text\\|message\\)/")
2639 (content-type-header (mail-fetch-field "content-type")))
2640 ;; The message is text if either there is no content type header
2641 ;; (a default of "text/plain; charset=US-ASCII" is assumed) or
2642 ;; the base content type is either text or message.
2643 (or (not content-type-header
)
2644 (string-match text-regexp content-type-header
)))))
2646 (defcustom rmail-show-message-verbose-min
200000
2647 "Message size at which to show progress messages for displaying it."
2652 (defun rmail-show-message-1 (&optional msg
)
2653 "Show message MSG (default: current message) using `rmail-view-buffer'.
2654 Return text to display in the minibuffer if MSG is out of
2655 range (displaying a reasonable choice as well), nil otherwise.
2656 The current mail message becomes the message displayed."
2657 (let ((mbox-buf rmail-buffer
)
2658 (view-buf rmail-view-buffer
)
2659 blurb beg end body-start coding-system character-coding
2660 is-text-message header-style
)
2662 (setq msg rmail-current-message
))
2663 (unless (setq blurb
(rmail-no-mail-p))
2666 rmail-current-message
1
2667 blurb
"No previous message"))
2668 ((> msg rmail-total-messages
)
2669 (setq msg rmail-total-messages
2670 rmail-current-message rmail-total-messages
2671 blurb
"No following message"))
2672 (t (setq rmail-current-message msg
)))
2673 (with-current-buffer rmail-buffer
2674 (setq header-style rmail-header-style
)
2675 ;; Mark the message as seen, but preserve buffer modified flag.
2676 (let ((modiff (buffer-modified-p)))
2677 (rmail-set-attribute rmail-unseen-attr-index nil
)
2679 (restore-buffer-modified-p modiff
)))
2680 ;; bracket the message in the mail
2681 ;; buffer and determine the coding system the transfer encoding.
2682 (rmail-swap-buffers-maybe)
2683 (setq beg
(rmail-msgbeg msg
)
2684 end
(rmail-msgend msg
))
2685 (when (> (- end beg
) rmail-show-message-verbose-min
)
2686 (message "Showing message %d" msg
))
2687 (narrow-to-region beg end
)
2689 (with-current-buffer rmail-view-buffer
2690 ;; We give the view buffer a buffer-local value of
2691 ;; rmail-header-style based on the binding in effect when
2692 ;; this function is called; `rmail-toggle-headers' can
2693 ;; inspect this value to determine how to toggle.
2694 (set (make-local-variable 'rmail-header-style
) header-style
))
2695 (if (and rmail-enable-mime
2696 rmail-show-mime-function
2697 (re-search-forward "mime-version: 1.0" nil t
))
2698 (let ((rmail-buffer mbox-buf
)
2699 (rmail-view-buffer view-buf
))
2700 (funcall rmail-show-mime-function
))
2701 (setq body-start
(search-forward "\n\n" nil t
))
2702 (narrow-to-region beg
(point))
2705 (if (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
)
2706 (setq coding-system
(intern (match-string 1)))
2707 (setq coding-system
(rmail-get-coding-system))))
2708 (setq character-coding
(mail-fetch-field "content-transfer-encoding")
2709 is-text-message
(rmail-is-text-p))
2710 (if character-coding
2711 (setq character-coding
(downcase character-coding
)))
2712 (narrow-to-region beg end
)
2713 ;; Decode the message body into an empty view buffer using a
2714 ;; unibyte temporary buffer where the character decoding takes
2716 (with-current-buffer rmail-view-buffer
2718 (if (null character-coding
)
2719 ;; Do it directly since that is fast.
2720 (rmail-decode-region body-start end coding-system view-buf
)
2721 ;; Can this be done directly, skipping the temp buffer?
2723 (set-buffer-multibyte nil
)
2724 (insert-buffer-substring mbox-buf body-start end
)
2726 ((string= character-coding
"quoted-printable")
2728 (or (mail-unquote-printable-region (point-min) (point-max)
2730 (message "Malformed MIME quoted-printable message")))
2731 ((and (string= character-coding
"base64") is-text-message
)
2733 (base64-decode-region (point-min) (point-max))
2734 (error (message "%s" (cdr err
)))))
2735 ((eq character-coding
'uuencode
)
2736 (error "uuencoded messages are not supported yet"))
2738 (rmail-decode-region (point-min) (point-max)
2739 coding-system view-buf
)))
2740 (with-current-buffer rmail-view-buffer
2741 ;; Prepare the separator (blank line) before the body.
2742 (goto-char (point-min))
2744 ;; Unquote quoted From lines
2745 (while (re-search-forward "^>+From " nil t
)
2749 (goto-char (point-min)))
2750 ;; Copy the headers to the front of the message view buffer.
2751 (rmail-copy-headers beg end
))
2752 ;; highlight the message, activate any URL like text and add
2753 ;; special highlighting for and quoted material.
2754 (with-current-buffer rmail-view-buffer
2755 (goto-char (point-min))
2756 (rmail-highlight-headers)
2757 ;(rmail-activate-urls)
2758 ;(rmail-process-quoted-material)
2760 ;; Update the mode-line with message status information and swap
2761 ;; the view buffer/mail buffer contents.
2762 (rmail-display-labels)
2763 (rmail-swap-buffers)
2764 (setq rmail-buffer-swapped t
)
2765 (run-hooks 'rmail-show-message-hook
)
2766 (when (> (- end beg
) rmail-show-message-verbose-min
)
2767 (message "Showing message %d...done" msg
))))
2770 (defun rmail-copy-headers (beg end
&optional ignored-headers
)
2771 "Copy displayed header fields to the message viewer buffer.
2772 BEG and END marks the start and end positions of the message in
2773 the mbox buffer. If the optional argument IGNORED-HEADERS is
2774 non-nil, ignore all header fields whose names match that regexp.
2775 Otherwise, if `rmail-displayed-headers' is non-nil, copy only
2776 those header fields whose names match that regexp. Otherwise,
2777 copy all header fields whose names do not match
2778 `rmail-ignored-headers' (unless they also match
2779 `rmail-nonignored-headers'). Moves point in the message viewer
2780 buffer to the end of the headers."
2781 (let ((header-start-regexp "\n[^ \t]")
2783 (with-current-buffer rmail-buffer
2784 (when (search-forward "\n\n" nil t
)
2787 ;; Put point right after the From header line.
2788 (narrow-to-region beg
(point))
2789 (goto-char (point-min))
2790 (unless (re-search-forward header-start-regexp nil t
)
2791 (rmail-error-bad-format))
2794 ;; Handle the case where all headers should be copied.
2795 ((eq rmail-header-style
'full
)
2796 (prepend-to-buffer rmail-view-buffer beg
(point-max))
2797 ;; rmail-show-message-1 expects this function to leave point
2798 ;; at the end of the headers.
2800 (let ((len (- (point-max) beg
)))
2801 (with-current-buffer rmail-view-buffer
2802 (goto-char (1+ len
)))))
2804 ;; Handle the case where the headers matching the displayed
2805 ;; headers regexp should be copied.
2806 ((and rmail-displayed-headers
(null ignored-headers
))
2809 (setq lim
(if (re-search-forward header-start-regexp nil t
)
2810 (1+ (match-beginning 0))
2812 (when (looking-at rmail-displayed-headers
)
2813 (append-to-buffer rmail-view-buffer
(point) lim
))
2815 ;; Handle the ignored headers.
2816 ((or ignored-headers
(setq ignored-headers rmail-ignored-headers
))
2817 (while (and ignored-headers
(not (eobp)))
2819 (setq lim
(if (re-search-forward header-start-regexp nil t
)
2820 (1+ (match-beginning 0))
2822 (if (and (looking-at ignored-headers
)
2823 (not (looking-at rmail-nonignored-headers
)))
2825 (append-to-buffer rmail-view-buffer
(point) lim
)
2827 (t (error "No headers selected for display!"))))))))
2829 (defun rmail-redecode-body (coding)
2830 "Decode the body of the current message using coding system CODING.
2831 This is useful with mail messages that have malformed or missing
2834 This function assumes that the current message is already decoded
2835 and displayed in the RMAIL buffer, but the coding system used to
2836 decode it was incorrect. It then decodes the message again,
2837 using the coding system CODING."
2838 (interactive "zCoding system for re-decoding this message: ")
2839 (when (not rmail-enable-mime
)
2840 (with-current-buffer rmail-buffer
2841 (rmail-swap-buffers-maybe)
2844 (let ((msgbeg (rmail-msgbeg rmail-current-message
))
2845 (msgend (rmail-msgend rmail-current-message
))
2846 (buffer-read-only nil
)
2847 body-start x-coding-header old-coding
)
2848 (narrow-to-region msgbeg msgend
)
2849 (goto-char (point-min))
2850 (unless (setq body-start
(search-forward "\n\n" (point-max) 1))
2851 (error "No message body"))
2854 ;; Narrow to headers
2855 (narrow-to-region (point-min) body-start
)
2856 (setq x-coding-header
(goto-char (point-min)))
2857 (if (not (re-search-forward "^X-Coding-System: *\\(.*\\)$" nil t
))
2858 (setq old-coding
(rmail-get-coding-system))
2859 (setq old-coding
(intern (match-string 1)))
2860 (setq x-coding-header
(point)))
2861 (check-coding-system old-coding
)
2862 ;; Make sure the new coding system uses the same EOL
2863 ;; conversion, to prevent ^M characters from popping up
2864 ;; all over the place.
2865 (let ((eol-type (coding-system-eol-type old-coding
)))
2866 (if (numberp eol-type
)
2868 (coding-system-change-eol-conversion coding eol-type
))))
2869 (when (not (coding-system-equal
2870 (coding-system-base old-coding
)
2871 (coding-system-base coding
)))
2872 ;; Rewrite the coding-system header.
2873 (goto-char x-coding-header
)
2874 (if (> (point) (point-min))
2875 (delete-region (line-beginning-position) (point))
2879 (insert "X-Coding-System: "
2880 (symbol-name coding
))))
2881 (rmail-show-message))))))
2883 (defun rmail-highlight-headers ()
2884 "Highlight the headers specified by `rmail-highlighted-headers'.
2885 Uses the face specified by `rmail-highlight-face'."
2886 (if rmail-highlighted-headers
2888 (search-forward "\n\n" nil
'move
)
2890 (narrow-to-region (point-min) (point))
2891 (let ((case-fold-search t
)
2892 (inhibit-read-only t
)
2893 ;; When rmail-highlight-face is removed, just
2894 ;; use 'rmail-highlight here.
2895 (face (or rmail-highlight-face
2896 (if (face-differs-from-default-p 'bold
)
2898 ;; List of overlays to reuse.
2899 (overlays rmail-overlay-list
))
2900 (goto-char (point-min))
2901 (while (re-search-forward rmail-highlighted-headers nil t
)
2902 (skip-chars-forward " \t")
2905 (while (progn (forward-line 1)
2906 (looking-at "[ \t]")))
2907 ;; Back up over newline, then trailing spaces or tabs
2909 (while (member (preceding-char) '(? ?
\t))
2912 ;; Reuse an overlay we already have.
2914 (setq overlay
(car overlays
)
2915 overlays
(cdr overlays
))
2916 (overlay-put overlay
'face face
)
2917 (move-overlay overlay beg
(point)))
2918 ;; Make a new overlay and add it to
2919 ;; rmail-overlay-list.
2920 (setq overlay
(make-overlay beg
(point)))
2921 (overlay-put overlay
'face face
)
2922 (setq rmail-overlay-list
2923 (cons overlay rmail-overlay-list
))))))))))
2925 (defun rmail-auto-file ()
2926 "Automatically move a message into a sub-folder based on criteria.
2927 Called when a new message is displayed."
2928 (if (or (zerop rmail-total-messages
)
2929 (rmail-message-attr-p rmail-current-message
"...F")
2930 (not (string= (buffer-file-name)
2931 (expand-file-name rmail-file-name
))))
2932 ;; Do nothing if the message has already been filed or if there
2935 ;; Find out some basics (common fields)
2936 (let ((from (mail-fetch-field "from"))
2937 (subj (mail-fetch-field "subject"))
2938 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2939 (d rmail-automatic-folder-directives
)
2940 (directive-loop nil
)
2943 (setq folder
(car (car d
))
2944 directive-loop
(cdr (car d
)))
2945 (while (and (car directive-loop
)
2947 ((string= (car directive-loop
) "from") from
)
2948 ((string= (car directive-loop
) "to") to
)
2949 ((string= (car directive-loop
) "subject") subj
)
2950 (t (mail-fetch-field (car directive-loop
))))))
2951 (and f
(string-match (car (cdr directive-loop
)) f
))))
2952 (setq directive-loop
(cdr (cdr directive-loop
))))
2953 ;; If there are no directives left, then it was a complete match.
2954 (if (null directive-loop
)
2956 (rmail-delete-forward)
2957 (if (string= "/dev/null" folder
)
2958 (rmail-delete-message)
2959 (rmail-output folder
1)
2961 (setq d
(cdr d
))))))
2963 ;; Simple message motion commands.
2965 (defun rmail-next-message (n)
2966 "Show following message whether deleted or not.
2967 With prefix arg N, moves forward N messages, or backward if N is negative."
2969 (set-buffer rmail-buffer
)
2970 (rmail-maybe-set-message-counters)
2971 (rmail-show-message (+ rmail-current-message n
)))
2973 (defun rmail-previous-message (n)
2974 "Show previous message whether deleted or not.
2975 With prefix arg N, moves backward N messages, or forward if N is negative."
2977 (rmail-next-message (- n
)))
2979 (defun rmail-next-undeleted-message (n)
2980 "Show following non-deleted message.
2981 With prefix arg N, moves forward N non-deleted messages,
2982 or backward if N is negative.
2984 Returns t if a new message is being shown, nil otherwise."
2986 (set-buffer rmail-buffer
)
2987 (rmail-maybe-set-message-counters)
2988 (let ((lastwin rmail-current-message
)
2989 (current rmail-current-message
))
2990 (while (and (> n
0) (< current rmail-total-messages
))
2991 (setq current
(1+ current
))
2992 (if (not (rmail-message-deleted-p current
))
2993 (setq lastwin current n
(1- n
))))
2994 (while (and (< n
0) (> current
1))
2995 (setq current
(1- current
))
2996 (if (not (rmail-message-deleted-p current
))
2997 (setq lastwin current n
(1+ n
))))
2998 (if (/= lastwin rmail-current-message
)
2999 (progn (rmail-show-message lastwin
)
3002 (message "No previous nondeleted message"))
3004 (message "No following nondeleted message"))
3007 (defun rmail-previous-undeleted-message (n)
3008 "Show previous non-deleted message.
3009 With prefix argument N, moves backward N non-deleted messages,
3010 or forward if N is negative."
3012 (rmail-next-undeleted-message (- n
)))
3014 (defun rmail-first-message ()
3015 "Show first message in file."
3017 (rmail-maybe-set-message-counters)
3018 (rmail-show-message 1))
3020 (defun rmail-last-message ()
3021 "Show last message in file."
3023 (rmail-maybe-set-message-counters)
3024 (rmail-show-message rmail-total-messages
))
3026 (defun rmail-next-error-move (msg-pos bad-marker
)
3027 "Move to an error locus (probably grep hit) in an Rmail buffer.
3028 MSG-POS is a marker pointing at the error message in the grep buffer.
3029 BAD-MARKER is a marker that ought to point at where to move to,
3030 but probably is garbage."
3032 (let* ((message-loc (compilation--message->loc
3033 (get-text-property msg-pos
'compilation-message
3034 (marker-buffer msg-pos
))))
3035 (column (car message-loc
))
3036 (linenum (cadr message-loc
))
3039 msgnum msgbeg msgend
3043 ;; Look at the whole Rmail file.
3044 (rmail-swap-buffers-maybe)
3049 ;; Find the line that the error message points at.
3050 (goto-char (point-min))
3051 (forward-line (1- linenum
))
3054 ;; Find the text at the start of the line,
3055 ;; before the first = sign.
3056 ;; This text has a good chance of being also in the
3059 (skip-chars-forward "^=\n")
3060 (setq line-text
(buffer-substring pos
(point))))
3062 ;; Find which message this position is in,
3063 ;; and the limits of that message.
3064 (setq msgnum
(rmail-what-message pos
))
3065 (setq msgbeg
(rmail-msgbeg msgnum
))
3066 (setq msgend
(rmail-msgend msgnum
))
3068 ;; Find which header this locus is in,
3069 ;; or if it's in the message body,
3070 ;; and the line-based position within that.
3072 (let ((header-end msgend
))
3073 (if (search-forward "\n\n" nil t
)
3074 (setq header-end
(point)))
3075 (if (>= pos header-end
)
3076 (setq line-number-within
3077 (count-lines header-end pos
))
3079 (unless (looking-at "^[^ \t]")
3080 (re-search-backward "^[^ \t]"))
3081 (looking-at "[^:\n]*[:\n]")
3082 (setq header-field
(match-string 0)
3083 line-number-within
(count-lines (point) pos
))))))
3085 ;; Display the right message.
3086 (rmail-show-message msgnum
)
3088 ;; Move to the right position within the displayed message.
3089 ;; Or at least try. The decoded message's lines may not
3090 ;; correspond to the lines in the inbox file.
3091 (goto-char (point-min))
3094 (re-search-forward (concat "^" (regexp-quote header-field
)) nil t
)
3095 (forward-line line-number-within
))
3096 (search-forward "\n\n" nil t
)
3097 (if (re-search-forward (concat "^" (regexp-quote line-text
)) nil t
)
3098 (goto-char (match-beginning 0))))
3100 ;; If the decoded message doesn't have enough lines,
3101 ;; go to the beginning rather than the end.
3102 (goto-char (point-min))
3103 ;; Otherwise, go to the right column.
3105 (forward-char column
)))))
3107 (defun rmail-what-message (&optional pos
)
3108 "Return message number POS (or point) is in."
3109 (let* ((high rmail-total-messages
)
3113 (with-current-buffer (if (rmail-buffers-swapped-p)
3117 (while (> (- high low
) 1)
3118 (if (>= where
(rmail-msgbeg mid
))
3121 (setq mid
(+ low
(/ (- high low
) 2))))
3122 (if (>= where
(rmail-msgbeg high
)) high low
)))
3124 ;; Searching in Rmail file.
3126 (defun rmail-search-message (msg regexp
)
3127 "Return non-nil, if for message number MSG, regexp REGEXP matches."
3128 ;; This is adequate because its only caller, rmail-search,
3129 ;; unswaps the buffers.
3130 (goto-char (rmail-msgbeg msg
))
3131 (if rmail-enable-mime
3132 (if rmail-search-mime-message-function
3133 (funcall rmail-search-mime-message-function msg regexp
)
3134 (error "You must set `rmail-search-mime-message-function'"))
3135 (re-search-forward regexp
(rmail-msgend msg
) t
)))
3137 (defvar rmail-search-last-regexp nil
)
3138 (defun rmail-search (regexp &optional n
)
3139 "Show message containing next match for REGEXP (but not the current msg).
3140 Prefix argument gives repeat count; negative argument means search
3141 backwards (through earlier messages).
3142 Interactively, empty argument means use same regexp used last time."
3144 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
3146 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3150 (if rmail-search-last-regexp
3151 (concat ", default "
3152 rmail-search-last-regexp
"): ")
3154 (setq regexp
(read-string prompt
))
3155 (cond ((not (equal regexp
""))
3156 (setq rmail-search-last-regexp regexp
))
3157 ((not rmail-search-last-regexp
)
3158 (error "No previous Rmail search string")))
3159 (list rmail-search-last-regexp
3160 (prefix-numeric-value current-prefix-arg
))))
3162 (message "%sRmail search for %s..."
3163 (if (< n
0) "Reverse " "")
3165 (set-buffer rmail-buffer
)
3166 (let ((orig-message rmail-current-message
)
3167 (msg rmail-current-message
)
3169 (opoint (if (rmail-buffers-swapped-p) (point)))
3171 (rmail-swap-buffers-maybe)
3172 (rmail-maybe-set-message-counters)
3176 ;; Check messages one by one, advancing message number up or
3177 ;; down but searching forward through each message.
3179 (while (and (null found
) (> msg
1))
3181 found
(rmail-search-message msg regexp
)))
3182 (while (and (null found
) (< msg rmail-total-messages
))
3184 found
(rmail-search-message msg regexp
))))
3185 (setq n
(+ n
(if reversep
1 -
1))))
3188 (rmail-show-message msg
)
3189 ;; Search forward (if this is a normal search) or backward
3190 ;; (if this is a reverse search) through this message to
3191 ;; position point. This search may fail because REGEXP
3192 ;; was found in the hidden portion of this message. In
3193 ;; that case, move point to the beginning of visible
3197 (goto-char (point-max))
3198 (re-search-backward regexp nil
'move
))
3199 (goto-char (point-min))
3200 (re-search-forward regexp nil t
))
3201 (message "%sRmail search for %s...done"
3202 (if reversep
"Reverse " "")
3204 (rmail-show-message orig-message
)
3205 (if opoint
(goto-char opoint
))
3207 (message "Search failed: %s" regexp
)))))
3209 (defun rmail-search-backwards (regexp &optional n
)
3210 "Show message containing previous match for REGEXP.
3211 Prefix argument gives repeat count; negative argument means search
3212 forward (through later messages).
3213 Interactively, empty argument means use same regexp used last time."
3215 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
3217 (concat (if reversep
"Reverse " "") "Rmail search (regexp"))
3221 (if rmail-search-last-regexp
3222 (concat ", default "
3223 rmail-search-last-regexp
"): ")
3225 (setq regexp
(read-string prompt
))
3226 (cond ((not (equal regexp
""))
3227 (setq rmail-search-last-regexp regexp
))
3228 ((not rmail-search-last-regexp
)
3229 (error "No previous Rmail search string")))
3230 (list rmail-search-last-regexp
3231 (prefix-numeric-value current-prefix-arg
))))
3232 (rmail-search regexp
(- (or n
1))))
3234 ;; Scan for attributes, and compare subjects.
3236 (defun rmail-first-unseen-message ()
3237 "Return message number of first message which has `unseen' attribute."
3238 (rmail-maybe-set-message-counters)
3243 (while (and (not found
) (<= current rmail-total-messages
))
3244 (if (rmail-message-attr-p current
"......U")
3245 (setq found current
))
3246 (setq current
(1+ current
))))
3249 (defun rmail-simplified-subject (&optional msgnum
)
3250 "Return the simplified subject of message MSGNUM (or current message).
3251 Simplifying the subject means stripping leading and trailing whitespace,
3252 and typical reply prefixes such as Re:."
3253 (let ((subject (or (rmail-get-header "Subject" msgnum
) "")))
3254 (setq subject
(rfc2047-decode-string subject
))
3255 (if (string-match "\\`[ \t]+" subject
)
3256 (setq subject
(substring subject
(match-end 0))))
3257 (if (string-match rmail-reply-regexp subject
)
3258 (setq subject
(substring subject
(match-end 0))))
3259 (if (string-match "[ \t]+\\'" subject
)
3260 (setq subject
(substring subject
0 (match-beginning 0))))
3261 ;; If Subject is long, mailers will break it into several lines at
3262 ;; arbitrary places, so normalize whitespace by replacing every
3263 ;; run of whitespace characters with a single space.
3264 (setq subject
(replace-regexp-in-string "[ \t\n]+" " " subject
))
3267 (defun rmail-simplified-subject-regexp ()
3268 "Return a regular expression matching the current simplified subject.
3269 The idea is to match it against simplified subjects of other messages."
3270 (let ((subject (rmail-simplified-subject)))
3271 (setq subject
(regexp-quote subject
))
3272 ;; Hide commas so it will work ok if parsed as a comma-separated list
3275 (replace-regexp-in-string "," "\054" subject t t
))
3276 (concat "\\`" subject
"\\'")))
3278 (defun rmail-next-same-subject (n)
3279 "Go to the next mail message having the same subject header.
3280 With prefix argument N, do this N times.
3281 If N is negative, go backwards instead."
3283 (let ((subject (rmail-simplified-subject))
3285 (i rmail-current-message
)
3287 (while (and (/= n
0)
3289 (< i rmail-total-messages
)
3292 (while (and (not done
)
3294 (< i rmail-total-messages
)
3296 (setq i
(if forward
(1+ i
) (1- i
)))
3297 (setq done
(string-equal subject
(rmail-simplified-subject i
))))
3298 (if done
(setq found i
)))
3299 (setq n
(if forward
(1- n
) (1+ n
))))
3301 (rmail-show-message found
)
3302 (error "No %s message with same subject"
3303 (if forward
"following" "previous")))))
3305 (defun rmail-previous-same-subject (n)
3306 "Go to the previous mail message having the same subject header.
3307 With prefix argument N, do this N times.
3308 If N is negative, go forwards instead."
3310 (rmail-next-same-subject (- n
)))
3312 ;;;; *** Rmail Message Deletion Commands ***
3314 (defun rmail-message-deleted-p (n)
3315 "Return non-nil if message number N is deleted (in `rmail-deleted-vector')."
3316 (= (aref rmail-deleted-vector n
) ?D
))
3318 (defun rmail-set-message-deleted-p (n state
)
3319 "Set the deleted state of message number N (in `rmail-deleted-vector').
3320 STATE non-nil means mark as deleted."
3321 (aset rmail-deleted-vector n
(if state ?D ?\s
)))
3323 (defun rmail-delete-message ()
3324 "Delete this message and stay on it."
3326 (rmail-set-attribute rmail-deleted-attr-index t
)
3327 (run-hooks 'rmail-delete-message-hook
))
3329 (defun rmail-undelete-previous-message ()
3330 "Back up to deleted message, select it, and undelete it."
3332 (set-buffer rmail-buffer
)
3333 (let ((msg rmail-current-message
))
3334 (while (and (> msg
0)
3335 (not (rmail-message-deleted-p msg
)))
3336 (setq msg
(1- msg
)))
3338 (error "No previous deleted message")
3339 (if (/= msg rmail-current-message
)
3340 (rmail-show-message msg
))
3341 (rmail-set-attribute rmail-deleted-attr-index nil
)
3342 (if (rmail-summary-exists)
3343 (with-current-buffer rmail-summary-buffer
3344 (rmail-summary-mark-undeleted msg
)))
3345 (rmail-maybe-display-summary))))
3347 (defun rmail-delete-forward (&optional backward
)
3348 "Delete this message and move to next nondeleted one.
3349 Deleted messages stay in the file until the \\[rmail-expunge] command is given.
3350 With prefix argument, delete and move backward.
3352 Returns t if a new message is displayed after the delete, or nil otherwise."
3354 (rmail-set-attribute rmail-deleted-attr-index t
)
3355 (run-hooks 'rmail-delete-message-hook
)
3356 (let ((del-msg rmail-current-message
))
3357 (if (rmail-summary-exists)
3358 (rmail-select-summary
3359 (rmail-summary-mark-deleted del-msg
)))
3360 (prog1 (rmail-next-undeleted-message (if backward -
1 1))
3361 (rmail-maybe-display-summary))))
3363 (defun rmail-delete-backward ()
3364 "Delete this message and move to previous nondeleted one.
3365 Deleted messages stay in the file until the \\[rmail-expunge] command is given."
3367 (rmail-delete-forward t
))
3371 ;; Compute the message number a given message would have after expunging.
3372 ;; The present number of the message is OLDNUM.
3373 ;; DELETEDVEC should be rmail-deleted-vector.
3374 ;; The value is nil for a message that would be deleted.
3375 (defun rmail-msg-number-after-expunge (deletedvec oldnum
)
3376 (if (or (null oldnum
) (= (aref deletedvec oldnum
) ?D
))
3381 (if (/= (aref deletedvec i
) ?D
)
3382 (setq newnum
(1+ newnum
)))
3386 (defun rmail-expunge-confirmed ()
3387 "Return t if expunge is needed and desirable.
3388 If `rmail-confirm-expunge' is non-nil, ask user to confirm."
3389 (set-buffer rmail-buffer
)
3390 (and (stringp rmail-deleted-vector
)
3391 (string-match "D" rmail-deleted-vector
)
3392 (if rmail-confirm-expunge
3393 (funcall rmail-confirm-expunge
3394 "Erase deleted messages from Rmail file? ")
3397 (defun rmail-only-expunge (&optional dont-show
)
3398 "Actually erase all deleted messages in the file."
3400 (rmail-swap-buffers-maybe)
3401 (set-buffer rmail-buffer
)
3402 (message "Expunging deleted messages...")
3403 ;; Discard all undo records for this buffer.
3404 (or (eq buffer-undo-list t
)
3405 (setq buffer-undo-list nil
))
3406 (rmail-maybe-set-message-counters)
3407 (let* ((omax (- (buffer-size) (point-max)))
3408 (omin (- (buffer-size) (point-min)))
3409 (opoint (if (and (> rmail-current-message
0)
3410 (rmail-message-deleted-p rmail-current-message
))
3412 (if rmail-enable-mime
3413 (with-current-buffer rmail-view-buffer
3414 (- (point)(point-min)))
3415 (- (point) (point-min)))))
3416 (messages-head (cons (aref rmail-message-vector
0) nil
))
3417 (messages-tail messages-head
)
3418 ;; Don't make any undo records for the expunging.
3419 (buffer-undo-list t
)
3424 (goto-char (point-min))
3428 (new-msgref (list (list 0)))
3429 (buffer-read-only nil
)
3430 (total rmail-total-messages
)
3431 (new-message-number rmail-current-message
)
3432 (messages rmail-message-vector
)
3433 (deleted rmail-deleted-vector
)
3434 (summary rmail-summary-vector
))
3435 (setq rmail-total-messages nil
3436 rmail-current-message nil
3437 rmail-message-vector nil
3438 rmail-deleted-vector nil
3439 rmail-summary-vector nil
)
3441 (while (<= number total
)
3442 (if (= (aref deleted number
) ?D
)
3444 (delete-region (aref messages number
)
3445 (aref messages
(1+ number
)))
3446 (move-marker (aref messages number
) nil
)
3447 (if (> new-message-number counter
)
3448 (setq new-message-number
(1- new-message-number
))))
3449 (setq counter
(1+ counter
))
3451 (setcdr messages-tail
3452 (cons (aref messages number
) nil
)))
3454 (cons (if (= counter number
) (aref summary
(1- number
)))
3457 (cons (aref rmail-msgref-vector number
)
3459 (setcar (car new-msgref
) counter
))
3460 (if (zerop (%
(setq number
(1+ number
)) 20))
3461 (message "Expunging deleted messages...%d" number
)))
3463 (setcdr messages-tail
3464 (cons (aref messages number
) nil
)))
3465 (setq rmail-current-message new-message-number
3466 rmail-total-messages counter
3467 rmail-message-vector
(apply 'vector messages-head
)
3468 rmail-deleted-vector
(make-string (1+ counter
) ?\s
)
3469 rmail-summary-vector
(vconcat (nreverse new-summary
))
3470 rmail-msgref-vector
(apply 'vector
(nreverse new-msgref
))
3472 (message "Expunging deleted messages...done")
3474 (narrow-to-region (- (buffer-size) omin
) (- (buffer-size) omax
)))
3476 (rmail-show-message (min rmail-current-message rmail-total-messages
)))
3477 (if rmail-enable-mime
3478 (goto-char (+ (point-min) opoint
))
3479 (goto-char (+ (point) opoint
))))))
3481 ;; The DONT-SHOW argument is new in 23. Does not seem very important.
3482 (defun rmail-expunge (&optional dont-show
)
3483 "Erase deleted messages from Rmail file and summary buffer.
3484 This always shows a message (so as not to leave the Rmail buffer
3485 unswapped), and always updates any summary (so that it remains
3486 consistent with the Rmail buffer). If DONT-SHOW is non-nil, it
3487 does not pop any summary buffer."
3489 (when (rmail-expunge-confirmed)
3490 (rmail-modify-format)
3491 (let ((was-deleted (rmail-message-deleted-p rmail-current-message
))
3492 (was-swapped (rmail-buffers-swapped-p)))
3493 (rmail-only-expunge t
)
3494 ;; We always update the summary buffer, so that the contents
3495 ;; remain consistent with the rmail buffer.
3496 ;; The only difference is, in the dont-show case, we use a
3497 ;; cut-down version of rmail-select-summary that does not pop
3498 ;; the summary buffer. It's only used by rmail-quit, which is
3499 ;; just going to bury any summary immediately after. If we made
3500 ;; rmail-quit bury the summary first, dont-show could be removed.
3501 ;; But the expunge might not be confirmed...
3502 (if (rmail-summary-exists)
3504 (let ((total rmail-total-messages
))
3505 (with-current-buffer rmail-summary-buffer
3506 (let ((rmail-total-messages total
))
3507 (rmail-update-summary))))
3508 (rmail-select-summary (rmail-update-summary))))
3509 ;; We always show a message, because (rmail-only-expunge t)
3510 ;; leaves the rmail buffer unswapped.
3511 ;; If we expunged the current message, a new one is current now,
3512 ;; so show it. If we weren't showing a message, show it.
3513 (if (or was-deleted
(not was-swapped
))
3514 (rmail-show-message-1 rmail-current-message
)
3515 ;; We can just show the same message that was being shown before.
3516 (rmail-display-labels)
3517 (rmail-swap-buffers)
3518 (setq rmail-buffer-swapped t
)))))
3520 ;;;; *** Rmail Mailing Commands ***
3522 (defun rmail-start-mail (&optional noerase to subject in-reply-to cc
3523 replybuffer sendactions same-window
3525 (let ((switch-function
3526 (cond (same-window nil
)
3527 (rmail-mail-new-frame 'switch-to-buffer-other-frame
)
3528 (t 'switch-to-buffer-other-window
)))
3531 ;; The function used here must behave like insert-buffer wrt
3532 ;; point and mark (see doc of sc-cite-original).
3533 (setq yank-action
(list 'insert-buffer replybuffer
)))
3534 (push (cons "cc" cc
) other-headers
)
3535 (push (cons "in-reply-to" in-reply-to
) other-headers
)
3537 (mapcar #'(lambda (elt)
3538 (cons (car elt
) (if (stringp (cdr elt
))
3539 (rfc2047-decode-string (cdr elt
)))))
3541 (if (stringp to
) (setq to
(rfc2047-decode-string to
)))
3542 (if (stringp in-reply-to
)
3543 (setq in-reply-to
(rfc2047-decode-string in-reply-to
)))
3544 (if (stringp cc
) (setq cc
(rfc2047-decode-string cc
)))
3545 (if (stringp subject
) (setq subject
(rfc2047-decode-string subject
)))
3547 (compose-mail to subject other-headers noerase
3548 switch-function yank-action sendactions
)
3549 (if (eq switch-function
'switch-to-buffer-other-frame
)
3550 ;; This is not a standard frame parameter; nothing except
3551 ;; sendmail.el looks at it.
3552 (modify-frame-parameters (selected-frame)
3553 '((mail-dedicated-frame . t
)))))))
3555 (defun rmail-mail-return (&optional newbuf
)
3556 "NEWBUF is a buffer to switch to."
3558 ;; If there is only one visible frame with no special handling,
3559 ;; consider deleting the mail window to return to Rmail.
3560 ((or (null (delq (selected-frame) (visible-frame-list)))
3561 (not (or (window-dedicated-p (frame-selected-window))
3562 (and pop-up-frames
(one-window-p))
3563 (cdr (assq 'mail-dedicated-frame
3564 (frame-parameters))))))
3565 (let (rmail-flag summary-buffer
)
3566 (and (not (one-window-p))
3567 (with-current-buffer
3568 (window-buffer (next-window (selected-window) 'not
))
3569 (setq rmail-flag
(eq major-mode
'rmail-mode
))
3570 (setq summary-buffer
3571 (and (boundp 'mail-bury-selects-summary
)
3572 mail-bury-selects-summary
3573 (boundp 'rmail-summary-buffer
)
3574 rmail-summary-buffer
3575 (buffer-name rmail-summary-buffer
)
3576 (not (get-buffer-window rmail-summary-buffer
))
3577 rmail-summary-buffer
))))
3579 ;; If the Rmail buffer has a summary, show that.
3580 (if summary-buffer
(switch-to-buffer summary-buffer
)
3582 (switch-to-buffer newbuf
))))
3583 ;; If the frame was probably made for this buffer, the user
3584 ;; probably wants to delete it now.
3585 ((display-multi-frame-p)
3586 (delete-frame (selected-frame)))
3587 ;; The previous frame is where normally they have the Rmail buffer
3589 (t (other-frame -
1))))
3591 (defun rmail-mail ()
3592 "Send mail in another window.
3593 While composing the message, use \\[mail-yank-original] to yank the
3594 original message into it."
3596 (rmail-start-mail nil nil nil nil nil rmail-view-buffer
))
3598 ;; FIXME should complain if there is nothing to continue.
3599 (defun rmail-continue ()
3600 "Continue composing outgoing message previously being composed."
3602 (rmail-start-mail t
))
3604 (defun rmail-reply (just-sender)
3605 "Reply to the current message.
3606 Normally include CC: to all other recipients of original message;
3607 prefix argument means ignore them. While composing the reply,
3608 use \\[mail-yank-original] to yank the original message into it."
3610 (if (zerop rmail-current-message
)
3611 (error "There is no message to reply to"))
3612 (let (from reply-to cc subject date to message-id references
3613 resent-to resent-cc resent-reply-to
3614 (msgnum rmail-current-message
))
3615 (rmail-apply-in-message
3616 rmail-current-message
3618 (search-forward "\n\n" nil
'move
)
3619 (narrow-to-region (point-min) (point))
3620 (setq from
(mail-fetch-field "from")
3621 reply-to
(or (mail-fetch-field "mail-reply-to" nil t
)
3622 (mail-fetch-field "reply-to" nil t
)
3624 subject
(mail-fetch-field "subject")
3625 date
(mail-fetch-field "date")
3626 message-id
(mail-fetch-field "message-id")
3627 references
(mail-fetch-field "references" nil nil t
)
3628 resent-reply-to
(mail-fetch-field "resent-reply-to" nil t
)
3629 ;; Bug#512. It's inappropriate to reply to these addresses.
3630 ;;; resent-cc (and (not just-sender)
3631 ;;; (mail-fetch-field "resent-cc" nil t))
3632 ;;; resent-to (or (mail-fetch-field "resent-to" nil t) "")
3633 ;;; resent-subject (mail-fetch-field "resent-subject")
3634 ;;; resent-date (mail-fetch-field "resent-date")
3635 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3638 (if (mail-fetch-field "mail-followup-to" nil t
)
3639 ;; If this header field is present, use it instead of the
3640 ;; To and CC fields.
3641 (setq to
(mail-fetch-field "mail-followup-to" nil t
))
3642 (setq cc
(or (mail-fetch-field "cc" nil t
) "")
3643 to
(or (mail-fetch-field "to" nil t
) ""))))))
3644 ;; Merge the resent-to and resent-cc into the to and cc.
3645 ;; Bug#512. It's inappropriate to reply to these addresses.
3646 ;;; (if (and resent-to (not (equal resent-to "")))
3647 ;;; (if (not (equal to ""))
3648 ;;; (setq to (concat to ", " resent-to))
3649 ;;; (setq to resent-to)))
3650 ;;; (if (and resent-cc (not (equal resent-cc "")))
3651 ;;; (if (not (equal cc ""))
3652 ;;; (setq cc (concat cc ", " resent-cc))
3653 ;;; (setq cc resent-cc)))
3654 ;; Add `Re: ' to subject if not there already.
3655 (and (stringp subject
)
3657 (concat rmail-reply-prefix
3658 (if (let ((case-fold-search t
))
3659 (string-match rmail-reply-regexp subject
))
3660 (substring subject
(match-end 0))
3664 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3665 ;; since they can handle the names unstripped.
3666 ;; I don't know whether there are other mailers that still
3667 ;; need the names to be stripped.
3668 ;;; (mail-strip-quoted-names reply-to)
3669 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3670 ;; header causes all the names in it to wind up in reply-to, not
3671 ;; in cc. But if what's left is an empty list, use the original.
3672 (let* ((reply-to-list (mail-dont-reply-to reply-to
)))
3673 (if (string= reply-to-list
"") reply-to reply-to-list
))
3675 (rmail-make-in-reply-to-field from date message-id
)
3678 ;; `mail-dont-reply-to' doesn't need `mail-strip-quoted-names'.
3679 (let* ((cc-list (mail-dont-reply-to
3680 (mail-strip-quoted-names
3681 (if (null cc
) to
(concat to
", " cc
))))))
3682 (if (string= cc-list
"") nil cc-list
)))
3683 (if (rmail-buffers-swapped-p)
3686 (list (list 'rmail-mark-message
3688 (with-current-buffer rmail-buffer
3689 (aref rmail-msgref-vector msgnum
))
3690 rmail-answered-attr-index
))
3692 (if (or references message-id
)
3693 (list (cons "References" (if references
3695 (mapconcat 'identity references
" ")
3699 (defun rmail-mark-message (buffer msgnum-list attribute
)
3700 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3701 This is use in the send-actions for message buffers.
3702 MSGNUM-LIST is a list of the form (MSGNUM)
3703 which is an element of rmail-msgref-vector."
3704 (with-current-buffer buffer
3705 (if (car msgnum-list
)
3706 (rmail-set-attribute attribute t
(car msgnum-list
)))))
3708 (defun rmail-make-in-reply-to-field (from date message-id
)
3715 (let ((tem (car (rfc822-addresses from
))))
3719 (regexp-quote (if (string-match "@[^@]*\\'" tem
)
3721 (match-beginning 0))
3724 ;; missing From, or Message-ID is sufficiently informative
3726 (concat message-id
" (" tem
")"))
3727 ;; Copy TEM, discarding text properties.
3728 (setq tem
(copy-sequence tem
))
3729 (set-text-properties 0 (length tem
) nil tem
)
3730 (setq tem
(copy-sequence tem
))
3731 ;; Use prin1 to fake RFC822 quoting
3732 (let ((field (prin1-to-string tem
)))
3734 (concat field
"'s message of " date
)
3736 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3737 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3738 ;; These strings both match all non-ASCII characters.
3739 (or (string-match (concat "\\`[ \t]*\\(" bar
3740 "\\)\\(<" foo
"@" foo
">\\)?[ \t]*\\'")
3741 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3743 (string-match (concat "\\`[ \t]*<" foo
"@" foo
">[ \t]*(\\("
3744 bar
"\\))[ \t]*\\'")
3745 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3747 (let ((start (match-beginning 1))
3748 (end (match-end 1)))
3749 ;; Trim whitespace which above regexp match allows
3750 (while (and (< start end
)
3751 (memq (aref from start
) '(?
\t ?\s
)))
3752 (setq start
(1+ start
)))
3753 (while (and (< start end
)
3754 (memq (aref from
(1- end
)) '(?
\t ?\s
)))
3755 (setq end
(1- end
)))
3756 (let ((field (substring from start end
)))
3757 (if date
(setq field
(concat "message from " field
" on " date
)))
3759 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3760 (concat message-id
" (" field
")")
3763 ;; If we can't kludge it simply, do it correctly
3764 (let ((mail-use-rfc822 t
))
3765 (rmail-make-in-reply-to-field from date message-id
)))))
3767 (defun rmail-forward (resend)
3768 "Forward the current message to another user.
3769 With prefix argument, \"resend\" the message instead of forwarding it;
3770 see the documentation of `rmail-resend'."
3773 (call-interactively 'rmail-resend
)
3774 (let ((forward-buffer rmail-buffer
)
3775 (msgnum rmail-current-message
)
3776 (subject (concat "["
3777 (let ((from (or (mail-fetch-field "From")
3778 (mail-fetch-field ">From"))))
3780 (concat (mail-strip-quoted-names from
) ": ")
3782 (or (mail-fetch-field "Subject") "")
3784 (if (rmail-start-mail
3785 nil nil subject nil nil nil
3786 (list (list 'rmail-mark-message
3788 (with-current-buffer rmail-buffer
3789 (aref rmail-msgref-vector msgnum
))
3790 rmail-forwarded-attr-index
))
3791 ;; If only one window, use it for the mail buffer.
3792 ;; Otherwise, use another window for the mail buffer
3793 ;; so that the Rmail buffer remains visible
3794 ;; and sending the mail will get back to it.
3795 (and (not rmail-mail-new-frame
) (one-window-p t
)))
3796 ;; The mail buffer is now current.
3798 ;; Insert after header separator--before signature if any.
3801 (if (and rmail-enable-mime rmail-enable-mime-composing
)
3803 (funcall rmail-insert-mime-forwarded-message-function
3805 ;; rmail-insert-mime-forwarded-message-function
3806 ;; works by inserting MML tags into forward-buffer.
3807 ;; The MUA will need to convert it to MIME before
3808 ;; sending. mail-encode-mml tells them to do that.
3809 ;; message.el does that automagically.
3810 (or (eq mail-user-agent
'message-user-agent
)
3811 (setq mail-encode-mml t
)))
3812 (insert "------- Start of forwarded message -------\n")
3813 ;; Quote lines with `- ' if they start with `-'.
3814 (let ((beg (point)) end
)
3815 (setq end
(point-marker))
3816 (set-marker-insertion-type end t
)
3817 (insert-buffer-substring forward-buffer
)
3819 (while (re-search-forward "^-" end t
)
3824 (skip-chars-backward "\n")
3827 (delete-region (point) end
)
3828 (set-marker end nil
))
3829 (insert "------- End of forwarded message -------\n"))
3832 (defun rmail-resend (address &optional from comment mail-alias-file
)
3833 "Resend current message to ADDRESSES.
3834 ADDRESSES should be a single address, a string consisting of several
3835 addresses separated by commas, or a list of addresses.
3837 Optional FROM is the address to resend the message from, and
3838 defaults from the value of `user-mail-address'.
3839 Optional COMMENT is a string to insert as a comment in the resent message.
3840 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3841 typically for purposes of moderating a list."
3842 (interactive "sResend to: ")
3844 (require 'mailalias
)
3845 (unless (or (eq rmail-view-buffer
(current-buffer))
3846 (eq rmail-buffer
(current-buffer)))
3847 (error "Not an Rmail buffer"))
3848 (if (not from
) (setq from user-mail-address
))
3849 (let ((tembuf (generate-new-buffer " sendmail temp"))
3850 (case-fold-search nil
)
3851 (mail-personal-alias-file
3852 (or mail-alias-file mail-personal-alias-file
))
3853 (mailbuf rmail-buffer
))
3855 (with-current-buffer tembuf
3856 ;;>> Copy message into temp buffer
3857 (if rmail-enable-mime
3858 (if rmail-insert-mime-resent-message-function
3859 (funcall rmail-insert-mime-resent-message-function mailbuf
)
3860 (error "You must set `rmail-insert-mime-resent-message-function'"))
3861 (insert-buffer-substring mailbuf
))
3862 (goto-char (point-min))
3863 ;; Delete any Sender field, since that's not specifiable.
3864 ; Only delete Sender fields in the actual header.
3865 (re-search-forward "^$" nil
'move
)
3866 ; Using "while" here rather than "if" because some buggy mail
3867 ; software may have inserted multiple Sender fields.
3868 (while (re-search-backward "^Sender:" nil t
)
3872 (while (looking-at "[ \t]")
3874 (delete-region beg
(point))))
3875 ; Go back to the beginning of the buffer so the Resent- fields
3876 ; are inserted there.
3877 (goto-char (point-min))
3878 ;;>> Insert resent-from:
3879 (insert "Resent-From: " from
"\n")
3880 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3881 ;;>> Insert resent-to: and bcc if need be.
3882 (let ((before (point)))
3884 (insert "Resent-Bcc: " (user-login-name) "\n"))
3885 (insert "Resent-To: " (if (stringp address
)
3887 (mapconcat 'identity address
",\n\t"))
3889 ;; Expand abbrevs in the recipients.
3891 (if (featurep 'mailabbrev
)
3892 (let ((end (point-marker))
3893 (local-abbrev-table mail-abbrevs
)
3894 (old-syntax-table (syntax-table)))
3895 (if (and (not (vectorp mail-abbrevs
))
3896 (file-exists-p mail-personal-alias-file
))
3897 (build-mail-abbrevs))
3898 (unless mail-abbrev-syntax-table
3899 (mail-abbrev-make-syntax-table))
3900 (set-syntax-table mail-abbrev-syntax-table
)
3902 (while (and (< (point) end
)
3903 (progn (forward-word 1)
3906 (set-syntax-table old-syntax-table
))
3907 (expand-mail-aliases before
(point)))))
3908 ;;>> Set up comment, if any.
3909 (if (and (sequencep comment
) (not (zerop (length comment
))))
3910 (let ((before (point))
3913 (or (eolp) (insert "\n"))
3914 (setq after
(point))
3916 (while (< (point) after
)
3917 (insert "Resent-Comment: ")
3919 ;; Don't expand aliases in the destination fields
3920 ;; of the original message.
3922 (funcall send-mail-function
)))
3923 (kill-buffer tembuf
))
3924 (with-current-buffer rmail-buffer
3925 (rmail-set-attribute rmail-resent-attr-index t rmail-current-message
))))
3927 (defvar mail-unsent-separator
3928 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3929 "^ *---+ +Returned message +---+ *$\\|"
3930 "^ *---+ *Returned mail follows *---+ *$\\|"
3931 "^Start of returned message$\\|"
3932 "^---+ Below this line is a copy of the message.$\\|"
3933 "^ *---+ +Original message +---+ *$\\|"
3934 "^ *--+ +begin message +--+ *$\\|"
3935 "^ *---+ +Original message follows +---+ *$\\|"
3936 "^ *---+ +Your message follows +---+ *$\\|"
3937 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3938 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3939 "A regexp that matches the separator before the text of a failed message.")
3941 (defvar mail-mime-unsent-header
"^Content-Type: message/rfc822 *$"
3942 "A regexp that matches the header of a MIME body part with a failed message.")
3944 ;; This is a cut-down version of rmail-clear-headers from Emacs 22.
3945 ;; It doesn't have the same functionality, hence the name change.
3946 (defun rmail-delete-headers (regexp)
3947 "Delete any mail headers matching REGEXP.
3948 The message should be narrowed to just the headers."
3950 (goto-char (point-min))
3951 (while (re-search-forward regexp nil t
)
3953 ;; This code from Emacs 22 doesn't seem right, since r-n-h is
3954 ;; just for display.
3955 ;;; (if (looking-at rmail-nonignored-headers)
3956 ;;; (forward-line 1)
3957 (delete-region (point)
3959 (if (re-search-forward "\n[^ \t]" nil t
)
3963 (autoload 'mail-position-on-field
"sendmail")
3965 (defun rmail-retry-failure ()
3966 "Edit a mail message which is based on the contents of the current message.
3967 For a message rejected by the mail system, extract the interesting headers and
3968 the body of the original message.
3969 If the failed message is a MIME multipart message, it is searched for a
3970 body part with a header which matches the variable `mail-mime-unsent-header'.
3971 Otherwise, the variable `mail-unsent-separator' should match the string that
3972 delimits the returned original message.
3973 The variable `rmail-retry-ignored-headers' is a regular expression
3974 specifying headers which should not be copied into the new message."
3976 (require 'mail-utils
)
3977 (let ((rmail-this-buffer (current-buffer))
3978 (msgnum rmail-current-message
)
3979 bounce-start bounce-end bounce-indent resending
3980 (content-type (rmail-get-header "Content-Type")))
3982 (goto-char (point-min))
3983 (let ((case-fold-search t
))
3984 (if (and content-type
3986 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3988 ;; Handle a MIME multipart bounce message.
3991 (substring content-type
(match-beginning 1)
3993 (unless (re-search-forward mail-mime-unsent-header nil t
)
3994 (error "Cannot find beginning of header in failed message"))
3995 (unless (search-forward "\n\n" nil t
)
3996 (error "Cannot find start of Mime data in failed message"))
3997 (setq bounce-start
(point))
3998 (if (search-forward codestring nil t
)
3999 (setq bounce-end
(match-beginning 0))
4000 (setq bounce-end
(point-max))))
4002 (or (re-search-forward mail-unsent-separator nil t
)
4003 (error "Cannot parse this as a failure message"))
4004 (skip-chars-forward "\n")
4005 ;; Support a style of failure message in which the original
4006 ;; message is indented, and included within lines saying
4007 ;; `Start of returned message' and `End of returned message'.
4008 (if (looking-at " +Received:")
4010 (setq bounce-start
(point))
4011 (skip-chars-forward " ")
4012 (setq bounce-indent
(- (current-column)))
4013 (goto-char (point-max))
4014 (re-search-backward "^End of returned message$" nil t
)
4015 (setq bounce-end
(point)))
4016 ;; One message contained a few random lines before
4017 ;; the old message header. The first line of the
4018 ;; message started with two hyphens. A blank line
4019 ;; followed these random lines. The same line
4020 ;; beginning with two hyphens was possibly marking
4021 ;; the end of the message.
4022 (if (looking-at "^--")
4023 (let ((boundary (buffer-substring-no-properties
4025 (progn (end-of-line) (point)))))
4026 (search-forward "\n\n")
4027 (skip-chars-forward "\n")
4028 (setq bounce-start
(point))
4029 (goto-char (point-max))
4030 (search-backward (concat "\n\n" boundary
) bounce-start t
)
4031 (setq bounce-end
(point)))
4032 (setq bounce-start
(point)
4033 bounce-end
(point-max)))
4034 (unless (search-forward "\n\n" nil t
)
4035 (error "Cannot find end of header in failed message"))))))
4036 ;; We have found the message that bounced, within the current message.
4037 ;; Now start sending new message; default header fields from original.
4038 ;; Turn off the usual actions for initializing the message body
4039 ;; because we want to get only the text from the failure message.
4040 (let (mail-signature mail-setup-hook
)
4041 (if (rmail-start-mail nil nil nil nil nil rmail-this-buffer
4042 (list (list 'rmail-mark-message
4044 (aref rmail-msgref-vector msgnum
)
4045 rmail-retried-attr-index
)))
4046 ;; Insert original text as initial text of new draft message.
4047 ;; Bind inhibit-read-only since the header delimiter
4048 ;; of the previous message was probably read-only.
4049 (let ((inhibit-read-only t
)
4052 (insert-buffer-substring rmail-this-buffer
4053 bounce-start bounce-end
)
4054 (goto-char (point-min))
4056 (indent-rigidly (point-min) (point-max) bounce-indent
))
4059 (insert mail-header-separator
)
4061 (narrow-to-region (point-min) eoh
)
4062 (rmail-delete-headers rmail-retry-ignored-headers
)
4063 (rmail-delete-headers "^\\(sender\\|return-path\\|received\\):")
4064 (setq resending
(mail-fetch-field "resent-to"))
4067 (insert "Resent-Bcc: " (user-login-name) "\n")
4068 (insert "BCC: " (user-login-name) "\n"))))
4069 (goto-char (point-min))
4070 (mail-position-on-field (if resending
"Resent-To" "To") t
))))))
4072 (defun rmail-summary-exists ()
4073 "Non-nil if in an RMAIL buffer and an associated summary buffer exists.
4074 In fact, the non-nil value returned is the summary buffer itself."
4075 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4076 rmail-summary-buffer
))
4078 (defun rmail-summary-displayed ()
4079 "t if in RMAIL buffer and an associated summary buffer is displayed."
4080 (and rmail-summary-buffer
(get-buffer-window rmail-summary-buffer
)))
4082 (defcustom rmail-redisplay-summary nil
4083 "Non-nil means Rmail should show the summary when it changes.
4084 This has an effect only if a summary buffer exists."
4086 :group
'rmail-summary
)
4088 (defcustom rmail-summary-window-size nil
4089 "Non-nil means specify the height for an Rmail summary window."
4090 :type
'(choice (const :tag
"Disabled" nil
) integer
)
4091 :group
'rmail-summary
)
4093 ;; Put the summary buffer back on the screen, if user wants that.
4094 (defun rmail-maybe-display-summary ()
4095 (let ((selected (selected-window))
4097 ;; If requested, make sure the summary is displayed.
4098 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4099 rmail-redisplay-summary
4100 (if (get-buffer-window rmail-summary-buffer
0)
4101 ;; It's already in some frame; show that one.
4102 (let ((frame (window-frame
4103 (get-buffer-window rmail-summary-buffer
0))))
4104 (make-frame-visible frame
)
4105 (raise-frame frame
))
4106 (display-buffer rmail-summary-buffer
)))
4107 ;; If requested, set the height of the summary window.
4108 (and rmail-summary-buffer
(buffer-name rmail-summary-buffer
)
4109 rmail-summary-window-size
4110 (setq window
(get-buffer-window rmail-summary-buffer
))
4111 ;; Don't try to change the size if just one window in frame.
4112 (not (eq window
(frame-root-window (window-frame window
))))
4115 (select-window window
)
4116 (enlarge-window (- rmail-summary-window-size
(window-height))))
4117 (select-window selected
)))))
4119 ;;;; *** Rmail Local Fontification ***
4121 (defun rmail-fontify-buffer-function ()
4122 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
4123 (add-hook 'rmail-show-message-hook
'rmail-fontify-message nil t
)
4124 ;; If we're already showing a message, fontify it now.
4125 (if rmail-current-message
(rmail-fontify-message))
4126 ;; Prevent Font Lock mode from kicking in.
4127 (setq font-lock-fontified t
))
4129 (defun rmail-unfontify-buffer-function ()
4130 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
4131 (let ((modified (buffer-modified-p))
4132 (buffer-undo-list t
) (inhibit-read-only t
)
4133 before-change-functions after-change-functions
4134 buffer-file-name buffer-file-truename
)
4137 (remove-hook 'rmail-show-message-hook
'rmail-fontify-message t
)
4138 (remove-text-properties (point-min) (point-max) '(rmail-fontified nil
))
4139 (font-lock-default-unfontify-buffer)
4140 (and (not modified
) (buffer-modified-p)
4141 (restore-buffer-modified-p nil
)))))
4143 (defun rmail-fontify-message ()
4144 ;; Fontify the current message if it is not already fontified.
4145 (if (text-property-any (point-min) (point-max) 'rmail-fontified nil
)
4146 (let ((modified (buffer-modified-p))
4147 (buffer-undo-list t
) (inhibit-read-only t
)
4148 before-change-functions after-change-functions
4149 buffer-file-name buffer-file-truename
)
4152 (add-text-properties (point-min) (point-max) '(rmail-fontified t
))
4153 (font-lock-fontify-region (point-min) (point-max))
4154 (and (not modified
) (buffer-modified-p)
4155 (restore-buffer-modified-p nil
)))))))
4157 ;;; Speedbar support for RMAIL files.
4158 (eval-when-compile (require 'speedbar
))
4160 (defvar rmail-speedbar-match-folder-regexp
"^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
4161 "*This regex is used to match folder names to be displayed in speedbar.
4162 Enabling this will permit speedbar to display your folders for easy
4163 browsing, and moving of messages.")
4165 (defvar rmail-speedbar-last-user nil
4166 "The last user to be displayed in the speedbar.")
4168 (defvar rmail-speedbar-key-map nil
4169 "Keymap used when in rmail display mode.")
4171 (defun rmail-install-speedbar-variables ()
4172 "Install those variables used by speedbar to enhance rmail."
4173 (if rmail-speedbar-key-map
4175 (setq rmail-speedbar-key-map
(speedbar-make-specialized-keymap))
4177 (define-key rmail-speedbar-key-map
"e" 'speedbar-edit-line
)
4178 (define-key rmail-speedbar-key-map
"r" 'speedbar-edit-line
)
4179 (define-key rmail-speedbar-key-map
"\C-m" 'speedbar-edit-line
)
4180 (define-key rmail-speedbar-key-map
"M"
4181 'rmail-speedbar-move-message-to-folder-on-line
)))
4184 (defvar rmail-speedbar-menu-items
4185 '(["Read Folder" speedbar-edit-line t
]
4186 ["Move message to folder" rmail-speedbar-move-message-to-folder-on-line
4187 (save-excursion (beginning-of-line)
4188 (looking-at "<M> "))])
4189 "Additional menu-items to add to speedbar frame.")
4191 ;; Make sure our special speedbar major mode is loaded
4192 (if (featurep 'speedbar
)
4193 (rmail-install-speedbar-variables)
4194 (add-hook 'speedbar-load-hook
'rmail-install-speedbar-variables
))
4196 (defun rmail-speedbar-buttons (buffer)
4197 "Create buttons for BUFFER containing rmail messages.
4198 Click on the address under Reply to: to reply to this person.
4199 Under Folders: Click a name to read it, or on the <M> to move the
4200 current message into that RMAIL folder."
4202 (with-current-buffer buffer
4203 (goto-char (point-min))
4204 (if (not (re-search-forward "^Reply-To: " nil t
))
4205 (if (not (re-search-forward "^From:? " nil t
))
4209 (setq from
(buffer-substring (point) (line-end-position)))))
4210 (goto-char (point-min))
4211 (if (and (looking-at "Reply to:")
4212 (equal from rmail-speedbar-last-user
))
4214 (setq rmail-speedbar-last-user from
)
4216 (insert "Reply To:\n")
4218 (speedbar-insert-button from
'speedbar-directory-face
'highlight
4219 'rmail-speedbar-button
'rmail-reply
))
4220 (insert "Folders:\n")
4221 (let* ((case-fold-search nil
)
4222 (df (directory-files (with-current-buffer buffer
4224 nil rmail-speedbar-match-folder-regexp
)))
4226 (when (file-regular-p file
)
4227 (speedbar-insert-button "<M>" 'speedbar-button-face
'highlight
4228 'rmail-speedbar-move-message file
)
4229 (speedbar-insert-button file
'speedbar-file-face
'highlight
4230 'rmail-speedbar-find-file nil t
)))))))
4232 (defun rmail-speedbar-button (text token indent
)
4233 "Execute an rmail command specified by TEXT.
4234 The command used is TOKEN. INDENT is not used."
4235 (speedbar-with-attached-buffer
4238 (defun rmail-speedbar-find-file (text token indent
)
4239 "Load in the rmail file TEXT.
4240 TOKEN and INDENT are not used."
4241 (speedbar-with-attached-buffer
4242 (message "Loading in RMAIL file %s..." text
)
4245 (defun rmail-speedbar-move-message-to-folder-on-line ()
4246 "If the current line is a folder, move current message to it."
4250 (if (re-search-forward "<M> " (line-end-position) t
)
4253 (speedbar-do-function-pointer)))))
4255 (defun rmail-speedbar-move-message (text token indent
)
4256 "From button TEXT, copy current message to the rmail file specified by TOKEN.
4257 TEXT and INDENT are not used."
4258 (speedbar-with-attached-buffer
4259 (message "Moving message to %s" token
)
4260 ;; expand-file-name is needed due to the unhelpful way in which
4261 ;; rmail-output expands non-absolute filenames against rmail-default-file.
4262 ;; What is the point of that, anyway?
4263 (rmail-output (expand-file-name token
))))
4265 ;; Functions for setting, getting and encoding the POP password.
4266 ;; The password is encoded to prevent it from being easily accessible
4267 ;; to "prying eyes." Obviously, this encoding isn't "real security,"
4268 ;; nor is it meant to be.
4271 (defun rmail-set-remote-password (password)
4272 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
4273 (interactive "sPassword: ")
4275 (setq rmail-encoded-remote-password
4276 (rmail-encode-string password
(emacs-pid)))
4277 (setq rmail-remote-password nil
)
4278 (setq rmail-encoded-remote-password nil
)))
4280 (defun rmail-get-remote-password (imap)
4281 "Get the password for retrieving mail from a POP or IMAP server. If none
4282 has been set, then prompt the user for one."
4283 (when (not rmail-encoded-remote-password
)
4284 (if (not rmail-remote-password
)
4285 (setq rmail-remote-password
4286 (read-passwd (if imap
4288 "POP password: "))))
4289 (rmail-set-remote-password rmail-remote-password
)
4290 (setq rmail-remote-password nil
))
4291 (rmail-encode-string rmail-encoded-remote-password
(emacs-pid)))
4293 (defun rmail-have-password ()
4294 (or rmail-remote-password rmail-encoded-remote-password
))
4296 (defun rmail-encode-string (string mask
)
4297 "Encode STRING with integer MASK, by taking the exclusive OR of the
4298 lowest byte in the mask with the first character of string, the
4299 second-lowest-byte with the second character of the string, etc.,
4300 restarting at the lowest byte of the mask whenever it runs out.
4301 Returns the encoded string. Calling the function again with an
4302 encoded string (and the same mask) will decode the string."
4303 (setq mask
(abs mask
)) ; doesn't work if negative
4304 (let* ((string-vector (string-to-vector string
)) (i 0)
4305 (len (length string-vector
)) (curmask mask
) charmask
)
4308 (setq curmask mask
))
4309 (setq charmask
(% curmask
256))
4310 (setq curmask
(lsh curmask -
8))
4311 (aset string-vector i
(logxor charmask
(aref string-vector i
)))
4313 (concat string-vector
)))
4315 (defun rmail-epa-decrypt ()
4316 "Decrypt OpenPGP armors in current message."
4319 ;; Save the current buffer here for cleanliness, in case we
4320 ;; change it in one of the calls to `epa-decrypt-region'.
4324 (goto-char (point-min))
4326 ;; In case the encrypted data is inside a mime attachment,
4327 ;; show it. This is a kludge; to be clean, it should not
4328 ;; modify the buffer, but I don't see how to do that.
4329 (when (search-forward "octet-stream" nil t
)
4332 (if (looking-at "Show")
4333 (rmail-mime-toggle-hidden)))
4335 ;; Now find all armored messages in the buffer
4336 ;; and decrypt them one by one.
4337 (goto-char (point-min))
4338 (while (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t
)
4339 (let ((coding-system-for-read coding-system-for-read
)
4340 armor-start armor-end after-end
)
4341 (setq armor-start
(match-beginning 0)
4342 armor-end
(re-search-forward "^-----END PGP MESSAGE-----$"
4345 (error "Encryption armor beginning has no matching end"))
4346 (goto-char armor-start
)
4348 ;; Because epa--find-coding-system-for-mime-charset not autoloaded.
4351 ;; Use the charset specified in the armor.
4352 (unless coding-system-for-read
4353 (if (re-search-forward "^Charset: \\(.*\\)" armor-end t
)
4354 (setq coding-system-for-read
4355 (epa--find-coding-system-for-mime-charset
4356 (intern (downcase (match-string 1)))))))
4358 ;; Advance over this armor.
4359 (goto-char armor-end
)
4360 (setq after-end
(- (point-max) armor-end
))
4362 ;; Decrypt it, maybe in place, maybe making new buffer.
4364 armor-start armor-end
4365 ;; Call back this function to prepare the output.
4367 (let ((inhibit-read-only t
))
4368 (delete-region armor-start armor-end
)
4369 (goto-char armor-start
)
4372 (push (list armor-start
(- (point-max) after-end
))
4375 (when (and decrypts
(rmail-buffers-swapped-p))
4376 (when (y-or-n-p "Replace the original message? ")
4377 (setq decrypts
(nreverse decrypts
))
4378 (let ((beg (rmail-msgbeg rmail-current-message
))
4379 (end (rmail-msgend rmail-current-message
))
4380 (from-buffer (current-buffer)))
4381 (with-current-buffer rmail-view-buffer
4382 (narrow-to-region beg end
)
4383 (goto-char (point-min))
4384 (dolist (d decrypts
)
4385 (if (re-search-forward "-----BEGIN PGP MESSAGE-----$" nil t
)
4386 (let (armor-start armor-end
)
4387 (setq armor-start
(match-beginning 0)
4388 armor-end
(re-search-forward "^-----END PGP MESSAGE-----$"
4391 (delete-region armor-start armor-end
)
4392 (insert-buffer-substring from-buffer
(nth 0 d
) (nth 1 d
)))))))))))))
4394 ;;;; Desktop support
4396 (defun rmail-restore-desktop-buffer (desktop-buffer-file-name
4398 desktop-buffer-misc
)
4399 "Restore an rmail buffer specified in a desktop file."
4400 (condition-case error
4402 (rmail-input desktop-buffer-file-name
)
4403 (if (eq major-mode
'rmail-mode
)
4407 (kill-buffer (current-buffer))
4410 (add-to-list 'desktop-buffer-mode-handlers
4411 '(rmail-mode . rmail-restore-desktop-buffer
))
4413 ;; We use this to record the encoding of the current message before
4414 ;; saving the message collection.
4415 (defvar rmail-message-encoding nil
)
4417 ;; Used in `write-region-annotate-functions' to write rmail files.
4418 (defun rmail-write-region-annotate (start end
)
4419 (when (and (null start
) (rmail-buffers-swapped-p))
4420 (setq rmail-message-encoding buffer-file-coding-system
)
4421 (set-buffer rmail-view-buffer
)
4425 ;; Used to restore the encoding of the buffer where we show the
4426 ;; current message, after we save the message collection. This is
4427 ;; needed because rmail-write-region-annotate switches buffers behind
4428 ;; save-file's back, with the side effect that last-coding-system-used
4429 ;; is assigned to buffer-file-coding-system of the wrong buffer.
4430 (defun rmail-after-save-hook ()
4431 (if (or (eq rmail-view-buffer
(current-buffer))
4432 (eq rmail-buffer
(current-buffer)))
4433 (with-current-buffer
4434 (if (rmail-buffers-swapped-p) rmail-buffer rmail-view-buffer
)
4435 (setq buffer-file-coding-system rmail-message-encoding
))))
4436 (add-hook 'after-save-hook
'rmail-after-save-hook
)
4439 ;;; Start of automatically extracted autoloads.
4441 ;;;### (autoloads (rmail-edit-current-message) "rmailedit" "rmailedit.el"
4442 ;;;;;; "090ad9432c3bf9a6098bb9c3d7c71baf")
4443 ;;; Generated autoloads from rmailedit.el
4445 (autoload 'rmail-edit-current-message
"rmailedit" "\
4446 Edit the contents of this message.
4452 ;;;### (autoloads (rmail-next-labeled-message rmail-previous-labeled-message
4453 ;;;;;; rmail-read-label rmail-kill-label rmail-add-label) "rmailkwd"
4454 ;;;;;; "rmailkwd.el" "08c288c88cfe7be50830122c064e3884")
4455 ;;; Generated autoloads from rmailkwd.el
4457 (autoload 'rmail-add-label
"rmailkwd" "\
4458 Add LABEL to labels associated with current RMAIL message.
4459 Completes (see `rmail-read-label') over known labels when reading.
4460 LABEL may be a symbol or string. Only one label is allowed.
4464 (autoload 'rmail-kill-label
"rmailkwd" "\
4465 Remove LABEL from labels associated with current RMAIL message.
4466 Completes (see `rmail-read-label') over known labels when reading.
4467 LABEL may be a symbol or string. Only one label is allowed.
4471 (autoload 'rmail-read-label
"rmailkwd" "\
4472 Read a label with completion, prompting with PROMPT.
4473 Completions are chosen from `rmail-label-obarray'. The default
4474 is `rmail-last-label', if that is non-nil. Updates `rmail-last-label'
4475 according to the choice made, and returns a symbol.
4477 \(fn PROMPT)" nil nil
)
4479 (autoload 'rmail-previous-labeled-message
"rmailkwd" "\
4480 Show previous message with one of the labels LABELS.
4481 LABELS should be a comma-separated list of label names.
4482 If LABELS is empty, the last set of labels specified is used.
4483 With prefix argument N moves backward N messages with these labels.
4485 \(fn N LABELS)" t nil
)
4487 (autoload 'rmail-next-labeled-message
"rmailkwd" "\
4488 Show next message with one of the labels LABELS.
4489 LABELS should be a comma-separated list of label names.
4490 If LABELS is empty, the last set of labels specified is used.
4491 With prefix argument N moves forward N messages with these labels.
4493 \(fn N LABELS)" t nil
)
4497 ;;;### (autoloads (rmail-mime) "rmailmm" "rmailmm.el" "5d992206e382290d07ad7d9a2bf250c9")
4498 ;;; Generated autoloads from rmailmm.el
4500 (autoload 'rmail-mime
"rmailmm" "\
4501 Toggle displaying of a MIME message.
4503 The actualy behavior depends on the value of `rmail-enable-mime'.
4505 If `rmail-enable-mime' is t (default), this command change the
4506 displaying of a MIME message between decoded presentation form
4509 With ARG, toggle the displaying of the current MIME entity only.
4511 If `rmail-enable-mime' is nil, this creates a temporary
4512 \"*RMAIL*\" buffer holding a decoded copy of the message. Inline
4513 content-types are handled according to
4514 `rmail-mime-media-type-handlers-alist'. By default, this
4515 displays text and multipart messages, and offers to download
4516 attachments as specfied by `rmail-mime-attachment-dirs-alist'.
4518 \(fn &optional ARG)" t nil
)
4522 ;;;### (autoloads (set-rmail-inbox-list) "rmailmsc" "rmailmsc.el"
4523 ;;;;;; "ca19b2f8a3e8aa01aa75ca7413f8a5ef")
4524 ;;; Generated autoloads from rmailmsc.el
4526 (autoload 'set-rmail-inbox-list
"rmailmsc" "\
4527 Set the inbox list of the current RMAIL file to FILE-NAME.
4528 You can specify one file name, or several names separated by commas.
4529 If FILE-NAME is empty, remove any existing inbox list.
4531 This applies only to the current session.
4533 \(fn FILE-NAME)" t nil
)
4537 ;;;### (autoloads (rmail-sort-by-labels rmail-sort-by-lines rmail-sort-by-correspondent
4538 ;;;;;; rmail-sort-by-recipient rmail-sort-by-author rmail-sort-by-subject
4539 ;;;;;; rmail-sort-by-date) "rmailsort" "rmailsort.el" "ad1c98fe868c0e5804cf945d6c980d0b")
4540 ;;; Generated autoloads from rmailsort.el
4542 (autoload 'rmail-sort-by-date
"rmailsort" "\
4543 Sort messages of current Rmail buffer by \"Date\" header.
4544 If prefix argument REVERSE is non-nil, sorts in reverse order.
4546 \(fn REVERSE)" t nil
)
4548 (autoload 'rmail-sort-by-subject
"rmailsort" "\
4549 Sort messages of current Rmail buffer by \"Subject\" header.
4550 Ignores any \"Re: \" prefix. If prefix argument REVERSE is
4551 non-nil, sorts in reverse order.
4553 \(fn REVERSE)" t nil
)
4555 (autoload 'rmail-sort-by-author
"rmailsort" "\
4556 Sort messages of current Rmail buffer by author.
4557 This uses either the \"From\" or \"Sender\" header, downcased.
4558 If prefix argument REVERSE is non-nil, sorts in reverse order.
4560 \(fn REVERSE)" t nil
)
4562 (autoload 'rmail-sort-by-recipient
"rmailsort" "\
4563 Sort messages of current Rmail buffer by recipient.
4564 This uses either the \"To\" or \"Apparently-To\" header, downcased.
4565 If prefix argument REVERSE is non-nil, sorts in reverse order.
4567 \(fn REVERSE)" t nil
)
4569 (autoload 'rmail-sort-by-correspondent
"rmailsort" "\
4570 Sort messages of current Rmail buffer by other correspondent.
4571 This uses either the \"From\", \"Sender\", \"To\", or
4572 \"Apparently-To\" header, downcased. Uses the first header not
4573 excluded by `mail-dont-reply-to-names'. If prefix argument
4574 REVERSE is non-nil, sorts in reverse order.
4576 \(fn REVERSE)" t nil
)
4578 (autoload 'rmail-sort-by-lines
"rmailsort" "\
4579 Sort messages of current Rmail buffer by the number of lines.
4580 If prefix argument REVERSE is non-nil, sorts in reverse order.
4582 \(fn REVERSE)" t nil
)
4584 (autoload 'rmail-sort-by-labels
"rmailsort" "\
4585 Sort messages of current Rmail buffer by labels.
4586 LABELS is a comma-separated list of labels. The order of these
4587 labels specifies the order of messages: messages with the first
4588 label come first, messages with the second label come second, and
4589 so on. Messages that have none of these labels come last.
4590 If prefix argument REVERSE is non-nil, sorts in reverse order.
4592 \(fn REVERSE LABELS)" t nil
)
4596 ;;;### (autoloads (rmail-summary-by-senders rmail-summary-by-topic
4597 ;;;;;; rmail-summary-by-regexp rmail-summary-by-recipients rmail-summary-by-labels
4598 ;;;;;; rmail-summary) "rmailsum" "rmailsum.el" "35e07b0a5ea8e41971f31a8780eba6bb")
4599 ;;; Generated autoloads from rmailsum.el
4601 (autoload 'rmail-summary
"rmailsum" "\
4602 Display a summary of all messages, one line per message.
4606 (autoload 'rmail-summary-by-labels
"rmailsum" "\
4607 Display a summary of all messages with one or more LABELS.
4608 LABELS should be a string containing the desired labels, separated by commas.
4610 \(fn LABELS)" t nil
)
4612 (autoload 'rmail-summary-by-recipients
"rmailsum" "\
4613 Display a summary of all messages with the given RECIPIENTS.
4614 Normally checks the To, From and Cc fields of headers;
4615 but if PRIMARY-ONLY is non-nil (prefix arg given),
4616 only look in the To and From fields.
4617 RECIPIENTS is a string of regexps separated by commas.
4619 \(fn RECIPIENTS &optional PRIMARY-ONLY)" t nil
)
4621 (autoload 'rmail-summary-by-regexp
"rmailsum" "\
4622 Display a summary of all messages according to regexp REGEXP.
4623 If the regular expression is found in the header of the message
4624 \(including in the date and other lines, as well as the subject line),
4625 Emacs will list the message in the summary.
4627 \(fn REGEXP)" t nil
)
4629 (autoload 'rmail-summary-by-topic
"rmailsum" "\
4630 Display a summary of all messages with the given SUBJECT.
4631 Normally checks just the Subject field of headers; but with prefix
4632 argument WHOLE-MESSAGE is non-nil, looks in the whole message.
4633 SUBJECT is a string of regexps separated by commas.
4635 \(fn SUBJECT &optional WHOLE-MESSAGE)" t nil
)
4637 (autoload 'rmail-summary-by-senders
"rmailsum" "\
4638 Display a summary of all messages whose \"From\" field matches SENDERS.
4639 SENDERS is a string of regexps separated by commas.
4641 \(fn SENDERS)" t nil
)
4645 ;;;### (autoloads (unforward-rmail-message undigestify-rmail-message)
4646 ;;;;;; "undigest" "undigest.el" "41e6a48ea63224385c447a944528feb6")
4647 ;;; Generated autoloads from undigest.el
4649 (autoload 'undigestify-rmail-message
"undigest" "\
4650 Break up a digest message into its constituent messages.
4651 Leaves original message, deleted, before the undigestified messages.
4655 (autoload 'unforward-rmail-message
"undigest" "\
4656 Extract a forwarded message from the containing message.
4657 This puts the forwarded message into a separate rmail message
4658 following the containing message.
4664 ;;; End of automatically extracted autoloads.
4669 ;;; rmail.el ends here