emacs-pretest-bug
[Top][All Lists]
Advanced

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

CVS Emacs + BBDB + mailabbrev.el change causes extra quotes


From: Mark Plaksin
Subject: CVS Emacs + BBDB + mailabbrev.el change causes extra quotes
Date: Tue, 01 Mar 2005 18:09:06 -0500
User-agent: Gnus/5.110003 (No Gnus v0.3) Emacs/21.3.50 (gnu/linux)

After the CVS Emacs change below, email addresses stored in BBDB and
expanded by mailabbrev have an extra set of quotes around them.  This does
not happen with aliases defined in .mailrc.  BBDB's bbdb-dwim-net-address
quotes email addresses before they get passed to mailabbrev, then
mailabbrev adds an extra set of quotes.

bbdb-dwim-net-address (reproduced below) looks like it does lots of
backslashing and quoting; maybe it would be useful in Emacs itself?

For example, if I have a BBDB entry for RMS like this:
  Richard M. Stallman
              net: address@hidden
       mail-alias: rms

and then compose a new message with Gnus, type "rms" in the To: field and
hit space, it expands to:
   ""Richard M. Stallman"" <address@hidden> 

If I undo the change, the problem goes away.  I can't tell what it's best
to "fix" Emacs or BBDB, so I'm posting to both lists.  The change is from
version 1.74 to 1.75 of mailabbrev.el; the ChangeLog entry says:

  2005-01-04  Richard M. Stallman  <address@hidden>
  
          * mail/mailabbrev.el (sendmail-pre-abbrev-expand-hook):
          Don't expand if the character is @, period, dash, etc.
          (define-mail-abbrev): Quote names that contain problem characters.

and the diff is:

Index: mailabbrev.el
===================================================================
RCS file: /cvsroot/emacs/emacs/lisp/mail/mailabbrev.el,v
retrieving revision 1.74
retrieving revision 1.75
diff -u -r1.74 -r1.75
--- mailabbrev.el       30 Sep 2003 12:44:53 -0000      1.74
+++ mailabbrev.el       4 Jan 2005 14:59:27 -0000       1.75
@@ -305,10 +305,19 @@
                    end (string-match "\"[ \t,]*" definition start))
            (setq end (string-match "[ \t,]+" definition start)))
        (setq end (string-match "[ \t\n,]*,[ \t\n,]*" definition start)))
-      (setq result (cons (substring definition start end) result))
-      (setq start (and end
-                      (/= (match-end 0) L)
-                      (match-end 0))))
+      (let ((tem (substring definition start end)))
+       ;; Advance the loop past this address.
+       (setq start (and end
+                        (/= (match-end 0) L)
+                        (match-end 0)))
+       ;; If the full name contains a problem character, quote it.
+       (when (string-match "\\(.+?\\)[ \t]*\\(<.*>\\)" tem)
+         (if (string-match "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]"
+                           (match-string 1 tem))
+             (setq tem (replace-regexp-in-string
+                        "\\(.+?\\)[ \t]*\\(<.*>\\)" "\"\\1\" \\2"
+                        tem))))
+       (push tem result)))
     (setq definition (mapconcat (function identity)
                                (nreverse result)
                                mail-alias-separator-string)))
@@ -485,7 +494,9 @@
             ;; the usual syntax table.
 
             (or (and (integerp last-command-char)
-                     (eq (char-syntax last-command-char) ?_))
+                     (or (eq (char-syntax last-command-char) ?_)
+                         ;; Don't expand on @.
+                         (memq last-command-char '(?@ ?. ?% ?! ?_ ?-))))
                 (let ((pre-abbrev-expand-hook nil)) ; That's us; don't loop.
                   ;; Use this table so that abbrevs can have hyphens in them.
                   (set-syntax-table mail-abbrev-syntax-table)
@@ -610,7 +621,8 @@
   (interactive "P")
   (if (looking-at "[ \t]*\n") (expand-abbrev))
   (setq this-command 'end-of-buffer)
-  (end-of-buffer arg))
+  (with-no-warnings
+   (end-of-buffer arg)))
 
 (eval-after-load "sendmail"
   '(progn

Here's bbdb-dwim-net-address:

(defun bbdb-dwim-net-address (record &optional net)
  "Returns a string to use as the email address of the given record.  The
given address is the address the mail is destined to; this is formatted like
\"Firstname Lastname <addr>\" unless both the first name and last name are
constituents of the address, as in address@hidden, or the address is
already in the form \"Name <foo>\" or \"foo (Name)\", in which case the
address is used as-is. If `bbdb-dwim-net-address-allow-redundancy' is non-nil,
the name is always included.  If `bbdb-dwim-net-address-allow-redundancy' is
'netonly the name is never included!"
  (or net (setq net (car (bbdb-record-net record))))
  (or net (error "record unhas network addresses"))
  (let* ((override (bbdb-record-getprop record 'mail-name))
         (name (or override (bbdb-record-name record)))
         fn ln (i 0))
    (if override
        (let ((both (bbdb-divide-name override)))
          (setq fn (car both)
                ln (car (cdr both)))
          (if (equal fn "") (setq fn nil))
          (if (equal ln "") (setq ln nil)))
      (setq fn (bbdb-record-firstname record)
            ln (bbdb-record-lastname record)))
    ;; if the name contains backslashes or double-quotes, backslash them.
    (if name
        (while (setq i (string-match "[\\\"]" name i))
          (setq name (concat (substring name 0 i) "\\" (substring name i))
                i (+ i 2))))
    (cond ((eq 'netonly bbdb-dwim-net-address-allow-redundancy)
           net)
          ((or (null name)
               (if (not bbdb-dwim-net-address-allow-redundancy)
                   (cond ((and fn ln)
                          (or (string-match
                               (concat "address@hidden" (regexp-quote fn)
                                       "address@hidden" (regexp-quote ln) "\\b")
                               net)
                              (string-match
                               (concat "address@hidden" (regexp-quote ln)
                                       "address@hidden" (regexp-quote fn) "\\b")
                               net)))
                         ((or fn ln)
                          (string-match
                           (concat "address@hidden" (regexp-quote (or fn ln)) 
"\\b")
                           net))))
               ;; already in "foo <bar>" or "bar <foo>" format.
               (string-match "\\`[ \t]*[^<]+[ \t]*<" net)
               (string-match "\\`[ \t]*[^(]+[ \t]*(" net))
           net)
          ;; if the name contains control chars or RFC822 specials, it needs
          ;; to be enclosed in quotes.  Double-quotes and backslashes have
          ;; already been escaped.  This quotes a few extra characters as
          ;; well (!,%, and $) just for common sense.
          ((string-match "[][\000-\037\177()<>@,;:.!$%]" name)
           (format "\"%s\" <%s>" name net))
          (t
           (format "%s <%s>" name net)))))

Thanks for the help!





reply via email to

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