X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=mime-edit.el;h=96b24f4bc2c1742da32e7e11efd9d36568761a32;hb=f67c5a3b76348ae0c56bd3e7f8a7eb4b03093cb3;hp=42232fbd6fbd5c729a1976a7fc39dc0f38318b3c;hpb=bcdd094f3c0ad3c1c89d599d7794288515dccf8e;p=elisp%2Fsemi.git diff --git a/mime-edit.el b/mime-edit.el index 42232fb..96b24f4 100644 --- a/mime-edit.el +++ b/mime-edit.el @@ -1,16 +1,15 @@ ;;; mime-edit.el --- Simple MIME Composer for GNU Emacs -;; Copyright (C) 1993,1994,1995,1996,1997 Free Software Foundation, Inc. +;; Copyright (C) 1993,1994,1995,1996,1997,1998 Free Software Foundation, Inc. ;; Author: UMEDA Masanobu ;; MORIOKA Tomohiko ;; Maintainer: MORIOKA Tomohiko ;; Created: 1994/08/21 renamed from mime.el ;; Renamed: 1997/2/21 from tm-edit.el -;; Version: $Revision: 0.79 $ ;; Keywords: MIME, multimedia, multilingual, mail, news -;; This file is part of SEMI (SEMI is Emacs MIME Interfaces). +;; This file is part of SEMI (Sophisticated Emacs MIME Interfaces). ;; This program is free software; you can redistribute it and/or ;; modify it under the terms of the GNU General Public License as @@ -92,7 +91,7 @@ ;; ;; This is a conventional plain text. It should be translated into ;; text/plain. -;; +;; ;;--[[text/plain]] ;; This is also a plain text. But, it is explicitly specified as is. ;;--[[text/plain; charset=ISO-8859-1]] @@ -121,45 +120,62 @@ ;;; @ version ;;; -(defconst mime-edit-RCS-ID - "$Id: mime-edit.el,v 0.79 1997-05-09 01:26:13 morioka Exp $") - -(defconst mime-edit-version (get-version-string mime-edit-RCS-ID)) - -(defconst mime-edit-version-name - (concat "SEMI MIME-Edit " mime-edit-version)) +(defconst mime-edit-version-string + `,(concat "SEMI " + (mapconcat #'number-to-string (cdr semi-version) ".") + " - \"" (car semi-version) "\"")) ;;; @ variables ;;; -(defvar mime-ignore-preceding-spaces nil - "*Ignore preceding white spaces if non-nil.") +(defgroup mime-edit nil + "MIME edit mode" + :group 'mime) -(defvar mime-ignore-trailing-spaces nil - "*Ignore trailing white spaces if non-nil.") +(defcustom mime-ignore-preceding-spaces nil + "*Ignore preceding white spaces if non-nil." + :group 'mime-edit + :type 'boolean) -(defvar mime-ignore-same-text-tag t +(defcustom mime-ignore-trailing-spaces nil + "*Ignore trailing white spaces if non-nil." + :group 'mime-edit + :type 'boolean) + +(defcustom mime-ignore-same-text-tag t "*Ignore preceding text content-type tag that is same with new one. -If non-nil, the text tag is not inserted unless something different.") +If non-nil, the text tag is not inserted unless something different." + :group 'mime-edit + :type 'boolean) -(defvar mime-auto-hide-body t - "*Hide non-textual body encoded in base64 after insertion if non-nil.") +(defcustom mime-auto-hide-body t + "*Hide non-textual body encoded in base64 after insertion if non-nil." + :group 'mime-edit + :type 'boolean) -(defvar mime-edit-voice-recorder +(defcustom mime-edit-voice-recorder (function mime-edit-voice-recorder-for-sun) - "*Function to record a voice message and encode it. [mime-edit.el]") + "*Function to record a voice message and encode it." + :group 'mime-edit + :type 'function) -(defvar mime-edit-mode-hook nil - "*Hook called when enter MIME mode.") +(defcustom mime-edit-mode-hook nil + "*Hook called when enter MIME mode." + :group 'mime-edit + :type 'hook) -(defvar mime-edit-translate-hook nil +(defcustom mime-edit-translate-hook nil "*Hook called before translating into a MIME compliant message. To insert a signature file automatically, call the function -`mime-edit-insert-signature' from this hook.") +`mime-edit-insert-signature' from this hook." + :group 'mime-edit + :type 'hook) -(defvar mime-edit-exit-hook nil - "*Hook called when exit MIME mode.") +(defcustom mime-edit-exit-hook nil + "*Hook called when exit MIME mode." + :group 'mime-edit + :type 'hook) (defvar mime-content-types '(("text" @@ -180,7 +196,7 @@ To insert a signature file automatically, call the function ("html" ;;("charset" "" "ISO-2022-JP" "US-ASCII" "ISO-8859-1" "ISO-8859-8") ) - ("x-rot13-47") + ("x-rot13-47-48") ) ("message" ("external-body" @@ -209,6 +225,7 @@ To insert a signature file automatically, call the function ("image" ("gif") ("jpeg") + ("png") ("tiff") ("x-pic") ("x-mag") @@ -220,8 +237,18 @@ To insert a signature file automatically, call the function ) "*Alist of content-type, subtype, parameters and its values.") -(defvar mime-file-types - '(("\\.rtf$" +(defcustom mime-file-types + '(("\\.txt$" + "text" "plain" nil + nil + "inline" (("filename" . file)) + ) + ("\\.pln$" + "text" "plain" nil + nil + "inline" (("filename" . file)) + ) + ("\\.rtf$" "text" "richtext" nil nil nil nil) @@ -244,6 +271,11 @@ To insert a signature file automatically, call the function "base64" "inline" (("filename" . file)) ) + ("\\.png$" + "image" "png" nil + "base64" + "inline" (("filename" . file)) + ) ("\\.tiff$" "image" "tiff" nil "base64" @@ -340,15 +372,56 @@ To insert a signature file automatically, call the function "attachment" (("filename" . file)) ) ("\\.signature" - "text" "plain" nil nil) + "text" "plain" nil nil nil nil) (".*" "application" "octet-stream" nil nil - "attachment" (("filename" . file)) - ) + "attachment" (("filename" . file))) ) "*Alist of file name, types, parameters, and default encoding. -If encoding is nil, it is determined from its contents.") +If encoding is nil, it is determined from its contents." + :type `(repeat + (list regexp + ;; primary-type + (choice :tag "Primary-Type" + ,@(nconc (mapcar (lambda (cell) + (list 'item (car cell)) + ) + mime-content-types) + '(string))) + ;; subtype + (choice :tag "Sub-Type" + ,@(nconc + (apply #'nconc + (mapcar (lambda (cell) + (mapcar (lambda (cell) + (list 'item (car cell)) + ) + (cdr cell))) + mime-content-types)) + '(string))) + ;; parameters + (repeat :tag "Parameters of Content-Type field" + (cons string (choice string symbol))) + ;; content-transfer-encoding + (choice :tag "Encoding" + ,@(cons + '(const nil) + (mapcar (lambda (cell) + (list 'item (car cell)) + ) + mime-file-encoding-method-alist))) + ;; disposition-type + (choice :tag "Disposition-Type" + (item nil) + (item "inline") + (item "attachment") + string) + ;; parameters + (repeat :tag "Parameters of Content-Disposition field" + (cons string (choice string symbol))) + )) + :group 'mime-edit) ;;; @@ about charset, encoding and transfer-level @@ -417,7 +490,7 @@ If encoding is nil, it is determined from its contents.") "Xref" "X-UIDL" "X-Filter" "X-Gnus-.*" "X-VM-.*") "Delete these fields from original message when it is inserted as message/rfc822 part. -Each elements are regexp of field-name. [mime-edit.el]") +Each elements are regexp of field-name.") (defvar mime-edit-yank-ignored-field-regexp (concat "^" @@ -431,17 +504,23 @@ Each elements are regexp of field-name. [mime-edit.el]") ;;; @@ about message splitting ;;; -(defvar mime-edit-split-message t - "*Split large message if it is non-nil. [mime-edit.el]") +(defcustom mime-edit-split-message t + "*Split large message if it is non-nil." + :group 'mime-edit + :type 'boolean) -(defvar mime-edit-message-default-max-lines 1000 - "*Default maximum lines of a message. [mime-edit.el]") +(defcustom mime-edit-message-default-max-lines 1000 + "*Default maximum lines of a message." + :group 'mime-edit + :type 'integer) -(defvar mime-edit-message-max-lines-alist +(defcustom mime-edit-message-max-lines-alist '((news-reply-mode . 500)) "Alist of major-mode vs maximum lines of a message. If it is not specified for a major-mode, -`mime-edit-message-default-max-lines' is used. [mime-edit.el]") +`mime-edit-message-default-max-lines' is used." + :group 'mime-edit + :type 'list) (defconst mime-edit-split-ignored-field-regexp "\\(^Content-\\|^Subject:\\|^Mime-Version:\\)") @@ -458,10 +537,10 @@ If it is not specified for a major-mode, ;;; (defvar mime-edit-signing-type 'pgp-elkins - "*PGP signing type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]") + "*PGP signing type (pgp-elkins, pgp-kazu or nil).") (defvar mime-edit-encrypting-type 'pgp-elkins - "*PGP encrypting type (pgp-elkins, pgp-kazu or nil). [mime-edit.el]") + "*PGP encrypting type (pgp-elkins, pgp-kazu or nil).") ;;; @@ about tag @@ -512,17 +591,25 @@ If it is not specified for a major-mode, "*If non-nil, insert X-Emacs header field.") (defvar mime-edit-x-emacs-value - (if running-xemacs - (concat emacs-version - (if (featurep 'mule) - " with mule" - " without mule")) + (if (featurep 'xemacs) + (concat emacs-version (if (featurep 'mule) + " with mule" + " without mule")) (let ((ver (if (string-match "\\.[0-9]+$" emacs-version) (substring emacs-version 0 (match-beginning 0)) emacs-version))) (if (featurep 'mule) - (concat "Emacs " ver ", MULE " mule-version) - ver)))) + (concat "Emacs " ver + (if enable-multibyte-characters + (concat ", MULE " mule-version) + " (with raw setting)") + (if (featurep 'meadow) + (concat ", " (Meadow-version)) + )) + ver))) + "Body of X-Emacs field. +If variable `mime-edit-insert-x-emacs-field' is not nil, it is +inserted into message header.") ;;; @ constants @@ -533,9 +620,13 @@ If it is not specified for a major-mode, Tspecials means any character that matches with it in header must be quoted.") (defconst mime-edit-mime-version-value - (concat "1.0 (generated by " mime-edit-version-name ")") + (concat "1.0 (generated by " mime-edit-version-string ")") "MIME version number.") +(defconst mime-edit-mime-version-field-for-message/partial + (concat "MIME-Version: 1.0 (split by " mime-edit-version-string ")\n") + "MIME version field for message/partial.") + ;;; @ keymap and menu ;;; @@ -650,7 +741,7 @@ Tspecials means any character that matches with it in header must be quoted.") )) mime-edit-menu-list))) ))) - + ;; modified by Steven L. Baur ;; 1995/12/6 (c.f. [tm-en:209]) (or (boundp 'mime-edit-popup-menu-for-xemacs) @@ -850,20 +941,20 @@ User customizable variables (not documented all of them): (if mime-edit-mode-flag (error "You are already editing a MIME message.") (setq mime-edit-mode-flag t) - + ;; Set transfer level into mode line ;; (setq mime-transfer-level-string (mime-encoding-name mime-transfer-level 'not-omit)) (force-mode-line-update) - + ;; Define menu for XEmacs. (if running-xemacs (mime-edit-define-menu-for-xemacs) ) - + (enable-invisible) - + ;; I don't care about saving these. (setq paragraph-start (regexp-or mime-edit-single-part-tag-regexp @@ -920,26 +1011,27 @@ just return to previous mode." (princ (documentation 'mime-edit-mode)) (print-help-return-message))) -(defun mime-edit-insert-text () +(defun mime-edit-insert-text (&optional subtype) "Insert a text message. -Charset is automatically obtained from the `charsets-mime-charset-alist'." +Charset is automatically obtained from the `charsets-mime-charset-alist'. +If optional argument SUBTYPE is not nil, text/SUBTYPE tag is inserted." (interactive) - (let ((ret (mime-edit-insert-tag "text" nil nil))) - (if ret - (progn - (if (looking-at mime-edit-single-part-tag-regexp) - (progn - ;; Make a space between the following message. - (insert "\n") - (forward-char -1) - )) - (if (and (member (second ret) '("enriched" "richtext")) - (fboundp 'enriched-mode) - ) - (enriched-mode t) - (if (boundp 'enriched-mode) - (enriched-mode nil) - )))))) + (let ((ret (mime-edit-insert-tag "text" subtype nil))) + (when ret + (if (looking-at mime-edit-single-part-tag-regexp) + (progn + ;; Make a space between the following message. + (insert "\n") + (forward-char -1) + )) + (if (and (member (cadr ret) '("enriched" "richtext")) + (fboundp 'enriched-mode) + ) + (enriched-mode t) + (if (boundp 'enriched-mode) + (enriched-mode -1) + )) + ))) (defun mime-edit-insert-file (file &optional verbose) "Insert a message from a file." @@ -1040,8 +1132,9 @@ Charset is automatically obtained from the `charsets-mime-charset-alist'." (let ((signature-insert-hook (function (lambda () - (apply (function mime-edit-insert-tag) - (mime-find-file-type signature-file-name)) + (let ((items (mime-find-file-type signature-file-name))) + (apply (function mime-edit-insert-tag) + (car items) (cadr items) (list (caddr items)))) ))) ) (insert-signature arg) @@ -1158,7 +1251,7 @@ Optional argument ENCODING specifies an encoding method such as base64." (t (goto-char (point-max)) )) - ;; Then search for the beginning. + ;; Then search for the beginning. (re-search-backward mime-edit-end-tag-regexp nil t) (or (looking-at mime-edit-beginning-tag-regexp) ;; Restore previous point. @@ -1443,7 +1536,7 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))." )) (defun mime-prompt-for-encoding (default) - "Ask for Content-Transfer-Encoding. [mime-edit.el]" + "Ask for Content-Transfer-Encoding." (let (encoding) (while (string= (setq encoding @@ -1599,8 +1692,9 @@ Parameter must be '(PROMPT CHOICE1 (CHOISE2 ...))." (insert (format "Content-Transfer-Encoding: %s\n" encoding)) ) (insert "\n") - (or (funcall (pgp-function 'mime-sign) - (point-min)(point-max) nil nil pgp-boundary) + (or (as-binary-process + (funcall (pgp-function 'mime-sign) + (point-min)(point-max) nil nil pgp-boundary)) (throw 'mime-edit-error 'pgp-error) ) )))) @@ -1801,7 +1895,7 @@ Content-Transfer-Encoding: 7bit (insert mime-edit-x-emacs-value) )) ;; Make primary MIME headers. - (or (mail-position-on-field "Mime-Version") + (or (mail-position-on-field "MIME-Version") (insert mime-edit-mime-version-value)) ;; Remove old Content-Type and other fields. (save-restriction @@ -1933,7 +2027,7 @@ Content-Transfer-Encoding: 7bit (intern (downcase charset)) (mime-edit-choose-charset))) (mime-edit-define-charset charset) - (cond ((string-equal contype "text/x-rot13-47") + (cond ((string-equal contype "text/x-rot13-47-48") (save-excursion (forward-line) (mule-caesar-region (point) (mime-edit-content-end)) @@ -1971,6 +2065,34 @@ Content-Transfer-Encoding: 7bit ) (encode-mime-charset-region beg (mime-edit-content-end) charset) + ;; Protect "From " in beginning of line + (save-restriction + (narrow-to-region beg (mime-edit-content-end)) + (goto-char beg) + (let (case-fold-search) + (if (re-search-forward "^From " nil t) + (unless encoding + (if (memq charset '(iso-2022-jp + iso-2022-jp-2 + iso-2022-int-1 + x-ctext)) + (while (progn + (replace-match "\e(BFrom ") + (re-search-forward "^From " nil t) + )) + (setq encoding "quoted-printable") + ))))) + ;; canonicalize line break code + (or (member encoding '(nil "7bit" "8bit" "quoted-printable")) + (save-restriction + (narrow-to-region beg (mime-edit-content-end)) + (goto-char beg) + (while (re-search-forward "\\([^\r]\\)\n" nil t) + (replace-match + (concat (buffer-substring (match-beginning 0) + (match-end 1)) "\r\n")) + ))) + (goto-char beg) (mime-encode-region beg (mime-edit-content-end) encoding) (mime-edit-define-encoding encoding) )) @@ -2009,7 +2131,7 @@ Content-Transfer-Encoding: 7bit (defun mime-edit-voice-recorder-for-sun (encoding) "Record voice in a buffer using Sun audio device, -and insert data encoded as ENCODING. [mime-edit.el]" +and insert data encoded as ENCODING." (message "Start the recording on %s. Type C-g to finish the recording..." (system-name)) (mime-insert-encoded-file "/dev/audio" encoding) @@ -2068,7 +2190,7 @@ and insert data encoded as ENCODING. [mime-edit.el]" ;;; @ multipart enclosure ;;; -(defun mime-edit-enclose-region (type beg end) +(defun mime-edit-enclose-region-internal (type beg end) (save-excursion (goto-char beg) (let ((current (point))) @@ -2087,40 +2209,40 @@ and insert data encoded as ENCODING. [mime-edit.el]" (defun mime-edit-enclose-quote-region (beg end) (interactive "*r") - (mime-edit-enclose-region "quote" beg end) + (mime-edit-enclose-region-internal 'quote beg end) ) (defun mime-edit-enclose-mixed-region (beg end) (interactive "*r") - (mime-edit-enclose-region "mixed" beg end) + (mime-edit-enclose-region-internal 'mixed beg end) ) (defun mime-edit-enclose-parallel-region (beg end) (interactive "*r") - (mime-edit-enclose-region "parallel" beg end) + (mime-edit-enclose-region-internal 'parallel beg end) ) (defun mime-edit-enclose-digest-region (beg end) (interactive "*r") - (mime-edit-enclose-region "digest" beg end) + (mime-edit-enclose-region-internal 'digest beg end) ) (defun mime-edit-enclose-alternative-region (beg end) (interactive "*r") - (mime-edit-enclose-region "alternative" beg end) + (mime-edit-enclose-region-internal 'alternative beg end) ) (defun mime-edit-enclose-signed-region (beg end) (interactive "*r") (if mime-edit-signing-type - (mime-edit-enclose-region "signed" beg end) + (mime-edit-enclose-region-internal 'signed beg end) (message "Please specify signing type.") )) (defun mime-edit-enclose-encrypted-region (beg end) (interactive "*r") (if mime-edit-signing-type - (mime-edit-enclose-region "encrypted" beg end) + (mime-edit-enclose-region-internal 'encrypted beg end) (message "Please specify encrypting type.") )) @@ -2139,7 +2261,7 @@ and insert data encoded as ENCODING. [mime-edit.el]" (defun mime-edit-set-split (arg) (interactive (list - (y-or-n-p "Do you want to enable split?") + (y-or-n-p "Do you want to enable split? ") )) (setq mime-edit-split-message arg) (if arg @@ -2184,7 +2306,7 @@ Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8." (defun mime-edit-set-sign (arg) (interactive (list - (y-or-n-p "Do you want to sign?") + (y-or-n-p "Do you want to sign? ") )) (if arg (if mime-edit-signing-type @@ -2203,7 +2325,7 @@ Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8." (defun mime-edit-set-encrypt (arg) (interactive (list - (y-or-n-p "Do you want to encrypt?") + (y-or-n-p "Do you want to encrypt? ") )) (if arg (if mime-edit-encrypting-type @@ -2243,12 +2365,11 @@ Optional TRANSFER-LEVEL is a number of transfer-level, 7 or 8." ;;; @ split ;;; -(defun mime-edit-insert-partial-header - (fields subject id number total separator) +(defun mime-edit-insert-partial-header (fields subject + id number total separator) (insert fields) (insert (format "Subject: %s (%d/%d)\n" subject number total)) - (insert (format "Mime-Version: 1.0 (split by %s)\n" - mime-edit-version-name)) + (insert mime-edit-mime-version-field-for-message/partial) (insert (format "\ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" id number total separator)) @@ -2266,7 +2387,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (or (cdr (assq major-mode mime-edit-message-max-lines-alist)) mime-edit-message-default-max-lines)) ) - (let* ((mime-edit-draft-file-name + (let* ((mime-edit-draft-file-name (or (buffer-file-name) (make-temp-name (expand-file-name "mime-draft" mime-temp-directory)))) @@ -2374,7 +2495,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (defvar mime-edit-buffer nil) ; buffer local variable (defun mime-edit-preview-message () - "preview editing MIME message. [mime-edit.el]" + "preview editing MIME message." (interactive) (let* ((str (buffer-string)) (separator mail-header-separator) @@ -2397,7 +2518,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (setq mail-header-separator separator) (make-local-variable 'mime-edit-buffer) (setq mime-edit-buffer the-buf) - + (run-hooks 'mime-edit-translate-hook) (mime-edit-translate-buffer) (goto-char (point-min)) @@ -2412,17 +2533,16 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" "Quitting method for mime-view." (let ((temp mime-raw-buffer) buf) - (mime-view-kill-buffer) + (mime-preview-kill-buffer) (set-buffer temp) (setq buf mime-edit-buffer) (kill-buffer temp) (switch-to-buffer buf) )) -(set-alist 'mime-view-quitting-method-alist +(set-alist 'mime-preview-quitting-method-alist 'mime-temp-message-mode - (function mime-edit-quitting-method) - ) + #'mime-edit-quitting-method) ;;; @ edit again @@ -2437,23 +2557,17 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (defun mime-edit-decode-buffer (not-decode-text) (save-excursion (goto-char (point-min)) - (let ((ctl (mime/Content-Type))) + (let ((ctl (mime-read-Content-Type))) (if ctl - (let ((ctype (car ctl)) - (params (cdr ctl)) - type stype) - (if (string-match "/" ctype) - (progn - (setq type (substring ctype 0 (match-beginning 0))) - (setq stype (substring ctype (match-end 0))) - ) - (setq type ctype) - ) + (let ((type (car ctl)) + (stype (car (cdr ctl))) + (params (cdr (cdr ctl))) + ) (cond - ((string= ctype "application/pgp-signature") + ((and (eq type 'application)(eq stype 'pgp-signature)) (delete-region (point-min)(point-max)) ) - ((string= type "multipart") + ((eq type 'multipart) (let* ((boundary (cdr (assoc "boundary" params))) (boundary-pat (concat "\n--" (regexp-quote boundary) "[ \t]*\n")) @@ -2496,12 +2610,13 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" ))) )) (t - (let* (charset + (let* ((ctype (format "%s/%s" type stype)) + charset (pstr (let ((bytes (+ 14 (length ctype)))) (mapconcat (function (lambda (attr) - (if (string-equal (car attr) "charset") + (if (string= (car attr) "charset") (progn (setq charset (cdr attr)) "") @@ -2531,7 +2646,7 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (eliminate-top-spaces (std11-unfold-string (buffer-substring hbeg end)))) - (if (or charset (string-equal type "text")) + (if (or charset (eq type 'text)) (progn (delete-region beg (1+ end)) (goto-char (point-min)) @@ -2558,12 +2673,14 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (insert (concat "\n" (mime-create-tag - (concat type "/" stype pstr) encoding))) + (format "%s/%s%s" type stype pstr) + encoding))) ) (delete-region (point-min) he) (insert (mime-create-tag - (concat type "/" stype pstr) encoding)) + (format "%s/%s%s" type stype pstr) + encoding)) )) )))) (or not-decode-text