* mu-msg-gmime: fix contacts list bug, update unit tests

This commit is contained in:
djcb 2010-08-19 22:44:57 +03:00
parent 93590436c1
commit d79b93a45d
4 changed files with 35 additions and 19 deletions

View File

@ -369,7 +369,7 @@ view_file (const gchar *path, const gchar *fields, size_t summary_len)
msg = mu_msg_gmime_new (path, NULL);
if (!msg)
return FALSE;
field = mu_msg_gmime_get_from (msg);
if (field)
g_print ("From: %s\n", field);

View File

@ -856,18 +856,18 @@ fill_contact (MuMsgContact *contact, InternetAddress *addr,
}
static int
static gboolean
address_list_foreach (InternetAddressList *addrlist,
MuMsgContactType ctype,
MuMsgContactForeachFunc func,
gpointer user_data)
{
int i,rv;
int i, rv;
if (!addrlist)
return 0;
for (i = 0, rv = 0; i != internet_address_list_length(addrlist); ++i) {
for (i = 0, rv = FALSE; i != internet_address_list_length(addrlist); ++i) {
MuMsgContact contact;
if (!fill_contact(&contact,
@ -877,34 +877,34 @@ address_list_foreach (InternetAddressList *addrlist,
continue;
}
rv = (func)(&contact, user_data);
if (rv != 0)
if (!(func)(&contact, user_data))
break;
}
return rv;
}
static int
static gboolean
get_contacts_from (MuMsgGMime *msg, MuMsgContactForeachFunc func,
gpointer user_data)
gpointer user_data)
{
InternetAddressList *lst;
int rv;
gboolean rv;
/* we go through this whole excercise of trying to get a *list*
* of 'From:' address (usually there is only one...), because
* internet_address_parse_string has the nice side-effect of
* splitting in names and addresses for us */
rv = FALSE;
lst = internet_address_list_parse_string (
g_mime_message_get_sender (msg->_mime_msg));
if (lst) {
rv = address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
func, user_data);
g_object_unref (G_OBJECT(lst));
}
}
return rv;
}

View File

@ -75,11 +75,11 @@ test_mu_msg_gmime_01 (void)
msg = mu_msg_gmime_new (mfile, NULL);
g_assert_cmpstr (mu_msg_gmime_get_to(msg),
==, "gcc-help@gcc.gnu.org");
==, "Donald Duck <gcc-help@gcc.gnu.org>");
g_assert_cmpstr (mu_msg_gmime_get_subject(msg),
==, "gcc include search order");
g_assert_cmpstr (mu_msg_gmime_get_from(msg),
==, "anon@example.com");
==, "Mickey Mouse <anon@example.com>");
g_assert_cmpstr (mu_msg_gmime_get_msgid(msg),
==, "3BE9E6535E3029448670913581E7A1A20D852173@"
"emss35m06.us.lmco.com");
@ -92,13 +92,21 @@ test_mu_msg_gmime_01 (void)
{
GSList *lst, *cur;
lst = mu_msg_gmime_contacts_list (msg);
g_assert_cmpuint (g_slist_length(lst),==, 1);
g_assert_cmpuint (g_slist_length(lst),==, 2);
cur = lst;
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
==, NULL);
==, "Mickey Mouse");
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
==, "anon@example.com");
cur = g_slist_next (cur);
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
==, "Donald Duck");
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
==, "gcc-help@gcc.gnu.org");
mu_msg_contact_list_free (lst);
}
@ -141,14 +149,22 @@ test_mu_msg_gmime_02 (void)
{
GSList *lst, *cur;
lst = mu_msg_gmime_contacts_list (msg);
g_assert_cmpuint (g_slist_length(lst),==, 1);
g_assert_cmpuint (g_slist_length(lst),==, 2);
cur = lst;
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
==, "anon@example.com");
cur = g_slist_next (cur);
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
==, "help-gnu-emacs@gnu.org");
mu_msg_contact_list_free (lst);
}

View File

@ -43,9 +43,9 @@ Received: from EMSS35M06.us.lmco.com ([158.187.107.143]) by
EMSS04I00.us.lmco.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 06 Aug
2008 23:14:20 -0400
Date: Thu, 31 Jul 2008 14:57:25 -0400
From: anon@example.com
From: "Mickey Mouse" <anon@example.com>
Subject: gcc include search order
To: gcc-help@gcc.gnu.org
To: "Donald Duck" <gcc-help@gcc.gnu.org>
Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com>
MIME-version: 1.0
Content-type: text/plain; charset=us-ascii