1 ;; gnus-notifications.el -- Send notification on new message in Gnus
3 ;; Copyright (C) 2012-2013 Free Software Foundation, Inc.
5 ;; Author: Julien Danjou <julien@danjou.info>
8 ;; This file is part of GNU Emacs.
10 ;; GNU Emacs is free software: you can redistribute it and/or modify
11 ;; it under the terms of the GNU General Public License as published by
12 ;; the Free Software Foundation, either version 3 of the License, or
13 ;; (at your option) any later version.
15 ;; GNU Emacs is distributed in the hope that it will be useful,
16 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ;; GNU General Public License for more details.
20 ;; You should have received a copy of the GNU General Public License
21 ;; along with GNU Emacs. If not, see <http://www.gnu.org/licenses/>.
25 ;; This implements notifications using `notifications-notify' on new
27 ;; Use (add-hook 'gnus-after-getting-new-news-hook 'gnus-notifications)
28 ;; to get notifications just after getting the new news.
33 (require 'notifications))
40 (require 'google-contacts)) ; Optional
43 (defgroup gnus-notifications nil
44 "Send notifications on new message in Gnus."
48 (defcustom gnus-notifications-use-google-contacts t
49 "Use Google Contacts to retrieve photo."
51 :group 'gnus-notifications)
53 (defcustom gnus-notifications-use-gravatar t
54 "Use Gravatar to retrieve photo."
56 :group 'gnus-notifications)
58 (defcustom gnus-notifications-minimum-level 1
59 "Minimum group level the message should have to be notified.
60 Any message in a group that has a greater value than this will
61 not get notifications."
63 :group 'gnus-notifications)
65 (defcustom gnus-notifications-timeout nil
66 "Timeout used for notifications sent via `notifications-notify'."
67 :type '(choice (const :tag "Server default" nil)
68 (integer :tag "Milliseconds"))
69 :group 'gnus-notifications)
71 (defvar gnus-notifications-sent nil
72 "Notifications already sent.")
74 (defvar gnus-notifications-id-to-msg nil
75 "Map notifications ids to messages.")
77 (defun gnus-notifications-action (id key)
78 (when (string= key "read")
79 (let ((group-article (assoc id gnus-notifications-id-to-msg)))
81 (let ((group (cadr group-article))
82 (article (nth 2 group-article)))
83 (gnus-fetch-group group (list article)))))))
85 (defun gnus-notifications-notify (from subject photo-file)
86 "Send a notification about a new mail.
87 Return a notification id if any, or t on success."
88 (if (fboundp 'notifications-notify)
89 (gnus-funcall-no-warning