Sat, 12 Nov 2005 15:27:41 +0000
[gaim-migrate @ 14345]
One parts doxygen one parts whitespace
| 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 | */ |
|
7282
73b94979f76b
[gaim-migrate @ 7861]
Mark Doliner <markdoliner@pidgin.im>
parents:
7167
diff
changeset
|
21 | faim_export int aim_email_sendcookies(aim_session_t *sess) |
| 3694 | 22 | { |
|
7282
73b94979f76b
[gaim-migrate @ 7861]
Mark Doliner <markdoliner@pidgin.im>
parents:
7167
diff
changeset
|
23 | aim_conn_t *conn; |
| 3694 | 24 | aim_frame_t *fr; |
| 25 | aim_snacid_t snacid; | |
| 26 | ||
|
7282
73b94979f76b
[gaim-migrate @ 7861]
Mark Doliner <markdoliner@pidgin.im>
parents:
7167
diff
changeset
|
27 | if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_EML))) |
| 3694 | 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 | ||
| 3725 | 64 | /** |
| 3694 | 65 | * Subtype 0x0007 - Receive information about your email account |
|
4804
e6e0e6d50d39
[gaim-migrate @ 5124]
Mark Doliner <markdoliner@pidgin.im>
parents:
3952
diff
changeset
|
66 | * |
| 3725 | 67 | * So I don't even know if you can have multiple 16 byte keys, |
| 3694 | 68 | * but this is coded so it will handle that, and handle it well. |
| 3725 | 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. | |
| 3694 | 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 | { | |
|
4871
962860053dcd
[gaim-migrate @ 5201]
Mark Doliner <markdoliner@pidgin.im>
parents:
4804
diff
changeset
|
78 | int ret = 0; |
| 3694 | 79 | aim_rxcallback_t userfunc; |
| 80 | struct aim_emailinfo *new; | |
| 81 | aim_tlvlist_t *tlvlist; | |
| 82 | fu8_t *cookie8, *cookie16; | |
| 3725 | 83 | int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */ |
| 3694 | 84 | |
| 7297 | 85 | char *alertitle = NULL, *alerturl = NULL; |
| 86 | ||
| 3694 | 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 */ | |
|
10996
145cffed9c3e
[gaim-migrate @ 12837]
Mark Doliner <markdoliner@pidgin.im>
parents:
8735
diff
changeset
|
91 | for (new = sess->emailinfo; (new && memcmp(cookie16, new->cookie16, 16)); new = new->next); |
| 3694 | 92 | if (new) { |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
7313
diff
changeset
|
93 | /* Free some of the old info, if it exists */ |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
94 | free(new->cookie8); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
95 | free(new->cookie16); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
96 | free(new->url); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
97 | free(new->domain); |
| 3694 | 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; | |
| 3725 | 102 | memset(new, 0, sizeof(struct aim_emailinfo)); |
|
7045
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
103 | new->next = sess->emailinfo; |
|
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
104 | sess->emailinfo = new; |
| 3694 | 105 | } |
| 106 | ||
| 107 | new->cookie8 = cookie8; | |
| 108 | new->cookie16 = cookie16; | |
| 109 | ||
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
110 | tlvlist = aim_tlvlist_readnum(bs, aimbs_get16(bs)); |
| 3694 | 111 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
112 | tmp = aim_tlv_get16(tlvlist, 0x0080, 1); |
| 3725 | 113 | if (tmp) { |
| 114 | if (new->nummsgs < tmp) | |
| 115 | havenewmail = 1; | |
| 116 | new->nummsgs = tmp; | |
| 117 | } else { | |
|
8735
01248ea222d3
[gaim-migrate @ 9490]
Jonathan Champ <royanee@users.sourceforge.net>
parents:
7313
diff
changeset
|
118 | /* If they don't send a 0x0080 TLV, it means we definitely have new mail */ |
| 3725 | 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 | } | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
123 | new->url = aim_tlv_getstr(tlvlist, 0x0007, 1); |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
124 | if (!(new->unread = aim_tlv_get8(tlvlist, 0x0081, 1))) { |
| 3725 | 125 | havenewmail = 0; |
| 126 | new->nummsgs = 0; | |
| 127 | } | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
128 | new->domain = aim_tlv_getstr(tlvlist, 0x0082, 1); |
|
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
129 | new->flag = aim_tlv_get16(tlvlist, 0x0084, 1); |
| 3694 | 130 | |
| 7297 | 131 | alertitle = aim_tlv_getstr(tlvlist, 0x0005, 1); |
| 132 | alerturl = aim_tlv_getstr(tlvlist, 0x000d, 1); | |
| 133 | ||
| 3694 | 134 | if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype))) |
|
7313
557d9e2b5dea
[gaim-migrate @ 7897]
Mark Doliner <markdoliner@pidgin.im>
parents:
7297
diff
changeset
|
135 | ret = userfunc(sess, rx, new, havenewmail, alertitle, (alerturl ? alerturl + 2 : NULL)); |
| 3694 | 136 | |
|
7167
9cfb68a44e17
[gaim-migrate @ 7734]
Mark Doliner <markdoliner@pidgin.im>
parents:
7045
diff
changeset
|
137 | aim_tlvlist_free(&tlvlist); |
|
4875
3aefead7212b
[gaim-migrate @ 5205]
Mark Doliner <markdoliner@pidgin.im>
parents:
4871
diff
changeset
|
138 | |
|
7313
557d9e2b5dea
[gaim-migrate @ 7897]
Mark Doliner <markdoliner@pidgin.im>
parents:
7297
diff
changeset
|
139 | free(alertitle); |
|
557d9e2b5dea
[gaim-migrate @ 7897]
Mark Doliner <markdoliner@pidgin.im>
parents:
7297
diff
changeset
|
140 | free(alerturl); |
|
557d9e2b5dea
[gaim-migrate @ 7897]
Mark Doliner <markdoliner@pidgin.im>
parents:
7297
diff
changeset
|
141 | |
|
4871
962860053dcd
[gaim-migrate @ 5201]
Mark Doliner <markdoliner@pidgin.im>
parents:
4804
diff
changeset
|
142 | return ret; |
| 3694 | 143 | } |
| 144 | ||
| 3725 | 145 | /** |
| 3694 | 146 | * Subtype 0x0016 - Send something or other |
| 3725 | 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. | |
| 3694 | 151 | */ |
|
7282
73b94979f76b
[gaim-migrate @ 7861]
Mark Doliner <markdoliner@pidgin.im>
parents:
7167
diff
changeset
|
152 | faim_export int aim_email_activate(aim_session_t *sess) |
| 3694 | 153 | { |
|
7282
73b94979f76b
[gaim-migrate @ 7861]
Mark Doliner <markdoliner@pidgin.im>
parents:
7167
diff
changeset
|
154 | aim_conn_t *conn; |
| 3694 | 155 | aim_frame_t *fr; |
| 156 | aim_snacid_t snacid; | |
| 157 | ||
|
7282
73b94979f76b
[gaim-migrate @ 7861]
Mark Doliner <markdoliner@pidgin.im>
parents:
7167
diff
changeset
|
158 | if (!sess || !(conn = aim_conn_findbygroup(sess, AIM_CB_FAM_EML))) |
| 3694 | 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 | { | |
|
7045
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
190 | while (sess->emailinfo) { |
|
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
191 | struct aim_emailinfo *tmp = sess->emailinfo; |
|
458b55091f8b
[gaim-migrate @ 7608]
Mark Doliner <markdoliner@pidgin.im>
parents:
7011
diff
changeset
|
192 | sess->emailinfo = sess->emailinfo->next; |
|
3952
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
193 | free(tmp->cookie16); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
194 | free(tmp->cookie8); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
195 | free(tmp->url); |
|
d13e1fde68d8
[gaim-migrate @ 4133]
Mark Doliner <markdoliner@pidgin.im>
parents:
3725
diff
changeset
|
196 | free(tmp->domain); |
| 3694 | 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 | } |