1 ;;; pmail.el --- main code of "PMAIL" mail reader for Emacs
3 ;; Copyright (C) 1985, 1986, 1987, 1988, 1993, 1994, 1995, 1996, 1997, 1998,
4 ;; 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009
5 ;; Free Software Foundation, Inc.
10 ;; This file is part of GNU Emacs.
12 ;; GNU Emacs is free software: you can redistribute it and/or modify
13 ;; it under the terms of the GNU General Public License as published by
14 ;; the Free Software Foundation, either version 3 of the License, or
15 ;; (at your option) any later version.
17 ;; GNU Emacs is distributed in the hope that it will be useful,
18 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
19 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 ;; GNU General Public License for more details.
22 ;; You should have received a copy of the GNU General Public License
23 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
29 ;; Souped up by shane@mit-ajax based on ideas of rlk@athena.mit.edu
30 ;; New features include attribute and keyword support, message
31 ;; selection by dispatch table, summary by attributes and keywords,
32 ;; expunging by dispatch table, sticky options for file commands.
34 ;; Extended by Bob Weiner of Motorola
35 ;; New features include: pmail and pmail-summary buffers remain
36 ;; synchronized and key bindings basically operate the same way in both
37 ;; buffers, summary by topic or by regular expression, pmail-reply-prefix
38 ;; variable, and a bury pmail buffer (wipe) command.
42 (eval-when-compile (require 'mule-util)) ; for detect-coding-with-priority
45 ;; The buffer-swapped-with feature has been moved here temporarily.
46 ;; When pmail is merged, this advice must be eliminated and the
47 ;; functionality somehow reimplemented.
49 (defvar buffer-swapped-with nil
50 "Buffer that this buffer's contents are temporarily swapped with.
51 You should only set this variable in file-visiting buffers,
52 because it only affects how to save the buffer in its file.")
54 (make-variable-buffer-local 'buffer-swapped-with)
56 (defadvice basic-save-buffer
57 (around check-swap activate)
58 "If this buffer's real contents are swapped with some other buffer,
59 temporarily unswap in order to save the real contents. This
60 advice is temporarily used by pmail until a satisfactory solution
62 (if (not buffer-swapped-with)
64 ;;; (if (and (string= "PMAIL" (buffer-name))
65 ;;; (< (buffer-size) 1000000))
69 (let ((modp (buffer-modified-p)))
71 ;;; (let ((case-fold-search nil))
72 ;;; (unless (or (string-match "PMAIL" (buffer-name))
73 ;;; (string-match "xmail" (buffer-name))
74 ;;; (string-match "mbox" (buffer-name)))
76 (buffer-swap-text buffer-swapped-with)
77 (set-buffer-modified-p modp)
79 (buffer-swap-text buffer-swapped-with)
80 (set-buffer-modified-p nil))))
82 (defconst pmail-attribute-header "X-RMAIL-ATTRIBUTES"
83 "The header that stores the Pmail attribute data.")
85 (defconst pmail-keyword-header "X-RMAIL-KEYWORDS"
86 "The header that stores the Pmail keyword data.")
90 (defconst pmail-answered-attr-index 0
91 "The index for the `answered' attribute.")
93 (defconst pmail-deleted-attr-index 1
94 "The index for the `deleted' attribute.")
96 (defconst pmail-edited-attr-index 2
97 "The index for the `edited' attribute.")
99 (defconst pmail-filed-attr-index 3
100 "The index for the `filed' attribute.")
102 (defconst pmail-retried-attr-index 4
103 "The index for the `retried' attribute.")
105 (defconst pmail-forwarded-attr-index 5
106 "The index for the `forwarded' attribute.")
108 (defconst pmail-unseen-attr-index 6
109 "The index for the `unseen' attribute.")
111 (defconst pmail-resent-attr-index 6
112 "The index for the `resent' attribute.")
114 (defconst pmail-attr-array
123 "An array that provides a mapping between an attribute index,
124 its character representation and its display representation.")
126 (defvar deleted-head)
127 (defvar font-lock-fontified)
128 (defvar mail-abbrev-syntax-table)
129 (defvar mail-abbrevs)
130 (defvar messages-head)
131 (defvar pmail-use-spam-filter)
133 (defvar rsf-sleep-after-message)
134 (defvar total-messages)
135 (defvar tool-bar-map)
137 (defvar pmail-header-style 'normal
138 "The current header display style choice, one of
139 'normal (selected headers) or 'full (all headers).")
141 ; These variables now declared in paths.el.
142 ;(defvar pmail-spool-directory "/usr/spool/mail/"
143 ; "This is the name of the directory used by the system mailer for\n\
144 ;delivering new mail. Its name should end with a slash.")
145 ;(defvar pmail-file-name
146 ; (expand-file-name "~/PMAIL")
149 ;; Temporary support for mbox.
150 (defcustom pmail-file-name "~/PMAIL"
151 "*Name of user's primary mail file."
157 "Mail reader for Emacs."
160 (defgroup pmail-retrieve nil
161 "Pmail retrieval options."
165 (defgroup pmail-files nil
170 (defgroup pmail-headers nil
171 "Pmail header options."
175 (defgroup pmail-reply nil
176 "Pmail reply options."
180 (defgroup pmail-summary nil
181 "Pmail summary options."
183 :prefix "pmail-summary-"
186 (defgroup pmail-output nil
187 "Output message to a file."
188 :prefix "pmail-output-"
192 (defgroup pmail-edit nil
194 :prefix "pmail-edit-"
197 (defgroup pmail-obsolete nil
198 "Pmail obsolete customization variables."
201 (defcustom pmail-movemail-program nil
202 "If non-nil, the file name of the `movemail' program."
203 :group 'pmail-retrieve
204 :type '(choice (const nil) string))
206 (defcustom pmail-pop-password nil
207 "*Password to use when reading mail from POP server.
208 Please use `pmail-remote-password' instead."
209 :type '(choice (string :tag "Password")
210 (const :tag "Not Required" nil))
211 :group 'pmail-obsolete)
213 (defcustom pmail-pop-password-required nil
214 "*Non-nil if a password is required when reading mail from a POP server.
215 Please use pmail-remote-password-required instead."
217 :group 'pmail-obsolete)
219 (defcustom pmail-remote-password nil
220 "*Password to use when reading mail from a remote server.
221 This setting is ignored for mailboxes whose URL already contains a password."
222 :type '(choice (string :tag "Password")
223 (const :tag "Not Required" nil))
224 :set-after '(pmail-pop-password)
225 :set #'(lambda (symbol value)
228 (boundp 'pmail-pop-password)
232 (setq pmail-pop-password nil))
233 :group 'pmail-retrieve
236 (defcustom pmail-remote-password-required nil
237 "*Non-nil if a password is required when reading mail from a remote server."
239 :set-after '(pmail-pop-password-required)
240 :set #'(lambda (symbol value)
243 (boundp 'pmail-pop-password-required)
244 pmail-pop-password-required)
245 pmail-pop-password-required
247 (setq pmail-pop-password-required nil))
248 :group 'pmail-retrieve
251 (defcustom pmail-movemail-flags nil
252 "*List of flags to pass to movemail.
253 Most commonly used to specify `-g' to enable GSS-API authentication
254 or `-k' to enable Kerberos authentication."
255 :type '(repeat string)
256 :group 'pmail-retrieve
259 (defvar pmail-remote-password-error "invalid usercode or password\\|
260 unknown user name or bad password\\|Authentication failed\\|MU_ERR_AUTH_FAILURE"
261 "Regular expression matching incorrect-password POP or IMAP server error
263 If you get an incorrect-password error that this expression does not match,
264 please report it with \\[report-emacs-bug].")
266 (defvar pmail-encoded-remote-password nil)
268 (defcustom pmail-preserve-inbox nil
269 "*Non-nil means leave incoming mail in the user's inbox--don't delete it."
271 :group 'pmail-retrieve)
273 (defcustom pmail-movemail-search-path nil
274 "*List of directories to search for movemail (in addition to `exec-path')."
275 :group 'pmail-retrieve
276 :type '(repeat (directory)))
278 (declare-function mail-position-on-field "sendmail" (field &optional soft))
279 (declare-function mail-text-start "sendmail" ())
280 (declare-function rmail-dont-reply-to "mail-utils" (destinations))
281 (declare-function pmail-update-summary "pmailsum" (&rest ignore))
283 (defun pmail-probe (prog)
284 "Determine what flavor of movemail PROG is.
285 We do this by executing it with `--version' and analyzing its output."
287 (let ((tbuf (current-buffer)))
288 (buffer-disable-undo tbuf)
289 (call-process prog nil tbuf nil "--version")
290 (if (not (buffer-modified-p tbuf))
291 ;; Should not happen...
293 (goto-char (point-min))
295 ((looking-at ".*movemail: invalid option")
296 'emacs) ;; Possibly...
297 ((looking-at "movemail (GNU Mailutils .*)")
303 (defun pmail-autodetect ()
304 "Determine the file name of the `movemail' program and return its flavor.
305 If `pmail-movemail-program' is non-nil, use it.
306 Otherwise, look for `movemail' in the directories in
307 `pmail-movemail-search-path', those in `exec-path', and `exec-directory'."
308 (if pmail-movemail-program
309 (pmail-probe pmail-movemail-program)
311 (dolist (dir (append pmail-movemail-search-path exec-path
312 (list exec-directory)))
313 (when (and dir (file-accessible-directory-p dir))
314 ;; Previously, this didn't have to work on Windows, because
315 ;; pmail-insert-inbox-text before r1.439 fell back to using
316 ;; (expand-file-name "movemail" exec-directory) and just
317 ;; assuming it would work.
318 ;; http://lists.gnu.org/archive/html/bug-gnu-emacs/2008-02/msg00087.html
319 (let ((progname (expand-file-name
321 (if (memq system-type '(ms-dos windows-nt))
323 (when (and (not (file-directory-p progname))
324 (file-executable-p progname))
325 (let ((x (pmail-probe progname)))
327 (setq pmail-movemail-program progname)
328 (throw 'scan x))))))))))
330 (defvar pmail-movemail-variant-in-use nil
331 "The movemail variant currently in use. Known variants are:
333 `emacs' Means any implementation, compatible with the native Emacs one.
335 `mailutils' Means GNU mailutils implementation, capable of handling full
336 mail URLs as the source mailbox.")
339 (defun pmail-movemail-variant-p (&rest variants)
340 "Return t if the current movemail variant is any of VARIANTS.
341 Currently known variants are 'emacs and 'mailutils."
342 (when (not pmail-movemail-variant-in-use)
344 (setq pmail-movemail-variant-in-use (pmail-autodetect)))
345 (not (null (member pmail-movemail-variant-in-use variants))))
347 ;; Call for effect, to set pmail-movemail-program (if not set by the
348 ;; user), and pmail-movemail-variant-in-use. Used by various functions.
349 ;; I'm not sure if M-x pmail is the only entry point to this package.
350 ;; If so, this can be moved there.
351 (pmail-movemail-variant-p)
354 (defcustom pmail-dont-reply-to-names nil "\
355 *A regexp specifying addresses to prune from a reply message.
356 A value of nil means exclude your own email address as an address
357 plus whatever is specified by `pmail-default-dont-reply-to-names'."
358 :type '(choice regexp (const :tag "Your Name" nil))
362 (defvar pmail-default-dont-reply-to-names "\\`info-" "\
363 A regular expression specifying part of the default value of the
364 variable `pmail-dont-reply-to-names', for when the user does not set
365 `pmail-dont-reply-to-names' explicitly. (The other part of the default
366 value is the user's email address and name.)
367 It is useful to set this variable in the site customization file.")
370 (defcustom pmail-ignored-headers
371 (concat "^via:\\|^mail-from:\\|^origin:\\|^references:\\|^sender:"
372 "\\|^status:\\|^received:\\|^x400-originator:\\|^x400-recipients:"
373 "\\|^x400-received:\\|^x400-mts-identifier:\\|^x400-content-type:"
374 "\\|^\\(resent-\\|\\)message-id:\\|^summary-line:\\|^resent-date:"
375 "\\|^nntp-posting-host:\\|^path:\\|^x-char.*:\\|^x-face:\\|^face:"
376 "\\|^x-mailer:\\|^delivered-to:\\|^lines:"
377 "\\|^content-transfer-encoding:\\|^x-coding-system:"
378 "\\|^return-path:\\|^errors-to:\\|^return-receipt-to:"
379 "\\|^precedence:\\|^mime-version:"
380 "\\|^list-owner:\\|^list-help:\\|^list-post:\\|^list-subscribe:"
381 "\\|^list-id:\\|^list-unsubscribe:\\|^list-archive:"
382 "\\|^content-length:\\|^nntp-posting-date:\\|^user-agent"
383 "\\|^importance:\\|^envelope-to:\\|^delivery-date\\|^openpgp:"
384 "\\|^mbox-line:\\|^cancel-lock:"
385 "\\|^DomainKey-Signature:\\|^dkim-signature:"
386 "\\|^resent-face:\\|^resent-x.*:\\|^resent-organization:\\|^resent-openpgp:"
388 "*Regexp to match header fields that Pmail should normally hide.
389 \(See also `pmail-nonignored-headers', which overrides this regexp.)
390 This variable is used for reformatting the message header,
391 which normally happens once for each message,
392 when you view the message for the first time in Pmail.
393 To make a change in this variable take effect
394 for a message that you have already viewed,
395 go to that message and type \\[pmail-toggle-header] twice."
397 :group 'pmail-headers)
399 (defcustom pmail-nonignored-headers "^x-spam-status:"
400 "*Regexp to match X header fields that Pmail should show.
401 This regexp overrides `pmail-ignored-headers'; if both this regexp
402 and that one match a certain header field, Pmail shows the field.
403 If this is nil, ignore all header fields in `pmail-ignored-headers'.
405 This variable is used for reformatting the message header,
406 which normally happens once for each message,
407 when you view the message for the first time in Pmail.
408 To make a change in this variable take effect
409 for a message that you have already viewed,
410 go to that message and type \\[pmail-toggle-header] twice."
411 :type '(choice (const nil) (regexp))
412 :group 'pmail-headers)
415 (defcustom pmail-displayed-headers nil
416 "*Regexp to match Header fields that Pmail should display.
417 If nil, display all header fields except those matched by
418 `pmail-ignored-headers'."
419 :type '(choice regexp (const :tag "All"))
420 :group 'pmail-headers)
423 (defcustom pmail-retry-ignored-headers "^x-authentication-warning:" "\
424 *Headers that should be stripped when retrying a failed message."
425 :type '(choice regexp (const nil :tag "None"))
426 :group 'pmail-headers)
429 (defcustom pmail-highlighted-headers "^From:\\|^Subject:" "\
430 *Regexp to match Header fields that Pmail should normally highlight.
431 A value of nil means don't highlight."
433 :group 'pmail-headers)
435 (defface pmail-highlight
436 '((t (:inherit highlight)))
437 "Face to use for highlighting the most important header fields."
438 :group 'pmail-headers
441 (defface pmail-header-name
442 '((t (:inherit font-lock-function-name-face)))
443 "Face to use for highlighting the header names."
444 :group 'pmail-headers
448 (defcustom pmail-delete-after-output nil "\
449 *Non-nil means automatically delete a message that is copied to a file."
454 (defcustom pmail-primary-inbox-list nil "\
455 *List of files which are inboxes for user's primary mail file `~/PMAIL'.
456 nil means the default, which is (\"/usr/spool/mail/$USER\")
457 \(the name varies depending on the operating system,
458 and the value of the environment variable MAIL overrides it)."
459 ;; Don't use backquote here, because we don't want to need it
461 :type (list 'choice '(const :tag "Default" nil)
462 (list 'repeat ':value (list (or (getenv "MAIL")
463 (concat "/var/spool/mail/"
466 :group 'pmail-retrieve
470 (defcustom pmail-mail-new-frame nil
471 "*Non-nil means Pmail makes a new frame for composing outgoing mail.
472 This is handy if you want to preserve the window configuration of
473 the frame where you have the PMAIL buffer displayed."
478 (defcustom pmail-secondary-file-directory "~/"
479 "*Directory for additional secondary Pmail files."
483 (defcustom pmail-secondary-file-regexp "\\.xmail$"
484 "*Regexp for which files are secondary Pmail files."
489 (defcustom pmail-confirm-expunge 'y-or-n-p
490 "*Whether and how to ask for confirmation before expunging deleted messages."
491 :type '(choice (const :tag "No confirmation" nil)
492 (const :tag "Confirm with y-or-n-p" y-or-n-p)
493 (const :tag "Confirm with yes-or-no-p" yes-or-no-p))
498 (defvar pmail-mode-hook nil
499 "List of functions to call when Pmail is invoked.")
502 (defvar pmail-get-new-mail-hook nil
503 "List of functions to call when Pmail has retrieved new mail.")
506 (defcustom pmail-show-message-hook nil
507 "List of functions to call when Pmail displays a message."
509 :options '(goto-address)
513 (defvar pmail-quit-hook nil
514 "List of functions to call when quitting out of Pmail.")
517 (defvar pmail-delete-message-hook nil
518 "List of functions to call when Pmail deletes a message.
519 When the hooks are called, the message has been marked deleted but is
520 still the current message in the Pmail buffer.")
522 ;; These may be altered by site-init.el to match the format of mmdf files
523 ;; delimiting used on a given host (delim1 and delim2 from the config
526 (defvar pmail-mmdf-delim1 "^\001\001\001\001\n"
527 "Regexp marking the start of an mmdf message.")
528 (defvar pmail-mmdf-delim2 "^\001\001\001\001\n"
529 "Regexp marking the end of an mmdf message.")
531 (defcustom pmail-message-filter nil
532 "If non-nil, a filter function for new messages in PMAIL.
533 Called with region narrowed to the message, including headers,
534 before obeying `pmail-ignored-headers'."
535 :group 'pmail-headers
536 :type '(choice (const nil) function))
538 (defcustom pmail-automatic-folder-directives nil
539 "List of directives specifying where to put a message.
540 Each element of the list is of the form:
542 (FOLDERNAME FIELD REGEXP [ FIELD REGEXP ] ... )
544 Where FOLDERNAME is the name of a BABYL format folder to put the
545 message. If any of the field regexp's are nil, then it is ignored.
547 If FOLDERNAME is \"/dev/null\", it is deleted.
548 If FOLDERNAME is nil then it is deleted, and skipped.
550 FIELD is the plain text name of a field in the message, such as
551 \"subject\" or \"from\". A FIELD of \"to\" will automatically include
552 all text from the \"cc\" field as well.
554 REGEXP is an expression to match in the preceeding specified FIELD.
555 FIELD/REGEXP pairs continue in the list.
558 (\"/dev/null\" \"from\" \"@spam.com\") ; delete all mail from spam.com
559 (\"RMS\" \"from\" \"rms@\") ; save all mail from RMS."
562 :type '(repeat (sexp :tag "Directive")))
564 (defvar pmail-reply-prefix "Re: "
565 "String to prepend to Subject line when replying to a message.")
567 ;; Some mailers use "Re(2):" or "Re^2:" or "Re: Re:" or "Re[2]:".
568 ;; This pattern should catch all the common variants.
569 ;; rms: I deleted the change to delete tags in square brackets
570 ;; because they mess up RT tags.
571 (defvar pmail-reply-regexp "\\`\\(Re\\(([0-9]+)\\|\\[[0-9]+\\]\\|\\^[0-9]+\\)?: *\\)*"
572 "Regexp to delete from Subject line before inserting `pmail-reply-prefix'.")
574 (defcustom pmail-display-summary nil
575 "*If non-nil, Pmail always displays the summary buffer."
576 :group 'pmail-summary
579 (defvar pmail-inbox-list nil)
580 (put 'pmail-inbox-list 'permanent-local t)
582 (defvar pmail-buffer nil
583 "The PMAIL buffer related to the current buffer.
584 In an PMAIL buffer, this holds the PMAIL buffer itself.
585 In a summary buffer, this holds the PMAIL buffer it is a summary for.")
586 (put 'pmail-buffer 'permanent-local t)
588 ;; Message counters and markers. Deleted flags.
590 (defvar pmail-current-message nil)
591 (put 'pmail-current-message 'permanent-local t)
593 (defvar pmail-total-messages nil)
594 (put 'pmail-total-messages 'permanent-local t)
596 (defvar pmail-message-vector nil)
597 (put 'pmail-message-vector 'permanent-local t)
599 (defvar pmail-deleted-vector nil)
600 (put 'pmail-deleted-vector 'permanent-local t)
602 (defvar pmail-msgref-vector nil
603 "In an Pmail buffer, a vector whose Nth element is a list (N).
604 When expunging renumbers messages, these lists are modified
605 by substituting the new message number into the existing list.")
606 (put 'pmail-msgref-vector 'permanent-local t)
608 (defvar pmail-overlay-list nil)
609 (put 'pmail-overlay-list 'permanent-local t)
611 ;; These are used by autoloaded pmail-summary.
613 (defvar pmail-summary-buffer nil)
614 (put 'pmail-summary-buffer 'permanent-local t)
615 (defvar pmail-summary-vector nil)
616 (put 'pmail-summary-vector 'permanent-local t)
618 (defvar pmail-view-buffer nil
619 "Buffer which holds PMAIL message for MIME displaying.")
620 (put 'pmail-view-buffer 'permanent-local t)
622 ;; `Sticky' default variables.
624 (defvar pmail-last-regexp nil)
625 (put 'pmail-last-regexp 'permanent-local t)
627 (defcustom pmail-default-file "~/xmail"
628 "*Default file name for \\[pmail-output]."
631 (defcustom pmail-default-body-file "~/mailout"
632 "*Default file name for \\[pmail-output-body-to-file]."
637 ;; Mule and MIME related variables.
640 (defvar pmail-file-coding-system nil
641 "Coding system used in PMAIL file.
643 This is set to nil by default.")
646 (defcustom pmail-enable-mime nil
647 "*If non-nil, PMAIL uses MIME feature.
648 If the value is t, PMAIL automatically shows MIME decoded message.
649 If the value is neither t nor nil, PMAIL does not show MIME decoded message
650 until a user explicitly requires it.
652 Even if the value is non-nil, you can't use MIME feature
653 if the feature specified by `pmail-mime-feature' is not available
655 :type '(choice (const :tag "on" t)
656 (const :tag "off" nil)
657 (other :tag "when asked" ask))
660 (defvar pmail-enable-mime-composing nil
661 "*If non-nil, PMAIL uses `pmail-insert-mime-forwarded-message-function' to forward.")
664 (defvar pmail-show-mime-function nil
665 "Function to show MIME decoded message of PMAIL file.
666 This function is called when `pmail-enable-mime' is non-nil.
667 It is called with no argument.")
670 (defvar pmail-insert-mime-forwarded-message-function nil
671 "Function to insert a message in MIME format so it can be forwarded.
672 This function is called if `pmail-enable-mime' or
673 `pmail-enable-mime-composing' is non-nil.
674 It is called with one argument FORWARD-BUFFER, which is a
675 buffer containing the message to forward. The current buffer
676 is the outgoing mail buffer.")
679 (defvar pmail-insert-mime-resent-message-function nil
680 "Function to insert a message in MIME format so it can be resent.
681 This function is called if `pmail-enable-mime' is non-nil.
682 It is called with one argument FORWARD-BUFFER, which is a
683 buffer containing the message to forward. The current buffer
684 is the outgoing mail buffer.")
687 (defvar pmail-search-mime-message-function nil
688 "Function to check if a regexp matches a MIME message.
689 This function is called if `pmail-enable-mime' is non-nil.
690 It is called with two arguments MSG and REGEXP, where
691 MSG is the message number, REGEXP is the regular expression.")
694 (defvar pmail-search-mime-header-function nil
695 "Function to check if a regexp matches a header of MIME message.
696 This function is called if `pmail-enable-mime' is non-nil.
697 It is called with three arguments MSG, REGEXP, and LIMIT, where
698 MSG is the message number,
699 REGEXP is the regular expression,
700 LIMIT is the position specifying the end of header.")
703 (defvar pmail-mime-feature 'pmail-mime
704 "Feature to require to load MIME support in Pmail.
705 When starting Pmail, if `pmail-enable-mime' is non-nil,
706 this feature is required with `require'.
708 The default value is `pmail-mime'. This feature is provided by
709 the pmail-mime package available at <http://www.m17n.org/pmail-mime/>.")
712 (defvar pmail-decode-mime-charset t
713 "*Non-nil means a message is decoded by MIME's charset specification.
714 If this variable is nil, or the message has not MIME specification,
715 the message is decoded as normal way.
717 If the variable `pmail-enable-mime' is non-nil, this variables is
718 ignored, and all the decoding work is done by a feature specified by
719 the variable `pmail-mime-feature'.")
722 (defvar pmail-mime-charset-pattern
723 (concat "^content-type:[ \t]*text/plain;"
724 "\\(?:[ \t\n]*\\(?:format\\|delsp\\)=\"?[-a-z0-9]+\"?;\\)*"
725 "[ \t\n]*charset=\"?\\([^ \t\n\";]+\\)\"?")
726 "Regexp to match MIME-charset specification in a header of message.
727 The first parenthesized expression should match the MIME-charset name.")
730 ;;; Regexp matching the delimiter of messages in UNIX mail format
731 ;;; (UNIX From lines), minus the initial ^. Note that if you change
732 ;;; this expression, you must change the code in pmail-nuke-pinhead-header
733 ;;; that knows the exact ordering of the \\( \\) subexpressions.
734 (defvar pmail-unix-mail-delimiter
735 (let ((time-zone-regexp
736 (concat "\\([A-Z]?[A-Z]?[A-Z][A-Z]\\( DST\\)?"
737 "\\|[-+]?[0-9][0-9][0-9][0-9]"
743 ;; Many things can happen to an RFC 822 mailbox before it is put into
744 ;; a `From' line. The leading phrase can be stripped, e.g.
745 ;; `Joe <@w.x:joe@y.z>' -> `<@w.x:joe@y.z>'. The <> can be stripped, e.g.
746 ;; `<@x.y:joe@y.z>' -> `@x.y:joe@y.z'. Everything starting with a CRLF
747 ;; can be removed, e.g.
748 ;; From: joe@y.z (Joe K
750 ;; can yield `From joe@y.z (Joe K Fri Mar 22 08:11:15 1996', and
753 ;; can yield `From Joe User Fri Mar 22 08:11:15 1996'.
754 ;; The mailbox can be removed or be replaced by white space, e.g.
755 ;; From: "Joe User"{space}{tab}
757 ;; can yield `From {space}{tab} Fri Mar 22 08:11:15 1996',
758 ;; where {space} and {tab} represent the Ascii space and tab characters.
759 ;; We want to match the results of any of these manglings.
760 ;; The following regexp rejects names whose first characters are
761 ;; obviously bogus, but after that anything goes.
762 "\\([^\0-\b\n-\r\^?].*\\)? "
764 ;; The time the message was sent.
765 "\\([^\0-\r \^?]+\\) +" ; day of the week
766 "\\([^\0-\r \^?]+\\) +" ; month
767 "\\([0-3]?[0-9]\\) +" ; day of month
768 "\\([0-2][0-9]:[0-5][0-9]\\(:[0-6][0-9]\\)?\\) *" ; time of day
770 ;; Perhaps a time zone, specified by an abbreviation, or by a
775 " \\([0-9][0-9]+\\) *"
777 ;; On some systems the time zone can appear after the year, too.
781 "\\(remote from .*\\)?"
786 (defvar pmail-font-lock-keywords
787 ;; These are all matched case-insensitively.
789 (let* ((cite-chars "[>|}]")
791 (cite-suffix (concat cite-prefix "0-9_.@-`'\"")))
792 (list '("^\\(From\\|Sender\\|Resent-From\\):"
793 . 'pmail-header-name)
794 '("^Reply-To:.*$" . 'pmail-header-name)
795 '("^Subject:" . 'pmail-header-name)
796 '("^X-Spam-Status:" . 'pmail-header-name)
797 '("^\\(To\\|Apparently-To\\|Cc\\|Newsgroups\\):"
798 . 'pmail-header-name)
799 ;; Use MATCH-ANCHORED to effectively anchor the regexp left side.
801 (,(concat "\\=[ \t]*"
802 "\\(\\(\\([" cite-prefix "]+[" cite-suffix "]*\\)?"
803 "\\(" cite-chars "[ \t]*\\)\\)+\\)"
805 (beginning-of-line) (end-of-line)
806 (1 font-lock-comment-delimiter-face nil t)
807 (5 font-lock-comment-face nil t)))
808 '("^\\(X-[a-z0-9-]+\\|In-reply-to\\|Date\\):.*\\(\n[ \t]+.*\\)*$"
809 . 'pmail-header-name))))
810 "Additional expressions to highlight in Pmail mode.")
812 ;; Perform BODY in the summary buffer
813 ;; in such a way that its cursor is properly updated in its own window.
814 (defmacro pmail-select-summary (&rest body)
815 `(let ((total pmail-total-messages))
816 (if (pmail-summary-displayed)
817 (let ((window (selected-window)))
821 (pop-to-buffer pmail-summary-buffer)
822 ;; pmail-total-messages is a buffer-local var
823 ;; in the pmail buffer.
824 ;; This way we make it available for the body
825 ;; even tho the pmail buffer is not current.
826 (let ((pmail-total-messages total))
828 (select-window window))))
830 (set-buffer pmail-summary-buffer)
831 (let ((pmail-total-messages total))
833 (pmail-maybe-display-summary)))
835 ;;;; *** Pmail Mode ***
837 ;; This variable is dynamically bound. The defvar is here to placate
838 ;; the byte compiler.
840 (defvar pmail-enable-multibyte nil)
843 (defun pmail-require-mime-maybe ()
844 "Require `pmail-mime-feature' if that is non-nil.
845 Signal an error and set `pmail-mime-feature' to nil if the feature
847 (when pmail-enable-mime
849 (require pmail-mime-feature)
853 (format "Although MIME support is requested
854 by setting `pmail-enable-mime' to non-nil, the required feature
855 `%s' (the value of `pmail-mime-feature')
856 is not available in the current session.
857 So, the MIME support is turned off for the moment."
860 (setq pmail-enable-mime nil)))))
864 (defun pmail (&optional file-name-arg)
865 "Read and edit incoming mail.
866 Moves messages into file named by `pmail-file-name' (a babyl format file)
867 and edits that file in PMAIL Mode.
868 Type \\[describe-mode] once editing that file, for a list of PMAIL commands.
870 May be called with file name as argument; then performs pmail editing on
871 that file, but does not copy any new mail into the file.
872 Interactively, if you supply a prefix argument, then you
873 have a chance to specify a file name with the minibuffer.
875 If `pmail-display-summary' is non-nil, make a summary for this PMAIL file."
876 (interactive (if current-prefix-arg
877 (list (read-file-name "Run pmail on PMAIL file: "))))
878 (pmail-require-mime-maybe)
879 (let* ((file-name (expand-file-name (or file-name-arg pmail-file-name)))
880 ;; Use find-buffer-visiting, not get-file-buffer, for those users
881 ;; who have find-file-visit-truename set to t.
882 (existed (find-buffer-visiting file-name))
883 run-mail-hook mail-buf msg-shown)
884 ;; Determine if an existing mail file has been changed behind the
886 (if (and existed (not (verify-visited-file-modtime existed)))
887 ;; The mail file has been changed. Revisit it and reset the
888 ;; message state variables when in pmail mode.
890 (find-file file-name)
891 (when (and (verify-visited-file-modtime existed)
892 (eq major-mode 'pmail-mode))
893 (pmail-set-message-counters)))
894 ;; The mail file is either unchanged or not visited. Visit it.
896 (let ((enable-local-variables nil))
897 (find-file-noselect file-name))))
898 ;; Insure that the collection and view buffers are in sync and
899 ;; insure that a message is not being edited.
900 (if (eq major-mode 'pmail-mode)
901 (pmail-swap-buffers-maybe))
902 (if (eq major-mode 'pmail-edit-mode)
903 (error "Exit Pmail Edit mode before getting new mail"))
904 (or (and existed (> (buffer-size) 0))
905 (setq run-mail-hook t))
906 ;; Insure that the Rmail file is in mbox format, the buffer is in
907 ;; Pmail mode and has been scanned to find all the messages
908 ;; (setting the global message variables in the process).
909 (pmail-convert-file-maybe)
910 (unless (eq major-mode 'pmail-mode)
912 (goto-char (point-max))
913 (pmail-maybe-set-message-counters)
914 (setq mail-buf pmail-buffer)
915 ;; Show the first unread message and process summary mode.
917 ;; Only get new mail when there is not a file name argument.
918 (unless file-name-arg
919 (pmail-get-new-mail))
921 (set-buffer mail-buf)
922 (pmail-show-message-maybe (pmail-first-unseen-message))
923 (if pmail-display-summary (pmail-summary))
924 (pmail-construct-io-menu)
926 (run-hooks 'pmail-mode-hook))))))
928 (defun pmail-convert-file-maybe ()
929 "Determine if the file needs to be converted to mbox format."
931 (goto-char (point-min))
932 ;; Detect previous Babyl format files.
933 (cond ((looking-at "BABYL OPTIONS:")
934 ;; The file is Babyl version 5. Use unrmail to convert
936 (pmail-convert-babyl-to-mbox))
937 ((looking-at "Version: 5\n")
938 ;; Losing babyl file made by old version of Pmail. Fix the
939 ;; babyl file header and use unrmail to convert to mbox
941 (let ((buffer-read-only nil))
942 (insert "BABYL OPTIONS: -*- pmail -*-\n")
943 (pmail-convert-babyl-to-mbox)))
944 ((equal (point-min) (point-max))
945 (message "Empty Pmail file."))
946 ((looking-at "From "))
947 (t (error "Invalid mbox file"))))
949 (defun pmail-error-bad-format (&optional msgnum)
950 "Report that the buffer is not in the mbox file format.
951 MSGNUM, if present, indicates the malformed message."
953 (error "Message %d is not a valid RFC2822 message" msgnum)
954 (error "Message is not a valid RFC2822 message")))
956 (defun pmail-convert-babyl-to-mbox ()
957 "Convert the mail file from Babyl version 5 to mbox.
958 This function also reinitializes local variables used by Pmail."
959 (let ((old-file (make-temp-file "pmail"))
960 (new-file (make-temp-file "pmail")))
963 (kill-all-local-variables)
964 (write-region (point-min) (point-max) old-file)
965 (unrmail old-file new-file)
966 (message "Replacing BABYL format with mbox format...")
967 (let ((inhibit-read-only t))
969 (insert-file-contents-literally new-file)
971 (pmail-perm-variables)
973 (goto-char (point-max))
974 (pmail-set-message-counters))
975 (message "Replacing BABYL format with mbox format...done"))
976 (delete-file old-file)
977 (delete-file new-file))))
979 (defun pmail-get-coding-system ()
980 "Return a suitable coding system to use for the current mail message.
981 The buffer is expected to be narrowed to just the header of the message."
982 (let ((content-type-header (mail-fetch-field "content-type"))
985 (setq separator (search-forward "\n\n")))
986 (if (and content-type-header
987 (string-match pmail-mime-charset-pattern content-type-header))
988 (substring content-type-header (match-beginning 1) (match-end 1))
991 ;;; Set up Pmail mode keymaps
993 (defvar pmail-mode-map nil)
996 (setq pmail-mode-map (make-keymap))
997 (suppress-keymap pmail-mode-map)
998 (define-key pmail-mode-map "a" 'pmail-add-label)
999 (define-key pmail-mode-map "b" 'pmail-bury)
1000 (define-key pmail-mode-map "c" 'pmail-continue)
1001 (define-key pmail-mode-map "d" 'pmail-delete-forward)
1002 (define-key pmail-mode-map "\C-d" 'pmail-delete-backward)
1003 (define-key pmail-mode-map "e" 'pmail-edit-current-message)
1004 (define-key pmail-mode-map "f" 'pmail-forward)
1005 (define-key pmail-mode-map "g" 'pmail-get-new-mail)
1006 (define-key pmail-mode-map "h" 'pmail-summary)
1007 (define-key pmail-mode-map "i" 'pmail-input)
1008 (define-key pmail-mode-map "j" 'pmail-show-message-maybe)
1009 (define-key pmail-mode-map "k" 'pmail-kill-label)
1010 (define-key pmail-mode-map "l" 'pmail-summary-by-labels)
1011 (define-key pmail-mode-map "\e\C-h" 'pmail-summary)
1012 (define-key pmail-mode-map "\e\C-l" 'pmail-summary-by-labels)
1013 (define-key pmail-mode-map "\e\C-r" 'pmail-summary-by-recipients)
1014 (define-key pmail-mode-map "\e\C-s" 'pmail-summary-by-regexp)
1015 (define-key pmail-mode-map "\e\C-t" 'pmail-summary-by-topic)
1016 (define-key pmail-mode-map "m" 'pmail-mail)
1017 (define-key pmail-mode-map "\em" 'pmail-retry-failure)
1018 (define-key pmail-mode-map "n" 'pmail-next-undeleted-message)
1019 (define-key pmail-mode-map "\en" 'pmail-next-message)
1020 (define-key pmail-mode-map "\e\C-n" 'pmail-next-labeled-message)
1021 (define-key pmail-mode-map "o" 'pmail-output)
1022 (define-key pmail-mode-map "\C-o" 'pmail-output-as-seen)
1023 (define-key pmail-mode-map "p" 'pmail-previous-undeleted-message)
1024 (define-key pmail-mode-map "\ep" 'pmail-previous-message)
1025 (define-key pmail-mode-map "\e\C-p" 'pmail-previous-labeled-message)
1026 (define-key pmail-mode-map "q" 'pmail-quit)
1027 (define-key pmail-mode-map "r" 'pmail-reply)
1028 ;; I find I can't live without the default M-r command -- rms.
1029 ;; (define-key pmail-mode-map "\er" 'pmail-search-backwards)
1030 (define-key pmail-mode-map "s" 'pmail-expunge-and-save)
1031 (define-key pmail-mode-map "\es" 'pmail-search)
1032 (define-key pmail-mode-map "t" 'pmail-toggle-header)
1033 (define-key pmail-mode-map "u" 'pmail-undelete-previous-message)
1034 (define-key pmail-mode-map "w" 'pmail-output-body-to-file)
1035 (define-key pmail-mode-map "\C-c\C-w" 'pmail-widen)
1036 (define-key pmail-mode-map "x" 'pmail-expunge)
1037 (define-key pmail-mode-map "." 'pmail-beginning-of-message)
1038 (define-key pmail-mode-map "/" 'pmail-end-of-message)
1039 (define-key pmail-mode-map "<" 'pmail-first-message)
1040 (define-key pmail-mode-map ">" 'pmail-last-message)
1041 (define-key pmail-mode-map " " 'scroll-up)
1042 (define-key pmail-mode-map "\177" 'scroll-down)
1043 (define-key pmail-mode-map "?" 'describe-mode)
1044 (define-key pmail-mode-map "\C-c\C-s\C-d" 'pmail-sort-by-date)
1045 (define-key pmail-mode-map "\C-c\C-s\C-s" 'pmail-sort-by-subject)
1046 (define-key pmail-mode-map "\C-c\C-s\C-a" 'pmail-sort-by-author)
1047 (define-key pmail-mode-map "\C-c\C-s\C-r" 'pmail-sort-by-recipient)
1048 (define-key pmail-mode-map "\C-c\C-s\C-c" 'pmail-sort-by-correspondent)
1049 (define-key pmail-mode-map "\C-c\C-s\C-l" 'pmail-sort-by-lines)
1050 (define-key pmail-mode-map "\C-c\C-s\C-k" 'pmail-sort-by-labels)
1051 (define-key pmail-mode-map "\C-c\C-n" 'pmail-next-same-subject)
1052 (define-key pmail-mode-map "\C-c\C-p" 'pmail-previous-same-subject)
1055 (define-key pmail-mode-map [menu-bar] (make-sparse-keymap))
1057 (define-key pmail-mode-map [menu-bar classify]
1058 (cons "Classify" (make-sparse-keymap "Classify")))
1060 (define-key pmail-mode-map [menu-bar classify input-menu]
1063 (define-key pmail-mode-map [menu-bar classify output-menu]
1066 (define-key pmail-mode-map [menu-bar classify output-body]
1067 '("Output body to file..." . pmail-output-body-to-file))
1069 (define-key pmail-mode-map [menu-bar classify output-inbox]
1070 '("Output..." . pmail-output))
1072 (define-key pmail-mode-map [menu-bar classify output]
1073 '("Output as seen..." . pmail-output-as-seen))
1075 (define-key pmail-mode-map [menu-bar classify kill-label]
1076 '("Kill Label..." . pmail-kill-label))
1078 (define-key pmail-mode-map [menu-bar classify add-label]
1079 '("Add Label..." . pmail-add-label))
1081 (define-key pmail-mode-map [menu-bar summary]
1082 (cons "Summary" (make-sparse-keymap "Summary")))
1084 (define-key pmail-mode-map [menu-bar summary senders]
1085 '("By Senders..." . pmail-summary-by-senders))
1087 (define-key pmail-mode-map [menu-bar summary labels]
1088 '("By Labels..." . pmail-summary-by-labels))
1090 (define-key pmail-mode-map [menu-bar summary recipients]
1091 '("By Recipients..." . pmail-summary-by-recipients))
1093 (define-key pmail-mode-map [menu-bar summary topic]
1094 '("By Topic..." . pmail-summary-by-topic))
1096 (define-key pmail-mode-map [menu-bar summary regexp]
1097 '("By Regexp..." . pmail-summary-by-regexp))
1099 (define-key pmail-mode-map [menu-bar summary all]
1100 '("All" . pmail-summary))
1102 (define-key pmail-mode-map [menu-bar mail]
1103 (cons "Mail" (make-sparse-keymap "Mail")))
1105 (define-key pmail-mode-map [menu-bar mail pmail-get-new-mail]
1106 '("Get New Mail" . pmail-get-new-mail))
1108 (define-key pmail-mode-map [menu-bar mail lambda]
1111 (define-key pmail-mode-map [menu-bar mail continue]
1112 '("Continue" . pmail-continue))
1114 (define-key pmail-mode-map [menu-bar mail resend]
1115 '("Re-send..." . pmail-resend))
1117 (define-key pmail-mode-map [menu-bar mail forward]
1118 '("Forward" . pmail-forward))
1120 (define-key pmail-mode-map [menu-bar mail retry]
1121 '("Retry" . pmail-retry-failure))
1123 (define-key pmail-mode-map [menu-bar mail reply]
1124 '("Reply" . pmail-reply))
1126 (define-key pmail-mode-map [menu-bar mail mail]
1127 '("Mail" . pmail-mail))
1129 (define-key pmail-mode-map [menu-bar delete]
1130 (cons "Delete" (make-sparse-keymap "Delete")))
1132 (define-key pmail-mode-map [menu-bar delete expunge/save]
1133 '("Expunge/Save" . pmail-expunge-and-save))
1135 (define-key pmail-mode-map [menu-bar delete expunge]
1136 '("Expunge" . pmail-expunge))
1138 (define-key pmail-mode-map [menu-bar delete undelete]
1139 '("Undelete" . pmail-undelete-previous-message))
1141 (define-key pmail-mode-map [menu-bar delete delete]
1142 '("Delete" . pmail-delete-forward))
1144 (define-key pmail-mode-map [menu-bar move]
1145 (cons "Move" (make-sparse-keymap "Move")))
1147 (define-key pmail-mode-map [menu-bar move search-back]
1148 '("Search Back..." . pmail-search-backwards))
1150 (define-key pmail-mode-map [menu-bar move search]
1151 '("Search..." . pmail-search))
1153 (define-key pmail-mode-map [menu-bar move previous]
1154 '("Previous Nondeleted" . pmail-previous-undeleted-message))
1156 (define-key pmail-mode-map [menu-bar move next]
1157 '("Next Nondeleted" . pmail-next-undeleted-message))
1159 (define-key pmail-mode-map [menu-bar move last]
1160 '("Last" . pmail-last-message))
1162 (define-key pmail-mode-map [menu-bar move first]
1163 '("First" . pmail-first-message))
1165 (define-key pmail-mode-map [menu-bar move previous]
1166 '("Previous" . pmail-previous-message))
1168 (define-key pmail-mode-map [menu-bar move next]
1169 '("Next" . pmail-next-message))
1172 (defvar pmail-tool-bar-map
1173 (let ((map (make-sparse-keymap)))
1174 (tool-bar-local-item-from-menu 'pmail-get-new-mail "mail/inbox"
1176 (tool-bar-local-item-from-menu 'pmail-next-undeleted-message "right-arrow"
1178 (tool-bar-local-item-from-menu 'pmail-previous-undeleted-message "left-arrow"
1180 (tool-bar-local-item-from-menu 'pmail-search "search"
1182 (tool-bar-local-item-from-menu 'pmail-input "open"
1184 (tool-bar-local-item-from-menu 'pmail-mail "mail/compose"
1186 (tool-bar-local-item-from-menu 'pmail-reply "mail/reply-all"
1188 (tool-bar-local-item-from-menu 'pmail-forward "mail/forward"
1190 (tool-bar-local-item-from-menu 'pmail-delete-forward "close"
1192 (tool-bar-local-item-from-menu 'pmail-output "mail/move"
1194 (tool-bar-local-item-from-menu 'pmail-output-body-to-file "mail/save"
1196 (tool-bar-local-item-from-menu 'pmail-expunge "delete"
1202 ;; Pmail mode is suitable only for specially formatted data.
1203 (put 'pmail-mode 'mode-class 'special)
1205 (defun pmail-mode-kill-summary ()
1206 (if pmail-summary-buffer (kill-buffer pmail-summary-buffer)))
1209 (defun pmail-mode ()
1210 "Pmail Mode is used by \\<pmail-mode-map>\\[pmail] for editing Pmail files.
1211 All normal editing commands are turned off.
1212 Instead, these commands are available:
1214 \\[pmail-beginning-of-message] Move point to front of this message.
1215 \\[pmail-end-of-message] Move point to bottom of this message.
1216 \\[scroll-up] Scroll to next screen of this message.
1217 \\[scroll-down] Scroll to previous screen of this message.
1218 \\[pmail-next-undeleted-message] Move to Next non-deleted message.
1219 \\[pmail-previous-undeleted-message] Move to Previous non-deleted message.
1220 \\[pmail-next-message] Move to Next message whether deleted or not.
1221 \\[pmail-previous-message] Move to Previous message whether deleted or not.
1222 \\[pmail-first-message] Move to the first message in Pmail file.
1223 \\[pmail-last-message] Move to the last message in Pmail file.
1224 \\[pmail-show-message-maybe] Jump to message specified by numeric position in file.
1225 \\[pmail-search] Search for string and show message it is found in.
1226 \\[pmail-delete-forward] Delete this message, move to next nondeleted.
1227 \\[pmail-delete-backward] Delete this message, move to previous nondeleted.
1228 \\[pmail-undelete-previous-message] Undelete message. Tries current message, then earlier messages
1229 till a deleted message is found.
1230 \\[pmail-edit-current-message] Edit the current message. \\[pmail-cease-edit] to return to Pmail.
1231 \\[pmail-expunge] Expunge deleted messages.
1232 \\[pmail-expunge-and-save] Expunge and save the file.
1233 \\[pmail-quit] Quit Pmail: expunge, save, then switch to another buffer.
1234 \\[save-buffer] Save without expunging.
1235 \\[pmail-get-new-mail] Move new mail from system spool directory into this file.
1236 \\[pmail-mail] Mail a message (same as \\[mail-other-window]).
1237 \\[pmail-continue] Continue composing outgoing message started before.
1238 \\[pmail-reply] Reply to this message. Like \\[pmail-mail] but initializes some fields.
1239 \\[pmail-retry-failure] Send this message again. Used on a mailer failure message.
1240 \\[pmail-forward] Forward this message to another user.
1241 \\[pmail-output] Output (append) this message to another mail file.
1242 \\[pmail-output-as-seen] Output (append) this message to file as it's displayed.
1243 \\[pmail-output-body-to-file] Save message body to a file. Default filename comes from Subject line.
1244 \\[pmail-input] Input Pmail file. Run Pmail on that file.
1245 \\[pmail-add-label] Add label to message. It will be displayed in the mode line.
1246 \\[pmail-kill-label] Kill label. Remove a label from current message.
1247 \\[pmail-next-labeled-message] Move to Next message with specified label
1248 (label defaults to last one specified).
1249 Standard labels: filed, unseen, answered, forwarded, deleted.
1250 Any other label is present only if you add it with \\[pmail-add-label].
1251 \\[pmail-previous-labeled-message] Move to Previous message with specified label
1252 \\[pmail-summary] Show headers buffer, with a one line summary of each message.
1253 \\[pmail-summary-by-labels] Summarize only messages with particular label(s).
1254 \\[pmail-summary-by-recipients] Summarize only messages with particular recipient(s).
1255 \\[pmail-summary-by-regexp] Summarize only messages with particular regexp(s).
1256 \\[pmail-summary-by-topic] Summarize only messages with subject line regexp(s).
1257 \\[pmail-toggle-header] Toggle display of complete header."
1259 (let ((finding-pmail-file (not (eq major-mode 'pmail-mode))))
1261 (when (and finding-pmail-file
1262 (null coding-system-for-read)
1263 default-enable-multibyte-characters)
1264 (let ((pmail-enable-multibyte t))
1265 (pmail-require-mime-maybe)
1266 (pmail-convert-file-maybe)
1267 (goto-char (point-max))
1268 (set-buffer-multibyte t)))
1269 (pmail-set-message-counters)
1270 (pmail-show-message-maybe pmail-total-messages)
1271 (when finding-pmail-file
1272 (when pmail-display-summary
1274 (pmail-construct-io-menu))
1275 (run-mode-hooks 'pmail-mode-hook)))
1277 (defun pmail-mode-2 ()
1278 (kill-all-local-variables)
1280 (pmail-perm-variables)
1283 (defun pmail-mode-1 ()
1284 (setq major-mode 'pmail-mode)
1285 (setq mode-name "PMAIL")
1286 (setq buffer-read-only t)
1287 ;; No need to auto save PMAIL files in normal circumstances
1288 ;; because they contain no info except attribute changes
1289 ;; and deletion of messages.
1290 ;; The one exception is when messages are copied into another mbox buffer.
1291 ;; pmail-output enables auto save when you do that.
1292 (setq buffer-auto-save-file-name nil)
1293 (use-local-map pmail-mode-map)
1294 (set-syntax-table text-mode-syntax-table)
1295 (setq local-abbrev-table text-mode-abbrev-table)
1296 ;; First attempt at adding hook functions to support buffer swapping...
1297 (add-hook 'kill-buffer-hook 'pmail-mode-kill-buffer-hook nil t)
1298 (add-hook 'change-major-mode-hook 'pmail-change-major-mode-hook nil t))
1300 (defun pmail-generate-viewer-buffer ()
1301 "Return a reusable buffer suitable for viewing messages.
1302 Create the buffer if necessary."
1303 (let* ((suffix (file-name-nondirectory (or buffer-file-name (buffer-name))))
1304 (name (format " *message-viewer %s*" suffix))
1305 (buf (get-buffer name)))
1307 (generate-new-buffer name))))
1309 (defun pmail-change-major-mode-hook ()
1310 ;; Bring the actual Pmail messages back into the main buffer.
1311 (if buffer-swapped-with
1312 (when (pmail-buffers-swapped-p)
1313 (setq buffer-swapped-with nil)
1314 (let ((modp (buffer-modified-p)))
1315 (buffer-swap-text pmail-view-buffer)
1316 (set-buffer-modified-p modp)))))
1317 ;; Throw away the summary.
1318 ;;(when (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer)))
1320 (defun pmail-buffers-swapped-p ()
1321 "Return non-nil if the message collection is in `pmail-view-buffer'."
1322 ;; We need to be careful to keep track of which buffer holds the
1323 ;; message collection, since we swap the collection the view of the
1324 ;; current message back and forth. This model is based on Stefan
1325 ;; Monnier's solution for tar-mode.
1326 (and (buffer-live-p pmail-view-buffer)
1327 (> (buffer-size pmail-view-buffer) (buffer-size))))
1329 (defun pmail-swap-buffers-maybe ()
1330 "Determine if the Pmail buffer is showing a message.
1331 If so restore the actual mbox message collection."
1332 (with-current-buffer pmail-buffer
1333 (when (pmail-buffers-swapped-p)
1334 (let ((modp (buffer-modified-p)))
1335 (buffer-swap-text pmail-view-buffer)
1336 (set-buffer-modified-p modp))
1337 (setq buffer-swapped-with nil))))
1339 (defun pmail-mode-kill-buffer-hook ()
1340 (if (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer)))
1342 ;; Set up the permanent locals associated with an Pmail file.
1343 (defun pmail-perm-variables ()
1344 (make-local-variable 'pmail-last-regexp)
1345 (make-local-variable 'pmail-deleted-vector)
1346 (make-local-variable 'pmail-buffer)
1347 (setq pmail-buffer (current-buffer))
1348 (set-buffer-multibyte nil)
1349 (make-local-variable 'pmail-view-buffer)
1351 (setq pmail-view-buffer (pmail-generate-viewer-buffer))
1352 (set-buffer pmail-view-buffer)
1353 (setq buffer-undo-list t)
1354 (set-buffer-multibyte t))
1355 (make-local-variable 'pmail-summary-buffer)
1356 (make-local-variable 'pmail-summary-vector)
1357 (make-local-variable 'pmail-current-message)
1358 (make-local-variable 'pmail-total-messages)
1359 (setq pmail-total-messages 0)
1360 (make-local-variable 'pmail-overlay-list)
1361 (setq pmail-overlay-list nil)
1362 (make-local-variable 'pmail-message-vector)
1363 (make-local-variable 'pmail-msgref-vector)
1364 (make-local-variable 'pmail-inbox-list)
1365 ;; Provide default set of inboxes for primary mail file ~/PMAIL.
1366 (and (null pmail-inbox-list)
1367 (or (equal buffer-file-name (expand-file-name pmail-file-name))
1368 (equal buffer-file-truename
1369 (abbreviate-file-name (file-truename pmail-file-name))))
1370 (setq pmail-inbox-list
1371 (or pmail-primary-inbox-list
1372 (list (or (getenv "MAIL")
1373 (concat rmail-spool-directory
1374 (user-login-name)))))))
1375 (set (make-local-variable 'tool-bar-map) pmail-tool-bar-map))
1377 ;; Set up the non-permanent locals associated with Pmail mode.
1378 (defun pmail-variables ()
1379 ;; Turn off undo. We turn it back on in pmail-edit.
1380 (setq buffer-undo-list t)
1381 ;; Don't let a local variables list in a message cause confusion.
1382 (make-local-variable 'local-enable-local-variables)
1383 (setq local-enable-local-variables nil)
1384 (make-local-variable 'revert-buffer-function)
1385 (setq revert-buffer-function 'pmail-revert)
1386 (make-local-variable 'font-lock-defaults)
1387 (setq font-lock-defaults
1388 '(pmail-font-lock-keywords
1390 (font-lock-maximum-size . nil)
1391 (font-lock-fontify-buffer-function . pmail-fontify-buffer-function)
1392 (font-lock-unfontify-buffer-function . pmail-unfontify-buffer-function)
1393 (font-lock-inhibit-thing-lock . (lazy-lock-mode fast-lock-mode))))
1394 (make-local-variable 'require-final-newline)
1395 (setq require-final-newline nil)
1396 (make-local-variable 'version-control)
1397 (setq version-control 'never)
1398 (make-local-variable 'kill-buffer-hook)
1399 (add-hook 'kill-buffer-hook 'pmail-mode-kill-summary)
1400 (make-local-variable 'file-precious-flag)
1401 (setq file-precious-flag t)
1402 (make-local-variable 'desktop-save-buffer)
1403 (setq desktop-save-buffer t))
1405 ;; Handle M-x revert-buffer done in an pmail-mode buffer.
1406 (defun pmail-revert (arg noconfirm)
1407 (set-buffer pmail-buffer)
1408 (let* ((revert-buffer-function (default-value 'revert-buffer-function))
1409 (pmail-enable-multibyte enable-multibyte-characters)
1410 ;; See similar code in `pmail'.
1411 (coding-system-for-read (and pmail-enable-multibyte 'raw-text)))
1412 ;; Call our caller again, but this time it does the default thing.
1413 (when (revert-buffer arg noconfirm)
1414 ;; If the user said "yes", and we changed something,
1415 ;; reparse the messages.
1416 (set-buffer pmail-buffer)
1418 ;; Convert all or part to Babyl file if possible.
1419 (pmail-convert-file-maybe)
1420 ;; We have read the file as raw-text, so the buffer is set to
1421 ;; unibyte. Make it multibyte if necessary.
1422 (if (and pmail-enable-multibyte
1423 (not enable-multibyte-characters))
1424 (set-buffer-multibyte t))
1425 (goto-char (point-max))
1426 (pmail-set-message-counters)
1427 (pmail-show-message-maybe pmail-total-messages)
1428 (run-hooks 'pmail-mode-hook))))
1430 (defun pmail-expunge-and-save ()
1431 "Expunge and save PMAIL file."
1433 (set-buffer pmail-buffer)
1435 (pmail-swap-buffers-maybe)
1437 (if (pmail-summary-exists)
1438 (pmail-select-summary (set-buffer-modified-p nil))
1439 (pmail-show-message)))
1441 (defun pmail-quit ()
1443 Hook `pmail-quit-hook' is run after expunging."
1445 (set-buffer pmail-buffer)
1447 (pmail-swap-buffers-maybe)
1449 (when (boundp 'pmail-quit-hook)
1450 (run-hooks 'pmail-quit-hook))
1451 ;; Don't switch to the summary buffer even if it was recently visible.
1452 (when pmail-summary-buffer
1453 (replace-buffer-in-windows pmail-summary-buffer)
1454 (bury-buffer pmail-summary-buffer))
1455 (if pmail-enable-mime
1456 (let ((obuf pmail-buffer)
1457 (ovbuf pmail-view-buffer))
1458 (set-buffer pmail-view-buffer)
1460 (replace-buffer-in-windows ovbuf)
1461 (replace-buffer-in-windows obuf)
1463 (let ((obuf (current-buffer)))
1465 (replace-buffer-in-windows obuf))))
1467 (defun pmail-bury ()
1468 "Bury current Pmail buffer and its summary buffer."
1470 ;; This let var was called pmail-buffer, but that interfered
1471 ;; with the buffer-local var used in summary buffers.
1472 (let ((buffer-to-bury (current-buffer)))
1473 (if (pmail-summary-exists)
1475 (while (setq window (get-buffer-window pmail-summary-buffer))
1476 (quit-window nil window))
1477 (bury-buffer pmail-summary-buffer)))
1480 (defun pmail-duplicate-message ()
1481 "Create a duplicated copy of the current message.
1482 The duplicate copy goes into the Pmail file just after the
1486 (let ((buffer-read-only nil)
1487 (number pmail-current-message)
1488 (string (buffer-substring (pmail-msgbeg pmail-current-message)
1489 (pmail-msgend pmail-current-message))))
1490 (goto-char (pmail-msgend pmail-current-message))
1492 (pmail-forget-messages)
1493 (pmail-show-message-maybe number)
1494 (message "Message duplicated")))
1497 (defun pmail-input (filename)
1498 "Run Pmail on file FILENAME."
1499 (interactive "FRun pmail on PMAIL file: ")
1502 ;; This used to scan subdirectories recursively, but someone pointed out
1503 ;; that if the user wants that, person can put all the files in one dir.
1504 ;; And the recursive scan was slow. So I took it out.
1506 (defun pmail-find-all-files (start)
1507 "Return list of file in dir START that match `pmail-secondary-file-regexp'."
1508 (if (file-accessible-directory-p start)
1510 (let* ((case-fold-search t)
1511 (files (directory-files start t pmail-secondary-file-regexp)))
1512 ;; Sort here instead of in directory-files
1513 ;; because this list is usually much shorter.
1514 (sort files 'string<))))
1516 (defun pmail-list-to-menu (menu-name l action &optional full-name)
1517 (let ((menu (make-sparse-keymap menu-name)))
1524 (car item) (cdr item) action
1526 (concat full-name "/"
1532 (list 'lambda () '(interactive)
1536 (concat full-name "/" item)
1538 pmail-secondary-file-directory)))))
1539 (define-key menu (vector (intern name))
1540 (cons name command))))
1544 ;; This command is always "disabled" when it appears in a menu.
1545 (put 'pmail-disable-menu 'menu-enable ''nil)
1547 (defun pmail-construct-io-menu ()
1548 (let ((files (pmail-find-all-files pmail-secondary-file-directory)))
1551 (define-key pmail-mode-map [menu-bar classify input-menu]
1552 (cons "Input Pmail File"
1553 (pmail-list-to-menu "Input Pmail File"
1556 (define-key pmail-mode-map [menu-bar classify output-menu]
1557 (cons "Output Pmail File"
1558 (pmail-list-to-menu "Output Pmail File"
1562 (define-key pmail-mode-map [menu-bar classify input-menu]
1563 '("Input Pmail File" . pmail-disable-menu))
1564 (define-key pmail-mode-map [menu-bar classify output-menu]
1565 '("Output Pmail File" . pmail-disable-menu)))))
1568 ;;;; *** Pmail input ***
1570 (declare-function rmail-spam-filter "rmail-spam-filter" (msg))
1571 (declare-function pmail-summary-goto-msg "pmailsum" (&optional n nowarn skip-pmail))
1572 (declare-function pmail-summary-mark-undeleted "pmailsum" (n))
1573 (declare-function pmail-summary-mark-deleted "pmailsum" (&optional n undel))
1574 (declare-function rfc822-addresses "rfc822" (header-text))
1575 (declare-function mail-abbrev-make-syntax-table "mailabbrev.el" ())
1576 (declare-function mail-sendmail-delimit-header "sendmail" ())
1577 (declare-function mail-header-end "sendmail" ())
1579 ;; RLK feature not added in this version:
1580 ;; argument specifies inbox file or files in various ways.
1582 (defun pmail-get-new-mail (&optional file-name)
1583 "Move any new mail from this PMAIL file's inbox files.
1584 The inbox files can be specified with the file's Mail: option. The
1585 variable `pmail-primary-inbox-list' specifies the inboxes for your
1586 primary PMAIL file if it has no Mail: option. By default, this is
1587 your /usr/spool/mail/$USER.
1589 You can also specify the file to get new mail from. In this case, the
1590 file of new mail is not changed or deleted. Noninteractively, you can
1591 pass the inbox file name as an argument. Interactively, a prefix
1592 argument causes us to read a file name and use that file as the inbox.
1594 If the variable `pmail-preserve-inbox' is non-nil, new mail will
1595 always be left in inbox files rather than deleted.
1597 This function runs `pmail-get-new-mail-hook' before saving the updated file.
1598 It returns t if it got any new messages."
1600 (list (if current-prefix-arg
1601 (read-file-name "Get new mail from file: "))))
1602 (run-hooks 'pmail-before-get-new-mail-hook)
1603 ;; If the disk file has been changed from under us,
1604 ;; revert to it before we get new mail.
1605 (or (verify-visited-file-modtime (current-buffer))
1606 (find-file (buffer-file-name)))
1607 (set-buffer pmail-buffer)
1608 (pmail-swap-buffers-maybe)
1609 (pmail-maybe-set-message-counters)
1611 ;; Get rid of all undo records for this buffer.
1612 (or (eq buffer-undo-list t)
1613 (setq buffer-undo-list nil))
1614 (let ((all-files (if file-name (list file-name) pmail-inbox-list))
1615 (pmail-enable-multibyte (default-value 'enable-multibyte-characters))
1619 (let ((opoint (point))
1620 ;; If buffer has not changed yet, and has not been
1621 ;; saved yet, don't replace the old backup file now.
1622 (make-backup-files (and make-backup-files (buffer-modified-p)))
1623 (buffer-read-only nil)
1624 ;; Don't make undo records while getting mail.
1625 (buffer-undo-list t)
1626 delete-files success files file-last-names)
1627 ;; Pull files off all-files onto files as long as there is
1628 ;; no name conflict. A conflict happens when two inbox
1629 ;; file names have the same last component.
1630 (while (and all-files
1631 (not (member (file-name-nondirectory (car all-files))
1633 (setq files (cons (car all-files) files)
1635 (cons (file-name-nondirectory (car all-files)) files))
1636 (setq all-files (cdr all-files)))
1637 ;; Put them back in their original order.
1638 (setq files (nreverse files))
1639 (goto-char (point-max))
1640 (skip-chars-backward " \t\n") ; just in case of brain damage
1641 (delete-region (point) (point-max)) ; caused by require-final-newline
1642 (setq found (pmail-get-new-mail-1 file-name files delete-files))))
1644 ;; Don't leave the buffer screwed up if we get a disk-full error.
1645 (or found (pmail-show-message-maybe))))
1647 (defun pmail-get-new-mail-1 (file-name files delete-files)
1648 "Return t if new messages are detected without error, nil otherwise."
1651 (let ((new-messages 0)
1652 (spam-filter-p (and (featurep 'rmail-spam-filter)
1653 pmail-use-spam-filter))
1655 result success suffix)
1656 (narrow-to-region (point) (point))
1657 ;; Read in the contents of the inbox files, renaming them as
1658 ;; necessary, and adding to the list of files to delete
1661 (pmail-insert-inbox-text files nil)
1662 (setq delete-files (pmail-insert-inbox-text files t)))
1663 ;; Scan the new text and convert each message to
1664 ;; Pmail/mbox format.
1665 (goto-char (point-min))
1666 (skip-chars-forward " \n")
1667 (narrow-to-region (point) (point-max))
1669 (setq new-messages (pmail-add-mbox-headers)
1671 ;; Try to delete the garbage just inserted.
1672 (or success (delete-region (point-min) (point-max)))
1673 ;; If we could not convert the file's inboxes, rename the
1674 ;; files we tried to read so we won't over and over again.
1675 (if (and (not file-name) (not success))
1676 (let ((delfiles delete-files)
1679 (while (file-exists-p (format "PMAILOSE.%d" count))
1680 (setq count (1+ count)))
1681 (rename-file (car delfiles) (format "PMAILOSE.%d" count))
1682 (setq delfiles (cdr delfiles))))))
1683 ;; Determine if there are messages.
1684 (unless (zerop new-messages)
1685 ;; There are. Process them.
1686 (goto-char (point-min))
1687 (pmail-count-new-messages)
1688 (run-hooks 'pmail-get-new-mail-hook)
1690 ;; Delete the old files, now that the Pmail file is saved.
1693 ;; First, try deleting.
1695 (delete-file (car delete-files))
1697 ;; If we can't delete it, truncate it.
1698 (write-region (point) (point) (car delete-files))))
1700 (setq delete-files (cdr delete-files)))
1701 (if (zerop new-messages)
1702 (when (or file-name pmail-inbox-list)
1703 (message "(No new mail has arrived)"))
1704 ;; Generate the spam message.
1705 (setq blurb (if spam-filter-p
1706 (pmail-get-new-mail-filter-spam new-messages)
1708 (if (pmail-summary-exists)
1709 (pmail-select-summary (pmail-update-summary)))
1710 (setq suffix (if (= 1 new-messages) "" "s"))
1711 (message "%d new message%s read%s" new-messages suffix blurb)
1713 (if rsf-beep (beep t))
1714 (sleep-for rsf-sleep-after-message))
1716 ;; Establish the return value and move to the first new
1717 ;; message unless we have other unseen messages before it.
1718 (setq result (> new-messages 0))
1720 (pmail-show-message-maybe (pmail-first-unseen-message)))
1721 (run-hooks 'pmail-after-get-new-mail-hook)
1724 (defun pmail-get-new-mail-filter-spam (new-message-count)
1725 "Process new messages for spam."
1726 (let* ((old-messages (- pmail-total-messages new-message-count))
1727 (rsf-number-of-spam 0)
1728 (rsf-scanned-message-number (1+ old-messages))
1729 ;; save deletion flags of old messages: vector starts at zero
1730 ;; (is one longer that no of messages), therefore take 1+
1732 (save-deleted (substring pmail-deleted-vector 0 (1+ old-messages)))
1734 ;; set all messages to undeleted
1735 (setq pmail-deleted-vector (make-string (1+ pmail-total-messages) ?\ ))
1736 (while (<= rsf-scanned-message-number pmail-total-messages)
1738 (if (not (rmail-spam-filter rsf-scanned-message-number))
1739 (progn (setq rsf-number-of-spam (1+ rsf-number-of-spam))))
1740 (setq rsf-scanned-message-number (1+ rsf-scanned-message-number))))
1741 (if (> rsf-number-of-spam 0)
1743 (when (pmail-expunge-confirmed)
1744 (pmail-only-expunge t))))
1745 (setq pmail-deleted-vector
1746 (concat save-deleted
1747 (make-string (- pmail-total-messages old-messages) ?\ )))
1748 ;; Generate a return value message based on the number of spam
1751 ((zerop rsf-number-of-spam) "")
1752 ((= 1 new-message-count) ", and appears to be spam")
1753 ((= rsf-number-of-spam new-message-count) ", and all appear to be spam")
1754 ((> rsf-number-of-spam 1)
1755 (format ", and %d appear to be spam" rsf-number-of-spam))
1756 (t ", and 1 appears to be spam"))))
1758 (defun pmail-parse-url (file)
1759 "Parse the supplied URL. Return (list MAILBOX-NAME REMOTE PASSWORD GOT-PASSWORD)
1760 WHERE MAILBOX-NAME is the name of the mailbox suitable as argument to the
1761 actual version of `movemail', REMOTE is non-nil if MAILBOX-NAME refers to
1762 a remote mailbox, PASSWORD is the password if it should be
1763 supplied as a separate argument to `movemail' or nil otherwise, GOT-PASSWORD
1764 is non-nil if the user has supplied the password interactively.
1767 ((string-match "^\\([^:]+\\)://\\(\\([^:@]+\\)\\(:\\([^@]+\\)\\)?@\\)?.*" file)
1768 (let (got-password supplied-password
1769 (proto (match-string 1 file))
1770 (user (match-string 3 file))
1771 (pass (match-string 5 file))
1772 (host (substring file (or (match-end 2)
1773 (+ 3 (match-end 1))))))
1776 (when pmail-remote-password-required
1777 (setq got-password (not (pmail-have-password)))
1778 (setq supplied-password (pmail-get-remote-password
1779 (string-equal proto "imap"))))
1780 ;; The password is embedded. Strip it out since movemail
1781 ;; does not really like it, in spite of the movemail spec.
1782 (setq file (concat proto "://" user "@" host)))
1784 (if (pmail-movemail-variant-p 'emacs)
1785 (if (string-equal proto "pop")
1786 (list (concat "po:" user ":" host)
1788 (or pass supplied-password)
1790 (error "Emacs movemail does not support %s protocol" proto))
1792 (or (string-equal proto "pop") (string-equal proto "imap"))
1793 (or supplied-password pass)
1796 ((string-match "^po:\\([^:]+\\)\\(:\\(.*\\)\\)?" file)
1797 (let (got-password supplied-password
1799 (user (match-string 1 file))
1800 (host (match-string 3 file)))
1802 (when pmail-remote-password-required
1803 (setq got-password (not (pmail-have-password)))
1804 (setq supplied-password (pmail-get-remote-password nil)))
1806 (list file "pop" supplied-password got-password)))
1809 (list file nil nil nil))))
1811 (defun pmail-insert-inbox-text (files renamep)
1812 ;; Detect a locked file now, so that we avoid moving mail
1813 ;; out of the real inbox file. (That could scare people.)
1814 (or (memq (file-locked-p buffer-file-name) '(nil t))
1815 (error "PMAIL file %s is locked"
1816 (file-name-nondirectory buffer-file-name)))
1817 (let (file tofile delete-files movemail popmail got-password password)
1819 ;; Handle remote mailbox names specially; don't expand as filenames
1820 ;; in case the userid contains a directory separator.
1821 (setq file (car files))
1822 (let ((url-data (pmail-parse-url file)))
1823 (setq file (nth 0 url-data))
1824 (setq popmail (nth 1 url-data))
1825 (setq password (nth 2 url-data))
1826 (setq got-password (nth 3 url-data)))
1830 (setq file (file-truename
1831 (substitute-in-file-name (expand-file-name file)))))
1832 (setq tofile (expand-file-name
1833 ;; Generate name to move to from inbox name,
1834 ;; in case of multiple inboxes that need moving.
1836 (file-name-nondirectory
1837 (if (memq system-type '(windows-nt cygwin ms-dos))
1838 ;; cannot have colons in file name
1839 (replace-regexp-in-string ":" "-" file)
1841 ;; Use the directory of this pmail file
1842 ;; because it's a nuisance to use the homedir
1843 ;; if that is on a full disk and this pmail
1845 (file-name-directory
1846 (expand-file-name buffer-file-name))))
1847 ;; Always use movemail to rename the file,
1848 ;; since there can be mailboxes in various directories.
1850 ;; On some systems, /usr/spool/mail/foo is a directory
1851 ;; and the actual inbox is /usr/spool/mail/foo/foo.
1852 (if (file-directory-p file)
1853 (setq file (expand-file-name (user-login-name)
1856 (message "Getting mail from the remote server ..."))
1857 ((and (file-exists-p tofile)
1858 (/= 0 (nth 7 (file-attributes tofile))))
1859 (message "Getting mail from %s..." tofile))
1860 ((and (file-exists-p file)
1861 (/= 0 (nth 7 (file-attributes file))))
1862 (message "Getting mail from %s..." file)))
1863 ;; Set TOFILE if have not already done so, and
1864 ;; rename or copy the file FILE to TOFILE if and as appropriate.
1865 (cond ((not renamep)
1867 ((or (file-exists-p tofile) (and (not popmail)
1868 (not (file-exists-p file))))
1872 (let ((errors (current-buffer)))
1873 (buffer-disable-undo errors)
1876 (list (or pmail-movemail-program "movemail") nil errors nil)
1877 (if pmail-preserve-inbox
1880 (if (pmail-movemail-variant-p 'mailutils)
1881 (append (list "--emacs") pmail-movemail-flags)
1882 pmail-movemail-flags)
1884 (if password (list password) nil))))
1885 (apply 'call-process args))
1886 (if (not (buffer-modified-p errors))
1887 ;; No output => movemail won
1890 (subst-char-in-region (point-min) (point-max)
1892 (goto-char (point-max))
1893 (skip-chars-backward " \t")
1894 (delete-region (point) (point-max))
1895 (goto-char (point-min))
1896 (if (looking-at "movemail: ")
1897 (delete-region (point-min) (match-end 0)))
1899 ;; If we just read the password, most likely it is
1900 ;; wrong. Otherwise, see if there is a specific
1901 ;; reason to think that the problem is a wrong passwd.
1902 (if (or got-password
1903 (re-search-forward pmail-remote-password-error
1905 (pmail-set-remote-password nil))
1907 ;; If using Mailutils, remove initial error code
1909 (when (pmail-movemail-variant-p 'mailutils)
1910 (goto-char (point-min))
1911 (when (looking-at "[A-Z][A-Z0-9_]*:")
1912 (delete-region (point-min) (match-end 0))))
1914 (message "movemail: %s"
1915 (buffer-substring (point-min)
1921 ;; At this point, TOFILE contains the name to read:
1922 ;; Either the alternate name (if we renamed)
1923 ;; or the actual inbox (if not renaming).
1924 (if (file-exists-p tofile)
1925 (let ((coding-system-for-read 'no-conversion)
1927 (goto-char (point-max))
1928 (setq size (nth 1 (insert-file-contents tofile)))
1929 ;; Determine if a pair of newline message separators need
1930 ;; to be added to the new collection of messages. This is
1931 ;; the case for all new message collections added to a
1932 ;; non-empty mail file.
1933 (unless (zerop size)
1935 (let ((start (point-min)))
1937 (unless (eq start (point-min))
1940 (setq size (+ 2 size))))))
1941 (goto-char (point-max))
1942 (or (= (preceding-char) ?\n)
1945 (if (not (and pmail-preserve-inbox (string= file tofile)))
1946 (setq delete-files (cons tofile delete-files)))))
1948 (setq files (cdr files)))
1951 ;; Decode the region specified by FROM and TO by CODING.
1952 ;; If CODING is nil or an invalid coding system, decode by `undecided'.
1953 (defun pmail-decode-region (from to coding &optional destination)
1954 (if (or (not coding) (not (coding-system-p coding)))
1955 (setq coding 'undecided))
1956 ;; Use -dos decoding, to remove ^M characters left from base64 or
1957 ;; rogue qp-encoded text.
1958 (decode-coding-region
1959 from to (coding-system-change-eol-conversion coding 1) destination)
1960 ;; Don't reveal the fact we used -dos decoding, as users generally
1961 ;; will not expect the PMAIL buffer to use DOS EOL format.
1962 (setq buffer-file-coding-system
1963 (setq last-coding-system-used
1964 (coding-system-change-eol-conversion coding 0))))
1966 (defun pmail-add-mbox-headers ()
1967 "Validate the RFC2822 format for the new messages.
1968 Point should be at the first new message.
1969 An error is signalled if the new messages are not RFC2822
1971 Unless an Rmail attribute header already exists, add it to the
1972 new messages. Return the number of new messages."
1979 ;; Detect an empty inbox file.
1980 (unless (= start (point-max))
1981 ;; Scan the new messages to establish a count and to insure that
1982 ;; an attribute header is present.
1983 (while (looking-at "From ")
1984 ;; Determine if a new attribute header needs to be added to
1986 (if (search-forward "\n\n" nil t)
1988 (setq count (1+ count))
1989 (narrow-to-region start (point))
1990 (unless (mail-fetch-field pmail-attribute-header)
1992 (insert pmail-attribute-header ": " value "\n"))
1994 (pmail-error-bad-format))
1995 ;; Move to the next message.
1996 (if (search-forward "\n\nFrom " nil 'move)
1998 (setq start (point))))
2001 (defun pmail-get-header (name &optional msgnum)
2002 "Return the value of message header NAME, nil if it has none.
2003 MSGNUM specifies the message number to get it from.
2004 If MSGNUM is nil, use the current message."
2005 (with-current-buffer pmail-buffer
2006 (or msgnum (setq msgnum pmail-current-message))
2009 (setq msgbeg (pmail-msgbeg msgnum))
2010 ;; All access to the buffer's local variables is now finished...
2012 ;; ... so it is ok to go to a different buffer.
2013 (if (pmail-buffers-swapped-p) (set-buffer pmail-view-buffer))
2018 (setq end (search-forward "\n\n" nil t))
2021 (narrow-to-region msgbeg end)
2022 (mail-fetch-field name))
2023 (pmail-error-bad-format msgnum)))))))))
2025 (defun pmail-set-header (name &optional msgnum value)
2026 "Store VALUE in message header NAME, nil if it has none.
2027 MSGNUM specifies the message number to operate on.
2028 If MSGNUM is nil, use the current message."
2029 (with-current-buffer pmail-buffer
2030 (or msgnum (setq msgnum pmail-current-message))
2033 (setq msgbeg (pmail-msgbeg msgnum))
2034 ;; All access to the buffer's local variables is now finished...
2036 ;; ... so it is ok to go to a different buffer.
2037 (if (pmail-buffers-swapped-p) (set-buffer pmail-view-buffer))
2042 (setq end (search-forward "\n\n" nil t))
2043 (if end (setq end (1- end)))
2046 (narrow-to-region msgbeg end)
2048 (if (re-search-forward (concat "^"
2053 (delete-region (point) (line-end-position))
2056 (insert name ": " value "\n")))
2057 (pmail-error-bad-format msgnum)))))))))
2059 ;;;; *** Pmail Attributes and Keywords ***
2061 (defun pmail-get-attr-names (&optional msg)
2062 "Return the message attributes in a comma separated string.
2063 MSG specifies the message number to get it from.
2064 If MSG is nil, use the current message."
2065 (let ((value (pmail-get-header pmail-attribute-header msg))
2067 (dotimes (index (length value))
2068 (setq temp (and (not (= ?- (aref value index)))
2069 (nth 1 (aref pmail-attr-array index)))
2072 ((and temp result) (format "%s, %s" result temp))
2077 (defun pmail-get-keywords (&optional msg)
2078 "Return the message keywords in a comma separated string.
2079 MSG, if non-nil, identifies the message number to use.
2080 If nil, that means the current message."
2081 (pmail-get-header pmail-keyword-header msg))
2083 (defun pmail-get-labels (&optional msg)
2084 "Return a string with the labels (attributes and keywords) of msg MSG.
2085 It is put in comma-separated form.
2086 MSG, if non-nil, identifies the message number to use.
2087 If nil, that means the current message."
2088 (let (blurb attr-names keywords)
2089 ;; Combine the message attributes and keywords
2090 ;; into a comma-separated list.
2091 (setq attr-names (pmail-get-attr-names pmail-current-message)
2092 keywords (pmail-get-keywords pmail-current-message))
2093 (if (string= keywords "")
2094 (setq keywords nil))
2096 ((and attr-names keywords) (concat " " attr-names ", " keywords))
2097 (attr-names (concat " " attr-names))
2098 (keywords (concat " " keywords))
2101 (defun pmail-display-labels ()
2102 "Update the current messages's attributes and keywords in mode line."
2103 (let ((blurb (pmail-get-labels)))
2104 (setq mode-line-process
2106 pmail-current-message pmail-total-messages blurb))
2107 ;; If pmail-enable-mime is non-nil, we may have to update
2108 ;; `mode-line-process' of pmail-view-buffer too.
2109 (if (and pmail-enable-mime
2110 (not (eq (current-buffer) pmail-view-buffer))
2111 (buffer-live-p pmail-view-buffer))
2112 (let ((mlp mode-line-process))
2113 (with-current-buffer pmail-view-buffer
2114 (setq mode-line-process mlp))))))
2116 (defun pmail-get-attr-value (attr state)
2117 "Return the character value for ATTR.
2118 ATTR is a (numeric) index, an offset into the mbox attribute
2119 header value. STATE is one of nil, t, or a character value."
2121 ((numberp state) state)
2123 (t (nth 0 (aref pmail-attr-array attr)))))
2125 (defun pmail-set-attribute (attr state &optional msgnum)
2126 "Turn an attribute of a message on or off according to STATE.
2127 STATE is either nil or the character (numeric) value associated
2128 with the state (nil represents off and non-nil represents on).
2129 ATTR is the index of the attribute. MSGNUM is message number to
2130 change; nil means current message."
2131 (with-current-buffer pmail-buffer
2132 (let ((value (pmail-get-attr-value attr state))
2133 (inhibit-read-only t)
2137 (or msgnum (setq msgnum pmail-current-message))
2139 ;; The "deleted" attribute is also stored in a special vector
2140 ;; so update that too.
2141 (if (= attr pmail-deleted-attr-index)
2142 (pmail-set-message-deleted-p msgnum state))
2143 (setq msgbeg (pmail-msgbeg msgnum))
2145 ;; All access to the buffer's local variables is now finished...
2148 ;; ... so it is ok to go to a different buffer.
2149 (if (pmail-buffers-swapped-p) (set-buffer pmail-view-buffer))
2153 ;; Determine if the current state is the desired state.
2156 (setq limit (search-forward "\n\n" nil t)))
2157 (if (search-forward (concat pmail-attribute-header ": ") limit t)
2158 ;; If this message already records attributes,
2159 ;; just change the value for this one.
2160 (let ((missing (- (+ (point) attr) (line-end-position))))
2161 ;; Position point at this attribute,
2162 ;; adding attributes if necessary.
2166 (insert-char ?- missing)
2168 (forward-char attr))
2169 ;; Change this attribute.
2170 (when (/= value (char-after))
2174 ;; Otherwise add a header line to record the attributes
2175 ;; and set all but this one to no.
2176 (let ((header-value "--------"))
2177 (aset header-value attr value)
2178 (goto-char (if limit (- limit 1) (point-max)))
2179 (setq altered (/= value ?-))
2180 (insert pmail-attribute-header ": " header-value "\n"))))))
2181 (if (= msgnum pmail-current-message)
2182 (pmail-display-labels))))
2183 ;; If we made a significant change in an attribute,
2184 ;; mark pmail-buffer modified, so it will be (1) saved
2185 ;; and (2) displayed in the mode line.
2187 (set-buffer-modified-p t)))))
2189 (defun pmail-message-attr-p (msg attrs)
2190 "Return t if the attributes header for message MSG matches regexp ATTRS.
2191 This function assumes the Pmail buffer is unswapped."
2194 (let ((start (pmail-msgbeg msg))
2198 (setq limit (search-forward "\n\n" (pmail-msgend msg) t))
2201 (search-forward (concat pmail-attribute-header ": ") limit t)
2202 (looking-at attrs))))))
2204 (defun pmail-message-unseen-p (msgnum)
2205 "Test the unseen attribute for message MSGNUM.
2206 Return non-nil if the unseen attribute is set, nil otherwise."
2207 (pmail-message-attr-p msgnum "......U"))
2209 ;;;; *** Pmail Message Selection And Support ***
2211 (defun pmail-msgend (n)
2212 (marker-position (aref pmail-message-vector (1+ n))))
2214 (defun pmail-msgbeg (n)
2215 (marker-position (aref pmail-message-vector n)))
2217 (defun pmail-apply-in-message (msgnum function &rest args)
2218 "Call FUNCTION on ARGS while narrowed to message MSGNUM.
2219 Point is at the start of the message.
2220 This returns what the call to FUNCTION returns.
2221 If MSGNUM is nil, use the current message."
2222 (with-current-buffer pmail-buffer
2223 (or msgnum (setq msgnum pmail-current-message))
2225 (let (msgbeg msgend)
2226 (setq msgbeg (pmail-msgbeg msgnum))
2227 (setq msgend (pmail-msgend msgnum))
2228 ;; All access to the pmail-buffer's local variables is now finished...
2230 ;; ... so it is ok to go to a different buffer.
2231 (if (pmail-buffers-swapped-p) (set-buffer pmail-view-buffer))
2237 (narrow-to-region msgbeg msgend)
2238 (apply function args)))))))))
2240 (defun pmail-widen-to-current-msgbeg (function)
2241 "Call FUNCTION with point at start of internal data of current message.
2242 Assumes that bounds were previously narrowed to display the message in Pmail.
2243 The bounds are widened enough to move point where desired, then narrowed
2246 FUNCTION may not change the visible text of the message, but it may
2247 change the invisible header text."
2251 (narrow-to-region (pmail-msgbeg pmail-current-message)
2253 (goto-char (point-min))
2255 ;; Note: we don't use save-restriction because that does not work right
2256 ;; if changes are made outside the saved restriction
2257 ;; before that restriction is restored.
2258 (narrow-to-region (pmail-msgbeg pmail-current-message)
2259 (pmail-msgend pmail-current-message)))))
2261 ;; Manage the message vectors and counters.
2263 (defun pmail-forget-messages ()
2265 (if (vectorp pmail-message-vector)
2267 (v pmail-message-vector)
2270 (move-marker (aref v i) nil)
2272 (setq pmail-message-vector nil)
2273 (setq pmail-msgref-vector nil)
2274 (setq pmail-deleted-vector nil)))
2276 (defun pmail-maybe-set-message-counters ()
2277 (if (not (and pmail-deleted-vector
2278 pmail-message-vector
2279 pmail-current-message
2280 pmail-total-messages))
2281 (pmail-set-message-counters)))
2283 (defun pmail-count-new-messages (&optional nomsg)
2284 "Count the number of new messages.
2285 The buffer should be narrowed to include only the new messages.
2286 Output a helpful message unless NOMSG is non-nil."
2287 (let* ((case-fold-search nil)
2291 (or nomsg (message "Counting new messages..."))
2292 (goto-char (point-max))
2293 ;; Put at the end of messages-head
2294 ;; the entry for message N+1, which marks
2295 ;; the end of message N. (N = number of messages).
2296 (setq messages-head (list (point-marker)))
2297 (pmail-set-message-counters-counter (point-min))
2298 (setq pmail-current-message (1+ pmail-total-messages))
2299 (setq pmail-total-messages
2300 (+ pmail-total-messages total-messages))
2301 (setq pmail-message-vector
2302 (vconcat pmail-message-vector (cdr messages-head)))
2303 (aset pmail-message-vector
2304 pmail-current-message (car messages-head))
2305 (setq pmail-deleted-vector
2306 (concat pmail-deleted-vector deleted-head))
2307 (setq pmail-summary-vector
2308 (vconcat pmail-summary-vector (make-vector total-messages nil)))
2309 (setq pmail-msgref-vector
2310 (vconcat pmail-msgref-vector (make-vector total-messages nil)))
2311 ;; Fill in the new elements of pmail-msgref-vector.
2312 (let ((i (1+ (- pmail-total-messages total-messages))))
2313 (while (<= i pmail-total-messages)
2314 (aset pmail-msgref-vector i (list i))
2316 (goto-char (point-min))
2317 (or nomsg (message "Counting new messages...done (%d)" total-messages))))
2319 (defun pmail-set-message-counters ()
2320 (pmail-forget-messages)
2324 (let* ((point-save (point))
2326 (messages-after-point)
2327 (case-fold-search nil)
2330 ;; Determine how many messages follow point.
2331 (message "Counting messages...")
2332 (goto-char (point-max))
2333 ;; Put at the end of messages-head
2334 ;; the entry for message N+1, which marks
2335 ;; the end of message N. (N = number of messages).
2336 (setq messages-head (list (point-marker)))
2337 (pmail-set-message-counters-counter (min (point) point-save))
2338 (setq messages-after-point total-messages)
2340 ;; Determine how many precede point.
2341 (pmail-set-message-counters-counter)
2342 (setq pmail-total-messages total-messages)
2343 (setq pmail-current-message
2345 (max 1 (- total-messages messages-after-point))))
2346 (setq pmail-message-vector
2347 (apply 'vector (cons (point-min-marker) messages-head))
2348 pmail-deleted-vector (concat "0" deleted-head)
2349 pmail-summary-vector (make-vector pmail-total-messages nil)
2350 pmail-msgref-vector (make-vector (1+ pmail-total-messages) nil))
2352 (while (<= i pmail-total-messages)
2353 (aset pmail-msgref-vector i (list i))
2355 (message "Counting messages...done")))))
2358 (defsubst pmail-collect-deleted (message-end)
2359 "Collect the message deletion flags for each message.
2360 MESSAGE-END is the buffer position corresponding to the end of
2361 the message. Point is at the beginning of the message."
2362 ;; NOTE: This piece of code will be executed on a per-message basis.
2363 ;; In the face of thousands of messages, it has to be as fast as
2364 ;; possible, hence some brute force constant use is employed in
2365 ;; addition to inlining.
2368 (cons (if (and (search-forward (concat pmail-attribute-header ": ") message-end t)
2371 ?\ ) deleted-head))))
2373 (defun pmail-set-message-counters-counter (&optional stop)
2374 ;; Collect the start position for each message into 'messages-head.
2375 (let ((start (point)))
2376 (while (search-backward "\n\nFrom " stop t)
2378 (pmail-collect-deleted start)
2379 (setq messages-head (cons (point-marker) messages-head)
2380 total-messages (1+ total-messages)
2382 ;; Show progress after every 20 messages or so.
2383 (if (zerop (% total-messages 20))
2384 (message "Counting messages...%d" total-messages)))
2385 ;; Handle the first message, maybe.
2388 (goto-char (point-min)))
2389 (unless (not (looking-at "From "))
2390 (pmail-collect-deleted start)
2391 (setq messages-head (cons (point-marker) messages-head)
2392 total-messages (1+ total-messages)))))
2394 ;; Display a message.
2396 ;;;; *** Pmail Message Formatting and Header Manipulation ***
2398 (defun pmail-toggle-header (&optional arg)
2399 "Show original message header if pruned header currently shown, or vice versa.
2400 With argument ARG, show the message header pruned if ARG is greater than zero;
2401 otherwise, show it in full."
2403 (setq pmail-header-style
2405 ((and (numberp arg) (> arg 0)) 'normal)
2406 ((eq pmail-header-style 'full) 'normal)
2408 (pmail-show-message-maybe))
2410 (defun pmail-beginning-of-message ()
2411 "Show current message starting from the beginning."
2413 (let ((pmail-show-message-hook
2414 (list (function (lambda ()
2415 (goto-char (point-min)))))))
2416 (pmail-show-message-maybe pmail-current-message)))
2418 (defun pmail-end-of-message ()
2419 "Show bottom of current message."
2421 (let ((pmail-show-message-hook
2422 (list (function (lambda ()
2423 (goto-char (point-max))
2424 (recenter (1- (window-height))))))))
2425 (pmail-show-message-maybe pmail-current-message)))
2427 (defun pmail-unknown-mail-followup-to ()
2428 "Handle a \"Mail-Followup-To\" header field with an unknown mailing list.
2429 Ask the user whether to add that list name to `mail-mailing-lists'."
2431 (let ((mail-followup-to (mail-fetch-field "mail-followup-to" nil t)))
2432 (when mail-followup-to
2435 (mail-strip-quoted-names mail-followup-to)
2436 ",[[:space:]]+" t)))
2437 (dolist (addr addresses)
2438 (when (and (not (member addr mail-mailing-lists))
2440 ;; taken from pmailsum.el
2442 (or pmail-user-mail-address-regexp
2444 (regexp-quote (user-login-name))
2447 (or user-mail-address
2448 (concat (user-login-name) "@"
2449 (or mail-host-address
2454 (format "Add `%s' to `mail-mailing-lists'? "
2456 (customize-save-variable 'mail-mailing-lists
2457 (cons addr mail-mailing-lists)))))))))
2459 (defun pmail-widen ()
2460 "Display the entire mailbox file."
2462 (pmail-swap-buffers-maybe)
2465 (defun pmail-show-message-maybe (&optional n no-summary)
2466 "Show message number N (prefix argument), counting from start of file.
2467 If summary buffer is currently displayed, update current message there also."
2469 (or (eq major-mode 'pmail-mode)
2470 (switch-to-buffer pmail-buffer))
2471 (pmail-swap-buffers-maybe)
2472 (pmail-maybe-set-message-counters)
2474 (let ((msgnum (or n pmail-current-message))
2476 (if (zerop pmail-total-messages)
2478 (with-current-buffer pmail-view-buffer
2480 (setq blurb "No mail.")))
2481 (setq blurb (pmail-show-message msgnum))
2482 (when mail-mailing-lists
2483 (pmail-unknown-mail-followup-to))
2484 (if transient-mark-mode (deactivate-mark))
2485 ;; If there is a summary buffer, try to move to this message
2486 ;; in that buffer. But don't complain if this message
2487 ;; is not mentioned in the summary.
2488 ;; Don't do this at all if we were called on behalf
2489 ;; of cursor motion in the summary buffer.
2490 (and (pmail-summary-exists) (not no-summary)
2491 (let ((curr-msg pmail-current-message))
2492 (pmail-select-summary
2493 (pmail-summary-goto-msg curr-msg t t))))
2494 (with-current-buffer pmail-buffer
2499 (defun pmail-is-text-p ()
2500 "Return t if the region contains a text message, nil otherwise."
2502 (let ((text-regexp "\\(text\\|message\\)/")
2503 (content-type-header (mail-fetch-field "content-type")))
2504 ;; The message is text if either there is no content type header
2505 ;; (a default of "text/plain; charset=US-ASCII" is assumed) or
2506 ;; the base content type is either text or message.
2507 (or (not content-type-header)
2508 (string-match text-regexp content-type-header)))))
2510 (defun pmail-show-message (&optional msg)
2511 "Show message MSG using a special view buffer.
2512 Return text to display in the minibuffer if MSG is out of
2513 range (displaying a reasonable choice as well), nil otherwise.
2514 The current mail message becomes the message displayed."
2515 (let ((mbox-buf pmail-buffer)
2516 (view-buf pmail-view-buffer)
2517 blurb beg end body-start coding-system character-coding is-text-message)
2519 (setq msg pmail-current-message))
2522 pmail-current-message 1
2523 blurb "No previous message"))
2524 ((> msg pmail-total-messages)
2525 (setq msg pmail-total-messages
2526 pmail-current-message pmail-total-messages
2527 blurb "No following message"))
2528 (t (setq pmail-current-message msg)))
2529 (with-current-buffer pmail-buffer
2530 ;; Mark the message as seen, bracket the message in the mail
2531 ;; buffer and determine the coding system the transfer encoding.
2532 (pmail-set-attribute pmail-unseen-attr-index nil)
2533 (pmail-swap-buffers-maybe)
2534 (setq beg (pmail-msgbeg msg)
2535 end (pmail-msgend msg))
2536 (narrow-to-region beg end)
2538 (setq body-start (search-forward "\n\n" nil t))
2539 (narrow-to-region beg (point))
2541 (setq character-coding (mail-fetch-field "content-transfer-encoding")
2542 is-text-message (pmail-is-text-p)
2543 coding-system (pmail-get-coding-system))
2544 (if character-coding
2545 (setq character-coding (downcase character-coding)))
2546 (narrow-to-region beg end)
2547 ;; Decode the message body into an empty view buffer using a
2548 ;; unibyte temporary buffer where the character decoding takes
2550 (with-current-buffer pmail-view-buffer
2552 (if (null character-coding)
2553 ;; Do it directly since that is fast.
2554 (pmail-decode-region body-start end coding-system view-buf)
2555 ;; Can this be done directly, skipping the temp buffer?
2557 (set-buffer-multibyte nil)
2558 (insert-buffer-substring mbox-buf body-start end)
2560 ((string= character-coding "quoted-printable")
2561 (mail-unquote-printable-region (point-min) (point-max)))
2562 ((and (string= character-coding "base64") is-text-message)
2563 (base64-decode-region (point-min) (point-max)))
2564 ((eq character-coding 'uuencode)
2565 (error "Not supported yet"))
2567 (pmail-decode-region (point-min) (point-max)
2568 coding-system view-buf)))
2569 ;; Copy the headers to the front of the message view buffer.
2570 (with-current-buffer pmail-view-buffer
2571 (goto-char (point-min)))
2572 (pmail-copy-headers beg end)
2573 ;; Add the separator (blank line) between headers and body;
2574 ;; highlight the message, activate any URL like text and add
2575 ;; special highlighting for and quoted material.
2576 (with-current-buffer pmail-view-buffer
2578 (goto-char (point-min))
2579 (pmail-highlight-headers)
2580 ;(pmail-activate-urls)
2581 ;(pmail-process-quoted-material)
2583 ;; Update the mode-line with message status information and swap
2584 ;; the view buffer/mail buffer contents.
2585 (pmail-display-labels)
2586 (let ((modp (buffer-modified-p)))
2587 (buffer-swap-text pmail-view-buffer)
2588 (set-buffer-modified-p modp))
2589 (setq buffer-swapped-with pmail-view-buffer)
2590 (run-hooks 'pmail-show-message-hook))
2593 (defun pmail-copy-headers (beg end &optional ignored-headers)
2594 "Copy displayed header fields to the message viewer buffer.
2595 BEG and END marks the start and end positions of the message in
2596 the mbox buffer. If the optional argument IGNORED-HEADERS is
2597 non-nil, ignore all header fields whose names match that regexp.
2598 Otherwise, if `rmail-displayed-headers' is non-nil, copy only
2599 those header fields whose names match that regexp. Otherwise,
2600 copy all header fields whose names do not match
2601 `rmail-ignored-headers' (unless they also match
2602 `rmail-nonignored-headers')."
2603 (let ((header-start-regexp "\n[^ \t]")
2605 (with-current-buffer pmail-buffer
2606 (when (search-forward "\n\n" nil t)
2609 ;; Put point right after the From header line.
2610 (narrow-to-region beg (point))
2611 (goto-char (point-min))
2612 (unless (re-search-forward header-start-regexp nil t)
2613 (pmail-error-bad-format))
2616 ;; Handle the case where all headers should be copied.
2617 ((eq pmail-header-style 'full)
2618 (prepend-to-buffer pmail-view-buffer beg (point-max)))
2619 ;; Handle the case where the headers matching the diplayed
2620 ;; headers regexp should be copied.
2621 ((and pmail-displayed-headers (null ignored-headers))
2624 (setq lim (if (re-search-forward header-start-regexp nil t)
2625 (1+ (match-beginning 0))
2627 (when (looking-at pmail-displayed-headers)
2628 (append-to-buffer pmail-view-buffer (point) lim))
2630 ;; Handle the ignored headers.
2631 ((or ignored-headers (setq ignored-headers pmail-ignored-headers))
2632 (while (and ignored-headers (not (eobp)))
2634 (setq lim (if (re-search-forward header-start-regexp nil t)
2635 (1+ (match-beginning 0))
2637 (if (and (looking-at ignored-headers)
2638 (not (looking-at pmail-nonignored-headers)))
2640 (append-to-buffer pmail-view-buffer (point) lim)
2642 (t (error "No headers selected for display!"))))))))
2644 ;; Find all occurrences of certain fields, and highlight them.
2645 (defun pmail-highlight-headers ()
2646 ;; Do this only if the system supports faces.
2647 (if (and (fboundp 'internal-find-face)
2648 pmail-highlighted-headers)
2650 (search-forward "\n\n" nil 'move)
2652 (narrow-to-region (point-min) (point))
2653 (let ((case-fold-search t)
2654 (inhibit-read-only t)
2655 ;; Highlight with boldface if that is available.
2656 ;; Otherwise use the `highlight' face.
2657 (face (or 'pmail-highlight
2658 (if (face-differs-from-default-p 'bold)
2660 ;; List of overlays to reuse.
2661 (overlays pmail-overlay-list))
2662 (goto-char (point-min))
2663 (while (re-search-forward pmail-highlighted-headers nil t)
2664 (skip-chars-forward " \t")
2667 (while (progn (forward-line 1)
2668 (looking-at "[ \t]")))
2669 ;; Back up over newline, then trailing spaces or tabs
2671 (while (member (preceding-char) '(? ?\t))
2674 ;; Reuse an overlay we already have.
2676 (setq overlay (car overlays)
2677 overlays (cdr overlays))
2678 (overlay-put overlay 'face face)
2679 (move-overlay overlay beg (point)))
2680 ;; Make a new overlay and add it to
2681 ;; pmail-overlay-list.
2682 (setq overlay (make-overlay beg (point)))
2683 (overlay-put overlay 'face face)
2684 (setq pmail-overlay-list
2685 (cons overlay pmail-overlay-list))))))))))
2687 (defun pmail-auto-file ()
2688 "Automatically move a message into a sub-folder based on criteria.
2689 Called when a new message is displayed."
2690 (if (or (zerop pmail-total-messages)
2691 (pmail-message-attr-p pmail-current-message "...F...")
2692 (not (string= (buffer-file-name)
2693 (expand-file-name pmail-file-name))))
2694 ;; Do nothing if the message has already been filed or if there
2697 ;; Find out some basics (common fields)
2698 (let ((from (mail-fetch-field "from"))
2699 (subj (mail-fetch-field "subject"))
2700 (to (concat (mail-fetch-field "to") "," (mail-fetch-field "cc")))
2701 (d pmail-automatic-folder-directives)
2702 (directive-loop nil)
2705 (setq folder (car (car d))
2706 directive-loop (cdr (car d)))
2707 (while (and (car directive-loop)
2709 ((string= (car directive-loop) "from") from)
2710 ((string= (car directive-loop) "to") to)
2711 ((string= (car directive-loop) "subject") subj)
2712 (t (mail-fetch-field (car directive-loop))))))
2713 (and f (string-match (car (cdr directive-loop)) f))))
2714 (setq directive-loop (cdr (cdr directive-loop))))
2715 ;; If there are no directives left, then it was a complete match.
2716 (if (null directive-loop)
2718 (pmail-delete-forward)
2719 (if (string= "/dev/null" folder)
2720 (pmail-delete-message)
2721 (pmail-output folder 1 t)
2723 (setq d (cdr d))))))
2725 ;; Simple message motion commands.
2727 (defun pmail-next-message (n)
2728 "Show following message whether deleted or not.
2729 With prefix arg N, moves forward N messages, or backward if N is negative."
2731 (set-buffer pmail-buffer)
2732 (pmail-maybe-set-message-counters)
2733 (pmail-show-message-maybe (+ pmail-current-message n)))
2735 (defun pmail-previous-message (n)
2736 "Show previous message whether deleted or not.
2737 With prefix arg N, moves backward N messages, or forward if N is negative."
2739 (pmail-next-message (- n)))
2741 (defun pmail-next-undeleted-message (n)
2742 "Show following non-deleted message.
2743 With prefix arg N, moves forward N non-deleted messages,
2744 or backward if N is negative.
2746 Returns t if a new message is being shown, nil otherwise."
2748 (set-buffer pmail-buffer)
2749 (pmail-maybe-set-message-counters)
2750 (let ((lastwin pmail-current-message)
2751 (current pmail-current-message))
2752 (while (and (> n 0) (< current pmail-total-messages))
2753 (setq current (1+ current))
2754 (if (not (pmail-message-deleted-p current))
2755 (setq lastwin current n (1- n))))
2756 (while (and (< n 0) (> current 1))
2757 (setq current (1- current))
2758 (if (not (pmail-message-deleted-p current))
2759 (setq lastwin current n (1+ n))))
2760 (if (/= lastwin pmail-current-message)
2761 (progn (pmail-show-message-maybe lastwin)
2764 (message "No previous nondeleted message"))
2766 (message "No following nondeleted message"))
2769 (defun pmail-previous-undeleted-message (n)
2770 "Show previous non-deleted message.
2771 With prefix argument N, moves backward N non-deleted messages,
2772 or forward if N is negative."
2774 (pmail-next-undeleted-message (- n)))
2776 (defun pmail-first-message ()
2777 "Show first message in file."
2779 (pmail-maybe-set-message-counters)
2780 (pmail-show-message-maybe (< 1 pmail-total-messages)))
2782 (defun pmail-last-message ()
2783 "Show last message in file."
2785 (pmail-maybe-set-message-counters)
2786 (pmail-show-message-maybe pmail-total-messages))
2788 (defun pmail-what-message ()
2789 "For debugging Pmail: find the message number that point is in."
2790 (let ((where (point))
2792 (high pmail-total-messages)
2793 (mid (/ pmail-total-messages 2)))
2794 (while (> (- high low) 1)
2795 (if (>= where (pmail-msgbeg mid))
2798 (setq mid (+ low (/ (- high low) 2))))
2799 (if (>= where (pmail-msgbeg high)) high low)))
2801 ;; Searching in Pmail file.
2803 (defun pmail-search-message (msg regexp)
2804 "Return non-nil, if for message number MSG, regexp REGEXP matches."
2805 ;; This is adequate because its only caller, pmail-search,
2806 ;; unswaps the buffers.
2807 (goto-char (pmail-msgbeg msg))
2808 (if pmail-enable-mime
2809 (funcall pmail-search-mime-message-function msg regexp)
2810 (re-search-forward regexp (pmail-msgend msg) t)))
2812 (defvar pmail-search-last-regexp nil)
2813 (defun pmail-search (regexp &optional n)
2814 "Show message containing next match for REGEXP (but not the current msg).
2815 Prefix argument gives repeat count; negative argument means search
2816 backwards (through earlier messages).
2817 Interactively, empty argument means use same regexp used last time."
2819 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
2821 (concat (if reversep "Reverse " "") "Pmail search (regexp"))
2825 (if pmail-search-last-regexp
2826 (concat ", default "
2827 pmail-search-last-regexp "): ")
2829 (setq regexp (read-string prompt))
2830 (cond ((not (equal regexp ""))
2831 (setq pmail-search-last-regexp regexp))
2832 ((not pmail-search-last-regexp)
2833 (error "No previous Pmail search string")))
2834 (list pmail-search-last-regexp
2835 (prefix-numeric-value current-prefix-arg))))
2837 (message "%sPmail search for %s..."
2838 (if (< n 0) "Reverse " "")
2840 (set-buffer pmail-buffer)
2841 (let ((orig-message pmail-current-message)
2842 (msg pmail-current-message)
2844 (opoint (if (pmail-buffers-swapped-p) (point)))
2846 (pmail-swap-buffers-maybe)
2847 (pmail-maybe-set-message-counters)
2851 ;; Check messages one by one, advancing message number up or
2852 ;; down but searching forward through each message.
2854 (while (and (null found) (> msg 1))
2856 found (pmail-search-message msg regexp)))
2857 (while (and (null found) (< msg pmail-total-messages))
2859 found (pmail-search-message msg regexp))))
2860 (setq n (+ n (if reversep 1 -1))))
2863 (pmail-show-message-maybe msg)
2864 ;; Search forward (if this is a normal search) or backward
2865 ;; (if this is a reverse search) through this message to
2866 ;; position point. This search may fail because REGEXP
2867 ;; was found in the hidden portion of this message. In
2868 ;; that case, move point to the beginning of visible
2872 (goto-char (point-max))
2873 (re-search-backward regexp nil 'move))
2874 (goto-char (point-min))
2875 (re-search-forward regexp nil t))
2876 (message "%sPmail search for %s...done"
2877 (if reversep "Reverse " "")
2879 (pmail-show-message-maybe orig-message)
2880 (if opoint (goto-char opoint))
2882 (message "Search failed: %s" regexp)))))
2884 (defun pmail-search-backwards (regexp &optional n)
2885 "Show message containing previous match for REGEXP.
2886 Prefix argument gives repeat count; negative argument means search
2887 forward (through later messages).
2888 Interactively, empty argument means use same regexp used last time."
2890 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
2892 (concat (if reversep "Reverse " "") "Pmail search (regexp"))
2896 (if pmail-search-last-regexp
2897 (concat ", default "
2898 pmail-search-last-regexp "): ")
2900 (setq regexp (read-string prompt))
2901 (cond ((not (equal regexp ""))
2902 (setq pmail-search-last-regexp regexp))
2903 ((not pmail-search-last-regexp)
2904 (error "No previous Pmail search string")))
2905 (list pmail-search-last-regexp
2906 (prefix-numeric-value current-prefix-arg))))
2907 (pmail-search regexp (- (or n 1))))
2909 ;; Scan for attributes, and compare subjects.
2911 (defun pmail-first-unseen-message ()
2912 "Return message number of first message which has `unseen' attribute."
2913 (pmail-maybe-set-message-counters)
2918 (while (and (not found) (<= current pmail-total-messages))
2919 (if (pmail-message-attr-p current "......U")
2920 (setq found current))
2921 (setq current (1+ current))))
2924 (defun pmail-simplified-subject (&optional msgnum)
2925 "Return the simplified subject of message MSGNUM (or current message).
2926 Simplifying the subject means stripping leading and trailing whitespace,
2927 and typical reply prefixes such as Re:."
2928 (let ((subject (or (pmail-get-header "Subject" msgnum) "")))
2929 (if (string-match "\\`[ \t]+" subject)
2930 (setq subject (substring subject (match-end 0))))
2931 (if (string-match pmail-reply-regexp subject)
2932 (setq subject (substring subject (match-end 0))))
2933 (if (string-match "[ \t]+\\'" subject)
2934 (setq subject (substring subject 0 (match-beginning 0))))
2937 (defun pmail-simplified-subject-regexp ()
2938 "Return a regular expression matching the current simplified subject.
2939 The idea is to match it against simplified subjects of other messages."
2940 (let ((subject (pmail-simplified-subject)))
2941 (setq subject (regexp-quote subject))
2942 ;; Hide commas so it will work ok if parsed as a comma-separated list
2945 (replace-regexp-in-string "," "\054" subject t t))
2946 (concat "\\`" subject "\\'")))
2948 (defun pmail-next-same-subject (n)
2949 "Go to the next mail message having the same subject header.
2950 With prefix argument N, do this N times.
2951 If N is negative, go backwards instead."
2953 (let ((subject (pmail-simplified-subject))
2955 (i pmail-current-message)
2957 (while (and (/= n 0)
2959 (< i pmail-total-messages)
2962 (while (and (not done)
2964 (< i pmail-total-messages)
2966 (setq i (if forward (1+ i) (1- i)))
2967 (setq done (string-equal subject (pmail-simplified-subject i))))
2968 (if done (setq found i)))
2969 (setq n (if forward (1- n) (1+ n))))
2971 (pmail-show-message-maybe found)
2972 (error "No %s message with same subject"
2973 (if forward "following" "previous")))))
2975 (defun pmail-previous-same-subject (n)
2976 "Go to the previous mail message having the same subject header.
2977 With prefix argument N, do this N times.
2978 If N is negative, go forwards instead."
2980 (pmail-next-same-subject (- n)))
2982 ;;;; *** Pmail Message Deletion Commands ***
2984 (defun pmail-message-deleted-p (n)
2985 (= (aref pmail-deleted-vector n) ?D))
2987 (defun pmail-set-message-deleted-p (n state)
2988 (aset pmail-deleted-vector n (if state ?D ?\ )))
2990 (defun pmail-delete-message ()
2991 "Delete this message and stay on it."
2993 (pmail-set-attribute pmail-deleted-attr-index t)
2994 (run-hooks 'pmail-delete-message-hook))
2996 (defun pmail-undelete-previous-message ()
2997 "Back up to deleted message, select it, and undelete it."
2999 (set-buffer pmail-buffer)
3000 (let ((msg pmail-current-message))
3001 (while (and (> msg 0)
3002 (not (pmail-message-deleted-p msg)))
3003 (setq msg (1- msg)))
3005 (error "No previous deleted message")
3006 (if (/= msg pmail-current-message)
3007 (pmail-show-message-maybe msg))
3008 (pmail-set-attribute pmail-deleted-attr-index nil)
3009 (if (pmail-summary-exists)
3011 (set-buffer pmail-summary-buffer)
3012 (pmail-summary-mark-undeleted msg)))
3013 (pmail-maybe-display-summary))))
3015 (defun pmail-delete-forward (&optional backward)
3016 "Delete this message and move to next nondeleted one.
3017 Deleted messages stay in the file until the \\[pmail-expunge] command is given.
3018 With prefix argument, delete and move backward.
3020 Returns t if a new message is displayed after the delete, or nil otherwise."
3022 (pmail-set-attribute pmail-deleted-attr-index t)
3023 (run-hooks 'pmail-delete-message-hook)
3024 (let ((del-msg pmail-current-message))
3025 (if (pmail-summary-exists)
3026 (pmail-select-summary
3027 (pmail-summary-mark-deleted del-msg)))
3028 (prog1 (pmail-next-undeleted-message (if backward -1 1))
3029 (pmail-maybe-display-summary))))
3031 (defun pmail-delete-backward ()
3032 "Delete this message and move to previous nondeleted one.
3033 Deleted messages stay in the file until the \\[pmail-expunge] command is given."
3035 (pmail-delete-forward t))
3039 ;; Compute the message number a given message would have after expunging.
3040 ;; The present number of the message is OLDNUM.
3041 ;; DELETEDVEC should be pmail-deleted-vector.
3042 ;; The value is nil for a message that would be deleted.
3043 (defun pmail-msg-number-after-expunge (deletedvec oldnum)
3044 (if (or (null oldnum) (= (aref deletedvec oldnum) ?D))
3049 (if (/= (aref deletedvec i) ?D)
3050 (setq newnum (1+ newnum)))
3054 (defun pmail-expunge-confirmed ()
3055 "Return t if deleted message should be expunged. If necessary, ask the user.
3056 See also user-option `pmail-confirm-expunge'."
3057 (set-buffer pmail-buffer)
3058 (or (not (stringp pmail-deleted-vector))
3059 (not (string-match "D" pmail-deleted-vector))
3060 (null pmail-confirm-expunge)
3061 (funcall pmail-confirm-expunge
3062 "Erase deleted messages from Pmail file? ")))
3064 (defun pmail-only-expunge (&optional dont-show)
3065 "Actually erase all deleted messages in the file."
3067 (pmail-swap-buffers-maybe)
3068 (set-buffer pmail-buffer)
3069 (message "Expunging deleted messages...")
3070 ;; Discard all undo records for this buffer.
3071 (or (eq buffer-undo-list t)
3072 (setq buffer-undo-list nil))
3073 (pmail-maybe-set-message-counters)
3074 (let* ((omax (- (buffer-size) (point-max)))
3075 (omin (- (buffer-size) (point-min)))
3076 (opoint (if (and (> pmail-current-message 0)
3077 (pmail-message-deleted-p pmail-current-message))
3079 (if pmail-enable-mime
3080 (with-current-buffer pmail-view-buffer
3081 (- (point)(point-min)))
3082 (- (point) (point-min)))))
3083 (messages-head (cons (aref pmail-message-vector 0) nil))
3084 (messages-tail messages-head)
3085 ;; Don't make any undo records for the expunging.
3086 (buffer-undo-list t)
3091 (goto-char (point-min))
3095 (new-msgref (list (list 0)))
3096 (buffer-read-only nil)
3097 (total pmail-total-messages)
3098 (new-message-number pmail-current-message)
3099 (messages pmail-message-vector)
3100 (deleted pmail-deleted-vector)
3101 (summary pmail-summary-vector))
3102 (setq pmail-total-messages nil
3103 pmail-current-message nil
3104 pmail-message-vector nil
3105 pmail-deleted-vector nil
3106 pmail-summary-vector nil)
3108 (while (<= number total)
3109 (if (= (aref deleted number) ?D)
3111 (delete-region (aref messages number)
3112 (aref messages (1+ number)))
3113 (move-marker (aref messages number) nil)
3114 (if (> new-message-number counter)
3115 (setq new-message-number (1- new-message-number))))
3116 (setq counter (1+ counter))
3118 (setcdr messages-tail
3119 (cons (aref messages number) nil)))
3121 (cons (if (= counter number) (aref summary (1- number)))
3124 (cons (aref pmail-msgref-vector number)
3126 (setcar (car new-msgref) counter))
3127 (if (zerop (% (setq number (1+ number)) 20))
3128 (message "Expunging deleted messages...%d" number)))
3130 (setcdr messages-tail
3131 (cons (aref messages number) nil)))
3132 (setq pmail-current-message new-message-number
3133 pmail-total-messages counter
3134 pmail-message-vector (apply 'vector messages-head)
3135 pmail-deleted-vector (make-string (1+ counter) ?\ )
3136 pmail-summary-vector (vconcat (nreverse new-summary))
3137 pmail-msgref-vector (apply 'vector (nreverse new-msgref))
3139 (message "Expunging deleted messages...done")
3141 (narrow-to-region (- (buffer-size) omin) (- (buffer-size) omax)))
3143 (pmail-show-message-maybe (min pmail-current-message pmail-total-messages)))
3144 (if pmail-enable-mime
3145 (goto-char (+ (point-min) opoint))
3146 (goto-char (+ (point) opoint))))))
3148 (defun pmail-expunge (&optional dont-show)
3149 "Erase deleted messages from Pmail file and summary buffer."
3151 (when (pmail-expunge-confirmed)
3152 (let ((old-total pmail-total-messages)
3153 (opoint (with-current-buffer pmail-buffer
3154 (when (pmail-buffers-swapped-p)
3156 (pmail-only-expunge dont-show)
3157 (if (pmail-summary-exists)
3158 (pmail-select-summary (pmail-update-summary))
3159 (pmail-show-message pmail-current-message)
3160 (if (and (eq old-total pmail-total-messages) opoint)
3161 (goto-char opoint))))))
3163 ;;;; *** Pmail Mailing Commands ***
3165 (defun pmail-start-mail (&optional noerase to subject in-reply-to cc
3166 replybuffer sendactions same-window others)
3169 (setq yank-action (list 'insert-buffer replybuffer)))
3170 (setq others (cons (cons "cc" cc) others))
3171 (setq others (cons (cons "in-reply-to" in-reply-to) others))
3173 (compose-mail to subject others
3175 yank-action sendactions)
3176 (if pmail-mail-new-frame
3178 (compose-mail to subject others
3179 noerase 'switch-to-buffer-other-frame
3180 yank-action sendactions)
3181 ;; This is not a standard frame parameter;
3182 ;; nothing except sendmail.el looks at it.
3183 (modify-frame-parameters (selected-frame)
3184 '((mail-dedicated-frame . t))))
3185 (compose-mail to subject others
3186 noerase 'switch-to-buffer-other-window
3187 yank-action sendactions)))))
3189 (defun pmail-mail ()
3190 "Send mail in another window.
3191 While composing the message, use \\[mail-yank-original] to yank the
3192 original message into it."
3194 (pmail-start-mail nil nil nil nil nil pmail-view-buffer))
3196 (defun pmail-continue ()
3197 "Continue composing outgoing message previously being composed."
3199 (pmail-start-mail t))
3201 (defun pmail-reply (just-sender)
3202 "Reply to the current message.
3203 Normally include CC: to all other recipients of original message;
3204 prefix argument means ignore them. While composing the reply,
3205 use \\[mail-yank-original] to yank the original message into it."
3207 (let (from reply-to cc subject date to message-id references
3208 resent-to resent-cc resent-reply-to
3209 (msgnum pmail-current-message))
3213 (if (pmail-buffers-swapped-p)
3215 (goto-char (point-min))
3216 (search-forward "\n\n" nil 'move))
3217 (goto-char (pmail-msgbeg pmail-current-message))
3221 (search-forward "\n\n"
3222 (pmail-msgend pmail-current-message)
3224 (setq from (mail-fetch-field "from")
3225 reply-to (or (mail-fetch-field "mail-reply-to" nil t)
3226 (mail-fetch-field "reply-to" nil t)
3228 subject (mail-fetch-field "subject")
3229 date (mail-fetch-field "date")
3230 message-id (mail-fetch-field "message-id")
3231 references (mail-fetch-field "references" nil nil t)
3232 resent-reply-to (mail-fetch-field "resent-reply-to" nil t)
3233 resent-cc (and (not just-sender)
3234 (mail-fetch-field "resent-cc" nil t))
3235 resent-to (or (mail-fetch-field "resent-to" nil t) "")
3236 ;;; resent-subject (mail-fetch-field "resent-subject")
3237 ;;; resent-date (mail-fetch-field "resent-date")
3238 ;;; resent-message-id (mail-fetch-field "resent-message-id")
3241 (if (mail-fetch-field "mail-followup-to" nil t)
3242 ;; If this header field is present, use it instead of
3243 ;; the To and CC fields.
3244 (setq to (mail-fetch-field "mail-followup-to" nil t))
3245 (setq cc (or (mail-fetch-field "cc" nil t) "")
3246 to (or (mail-fetch-field "to" nil t) ""))))))
3248 ;; Merge the resent-to and resent-cc into the to and cc.
3249 (if (and resent-to (not (equal resent-to "")))
3250 (if (not (equal to ""))
3251 (setq to (concat to ", " resent-to))
3252 (setq to resent-to)))
3253 (if (and resent-cc (not (equal resent-cc "")))
3254 (if (not (equal cc ""))
3255 (setq cc (concat cc ", " resent-cc))
3256 (setq cc resent-cc)))
3257 ;; Add `Re: ' to subject if not there already.
3258 (and (stringp subject)
3260 (concat pmail-reply-prefix
3261 (if (let ((case-fold-search t))
3262 (string-match pmail-reply-regexp subject))
3263 (substring subject (match-end 0))
3267 ;; Using mail-strip-quoted-names is undesirable with newer mailers
3268 ;; since they can handle the names unstripped.
3269 ;; I don't know whether there are other mailers that still
3270 ;; need the names to be stripped.
3271 ;;; (mail-strip-quoted-names reply-to)
3272 ;; Remove unwanted names from reply-to, since Mail-Followup-To
3273 ;; header causes all the names in it to wind up in reply-to, not
3274 ;; in cc. But if what's left is an empty list, use the original.
3275 (let* ((reply-to-list (rmail-dont-reply-to reply-to)))
3276 (if (string= reply-to-list "") reply-to reply-to-list))
3278 (pmail-make-in-reply-to-field from date message-id)
3281 ;; mail-strip-quoted-names is NOT necessary for pmail-dont-reply-to
3283 (let* ((cc-list (rmail-dont-reply-to
3284 (mail-strip-quoted-names
3285 (if (null cc) to (concat to ", " cc))))))
3286 (if (string= cc-list "") nil cc-list)))
3288 (list (list 'pmail-mark-message
3290 (with-current-buffer pmail-buffer
3291 (aref pmail-msgref-vector msgnum))
3292 pmail-answered-attr-index))
3294 (list (cons "References" (concat (mapconcat 'identity references " ")
3295 " " message-id))))))
3297 (defun pmail-mark-message (buffer msgnum-list attribute)
3298 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3299 This is use in the send-actions for message buffers.
3300 MSGNUM-LIST is a list of the form (MSGNUM)
3301 which is an element of pmail-msgref-vector."
3304 (if (car msgnum-list)
3305 (pmail-set-attribute attribute t (car msgnum-list)))))
3307 (defun pmail-make-in-reply-to-field (from date message-id)
3314 (let ((tem (car (rfc822-addresses from))))
3318 (regexp-quote (if (string-match "@[^@]*\\'" tem)
3320 (match-beginning 0))
3323 ;; missing From, or Message-ID is sufficiently informative
3325 (concat message-id " (" tem ")"))
3326 ;; Copy TEM, discarding text properties.
3327 (setq tem (copy-sequence tem))
3328 (set-text-properties 0 (length tem) nil tem)
3329 (setq tem (copy-sequence tem))
3330 ;; Use prin1 to fake RFC822 quoting
3331 (let ((field (prin1-to-string tem)))
3333 (concat field "'s message of " date)
3335 ((let* ((foo "[^][\000-\037()<>@,;:\\\" ]+")
3336 (bar "[^][\000-\037()<>@,;:\\\"]+"))
3337 ;; These strings both match all non-ASCII characters.
3338 (or (string-match (concat "\\`[ \t]*\\(" bar
3339 "\\)\\(<" foo "@" foo ">\\)?[ \t]*\\'")
3340 ;; "Unix Loser <Foo@bar.edu>" => "Unix Loser"
3342 (string-match (concat "\\`[ \t]*<" foo "@" foo ">[ \t]*(\\("
3343 bar "\\))[ \t]*\\'")
3344 ;; "<Bugs@bar.edu>" (Losing Unix) => "Losing Unix"
3346 (let ((start (match-beginning 1))
3347 (end (match-end 1)))
3348 ;; Trim whitespace which above regexp match allows
3349 (while (and (< start end)
3350 (memq (aref from start) '(?\t ?\ )))
3351 (setq start (1+ start)))
3352 (while (and (< start end)
3353 (memq (aref from (1- end)) '(?\t ?\ )))
3354 (setq end (1- end)))
3355 (let ((field (substring from start end)))
3356 (if date (setq field (concat "message from " field " on " date)))
3358 ;; "<AA259@bar.edu> (message from Unix Loser on 1-Apr-89)"
3359 (concat message-id " (" field ")")
3362 ;; If we can't kludge it simply, do it correctly
3363 (let ((mail-use-rfc822 t))
3364 (pmail-make-in-reply-to-field from date message-id)))))
3366 (defun pmail-forward (resend)
3367 "Forward the current message to another user.
3368 With prefix argument, \"resend\" the message instead of forwarding it;
3369 see the documentation of `pmail-resend'."
3372 (call-interactively 'pmail-resend)
3373 (let ((forward-buffer pmail-buffer)
3374 (msgnum pmail-current-message)
3375 (subject (concat "["
3376 (let ((from (or (mail-fetch-field "From")
3377 (mail-fetch-field ">From"))))
3379 (concat (mail-strip-quoted-names from) ": ")
3381 (or (mail-fetch-field "Subject") "")
3383 (if (pmail-start-mail
3384 nil nil subject nil nil nil
3385 (list (list 'pmail-mark-message
3387 (with-current-buffer pmail-buffer
3388 (aref pmail-msgref-vector msgnum))
3389 pmail-forwarded-attr-index))
3390 ;; If only one window, use it for the mail buffer.
3391 ;; Otherwise, use another window for the mail buffer
3392 ;; so that the Pmail buffer remains visible
3393 ;; and sending the mail will get back to it.
3394 (and (not pmail-mail-new-frame) (one-window-p t)))
3395 ;; The mail buffer is now current.
3397 ;; Insert after header separator--before signature if any.
3398 (goto-char (mail-text-start))
3399 (if (or pmail-enable-mime pmail-enable-mime-composing)
3400 (funcall pmail-insert-mime-forwarded-message-function
3402 (insert "------- Start of forwarded message -------\n")
3403 ;; Quote lines with `- ' if they start with `-'.
3404 (let ((beg (point)) end)
3405 (setq end (point-marker))
3406 (set-marker-insertion-type end t)
3407 (insert-buffer-substring forward-buffer)
3409 (while (re-search-forward "^-" end t)
3414 (skip-chars-backward "\n")
3417 (delete-region (point) end)
3418 (set-marker end nil))
3419 (insert "------- End of forwarded message -------\n"))
3422 (defun pmail-resend (address &optional from comment mail-alias-file)
3423 "Resend current message to ADDRESSES.
3424 ADDRESSES should be a single address, a string consisting of several
3425 addresses separated by commas, or a list of addresses.
3427 Optional FROM is the address to resend the message from, and
3428 defaults from the value of `user-mail-address'.
3429 Optional COMMENT is a string to insert as a comment in the resent message.
3430 Optional ALIAS-FILE is alternate aliases file to be used by sendmail,
3431 typically for purposes of moderating a list."
3432 (interactive "sResend to: ")
3434 (require 'mailalias)
3435 (unless (or (eq pmail-view-buffer (current-buffer))
3436 (eq pmail-buffer (current-buffer)))
3437 (error "Not an Pmail buffer"))
3438 (if (not from) (setq from user-mail-address))
3439 (let ((tembuf (generate-new-buffer " sendmail temp"))
3440 (case-fold-search nil)
3441 (mail-personal-alias-file
3442 (or mail-alias-file mail-personal-alias-file))
3443 (mailbuf pmail-buffer))
3445 (with-current-buffer tembuf
3446 ;;>> Copy message into temp buffer
3447 (if pmail-enable-mime
3448 (funcall pmail-insert-mime-resent-message-function mailbuf)
3449 (insert-buffer-substring mailbuf))
3450 (goto-char (point-min))
3451 ;; Delete any Sender field, since that's not specifiable.
3452 ; Only delete Sender fields in the actual header.
3453 (re-search-forward "^$" nil 'move)
3454 ; Using "while" here rather than "if" because some buggy mail
3455 ; software may have inserted multiple Sender fields.
3456 (while (re-search-backward "^Sender:" nil t)
3460 (while (looking-at "[ \t]")
3462 (delete-region beg (point))))
3463 ; Go back to the beginning of the buffer so the Resent- fields
3464 ; are inserted there.
3465 (goto-char (point-min))
3466 ;;>> Insert resent-from:
3467 (insert "Resent-From: " from "\n")
3468 (insert "Resent-Date: " (mail-rfc822-date) "\n")
3469 ;;>> Insert resent-to: and bcc if need be.
3470 (let ((before (point)))
3472 (insert "Resent-Bcc: " (user-login-name) "\n"))
3473 (insert "Resent-To: " (if (stringp address)
3475 (mapconcat 'identity address ",\n\t"))
3477 ;; Expand abbrevs in the recipients.
3479 (if (featurep 'mailabbrev)
3480 (let ((end (point-marker))
3481 (local-abbrev-table mail-abbrevs)
3482 (old-syntax-table (syntax-table)))
3483 (if (and (not (vectorp mail-abbrevs))
3484 (file-exists-p mail-personal-alias-file))
3485 (build-mail-abbrevs))
3486 (unless mail-abbrev-syntax-table
3487 (mail-abbrev-make-syntax-table))
3488 (set-syntax-table mail-abbrev-syntax-table)
3490 (while (and (< (point) end)
3491 (progn (forward-word 1)
3494 (set-syntax-table old-syntax-table))
3495 (expand-mail-aliases before (point)))))
3496 ;;>> Set up comment, if any.
3497 (if (and (sequencep comment) (not (zerop (length comment))))
3498 (let ((before (point))
3501 (or (eolp) (insert "\n"))
3502 (setq after (point))
3504 (while (< (point) after)
3505 (insert "Resent-Comment: ")
3507 ;; Don't expand aliases in the destination fields
3508 ;; of the original message.
3510 (funcall send-mail-function)))
3511 (kill-buffer tembuf))
3512 (with-current-buffer pmail-buffer
3513 (pmail-set-attribute pmail-resent-attr-index t pmail-current-message))))
3515 (defvar mail-unsent-separator
3516 (concat "^ *---+ +Unsent message follows +---+ *$\\|"
3517 "^ *---+ +Returned message +---+ *$\\|"
3518 "^ *---+ *Returned mail follows *---+ *$\\|"
3519 "^Start of returned message$\\|"
3520 "^---+ Below this line is a copy of the message.$\\|"
3521 "^ *---+ +Original message +---+ *$\\|"
3522 "^ *--+ +begin message +--+ *$\\|"
3523 "^ *---+ +Original message follows +---+ *$\\|"
3524 "^ *---+ +Your message follows +---+ *$\\|"
3525 "^|? *---+ +Message text follows: +---+ *|?$\\|"
3526 "^ *---+ +This is a copy of \\w+ message, including all the headers.*---+ *$")
3527 "A regexp that matches the separator before the text of a failed message.")
3529 (defvar mail-mime-unsent-header "^Content-Type: message/rfc822 *$"
3530 "A regexp that matches the header of a MIME body part with a failed message.")
3532 (defun pmail-retry-failure ()
3533 "Edit a mail message which is based on the contents of the current message.
3534 For a message rejected by the mail system, extract the interesting headers and
3535 the body of the original message.
3536 If the failed message is a MIME multipart message, it is searched for a
3537 body part with a header which matches the variable `mail-mime-unsent-header'.
3538 Otherwise, the variable `mail-unsent-separator' should match the string that
3539 delimits the returned original message.
3540 The variable `pmail-retry-ignored-headers' is a regular expression
3541 specifying headers which should not be copied into the new message."
3543 (require 'mail-utils)
3544 (let ((pmail-this-buffer (current-buffer))
3545 (msgnum pmail-current-message)
3546 bounce-start bounce-end bounce-indent resending
3547 ;; Fetch any content-type header in current message
3548 ;; Must search thru the whole unpruned header.
3552 (mail-fetch-field "Content-Type") ))))
3554 (goto-char (point-min))
3555 (let ((case-fold-search t))
3556 (if (and content-type
3558 ";[\n\t ]*boundary=\"?\\([-0-9a-z'()+_,./:=? ]+\\)\"?"
3560 ;; Handle a MIME multipart bounce message.
3563 (substring content-type (match-beginning 1)
3565 (unless (re-search-forward mail-mime-unsent-header nil t)
3566 (error "Cannot find beginning of header in failed message"))
3567 (unless (search-forward "\n\n" nil t)
3568 (error "Cannot find start of Mime data in failed message"))
3569 (setq bounce-start (point))
3570 (if (search-forward codestring nil t)
3571 (setq bounce-end (match-beginning 0))
3572 (setq bounce-end (point-max))))
3574 (or (re-search-forward mail-unsent-separator nil t)
3575 (error "Cannot parse this as a failure message"))
3576 (skip-chars-forward "\n")
3577 ;; Support a style of failure message in which the original
3578 ;; message is indented, and included within lines saying
3579 ;; `Start of returned message' and `End of returned message'.
3580 (if (looking-at " +Received:")
3582 (setq bounce-start (point))
3583 (skip-chars-forward " ")
3584 (setq bounce-indent (- (current-column)))
3585 (goto-char (point-max))
3586 (re-search-backward "^End of returned message$" nil t)
3587 (setq bounce-end (point)))
3588 ;; One message contained a few random lines before
3589 ;; the old message header. The first line of the
3590 ;; message started with two hyphens. A blank line
3591 ;; followed these random lines. The same line
3592 ;; beginning with two hyphens was possibly marking
3593 ;; the end of the message.
3594 (if (looking-at "^--")
3595 (let ((boundary (buffer-substring-no-properties
3597 (progn (end-of-line) (point)))))
3598 (search-forward "\n\n")
3599 (skip-chars-forward "\n")
3600 (setq bounce-start (point))
3601 (goto-char (point-max))
3602 (search-backward (concat "\n\n" boundary) bounce-start t)
3603 (setq bounce-end (point)))
3604 (setq bounce-start (point)
3605 bounce-end (point-max)))
3606 (unless (search-forward "\n\n" nil t)
3607 (error "Cannot find end of header in failed message"))))))
3608 ;; We have found the message that bounced, within the current message.
3609 ;; Now start sending new message; default header fields from original.
3610 ;; Turn off the usual actions for initializing the message body
3611 ;; because we want to get only the text from the failure message.
3612 (let (mail-signature mail-setup-hook)
3613 (if (pmail-start-mail nil nil nil nil nil pmail-this-buffer
3614 (list (list 'pmail-mark-message
3616 (aref pmail-msgref-vector msgnum)
3617 pmail-retried-attr-index)))
3618 ;; Insert original text as initial text of new draft message.
3619 ;; Bind inhibit-read-only since the header delimiter
3620 ;; of the previous message was probably read-only.
3621 (let ((inhibit-read-only t)
3622 pmail-displayed-headers
3623 pmail-ignored-headers)
3625 (insert-buffer-substring pmail-this-buffer
3626 bounce-start bounce-end)
3627 (goto-char (point-min))
3629 (indent-rigidly (point-min) (point-max) bounce-indent))
3630 (mail-sendmail-delimit-header)
3632 (narrow-to-region (point-min) (mail-header-end))
3633 (setq resending (mail-fetch-field "resent-to"))
3636 (insert "Resent-Bcc: " (user-login-name) "\n")
3637 (insert "BCC: " (user-login-name) "\n"))))
3638 (goto-char (point-min))
3639 (mail-position-on-field (if resending "Resent-To" "To") t))))))
3641 (defun pmail-summary-exists ()
3642 "Non-nil if in an PMAIL buffer and an associated summary buffer exists.
3643 In fact, the non-nil value returned is the summary buffer itself."
3644 (and pmail-summary-buffer (buffer-name pmail-summary-buffer)
3645 pmail-summary-buffer))
3647 (defun pmail-summary-displayed ()
3648 "t if in PMAIL buffer and an associated summary buffer is displayed."
3649 (and pmail-summary-buffer (get-buffer-window pmail-summary-buffer)))
3651 (defcustom pmail-redisplay-summary nil
3652 "*Non-nil means Pmail should show the summary when it changes.
3653 This has an effect only if a summary buffer exists."
3655 :group 'pmail-summary)
3657 (defcustom pmail-summary-window-size nil
3658 "*Non-nil means specify the height for an Pmail summary window."
3659 :type '(choice (const :tag "Disabled" nil) integer)
3660 :group 'pmail-summary)
3662 ;; Put the summary buffer back on the screen, if user wants that.
3663 (defun pmail-maybe-display-summary ()
3664 (let ((selected (selected-window))
3666 ;; If requested, make sure the summary is displayed.
3667 (and pmail-summary-buffer (buffer-name pmail-summary-buffer)
3668 pmail-redisplay-summary
3669 (if (get-buffer-window pmail-summary-buffer 0)
3670 ;; It's already in some frame; show that one.
3671 (let ((frame (window-frame
3672 (get-buffer-window pmail-summary-buffer 0))))
3673 (make-frame-visible frame)
3674 (raise-frame frame))
3675 (display-buffer pmail-summary-buffer)))
3676 ;; If requested, set the height of the summary window.
3677 (and pmail-summary-buffer (buffer-name pmail-summary-buffer)
3678 pmail-summary-window-size
3679 (setq window (get-buffer-window pmail-summary-buffer))
3680 ;; Don't try to change the size if just one window in frame.
3681 (not (eq window (frame-root-window (window-frame window))))
3684 (select-window window)
3685 (enlarge-window (- pmail-summary-window-size (window-height))))
3686 (select-window selected)))))
3688 ;;;; *** Pmail Local Fontification ***
3690 (defun pmail-fontify-buffer-function ()
3691 ;; This function's symbol is bound to font-lock-fontify-buffer-function.
3692 (add-hook 'pmail-show-message-hook 'pmail-fontify-message nil t)
3693 ;; If we're already showing a message, fontify it now.
3694 (if pmail-current-message (pmail-fontify-message))
3695 ;; Prevent Font Lock mode from kicking in.
3696 (setq font-lock-fontified t))
3698 (defun pmail-unfontify-buffer-function ()
3699 ;; This function's symbol is bound to font-lock-fontify-unbuffer-function.
3700 (let ((modified (buffer-modified-p))
3701 (buffer-undo-list t) (inhibit-read-only t)
3702 before-change-functions after-change-functions
3703 buffer-file-name buffer-file-truename)
3706 (remove-hook 'pmail-show-message-hook 'pmail-fontify-message t)
3707 (remove-text-properties (point-min) (point-max) '(pmail-fontified nil))
3708 (font-lock-default-unfontify-buffer)
3709 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))
3711 (defun pmail-fontify-message ()
3712 ;; Fontify the current message if it is not already fontified.
3713 (if (text-property-any (point-min) (point-max) 'pmail-fontified nil)
3714 (let ((modified (buffer-modified-p))
3715 (buffer-undo-list t) (inhibit-read-only t)
3716 before-change-functions after-change-functions
3717 buffer-file-name buffer-file-truename)
3720 (add-text-properties (point-min) (point-max) '(pmail-fontified t))
3721 (font-lock-fontify-region (point-min) (point-max))
3722 (and (not modified) (buffer-modified-p) (set-buffer-modified-p nil)))))))
3724 ;;; Speedbar support for PMAIL files.
3725 (eval-when-compile (require 'speedbar))
3727 (defvar pmail-speedbar-match-folder-regexp "^[A-Z0-9]+\\(\\.[A-Z0-9]+\\)?$"
3728 "*This regex is used to match folder names to be displayed in speedbar.
3729 Enabling this will permit speedbar to display your folders for easy
3730 browsing, and moving of messages.")
3732 (defvar pmail-speedbar-last-user nil
3733 "The last user to be displayed in the speedbar.")
3735 (defvar pmail-speedbar-key-map nil
3736 "Keymap used when in pmail display mode.")
3738 (defun pmail-install-speedbar-variables ()
3739 "Install those variables used by speedbar to enhance pmail."
3740 (if pmail-speedbar-key-map
3742 (setq pmail-speedbar-key-map (speedbar-make-specialized-keymap))
3744 (define-key pmail-speedbar-key-map "e" 'speedbar-edit-line)
3745 (define-key pmail-speedbar-key-map "r" 'speedbar-edit-line)
3746 (define-key pmail-speedbar-key-map "\C-m" 'speedbar-edit-line)
3747 (define-key pmail-speedbar-key-map "M"
3748 'pmail-speedbar-move-message-to-folder-on-line)))
3750 (defvar pmail-speedbar-menu-items
3751 '(["Read Folder" speedbar-edit-line t]
3752 ["Move message to folder" pmail-speedbar-move-message-to-folder-on-line
3753 (save-excursion (beginning-of-line)
3754 (looking-at "<M> "))])
3755 "Additional menu-items to add to speedbar frame.")
3757 ;; Make sure our special speedbar major mode is loaded
3758 (if (featurep 'speedbar)
3759 (pmail-install-speedbar-variables)
3760 (add-hook 'speedbar-load-hook 'pmail-install-speedbar-variables))
3762 (defun pmail-speedbar-buttons (buffer)
3763 "Create buttons for BUFFER containing pmail messages.
3764 Click on the address under Reply to: to reply to this person.
3765 Under Folders: Click a name to read it, or on the <M> to move the
3766 current message into that PMAIL folder."
3770 (goto-char (point-min))
3771 (if (not (re-search-forward "^Reply-To: " nil t))
3772 (if (not (re-search-forward "^From:? " nil t))
3776 (setq from (buffer-substring (point) (save-excursion
3779 (goto-char (point-min))
3780 (if (and (looking-at "Reply to:")
3781 (equal from pmail-speedbar-last-user))
3783 (setq pmail-speedbar-last-user from)
3785 (insert "Reply To:\n")
3787 (speedbar-insert-button from 'speedbar-directory-face 'highlight
3788 'pmail-speedbar-button 'pmail-reply))
3789 (insert "Folders:\n")
3790 (let* ((case-fold-search nil)
3791 (df (directory-files (save-excursion (set-buffer buffer)
3793 nil pmail-speedbar-match-folder-regexp)))
3795 (speedbar-insert-button "<M>" 'speedbar-button-face 'highlight
3796 'pmail-speedbar-move-message (car df))
3797 (speedbar-insert-button (car df) 'speedbar-file-face 'highlight
3798 'pmail-speedbar-find-file nil t)
3799 (setq df (cdr df)))))))
3801 (defun pmail-speedbar-button (text token indent)
3802 "Execute an pmail command specified by TEXT.
3803 The command used is TOKEN. INDENT is not used."
3804 (speedbar-with-attached-buffer
3807 (defun pmail-speedbar-find-file (text token indent)
3808 "Load in the pmail file TEXT.
3809 TOKEN and INDENT are not used."
3810 (speedbar-with-attached-buffer
3811 (message "Loading in PMAIL file %s..." text)
3814 (defun pmail-speedbar-move-message-to-folder-on-line ()
3815 "If the current line is a folder, move current message to it."
3819 (if (re-search-forward "<M> " (save-excursion (end-of-line) (point)) t)
3822 (speedbar-do-function-pointer)))))
3824 (defun pmail-speedbar-move-message (text token indent)
3825 "From button TEXT, copy current message to the pmail file specified by TOKEN.
3826 TEXT and INDENT are not used."
3827 (speedbar-with-attached-buffer
3828 (message "Moving message to %s" token)
3829 (pmail-output token)))
3831 ; Functions for setting, getting and encoding the POP password.
3832 ; The password is encoded to prevent it from being easily accessible
3833 ; to "prying eyes." Obviously, this encoding isn't "real security,"
3834 ; nor is it meant to be.
3837 (defun pmail-set-remote-password (password)
3838 "Set PASSWORD to be used for retrieving mail from a POP or IMAP server."
3839 (interactive "sPassword: ")
3841 (setq pmail-encoded-remote-password
3842 (pmail-encode-string password (emacs-pid)))
3843 (setq pmail-remote-password nil)
3844 (setq pmail-encoded-remote-password nil)))
3846 (defun pmail-get-remote-password (imap)
3847 "Get the password for retrieving mail from a POP or IMAP server. If none
3848 has been set, then prompt the user for one."
3849 (when (not pmail-encoded-remote-password)
3850 (if (not pmail-remote-password)
3851 (setq pmail-remote-password
3852 (read-passwd (if imap
3854 "POP password: "))))
3855 (pmail-set-remote-password pmail-remote-password)
3856 (setq pmail-remote-password nil))
3857 (pmail-encode-string pmail-encoded-remote-password (emacs-pid)))
3859 (defun pmail-have-password ()
3860 (or pmail-remote-password pmail-encoded-remote-password))
3862 (defun pmail-encode-string (string mask)
3863 "Encode STRING with integer MASK, by taking the exclusive OR of the
3864 lowest byte in the mask with the first character of string, the
3865 second-lowest-byte with the second character of the string, etc.,
3866 restarting at the lowest byte of the mask whenever it runs out.
3867 Returns the encoded string. Calling the function again with an
3868 encoded string (and the same mask) will decode the string."
3869 (setq mask (abs mask)) ; doesn't work if negative
3870 (let* ((string-vector (string-to-vector string)) (i 0)
3871 (len (length string-vector)) (curmask mask) charmask)
3874 (setq curmask mask))
3875 (setq charmask (% curmask 256))
3876 (setq curmask (lsh curmask -8))
3877 (aset string-vector i (logxor charmask (aref string-vector i)))
3879 (concat string-vector)))
3881 ;;;; Desktop support
3883 (defun pmail-restore-desktop-buffer (desktop-buffer-file-name
3885 desktop-buffer-misc)
3886 "Restore an pmail buffer specified in a desktop file."
3887 (condition-case error
3889 (pmail-input desktop-buffer-file-name)
3890 (if (eq major-mode 'pmail-mode)
3894 (kill-buffer (current-buffer))
3897 (add-to-list 'desktop-buffer-mode-handlers
3898 '(pmail-mode . pmail-restore-desktop-buffer))
3904 ;; change-log-default-name: "ChangeLog.pmail"
3907 ;; arch-tag: 65d257d3-c281-4a65-9c38-e61af95af2f0
3908 ;;; pmail.el ends here