mirror of https://github.com/djcb/mu.git
* mu_msg_str: add mu_msg_str_display_contact[_s], to guess the name-part from
the values in To/Cc/Bcc/From fields. (ie. '"Foo Bar" <foo@bar.cuux>' => 'Foo Bar')
This commit is contained in:
parent
aaa5f6220d
commit
a7a76e7989
|
@ -195,3 +195,37 @@ mu_msg_str_summarize (const char* str, size_t max_lines)
|
|||
return summary;
|
||||
}
|
||||
|
||||
|
||||
const char*
|
||||
mu_msg_str_display_contact_s (const char *str)
|
||||
{
|
||||
static gchar contact[255];
|
||||
gchar *c, *c2;
|
||||
|
||||
if (!str)
|
||||
str = "";
|
||||
|
||||
g_strlcpy (contact, str, sizeof(contact));
|
||||
|
||||
/* strip the address, if any */
|
||||
c = g_strstr_len (contact, -1, "<");
|
||||
if (c != NULL)
|
||||
*c = '\0';
|
||||
|
||||
/* replace " with space */
|
||||
for (c2 = contact; *c2; ++c2)
|
||||
if (*c2 == '"')
|
||||
*c2 = ' ';
|
||||
|
||||
g_strstrip (contact);
|
||||
|
||||
return contact;
|
||||
}
|
||||
|
||||
char*
|
||||
mu_msg_str_display_contact (const char *str)
|
||||
{
|
||||
g_return_val_if_fail (str, NULL);
|
||||
|
||||
return g_strdup (mu_msg_str_display_contact_s (str));
|
||||
}
|
||||
|
|
|
@ -61,6 +61,27 @@ char* mu_msg_str_date (const char* frm, time_t t) G_GNUC_WARN_UNUSED_RES
|
|||
const char* mu_msg_str_display_date_s (time_t t);
|
||||
|
||||
|
||||
/**
|
||||
* create a 'display contact' from an email header To/Cc/Bcc/From-type address
|
||||
* ie., turn
|
||||
* "Foo Bar" <foo@bar.com>
|
||||
* into
|
||||
* Foo Bar
|
||||
* Note that this is based on some simple heuristics. Max length is 255 bytes.
|
||||
*
|
||||
* mu_msg_str_display_contact_s returns a statically allocated
|
||||
* buffer (ie, non-reentrant), while mu_msg_str_display_contact
|
||||
* returns a newly allocated string that you must free with g_free
|
||||
* when done with it.
|
||||
*
|
||||
* @param str a 'contact str' (ie., what is in the To/Cc/Bcc/From fields), or NULL
|
||||
*
|
||||
* @return a newly allocated string with a display contact
|
||||
*/
|
||||
const char* mu_msg_str_display_contact_s (const char *str);
|
||||
char *mu_msg_str_display_contact (const char *str);
|
||||
|
||||
|
||||
/**
|
||||
* get a display size for a given size_t; uses M for sizes >
|
||||
* 1000*1000, k for smaller sizes. Note: this function use the
|
||||
|
|
Loading…
Reference in New Issue