Formatting fix, for AUTHORS.
[emacs.git] / lisp / mail / pmailsum.el
blobeaf3975d9a4117cff663f8fc1c3236982e24d775
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 Free Software Foundation, Inc.
6 ;; Maintainer: FSF
7 ;; Keywords: mail
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/>.
24 ;;; Commentary:
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.
30 ;;; Code:
32 (defvar msgnum)
34 ;; For pmail-select-summary
35 (require 'pmail)
37 ;;;###autoload
38 (defcustom pmail-summary-scroll-between-messages t
39 "*Non-nil means Pmail summary scroll commands move between messages."
40 :type 'boolean
41 :group 'pmail-summary)
43 ;;;###autoload
44 (defcustom pmail-summary-line-count-flag t
45 "*Non-nil means Pmail summary should show the number of lines in each message."
46 :type 'boolean
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)))
73 ;;;###autoload
74 (defun pmail-summary ()
75 "Display a summary of all messages, one line per message."
76 (interactive)
77 (pmail-new-summary "All" '(pmail-summary) nil)
78 (unless (get-buffer-window pmail-buffer)
79 (pmail-summary-beginning-of-message)))
81 ;;;###autoload
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) "\\),")))
95 ;;;###autoload
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")
103 (pmail-new-summary
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))
109 ;;;###autoload
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
123 regexp))
125 ;; pmail-summary-by-topic
126 ;; 1989 R.A. Schnitzler
128 ;;;###autoload
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."
135 (interactive
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" "")
142 "): ")))
143 (list (read-string prompt nil nil subject) current-prefix-arg)))
144 (pmail-new-summary
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)
151 (save-restriction
152 (goto-char (pmail-msgbeg msg))
153 (search-forward "\n*** EOOH ***\n" (pmail-msgend msg) 'move)
154 (narrow-to-region
155 (point)
156 (progn (search-forward (if whole-message "\^_" "\n\n")) (point)))
157 (goto-char (point-min))
158 (if whole-message (re-search-forward subject nil t)
159 (string-match subject (let ((subj (mail-fetch-field "Subject")))
160 (if subj
161 (funcall pmail-summary-line-decoder subj)
162 ""))))))
164 ;;;###autoload
165 (defun pmail-summary-by-senders (senders)
166 "Display a summary of all messages with the given SENDERS.
167 SENDERS is a string of names separated by commas."
168 (interactive "sSenders to summarize by: ")
169 (pmail-new-summary
170 (concat "senders " senders)
171 (list 'pmail-summary-by-senders senders)
172 'pmail-message-senders-p
173 (mail-comma-list-regexp senders)))
175 (defun pmail-message-senders-p (msg senders)
176 (save-restriction
177 (goto-char (pmail-msgbeg msg))
178 (search-forward "\n*** EOOH ***\n")
179 (narrow-to-region (point) (progn (search-forward "\n\n") (point)))
180 (string-match senders (or (mail-fetch-field "From") ""))))
182 ;; General making of a summary buffer.
184 (defvar pmail-summary-symbol-number 0)
186 (defvar pmail-new-summary-line-count)
188 (defun pmail-new-summary (desc redo func &rest args)
189 "Create a summary of selected messages.
190 DESC makes part of the mode line of the summary buffer. REDO is form ...
191 For each message, FUNC is applied to the message number and ARGS...
192 and if the result is non-nil, that message is included.
193 nil for FUNCTION means all messages."
194 (message "Computing summary lines...")
195 (unless pmail-buffer
196 (error "No PMAIL buffer found"))
197 (let (mesg was-in-summary)
198 (if (eq major-mode 'pmail-summary-mode)
199 (setq was-in-summary t))
200 (with-current-buffer pmail-buffer
201 (setq mesg pmail-current-message
202 pmail-summary-buffer (pmail-new-summary-1 desc redo func args)))
203 ;; Now display the summary buffer and go to the right place in it.
204 (unless was-in-summary
205 (if (and (one-window-p)
206 pop-up-windows
207 (not pop-up-frames))
208 ;; If there is just one window, put the summary on the top.
209 (progn
210 (split-window (selected-window) pmail-summary-window-size)
211 (select-window (next-window (frame-first-window)))
212 (pop-to-buffer pmail-summary-buffer)
213 ;; If pop-to-buffer did not use that window, delete that
214 ;; window. (This can happen if it uses another frame.)
215 (if (not (eq pmail-summary-buffer
216 (window-buffer (frame-first-window))))
217 (delete-other-windows)))
218 (pop-to-buffer pmail-summary-buffer))
219 (set-buffer pmail-buffer)
220 ;; This is how pmail makes the summary buffer reappear.
221 ;; We do this here to make the window the proper size.
222 (pmail-select-summary nil)
223 (set-buffer pmail-summary-buffer))
224 (pmail-summary-goto-msg mesg t t)
225 (pmail-summary-construct-io-menu)
226 (message "Computing summary lines...done")))
228 (defun pmail-new-summary-1 (description form function &rest args)
229 "Filter messages to obtain summary lines.
230 DESCRIPTION is added to the mode line.
232 Return the summary buffer by invoking FUNCTION on each message
233 passing the message number and ARGS...
235 REDO is a form ...
237 The current buffer must be a Pmail buffer either containing a
238 collection of mbox formatted messages or displaying a single
239 message."
240 (let ((summary-msgs ())
241 (pmail-new-summary-line-count 0)
242 (sumbuf (pmail-get-create-summary-buffer)))
243 (let ((swap (pmail-use-collection-buffer))
244 (msgnum 1)
245 (buffer-read-only nil)
246 (old-min (point-min-marker))
247 (old-max (point-max-marker)))
248 ;; Can't use save-restriction here; that doesn't work if we
249 ;; plan to modify text outside the original restriction.
250 (save-excursion
251 (widen)
252 (goto-char (point-min))
253 (while (>= pmail-total-messages msgnum)
254 (if (or (null function)
255 (apply function (cons msgnum args)))
256 (setq summary-msgs
257 (cons (cons msgnum (pmail-get-summary msgnum))
258 summary-msgs)))
259 (setq msgnum (1+ msgnum))
260 ;; Provide a periodic User progress message.
261 (if (zerop (% pmail-new-summary-line-count 10))
262 (message "Computing summary lines...%d"
263 pmail-new-summary-line-count)))
264 (setq summary-msgs (nreverse summary-msgs)))
265 (narrow-to-region old-min old-max))
267 ;; Temporarily, while summary buffer is unfinished,
268 ;; we "don't have" a summary.
270 ;; I have not a clue what this clause is doing. If you read this
271 ;; chunk of code and have a clue, then please email that clue to
272 ;; pmr@pajato.com
273 (setq pmail-summary-buffer nil)
274 (if pmail-enable-mime
275 (with-current-buffer pmail-buffer
276 (setq pmail-summary-buffer nil)))
278 (save-excursion
279 (let ((rbuf (current-buffer))
280 (total pmail-total-messages))
281 (set-buffer sumbuf)
282 ;; Set up the summary buffer's contents.
283 (let ((buffer-read-only nil))
284 (erase-buffer)
285 (while summary-msgs
286 (princ (cdr (car summary-msgs)) sumbuf)
287 (setq summary-msgs (cdr summary-msgs)))
288 (goto-char (point-min)))
289 ;; Set up the rest of its state and local variables.
290 (setq buffer-read-only t)
291 (pmail-summary-mode)
292 (make-local-variable 'minor-mode-alist)
293 (setq minor-mode-alist (list (list t (concat ": " description))))
294 (setq pmail-buffer rbuf
295 pmail-summary-redo form
296 pmail-total-messages total)))
297 sumbuf))
299 (defun pmail-get-create-summary-buffer ()
300 "Obtain a summary buffer by re-using an existing summary
301 buffer, or by creating a new summary buffer."
302 (if (and pmail-summary-buffer (buffer-name pmail-summary-buffer))
303 pmail-summary-buffer
304 (generate-new-buffer (concat (buffer-name) "-summary"))))
307 ;; Low levels of generating a summary.
309 (defun pmail-get-summary (msgnum)
310 "Return the summary line for message MSGNUM.
311 If the message has a summary line already, it will be stored in
312 the message as a header and simply returned, otherwise the
313 summary line is created, saved in the message header, cached and
314 returned.
316 The current buffer contains the unrestricted message collection."
317 (let ((line (aref pmail-summary-vector (1- msgnum))))
318 (unless line
319 ;; Register a summary line for MSGNUM.
320 (setq pmail-new-summary-line-count (1+ pmail-new-summary-line-count)
321 line (pmail-get-create-summary-line msgnum))
322 ;; Cache the summary line for use during this Pmail session.
323 (aset pmail-summary-vector (1- msgnum) line))
324 line))
326 ;;;###autoload
327 (defcustom pmail-summary-line-decoder (function identity)
328 "*Function to decode summary-line.
330 By default, `identity' is set."
331 :type 'function
332 :group 'pmail-summary)
334 (defun pmail-get-create-summary-line (msgnum)
335 "Return the summary line for message MSGNUM.
336 Obtain the message summary from the header if it is available
337 otherwise create it and store it in the message header.
339 The current buffer contains the unrestricted message collection."
340 (let ((beg (pmail-msgbeg msgnum))
341 (end (pmail-msgend msgnum)))
342 (goto-char beg)
343 (if (search-forward "\n\n" end t)
344 (save-restriction
345 (narrow-to-region beg (point))
346 ;; Generate a status line from the message and put it in the
347 ;; message.
348 (pmail-create-summary msgnum))
349 (pmail-error-bad-format msgnum))))
351 (defun pmail-get-summary-labels ()
352 "Return a coded string wrapped in curly braces denoting the status labels.
354 The current buffer is narrowed to the message headers for
355 the message being processed."
356 (let ((status (mail-fetch-field pmail-attribute-header))
357 (index 0)
358 (result "")
359 char)
360 ;; Strip off the read/unread and the deleted attribute which are
361 ;; handled separately.
362 (setq status
363 (if status
364 (concat (substring status 0 1) (substring status 2 6))
365 ""))
366 (while (< index (length status))
367 (unless (string= "-" (setq char (substring status index (1+ index))))
368 (setq result (concat result char)))
369 (setq index (1+ index)))
370 (when (> (length result) 0)
371 (setq result (concat "{" result "}")))
372 result))
374 (defun pmail-create-summary (msgnum)
375 "Return the summary line for message MSGNUM.
376 The current buffer is narrowed to the header for message MSGNUM."
377 (goto-char (point-min))
378 (let ((line (pmail-make-basic-summary-line))
379 (labels (pmail-get-summary-labels))
380 pos prefix status suffix)
381 (setq pos (string-match "#" line)
382 status (cond
383 ((pmail-message-deleted-p msgnum) ?D)
384 ((pmail-message-unseen-p msgnum) ?-)
385 (t ? ))
386 prefix (format "%5d%c %s" msgnum status (substring line 0 pos))
387 suffix (substring line (1+ pos)))
388 (funcall pmail-summary-line-decoder (concat prefix labels suffix))))
390 ;;;###autoload
391 (defcustom pmail-user-mail-address-regexp nil
392 "*Regexp matching user mail addresses.
393 If non-nil, this variable is used to identify the correspondent
394 when receiving new mail. If it matches the address of the sender,
395 the recipient is taken as correspondent of a mail.
396 If nil \(default value\), your `user-login-name' and `user-mail-address'
397 are used to exclude yourself as correspondent.
399 Usually you don't have to set this variable, except if you collect mails
400 sent by you under different user names.
401 Then it should be a regexp matching your mail addresses.
403 Setting this variable has an effect only before reading a mail."
404 :type '(choice (const :tag "None" nil) regexp)
405 :group 'pmail-retrieve
406 :version "21.1")
408 (defun pmail-make-basic-summary-line ()
409 (goto-char (point-min))
410 (concat (save-excursion
411 (if (not (re-search-forward "^Date:" nil t))
413 (cond ((re-search-forward "\\([^0-9:]\\)\\([0-3]?[0-9]\\)\\([- \t_]+\\)\\([adfjmnos][aceopu][bcglnprtvy]\\)"
414 (save-excursion (end-of-line) (point)) t)
415 (format "%2d-%3s"
416 (string-to-number (buffer-substring
417 (match-beginning 2)
418 (match-end 2)))
419 (buffer-substring
420 (match-beginning 4) (match-end 4))))
421 ((re-search-forward "\\([^a-z]\\)\\([adfjmnos][acepou][bcglnprtvy]\\)\\([-a-z \t_]*\\)\\([0-9][0-9]?\\)"
422 (save-excursion (end-of-line) (point)) t)
423 (format "%2d-%3s"
424 (string-to-number (buffer-substring
425 (match-beginning 4)
426 (match-end 4)))
427 (buffer-substring
428 (match-beginning 2) (match-end 2))))
429 ((re-search-forward "\\(19\\|20\\)\\([0-9][0-9]\\)-\\([01][0-9]\\)-\\([0-3][0-9]\\)"
430 (save-excursion (end-of-line) (point)) t)
431 (format "%2s%2s%2s"
432 (buffer-substring
433 (match-beginning 2) (match-end 2))
434 (buffer-substring
435 (match-beginning 3) (match-end 3))
436 (buffer-substring
437 (match-beginning 4) (match-end 4))))
438 (t "??????"))))
440 (save-excursion
441 (let* ((from (and (re-search-forward "^From:[ \t]*" nil t)
442 (mail-strip-quoted-names
443 (buffer-substring
444 (1- (point))
445 ;; Get all the lines of the From field
446 ;; so that we get a whole comment if there is one,
447 ;; so that mail-strip-quoted-names can discard it.
448 (let ((opoint (point)))
449 (while (progn (forward-line 1)
450 (looking-at "[ \t]")))
451 ;; Back up over newline, then trailing spaces or tabs
452 (forward-char -1)
453 (skip-chars-backward " \t")
454 (point))))))
455 len mch lo)
456 (if (or (null from)
457 (string-match
458 (or pmail-user-mail-address-regexp
459 (concat "^\\("
460 (regexp-quote (user-login-name))
461 "\\($\\|@\\)\\|"
462 (regexp-quote
463 ;; Don't lose if run from init file
464 ;; where user-mail-address is not
465 ;; set yet.
466 (or user-mail-address
467 (concat (user-login-name) "@"
468 (or mail-host-address
469 (system-name)))))
470 "\\>\\)"))
471 from))
472 ;; No From field, or it's this user.
473 (save-excursion
474 (goto-char (point-min))
475 (if (not (re-search-forward "^To:[ \t]*" nil t))
477 (setq from
478 (concat "to: "
479 (mail-strip-quoted-names
480 (buffer-substring
481 (point)
482 (progn (end-of-line)
483 (skip-chars-backward " \t")
484 (point)))))))))
485 (if (null from)
487 (setq len (length from))
488 (setq mch (string-match "[@%]" from))
489 (format "%25s"
490 (if (or (not mch) (<= len 25))
491 (substring from (max 0 (- len 25)))
492 (substring from
493 (setq lo (cond ((< (- mch 14) 0) 0)
494 ((< len (+ mch 11))
495 (- len 25))
496 (t (- mch 14))))
497 (min len (+ lo 25))))))))
498 (if pmail-summary-line-count-flag
499 (save-excursion
500 (save-restriction
501 (widen)
502 (let ((beg (pmail-msgbeg msgnum))
503 (end (pmail-msgend msgnum))
504 lines)
505 (save-excursion
506 (goto-char beg)
507 ;; Count only lines in the reformatted header,
508 ;; if we have reformatted it.
509 (search-forward "\n*** EOOH ***\n" end t)
510 (setq lines (count-lines (point) end)))
511 (format (cond
512 ((<= lines 9) " [%d]")
513 ((<= lines 99) " [%d]")
514 ((<= lines 999) " [%3d]")
515 (t "[%d]"))
516 lines))))
517 " ")
518 " #" ;The # is part of the format.
519 (if (re-search-forward "^Subject:" nil t)
520 (progn (skip-chars-forward " \t")
521 (buffer-substring (point)
522 (progn (end-of-line)
523 (point))))
524 (re-search-forward "[\n][\n]+" nil t)
525 (buffer-substring (point) (progn (end-of-line) (point))))
526 "\n"))
528 ;; Simple motion in a summary buffer.
530 (defun pmail-summary-next-all (&optional number)
531 (interactive "p")
532 (forward-line (if number number 1))
533 ;; It doesn't look nice to move forward past the last message line.
534 (and (eobp) (> number 0)
535 (forward-line -1))
536 (display-buffer pmail-buffer))
538 (defun pmail-summary-previous-all (&optional number)
539 (interactive "p")
540 (forward-line (- (if number number 1)))
541 ;; It doesn't look nice to move forward past the last message line.
542 (and (eobp) (< number 0)
543 (forward-line -1))
544 (display-buffer pmail-buffer))
546 (defun pmail-summary-next-msg (&optional number)
547 "Display next non-deleted msg from pmail file.
548 With optional prefix argument NUMBER, moves forward this number of non-deleted
549 messages, or backward if NUMBER is negative."
550 (interactive "p")
551 (forward-line 0)
552 (and (> number 0) (end-of-line))
553 (let ((count (if (< number 0) (- number) number))
554 (search (if (> number 0) 're-search-forward 're-search-backward))
555 (non-del-msg-found nil))
556 (while (and (> count 0) (setq non-del-msg-found
557 (or (funcall search "^.....[^D]" nil t)
558 non-del-msg-found)))
559 (setq count (1- count))))
560 (beginning-of-line)
561 (display-buffer pmail-buffer))
563 (defun pmail-summary-previous-msg (&optional number)
564 "Display previous non-deleted msg from pmail file.
565 With optional prefix argument NUMBER, moves backward this number of
566 non-deleted messages."
567 (interactive "p")
568 (pmail-summary-next-msg (- (if number number 1))))
570 (defun pmail-summary-next-labeled-message (n labels)
571 "Show next message with LABELS. Defaults to last labels used.
572 With prefix argument N moves forward N messages with these labels."
573 (interactive "p\nsMove to next msg with labels: ")
574 (let (msg)
575 (save-excursion
576 (set-buffer pmail-buffer)
577 (pmail-next-labeled-message n labels)
578 (setq msg pmail-current-message))
579 (pmail-summary-goto-msg msg)))
581 (defun pmail-summary-previous-labeled-message (n labels)
582 "Show previous message with LABELS. Defaults to last labels used.
583 With prefix argument N moves backward N messages with these labels."
584 (interactive "p\nsMove to previous msg with labels: ")
585 (let (msg)
586 (save-excursion
587 (set-buffer pmail-buffer)
588 (pmail-previous-labeled-message n labels)
589 (setq msg pmail-current-message))
590 (pmail-summary-goto-msg msg)))
592 (defun pmail-summary-next-same-subject (n)
593 "Go to the next message in the summary having the same subject.
594 With prefix argument N, do this N times.
595 If N is negative, go backwards."
596 (interactive "p")
597 (let ((forward (> n 0))
598 search-regexp i found)
599 (with-current-buffer pmail-buffer
600 (setq search-regexp (pmail-current-subject-regexp)
601 i pmail-current-message))
602 (save-excursion
603 (while (and (/= n 0)
604 (if forward
605 (not (eobp))
606 (not (bobp))))
607 (let (done)
608 (while (and (not done)
609 (if forward
610 (not (eobp))
611 (not (bobp))))
612 ;; Advance thru summary.
613 (forward-line (if forward 1 -1))
614 ;; Get msg number of this line.
615 (setq i (string-to-number
616 (buffer-substring (point)
617 (min (point-max) (+ 6 (point))))))
618 ;; See if that msg has desired subject.
619 (save-excursion
620 (set-buffer pmail-buffer)
621 (save-restriction
622 (widen)
623 (goto-char (pmail-msgbeg i))
624 (search-forward "\n*** EOOH ***\n")
625 (let ((beg (point)) end)
626 (search-forward "\n\n")
627 (setq end (point))
628 (goto-char beg)
629 (setq done (re-search-forward search-regexp end t))))))
630 (if done (setq found i)))
631 (setq n (if forward (1- n) (1+ n)))))
632 (if found
633 (pmail-summary-goto-msg found)
634 (error "No %s message with same subject"
635 (if forward "following" "previous")))))
637 (defun pmail-summary-previous-same-subject (n)
638 "Go to the previous message in the summary having the same subject.
639 With prefix argument N, do this N times.
640 If N is negative, go forwards instead."
641 (interactive "p")
642 (pmail-summary-next-same-subject (- n)))
644 ;; Delete and undelete summary commands.
646 (defun pmail-summary-delete-forward (&optional count)
647 "Delete this message and move to next nondeleted one.
648 Deleted messages stay in the file until the \\[pmail-expunge] command is given.
649 A prefix argument serves as a repeat count;
650 a negative argument means to delete and move backward."
651 (interactive "p")
652 (unless (numberp count) (setq count 1))
653 (let (end del-msg
654 (backward (< count 0)))
655 (while (/= count 0)
656 (pmail-summary-goto-msg)
657 (with-current-buffer pmail-buffer
658 (pmail-delete-message)
659 (setq del-msg pmail-current-message))
660 (pmail-summary-mark-deleted del-msg)
661 (while (and (not (if backward (bobp) (eobp)))
662 (save-excursion (beginning-of-line)
663 (looking-at " *[0-9]+D")))
664 (forward-line (if backward -1 1)))
665 ;; It looks ugly to move to the empty line at end of buffer.
666 (and (eobp) (not backward)
667 (forward-line -1))
668 (setq count
669 (if (> count 0) (1- count) (1+ count))))))
671 (defun pmail-summary-delete-backward (&optional count)
672 "Delete this message and move to previous nondeleted one.
673 Deleted messages stay in the file until the \\[pmail-expunge] command is given.
674 A prefix argument serves as a repeat count;
675 a negative argument means to delete and move forward."
676 (interactive "p")
677 (pmail-summary-delete-forward (- count)))
679 (defun pmail-summary-mark-deleted (&optional n undel)
680 ;; Since third arg is t, this only alters the summary, not the Pmail buf.
681 (and n (pmail-summary-goto-msg n t t))
682 (or (eobp)
683 (not (overlay-get pmail-summary-overlay 'face))
684 (let ((buffer-read-only nil))
685 (skip-chars-forward " ")
686 (skip-chars-forward "[0-9]")
687 (if undel
688 (if (looking-at "D")
689 (progn (delete-char 1) (insert " ")))
690 (delete-char 1)
691 (insert "D"))))
692 (beginning-of-line))
694 (defun pmail-summary-mark-undeleted (n)
695 (pmail-summary-mark-deleted n t))
697 (defun pmail-summary-deleted-p (&optional n)
698 (save-excursion
699 (and n (pmail-summary-goto-msg n nil t))
700 (skip-chars-forward " ")
701 (skip-chars-forward "[0-9]")
702 (looking-at "D")))
704 (defun pmail-summary-undelete (&optional arg)
705 "Undelete current message.
706 Optional prefix ARG means undelete ARG previous messages."
707 (interactive "p")
708 (if (/= arg 1)
709 (pmail-summary-undelete-many arg)
710 (let ((buffer-read-only nil)
711 (opoint (point)))
712 (end-of-line)
713 (cond ((re-search-backward "\\(^ *[0-9]*\\)\\(D\\)" nil t)
714 (replace-match "\\1 ")
715 (pmail-summary-goto-msg)
716 (if pmail-enable-mime
717 (set-buffer pmail-buffer)
718 (pop-to-buffer pmail-buffer))
719 (and (pmail-message-deleted-p pmail-current-message)
720 (pmail-undelete-previous-message))
721 (if pmail-enable-mime
722 (pop-to-buffer pmail-buffer))
723 (pop-to-buffer pmail-summary-buffer))
724 (t (goto-char opoint))))))
726 (defun pmail-summary-undelete-many (&optional n)
727 "Undelete all deleted msgs, optional prefix arg N means undelete N prev msgs."
728 (interactive "P")
729 (save-excursion
730 (set-buffer pmail-buffer)
731 (let* ((init-msg (if n pmail-current-message pmail-total-messages))
732 (pmail-current-message init-msg)
733 (n (or n pmail-total-messages))
734 (msgs-undeled 0))
735 (while (and (> pmail-current-message 0)
736 (< msgs-undeled n))
737 (if (pmail-message-deleted-p pmail-current-message)
738 (progn (pmail-set-attribute "deleted" nil)
739 (setq msgs-undeled (1+ msgs-undeled))))
740 (setq pmail-current-message (1- pmail-current-message)))
741 (set-buffer pmail-summary-buffer)
742 (setq pmail-current-message init-msg msgs-undeled 0)
743 (while (and (> pmail-current-message 0)
744 (< msgs-undeled n))
745 (if (pmail-summary-deleted-p pmail-current-message)
746 (progn (pmail-summary-mark-undeleted pmail-current-message)
747 (setq msgs-undeled (1+ msgs-undeled))))
748 (setq pmail-current-message (1- pmail-current-message))))
749 (pmail-summary-goto-msg)))
751 ;; Pmail Summary mode is suitable only for specially formatted data.
752 (put 'pmail-summary-mode 'mode-class 'special)
754 (defun pmail-summary-mode ()
755 "Pmail Summary Mode is invoked from Pmail Mode by using \\<pmail-mode-map>\\[pmail-summary].
756 As commands are issued in the summary buffer, they are applied to the
757 corresponding mail messages in the pmail buffer.
759 All normal editing commands are turned off.
760 Instead, nearly all the Pmail mode commands are available,
761 though many of them move only among the messages in the summary.
763 These additional commands exist:
765 \\[pmail-summary-undelete-many] Undelete all or prefix arg deleted messages.
766 \\[pmail-summary-wipe] Delete the summary and go to the Pmail buffer.
768 Commands for sorting the summary:
770 \\[pmail-summary-sort-by-date] Sort by date.
771 \\[pmail-summary-sort-by-subject] Sort by subject.
772 \\[pmail-summary-sort-by-author] Sort by author.
773 \\[pmail-summary-sort-by-recipient] Sort by recipient.
774 \\[pmail-summary-sort-by-correspondent] Sort by correspondent.
775 \\[pmail-summary-sort-by-lines] Sort by lines.
776 \\[pmail-summary-sort-by-labels] Sort by labels."
777 (interactive)
778 (kill-all-local-variables)
779 (setq major-mode 'pmail-summary-mode)
780 (setq mode-name "PMAIL Summary")
781 (setq truncate-lines t)
782 (setq buffer-read-only t)
783 (set-syntax-table text-mode-syntax-table)
784 (make-local-variable 'pmail-buffer)
785 (make-local-variable 'pmail-total-messages)
786 (make-local-variable 'pmail-current-message)
787 (setq pmail-current-message nil)
788 (make-local-variable 'pmail-summary-redo)
789 (setq pmail-summary-redo nil)
790 (make-local-variable 'revert-buffer-function)
791 (make-local-variable 'font-lock-defaults)
792 (setq font-lock-defaults '(pmail-summary-font-lock-keywords t))
793 (pmail-summary-enable)
794 (run-mode-hooks 'pmail-summary-mode-hook))
796 ;; Summary features need to be disabled during edit mode.
797 (defun pmail-summary-disable ()
798 (use-local-map text-mode-map)
799 (remove-hook 'post-command-hook 'pmail-summary-pmail-update t)
800 (setq revert-buffer-function nil))
802 (defun pmail-summary-enable ()
803 (use-local-map pmail-summary-mode-map)
804 (add-hook 'post-command-hook 'pmail-summary-pmail-update nil t)
805 (setq revert-buffer-function 'pmail-update-summary))
807 (defvar pmail-summary-put-back-unseen nil
808 "Used for communicating between calls to `pmail-summary-pmail-update'.
809 If it moves to a message within an Incremental Search, and removes
810 the `unseen' attribute from that message, it sets this flag
811 so that if the next motion between messages is in the same Incremental
812 Search, the `unseen' attribute is restored.")
814 ;; Show in Pmail the message described by the summary line that point is on,
815 ;; but only if the Pmail buffer is already visible.
816 ;; This is a post-command-hook in summary buffers.
817 (defun pmail-summary-pmail-update ()
818 (let (buffer-read-only)
819 (save-excursion
820 ;; If at end of buffer, pretend we are on the last text line.
821 (if (eobp)
822 (forward-line -1))
823 (beginning-of-line)
824 (skip-chars-forward " ")
825 (let ((msg-num (string-to-number (buffer-substring
826 (point)
827 (progn (skip-chars-forward "0-9")
828 (point))))))
829 ;; Always leave `unseen' removed
830 ;; if we get out of isearch mode.
831 ;; Don't let a subsequent isearch restore that `unseen'.
832 (if (not isearch-mode)
833 (setq pmail-summary-put-back-unseen nil))
835 (or (eq pmail-current-message msg-num)
836 (let ((window (get-buffer-window pmail-buffer t))
837 (owin (selected-window)))
838 (if isearch-mode
839 (save-excursion
840 (set-buffer pmail-buffer)
841 ;; If we first saw the previous message in this search,
842 ;; and we have gone to a different message while searching,
843 ;; put back `unseen' on the former one.
844 (if pmail-summary-put-back-unseen
845 (pmail-set-attribute "unseen" t
846 pmail-current-message))
847 ;; Arrange to do that later, for the new current message,
848 ;; if it still has `unseen'.
849 (setq pmail-summary-put-back-unseen
850 (pmail-message-attr-p msg-num pmail-unseen-attr-index)))
851 (setq pmail-summary-put-back-unseen nil))
853 ;; Go to the desired message.
854 (setq pmail-current-message msg-num)
856 ;; Update the summary to show the message has been seen.
857 (if (= (following-char) ?-)
858 (progn
859 (delete-char 1)
860 (insert " ")))
862 (if window
863 ;; Using save-window-excursion would cause the new value
864 ;; of point to get lost.
865 (unwind-protect
866 (progn
867 (select-window window)
868 (pmail-show-message-maybe msg-num t))
869 (select-window owin))
870 (if (buffer-name pmail-buffer)
871 (save-excursion
872 (set-buffer pmail-buffer)
873 (pmail-show-message-maybe msg-num t))))))
874 (pmail-summary-update-highlight nil)))))
876 (defun pmail-summary-save-buffer ()
877 "Save the buffer associated with this PMAIL summary."
878 (interactive)
879 (save-window-excursion
880 (save-excursion
881 (switch-to-buffer pmail-buffer)
882 (save-buffer))))
885 (if pmail-summary-mode-map
887 (setq pmail-summary-mode-map (make-keymap))
888 (suppress-keymap pmail-summary-mode-map)
890 (define-key pmail-summary-mode-map [mouse-2] 'pmail-summary-mouse-goto-message)
891 (define-key pmail-summary-mode-map "a" 'pmail-summary-add-label)
892 (define-key pmail-summary-mode-map "b" 'pmail-summary-bury)
893 (define-key pmail-summary-mode-map "c" 'pmail-summary-continue)
894 (define-key pmail-summary-mode-map "d" 'pmail-summary-delete-forward)
895 (define-key pmail-summary-mode-map "\C-d" 'pmail-summary-delete-backward)
896 (define-key pmail-summary-mode-map "e" 'pmail-summary-edit-current-message)
897 (define-key pmail-summary-mode-map "f" 'pmail-summary-forward)
898 (define-key pmail-summary-mode-map "g" 'pmail-summary-get-new-mail)
899 (define-key pmail-summary-mode-map "h" 'pmail-summary)
900 (define-key pmail-summary-mode-map "i" 'pmail-summary-input)
901 (define-key pmail-summary-mode-map "j" 'pmail-summary-goto-msg)
902 (define-key pmail-summary-mode-map "\C-m" 'pmail-summary-goto-msg)
903 (define-key pmail-summary-mode-map "k" 'pmail-summary-kill-label)
904 (define-key pmail-summary-mode-map "l" 'pmail-summary-by-labels)
905 (define-key pmail-summary-mode-map "\e\C-h" 'pmail-summary)
906 (define-key pmail-summary-mode-map "\e\C-l" 'pmail-summary-by-labels)
907 (define-key pmail-summary-mode-map "\e\C-r" 'pmail-summary-by-recipients)
908 (define-key pmail-summary-mode-map "\e\C-s" 'pmail-summary-by-regexp)
909 (define-key pmail-summary-mode-map "\e\C-t" 'pmail-summary-by-topic)
910 (define-key pmail-summary-mode-map "m" 'pmail-summary-mail)
911 (define-key pmail-summary-mode-map "\M-m" 'pmail-summary-retry-failure)
912 (define-key pmail-summary-mode-map "n" 'pmail-summary-next-msg)
913 (define-key pmail-summary-mode-map "\en" 'pmail-summary-next-all)
914 (define-key pmail-summary-mode-map "\e\C-n" 'pmail-summary-next-labeled-message)
915 (define-key pmail-summary-mode-map "o" 'pmail-summary-output-to-babyl-file)
916 (define-key pmail-summary-mode-map "\C-o" 'pmail-summary-output)
917 (define-key pmail-summary-mode-map "p" 'pmail-summary-previous-msg)
918 (define-key pmail-summary-mode-map "\ep" 'pmail-summary-previous-all)
919 (define-key pmail-summary-mode-map "\e\C-p" 'pmail-summary-previous-labeled-message)
920 (define-key pmail-summary-mode-map "q" 'pmail-summary-quit)
921 (define-key pmail-summary-mode-map "Q" 'pmail-summary-wipe)
922 (define-key pmail-summary-mode-map "r" 'pmail-summary-reply)
923 (define-key pmail-summary-mode-map "s" 'pmail-summary-expunge-and-save)
924 (define-key pmail-summary-mode-map "\es" 'pmail-summary-search)
925 (define-key pmail-summary-mode-map "t" 'pmail-summary-toggle-header)
926 (define-key pmail-summary-mode-map "u" 'pmail-summary-undelete)
927 (define-key pmail-summary-mode-map "\M-u" 'pmail-summary-undelete-many)
928 (define-key pmail-summary-mode-map "x" 'pmail-summary-expunge)
929 (define-key pmail-summary-mode-map "w" 'pmail-summary-output-body)
930 (define-key pmail-summary-mode-map "." 'pmail-summary-beginning-of-message)
931 (define-key pmail-summary-mode-map "/" 'pmail-summary-end-of-message)
932 (define-key pmail-summary-mode-map "<" 'pmail-summary-first-message)
933 (define-key pmail-summary-mode-map ">" 'pmail-summary-last-message)
934 (define-key pmail-summary-mode-map " " 'pmail-summary-scroll-msg-up)
935 (define-key pmail-summary-mode-map "\177" 'pmail-summary-scroll-msg-down)
936 (define-key pmail-summary-mode-map "?" 'describe-mode)
937 (define-key pmail-summary-mode-map "\C-c\C-n" 'pmail-summary-next-same-subject)
938 (define-key pmail-summary-mode-map "\C-c\C-p" 'pmail-summary-previous-same-subject)
939 (define-key pmail-summary-mode-map "\C-c\C-s\C-d"
940 'pmail-summary-sort-by-date)
941 (define-key pmail-summary-mode-map "\C-c\C-s\C-s"
942 'pmail-summary-sort-by-subject)
943 (define-key pmail-summary-mode-map "\C-c\C-s\C-a"
944 'pmail-summary-sort-by-author)
945 (define-key pmail-summary-mode-map "\C-c\C-s\C-r"
946 'pmail-summary-sort-by-recipient)
947 (define-key pmail-summary-mode-map "\C-c\C-s\C-c"
948 'pmail-summary-sort-by-correspondent)
949 (define-key pmail-summary-mode-map "\C-c\C-s\C-l"
950 'pmail-summary-sort-by-lines)
951 (define-key pmail-summary-mode-map "\C-c\C-s\C-k"
952 'pmail-summary-sort-by-labels)
953 (define-key pmail-summary-mode-map "\C-x\C-s" 'pmail-summary-save-buffer)
956 ;;; Menu bar bindings.
958 (define-key pmail-summary-mode-map [menu-bar] (make-sparse-keymap))
960 (define-key pmail-summary-mode-map [menu-bar classify]
961 (cons "Classify" (make-sparse-keymap "Classify")))
963 (define-key pmail-summary-mode-map [menu-bar classify output-menu]
964 '("Output (Pmail Menu)..." . pmail-summary-output-menu))
966 (define-key pmail-summary-mode-map [menu-bar classify input-menu]
967 '("Input Pmail File (menu)..." . pmail-input-menu))
969 (define-key pmail-summary-mode-map [menu-bar classify input-menu]
970 '(nil))
972 (define-key pmail-summary-mode-map [menu-bar classify output-menu]
973 '(nil))
975 (define-key pmail-summary-mode-map [menu-bar classify output-body]
976 '("Output (body)..." . pmail-summary-output-body))
978 (define-key pmail-summary-mode-map [menu-bar classify output-inbox]
979 '("Output (inbox)..." . pmail-summary-output))
981 (define-key pmail-summary-mode-map [menu-bar classify output]
982 '("Output (Pmail)..." . pmail-summary-output-to-babyl-file))
984 (define-key pmail-summary-mode-map [menu-bar classify kill-label]
985 '("Kill Label..." . pmail-summary-kill-label))
987 (define-key pmail-summary-mode-map [menu-bar classify add-label]
988 '("Add Label..." . pmail-summary-add-label))
990 (define-key pmail-summary-mode-map [menu-bar summary]
991 (cons "Summary" (make-sparse-keymap "Summary")))
993 (define-key pmail-summary-mode-map [menu-bar summary senders]
994 '("By Senders..." . pmail-summary-by-senders))
996 (define-key pmail-summary-mode-map [menu-bar summary labels]
997 '("By Labels..." . pmail-summary-by-labels))
999 (define-key pmail-summary-mode-map [menu-bar summary recipients]
1000 '("By Recipients..." . pmail-summary-by-recipients))
1002 (define-key pmail-summary-mode-map [menu-bar summary topic]
1003 '("By Topic..." . pmail-summary-by-topic))
1005 (define-key pmail-summary-mode-map [menu-bar summary regexp]
1006 '("By Regexp..." . pmail-summary-by-regexp))
1008 (define-key pmail-summary-mode-map [menu-bar summary all]
1009 '("All" . pmail-summary))
1011 (define-key pmail-summary-mode-map [menu-bar mail]
1012 (cons "Mail" (make-sparse-keymap "Mail")))
1014 (define-key pmail-summary-mode-map [menu-bar mail pmail-summary-get-new-mail]
1015 '("Get New Mail" . pmail-summary-get-new-mail))
1017 (define-key pmail-summary-mode-map [menu-bar mail lambda]
1018 '("----"))
1020 (define-key pmail-summary-mode-map [menu-bar mail continue]
1021 '("Continue" . pmail-summary-continue))
1023 (define-key pmail-summary-mode-map [menu-bar mail resend]
1024 '("Re-send..." . pmail-summary-resend))
1026 (define-key pmail-summary-mode-map [menu-bar mail forward]
1027 '("Forward" . pmail-summary-forward))
1029 (define-key pmail-summary-mode-map [menu-bar mail retry]
1030 '("Retry" . pmail-summary-retry-failure))
1032 (define-key pmail-summary-mode-map [menu-bar mail reply]
1033 '("Reply" . pmail-summary-reply))
1035 (define-key pmail-summary-mode-map [menu-bar mail mail]
1036 '("Mail" . pmail-summary-mail))
1038 (define-key pmail-summary-mode-map [menu-bar delete]
1039 (cons "Delete" (make-sparse-keymap "Delete")))
1041 (define-key pmail-summary-mode-map [menu-bar delete expunge/save]
1042 '("Expunge/Save" . pmail-summary-expunge-and-save))
1044 (define-key pmail-summary-mode-map [menu-bar delete expunge]
1045 '("Expunge" . pmail-summary-expunge))
1047 (define-key pmail-summary-mode-map [menu-bar delete undelete]
1048 '("Undelete" . pmail-summary-undelete))
1050 (define-key pmail-summary-mode-map [menu-bar delete delete]
1051 '("Delete" . pmail-summary-delete-forward))
1053 (define-key pmail-summary-mode-map [menu-bar move]
1054 (cons "Move" (make-sparse-keymap "Move")))
1056 (define-key pmail-summary-mode-map [menu-bar move search-back]
1057 '("Search Back..." . pmail-summary-search-backward))
1059 (define-key pmail-summary-mode-map [menu-bar move search]
1060 '("Search..." . pmail-summary-search))
1062 (define-key pmail-summary-mode-map [menu-bar move previous]
1063 '("Previous Nondeleted" . pmail-summary-previous-msg))
1065 (define-key pmail-summary-mode-map [menu-bar move next]
1066 '("Next Nondeleted" . pmail-summary-next-msg))
1068 (define-key pmail-summary-mode-map [menu-bar move last]
1069 '("Last" . pmail-summary-last-message))
1071 (define-key pmail-summary-mode-map [menu-bar move first]
1072 '("First" . pmail-summary-first-message))
1074 (define-key pmail-summary-mode-map [menu-bar move previous]
1075 '("Previous" . pmail-summary-previous-all))
1077 (define-key pmail-summary-mode-map [menu-bar move next]
1078 '("Next" . pmail-summary-next-all))
1080 (defun pmail-summary-mouse-goto-message (event)
1081 "Select the message whose summary line you click on."
1082 (interactive "@e")
1083 (goto-char (posn-point (event-end event)))
1084 (pmail-summary-goto-msg))
1086 (defun pmail-summary-goto-msg (&optional n nowarn skip-pmail)
1087 "Go to message N in the summary buffer and the Pmail buffer.
1088 If N is nil, use the message corresponding to point in the summary
1089 and move to that message in the Pmail buffer.
1091 If NOWARN, don't say anything if N is out of range.
1092 If SKIP-PMAIL, don't do anything to the Pmail buffer."
1093 (interactive "P")
1094 (if (consp n) (setq n (prefix-numeric-value n)))
1095 (if (eobp) (forward-line -1))
1096 (beginning-of-line)
1097 (let* ((obuf (current-buffer))
1098 (buf pmail-buffer)
1099 (cur (point))
1100 message-not-found
1101 (curmsg (string-to-number
1102 (buffer-substring (point)
1103 (min (point-max) (+ 6 (point))))))
1104 (total (save-excursion (set-buffer buf) pmail-total-messages)))
1105 ;; If message number N was specified, find that message's line
1106 ;; or set message-not-found.
1107 ;; If N wasn't specified or that message can't be found.
1108 ;; set N by default.
1109 (if (not n)
1110 (setq n curmsg)
1111 (if (< n 1)
1112 (progn (message "No preceding message")
1113 (setq n 1)))
1114 (if (and (> n total)
1115 (> total 0))
1116 (progn (message "No following message")
1117 (goto-char (point-max))
1118 (pmail-summary-goto-msg nil nowarn skip-pmail)))
1119 (goto-char (point-min))
1120 (if (not (re-search-forward (format "^%5d[^0-9]" n) nil t))
1121 (progn (or nowarn (message "Message %d not found" n))
1122 (setq n curmsg)
1123 (setq message-not-found t)
1124 (goto-char cur))))
1125 (beginning-of-line)
1126 (skip-chars-forward " ")
1127 (skip-chars-forward "0-9")
1128 (save-excursion (if (= (following-char) ?-)
1129 (let ((buffer-read-only nil))
1130 (delete-char 1)
1131 (insert " "))))
1132 (pmail-summary-update-highlight message-not-found)
1133 (beginning-of-line)
1134 (if skip-pmail
1136 (let ((selwin (selected-window)))
1137 (unwind-protect
1138 (progn (pop-to-buffer buf)
1139 (pmail-show-message-maybe n))
1140 (select-window selwin)
1141 ;; The actions above can alter the current buffer. Preserve it.
1142 (set-buffer obuf))))))
1144 ;; Update the highlighted line in an pmail summary buffer.
1145 ;; That should be current. We highlight the line point is on.
1146 ;; If NOT-FOUND is non-nil, we turn off highlighting.
1147 (defun pmail-summary-update-highlight (not-found)
1148 ;; Make sure we have an overlay to use.
1149 (or pmail-summary-overlay
1150 (progn
1151 (make-local-variable 'pmail-summary-overlay)
1152 (setq pmail-summary-overlay (make-overlay (point) (point)))))
1153 ;; If this message is in the summary, use the overlay to highlight it.
1154 ;; Otherwise, don't highlight anything.
1155 (if not-found
1156 (overlay-put pmail-summary-overlay 'face nil)
1157 (move-overlay pmail-summary-overlay
1158 (save-excursion (beginning-of-line)
1159 (skip-chars-forward " ")
1160 (point))
1161 (save-excursion (end-of-line) (point)))
1162 (overlay-put pmail-summary-overlay 'face 'highlight)))
1164 (defun pmail-summary-scroll-msg-up (&optional dist)
1165 "Scroll the Pmail window forward.
1166 If the Pmail window is displaying the end of a message,
1167 advance to the next message."
1168 (interactive "P")
1169 (if (eq dist '-)
1170 (pmail-summary-scroll-msg-down nil)
1171 (let ((pmail-buffer-window (get-buffer-window pmail-buffer)))
1172 (if pmail-buffer-window
1173 (if (let ((pmail-summary-window (selected-window)))
1174 (select-window pmail-buffer-window)
1175 (prog1
1176 ;; Is EOB visible in the buffer?
1177 (save-excursion
1178 (let ((ht (window-height (selected-window))))
1179 (move-to-window-line (- ht 2))
1180 (end-of-line)
1181 (eobp)))
1182 (select-window pmail-summary-window)))
1183 (if (not pmail-summary-scroll-between-messages)
1184 (error "End of buffer")
1185 (pmail-summary-next-msg (or dist 1)))
1186 (let ((other-window-scroll-buffer pmail-buffer))
1187 (scroll-other-window dist)))
1188 ;; If it isn't visible at all, show the beginning.
1189 (pmail-summary-beginning-of-message)))))
1191 (defun pmail-summary-scroll-msg-down (&optional dist)
1192 "Scroll the Pmail window backward.
1193 If the Pmail window is now displaying the beginning of a message,
1194 move to the previous message."
1195 (interactive "P")
1196 (if (eq dist '-)
1197 (pmail-summary-scroll-msg-up nil)
1198 (let ((pmail-buffer-window (get-buffer-window pmail-buffer)))
1199 (if pmail-buffer-window
1200 (if (let ((pmail-summary-window (selected-window)))
1201 (select-window pmail-buffer-window)
1202 (prog1
1203 ;; Is BOB visible in the buffer?
1204 (save-excursion
1205 (move-to-window-line 0)
1206 (beginning-of-line)
1207 (bobp))
1208 (select-window pmail-summary-window)))
1209 (if (not pmail-summary-scroll-between-messages)
1210 (error "Beginning of buffer")
1211 (pmail-summary-previous-msg (or dist 1)))
1212 (let ((other-window-scroll-buffer pmail-buffer))
1213 (scroll-other-window-down dist)))
1214 ;; If it isn't visible at all, show the beginning.
1215 (pmail-summary-beginning-of-message)))))
1217 (defun pmail-summary-beginning-of-message ()
1218 "Show current message from the beginning."
1219 (interactive)
1220 (pmail-summary-show-message 'BEG))
1222 (defun pmail-summary-end-of-message ()
1223 "Show bottom of current message."
1224 (interactive)
1225 (pmail-summary-show-message 'END))
1227 (defun pmail-summary-show-message (where)
1228 "Show current mail message.
1229 Position it according to WHERE which can be BEG or END"
1230 (if (and (one-window-p) (not pop-up-frames))
1231 ;; If there is just one window, put the summary on the top.
1232 (let ((buffer pmail-buffer))
1233 (split-window (selected-window) pmail-summary-window-size)
1234 (select-window (frame-first-window))
1235 (pop-to-buffer pmail-buffer)
1236 ;; If pop-to-buffer did not use that window, delete that
1237 ;; window. (This can happen if it uses another frame.)
1238 (or (eq buffer (window-buffer (next-window (frame-first-window))))
1239 (delete-other-windows)))
1240 (pop-to-buffer pmail-buffer))
1241 (cond
1242 ((eq where 'BEG)
1243 (goto-char (point-min))
1244 (search-forward "\n\n"))
1245 ((eq where 'END)
1246 (goto-char (point-max))
1247 (recenter (1- (window-height))))
1249 (pop-to-buffer pmail-summary-buffer))
1251 (defun pmail-summary-bury ()
1252 "Bury the Pmail buffer and the Pmail summary buffer."
1253 (interactive)
1254 (let ((buffer-to-bury (current-buffer)))
1255 (let (window)
1256 (while (setq window (get-buffer-window pmail-buffer))
1257 (set-window-buffer window (other-buffer pmail-buffer)))
1258 (bury-buffer pmail-buffer))
1259 (switch-to-buffer (other-buffer buffer-to-bury))
1260 (bury-buffer buffer-to-bury)))
1262 (defun pmail-summary-quit ()
1263 "Quit out of Pmail and Pmail summary."
1264 (interactive)
1265 (pmail-summary-wipe)
1266 (pmail-quit))
1268 (defun pmail-summary-wipe ()
1269 "Kill and wipe away Pmail summary, remaining within Pmail."
1270 (interactive)
1271 (save-excursion (set-buffer pmail-buffer) (setq pmail-summary-buffer nil))
1272 (let ((local-pmail-buffer pmail-buffer))
1273 (kill-buffer (current-buffer))
1274 ;; Delete window if not only one.
1275 (if (not (eq (selected-window) (next-window nil 'no-minibuf)))
1276 (delete-window))
1277 ;; Switch windows to the pmail buffer, or switch to it in this window.
1278 (pop-to-buffer local-pmail-buffer)))
1280 (defun pmail-summary-expunge ()
1281 "Actually erase all deleted messages and recompute summary headers."
1282 (interactive)
1283 (save-excursion
1284 (set-buffer pmail-buffer)
1285 (when (pmail-expunge-confirmed)
1286 (pmail-only-expunge)))
1287 (pmail-update-summary))
1289 (defun pmail-summary-expunge-and-save ()
1290 "Expunge and save PMAIL file."
1291 (interactive)
1292 (save-excursion
1293 (set-buffer pmail-buffer)
1294 (when (pmail-expunge-confirmed)
1295 (pmail-only-expunge)))
1296 (pmail-update-summary)
1297 (save-excursion
1298 (set-buffer pmail-buffer)
1299 (save-buffer))
1300 (set-buffer-modified-p nil))
1302 (defun pmail-summary-get-new-mail (&optional file-name)
1303 "Get new mail and recompute summary headers.
1305 Optionally you can specify the file to get new mail from. In this case,
1306 the file of new mail is not changed or deleted. Noninteractively, you can
1307 pass the inbox file name as an argument. Interactively, a prefix
1308 argument says to read a file name and use that file as the inbox."
1309 (interactive
1310 (list (if current-prefix-arg
1311 (read-file-name "Get new mail from file: "))))
1312 (let (msg)
1313 (save-excursion
1314 (set-buffer pmail-buffer)
1315 (pmail-get-new-mail file-name)
1316 ;; Get the proper new message number.
1317 (setq msg pmail-current-message))
1318 ;; Make sure that message is displayed.
1319 (or (zerop msg)
1320 (pmail-summary-goto-msg msg))))
1322 (defun pmail-summary-input (filename)
1323 "Run Pmail on file FILENAME."
1324 (interactive "FRun pmail on PMAIL file: ")
1325 ;; We switch windows here, then display the other Pmail file there.
1326 (pop-to-buffer pmail-buffer)
1327 (pmail filename))
1329 (defun pmail-summary-first-message ()
1330 "Show first message in Pmail file from summary buffer."
1331 (interactive)
1332 (with-no-warnings
1333 (beginning-of-buffer)))
1335 (defun pmail-summary-last-message ()
1336 "Show last message in Pmail file from summary buffer."
1337 (interactive)
1338 (with-no-warnings
1339 (end-of-buffer))
1340 (forward-line -1))
1342 (declare-function pmail-abort-edit "pmailedit" ())
1343 (declare-function pmail-cease-edit "pmailedit"())
1344 (declare-function pmail-set-label "pmailkwd" (l state &optional n))
1345 (declare-function pmail-output-read-file-name "pmailout" ())
1346 (declare-function pmail-output-read-pmail-file-name "pmailout" ())
1347 (declare-function mail-send-and-exit "sendmail" (&optional arg))
1349 (defvar pmail-summary-edit-map nil)
1350 (if pmail-summary-edit-map
1352 (setq pmail-summary-edit-map
1353 (nconc (make-sparse-keymap) text-mode-map))
1354 (define-key pmail-summary-edit-map "\C-c\C-c" 'pmail-cease-edit)
1355 (define-key pmail-summary-edit-map "\C-c\C-]" 'pmail-abort-edit))
1357 (defun pmail-summary-edit-current-message ()
1358 "Edit the contents of this message."
1359 (interactive)
1360 (pop-to-buffer pmail-buffer)
1361 (pmail-edit-current-message)
1362 (use-local-map pmail-summary-edit-map))
1364 (defun pmail-summary-cease-edit ()
1365 "Finish editing message, then go back to Pmail summary buffer."
1366 (interactive)
1367 (pmail-cease-edit)
1368 (pop-to-buffer pmail-summary-buffer))
1370 (defun pmail-summary-abort-edit ()
1371 "Abort edit of current message; restore original contents.
1372 Go back to summary buffer."
1373 (interactive)
1374 (pmail-abort-edit)
1375 (pop-to-buffer pmail-summary-buffer))
1377 (defun pmail-summary-search-backward (regexp &optional n)
1378 "Show message containing next match for REGEXP.
1379 Prefix argument gives repeat count; negative argument means search
1380 backwards (through earlier messages).
1381 Interactively, empty argument means use same regexp used last time."
1382 (interactive
1383 (let* ((reversep (>= (prefix-numeric-value current-prefix-arg) 0))
1384 (prompt
1385 (concat (if reversep "Reverse " "") "Pmail search (regexp"))
1386 regexp)
1387 (setq prompt
1388 (concat prompt
1389 (if pmail-search-last-regexp
1390 (concat ", default "
1391 pmail-search-last-regexp "): ")
1392 "): ")))
1393 (setq regexp (read-string prompt))
1394 (cond ((not (equal regexp ""))
1395 (setq pmail-search-last-regexp regexp))
1396 ((not pmail-search-last-regexp)
1397 (error "No previous Pmail search string")))
1398 (list pmail-search-last-regexp
1399 (prefix-numeric-value current-prefix-arg))))
1400 ;; Don't use save-excursion because that prevents point from moving
1401 ;; properly in the summary buffer.
1402 (let ((buffer (current-buffer)))
1403 (unwind-protect
1404 (progn
1405 (set-buffer pmail-buffer)
1406 (pmail-search regexp (- n)))
1407 (set-buffer buffer))))
1409 (defun pmail-summary-search (regexp &optional n)
1410 "Show message containing next match for REGEXP.
1411 Prefix argument gives repeat count; negative argument means search
1412 backwards (through earlier messages).
1413 Interactively, empty argument means use same regexp used last time."
1414 (interactive
1415 (let* ((reversep (< (prefix-numeric-value current-prefix-arg) 0))
1416 (prompt
1417 (concat (if reversep "Reverse " "") "Pmail search (regexp"))
1418 regexp)
1419 (setq prompt
1420 (concat prompt
1421 (if pmail-search-last-regexp
1422 (concat ", default "
1423 pmail-search-last-regexp "): ")
1424 "): ")))
1425 (setq regexp (read-string prompt))
1426 (cond ((not (equal regexp ""))
1427 (setq pmail-search-last-regexp regexp))
1428 ((not pmail-search-last-regexp)
1429 (error "No previous Pmail search string")))
1430 (list pmail-search-last-regexp
1431 (prefix-numeric-value current-prefix-arg))))
1432 ;; Don't use save-excursion because that prevents point from moving
1433 ;; properly in the summary buffer.
1434 (let ((buffer (current-buffer)))
1435 (unwind-protect
1436 (progn
1437 (set-buffer pmail-buffer)
1438 (pmail-search regexp n))
1439 (set-buffer buffer))))
1441 (defun pmail-summary-toggle-header ()
1442 "Show original message header if pruned header currently shown, or vice versa."
1443 (interactive)
1444 (save-window-excursion
1445 (set-buffer pmail-buffer)
1446 (pmail-toggle-header))
1447 ;; Inside save-excursion, some changes to point in the PMAIL buffer are lost.
1448 ;; Set point to point-min in the PMAIL buffer, if it is visible.
1449 (let ((window (get-buffer-window pmail-buffer)))
1450 (if window
1451 ;; Using save-window-excursion would lose the new value of point.
1452 (let ((owin (selected-window)))
1453 (unwind-protect
1454 (progn
1455 (select-window window)
1456 (goto-char (point-min)))
1457 (select-window owin))))))
1460 (defun pmail-summary-add-label (label)
1461 "Add LABEL to labels associated with current Pmail message.
1462 Completion is performed over known labels when reading."
1463 (interactive (list (save-excursion
1464 (set-buffer pmail-buffer)
1465 (pmail-read-label "Add label"))))
1466 (save-excursion
1467 (set-buffer pmail-buffer)
1468 (pmail-add-label label)))
1470 (defun pmail-summary-kill-label (label)
1471 "Remove LABEL from labels associated with current Pmail message.
1472 Completion is performed over known labels when reading."
1473 (interactive (list (save-excursion
1474 (set-buffer pmail-buffer)
1475 (pmail-read-label "Kill label"))))
1476 (save-excursion
1477 (set-buffer pmail-buffer)
1478 (pmail-set-label label nil)))
1480 ;;;; *** Pmail Summary Mailing Commands ***
1482 (defun pmail-summary-override-mail-send-and-exit ()
1483 "Replace bindings to `mail-send-and-exit' with `pmail-summary-send-and-exit'."
1484 (use-local-map (copy-keymap (current-local-map)))
1485 (dolist (key (where-is-internal 'mail-send-and-exit))
1486 (define-key (current-local-map) key 'pmail-summary-send-and-exit)))
1488 (defun pmail-summary-mail ()
1489 "Send mail in another window.
1490 While composing the message, use \\[mail-yank-original] to yank the
1491 original message into it."
1492 (interactive)
1493 (let ((window (get-buffer-window pmail-buffer)))
1494 (if window
1495 (select-window window)
1496 (set-buffer pmail-buffer)))
1497 (pmail-start-mail nil nil nil nil nil (current-buffer))
1498 (pmail-summary-override-mail-send-and-exit))
1500 (defun pmail-summary-continue ()
1501 "Continue composing outgoing message previously being composed."
1502 (interactive)
1503 (let ((window (get-buffer-window pmail-buffer)))
1504 (if window
1505 (select-window window)
1506 (set-buffer pmail-buffer)))
1507 (pmail-start-mail t))
1509 (defun pmail-summary-reply (just-sender)
1510 "Reply to the current message.
1511 Normally include CC: to all other recipients of original message;
1512 prefix argument means ignore them. While composing the reply,
1513 use \\[mail-yank-original] to yank the original message into it."
1514 (interactive "P")
1515 (let ((window (get-buffer-window pmail-buffer)))
1516 (if window
1517 (select-window window)
1518 (set-buffer pmail-buffer)))
1519 (pmail-reply just-sender)
1520 (pmail-summary-override-mail-send-and-exit))
1522 (defun pmail-summary-retry-failure ()
1523 "Edit a mail message which is based on the contents of the current message.
1524 For a message rejected by the mail system, extract the interesting headers and
1525 the body of the original message; otherwise copy the current message."
1526 (interactive)
1527 (let ((window (get-buffer-window pmail-buffer)))
1528 (if window
1529 (select-window window)
1530 (set-buffer pmail-buffer)))
1531 (pmail-retry-failure)
1532 (pmail-summary-override-mail-send-and-exit))
1534 (defun pmail-summary-send-and-exit ()
1535 "Send mail reply and return to summary buffer."
1536 (interactive)
1537 (mail-send-and-exit t))
1539 (defun pmail-summary-forward (resend)
1540 "Forward the current message to another user.
1541 With prefix argument, \"resend\" the message instead of forwarding it;
1542 see the documentation of `pmail-resend'."
1543 (interactive "P")
1544 (save-excursion
1545 (let ((window (get-buffer-window pmail-buffer)))
1546 (if window
1547 (select-window window)
1548 (set-buffer pmail-buffer)))
1549 (pmail-forward resend)
1550 (pmail-summary-override-mail-send-and-exit)))
1552 (defun pmail-summary-resend ()
1553 "Resend current message using `pmail-resend'."
1554 (interactive)
1555 (save-excursion
1556 (let ((window (get-buffer-window pmail-buffer)))
1557 (if window
1558 (select-window window)
1559 (set-buffer pmail-buffer)))
1560 (call-interactively 'pmail-resend)))
1562 ;; Summary output commands.
1564 (defun pmail-summary-output-to-babyl-file (&optional file-name n)
1565 "Append the current message to an Pmail file named FILE-NAME.
1566 If the file does not exist, ask if it should be created.
1567 If file is being visited, the message is appended to the Emacs
1568 buffer visiting that file.
1570 A prefix argument N says to output N consecutive messages
1571 starting with the current one. Deleted messages are skipped and don't count."
1572 (interactive
1573 (progn (require 'pmailout)
1574 (list (pmail-output-read-pmail-file-name)
1575 (prefix-numeric-value current-prefix-arg))))
1576 (let ((i 0) prev-msg)
1577 (while
1578 (and (< i n)
1579 (progn (pmail-summary-goto-msg)
1580 (not (eq prev-msg
1581 (setq prev-msg
1582 (with-current-buffer pmail-buffer
1583 pmail-current-message))))))
1584 (setq i (1+ i))
1585 (with-current-buffer pmail-buffer
1586 (let ((pmail-delete-after-output nil))
1587 (pmail-output-to-babyl-file file-name 1)))
1588 (if pmail-delete-after-output
1589 (pmail-summary-delete-forward nil)
1590 (if (< i n)
1591 (pmail-summary-next-msg 1))))))
1593 (defalias 'pmail-summary-output-to-pmail-file
1594 'pmail-summary-output-to-babyl-file)
1596 (defun pmail-summary-output (&optional file-name n)
1597 "Append this message to Unix mail file named FILE-NAME.
1599 A prefix argument N says to output N consecutive messages
1600 starting with the current one. Deleted messages are skipped and don't count."
1601 (interactive
1602 (progn (require 'pmailout)
1603 (list (pmail-output-read-file-name)
1604 (prefix-numeric-value current-prefix-arg))))
1605 (let ((i 0) prev-msg)
1606 (while
1607 (and (< i n)
1608 (progn (pmail-summary-goto-msg)
1609 (not (eq prev-msg
1610 (setq prev-msg
1611 (with-current-buffer pmail-buffer
1612 pmail-current-message))))))
1613 (setq i (1+ i))
1614 (with-current-buffer pmail-buffer
1615 (let ((pmail-delete-after-output nil))
1616 (pmail-output file-name 1)))
1617 (if pmail-delete-after-output
1618 (pmail-summary-delete-forward nil)
1619 (if (< i n)
1620 (pmail-summary-next-msg 1))))))
1622 (defun pmail-summary-output-menu ()
1623 "Output current message to another Pmail file, chosen with a menu.
1624 Also set the default for subsequent \\[pmail-output-to-babyl-file] commands.
1625 The variables `pmail-secondary-file-directory' and
1626 `pmail-secondary-file-regexp' control which files are offered in the menu."
1627 (interactive)
1628 (save-excursion
1629 (set-buffer pmail-buffer)
1630 (let ((pmail-delete-after-output nil))
1631 (call-interactively 'pmail-output-menu)))
1632 (if pmail-delete-after-output
1633 (pmail-summary-delete-forward nil)))
1635 (defun pmail-summary-construct-io-menu ()
1636 (let ((files (pmail-find-all-files pmail-secondary-file-directory)))
1637 (if files
1638 (progn
1639 (define-key pmail-summary-mode-map [menu-bar classify input-menu]
1640 (cons "Input Pmail File"
1641 (pmail-list-to-menu "Input Pmail File"
1642 files
1643 'pmail-summary-input)))
1644 (define-key pmail-summary-mode-map [menu-bar classify output-menu]
1645 (cons "Output Pmail File"
1646 (pmail-list-to-menu "Output Pmail File"
1647 files
1648 'pmail-summary-output-to-babyl-file))))
1649 (define-key pmail-summary-mode-map [menu-bar classify input-menu]
1650 '("Input Pmail File" . pmail-disable-menu))
1651 (define-key pmail-summary-mode-map [menu-bar classify output-menu]
1652 '("Output Pmail File" . pmail-disable-menu)))))
1654 (defun pmail-summary-output-body (&optional file-name)
1655 "Write this message body to the file FILE-NAME.
1656 FILE-NAME defaults, interactively, from the Subject field of the message."
1657 (interactive)
1658 (save-excursion
1659 (set-buffer pmail-buffer)
1660 (let ((pmail-delete-after-output nil))
1661 (if file-name
1662 (pmail-output-body-to-file file-name)
1663 (call-interactively 'pmail-output-body-to-file))))
1664 (if pmail-delete-after-output
1665 (pmail-summary-delete-forward nil)))
1667 ;; Sorting messages in Pmail Summary buffer.
1669 (defun pmail-summary-sort-by-date (reverse)
1670 "Sort messages of current Pmail summary by date.
1671 If prefix argument REVERSE is non-nil, sort them in reverse order."
1672 (interactive "P")
1673 (pmail-sort-from-summary (function pmail-sort-by-date) reverse))
1675 (defun pmail-summary-sort-by-subject (reverse)
1676 "Sort messages of current Pmail summary by subject.
1677 If prefix argument REVERSE is non-nil, sort them in reverse order."
1678 (interactive "P")
1679 (pmail-sort-from-summary (function pmail-sort-by-subject) reverse))
1681 (defun pmail-summary-sort-by-author (reverse)
1682 "Sort messages of current Pmail summary by author.
1683 If prefix argument REVERSE is non-nil, sort them in reverse order."
1684 (interactive "P")
1685 (pmail-sort-from-summary (function pmail-sort-by-author) reverse))
1687 (defun pmail-summary-sort-by-recipient (reverse)
1688 "Sort messages of current Pmail summary by recipient.
1689 If prefix argument REVERSE is non-nil, sort them in reverse order."
1690 (interactive "P")
1691 (pmail-sort-from-summary (function pmail-sort-by-recipient) reverse))
1693 (defun pmail-summary-sort-by-correspondent (reverse)
1694 "Sort messages of current Pmail summary by other correspondent.
1695 If prefix argument REVERSE is non-nil, sort them in reverse order."
1696 (interactive "P")
1697 (pmail-sort-from-summary (function pmail-sort-by-correspondent) reverse))
1699 (defun pmail-summary-sort-by-lines (reverse)
1700 "Sort messages of current Pmail summary by lines of the message.
1701 If prefix argument REVERSE is non-nil, sort them in reverse order."
1702 (interactive "P")
1703 (pmail-sort-from-summary (function pmail-sort-by-lines) reverse))
1705 (defun pmail-summary-sort-by-labels (reverse labels)
1706 "Sort messages of current Pmail summary by labels.
1707 If prefix argument REVERSE is non-nil, sort them in reverse order.
1708 KEYWORDS is a comma-separated list of labels."
1709 (interactive "P\nsSort by labels: ")
1710 (pmail-sort-from-summary
1711 (function (lambda (reverse)
1712 (pmail-sort-by-labels reverse labels)))
1713 reverse))
1715 (defun pmail-sort-from-summary (sortfun reverse)
1716 "Sort Pmail messages from Summary buffer and update it after sorting."
1717 (require 'pmailsort)
1718 (let ((selwin (selected-window)))
1719 (unwind-protect
1720 (progn (pop-to-buffer pmail-buffer)
1721 (funcall sortfun reverse))
1722 (select-window selwin))))
1724 (provide 'pmailsum)
1726 ;; arch-tag: 80b0a27a-a50d-4f37-9466-83d32d1e0ca8
1727 ;;; pmailsum.el ends here