;; 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.6 $
+;; Version: $Revision: 1.7 $
;; 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.6 1998-02-17 12:48:20 morioka Exp $")
+ "$Id: eword-decode.el,v 1.7 1998-02-17 13:01:10 morioka Exp $")
(defconst eword-decode-version (get-version-string eword-decode-RCS-ID))
(let ((body (buffer-substring p end))
(default-mime-charset default-charset))
(delete-region p end)
- (insert (eword-decode-structured-field-body
+ (insert (eword-decode-and-fold-structured-field
body (1+ len)))
))
(t
(concat "(" (std11-wrap-as-quoted-pairs value '(?( ?))) ")"))
(t value))))
+(defun eword-decode-and-fold-structured-field
+ (string start-column &optional max-column must-unfold)
+ "Decode and fold (fill) STRING as structured field body.
+It decodes non us-ascii characters in FULL-NAME encoded as
+encoded-words or invalid \"raw\" string. \"Raw\" non us-ascii
+characters are regarded as variable `default-mime-charset'.
+
+If an encoded-word is broken or your emacs implementation can not
+decode the charset included in it, it is not decoded.
+
+If MAX-COLUMN is omitted, `fill-column' is used.
+
+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)."
+ (or max-column
+ (setq max-column fill-column))
+ (let ((c start-column)
+ (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-structured-field-body (string &optional must-unfold
start-column max-column)
"Decode non us-ascii characters in STRING as structured field body.
such as a version of Net$cape)."
(if start-column
;; fold with max-column
- (let ((c start-column)
- (tokens (eword-lexical-analyze string must-unfold))
- (result ""))
- (or max-column
- (setq max-column fill-column))
- (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)
+ (eword-decode-and-fold-structured-field
+ string start-column max-column must-unfold)
;; Don't fold
(mapconcat (function eword-decode-token)
(eword-lexical-analyze string must-unfold)