source: libfaim/email.c @ 5d9c664

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