* (TESTPAT): add test.
authorakr <akr>
Sat, 18 Jul 1998 20:34:12 +0000 (20:34 +0000)
committerakr <akr>
Sat, 18 Jul 1998 20:34:12 +0000 (20:34 +0000)
* eword-decode.el (eword-analyze-quoted-string): quote string as quoted-string.
(eword-analyze-encoded-word): quote non-atoms string as quoted-string.

ChangeLog
TESTPAT
eword-decode.el

index bb3e050..059c0f9 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,14 @@
 1998-07-18  Tanaka Akira  <akr@jaist.ac.jp>
 
+       * (TESTPAT): add test.
+
+       * eword-decode.el (eword-analyze-quoted-string): quote string as
+       quoted-string.
+       (eword-analyze-encoded-word): quote non-atoms string as
+       quoted-string.
+
+1998-07-18  Tanaka Akira  <akr@jaist.ac.jp>
+
        * Fix character code for ChangeLog.
 
 1998-07-18  Tanaka Akira  <akr@jaist.ac.jp>
diff --git a/TESTPAT b/TESTPAT
index 7b7402c..82f0605 100644 (file)
--- a/TESTPAT
+++ b/TESTPAT
@@ -1,5 +1,5 @@
 ;----------------------------------------------------------------------------
-;-------- This sequece of hyphens is 76 bytes long. -------------------------
+;-------- This sequece of HYPHEN-MINUS is 76 bytes long. --------------------
 ;----------------------------------------------------------------------------
 
 ; options:
 
 (defun decode (src dsts &rest opts)
   (setq eword-lexical-analyze-cache nil)
-  (setq eword-decode-sticked-encoded-word nil)
+  (setq eword-decode-sticked-encoded-word
+    (or (memq 'permit-sticked-comment opts)
+       (memq 'permit-sticked-special opts)))
   (setq eword-decode-quoted-encoded-word nil)
-  (if (memq 'permit-sticked-comment opts) (setq eword-decode-sticked-encoded-word t))
   (if (stringp dsts) (setq dsts (list dsts)))
   (with-temp-buffer
-    (insert src "\nDummy-Header: \n" mail-header-separator)
-    (eword-decode-header 'us-ascii)
+    (insert src "\n" mail-header-separator)
+    (eword-decode-header 'us-ascii mail-header-separator)
     (goto-char (point-min))
+    (std11-narrow-to-header mail-header-separator)
     (std11-field-end)
     (let ((result (buffer-substring (point-min) (point))))
-      (if (member result dsts)
-         t
-       result))))
+      (if (member result dsts) t result))))
 
 (defun encode (src dsts &rest opts)
+  (setq eword-lexical-analyze-cache nil)
+  (setq eword-decode-sticked-encoded-word nil)
+  (setq eword-decode-quoted-encoded-word nil)
   (if (stringp dsts) (setq dsts (list dsts)))
   (with-temp-buffer
-    (insert src "\nDummy-Header: \n" mail-header-separator)
+    (insert src "\n" mail-header-separator)
     (goto-char (point-min))
     (eword-encode-header 'us-ascii)
     (goto-char (point-min))
+    (std11-narrow-to-header mail-header-separator)
     (std11-field-end)
     (let ((result (buffer-substring (point-min) (point))))
-      (if (member result dsts)
-         t
-       result))))
+      (if (member result dsts) t result))))
 
 ;;; from RFC2047
 
 'permit-sticked-comment)
 
 (decode
-"From: =?ISO-2022-JP?B?YSJiGyRCJCIbKEJjXAo=?= <akr@jaist.ac.jp>"
-"From: \"a\"b\e$B$"\e(Bc\\\" <akr@jaist.ac.jp>")
+"From: =?US-ASCII?Q?=28?= <akr@jaist.ac.jp>, =?US-ASCII?Q?=29?= <akr@jaist.ac.jp>"
+"From: \"(\" <akr@jaist.ac.jp>, \")\" <akr@jaist.ac.jp>")
+
+(decode
+"From: =?ISO-2022-JP?B?YSJiGyRCJCIbKEJjXA==?= <akr@jaist.ac.jp>"
+"From: \"a\\\"b\e$B$"\e(Bc\\\\\" <akr@jaist.ac.jp>")
 
 (encode
-"From: "a\"b\e$B$"\e(B\\" <akr@jaist.ac.jp>"
-"From: =?ISO-2022-JP?B?YSJiGyRCJCIbKEJjXAo=?= <akr@jaist.ac.jp>")
+"From: \"a\\\"b\e$B$"\e(Bc\\\\\" <akr@jaist.ac.jp>"
+"From: =?ISO-2022-JP?B?YSJiGyRCJCIbKEJjXA==?= <akr@jaist.ac.jp>")
 
 (decode
 "To: =?ISO-2022-JP?B?GyRCJCIbKEI=?=<akr@jaist.ac.jp>"
 "Subject: =?ISO-2022-JP?B?DQoNCg==?="
 "Subject: ")
 
+(decode
+"Subject: =?US-ASCII?Q?a=0D=0A_b?="
+"Subject: a b")
+
+(decode
+"Subject: =?ISO-2022-JP?B?GyRCJCIbKEI=?= a
+ =?ISO-2022-JP?B?GyRCJCQbKEI=?="
+"From: \e$B$"\e(B a \e$B$$\e(B")
+
 (encode
 "Subject: \e$B0$\e(B                                                                                                                          \e$BR_\e(B"
 "Subject: =?ISO-2022-JP?B?GyRCMCQbKEIgICAgICAgICAgICAgICAgICAgICAgICAgICAg?=
 "From: \e.A\eN! <akr@jaist.ac.jp>"\e*B
 "From: =?ISO-8859-1?Q?=A1?= <akr@jaist.ac.jp>")
 
+(decode
+"From: =?ISO-8859-1?Q?abcdefghijklmnopqrst=A1=28=29=22=5C?= <akr@jaist.ac.jp>"
+"From: \"abcdefghijklmnopqrst\e.A\eN!()\\\"\\\\\" <akr@jaist.ac.jp>")\e*B
+
 (encode
-"From: \"abcdefghijklmnopqrstu\e.A\eN!()\\\"\\\\\" <akr@jaist.ac.jp>"\e*B
+"From: \"abcdefghijklmnopqrst\e.A\eN!()\\\"\\\\\" <akr@jaist.ac.jp>"\e*B
 "From: =?ISO-8859-1?Q?abcdefghijklmnopqrst=A1=28=29=22=5C?= <akr@jaist.ac.jp>")
 
 (encode
 "From: akr@jaist.ac.jp (abcdefghijklmnopqrst\e.A\eN!\\(\\)\"\\\\)"\e*B
 "From: akr@jaist.ac.jp (=?ISO-8859-1?Q?abcdefghijklmnopqrst=A1=28=29\"=5C?=)")
 
+(decode
+"Subject: ?= =?"
+"Subject: ?= =?")
+
+(decode
+"Subject: \" =?ISO-2022-JP?B?GyRCJCIbKEI=?= \""
+"Subject: \" \e$B$"\e(B \"")
+
+(decode
+"From: \"\\\\\" =?ISO-2022-JP?B?GyRCJCIbKEI=?= \"\" <akr@jaist.ac.jp>"
+"From: \"\\\\\" \e$B$"\e(B \"\" <akr@jaist.ac.jp>")
+
+(decode
+"Subject: =?ISO-2022-JP?Q?=1B$B$\"=1B(B_=1B$B$\"=1B(B?="
+"Subject: \e$B$"\e(B \e$B$"\e(B")
+
+(decode
+"Subject: =?ISO-2022-JP?Q?=1B$B$\"=1B(B =1B$B$\"=1B(B?="
+"Subject: =?ISO-2022-JP?Q?=1B$B$\"=1B(B =1B$B$\"=1B(B?=")
+
+(decode
+"Subject: =?ISO-2022-JP?B?GyRCJCIbKEI=?= a =?ISO-8859-8?Q?=E0?="
+"Subject: \e$B$"\e(B a \e.H\eN`")\e*B
+
+(encode
+"Subject: \e$B$"\e(B a \e.H\eN`"\e*B
+"Subject: =?ISO-2022-JP?B?GyRCJCIbKEI=?= a =?ISO-8859-8?Q?=E0?=")
+
+(decode
+"Subject: =?ISO-8859-8?Q?=E0?= =?ISO-2022-JP?B?GyRCTm0bKEI=?="
+"Subject: \e.H\eN`\e$BNm\e(B")\e*B
+
+(encode
+"Subject: \e.H\eN`\e$BNm\e(B"\e*B
+"Subject: =?ISO-8859-8?Q?=E0?= =?ISO-2022-JP?B?GyRCTm0bKEI=?=")
+
+(decode
+"Subject: =?ISO-8859-8?Q?=E0_?= =?ISO-2022-JP?B?GyRCTm0bKEI=?="
+"Subject: \e.H\eN` \e$BNm\e(B")\e*B
+
+(encode
+"Subject: \e.H\eN` \e$BNm\e(B"\e*B
+'("Subject: =?ISO-8859-8?Q?=E0_?= =?ISO-2022-JP?B?GyRCTm0bKEI=?="
+  "Subject: =?ISO-8859-8?Q?=E0?= =?ISO-2022-JP?B?IBskQk5tGyhC?="))
+
+(encode
+"Subject: \e.F\eNC\e$B4X?t\e(B"\e*B
+'("Subject: =?ISO-8859-7?Q?=C3?= =?ISO-2022-JP?B?GyRCNFg/dBsoQg==?="
+  "Subject: =?ISO-2022-JP-2?B?Gy5GG05DGyRCNFg/dBsoQg==?="))
+
+(decode
+"Subject: =?ISO-2022-JP-2?B?Gy5GG05DGyRCNFg/dBsoQg==?="
+"Subject: \e.F\eNC\e$B4X?t\e(B")\e*B
+
+(decode
+"Subject: =?ISO-8859-7?Q?=C3?= =?ISO-2022-JP?B?GyRCNFg/dBsoQg==?="
+"Subject: \e.F\eNC\e$B4X?t\e(B")\e*B
+
 ;----------------------------------------------------------------------------
index fa07ab1..c8a4a0f 100644 (file)
@@ -575,16 +575,18 @@ be the result."
 (defun eword-analyze-quoted-string (string &optional must-unfold)
   (let ((p (std11-check-enclosure string ?\" ?\")))
     (if p
-       (cons (cons 'quoted-string
-                   (if eword-decode-quoted-encoded-word
-                       (eword-decode-quoted-string
-                        (substring string 0 p)
-                        default-mime-charset)
-                     (decode-mime-charset-string
-                      (std11-strip-quoted-pair (substring string 0 p))
-                      default-mime-charset)))
-             (substring string p)))
-      ))
+        (cons (cons 'quoted-string
+                    (if eword-decode-quoted-encoded-word
+                        (std11-wrap-as-quoted-string
+                         (eword-decode-quoted-string
+                          (substring string 1 (1- p))
+                          default-mime-charset))
+                      (std11-wrap-as-quoted-string
+                       (decode-mime-charset-string
+                        (std11-strip-quoted-pair (substring string 1 (1- p)))
+                        default-mime-charset))))
+              (substring string p)))
+    ))
 
 (defun eword-analyze-domain-literal (string &optional must-unfold)
   (std11-analyze-domain-literal string))
@@ -611,12 +613,20 @@ be the result."
 
 (defun eword-analyze-encoded-word (string &optional must-unfold)
   (let ((decoded (eword-decode-first-encoded-words
-                  string
-                  eword-encoded-word-in-phrase-regexp
-                  eword-after-encoded-word-in-phrase-regexp
-                  must-unfold)))
+                  string
+                  eword-encoded-word-in-phrase-regexp
+                  eword-after-encoded-word-in-phrase-regexp
+                  must-unfold)))
     (if decoded
-      (cons (cons 'atom (car decoded)) (cdr decoded)))))
+        (let ((s (car decoded)))
+          (while (or (string-match std11-atom-regexp s)
+                     (string-match std11-spaces-regexp s))
+            (setq s (substring s (match-end 0))))
+          (if (= (length s) 0)
+              (cons (cons 'atom (car decoded)) (cdr decoded))
+            (cons (cons 'quoted-string
+                        (std11-wrap-as-quoted-string (car decoded)))
+                  (cdr decoded)))))))
 
 (defun eword-analyze-atom (string &optional must-unfold)
   (if (let ((enable-multibyte-characters nil))