Show
Ignore:
Timestamp:
09/09/06 16:30:10 (2 years ago)
Author:
miyoshi
Message:

Sync up with Emacs CVS HEAD.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/lisp/gnus/rfc2047.el

    r4058 r4161  
    172172      (buffer-substring-no-properties (point) (point-max))))) 
    173173 
     174(defun rfc2047-quote-special-characters-in-quoted-strings (&optional 
     175                                                           encodable-regexp) 
     176  "Quote special characters with `\\'s in quoted strings. 
     177Quoting will not be done in a quoted string if it contains characters 
     178matching ENCODABLE-REGEXP." 
     179  (goto-char (point-min)) 
     180  (let ((tspecials (concat "[" ietf-drums-tspecials "]")) 
     181        beg) 
     182    (with-syntax-table (standard-syntax-table) 
     183      (while (search-forward "\"" nil t) 
     184        (unless (eq (char-before) ?\\) 
     185          (setq beg (match-end 0)) 
     186          (goto-char (match-beginning 0)) 
     187          (condition-case nil 
     188              (progn 
     189                (forward-sexp) 
     190                (save-restriction 
     191                  (narrow-to-region beg (1- (point))) 
     192                  (goto-char beg) 
     193                  (unless (and encodable-regexp 
     194                               (re-search-forward encodable-regexp nil t)) 
     195                    (while (re-search-forward tspecials nil 'move) 
     196                      (unless (and (eq (char-before) ?\\) ;; Already quoted. 
     197                                   (looking-at tspecials)) 
     198                        (goto-char (match-beginning 0)) 
     199                        (unless (or (eq (char-before) ?\\) 
     200                                    (and rfc2047-encode-encoded-words 
     201                                         (eq (char-after) ??) 
     202                                         (eq (char-before) ?=))) 
     203                          (insert "\\"))) 
     204                      (forward-char))))) 
     205            (error 
     206             (goto-char beg)))))))) 
     207 
    174208(defvar rfc2047-encoding-type 'address-mime 
    175209  "The type of encoding done by `rfc2047-encode-region'. 
     
    188222        (save-restriction 
    189223          (rfc2047-narrow-to-field) 
     224          (setq method nil 
     225                alist rfc2047-header-encoding-alist) 
     226          (while (setq elem (pop alist)) 
     227            (when (or (and (stringp (car elem)) 
     228                           (looking-at (car elem))) 
     229                      (eq (car elem) t)) 
     230              (setq alist nil 
     231                    method (cdr elem)))) 
    190232          (if (not (rfc2047-encodable-p)) 
    191               (prog1 
     233              (prog2 
     234                  (when (eq method 'address-mime) 
     235                    (rfc2047-quote-special-characters-in-quoted-strings)) 
    192236                  (if (and (eq (mm-body-7-or-8) '8bit) 
    193237                           (mm-multibyte-p) 
     
    210254                   (point-max)))) 
    211255            ;; We found something that may perhaps be encoded. 
    212             (setq method nil 
    213                   alist rfc2047-header-encoding-alist) 
    214             (while (setq elem (pop alist)) 
    215               (when (or (and (stringp (car elem)) 
    216                              (looking-at (car elem))) 
    217                         (eq (car elem) t)) 
    218                 (setq alist nil 
    219                       method (cdr elem)))) 
    220256            (re-search-forward "^[^:]+: *" nil t) 
    221257            (cond 
     
    348384                (goto-char end)))) 
    349385        ;; `address-mime' case -- take care of quoted words, comments. 
     386        (rfc2047-quote-special-characters-in-quoted-strings encodable-regexp) 
    350387        (with-syntax-table rfc2047-syntax-table 
    351388          (goto-char (point-min)) 
     
    822859them.") 
    823860 
     861(defun rfc2047-strip-backslashes-in-quoted-strings () 
     862  "Strip backslashes in quoted strings.  `\\\"' remains." 
     863  (goto-char (point-min)) 
     864  (let (beg) 
     865    (with-syntax-table (standard-syntax-table) 
     866      (while (search-forward "\"" nil t) 
     867        (unless (eq (char-before) ?\\) 
     868          (setq beg (match-end 0)) 
     869          (goto-char (match-beginning 0)) 
     870          (condition-case nil 
     871              (progn 
     872                (forward-sexp) 
     873                (save-restriction 
     874                  (narrow-to-region beg (1- (point))) 
     875                  (goto-char beg) 
     876                  (while (search-forward "\\" nil 'move) 
     877                    (unless (memq (char-after) '(?\")) 
     878                      (delete-backward-char 1)) 
     879                    (forward-char))) 
     880                (forward-char)) 
     881            (error 
     882             (goto-char beg)))))))) 
     883 
    824884(defun rfc2047-charset-to-coding-system (charset) 
    825885  "Return coding-system corresponding to MIME CHARSET. 
     
    899959;; `=?iso-8859-1?q?foo?=@'. 
    900960 
    901 (defun rfc2047-decode-region (start end) 
    902   "Decode MIME-encoded words in region between START and END." 
     961(defun rfc2047-decode-region (start end &optional address-mime) 
     962  "Decode MIME-encoded words in region between START and END. 
     963If ADDRESS-MIME is non-nil, strip backslashes which precede characters 
     964other than `\"' and `\\' in quoted strings." 
    903965  (interactive "r") 
    904966  (let ((case-fold-search t) 
     
    911973      (save-restriction 
    912974        (narrow-to-region start end) 
     975        (when address-mime 
     976          (rfc2047-strip-backslashes-in-quoted-strings)) 
    913977        (goto-char (setq b start)) 
    914978        ;; Look for the encoded-words. 
     
    9961060          (mm-decode-coding-region b (point-max) mail-parse-charset)))))) 
    9971061 
    998 (defun rfc2047-decode-string (string) 
    999   "Decode the quoted-printable-encoded STRING and return the results." 
     1062(defun rfc2047-decode-address-region (start end) 
     1063  "Decode MIME-encoded words in region between START and END. 
     1064Backslashes which precede characters other than `\"' and `\\' in quoted 
     1065strings are stripped." 
     1066  (rfc2047-decode-region start end t)) 
     1067 
     1068(defun rfc2047-decode-string (string &optional address-mime) 
     1069  "Decode MIME-encoded STRING and return the result. 
     1070If ADDRESS-MIME is non-nil, strip backslashes which precede characters 
     1071other than `\"' and `\\' in quoted strings." 
    10001072  (let ((m (mm-multibyte-p))) 
    10011073    (if (string-match "=\\?" string) 
     
    10111083          (insert string) 
    10121084          (inline 
    1013             (rfc2047-decode-region (point-min) (point-max))) 
     1085            (rfc2047-decode-region (point-min) (point-max) address-mime)) 
    10141086          (buffer-string)) 
     1087      (when address-mime 
     1088        (setq string 
     1089              (with-temp-buffer 
     1090                (when (mm-multibyte-string-p string) 
     1091                  (mm-enable-multibyte)) 
     1092                (insert string) 
     1093                (rfc2047-strip-backslashes-in-quoted-strings) 
     1094                (buffer-string)))) 
    10151095      ;; Fixme: As above, `m' here is inappropriate. 
    10161096      (if (and m 
     
    10341114        (mm-string-as-multibyte string))))) 
    10351115 
     1116(defun rfc2047-decode-address-string (string) 
     1117  "Decode MIME-encoded STRING and return the result. 
     1118Backslashes which precede characters other than `\"' and `\\' in quoted 
     1119strings are stripped." 
     1120  (rfc2047-decode-string string t)) 
     1121 
    10361122(defun rfc2047-pad-base64 (string) 
    10371123  "Pad STRING to quartets."