;; Renamed: 1993/06/03 to tiny-mime.el
;; Renamed: 1995/10/03 from tiny-mime.el (split off encoder)
;; Renamed: 1997/02/22 from tm-ew-d.el
-;; Version: $Revision: 1.4 $
+;; Version: $Revision: 1.5 $
;; Keywords: encoded-word, MIME, multilingual, header, mail, news
;; This file is part of SEMI (SEMI is Emacs MIME Interfaces).
;;;
(defconst eword-decode-RCS-ID
- "$Id: eword-decode.el,v 1.4 1998-02-16 21:25:30 morioka Exp $")
+ "$Id: eword-decode.el,v 1.5 1998-02-17 12:29:22 morioka Exp $")
(defconst eword-decode-version (get-version-string eword-decode-RCS-ID))
code-conversion
default-mime-charset))))
(if default-charset
- (let (beg end field-name)
+ (let (beg end field-name len)
(goto-char (point-min))
(while (re-search-forward std11-field-head-regexp nil t)
(setq beg (match-beginning 0)
p (match-end 0)
- field-name (intern
- (downcase (buffer-substring beg (1- p))))
+ field-name (buffer-substring beg (1- p))
+ len (string-width field-name)
+ field-name (intern (downcase field-name))
end (std11-field-end))
(cond ((memq field-name eword-decode-ignored-field-list)
;; Don't decode
(let ((body (buffer-substring p end))
(default-mime-charset default-charset))
(delete-region p end)
- (insert (eword-decode-structured-field-body body))
+ (insert (eword-decode-structured-field-body
+ body (1+ len)))
))
(t
;; Decode as unstructured field
eword-lexical-analyze-cache-max)))
ret)))
-(defun eword-decode-structured-field-body (string &optional must-unfold)
+(defun eword-decode-token (token)
+ (let ((type (car token))
+ (value (cdr token)))
+ (cond ((eq type 'quoted-string)
+ (std11-wrap-as-quoted-string value))
+ ((eq type 'comment)
+ (concat "(" (std11-wrap-as-quoted-pairs value '(?( ?))) ")"))
+ (t value))))
+
+(defun eword-decode-structured-field-body (string &optional must-unfold
+ start-column max-column)
"Decode non us-ascii characters in STRING as structured field body.
STRING is unfolded before decoding.
If MUST-UNFOLD is non-nil, it unfolds and eliminates line-breaks even
if there are in decoded encoded-words (generated by bad manner MUA
such as a version of Net$cape)."
- (mapconcat (function
- (lambda (token)
- (let ((type (car token))
- (value (cdr token)))
- (cond ((eq type 'quoted-string)
- (std11-wrap-as-quoted-string value)
- )
- ((eq type 'comment)
- (concat "("
- (std11-wrap-as-quoted-pairs value '(?( ?)))
- ")")
- )
- (t
- value)))))
- (eword-lexical-analyze string must-unfold)
- ""))
+ (or max-column
+ (setq max-column fill-column))
+ (let ((c (or start-column 6))
+ (tokens (eword-lexical-analyze string must-unfold))
+ (result ""))
+ (while tokens
+ (let* ((token (car tokens))
+ (type (car token)))
+ (setq tokens (cdr tokens))
+ (if (eq type 'spaces)
+ (let* ((next-token (car tokens))
+ (next-str (eword-decode-token next-token))
+ (next-len (string-width next-str))
+ (next-c (+ c next-len 1)))
+ (if (< next-c max-column)
+ (setq result (concat result " " next-str)
+ c next-c)
+ (setq result (concat result "\n " next-str)
+ c (1+ next-len)))
+ (setq tokens (cdr tokens))
+ )
+ (let* ((str (eword-decode-token token)))
+ (setq result (concat result str)
+ c (+ c (string-width str)))
+ ))))
+ result))
(defun eword-decode-unstructured-field-body (string &optional must-unfold)
"Decode non us-ascii characters in STRING as unstructured field body.