-;;; 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.
;;; Code:
-(eval-when-compile
- (require 'cl))
+(eval-when-compile (require 'cl-lib))
(defvar message-posting-charset)
(require 'mm-util)
(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)))
"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
;; 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
;; 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.
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 "=="))