diff options
author | Milan Crha <mcrha@redhat.com> | 2008-01-21 18:21:29 +0800 |
---|---|---|
committer | Milan Crha <mcrha@src.gnome.org> | 2008-01-21 18:21:29 +0800 |
commit | 2be6b60d8311b0fd537a2889f8997d3f084755b0 (patch) | |
tree | 3d867d516d19fcb3240c08d6beb3343e5110949d /addressbook/gui/widgets/eab-gui-util.c | |
parent | a63fbb553de7beeec54b6d691e80f650b3548e91 (diff) | |
download | gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.tar gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.tar.gz gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.tar.bz2 gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.tar.lz gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.tar.xz gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.tar.zst gsoc2013-evolution-2be6b60d8311b0fd537a2889f8997d3f084755b0.zip |
** Fix for bug #324604 inspired by patch of makuchaku (Mayank)
2008-01-21 Milan Crha <mcrha@redhat.com>
** Fix for bug #324604 inspired by patch of makuchaku (Mayank)
* gui/widgets/eab-gui-util.h:
* gui/widgets/eab-gui-util.c: (eab_parse_qp_email),
(eab_parse_qp_email_to_html): New helper functions for decoding
email addresses from RFC822 or RFC2047 form to UTF-8.
* gui/widgets/e-minicard.c: (add_email_field):
* gui/widgets/eab-contact-display.c: (render_contact_list),
(render_contact), (eab_contact_display_render_compact):
* gui/widgets/e-addressbook-table-adapter.c:
(struct _EAddressbookTableAdapterPrivate), (addressbook_dispose),
(addressbook_value_at), (addressbook_set_value_at), (remove_contacts),
(modify_contact), (model_changed), (eab_table_adapter_construct):
* gui/widgets/eab-gui-util.c: (get_email),
(eab_send_contact_list_as_attachment):
Ensure the print of the email is transformed from RFC822 or RFC2047.
svn path=/trunk/; revision=34863
Diffstat (limited to 'addressbook/gui/widgets/eab-gui-util.c')
-rw-r--r-- | addressbook/gui/widgets/eab-gui-util.c | 97 |
1 files changed, 91 insertions, 6 deletions
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c index 9124583b82..842e954f20 100644 --- a/addressbook/gui/widgets/eab-gui-util.c +++ b/addressbook/gui/widgets/eab-gui-util.c @@ -34,11 +34,15 @@ #include "util/eab-book-util.h" #include <libebook/e-destination.h> #include "e-util/e-error.h" +#include "e-util/e-html-utils.h" #include "misc/e-image-chooser.h" #include <e-util/e-icon-factory.h> #include "eab-contact-merging.h" #include <gnome.h> +/* we link to camel for decoding quoted printable email addresses */ +#include <camel/camel-mime-utils.h> + #include "addressbook/gui/contact-editor/eab-editor.h" #include "addressbook/gui/contact-editor/e-contact-editor.h" #include "addressbook/gui/contact-list-editor/e-contact-list-editor.h" @@ -932,6 +936,25 @@ eab_send_to_contact_and_email_num_list (GList *c) CORBA_exception_free (&ev); } +static const char * +get_email (EContact *contact, EContactField field_id, gchar **to_free) +{ + char *name = NULL, *mail = NULL; + const char *value = e_contact_get_const (contact, field_id); + + *to_free = NULL; + + if (eab_parse_qp_email (value, &name, &mail)) { + *to_free = g_strdup_printf ("%s <%s>", name, mail); + value = *to_free; + } + + g_free (name); + g_free (mail); + + return value; +} + static void eab_send_contact_list_as_attachment (GList *contacts) { @@ -1005,18 +1028,25 @@ eab_send_contact_list_as_attachment (GList *contacts) } else { EContact *contact = contacts->data; const gchar *tempstr2; + gchar *tempfree = NULL; tempstr2 = e_contact_get_const (contact, E_CONTACT_FILE_AS); if (!tempstr2 || !*tempstr2) tempstr2 = e_contact_get_const (contact, E_CONTACT_FULL_NAME); if (!tempstr2 || !*tempstr2) tempstr2 = e_contact_get_const (contact, E_CONTACT_ORG); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_1); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_2); - if (!tempstr2 || !*tempstr2) - tempstr2 = e_contact_get_const (contact, E_CONTACT_EMAIL_3); + if (!tempstr2 || !*tempstr2) { + g_free (tempfree); + tempstr2 = get_email (contact, E_CONTACT_EMAIL_1, &tempfree); + } + if (!tempstr2 || !*tempstr2) { + g_free (tempfree); + tempstr2 = get_email (contact, E_CONTACT_EMAIL_2, &tempfree); + } + if (!tempstr2 || !*tempstr2) { + g_free (tempfree); + tempstr2 = get_email (contact, E_CONTACT_EMAIL_3, &tempfree); + } if (!tempstr2 || !*tempstr2) tempstr = g_strdup_printf (_("Contact information")); @@ -1024,6 +1054,7 @@ eab_send_contact_list_as_attachment (GList *contacts) tempstr = g_strdup_printf (_("Contact information for %s"), tempstr2); subject = CORBA_string_dup (tempstr); g_free (tempstr); + g_free (tempfree); } GNOME_Evolution_Composer_setHeaders (composer_server, "", to_list, cc_list, bcc_list, subject, &ev); @@ -1118,3 +1149,57 @@ eab_create_image_chooser_widget(gchar *name, return w; } + +/* To parse something like... +=?UTF-8?Q?=E0=A4=95=E0=A4=95=E0=A4=AC=E0=A5=82=E0=A5=8B=E0=A5=87?=\t\n=?UTF-8?Q?=E0=A4=B0?=\t\n<aa@aa.ccom> +and return the decoded representation of name & email parts. +*/ +gboolean +eab_parse_qp_email (const gchar *string, gchar **name, gchar **email) +{ + struct _camel_header_address *address; + gboolean res = FALSE; + + address = camel_header_address_decode (string, "UTF-8"); + + if (!address) + return FALSE; + + /* report success only when we have filled both name and email address */ + if (address->type == CAMEL_HEADER_ADDRESS_NAME && address->name && *address->name && address->v.addr && *address->v.addr) { + *name = g_strdup (address->name); + *email = g_strdup (address->v.addr); + res = TRUE; + } + + camel_header_address_unref (address); + + return res; +} + +/* This is only wrapper to parse_qp_mail, it decodes string and if returned TRUE, + then makes one string and returns it, otherwise returns NULL. + Returned string is usable to place directly into GtkHtml stream. + Returned value should be freed with g_free. */ +char * +eab_parse_qp_email_to_html (const gchar *string) +{ + char *name = NULL, *mail = NULL; + char *html_name, *html_mail; + char *value; + + if (!eab_parse_qp_email (string, &name, &mail)) + return NULL; + + html_name = e_text_to_html (name, 0); + html_mail = e_text_to_html (mail, E_TEXT_TO_HTML_CONVERT_ADDRESSES); + + value = g_strdup_printf ("%s <%s>", html_name, html_mail); + + g_free (html_name); + g_free (html_mail); + g_free (name); + g_free (mail); + + return value; +} |