comparison lisp/mail/pmail.el @ 101077:22a55aabcdba

(pmail-count-screen-lines, pmail-use-collection-buffer) (pmail-use-viewer-buffer): Fns deleted. Other functions reordered but not changed.
author Richard M. Stallman <rms@gnu.org>
date Sat, 10 Jan 2009 21:42:11 +0000
parents cc1abbe3dfe5
children f77a0ad64329
comparison
equal deleted inserted replaced
101076:6c4177798438 101077:22a55aabcdba
68 (unwind-protect 68 (unwind-protect
69 (let ((modp (buffer-modified-p))) 69 (let ((modp (buffer-modified-p)))
70 ;;; (save-match-data 70 ;;; (save-match-data
71 ;;; (let ((case-fold-search nil)) 71 ;;; (let ((case-fold-search nil))
72 ;;; (unless (or (string-match "PMAIL" (buffer-name)) 72 ;;; (unless (or (string-match "PMAIL" (buffer-name))
73 ;;; (string-match "xmail" (buffer-name))) 73 ;;; (string-match "xmail" (buffer-name))
74 ;;; (string-match "mbox" (buffer-name)))
74 ;;; (debug)))) 75 ;;; (debug))))
75 (buffer-swap-text buffer-swapped-with) 76 (buffer-swap-text buffer-swapped-with)
76 (set-buffer-modified-p modp) 77 (set-buffer-modified-p modp)
77 ad-do-it) 78 ad-do-it)
78 (buffer-swap-text buffer-swapped-with) 79 (buffer-swap-text buffer-swapped-with)
1323 ;; current message back and forth. This model is based on Stefan 1324 ;; current message back and forth. This model is based on Stefan
1324 ;; Monnier's solution for tar-mode. 1325 ;; Monnier's solution for tar-mode.
1325 (and (buffer-live-p pmail-view-buffer) 1326 (and (buffer-live-p pmail-view-buffer)
1326 (> (buffer-size pmail-view-buffer) (buffer-size)))) 1327 (> (buffer-size pmail-view-buffer) (buffer-size))))
1327 1328
1329 (defun pmail-swap-buffers-maybe ()
1330 "Determine if the Pmail buffer is showing a message.
1331 If so restore the actual mbox message collection."
1332 (with-current-buffer pmail-buffer
1333 (when (pmail-buffers-swapped-p)
1334 (let ((modp (buffer-modified-p)))
1335 (buffer-swap-text pmail-view-buffer)
1336 (set-buffer-modified-p modp))
1337 (setq buffer-swapped-with nil))))
1338
1328 (defun pmail-mode-kill-buffer-hook () 1339 (defun pmail-mode-kill-buffer-hook ()
1329 (if (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer))) 1340 (if (buffer-live-p pmail-view-buffer) (kill-buffer pmail-view-buffer)))
1330 1341
1331 ;; Set up the permanent locals associated with an Pmail file. 1342 ;; Set up the permanent locals associated with an Pmail file.
1332 (defun pmail-perm-variables () 1343 (defun pmail-perm-variables ()
1479 (goto-char (pmail-msgend pmail-current-message)) 1490 (goto-char (pmail-msgend pmail-current-message))
1480 (insert string) 1491 (insert string)
1481 (pmail-forget-messages) 1492 (pmail-forget-messages)
1482 (pmail-show-message-maybe number) 1493 (pmail-show-message-maybe number)
1483 (message "Message duplicated"))) 1494 (message "Message duplicated")))
1484 1495
1485 ;;;###autoload 1496 ;;;###autoload
1486 (defun pmail-input (filename) 1497 (defun pmail-input (filename)
1487 "Run Pmail on file FILENAME." 1498 "Run Pmail on file FILENAME."
1488 (interactive "FRun pmail on PMAIL file: ") 1499 (interactive "FRun pmail on PMAIL file: ")
1489 (pmail filename)) 1500 (pmail filename))
1985 (if (search-forward "\n\nFrom " nil 'move) 1996 (if (search-forward "\n\nFrom " nil 'move)
1986 (forward-char -5)) 1997 (forward-char -5))
1987 (setq start (point)))) 1998 (setq start (point))))
1988 count)))) 1999 count))))
1989 2000
1990 ;;;; *** Pmail Message Formatting and Header Manipulation ***
1991
1992 (defun pmail-copy-headers (beg end &optional ignored-headers)
1993 "Copy displayed header fields to the message viewer buffer.
1994 BEG and END marks the start and end positions of the message in
1995 the mbox buffer. If the optional argument IGNORED-HEADERS is
1996 non-nil, ignore all header fields whose names match that regexp.
1997 Otherwise, if `rmail-displayed-headers' is non-nil, copy only
1998 those header fields whose names match that regexp. Otherwise,
1999 copy all header fields whose names do not match
2000 `rmail-ignored-headers' (unless they also match
2001 `rmail-nonignored-headers')."
2002 (let ((header-start-regexp "\n[^ \t]")
2003 lim)
2004 (with-current-buffer pmail-buffer
2005 (when (search-forward "\n\n" nil t)
2006 (forward-char -1)
2007 (save-restriction
2008 ;; Put point right after the From header line.
2009 (narrow-to-region beg (point))
2010 (goto-char (point-min))
2011 (unless (re-search-forward header-start-regexp nil t)
2012 (pmail-error-bad-format))
2013 (forward-char -1)
2014 (cond
2015 ;; Handle the case where all headers should be copied.
2016 ((eq pmail-header-style 'full)
2017 (prepend-to-buffer pmail-view-buffer beg (point-max)))
2018 ;; Handle the case where the headers matching the diplayed
2019 ;; headers regexp should be copied.
2020 ((and pmail-displayed-headers (null ignored-headers))
2021 (while (not (eobp))
2022 (save-excursion
2023 (setq lim (if (re-search-forward header-start-regexp nil t)
2024 (1+ (match-beginning 0))
2025 (point-max))))
2026 (when (looking-at pmail-displayed-headers)
2027 (append-to-buffer pmail-view-buffer (point) lim))
2028 (goto-char lim)))
2029 ;; Handle the ignored headers.
2030 ((or ignored-headers (setq ignored-headers pmail-ignored-headers))
2031 (while (and ignored-headers (not (eobp)))
2032 (save-excursion
2033 (setq lim (if (re-search-forward header-start-regexp nil t)
2034 (1+ (match-beginning 0))
2035 (point-max))))
2036 (if (and (looking-at ignored-headers)
2037 (not (looking-at pmail-nonignored-headers)))
2038 (goto-char lim)
2039 (append-to-buffer pmail-view-buffer (point) lim)
2040 (goto-char lim))))
2041 (t (error "No headers selected for display!"))))))))
2042
2043 (defun pmail-toggle-header (&optional arg)
2044 "Show original message header if pruned header currently shown, or vice versa.
2045 With argument ARG, show the message header pruned if ARG is greater than zero;
2046 otherwise, show it in full."
2047 (interactive "P")
2048 (setq pmail-header-style
2049 (cond
2050 ((and (numberp arg) (> arg 0)) 'normal)
2051 ((eq pmail-header-style 'full) 'normal)
2052 (t 'full)))
2053 (pmail-show-message-maybe))
2054
2055 ;; Lifted from repos-count-screen-lines.
2056 ;; Return number of screen lines between START and END.
2057 (defun pmail-count-screen-lines (start end)
2058 (save-excursion
2059 (save-restriction
2060 (narrow-to-region start end)
2061 (goto-char (point-min))
2062 (vertical-motion (- (point-max) (point-min))))))
2063
2064 (defun pmail-get-header (name &optional msgnum) 2001 (defun pmail-get-header (name &optional msgnum)
2065 "Return the value of message header NAME, nil if it has none. 2002 "Return the value of message header NAME, nil if it has none.
2066 MSGNUM specifies the message number to get it from. 2003 MSGNUM specifies the message number to get it from.
2067 If MSGNUM is nil, use the current message." 2004 If MSGNUM is nil, use the current message."
2068 (with-current-buffer pmail-buffer 2005 (with-current-buffer pmail-buffer
2269 Return non-nil if the unseen attribute is set, nil otherwise." 2206 Return non-nil if the unseen attribute is set, nil otherwise."
2270 (pmail-message-attr-p msgnum "......U")) 2207 (pmail-message-attr-p msgnum "......U"))
2271 2208
2272 ;;;; *** Pmail Message Selection And Support *** 2209 ;;;; *** Pmail Message Selection And Support ***
2273 2210
2274 ;; (defun pmail-get-collection-buffer ()
2275 ;; "Return the buffer containing the mbox formatted messages."
2276 ;; (if (eq major-mode 'pmail-mode)
2277 ;; (if pmail-buffers-swapped-p
2278 ;; pmail-view-buffer
2279 ;; pmail-buffer)
2280 ;; (error "The current buffer must be in Pmail mode.")))
2281
2282 (defun pmail-use-collection-buffer ()
2283 "Insure that the Pmail buffer contains the message collection.
2284 Return the current message number if the Pmail buffer is in a
2285 swapped state, i.e. it currently contains a single decoded
2286 message rather than an entire message collection, nil otherwise."
2287 (let (result)
2288 (when (pmail-buffers-swapped-p)
2289 (let ((modp (buffer-modified-p)))
2290 (buffer-swap-text pmail-view-buffer)
2291 (set-buffer-modified-p modp))
2292 (setq buffer-swapped-with nil
2293 result pmail-current-message))
2294 result))
2295
2296 (defun pmail-use-viewer-buffer (&optional msgnum)
2297 "Insure that the Pmail buffer contains the current message.
2298 If message MSGNUM is non-nil make it the current message and
2299 display it. Return nil."
2300 (let (result)
2301 (cond
2302 ((not (pmail-buffers-swapped-p))
2303 (let ((message (or msgnum pmail-current-message)))
2304 (pmail-show-message message)))
2305 ((and msgnum (/= msgnum pmail-current-message))
2306 (pmail-show-message msgnum))
2307 (t))
2308 result))
2309
2310 (defun pmail-msgend (n) 2211 (defun pmail-msgend (n)
2311 (marker-position (aref pmail-message-vector (1+ n)))) 2212 (marker-position (aref pmail-message-vector (1+ n))))
2312 2213
2313 (defun pmail-msgbeg (n) 2214 (defun pmail-msgbeg (n)
2314 (marker-position (aref pmail-message-vector n))) 2215 (marker-position (aref pmail-message-vector n)))
2354 ;; Note: we don't use save-restriction because that does not work right 2255 ;; Note: we don't use save-restriction because that does not work right
2355 ;; if changes are made outside the saved restriction 2256 ;; if changes are made outside the saved restriction
2356 ;; before that restriction is restored. 2257 ;; before that restriction is restored.
2357 (narrow-to-region (pmail-msgbeg pmail-current-message) 2258 (narrow-to-region (pmail-msgbeg pmail-current-message)
2358 (pmail-msgend pmail-current-message))))) 2259 (pmail-msgend pmail-current-message)))))
2260
2261 ;; Manage the message vectors and counters.
2359 2262
2360 (defun pmail-forget-messages () 2263 (defun pmail-forget-messages ()
2361 (unwind-protect 2264 (unwind-protect
2362 (if (vectorp pmail-message-vector) 2265 (if (vectorp pmail-message-vector)
2363 (let* ((i 0) 2266 (let* ((i 0)
2485 (goto-char (point-min))) 2388 (goto-char (point-min)))
2486 (unless (not (looking-at "From ")) 2389 (unless (not (looking-at "From "))
2487 (pmail-collect-deleted start) 2390 (pmail-collect-deleted start)
2488 (setq messages-head (cons (point-marker) messages-head) 2391 (setq messages-head (cons (point-marker) messages-head)
2489 total-messages (1+ total-messages))))) 2392 total-messages (1+ total-messages)))))
2393
2394 ;; Display a message.
2395
2396 ;;;; *** Pmail Message Formatting and Header Manipulation ***
2397
2398 (defun pmail-toggle-header (&optional arg)
2399 "Show original message header if pruned header currently shown, or vice versa.
2400 With argument ARG, show the message header pruned if ARG is greater than zero;
2401 otherwise, show it in full."
2402 (interactive "P")
2403 (setq pmail-header-style
2404 (cond
2405 ((and (numberp arg) (> arg 0)) 'normal)
2406 ((eq pmail-header-style 'full) 'normal)
2407 (t 'full)))
2408 (pmail-show-message-maybe))
2490 2409
2491 (defun pmail-beginning-of-message () 2410 (defun pmail-beginning-of-message ()
2492 "Show current message starting from the beginning." 2411 "Show current message starting from the beginning."
2493 (interactive) 2412 (interactive)
2494 (let ((pmail-show-message-hook 2413 (let ((pmail-show-message-hook
2535 (format "Add `%s' to `mail-mailing-lists'? " 2454 (format "Add `%s' to `mail-mailing-lists'? "
2536 addr))) 2455 addr)))
2537 (customize-save-variable 'mail-mailing-lists 2456 (customize-save-variable 'mail-mailing-lists
2538 (cons addr mail-mailing-lists))))))))) 2457 (cons addr mail-mailing-lists)))))))))
2539 2458
2540 (defun pmail-swap-buffers-maybe ()
2541 "Determine if the Pmail buffer is showing a message.
2542 If so restore the actual mbox message collection."
2543 (with-current-buffer pmail-buffer
2544 (when (pmail-buffers-swapped-p)
2545 (let ((modp (buffer-modified-p)))
2546 (buffer-swap-text pmail-view-buffer)
2547 (set-buffer-modified-p modp))
2548 (setq buffer-swapped-with nil))))
2549
2550 (defun pmail-widen () 2459 (defun pmail-widen ()
2551 "Display the entire mailbox file." 2460 "Display the entire mailbox file."
2552 (interactive) 2461 (interactive)
2553 (pmail-swap-buffers-maybe) 2462 (pmail-swap-buffers-maybe)
2554 (widen)) 2463 (widen))
2555 2464
2556 (defun pmail-show-message-maybe (&optional n no-summary) 2465 (defun pmail-show-message-maybe (&optional n no-summary)
2557 "Show message number N (prefix argument), counting from start of file. 2466 "Show message number N (prefix argument), counting from start of file.
2558 If summary buffer is currently displayed, update current message there also." 2467 If summary buffer is currently displayed, update current message there also."
2559 (interactive "p") 2468 (interactive "p")
2560 (or (eq major-mode 'pmail-mode) 2469 (or (eq major-mode 'pmail-mode)
2679 (set-buffer-modified-p modp)) 2588 (set-buffer-modified-p modp))
2680 (setq buffer-swapped-with pmail-view-buffer) 2589 (setq buffer-swapped-with pmail-view-buffer)
2681 (run-hooks 'pmail-show-message-hook)) 2590 (run-hooks 'pmail-show-message-hook))
2682 blurb)) 2591 blurb))
2683 2592
2593 (defun pmail-copy-headers (beg end &optional ignored-headers)
2594 "Copy displayed header fields to the message viewer buffer.
2595 BEG and END marks the start and end positions of the message in
2596 the mbox buffer. If the optional argument IGNORED-HEADERS is
2597 non-nil, ignore all header fields whose names match that regexp.
2598 Otherwise, if `rmail-displayed-headers' is non-nil, copy only
2599 those header fields whose names match that regexp. Otherwise,
2600 copy all header fields whose names do not match
2601 `rmail-ignored-headers' (unless they also match
2602 `rmail-nonignored-headers')."
2603 (let ((header-start-regexp "\n[^ \t]")
2604 lim)
2605 (with-current-buffer pmail-buffer
2606 (when (search-forward "\n\n" nil t)
2607 (forward-char -1)
2608 (save-restriction
2609 ;; Put point right after the From header line.
2610 (narrow-to-region beg (point))
2611 (goto-char (point-min))
2612 (unless (re-search-forward header-start-regexp nil t)
2613 (pmail-error-bad-format))
2614 (forward-char -1)
2615 (cond
2616 ;; Handle the case where all headers should be copied.
2617 ((eq pmail-header-style 'full)
2618 (prepend-to-buffer pmail-view-buffer beg (point-max)))
2619 ;; Handle the case where the headers matching the diplayed
2620 ;; headers regexp should be copied.
2621 ((and pmail-displayed-headers (null ignored-headers))
2622 (while (not (eobp))
2623 (save-excursion
2624 (setq lim (if (re-search-forward header-start-regexp nil t)
2625 (1+ (match-beginning 0))
2626 (point-max))))
2627 (when (looking-at pmail-displayed-headers)
2628 (append-to-buffer pmail-view-buffer (point) lim))
2629 (goto-char lim)))
2630 ;; Handle the ignored headers.
2631 ((or ignored-headers (setq ignored-headers pmail-ignored-headers))
2632 (while (and ignored-headers (not (eobp)))
2633 (save-excursion
2634 (setq lim (if (re-search-forward header-start-regexp nil t)
2635 (1+ (match-beginning 0))
2636 (point-max))))
2637 (if (and (looking-at ignored-headers)
2638 (not (looking-at pmail-nonignored-headers)))
2639 (goto-char lim)
2640 (append-to-buffer pmail-view-buffer (point) lim)
2641 (goto-char lim))))
2642 (t (error "No headers selected for display!"))))))))
2643
2684 ;; Find all occurrences of certain fields, and highlight them. 2644 ;; Find all occurrences of certain fields, and highlight them.
2685 (defun pmail-highlight-headers () 2645 (defun pmail-highlight-headers ()
2686 ;; Do this only if the system supports faces. 2646 ;; Do this only if the system supports faces.
2687 (if (and (fboundp 'internal-find-face) 2647 (if (and (fboundp 'internal-find-face)
2688 pmail-highlighted-headers) 2648 pmail-highlighted-headers)
2759 (if (string= "/dev/null" folder) 2719 (if (string= "/dev/null" folder)
2760 (pmail-delete-message) 2720 (pmail-delete-message)
2761 (pmail-output folder 1 t) 2721 (pmail-output folder 1 t)
2762 (setq d nil)))) 2722 (setq d nil))))
2763 (setq d (cdr d)))))) 2723 (setq d (cdr d))))))
2724
2725 ;; Simple message motion commands.
2764 2726
2765 (defun pmail-next-message (n) 2727 (defun pmail-next-message (n)
2766 "Show following message whether deleted or not. 2728 "Show following message whether deleted or not.
2767 With prefix arg N, moves forward N messages, or backward if N is negative." 2729 With prefix arg N, moves forward N messages, or backward if N is negative."
2768 (interactive "p") 2730 (interactive "p")
2822 (interactive) 2784 (interactive)
2823 (pmail-maybe-set-message-counters) 2785 (pmail-maybe-set-message-counters)
2824 (pmail-show-message-maybe pmail-total-messages)) 2786 (pmail-show-message-maybe pmail-total-messages))
2825 2787
2826 (defun pmail-what-message () 2788 (defun pmail-what-message ()
2789 "For debugging Pmail: find the message number that point is in."
2827 (let ((where (point)) 2790 (let ((where (point))
2828 (low 1) 2791 (low 1)
2829 (high pmail-total-messages) 2792 (high pmail-total-messages)
2830 (mid (/ pmail-total-messages 2))) 2793 (mid (/ pmail-total-messages 2)))
2831 (while (> (- high low) 1) 2794 (while (> (- high low) 1)
2833 (setq low mid) 2796 (setq low mid)
2834 (setq high mid)) 2797 (setq high mid))
2835 (setq mid (+ low (/ (- high low) 2)))) 2798 (setq mid (+ low (/ (- high low) 2))))
2836 (if (>= where (pmail-msgbeg high)) high low))) 2799 (if (>= where (pmail-msgbeg high)) high low)))
2837 2800
2801 ;; Searching in Pmail file.
2802
2838 (defun pmail-search-message (msg regexp) 2803 (defun pmail-search-message (msg regexp)
2839 "Return non-nil, if for message number MSG, regexp REGEXP matches." 2804 "Return non-nil, if for message number MSG, regexp REGEXP matches."
2840 ;; This is adequate because its only caller, pmail-search, 2805 ;; This is adequate because its only caller, pmail-search,
2841 ;; unswaps the buffers. 2806 ;; unswaps the buffers.
2842 (goto-char (pmail-msgbeg msg)) 2807 (goto-char (pmail-msgbeg msg))
2938 ((not pmail-search-last-regexp) 2903 ((not pmail-search-last-regexp)
2939 (error "No previous Pmail search string"))) 2904 (error "No previous Pmail search string")))
2940 (list pmail-search-last-regexp 2905 (list pmail-search-last-regexp
2941 (prefix-numeric-value current-prefix-arg)))) 2906 (prefix-numeric-value current-prefix-arg))))
2942 (pmail-search regexp (- (or n 1)))) 2907 (pmail-search regexp (- (or n 1))))
2943 2908
2909 ;; Scan for attributes, and compare subjects.
2944 2910
2945 (defun pmail-first-unseen-message () 2911 (defun pmail-first-unseen-message ()
2946 "Return the message index for the first message which has the 2912 "Return message number of first message which has `unseen' attribute."
2947 `unseen' attribute."
2948 (pmail-maybe-set-message-counters) 2913 (pmail-maybe-set-message-counters)
2949 (let ((current 1) 2914 (let ((current 1)
2950 found) 2915 found)
2951 (save-restriction 2916 (save-restriction
2952 (widen) 2917 (widen)
3066 (defun pmail-delete-backward () 3031 (defun pmail-delete-backward ()
3067 "Delete this message and move to previous nondeleted one. 3032 "Delete this message and move to previous nondeleted one.
3068 Deleted messages stay in the file until the \\[pmail-expunge] command is given." 3033 Deleted messages stay in the file until the \\[pmail-expunge] command is given."
3069 (interactive) 3034 (interactive)
3070 (pmail-delete-forward t)) 3035 (pmail-delete-forward t))
3036
3037 ;; Expunging.
3071 3038
3072 ;; Compute the message number a given message would have after expunging. 3039 ;; Compute the message number a given message would have after expunging.
3073 ;; The present number of the message is OLDNUM. 3040 ;; The present number of the message is OLDNUM.
3074 ;; DELETEDVEC should be pmail-deleted-vector. 3041 ;; DELETEDVEC should be pmail-deleted-vector.
3075 ;; The value is nil for a message that would be deleted. 3042 ;; The value is nil for a message that would be deleted.
3324 (aref pmail-msgref-vector msgnum)) 3291 (aref pmail-msgref-vector msgnum))
3325 pmail-answered-attr-index)) 3292 pmail-answered-attr-index))
3326 nil 3293 nil
3327 (list (cons "References" (concat (mapconcat 'identity references " ") 3294 (list (cons "References" (concat (mapconcat 'identity references " ")
3328 " " message-id)))))) 3295 " " message-id))))))
3329 3296
3330 (defun pmail-mark-message (buffer msgnum-list attribute) 3297 (defun pmail-mark-message (buffer msgnum-list attribute)
3331 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE. 3298 "Give BUFFER's message number in MSGNUM-LIST the attribute ATTRIBUTE.
3332 This is use in the send-actions for message buffers. 3299 This is use in the send-actions for message buffers.
3333 MSGNUM-LIST is a list of the form (MSGNUM) 3300 MSGNUM-LIST is a list of the form (MSGNUM)
3334 which is an element of pmail-msgref-vector." 3301 which is an element of pmail-msgref-vector."