emacs-orgmode@gnu.org archives
 help / color / mirror / code / Atom feed
* [PATCH] org-contacts: Implement a way to ignore certain new addresses
@ 2013-08-22 16:01 Frank Terbeck
  2013-08-22 19:08 ` Greg Troxel
  0 siblings, 1 reply; 2+ messages in thread
From: Frank Terbeck @ 2013-08-22 16:01 UTC (permalink / raw)
  To: emacs-orgmode; +Cc: Frank Terbeck

With some bugtrackers (like the one github uses or with roundup for
example) or when you use gwene to follow certain site's RSS feeds,
you may run into situations, where `org-contacts-check-mail-address'
will ask if it should add a non-sensical email-address.

With this change, you can fine-tune in which situations org-contacts
is going ask you about whether or not you want to add a given new
address to an existing contact.

Valid values are functions that accept one argument and strings, that
will be used at regular expressions via `string-match'.

A minimal example is this:

  (add-to-list 'org-contacts-new-address-ignore
               "notifications@github\\.com")

The following is equivalent:

  (add-to-list 'org-contacts-new-address-ignore
               #'(lambda (x)
                   (string-match "notifications@github\\.com" x)))

Signed-off-by: Frank Terbeck <ft@bewatermyfriend.org>
---

  Please keep me CC:ed, as I am not subscribed.

 contrib/lisp/org-contacts.el | 45 +++++++++++++++++++++++++++++++++++++++-----
 1 file changed, 40 insertions(+), 5 deletions(-)

diff --git a/contrib/lisp/org-contacts.el b/contrib/lisp/org-contacts.el
index 97171d0..dd90a92 100644
--- a/contrib/lisp/org-contacts.el
+++ b/contrib/lisp/org-contacts.el
@@ -155,6 +155,25 @@ The following replacements are available:
   :type 'string
   :group 'org-contacts)
 
+(defcustom org-contacts-new-address-ignore
+  nil
+  "List of checks to run to determine whether or not to add a new
+email address to an existing contact.
+
+If an entry is a string, it is assumed to be a regular expression
+to match against the new address. If it is a symbol, it is
+assumed to be a function, that takes one argument, which is going
+to be set to the new address.
+
+If the regular expression matches or the function returns a
+non-nil value, the new address is not considered to be added to
+the existing account.
+
+Finally, here is an example:
+
+  (add-to-list 'org-contacts-new-address-ignore
+               \"notifications@github\\\\.com\")")
+
 (defcustom org-contacts-matcher
   (mapconcat 'identity (list org-contacts-email-property
 			     org-contacts-alias-property
@@ -728,13 +747,29 @@ This function should be called from `gnus-article-prepare-hook'."
       (concat (org-contacts-format-name name) " <" email ">")
     email))
 
+(defun org-contacts-new-address-ignored (mail)
+  "Check whether a mail address is marked to be ignored via the
+`org-contacts-new-address-ignore' list."
+  (catch 'ignored-mail
+    (dolist (matcher org-contacts-new-address-ignore)
+      (cond ((stringp matcher)
+             (and (string-match matcher mail)
+                  (throw 'ignored-mail t)))
+            ((functionp matcher)
+             (and (funcall matcher mail)
+                  (throw 'ignored-mail t)))
+            ;; Ignore all other entries.
+            (t t)))
+    (throw 'ignored-mail nil)))
+
 (defun org-contacts-check-mail-address (mail)
   "Add MAIL address to contact at point if it does not have it."
-  (let ((mails (org-entry-get (point) org-contacts-email-property)))
-    (unless (member mail (split-string mails))
-      (when (yes-or-no-p
-             (format "Do you want to add this address to %s?" (org-get-heading t)))
-        (org-set-property org-contacts-email-property (concat mails " " mail))))))
+  (unless (org-contacts-new-address-ignored mail)
+    (let ((mails (org-entry-get (point) org-contacts-email-property)))
+      (unless (member mail (split-string mails))
+        (when (yes-or-no-p
+               (format "Do you want to add this address to %s?" (org-get-heading t)))
+          (org-set-property org-contacts-email-property (concat mails " " mail)))))))
 
 (defun org-contacts-gnus-check-mail-address ()
   "Check that contact has the current address recorded.
-- 
1.8.3

^ permalink raw reply related	[flat|nested] 2+ messages in thread

* Re: [PATCH] org-contacts: Implement a way to ignore certain new addresses
  2013-08-22 16:01 [PATCH] org-contacts: Implement a way to ignore certain new addresses Frank Terbeck
@ 2013-08-22 19:08 ` Greg Troxel
  0 siblings, 0 replies; 2+ messages in thread
From: Greg Troxel @ 2013-08-22 19:08 UTC (permalink / raw)
  To: Frank Terbeck; +Cc: emacs-orgmode

[-- Attachment #1: Type: text/plain, Size: 923 bytes --]


Frank Terbeck <ft@bewatermyfriend.org> writes:

>   (add-to-list 'org-contacts-new-address-ignore
>                "notifications@github\\.com")

Amusingly I filed a bug with github, saying that they should not emit
mail with a person's name and an email address that does not belong to
the person.  They acknowleged that it would be better not to do this,
but it didn't seem likely to get fixed.

Another useful feature would be to add a property to a person's record
that other names and email addresses shouldn't get picked up.  This
would be sort of like ignoring
  "Fred Foonly <notifications@github.com>"
based on that email address being used in a flaky manner,
and instead ignore
  "Fred Foonly <noreply@massmail.bigcompany.com>"
based on Fred being marked as having odd sending addresses, and
  "Benefits Update <foonly@bigcompany.com>"
based on foonly@bigcompany.com being marked as having odd full-name
parts.


[-- Attachment #2: Type: application/pgp-signature, Size: 194 bytes --]

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-08-22 19:09 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-08-22 16:01 [PATCH] org-contacts: Implement a way to ignore certain new addresses Frank Terbeck
2013-08-22 19:08 ` Greg Troxel

Code repositories for project(s) associated with this public inbox

	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).