Пример #1
0
END_TEST

START_TEST(test_dbmail_message_store2)
{
	DbmailMessage *m, *n;
	u64_t physid;
	char *t;
	char *expect;

	m = message_init(broken_message2);
	
	dbmail_message_set_header(m, "Return-Path", dbmail_message_get_header(m, "From"));
	
	expect = dbmail_message_to_string(m);
	fail_unless(m != NULL, "dbmail_message_store2 failed");

	dbmail_message_store(m);
	physid = dbmail_message_get_physid(m);
	dbmail_message_free(m);

	n = dbmail_message_new();
	dbmail_message_set_physid(n, physid);
	n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_FULL);
	fail_unless(n != NULL, "_mime_retrieve failed");
	
	t = dbmail_message_to_string(n);
	
	COMPARE(expect,t);
	
	dbmail_message_free(n);
	g_free(expect);
	g_free(t);
	
}
Пример #2
0
END_TEST


START_TEST(test_dbmail_message_construct)
{
	const gchar *sender = "*****@*****.**";
	const gchar *subject = "Some test";
	const gchar *recipient = "<*****@*****.**> Bar";
	gchar *body = g_strdup("\ntesting\n\nááááä\n\n");
	gchar *expect = g_strdup("From: [email protected]\n"
	"Subject: Some test\n"
	"To: [email protected]\n"
	"MIME-Version: 1.0\n"
	"Content-Type: text/plain; charset=utf-8\n"
	"Content-Transfer-Encoding: base64\n"
	"\n"
	"CnRlc3RpbmcKCuHh4eHk");
	gchar *result;

	DbmailMessage *message = dbmail_message_new();
	message = dbmail_message_construct(message,recipient,sender,subject,body);
	result = dbmail_message_to_string(message);
	fail_unless(MATCH(expect,result),"dbmail_message_construct failed\n%s\n%s", expect, result);
	dbmail_message_free(message);
	g_free(body);
	g_free(result);
	g_free(expect);

	body = g_strdup("Mit freundlichen Gr=C3=BC=C3=9Fen");
	message = dbmail_message_new();
	message = dbmail_message_construct(message,recipient,sender,subject,body);
	//printf ("%s\n", dbmail_message_to_string(message));
	dbmail_message_free(message);
	g_free(body);
}
Пример #3
0
END_TEST

START_TEST(test_dbmail_message_to_string)
{
        char *result;
	DbmailMessage *m;
        
	m = message_init(multipart_message);
        result = dbmail_message_to_string(m);
	COMPARE(multipart_message, result);
	g_free(result);
	dbmail_message_free(m);

	//
	m = message_init(simple_with_from);
	result = dbmail_message_to_string(m);
	COMPARE(simple_with_from, result);
	g_free(result);
	dbmail_message_free(m);

}
Пример #4
0
static char *store_and_retrieve(DbmailMessage *m)
{
	u64_t physid;
	DbmailMessage *n;
	char *t;

	dbmail_message_store(m);
	physid = dbmail_message_get_physid(m);
	fail_unless(physid != 0,"dbmail_message_store failed. physid [%llu]", physid);
	dbmail_message_free(m);

	n = dbmail_message_new();
	dbmail_message_set_physid(n, physid);
	n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_FULL);
	fail_unless(n != NULL, "_mime_retrieve failed");
	
	t = dbmail_message_to_string(n);
	dbmail_message_free(n);
	return t;
}
Пример #5
0
void Http_getMessages(T R)
{
	DbmailMessage *m = dbmail_message_new();
	struct evbuffer *buf;
	uint64_t pid;
	uint64_t id = 0;

	if (! Request_getId(R)) return;

	if (! (id = strtoull(Request_getId(R), NULL, 10))) {
		Request_error(R, HTTP_NOTFOUND, "Not found");
		return;
	}

	db_get_physmessage_id(id, &pid);
	if (! pid) {
		Request_error(R, HTTP_NOTFOUND, "Not found");
		return;
	}
	buf = evbuffer_new();
	m = dbmail_message_retrieve(m, pid);
	if (Request_getMethod(R) == NULL) {

		/*
		 * retrieve message meta-data
		 * C < GET /messages/1245911
		 */

		uint64_t size = dbmail_message_get_size(m, TRUE);
		Request_setContentType(R,"application/json; charset=utf-8");
		evbuffer_add_printf(buf, "{\"messages\": {\n");
		evbuffer_add_printf(buf, "   \"%lu\":{\"size\":%lu}", id, size);
		evbuffer_add_printf(buf, "\n}}\n");

	} else if (MATCH(Request_getMethod(R), "view")) {

		/*
		 * retrieve message by message_idnr
		 * C < GET /messages/1245911/view
		 */

		char *s = dbmail_message_to_string(m);
		Request_setContentType(R, "message/rfc822; charset=utf-8");
		evbuffer_add_printf(buf, "%s", s);
		g_free(s);

	} else if (MATCH(Request_getMethod(R),"headers")) {

		Request_setContentType(R, "text/plain; charset=utf-8");
		if (Request_getArg(R) && strlen(Request_getArg(R))) {

			/*
			 * retrieve selected message headers 
			 * C < GET /messages/1245911/headers/subject,from,to
			 */

			int i = 0;
			char **headerlist = g_strsplit(Request_getArg(R),",",0);
			while (headerlist[i]) {
				char *hname = headerlist[i];
				hname[0] = g_ascii_toupper(hname[0]);
				TRACE(TRACE_DEBUG,"header: [%s]", headerlist[i]);
				GList * headers = dbmail_message_get_header_repeated(m, headerlist[i]);

				while(headers) {
					evbuffer_add_printf(buf, "%s: %s\n", hname, (char *)headers->data);
					if (! g_list_next(headers))
						break;
					headers = g_list_next(headers);
				}
				i++;
			}
		} else {

			/*
			 * retrieve all message headers
			 * C < GET /messages/1245911/headers
			 */

			char *s = dbmail_message_hdrs_to_string(m);
			Request_setContentType(R, "text/plain; charset=utf-8");
			evbuffer_add_printf(buf, "%s", s);
			g_free(s);
		}
	}

	if (EVBUFFER_LENGTH(buf))
		Request_send(R, HTTP_OK, "OK", buf);
	else		
		Request_error(R, HTTP_SERVUNAVAIL, "Server error");

	evbuffer_free(buf);
	dbmail_message_free(m);
}
Пример #6
0
END_TEST


START_TEST(test_dbmail_message_store)
{
	DbmailMessage *m;
	char *t, *e;

	//-----------------------------------------
	m = message_init("From: paul\n");
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(simple);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(rfc822);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_message);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_message2);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(message_rfc822);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_message3);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_message4);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_message5);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_mixed);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(broken_message);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	//COMPARE(expect,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(encoded_message_latin_1);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(encoded_message_latin_2);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(encoded_message_utf8);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(encoded_message_utf8_1);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(encoded_message_utf8_2);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(encoded_message_koi);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(raw_message_koi);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_alternative);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(outlook_multipart);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	COMPARE(e,t);
	g_free(e);
	g_free(t);
	//-----------------------------------------
	m = message_init(multipart_alternative2);
	e = dbmail_message_to_string(m);
	t = store_and_retrieve(m);
	// FIXME COMPARE(e,t);
	g_free(e);
	g_free(t);
}