* Sync up to flim-1_11_2 from flim-1_11_0.
[elisp/flim.git] / eword-decode.el
index f176a48..67c02e6 100644 (file)
@@ -476,6 +476,39 @@ Each field name must be symbol."
   :group 'eword-decode
   :type '(repeat symbol))
 
+(defun eword-decode-field-body
+  (field-body field-name &optional unfolded max-column)
+  "Decode FIELD-BODY as FIELD-NAME, and return the result.
+
+If UNFOLDED is non-nil, it is assumed that FIELD-BODY is
+already unfolded.
+
+If MAX-COLUMN is non-nil, the result is folded with MAX-COLUMN
+or `fill-column' if MAX-COLUMN is t.
+Otherwise, the result is unfolded.
+
+MIME encoded-word in FIELD-BODY is recognized according to
+`eword-decode-ignored-field-list',
+`eword-decode-structured-field-list' and FIELD-NAME.
+
+Non MIME encoded-word part in FILED-BODY is decoded with
+`default-mime-charset'."
+  (if (symbolp field-name) (setq field-name (symbol-name field-name)))
+  (let ((decoded
+          (if unfolded
+            (let ((ew-ignore-76bytes-limit t))
+              (ew-decode-field
+               field-name (ew-lf-crlf-to-crlf field-body)))
+            (ew-decode-field
+             field-name (ew-lf-crlf-to-crlf field-body)))))
+    (if max-column
+        (setq decoded (ew-crlf-refold
+                       decoded
+                       (1+ (string-width field-name))
+                       (if (eq max-column t) fill-column max-column)))
+      (setq decoded (ew-crlf-unfold decoded)))
+    (ew-crlf-to-lf decoded)))
+
 (defun eword-decode-header (&optional code-conversion separator)
   "Decode MIME encoded-words in header fields.
 If CODE-CONVERSION is nil, it decodes only encoded-words.  If it is