Mercurial > emacs
comparison lisp/mail/rmail.el @ 16241:3c84b8d28902
(rmail-insert-inbox-text): Detect locked
RMAIL files at the outset, before copying any files.
(rmail-find-all-files): Eliminate recursive scan. Rely on directory-files
to do the filtering.
(rmail-convert-to-babyl-format):
Increase sit-for timeout to 3 seconds.
(rmail-get-new-mail): Handle files in multiple batches,
in case two inboxes have the same last name component.
(rmail-show-message): Bind `end' after clearing the
"unseen" attribute.
(rmail-show-message): Clear `unseen' even if header
is already reformatted--but don't do it if rmail-not-really-seen.
(rmail-not-really-seen): New variable.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Thu, 19 Sep 1996 03:21:11 +0000 |
parents | 79dba775070d |
children | 2e16f18e316c |
comparison
equal
deleted
inserted
replaced
16240:b448d7632094 | 16241:3c84b8d28902 |
---|---|
794 (defun rmail-input (filename) | 794 (defun rmail-input (filename) |
795 "Run Rmail on file FILENAME." | 795 "Run Rmail on file FILENAME." |
796 (interactive "FRun rmail on RMAIL file: ") | 796 (interactive "FRun rmail on RMAIL file: ") |
797 (rmail filename)) | 797 (rmail filename)) |
798 | 798 |
799 ;; Return a list of file names for all files in or under START | 799 |
800 ;; whose names match rmail-secondary-file-regexp. | 800 ;; This used to scan subdirectories recursively, but someone pointed out |
801 ;; This includes START itself, if that name matches. | 801 ;; that if the user wants that, person can put all the files in one dir. |
802 ;; But normally START is a directory. | 802 ;; And the recursive scan was slow. So I took it out. |
803 ;; rms, Sep 1996. | |
803 (defun rmail-find-all-files (start) | 804 (defun rmail-find-all-files (start) |
805 "Return list of file in dir START that match `rmail-secondary-file-regexp'." | |
804 (if (file-accessible-directory-p start) | 806 (if (file-accessible-directory-p start) |
805 ;; Don't sort here. | 807 ;; Don't sort here. |
806 (let ((files (directory-files start t | 808 (let* ((case-fold-search t) |
807 rmail-secondary-file-regexp t)) | 809 (files (directory-files start t rmail-secondary-file-regexp))) |
808 (ret nil) | |
809 file) | |
810 (while files | |
811 (setq file (car files)) | |
812 (setq files (cdr files)) | |
813 (or (member (file-name-nondirectory start) '("." "..")) | |
814 (setq ret (nconc | |
815 (rmail-find-all-files file) | |
816 ret)))) | |
817 ;; Sort here instead of in directory-files | 810 ;; Sort here instead of in directory-files |
818 ;; because this list is usually much shorter. | 811 ;; because this list is usually much shorter. |
819 (sort ret 'string<)) | 812 (sort files 'string<)))) |
820 (let ((case-fold-search nil)) | |
821 (if (string-match rmail-secondary-file-regexp start) | |
822 (list (file-name-nondirectory start)))))) | |
823 | 813 |
824 (defun rmail-list-to-menu (menu-name l action &optional full-name) | 814 (defun rmail-list-to-menu (menu-name l action &optional full-name) |
825 (let ((menu (make-sparse-keymap menu-name))) | 815 (let ((menu (make-sparse-keymap menu-name))) |
826 (mapcar | 816 (mapcar |
827 (function (lambda (item) | 817 (function (lambda (item) |
905 (rmail-maybe-set-message-counters) | 895 (rmail-maybe-set-message-counters) |
906 (widen) | 896 (widen) |
907 ;; Get rid of all undo records for this buffer. | 897 ;; Get rid of all undo records for this buffer. |
908 (or (eq buffer-undo-list t) | 898 (or (eq buffer-undo-list t) |
909 (setq buffer-undo-list nil)) | 899 (setq buffer-undo-list nil)) |
910 (unwind-protect | 900 (let ((all-files (if file-name (list file-name) |
911 (let ((opoint (point)) | 901 rmail-inbox-list))) |
912 (new-messages 0) | 902 (unwind-protect |
913 (delete-files ()) | 903 (while all-files |
914 ;; If buffer has not changed yet, and has not been saved yet, | 904 (let ((opoint (point)) |
915 ;; don't replace the old backup file now. | 905 (new-messages 0) |
916 (make-backup-files (and make-backup-files (buffer-modified-p))) | 906 (delete-files ()) |
917 (buffer-read-only nil) | 907 ;; If buffer has not changed yet, and has not been saved yet, |
918 ;; Don't make undo records for what we do in getting mail. | 908 ;; don't replace the old backup file now. |
919 (buffer-undo-list t) | 909 (make-backup-files (and make-backup-files (buffer-modified-p))) |
920 success) | 910 (buffer-read-only nil) |
921 (goto-char (point-max)) | 911 ;; Don't make undo records for what we do in getting mail. |
922 (skip-chars-backward " \t\n") ; just in case of brain damage | 912 (buffer-undo-list t) |
923 (delete-region (point) (point-max)) ; caused by require-final-newline | 913 success |
924 (save-excursion | 914 ;; Files to insert this time around. |
925 (save-restriction | 915 files |
926 (narrow-to-region (point) (point)) | 916 ;; Last names of those files. |
927 ;; Read in the contents of the inbox files, | 917 file-last-names) |
928 ;; renaming them as necessary, | 918 ;; Pull files off all-files onto files |
929 ;; and adding to the list of files to delete eventually. | 919 ;; as long as there is no name conflict. |
930 (if file-name | 920 ;; A conflict happens when two inbox file names |
931 (rmail-insert-inbox-text (list file-name) nil) | 921 ;; have the same last component. |
932 (setq delete-files (rmail-insert-inbox-text rmail-inbox-list t))) | 922 (while (and all-files |
933 ;; Scan the new text and convert each message to babyl format. | 923 (not (member (file-name-nondirectory (car all-files)) |
934 (goto-char (point-min)) | 924 file-last-names))) |
935 (unwind-protect | 925 (setq files (cons (car all-files) files) |
936 (save-excursion | 926 file-last-names |
937 (setq new-messages (rmail-convert-to-babyl-format) | 927 (cons (file-name-nondirectory (car all-files)) files)) |
938 success t)) | 928 (setq all-files (cdr all-files))) |
939 ;; If we could not convert the file's inboxes, | 929 ;; Put them back in their original order. |
940 ;; rename the files we tried to read | 930 (setq files (nreverse files)) |
941 ;; so we won't over and over again. | 931 |
942 (if (and (not file-name) (not success)) | 932 (goto-char (point-max)) |
943 (let ((files delete-files) | 933 (skip-chars-backward " \t\n") ; just in case of brain damage |
944 (count 0)) | 934 (delete-region (point) (point-max)) ; caused by require-final-newline |
945 (while files | 935 (save-excursion |
946 (while (file-exists-p (format "RMAILOSE.%d" count)) | 936 (save-restriction |
947 (setq count (1+ count))) | 937 (narrow-to-region (point) (point)) |
948 (rename-file (car files) | 938 ;; Read in the contents of the inbox files, |
949 (format "RMAILOSE.%d" count)) | 939 ;; renaming them as necessary, |
950 (setq files (cdr files)))))) | 940 ;; and adding to the list of files to delete eventually. |
951 (or (zerop new-messages) | 941 (if file-name |
952 (let (success) | 942 (rmail-insert-inbox-text files nil) |
953 (widen) | 943 (setq delete-files (rmail-insert-inbox-text files t))) |
954 (search-backward "\n\^_" nil t) | 944 ;; Scan the new text and convert each message to babyl format. |
955 (narrow-to-region (point) (point-max)) | 945 (goto-char (point-min)) |
956 (goto-char (1+ (point-min))) | 946 (unwind-protect |
957 (rmail-count-new-messages) | 947 (save-excursion |
958 (run-hooks 'rmail-get-new-mail-hook) | 948 (setq new-messages (rmail-convert-to-babyl-format) |
959 (save-buffer))) | 949 success t)) |
960 ;; Delete the old files, now that babyl file is saved. | 950 ;; If we could not convert the file's inboxes, |
961 (while delete-files | 951 ;; rename the files we tried to read |
962 (condition-case () | 952 ;; so we won't over and over again. |
963 ;; First, try deleting. | 953 (if (and (not file-name) (not success)) |
954 (let ((delfiles delete-files) | |
955 (count 0)) | |
956 (while delfiles | |
957 (while (file-exists-p (format "RMAILOSE.%d" count)) | |
958 (setq count (1+ count))) | |
959 (rename-file (car delfiles) | |
960 (format "RMAILOSE.%d" count)) | |
961 (setq delfiles (cdr delfiles)))))) | |
962 (or (zerop new-messages) | |
963 (let (success) | |
964 (widen) | |
965 (search-backward "\n\^_" nil t) | |
966 (narrow-to-region (point) (point-max)) | |
967 (goto-char (1+ (point-min))) | |
968 (rmail-count-new-messages) | |
969 (run-hooks 'rmail-get-new-mail-hook) | |
970 (save-buffer))) | |
971 ;; Delete the old files, now that babyl file is saved. | |
972 (while delete-files | |
964 (condition-case () | 973 (condition-case () |
965 (delete-file (car delete-files)) | 974 ;; First, try deleting. |
966 (file-error | 975 (condition-case () |
967 ;; If we can't delete it, truncate it. | 976 (delete-file (car delete-files)) |
968 (write-region (point) (point) (car delete-files)))) | 977 (file-error |
969 (file-error nil)) | 978 ;; If we can't delete it, truncate it. |
970 (setq delete-files (cdr delete-files))))) | 979 (write-region (point) (point) (car delete-files)))) |
971 (if (= new-messages 0) | 980 (file-error nil)) |
972 (progn (goto-char opoint) | 981 (setq delete-files (cdr delete-files))))) |
973 (if (or file-name rmail-inbox-list) | 982 (if (= new-messages 0) |
974 (message "(No new mail has arrived)")) | 983 (progn (goto-char opoint) |
975 nil) | 984 (if (or file-name rmail-inbox-list) |
976 (if (rmail-summary-exists) | 985 (message "(No new mail has arrived)")) |
977 (rmail-select-summary | 986 nil) |
978 (rmail-update-summary))) | 987 (if (rmail-summary-exists) |
979 (message "%d new message%s read" | 988 (rmail-select-summary |
980 new-messages (if (= 1 new-messages) "" "s")) | 989 (rmail-update-summary))) |
981 ;; Move to the first new message | 990 (message "%d new message%s read" |
982 ;; unless we have other unseen messages before it. | 991 new-messages (if (= 1 new-messages) "" "s")) |
983 (rmail-show-message (rmail-first-unseen-message)) | 992 ;; Move to the first new message |
984 (run-hooks 'rmail-after-get-new-mail-hook) | 993 ;; unless we have other unseen messages before it. |
985 t)) | 994 (rmail-show-message (rmail-first-unseen-message)) |
986 ;; Don't leave the buffer screwed up if we get a disk-full error. | 995 (run-hooks 'rmail-after-get-new-mail-hook) |
987 (rmail-show-message))) | 996 t))) |
997 ;; Don't leave the buffer screwed up if we get a disk-full error. | |
998 (rmail-show-message)))) | |
988 | 999 |
989 (defun rmail-insert-inbox-text (files renamep) | 1000 (defun rmail-insert-inbox-text (files renamep) |
1001 ;; Detect a locked file now, so that we avoid moving mail | |
1002 ;; out of the real inbox file. (That could scare people.) | |
1003 (or (memq (file-locked-p buffer-file-name) '(nil t)) | |
1004 (error "RMAIL file %s is locked" | |
1005 (file-name-nondirectory buffer-file-name))) | |
990 (let (file tofile delete-files movemail popmail) | 1006 (let (file tofile delete-files movemail popmail) |
991 (while files | 1007 (while files |
992 (setq file (file-truename | 1008 (setq file (file-truename |
993 (expand-file-name (substitute-in-file-name (car files)))) | 1009 (expand-file-name (substitute-in-file-name (car files)))) |
994 tofile (expand-file-name | 1010 tofile (expand-file-name |
1140 (let ((count 0) start | 1156 (let ((count 0) start |
1141 (case-fold-search nil) | 1157 (case-fold-search nil) |
1142 (invalid-input-resync | 1158 (invalid-input-resync |
1143 (function (lambda () | 1159 (function (lambda () |
1144 (message "Invalid Babyl format in inbox!") | 1160 (message "Invalid Babyl format in inbox!") |
1145 (sit-for 1) | 1161 (sit-for 3) |
1146 ;; Try to get back in sync with a real message. | 1162 ;; Try to get back in sync with a real message. |
1147 (if (re-search-forward | 1163 (if (re-search-forward |
1148 (concat mmdf-delim1 "\\|^From") nil t) | 1164 (concat mmdf-delim1 "\\|^From") nil t) |
1149 (beginning-of-line) | 1165 (beginning-of-line) |
1150 (goto-char (point-max))))))) | 1166 (goto-char (point-max))))))) |
1645 (setq n rmail-total-messages | 1661 (setq n rmail-total-messages |
1646 rmail-current-message rmail-total-messages | 1662 rmail-current-message rmail-total-messages |
1647 blurb "No following message")) | 1663 blurb "No following message")) |
1648 (t | 1664 (t |
1649 (setq rmail-current-message n)))) | 1665 (setq rmail-current-message n)))) |
1650 (let ((beg (rmail-msgbeg n)) | 1666 (let ((beg (rmail-msgbeg n))) |
1651 (end (rmail-msgend n))) | |
1652 (goto-char beg) | 1667 (goto-char beg) |
1653 (forward-line 1) | 1668 (forward-line 1) |
1654 (if (= (following-char) ?0) | 1669 ;; Clear the "unseen" attribute when we show a message. |
1655 (progn | 1670 (rmail-set-attribute "unseen" nil) |
1671 ;; Reformat the header, or else find the reformatted header. | |
1672 (let ((end (rmail-msgend n))) | |
1673 (if (= (following-char) ?0) | |
1656 (rmail-reformat-message beg end) | 1674 (rmail-reformat-message beg end) |
1657 (rmail-set-attribute "unseen" nil)) | 1675 (search-forward "\n*** EOOH ***\n" end t) |
1658 (search-forward "\n*** EOOH ***\n" end t) | 1676 (narrow-to-region (point) end))) |
1659 (narrow-to-region (point) end)) | |
1660 (goto-char (point-min)) | 1677 (goto-char (point-min)) |
1661 (rmail-display-labels) | 1678 (rmail-display-labels) |
1662 (rmail-highlight-headers) | 1679 (rmail-highlight-headers) |
1663 (if transient-mark-mode (deactivate-mark)) | 1680 (if transient-mark-mode (deactivate-mark)) |
1664 (run-hooks 'rmail-show-message-hook) | 1681 (run-hooks 'rmail-show-message-hook) |