~pkal/public-inbox

2 2

[PATCH 3/3] When inserting into the list, don't allow duplicate emails

Details
Message ID
<20201229002924.10117-4-swflint@flintfam.org>
DKIM signature
missing
Download raw message
Patch: +2 -1
---
 autocrypt.el | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/autocrypt.el b/autocrypt.el
index a3f215f..1cccfa5 100644
--- a/autocrypt.el
+++ b/autocrypt.el
@@ -527,7 +527,8 @@ PREFERENCE is one of 'mutual, 'no-preference, 'none, or nil."
      (if (string-empty-p value)
          nil
        (intern value)))))
  (push (list email fingerprint preference) autocrypt-accounts)
  (pushnew (list email fingerprint preference) autocrypt-accounts
           :key #'first :test #'string=)
  (autocrypt-save-data))


-- 
2.29.2
Details
Message ID
<87zh1xtdfc.fsf@posteo.net>
In-Reply-To
<20201229002924.10117-4-swflint@flintfam.org> (view parent)
DKIM signature
missing
Download raw message
Samuel W. Flint <swflint@flintfam.org> writes:

> +  (pushnew (list email fingerprint preference) autocrypt-accounts
> +           :key #'first :test #'string=)

Use `cl-pushnew` instead part of cl-lib.el.

-- 
Thierry
Details
Message ID
<87ft3ovhbx.fsf@posteo.net>
In-Reply-To
<87zh1xtdfc.fsf@posteo.net> (view parent)
DKIM signature
missing
Download raw message
Thierry Volpiatto <thievol@posteo.net> writes:

> Samuel W. Flint <swflint@flintfam.org> writes:
>
>> +  (pushnew (list email fingerprint preference) autocrypt-accounts
>> +           :key #'first :test #'string=)
>
> Use `cl-pushnew` instead part of cl-lib.el.

And setting that aside, (cl-)pushnew will silently "fail" if in this
case the alist already contains `email'. I think it would be a better
idea to do something like

        (when (assoc email autocrypt-accounts)
          (user-error "There is already an account for this address"))

-- 
	Philip K.
Reply to thread Export thread (mbox)