branch: externals/ebdb
commit dd2f73cfb7e8c9b9fa5369c783e84530817c98ca
Author: Eric Abrahamsen <e...@ericabrahamsen.net>
Commit: Eric Abrahamsen <e...@ericabrahamsen.net>

    Change behavior of mail insertion
    
    * ebdb.el (ebdb-record-insert-field): Change what this method does. It
      previously sorted all the record's mails, which is a no-no because
      it was setting slot values directly, without going through the
      database-aware accessors. Don't do that (we still don't have a good
      way of doing that). Instead, do something else: set the priority the
      mail, if the record has no other primary mail.
---
 ebdb.el | 15 ++++++++-------
 1 file changed, 8 insertions(+), 7 deletions(-)

diff --git a/ebdb.el b/ebdb.el
index e3042e1..613660b 100644
--- a/ebdb.el
+++ b/ebdb.el
@@ -3019,13 +3019,14 @@ If FIELD doesn't specify a year, use the current year."
 (cl-defmethod ebdb-record-organizations ((_record ebdb-record-entity))
   nil)
 
-(cl-defmethod ebdb-record-insert-field :after ((record ebdb-record-entity)
-                                              (_mail ebdb-field-mail)
-                                              &optional _slot)
-  "After giving RECORD a new mail field, sort RECORD's mails by
-priority."
-  (let ((sorted (ebdb-sort-mails (slot-value record 'mail))))
-    (setf (slot-value record 'mail) sorted)))
+(cl-defmethod ebdb-record-insert-field :before ((record ebdb-record-entity)
+                                               (mail ebdb-field-mail)
+                                               &optional _slot)
+  "Possibly set the priority of a newly-added mail address.
+If RECORD has no other primary mail, set MAIL's priority to
+primary."
+  (when (null (object-assoc 'primary 'priority (ebdb-record-mail record)))
+    (setf (slot-value mail 'priority) 'primary)))
 
 (defun ebdb-compose-mail (&rest args)
   "Start composing a mail message to send.

Reply via email to