]> crepu.dev Git - config.git/blob - djavu-asus/emacs/elpa/jabber-20230715.456/jabber-gmail.el
5b8f472a5712478a381bd80a929048b89eba2288
[config.git] / djavu-asus / emacs / elpa / jabber-20230715.456 / jabber-gmail.el
1 ;;; jabber-gmail.el --- Gmail notifications via emacs-jabber -*- lexical-binding: t; -*-
2
3 ;; Copyright (C) 2008 Magnus Henoch <mange@freemail.hu>
4 ;; Copyright (C) 2007 Valery V. Vorotyntsev <valery.vv@gmail.com>
5
6 ;; This program is free software; you can redistribute it and/or
7 ;; modify it under the terms of the GNU General Public License
8 ;; as published by the Free Software Foundation; either version 2
9 ;; of the License, or (at your option) any later version.
10 ;;
11 ;; This program is distributed in the hope that it will be useful,
12 ;; but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ;; GNU General Public License for more details.
15 ;;
16 ;; You should have received a copy of the GNU General Public License
17 ;; along with this program; if not, write to the Free Software
18 ;; Foundation, Inc., 51 Franklin Street, Fifth Floor,
19 ;; Boston, MA 02110-1301, USA.
20
21 ;;; Usage:
22
23 ;; Add the following line to your ~/.emacs:
24 ;;
25 ;; (require 'jabber-gmail)
26 ;;
27 ;; If you prefer on demand loading
28 ;; [http://a-nickels-worth.blogspot.com/2007/11/effective-emacs.html]:
29 ;;
30 ;; (autoload 'jabber-gmail-query "jabber-gmail")
31 ;; (autoload 'jabber-gmail-subscribe "jabber-gmail")
32 ;; (add-hook 'jabber-post-connect-hook 'jabber-gmail-subscribe)
33 ;;
34 ;; You may wish to bind a shortcut for `jabber-gmail-query'
35 ;;
36 ;; (global-set-key (kbd "<f9> g") 'jabber-gmail-query)
37 ;;
38 ;; or to customize `jabber-gmail-dothreads'
39 ;;
40 ;; (defun jabber-gmail-dothreads (ts)
41 ;; (let ((msg (format "%d new messages in gmail inbox" (length ts))))
42 ;; (message msg)
43 ;; (jabber-screen-message msg)))
44
45 ;;;###autoload
46 (defun jabber-gmail-subscribe (jc)
47 "Subscribe to gmail notifications.
48 See http://code.google.com/apis/talk/jep_extensions/usersettings.html#4"
49 (interactive (list (jabber-read-account)))
50 (jabber-send-iq jc (jabber-connection-bare-jid jc) "set"
51 '(usersetting ((xmlns . "google:setting"))
52 (mailnotifications ((value . "true"))))
53 #'jabber-report-success "Gmail subscription"
54 #'jabber-process-data "Gmail subscription")
55
56 ;; Looks like "one shot" request is still needed to activate
57 ;; notifications machinery.
58 (jabber-gmail-query jc))
59
60 (add-to-list 'jabber-iq-set-xmlns-alist
61 (cons "google:mail:notify" #'jabber-gmail-process-new-mail))
62 (defun jabber-gmail-process-new-mail (jc xml-sexp)
63 "Process new gmail notification.
64 See http://code.google.com/apis/talk/jep_extensions/gmail.html#notifications"
65 (let ((from (jabber-xml-get-attribute xml-sexp 'from))
66 (id (jabber-xml-get-attribute xml-sexp 'id)))
67 ;; respond to server
68 (jabber-send-iq jc from "result" nil
69 nil nil nil nil
70 id))
71
72 (jabber-gmail-query jc))
73
74 ;;;###autoload
75 (defun jabber-gmail-query (jc)
76 "Request mail information from the Google Talk server (a.k.a. one shot query).
77 See http://code.google.com/apis/talk/jep_extensions/gmail.html#requestmail"
78 (interactive (list (jabber-read-account)))
79 (jabber-send-iq jc (jabber-connection-bare-jid jc) "get"
80 '(query ((xmlns . "google:mail:notify")))
81 #'jabber-gmail-process-mailbox nil
82 #'jabber-process-data "Gmail query" "gmail-query"))
83
84 (defun jabber-gmail-process-mailbox (jc xml-sexp &rest ignore)
85 "Process gmail query response.
86 See http://code.google.com/apis/talk/jep_extensions/gmail.html#response"
87 (let ((ts (jabber-xml-node-children
88 (car (jabber-xml-get-children xml-sexp 'mailbox)))))
89 (when ts (jabber-gmail-dothreads ts))))
90
91 (defun jabber-gmail-dothreads (threads)
92 "Process <mail-thread-info/> elements.
93 THREADS is a list of XML sexps, corresponding to <mail-thread-info/> elements.
94 See http://code.google.com/apis/talk/jep_extensions/gmail.html#response"
95 (message "%d new messages in gmail inbox" (length threads)))
96
97 (provide 'jabber-gmail)
98 ;; arch-tag: 102bc8e4-e08f-11dc-ab66-000a95c2fcd0