"S/MIME encryption of current region.")
(autoload 'smime-sign-region "smime"
"S/MIME signature of current region.")
+(defvar smime-output-buffer)
+(defvar smime-errors-buffer)
;;; @ version
"A string formatted version of `mime-transfer-level'.")
(make-variable-buffer-local 'mime-transfer-level-string)
-
;;; @@ about content transfer encoding
(defvar mime-content-transfer-encoding-priority-list
(mime-create-tag
(mime-edit-set-parameter
(mime-edit-get-contype tag)
- "charset" (upcase (symbol-name charset)))
+ "charset"
+ (let ((comment (get charset 'mime-charset-comment)))
+ (if comment
+ (concat (upcase (symbol-name charset)) " (" comment ")")
+ (upcase (symbol-name charset)))))
(mime-edit-get-encoding tag)))))))
(defun mime-edit-define-encoding (encoding)
(let ((tag (buffer-substring (match-beginning 0)(match-end 0))))
(replace-match (concat "-" (substring tag 2))))))))
+(defvar mime-edit-pgp-user-id nil)
+
(defun mime-edit-sign-pgp-mime (beg end boundary)
(save-excursion
(save-restriction
(defvar mime-edit-pgp-processing nil)
(make-variable-buffer-local 'mime-edit-pgp-processing)
-(defvar mime-edit-pgp-user-id nil)
-
(defun mime-edit-set-sign (arg)
(interactive
(list
;;; Code:
+(eval-when-compile (require 'cl))
+
(eval-when-compile (require 'static))
(require 'mime-view)
(require 'alist)
(require 'path-util)
-(cond
- ((featurep 'xemacs)
-
- (require 'images)
-
- (defun-maybe image-inline-p (format)
- (or (memq format image-native-formats)
- (find-if (function
- (lambda (native)
- (image-converter-chain format native)))
- image-native-formats)))
-
- (image-register-netpbm-utilities)
- (image-register-converter 'pic 'ppm "pictoppm")
- (image-register-converter 'mag 'ppm "magtoppm")
-
- (defun image-insert-at-point (image)
- (let ((e (make-extent (point) (point))))
- (set-extent-end-glyph e (make-glyph image))))
-
- (defsubst-maybe image-invalid-glyph-p (glyph)
- (or (null (aref glyph 0))
- (null (aref glyph 2))
- (equal (aref glyph 2) ""))))
- ((featurep 'mule)
-
- (eval-when-compile (ignore-errors (require 'image)))
-
- (eval-and-compile
- (autoload 'bitmap-insert-xbm-buffer "bitmap"))
-
- (static-if (fboundp 'image-type-available-p)
- (defalias-maybe 'image-inline-p 'image-type-available-p)
- (defvar image-native-formats '(xbm))
- (defun-maybe image-inline-p (format)
- (memq format image-native-formats)))
-
- (static-unless (or (not (fboundp 'create-image))
- (memq 'data-p (aref (symbol-function 'create-image) 0)))
- (defadvice create-image
- (around data-p (file-or-data &optional type data-p &rest props) activate)
- (if (ad-get-arg 2)
- (setq ad-return-value
- (nconc
- (list 'image ':type (ad-get-arg 1) ':data (ad-get-arg 0))
- props))
- (ad-set-args 0 (list (ad-get-arg 0) (ad-get-arg 1) (ad-get-arg 3)))
- ad-do-it)))
-
- (defun-maybe image-normalize (format data)
- (if (memq format '(xbm xpm))
- (create-image data format 'data)
- (let ((image-file
- (make-temp-name
- (expand-file-name "tm" temporary-file-directory))))
- (with-temp-buffer
- (insert data)
- (write-region-as-binary (point-min)(point-max) image-file))
- (create-image image-file format))))
-
- (defun image-insert-at-point (image)
- (static-if (fboundp 'insert-image)
- (unwind-protect
- (save-excursion
- (static-if (condition-case nil
- (progn (insert-image '(image)) nil)
- (wrong-number-of-arguments t))
- (insert-image image "x")
- (insert-image image))
- (insert "\n")
- (save-window-excursion
- (set-window-buffer (selected-window)(current-buffer))
- (sit-for 0)))
- (let ((file (plist-get (cdr image) ':file)))
- (and file (file-exists-p file)
- (delete-file file))))
- (when (eq (plist-get (cdr image) ':type) 'xbm)
- (save-restriction
- (narrow-to-region (point)(point))
- (insert (plist-get (cdr image) ':data))
- (let ((mark (set-marker (make-marker) (point))))
- (bitmap-insert-xbm-buffer (current-buffer))
- (delete-region (point-min) mark))))))
-
- (defsubst-maybe image-invalid-glyph-p (glyph)
- (not (eq 'image (nth 0 glyph))))))
-
-;;
-;; X-Face
-;;
-
-(cond
- ((module-installed-p 'highlight-headers)
- (eval-and-compile
- (autoload 'highlight-headers "highlight-headers"))
-
- (defun mime-preview-x-face-function-use-highlight-headers ()
- (highlight-headers (point-min) (re-search-forward "^$" nil t) t))
- (add-hook 'mime-display-header-hook
- 'mime-preview-x-face-function-use-highlight-headers))
- ((and (featurep 'mule)
- (condition-case nil
- (require 'x-face-mule)
- (file-error nil))
- (exec-installed-p uncompface-program exec-path))
- (add-hook 'mime-display-header-hook 'x-face-decode-message-header)))
+(static-if (featurep 'xemacs)
+ (progn
+ (defun mime-image-type-available-p (type)
+ (memq type (image-instantiator-format-list)))
+
+ (defun mime-image-create (file-or-data &optional type data-p &rest props)
+ (let ((instance
+ (make-image-instance
+ (if (and type (mime-image-type-available-p type))
+ (vector type (if data-p :data :file) file-or-data)
+ file-or-data)
+ nil nil 'noerror)))
+ (if (nothing-image-instance-p instance) nil
+ (make-glyph instance))))
+
+ (defun mime-image-insert (image string &optional area)
+ (let ((extent (make-extent (point) (progn (insert string)(point)))))
+ (set-extent-property extent 'invisible t)
+ (set-extent-end-glyph extent image))))
+ (condition-case nil
+ (progn
+ (require 'image)
+ (defalias 'mime-image-type-available-p 'image-type-available-p)
+ (defalias 'mime-image-create 'create-image)
+ (defalias 'mime-image-insert 'insert-image))
+ (error
+ (condition-case nil
+ (progn
+ (require (if (featurep 'mule) 'bitmap ""))
+ (defun mime-image-read-xbm-buffer (buffer)
+ (condition-case nil
+ (mapconcat #'bitmap-compose
+ (append (bitmap-decode-xbm
+ (bitmap-read-xbm-buffer
+ (current-buffer))) nil) "\n")
+ (error nil)))
+ (defun mime-image-insert (image string &optional area)
+ (insert image)))
+ (error
+ (defun mime-image-read-xbm-buffer (buffer)
+ (save-excursion
+ (set-buffer buffer)
+ (let ((case-fold-search t) width height xbytes right margin)
+ (goto-char (point-min))
+ (or (re-search-forward "_width[\t ]+\\([0-9]+\\)" nil t)
+ (error "!! Illegal xbm file format" (current-buffer)))
+ (setq width (string-to-int (match-string 1))
+ xbytes (/ (+ width 7) 8))
+ (goto-char (point-min))
+ (or (re-search-forward "_height[\t ]+\\([0-9]+\\)" nil t)
+ (error "!! Illegal xbm file format" (current-buffer)))
+ (setq height (string-to-int (match-string 1)))
+ (goto-char (point-min))
+ (re-search-forward "0x[0-9a-f][0-9a-f],")
+ (delete-region (point-min) (match-beginning 0))
+ (goto-char (point-min))
+ (while (re-search-forward "[\n\r\t ,;}]" nil t)
+ (replace-match ""))
+ (goto-char (point-min))
+ (while (re-search-forward "0x" nil t)
+ (replace-match "\\x" nil t))
+ (goto-char (point-min))
+ (insert "(" (number-to-string width) " "
+ (number-to-string height) " \"")
+ (goto-char (point-max))
+ (insert "\")")
+ (goto-char (point-min))
+ (read (current-buffer)))))
+
+ (defun mime-image-insert (image string &optional area)
+ (save-restriction
+ (narrow-to-region (point)(point))
+ (let ((face (gensym "mis")))
+ (or (facep face) (make-face face))
+ (set-face-stipple face image)
+ (let ((row (make-string (/ (car image) (frame-char-width)) ? ))
+ (height (/ (nth 1 image) (frame-char-height)))
+ (i 0))
+ (while (< i height)
+ (set-text-properties (point) (progn (insert row)(point))
+ (list 'face face))
+ (insert "\n")
+ (setq i (1+ i)))))))))
+
+ (defun mime-image-type-available-p (type)
+ (eq type 'xbm))
+
+ (defun mime-image-create (file-or-data &optional type data-p &rest props)
+ (when (or (null type) (eq type 'xbm))
+ (with-temp-buffer
+ (if data-p
+ (insert file-or-data)
+ (insert-file-contents file-or-data))
+ (mime-image-read-xbm-buffer (current-buffer))))))))
(defvar mime-image-format-alist
'((image jpeg jpeg)
(image xbm xbm)
(image x-xbm xbm)
(image x-xpixmap xpm)
- (image x-pic pic)
- (image x-mag mag)
(image png png)))
(dolist (rule mime-image-format-alist)
- (let ((type (car rule))
- (subtype (nth 1 rule))
- (format (nth 2 rule)))
- (when (image-inline-p format)
- (ctree-set-calist-strictly
- 'mime-preview-condition
- (list (cons 'type type)(cons 'subtype subtype)
- '(body . visible)
- (cons 'body-presentation-method #'mime-display-image)
- (cons 'image-format format))))))
-
+ (when (mime-image-type-available-p (nth 2 rule))
+ (ctree-set-calist-strictly
+ 'mime-preview-condition
+ (list (cons 'type (car rule))(cons 'subtype (nth 1 rule))
+ '(body . visible)
+ (cons 'body-presentation-method #'mime-display-image)
+ (cons 'image-format (nth 2 rule))))))
+
;;; @ content filter for images
;;;
;; (for XEmacs 19.12 or later)
-(eval-when-compile
- (defmacro mime-image-normalize-xbm (entity)
- (` (with-temp-buffer
- (mime-insert-entity-content (, entity))
- (let ((cur (current-buffer))
- width height)
- (goto-char (point-min))
- (search-forward "width ")
- (setq width (read cur))
- (goto-char (point-min))
- (search-forward "height ")
- (setq height (read cur))
- (goto-char (point-min))
- (search-forward "{")
- (delete-region (point-min) (point))
- (insert "\"")
- (search-forward "}")
- (delete-region (1- (point)) (point-max))
- (insert "\"")
- (goto-char (point-min))
- (while (re-search-forward "[^\"0-9A-FXa-fx]+" nil t)
- (replace-match ""))
- (goto-char (point-min))
- (while (search-forward "0x" nil t)
- (replace-match "\\\\x"))
- (goto-char (point-min))
- (, (if (featurep 'xemacs)
- (` (vector 'xbm :data
- (list width height (read cur))))
- '(` (image :type xbm :width (, width) :height (, height)
- :data (, (read cur)))))))))))
-
(defun mime-display-image (entity situation)
(message "Decoding image...")
- (let* ((format (cdr (assq 'image-format situation)))
- (image (if (or (featurep 'xemacs) (boundp 'image-types))
- (if (eq 'xbm format)
- (mime-image-normalize-xbm entity)
- (image-normalize format (mime-entity-content entity)))
- (image-normalize format (mime-entity-content entity)))))
- (if (image-invalid-glyph-p image)
- (message "Invalid glyph!")
- (image-insert-at-point image)
- (message "Decoding image... done")))
- (static-when (featurep 'xemacs)
- (insert "\n")))
-
+ (let ((format (cdr (assq 'image-format situation)))
+ (image-file
+ (make-temp-name (expand-file-name "tm" temporary-file-directory)))
+ (orig-mode (default-file-modes))
+ image)
+ (unwind-protect
+ (progn
+ (set-default-file-modes 448)
+ (mime-write-entity-content entity image-file)
+ (if (null (setq image (mime-image-create image-file format)))
+ (message "Invalid glyph!")
+ (save-excursion
+ (mime-image-insert image "x")
+ (insert "\n")
+ (save-window-excursion
+ (set-window-buffer (selected-window)(current-buffer))
+ (sit-for 0))
+ (message "Decoding image... done"))))
+ (set-default-file-modes orig-mode)
+ (condition-case nil
+ (delete-file image-file)
+ (error nil)))))
;;; @ end
;;;
"S/MIME decryption of current region.")
(autoload 'smime-verify-region "smime"
"S/MIME verification of current region.")
+(defvar smime-output-buffer)
+(defvar smime-errors-buffer)
;;; @ Internal method for multipart/signed
(format "%s-%s" (buffer-name) (mime-entity-number entity)))
(mother (current-buffer))
(preview-buffer (concat "*Preview-" (buffer-name) "*")))
- (when (memq (or (cdr (assq 'smime-type situation)) enveloped-data)
+ (when (memq (or (cdr (assq 'smime-type situation)) 'enveloped-data)
'(enveloped-data signed-data))
(set-buffer (get-buffer-create new-name))
(let ((inhibit-read-only t)
"GnuPG interface"
:group 'pgg)
-(defcustom pgg-gpg-program "gpg"
+(defcustom pgg-gpg-program "gpg"
"The GnuPG executable."
:group 'pgg-gpg
:type 'string)
(with-current-buffer (get-buffer-create output-buffer)
(buffer-disable-undo)
(erase-buffer))
- (as-binary-process
- (setq process
- (apply #'start-process-shell-command "*GnuPG*" output-buffer
- program args)))
- (set-process-sentinel process #'ignore)
- (when passphrase
- (process-send-string process (concat passphrase "\n")))
- (process-send-region process start end)
- (process-send-eof process)
- (while (eq 'run (process-status process))
- (accept-process-output process 5))
- (setq status (process-status process)
- exit-status (process-exit-status process))
- (delete-process process)
- (with-current-buffer output-buffer
- (pgg-convert-lbt-region (point-min)(point-max) 'LF)
+ (unwind-protect
+ (progn
+ (as-binary-process
+ (setq process
+ (apply #'start-process-shell-command "*GnuPG*" output-buffer
+ program args)))
+ (set-process-sentinel process #'ignore)
+ (when passphrase
+ (process-send-string process (concat passphrase "\n")))
+ (process-send-region process start end)
+ (process-send-eof process)
+ (while (eq 'run (process-status process))
+ (accept-process-output process 5))
+ (setq status (process-status process)
+ exit-status (process-exit-status process))
+ (delete-process process)
+ (with-current-buffer output-buffer
+ (pgg-convert-lbt-region (point-min)(point-max) 'LF)
- (if (memq status '(stop signal))
- (error "%s exited abnormally: '%s'" program exit-status))
- (if (= 127 exit-status)
- (error "%s could not be found" program))
+ (if (memq status '(stop signal))
+ (error "%s exited abnormally: '%s'" program exit-status))
+ (if (= 127 exit-status)
+ (error "%s could not be found" program))
- (set-buffer (get-buffer-create errors-buffer))
- (buffer-disable-undo)
- (erase-buffer)
- (insert-file-contents errors-file-name)
- (delete-file errors-file-name)
+ (set-buffer (get-buffer-create errors-buffer))
+ (buffer-disable-undo)
+ (erase-buffer)
+ (insert-file-contents errors-file-name)
- (set-buffer (get-buffer-create status-buffer))
- (buffer-disable-undo)
- (erase-buffer)
- (insert-file-contents status-file-name)
- (delete-file status-file-name)
-
+ (set-buffer (get-buffer-create status-buffer))
+ (buffer-disable-undo)
+ (erase-buffer)
+ (insert-file-contents status-file-name)))
(if (and process (eq 'run (process-status process)))
- (interrupt-process process)))))
+ (interrupt-process process))
+ (condition-case nil
+ (progn
+ (delete-file status-file-name)
+ (delete-file errors-file-name))
+ (file-error nil)))))
(luna-define-method pgg-scheme-lookup-key ((scheme pgg-scheme-gpg)
string &optional type)
(erase-buffer))
(when passphrase
(setenv "PGPPASSFD" "0"))
- (as-binary-process
- (setq process
- (apply #'start-process-shell-command "*PGP*" output-buffer
- program args)))
- (set-process-sentinel process #'ignore)
- (when passphrase
- (process-send-string process (concat passphrase "\n")))
- (process-send-region process start end)
- (process-send-eof process)
- (while (eq 'run (process-status process))
- (accept-process-output process 5))
- (setq status (process-status process)
- exit-status (process-exit-status process))
- (delete-process process)
- (with-current-buffer output-buffer
- (pgg-convert-lbt-region (point-min)(point-max) 'LF)
-
- (if (memq status '(stop signal))
- (error "%s exited abnormally: '%s'" program exit-status))
- (if (= 127 exit-status)
- (error "%s could not be found" program))
-
- (set-buffer (get-buffer-create errors-buffer))
- (buffer-disable-undo)
- (erase-buffer)
- (insert-file-contents errors-file-name)
- (delete-file errors-file-name)
-
+ (unwind-protect
+ (progn
+ (as-binary-process
+ (setq process
+ (apply #'start-process-shell-command "*PGP*" output-buffer
+ program args)))
+ (set-process-sentinel process #'ignore)
+ (when passphrase
+ (process-send-string process (concat passphrase "\n")))
+ (process-send-region process start end)
+ (process-send-eof process)
+ (while (eq 'run (process-status process))
+ (accept-process-output process 5))
+ (setq status (process-status process)
+ exit-status (process-exit-status process))
+ (delete-process process)
+ (with-current-buffer output-buffer
+ (pgg-convert-lbt-region (point-min)(point-max) 'LF)
+
+ (if (memq status '(stop signal))
+ (error "%s exited abnormally: '%s'" program exit-status))
+ (if (= 127 exit-status)
+ (error "%s could not be found" program))
+
+ (set-buffer (get-buffer-create errors-buffer))
+ (buffer-disable-undo)
+ (erase-buffer)
+ (insert-file-contents errors-file-name)))
(if (and process (eq 'run (process-status process)))
- (interrupt-process process)))))
+ (interrupt-process process))
+ (condition-case nil
+ (delete-file errors-file-name)
+ (file-error nil)))))
(luna-define-method pgg-scheme-lookup-key ((scheme pgg-scheme-pgp)
string &optional type)
(erase-buffer))
(when passphrase
(setenv "PGPPASSFD" "0"))
- (as-binary-process
- (setq process
- (apply #'start-process-shell-command "*PGP*" output-buffer
- program args)))
- (set-process-sentinel process #'ignore)
- (when passphrase
- (process-send-string process (concat passphrase "\n")))
- (process-send-region process start end)
- (process-send-eof process)
- (while (eq 'run (process-status process))
- (accept-process-output process 5))
- (setq status (process-status process)
- exit-status (process-exit-status process))
- (delete-process process)
- (with-current-buffer output-buffer
- (pgg-convert-lbt-region (point-min)(point-max) 'LF)
-
- (if (memq status '(stop signal))
- (error "%s exited abnormally: '%s'" program exit-status))
- (if (= 127 exit-status)
- (error "%s could not be found" program))
-
- (set-buffer (get-buffer-create errors-buffer))
- (buffer-disable-undo)
- (erase-buffer)
- (insert-file-contents errors-file-name)
- (delete-file errors-file-name)
-
+ (unwind-protect
+ (progn
+ (as-binary-process
+ (setq process
+ (apply #'start-process-shell-command "*PGP*" output-buffer
+ program args)))
+ (set-process-sentinel process #'ignore)
+ (when passphrase
+ (process-send-string process (concat passphrase "\n")))
+ (process-send-region process start end)
+ (process-send-eof process)
+ (while (eq 'run (process-status process))
+ (accept-process-output process 5))
+ (setq status (process-status process)
+ exit-status (process-exit-status process))
+ (delete-process process)
+ (with-current-buffer output-buffer
+ (pgg-convert-lbt-region (point-min)(point-max) 'LF)
+
+ (if (memq status '(stop signal))
+ (error "%s exited abnormally: '%s'" program exit-status))
+ (if (= 127 exit-status)
+ (error "%s could not be found" program))
+
+ (set-buffer (get-buffer-create errors-buffer))
+ (buffer-disable-undo)
+ (erase-buffer)
+ (insert-file-contents errors-file-name)))
(if (and process (eq 'run (process-status process)))
- (interrupt-process process)))))
+ (interrupt-process process))
+ (condition-case nil
+ (delete-file errors-file-name)
+ (file-error nil)))))
(luna-define-method pgg-scheme-lookup-key ((scheme pgg-scheme-pgp5)
string &optional type)
(if signature (delete-file signature))
(with-current-buffer pgg-errors-buffer
(goto-char (point-min))
- (re-search-forward "^Good signature" nil t))))
+ (if (re-search-forward "^Good signature" nil t)
+ (progn
+ (set-buffer pgg-output-buffer)
+ (insert-buffer-substring pgg-errors-buffer)
+ t)
+ nil))))
(luna-define-method pgg-scheme-insert-key ((scheme pgg-scheme-pgp5))
(let* ((pgg-pgp5-user-id (or pgg-pgp5-user-id pgg-default-user-id))
,@body)))
(defun pgg-temp-buffer-show-function (buffer)
- (let ((window (split-window-vertically
- (- (window-height)
- (/ (window-height) 5)))))
- (set-window-buffer window buffer)))
+ (let ((window (split-window-vertically)))
+ (set-window-buffer window buffer)
+ (shrink-window-if-larger-than-buffer window)))
(defun pgg-display-output-buffer (start end status)
(if status
;; for image/* and X-Face
(defvar mime-setup-enable-inline-image
(and window-system
- (or (featurep 'xemacs)
- (and (featurep 'mule)(module-installed-p 'bitmap))))
+ (or (featurep 'xemacs) (featurep 'mule))))
"*If it is non-nil, semi-setup sets up to use mime-image.")
(if mime-setup-enable-inline-image
- (call-after-loaded 'mime-view
- (function
- (lambda ()
- (require 'mime-image)))))
-
+ (eval-after-load "mime-view"
+ '(require 'mime-image)))
;; for text/html
(defvar mime-setup-enable-inline-html
(smime-parse-attribute
(buffer-substring (point)(progn (end-of-line)(point))))))))
-(static-condition-case nil
- (directory-files nil nil nil nil nil)
- (wrong-number-of-arguments
- (defmacro smime-directory-files
- (directory &optional full match nosort files-only)
- (if files-only
- `(delq nil (mapcar
- (lambda (file)
- ,(if (eq files-only t)
- `(if (file-directory-p file) nil file)
- `(if (file-directory-p file) file nil)))
- (directory-files ,directory ,full ,match ,nosort)))
- `(directory-files ,directory ,full ,match ,nosort))))
- (error
- (defalias 'smime-directory-files 'directory-files)))
-
(defsubst smime-find-certificate (attr)
- (let ((files (if (file-directory-p smime-certificate-directory)
- (delq nil (mapcar (lambda (file)
- (if (file-directory-p file) nil
- file))
- (directory-files
- smime-certificate-directory
- 'full)))
- nil)))
+ (let ((files
+ (and (file-directory-p smime-certificate-directory)
+ (delq nil (mapcar (lambda (file)
+ (if (file-directory-p file) nil
+ file))
+ (directory-files
+ smime-certificate-directory
+ 'full))))))
(catch 'found
(while files
(if (or (string-equal
the detached signature of the current region."
(let* ((basename (expand-file-name "smime" temporary-file-directory))
(orig-file (make-temp-name basename))
- (args (list "-qs" signature))
(orig-mode (default-file-modes)))
(unwind-protect
(progn