comparison lisp/packages/reportmail.el @ 100:4be1180a9e89 r20-1b2

Import from CVS: tag r20-1b2
author cvs
date Mon, 13 Aug 2007 09:15:11 +0200
parents 131b0175ea99
children
comparison
equal deleted inserted replaced
99:2d83cbd90d8d 100:4be1180a9e89
18 ;; GNU Emacs General Public License. A copy of this license is 18 ;; GNU Emacs General Public License. A copy of this license is
19 ;; supposed to have been given to you along with GNU Emacs so you 19 ;; supposed to have been given to you along with GNU Emacs so you
20 ;; can know your rights and responsibilities. It should be in a 20 ;; can know your rights and responsibilities. It should be in a
21 ;; file named COPYING. Among other things, the copyright notice 21 ;; file named COPYING. Among other things, the copyright notice
22 ;; and this notice must be preserved on all copies. 22 ;; and this notice must be preserved on all copies.
23
24 ;;; Synched up with: Not in FSF.
25 ;;; #### Appears to duplicate time.el. Perhaps should be nuked.
26 23
27 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 24 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
28 ; 25 ;
29 ; Installation 26 ; Installation
30 ; ------------ 27 ; ------------
119 116
120 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 117 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
121 ; 118 ;
122 ; HISTORY 119 ; HISTORY
123 ; 120 ;
124 ; 19 dec 93 Jamie Zawinski <jwz@netscape.com> 121 ; 19 dec 93 Jamie Zawinski <jwz@lucid.com>
125 ; Protected it from edits of the *reportmail* buffer; made the process 122 ; Protected it from edits of the *reportmail* buffer; made the process
126 ; filters not interfere with the match data. 123 ; filters not interfere with the match data.
127 ; 124 ;
128 ; 15 dec 93 Jamie Zawinski <jwz@netscape.com> 125 ; 15 dec 93 Jamie Zawinski <jwz@lucid.com>
129 ; Kyle renamed timer.el to itimer.el; made this use the new names. 126 ; Kyle renamed timer.el to itimer.el; made this use the new names.
130 ; 127 ;
131 ; 27 aug 93 Jamie Zawinski <jwz@netscape.com> 128 ; 27 aug 93 Jamie Zawinski <jwz@lucid.com>
132 ; Use mail-extr to parse addresses if it is loadable. 129 ; Use mail-extr to parse addresses if it is loadable.
133 ; 130 ;
134 ; 15 oct 92 Benjamin Pierce (bcp@cs.cmu.edu) 131 ; 15 oct 92 Benjamin Pierce (bcp@cs.cmu.edu)
135 ; Merged recent changes 132 ; Merged recent changes
136 ; 133 ;
137 ; 14 oct 92 Jamie Zawinski <jwz@netscape.com> 134 ; 14 oct 92 Jamie Zawinski <jwz@lucid.com>
138 ; Added support for xbiff++. 135 ; Added support for xbiff++.
139 ; 136 ;
140 ; 17 sep 92 Benjamin Pierce (bcp@cs.cmu.edu) 137 ; 17 sep 92 Benjamin Pierce (bcp@cs.cmu.edu)
141 ; Improvements to message display code. 138 ; Improvements to message display code.
142 ; 139 ;
143 ; 15 sep 92 Benjamin Pierce (bcp@cs.cmu.edu) 140 ; 15 sep 92 Benjamin Pierce (bcp@cs.cmu.edu)
144 ; Minor bug fixes. 141 ; Minor bug fixes.
145 ; 142 ;
146 ; 1 may 92 Jamie Zawinski <jwz@netscape.com> 143 ; 1 may 92 Jamie Zawinski <jwz@lucid.com>
147 ; Converted to work with Kyle Jones' timer.el package. 144 ; Converted to work with Kyle Jones' timer.el package.
148 ; 145 ;
149 ; 3 may 91 Jamie Zawinski <jwz@netscape.com> 146 ; 3 may 91 Jamie Zawinski <jwz@lucid.com>
150 ; Made the display-time-sentinel make a fuss when the process dies. 147 ; Made the display-time-sentinel make a fuss when the process dies.
151 ; 148 ;
152 ; 26 mar 91 Jamie Zawinski <jwz@netscape.com> 149 ; 26 mar 91 Jamie Zawinski <jwz@lucid.com>
153 ; Merged with BCP's latest posted version 150 ; Merged with BCP's latest posted version
154 ; 151 ;
155 ; 5 mar 91 Jamie Zawinski <jwz@netscape.com> 152 ; 5 mar 91 Jamie Zawinski <jwz@lucid.com>
156 ; Added compatibility with Emacs 18.57. 153 ; Added compatibility with Emacs 18.57.
157 ; 154 ;
158 ; 25 Jan 91 Benjamin Pierce (bcp@cs.cmu.edu) 155 ; 25 Jan 91 Benjamin Pierce (bcp@cs.cmu.edu)
159 ; Added facility for regular-expression matching of junk-mail 156 ; Added facility for regular-expression matching of junk-mail
160 ; checklist. Set inhibit-local-variables to t inside of 157 ; checklist. Set inhibit-local-variables to t inside of
161 ; display-time-process-new-mail to prevent letterbombs 158 ; display-time-process-new-mail to prevent letterbombs
162 ; (suggested by jwz). 159 ; (suggested by jwz).
163 ; 160 ;
164 ; 15 feb 91 Jamie Zawinski <jwz@netscape.com> 161 ; 15 feb 91 Jamie Zawinski <jwz@lucid.com>
165 ; Made the values of display-time-message-separator and 162 ; Made the values of display-time-message-separator and
166 ; display-time-incoming-mail-file be initialized when this code 163 ; display-time-incoming-mail-file be initialized when this code
167 ; starts, instead of forcing the user to do it. This means that 164 ; starts, instead of forcing the user to do it. This means that
168 ; this code can safely be dumped with emacs. Also, it now notices 165 ; this code can safely be dumped with emacs. Also, it now notices
169 ; when it's at CMU, and defaults to something reasonable. Removed 166 ; when it's at CMU, and defaults to something reasonable. Removed
170 ; display-time-wait-hard, because I learned how to make echo-area 167 ; display-time-wait-hard, because I learned how to make echo-area
171 ; messages be persistent (not go away at the first key). I wish 168 ; messages be persistent (not go away at the first key). I wish
172 ; GC messages didn't destroy it, though... 169 ; GC messages didn't destroy it, though...
173 ; 170 ;
174 ; 20 Dec 90 Jamie Zawinski <jwz@netscape.com> 171 ; 20 Dec 90 Jamie Zawinski <jwz@lucid.com>
175 ; Added new variables: display-time-no-file-means-no-mail, 172 ; Added new variables: display-time-no-file-means-no-mail,
176 ; display-time-wait-hard, and display-time-junk-mail-ring-bell. 173 ; display-time-wait-hard, and display-time-junk-mail-ring-bell.
177 ; Made display-time-message-separator be compared case-insensitively. 174 ; Made display-time-message-separator be compared case-insensitively.
178 ; Made the junk-mail checklist use a member-search rather than a 175 ; Made the junk-mail checklist use a member-search rather than a
179 ; prefix-search. 176 ; prefix-search.
206 ; To use: (setq display-time-load nil) 203 ; To use: (setq display-time-load nil)
207 ; 204 ;
208 ; Added facility for reporting incoming mail (modeled after gosmacs 205 ; Added facility for reporting incoming mail (modeled after gosmacs
209 ; reportmail.ml package written by Benjamin Pierce). 206 ; reportmail.ml package written by Benjamin Pierce).
210 207
211 (require 'itimer) ; this is xemacs, so why conditionalize? 208
212 (require 'mail-extr) 209 (if (string-match "XEmacs" emacs-version)
210 (require 'itimer))
211
212 (condition-case ()
213 (require 'mail-extr)
214 (error nil))
213 215
214 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
215 ;;; User Variables ;;; 217 ;;; User Variables ;;;
216 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 218 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
217 219
354 (defmacro display-time-debug (mesg &rest args) 356 (defmacro display-time-debug (mesg &rest args)
355 (list 357 (list
356 'if 'display-time-debugging 358 'if 'display-time-debugging
357 (list 'display-time-debug-mesg 359 (list 'display-time-debug-mesg
358 (append (list 'format mesg) args)))) 360 (append (list 'format mesg) args))))
361
362 (defmacro display-time-save-match-data (&rest body)
363 ;; Execute the BODY forms, restoring the global value of the match data.
364 ;; We need this because it's antisocial for process filters to change
365 ;; the regexp match registers.
366 (list 'let '((_match_data_ (match-data)))
367 (list 'unwind-protect
368 (cons 'progn body)
369 '(store-match-data _match_data_))))
359 370
360 (defun display-time-init () 371 (defun display-time-init ()
361 ;; If the mail-file isn't set, figure it out. 372 ;; If the mail-file isn't set, figure it out.
362 (or display-time-incoming-mail-file 373 (or display-time-incoming-mail-file
363 (setq display-time-incoming-mail-file 374 (setq display-time-incoming-mail-file
423 (if (not (memq 'display-time-string global-mode-string)) 434 (if (not (memq 'display-time-string global-mode-string))
424 (setq global-mode-string 435 (setq global-mode-string
425 (append global-mode-string '(display-time-string)))) 436 (append global-mode-string '(display-time-string))))
426 (setq display-time-string "time and load") 437 (setq display-time-string "time and load")
427 438
428 (let ((old (get-itimer "display-time"))) 439 (if (featurep 'itimer)
429 (if old (delete-itimer old)) 440 (let ((old (get-itimer "display-time")))
430 (start-itimer "display-time" 'display-time-timer-function 441 (if old (delete-itimer old))
431 display-time-interval display-time-interval) 442 (start-itimer "display-time" 'display-time-timer-function
432 (display-time-timer-function)) 443 display-time-interval display-time-interval)
433 444 (display-time-timer-function))
445 ;; if we don't have timers, then use one of the process mechanisms.
446 (setq display-time-loadst-process
447 (if (string-match "18\\.5[0-5]" (emacs-version))
448 (start-process "display-time-loadst" nil
449 "loadst"
450 "-n" (int-to-string display-time-interval))
451 (start-process "display-time-wakeup" nil
452 (concat exec-directory "wakeup")
453 (int-to-string display-time-interval))))
454 (process-kill-without-query display-time-loadst-process)
455 (set-process-sentinel display-time-loadst-process
456 'display-time-sentinel)
457 (set-process-filter display-time-loadst-process
458 (if (string-match "^18\\.5[0-5]" (emacs-version))
459 'display-time-filter-18-55
460 'display-time-filter-18-57)))
461
434 (if display-time-use-xbiff 462 (if display-time-use-xbiff
435 (progn 463 (progn
436 (display-time-del-file display-time-mail-arrived-file) 464 (display-time-del-file display-time-mail-arrived-file)
437 (setq display-time-xbiff-process 465 (setq display-time-xbiff-process
438 (apply 'start-process "display-time-xbiff" nil 466 (apply 'start-process "display-time-xbiff" nil
443 (sit-for 1) ; Need time to see if xbiff fails. 471 (sit-for 1) ; Need time to see if xbiff fails.
444 (if (/= 0 (process-exit-status display-time-xbiff-process)) 472 (if (/= 0 (process-exit-status display-time-xbiff-process))
445 (error "Display time: xbiff failed. Check xbiff-arg-list")))))) 473 (error "Display time: xbiff failed. Check xbiff-arg-list"))))))
446 (display-time-total-reset)) 474 (display-time-total-reset))
447 475
448 (defun display-time-timer-function () 476
449 ;; was: (defun display-time-filter-18-57 (proc string) ; args are ignored 477 (defun display-time-sentinel (proc reason)
450 ;; but we're not supporting version 18 here and I'm trimming excess 478 (display-time-save-match-data
451 (save-match-data 479 ;; notice if the process has died an untimely death...
452 (display-time-debug "display-time-timer-function") 480 (display-time-debug "display-time-sentinel")
453 (if display-time-flush-echo-area 481 (cond ((memq (process-status proc) '(stop exit closed signal))
454 (progn 482 (if (and (stringp reason) (string-match "\n?\n*\\'" reason))
455 (display-time-debug "flush echo area") 483 (setq reason (substring reason 0 (match-beginning 0))))
456 (display-time-message ""))) 484 (beep)
457 (let ((mailp (and (file-exists-p display-time-incoming-mail-file) 485 (setq display-time-string (format "%s" reason))
458 (not (eq 0 (nth 7 (file-attributes 486 (display-time-message "")
459 display-time-incoming-mail-file))))))) 487 (message "process %s: %s (%s)" proc reason (process-status proc))))
460 (if display-time-announce-mail 488 (display-time-force-redisplay)))
461 (if mailp 489
462 (display-time-process-new-mail) 490 (defun display-time-filter-18-55 (proc string)
491 (display-time-save-match-data
492 (if display-time-flush-echo-area (display-time-message ""))
493 ;; Desired data can't need more than the last 30 chars,
494 ;; so save time by flushing the rest.
495 ;; This way, if we have many different times all collected at once,
496 ;; we can discard all but the last few very fast.
497 (display-time-debug "display-time-filter-18-55")
498 (if (> (length string) 30) (setq string (substring string -30)))
499 ;; Now discard all but the very last one.
500 (while (and (> (length string) 4)
501 (string-match "[0-9]+:[0-9][0-9].." string 4))
502 (setq string (substring string (match-beginning 0))))
503 (if (string-match "[^0-9][0-9]+:" string)
504 (setq string (substring string 0 (1+ (match-beginning 0)))))
505 ;; If we're announcing mail and mail has come, process any new messages
506 (if display-time-announce-mail
507 (if (string-match "Mail" string)
508 (display-time-process-new-mail)
509 (display-time-total-reset)))
510 ;; Format the mode line time display
511 (let ((time-string (if (string-match "Mail" string)
512 (if display-time-announce-mail
513 display-time-mail-modeline
514 "Mail "))))
515 (if (and display-time-time (string-match "[0-9]+:[0-9][0-9].." string))
516 (setq time-string
517 (concat time-string
518 (substring string (match-beginning 0) (match-end 0))
519 " ")))
520 (if display-time-day-and-date
521 (setq time-string
522 (concat time-string
523 (substring (current-time-string) 0 11))))
524 (if (and display-time-load (string-match "[0-9]+\\.[0-9][0-9]" string))
525 (setq time-string
526 (concat time-string
527 (substring string (match-beginning 0) (match-end 0))
528 " ")))
529 ;; Install the new time for display.
530 (setq display-time-string time-string)
531 (display-time-force-redisplay))))
532
533 (defun display-time-filter-18-57 (proc string) ; args are ignored
534 (display-time-save-match-data
535 (display-time-debug "display-time-filter-18-57")
536 (if display-time-flush-echo-area
537 (progn
538 (display-time-debug "flush echo area")
539 (display-time-message "")))
540 (let ((mailp (and (file-exists-p display-time-incoming-mail-file)
541 (not (eq 0 (nth 7 (file-attributes
542 display-time-incoming-mail-file)))))))
543 (if display-time-announce-mail
544 (if mailp
545 (display-time-process-new-mail)
463 (display-time-total-reset))) 546 (display-time-total-reset)))
464 ;; Format the mode line time display 547 ;; Format the mode line time display
465 (let ((time-string (if mailp 548 (let ((time-string (if mailp
466 (if display-time-announce-mail 549 (if display-time-announce-mail
467 display-time-mail-modeline 550 display-time-mail-modeline
468 "Mail ")))) 551 "Mail "))))
469 (if display-time-time 552 (if display-time-time
470 (let* ((time (current-time-string)) 553 (let* ((time (current-time-string))
471 (hour (read (substring time 11 13))) 554 (hour (read (substring time 11 13)))
472 (pm (>= hour 12))) 555 (pm (>= hour 12)))
473 (if (> hour 12) (setq hour (- hour 12))) 556 (if (> hour 12) (setq hour (- hour 12)))
474 (if (= hour 0) (setq hour 12)) 557 (if (= hour 0) (setq hour 12))
475 (setq time-string
476 (concat time-string
477 (format "%d" hour) (substring time 13 16)
478 (if pm "pm " "am ")))))
479 (if display-time-day-and-date
480 (setq time-string 558 (setq time-string
481 (concat time-string 559 (concat time-string
482 (substring (current-time-string) 0 11)))) 560 (format "%d" hour) (substring time 13 16)
483 (if display-time-load 561 (if pm "pm " "am ")))))
484 (setq time-string 562 (if display-time-day-and-date
485 (concat time-string 563 (setq time-string
486 (condition-case () 564 (concat time-string
487 (let* ((la (car (load-average))) 565 (substring (current-time-string) 0 11))))
488 (load (if (zerop la) 566 (if display-time-load
489 nil 567 (setq time-string
490 (format "%03d" la)))) 568 (concat time-string
491 (if load 569 (condition-case ()
492 (concat (substring load 0 -2) 570 (let* ((la (car (load-average)))
493 "." (substring load -2)) 571 (load (if (zerop la)
494 "")) 572 nil
495 (error "load-error")) 573 (format "%03d" la))))
496 " "))) 574 (if load
497 ;; Install the new time for display. 575 (concat (substring load 0 -2)
498 (setq display-time-string time-string) 576 "." (substring load -2))
499 (force-mode-line-update t))))) 577 ""))
578 (error "load-error"))
579 " ")))
580 ;; Install the new time for display.
581 (setq display-time-string time-string)
582
583 (display-time-force-redisplay)))))
584
585 (defun display-time-timer-function ()
586 (display-time-filter-18-57 nil nil))
587
588 (defun display-time-force-redisplay ()
589 "Force redisplay of all buffers' mode lines to be considered."
590 (save-excursion (set-buffer (other-buffer)))
591 (set-buffer-modified-p (buffer-modified-p))
592 ;; Do redisplay right now, if no input pending.
593 (sit-for 0))
500 594
501 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 595 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
502 ;;; Mail processing ;;; 596 ;;; Mail processing ;;;
503 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; 597 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
504 598
560 (setq display-time-mail-who-from "Junk mail") 654 (setq display-time-mail-who-from "Junk mail")
561 (setq display-time-mail-modeline "") 655 (setq display-time-mail-modeline "")
562 (setq display-time-previous-mail-buffer-max 1) 656 (setq display-time-previous-mail-buffer-max 1)
563 (display-time-message "") ; clear the echo-area. 657 (display-time-message "") ; clear the echo-area.
564 ) 658 )
659
660 (or (fboundp 'buffer-disable-undo)
661 (fset 'buffer-disable-undo 'buffer-flush-undo))
565 662
566 (defun display-time-process-new-mail () 663 (defun display-time-process-new-mail ()
567 (setq display-time-may-need-to-reset t) 664 (setq display-time-may-need-to-reset t)
568 (let ((mail-buffer (get-buffer display-time-mail-buffer-name)) 665 (let ((mail-buffer (get-buffer display-time-mail-buffer-name))
569 (inhibit-local-variables t) 666 (inhibit-local-variables t)
691 (insert str)))) 788 (insert str))))
692 ;; if we're reading from the echo-area, and all we were going to do is 789 ;; if we're reading from the echo-area, and all we were going to do is
693 ;; clear the thing, like, don't bother, that's annoying. 790 ;; clear the thing, like, don't bother, that's annoying.
694 (if (and in-echo-area-already (string= "" str)) 791 (if (and in-echo-area-already (string= "" str))
695 nil 792 nil
696 ;; XEmacs version fix 793 (if (and (string= str "") (string-match "^19" emacs-version))
697 (if (and (string= str "") (not (string-match "^18" emacs-version)))
698 (message nil) 794 (message nil)
699 (message "%s" str))))) 795 (message "%s" str)))))
700 796
701 (defun display-time-process-good-message () 797 (defun display-time-process-good-message ()
702 (display-time-debug "Formatting message announcement (good message)") 798 (display-time-debug "Formatting message announcement (good message)")
759 (to (display-time-get-field "To" "")) 855 (to (display-time-get-field "To" ""))
760 (print-subject (if (string= subject "") 856 (print-subject (if (string= subject "")
761 "" 857 ""
762 (concat " (" subject ")"))) 858 (concat " (" subject ")")))
763 (print-from (display-time-truncate from display-time-max-from-length)) 859 (print-from (display-time-truncate from display-time-max-from-length))
860 (short-from (display-time-truncate
861 (display-time-extract-short-addr from) 25))
764 (print-to (if (display-time-member to display-time-my-addresses) 862 (print-to (if (display-time-member to display-time-my-addresses)
765 "" 863 ""
766 (display-time-truncate 864 (display-time-truncate
767 (display-time-extract-short-addr to) 865 (display-time-extract-short-addr to)
768 display-time-max-to-length)))) 866 display-time-max-to-length))))
871 969
872 (defvar display-time-debugging-messages nil 970 (defvar display-time-debugging-messages nil
873 "When non-NIL, reportmail displays status messages in real time.") 971 "When non-NIL, reportmail displays status messages in real time.")
874 972
875 (defun display-time-debug-mesg (mesg) 973 (defun display-time-debug-mesg (mesg)
876 (save-match-data 974 (display-time-save-match-data
877 (if display-time-debugging-messages 975 (if display-time-debugging-messages
878 (progn 976 (progn
879 (message "Reportmail: %s" mesg) 977 (message "Reportmail: %s" mesg)
880 (sit-for 1) 978 (sit-for 1)
881 )) 979 ))