update store, msg for new contacts-cache handling

This commit is contained in:
djcb 2019-05-11 13:29:23 +03:00
parent c858651d0c
commit 9edcae0203
6 changed files with 49 additions and 39 deletions

View File

@ -102,8 +102,8 @@ add_contact (JsonArray **arr, MuMsgContact *c)
cell = json_object_new ();
if (c->name)
json_object_set_string_member (cell, "name", c->name);
if (c->address)
json_object_set_string_member (cell, "email", c->address);
if (c->email)
json_object_set_string_member (cell, "email", c->email);
json_array_add_object_element (*arr, cell); /* consumes */
}

View File

@ -90,21 +90,21 @@ struct _ContactData {
typedef struct _ContactData ContactData;
static gchar*
get_name_addr_pair (MuMsgContact *c)
get_name_email_pair (MuMsgContact *c)
{
gchar *name, *addr, *pair;
gchar *name, *email, *pair;
name = (char*)mu_msg_contact_name(c);
addr = (char*)mu_msg_contact_address(c);
name = (char*)mu_msg_contact_name(c);
email = (char*)mu_msg_contact_email(c);
name = name ? mu_str_escape_c_literal (name, TRUE) : NULL;
addr = addr ? mu_str_escape_c_literal (addr, TRUE) : NULL;
name = name ? mu_str_escape_c_literal (name, TRUE) : NULL;
email = email ? mu_str_escape_c_literal (email, TRUE) : NULL;
pair = g_strdup_printf ("(%s . %s)",
name ? name : "nil",
addr ? addr : "nil");
email ? email : "nil");
g_free (name);
g_free (addr);
g_free (email);
return pair;
}
@ -156,7 +156,7 @@ each_contact (MuMsgContact *c, ContactData *cdata)
cdata->prev_ctype = ctype;
pair = get_name_addr_pair (c);
pair = get_name_email_pair (c);
g_string_append (cdata->gstr, pair);
g_free (pair);

View File

@ -613,6 +613,9 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
if (!addr)
return FALSE;
self->full_address = internet_address_to_string (
addr, NULL, FALSE);
self->name = internet_address_get_name (addr);
if (mu_str_is_empty (self->name)) {
self->name = NULL;
@ -624,20 +627,20 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
* check, g_mime hits an assert
*/
if (INTERNET_ADDRESS_IS_MAILBOX(addr))
self->address = internet_address_mailbox_get_addr
self->email= internet_address_mailbox_get_addr
(INTERNET_ADDRESS_MAILBOX(addr));
else
self->address = NULL;
self->email = NULL;
/* if there's no address, just a name, it's probably a local
* address (without @) */
if (self->name && !self->address)
self->address = self->name;
if (self->name && !self->email)
self->email = self->name;
/* note, the address could NULL e.g. when the recipient is something like
* 'Undisclosed recipients'
/* note, the address could be NULL e.g. when the recipient is something
* like 'Undisclosed recipients'
*/
return self->address != NULL;
return self->email != NULL;
}
static void
@ -652,13 +655,18 @@ address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
len = internet_address_list_length(addrlist);
for (i = 0; i != len; ++i) {
MuMsgContact contact;
MuMsgContact contact;
gboolean keep_going;
if (!fill_contact(&contact,
internet_address_list_get_address (addrlist, i),
ctype))
continue;
if (!(func)(&contact, user_data))
keep_going = func(&contact, user_data);
g_free ((char*)contact.full_address);
if (!keep_going)
break;
}
}

View File

@ -545,10 +545,11 @@ typedef guint MuMsgContactType;
((MCT) < MU_MSG_CONTACT_TYPE_NUM)
struct _MuMsgContact {
const char *name; /* Foo Bar */
const char *address; /* foo@bar.cuux */
MuMsgContactType type; /* MU_MSG_CONTACT_TYPE_{ TO,
* CC, BCC, FROM, REPLY_TO} */
const char *name; /**< Foo Bar */
const char *email; /**< foo@bar.cuux */
const char *full_address; /**< Foo Bar <foo@bar.cuux> */
MuMsgContactType type; /**< MU_MSG_CONTACT_TYPE_{ TO,
CC, BCC, FROM, REPLY_TO} */
};
typedef struct _MuMsgContact MuMsgContact;
@ -563,13 +564,13 @@ typedef struct _MuMsgContact MuMsgContact;
#define mu_msg_contact_name(ct) ((ct)->name)
/**
* macro to get the address of a contact
* macro to get the email address of a contact
*
* @param ct a MuMsgContact
*
* @return the address
*/
#define mu_msg_contact_address(ct) ((ct)->address)
#define mu_msg_contact_email(ct) ((ct)->email)
/**
* macro to get the contact type

View File

@ -594,17 +594,18 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
termgen.index_text (flat, 1, pfx);
}
if (!mu_str_is_empty(contact->address)) {
const auto flat = Mux::utf8_flatten(contact->address);
if (!mu_str_is_empty(contact->email)) {
const auto flat = Mux::utf8_flatten(contact->email);
add_term(*msgdoc->_doc, pfx + flat);
add_address_subfields (*msgdoc->_doc, contact->address, pfx);
add_address_subfields (*msgdoc->_doc, contact->email, pfx);
/* store it also in our contacts cache */
auto contacts = msgdoc->_store->contacts();
if (contacts)
contacts->add(contact->address,
contact->name ? contact->name : "",
msgdoc->_personal,
mu_msg_get_date(msgdoc->_msg));
contacts->add(Mu::ContactInfo(contact->full_address,
contact->email,
contact->name ? contact->name : "",
msgdoc->_personal,
mu_msg_get_date(msgdoc->_msg)));
}
return TRUE;
@ -616,12 +617,12 @@ each_contact_check_if_personal (MuMsgContact *contact, MsgDoc *msgdoc)
{
GSList *cur;
if (msgdoc->_personal || !contact->address)
if (msgdoc->_personal || !contact->email)
return TRUE;
for (cur = msgdoc->_my_addresses; cur; cur = g_slist_next (cur)) {
if (g_ascii_strcasecmp (
contact->address, (const char*)cur->data) == 0) {
contact->email, (const char*)cur->data) == 0) {
msgdoc->_personal = TRUE;
break;
}

View File

@ -65,13 +65,13 @@ check_contact_01 (MuMsgContact *contact, int *idx)
case 0:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, "Mickey Mouse");
g_assert_cmpstr (mu_msg_contact_address (contact),
g_assert_cmpstr (mu_msg_contact_email (contact),
==, "anon@example.com");
break;
case 1:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, "Donald Duck");
g_assert_cmpstr (mu_msg_contact_address (contact),
g_assert_cmpstr (mu_msg_contact_email (contact),
==, "gcc-help@gcc.gnu.org");
break;
default:
@ -128,13 +128,13 @@ check_contact_02 (MuMsgContact *contact, int *idx)
case 0:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address (contact),
g_assert_cmpstr (mu_msg_contact_email (contact),
==, "anon@example.com");
break;
case 1:
g_assert_cmpstr (mu_msg_contact_name (contact),
==, NULL);
g_assert_cmpstr (mu_msg_contact_address (contact),
g_assert_cmpstr (mu_msg_contact_email (contact),
==, "help-gnu-emacs@gnu.org");
break;
default: