(gnus-cache-generate-active): Fix bug in
[gnus] / lisp / rfc2047.el
index c5605a0..5955524 100644 (file)
@@ -71,8 +71,8 @@ Value is what BODY returns."
   '(("Newsgroups" . nil)
     ("Followup-To" . nil)
     ("Message-ID" . nil)
-    ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|Reply-To\\|Sender\\)" .
-     address-mime)
+    ("\\(Resent-\\)?\\(From\\|Cc\\|To\\|Bcc\\|Reply-To\\|Sender\
+\\|Mail-Followup-To\\|Mail-Copies-To\\)" . address-mime)
     (t . mime))
   "*Header/encoding method alist.
 The list is traversed sequentially.  The keys can either be
@@ -133,9 +133,7 @@ quoted-printable and base64 respectively.")
    (progn
      (forward-line 1)
      (if (re-search-forward "^[^ \n\t]" nil t)
-        (progn
-          (beginning-of-line)
-          (point))
+        (rfc2047-point-at-bol)
        (point-max))))
   (goto-char (point-min)))
 
@@ -290,13 +288,23 @@ Dynamically bind `rfc2047-encoding-type' to change that."
   (save-restriction
     (narrow-to-region b e)
     (if (eq 'mime rfc2047-encoding-type)
-       ;; Simple case -- treat as single word.
+       ;; Simple case.  Treat as single word after any initial ASCII
+       ;; part and before any tailing ASCII part.  The leading ASCII
+       ;; is relevant for instance in Subject headers with `Re:' for
+       ;; interoperability with non-MIME clients, and we might as
+       ;; well avoid the tail too.
        (progn
          (goto-char (point-min))
          ;; Does it need encoding?
-         (skip-chars-forward "\000-\177" e)
+         (skip-chars-forward "\000-\177")
          (unless (eobp)
-           (rfc2047-encode b e)))
+           (skip-chars-backward "^ \n") ; beginning of space-delimited word
+           (rfc2047-encode (point) (progn
+                                     (goto-char e)
+                                     (skip-chars-backward "\000-\177")
+                                     (skip-chars-forward "^ \n")
+                                     ;; end of space-delimited word
+                                     (point)))))
       ;; `address-mime' case -- take care of quoted words, comments.
       (with-syntax-table rfc2047-syntax-table
        (let ((start)                   ; start of current token
@@ -368,8 +376,9 @@ Dynamically bind `rfc2047-encoding-type' to change that."
                            end (1+ end)))
                    (rfc2047-encode start end)
                    (setq last-encoded t)))))
-           (error (error "Invalid data for rfc2047 encoding: %s"
-                         (buffer-substring b e)))))))
+           (error
+            (message "Invalid data for rfc2047 encoding: %s"
+                     (buffer-substring b e)))))))
     (rfc2047-fold-region b (point))))
 
 (defun rfc2047-encode-string (string)
@@ -551,8 +560,13 @@ By default, the region is treated as containing addresses (see
         b e nil
         ;; = (\075), _ (\137), ? (\077) are used in the encoded word.
         ;; Avoid using 8bit characters.
-        ;; Equivalent to "^\000-\007\011\013\015-\037\200-\377=_?"
-        "\010\012\014\040-\074\076\100-\136\140-\177")
+        ;; This list excludes `especials' (see the RFC2047 syntax),
+        ;; meaning that some characters in non-structured fields will
+        ;; get encoded when they con't need to be.  The following is
+        ;; what it used to be.
+;;;     ;; Equivalent to "^\000-\007\011\013\015-\037\200-\377=_?"
+;;;     "\010\012\014\040-\074\076\100-\136\140-\177")
+        "-\b\n\f !#-'*+0-9A-Z\\^`-~\d")
        (subst-char-in-region (point-min) (point-max) ?  ?_)
        ;; The size of QP encapsulation is about 20, so set limit to
        ;; 56=76-20.
@@ -580,6 +594,12 @@ By default, the region is treated as containing addresses (see
 ;; Also check whether it needs to worry about delimiting fields like
 ;; encoding.
 
+;; In fact it's reported that (invalid) encoding of mailboxes in
+;; addr-specs is in use, so delimiting fields might help.  Probably
+;; not decoding a word which isn't properly delimited is good enough
+;; and worthwhile (is it more correct or not?), e.g. something like
+;; `=?iso-8859-1?q?foo?=@'.
+
 (defun rfc2047-decode-region (start end)
   "Decode MIME-encoded words in region between START and END."
   (interactive "r")
@@ -696,19 +716,16 @@ If your Emacs implementation can't decode CHARSET, return nil."
       (when (and (eq cs 'ascii)
                 mail-parse-charset)
        (setq cs mail-parse-charset))
-      ;; Fixme: What's this for?  The following comment makes no sense. -- fx
-      (mm-with-unibyte-current-buffer
-       ;; In Emacs Mule 4, decoding UTF-8 should be in unibyte mode.
-       (mm-decode-coding-string
-        (cond
-         ((equal "B" encoding)
-          (base64-decode-string
-           (rfc2047-pad-base64 string)))
-         ((equal "Q" encoding)
-          (quoted-printable-decode-string
-           (mm-replace-chars-in-string string ?_ ? )))
-         (t (error "Invalid encoding: %s" encoding)))
-        cs)))))
+      (mm-decode-coding-string
+       (cond
+       ((equal "B" encoding)
+        (base64-decode-string
+         (rfc2047-pad-base64 string)))
+       ((equal "Q" encoding)
+        (quoted-printable-decode-string
+         (mm-replace-chars-in-string string ?_ ? )))
+       (t (error "Invalid encoding: %s" encoding)))
+       cs))))
 
 (provide 'rfc2047)