aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKenichi Handa1997-02-26 12:57:47 +0000
committerKenichi Handa1997-02-26 12:57:47 +0000
commitd1e69dec618a031dccb5a2b8514b50ad66fcbbfb (patch)
tree76d689b92e6865720c1a6ac3689d037fad17a2b1
parent2a23c7c2d179a7a9786f9806fcbba6a0c42f8794 (diff)
downloademacs-d1e69dec618a031dccb5a2b8514b50ad66fcbbfb.tar.gz
emacs-d1e69dec618a031dccb5a2b8514b50ad66fcbbfb.zip
(rmail-view-buffer, rmail-enable-mime, rmail-show-mime-function,
rmail-mime-feature): New variables to control MIME feature. (rmail-file-coding-system): Initial value is nil. (rmail, rmail-convert-file, rmail-insert-inbox-text): Check rmail-enable-mime. Read a file without any code conversion. (rmail-variables): Setup local variables rmail-buffer and rmail-view-buffer. (rmail-decode-babyl-format, rmail-convert-babyl-format): Perform code conversion of RMAIL file if rmail-enable-mime is nil. (rmail-show-message): Make sure to be in rmail-buffer. If rmail-enable-mime is t, call appropriate function to decode MIME format. (rmail-mail, rmail-reply): Call rmail-start-mail with argument rmail-view-buffer.
-rw-r--r--lisp/mail/rmail.el121
1 files changed, 89 insertions, 32 deletions
diff --git a/lisp/mail/rmail.el b/lisp/mail/rmail.el
index 3e2d5eae86b..70308097d9c 100644
--- a/lisp/mail/rmail.el
+++ b/lisp/mail/rmail.el
@@ -295,6 +295,35 @@ before obeying `rmail-ignored-headers'.")
295 (let ((rmail-total-messages total)) 295 (let ((rmail-total-messages total))
296 (,@ body)))) 296 (,@ body))))
297 (rmail-maybe-display-summary)))) 297 (rmail-maybe-display-summary))))
298
299(defvar rmail-view-buffer nil
300 "Buffer which holds RMAIL message for displaying.")
301
302;; Mule and MIME related variables.
303
304;;;###autoload
305(defvar rmail-file-coding-system nil
306 "Coding system used in RMAIL file.
307
308This is set to nil by default.")
309
310;;;###autoload
311(defvar rmail-enable-mime nil
312 "*If non-nil, RMAIL uses MIME feature.
313If the value is t, RMAIL automatically shows MIME decoded message.
314If the value is neither t nor nil, RMAIL does not show MIME decoded message
315until a user explicitly require it.")
316
317;;;###autoload
318(defvar rmail-show-mime-function nil
319 "Function to show MIME decoded message of RMAIL file.")
320
321;;;###autoload
322(defvar rmail-mime-feature 'rmail-mime
323 "Feature to provide for using MIME feature in RMAIL.
324When starting rmail, this feature is requrired if rmail-enable-mime
325is non-nil.")
326
298 327
299;;;; *** Rmail Mode *** 328;;;; *** Rmail Mode ***
300 329
@@ -313,8 +342,15 @@ have a chance to specify a file name with the minibuffer.
313If `rmail-display-summary' is non-nil, make a summary for this RMAIL file." 342If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
314 (interactive (if current-prefix-arg 343 (interactive (if current-prefix-arg
315 (list (read-file-name "Run rmail on RMAIL file: ")))) 344 (list (read-file-name "Run rmail on RMAIL file: "))))
345 (if rmail-enable-mime
346 (condition-case err
347 (require rmail-mime-feature)
348 (error (message "Feature `%s' not provided" rmail-mime-feature)
349 (sit-for 1)
350 (setq rmail-enable-mime nil))))
316 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name))) 351 (let* ((file-name (expand-file-name (or file-name-arg rmail-file-name)))
317 (existed (get-file-buffer file-name)) 352 (existed (get-file-buffer file-name))
353 (coding-system-for-read 'no-conversion)
318 run-mail-hook) 354 run-mail-hook)
319 ;; Like find-file, but in the case where a buffer existed 355 ;; Like find-file, but in the case where a buffer existed
320 ;; and the file was reverted, recompute the message-data. 356 ;; and the file was reverted, recompute the message-data.
@@ -391,6 +427,13 @@ If `rmail-display-summary' is non-nil, make a summary for this RMAIL file."
391 ;; Non-empty file in non-RMAIL format. Add header and convert. 427 ;; Non-empty file in non-RMAIL format. Add header and convert.
392 (setq convert t) 428 (setq convert t)
393 (rmail-insert-rmail-file-header))) 429 (rmail-insert-rmail-file-header)))
430 (if (and (not convert)
431 (not rmail-enable-mime)
432 rmail-file-coding-system)
433 ;; Decode BABYL part at the headq only. The remaining non
434 ;; BABYL parts are decode in rmail-convert-to-babyl-format if
435 ;; necessary..
436 (rmail-decode-babyl-format))
394 ;; If file was not a Babyl file or if there are 437 ;; If file was not a Babyl file or if there are
395 ;; Unix format messages added at the end, 438 ;; Unix format messages added at the end,
396 ;; convert file as necessary. 439 ;; convert file as necessary.
@@ -423,6 +466,24 @@ Note: This is the header of an rmail file.
423Note: If you are seeing it in rmail, 466Note: If you are seeing it in rmail,
424Note: it means the file has no messages in it.\n\^_"))) 467Note: it means the file has no messages in it.\n\^_")))
425 468
469;; Decode Babyl formated part at the head of current buffer by
470;; rmail-file-coding-system.
471
472(defun rmail-decode-babyl-format ()
473 (let ((modifiedp (buffer-modified-p))
474 (buffer-read-only nil)
475 pos)
476 (goto-char (point-min))
477 (search-forward "\n\^_" nil t) ; Skip BYBYL header.
478 (setq pos (point))
479 (message "Decoding messages...")
480 (while (search-forward "\n\^_" nil t)
481 (decode-coding-region pos (point) rmail-file-coding-system)
482 (setq pos (point)))
483 (message "Decoding messages...done")
484 (set-buffer-file-coding-system rmail-file-coding-system)
485 (set-buffer-modified-p modifiedp)))
486
426(if rmail-mode-map 487(if rmail-mode-map
427 nil 488 nil
428 (setq rmail-mode-map (make-keymap)) 489 (setq rmail-mode-map (make-keymap))
@@ -691,6 +752,10 @@ Instead, these commands are available:
691 (make-local-variable 'rmail-last-label) 752 (make-local-variable 'rmail-last-label)
692 (make-local-variable 'rmail-last-regexp) 753 (make-local-variable 'rmail-last-regexp)
693 (make-local-variable 'rmail-deleted-vector) 754 (make-local-variable 'rmail-deleted-vector)
755 (make-local-variable 'rmail-buffer)
756 (setq rmail-buffer (current-buffer))
757 (make-local-variable 'rmail-view-buffer)
758 (setq rmail-view-buffer rmail-buffer)
694 (make-local-variable 'rmail-summary-buffer) 759 (make-local-variable 'rmail-summary-buffer)
695 (make-local-variable 'rmail-summary-vector) 760 (make-local-variable 'rmail-summary-vector)
696 (make-local-variable 'rmail-current-message) 761 (make-local-variable 'rmail-current-message)
@@ -1014,9 +1079,6 @@ It returns t if it got any new messages."
1014 ;; Don't leave the buffer screwed up if we get a disk-full error. 1079 ;; Don't leave the buffer screwed up if we get a disk-full error.
1015 (rmail-show-message)))) 1080 (rmail-show-message))))
1016 1081
1017(defvar rmail-file-coding-system 'coding-system-iso2022-7
1018 "Coding system used in RMAIL file.")
1019
1020(defun rmail-insert-inbox-text (files renamep) 1082(defun rmail-insert-inbox-text (files renamep)
1021 ;; Detect a locked file now, so that we avoid moving mail 1083 ;; Detect a locked file now, so that we avoid moving mail
1022 ;; out of the real inbox file. (That could scare people.) 1084 ;; out of the real inbox file. (That could scare people.)
@@ -1144,29 +1206,10 @@ It returns t if it got any new messages."
1144 ;; Either the alternate name (if we renamed) 1206 ;; Either the alternate name (if we renamed)
1145 ;; or the actual inbox (if not renaming). 1207 ;; or the actual inbox (if not renaming).
1146 (if (file-exists-p tofile) 1208 (if (file-exists-p tofile)
1147 (let (size) 1209 (let ((coding-system-for-read 'no-conversion)
1210 size)
1148 (goto-char (point-max)) 1211 (goto-char (point-max))
1149 ;; At first, read the file as is (i.e. no decoding). 1212 (setq size (nth 1 (insert-file-contents tofile)))
1150 (setq size (nth 1 (let ((coding-system-for-read 'no-conversion))
1151 (insert-file-contents tofile))))
1152 ;; Then, decode the contents one by one.
1153 (let ((pos (point)))
1154 (cond ((looking-at "^From ") ; new mails.
1155 (forward-line 1)
1156 (while (not (eobp))
1157 (setq pos (point))
1158 (search-forward "\nFrom " nil 'move)
1159 (decode-coding-region pos (point)
1160 'automatic-conversion)))
1161 ((looking-at "BABYL OPTIONS:\\|\^L") ; Babyl format
1162 (while (not (eobp))
1163 (setq pos (point))
1164 (search-forward "\n^_" nil 'move)
1165 (decode-coding-region pos (point)
1166 rmail-file-coding-system)))
1167 (t ; Perhaps MMDF format. Convert all data at once.
1168 (decode-coding-region (point) (point-max)
1169 'automatic-conversion))))
1170 (goto-char (point-max)) 1213 (goto-char (point-max))
1171 (or (= (preceding-char) ?\n) 1214 (or (= (preceding-char) ?\n)
1172 (zerop size) 1215 (zerop size)
@@ -1216,6 +1259,7 @@ Optional DEFAULT is password to start with."
1216 (goto-char (point-min)) 1259 (goto-char (point-min))
1217 (save-restriction 1260 (save-restriction
1218 (while (not (eobp)) 1261 (while (not (eobp))
1262 (setq start (point))
1219 (cond ((looking-at "BABYL OPTIONS:");Babyl header 1263 (cond ((looking-at "BABYL OPTIONS:");Babyl header
1220 (if (search-forward "\n\^_" nil t) 1264 (if (search-forward "\n\^_" nil t)
1221 ;; If we find the proper terminator, delete through there. 1265 ;; If we find the proper terminator, delete through there.
@@ -1235,13 +1279,16 @@ Optional DEFAULT is password to start with."
1235 (save-excursion 1279 (save-excursion
1236 (skip-chars-forward " \t\n") 1280 (skip-chars-forward " \t\n")
1237 (point))) 1281 (point)))
1282 (or rmail-enable-mime
1283 (not rmail-file-coding-system)
1284 (decode-coding-region start (point)
1285 rmail-file-coding-system))
1238 (narrow-to-region (point) (point-max))) 1286 (narrow-to-region (point) (point-max)))
1239 ;;*** MMDF format 1287 ;;*** MMDF format
1240 ((let ((case-fold-search t)) 1288 ((let ((case-fold-search t))
1241 (looking-at mmdf-delim1)) 1289 (looking-at mmdf-delim1))
1242 (let ((case-fold-search t)) 1290 (let ((case-fold-search t))
1243 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n") 1291 (replace-match "\^L\n0, unseen,,\n*** EOOH ***\n")
1244 (setq start (point))
1245 (re-search-forward mmdf-delim2 nil t) 1292 (re-search-forward mmdf-delim2 nil t)
1246 (replace-match "\^_")) 1293 (replace-match "\^_"))
1247 (save-excursion 1294 (save-excursion
@@ -1250,11 +1297,13 @@ Optional DEFAULT is password to start with."
1250 (goto-char (point-min)) 1297 (goto-char (point-min))
1251 (while (search-forward "\n\^_" nil t); single char "\^_" 1298 (while (search-forward "\n\^_" nil t); single char "\^_"
1252 (replace-match "\n^_")))); 2 chars: "^" and "_" 1299 (replace-match "\n^_")))); 2 chars: "^" and "_"
1300 (or rmail-enable-mime
1301 (not rmail-file-coding-system)
1302 (decode-coding-region start (point) 'automatic-conversion))
1253 (narrow-to-region (point) (point-max)) 1303 (narrow-to-region (point) (point-max))
1254 (setq count (1+ count))) 1304 (setq count (1+ count)))
1255 ;;*** Mail format 1305 ;;*** Mail format
1256 ((looking-at "^From ") 1306 ((looking-at "^From ")
1257 (setq start (point))
1258 (insert "\^L\n0, unseen,,\n*** EOOH ***\n") 1307 (insert "\^L\n0, unseen,,\n*** EOOH ***\n")
1259 (rmail-nuke-pinhead-header) 1308 (rmail-nuke-pinhead-header)
1260 ;; If this message has a Content-Length field, 1309 ;; If this message has a Content-Length field,
@@ -1311,6 +1360,9 @@ Optional DEFAULT is password to start with."
1311 (while (search-forward "\n\^_" nil t); single char 1360 (while (search-forward "\n\^_" nil t); single char
1312 (replace-match "\n^_")))); 2 chars: "^" and "_" 1361 (replace-match "\n^_")))); 2 chars: "^" and "_"
1313 (insert ?\^_) 1362 (insert ?\^_)
1363 (or rmail-enable-mime
1364 (not rmail-file-coding-system)
1365 (decode-coding-region start (point) 'automatic-conversion))
1314 (narrow-to-region (point) (point-max))) 1366 (narrow-to-region (point) (point-max)))
1315 ;; 1367 ;;
1316 ;; This kludge is because some versions of sendmail.el 1368 ;; This kludge is because some versions of sendmail.el
@@ -1710,6 +1762,8 @@ change the invisible header text."
1710 "Show message number N (prefix argument), counting from start of file. 1762 "Show message number N (prefix argument), counting from start of file.
1711If summary buffer is currently displayed, update current message there also." 1763If summary buffer is currently displayed, update current message there also."
1712 (interactive "p") 1764 (interactive "p")
1765 (or (eq major-mode 'rmail-mode)
1766 (switch-to-buffer rmail-buffer))
1713 (rmail-maybe-set-message-counters) 1767 (rmail-maybe-set-message-counters)
1714 (widen) 1768 (widen)
1715 (if (zerop rmail-total-messages) 1769 (if (zerop rmail-total-messages)
@@ -1742,6 +1796,10 @@ If summary buffer is currently displayed, update current message there also."
1742 (narrow-to-region (point) end))) 1796 (narrow-to-region (point) end)))
1743 (goto-char (point-min)) 1797 (goto-char (point-min))
1744 (rmail-display-labels) 1798 (rmail-display-labels)
1799 (if (eq rmail-enable-mime t)
1800 (funcall rmail-show-mime-function)
1801 (setq rmail-view-buffer rmail-buffer)
1802 )
1745 (rmail-highlight-headers) 1803 (rmail-highlight-headers)
1746 (if transient-mark-mode (deactivate-mark)) 1804 (if transient-mark-mode (deactivate-mark))
1747 (run-hooks 'rmail-show-message-hook) 1805 (run-hooks 'rmail-show-message-hook)
@@ -2243,7 +2301,7 @@ Deleted messages stay in the file until the \\[rmail-expunge] command is given."
2243While composing the message, use \\[mail-yank-original] to yank the 2301While composing the message, use \\[mail-yank-original] to yank the
2244original message into it." 2302original message into it."
2245 (interactive) 2303 (interactive)
2246 (rmail-start-mail nil nil nil nil nil (current-buffer))) 2304 (rmail-start-mail nil nil nil nil nil rmail-view-buffer))
2247 2305
2248(defun rmail-continue () 2306(defun rmail-continue ()
2249 "Continue composing outgoing message previously being composed." 2307 "Continue composing outgoing message previously being composed."
@@ -2261,8 +2319,7 @@ use \\[mail-yank-original] to yank the original message into it."
2261 (interactive "P") 2319 (interactive "P")
2262 (let (from reply-to cc subject date to message-id references 2320 (let (from reply-to cc subject date to message-id references
2263 resent-to resent-cc resent-reply-to 2321 resent-to resent-cc resent-reply-to
2264 (msgnum rmail-current-message) 2322 (msgnum rmail-current-message))
2265 (rmail-buffer (current-buffer)))
2266 (save-excursion 2323 (save-excursion
2267 (save-restriction 2324 (save-restriction
2268 (widen) 2325 (widen)
@@ -2323,7 +2380,7 @@ use \\[mail-yank-original] to yank the original message into it."
2323 (mail-strip-quoted-names 2380 (mail-strip-quoted-names
2324 (if (null cc) to (concat to ", " cc)))))) 2381 (if (null cc) to (concat to ", " cc))))))
2325 (if (string= cc-list "") nil cc-list))) 2382 (if (string= cc-list "") nil cc-list)))
2326 (current-buffer) 2383 rmail-view-buffer
2327 (list (list '(lambda () 2384 (list (list '(lambda ()
2328 (let ((msgnum rmail-send-actions-rmail-msg-number)) 2385 (let ((msgnum rmail-send-actions-rmail-msg-number))
2329 (save-excursion 2386 (save-excursion
@@ -2338,7 +2395,7 @@ use \\[mail-yank-original] to yank the original message into it."
2338 ;; so that rmail-only-expunge can relocate the message number. 2395 ;; so that rmail-only-expunge can relocate the message number.
2339 (make-local-variable 'rmail-send-actions-rmail-buffer) 2396 (make-local-variable 'rmail-send-actions-rmail-buffer)
2340 (make-local-variable 'rmail-send-actions-rmail-msg-number) 2397 (make-local-variable 'rmail-send-actions-rmail-msg-number)
2341 (setq rmail-send-actions-rmail-buffer rmail-buffer) 2398 (setq rmail-send-actions-rmail-buffer rmail-view-buffer)
2342 (setq rmail-send-actions-rmail-msg-number msgnum))) 2399 (setq rmail-send-actions-rmail-msg-number msgnum)))
2343 2400
2344(defun rmail-make-in-reply-to-field (from date message-id) 2401(defun rmail-make-in-reply-to-field (from date message-id)