* Sync up to flim-1_12_5 from flim-1_12_1.
[elisp/flim.git] / ew-dec.el
index 7811387..d958195 100644 (file)
--- a/ew-dec.el
+++ b/ew-dec.el
@@ -26,7 +26,7 @@ each line is separated by CRLF."
         (tmp (assoc key ew-decode-field-cache-buf)))
     (if tmp
        (cdr tmp)
-      (progn
+      (let ((decoded (ew-decode-field-no-cache field-name field-body)))
        (setq tmp (nthcdr ew-decode-field-cache-num
                          ew-decode-field-cache-buf))
        (if (cdr tmp)
@@ -38,9 +38,7 @@ each line is separated by CRLF."
                (cons (cons nil nil)
                      ew-decode-field-cache-buf)))
        (setcar (car ew-decode-field-cache-buf) key)
-       (setcdr (car ew-decode-field-cache-buf)
-               (ew-decode-field-no-cache
-                field-name field-body))
+       (setcdr (car ew-decode-field-cache-buf) decoded)
        (cdar ew-decode-field-cache-buf)))))
 
 (defun ew-analyze-field-to-decode (field-name field-body)
@@ -461,6 +459,43 @@ each line is separated by CRLF."
   (not (eq (charsets-to-mime-charset (find-charset-string str)) 'us-ascii)))
 
 ;;;
+
+(defun ew-decode-field-interest-option-order (field-name field-body)
+  (let* ((ew-decode-sticked-encoded-word nil)
+        (ew-decode-quoted-encoded-word nil)
+        (ew-ignore-75bytes-limit nil)
+        (ew-ignore-76bytes-limit nil)
+        (ew-permit-sticked-comment nil)
+        (ew-permit-sticked-special nil)
+        (ew-permit-null-encoded-text nil)
+        (decoded (make-vector (lsh 1 (length ew-option-list)) nil))
+        tmp
+        i j k
+        )
+    (aset decoded 0 (list 0 (ew-decode-field field-name field-body)))
+    (setq i 1)
+    (while (< i (length decoded))
+      (ew-restore-boolean-options i)
+      (setq tmp (ew-decode-field field-name field-body))
+      (setq j 0)
+      (while (<= (lsh 1 j) i)
+       (unless (zerop (logand i (lsh 1 j)))
+         (setq k (logand i (lognot (lsh 1 j))))
+         (when (or (not (aref decoded i))
+                   (< (car (aref decoded i))
+                      (+ (if (equal (cadr (aref decoded k)) tmp) 0 1)
+                         (car (aref decoded k)))))
+           (aset decoded i
+                 (ew-cons*
+                  (+ (if (equal (cadr (aref decoded k)) tmp) 0 1)
+                     (car (aref decoded k)))
+                  tmp
+                  (nth j ew-option-list)
+                  (cddr (aref decoded k))))))
+       (setq j (1+ j)))
+      (setq i (1+ i)))
+    (reverse (cddr (aref decoded (1- (length decoded)))))))
+
 (defun ew-decode-field-test (field-name field-body)
   (interactive
    (list
@@ -496,11 +531,13 @@ each line is separated by CRLF."
               ew-ignore-75bytes-limit
               ew-permit-sticked-special
               ew-permit-sticked-comment
-              ew-permit-null-encoded-text
               ew-decode-sticked-encoded-word
               ew-decode-quoted-encoded-word
+              ew-permit-null-encoded-text
               ))
            d1 d2)
+       (when (<= 16 (prefix-numeric-value current-prefix-arg))
+         (setq options (ew-decode-field-interest-option-order field-name field-body)))
        (setq d1 (ew-decode-field-no-cache field-name field-body))
        (insert field-name ":" field-body "\n"
                (make-string 76 ?-) "\n"
@@ -514,11 +551,11 @@ each line is separated by CRLF."
            (setq d1 d2))
          (setq options (cdr options)))
        (insert (make-string 76 ?-) "\n")
-       (when current-prefix-arg
+       (when (<= 4 (prefix-numeric-value current-prefix-arg))
          (mapcar
           (lambda (frag)
-            (insert (format "%-16s %S\n"
-                            (get frag 'type)
+            (insert (format "%-15s %S\n"
+                            (substring (symbol-name (get frag 'type)) 3)
                             (symbol-name frag)))
             nil)
           (ew-frag-list (ew-analyze-field-to-decode field-name field-body)))
@@ -544,4 +581,16 @@ each line is separated by CRLF."
 (ew-decode-field "To" "\"A\\BC\" <foo@bar>")
 (ew-decode-field "To" "\"\e\\$\\B\\$\\\"\e\\(\\B\" <foo@bar>")
 
+(ew-decode-field-test "Subject" " =?US-ASCII?Q??=?US-ASCII?Q?a?=")
+(ew-decode-field-test "Subject" " =?xUS-ASCII?Q??=?xUS-ASCII?Q?a?=")
+(ew-decode-field-test "Subject" " =?+US-ASCII?Q??=?+US-ASCII?Q?a?=")
+
+(ew-decode-field "From"" ()=?+US-ASCII?Q??=?+US-ASCII?Q?a?= =?US-ASCII?Q??= <akr@foo> (aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa)")
+
+(let ((ew-default-mime-charset 'iso-2022-jp-2))
+  (ew-decode-field-no-cache
+     "From" "\"Cl\351ment Brousset\" <cbrousset@staffandline.com>"))
+
+(ew-decode-field-no-cache "From" " \"Jacek \\\"Jaytee\\\" Szyd\263owski\" <jaytee@friko.onet.pl>")
+
 )