Mercurial > pidgin
comparison libgaim/protocols/jabber/google.c @ 15163:fe05223b5d04
[gaim-migrate @ 17949]
Gmail notifications patch from Chris Stafford
- The plugin will only do anything if it sees "google:mail:notify" in disco.
- I decided to give Jabber a mail notification option for this, since the
feature has traditionally meant "notify me of new mail if I happen to have
a mail account that this server will notify me of"
- I decided to show the first unread mail in a thread, rather than all unread
messages[A
- I made a google.c/google.h file to keep code for Google Talk extensions
committer: Tailor Script <tailor@pidgin.im>
author | Sean Egan <seanegan@gmail.com> |
---|---|
date | Sun, 10 Dec 2006 23:08:45 +0000 |
parents | |
children | b52cdf3cff4f |
comparison
equal
deleted
inserted
replaced
15162:96f3a7286375 | 15163:fe05223b5d04 |
---|---|
1 | |
2 /** | |
3 * Gaim is the legal property of its developers, whose names are too numerous | |
4 * to list here. Please refer to the COPYRIGHT file distributed with this | |
5 * source distribution. | |
6 * | |
7 * This program is free software; you can redistribute it and/or modify | |
8 * it under the terms of the GNU General Public License as published by | |
9 * the Free Software Foundation; either version 2 of the License, or | |
10 * (at your option) any later version. | |
11 * | |
12 * This program is distributed in the hope that it will be useful, | |
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 * GNU General Public License for more details. | |
16 * | |
17 * You should have received a copy of the GNU General Public License | |
18 * along with this program; if not, write to the Free Software | |
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
20 */ | |
21 | |
22 #include "internal.h" | |
23 #include "debug.h" | |
24 #include "google.h" | |
25 #include "jabber.h" | |
26 #include "iq.h" | |
27 | |
28 static void | |
29 jabber_gmail_parse(JabberStream *js, xmlnode *packet, gpointer nul) | |
30 { | |
31 const char *type = xmlnode_get_attrib(packet, "type"); | |
32 xmlnode *child; | |
33 xmlnode *message, *sender_node, *subject_node; | |
34 const char *from, *to, *subject, *url, *tid; | |
35 const char *in_str; | |
36 char *to_name; | |
37 int i, count = 1, returned_count; | |
38 | |
39 const char **tos, **froms, **subjects, **urls; | |
40 | |
41 if (strcmp(type, "result")) | |
42 return; | |
43 | |
44 child = xmlnode_get_child(packet, "mailbox"); | |
45 if (!child) | |
46 return; | |
47 | |
48 in_str = xmlnode_get_attrib(child, "total-matched"); | |
49 if (in_str && *in_str) | |
50 count = atoi(in_str); | |
51 | |
52 if (count == 0) | |
53 return; | |
54 | |
55 message = xmlnode_get_child(child, "mail-thread-info"); | |
56 | |
57 /* Loop once to see how many messages were returned so we can allocate arrays | |
58 * accordingly */ | |
59 if (!message) | |
60 return; | |
61 for (returned_count = 0; message; returned_count++, message=xmlnode_get_next_twin(message)); | |
62 | |
63 froms = g_new0(const char* , returned_count); | |
64 tos = g_new0(const char* , returned_count); | |
65 subjects = g_new0(const char* , returned_count); | |
66 urls = g_new0(const char* , returned_count); | |
67 | |
68 to = xmlnode_get_attrib(packet, "to"); | |
69 to_name = jabber_get_bare_jid(to); | |
70 url = xmlnode_get_attrib(child, "url"); | |
71 if (!url || !*url) | |
72 url = "http://www.gmail.com"; | |
73 | |
74 message= xmlnode_get_child(child, "mail-thread-info"); | |
75 for (i=0; message; message = xmlnode_get_next_twin(message), i++) { | |
76 subject_node = xmlnode_get_child(message, "subject"); | |
77 sender_node = xmlnode_get_child(message, "senders"); | |
78 sender_node = xmlnode_get_child(sender_node, "sender"); | |
79 | |
80 while (sender_node && (!xmlnode_get_attrib(sender_node, "unread") || | |
81 !strcmp(xmlnode_get_attrib(sender_node, "unread"),"0"))) | |
82 sender_node = xmlnode_get_next_twin(sender_node); | |
83 | |
84 if (!sender_node) { | |
85 i--; | |
86 continue; | |
87 } | |
88 | |
89 from = xmlnode_get_attrib(sender_node, "name"); | |
90 if (!from || !*from) | |
91 from = xmlnode_get_attrib(sender_node, "address"); | |
92 subject = xmlnode_get_data(subject_node); | |
93 /* | |
94 * url = xmlnode_get_attrib(message, "url"); | |
95 */ | |
96 tos[i] = (to_name != NULL ? to_name : ""); | |
97 froms[i] = (from != NULL ? from : ""); | |
98 subjects[i] = (subject != NULL ? subject : ""); | |
99 urls[i] = (url != NULL ? url : ""); | |
100 | |
101 tid = xmlnode_get_attrib(message, "tid"); | |
102 if (tid && | |
103 (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) { | |
104 g_free(js->gmail_last_tid); | |
105 js->gmail_last_tid = g_strdup(tid); | |
106 } | |
107 } | |
108 | |
109 if (i>0) | |
110 gaim_notify_emails(js->gc, returned_count, TRUE, subjects, froms, tos, | |
111 urls, NULL, js->gc->account); | |
112 g_free(to_name); | |
113 g_free(tos); | |
114 g_free(froms); | |
115 g_free(subjects); | |
116 g_free(urls); | |
117 | |
118 in_str = xmlnode_get_attrib(child, "result-time"); | |
119 if (in_str && *in_str) { | |
120 g_free(js->gmail_last_time); | |
121 js->gmail_last_time = g_strdup(in_str); | |
122 } | |
123 } | |
124 | |
125 void | |
126 jabber_gmail_poke(JabberStream *js, xmlnode *packet) | |
127 { | |
128 const char *type; | |
129 xmlnode *query; | |
130 JabberIq *iq; | |
131 | |
132 /* bail if the user isn't interested */ | |
133 if (!gaim_account_get_check_mail(js->gc->account)) | |
134 return; | |
135 | |
136 type = xmlnode_get_attrib(packet, "type"); | |
137 | |
138 | |
139 /* Is this an initial incoming mail notification? If so, send a request for more info */ | |
140 if (strcmp(type, "set") || !xmlnode_get_child(packet, "new-mail")) | |
141 return; | |
142 | |
143 gaim_debug(GAIM_DEBUG_MISC, "jabber", | |
144 "Got new mail notification. Sending request for more info\n"); | |
145 | |
146 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "google:mail:notify"); | |
147 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); | |
148 query = xmlnode_get_child(iq->node, "query"); | |
149 | |
150 if (js->gmail_last_time) | |
151 xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time); | |
152 if (js->gmail_last_tid) | |
153 xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid); | |
154 | |
155 jabber_iq_send(iq); | |
156 return; | |
157 } | |
158 | |
159 void jabber_gmail_init(JabberStream *js) { | |
160 JabberIq *iq; | |
161 | |
162 if (!gaim_account_get_check_mail(js->gc->account)) | |
163 return; | |
164 | |
165 iq = jabber_iq_new_query(js, JABBER_IQ_GET, "google:mail:notify"); | |
166 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); | |
167 jabber_iq_send(iq); | |
168 } |