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