libpurple/protocols/jabber/google/gmail.c

Fri, 01 May 2020 04:42:52 -0500

author
Gary Kramlich <grim@reaperworld.com>
date
Fri, 01 May 2020 04:42:52 -0500
changeset 40358
e6fe6fc1f516
parent 40131
00bfb6134525
child 40439
e9838d634d5e
permissions
-rw-r--r--

move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually

29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
1 /**
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
2 * Purple is the legal property of its developers, whose names are too numerous
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
3 * to list here. Please refer to the COPYRIGHT file distributed with this
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
4 * source distribution.
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
5 *
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
6 * This program is free software; you can redistribute it and/or modify
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
7 * it under the terms of the GNU General Public License as published by
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
8 * the Free Software Foundation; either version 2 of the License, or
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
9 * (at your option) any later version.
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
10 *
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
11 * This program is distributed in the hope that it will be useful,
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
14 * GNU General Public License for more details.
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
15 *
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
16 * You should have received a copy of the GNU General Public License
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
17 * along with this program; if not, write to the Free Software
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
19 */
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
20
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
21 #include "internal.h"
40358
e6fe6fc1f516 move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents: 40131
diff changeset
22 #include <purple.h>
e6fe6fc1f516 move all protocols, purple plugins, and purple tests to use purple.h instead of including files individually
Gary Kramlich <grim@reaperworld.com>
parents: 40131
diff changeset
23
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
24 #include "jabber.h"
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
25 #include "gmail.h"
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
26
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
27 static void
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
28 jabber_gmail_parse(JabberStream *js, const char *from,
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
29 JabberIqType type, const char *id,
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
30 PurpleXmlNode *packet, gpointer nul)
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
31 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
32 PurpleXmlNode *child;
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
33 PurpleXmlNode *message;
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
34 const char *to, *url;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
35 const char *in_str;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
36 char *to_name;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
37
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
38 int i, count = 1, returned_count;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
39
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
40 const char **tos, **froms, **urls;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
41 char **subjects;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
42
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
43 if (type == JABBER_IQ_ERROR)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
44 return;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
45
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
46 child = purple_xmlnode_get_child(packet, "mailbox");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
47 if (!child)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
48 return;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
49
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
50 in_str = purple_xmlnode_get_attrib(child, "total-matched");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
51 if (in_str && *in_str)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
52 count = atoi(in_str);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
53
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
54 /* If Gmail doesn't tell us who the mail is to, let's use our JID */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
55 to = purple_xmlnode_get_attrib(packet, "to");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
56
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
57 message = purple_xmlnode_get_child(child, "mail-thread-info");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
58
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
59 if (count == 0 || !message) {
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
60 if (count > 0) {
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
61 char *bare_jid = jabber_get_bare_jid(to);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
62 const char *default_tos[2] = { bare_jid };
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
63
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
64 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, default_tos, NULL, NULL, NULL);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
65 g_free(bare_jid);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
66 } else {
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
67 purple_notify_emails(js->gc, count, FALSE, NULL, NULL, NULL, NULL, NULL, NULL);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
68 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
69
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
70 return;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
71 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
72
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
73 /* Loop once to see how many messages were returned so we can allocate arrays
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
74 * accordingly */
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
75 for (returned_count = 0; message; returned_count++, message=purple_xmlnode_get_next_twin(message));
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
76
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
77 froms = g_new0(const char* , returned_count + 1);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
78 tos = g_new0(const char* , returned_count + 1);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
79 subjects = g_new0(char* , returned_count + 1);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
80 urls = g_new0(const char* , returned_count + 1);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
81
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
82 to = purple_xmlnode_get_attrib(packet, "to");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
83 to_name = jabber_get_bare_jid(to);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
84 url = purple_xmlnode_get_attrib(child, "url");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
85 if (!url || !*url)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
86 url = "http://www.gmail.com";
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
87
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
88 message= purple_xmlnode_get_child(child, "mail-thread-info");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
89 for (i=0; message; message = purple_xmlnode_get_next_twin(message), i++) {
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
90 PurpleXmlNode *sender_node, *subject_node;
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
91 const char *from, *tid;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
92 char *subject;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
93
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
94 subject_node = purple_xmlnode_get_child(message, "subject");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
95 sender_node = purple_xmlnode_get_child(message, "senders");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
96 sender_node = purple_xmlnode_get_child(sender_node, "sender");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
97
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
98 while (sender_node && (!purple_xmlnode_get_attrib(sender_node, "unread") ||
38358
30ba44276e74 Merge release-2.x.y into default
dx <dx@dxzone.com.ar>
parents: 34935 38261
diff changeset
99 purple_strequal(purple_xmlnode_get_attrib(sender_node, "unread"),"0")))
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
100 sender_node = purple_xmlnode_get_next_twin(sender_node);
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
101
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
102 if (!sender_node) {
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
103 i--;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
104 continue;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
105 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
106
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
107 from = purple_xmlnode_get_attrib(sender_node, "name");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
108 if (!from || !*from)
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
109 from = purple_xmlnode_get_attrib(sender_node, "address");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
110 subject = purple_xmlnode_get_data(subject_node);
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
111 /*
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
112 * url = purple_xmlnode_get_attrib(message, "url");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
113 */
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
114 tos[i] = (to_name != NULL ? to_name : "");
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
115 froms[i] = (from != NULL ? from : "");
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
116 subjects[i] = (subject != NULL ? subject : g_strdup(""));
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
117 urls[i] = url;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
118
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
119 tid = purple_xmlnode_get_attrib(message, "tid");
38261
653645acccc8 Use g_strcmp0() for code simplification
qarkai <qarkai@gmail.com>
parents: 38258
diff changeset
120 if (g_strcmp0(tid, js->gmail_last_tid) > 0) {
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
121 g_free(js->gmail_last_tid);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
122 js->gmail_last_tid = g_strdup(tid);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
123 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
124 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
125
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
126 if (i>0)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
127 purple_notify_emails(js->gc, count, count == i, (const char**) subjects, froms, tos,
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
128 urls, NULL, NULL);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
129
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
130 g_free(to_name);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
131 g_free(tos);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
132 g_free(froms);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
133 for (i = 0; i < returned_count; i++)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
134 g_free(subjects[i]);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
135 g_free(subjects);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
136 g_free(urls);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
137
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
138 in_str = purple_xmlnode_get_attrib(child, "result-time");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
139 if (in_str && *in_str) {
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
140 g_free(js->gmail_last_time);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
141 js->gmail_last_time = g_strdup(in_str);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
142 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
143 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
144
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
145 void
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
146 jabber_gmail_poke(JabberStream *js, const char *from, JabberIqType type,
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
147 const char *id, PurpleXmlNode *new_mail)
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
148 {
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
149 PurpleXmlNode *query;
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
150 JabberIq *iq;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
151
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
152 /* bail if the user isn't interested */
32438
dc8991868906 A boring and large patch so I can merge heads.
Elliott Sales de Andrade <qulogic@pidgin.im>
parents: 29914
diff changeset
153 if (!purple_account_get_check_mail(purple_connection_get_account(js->gc)))
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
154 return;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
155
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
156 /* Is this an initial incoming mail notification? If so, send a request for more info */
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
157 if (type != JABBER_IQ_SET)
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
158 return;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
159
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
160 /* Acknowledge the notification */
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
161 iq = jabber_iq_new(js, JABBER_IQ_RESULT);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
162 if (from)
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
163 purple_xmlnode_set_attrib(iq->node, "to", from);
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
164 purple_xmlnode_set_attrib(iq->node, "id", id);
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
165 jabber_iq_send(iq);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
166
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
167 purple_debug_misc("jabber",
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
168 "Got new mail notification. Sending request for more info\n");
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
169
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
170 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
171 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
172 query = purple_xmlnode_get_child(iq->node, "query");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
173
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
174 if (js->gmail_last_time)
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
175 purple_xmlnode_set_attrib(query, "newer-than-time", js->gmail_last_time);
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
176 if (js->gmail_last_tid)
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
177 purple_xmlnode_set_attrib(query, "newer-than-tid", js->gmail_last_tid);
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
178
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
179 jabber_iq_send(iq);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
180 }
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
181
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
182 void jabber_gmail_init(JabberStream *js) {
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
183 JabberIq *iq;
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
184 PurpleXmlNode *usersetting, *mailnotifications;
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
185
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
186 if (!purple_account_get_check_mail(purple_connection_get_account(js->gc)))
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
187 return;
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
188
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
189 /*
33956
84f5fef32685 Fix and/or canonicalize a few URLs.
Mark Doliner <mark@kingant.net>
parents: 32438
diff changeset
190 * Quoting https://developers.google.com/talk/jep_extensions/usersettings:
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
191 * To ensure better compatibility with other clients, rather than
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
192 * setting this value to "false" to turn off notifications, it is
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
193 * recommended that a client set this to "true" and filter incoming
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
194 * email notifications itself.
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
195 */
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
196 iq = jabber_iq_new(js, JABBER_IQ_SET);
34935
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
197 usersetting = purple_xmlnode_new_child(iq->node, "usersetting");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
198 purple_xmlnode_set_namespace(usersetting, "google:setting");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
199 mailnotifications = purple_xmlnode_new_child(usersetting, "mailnotifications");
686fa55b0deb Replaced xmlnode with PurpleXmlNode, and xmlnode_* API with purple_xmlnode_* API
Ankit Vani <a@nevitus.org>
parents: 33956
diff changeset
200 purple_xmlnode_set_attrib(mailnotifications, "value", "true");
29914
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
201 jabber_iq_send(iq);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
202
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
203 iq = jabber_iq_new_query(js, JABBER_IQ_GET, NS_GOOGLE_MAIL_NOTIFY);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
204 jabber_iq_set_callback(iq, jabber_gmail_parse, NULL);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
205 jabber_iq_send(iq);
a4ed5999f6d0 Added new files in sub directory google
Marcus Lundblad <malu@pidgin.im>
parents:
diff changeset
206 }

mercurial