aboutsummaryrefslogtreecommitdiffstats
path: root/mail
diff options
context:
space:
mode:
Diffstat (limited to 'mail')
-rw-r--r--mail/ChangeLog11
-rw-r--r--mail/em-popup.c53
-rw-r--r--mail/em-utils.c73
-rw-r--r--mail/em-utils.h1
4 files changed, 118 insertions, 20 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog
index 84a224755f..54a820c72b 100644
--- a/mail/ChangeLog
+++ b/mail/ChangeLog
@@ -1,3 +1,14 @@
+2008-03-13 Milan Crha <mcrha@redhat.com>
+
+ ** Fix for bug #273177
+
+ * em-utils.h: (em_utils_add_vcard):
+ * em-utils.c: (emu_add_address_or_vcard),
+ (em_utils_add_address), (em_utils_add_vcard):
+ New function to add whole vCard to addressbook.
+ * em-popup.c: (emp_add_vcard), (emp_standard_menu_factory):
+ Add popup menu item to vcard attachments.
+
2008-03-12 Matthew Barnes <mbarnes@redhat.com>
** Fixes breakage caused by bug #513951
diff --git a/mail/em-popup.c b/mail/em-popup.c
index 53797b0fdb..d44d206414 100644
--- a/mail/em-popup.c
+++ b/mail/em-popup.c
@@ -56,6 +56,7 @@
#include <camel/camel-mime-utils.h>
#include <camel/camel-mime-part.h>
#include <camel/camel-url.h>
+#include <camel/camel-stream-mem.h>
#include <camel/camel-vee-folder.h>
#include <camel/camel-vtrash-folder.h>
@@ -697,6 +698,40 @@ emp_standard_items_free(EPopup *ep, GSList *items, void *data)
}
static void
+emp_add_vcard (EPopup *ep, EPopupItem *item, void *data)
+{
+ EPopupTarget *target = ep->target;
+ CamelMimePart *part;
+ CamelDataWrapper *content;
+ CamelStreamMem *mem;
+
+
+ if (target->type == EM_POPUP_TARGET_ATTACHMENTS)
+ part = ((EAttachment *) ((EMPopupTargetAttachments *) target)->attachments->data)->body;
+ else
+ part = ((EMPopupTargetPart *) target)->part;
+
+ if (!part)
+ return;
+
+ content = camel_medium_get_content_object (CAMEL_MEDIUM (part));
+ mem = CAMEL_STREAM_MEM (camel_stream_mem_new ());
+
+ if (camel_data_wrapper_decode_to_stream (content, CAMEL_STREAM (mem)) == -1 ||
+ !mem->buffer->data)
+ g_warning ("Read part's content failed!");
+ else {
+ GString *vcard = g_string_new_len ((const gchar *) mem->buffer->data, mem->buffer->len);
+
+ em_utils_add_vcard (target->widget, vcard->str);
+
+ g_string_free (vcard, TRUE);
+ }
+
+ camel_object_unref (mem);
+}
+
+static void
emp_standard_menu_factory(EPopup *emp, void *data)
{
int i, len;
@@ -768,7 +803,6 @@ emp_standard_menu_factory(EPopup *emp, void *data)
apps = gnome_vfs_mime_get_all_applications(name_type);
}
}
- g_free (mime_type);
if (apps) {
GString *label = g_string_new("");
@@ -800,6 +834,23 @@ emp_standard_menu_factory(EPopup *emp, void *data)
g_string_free(label, TRUE);
g_list_free(apps);
}
+
+ if (g_ascii_strcasecmp (mime_type, "text/x-vcard") == 0||
+ g_ascii_strcasecmp (mime_type, "text/vcard") == 0) {
+ EPopupItem *item;
+
+ item = g_malloc0 (sizeof (*item));
+ item->type = E_POPUP_ITEM;
+ item->path = "00.00.vcf.00"; /* make it first item */
+ item->label = _("_Add to Address Book");
+ item->activate = emp_add_vcard;
+ item->user_data = NULL;
+ item->image = "contact-new";
+
+ e_popup_add_items (emp, g_slist_append (NULL, item), NULL, NULL, NULL);
+ }
+
+ g_free (mime_type);
}
for (i=0;i<len;i++) {
diff --git a/mail/em-utils.c b/mail/em-utils.c
index 0c81fbe8bd..94d4fdc6ef 100644
--- a/mail/em-utils.c
+++ b/mail/em-utils.c
@@ -666,39 +666,51 @@ emu_add_address_cb(BonoboListener *listener, const char *name, const CORBA_any *
g_free(type);
}
-/**
- * em_utils_add_address:
- * @parent:
- * @email:
- *
- * Add address @email to the addressbook.
- **/
-void em_utils_add_address(struct _GtkWidget *parent, const char *email)
+/* one of email or vcard should be always NULL, never both of them */
+static void
+emu_add_address_or_vcard (struct _GtkWidget *parent, const char *email, const char *vcard)
{
- CamelInternetAddress *cia;
GtkWidget *win;
GtkWidget *control;
/*GtkWidget *socket;*/
- char *buf;
+ char *email_buf = NULL;
- cia = camel_internet_address_new ();
- if (camel_address_decode ((CamelAddress *) cia, email) == -1) {
+ if (email) {
+ CamelInternetAddress *cia;
+
+ cia = camel_internet_address_new ();
+ if (camel_address_decode ((CamelAddress *) cia, email) == -1) {
+ camel_object_unref (cia);
+ return;
+ }
+
+ email_buf = camel_address_format ((CamelAddress *) cia);
camel_object_unref (cia);
- return;
}
- buf = camel_address_format ((CamelAddress *) cia);
- camel_object_unref (cia);
-
win = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title((GtkWindow *)win, _("Add address"));
- gtk_window_set_transient_for((GtkWindow *)win, ((GtkWindow *)parent));
+
+ if (parent && !GTK_IS_WINDOW (parent)) {
+ parent = gtk_widget_get_toplevel (parent);
+ if (!parent || !(GTK_WIDGET_TOPLEVEL (parent)))
+ parent = NULL;
+ }
+
+ if (parent)
+ gtk_window_set_transient_for((GtkWindow *)win, ((GtkWindow *)parent));
+
gtk_window_set_position((GtkWindow *)win, GTK_WIN_POS_CENTER_ON_PARENT);
gtk_window_set_type_hint((GtkWindow *)win, GDK_WINDOW_TYPE_HINT_DIALOG);
control = bonobo_widget_new_control("OAFIID:GNOME_Evolution_Addressbook_AddressPopup:" BASE_VERSION, CORBA_OBJECT_NIL);
- bonobo_widget_set_property((BonoboWidget *)control, "email", TC_CORBA_string, buf, NULL);
- g_free (buf);
+
+ if (email_buf)
+ bonobo_widget_set_property ((BonoboWidget *) control, "email", TC_CORBA_string, email_buf, NULL);
+ else
+ bonobo_widget_set_property ((BonoboWidget *) control, "vcard", TC_CORBA_string, vcard, NULL);
+
+ g_free (email_buf);
bonobo_event_source_client_add_listener(bonobo_widget_get_objref((BonoboWidget *)control), emu_add_address_cb, NULL, NULL, win);
@@ -709,6 +721,29 @@ void em_utils_add_address(struct _GtkWidget *parent, const char *email)
gtk_widget_show_all(win);
}
+/**
+ * em_utils_add_address:
+ * @parent:
+ * @email:
+ *
+ * Add address @email to the addressbook.
+ **/
+void
+em_utils_add_address (struct _GtkWidget *parent, const char *email)
+{
+ emu_add_address_or_vcard (parent, email, NULL);
+}
+
+/**
+ * em_utils_add_vcard:
+ * Adds whole vCard to the addressbook.
+ **/
+void
+em_utils_add_vcard (struct _GtkWidget *parent, const char *vcard)
+{
+ emu_add_address_or_vcard (parent, NULL, vcard);
+}
+
/* ********************************************************************** */
/* Flag-for-Followup... */
diff --git a/mail/em-utils.h b/mail/em-utils.h
index 587e2c18b7..2b8fae822c 100644
--- a/mail/em-utils.h
+++ b/mail/em-utils.h
@@ -61,6 +61,7 @@ gboolean em_utils_save_part_to_file(struct _GtkWidget *parent, const char *filen
void em_utils_save_messages (struct _GtkWidget *parent, struct _CamelFolder *folder, GPtrArray *uids);
void em_utils_add_address(struct _GtkWidget *parent, const char *email);
+void em_utils_add_vcard(struct _GtkWidget *parent, const char *vcard);
void em_utils_flag_for_followup (struct _GtkWidget *parent, struct _CamelFolder *folder, GPtrArray *uids);
void em_utils_flag_for_followup_clear (struct _GtkWidget *parent, struct _CamelFolder *folder, GPtrArray *uids);