From: morioka Date: Sat, 31 Oct 1998 17:19:25 +0000 (+0000) Subject: (mime-edit-decode-multipart-in-buffer): Change interface. X-Git-Tag: semi-1_11_0~10 X-Git-Url: http://git.chise.org/gitweb/?a=commitdiff_plain;h=82fe2d7ca58159d0a4fcda7e880d96d6a626e5e4;p=elisp%2Fsemi.git (mime-edit-decode-multipart-in-buffer): Change interface. (mime-edit-decode-single-part-in-buffer): New function. (mime-edit-decode-message-in-buffer): Swap arguments; use function `mime-edit-decode-single-part-in-buffer'. (mime-edit-again): Modify for `mime-edit-decode-message-in-buffer'. --- diff --git a/mime-edit.el b/mime-edit.el index 7210346..72022da 100644 --- a/mime-edit.el +++ b/mime-edit.el @@ -2577,9 +2577,10 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" "\\):") "Regexp for deleted header fields when `mime-edit-again' is called.") -(defun mime-edit-decode-multipart-in-buffer (subtype boundary - &optional not-decode-text) - (let* ((boundary-pat (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))) +(defun mime-edit-decode-multipart-in-buffer (content-type not-decode-text) + (let* ((subtype (mime-content-type-subtype content-type)) + (boundary (mime-content-type-parameter content-type "boundary")) + (boundary-pat (concat "\n--" (regexp-quote boundary) "[ \t]*\n"))) (re-search-forward boundary-pat nil t) (let ((bb (match-beginning 0)) eb tag) (setq tag (format "\n--<<%s>>-{\n" subtype)) @@ -2606,10 +2607,11 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" (save-restriction (narrow-to-region beg end) (mime-edit-decode-message-in-buffer - not-decode-text (if (eq subtype 'digest) (eval-when-compile - (make-mime-content-type 'message 'rfc822)))) + (make-mime-content-type 'message 'rfc822)) + ) + not-decode-text) (goto-char (point-max)) )))) )) @@ -2622,107 +2624,104 @@ Content-Type: message/partial; id=%s; number=%d; total=%d\n%s\n" ))) )) +(defun mime-edit-decode-single-part-in-buffer (content-type not-decode-text) + (let* ((type (mime-content-type-primary-type content-type)) + (subtype (mime-content-type-subtype content-type)) + (ctype (format "%s/%s" type subtype)) + charset + (pstr (let ((bytes (+ 14 (length ctype)))) + (mapconcat (function + (lambda (attr) + (if (string= (car attr) "charset") + (progn + (setq charset (cdr attr)) + "") + (let* ((str (concat (car attr) + "=" (cdr attr))) + (bs (length str))) + (setq bytes (+ bytes bs 2)) + (if (< bytes 76) + (concat "; " str) + (setq bytes (+ bs 1)) + (concat ";\n " str) + ) + )))) + (mime-content-type-parameters content-type) ""))) + encoding + encoded + (limit (save-excursion + (if (search-forward "\n\n" nil t) + (1- (point)))))) + (save-excursion + (if (re-search-forward + "^Content-Transfer-Encoding:" limit t) + (let ((beg (match-beginning 0)) + (hbeg (match-end 0)) + (end (std11-field-end))) + (setq encoding + (downcase + (eliminate-top-spaces + (std11-unfold-string + (buffer-substring hbeg end))))) + (if (or charset (eq type 'text)) + (progn + (delete-region beg (1+ end)) + (goto-char (point-min)) + (if (search-forward "\n\n" nil t) + (progn + (mime-decode-region + (match-end 0)(point-max) encoding) + (setq encoded t + encoding nil) + ))))))) + (if (or encoded (not not-decode-text)) + (decode-mime-charset-region (point-min)(point-max) + (or charset default-mime-charset)) + ) + (let ((he (if (re-search-forward "^$" nil t) + (match-end 0) + (point-min) + ))) + (if (and (eq type 'text) + (eq subtype 'x-rot13-47-48)) + (mule-caesar-region he (point-max)) + ) + (if (= (point-min) 1) + (progn + (goto-char he) + (insert + (concat "\n" + (mime-create-tag + (format "%s/%s%s" type subtype pstr) + encoding))) + ) + (delete-region (point-min) he) + (insert + (mime-create-tag (format "%s/%s%s" type subtype pstr) + encoding)) + )) + )) + ;;;###autoload -(defun mime-edit-decode-message-in-buffer (&optional not-decode-text - default-content-type) +(defun mime-edit-decode-message-in-buffer (&optional default-content-type + not-decode-text) (save-excursion (goto-char (point-min)) (let ((ctl (or (mime-read-Content-Type) default-content-type))) (if ctl - (let ((type (mime-content-type-primary-type ctl)) - (stype (mime-content-type-subtype ctl)) - (params (mime-content-type-parameters ctl))) + (let ((type (mime-content-type-primary-type ctl))) (cond - ((and (eq type 'application)(eq stype 'pgp-signature)) + ((and (eq type 'application) + (eq (mime-content-type-subtype ctl) 'pgp-signature)) (delete-region (point-min)(point-max)) ) ((eq type 'multipart) - (mime-edit-decode-multipart-in-buffer - stype (cdr (assoc "boundary" params)) not-decode-text) + (mime-edit-decode-multipart-in-buffer ctl not-decode-text) ) (t - (let* ((ctype (format "%s/%s" type stype)) - charset - (pstr - (let ((bytes (+ 14 (length ctype)))) - (mapconcat (function - (lambda (attr) - (if (string= (car attr) "charset") - (progn - (setq charset (cdr attr)) - "") - (let* ((str - (concat (car attr) - "=" (cdr attr)) - ) - (bs (length str)) - ) - (setq bytes (+ bytes bs 2)) - (if (< bytes 76) - (concat "; " str) - (setq bytes (+ bs 1)) - (concat ";\n " str) - ) - )))) - params ""))) - encoding - encoded - (limit (save-excursion - (if (search-forward "\n\n" nil t) - (1- (point)))))) - (save-excursion - (if (re-search-forward - "^Content-Transfer-Encoding:" limit t) - (let ((beg (match-beginning 0)) - (hbeg (match-end 0)) - (end (std11-field-end))) - (setq encoding - (downcase - (eliminate-top-spaces - (std11-unfold-string - (buffer-substring hbeg end))))) - (if (or charset (eq type 'text)) - (progn - (delete-region beg (1+ end)) - (goto-char (point-min)) - (if (search-forward "\n\n" nil t) - (progn - (mime-decode-region - (match-end 0)(point-max) encoding) - (setq encoded t - encoding nil) - ))))))) - (if (or encoded (not not-decode-text)) - (decode-mime-charset-region - (point-min)(point-max) - (or charset default-mime-charset)) - ) - (let ((he - (if (re-search-forward "^$" nil t) - (match-end 0) - (point-min) - ))) - (if (and (eq type 'text) - (eq stype 'x-rot13-47-48)) - (mule-caesar-region he (point-max)) - ) - (if (= (point-min) 1) - (progn - (goto-char he) - (insert - (concat "\n" - (mime-create-tag - (format "%s/%s%s" type stype pstr) - encoding))) - ) - (delete-region (point-min) he) - (insert - (mime-create-tag - (format "%s/%s%s" type stype pstr) - encoding)) - )) - )))) + (mime-edit-decode-single-part-in-buffer ctl not-decode-text) + ))) (or not-decode-text (decode-mime-charset-region (point-min) (point-max) default-mime-charset) @@ -2741,7 +2740,7 @@ converted to MIME-Edit tags." nil t) (replace-match "\n\n") ) - (mime-edit-decode-message-in-buffer not-decode-text) + (mime-edit-decode-message-in-buffer nil not-decode-text) (goto-char (point-min)) (save-restriction (std11-narrow-to-header)