aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMilan Crha <mcrha@redhat.com>2013-01-23 00:06:53 +0800
committerMilan Crha <mcrha@redhat.com>2013-01-23 00:06:53 +0800
commit41edc5515b6e9333b36a39bb31ebbd455e74d73d (patch)
treeb47af0cc448596c20151cb482cf9b244f65a7b4d
parentdde7200f40a26aa9a70949a56aae0a53bbf67afd (diff)
downloadgsoc2013-evolution-41edc5515b6e9333b36a39bb31ebbd455e74d73d.tar.gz
gsoc2013-evolution-41edc5515b6e9333b36a39bb31ebbd455e74d73d.tar.zst
gsoc2013-evolution-41edc5515b6e9333b36a39bb31ebbd455e74d73d.zip
Contact's print doesn't decode QP encoded email addresses
-rw-r--r--addressbook/gui/widgets/Makefile.am1
-rw-r--r--addressbook/gui/widgets/e-addressbook-table-adapter.c1
-rw-r--r--addressbook/gui/widgets/e-minicard.c1
-rw-r--r--addressbook/gui/widgets/eab-contact-formatter.c1
-rw-r--r--addressbook/gui/widgets/eab-gui-util.c55
-rw-r--r--addressbook/gui/widgets/eab-gui-util.h6
-rw-r--r--addressbook/printing/Makefile.am1
-rw-r--r--addressbook/printing/e-contact-print.c55
-rw-r--r--addressbook/util/Makefile.am4
-rw-r--r--addressbook/util/eab-book-util.c56
-rw-r--r--addressbook/util/eab-book-util.h6
11 files changed, 120 insertions, 67 deletions
diff --git a/addressbook/gui/widgets/Makefile.am b/addressbook/gui/widgets/Makefile.am
index 4881613c79..79652c4249 100644
--- a/addressbook/gui/widgets/Makefile.am
+++ b/addressbook/gui/widgets/Makefile.am
@@ -75,6 +75,7 @@ libeabwidgets_la_SOURCES = \
libeabwidgets_la_LIBADD = \
$(top_builddir)/shell/libeshell.la \
$(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/addressbook/util/libeabutil.la \
$(EVOLUTION_DATA_SERVER_LIBS) \
$(GNOME_PLATFORM_LIBS) \
$(GTKHTML_LIBS) \
diff --git a/addressbook/gui/widgets/e-addressbook-table-adapter.c b/addressbook/gui/widgets/e-addressbook-table-adapter.c
index 51886cf186..12be6c821d 100644
--- a/addressbook/gui/widgets/e-addressbook-table-adapter.c
+++ b/addressbook/gui/widgets/e-addressbook-table-adapter.c
@@ -30,6 +30,7 @@
#include "e-addressbook-model.h"
#include "e-addressbook-table-adapter.h"
+#include "eab-book-util.h"
#include "eab-contact-merging.h"
#include "eab-gui-util.h"
#include <libxml/tree.h>
diff --git a/addressbook/gui/widgets/e-minicard.c b/addressbook/gui/widgets/e-minicard.c
index 6a049aca50..d5a1a3ce99 100644
--- a/addressbook/gui/widgets/e-minicard.c
+++ b/addressbook/gui/widgets/e-minicard.c
@@ -34,6 +34,7 @@
#include "e-util/e-util.h"
+#include "eab-book-util.h"
#include "eab-gui-util.h"
#include "e-minicard-label.h"
#include "e-minicard-view.h"
diff --git a/addressbook/gui/widgets/eab-contact-formatter.c b/addressbook/gui/widgets/eab-contact-formatter.c
index 3684e4b81c..1e154d5a25 100644
--- a/addressbook/gui/widgets/eab-contact-formatter.c
+++ b/addressbook/gui/widgets/eab-contact-formatter.c
@@ -25,6 +25,7 @@
#include "e-util/e-util.h"
+#include "eab-book-util.h"
#include "eab-gui-util.h"
G_DEFINE_TYPE (
diff --git a/addressbook/gui/widgets/eab-gui-util.c b/addressbook/gui/widgets/eab-gui-util.c
index b692fdf2ce..089c12b573 100644
--- a/addressbook/gui/widgets/eab-gui-util.c
+++ b/addressbook/gui/widgets/eab-gui-util.c
@@ -617,61 +617,6 @@ eab_transfer_contacts (ESourceRegistry *registry,
book_loaded_cb, process);
}
-/* 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. */
-gchar *
-eab_parse_qp_email_to_html (const gchar *string)
-{
- gchar *name = NULL, *mail = NULL;
- gchar *html_name, *html_mail;
- gchar *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 &lt;%s&gt;", html_name, html_mail);
-
- g_free (html_name);
- g_free (html_mail);
- g_free (name);
- g_free (mail);
-
- return value;
-}
-
/*
* eab_format_address helper function
*
diff --git a/addressbook/gui/widgets/eab-gui-util.h b/addressbook/gui/widgets/eab-gui-util.h
index 6d3c7bf5cb..d6c6cb24da 100644
--- a/addressbook/gui/widgets/eab-gui-util.h
+++ b/addressbook/gui/widgets/eab-gui-util.h
@@ -54,12 +54,6 @@ ESource * eab_select_source (ESourceRegistry *registry,
const gchar *select_uid,
GtkWindow *parent);
-/* To parse quoted printable address & return email & name fields */
-gboolean eab_parse_qp_email (const gchar *string,
- gchar **name,
- gchar **email);
-gchar * eab_parse_qp_email_to_html (const gchar *string);
-
gchar * eab_format_address (EContact *contact,
EContactField address_type);
diff --git a/addressbook/printing/Makefile.am b/addressbook/printing/Makefile.am
index 8b54d3817d..d03938f21d 100644
--- a/addressbook/printing/Makefile.am
+++ b/addressbook/printing/Makefile.am
@@ -24,6 +24,7 @@ libecontactprint_la_SOURCES = \
libecontactprint_la_LIBADD = \
$(top_builddir)/e-util/libeutil.la \
+ $(top_builddir)/addressbook/util/libeabutil.la \
$(EVOLUTION_DATA_SERVER_LIBS) \
$(GNOME_PLATFORM_LIBS) \
$(GTKHTML_LIBS)
diff --git a/addressbook/printing/e-contact-print.c b/addressbook/printing/e-contact-print.c
index e11273a5df..06d3cdf93e 100644
--- a/addressbook/printing/e-contact-print.c
+++ b/addressbook/printing/e-contact-print.c
@@ -36,6 +36,8 @@
#include "e-util/e-util.h"
#include "e-util/e-util-private.h"
+#include "addressbook/util/eab-book-util.h"
+
#include "e-contact-print.h"
typedef struct _EContactPrintContext EContactPrintContext;
@@ -226,6 +228,41 @@ e_contact_start_new_column (EContactPrintContext *ctxt)
}
}
+static gchar *
+get_contact_string_value (EContact *contact,
+ gint field)
+{
+ const gchar *value;
+
+ g_return_val_if_fail (contact != NULL, NULL);
+
+ value = e_contact_get_const (contact, field);
+ if (!value || !*value)
+ return NULL;
+
+ if (field == E_CONTACT_EMAIL_1 ||
+ field == E_CONTACT_EMAIL_2 ||
+ field == E_CONTACT_EMAIL_3 ||
+ field == E_CONTACT_EMAIL_4) {
+ gchar *email = NULL, *name = NULL;
+
+ if (eab_parse_qp_email (value, &name, &email)) {
+ gchar *res;
+
+ if (name && *name)
+ res = g_strdup_printf ("%s <%s>", name, email);
+ else
+ res = g_strdup_printf ("%s", email);
+
+ g_free (name);
+ g_free (email);
+
+ return res;
+ }
+ }
+ return g_strdup (value);
+}
+
static gdouble
e_contact_get_contact_height (EContact *contact,
EContactPrintContext *ctxt)
@@ -247,12 +284,14 @@ e_contact_get_contact_height (EContact *contact,
for (field = E_CONTACT_FILE_AS; field != E_CONTACT_LAST_SIMPLE_STRING; field++)
{
- const gchar *value;
+ gchar *value;
gchar *text;
- value = e_contact_get_const (contact, field);
- if (value == NULL || *value == '\0')
+ value = get_contact_string_value (contact, field);
+ if (value == NULL || *value == '\0') {
+ g_free (value);
continue;
+ }
text = g_strdup_printf (
"%s: %s",
@@ -263,6 +302,7 @@ e_contact_get_contact_height (EContact *contact,
cntct_height += .2 * get_font_height (ctxt->style->body_font);
+ g_free (value);
g_free (text);
}
@@ -314,16 +354,18 @@ e_contact_print_contact (EContact *contact,
for (field = E_CONTACT_FILE_AS; field != E_CONTACT_LAST_SIMPLE_STRING; field++)
{
- const gchar *value;
+ gchar *value;
gchar *text;
gint wrapped_lines = 0;
if (ctxt->y > page_height)
e_contact_start_new_column (ctxt);
- value = e_contact_get_const (contact, field);
- if (value == NULL || *value == '\0')
+ value = get_contact_string_value (contact, field);
+ if (value == NULL || *value == '\0') {
+ g_free (value);
continue;
+ }
text = g_strdup_printf (
"%s: %s",
@@ -349,6 +391,7 @@ e_contact_print_contact (EContact *contact,
ctxt->y += .2 * get_font_height (ctxt->style->body_font);
+ g_free (value);
g_free (text);
}
diff --git a/addressbook/util/Makefile.am b/addressbook/util/Makefile.am
index 10f3bb0b97..83bf1e7003 100644
--- a/addressbook/util/Makefile.am
+++ b/addressbook/util/Makefile.am
@@ -10,7 +10,9 @@ libeabutil_la_CPPFLAGS = \
-I$(top_srcdir) \
-I$(top_builddir)/shell \
-I$(top_srcdir)/shell \
+ $(CAMEL_CFLAGS) \
$(EVOLUTION_DATA_SERVER_CFLAGS) \
+ $(GTKHTML_CFLAGS) \
$(GNOME_PLATFORM_CFLAGS)
libeabutil_la_SOURCES = \
@@ -22,7 +24,9 @@ libeabutil_la_LDFLAGS = -avoid-version $(NO_UNDEFINED)
libeabutil_la_LIBADD = \
$(top_builddir)/e-util/libeutil.la \
$(top_builddir)/shell/libeshell.la \
+ $(CAMEL_LIBS) \
$(EVOLUTION_DATA_SERVER_LIBS) \
+ $(GTKHTML_LIBS) \
$(GNOME_PLATFORM_LIBS)
dist-hook:
diff --git a/addressbook/util/eab-book-util.c b/addressbook/util/eab-book-util.c
index 7104c445cb..161d848ce6 100644
--- a/addressbook/util/eab-book-util.c
+++ b/addressbook/util/eab-book-util.c
@@ -27,6 +27,7 @@
#include <string.h>
+#include "e-util/e-util.h"
#include "eab-book-util.h"
/* Copied from camel_strstrcase */
@@ -244,3 +245,58 @@ e_utf8_casefold_collate (const gchar *str1,
{
return e_utf8_casefold_collate_len (str1, str2, -1);
}
+
+/* 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. */
+gchar *
+eab_parse_qp_email_to_html (const gchar *string)
+{
+ gchar *name = NULL, *mail = NULL;
+ gchar *html_name, *html_mail;
+ gchar *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 &lt;%s&gt;", html_name, html_mail);
+
+ g_free (html_name);
+ g_free (html_mail);
+ g_free (name);
+ g_free (mail);
+
+ return value;
+}
diff --git a/addressbook/util/eab-book-util.h b/addressbook/util/eab-book-util.h
index f05c9a7bbd..45602c2547 100644
--- a/addressbook/util/eab-book-util.h
+++ b/addressbook/util/eab-book-util.h
@@ -45,6 +45,12 @@ gint e_utf8_casefold_collate_len (const gchar *str1,
gint e_utf8_casefold_collate (const gchar *str1,
const gchar *str2);
+/* To parse quoted printable address & return email & name fields */
+gboolean eab_parse_qp_email (const gchar *string,
+ gchar **name,
+ gchar **email);
+gchar * eab_parse_qp_email_to_html (const gchar *string);
+
G_END_DECLS
#endif /* EAB_BOOK_UTIL_H */