* mu-msg.c: make mu_msg_contacts_foreach also work for the Xapian::Document backend
This commit is contained in:
87
src/mu-msg.c
87
src/mu-msg.c
@ -521,25 +521,19 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
|
|||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
address_list_foreach (InternetAddressList *addrlist,
|
address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
|
||||||
MuMsgContactType ctype,
|
MuMsgContactForeachFunc func, gpointer user_data)
|
||||||
MuMsgContactForeachFunc func,
|
|
||||||
gpointer user_data)
|
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if (!addrlist)
|
for (i = 0; addrlist && i != internet_address_list_length(addrlist);
|
||||||
return;
|
++i) {
|
||||||
|
|
||||||
for (i = 0; i != internet_address_list_length(addrlist); ++i) {
|
|
||||||
|
|
||||||
MuMsgContact contact;
|
MuMsgContact contact;
|
||||||
if (!fill_contact(&contact,
|
if (!fill_contact(&contact,
|
||||||
internet_address_list_get_address (addrlist, i),
|
internet_address_list_get_address (addrlist, i),
|
||||||
ctype)) {
|
ctype))
|
||||||
MU_WRITE_LOG ("ignoring contact");
|
|
||||||
continue;
|
continue;
|
||||||
}
|
|
||||||
|
|
||||||
if (!(func)(&contact, user_data))
|
if (!(func)(&contact, user_data))
|
||||||
break;
|
break;
|
||||||
@ -547,30 +541,25 @@ address_list_foreach (InternetAddressList *addrlist,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
get_contacts_from (MuMsg *msg, MuMsgContactForeachFunc func,
|
addresses_foreach (const char* addrs, MuMsgContactType ctype,
|
||||||
gpointer user_data)
|
MuMsgContactForeachFunc func, gpointer user_data)
|
||||||
{
|
{
|
||||||
InternetAddressList *lst;
|
InternetAddressList *addrlist;
|
||||||
|
|
||||||
/* 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 */
|
|
||||||
lst = internet_address_list_parse_string (
|
|
||||||
g_mime_message_get_sender (msg->_file->_mime_msg));
|
|
||||||
|
|
||||||
if (lst) {
|
if (!addrs)
|
||||||
address_list_foreach (lst, MU_MSG_CONTACT_TYPE_FROM,
|
return;
|
||||||
func, user_data);
|
|
||||||
g_object_unref (G_OBJECT(lst));
|
addrlist = internet_address_list_parse_string (addrs);
|
||||||
}
|
if (addrlist) {
|
||||||
|
address_list_foreach (addrlist, ctype, func, user_data);
|
||||||
|
g_object_unref (addrlist);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void
|
void
|
||||||
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
msg_contact_foreach_file (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||||
gpointer user_data)
|
gpointer user_data)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
@ -583,12 +572,10 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
|||||||
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
{GMIME_RECIPIENT_TYPE_BCC, MU_MSG_CONTACT_TYPE_BCC},
|
||||||
};
|
};
|
||||||
|
|
||||||
g_return_if_fail (msg && msg->_file);
|
/* sender */
|
||||||
g_return_if_fail (func);
|
addresses_foreach (g_mime_message_get_sender (msg->_file->_mime_msg),
|
||||||
|
MU_MSG_CONTACT_TYPE_FROM, func, user_data);
|
||||||
|
|
||||||
/* first, get the from address(es) */
|
|
||||||
get_contacts_from (msg, func, user_data);
|
|
||||||
|
|
||||||
/* get to, cc, bcc */
|
/* get to, cc, bcc */
|
||||||
for (i = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
for (i = 0; i != G_N_ELEMENTS(ctypes); ++i) {
|
||||||
InternetAddressList *addrlist;
|
InternetAddressList *addrlist;
|
||||||
@ -599,6 +586,38 @@ mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
static void
|
||||||
|
msg_contact_foreach_doc (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
addresses_foreach (mu_msg_get_from (msg),
|
||||||
|
MU_MSG_CONTACT_TYPE_FROM, func, user_data);
|
||||||
|
addresses_foreach (mu_msg_get_to (msg),
|
||||||
|
MU_MSG_CONTACT_TYPE_TO, func, user_data);
|
||||||
|
addresses_foreach (mu_msg_get_cc (msg),
|
||||||
|
MU_MSG_CONTACT_TYPE_CC, func, user_data);
|
||||||
|
addresses_foreach (mu_msg_get_bcc (msg),
|
||||||
|
MU_MSG_CONTACT_TYPE_BCC, func, user_data);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
mu_msg_contact_foreach (MuMsg *msg, MuMsgContactForeachFunc func,
|
||||||
|
gpointer user_data)
|
||||||
|
{
|
||||||
|
g_return_if_fail (msg);
|
||||||
|
g_return_if_fail (func);
|
||||||
|
|
||||||
|
if (msg->_doc)
|
||||||
|
msg_contact_foreach_doc (msg, func, user_data);
|
||||||
|
else if (msg->_file)
|
||||||
|
msg_contact_foreach_file (msg, func, user_data);
|
||||||
|
else
|
||||||
|
g_return_if_reached ();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
cmp_str (const char* s1, const char *s2)
|
cmp_str (const char* s1, const char *s2)
|
||||||
{
|
{
|
||||||
|
|||||||
Reference in New Issue
Block a user