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