Mercurial > emacs
annotate lisp/mail/unrmail.el @ 75952:bf9581a17f60
*** empty log message ***
author | Andreas Schwab <schwab@suse.de> |
---|---|
date | Fri, 16 Feb 2007 13:21:59 +0000 |
parents | e3694f1cb928 |
children | 8e27d63c45eb 95d0cdf160ea |
rev | line source |
---|---|
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
1 ;;; unrmail.el --- convert Rmail files to mailbox files |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
2 |
74509 | 3 ;; Copyright (C) 1992, 2001, 2002, 2003, 2004, 2005, |
75347 | 4 ;; 2006, 2007 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 | |
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 2, or (at your option) | |
14 ;; any later version. | |
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 | |
14169 | 22 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
64085 | 23 ;; Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, |
24 ;; Boston, MA 02110-1301, USA. | |
982 | 25 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
26 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
27 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
28 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
29 |
982 | 30 (defvar command-line-args-left) ;Avoid 'free variable' warning |
31 | |
32 ;;;###autoload | |
33 (defun batch-unrmail () | |
6618 | 34 "Convert Rmail files to system inbox format. |
982 | 35 Specify the input Rmail file names as command line arguments. |
36 For each Rmail file, the corresponding output file name | |
37 is made by adding `.mail' at the end. | |
38 For example, invoke `emacs -batch -f batch-unrmail RMAIL'." | |
39 ;; command-line-args-left is what is left of the command line (from startup.el) | |
40 (if (not noninteractive) | |
41 (error "`batch-unrmail' is to be used only with -batch")) | |
42 (let ((error nil)) | |
43 (while command-line-args-left | |
44 (or (unrmail (car command-line-args-left) | |
45 (concat (car command-line-args-left) ".mail")) | |
46 (setq error t)) | |
47 (setq command-line-args-left (cdr command-line-args-left))) | |
48 (message "Done") | |
49 (kill-emacs (if error 1 0)))) | |
50 | |
51 ;;;###autoload | |
52 (defun unrmail (file to-file) | |
6618 | 53 "Convert Rmail file FILE to system inbox format file TO-FILE." |
4266
5a7266ff9af1
(unrmail): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
54 (interactive "fUnrmail (rmail file): \nFUnrmail into (new mailbox file): ") |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
55 (with-temp-buffer |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
56 ;; 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
|
57 (let ((coding-system-for-read 'raw-text)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
58 (insert-file-contents file)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
59 ;; But make it multibyte. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
60 (set-buffer-multibyte t) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
61 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
62 (if (not (looking-at "BABYL OPTIONS")) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
63 (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
|
64 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
65 ;; 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
|
66 (let ((modifiedp (buffer-modified-p)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
67 (coding-system rmail-file-coding-system) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
68 from to) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
69 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
70 (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
|
71 (setq from (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
72 (goto-char (point-max)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
73 (search-backward "\n\^_" from 'mv) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
74 (setq to (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
75 (unless (and coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
76 (coding-system-p coding-system)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
77 (setq coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
78 ;; 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
|
79 ;; 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
|
80 ;; 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
|
81 ;; 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
|
82 ;; 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
|
83 ;; detect-coding-with-priority below achieves that. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
84 (car (detect-coding-with-priority |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
85 from to |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
86 '((coding-category-emacs-mule . emacs-mule)))))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
87 (unless (memq coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
88 '(undecided undecided-unix)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
89 (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
|
90 (let ((buffer-undo-list t)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
91 (decode-coding-region from to coding-system)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
92 (setq coding-system last-coding-system-used)) |
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 (setq buffer-file-coding-system nil) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
95 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
96 ;; 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
|
97 (setq save-buffer-coding-system |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
98 (or coding-system 'undecided))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
99 |
14296
e3e1d7c2e7e5
(unrmail): Default the directory of TO-FILE based on FILE.
Karl Heuer <kwzh@gnu.org>
parents:
14169
diff
changeset
|
100 ;; 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
|
101 (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
|
102 (condition-case () |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
103 (delete-file to-file) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
104 (file-error nil)) |
4266
5a7266ff9af1
(unrmail): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
105 (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
|
106 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
107 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
108 (let ((temp-buffer (get-buffer-create " unrmail")) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
109 (from-buffer (current-buffer))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
110 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
111 ;; Process the messages one by one. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
112 (while (search-forward "\^_\^l" nil t) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
113 (let ((beg (point)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
114 (end (save-excursion |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
115 (if (search-forward "\^_" nil t) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
116 (1- (point)) (point-max)))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
117 (coding 'raw-text) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
118 label-line attrs keywords |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
119 mail-from reformatted) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
120 (with-current-buffer temp-buffer |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
121 (setq buffer-undo-list t) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
122 (erase-buffer) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
123 (setq buffer-file-coding-system coding) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
124 (insert-buffer-substring from-buffer beg end) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
125 (goto-char (point-min)) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
126 (forward-line 1) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
127 ;; Record whether the header is reformatted. |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
128 (setq reformatted (= (following-char) ?1)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
129 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
130 ;; 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
|
131 ;; and the keywords from it. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
132 (setq label-line |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
133 (buffer-substring (point) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
134 (save-excursion (forward-line 1) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
135 (point)))) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
136 (search-forward ",,") |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
137 (unless (eolp) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
138 (setq keywords |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
139 (buffer-substring (point) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
140 (progn (end-of-line) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
141 (1- (point))))) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
142 (setq keywords |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
143 (replace-regexp-in-string ", " "," keywords))) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
144 |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
145 (setq attrs |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
146 (list |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
147 (if (string-match ", answered," label-line) ?A ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
148 (if (string-match ", deleted," label-line) ?D ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
149 (if (string-match ", edited," label-line) ?E ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
150 (if (string-match ", filed," label-line) ?F ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
151 (if (string-match ", resent," label-line) ?R ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
152 (if (string-match ", unseen," label-line) ?\ ?-) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
153 (if (string-match ", stored," label-line) ?S ?-))) |
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 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
177 ;; Some operations on the message header itself. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
178 (goto-char (point-min)) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
179 (save-restriction |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
180 (narrow-to-region |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
181 (point-min) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
182 (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
|
183 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
184 ;; 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
|
185 (setq mail-from |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
186 (or (mail-fetch-field "Mail-From") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
187 (concat "From " |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
188 (mail-strip-quoted-names (or (mail-fetch-field "from") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
189 (mail-fetch-field "really-from") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
190 (mail-fetch-field "sender") |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
191 "unknown")) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
192 " " (current-time-string)))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
193 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
194 ;; 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
|
195 (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
|
196 (if maybe-coding |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
197 (setq coding (intern maybe-coding)))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
198 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
199 ;; 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
|
200 (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
|
201 (beginning-of-line) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
202 (delete-region (point) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
203 (progn (forward-line 1) (point))))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
204 |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
205 (goto-char (point-min)) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
206 ;; Insert the `From ' line. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
207 (insert mail-from "\n") |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
208 ;; Record the keywords and attributes in our special way. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
209 (insert "X-BABYL-V6-ATTRIBUTES: " (apply 'string attrs) "\n") |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
210 (when keywords |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
211 (insert "X-BABYL-V6-KEYWORDS: " keywords "\n")) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
212 (goto-char (point-min)) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
213 ;; ``Quote'' "\nFrom " as "\n>From " |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
214 ;; (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
|
215 ;; 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
|
216 (let ((case-fold-search nil)) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
217 (while (search-forward "\nFrom " nil t) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
218 (forward-char -5) |
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
219 (insert ?>))) |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
220 ;; Write it to the output file. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
221 (write-region (point-min) (point-max) to-file t |
55497
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
222 'nomsg)))) |
85aa052b7bf2
(unrmail): Mostly rewritten. Parses the file
Richard M. Stallman <rms@gnu.org>
parents:
52401
diff
changeset
|
223 (kill-buffer temp-buffer)) |
4266
5a7266ff9af1
(unrmail): Total rewrite.
Richard M. Stallman <rms@gnu.org>
parents:
2247
diff
changeset
|
224 (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
|
225 |
18383 | 226 (provide 'unrmail) |
227 | |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
228 ;;; unrmail.el ends here |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
229 |
52401 | 230 ;;; arch-tag: 14c6290d-60b2-456f-8909-5c2387de6acb |