3694
|
1 /*
|
|
2 * Family 0x0018 - Email notification
|
|
3 *
|
|
4 * Used for being alerted when the email address(es) associated with
|
|
5 * your screen name get new electronic-m. For normal AIM accounts, you
|
|
6 * get the email address screenname@netscape.net. AOL accounts have
|
|
7 * screenname@aol.com, and can also activate a netscape.net account.
|
|
8 *
|
|
9 */
|
|
10
|
|
11 #define FAIM_INTERNAL
|
|
12 #include <aim.h>
|
|
13
|
3725
|
14 /**
|
3694
|
15 * Subtype 0x0006 - Request information about your email account
|
3725
|
16 *
|
|
17 * @param sess The oscar session.
|
|
18 * @param conn The email connection for this session.
|
|
19 * @return Return 0 if no errors, otherwise return the error number.
|
3694
|
20 */
|
|
21 faim_export int aim_email_sendcookies(aim_session_t *sess, aim_conn_t *conn)
|
|
22 {
|
|
23 aim_frame_t *fr;
|
|
24 aim_snacid_t snacid;
|
|
25
|
|
26 if (!sess || !conn)
|
|
27 return -EINVAL;
|
|
28
|
|
29 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16+16)))
|
|
30 return -ENOMEM;
|
|
31 snacid = aim_cachesnac(sess, 0x0018, 0x0006, 0x0000, NULL, 0);
|
|
32 aim_putsnac(&fr->data, 0x0018, 0x0006, 0x0000, snacid);
|
|
33
|
|
34 /* Number of cookies to follow */
|
|
35 aimbs_put16(&fr->data, 0x0002);
|
|
36
|
|
37 /* Cookie */
|
|
38 aimbs_put16(&fr->data, 0x5d5e);
|
|
39 aimbs_put16(&fr->data, 0x1708);
|
|
40 aimbs_put16(&fr->data, 0x55aa);
|
|
41 aimbs_put16(&fr->data, 0x11d3);
|
|
42 aimbs_put16(&fr->data, 0xb143);
|
|
43 aimbs_put16(&fr->data, 0x0060);
|
|
44 aimbs_put16(&fr->data, 0xb0fb);
|
|
45 aimbs_put16(&fr->data, 0x1ecb);
|
|
46
|
|
47 /* Cookie */
|
|
48 aimbs_put16(&fr->data, 0xb380);
|
|
49 aimbs_put16(&fr->data, 0x9ad8);
|
|
50 aimbs_put16(&fr->data, 0x0dba);
|
|
51 aimbs_put16(&fr->data, 0x11d5);
|
|
52 aimbs_put16(&fr->data, 0x9f8a);
|
|
53 aimbs_put16(&fr->data, 0x0060);
|
|
54 aimbs_put16(&fr->data, 0xb0ee);
|
|
55 aimbs_put16(&fr->data, 0x0631);
|
|
56
|
|
57 aim_tx_enqueue(sess, fr);
|
|
58
|
|
59 return 0;
|
|
60 }
|
|
61
|
|
62
|
3725
|
63 /**
|
3694
|
64 * Subtype 0x0007 - Receive information about your email account
|
4804
|
65 *
|
3725
|
66 * So I don't even know if you can have multiple 16 byte keys,
|
3694
|
67 * but this is coded so it will handle that, and handle it well.
|
3725
|
68 * This tells you if you have unread mail or not, the URL you
|
|
69 * should use to access that mail, and the domain name for the
|
|
70 * email account (screenname@domainname.com). If this is the
|
|
71 * first 0x0007 SNAC you've received since you signed on, or if
|
|
72 * this is just a periodic status update, this will also contain
|
|
73 * the number of unread emails that you have.
|
3694
|
74 */
|
|
75 static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
76 {
|
|
77 aim_rxcallback_t userfunc;
|
|
78 struct aim_emailinfo *new;
|
|
79 aim_tlvlist_t *tlvlist;
|
|
80 fu8_t *cookie8, *cookie16;
|
3725
|
81 int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */
|
3694
|
82
|
|
83 cookie8 = aimbs_getraw(bs, 8); /* Possibly the code used to log you in to mail? */
|
|
84 cookie16 = aimbs_getraw(bs, 16); /* Mail cookie sent above */
|
|
85
|
|
86 /* See if we already have some info associated with this cookie */
|
|
87 for (new=sess->emailinfo; (new && strncmp(cookie16, new->cookie16, 16)); new=new->next);
|
|
88 if (new) {
|
|
89 /* Free some of the old info, if existant */
|
3952
|
90 free(new->cookie8);
|
|
91 free(new->cookie16);
|
|
92 free(new->url);
|
|
93 free(new->domain);
|
3694
|
94 } else {
|
|
95 /* We don't already have info, so create a new struct for it */
|
|
96 if (!(new = malloc(sizeof(struct aim_emailinfo))))
|
|
97 return -ENOMEM;
|
3725
|
98 memset(new, 0, sizeof(struct aim_emailinfo));
|
3694
|
99 new->next = sess->emailinfo;
|
|
100 sess->emailinfo = new;
|
|
101 }
|
|
102
|
|
103 new->cookie8 = cookie8;
|
|
104 new->cookie16 = cookie16;
|
|
105
|
3952
|
106 tlvlist = aim_readtlvchain_num(bs, aimbs_get16(bs));
|
3694
|
107
|
3725
|
108 tmp = aim_gettlv16(tlvlist, 0x0080, 1);
|
|
109 if (tmp) {
|
|
110 if (new->nummsgs < tmp)
|
|
111 havenewmail = 1;
|
|
112 new->nummsgs = tmp;
|
|
113 } else {
|
|
114 /* If they don't send a 0x0080 TLV, it means we definately have new mail */
|
|
115 /* (ie. this is not just another status update) */
|
|
116 havenewmail = 1;
|
|
117 new->nummsgs++; /* We know we have at least 1 new email */
|
|
118 }
|
3694
|
119 new->url = aim_gettlv_str(tlvlist, 0x0007, 1);
|
3725
|
120 if (!(new->unread = aim_gettlv8(tlvlist, 0x0081, 1))) {
|
|
121 havenewmail = 0;
|
|
122 new->nummsgs = 0;
|
|
123 }
|
3694
|
124 new->domain = aim_gettlv_str(tlvlist, 0x0082, 1);
|
|
125 new->flag = aim_gettlv16(tlvlist, 0x0084, 1);
|
|
126
|
|
127 if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
|
3725
|
128 return userfunc(sess, rx, new, havenewmail);
|
3694
|
129
|
|
130 return 0;
|
|
131 }
|
|
132
|
3725
|
133 /**
|
3694
|
134 * Subtype 0x0016 - Send something or other
|
3725
|
135 *
|
|
136 * @param sess The oscar session.
|
|
137 * @param conn The email connection for this session.
|
|
138 * @return Return 0 if no errors, otherwise return the error number.
|
3694
|
139 */
|
|
140 faim_export int aim_email_activate(aim_session_t *sess, aim_conn_t *conn)
|
|
141 {
|
|
142 aim_frame_t *fr;
|
|
143 aim_snacid_t snacid;
|
|
144
|
|
145 if (!sess || !conn)
|
|
146 return -EINVAL;
|
|
147
|
|
148 if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+16)))
|
|
149 return -ENOMEM;
|
|
150 snacid = aim_cachesnac(sess, 0x0018, 0x0016, 0x0000, NULL, 0);
|
|
151 aim_putsnac(&fr->data, 0x0018, 0x0016, 0x0000, snacid);
|
|
152
|
|
153 /* I would guess this tells AIM that you want updates for your mail accounts */
|
|
154 /* ...but I really have no idea */
|
|
155 aimbs_put8(&fr->data, 0x02);
|
|
156 aimbs_put32(&fr->data, 0x04000000);
|
|
157 aimbs_put32(&fr->data, 0x04000000);
|
|
158 aimbs_put32(&fr->data, 0x04000000);
|
|
159 aimbs_put32(&fr->data, 0x00000000);
|
|
160
|
|
161 aim_tx_enqueue(sess, fr);
|
|
162
|
|
163 return 0;
|
|
164 }
|
|
165
|
|
166 static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
|
|
167 {
|
|
168
|
|
169 if (snac->subtype == 0x0007)
|
|
170 return parseinfo(sess, mod, rx, snac, bs);
|
|
171
|
|
172 return 0;
|
|
173 }
|
|
174
|
|
175 static void email_shutdown(aim_session_t *sess, aim_module_t *mod)
|
|
176 {
|
|
177 while (sess->emailinfo) {
|
|
178 struct aim_emailinfo *tmp = sess->emailinfo;
|
|
179 sess->emailinfo = sess->emailinfo->next;
|
3952
|
180 free(tmp->cookie16);
|
|
181 free(tmp->cookie8);
|
|
182 free(tmp->url);
|
|
183 free(tmp->domain);
|
3694
|
184 free(tmp);
|
|
185 }
|
|
186
|
|
187 return;
|
|
188 }
|
|
189
|
|
190 faim_internal int email_modfirst(aim_session_t *sess, aim_module_t *mod)
|
|
191 {
|
|
192
|
|
193 mod->family = 0x0018;
|
|
194 mod->version = 0x0001;
|
|
195 mod->toolid = 0x0010;
|
|
196 mod->toolversion = 0x0629;
|
|
197 mod->flags = 0;
|
|
198 strncpy(mod->name, "email", sizeof(mod->name));
|
|
199 mod->snachandler = snachandler;
|
|
200 mod->shutdown = email_shutdown;
|
|
201
|
|
202 return 0;
|
|
203 }
|