mirror of https://github.com/djcb/mu.git
* mu-msg-gmime: fix contacts list bug, update unit tests
This commit is contained in:
parent
93590436c1
commit
d79b93a45d
|
@ -369,7 +369,7 @@ view_file (const gchar *path, const gchar *fields, size_t summary_len)
|
||||||
msg = mu_msg_gmime_new (path, NULL);
|
msg = mu_msg_gmime_new (path, NULL);
|
||||||
if (!msg)
|
if (!msg)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
field = mu_msg_gmime_get_from (msg);
|
field = mu_msg_gmime_get_from (msg);
|
||||||
if (field)
|
if (field)
|
||||||
g_print ("From: %s\n", field);
|
g_print ("From: %s\n", field);
|
||||||
|
|
|
@ -856,18 +856,18 @@ fill_contact (MuMsgContact *contact, InternetAddress *addr,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
static gboolean
|
||||||
address_list_foreach (InternetAddressList *addrlist,
|
address_list_foreach (InternetAddressList *addrlist,
|
||||||
MuMsgContactType ctype,
|
MuMsgContactType ctype,
|
||||||
MuMsgContactForeachFunc func,
|
MuMsgContactForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
int i,rv;
|
int i, rv;
|
||||||
|
|
||||||
if (!addrlist)
|
if (!addrlist)
|
||||||
return 0;
|
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;
|
MuMsgContact contact;
|
||||||
if (!fill_contact(&contact,
|
if (!fill_contact(&contact,
|
||||||
|
@ -877,34 +877,34 @@ address_list_foreach (InternetAddressList *addrlist,
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
rv = (func)(&contact, user_data);
|
if (!(func)(&contact, user_data))
|
||||||
if (rv != 0)
|
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static gboolean
|
||||||
get_contacts_from (MuMsgGMime *msg, MuMsgContactForeachFunc func,
|
get_contacts_from (MuMsgGMime *msg, MuMsgContactForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
InternetAddressList *lst;
|
InternetAddressList *lst;
|
||||||
int rv;
|
gboolean rv;
|
||||||
|
|
||||||
/* we go through this whole excercise of trying to get a *list*
|
/* we go through this whole excercise of trying to get a *list*
|
||||||
* of 'From:' address (usually there is only one...), because
|
* of 'From:' address (usually there is only one...), because
|
||||||
* internet_address_parse_string has the nice side-effect of
|
* internet_address_parse_string has the nice side-effect of
|
||||||
* splitting in names and addresses for us */
|
* splitting in names and addresses for us */
|
||||||
|
rv = FALSE;
|
||||||
lst = internet_address_list_parse_string (
|
lst = internet_address_list_parse_string (
|
||||||
g_mime_message_get_sender (msg->_mime_msg));
|
g_mime_message_get_sender (msg->_mime_msg));
|
||||||
if (lst) {
|
if (lst) {
|
||||||
rv = address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
|
rv = address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
|
||||||
func, user_data);
|
func, user_data);
|
||||||
g_object_unref (G_OBJECT(lst));
|
g_object_unref (G_OBJECT(lst));
|
||||||
}
|
}
|
||||||
|
|
||||||
return rv;
|
return rv;
|
||||||
}
|
}
|
||||||
|
|
|
@ -75,11 +75,11 @@ test_mu_msg_gmime_01 (void)
|
||||||
msg = mu_msg_gmime_new (mfile, NULL);
|
msg = mu_msg_gmime_new (mfile, NULL);
|
||||||
|
|
||||||
g_assert_cmpstr (mu_msg_gmime_get_to(msg),
|
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),
|
g_assert_cmpstr (mu_msg_gmime_get_subject(msg),
|
||||||
==, "gcc include search order");
|
==, "gcc include search order");
|
||||||
g_assert_cmpstr (mu_msg_gmime_get_from(msg),
|
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),
|
g_assert_cmpstr (mu_msg_gmime_get_msgid(msg),
|
||||||
==, "3BE9E6535E3029448670913581E7A1A20D852173@"
|
==, "3BE9E6535E3029448670913581E7A1A20D852173@"
|
||||||
"emss35m06.us.lmco.com");
|
"emss35m06.us.lmco.com");
|
||||||
|
@ -92,13 +92,21 @@ test_mu_msg_gmime_01 (void)
|
||||||
{
|
{
|
||||||
GSList *lst, *cur;
|
GSList *lst, *cur;
|
||||||
lst = mu_msg_gmime_contacts_list (msg);
|
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;
|
cur = lst;
|
||||||
|
|
||||||
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
|
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
|
||||||
==, NULL);
|
==, "Mickey Mouse");
|
||||||
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
|
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
|
||||||
==, "anon@example.com");
|
==, "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);
|
mu_msg_contact_list_free (lst);
|
||||||
}
|
}
|
||||||
|
@ -141,14 +149,22 @@ test_mu_msg_gmime_02 (void)
|
||||||
{
|
{
|
||||||
GSList *lst, *cur;
|
GSList *lst, *cur;
|
||||||
lst = mu_msg_gmime_contacts_list (msg);
|
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;
|
cur = lst;
|
||||||
|
|
||||||
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
|
g_assert_cmpstr (mu_msg_contact_name ((MuMsgContact*)cur->data),
|
||||||
==, NULL);
|
==, NULL);
|
||||||
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
|
g_assert_cmpstr (mu_msg_contact_address ((MuMsgContact*)cur->data),
|
||||||
==, "anon@example.com");
|
==, "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);
|
mu_msg_contact_list_free (lst);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -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
|
EMSS04I00.us.lmco.com with Microsoft SMTPSVC(5.0.2195.6713); Wed, 06 Aug
|
||||||
2008 23:14:20 -0400
|
2008 23:14:20 -0400
|
||||||
Date: Thu, 31 Jul 2008 14:57:25 -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
|
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>
|
Message-id: <3BE9E6535E3029448670913581E7A1A20D852173@emss35m06.us.lmco.com>
|
||||||
MIME-version: 1.0
|
MIME-version: 1.0
|
||||||
Content-type: text/plain; charset=us-ascii
|
Content-type: text/plain; charset=us-ascii
|
||||||
|
|
Loading…
Reference in New Issue