mirror of https://github.com/djcb/mu.git
update store, msg for new contacts-cache handling
This commit is contained in:
parent
c858651d0c
commit
9edcae0203
|
@ -102,8 +102,8 @@ add_contact (JsonArray **arr, MuMsgContact *c)
|
||||||
cell = json_object_new ();
|
cell = json_object_new ();
|
||||||
if (c->name)
|
if (c->name)
|
||||||
json_object_set_string_member (cell, "name", c->name);
|
json_object_set_string_member (cell, "name", c->name);
|
||||||
if (c->address)
|
if (c->email)
|
||||||
json_object_set_string_member (cell, "email", c->address);
|
json_object_set_string_member (cell, "email", c->email);
|
||||||
|
|
||||||
json_array_add_object_element (*arr, cell); /* consumes */
|
json_array_add_object_element (*arr, cell); /* consumes */
|
||||||
}
|
}
|
||||||
|
|
|
@ -90,21 +90,21 @@ struct _ContactData {
|
||||||
typedef struct _ContactData ContactData;
|
typedef struct _ContactData ContactData;
|
||||||
|
|
||||||
static gchar*
|
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);
|
name = (char*)mu_msg_contact_name(c);
|
||||||
addr = (char*)mu_msg_contact_address(c);
|
email = (char*)mu_msg_contact_email(c);
|
||||||
|
|
||||||
name = name ? mu_str_escape_c_literal (name, TRUE) : NULL;
|
name = name ? mu_str_escape_c_literal (name, TRUE) : NULL;
|
||||||
addr = addr ? mu_str_escape_c_literal (addr, TRUE) : NULL;
|
email = email ? mu_str_escape_c_literal (email, TRUE) : NULL;
|
||||||
|
|
||||||
pair = g_strdup_printf ("(%s . %s)",
|
pair = g_strdup_printf ("(%s . %s)",
|
||||||
name ? name : "nil",
|
name ? name : "nil",
|
||||||
addr ? addr : "nil");
|
email ? email : "nil");
|
||||||
g_free (name);
|
g_free (name);
|
||||||
g_free (addr);
|
g_free (email);
|
||||||
|
|
||||||
return pair;
|
return pair;
|
||||||
}
|
}
|
||||||
|
@ -156,7 +156,7 @@ each_contact (MuMsgContact *c, ContactData *cdata)
|
||||||
|
|
||||||
cdata->prev_ctype = ctype;
|
cdata->prev_ctype = ctype;
|
||||||
|
|
||||||
pair = get_name_addr_pair (c);
|
pair = get_name_email_pair (c);
|
||||||
g_string_append (cdata->gstr, pair);
|
g_string_append (cdata->gstr, pair);
|
||||||
g_free (pair);
|
g_free (pair);
|
||||||
|
|
||||||
|
|
24
lib/mu-msg.c
24
lib/mu-msg.c
|
@ -613,6 +613,9 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
|
||||||
if (!addr)
|
if (!addr)
|
||||||
return FALSE;
|
return FALSE;
|
||||||
|
|
||||||
|
self->full_address = internet_address_to_string (
|
||||||
|
addr, NULL, FALSE);
|
||||||
|
|
||||||
self->name = internet_address_get_name (addr);
|
self->name = internet_address_get_name (addr);
|
||||||
if (mu_str_is_empty (self->name)) {
|
if (mu_str_is_empty (self->name)) {
|
||||||
self->name = NULL;
|
self->name = NULL;
|
||||||
|
@ -624,20 +627,20 @@ fill_contact (MuMsgContact *self, InternetAddress *addr,
|
||||||
* check, g_mime hits an assert
|
* check, g_mime hits an assert
|
||||||
*/
|
*/
|
||||||
if (INTERNET_ADDRESS_IS_MAILBOX(addr))
|
if (INTERNET_ADDRESS_IS_MAILBOX(addr))
|
||||||
self->address = internet_address_mailbox_get_addr
|
self->email= internet_address_mailbox_get_addr
|
||||||
(INTERNET_ADDRESS_MAILBOX(addr));
|
(INTERNET_ADDRESS_MAILBOX(addr));
|
||||||
else
|
else
|
||||||
self->address = NULL;
|
self->email = NULL;
|
||||||
|
|
||||||
/* if there's no address, just a name, it's probably a local
|
/* if there's no address, just a name, it's probably a local
|
||||||
* address (without @) */
|
* address (without @) */
|
||||||
if (self->name && !self->address)
|
if (self->name && !self->email)
|
||||||
self->address = self->name;
|
self->email = self->name;
|
||||||
|
|
||||||
/* note, the address could NULL e.g. when the recipient is something like
|
/* note, the address could be NULL e.g. when the recipient is something
|
||||||
* 'Undisclosed recipients'
|
* like 'Undisclosed recipients'
|
||||||
*/
|
*/
|
||||||
return self->address != NULL;
|
return self->email != NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
@ -653,12 +656,17 @@ address_list_foreach (InternetAddressList *addrlist, MuMsgContactType ctype,
|
||||||
|
|
||||||
for (i = 0; i != len; ++i) {
|
for (i = 0; i != len; ++i) {
|
||||||
MuMsgContact contact;
|
MuMsgContact contact;
|
||||||
|
gboolean keep_going;
|
||||||
|
|
||||||
if (!fill_contact(&contact,
|
if (!fill_contact(&contact,
|
||||||
internet_address_list_get_address (addrlist, i),
|
internet_address_list_get_address (addrlist, i),
|
||||||
ctype))
|
ctype))
|
||||||
continue;
|
continue;
|
||||||
|
|
||||||
if (!(func)(&contact, user_data))
|
keep_going = func(&contact, user_data);
|
||||||
|
g_free ((char*)contact.full_address);
|
||||||
|
|
||||||
|
if (!keep_going)
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
13
lib/mu-msg.h
13
lib/mu-msg.h
|
@ -545,10 +545,11 @@ typedef guint MuMsgContactType;
|
||||||
((MCT) < MU_MSG_CONTACT_TYPE_NUM)
|
((MCT) < MU_MSG_CONTACT_TYPE_NUM)
|
||||||
|
|
||||||
struct _MuMsgContact {
|
struct _MuMsgContact {
|
||||||
const char *name; /* Foo Bar */
|
const char *name; /**< Foo Bar */
|
||||||
const char *address; /* foo@bar.cuux */
|
const char *email; /**< foo@bar.cuux */
|
||||||
MuMsgContactType type; /* MU_MSG_CONTACT_TYPE_{ TO,
|
const char *full_address; /**< Foo Bar <foo@bar.cuux> */
|
||||||
* CC, BCC, FROM, REPLY_TO} */
|
MuMsgContactType type; /**< MU_MSG_CONTACT_TYPE_{ TO,
|
||||||
|
CC, BCC, FROM, REPLY_TO} */
|
||||||
};
|
};
|
||||||
typedef struct _MuMsgContact MuMsgContact;
|
typedef struct _MuMsgContact MuMsgContact;
|
||||||
|
|
||||||
|
@ -563,13 +564,13 @@ typedef struct _MuMsgContact MuMsgContact;
|
||||||
#define mu_msg_contact_name(ct) ((ct)->name)
|
#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
|
* @param ct a MuMsgContact
|
||||||
*
|
*
|
||||||
* @return the address
|
* @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
|
* macro to get the contact type
|
||||||
|
|
|
@ -594,17 +594,18 @@ each_contact_info (MuMsgContact *contact, MsgDoc *msgdoc)
|
||||||
termgen.index_text (flat, 1, pfx);
|
termgen.index_text (flat, 1, pfx);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!mu_str_is_empty(contact->address)) {
|
if (!mu_str_is_empty(contact->email)) {
|
||||||
const auto flat = Mux::utf8_flatten(contact->address);
|
const auto flat = Mux::utf8_flatten(contact->email);
|
||||||
add_term(*msgdoc->_doc, pfx + flat);
|
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 */
|
/* store it also in our contacts cache */
|
||||||
auto contacts = msgdoc->_store->contacts();
|
auto contacts = msgdoc->_store->contacts();
|
||||||
if (contacts)
|
if (contacts)
|
||||||
contacts->add(contact->address,
|
contacts->add(Mu::ContactInfo(contact->full_address,
|
||||||
|
contact->email,
|
||||||
contact->name ? contact->name : "",
|
contact->name ? contact->name : "",
|
||||||
msgdoc->_personal,
|
msgdoc->_personal,
|
||||||
mu_msg_get_date(msgdoc->_msg));
|
mu_msg_get_date(msgdoc->_msg)));
|
||||||
}
|
}
|
||||||
|
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
@ -616,12 +617,12 @@ each_contact_check_if_personal (MuMsgContact *contact, MsgDoc *msgdoc)
|
||||||
{
|
{
|
||||||
GSList *cur;
|
GSList *cur;
|
||||||
|
|
||||||
if (msgdoc->_personal || !contact->address)
|
if (msgdoc->_personal || !contact->email)
|
||||||
return TRUE;
|
return TRUE;
|
||||||
|
|
||||||
for (cur = msgdoc->_my_addresses; cur; cur = g_slist_next (cur)) {
|
for (cur = msgdoc->_my_addresses; cur; cur = g_slist_next (cur)) {
|
||||||
if (g_ascii_strcasecmp (
|
if (g_ascii_strcasecmp (
|
||||||
contact->address, (const char*)cur->data) == 0) {
|
contact->email, (const char*)cur->data) == 0) {
|
||||||
msgdoc->_personal = TRUE;
|
msgdoc->_personal = TRUE;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
|
@ -65,13 +65,13 @@ check_contact_01 (MuMsgContact *contact, int *idx)
|
||||||
case 0:
|
case 0:
|
||||||
g_assert_cmpstr (mu_msg_contact_name (contact),
|
g_assert_cmpstr (mu_msg_contact_name (contact),
|
||||||
==, "Mickey Mouse");
|
==, "Mickey Mouse");
|
||||||
g_assert_cmpstr (mu_msg_contact_address (contact),
|
g_assert_cmpstr (mu_msg_contact_email (contact),
|
||||||
==, "anon@example.com");
|
==, "anon@example.com");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
g_assert_cmpstr (mu_msg_contact_name (contact),
|
g_assert_cmpstr (mu_msg_contact_name (contact),
|
||||||
==, "Donald Duck");
|
==, "Donald Duck");
|
||||||
g_assert_cmpstr (mu_msg_contact_address (contact),
|
g_assert_cmpstr (mu_msg_contact_email (contact),
|
||||||
==, "gcc-help@gcc.gnu.org");
|
==, "gcc-help@gcc.gnu.org");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -128,13 +128,13 @@ check_contact_02 (MuMsgContact *contact, int *idx)
|
||||||
case 0:
|
case 0:
|
||||||
g_assert_cmpstr (mu_msg_contact_name (contact),
|
g_assert_cmpstr (mu_msg_contact_name (contact),
|
||||||
==, NULL);
|
==, NULL);
|
||||||
g_assert_cmpstr (mu_msg_contact_address (contact),
|
g_assert_cmpstr (mu_msg_contact_email (contact),
|
||||||
==, "anon@example.com");
|
==, "anon@example.com");
|
||||||
break;
|
break;
|
||||||
case 1:
|
case 1:
|
||||||
g_assert_cmpstr (mu_msg_contact_name (contact),
|
g_assert_cmpstr (mu_msg_contact_name (contact),
|
||||||
==, NULL);
|
==, NULL);
|
||||||
g_assert_cmpstr (mu_msg_contact_address (contact),
|
g_assert_cmpstr (mu_msg_contact_email (contact),
|
||||||
==, "help-gnu-emacs@gnu.org");
|
==, "help-gnu-emacs@gnu.org");
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
|
Loading…
Reference in New Issue