2 * Purple's oscar protocol plugin
3 * This file is the legal property of its developers.
4 * Please see the AUTHORS file distributed alongside this file.
6 * This library is free software; you can redistribute it and/or
7 * modify it under the terms of the GNU Lesser General Public
8 * License as published by the Free Software Foundation; either
9 * version 2 of the License, or (at your option) any later version.
11 * This library 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 GNU
14 * Lesser General Public License for more details.
16 * You should have received a copy of the GNU Lesser General Public
17 * License along with this library; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA
22 * Family 0x0018 - Email notification
24 * Used for being alerted when the email address(es) associated with
25 * your username get new electronic-m. For normal AIM accounts, you
26 * get the email address username@netscape.net. AOL accounts have
27 * username@aol.com, and can also activate a netscape.net account.
28 * Note: This information might be out of date.
34 * Subtype 0x0006 - Request information about your email account
36 * @param od The oscar session.
37 * @param conn The email connection for this session.
38 * @return Return 0 if no errors, otherwise return the error number.
41 aim_email_sendcookies(OscarData
*od
)
47 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_ALERT
)))
50 byte_stream_new(&bs
, 2+16+16);
52 /* Number of cookies to follow */
53 byte_stream_put16(&bs
, 0x0002);
56 byte_stream_put16(&bs
, 0x5d5e);
57 byte_stream_put16(&bs
, 0x1708);
58 byte_stream_put16(&bs
, 0x55aa);
59 byte_stream_put16(&bs
, 0x11d3);
60 byte_stream_put16(&bs
, 0xb143);
61 byte_stream_put16(&bs
, 0x0060);
62 byte_stream_put16(&bs
, 0xb0fb);
63 byte_stream_put16(&bs
, 0x1ecb);
66 byte_stream_put16(&bs
, 0xb380);
67 byte_stream_put16(&bs
, 0x9ad8);
68 byte_stream_put16(&bs
, 0x0dba);
69 byte_stream_put16(&bs
, 0x11d5);
70 byte_stream_put16(&bs
, 0x9f8a);
71 byte_stream_put16(&bs
, 0x0060);
72 byte_stream_put16(&bs
, 0xb0ee);
73 byte_stream_put16(&bs
, 0x0631);
75 snacid
= aim_cachesnac(od
, SNAC_FAMILY_ALERT
, 0x0006, 0x0000, NULL
, 0);
76 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_ALERT
, 0x0006, snacid
, &bs
);
78 byte_stream_destroy(&bs
);
85 * Subtype 0x0007 - Receive information about your email account
87 * So I don't even know if you can have multiple 16 byte keys,
88 * but this is coded so it will handle that, and handle it well.
89 * This tells you if you have unread mail or not, the URL you
90 * should use to access that mail, and the domain name for the
91 * email account (username@domainname.com). If this is the
92 * first 0x0007 SNAC you've received since you signed on, or if
93 * this is just a periodic status update, this will also contain
94 * the number of unread emails that you have.
97 parseinfo(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
100 aim_rxcallback_t userfunc
;
101 struct aim_emailinfo
*new;
103 guint8
*cookie8
, *cookie16
;
104 int tmp
, havenewmail
= 0; /* Used to tell the client we have _new_ mail */
106 char *alertitle
= NULL
, *alerturl
= NULL
;
108 cookie8
= byte_stream_getraw(bs
, 8); /* Possibly the code used to log you in to mail? */
109 cookie16
= byte_stream_getraw(bs
, 16); /* Mail cookie sent above */
111 /* See if we already have some info associated with this cookie */
112 for (new = od
->emailinfo
; (new && memcmp(cookie16
, new->cookie16
, 16)); new = new->next
);
114 /* Free some of the old info, if it exists */
115 g_free(new->cookie8
);
116 g_free(new->cookie16
);
120 /* We don't already have info, so create a new struct for it */
121 new = g_new0(struct aim_emailinfo
, 1);
122 new->next
= od
->emailinfo
;
126 new->cookie8
= cookie8
;
127 new->cookie16
= cookie16
;
129 tlvlist
= aim_tlvlist_readnum(bs
, byte_stream_get16(bs
));
131 tmp
= aim_tlv_get16(tlvlist
, 0x0080, 1);
133 if (new->nummsgs
< tmp
)
137 /* If they don't send a 0x0080 TLV, it means we definitely have new mail */
138 /* (ie. this is not just another status update) */
140 new->nummsgs
++; /* We know we have at least 1 new email */
142 new->url
= aim_tlv_getstr(tlvlist
, 0x0007, 1);
143 if (!(new->unread
= aim_tlv_get8(tlvlist
, 0x0081, 1))) {
147 new->domain
= aim_tlv_getstr(tlvlist
, 0x0082, 1);
148 new->flag
= aim_tlv_get16(tlvlist
, 0x0084, 1);
150 alertitle
= aim_tlv_getstr(tlvlist
, 0x0005, 1);
151 alerturl
= aim_tlv_getstr(tlvlist
, 0x000d, 1);
153 if ((userfunc
= aim_callhandler(od
, snac
->family
, snac
->subtype
)))
154 ret
= userfunc(od
, conn
, frame
, new, havenewmail
, alertitle
, (alerturl
? alerturl
+ 2 : NULL
));
156 aim_tlvlist_free(tlvlist
);
165 * Subtype 0x0016 - Send something or other
167 * @param od The oscar session.
168 * @param conn The email connection for this session.
169 * @return Return 0 if no errors, otherwise return the error number.
172 aim_email_activate(OscarData
*od
)
174 FlapConnection
*conn
;
178 if (!od
|| !(conn
= flap_connection_findbygroup(od
, SNAC_FAMILY_ALERT
)))
181 byte_stream_new(&bs
, 1+16);
183 /* I would guess this tells AIM that you want updates for your mail accounts */
184 /* ...but I really have no idea */
185 byte_stream_put8(&bs
, 0x02);
186 byte_stream_put32(&bs
, 0x04000000);
187 byte_stream_put32(&bs
, 0x04000000);
188 byte_stream_put32(&bs
, 0x04000000);
189 byte_stream_put32(&bs
, 0x00000000);
191 snacid
= aim_cachesnac(od
, SNAC_FAMILY_ALERT
, 0x0016, 0x0000, NULL
, 0);
192 flap_connection_send_snac(od
, conn
, SNAC_FAMILY_ALERT
, 0x0006, snacid
, &bs
);
194 byte_stream_destroy(&bs
);
200 snachandler(OscarData
*od
, FlapConnection
*conn
, aim_module_t
*mod
, FlapFrame
*frame
, aim_modsnac_t
*snac
, ByteStream
*bs
)
202 if (snac
->subtype
== 0x0007)
203 return parseinfo(od
, conn
, mod
, frame
, snac
, bs
);
209 email_shutdown(OscarData
*od
, aim_module_t
*mod
)
211 while (od
->emailinfo
)
213 struct aim_emailinfo
*tmp
= od
->emailinfo
;
214 od
->emailinfo
= od
->emailinfo
->next
;
215 g_free(tmp
->cookie16
);
216 g_free(tmp
->cookie8
);
226 email_modfirst(OscarData
*od
, aim_module_t
*mod
)
228 mod
->family
= SNAC_FAMILY_ALERT
;
229 mod
->version
= 0x0001;
230 mod
->toolid
= 0x0010;
231 mod
->toolversion
= 0x0629;
233 strncpy(mod
->name
, "alert", sizeof(mod
->name
));
234 mod
->snachandler
= snachandler
;
235 mod
->shutdown
= email_shutdown
;