From 0cf8a7c05cdd7638014feb264f50ac0be807aa15 Mon Sep 17 00:00:00 2001 From: morioka Date: Tue, 17 Feb 1998 13:01:10 +0000 Subject: [PATCH] (eword-decode-and-fold-structured-field): New function. (eword-decode-structured-field-body): Use it. (eword-decode-header): Likewise. --- eword-decode.el | 76 ++++++++++++++++++++++++++++++++++--------------------- 1 file changed, 47 insertions(+), 29 deletions(-) diff --git a/eword-decode.el b/eword-decode.el index f984684..68d2b18 100644 --- a/eword-decode.el +++ b/eword-decode.el @@ -10,7 +10,7 @@ ;; 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). @@ -45,7 +45,7 @@ ;;; (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)) @@ -235,7 +235,7 @@ If SEPARATOR is not nil, it is used as header separator." (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 @@ -464,6 +464,48 @@ characters encoded as encoded-words or invalid \"raw\" format. (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. @@ -481,32 +523,8 @@ if there are in decoded encoded-words (generated by bad manner MUA 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) -- 1.7.10.4