* lisp/mail/rfc2231.el (rfc2231-decode-encoded-string): Fix match data error
Get (match-string 3 string) earlier, in case `mm-charset-to-coding-system` clobbers the match data. Also, check that `string-match` succeeded before using its match data.
This commit is contained in:
parent
4970e2c7ea
commit
ed9520b38e
1 changed files with 19 additions and 17 deletions
|
|
@ -215,23 +215,25 @@ These look like:
|
|||
\"\\='en-us\\='This%20is%20%2A%2A%2Afun%2A%2A%2A\",
|
||||
\"\\='\\='This%20is%20%2A%2A%2Afun%2A%2A%2A\", or
|
||||
\"This is ***fun***\"."
|
||||
(string-match "\\`\\(?:\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)" string)
|
||||
(let ((coding-system (mm-charset-to-coding-system
|
||||
(match-string 1 string) nil t))
|
||||
;;(language (match-string 2 string))
|
||||
(value (match-string 3 string)))
|
||||
(mm-with-unibyte-buffer
|
||||
(insert value)
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward "%\\([[:xdigit:]][[:xdigit:]]\\)" nil t)
|
||||
(insert
|
||||
(prog1
|
||||
(string-to-number (match-string 1) 16)
|
||||
(delete-region (match-beginning 0) (match-end 0)))))
|
||||
;; Decode using the charset, if any.
|
||||
(if (memq coding-system '(nil ascii))
|
||||
(buffer-string)
|
||||
(decode-coding-string (buffer-string) coding-system)))))
|
||||
(if (not (string-match "\\`\\(?:\\([^']+\\)?'\\([^']+\\)?'\\)?\\(.+\\)\\'"
|
||||
string))
|
||||
(error "Unrecognized RFC2231 format: %S" string)
|
||||
(let ((value (match-string 3 string))
|
||||
;;(language (match-string 2 string))
|
||||
(coding-system (mm-charset-to-coding-system
|
||||
(match-string 1 string) nil t)))
|
||||
(mm-with-unibyte-buffer
|
||||
(insert value)
|
||||
(goto-char (point-min))
|
||||
(while (re-search-forward "%\\([[:xdigit:]][[:xdigit:]]\\)" nil t)
|
||||
(insert
|
||||
(prog1
|
||||
(string-to-number (match-string 1) 16)
|
||||
(delete-region (match-beginning 0) (match-end 0)))))
|
||||
;; Decode using the charset, if any.
|
||||
(if (memq coding-system '(nil ascii))
|
||||
(buffer-string)
|
||||
(decode-coding-string (buffer-string) coding-system))))))
|
||||
|
||||
(defun rfc2231-encode-string (param value)
|
||||
"Return a PARAM=VALUE string encoded according to RFC2231.
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue