Commit ba7ac1f6 authored by Julien Danjou's avatar Julien Danjou Committed by Katsumi Yamaoka
Browse files

gnus-notifications.el: Add defcustom for timeout and actions support

parent b1183529
2012-08-30 Julien Danjou <julien@danjou.info>
* gnus-notifications.el (gnus-notifications-notify): Use timeout from
`gnus-notifications-timeout'.
(gnus-notifications-timeout): Add.
(gnus-notifications-action): New function.
(gnus-notifications-notify): Add :action using
`gnus-notifications-action'.
(gnus-notifications-id-to-msg): New variable.
(gnus-notifications): Use `gnus-notifications-id-to-msg' to map
notifications id to messages.
2012-08-30 Kenichi Handa <handa@gnu.org>
* qp.el (quoted-printable-decode-region): Decode multiple bytes at
......
......@@ -58,20 +58,42 @@ not get notifications."
:type 'integer
:group 'gnus-notifications)
(defcustom gnus-notifications-timeout nil
"Timeout used for notifications sent via `notifications-notify'."
:type 'integer
:group 'gnus-notifications)
(defvar gnus-notifications-sent nil
"Notifications already sent.")
(defvar gnus-notifications-id-to-msg nil
"Map notifications ids to messages.")
(defun gnus-notifications-action (id key)
(when (string= key "read")
(let ((group-article (assoc id gnus-notifications-id-to-msg)))
(when group-article
(let ((group (cadr group-article))
(article (caddr group-article)))
(gnus-fetch-group group (list article)))))))
(defun gnus-notifications-notify (from subject photo-file)
"Send a notification about a new mail."
"Send a notification about a new mail.
Return a notification id if any, or t on success."
(if (fboundp 'notifications-notify)
(notifications-notify
:title from
:body subject
:actions '("read" "Read")
:on-action 'gnus-notifications-action
:app-icon (image-search-load-path "gnus/gnus.png")
:app-name "Gnus"
:category "email.arrived"
:timeout gnus-notifications-timeout
:image-path photo-file)
(message "New message from %s: %s" from subject)))
(message "New message from %s: %s" from subject)
;; Don't return an id
t))
(defun gnus-notifications-get-photo (mail-address)
"Get photo for mail address."
......@@ -136,21 +158,23 @@ This is typically a function to add in
(article-decode-encoded-words) ; to decode mail addresses, subjects, etc
(let* ((address-components (mail-extract-address-components
(or (mail-fetch-field "From") "")))
(address (cadr address-components))
(photo-file (gnus-notifications-get-photo-file
address)))
(when (or
;; Ignore mails from ourselves
(gnus-string-match-p gnus-ignored-from-addresses
address)
(gnus-notifications-notify
(or (car address-components) address)
(mail-fetch-field "Subject")
photo-file))
;; Register that we did notify this message
(setcdr group-notifications (cons article (cdr group-notifications))))
(when photo-file
(delete-file photo-file)))))))))))
(address (cadr address-components)))
;; Ignore mails from ourselves
(unless (gnus-string-match-p gnus-ignored-from-addresses
address)
(let* ((photo-file (gnus-notifications-get-photo-file address))
(notification-id (gnus-notifications-notify
(or (car address-components) address)
(mail-fetch-field "Subject")
photo-file)))
(when notification-id
;; Register that we did notify this message
(setcdr group-notifications (cons article (cdr group-notifications)))
(unless (eq notification-id t)
;; Register the notification id for later actions
(add-to-list 'gnus-notifications-id-to-msg (list notification-id group article))))
(when photo-file
(delete-file photo-file)))))))))))))
(provide 'gnus-notifications)
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment