Mercurial > emacs
annotate lisp/mail/unrmail.el @ 88151:ef41980f1588
Mostly rewritten. Parses the file directly and converts.
(batch-convert-babyl, convert-babyl-file, decode-babyl-file)
(decode-babyl): New functions.
(unrmail, batch-unrmail): Now aliases.
author | Richard M. Stallman <rms@gnu.org> |
---|---|
date | Sun, 03 Oct 2004 01:20:20 +0000 |
parents | 0ccb1fcb32c7 |
children | d7ddb3e565de |
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 |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
3 ;;; Copyright (C) 1992, 2002, 2004 Free Software Foundation, Inc. |
982 | 4 |
38695 | 5 ;; Maintainer: FSF |
2247
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
6 ;; Keywords: mail |
2c7997f249eb
Add or correct keywords
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
2233
diff
changeset
|
7 |
982 | 8 ;; This file is part of GNU Emacs. |
9 | |
10 ;; GNU Emacs is free software; you can redistribute it and/or modify | |
11 ;; it under the terms of the GNU General Public License as published by | |
12 ;; the Free Software Foundation; either version 2, or (at your option) | |
13 ;; any later version. | |
14 | |
15 ;; GNU Emacs is distributed in the hope that it will be useful, | |
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of | |
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
18 ;; GNU General Public License for more details. | |
19 | |
20 ;; You should have received a copy of the GNU General Public License | |
14169 | 21 ;; along with GNU Emacs; see the file COPYING. If not, write to the |
22 ;; Free Software Foundation, Inc., 59 Temple Place - Suite 330, | |
23 ;; Boston, MA 02111-1307, USA. | |
982 | 24 |
38414
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
25 ;;; Commentary: |
67b464da13ec
Some fixes to follow coding conventions.
Pavel Janík <Pavel@Janik.cz>
parents:
18383
diff
changeset
|
26 |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
27 ;;; Code: |
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
28 |
982 | 29 (defvar command-line-args-left) ;Avoid 'free variable' warning |
30 | |
31 ;;;###autoload | |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
32 (defun batch-convert-babyl () |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
33 "Convert Babyl files (old Rmail file) to system inbox format. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
34 Specify the input Babyl file names as command line arguments. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
35 For each Babyl file, the corresponding output file name |
982 | 36 is made by adding `.mail' at the end. |
37 For example, invoke `emacs -batch -f batch-unrmail RMAIL'." | |
38 ;; command-line-args-left is what is left of the command line (from startup.el) | |
39 (if (not noninteractive) | |
40 (error "`batch-unrmail' is to be used only with -batch")) | |
41 (let ((error nil)) | |
42 (while command-line-args-left | |
43 (or (unrmail (car command-line-args-left) | |
44 (concat (car command-line-args-left) ".mail")) | |
45 (setq error t)) | |
46 (setq command-line-args-left (cdr command-line-args-left))) | |
47 (message "Done") | |
48 (kill-emacs (if error 1 0)))) | |
49 | |
50 ;;;###autoload | |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
51 (defalias 'batch-unrmail 'batch-convert-babyl) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
52 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
53 ;;;###autoload |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
54 (defun convert-babyl-file (file to-file) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
55 "Convert Babyl (old 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
|
56 (interactive "fUnrmail (rmail file): \nFUnrmail into (new mailbox file): ") |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
57 (with-temp-buffer |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
58 (decode-babyl-file file) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
59 ;; Write it to the output file. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
60 ;; Since the file may contain messages of different encodings |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
61 ;; at the tail (non-BYBYL part), we can't decode them at once |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
62 ;; on reading. So, at first, we read the file without text |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
63 ;; code conversion, then decode the messages one by one by |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
64 ;; rmail-decode-babyl-format or |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
65 ;; rmail-convert-to-babyl-format. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
66 (let ((coding-system-for-write 'raw-text)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
67 (write-region (point-min) (point-max) to-file nil |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
68 'nomsg)))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
69 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
70 ;;;###autoload |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
71 (defalias 'unrmail 'convert-babyl-file) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
72 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
73 ;;;###autoload |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
74 (defun decode-babyl-file (file) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
75 "Convert Babyl file FILE to system inbox format in current buffer." |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
76 (interactive "fUnrmail (rmail file): ") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
77 ;; Read in the Babyl file with no decoding. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
78 (let ((thisbuf (current-buffer))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
79 (with-temp-buffer |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
80 (let ((coding-system-for-read 'raw-text)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
81 (insert-file-contents file)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
82 ;; But make it multibyte. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
83 (set-buffer-multibyte t) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
84 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
85 (if (not (looking-at "BABYL OPTIONS")) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
86 (error "File %s not in Babyl format")) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
87 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
88 (decode-babyl thisbuf)))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
89 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
90 ;;;###autoload |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
91 (defun decode-babyl (outbuf) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
92 "Convert Babyl data in current bufer to inbox format and store in OUTBUF." |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
93 ;; Decode the file contents just as Rmail did. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
94 (let ((modifiedp (buffer-modified-p)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
95 (coding-system rmail-file-coding-system) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
96 from to) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
97 (goto-char (point-min)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
98 (search-forward "\n\^_" nil t) ; Skip BABYL header. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
99 (setq from (point)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
100 (goto-char (point-max)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
101 (search-backward "\n\^_" from 'mv) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
102 (setq to (point)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
103 (unless (and coding-system |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
104 (coding-system-p coding-system)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
105 (setq coding-system |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
106 ;; Emacs 21.1 and later writes RMAIL files in emacs-mule, but |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
107 ;; earlier versions did that with the current buffer's encoding. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
108 ;; So we want to favor detection of emacs-mule (whose normal |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
109 ;; priority is quite low), but still allow detection of other |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
110 ;; encodings if emacs-mule won't fit. The call to |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
111 ;; detect-coding-with-priority below achieves that. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
112 (car (detect-coding-with-priority |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
113 from to |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
114 '((coding-category-emacs-mule . emacs-mule)))))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
115 (unless (memq coding-system |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
116 '(undecided undecided-unix)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
117 (set-buffer-modified-p t) ; avoid locking when decoding |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
118 (let ((buffer-undo-list t)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
119 (decode-coding-region from to coding-system)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
120 (setq coding-system last-coding-system-used)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
121 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
122 (setq buffer-file-coding-system nil) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
123 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
124 ;; We currently don't use this value, but maybe we should. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
125 (setq save-buffer-coding-system |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
126 (or coding-system 'undecided))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
127 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
128 (goto-char (point-min)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
129 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
130 (let ((temp-buffer (get-buffer-create " unrmail")) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
131 (from-buffer (current-buffer))) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
132 |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
133 ;; Process the messages one by one. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
134 (while (search-forward "\^_\^l" nil t) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
135 (let ((beg (point)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
136 (end (save-excursion |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
137 (if (search-forward "\^_" nil t) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
138 (1- (point)) (point-max)))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
139 (coding 'raw-text) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
140 label-line attrs keywords |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
141 mail-from reformatted) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
142 (with-current-buffer temp-buffer |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
143 (setq buffer-undo-list t) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
144 (erase-buffer) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
145 (setq buffer-file-coding-system coding) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
146 (insert-buffer-substring from-buffer beg end) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
147 (goto-char (point-min)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
148 (forward-line 1) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
149 ;; Record whether the header is reformatted. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
150 (setq reformatted (= (following-char) ?1)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
151 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
152 ;; Collect the label line, then get the attributes |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
153 ;; and the keywords from it. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
154 (setq label-line |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
155 (buffer-substring (point) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
156 (save-excursion (forward-line 1) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
157 (point)))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
158 (search-forward ",,") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
159 (unless (eolp) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
160 (setq keywords |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
161 (buffer-substring (point) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
162 (progn (end-of-line) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
163 (1- (point))))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
164 (setq keywords |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
165 (replace-regexp-in-string ", " "," keywords))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
166 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
167 (setq attrs |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
168 (list |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
169 (if (string-match ", answered," label-line) ?A ?-) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
170 (if (string-match ", deleted," label-line) ?D ?-) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
171 (if (string-match ", edited," label-line) ?E ?-) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
172 (if (string-match ", filed," label-line) ?F ?-) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
173 (if (string-match ", resent," label-line) ?R ?-) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
174 (if (string-match ", unseen," label-line) ?\ ?-) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
175 (if (string-match ", stored," label-line) ?S ?-))) |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
176 |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
177 ;; Delete the special Babyl lines at the start, |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
178 ;; and the ***EOOH*** line, and the reformatted header if any. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
179 (goto-char (point-min)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
180 (if reformatted |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
181 (progn |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
182 (forward-line 2) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
183 ;; Delete Summary-Line headers. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
184 (let ((case-fold-search t)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
185 (while (looking-at "Summary-Line:") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
186 (forward-line 1))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
187 (delete-region (point-min) (point)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
188 ;; Delete the old reformatted header. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
189 (re-search-forward "^[*][*][*] EOOH [*][*][*]\n") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
190 (forward-line -1) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
191 (let ((start (point))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
192 (search-forward "\n\n") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
193 (delete-region start (point)))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
194 ;; Not reformatted. Delete the special |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
195 ;; lines before the real header. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
196 (re-search-forward "^[*][*][*] EOOH [*][*][*]\n") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
197 (delete-region (point-min) (point))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
198 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
199 ;; Some operations on the message header itself. |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
200 (goto-char (point-min)) |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
201 (save-restriction |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
202 (narrow-to-region |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
203 (point-min) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
204 (save-excursion (search-forward "\n\n" nil 'move) (point))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
205 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
206 ;; Fetch or construct what we should use in the `From ' line. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
207 (setq mail-from |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
208 (or (mail-fetch-field "Mail-From") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
209 (concat "From " |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
210 (mail-strip-quoted-names (or (mail-fetch-field "from") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
211 (mail-fetch-field "really-from") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
212 (mail-fetch-field "sender") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
213 "unknown")) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
214 " " (current-time-string)))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
215 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
216 ;; If the message specifies a coding system, use it. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
217 (let ((maybe-coding (mail-fetch-field "X-Coding-System"))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
218 (if maybe-coding |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
219 (setq coding (intern maybe-coding)))) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
220 |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
221 ;; Delete the Mail-From: header field if any. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
222 (when (re-search-forward "^Mail-from:" nil t) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
223 (beginning-of-line) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
224 (delete-region (point) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
225 (progn (forward-line 1) (point))))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
226 |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
227 (goto-char (point-min)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
228 ;; Insert the `From ' line. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
229 (insert mail-from "\n") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
230 ;; Record the keywords and attributes in our special way. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
231 (insert "X-BABYL-V6-ATTRIBUTES: " (apply 'string attrs) "\n") |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
232 (when keywords |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
233 (insert "X-BABYL-V6-KEYWORDS: " keywords "\n")) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
234 (goto-char (point-min)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
235 ;; ``Quote'' "\nFrom " as "\n>From " |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
236 ;; (note that this isn't really quoting, as there is no requirement |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
237 ;; that "\n[>]+From " be quoted in the same transparent way.) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
238 (let ((case-fold-search nil)) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
239 (while (search-forward "\nFrom " nil t) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
240 (forward-char -5) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
241 (insert ?>))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
242 ;; Write it to the original buffer. |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
243 (append-to-buffer thisbuf (point-min) (point-max))))) |
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
244 (kill-buffer temp-buffer))) |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
245 |
18383 | 246 (provide 'unrmail) |
247 | |
2233
fb0ed5a1d0f3
Add standard library headers.
Eric S. Raymond <esr@snark.thyrsus.com>
parents:
982
diff
changeset
|
248 ;;; unrmail.el ends here |
47631
433ae412d00f
(unrmail): Do the work directly,
Richard M. Stallman <rms@gnu.org>
parents:
38695
diff
changeset
|
249 |
88151
ef41980f1588
Mostly rewritten. Parses the file directly and converts.
Richard M. Stallman <rms@gnu.org>
parents:
88131
diff
changeset
|
250 ;;; arch-tag: 14c6290d-60b2-456f-8909-5c2387de6acb |