Navigation Menu

Skip to content

Commit

Permalink
wip fix broken structure
Browse files Browse the repository at this point in the history
  • Loading branch information
pjstevns committed Aug 1, 2012
1 parent 41cfc3d commit 4597ed7
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 19 deletions.
40 changes: 24 additions & 16 deletions src/dm_misc.c
Expand Up @@ -1332,20 +1332,22 @@ static void _structure_part_multipart(GMimeObject *part, gpointer data, gboolean
static void _structure_part_message_rfc822(GMimeObject *part, gpointer data, gboolean extension);


static void get_param_list(gpointer key, gpointer value, gpointer data)
{
gchar *s = g_mime_utils_header_encode_text(((GMimeParam *)value)->value);
*(GList **)data = g_list_append_printf(*(GList **)data, "\"%s\"", (char *)key);
*(GList **)data = g_list_append_printf(*(GList **)data, "\"%s\"", s);
g_free(s);
}

static GList * imap_append_hash_as_string(GList *list, GHashTable *hash)
static GList * imap_append_hash_as_string(GList *list, const GMimeParam *hash)
{
GList *l = NULL;
char *s;
if (hash)
g_hash_table_foreach(hash, get_param_list, (gpointer)&(l));

while (hash) {
gchar *value = g_mime_utils_header_encode_text(g_mime_param_get_value(hash));
l = g_list_append_printf(l, "\"%s\"", g_mime_param_get_name(hash));
if (value[0] == '"')
l = g_list_append_printf(l, "%s", value);
else
l = g_list_append_printf(l, "\"%s\"", value);
g_free(value);
hash = g_mime_param_next(hash);
}

if (l) {
s = dbmail_imap_plist_as_string(l);
list = g_list_append_printf(list, "%s", s);
Expand All @@ -1367,10 +1369,13 @@ static GList * imap_append_disposition_as_string(GList *list, GMimeObject *part)

if(disp) {
disposition = g_mime_content_disposition_new_from_string(disp);
t = g_list_append_printf(t,"\"%s\"",disposition->disposition);
t = g_list_append_printf(t,"\"%s\"",
g_mime_content_disposition_get_disposition(disposition));

/* paramlist */
t = imap_append_hash_as_string(t, disposition->param_hash);
t = imap_append_hash_as_string(t,
g_mime_content_disposition_get_params(disposition));

g_object_unref(disposition);

result = dbmail_imap_plist_as_string(t);
Expand Down Expand Up @@ -1500,7 +1505,8 @@ void _structure_part_multipart(GMimeObject *part, gpointer data, gboolean extens
/* extension data (only for multipart, in case of BODYSTRUCTURE command argument) */
if (extension) {
/* paramlist */
list = imap_append_hash_as_string(list, type->param_hash);
list = imap_append_hash_as_string(list,
g_mime_content_type_get_params(type));
/* disposition */
list = imap_append_disposition_as_string(list, object);
/* language */
Expand Down Expand Up @@ -1544,7 +1550,8 @@ void _structure_part_message_rfc822(GMimeObject *part, gpointer data, gboolean e
list = g_list_append_printf(list,"\"%s\"", type->type);
list = g_list_append_printf(list,"\"%s\"", type->subtype);
/* paramlist */
list = imap_append_hash_as_string(list, type->param_hash);
list = imap_append_hash_as_string(list,
g_mime_content_type_get_params((GMimeContentType *)type));
/* body id */
if ((result = (char *)g_mime_object_get_content_id(object)))
list = g_list_append_printf(list,"\"%s\"", result);
Expand Down Expand Up @@ -1600,7 +1607,8 @@ void _structure_part_text(GMimeObject *part, gpointer data, gboolean extension)
list = g_list_append_printf(list,"\"%s\"", type->type);
list = g_list_append_printf(list,"\"%s\"", type->subtype);
/* paramlist */
list = imap_append_hash_as_string(list, type->param_hash);
list = imap_append_hash_as_string(list,
g_mime_content_type_get_params(type));
/* body id */
if ((result = (char *)g_mime_object_get_content_id(object)))
list = g_list_append_printf(list,"\"%s\"", result);
Expand Down
13 changes: 10 additions & 3 deletions test/check_dbmail_imapd.c
Expand Up @@ -236,7 +236,7 @@ START_TEST(test_imap_get_structure)
message = dbmail_message_init_with_string(message, g_string_new(multipart_message));
result = imap_get_structure(GMIME_MESSAGE(message->content), 1);
strncpy(expect,"((\"text\" \"html\" NIL NIL NIL \"7BIT\" 30 3 NIL (\"inline\" NIL) NIL NIL)"
"(\"text\" \"plain\" (\"name\" \"testfile\" \"charset\" \"us-ascii\") NIL NIL \"base64\" 432 7 NIL NIL NIL NIL)"
"(\"text\" \"plain\" (\"charset\" \"us-ascii\" \"name\" \"testfile\") NIL NIL \"base64\" 432 7 NIL NIL NIL NIL)"
" \"mixed\" (\"boundary\" \"boundary\") NIL NIL NIL)",1024);
fail_unless(strncasecmp(result,expect,1024)==0, "imap_get_structure failed\n[%s] !=\n[%s]\n", expect, result);
g_free(result);
Expand Down Expand Up @@ -883,30 +883,37 @@ Suite *dbmail_suite(void)
suite_add_tcase(s, tc_misc);

tcase_add_checked_fixture(tc_session, setup, teardown);
/*
tcase_add_test(tc_session, test_imap_session_new);
tcase_add_test(tc_session, test_imap_bodyfetch);
*/
tcase_add_test(tc_session, test_imap_get_structure);
/*
tcase_add_test(tc_session, test_imap_cleanup_address);
tcase_add_test(tc_session, test_internet_address_list_parse_string);
tcase_add_test(tc_session, test_imap_get_envelope);
tcase_add_test(tc_session, test_imap_get_envelope_8bit_id);
tcase_add_test(tc_session, test_imap_get_envelope_koi);
tcase_add_test(tc_session, test_imap_get_envelope_latin);
tcase_add_test(tc_session, test_imap_get_partspec);

*/

tcase_add_checked_fixture(tc_mime, setup, teardown);

tcase_add_checked_fixture(tc_util, setup, teardown);
/*
tcase_add_test(tc_util, test_dbmail_imap_plist_as_string);
tcase_add_test(tc_util, test_dbmail_imap_plist_collapse);
tcase_add_test(tc_util, test_dbmail_imap_astring_as_string);
tcase_add_test(tc_util, test_g_list_slices);
tcase_add_test(tc_util, test_g_list_slices_u64);
tcase_add_test(tc_util, test_listex_match);
tcase_add_test(tc_util, test_date_sql2imap);

*/
tcase_add_checked_fixture(tc_misc, setup, teardown);
/*
tcase_add_test(tc_misc, test_dm_base_subject);
*/
return s;
}

Expand Down

0 comments on commit 4597ed7

Please sign in to comment.