emacs-diffs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Emacs-diffs] master e7b9a6f: * lisp/mail/rfc2047.el: Use cl-lib & lexic


From: Stefan Monnier
Subject: [Emacs-diffs] master e7b9a6f: * lisp/mail/rfc2047.el: Use cl-lib & lexical-binding, silence warning
Date: Sun, 21 May 2017 23:19:06 -0400 (EDT)

branch: master
commit e7b9a6fc4adc584b1c89a8e7502734d063fab2cd
Author: Stefan Monnier <address@hidden>
Commit: Stefan Monnier <address@hidden>

    * 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.
---
 lisp/mail/rfc2047.el | 22 ++++++++++++----------
 1 file changed, 12 insertions(+), 10 deletions(-)

diff --git a/lisp/mail/rfc2047.el b/lisp/mail/rfc2047.el
index d276e21..bb8bc01 100644
--- a/lisp/mail/rfc2047.el
+++ b/lisp/mail/rfc2047.el
@@ -1,4 +1,4 @@
-;;; 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 "=="))



reply via email to

[Prev in Thread] Current Thread [Next in Thread]