1 ;;; pmailsum.el --- make summary buffers for the mail reader
3 ;; Copyright (C) 1985, 1993, 1994, 1995, 1996, 2000, 2001, 2002, 2003,
4 ;; 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
9 ;; This file is part of GNU Emacs.
11 ;; GNU Emacs is free software: you can redistribute it and/or modify
12 ;; it under the terms of the GNU General Public License as published by
13 ;; the Free Software Foundation, either version 3 of the License, or
14 ;; (at your option) any later version.
16 ;; GNU Emacs is distributed in the hope that it will be useful,
17 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
18 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 ;; GNU General Public License for more details.
21 ;; You should have received a copy of the GNU General Public License
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
26 ;; Extended by Bob Weiner of Motorola
27 ;; Provided all commands from pmail-mode in pmail-summary-mode and made key
28 ;; bindings in both modes wholly compatible.
34 ;; For pmail-select-summary
38 (defcustom pmail-summary-scroll-between-messages t
39 "*Non-nil means Pmail summary scroll commands move between messages."
41 :group
'pmail-summary
)
44 (defcustom pmail-summary-line-count-flag t
45 "*Non-nil means Pmail summary should show the number of lines in each message."
47 :group
'pmail-summary
)
49 (defvar pmail-summary-font-lock-keywords
50 '(("^.....D.*" . font-lock-string-face
) ; Deleted.
51 ("^.....-.*" . font-lock-type-face
) ; Unread.
52 ;; Neither of the below will be highlighted if either of the above are:
53 ("^.....[^D-] \\(......\\)" 1 font-lock-keyword-face
) ; Date.
54 ("{ \\([^\n}]+\\) }" 1 font-lock-comment-face
)) ; Labels.
55 "Additional expressions to highlight in Pmail Summary mode.")
57 (defvar pmail-summary-redo
58 "(FUNCTION . ARGS) to regenerate this Pmail summary buffer.")
60 (defvar pmail-summary-overlay nil
)
61 (put 'pmail-summary-overlay
'permanent-local t
)
63 (defvar pmail-summary-mode-map nil
)
65 ;; Entry points for making a summary buffer.
67 ;; Regenerate the contents of the summary
68 ;; using the same selection criterion as last time.
69 ;; M-x revert-buffer in a summary buffer calls this function.
70 (defun pmail-update-summary (&rest ignore
)
71 (apply (car pmail-summary-redo
) (cdr pmail-summary-redo
)))
74 (defun pmail-summary ()
75 "Display a summary of all messages, one line per message."
77 (pmail-new-summary "All" '(pmail-summary) nil
)
78 (unless (get-buffer-window pmail-buffer
)
79 (pmail-summary-beginning-of-message)))
82 (defun pmail-summary-by-labels (labels)
83 "Display a summary of all messages with one or more LABELS.
84 LABELS should be a string containing the desired labels, separated by commas."
85 (interactive "sLabels to summarize by: ")
86 (if (string= labels
"")
87 (setq labels
(or pmail-last-multi-labels
88 (error "No label specified"))))
89 (setq pmail-last-multi-labels labels
)
90 (pmail-new-summary (concat "labels " labels
)
91 (list 'pmail-summary-by-labels labels
)
92 'pmail-message-labels-p
93 (concat ", \\(" (mail-comma-list-regexp labels
) "\\),")))
96 (defun pmail-summary-by-recipients (recipients &optional primary-only
)
97 "Display a summary of all messages with the given RECIPIENTS.
98 Normally checks the To, From and Cc fields of headers;
99 but if PRIMARY-ONLY is non-nil (prefix arg given),
100 only look in the To and From fields.
101 RECIPIENTS is a string of regexps separated by commas."
102 (interactive "sRecipients to summarize by: \nP")
104 (concat "recipients " recipients
)
105 (list 'pmail-summary-by-recipients recipients primary-only
)
106 'pmail-message-recipients-p
107 (mail-comma-list-regexp recipients
) primary-only
))
110 (defun pmail-summary-by-regexp (regexp)
111 "Display a summary of all messages according to regexp REGEXP.
112 If the regular expression is found in the header of the message
113 \(including in the date and other lines, as well as the subject line),
114 Emacs will list the header line in the PMAIL-summary."
115 (interactive "sRegexp to summarize by: ")
116 (if (string= regexp
"")
117 (setq regexp
(or pmail-last-regexp
118 (error "No regexp specified"))))
119 (setq pmail-last-regexp regexp
)
120 (pmail-new-summary (concat "regexp " regexp
)
121 (list 'pmail-summary-by-regexp regexp
)
122 'pmail-message-regexp-p
125 ;; pmail-summary-by-topic
126 ;; 1989 R.A. Schnitzler
129 (defun pmail-summary-by-topic (subject &optional whole-message
)
130 "Display a summary of all messages with the given SUBJECT.
131 Normally checks the Subject field of headers;
132 but if WHOLE-MESSAGE is non-nil (prefix arg given),
133 look in the whole message.
134 SUBJECT is a string of regexps separated by commas."
136 (let* ((subject (with-current-buffer pmail-buffer
137 (pmail-current-subject)))
138 (subject-re (with-current-buffer pmail-buffer
139 (pmail-current-subject-regexp)))
140 (prompt (concat "Topics to summarize by (regexp"
141 (if subject
", default current subject" "")
143 (list (read-string prompt nil nil subject
) current-prefix-arg
)))
145 (concat "about " subject
)
146 (list 'pmail-summary-by-topic subject whole-message
)
147 'pmail-message-subject-p
148 (mail-comma-list-regexp subject
) whole-message
))
150 (defun pmail-message-subject-p (msg subject
&optional whole-message
)
152 (error "pmail-message-subject-p has not been updated for Pmail")
154 (goto-char (pmail-msgbeg msg
))
155 (search-forward "\n*** EOOH ***\n" (pmail-msgend msg
) 'move
)
158 (progn (search-forward (if whole-message
"\^_" "\n\n")) (point)))
159 (goto-char (point-min))
160 (if whole-message
(re-search-forward subject nil t
)
161 (string-match subject
(let ((subj (mail-fetch-field "Subject")))
163 (funcall pmail-summary-line-decoder subj
)
167 (defun pmail-summary-by-senders (senders)
168 "Display a summary of all messages with the given SENDERS.
169 SENDERS is a string of names separated by commas."
170 (interactive "sSenders to summarize by: ")
172 (concat "senders " senders
)
173 (list 'pmail-summary-by-senders senders
)
174 'pmail-message-senders-p
175 (mail-comma-list-regexp senders
)))
177 (defun pmail-message-senders-p (msg senders
)
179 (error "pmail-message-senders-p has not been updated for Pmail")
181 (goto-char (pmail-msgbeg msg
))
182 (search-forward "\n*** EOOH ***\n")
183 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
184 (string-match senders
(or (mail-fetch-field "From") ""))))
186 ;; General making of a summary buffer.
188 (defvar pmail-summary-symbol-number
0)
190 (defvar pmail-new-summary-line-count
)
192 (defun pmail-new-summary (desc redo func
&rest args
)
193 "Create a summary of selected messages.
194 DESC makes part of the mode line of the summary buffer. REDO is form ...
195 For each message, FUNC is applied to the message number and ARGS...
196 and if the result is non-nil, that message is included.
197 nil for FUNCTION means all messages."
198 (message "Computing summary lines...")
200 (error "No PMAIL buffer found"))
201 (let (mesg was-in-summary
)
202 (if (eq major-mode
'pmail-summary-mode
)
203 (setq was-in-summary t
))
204 (with-current-buffer pmail-buffer
205 (setq mesg pmail-current-message
206 pmail-summary-buffer
(pmail-new-summary-1 desc redo func args
)))
207 ;; Now display the summary buffer and go to the right place in it.
208 (unless was-in-summary
209 (if (and (one-window-p)
212 ;; If there is just one window, put the summary on the top.
214 (split-window (selected-window) pmail-summary-window-size
)
215 (select-window (next-window (frame-first-window)))
216 (pop-to-buffer pmail-summary-buffer
)
217 ;; If pop-to-buffer did not use that window, delete that
218 ;; window. (This can happen if it uses another frame.)
219 (if (not (eq pmail-summary-buffer
220 (window-buffer (frame-first-window))))
221 (delete-other-windows)))
222 (pop-to-buffer pmail-summary-buffer
))
223 (set-buffer pmail-buffer
)
224 ;; This is how pmail makes the summary buffer reappear.
225 ;; We do this here to make the window the proper size.
226 (pmail-select-summary nil
)
227 (set-buffer pmail-summary-buffer
))
228 (pmail-summary-goto-msg mesg t t
)
229 (pmail-summary-construct-io-menu)
230 (message "Computing summary lines...done")))
232 (defun pmail-new-summary-1 (description form function
&rest args
)
233 "Filter messages to obtain summary lines.
234 DESCRIPTION is added to the mode line.
236 Return the summary buffer by invoking FUNCTION on each message
237 passing the message number and ARGS...
241 The current buffer must be a Pmail buffer either containing a
242 collection of mbox formatted messages or displaying a single
244 (let ((summary-msgs ())
245 (pmail-new-summary-line-count 0)
246 (sumbuf (pmail-get-create-summary-buffer)))
247 ;; Scan the messages, getting their summary strings
248 ;; and putting the list of them in SUMMARY-MSGS.
250 (total pmail-total-messages
)
251 (inhibit-read-only t
))
253 (if (pmail-buffers-swapped-p)
254 (set-buffer pmail-view-buffer
))
255 (let ((old-min (point-min-marker))
256 (old-max (point-max-marker)))
258 ;; Can't use save-restriction here; that doesn't work if we
259 ;; plan to modify text outside the original restriction.
262 (goto-char (point-min))
263 (while (>= total msgnum
)
264 ;; First test whether to include this message.
265 (if (or (null function
)
266 (apply function
(cons msgnum args
)))
268 ;; Go back to the Pmail buffer so
269 ;; so pmail-get-summary can see its local vars.
270 (with-current-buffer pmail-buffer
271 (cons (cons msgnum
(pmail-get-summary msgnum
))
273 (setq msgnum
(1+ msgnum
))
274 ;; Provide a periodic User progress message.
275 (if (zerop (% pmail-new-summary-line-count
10))
276 (message "Computing summary lines...%d"
277 pmail-new-summary-line-count
)))
278 (setq summary-msgs
(nreverse summary-msgs
)))
279 (narrow-to-region old-min old-max
)))))
281 ;; Temporarily, while summary buffer is unfinished,
282 ;; we "don't have" a summary.
284 ;; I have not a clue what this clause is doing. If you read this
285 ;; chunk of code and have a clue, then please email that clue to
287 (setq pmail-summary-buffer nil
)
288 (if pmail-enable-mime
289 (with-current-buffer pmail-buffer
290 (setq pmail-summary-buffer nil
)))
293 (let ((rbuf (current-buffer))
294 (total pmail-total-messages
))
296 ;; Set up the summary buffer's contents.
297 (let ((buffer-read-only nil
))
300 (princ (cdr (car summary-msgs
)) sumbuf
)
301 (setq summary-msgs
(cdr summary-msgs
)))
302 (goto-char (point-min)))
303 ;; Set up the rest of its state and local variables.
304 (setq buffer-read-only t
)
306 (make-local-variable 'minor-mode-alist
)
307 (setq minor-mode-alist
(list (list t
(concat ": " description
))))
308 (setq pmail-buffer rbuf
309 pmail-summary-redo form
310 pmail-total-messages total
)))
313 (defun pmail-get-create-summary-buffer ()
314 "Obtain a summary buffer by re-using an existing summary
315 buffer, or by creating a new summary buffer."
316 (if (and pmail-summary-buffer
(buffer-name pmail-summary-buffer
))
318 (generate-new-buffer (concat (buffer-name) "-summary"))))
321 ;; Low levels of generating a summary.
323 (defun pmail-get-summary (msgnum)
324 "Return the summary line for message MSGNUM.
325 If the message has a summary line already, it will be stored in
326 the message as a header and simply returned, otherwise the
327 summary line is created, saved in the message header, cached and
330 The current buffer contains the unrestricted message collection."
331 (let ((line (aref pmail-summary-vector
(1- msgnum
))))
333 ;; Register a summary line for MSGNUM.
334 (setq pmail-new-summary-line-count
(1+ pmail-new-summary-line-count
)
335 line
(pmail-get-create-summary-line msgnum
))
336 ;; Cache the summary line for use during this Pmail session.
337 (aset pmail-summary-vector
(1- msgnum
) line
))
341 (defcustom pmail-summary-line-decoder
(function identity
)
342 "*Function to decode summary-line.
344 By default, `identity' is set."
346 :group
'pmail-summary
)
348 (defun pmail-get-create-summary-line (msgnum)
349 "Return the summary line for message MSGNUM.
350 Obtain the message summary from the header if it is available
351 otherwise create it and store it in the message header.
353 The current buffer contains the unrestricted message collection."
354 (let ((beg (pmail-msgbeg msgnum
))
355 (end (pmail-msgend msgnum
)))
357 (if (search-forward "\n\n" end t
)
359 (narrow-to-region beg
(point))
360 ;; Generate a status line from the message and put it in the
362 (pmail-create-summary msgnum
))
363 (pmail-error-bad-format msgnum
))))
365 (defun pmail-get-summary-labels ()
366 "Return a coded string wrapped in curly braces denoting the status labels.
368 The current buffer is narrowed to the message headers for
369 the message being processed."
370 (let ((status (mail-fetch-field pmail-attribute-header
))
374 ;; Strip off the read/unread and the deleted attribute which are
375 ;; handled separately.
378 (concat (substring status
0 1) (substring status
2 6))
380 (while (< index
(length status
))
381 (unless (string= "-" (setq char
(substring status index
(1+ index
))))
382 (setq result
(concat result char
)))
383 (setq index
(1+ index
)))
384 (when (> (length result
) 0)
385 (setq result
(concat "{" result
"}")))
388 (defun pmail-create-summary (msgnum)
389 "Return the summary line for message MSGNUM.
390 The current buffer is narrowed to the header for message MSGNUM."
391 (goto-char (point-min))
392 (let ((line (pmail-make-basic-summary-line))
393 (labels (pmail-get-summary-labels))
394 pos prefix status suffix
)
395 (setq pos
(string-match "#" line
)
397 ((pmail-message-deleted-p msgnum
) ?D
)
398 ((pmail-message-unseen-p msgnum
) ?-
)
400 prefix
(format "%5d%c %s" msgnum status
(substring line
0 pos
))
401 suffix
(substring line
(1+ pos
)))
402 (funcall pmail-summary-line-decoder
(concat prefix labels suffix
))))
405 (defcustom pmail-user-mail-address-regexp nil
406 "*Regexp matching user mail addresses.
407 If non-nil, this variable is used to identify the correspondent
408 when receiving new mail. If it matches the address of the sender,
409 the recipient is taken as correspondent of a mail.
410 If nil \(default value\), your `user-login-name' and `user-mail-address'
411 are used to exclude yourself as correspondent.
413 Usually you don't have to set this variable, except if you collect mails
414 sent by you under different user names.
415 Then it should be a regexp matching your mail addresses.
417 Setting this variable has an effect only before reading a mail."
418 :type
'(choice (const :tag
"None" nil
) regexp
)
419 :group
'pmail-retrieve
422 (defun pmail-make-basic-summary-line ()
423 (goto-char (point-min))
424 (concat (save-excursion
425 (if (not (re-search-forward "^Date:" nil t
))
427 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
428 (save-excursion (end-of-line) (point)) t
)
430 (string-to-number (buffer-substring
434 (match-beginning 4) (match-end 4))))
435 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
436 (save-excursion (end-of-line) (point)) t
)
438 (string-to-number (buffer-substring
442 (match-beginning 2) (match-end 2))))
443 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
444 (save-excursion (end-of-line) (point)) t
)
447 (match-beginning 2) (match-end 2))
449 (match-beginning 3) (match-end 3))
451 (match-beginning 4) (match-end 4))))
455 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t
)
456 (mail-strip-quoted-names
459 ;; Get all the lines of the From field
460 ;; so that we get a whole comment if there is one,
461 ;; so that mail-strip-quoted-names can discard it.
462 (let ((opoint (point)))
463 (while (progn (forward-line 1)
464 (looking-at "[ \t]")))
465 ;; Back up over newline, then trailing spaces or tabs
467 (skip-chars-backward " \t")
472 (or pmail-user-mail-address-regexp
474 (regexp-quote (user-login-name))
477 ;; Don't lose if run from init file
478 ;; where user-mail-address is not
480 (or user-mail-address
481 (concat (user-login-name) "@"
482 (or mail-host-address
486 ;; No From field, or it's this user.
488 (goto-char (point-min))
489 (if (not (re-search-forward "^To:[ \t]*" nil t
))
493 (mail-strip-quoted-names
497 (skip-chars-backward " \t")
501 (setq len
(length from
))
502 (setq mch
(string-match "[@%]" from
))
504 (if (or (not mch
) (<= len
25))
505 (substring from
(max 0 (- len
25)))
507 (setq lo
(cond ((< (- mch
14) 0) 0)
511 (min len
(+ lo
25))))))))
512 (if pmail-summary-line-count-flag
516 (let ((beg (pmail-msgbeg msgnum
))
517 (end (pmail-msgend msgnum
))
521 ;; Count only lines in the reformatted header,
522 ;; if we have reformatted it.
523 (search-forward "\n*** EOOH ***\n" end t
)
524 (setq lines
(count-lines (point) end
)))
526 ((<= lines
9) " [%d]")
527 ((<= lines
99) " [%d]")
528 ((<= lines
999) " [%3d]")
532 " #" ;The # is part of the format.
533 (if (re-search-forward "^Subject:" nil t
)
534 (progn (skip-chars-forward " \t")
535 (buffer-substring (point)
538 (re-search-forward "[\n][\n]+" nil t
)
539 (buffer-substring (point) (progn (end-of-line) (point))))
542 ;; Simple motion in a summary buffer.
544 (defun pmail-summary-next-all (&optional number
)
546 (forward-line (if number number
1))
547 ;; It doesn't look nice to move forward past the last message line.
548 (and (eobp) (> number
0)
550 (display-buffer pmail-buffer
))
552 (defun pmail-summary-previous-all (&optional number
)
554 (forward-line (- (if number number
1)))
555 ;; It doesn't look nice to move forward past the last message line.
556 (and (eobp) (< number
0)
558 (display-buffer pmail-buffer
))
560 (defun pmail-summary-next-msg (&optional number
)
561 "Display next non-deleted msg from pmail file.
562 With optional prefix argument NUMBER, moves forward this number of non-deleted
563 messages, or backward if NUMBER is negative."
566 (and (> number
0) (end-of-line))
567 (let ((count (if (< number
0) (- number
) number
))
568 (search (if (> number
0) 're-search-forward
're-search-backward
))
569 (non-del-msg-found nil
))
570 (while (and (> count
0) (setq non-del-msg-found
571 (or (funcall search
"^.....[^D]" nil t
)
573 (setq count
(1- count
))))
575 (display-buffer pmail-buffer
))
577 (defun pmail-summary-previous-msg (&optional number
)
578 "Display previous non-deleted msg from pmail file.
579 With optional prefix argument NUMBER, moves backward this number of
580 non-deleted messages."
582 (pmail-summary-next-msg (- (if number number
1))))
584 (defun pmail-summary-next-labeled-message (n labels
)
585 "Show next message with LABELS. Defaults to last labels used.
586 With prefix argument N moves forward N messages with these labels."
587 (interactive "p\nsMove to next msg with labels: ")
590 (set-buffer pmail-buffer
)
591 (pmail-next-labeled-message n labels
)
592 (setq msg pmail-current-message
))
593 (pmail-summary-goto-msg msg
)))
595 (defun pmail-summary-previous-labeled-message (n labels
)
596 "Show previous message with LABELS. Defaults to last labels used.
597 With prefix argument N moves backward N messages with these labels."
598 (interactive "p\nsMove to previous msg with labels: ")
601 (set-buffer pmail-buffer
)
602 (pmail-previous-labeled-message n labels
)
603 (setq msg pmail-current-message
))
604 (pmail-summary-goto-msg msg
)))
606 (defun pmail-summary-next-same-subject (n)
607 "Go to the next message in the summary having the same subject.
608 With prefix argument N, do this N times.
609 If N is negative, go backwards."
611 (let ((forward (> n
0))
612 search-regexp i found
)
613 (with-current-buffer pmail-buffer
614 (setq search-regexp
(pmail-current-subject-regexp)
615 i pmail-current-message
))
622 (while (and (not done
)
626 ;; Advance thru summary.
627 (forward-line (if forward
1 -
1))
628 ;; Get msg number of this line.
629 (setq i
(string-to-number
630 (buffer-substring (point)
631 (min (point-max) (+ 6 (point))))))
632 ;; See if that msg has desired subject.
634 (set-buffer pmail-buffer
)
637 (goto-char (pmail-msgbeg i
))
638 (search-forward "\n*** EOOH ***\n")
639 (let ((beg (point)) end
)
640 (search-forward "\n\n")
643 (setq done
(re-search-forward search-regexp end t
))))))
644 (if done
(setq found i
)))
645 (setq n
(if forward
(1- n
) (1+ n
)))))
647 (pmail-summary-goto-msg found
)
648 (error "No %s message with same subject"
649 (if forward
"following" "previous")))))
651 (defun pmail-summary-previous-same-subject (n)
652 "Go to the previous message in the summary having the same subject.
653 With prefix argument N, do this N times.
654 If N is negative, go forwards instead."
656 (pmail-summary-next-same-subject (- n
)))
658 ;; Delete and undelete summary commands.
660 (defun pmail-summary-delete-forward (&optional count
)
661 "Delete this message and move to next nondeleted one.
662 Deleted messages stay in the file until the \\[pmail-expunge] command is given.
663 A prefix argument serves as a repeat count;
664 a negative argument means to delete and move backward."
666 (unless (numberp count
) (setq count
1))
668 (backward (< count
0)))
670 (pmail-summary-goto-msg)
671 (with-current-buffer pmail-buffer
672 (pmail-delete-message)
673 (setq del-msg pmail-current-message
))
674 (pmail-summary-mark-deleted del-msg
)
675 (while (and (not (if backward
(bobp) (eobp)))
676 (save-excursion (beginning-of-line)
677 (looking-at " *[0-9]+D")))
678 (forward-line (if backward -
1 1)))
679 ;; It looks ugly to move to the empty line at end of buffer.
680 (and (eobp) (not backward
)
683 (if (> count
0) (1- count
) (1+ count
))))))
685 (defun pmail-summary-delete-backward (&optional count
)
686 "Delete this message and move to previous nondeleted one.
687 Deleted messages stay in the file until the \\[pmail-expunge] command is given.
688 A prefix argument serves as a repeat count;
689 a negative argument means to delete and move forward."
691 (pmail-summary-delete-forward (- count
)))
693 (defun pmail-summary-mark-deleted (&optional n undel
)
694 ;; Since third arg is t, this only alters the summary, not the Pmail buf.
695 (and n
(pmail-summary-goto-msg n t t
))
697 (not (overlay-get pmail-summary-overlay
'face
))
698 (let ((buffer-read-only nil
))
699 (skip-chars-forward " ")
700 (skip-chars-forward "[0-9]")
703 (progn (delete-char 1) (insert " ")))
708 (defun pmail-summary-mark-undeleted (n)
709 (pmail-summary-mark-deleted n t
))
711 (defun pmail-summary-deleted-p (&optional n
)
713 (and n
(pmail-summary-goto-msg n nil t
))
714 (skip-chars-forward " ")
715 (skip-chars-forward "[0-9]")
718 (defun pmail-summary-undelete (&optional arg
)
719 "Undelete current message.
720 Optional prefix ARG means undelete ARG previous messages."
723 (pmail-summary-undelete-many arg
)
724 (let ((buffer-read-only nil
)
727 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t
)
728 (replace-match "\\1 ")
729 (pmail-summary-goto-msg)
730 (if pmail-enable-mime
731 (set-buffer pmail-buffer
)
732 (pop-to-buffer pmail-buffer
))
733 (and (pmail-message-deleted-p pmail-current-message
)
734 (pmail-undelete-previous-message))
735 (if pmail-enable-mime
736 (pop-to-buffer pmail-buffer
))
737 (pop-to-buffer pmail-summary-buffer
))
738 (t (goto-char opoint
))))))
740 (defun pmail-summary-undelete-many (&optional n
)
741 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
744 (set-buffer pmail-buffer
)
745 (let* ((init-msg (if n pmail-current-message pmail-total-messages
))
746 (pmail-current-message init-msg
)
747 (n (or n pmail-total-messages
))
749 (while (and (> pmail-current-message
0)
751 (if (pmail-message-deleted-p pmail-current-message
)
752 (progn (pmail-set-attribute "deleted" nil
)
753 (setq msgs-undeled
(1+ msgs-undeled
))))
754 (setq pmail-current-message
(1- pmail-current-message
)))
755 (set-buffer pmail-summary-buffer
)
756 (setq pmail-current-message init-msg msgs-undeled
0)
757 (while (and (> pmail-current-message
0)
759 (if (pmail-summary-deleted-p pmail-current-message
)
760 (progn (pmail-summary-mark-undeleted pmail-current-message
)
761 (setq msgs-undeled
(1+ msgs-undeled
))))
762 (setq pmail-current-message
(1- pmail-current-message
))))
763 (pmail-summary-goto-msg)))
765 ;; Pmail Summary mode is suitable only for specially formatted data.
766 (put 'pmail-summary-mode
'mode-class
'special
)
768 (defun pmail-summary-mode ()
769 "Pmail Summary Mode is invoked from Pmail Mode by using \\<pmail-mode-map>\\[pmail-summary].
770 As commands are issued in the summary buffer, they are applied to the
771 corresponding mail messages in the pmail buffer.
773 All normal editing commands are turned off.
774 Instead, nearly all the Pmail mode commands are available,
775 though many of them move only among the messages in the summary.
777 These additional commands exist:
779 \\[pmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
780 \\[pmail-summary-wipe] Delete the summary and go to the Pmail buffer.
782 Commands for sorting the summary:
784 \\[pmail-summary-sort-by-date] Sort by date.
785 \\[pmail-summary-sort-by-subject] Sort by subject.
786 \\[pmail-summary-sort-by-author] Sort by author.
787 \\[pmail-summary-sort-by-recipient] Sort by recipient.
788 \\[pmail-summary-sort-by-correspondent] Sort by correspondent.
789 \\[pmail-summary-sort-by-lines] Sort by lines.
790 \\[pmail-summary-sort-by-labels] Sort by labels."
792 (kill-all-local-variables)
793 (setq major-mode
'pmail-summary-mode
)
794 (setq mode-name
"PMAIL Summary")
795 (setq truncate-lines t
)
796 (setq buffer-read-only t
)
797 (set-syntax-table text-mode-syntax-table
)
798 (make-local-variable 'pmail-buffer
)
799 (make-local-variable 'pmail-total-messages
)
800 (make-local-variable 'pmail-current-message
)
801 (setq pmail-current-message nil
)
802 (make-local-variable 'pmail-summary-redo
)
803 (setq pmail-summary-redo nil
)
804 (make-local-variable 'revert-buffer-function
)
805 (make-local-variable 'font-lock-defaults
)
806 (setq font-lock-defaults
'(pmail-summary-font-lock-keywords t
))
807 (pmail-summary-enable)
808 (run-mode-hooks 'pmail-summary-mode-hook
))
810 ;; Summary features need to be disabled during edit mode.
811 (defun pmail-summary-disable ()
812 (use-local-map text-mode-map
)
813 (remove-hook 'post-command-hook
'pmail-summary-pmail-update t
)
814 (setq revert-buffer-function nil
))
816 (defun pmail-summary-enable ()
817 (use-local-map pmail-summary-mode-map
)
818 (add-hook 'post-command-hook
'pmail-summary-pmail-update nil t
)
819 (setq revert-buffer-function
'pmail-update-summary
))
821 (defvar pmail-summary-put-back-unseen nil
822 "Used for communicating between calls to `pmail-summary-pmail-update'.
823 If it moves to a message within an Incremental Search, and removes
824 the `unseen' attribute from that message, it sets this flag
825 so that if the next motion between messages is in the same Incremental
826 Search, the `unseen' attribute is restored.")
828 ;; Show in Pmail the message described by the summary line that point is on,
829 ;; but only if the Pmail buffer is already visible.
830 ;; This is a post-command-hook in summary buffers.
831 (defun pmail-summary-pmail-update ()
832 (let (buffer-read-only)
834 ;; If at end of buffer, pretend we are on the last text line.
838 (skip-chars-forward " ")
839 (let ((msg-num (string-to-number (buffer-substring
841 (progn (skip-chars-forward "0-9")
843 ;; Always leave `unseen' removed
844 ;; if we get out of isearch mode.
845 ;; Don't let a subsequent isearch restore that `unseen'.
846 (if (not isearch-mode
)
847 (setq pmail-summary-put-back-unseen nil
))
849 (or (eq pmail-current-message msg-num
)
850 (let ((window (get-buffer-window pmail-buffer t
))
851 (owin (selected-window)))
854 (set-buffer pmail-buffer
)
855 ;; If we first saw the previous message in this search,
856 ;; and we have gone to a different message while searching,
857 ;; put back `unseen' on the former one.
858 (if pmail-summary-put-back-unseen
859 (pmail-set-attribute "unseen" t
860 pmail-current-message
))
861 ;; Arrange to do that later, for the new current message,
862 ;; if it still has `unseen'.
863 (setq pmail-summary-put-back-unseen
864 (pmail-message-attr-p msg-num pmail-unseen-attr-index
)))
865 (setq pmail-summary-put-back-unseen nil
))
867 ;; Go to the desired message.
868 (setq pmail-current-message msg-num
)
870 ;; Update the summary to show the message has been seen.
871 (if (= (following-char) ?-
)
877 ;; Using save-window-excursion would cause the new value
878 ;; of point to get lost.
881 (select-window window
)
882 (pmail-show-message-maybe msg-num t
))
883 (select-window owin
))
884 (if (buffer-name pmail-buffer
)
886 (set-buffer pmail-buffer
)
887 (pmail-show-message-maybe msg-num t
))))))
888 (pmail-summary-update-highlight nil
)))))
890 (defun pmail-summary-save-buffer ()
891 "Save the buffer associated with this PMAIL summary."
893 (save-window-excursion
895 (switch-to-buffer pmail-buffer
)
899 (if pmail-summary-mode-map
901 (setq pmail-summary-mode-map
(make-keymap))
902 (suppress-keymap pmail-summary-mode-map
)
904 (define-key pmail-summary-mode-map
[mouse-2
] 'pmail-summary-mouse-goto-message
)
905 (define-key pmail-summary-mode-map
"a" 'pmail-summary-add-label
)
906 (define-key pmail-summary-mode-map
"b" 'pmail-summary-bury
)
907 (define-key pmail-summary-mode-map
"c" 'pmail-summary-continue
)
908 (define-key pmail-summary-mode-map
"d" 'pmail-summary-delete-forward
)
909 (define-key pmail-summary-mode-map
"\C-d" 'pmail-summary-delete-backward
)
910 (define-key pmail-summary-mode-map
"e" 'pmail-summary-edit-current-message
)
911 (define-key pmail-summary-mode-map
"f" 'pmail-summary-forward
)
912 (define-key pmail-summary-mode-map
"g" 'pmail-summary-get-new-mail
)
913 (define-key pmail-summary-mode-map
"h" 'pmail-summary
)
914 (define-key pmail-summary-mode-map
"i" 'pmail-summary-input
)
915 (define-key pmail-summary-mode-map
"j" 'pmail-summary-goto-msg
)
916 (define-key pmail-summary-mode-map
"\C-m" 'pmail-summary-goto-msg
)
917 (define-key pmail-summary-mode-map
"k" 'pmail-summary-kill-label
)
918 (define-key pmail-summary-mode-map
"l" 'pmail-summary-by-labels
)
919 (define-key pmail-summary-mode-map
"\e\C-h" 'pmail-summary
)
920 (define-key pmail-summary-mode-map
"\e\C-l" 'pmail-summary-by-labels
)
921 (define-key pmail-summary-mode-map
"\e\C-r" 'pmail-summary-by-recipients
)
922 (define-key pmail-summary-mode-map
"\e\C-s" 'pmail-summary-by-regexp
)
923 (define-key pmail-summary-mode-map
"\e\C-t" 'pmail-summary-by-topic
)
924 (define-key pmail-summary-mode-map
"m" 'pmail-summary-mail
)
925 (define-key pmail-summary-mode-map
"\M-m" 'pmail-summary-retry-failure
)
926 (define-key pmail-summary-mode-map
"n" 'pmail-summary-next-msg
)
927 (define-key pmail-summary-mode-map
"\en" 'pmail-summary-next-all
)
928 (define-key pmail-summary-mode-map
"\e\C-n" 'pmail-summary-next-labeled-message
)
929 (define-key pmail-summary-mode-map
"o" 'pmail-summary-output-to-babyl-file
)
930 (define-key pmail-summary-mode-map
"\C-o" 'pmail-summary-output
)
931 (define-key pmail-summary-mode-map
"p" 'pmail-summary-previous-msg
)
932 (define-key pmail-summary-mode-map
"\ep" 'pmail-summary-previous-all
)
933 (define-key pmail-summary-mode-map
"\e\C-p" 'pmail-summary-previous-labeled-message
)
934 (define-key pmail-summary-mode-map
"q" 'pmail-summary-quit
)
935 (define-key pmail-summary-mode-map
"Q" 'pmail-summary-wipe
)
936 (define-key pmail-summary-mode-map
"r" 'pmail-summary-reply
)
937 (define-key pmail-summary-mode-map
"s" 'pmail-summary-expunge-and-save
)
938 (define-key pmail-summary-mode-map
"\es" 'pmail-summary-search
)
939 (define-key pmail-summary-mode-map
"t" 'pmail-summary-toggle-header
)
940 (define-key pmail-summary-mode-map
"u" 'pmail-summary-undelete
)
941 (define-key pmail-summary-mode-map
"\M-u" 'pmail-summary-undelete-many
)
942 (define-key pmail-summary-mode-map
"x" 'pmail-summary-expunge
)
943 (define-key pmail-summary-mode-map
"w" 'pmail-summary-output-body
)
944 (define-key pmail-summary-mode-map
"." 'pmail-summary-beginning-of-message
)
945 (define-key pmail-summary-mode-map
"/" 'pmail-summary-end-of-message
)
946 (define-key pmail-summary-mode-map
"<" 'pmail-summary-first-message
)
947 (define-key pmail-summary-mode-map
">" 'pmail-summary-last-message
)
948 (define-key pmail-summary-mode-map
" " 'pmail-summary-scroll-msg-up
)
949 (define-key pmail-summary-mode-map
"\177" 'pmail-summary-scroll-msg-down
)
950 (define-key pmail-summary-mode-map
"?" 'describe-mode
)
951 (define-key pmail-summary-mode-map
"\C-c\C-n" 'pmail-summary-next-same-subject
)
952 (define-key pmail-summary-mode-map
"\C-c\C-p" 'pmail-summary-previous-same-subject
)
953 (define-key pmail-summary-mode-map
"\C-c\C-s\C-d"
954 'pmail-summary-sort-by-date
)
955 (define-key pmail-summary-mode-map
"\C-c\C-s\C-s"
956 'pmail-summary-sort-by-subject
)
957 (define-key pmail-summary-mode-map
"\C-c\C-s\C-a"
958 'pmail-summary-sort-by-author
)
959 (define-key pmail-summary-mode-map
"\C-c\C-s\C-r"
960 'pmail-summary-sort-by-recipient
)
961 (define-key pmail-summary-mode-map
"\C-c\C-s\C-c"
962 'pmail-summary-sort-by-correspondent
)
963 (define-key pmail-summary-mode-map
"\C-c\C-s\C-l"
964 'pmail-summary-sort-by-lines
)
965 (define-key pmail-summary-mode-map
"\C-c\C-s\C-k"
966 'pmail-summary-sort-by-labels
)
967 (define-key pmail-summary-mode-map
"\C-x\C-s" 'pmail-summary-save-buffer
)
970 ;;; Menu bar bindings.
972 (define-key pmail-summary-mode-map
[menu-bar
] (make-sparse-keymap))
974 (define-key pmail-summary-mode-map
[menu-bar classify
]
975 (cons "Classify" (make-sparse-keymap "Classify")))
977 (define-key pmail-summary-mode-map
[menu-bar classify output-menu
]
978 '("Output (Pmail Menu)..." . pmail-summary-output-menu
))
980 (define-key pmail-summary-mode-map
[menu-bar classify input-menu
]
981 '("Input Pmail File (menu)..." . pmail-input-menu
))
983 (define-key pmail-summary-mode-map
[menu-bar classify input-menu
]
986 (define-key pmail-summary-mode-map
[menu-bar classify output-menu
]
989 (define-key pmail-summary-mode-map
[menu-bar classify output-body
]
990 '("Output (body)..." . pmail-summary-output-body
))
992 (define-key pmail-summary-mode-map
[menu-bar classify output-inbox
]
993 '("Output (inbox)..." . pmail-summary-output
))
995 (define-key pmail-summary-mode-map
[menu-bar classify output
]
996 '("Output (Pmail)..." . pmail-summary-output-to-babyl-file
))
998 (define-key pmail-summary-mode-map
[menu-bar classify kill-label
]
999 '("Kill Label..." . pmail-summary-kill-label
))
1001 (define-key pmail-summary-mode-map
[menu-bar classify add-label
]
1002 '("Add Label..." . pmail-summary-add-label
))
1004 (define-key pmail-summary-mode-map
[menu-bar summary
]
1005 (cons "Summary" (make-sparse-keymap "Summary")))
1007 (define-key pmail-summary-mode-map
[menu-bar summary senders
]
1008 '("By Senders..." . pmail-summary-by-senders
))
1010 (define-key pmail-summary-mode-map
[menu-bar summary labels
]
1011 '("By Labels..." . pmail-summary-by-labels
))
1013 (define-key pmail-summary-mode-map
[menu-bar summary recipients
]
1014 '("By Recipients..." . pmail-summary-by-recipients
))
1016 (define-key pmail-summary-mode-map
[menu-bar summary topic
]
1017 '("By Topic..." . pmail-summary-by-topic
))
1019 (define-key pmail-summary-mode-map
[menu-bar summary regexp
]
1020 '("By Regexp..." . pmail-summary-by-regexp
))
1022 (define-key pmail-summary-mode-map
[menu-bar summary all
]
1023 '("All" . pmail-summary
))
1025 (define-key pmail-summary-mode-map
[menu-bar mail
]
1026 (cons "Mail" (make-sparse-keymap "Mail")))
1028 (define-key pmail-summary-mode-map
[menu-bar mail pmail-summary-get-new-mail
]
1029 '("Get New Mail" . pmail-summary-get-new-mail
))
1031 (define-key pmail-summary-mode-map
[menu-bar mail lambda
]
1034 (define-key pmail-summary-mode-map
[menu-bar mail continue
]
1035 '("Continue" . pmail-summary-continue
))
1037 (define-key pmail-summary-mode-map
[menu-bar mail resend
]
1038 '("Re-send..." . pmail-summary-resend
))
1040 (define-key pmail-summary-mode-map
[menu-bar mail forward
]
1041 '("Forward" . pmail-summary-forward
))
1043 (define-key pmail-summary-mode-map
[menu-bar mail retry
]
1044 '("Retry" . pmail-summary-retry-failure
))
1046 (define-key pmail-summary-mode-map
[menu-bar mail reply
]
1047 '("Reply" . pmail-summary-reply
))
1049 (define-key pmail-summary-mode-map
[menu-bar mail mail
]
1050 '("Mail" . pmail-summary-mail
))
1052 (define-key pmail-summary-mode-map
[menu-bar delete
]
1053 (cons "Delete" (make-sparse-keymap "Delete")))
1055 (define-key pmail-summary-mode-map
[menu-bar delete expunge
/save
]
1056 '("Expunge/Save" . pmail-summary-expunge-and-save
))
1058 (define-key pmail-summary-mode-map
[menu-bar delete expunge
]
1059 '("Expunge" . pmail-summary-expunge
))
1061 (define-key pmail-summary-mode-map
[menu-bar delete undelete
]
1062 '("Undelete" . pmail-summary-undelete
))
1064 (define-key pmail-summary-mode-map
[menu-bar delete delete
]
1065 '("Delete" . pmail-summary-delete-forward
))
1067 (define-key pmail-summary-mode-map
[menu-bar move
]
1068 (cons "Move" (make-sparse-keymap "Move")))
1070 (define-key pmail-summary-mode-map
[menu-bar move search-back
]
1071 '("Search Back..." . pmail-summary-search-backward
))
1073 (define-key pmail-summary-mode-map
[menu-bar move search
]
1074 '("Search..." . pmail-summary-search
))
1076 (define-key pmail-summary-mode-map
[menu-bar move previous
]
1077 '("Previous Nondeleted" . pmail-summary-previous-msg
))
1079 (define-key pmail-summary-mode-map
[menu-bar move next
]
1080 '("Next Nondeleted" . pmail-summary-next-msg
))
1082 (define-key pmail-summary-mode-map
[menu-bar move last
]
1083 '("Last" . pmail-summary-last-message
))
1085 (define-key pmail-summary-mode-map
[menu-bar move first
]
1086 '("First" . pmail-summary-first-message
))
1088 (define-key pmail-summary-mode-map
[menu-bar move previous
]
1089 '("Previous" . pmail-summary-previous-all
))
1091 (define-key pmail-summary-mode-map
[menu-bar move next
]
1092 '("Next" . pmail-summary-next-all
))
1094 (defun pmail-summary-mouse-goto-message (event)
1095 "Select the message whose summary line you click on."
1097 (goto-char (posn-point (event-end event
)))
1098 (pmail-summary-goto-msg))
1100 (defun pmail-summary-goto-msg (&optional n nowarn skip-pmail
)
1101 "Go to message N in the summary buffer and the Pmail buffer.
1102 If N is nil, use the message corresponding to point in the summary
1103 and move to that message in the Pmail buffer.
1105 If NOWARN, don't say anything if N is out of range.
1106 If SKIP-PMAIL, don't do anything to the Pmail buffer."
1108 (if (consp n
) (setq n
(prefix-numeric-value n
)))
1109 (if (eobp) (forward-line -
1))
1111 (let* ((obuf (current-buffer))
1115 (curmsg (string-to-number
1116 (buffer-substring (point)
1117 (min (point-max) (+ 6 (point))))))
1118 (total (save-excursion (set-buffer buf
) pmail-total-messages
)))
1119 ;; If message number N was specified, find that message's line
1120 ;; or set message-not-found.
1121 ;; If N wasn't specified or that message can't be found.
1122 ;; set N by default.
1126 (progn (message "No preceding message")
1128 (if (and (> n total
)
1130 (progn (message "No following message")
1131 (goto-char (point-max))
1132 (pmail-summary-goto-msg nil nowarn skip-pmail
)))
1133 (goto-char (point-min))
1134 (if (not (re-search-forward (format "^%5d[^0-9]" n
) nil t
))
1135 (progn (or nowarn
(message "Message %d not found" n
))
1137 (setq message-not-found t
)
1140 (skip-chars-forward " ")
1141 (skip-chars-forward "0-9")
1142 (save-excursion (if (= (following-char) ?-
)
1143 (let ((buffer-read-only nil
))
1146 (pmail-summary-update-highlight message-not-found
)
1150 (let ((selwin (selected-window)))
1152 (progn (pop-to-buffer buf
)
1153 (pmail-show-message-maybe n
))
1154 (select-window selwin
)
1155 ;; The actions above can alter the current buffer. Preserve it.
1156 (set-buffer obuf
))))))
1158 ;; Update the highlighted line in an pmail summary buffer.
1159 ;; That should be current. We highlight the line point is on.
1160 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1161 (defun pmail-summary-update-highlight (not-found)
1162 ;; Make sure we have an overlay to use.
1163 (or pmail-summary-overlay
1165 (make-local-variable 'pmail-summary-overlay
)
1166 (setq pmail-summary-overlay
(make-overlay (point) (point)))))
1167 ;; If this message is in the summary, use the overlay to highlight it.
1168 ;; Otherwise, don't highlight anything.
1170 (overlay-put pmail-summary-overlay
'face nil
)
1171 (move-overlay pmail-summary-overlay
1172 (save-excursion (beginning-of-line)
1173 (skip-chars-forward " ")
1175 (save-excursion (end-of-line) (point)))
1176 (overlay-put pmail-summary-overlay
'face
'highlight
)))
1178 (defun pmail-summary-scroll-msg-up (&optional dist
)
1179 "Scroll the Pmail window forward.
1180 If the Pmail window is displaying the end of a message,
1181 advance to the next message."
1184 (pmail-summary-scroll-msg-down nil
)
1185 (let ((pmail-buffer-window (get-buffer-window pmail-buffer
)))
1186 (if pmail-buffer-window
1187 (if (let ((pmail-summary-window (selected-window)))
1188 (select-window pmail-buffer-window
)
1190 ;; Is EOB visible in the buffer?
1192 (let ((ht (window-height (selected-window))))
1193 (move-to-window-line (- ht
2))
1196 (select-window pmail-summary-window
)))
1197 (if (not pmail-summary-scroll-between-messages
)
1198 (error "End of buffer")
1199 (pmail-summary-next-msg (or dist
1)))
1200 (let ((other-window-scroll-buffer pmail-buffer
))
1201 (scroll-other-window dist
)))
1202 ;; If it isn't visible at all, show the beginning.
1203 (pmail-summary-beginning-of-message)))))
1205 (defun pmail-summary-scroll-msg-down (&optional dist
)
1206 "Scroll the Pmail window backward.
1207 If the Pmail window is now displaying the beginning of a message,
1208 move to the previous message."
1211 (pmail-summary-scroll-msg-up nil
)
1212 (let ((pmail-buffer-window (get-buffer-window pmail-buffer
)))
1213 (if pmail-buffer-window
1214 (if (let ((pmail-summary-window (selected-window)))
1215 (select-window pmail-buffer-window
)
1217 ;; Is BOB visible in the buffer?
1219 (move-to-window-line 0)
1222 (select-window pmail-summary-window
)))
1223 (if (not pmail-summary-scroll-between-messages
)
1224 (error "Beginning of buffer")
1225 (pmail-summary-previous-msg (or dist
1)))
1226 (let ((other-window-scroll-buffer pmail-buffer
))
1227 (scroll-other-window-down dist
)))
1228 ;; If it isn't visible at all, show the beginning.
1229 (pmail-summary-beginning-of-message)))))
1231 (defun pmail-summary-beginning-of-message ()
1232 "Show current message from the beginning."
1234 (pmail-summary-show-message 'BEG
))
1236 (defun pmail-summary-end-of-message ()
1237 "Show bottom of current message."
1239 (pmail-summary-show-message 'END
))
1241 (defun pmail-summary-show-message (where)
1242 "Show current mail message.
1243 Position it according to WHERE which can be BEG or END"
1244 (if (and (one-window-p) (not pop-up-frames
))
1245 ;; If there is just one window, put the summary on the top.
1246 (let ((buffer pmail-buffer
))
1247 (split-window (selected-window) pmail-summary-window-size
)
1248 (select-window (frame-first-window))
1249 (pop-to-buffer pmail-buffer
)
1250 ;; If pop-to-buffer did not use that window, delete that
1251 ;; window. (This can happen if it uses another frame.)
1252 (or (eq buffer
(window-buffer (next-window (frame-first-window))))
1253 (delete-other-windows)))
1254 (pop-to-buffer pmail-buffer
))
1257 (goto-char (point-min))
1258 (search-forward "\n\n"))
1260 (goto-char (point-max))
1261 (recenter (1- (window-height))))
1263 (pop-to-buffer pmail-summary-buffer
))
1265 (defun pmail-summary-bury ()
1266 "Bury the Pmail buffer and the Pmail summary buffer."
1268 (let ((buffer-to-bury (current-buffer)))
1270 (while (setq window
(get-buffer-window pmail-buffer
))
1271 (set-window-buffer window
(other-buffer pmail-buffer
)))
1272 (bury-buffer pmail-buffer
))
1273 (switch-to-buffer (other-buffer buffer-to-bury
))
1274 (bury-buffer buffer-to-bury
)))
1276 (defun pmail-summary-quit ()
1277 "Quit out of Pmail and Pmail summary."
1279 (pmail-summary-wipe)
1282 (defun pmail-summary-wipe ()
1283 "Kill and wipe away Pmail summary, remaining within Pmail."
1285 (save-excursion (set-buffer pmail-buffer
) (setq pmail-summary-buffer nil
))
1286 (let ((local-pmail-buffer pmail-buffer
))
1287 (kill-buffer (current-buffer))
1288 ;; Delete window if not only one.
1289 (if (not (eq (selected-window) (next-window nil
'no-minibuf
)))
1291 ;; Switch windows to the pmail buffer, or switch to it in this window.
1292 (pop-to-buffer local-pmail-buffer
)))
1294 (defun pmail-summary-expunge ()
1295 "Actually erase all deleted messages and recompute summary headers."
1298 (set-buffer pmail-buffer
)
1299 (when (pmail-expunge-confirmed)
1300 (pmail-only-expunge)))
1301 (pmail-update-summary))
1303 (defun pmail-summary-expunge-and-save ()
1304 "Expunge and save PMAIL file."
1307 (set-buffer pmail-buffer
)
1308 (when (pmail-expunge-confirmed)
1309 (pmail-only-expunge)))
1310 (pmail-update-summary)
1312 (set-buffer pmail-buffer
)
1314 (set-buffer-modified-p nil
))
1316 (defun pmail-summary-get-new-mail (&optional file-name
)
1317 "Get new mail and recompute summary headers.
1319 Optionally you can specify the file to get new mail from. In this case,
1320 the file of new mail is not changed or deleted. Noninteractively, you can
1321 pass the inbox file name as an argument. Interactively, a prefix
1322 argument says to read a file name and use that file as the inbox."
1324 (list (if current-prefix-arg
1325 (read-file-name "Get new mail from file: "))))
1328 (set-buffer pmail-buffer
)
1329 (pmail-get-new-mail file-name
)
1330 ;; Get the proper new message number.
1331 (setq msg pmail-current-message
))
1332 ;; Make sure that message is displayed.
1334 (pmail-summary-goto-msg msg
))))
1336 (defun pmail-summary-input (filename)
1337 "Run Pmail on file FILENAME."
1338 (interactive "FRun pmail on PMAIL file: ")
1339 ;; We switch windows here, then display the other Pmail file there.
1340 (pop-to-buffer pmail-buffer
)
1343 (defun pmail-summary-first-message ()
1344 "Show first message in Pmail file from summary buffer."
1347 (beginning-of-buffer)))
1349 (defun pmail-summary-last-message ()
1350 "Show last message in Pmail file from summary buffer."
1356 (declare-function pmail-abort-edit
"pmailedit" ())
1357 (declare-function pmail-cease-edit
"pmailedit"())
1358 (declare-function pmail-set-label
"pmailkwd" (l state
&optional n
))
1359 (declare-function pmail-output-read-file-name
"pmailout" ())
1360 (declare-function pmail-output-read-pmail-file-name
"pmailout" ())
1361 (declare-function mail-send-and-exit
"sendmail" (&optional arg
))
1363 (defvar pmail-summary-edit-map nil
)
1364 (if pmail-summary-edit-map
1366 (setq pmail-summary-edit-map
1367 (nconc (make-sparse-keymap) text-mode-map
))
1368 (define-key pmail-summary-edit-map
"\C-c\C-c" 'pmail-cease-edit
)
1369 (define-key pmail-summary-edit-map
"\C-c\C-]" 'pmail-abort-edit
))
1371 (defun pmail-summary-edit-current-message ()
1372 "Edit the contents of this message."
1374 (pop-to-buffer pmail-buffer
)
1375 (pmail-edit-current-message)
1376 (use-local-map pmail-summary-edit-map
))
1378 (defun pmail-summary-cease-edit ()
1379 "Finish editing message, then go back to Pmail summary buffer."
1382 (pop-to-buffer pmail-summary-buffer
))
1384 (defun pmail-summary-abort-edit ()
1385 "Abort edit of current message; restore original contents.
1386 Go back to summary buffer."
1389 (pop-to-buffer pmail-summary-buffer
))
1391 (defun pmail-summary-search-backward (regexp &optional n
)
1392 "Show message containing next match for REGEXP.
1393 Prefix argument gives repeat count; negative argument means search
1394 backwards (through earlier messages).
1395 Interactively, empty argument means use same regexp used last time."
1397 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg
) 0))
1399 (concat (if reversep
"Reverse " "") "Pmail search (regexp"))
1403 (if pmail-search-last-regexp
1404 (concat ", default "
1405 pmail-search-last-regexp
"): ")
1407 (setq regexp
(read-string prompt
))
1408 (cond ((not (equal regexp
""))
1409 (setq pmail-search-last-regexp regexp
))
1410 ((not pmail-search-last-regexp
)
1411 (error "No previous Pmail search string")))
1412 (list pmail-search-last-regexp
1413 (prefix-numeric-value current-prefix-arg
))))
1414 ;; Don't use save-excursion because that prevents point from moving
1415 ;; properly in the summary buffer.
1416 (let ((buffer (current-buffer)))
1419 (set-buffer pmail-buffer
)
1420 (pmail-search regexp
(- n
)))
1421 (set-buffer buffer
))))
1423 (defun pmail-summary-search (regexp &optional n
)
1424 "Show message containing next match for REGEXP.
1425 Prefix argument gives repeat count; negative argument means search
1426 backwards (through earlier messages).
1427 Interactively, empty argument means use same regexp used last time."
1429 (let* ((reversep (< (prefix-numeric-value current-prefix-arg
) 0))
1431 (concat (if reversep
"Reverse " "") "Pmail search (regexp"))
1435 (if pmail-search-last-regexp
1436 (concat ", default "
1437 pmail-search-last-regexp
"): ")
1439 (setq regexp
(read-string prompt
))
1440 (cond ((not (equal regexp
""))
1441 (setq pmail-search-last-regexp regexp
))
1442 ((not pmail-search-last-regexp
)
1443 (error "No previous Pmail search string")))
1444 (list pmail-search-last-regexp
1445 (prefix-numeric-value current-prefix-arg
))))
1446 ;; Don't use save-excursion because that prevents point from moving
1447 ;; properly in the summary buffer.
1448 (let ((buffer (current-buffer)))
1451 (set-buffer pmail-buffer
)
1452 (pmail-search regexp n
))
1453 (set-buffer buffer
))))
1455 (defun pmail-summary-toggle-header ()
1456 "Show original message header if pruned header currently shown, or vice versa."
1458 (save-window-excursion
1459 (set-buffer pmail-buffer
)
1460 (pmail-toggle-header))
1461 ;; Inside save-excursion, some changes to point in the PMAIL buffer are lost.
1462 ;; Set point to point-min in the PMAIL buffer, if it is visible.
1463 (let ((window (get-buffer-window pmail-buffer
)))
1465 ;; Using save-window-excursion would lose the new value of point.
1466 (let ((owin (selected-window)))
1469 (select-window window
)
1470 (goto-char (point-min)))
1471 (select-window owin
))))))
1474 (defun pmail-summary-add-label (label)
1475 "Add LABEL to labels associated with current Pmail message.
1476 Completion is performed over known labels when reading."
1477 (interactive (list (save-excursion
1478 (set-buffer pmail-buffer
)
1479 (pmail-read-label "Add label"))))
1481 (set-buffer pmail-buffer
)
1482 (pmail-add-label label
)))
1484 (defun pmail-summary-kill-label (label)
1485 "Remove LABEL from labels associated with current Pmail message.
1486 Completion is performed over known labels when reading."
1487 (interactive (list (save-excursion
1488 (set-buffer pmail-buffer
)
1489 (pmail-read-label "Kill label"))))
1491 (set-buffer pmail-buffer
)
1492 (pmail-set-label label nil
)))
1494 ;;;; *** Pmail Summary Mailing Commands ***
1496 (defun pmail-summary-override-mail-send-and-exit ()
1497 "Replace bindings to `mail-send-and-exit' with `pmail-summary-send-and-exit'."
1498 (use-local-map (copy-keymap (current-local-map)))
1499 (dolist (key (where-is-internal 'mail-send-and-exit
))
1500 (define-key (current-local-map) key
'pmail-summary-send-and-exit
)))
1502 (defun pmail-summary-mail ()
1503 "Send mail in another window.
1504 While composing the message, use \\[mail-yank-original] to yank the
1505 original message into it."
1507 (let ((window (get-buffer-window pmail-buffer
)))
1509 (select-window window
)
1510 (set-buffer pmail-buffer
)))
1511 (pmail-start-mail nil nil nil nil nil
(current-buffer))
1512 (pmail-summary-override-mail-send-and-exit))
1514 (defun pmail-summary-continue ()
1515 "Continue composing outgoing message previously being composed."
1517 (let ((window (get-buffer-window pmail-buffer
)))
1519 (select-window window
)
1520 (set-buffer pmail-buffer
)))
1521 (pmail-start-mail t
))
1523 (defun pmail-summary-reply (just-sender)
1524 "Reply to the current message.
1525 Normally include CC: to all other recipients of original message;
1526 prefix argument means ignore them. While composing the reply,
1527 use \\[mail-yank-original] to yank the original message into it."
1529 (let ((window (get-buffer-window pmail-buffer
)))
1531 (select-window window
)
1532 (set-buffer pmail-buffer
)))
1533 (pmail-reply just-sender
)
1534 (pmail-summary-override-mail-send-and-exit))
1536 (defun pmail-summary-retry-failure ()
1537 "Edit a mail message which is based on the contents of the current message.
1538 For a message rejected by the mail system, extract the interesting headers and
1539 the body of the original message; otherwise copy the current message."
1541 (let ((window (get-buffer-window pmail-buffer
)))
1543 (select-window window
)
1544 (set-buffer pmail-buffer
)))
1545 (pmail-retry-failure)
1546 (pmail-summary-override-mail-send-and-exit))
1548 (defun pmail-summary-send-and-exit ()
1549 "Send mail reply and return to summary buffer."
1551 (mail-send-and-exit t
))
1553 (defun pmail-summary-forward (resend)
1554 "Forward the current message to another user.
1555 With prefix argument, \"resend\" the message instead of forwarding it;
1556 see the documentation of `pmail-resend'."
1559 (let ((window (get-buffer-window pmail-buffer
)))
1561 (select-window window
)
1562 (set-buffer pmail-buffer
)))
1563 (pmail-forward resend
)
1564 (pmail-summary-override-mail-send-and-exit)))
1566 (defun pmail-summary-resend ()
1567 "Resend current message using `pmail-resend'."
1570 (let ((window (get-buffer-window pmail-buffer
)))
1572 (select-window window
)
1573 (set-buffer pmail-buffer
)))
1574 (call-interactively 'pmail-resend
)))
1576 ;; Summary output commands.
1578 (defun pmail-summary-output-to-babyl-file (&optional file-name n
)
1579 "Append the current message to an Pmail file named FILE-NAME.
1580 If the file does not exist, ask if it should be created.
1581 If file is being visited, the message is appended to the Emacs
1582 buffer visiting that file.
1584 A prefix argument N says to output N consecutive messages
1585 starting with the current one. Deleted messages are skipped and don't count."
1587 (progn (require 'pmailout
)
1588 (list (pmail-output-read-pmail-file-name)
1589 (prefix-numeric-value current-prefix-arg
))))
1590 (let ((i 0) prev-msg
)
1593 (progn (pmail-summary-goto-msg)
1596 (with-current-buffer pmail-buffer
1597 pmail-current-message
))))))
1599 (with-current-buffer pmail-buffer
1600 (let ((pmail-delete-after-output nil
))
1601 (pmail-output-to-babyl-file file-name
1)))
1602 (if pmail-delete-after-output
1603 (pmail-summary-delete-forward nil
)
1605 (pmail-summary-next-msg 1))))))
1607 (defalias 'pmail-summary-output-to-pmail-file
1608 'pmail-summary-output-to-babyl-file
)
1610 (defun pmail-summary-output (&optional file-name n
)
1611 "Append this message to Unix mail file named FILE-NAME.
1613 A prefix argument N says to output N consecutive messages
1614 starting with the current one. Deleted messages are skipped and don't count."
1616 (progn (require 'pmailout
)
1617 (list (pmail-output-read-file-name)
1618 (prefix-numeric-value current-prefix-arg
))))
1619 (let ((i 0) prev-msg
)
1622 (progn (pmail-summary-goto-msg)
1625 (with-current-buffer pmail-buffer
1626 pmail-current-message
))))))
1628 (with-current-buffer pmail-buffer
1629 (let ((pmail-delete-after-output nil
))
1630 (pmail-output file-name
1)))
1631 (if pmail-delete-after-output
1632 (pmail-summary-delete-forward nil
)
1634 (pmail-summary-next-msg 1))))))
1636 (defun pmail-summary-output-menu ()
1637 "Output current message to another Pmail file, chosen with a menu.
1638 Also set the default for subsequent \\[pmail-output-to-babyl-file] commands.
1639 The variables `pmail-secondary-file-directory' and
1640 `pmail-secondary-file-regexp' control which files are offered in the menu."
1643 (set-buffer pmail-buffer
)
1644 (let ((pmail-delete-after-output nil
))
1645 (call-interactively 'pmail-output-menu
)))
1646 (if pmail-delete-after-output
1647 (pmail-summary-delete-forward nil
)))
1649 (defun pmail-summary-construct-io-menu ()
1650 (let ((files (pmail-find-all-files pmail-secondary-file-directory
)))
1653 (define-key pmail-summary-mode-map
[menu-bar classify input-menu
]
1654 (cons "Input Pmail File"
1655 (pmail-list-to-menu "Input Pmail File"
1657 'pmail-summary-input
)))
1658 (define-key pmail-summary-mode-map
[menu-bar classify output-menu
]
1659 (cons "Output Pmail File"
1660 (pmail-list-to-menu "Output Pmail File"
1662 'pmail-summary-output-to-babyl-file
))))
1663 (define-key pmail-summary-mode-map
[menu-bar classify input-menu
]
1664 '("Input Pmail File" . pmail-disable-menu
))
1665 (define-key pmail-summary-mode-map
[menu-bar classify output-menu
]
1666 '("Output Pmail File" . pmail-disable-menu
)))))
1668 (defun pmail-summary-output-body (&optional file-name
)
1669 "Write this message body to the file FILE-NAME.
1670 FILE-NAME defaults, interactively, from the Subject field of the message."
1673 (set-buffer pmail-buffer
)
1674 (let ((pmail-delete-after-output nil
))
1676 (pmail-output-body-to-file file-name
)
1677 (call-interactively 'pmail-output-body-to-file
))))
1678 (if pmail-delete-after-output
1679 (pmail-summary-delete-forward nil
)))
1681 ;; Sorting messages in Pmail Summary buffer.
1683 (defun pmail-summary-sort-by-date (reverse)
1684 "Sort messages of current Pmail summary by date.
1685 If prefix argument REVERSE is non-nil, sort them in reverse order."
1687 (pmail-sort-from-summary (function pmail-sort-by-date
) reverse
))
1689 (defun pmail-summary-sort-by-subject (reverse)
1690 "Sort messages of current Pmail summary by subject.
1691 If prefix argument REVERSE is non-nil, sort them in reverse order."
1693 (pmail-sort-from-summary (function pmail-sort-by-subject
) reverse
))
1695 (defun pmail-summary-sort-by-author (reverse)
1696 "Sort messages of current Pmail summary by author.
1697 If prefix argument REVERSE is non-nil, sort them in reverse order."
1699 (pmail-sort-from-summary (function pmail-sort-by-author
) reverse
))
1701 (defun pmail-summary-sort-by-recipient (reverse)
1702 "Sort messages of current Pmail summary by recipient.
1703 If prefix argument REVERSE is non-nil, sort them in reverse order."
1705 (pmail-sort-from-summary (function pmail-sort-by-recipient
) reverse
))
1707 (defun pmail-summary-sort-by-correspondent (reverse)
1708 "Sort messages of current Pmail summary by other correspondent.
1709 If prefix argument REVERSE is non-nil, sort them in reverse order."
1711 (pmail-sort-from-summary (function pmail-sort-by-correspondent
) reverse
))
1713 (defun pmail-summary-sort-by-lines (reverse)
1714 "Sort messages of current Pmail summary by lines of the message.
1715 If prefix argument REVERSE is non-nil, sort them in reverse order."
1717 (pmail-sort-from-summary (function pmail-sort-by-lines
) reverse
))
1719 (defun pmail-summary-sort-by-labels (reverse labels
)
1720 "Sort messages of current Pmail summary by labels.
1721 If prefix argument REVERSE is non-nil, sort them in reverse order.
1722 KEYWORDS is a comma-separated list of labels."
1723 (interactive "P\nsSort by labels: ")
1724 (pmail-sort-from-summary
1725 (function (lambda (reverse)
1726 (pmail-sort-by-labels reverse labels
)))
1729 (defun pmail-sort-from-summary (sortfun reverse
)
1730 "Sort Pmail messages from Summary buffer and update it after sorting."
1731 (require 'pmailsort
)
1732 (let ((selwin (selected-window)))
1734 (progn (pop-to-buffer pmail-buffer
)
1735 (funcall sortfun reverse
))
1736 (select-window selwin
))))
1741 ;; change-log-default-name: "ChangeLog.pmail"
1744 ;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
1745 ;;; pmailsum.el ends here