Ejemplo n.º 1
0
static int
decode_envelope (CamelIMAP4Engine *engine, CamelMessageInfo *info, camel_imap4_token_t *token, CamelException *ex)
{
	CamelIMAP4MessageInfo *iinfo = (CamelIMAP4MessageInfo *) info;
	unsigned char md5sum[16];
	char *nstring, *msgid;

	if (camel_imap4_engine_next_token (engine, token, ex) == -1)
		return -1;

	if (token->token != '(') {
		camel_imap4_utils_set_unexpected_token_error (ex, engine, token);
		return -1;
	}

	if (envelope_decode_date (engine, &iinfo->info.date_sent, ex) == -1)
		goto exception;

	/* subject */
	if (envelope_decode_nstring (engine, &nstring, TRUE, ex) == -1)
		goto exception;

	iinfo->info.needs_free = TRUE;

	iinfo->info.subject = camel_pstring_strdup (nstring);
	g_free(nstring);

	/* from */
	if (envelope_decode_addresses (engine, &nstring, ex) == -1)
		goto exception;
	iinfo->info.from = camel_pstring_strdup (nstring);
	g_free(nstring);

	/* sender */
	if (envelope_decode_addresses (engine, &nstring, ex) == -1)
		goto exception;
	g_free (nstring);

	/* reply-to */
	if (envelope_decode_addresses (engine, &nstring, ex) == -1)
		goto exception;
	g_free (nstring);

	/* to */
	if (envelope_decode_addresses (engine, &nstring, ex) == -1)
		goto exception;
	iinfo->info.to = camel_pstring_strdup (nstring);
	g_free(nstring);

	/* cc */
	if (envelope_decode_addresses (engine, &nstring, ex) == -1)
		goto exception;
	iinfo->info.cc = camel_pstring_strdup (nstring);
	g_free(nstring);

	/* bcc */
	if (envelope_decode_addresses (engine, &nstring, ex) == -1)
		goto exception;
	g_free (nstring);

	/* in-reply-to */
	if (envelope_decode_nstring (engine, &nstring, FALSE, ex) == -1)
		goto exception;

	if (nstring != NULL) {
		if (!iinfo->info.references)
			iinfo->info.references = decode_references (NULL, nstring);

		g_free (nstring);
	}

	/* message-id */
	if (envelope_decode_nstring (engine, &nstring, FALSE, ex) == -1)
		goto exception;

	if (nstring != NULL) {
		if ((msgid = camel_header_msgid_decode (nstring))) {
			md5_get_digest (msgid, strlen (msgid), md5sum);
			memcpy (iinfo->info.message_id.id.hash, md5sum, sizeof (CamelSummaryMessageID));
			g_free (msgid);
		}
		g_free (nstring);
	}

	if (camel_imap4_engine_next_token (engine, token, ex) == -1)
		return -1;

	if (token->token != ')') {
		camel_imap4_utils_set_unexpected_token_error (ex, engine, token);
		goto exception;
	}

	return 0;

 exception:

	return -1;
}
Ejemplo n.º 2
0
static int
decode_envelope (SpruceIMAPEngine *engine, SpruceMessageInfo *info, spruce_imap_token_t *token, GError **err)
{
	unsigned char md5sum[16];
	char *nstring, *msgid;
	GChecksum *checksum;
	size_t len = 16;
	
	if (spruce_imap_engine_next_token (engine, token, err) == -1)
		return -1;
	
	if (token->token != '(') {
		spruce_imap_utils_set_unexpected_token_error (err, engine, token);
		return -1;
	}
	
	if (envelope_decode_date (engine, &info->date_sent, err) == -1)
		goto exception;
	
	if (envelope_decode_nstring (engine, &info->subject, TRUE, err) == -1)
		goto exception;
	
	if (envelope_decode_addresses (engine, &info->from, err) == -1)
		goto exception;
	
	if (envelope_decode_addresses (engine, &info->sender, err) == -1)
		goto exception;
	
	if (envelope_decode_addresses (engine, &info->reply_to, err) == -1)
		goto exception;
	
	if (envelope_decode_addresses (engine, &info->to, err) == -1)
		goto exception;
	
	if (envelope_decode_addresses (engine, &info->cc, err) == -1)
		goto exception;
	
	if (envelope_decode_addresses (engine, &info->bcc, err) == -1)
		goto exception;
	
	if (envelope_decode_nstring (engine, &nstring, FALSE, err) == -1)
		goto exception;
	
	if (nstring != NULL) {
		info->references = decode_references (nstring);
		g_free (nstring);
	}
	
	if (envelope_decode_nstring (engine, &nstring, FALSE, err) == -1)
		goto exception;
	
	if (nstring != NULL) {
		if ((msgid = g_mime_utils_decode_message_id (nstring))) {
			checksum = g_checksum_new (G_CHECKSUM_MD5);
			g_checksum_update (checksum, msgid, strlen (msgid));
			g_checksum_get_digest (checksum, md5sum, &len);
			g_checksum_free (checksum);
			
			memcpy (info->message_id.id.hash, md5sum, sizeof (info->message_id.id.hash));
			g_free (msgid);
		}
		g_free (nstring);
	}
	
	if (spruce_imap_engine_next_token (engine, token, err) == -1)
		return -1;
	
	if (token->token != ')') {
		spruce_imap_utils_set_unexpected_token_error (err, engine, token);
		goto exception;
	}
	
	return 0;
	
 exception:
	
	return -1;
}