2005-10-13 Reiner Steib <Reiner.Steib@gmx.de>
+ * mml-sec.el (mml-secure-method): New internal variable.
+ (mml-secure-sign, mml-secure-encrypt, mml-secure-message-sign)
+ (mml-secure-message-sign-encrypt, mml-secure-message-encrypt): New
+ functions using mml-secure-method.
+
+ * mml.el (mml-mode-map): Add key bindings for those functions.
+ (mml-menu): Simplify security menu entries. Suggested by Jesper
+ Harder <harder@myrealbox.com>.
+ (mml-attach-file, mml-attach-buffer, mml-attach-external): Goto
+ end of message if point is the headers of the message.
+
+ * message.el (message-in-body-p): New function.
+
+ * assistant.el: Autoload gnus-util and netrc.
+
+ * mm-util.el (mm-charset-to-coding-system): Add allow-override.
+ Use `mm-charset-override-alist' only when decoding.
+
+ * mm-bodies.el (mm-decode-body): Call
+ `mm-charset-to-coding-system' with allow-override argument.
+
* gnus-art.el (gnus-mime-view-part-as-type-internal): Try to fetch
`filename' from Content-Disposition if Content-Type doesn't
provide `name'.
(pop alist))
out)))
-(defun mm-charset-to-coding-system (charset &optional lbt)
+(defun mm-charset-to-coding-system (charset &optional lbt
+ allow-override)
"Return coding-system corresponding to CHARSET.
CHARSET is a symbol naming a MIME charset.
If optional argument LBT (`unix', `dos' or `mac') is specified, it is
-used as the line break code type of the coding system."
+used as the line break code type of the coding system.
+
+If ALLOW-OVERRIDE is given, use `mm-charset-override-alist' to
+map undesired charset names to their replacement. This should
+only be used for decoding, not for encoding."
+ ;; OVERRIDE is used (only) in `mm-decode-body'.
(when (stringp charset)
(setq charset (intern (downcase charset))))
(when lbt
((or (null (mm-get-coding-system-list))
(not (fboundp 'coding-system-get)))
charset)
- ;; Check override list quite early:
- ((let ((cs (cdr (assq charset mm-charset-override-alist))))
- (and cs (mm-coding-system-p cs) cs)))
+ ;; Check override list quite early. Should only used for decoding, not for
+ ;; encoding!
+ ((and allow-override
+ (let ((cs (cdr (assq charset mm-charset-override-alist))))
+ (and cs (mm-coding-system-p cs) cs))))
;; ascii
((eq charset 'us-ascii)
'ascii)
(cons method tags))))
(t (error "The message is corrupted. No mail header separator"))))))
+(defvar mml-secure-method
+ (if (equal mml-default-encrypt-method mml-default-sign-method)
+ mml-default-sign-method
+ "pgpmime")
+ "Current security method. Internal variable.")
+
+(defun mml-secure-sign (&optional method)
+ "Add MML tags to sign this MML part.
+Use METHOD if given. Else use `mml-secure-method' or
+`mml-default-sign-method'."
+ (interactive)
+ (mml-secure-part
+ (or method mml-secure-method mml-default-sign-method)
+ 'sign))
+
+(defun mml-secure-encrypt (&optional method)
+ "Add MML tags to encrypt this MML part.
+Use METHOD if given. Else use `mml-secure-method' or
+`mml-default-sign-method'."
+ (interactive)
+ (mml-secure-part
+ (or method mml-secure-method mml-default-sign-method)))
+
(defun mml-secure-sign-pgp ()
"Add MML tags to PGP sign this MML part."
(interactive)
(when (re-search-backward "^<#secure.*>\n" nil t)
(delete-region (match-beginning 0) (match-end 0)))))
+
+(defun mml-secure-message-sign (&optional method)
+ "Add MML tags to sign this MML part.
+Use METHOD if given. Else use `mml-secure-method' or
+`mml-default-sign-method'."
+ (interactive)
+ (mml-secure-part
+ (or method mml-secure-method mml-default-sign-method)
+ 'sign))
+
+(defun mml-secure-message-sign-encrypt (&optional method)
+ "Add MML tag to sign and encrypt the entire message.
+Use METHOD if given. Else use `mml-secure-method' or
+`mml-default-sign-method'."
+ (interactive)
+ (mml-secure-message
+ (or method mml-secure-method mml-default-sign-method)
+ 'signencrypt))
+
+(defun mml-secure-message-encrypt (&optional method)
+ "Add MML tag to encrypt the entire message.
+Use METHOD if given. Else use `mml-secure-method' or
+`mml-default-sign-method'."
+ (interactive)
+ (mml-secure-message
+ (or method mml-secure-method mml-default-sign-method)
+ 'encrypt))
+
(defun mml-secure-message-sign-smime ()
"Add MML tag to encrypt/sign the entire message."
(interactive)
(encryptpart (make-sparse-keymap))
(map (make-sparse-keymap))
(main (make-sparse-keymap)))
+ (define-key map "\C-s" 'mml-secure-message-sign)
+ (define-key map "\C-c" 'mml-secure-message-encrypt)
+ (define-key map "\C-e" 'mml-secure-message-sign-encrypt)
+ (define-key map "\C-p\C-s" 'mml-secure-sign)
+ (define-key map "\C-p\C-c" 'mml-secure-encrypt)
(define-key sign "p" 'mml-secure-message-sign-pgpmime)
(define-key sign "o" 'mml-secure-message-sign-pgp)
(define-key sign "s" 'mml-secure-message-sign-smime)
["Attach File..." mml-attach-file
,@(if (featurep 'xemacs) '(t)
'(:help "Attach a file at point"))]
- ["Attach Buffer..." mml-attach-buffer t]
- ["Attach External..." mml-attach-external t]
- ["Insert Part..." mml-insert-part t]
- ["Insert Multipart..." mml-insert-multipart t]
- ["PGP/MIME Sign" mml-secure-message-sign-pgpmime t]
- ["PGP/MIME Encrypt" mml-secure-message-encrypt-pgpmime t]
- ["PGP Sign" mml-secure-message-sign-pgp t]
- ["PGP Encrypt" mml-secure-message-encrypt-pgp t]
- ["S/MIME Sign" mml-secure-message-sign-smime t]
- ["S/MIME Encrypt" mml-secure-message-encrypt-smime t]
- ("Secure MIME part"
- ["PGP/MIME Sign Part" mml-secure-sign-pgpmime t]
- ["PGP/MIME Encrypt Part" mml-secure-encrypt-pgpmime t]
- ["PGP Sign Part" mml-secure-sign-pgp t]
- ["PGP Encrypt Part" mml-secure-encrypt-pgp t]
- ["S/MIME Sign Part" mml-secure-sign-smime t]
- ["S/MIME Encrypt Part" mml-secure-encrypt-smime t])
- ["Encrypt/Sign off" mml-unsecure-message t]
+ ["Attach Buffer..." mml-attach-buffer
+ ,@(if (featurep 'xemacs) '(t)
+ '(:help "Attach a buffer to the outgoing MIME message"))]
+ ["Attach External..." mml-attach-external
+ ,@(if (featurep 'xemacs) '(t)
+ '(:help "Attach reference to file"))]
+ ;;
+ ("Change Security Method"
+ ["PGP/MIME"
+ (lambda () (interactive) (setq mml-secure-method "pgpmime"))
+ ,@(if (featurep 'xemacs) nil
+ '(:help "Set Security Method to PGP/MIME"))
+ :style radio
+ :selected (equal mml-secure-method "pgpmime") ]
+ ["S/MIME"
+ (lambda () (interactive) (setq mml-secure-method "smime"))
+ ,@(if (featurep 'xemacs) nil
+ '(:help "Set Security Method to S/MIME"))
+ :style radio
+ :selected (equal mml-secure-method "smime") ]
+ ["Inline PGP"
+ (lambda () (interactive) (setq mml-secure-method "pgp"))
+ ,@(if (featurep 'xemacs) nil
+ '(:help "Set Security Method to inline PGP"))
+ :style radio
+ :selected (equal mml-secure-method "pgp") ] )
+ ;;
+ ["Sign Message" mml-secure-message-sign t]
+ ["Encrypt Message" mml-secure-message-encrypt t]
+ ["Sign and Encrypt Message" mml-secure-message-sign-encrypt t]
+ ["Encrypt/Sign off" mml-unsecure-message
+ ,@(if (featurep 'xemacs) '(t)
+ '(:help "Don't Encrypt/Sign Message"))]
+ ;; Maybe we could remove these, because people who write MML most probably
+ ;; don't use the menu:
+ ["Insert Part..." mml-insert-part
+ :active (message-in-body-p)]
+ ["Insert Multipart..." mml-insert-multipart
+ :active (message-in-body-p)]
+ ;;
+ ;; Do we have separate encrypt and encrypt/sign commands for parts?
+ ["Sign Part" mml-secure-sign t]
+ ["Encrypt Part" mml-secure-encrypt t]
;;["Narrow" mml-narrow-to-part t]
- ["Quote MML" mml-quote-region
+ ["Quote MML in region" mml-quote-region
:active (message-mark-active-p)
,@(if (featurep 'xemacs) nil
'(:help "Quote MML tags in region"))]
(description (mml-minibuffer-read-description))
(disposition (mml-minibuffer-read-disposition type)))
(list file type description disposition)))
- (mml-insert-empty-tag 'part
- 'type type
- 'filename file
- 'disposition (or disposition "attachment")
- 'description description))
+ (save-excursion
+ (unless (message-in-body-p) (goto-char (point-max)))
+ (mml-insert-empty-tag 'part
+ 'type type
+ 'filename file
+ 'disposition (or disposition "attachment")
+ 'description description)))
(defun mml-dnd-attach-file (uri action)
"Attach a drag and drop file.
(type (mml-minibuffer-read-type buffer "text/plain"))
(description (mml-minibuffer-read-description)))
(list buffer type description)))
- (mml-insert-empty-tag 'part 'type type 'buffer buffer
- 'disposition "attachment" 'description description))
+ (save-excursion
+ (unless (message-in-body-p) (goto-char (point-max)))
+ (mml-insert-empty-tag 'part 'type type 'buffer buffer
+ 'disposition "attachment"
+ 'description description)))
(defun mml-attach-external (file &optional type description)
"Attach an external file into the buffer.
(type (mml-minibuffer-read-type file))
(description (mml-minibuffer-read-description)))
(list file type description)))
- (mml-insert-empty-tag 'external 'type type 'name file
- 'disposition "attachment" 'description description))
+ (save-excursion
+ (unless (message-in-body-p) (goto-char (point-max)))
+ (mml-insert-empty-tag 'external 'type type 'name file
+ 'disposition "attachment" 'description description)))
(defun mml-insert-multipart (&optional type)
(interactive (list (completing-read "Multipart type (default mixed): "