Commit e7b9a6fc authored by Stefan Monnier's avatar Stefan Monnier

* lisp/mail/rfc2047.el: Use cl-lib & lexical-binding, silence warning

(rfc2047-decode-encoded-words): Use dolist.
(rfc2047-decode-string): Avoid string-to-multibyte.
(rfc2047-pad-base64): Use pcase.
parent 08848e33
;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages
;;; rfc2047.el --- functions for encoding and decoding rfc2047 messages -*- lexical-binding:t -*-
;; Copyright (C) 1998-2017 Free Software Foundation, Inc.
......@@ -26,8 +26,7 @@
;;; Code:
(eval-when-compile
(require 'cl))
(eval-when-compile (require 'cl-lib))
(defvar message-posting-charset)
(require 'mm-util)
......@@ -155,7 +154,7 @@ This is either `base64' or `quoted-printable'."
(goto-char (point-min))
(skip-chars-forward "\x20-\x7f\r\n\t" limit)
(while (< (point) limit)
(incf n8bit)
(cl-incf n8bit)
(forward-char 1)
(skip-chars-forward "\x20-\x7f\r\n\t" limit))
(if (or (< (* 6 n8bit) (- limit (point-min)))
......@@ -931,11 +930,10 @@ only be used for decoding, not for encoding."
"Decode successive encoded-words in WORDS and return a decoded string.
Each element of WORDS looks like (CHARSET ENCODING ENCODED-TEXT
ENCODED-WORD)."
(let (word charset cs encoding text rest)
(while words
(setq word (pop words))
(let (cs text rest)
(dolist (word words)
(if (and (setq cs (rfc2047-charset-to-coding-system
(setq charset (car word)) t))
(car word) t))
(condition-case code
(cond ((char-equal ?B (nth 1 word))
(setq text (base64-decode-string
......@@ -955,6 +953,8 @@ ENCODED-WORD)."
;; Don't decode encoded-word.
(push (cons nil (nth 3 word)) rest)))
(while rest
;; FIXME: This looks O(N²). Can we make it more efficient
;; with something like mapconcat?
(setq words (concat
(or (and (setq cs (caar rest))
(condition-case code
......@@ -1140,7 +1140,9 @@ other than `\"' and `\\' in quoted strings."
;; string is purely ASCII
string
(decode-coding-string string mail-parse-charset))
(string-to-multibyte string))))
(if (multibyte-string-p string)
string
(decode-coding-string string 'us-ascii)))))
(defun rfc2047-decode-address-string (string)
"Decode MIME-encoded STRING and return the result.
......@@ -1157,7 +1159,7 @@ strings are stripped."
string
(when (string-match "=+$" string)
(setq string (substring string 0 (match-beginning 0))))
(case (mod (length string) 4)
(pcase (mod (length string) 4)
(0 string)
(1 string) ;; Error, don't pad it.
(2 (concat string "=="))
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment