source: libfaim/email.c @ 8c46404

barnowl_perlaimdebianowlrelease-1.10release-1.4release-1.5release-1.6release-1.7release-1.8release-1.9
Last change on this file since 8c46404 was e374dee, checked in by James M. Kretchmar <kretch@mit.edu>, 20 years ago
*** empty log message ***
  • Property mode set to 100644
File size: 5.7 KB
Line 
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
14/**
15 * Subtype 0x0006 - Request information about your email account
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.
20 */
21faim_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
63/**
64 * Subtype 0x0007 - Receive information about your email account
65 *
66 * So I don't even know if you can have multiple 16 byte keys,
67 * but this is coded so it will handle that, and handle it well.
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.
74 */
75static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
76{
77        int ret = 0;
78        aim_rxcallback_t userfunc;
79        struct aim_emailinfo *new;
80        aim_tlvlist_t *tlvlist;
81        fu8_t *cookie8, *cookie16;
82        int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */
83
84        cookie8 = aimbs_getraw(bs, 8); /* Possibly the code used to log you in to mail? */
85        cookie16 = aimbs_getraw(bs, 16); /* Mail cookie sent above */
86
87        /* See if we already have some info associated with this cookie */
88        for (new=sess->emailinfo; (new && strncmp(cookie16, new->cookie16, 16)); new=new->next);
89        if (new) {
90                /* Free some of the old info, if existant */
91                free(new->cookie8);
92                free(new->cookie16);
93                free(new->url);
94                free(new->domain);
95        } else {
96                /* We don't already have info, so create a new struct for it */
97                if (!(new = malloc(sizeof(struct aim_emailinfo))))
98                        return -ENOMEM;
99                memset(new, 0, sizeof(struct aim_emailinfo));
100                new->next = sess->emailinfo;
101                sess->emailinfo = new;
102        }
103
104        new->cookie8 = cookie8;
105        new->cookie16 = cookie16;
106
107        tlvlist = aim_readtlvchain_num(bs, aimbs_get16(bs));
108
109        tmp = aim_gettlv16(tlvlist, 0x0080, 1);
110        if (tmp) {
111                if (new->nummsgs < tmp)
112                        havenewmail = 1;
113                new->nummsgs = tmp;
114        } else {
115                /* If they don't send a 0x0080 TLV, it means we definately have new mail */
116                /* (ie. this is not just another status update) */
117                havenewmail = 1;
118                new->nummsgs++; /* We know we have at least 1 new email */
119        }
120        new->url = aim_gettlv_str(tlvlist, 0x0007, 1);
121        if (!(new->unread = aim_gettlv8(tlvlist, 0x0081, 1))) {
122                havenewmail = 0;
123                new->nummsgs = 0;
124        }
125        new->domain = aim_gettlv_str(tlvlist, 0x0082, 1);
126        new->flag = aim_gettlv16(tlvlist, 0x0084, 1);
127
128        if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
129                ret = userfunc(sess, rx, new, havenewmail);
130
131        aim_freetlvchain(&tlvlist);
132
133        return ret;
134}
135
136/**
137 * Subtype 0x0016 - Send something or other
138 *
139 * @param sess The oscar session.
140 * @param conn The email connection for this session.
141 * @return Return 0 if no errors, otherwise return the error number.
142 */
143faim_export int aim_email_activate(aim_session_t *sess, aim_conn_t *conn)
144{
145        aim_frame_t *fr;
146        aim_snacid_t snacid;
147
148        if (!sess || !conn)
149                return -EINVAL;
150
151        if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+16)))
152                return -ENOMEM;
153        snacid = aim_cachesnac(sess, 0x0018, 0x0016, 0x0000, NULL, 0);
154        aim_putsnac(&fr->data, 0x0018, 0x0016, 0x0000, snacid);
155
156        /* I would guess this tells AIM that you want updates for your mail accounts */
157        /* ...but I really have no idea */
158        aimbs_put8(&fr->data, 0x02);
159        aimbs_put32(&fr->data, 0x04000000);
160        aimbs_put32(&fr->data, 0x04000000);
161        aimbs_put32(&fr->data, 0x04000000);
162        aimbs_put32(&fr->data, 0x00000000);
163
164        aim_tx_enqueue(sess, fr);
165
166        return 0;
167}
168
169static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
170{
171
172        if (snac->subtype == 0x0007)
173                return parseinfo(sess, mod, rx, snac, bs);
174
175        return 0;
176}
177
178static void email_shutdown(aim_session_t *sess, aim_module_t *mod)
179{
180        while (sess->emailinfo) {
181                struct aim_emailinfo *tmp = sess->emailinfo;
182                sess->emailinfo = sess->emailinfo->next;
183                free(tmp->cookie16);
184                free(tmp->cookie8);
185                free(tmp->url);
186                free(tmp->domain);
187                free(tmp);
188        }
189
190        return;
191}
192
193faim_internal int email_modfirst(aim_session_t *sess, aim_module_t *mod)
194{
195
196        mod->family = 0x0018;
197        mod->version = 0x0001;
198        mod->toolid = 0x0010;
199        mod->toolversion = 0x0629;
200        mod->flags = 0;
201        strncpy(mod->name, "email", sizeof(mod->name));
202        mod->snachandler = snachandler;
203        mod->shutdown = email_shutdown;
204
205        return 0;
206}
Note: See TracBrowser for help on using the repository browser.