[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[elpa] externals/ebdb 7662133 140/350: Simplify ebdb-dwim-mail
From: |
Eric Abrahamsen |
Subject: |
[elpa] externals/ebdb 7662133 140/350: Simplify ebdb-dwim-mail |
Date: |
Mon, 14 Aug 2017 11:46:23 -0400 (EDT) |
branch: externals/ebdb
commit 7662133c0dd8142e03a8a1db786a4a230145503a
Author: Eric Abrahamsen <address@hidden>
Commit: Eric Abrahamsen <address@hidden>
Simplify ebdb-dwim-mail
* ebdb.el: Remove options `ebdb-mail-name-format' and
`ebdb-mail-name'. Re-instate later if people complain. If a
different name is desired for a particular mail address, we can use
the mail-aka slot.
* ebdb-com.el (ebdb-dwim-mail): Don't go to such lengths when matching
the name and mail user. Just a simple check for likely matches, and
move on. This also removes dependency on person record complex
names, which previously would have raised an error for an
organization.
---
ebdb-com.el | 96 ++++++++++++++++++++++++-------------------------------------
ebdb.el | 30 ++++---------------
2 files changed, 43 insertions(+), 83 deletions(-)
diff --git a/ebdb-com.el b/ebdb-com.el
index 6aec6e9..c046d36 100644
--- a/ebdb-com.el
+++ b/ebdb-com.el
@@ -2107,71 +2107,49 @@ the record to be displayed or nil otherwise."
(defun ebdb-dwim-mail (record &optional mail)
;; Do What I Mean!
"Return a string to use as the mail address of RECORD.
-The name in the mail address is formatted obeying `ebdb-mail-name-format'
-and `ebdb-mail-name'. However, if both the first name and last name
-are constituents of the address as in address@hidden,
-and `ebdb-mail-avoid-redundancy' is non-nil, then the address is used as is
-and `ebdb-mail-name-format' and `ebdb-mail-name' are ignored.
-If `ebdb-mail-avoid-redundancy' is 'mail-only the name is never included.
-MAIL may be a mail address to be used for RECORD.
-If MAIL is an integer, use the MAILth mail address of RECORD.
-If MAIL is nil use RECORD's primary mail address."
+
+However, if both the first name and last name are constituents of
+the address as in address@hidden, and
+`ebdb-mail-avoid-redundancy' is non-nil, then the address is used
+as is. If `ebdb-mail-avoid-redundancy' is 'mail-only the name
+is never included. MAIL may be a mail address to be used for
+RECORD. If MAIL is an integer, use the MAILth mail address of
+RECORD. If MAIL is nil use RECORD's primary mail address."
(unless mail
(let ((mails (ebdb-record-mail record t)))
(setq mail (or (and (integerp mail) (nth mail mails))
(object-assoc 'primary 'priority mails)
(car mails)))))
(unless mail (error "Record has no mail addresses"))
- (let ((mail-aka (slot-value mail 'aka))
- name fn ln)
- (setq mail (slot-value mail 'mail))
- (cond (mail-aka
- (setq name mail-aka))
- ((functionp ebdb-mail-name)
- (setq name (funcall ebdb-mail-name record))
- (if (consp name)
- (setq fn (car name) ln (cdr name)
- name (if (eq ebdb-mail-name-format 'first-last)
- (ebdb-concat 'name-first-last fn ln)
- (ebdb-concat 'name-last-first ln fn)))
- (let ((pair (ebdb-divide-name name)))
- (setq fn (car pair) ln (cdr pair)))))
- ((setq name (ebdb-record-user-field record ebdb-mail-name))
- (let ((pair (ebdb-divide-name name)))
- (setq fn (car pair) ln (cdr pair))))
- (t
- (setq name (if (eq ebdb-mail-name-format 'first-last)
- (ebdb-record-name record)
- (ebdb-name-lf (slot-value record 'name)))
- fn (ebdb-record-firstname record)
- ln (ebdb-record-lastname record))))
- (if (or (not name) (equal "" name)
- (eq 'mail-only ebdb-mail-avoid-redundancy)
- (and ebdb-mail-avoid-redundancy
- (cond ((and fn ln)
- (let ((fnq (regexp-quote fn))
- (lnq (regexp-quote ln)))
- (or (string-match (concat "address@hidden" fnq
- "address@hidden" lnq "\\b")
- mail)
- (string-match (concat "address@hidden" lnq
- "address@hidden" fnq "\\b")
- mail))))
- ((or fn ln)
- (string-match (concat "address@hidden"
- (regexp-quote (or fn ln)) "\\b")
- mail)))))
- mail
- ;; If the name contains backslashes or double-quotes, backslash them.
- (setq name (replace-regexp-in-string "[\\\"]" "\\\\\\&" name))
- ;; If the name contains control chars or RFC822 specials, it needs
- ;; to be enclosed in quotes. This quotes a few extra characters as
- ;; well (!,%, and $) just for common sense.
- ;; `define-mail-alias' uses regexp "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]".
- (format (if (string-match "[][[:cntrl:]\177()<>@,;:.!$%[:nonascii:]]"
name)
- "\"%s\" <%s>"
- "%s <%s>")
- name mail))))
+ (let* ((name-base (or (slot-value mail 'aka) (ebdb-record-name record)))
+ (mail (slot-value mail 'mail))
+ (name
+ (cond
+ ((or (eq 'mail-only ebdb-mail-avoid-redundancy)
+ (and ebdb-mail-avoid-redundancy
+ (string-match-p
+ (regexp-quote
+ (replace-regexp-in-string
+ "\s" "" name-base))
+ (replace-regexp-in-string
+ "[-._]" "" (car (split-string mail "@"))))))
+ nil)
+ (name-base)
+ (t nil))))
+ (if name
+ (progn
+ ;; If the name contains backslashes or double-quotes, backslash them.
+ (setq name (replace-regexp-in-string "[\\\"]" "\\\\\\&" name))
+ ;; If the name contains control chars or RFC822 specials, it needs
+ ;; to be enclosed in quotes. This quotes a few extra characters as
+ ;; well (!,%, and $) just for common sense.
+ ;; `define-mail-alias' uses regexp "[^- !#$%&'*+/0-9=?A-Za-z^_`{|}~]".
+
+ (format (if (string-match "[][[:cntrl:]\177()<>@,;:.!$%[:nonascii:]]"
name)
+ "\"%s\" <%s>"
+ "%s <%s>")
+ name mail))
+ mail)))
(defun ebdb-compose-mail (&rest args)
"Start composing a mail message to send."
diff --git a/ebdb.el b/ebdb.el
index 109dc54..0061706 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -3602,31 +3602,13 @@ Whether this is used at all depends on the variable
`ebdb-check-postcode'."
-(defcustom ebdb-mail-name-format 'first-last
- "Format for names when sending mail.
-If first-last format names as \"Firstname Lastname\".
-If last-first format names as \"Lastname, Firstname\".
-If `ebdb-mail-name' returns the full name as a single string, this takes
-precedence over `ebdb-mail-name-format'. Likewise, if the mail address itself
-includes a name, this is not reformatted."
- :group 'ebdb-sendmail
- :type '(choice (const :tag "Firstname Lastname" first-last)
- (const :tag "Lastname, Firstname" last-first)))
-
-(defcustom ebdb-mail-name 'mail-name
- "Xfield holding the full name for a record when sending mail.
-This may also be a function taking one argument, a record.
-If it returns the full mail name as a single string, this is used \"as is\".
-If it returns a cons pair (FIRST . LAST) with the first and last name
-for this record, these are formatted obeying `ebdb-mail-name-format'."
- :group 'ebdb-sendmail
- :type '(choice (symbol :tag "xfield")
- (function :tag "mail name function")))
-
(defcustom ebdb-mail-avoid-redundancy nil
- "Mail address to use for EBDB records when sending mail.
-If non-nil do not use full name in mail address when same as mail.
-If value is mail-only never use full name."
+ "How to handle the name part of `ebdb-dwim-mail'.
+
+If nil, always return both name and mail. If value is mail-only
+never use full name. Other non-nil values mean do not use full
+name in mail address when same as mail.
+"
:group 'ebdb-sendmail
:type '(choice (const :tag "Allow redundancy" nil)
(const :tag "Never use full name" mail-only)
- [elpa] externals/ebdb 281c61e 154/350: Don't ((lambda ()), (continued)
- [elpa] externals/ebdb 281c61e 154/350: Don't ((lambda ()), Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 4cce4c8 096/350: Simplify role field adoption process, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 0910ddd 105/350: Change default of ebdb-default-user-field, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b495e29 083/350: Omnibus changes to display and redisplay, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 29bf304 101/350: Rework MUA window popups, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 81e23c3 134/350: Simplify record mail citing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb b661aac 124/350: First generalized version of snarfing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb aae57ff 139/350: Ensure that extra name field instances go in 'aka slot, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 057c4c0 144/350: Have ebdb-snarf accept optional records argument, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 8d81a19 132/350: Add EBDB record citation, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 7662133 140/350: Simplify ebdb-dwim-mail,
Eric Abrahamsen <=
- [elpa] externals/ebdb 0cfe1ec 164/350: Provide keybinding for ebdb-format-all-records, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb bf51b58 161/350: Fix ebdb-delete-redundant-mails, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 279eb56 169/350: Tweaks and additions to manual, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb eea0abf 165/350: VCard export is good enough, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 64b5e43 170/350: Fix autoloads in ebdb.el, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a968dd3 143/350: First actually-working version of snarfing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb a8e0221 179/350: Missing local variable binding, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb e71548d 172/350: Allow for characters before mail addresses when snarfing, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 14b03b5 186/350: Fix menu entry of ebdb-create-record, Eric Abrahamsen, 2017/08/14
- [elpa] externals/ebdb 10c1e76 185/350: When replying to messages, start with a populated EBDB buffer, Eric Abrahamsen, 2017/08/14