Mercurial > emacs
annotate lisp/mail/unrmail.el @ 101864:267681f66b59
*** empty log message ***
author | Eli Zaretskii <eliz@gnu.org> |
---|---|
date | Sat, 07 Feb 2009 11:09:56 +0000 |
parents | 1eedc742bd61 |
children | a67721ab1564 |
rev | line source |
---|---|
101536
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
1 ;;; unrmail.el --- convert Rmail Babyl files to mailbox files |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
2 |
101536
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
3 ;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, |
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
4 ;; 2009 Free Software Foundation, Inc. |
982 | 5 |
38695 | 6 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
7 ;; Keywords: mail |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
8 |
982 | 9 ;; This file is part of GNU Emacs. |
10 | |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
11 ;; GNU Emacs is free software: you can redistribute it and/or modify |
982 | 12 ;; it under the terms of the GNU General Public License as published by |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
13 ;; the Free Software Foundation, either version 3 of the License, or |
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
14 ;; (at your option) any later version. |
982 | 15 |
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. | |
20 | |
21 ;; You should have received a copy of the GNU General Public License | |
94674
ef65fa4dca3b
Switch to recommended form of GPLv3 permissions notice.
Glenn Morris <rgm@gnu.org>
parents:
93975
diff
changeset
|
22 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>. |
982 | 23 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
24 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
25 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
26 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
27 |
982 | 28 ;;;###autoload |
29 (defun batch-unrmail () | |
101536
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
30 "Convert old-style Rmail Babyl files to system inbox format. |
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
31 Specify the input Rmail Babyl file names as command line arguments. |
982 | 32 For each Rmail file, the corresponding output file name |
33 is made by adding `.mail' at the end. | |
34 For example, invoke `emacs -batch -f batch-unrmail RMAIL'." | |
35 (if (not noninteractive) | |
36 (error "`batch-unrmail' is to be used only with -batch")) | |
37 (let ((error nil)) | |
38 (while command-line-args-left | |
39 (or (unrmail (car command-line-args-left) | |
40 (concat (car command-line-args-left) ".mail")) | |
41 (setq error t)) | |
42 (setq command-line-args-left (cdr command-line-args-left))) | |
43 (message "Done") | |
44 (kill-emacs (if error 1 0)))) | |
45 | |
86440
4aedd218aad1
* mail/mspools.el (rmail-get-new-mail):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78232
diff
changeset
|
46 (declare-function mail-strip-quoted-names "mail-utils" (address)) |
4aedd218aad1
* mail/mspools.el (rmail-get-new-mail):
Dan Nicolaescu <dann@ics.uci.edu>
parents:
78232
diff
changeset
|
47 |
982 | 48 ;;;###autoload |
49 (defun unrmail (file to-file) | |
101536
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
50 "Convert old-style Rmail Babyl file FILE to system inbox format file TO-FILE." |
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
51 (interactive "fUnrmail (babyl file): \nFUnrmail into (new mailbox file): ") |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
52 (with-temp-buffer |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
53 ;; Read in the old Rmail file with no decoding. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
54 (let ((coding-system-for-read 'raw-text)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
55 (insert-file-contents file)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
56 ;; But make it multibyte. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
57 (set-buffer-multibyte t) |
101711
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
58 (setq buffer-file-coding-system 'raw-text-unix) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
59 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
60 (if (not (looking-at "BABYL OPTIONS")) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
61 (error "This file is not in Babyl format")) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
62 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
63 ;; Decode the file contents just as Rmail did. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
64 (let ((modifiedp (buffer-modified-p)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
65 (coding-system rmail-file-coding-system) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
66 from to) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
67 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
68 (search-forward "\n\^_" nil t) ; Skip BABYL header. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
69 (setq from (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
70 (goto-char (point-max)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
71 (search-backward "\n\^_" from 'mv) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
72 (setq to (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
73 (unless (and coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
74 (coding-system-p coding-system)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
75 (setq coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
76 ;; Emacs 21.1 and later writes RMAIL files in emacs-mule, but |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
77 ;; earlier versions did that with the current buffer's encoding. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
78 ;; So we want to favor detection of emacs-mule (whose normal |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
79 ;; priority is quite low), but still allow detection of other |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
80 ;; encodings if emacs-mule won't fit. The call to |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
81 ;; detect-coding-with-priority below achieves that. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
82 (car (detect-coding-with-priority |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
83 from to |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
84 '((coding-category-emacs-mule . emacs-mule)))))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
85 (unless (memq coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
86 '(undecided undecided-unix)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
87 (set-buffer-modified-p t) ; avoid locking when decoding |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
88 (let ((buffer-undo-list t)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
89 (decode-coding-region from to coding-system)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
90 (setq coding-system last-coding-system-used)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
91 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
92 (setq buffer-file-coding-system nil) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
93 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
94 ;; We currently don't use this value, but maybe we should. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
95 (setq save-buffer-coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
96 (or coding-system 'undecided))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
97 |
14296
e3e1d7c2e7e5
(unrmail): Default the directory of TO-FILE based on FILE.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
98 ;; Default the directory of TO-FILE based on where FILE is. |
e3e1d7c2e7e5
(unrmail): Default the directory of TO-FILE based on FILE.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
99 (setq to-file (expand-file-name to-file default-directory)) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
100 (condition-case () |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
101 (delete-file to-file) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
102 (file-error nil)) |
4266
5a7266ff9af1
(unrmail): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
103 (message "Writing messages to %s..." to-file) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
104 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
105 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
106 (let ((temp-buffer (get-buffer-create " unrmail")) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
107 (from-buffer (current-buffer))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
108 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
109 ;; Process the messages one by one. |
101839
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
110 (while (re-search-forward "^\^_\^l" nil t) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
111 (let ((beg (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
112 (end (save-excursion |
101839
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
113 (if (re-search-forward "^\^_\\(\^l\\|\\'\\)" nil t) |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
114 (match-beginning 0) |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
115 (point-max)))) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
116 (coding 'raw-text) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
117 label-line attrs keywords |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
118 mail-from reformatted) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
119 (with-current-buffer temp-buffer |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
120 (setq buffer-undo-list t) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
121 (erase-buffer) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
122 (setq buffer-file-coding-system coding) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
123 (insert-buffer-substring from-buffer beg end) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
124 (goto-char (point-min)) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
125 (forward-line 1) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
126 ;; Record whether the header is reformatted. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
127 (setq reformatted (= (following-char) ?1)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
128 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
129 ;; Collect the label line, then get the attributes |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
130 ;; and the keywords from it. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
131 (setq label-line |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
132 (buffer-substring (point) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
133 (save-excursion (forward-line 1) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
134 (point)))) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
135 (search-forward ",,") |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
136 (unless (eolp) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
137 (setq keywords |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
138 (buffer-substring (point) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
139 (progn (end-of-line) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
140 (1- (point))))) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
141 (setq keywords |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
142 (replace-regexp-in-string ", " "," keywords))) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
143 |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
144 (setq attrs |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
145 (list |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
146 (if (string-match ", answered," label-line) ?A ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
147 (if (string-match ", deleted," label-line) ?D ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
148 (if (string-match ", edited," label-line) ?E ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
149 (if (string-match ", filed," label-line) ?F ?-) |
101685
c39779cefaea
(unrmail): Fix conversion of BABYL attributes into Rmail-mbox attributes.
Eli Zaretskii <eliz@gnu.org>
parents:
101589
diff
changeset
|
150 (if (string-match ", retried," label-line) ?R ?-) |
c39779cefaea
(unrmail): Fix conversion of BABYL attributes into Rmail-mbox attributes.
Eli Zaretskii <eliz@gnu.org>
parents:
101589
diff
changeset
|
151 (if (string-match ", forwarded," label-line) ?S ?-) |
c39779cefaea
(unrmail): Fix conversion of BABYL attributes into Rmail-mbox attributes.
Eli Zaretskii <eliz@gnu.org>
parents:
101589
diff
changeset
|
152 (if (string-match ", unseen," label-line) ?U ?-) |
c39779cefaea
(unrmail): Fix conversion of BABYL attributes into Rmail-mbox attributes.
Eli Zaretskii <eliz@gnu.org>
parents:
101589
diff
changeset
|
153 (if (string-match ", resent," label-line) ?r ?-))) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
154 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
155 ;; Delete the special Babyl lines at the start, |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
156 ;; and the ***EOOH*** line, and the reformatted header if any. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
157 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
158 (if reformatted |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
159 (progn |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
160 (forward-line 2) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
161 ;; Delete Summary-Line headers. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
162 (let ((case-fold-search t)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
163 (while (looking-at "Summary-Line:") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
164 (forward-line 1))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
165 (delete-region (point-min) (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
166 ;; Delete the old reformatted header. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
167 (re-search-forward "^[*][*][*] EOOH [*][*][*]\n") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
168 (forward-line -1) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
169 (let ((start (point))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
170 (search-forward "\n\n") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
171 (delete-region start (point)))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
172 ;; Not reformatted. Delete the special |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
173 ;; lines before the real header. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
174 (re-search-forward "^[*][*][*] EOOH [*][*][*]\n") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
175 (delete-region (point-min) (point))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
176 |
101839
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
177 ;; Handle rmime formatting. |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
178 (when (require 'rmime nil t) |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
179 (let ((start (point))) |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
180 (while (search-forward rmime-magic-string nil t)) |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
181 (delete-region start (point)))) |
1eedc742bd61
Sync final change from rmail-mox-branch, rev 1.13.2.4, 2006-01-16.
Glenn Morris <rgm@gnu.org>
parents:
101830
diff
changeset
|
182 |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
183 ;; Some operations on the message header itself. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
184 (goto-char (point-min)) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
185 (save-restriction |
101536
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
186 (narrow-to-region |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
187 (point-min) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
188 (save-excursion (search-forward "\n\n" nil 'move) (point))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
189 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
190 ;; Fetch or construct what we should use in the `From ' line. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
191 (setq mail-from |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
192 (or (mail-fetch-field "Mail-From") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
193 (concat "From " |
101770
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
194 (mail-strip-quoted-names |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
195 (or (mail-fetch-field "from") |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
196 (mail-fetch-field "really-from") |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
197 (mail-fetch-field "sender") |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
198 "unknown")) |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
199 " " |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
200 (let ((date (mail-fetch-field "date"))) |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
201 (or |
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
202 (and date |
101771 | 203 (ignore-errors |
101830
6babeadc07c9
(unrmail): Use current-time-string.
Glenn Morris <rgm@gnu.org>
parents:
101771
diff
changeset
|
204 (current-time-string |
101771 | 205 (date-to-time date)))) |
101770
dab601ced3e6
(unrmail): In the absence of Mail-from, prefer Date over current-time.
Glenn Morris <rgm@gnu.org>
parents:
101711
diff
changeset
|
206 (current-time-string)))))) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
207 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
208 ;; If the message specifies a coding system, use it. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
209 (let ((maybe-coding (mail-fetch-field "X-Coding-System"))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
210 (if maybe-coding |
101711
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
211 (setq coding |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
212 ;; Force Unix EOLs. |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
213 (coding-system-change-eol-conversion |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
214 (intern maybe-coding) 0)) |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
215 ;; If there's no X-Coding-System header, assume the |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
216 ;; message was never decoded. |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
217 (setq coding 'raw-text-unix))) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
218 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
219 ;; Delete the Mail-From: header field if any. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
220 (when (re-search-forward "^Mail-from:" nil t) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
221 (beginning-of-line) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
222 (delete-region (point) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
223 (progn (forward-line 1) (point))))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
224 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
225 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
226 ;; Insert the `From ' line. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
227 (insert mail-from "\n") |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
228 ;; Record the keywords and attributes in our special way. |
101589
01abffb7f38c
(unrmail): Record labels in X-RMAIL-* fields, which are recognized by
Chong Yidong <cyd@stupidchicken.com>
parents:
101536
diff
changeset
|
229 (insert "X-RMAIL-ATTRIBUTES: " (apply 'string attrs) "\n") |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
230 (when keywords |
101589
01abffb7f38c
(unrmail): Record labels in X-RMAIL-* fields, which are recognized by
Chong Yidong <cyd@stupidchicken.com>
parents:
101536
diff
changeset
|
231 (insert "X-RMAIL-KEYWORDS: " keywords "\n")) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
232 (goto-char (point-min)) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
233 ;; ``Quote'' "\nFrom " as "\n>From " |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
234 ;; (note that this isn't really quoting, as there is no requirement |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
235 ;; that "\n[>]+From " be quoted in the same transparent way.) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
236 (let ((case-fold-search nil)) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
237 (while (search-forward "\nFrom " nil t) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
238 (forward-char -5) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
239 (insert ?>))) |
101711
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
240 ;; Write it to the output file, suitably encoded. |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
241 (let ((coding-system-for-write coding)) |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
242 (write-region (point-min) (point-max) to-file t |
4ea3bd98b124
(unrmail): Set coding-system of the old Rmail file to `raw-text-unix'.
Eli Zaretskii <eliz@gnu.org>
parents:
101685
diff
changeset
|
243 'nomsg))))) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
244 (kill-buffer temp-buffer)) |
4266
5a7266ff9af1
(unrmail): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
245 (message "Writing messages to %s...done" to-file))) |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
246 |
18383 | 247 (provide 'unrmail) |
248 | |
101536
a8fcffcd20d5
(command-line-args-left): Remove unneeded declaration.
Glenn Morris <rgm@gnu.org>
parents:
100908
diff
changeset
|
249 ;; arch-tag: 14c6290d-60b2-456f-8909-5c2387de6acb |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
250 ;;; unrmail.el ends here |