;----------------------------------------------------------------------------
; options:
-;encode-sticked-comment-as-atom ; violate policy preventing structure
-;ignore-75bytes-limit ; violate RFC2047
-;ignore-76bytes-limit ; violate RFC2047
-;permit-sticked-comment ; violate RFC2047
-;permit-sticked-special ; violate RFC2047
-;separate-sticked-comment ; violate policy preserving absence of space
-;separate-sticked-special ; violate policy preserving absence of space
-;zero-characters-encoded-word-hack ; violate common sense (very tricky)
-;quoted-encoded-word ; violate character sequence semantics
-
-;;; test driver for FLAM (and FLIM)
-
-(defun decode-flam (src dsts &rest opts)
- (setq eword-lexical-analyze-cache 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)
- (with-temp-buffer
- (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))))
-
-(defun encode-flam (src dsts &rest opts)
- (setq eword-lexical-analyze-cache nil)
- (setq eword-decode-sticked-encoded-word nil)
- (setq eword-decode-quoted-encoded-word nil)
- (with-temp-buffer
- (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))))
+;encode-sticked-comment-as-atom ; violate the policy preserving structures
+;ignore-75bytes-limit ; violate RFC2047
+;ignore-76bytes-limit ; violate RFC2047
+;permit-sticked-comment ; violate RFC2047
+;permit-sticked-special ; violate RFC2047
+;separate-sticked-comment ; violate the policy preserving absence of space
+;separate-sticked-special ; violate the policy preserving absence of space
+;zero-characters-encoded-word-hack ; violate common sense (very tricky)
+;quoted-encoded-word ; violate character sequence semantics
+
+;;; test driver
(setq decode-test 'decode-flam)
(setq encode-test 'encode-flam)
(apply decode-test src dsts opts)
(error nil))))
(if (eq res t)
- (setq decode-succ-count (1+ decode-succ-count))
- (insert (format "\n;fail;%S" res)))
+ (progn
+ (setq decode-succ-count (1+ decode-succ-count))
+ (insert "\n'dsucc"))
+ (insert (format "\n%S\n'dfail" res)))
res))
(setq encode-succ-count 0)
(apply encode-test src dsts opts)
(error nil))))
(if (eq res t)
- (setq encode-succ-count (1+ encode-succ-count))
- (insert (format "\n;fail;%S" res)))
+ (progn
+ (setq encode-succ-count (1+ encode-succ-count))
+ (insert "\n'esucc"))
+ (insert (format "\n%S\n'efail" res)))
res))
(defun report ()
decode-succ-count decode-all-count
encode-succ-count encode-all-count)))
-;;;start-test;;;
+;;; FLAM specific part (FLIM is OK)
+(defun decode-flam (src dsts &rest opts)
+ (setq eword-lexical-analyze-cache 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)
+ (with-temp-buffer
+ (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))))
+
+(defun encode-flam (src dsts &rest opts)
+ (setq eword-lexical-analyze-cache nil)
+ (setq eword-decode-sticked-encoded-word nil)
+ (setq eword-decode-quoted-encoded-word nil)
+ (with-temp-buffer
+ (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))))
+
+;;;start-test;;;
;; Section 1: Decoding examples from RFC2047
"From: Nathaniel Borenstein <nsb@thumper.bellcore.com>
(=?iso-8859-8?b?7eXs+SDv4SDp7Oj08A==?=)"
"From: Nathaniel Borenstein <nsb@thumper.bellcore.com> (\e.H\eNm\eNe\eNl\eNy \eNo\eNa \eNi\eNl\eNh\eNt\eNp)")\e*B
-; FLAM
(decode
"From: foo@bar.baz (=?ISO-8859-1?Q?a?=)"
(decode
"From: < =?ISO-2022-JP?B?GyRCJCIbKEI=?= @jaist.ac.jp>"
"From: < =?ISO-2022-JP?B?GyRCJCIbKEI=?= @jaist.ac.jp>")
-; FLAM
(decode
"From: =?ISO-2022-JP?Q?=1B=24BAA=1B=28B?= <akr@jaist.ac.jp>"
"Subject: =?ISO-2022-JP?B?GyRCJCIbKEI=?=="
"Subject: =?ISO-2022-JP?B?GyRCJCIbKEI=?==")
+(decode
+"From: akr@jaist.ac.jp (\\=?ISO-2022-JP?B?GyRCJCIbKEI=?=)"
+"From: akr@jaist.ac.jp (\\=?ISO-2022-JP?B?GyRCJCIbKEI=?=)")
+
;; Section 3: Decoding melancholy inputs.
(decode
"From:=?ISO-2022-JP?B?GyRCJCIbKEI=?= <akr@jaist.ac.jp>"
"From:=?ISO-2022-JP?B?GyRCJCIbKEI=?= <akr@jaist.ac.jp>")
-; FLAM
(decode
"From: akr@jaist.ac.jp
(=?ISO-2022-JP?B?GyRCJCIbKEI=?=\\a=?ISO-2022-JP?B?GyRCJCQbKEI=?=)"
"From: akr@jaist.ac.jp (\e$B$"\e(B\\a\e$B$$\e(B)")
-; FLAM
(decode
"From: (a)=?ISO-2022-JP?B?GyRCJCIbKEI=?= <akr@jaist.ac.jp>"
"From: akr@jaist.ac.jp
(=?ISO-2022-JP?B?GyRCJCIbKEI=?=a=?ISO-2022-JP?B?GyRCJCQbKEI=?=)"
"From: akr@jaist.ac.jp (=?ISO-2022-JP?B?GyRCJCIbKEI=?=a=?ISO-2022-JP?B?GyRCJCQbKEI=?=)")
-; FLAM
(decode
"From: akr@jaist.ac.jp
(=?ISO-2022-JP?B?GyRCJCIbKEI=?=(=?ISO-2022-JP?B?GyRCJCQbKEI=?=)=?ISO-2022-JP?B?GyRCJCYbKEI=?=)"
"From: akr@jaist.ac.jp (=?ISO-2022-JP?B?GyRCJCIbKEI=?=(=?ISO-2022-JP?B?GyRCJCQbKEI=?=)=?ISO-2022-JP?B?GyRCJCYbKEI=?=)")
-; FLAM
(decode
"From: akr@jaist.ac.jp
(encode
"From: \"\e$B$"\e(B(\e$B$"\e(B)\" <akr@jaist.ac.jp>"
"From: =?ISO-2022-JP?B?GyRCJCIbKEIoGyRCJCIbKEIp?= <akr@jaist.ac.jp>")
-; FLAM
(encode
"From: \"a\\\"b\e$B$"\e(Bc\\\\\" <akr@jaist.ac.jp>"
"From: =?ISO-2022-JP?B?YSJiGyRCJCIbKEJjXA==?= <akr@jaist.ac.jp>")
-; FLAM
(encode
"Subject: \e$B0$\e(B \e$BR_\e(B"
"Subject: =?ISO-2022-JP?B?GyRCMCQbKEIgICAgICAgICAgICAgICAgICAgICAgICAgICAg?=
=?US-ASCII?Q?____________________________________________________________?=
=?ISO-2022-JP?B?ICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgIBskQlJfGyhC?=")
-; FLAM
(encode
"Subject: \e$B0$\e(B \e$BR_\e(B"
"Subject: =?ISO-2022-JP?B?GyQpQrCkICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICAgICDS3w=="
'ignore-76bytes-limit 'ignore-75bytes-limit)
-; FLAM
(encode
"From: \e.A\eN! <akr@jaist.ac.jp>"\e*B
(encode
"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>")
-; FLAM
(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?=)")
-; FLAM
(encode
"Subject: \e$B$"\e(B a \e.H\eN`"\e*B
(encode
"Subject: \e.H\eN`\e$BNm\e(B"\e*B
"Subject: =?ISO-8859-8?Q?=E0?= =?ISO-2022-JP?B?GyRCTm0bKEI=?=")
-; FLAM
(encode
"Subject: \e.H\eN` \e$BNm\e(B"\e*B
"From: akr@jaist.ac.jp
(=?ISO-2022-JP?B?GyRCJCIbKEI=?=(=?ISO-2022-JP?B?GyRCJCQbKEI=?=)=?ISO-2022-JP?B?GyRCJCYbKEI=?=)"
'ignore-76bytes-limit)
-; FLAM
(encode
"From: akr@jaist.ac.jp (\e$B$"\e(B(\e$B$$\e(B)\e$B$&\e(B)"
=?ISO-2022-JP?B?GyhC?=(=?ISO-2022-JP?B?GyRCJCQbKEI=?=
=?ISO-2022-JP?B?GyhC?=)=?ISO-2022-JP?B?GyRCJCYbKEI=?=)"
'zero-characters-encoded-word-hack)
-; FLAM
(encode
"From: \e$B$"\e(B(\e$B$"\e(B) <akr@jaist.ac.jp>"
"From: =?ISO-2022-JP?B?GyRCJCIbKEIoGyRCJCIbKEIp?= <akr@jaist.ac.jp>"
'encode-sticked-comment-as-atom)
-; FLAM
(encode
"From: \e$B$"\e(B(\e$B$"\e(B) <akr@jaist.ac.jp>"
"From: =?ISO-2022-JP?B?GyRCJCIbKEI=?=(=?ISO-2022-JP?B?GyRCJCIbKEI=?=)
<akr@jaist.ac.jp>"
'permit-sticked-comment)
-; FLAM
(encode
"From: \e$B$"\e(B(\e$B$"\e(B) <akr@jaist.ac.jp>"
"From: =?ISO-2022-JP?B?GyRCJCIbKEI=?= (=?ISO-2022-JP?B?GyRCJCIbKEI=?=)
<akr@jaist.ac.jp>"
'separate-sticked-comment)
-; FLAM
(encode
"To: \e$B$"\e(B<akr@jaist.ac.jp>"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?=<akr@jaist.ac.jp>"
'permit-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B<akr@jaist.ac.jp>"
"To: <akr@jaist.ac.jp>,\e$B$"\e(B<akr@jaist.ac.jp>"
"To: <akr@jaist.ac.jp>,=?ISO-2022-JP?B?GyRCJCIbKEI=?=<akr@jaist.ac.jp>"
'permit-sticked-special)
-; FLAM
(encode
"To: <akr@jaist.ac.jp>,\e$B$"\e(B<akr@jaist.ac.jp>"
"To: akr@jaist.ac.jp,\e$B$"\e(B<akr@jaist.ac.jp>"
"To: akr@jaist.ac.jp,=?ISO-2022-JP?B?GyRCJCIbKEI=?=<akr@jaist.ac.jp>"
'permit-sticked-special)
-; FLAM
(encode
"To: akr@jaist.ac.jp,\e$B$"\e(B<akr@jaist.ac.jp>"
"To: \e$B$"\e(B:akr@jaist.ac.jp;"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?=:akr@jaist.ac.jp;"
'permit-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:akr@jaist.ac.jp;"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?= :akr@jaist.ac.jp;"
'separate-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:\e$B$$\e(B<akr@jaist.ac.jp>;"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?=:=?ISO-2022-JP?B?GyRCJCQbKEI=?=<akr@jaist.ac.jp>;"
'ignore-76bytes-limit 'permit-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:\e$B$$\e(B<akr@jaist.ac.jp>;"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?=:=?ISO-2022-JP?B?GyRCJCQbKEI=?=
=?ISO-2022-JP?B?GyhC?=<akr@jaist.ac.jp>;"
'zero-characters-encoded-word-hack 'permit-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:\e$B$$\e(B<akr@jaist.ac.jp>;"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?= : =?ISO-2022-JP?B?GyRCJCQbKEI=?=
<akr@jaist.ac.jp>;"
'separate-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:\e$B$$\e(B<foo@bar>,\e$B$&\e(B<foo@bar>;,\e$B$(\e(B<foo@bar>"
"To: =?ISO-2022-JP?B?GyRCJCIbKEI=?=:=?ISO-2022-JP?B?GyRCJCQbKEI=?=<foo@bar>,=?ISO-2022-JP?B?GyRCJCYbKEI=?=<foo@bar>;,=?ISO-2022-JP?B?GyRCJCgbKEI=?=<foo@bar>"
'ignore-76bytes-limit 'permit-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:\e$B$$\e(B<foo@bar>,\e$B$&\e(B<foo@bar>;,\e$B$(\e(B<foo@bar>"
=?ISO-2022-JP?B?GyhC?=<foo@bar>,=?ISO-2022-JP?B?GyRCJCYbKEI=?=
=?ISO-2022-JP?B?GyhC?=<foo@bar>;,=?ISO-2022-JP?B?GyRCJCgbKEI=?=<foo@bar>"
'zero-characters-encoded-word-hack 'permit-sticked-special)
-; FLAM
(encode
"To: \e$B$"\e(B:\e$B$$\e(B<foo@bar>,\e$B$&\e(B<foo@bar>;,\e$B$(\e(B<foo@bar>"
<foo@bar>, =?ISO-2022-JP?B?GyRCJCYbKEI=?= <foo@bar>;,
=?ISO-2022-JP?B?GyRCJCgbKEI=?= <foo@bar>"
'separate-sticked-special)
-; FLAM
;; Section 7: Using quoted-encoded-words.
;
; \e$B%^%C%A$7$J$$ItJ,$O$=$NItJ,$N$^$^$NFbMF$rI=$9!#\e(B
;
; rule 2: \e$BJ8;zNsCf$G\e(B =?charset?encoding?text?= \e$B$H$$$&%Q%?!<%s$K\e(B
-; \e$B%^%C%A$9$kItJ,$O\e(B charset \e$B$N@hF,$K\e(B '*' \e$B$,$$$/$DIU$$$F$$$k$+$GFbMF$N\e(B
+; \e$B%^%C%A$9$kItJ,$O\e(B charset \e$B$N@hF,$K\e(B * \e$B$,$$$/$DIU$$$F$$$k$+$GFbMF$N\e(B
; \e$B2r<a$rJQ$($k!#\e(B
;
-; \e$B6v?t$N>l9g\e(B(0, 2, 4, ...): charset \e$B$N@hF,$N\e(B '*' \e$B$N?t$rH>J,$K$7$?J8;zNs\e(B
-; \e$B4q?t$N>l9g\e(B(1, 3, 5, ...): charset \e$B$N@hF,$N\e(B '*' \e$B$N?t$rH>J,\e(B(\e$B>.?tE@0J2<\e(B
+; \e$B6v?t$N>l9g\e(B(0, 2, 4, ...): charset \e$B$N@hF,$N\e(B * \e$B$N?t$rH>J,$K$7$?J8;zNs\e(B
+; \e$B4q?t$N>l9g\e(B(1, 3, 5, ...): charset \e$B$N@hF,$N\e(B * \e$B$N?t$rH>J,\e(B(\e$B>.?tE@0J2<\e(B
; \e$B@Z<N$F\e(B)\e$B$K$7$F!"$=$l$r\e(B encoded-word \e$B$H;W$C$F%G%3!<%I$7$?J8;zNs!#\e(B
;
-; NOTE: '*' \e$B$r\e(B quoted-encoded-word \e$BI=8=$N\e(B quote \e$BJ8;z$H8F$V!#\e(B
+; NOTE: * \e$B$r\e(B quoted-encoded-word \e$BI=8=$N\e(B quote \e$BJ8;z$H8F$V!#\e(B
;
-; NOTE: \e$B8=;~E@\e(B(1998/07/19)\e$B$G\e(B IANA \e$B$N%l%8%9%H%j$K$O\e(B '*' \e$B$r4^$`\e(B charset \e$B$O\e(B
+; NOTE: \e$B8=;~E@\e(B(1998/07/19)\e$B$G\e(B IANA \e$B$K$O\e(B * \e$B$r4^$`\e(B charset \e$B$O\e(B
; \e$BEPO?$5$l$F$$$J$$$N$G!"$=$l$i$N\e(B charset \e$B$r;H$C$?\e(B
-; encoded-word \e$B$rI=8=$9$k$K$O\e(B '*' \e$B$r\e(B 1\e$B$D$D$1$k$3$H$K$J$k!#\e(B
+; encoded-word \e$B$rI=8=$9$k$K$O\e(B * \e$B$r\e(B 1\e$B$D$D$1$k$3$H$K$J$k!#\e(B
;
; =?US-ASCII?Q?abcdef?= \e$B$H$$$&\e(Bencoded-word : =?*US-ASCII?Q?abcdef?=
;
; =?US-ASCII*?Q?abcdef?= \e$B$H$$$&J8;zNs\e(B : =?US-ASCII*?Q?abcdef?=
; =?U*S-ASCII?Q?abcdef?= \e$B$H$$$&J8;zNs\e(B : =?U*S-ASCII?Q?abcdef?=
;
-; NOTE: encoded-word \e$B$K8+$($kJ8;zNs$G\e(B '*' \e$B$,G\A}$5$l$k$N$O\e(B charset \e$B$N\e(B
-; \e$B@hF,$@$1$G$"$j!"\e(Bencoding \e$B$d\e(B encoded-text \e$B$O$?$H$(\e(B '*' \e$B$,F~$C$F$$$F$b\e(B
-; \e$BJQ2=$7$J$$!#$^$?!"\e(Bcharset \e$BCf$G$b\e(B \e$B@hF,0J30$N\e(B '*' \e$B$OJQ2=$7$J$$!#\e(B
+; NOTE: encoded-word \e$B$K8+$($kJ8;zNs$G\e(B * \e$B$,G\A}$5$l$k$N$O\e(B charset \e$B$N\e(B
+; \e$B@hF,$@$1$G$"$j!"\e(Bencoding \e$B$d\e(B encoded-text \e$B$O$?$H$(\e(B * \e$B$,F~$C$F$$$F$b\e(B
+; \e$BJQ2=$7$J$$!#$^$?!"\e(Bcharset \e$BCf$G$b\e(B \e$B@hF,0J30$N\e(B * \e$B$OJQ2=$7$J$$!#\e(B
;
; rule 3: \e$BJ8;zNsA4BN$NFbMF$O!"\e(Brule 1 \e$B$H\e(B rule 2 \e$B$G2r<a$7$?3FItJ,$N\e(B
; \e$BJ8;zNs$rC1=c$KO"7k$7$?J8;zNs$H$9$k!#\e(B
"Subject: =?Unknown-Charset?B?gqA=?="
"Subject: =?*Unknown-Charset?B?gqA=?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?US-ASCII?G?H4sIAMsIsjUCA0tMSk5JTQMA7zmOSwYAAAA?="
"Subject: =?*US-ASCII?G?H4sIAMsIsjUCA0tMSk5JTQMA7zmOSwYAAAA?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?US-ASCII?Unknown-Encoding?H4sIAMsIsjUCA0tMSk5JTQMA7zmOSwYAAAA?="
"Subject: =?*US-ASCII?Unknown-Encoding?H4sIAMsIsjUCA0tMSk5JTQMA7zmOSwYAAAA?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?Unknown-Charset?B?gqA=?= =?Unknown-Charset?B?gqA=?="
"Subject: =?*Unknown-Charset?B?gqA=?==?*Unknown-Charset?B?gqA=?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?Unknown-Charset?B?gqA=?= =?Unknown-Charset?B?gqA=?="
"Subject: =?*Unknown-Charset?B?gqA=?==?*Unknown-Charset?B?gqA=?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?Unknown-Charset?B?gqA=?=
=?Unknown-Charset?B?gqA=?="
"Subject: =?*Unknown-Charset?B?gqA=?==?*Unknown-Charset?B?gqA=?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?Unknown-Charset?B?gqA=?=
=?Unknown-Charset?B?gqA=?="
"Subject: =?*Unknown-Charset?B?gqA=?==?*Unknown-Charset?B?gqA=?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: a=?Unknown-Charset?B?gqA=?="
"Subject: a =?Unknown-Charset?B?gqA=?= b"
"Subject: a =?*Unknown-Charset?B?gqA=?= b"
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?ISO-2022-JP?B?DQoNCg==?="
"Subject: =?*US-ASCII?Q?=0D=0A=0D=0A?="
'quoted-encoded-word)
-; FLAM
(decode
"Subject: =?US-ASCII?Q?a=0D=0A_b?="
"Subject: a=?*US-ASCII?Q?=0D=0A?= b"
'quoted-encoded-word)
-; FLAM
+
+(decode
+"Subject: =?US-ASCII?Q?a=0D=0Ab?="
+"Subject: a=?*US-ASCII?Q?=0D=0A?=b"
+'quoted-encoded-word)
;;;end-test;;;