END_TEST START_TEST(test_dbmail_message_cache_headers) { DbmailMessage *m = dbmail_message_new(); char *s = g_new0(char,20); GString *j = g_string_new(multipart_message); m = dbmail_message_init_with_string(m,j); dbmail_message_set_header(m, "References", "<*****@*****.**> <*****@*****.**> <*****@*****.**> "); dbmail_message_store(m); dbmail_message_free(m); g_string_free(j,TRUE); sprintf(s,"%.*s",10,"abcdefghijklmnopqrstuvwxyz"); fail_unless(MATCH(s,"abcdefghij"),"string truncate failed"); g_free(s); m = dbmail_message_new(); j = g_string_new(multipart_message); m = dbmail_message_init_with_string(m,j); dbmail_message_set_header(m, "Subject", "=?utf-8?Q?[xxxxxxxxxxxxxxxxxx.xx_0000747]:_=C3=84nderungen_an_der_Artikel?= =?utf-8?Q?-Detailseite?=" ); dbmail_message_store(m); dbmail_message_free(m); g_string_free(j,TRUE); }
END_TEST START_TEST(test_dbmail_message_encoded) { DbmailMessage *m = dbmail_message_new(); GString *s = g_string_new(encoded_message_koi); //const char *exp = ":: [ Arrty ] :: [ Roy (L) Stèphanie ] <*****@*****.**>"; u64_t id = 0; m = dbmail_message_init_with_string(m, s); fail_unless(strcmp(dbmail_message_get_header(m,"From"),"=?koi8-r?Q?=E1=CE=D4=CF=CE=20=EE=C5=C8=CF=D2=CF=DB=C9=C8=20?=<*****@*****.**>")==0, "dbmail_message_get_header failed for koi-8 encoded header"); dbmail_message_free(m); m = dbmail_message_new(); g_string_printf(s, "%s", utf7_header); m = dbmail_message_init_with_string(m, s); g_string_free(s, TRUE); dbmail_message_store(m); id = dbmail_message_get_physid(m); dbmail_message_free(m); m = dbmail_message_new(); m = dbmail_message_retrieve(m, id, DBMAIL_MESSAGE_FILTER_FULL); dbmail_message_free(m); }
END_TEST //DbmailMessage * dbmail_message_retrieve(DbmailMessage *self, u64_t physid, int filter); START_TEST(test_dbmail_message_retrieve) { DbmailMessage *m, *n; GString *s; u64_t physid; s = g_string_new(multipart_message); m = dbmail_message_new(); m = dbmail_message_init_with_string(m, s); fail_unless(m != NULL, "dbmail_message_init_with_string failed"); dbmail_message_set_header(m, "References", "<*****@*****.**> <*****@*****.**> <*****@*****.**> "); dbmail_message_store(m); physid = dbmail_message_get_physid(m); fail_unless(physid > 0, "dbmail_message_get_physid failed"); n = dbmail_message_new(); n = dbmail_message_retrieve(n,physid,DBMAIL_MESSAGE_FILTER_HEAD); fail_unless(n != NULL, "dbmail_message_retrieve failed"); fail_unless(n->content != NULL, "dbmail_message_retrieve failed"); dbmail_message_free(m); dbmail_message_free(n); g_string_free(s,TRUE); }
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); }
int send_alert(uint64_t user_idnr, char *subject, char *body) { DbmailMessage *new_message; Field_T postmaster; char *from; int msgflags[IMAP_NFLAGS]; // Only send each unique alert once a day. char *tmp = g_strconcat(subject, body, NULL); char *userchar = g_strdup_printf("%" PRIu64 "", user_idnr); char handle[FIELDSIZE]; memset(handle, 0, sizeof(handle)); dm_md5(tmp, handle); if (db_replycache_validate(userchar, "send_alert", handle, 1) != DM_SUCCESS) { TRACE(TRACE_INFO, "Already sent alert [%s] to user [%" PRIu64 "] today", subject, user_idnr); g_free(userchar); g_free(tmp); return 0; } else { TRACE(TRACE_INFO, "Sending alert [%s] to user [%" PRIu64 "]", subject, user_idnr); db_replycache_register(userchar, "send_alert", handle); g_free(userchar); g_free(tmp); } // From the Postmaster. if (config_get_value("POSTMASTER", "DBMAIL", postmaster) < 0) { TRACE(TRACE_NOTICE, "no config value for POSTMASTER"); } if (strlen(postmaster)) from = postmaster; else from = DEFAULT_POSTMASTER; // Set the \Flagged flag. memset(msgflags, 0, sizeof(msgflags)); msgflags[IMAP_FLAG_FLAGGED] = 1; // Get the user's login name. char *to = auth_get_userid(user_idnr); new_message = dbmail_message_new(NULL); new_message = dbmail_message_construct(new_message, to, from, subject, body); // Pre-insert the message and get a new_message->id dbmail_message_store(new_message); uint64_t tmpid = new_message->id; if (sort_deliver_to_mailbox(new_message, user_idnr, "INBOX", BOX_BRUTEFORCE, msgflags, NULL) != DSN_CLASS_OK) { TRACE(TRACE_ERR, "Unable to deliver alert [%s] to user [%" PRIu64 "]", subject, user_idnr); } g_free(to); db_delete_message(tmpid); dbmail_message_free(new_message); return 0; }
END_TEST START_TEST(test_dbmail_message_8bit) { DbmailMessage *m = dbmail_message_new(); GString *s = g_string_new(raw_message_koi); m = dbmail_message_init_with_string(m, s); g_string_free(s,TRUE); dbmail_message_store(m); dbmail_message_free(m); /* */ m = dbmail_message_new(); s = g_string_new(encoded_message_utf8); m = dbmail_message_init_with_string(m, s); g_string_free(s, TRUE); dbmail_message_store(m); dbmail_message_free(m); }
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; }