(rfc2047-allow-irregular-q-encoded-words): New variable.
authorKatsumi Yamaoka <yamaoka@jpl.org>
Tue, 27 Nov 2007 09:33:15 +0000 (09:33 +0000)
committerKatsumi Yamaoka <yamaoka@jpl.org>
Tue, 27 Nov 2007 09:33:15 +0000 (09:33 +0000)
(rfc2047-encodable-p): Use rfc2047-encoded-word-regexp instead of "=?" to look
 for encoded word that should be encoded again.
(rfc2047-encoded-word-regexp): Make B encoding pattern strict.
(rfc2047-encoded-word-regexp-loose): New constant that has loose Q encoding
 pattern.
(rfc2047-decode-region): Switch strict regexp and loose one according to
 rfc2047-allow-irregular-q-encoded-words.

lisp/ChangeLog
lisp/rfc2047.el

index 3ae8b71..692375b 100644 (file)
@@ -1,3 +1,14 @@
+2007-11-27  Katsumi Yamaoka  <yamaoka@jpl.org>
+
+       * rfc2047.el (rfc2047-allow-irregular-q-encoded-words): New variable.
+       (rfc2047-encodable-p): Use rfc2047-encoded-word-regexp instead of "=?"
+       to look for encoded word that should be encoded again.
+       (rfc2047-encoded-word-regexp): Make B encoding pattern strict.
+       (rfc2047-encoded-word-regexp-loose): New constant that has loose Q
+       encoding pattern.
+       (rfc2047-decode-region): Switch strict regexp and loose one according
+       to rfc2047-allow-irregular-q-encoded-words.
+
 2007-11-25  Romain Francoise  <romain@orebokech.com>
 
        * gnus-msg.el (gnus-summary-reply): Delete extra paren.
index 4f63cae..5825e6f 100644 (file)
@@ -99,6 +99,9 @@ quoted-printable and base64 respectively.")
 (defvar rfc2047-encode-encoded-words t
   "Whether encoded words should be encoded again.")
 
+(defvar rfc2047-allow-irregular-q-encoded-words t
+  "*Whether to decode irregular Q-encoded words.")
+
 ;;;
 ;;; Functions for encoding RFC2047 messages
 ;;;
@@ -296,7 +299,7 @@ The buffer may be narrowed."
     (goto-char (point-min))
     (or (and rfc2047-encode-encoded-words
             (prog1
-                (search-forward "=?" nil t)
+                (re-search-forward rfc2047-encoded-word-regexp nil t)
               (goto-char (point-min))))
        (and charsets
             (not (equal charsets (list (car message-posting-charset))))))))
@@ -827,8 +830,15 @@ it, put the following line in your ~/.gnus.el file:
 
 (eval-and-compile
   (defconst rfc2047-encoded-word-regexp
-    "=\\?\\([^][\000-\040()<>@,\;:*\\\"/?.=]+\\)\\(?:\\*[^?]+\\)?\
-\\?\\(B\\|Q\\)\\?\\([!->@-~ ]*\\)\\?="))
+    "=\\?\\([^][\000-\040()<>@,\;:*\\\"/?.=]+\\)\\(?:\\*[^?]+\\)?\\?\
+\\(B\\?[+/0-9A-Za-z]*=*\
+\\|Q\\?[ ->@-~]*\
+\\)\\?=")
+  (defconst rfc2047-encoded-word-regexp-loose
+    "=\\?\\([^][\000-\040()<>@,\;:*\\\"/?.=]+\\)\\(?:\\*[^?]+\\)?\\?\
+\\(B\\?[+/0-9A-Za-z]*=*\
+\\|Q\\?\\(?:\\?+[ -<>@-~]\\)?\\(?:[ ->@-~]+\\?+[ -<>@-~]\\)*[ ->@-~]*\\?*\
+\\)\\?="))
 
 (defvar rfc2047-quote-decoded-words-containing-tspecials nil
   "If non-nil, quote decoded words containing special characters.")
@@ -948,10 +958,12 @@ If ADDRESS-MIME is non-nil, strip backslashes which precede characters
 other than `\"' and `\\' in quoted strings."
   (interactive "r")
   (let ((case-fold-search t)
-       (eword-regexp (eval-when-compile
-                       ;; Ignore whitespace between encoded-words.
-                       (concat "[\n\t ]*\\(" rfc2047-encoded-word-regexp
-                               "\\)")))
+       (eword-regexp
+        (if rfc2047-allow-irregular-q-encoded-words
+            (eval-when-compile
+              (concat "[\n\t ]*\\(" rfc2047-encoded-word-regexp-loose "\\)"))
+          (eval-when-compile
+            (concat "[\n\t ]*\\(" rfc2047-encoded-word-regexp "\\)"))))
        b e match words)
     (save-excursion
       (save-restriction
@@ -967,7 +979,7 @@ other than `\"' and `\\' in quoted strings."
          (while match
            (push (list (match-string 2) ;; charset
                        (char-after (match-beginning 3)) ;; encoding
-                       (match-string 4) ;; encoded-text
+                       (substring (match-string 3) 2) ;; encoded-text
                        (match-string 1)) ;; encoded-word
                  words)
            ;; Look for the subsequent encoded-words.