* mu-msg.c / test-mu-msg.c: improve attachment detection

This commit is contained in:
Dirk-Jan C. Binnema 2010-11-20 18:41:57 +02:00
parent da7140a602
commit e8556fd303
2 changed files with 65 additions and 14 deletions

View File

@ -231,11 +231,12 @@ get_recipient (MuMsg *msg, GMimeRecipientType rtype, StringFields field)
char *recep;
InternetAddressList *receps;
receps = g_mime_message_get_recipients (msg->_mime_msg, rtype);
receps = g_mime_message_get_recipients (msg->_mime_msg,
rtype);
/* FIXME: is there an internal leak in
* internet_address_list_to_string? */
recep = (char*)internet_address_list_to_string (receps, TRUE);
recep = (char*)internet_address_list_to_string (receps,
TRUE);
if (recep && recep[0]=='\0')
g_free (recep);
else
@ -275,21 +276,33 @@ mu_msg_get_date (MuMsg *msg)
}
static gboolean
part_is_inline (GMimeObject *part)
part_looks_like_attachment (GMimeObject *part)
{
GMimeContentDisposition *disp;
const char *str;
disp = g_mime_object_get_content_disposition (part);
if (!GMIME_IS_CONTENT_DISPOSITION(disp))
return TRUE;
return FALSE; /* no content disp? prob not
* an attachment. */
str = g_mime_content_disposition_get_disposition (disp);
if (str && (strcmp (str, GMIME_DISPOSITION_ATTACHMENT) == 0))
return FALSE;
return TRUE;
/* ok, it says it's an attachment, so it probably is... */
if (!str)
return TRUE;
if (strcmp (str, GMIME_DISPOSITION_ATTACHMENT) == 0)
return TRUE;
else if (strcmp (str, GMIME_DISPOSITION_INLINE) == 0) {
/* inline-images are also considered attachments... */
GMimeContentType *ct;
ct = g_mime_object_get_content_type (part);
if (ct)
return g_mime_content_type_is_type
(ct, "image", "*");
}
return FALSE;
}
@ -302,7 +315,7 @@ msg_cflags_cb (GMimeObject *parent, GMimeObject *part, MuMsgFlags *flags)
if (!GMIME_IS_PART(part))
return;
if (!part_is_inline(part))
if (part_looks_like_attachment(part))
*flags |= MU_MSG_FLAG_HAS_ATTACH;
}
@ -335,9 +348,11 @@ get_content_flags (MuMsg *msg)
}
if (ctype) {
if (g_mime_content_type_is_type (ctype,"*", "signed"))
if (g_mime_content_type_is_type
(ctype,"*", "signed"))
flags |= MU_MSG_FLAG_SIGNED;
if (g_mime_content_type_is_type (ctype,"*", "encrypted"))
if (g_mime_content_type_is_type
(ctype,"*", "encrypted"))
flags |= MU_MSG_FLAG_ENCRYPTED;
}
} else
@ -353,7 +368,6 @@ mu_msg_get_flags (MuMsg *msg)
g_return_val_if_fail (msg, MU_MSG_FLAG_NONE);
if (msg->_flags == MU_MSG_FLAG_NONE) {
msg->_flags = 0;
msg->_flags = mu_msg_flags_from_file (mu_msg_get_path(msg));
msg->_flags |= get_content_flags (msg);
}

View File

@ -145,9 +145,13 @@ test_mu_msg_02 (void)
==, 1218051515);
i = 0;
mu_msg_contact_foreach (msg, (MuMsgContactForeachFunc)check_contact_02,
mu_msg_contact_foreach (msg,
(MuMsgContactForeachFunc)check_contact_02,
&i);
g_assert_cmpint (i,==,2);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_SEEN);
mu_msg_destroy (msg);
}
@ -173,11 +177,42 @@ test_mu_msg_03 (void)
g_assert_cmpstr (mu_msg_get_body_text(msg),
==,
"\nLet's write some fünkÿ text\nusing umlauts.\n\nFoo.\n");
g_assert_cmpuint (mu_msg_get_flags(msg),
==, 0);
mu_msg_destroy (msg);
}
static void
test_mu_msg_04 (void)
{
MuMsg *msg;
msg = mu_msg_new (MU_TESTMAILDIR2
"Foo/cur/mail4", NULL);
g_assert_cmpstr (mu_msg_get_to(msg),
==, "George Custer <gac@example.com>");
g_assert_cmpstr (mu_msg_get_subject(msg),
==, "pics for you");
g_assert_cmpstr (mu_msg_get_from(msg),
==, "Sitting Bull <sb@example.com>");
g_assert_cmpuint (mu_msg_get_prio(msg), /* 'low' */
==, MU_MSG_PRIO_NORMAL);
g_assert_cmpuint (mu_msg_get_date(msg),
==, 0);
g_assert_cmpuint (mu_msg_get_flags(msg),
==, MU_MSG_FLAG_HAS_ATTACH);
mu_msg_destroy (msg);
}
/* static gboolean */
/* ignore_error (const char* log_domain, GLogLevelFlags log_level, const gchar* msg, */
/* gpointer user_data) */
@ -199,6 +234,8 @@ main (int argc, char *argv[])
test_mu_msg_02);
g_test_add_func ("/mu-msg/mu-msg-03",
test_mu_msg_03);
g_test_add_func ("/mu-msg/mu-msg-04",
test_mu_msg_04);
g_log_set_handler (NULL,
G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL| G_LOG_FLAG_RECURSION,