Mercurial > pidgin.yaz
annotate libpurple/protocols/jabber/google/gmail.c @ 32767:2ec94166be43
On the way to hiding the PurpleConnection struct.
* Added purple_connection_get_flags() and purple_connection_set_flags()
* Use purple_connection_ accessor functions.
author | andrew.victor@mxit.com |
---|---|
date | Tue, 18 Oct 2011 18:47:48 +0000 |
parents | 34f586bffe4e |
children |
rev | line source |
---|---|
30906
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
1 /** |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
2 * Purple is the legal property of its developers, whose names are too numerous |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
3 * to list here. Please refer to the COPYRIGHT file distributed with this |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
4 * source distribution. |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
5 * |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
6 * This program is free software; you can redistribute it and/or modify |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
7 * it under the terms of the GNU General Public License as published by |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
8 * the Free Software Foundation; either version 2 of the License, or |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
9 * (at your option) any later version. |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
10 * |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
11 * This program is distributed in the hope that it will be useful, |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
14 * GNU General Public License for more details. |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
15 * |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
16 * You should have received a copy of the GNU General Public License |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
17 * along with this program; if not, write to the Free Software |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
19 */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
20 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
21 #include "internal.h" |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
22 #include "debug.h" |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
23 #include "jabber.h" |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
24 #include "gmail.h" |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
25 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
26 static void |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
27 jabber_gmail_parse(JabberStream *js, const char *from, |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
28 JabberIqType type, const char *id, |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
29 xmlnode *packet, gpointer nul) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
30 { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
31 xmlnode *child; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
32 xmlnode *message; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
33 const char *to, *url; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
34 const char *in_str; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
35 char *to_name; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
36 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
37 int i, count = 1, returned_count; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
38 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
39 const char **tos, **froms, **urls; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
40 char **subjects; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
41 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
42 if (type == JABBER_IQ_ERROR) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
43 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
44 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
45 child = xmlnode_get_child(packet, "mailbox"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
46 if (!child) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
47 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
48 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
49 in_str = xmlnode_get_attrib(child, "total-matched"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
50 if (in_str && *in_str) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
51 count = atoi(in_str); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
52 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
53 /* If Gmail doesn't tell us who the mail is to, let's use our JID */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
54 to = xmlnode_get_attrib(packet, "to"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
55 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
56 message = xmlnode_get_child(child, "mail-thread-info"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
57 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
58 if (count == 0 || !message) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
59 if (count > 0) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
60 char *bare_jid = jabber_get_bare_jid(to); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
61 const char *default_tos[2] = { bare_jid }; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
62 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
63 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, default_tos, NULL, NULL, NULL); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
64 g_free(bare_jid); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
65 } else { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
66 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, NULL, NULL, NULL, NULL); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
67 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
68 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
69 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
70 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
71 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
72 /* Loop once to see how many messages were returned so we can allocate arrays |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
73 * accordingly */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
74 for (returned_count = 0; message; returned_count++, message=xmlnode_get_next_twin(message)); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
75 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
76 froms = g_new0(const char* , returned_count + 1); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
77 tos = g_new0(const char* , returned_count + 1); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
78 subjects = g_new0(char* , returned_count + 1); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
79 urls = g_new0(const char* , returned_count + 1); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
80 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
81 to = xmlnode_get_attrib(packet, "to"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
82 to_name = jabber_get_bare_jid(to); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
83 url = xmlnode_get_attrib(child, "url"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
84 if (!url || !*url) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
85 url = "http://www.gmail.com"; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
86 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
87 message= xmlnode_get_child(child, "mail-thread-info"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
88 for (i=0; message; message = xmlnode_get_next_twin(message), i++) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
89 xmlnode *sender_node, *subject_node; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
90 const char *from, *tid; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
91 char *subject; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
92 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
93 subject_node = xmlnode_get_child(message, "subject"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
94 sender_node = xmlnode_get_child(message, "senders"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
95 sender_node = xmlnode_get_child(sender_node, "sender"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
96 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
97 while (sender_node && (!xmlnode_get_attrib(sender_node, "unread") || |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
98 !strcmp(xmlnode_get_attrib(sender_node, "unread"),"0"))) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
99 sender_node = xmlnode_get_next_twin(sender_node); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
100 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
101 if (!sender_node) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
102 i--; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
103 continue; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
104 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
105 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
106 from = xmlnode_get_attrib(sender_node, "name"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
107 if (!from || !*from) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
108 from = xmlnode_get_attrib(sender_node, "address"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
109 subject = xmlnode_get_data(subject_node); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
110 /* |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
111 * url = xmlnode_get_attrib(message, "url"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
112 */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
113 tos[i] = (to_name != NULL ? to_name : ""); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
114 froms[i] = (from != NULL ? from : ""); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
115 subjects[i] = (subject != NULL ? subject : g_strdup("")); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
116 urls[i] = url; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
117 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
118 tid = xmlnode_get_attrib(message, "tid"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
119 if (tid && |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
120 (js->gmail_last_tid == NULL || strcmp(tid, js->gmail_last_tid) > 0)) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
121 g_free(js->gmail_last_tid); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
122 js->gmail_last_tid = g_strdup(tid); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
123 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
124 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
125 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
126 if (i>0) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
127 purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos, |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
128 urls, NULL, NULL); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
129 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
130 g_free(to_name); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
131 g_free(tos); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
132 g_free(froms); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
133 for (i = 0; i < returned_count; i++) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
134 g_free(subjects[i]); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
135 g_free(subjects); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
136 g_free(urls); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
137 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
138 in_str = xmlnode_get_attrib(child, "result-time"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
139 if (in_str && *in_str) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
140 g_free(js->gmail_last_time); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
141 js->gmail_last_time = g_strdup(in_str); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
142 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
143 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
144 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
145 void |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
146 jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type, |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
147 const char *id, xmlnode *new_mail) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
148 { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
149 xmlnode *query; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
150 JabberIq *iq; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
151 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
152 /* bail if the user isn't interested */ |
32767
2ec94166be43
On the way to hiding the PurpleConnection struct.
andrew.victor@mxit.com
parents:
30906
diff
changeset
|
153 if (!purple_account_get_check_mail(purple_connection_get_account(js->gc))) |
30906
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
154 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
155 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
156 /* Is this an initial incoming mail notification? If so, send a request for more info */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
157 if (type != JABBER_IQ_SET) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
158 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
159 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
160 /* Acknowledge the notification */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
161 iq = jabber_iq_new(js, JABBER_IQ_RESULT); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
162 if (from) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
163 xmlnode_set_attrib(iq->node, "to", from); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
164 xmlnode_set_attrib(iq->node, "id", id); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
165 jabber_iq_send(iq); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
166 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
167 purple_debug_misc("jabber", |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
168 "Got new mail notification. Sending request for more info\n"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
169 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
170 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
171 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
172 query = xmlnode_get_child(iq->node, "query"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
173 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
174 if (js->gmail_last_time) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
175 xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
176 if (js->gmail_last_tid) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
177 xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
178 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
179 jabber_iq_send(iq); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
180 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
181 } |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
182 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
183 void jabber_gmail_init(JabberStream *js) { |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
184 JabberIq *iq; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
185 xmlnode *usersetting, *mailnotifications; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
186 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
187 if (!purple_account_get_check_mail(purple_connection_get_account(js->gc))) |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
188 return; |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
189 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
190 /* |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
191 * Quoting http://code.google.com/apis/talk/jep_extensions/usersettings.html: |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
192 * To ensure better compatibility with other clients, rather than |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
193 * setting this value to "false" to turn off notifications, it is |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
194 * recommended that a client set this to "true" and filter incoming |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
195 * email notifications itself. |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
196 */ |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
197 iq = jabber_iq_new(js, JABBER_IQ_SET); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
198 usersetting = xmlnode_new_child(iq->node, "usersetting"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
199 xmlnode_set_namespace(usersetting, "google:setting"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
200 mailnotifications = xmlnode_new_child(usersetting, "mailnotifications"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
201 xmlnode_set_attrib(mailnotifications, "value", "true"); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
202 jabber_iq_send(iq); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
203 |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
204 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
205 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
206 jabber_iq_send(iq); |
34f586bffe4e
Added new files in sub directory google
Marcus Lundblad <ml@update.uu.se>
parents:
diff
changeset
|
207 } |