From 7a654d17d6dc1fb17c89194488ab3a0bf80a257f Mon Sep 17 00:00:00 2001 From: morioka Date: Tue, 17 Feb 1998 12:29:22 +0000 Subject: [PATCH] (eword-decode-token): New function. (eword-decode-structured-field-body): Add new optional arguments `START-COLUMN' and `MAX-COLUMN'; fill results; use function `eword-decode-token'. (eword-decode-header): Specify START-COLUMN for `eword-decode-structured-field-body'. --- eword-decode.el | 68 ++++++++++++++++++++++++++++++++++++------------------- 1 file changed, 45 insertions(+), 23 deletions(-) diff --git a/eword-decode.el b/eword-decode.el index 60c5621..91195d3 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.4 $ +;; Version: $Revision: 1.5 $ ;; 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.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)) @@ -218,13 +218,14 @@ If SEPARATOR is not nil, it is used as header separator." 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 @@ -234,7 +235,8 @@ 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 body)) + (insert (eword-decode-structured-field-body + body (1+ len))) )) (t ;; Decode as unstructured field @@ -453,7 +455,17 @@ characters encoded as encoded-words or invalid \"raw\" format. 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. @@ -467,22 +479,32 @@ decode the charset included in it, it is not decoded. 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. -- 1.7.10.4