view src/protocols/oscar/email.c @ 5205:fefad67de2c7

[gaim-migrate @ 5573] I had a damn good commit message, but it was eaten. Let's try it again. Announcing, Gaim Plugin API version 2.0, or GPAPIV2.0 for short. There are lots'a cool thingies here. Okay now, this isn't as cool as the previous message, but: 1) There's now a single entry function for all plugin types. It returns a detailed information structure on the plugin. This removes a lot of the ugliness from old plugins. Oh yeah, libicq wasn't converted to this, so if you use it, well, you shouldn't have used it anyway, but now you can't! bwahahaha. Use AIM/ICQ. 2) There are now 3 types of plugins: Standard, Loader, and Protocol plugins. Standard plugins are, well, standard, compiled plugins. Loader plugins load other plugins. For example, the perl support is now a loader plugin. It loads perl scripts. In the future, we'll have Ruby and Python loader plugins. Protocol plugins are, well, protocol plugins... yeah... 3) Plugins have unique IDs, so they can be referred to or automatically updated from a plugin database in the future. Neat, huh? 4) Plugins will have dependency support in the future, and can be hidden, so if you have, say, a logging core plugin, it won't have to show up, but then you load the GTK+ logging plugin and it'll auto-load the core plugin. Core/UI split plugins! 5) There will eventually be custom plugin signals and RPC of some sort, for the core/ui split plugins. So, okay, back up .gaimrc. I'd like to thank my parents for their support, javabsp for helping convert a bunch of protocol plugins, and Etan for helping convert a bunch of standard plugins. Have fun. If you have any problems, please let me know, but you probably won't have anything major happen. You will have to convert your plugins, though, and I'm not guaranteeing that all perl scripts will still work. I'll end up changing the perl script API eventually, so I know they won't down the road. Don't worry, though. It'll be mass cool. faceprint wants me to just commit the damn code already. So, here we go!!! .. .. I need a massage. From a young, cute girl. Are there any young, cute girls in the audience? IM me plz k thx. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Fri, 25 Apr 2003 06:47:33 +0000
parents 26837f462a66
children 4375bf2d9020
line wrap: on
line source

/*
 * Family 0x0018 - Email notification
 *
 * Used for being alerted when the email address(es) associated with 
 * your screen name get new electronic-m.  For normal AIM accounts, you 
 * get the email address screenname@netscape.net.  AOL accounts have 
 * screenname@aol.com, and can also activate a netscape.net account.
 *
 */

#define FAIM_INTERNAL
#include <aim.h>

/**
 * Subtype 0x0006 - Request information about your email account
 *
 * @param sess The oscar session.
 * @param conn The email connection for this session.
 * @return Return 0 if no errors, otherwise return the error number.
 */
faim_export int aim_email_sendcookies(aim_session_t *sess, aim_conn_t *conn)
{
	aim_frame_t *fr;
	aim_snacid_t snacid;

	if (!sess || !conn)
		return -EINVAL;

	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+2+16+16)))
		return -ENOMEM;
	snacid = aim_cachesnac(sess, 0x0018, 0x0006, 0x0000, NULL, 0);
	aim_putsnac(&fr->data, 0x0018, 0x0006, 0x0000, snacid);

	/* Number of cookies to follow */
	aimbs_put16(&fr->data, 0x0002);

	/* Cookie */
	aimbs_put16(&fr->data, 0x5d5e);
	aimbs_put16(&fr->data, 0x1708);
	aimbs_put16(&fr->data, 0x55aa);
	aimbs_put16(&fr->data, 0x11d3);
	aimbs_put16(&fr->data, 0xb143);
	aimbs_put16(&fr->data, 0x0060);
	aimbs_put16(&fr->data, 0xb0fb);
	aimbs_put16(&fr->data, 0x1ecb);

	/* Cookie */
	aimbs_put16(&fr->data, 0xb380);
	aimbs_put16(&fr->data, 0x9ad8);
	aimbs_put16(&fr->data, 0x0dba);
	aimbs_put16(&fr->data, 0x11d5);
	aimbs_put16(&fr->data, 0x9f8a);
	aimbs_put16(&fr->data, 0x0060);
	aimbs_put16(&fr->data, 0xb0ee);
	aimbs_put16(&fr->data, 0x0631);

	aim_tx_enqueue(sess, fr);

	return 0;
}


/**
 * Subtype 0x0007 - Receive information about your email account
 *
 * So I don't even know if you can have multiple 16 byte keys, 
 * but this is coded so it will handle that, and handle it well.
 * This tells you if you have unread mail or not, the URL you 
 * should use to access that mail, and the domain name for the 
 * email account (screenname@domainname.com).  If this is the 
 * first 0x0007 SNAC you've received since you signed on, or if 
 * this is just a periodic status update, this will also contain 
 * the number of unread emails that you have.
 */
static int parseinfo(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{
	int ret = 0;
	aim_rxcallback_t userfunc;
	struct aim_emailinfo *new;
	aim_tlvlist_t *tlvlist;
	fu8_t *cookie8, *cookie16;
	int tmp, havenewmail = 0; /* Used to tell the client we have _new_ mail */

	cookie8 = aimbs_getraw(bs, 8); /* Possibly the code used to log you in to mail? */
	cookie16 = aimbs_getraw(bs, 16); /* Mail cookie sent above */

	/* See if we already have some info associated with this cookie */
	for (new=sess->emailinfo; (new && strncmp(cookie16, new->cookie16, 16)); new=new->next);
	if (new) {
		/* Free some of the old info, if existant */
		free(new->cookie8);
		free(new->cookie16);
		free(new->url);
		free(new->domain);
	} else {
		/* We don't already have info, so create a new struct for it */
		if (!(new = malloc(sizeof(struct aim_emailinfo))))
			return -ENOMEM;
		memset(new, 0, sizeof(struct aim_emailinfo));
		new->next = sess->emailinfo;
		sess->emailinfo = new;
	}

	new->cookie8 = cookie8;
	new->cookie16 = cookie16;

	tlvlist = aim_readtlvchain_num(bs, aimbs_get16(bs));

	tmp = aim_gettlv16(tlvlist, 0x0080, 1);
	if (tmp) {
		if (new->nummsgs < tmp)
			havenewmail = 1;
		new->nummsgs = tmp;
	} else {
		/* If they don't send a 0x0080 TLV, it means we definately have new mail */
		/* (ie. this is not just another status update) */
		havenewmail = 1;
		new->nummsgs++; /* We know we have at least 1 new email */
	}
	new->url = aim_gettlv_str(tlvlist, 0x0007, 1);
	if (!(new->unread = aim_gettlv8(tlvlist, 0x0081, 1))) {
		havenewmail = 0;
		new->nummsgs = 0;
	}
	new->domain = aim_gettlv_str(tlvlist, 0x0082, 1);
	new->flag = aim_gettlv16(tlvlist, 0x0084, 1);

	if ((userfunc = aim_callhandler(sess, rx->conn, snac->family, snac->subtype)))
		ret = userfunc(sess, rx, new, havenewmail);

	aim_freetlvchain(&tlvlist);

	return ret;
}

/**
 * Subtype 0x0016 - Send something or other
 *
 * @param sess The oscar session.
 * @param conn The email connection for this session.
 * @return Return 0 if no errors, otherwise return the error number.
 */
faim_export int aim_email_activate(aim_session_t *sess, aim_conn_t *conn)
{
	aim_frame_t *fr;
	aim_snacid_t snacid;

	if (!sess || !conn)
		return -EINVAL;

	if (!(fr = aim_tx_new(sess, conn, AIM_FRAMETYPE_FLAP, 0x02, 10+1+16)))
		return -ENOMEM;
	snacid = aim_cachesnac(sess, 0x0018, 0x0016, 0x0000, NULL, 0);
	aim_putsnac(&fr->data, 0x0018, 0x0016, 0x0000, snacid);

	/* I would guess this tells AIM that you want updates for your mail accounts */
	/* ...but I really have no idea */
	aimbs_put8(&fr->data, 0x02);
	aimbs_put32(&fr->data, 0x04000000);
	aimbs_put32(&fr->data, 0x04000000);
	aimbs_put32(&fr->data, 0x04000000);
	aimbs_put32(&fr->data, 0x00000000);

	aim_tx_enqueue(sess, fr);

	return 0;
}

static int snachandler(aim_session_t *sess, aim_module_t *mod, aim_frame_t *rx, aim_modsnac_t *snac, aim_bstream_t *bs)
{

	if (snac->subtype == 0x0007)
		return parseinfo(sess, mod, rx, snac, bs);

	return 0;
}

static void email_shutdown(aim_session_t *sess, aim_module_t *mod)
{
	while (sess->emailinfo) {
		struct aim_emailinfo *tmp = sess->emailinfo;
		sess->emailinfo = sess->emailinfo->next;
		free(tmp->cookie16);
		free(tmp->cookie8);
		free(tmp->url);
		free(tmp->domain);
		free(tmp);
	}

	return;
}

faim_internal int email_modfirst(aim_session_t *sess, aim_module_t *mod)
{

	mod->family = 0x0018;
	mod->version = 0x0001;
	mod->toolid = 0x0010;
	mod->toolversion = 0x0629;
	mod->flags = 0;
	strncpy(mod->name, "email", sizeof(mod->name));
	mod->snachandler = snachandler;
	mod->shutdown = email_shutdown;

	return 0;
}