From e67ca727d4130585f4dcf4c71fff0e52e6b6e396 Mon Sep 17 00:00:00 2001 From: Matthew Barnes Date: Sun, 19 May 2013 12:09:11 -0400 Subject: Rename EMailParserVCardInline to EMailParserVCard. --- modules/vcard-inline/Makefile.am | 4 +- modules/vcard-inline/e-mail-parser-vcard-inline.c | 389 --------------------- modules/vcard-inline/e-mail-parser-vcard-inline.h | 30 -- modules/vcard-inline/e-mail-parser-vcard.c | 389 +++++++++++++++++++++ modules/vcard-inline/e-mail-parser-vcard.h | 30 ++ .../vcard-inline/evolution-module-vcard-inline.c | 4 +- 6 files changed, 423 insertions(+), 423 deletions(-) delete mode 100644 modules/vcard-inline/e-mail-parser-vcard-inline.c delete mode 100644 modules/vcard-inline/e-mail-parser-vcard-inline.h create mode 100644 modules/vcard-inline/e-mail-parser-vcard.c create mode 100644 modules/vcard-inline/e-mail-parser-vcard.h (limited to 'modules/vcard-inline') diff --git a/modules/vcard-inline/Makefile.am b/modules/vcard-inline/Makefile.am index 16ef25da26..85e2333596 100644 --- a/modules/vcard-inline/Makefile.am +++ b/modules/vcard-inline/Makefile.am @@ -12,8 +12,8 @@ module_vcard_inline_la_CPPFLAGS = \ module_vcard_inline_la_SOURCES = \ e-mail-formatter-vcard-inline.c \ e-mail-formatter-vcard-inline.h \ - e-mail-parser-vcard-inline.c \ - e-mail-parser-vcard-inline.h \ + e-mail-parser-vcard.c \ + e-mail-parser-vcard.h \ e-mail-part-vcard.h \ evolution-module-vcard-inline.c diff --git a/modules/vcard-inline/e-mail-parser-vcard-inline.c b/modules/vcard-inline/e-mail-parser-vcard-inline.c deleted file mode 100644 index 899f24bc2b..0000000000 --- a/modules/vcard-inline/e-mail-parser-vcard-inline.c +++ /dev/null @@ -1,389 +0,0 @@ -/* - * e-mail-parser-vcard-inline.c - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - */ - -#ifdef HAVE_CONFIG_H -#include -#endif - -#include -#include -#include -#include -#include - -#include "e-mail-parser-vcard-inline.h" -#include "e-mail-part-vcard.h" - -#include - -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include - -#include - -#define d(x) - -typedef EMailParserExtension EMailParserVCardInline; -typedef EMailParserExtensionClass EMailParserVCardInlineClass; - -typedef EExtension EMailParserVCardInlineLoader; -typedef EExtensionClass EMailParserVCardInlineLoaderClass; - -GType e_mail_parser_vcard_inline_get_type (void); - -G_DEFINE_DYNAMIC_TYPE ( - EMailParserVCardInline, - e_mail_parser_vcard_inline, - E_TYPE_MAIL_PARSER_EXTENSION) - -static const gchar *parser_mime_types[] = { - "text/vcard", - "text/x-vcard", - "text/directory", - NULL -}; - -static void -mail_part_vcard_inline_free (EMailPart *mail_part) -{ - EMailPartVCard *vi_part = (EMailPartVCard *) mail_part; - - g_clear_object (&vi_part->contact_display); - g_clear_object (&vi_part->message_label); - g_clear_object (&vi_part->formatter); - g_clear_object (&vi_part->iframe); - g_clear_object (&vi_part->save_button); - g_clear_object (&vi_part->toggle_button); - g_clear_object (&vi_part->folder); - - if (vi_part->message_uid) { - g_free (vi_part->message_uid); - vi_part->message_uid = NULL; - } -} - -static void -client_connect_cb (GObject *source_object, - GAsyncResult *result, - gpointer user_data) -{ - GSList *contact_list = user_data; - EShell *shell; - EClient *client; - EBookClient *book_client; - ESourceRegistry *registry; - GSList *iter; - GError *error = NULL; - - client = e_book_client_connect_finish (result, &error); - - /* Sanity check. */ - g_return_if_fail ( - ((client != NULL) && (error == NULL)) || - ((client == NULL) && (error != NULL))); - - if (error != NULL) { - g_warning ("%s: %s", G_STRFUNC, error->message); - g_error_free (error); - goto exit; - } - - book_client = E_BOOK_CLIENT (client); - - shell = e_shell_get_default (); - registry = e_shell_get_registry (shell); - - for (iter = contact_list; iter != NULL; iter = iter->next) { - EContact *contact; - - contact = E_CONTACT (iter->data); - eab_merging_book_add_contact ( - registry, book_client, contact, NULL, NULL); - } - - g_object_unref (client); - - exit: - g_slist_free_full (contact_list, (GDestroyNotify) g_object_unref); -} - -static void -save_vcard_cb (WebKitDOMEventTarget *button, - WebKitDOMEvent *event, - EMailPartVCard *vcard_part) -{ - EShell *shell; - ESource *source; - ESourceRegistry *registry; - ESourceSelector *selector; - GSList *contact_list; - const gchar *extension_name; - GtkWidget *dialog; - - shell = e_shell_get_default (); - registry = e_shell_get_registry (shell); - extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK; - - dialog = e_source_selector_dialog_new (NULL, registry, extension_name); - - selector = e_source_selector_dialog_get_selector ( - E_SOURCE_SELECTOR_DIALOG (dialog)); - - source = e_source_registry_ref_default_address_book (registry); - e_source_selector_set_primary_selection (selector, source); - g_object_unref (source); - - if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) { - gtk_widget_destroy (dialog); - return; - } - - source = e_source_selector_dialog_peek_primary_selection ( - E_SOURCE_SELECTOR_DIALOG (dialog)); - - gtk_widget_destroy (dialog); - - g_return_if_fail (source != NULL); - - contact_list = g_slist_copy_deep ( - vcard_part->contact_list, - (GCopyFunc) g_object_ref, NULL); - - e_book_client_connect ( - source, NULL, client_connect_cb, contact_list); -} - -static void -display_mode_toggle_cb (WebKitDOMEventTarget *button, - WebKitDOMEvent *event, - EMailPartVCard *vcard_part) -{ - EABContactDisplayMode mode; - gchar *uri; - gchar *html_label, *access_key; - - mode = eab_contact_formatter_get_display_mode (vcard_part->formatter); - if (mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) { - mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; - - html_label = e_mail_formatter_parse_html_mnemonics ( - _("Show F_ull vCard"), &access_key); - - webkit_dom_html_element_set_inner_html ( - WEBKIT_DOM_HTML_ELEMENT (button), - html_label, NULL); - if (access_key) { - webkit_dom_html_element_set_access_key ( - WEBKIT_DOM_HTML_ELEMENT (button), - access_key); - g_free (access_key); - } - - g_free (html_label); - - } else { - mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; - - html_label = e_mail_formatter_parse_html_mnemonics ( - _("Show Com_pact vCard"), &access_key); - - webkit_dom_html_element_set_inner_html ( - WEBKIT_DOM_HTML_ELEMENT (button), - html_label, NULL); - if (access_key) { - webkit_dom_html_element_set_access_key ( - WEBKIT_DOM_HTML_ELEMENT (button), - access_key); - g_free (access_key); - } - - g_free (html_label); - } - - eab_contact_formatter_set_display_mode (vcard_part->formatter, mode); - - uri = e_mail_part_build_uri ( - vcard_part->folder, vcard_part->message_uid, - "part_id", G_TYPE_STRING, vcard_part->parent.id, - "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW, NULL); - - webkit_dom_html_iframe_element_set_src ( - WEBKIT_DOM_HTML_IFRAME_ELEMENT (vcard_part->iframe), uri); - - g_free (uri); -} - -static void -bind_dom (EMailPartVCard *vcard_part, - WebKitDOMElement *attachment) -{ - WebKitDOMNodeList *list; - WebKitDOMElement *iframe, *toggle_button, *save_button; - - /* IFRAME */ - list = webkit_dom_element_get_elements_by_tag_name (attachment, "iframe"); - if (webkit_dom_node_list_get_length (list) != 1) - return; - iframe = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0)); - if (vcard_part->iframe) - g_object_unref (vcard_part->iframe); - vcard_part->iframe = g_object_ref (iframe); - - /* TOGGLE DISPLAY MODE BUTTON */ - list = webkit_dom_element_get_elements_by_class_name ( - attachment, "org-gnome-vcard-inline-display-mode-button"); - if (webkit_dom_node_list_get_length (list) != 1) - return; - toggle_button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0)); - if (vcard_part->toggle_button) - g_object_unref (vcard_part->toggle_button); - vcard_part->toggle_button = g_object_ref (toggle_button); - - /* SAVE TO ADDRESSBOOK BUTTON */ - list = webkit_dom_element_get_elements_by_class_name ( - attachment, "org-gnome-vcard-inline-save-button"); - if (webkit_dom_node_list_get_length (list) != 1) - return; - save_button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0)); - if (vcard_part->save_button) - g_object_unref (vcard_part->save_button); - vcard_part->save_button = g_object_ref (save_button); - - webkit_dom_event_target_add_event_listener ( - WEBKIT_DOM_EVENT_TARGET (toggle_button), - "click", G_CALLBACK (display_mode_toggle_cb), - FALSE, vcard_part); - - webkit_dom_event_target_add_event_listener ( - WEBKIT_DOM_EVENT_TARGET (save_button), - "click", G_CALLBACK (save_vcard_cb), - FALSE, vcard_part); - - /* Bind collapse buttons for contact lists. */ - eab_contact_formatter_bind_dom ( - webkit_dom_html_iframe_element_get_content_document ( - WEBKIT_DOM_HTML_IFRAME_ELEMENT (iframe))); -} - -static void -decode_vcard (EMailPartVCard *vcard_part, - CamelMimePart *mime_part) -{ - CamelDataWrapper *data_wrapper; - CamelMedium *medium; - CamelStream *stream; - GSList *contact_list; - GByteArray *array; - const gchar *string; - const guint8 padding[2] = {0}; - - array = g_byte_array_new (); - medium = CAMEL_MEDIUM (mime_part); - - /* Stream takes ownership of the byte array. */ - stream = camel_stream_mem_new_with_byte_array (array); - data_wrapper = camel_medium_get_content (medium); - camel_data_wrapper_decode_to_stream_sync ( - data_wrapper, stream, NULL, NULL); - - /* because the result is not NULL-terminated */ - g_byte_array_append (array, padding, 2); - - string = (gchar *) array->data; - contact_list = eab_contact_list_from_string (string); - vcard_part->contact_list = contact_list; - - g_object_unref (mime_part); - g_object_unref (stream); -} - -static gboolean -empe_vcard_inline_parse (EMailParserExtension *extension, - EMailParser *parser, - CamelMimePart *part, - GString *part_id, - GCancellable *cancellable, - GQueue *out_mail_parts) -{ - EMailPartVCard *vcard_part; - GQueue work_queue = G_QUEUE_INIT; - gint len; - - len = part_id->len; - g_string_append (part_id, ".org-gnome-vcard-inline-display"); - - vcard_part = (EMailPartVCard *) e_mail_part_subclass_new ( - part, part_id->str, sizeof (EMailPartVCard), - (GFreeFunc) mail_part_vcard_inline_free); - vcard_part->parent.mime_type = camel_content_type_simple ( - camel_mime_part_get_content_type (part)); - vcard_part->parent.bind_func = (EMailPartDOMBindFunc) bind_dom; - vcard_part->parent.is_attachment = TRUE; - vcard_part->formatter = g_object_new ( - EAB_TYPE_CONTACT_FORMATTER, - "display-mode", EAB_CONTACT_DISPLAY_RENDER_COMPACT, - "render-maps", FALSE, NULL); - g_object_ref (part); - - decode_vcard (vcard_part, part); - - g_string_truncate (part_id, len); - - g_queue_push_tail (&work_queue, vcard_part); - - e_mail_parser_wrap_as_attachment ( - parser, part, part_id, &work_queue); - - e_queue_transfer (&work_queue, out_mail_parts); - - return TRUE; -} - -static void -e_mail_parser_vcard_inline_class_init (EMailParserExtensionClass *class) -{ - class->mime_types = parser_mime_types; - class->flags = E_MAIL_PARSER_EXTENSION_INLINE_DISPOSITION; - class->parse = empe_vcard_inline_parse; -} - -static void -e_mail_parser_vcard_inline_class_finalize (EMailParserExtensionClass *class) -{ -} - -static void -e_mail_parser_vcard_inline_init (EMailParserExtension *extension) -{ -} - -void -e_mail_parser_vcard_inline_type_register (GTypeModule *type_module) -{ - e_mail_parser_vcard_inline_register_type (type_module); -} - diff --git a/modules/vcard-inline/e-mail-parser-vcard-inline.h b/modules/vcard-inline/e-mail-parser-vcard-inline.h deleted file mode 100644 index 76ec5fe206..0000000000 --- a/modules/vcard-inline/e-mail-parser-vcard-inline.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * e-mail-parser-vcard-inline.h - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU Lesser General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) version 3. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * Lesser General Public License for more details. - * - * You should have received a copy of the GNU Lesser General Public - * License along with the program; if not, see - * - */ - -#ifndef E_MAIL_PARSER_VCARD_INLINE_H -#define E_MAIL_PARSER_VCARD_INLINE_H - -#include - -G_BEGIN_DECLS - -void e_mail_parser_vcard_inline_type_register (GTypeModule *type_module); - -G_END_DECLS - -#endif /* E_MAIL_PARSER_VCARD_INLINE_H */ diff --git a/modules/vcard-inline/e-mail-parser-vcard.c b/modules/vcard-inline/e-mail-parser-vcard.c new file mode 100644 index 0000000000..5fbc3c0dc3 --- /dev/null +++ b/modules/vcard-inline/e-mail-parser-vcard.c @@ -0,0 +1,389 @@ +/* + * e-mail-parser-vcard.c + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + */ + +#ifdef HAVE_CONFIG_H +#include +#endif + +#include +#include +#include +#include +#include + +#include "e-mail-parser-vcard.h" +#include "e-mail-part-vcard.h" + +#include + +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include + +#include + +#define d(x) + +typedef EMailParserExtension EMailParserVCard; +typedef EMailParserExtensionClass EMailParserVCardClass; + +typedef EExtension EMailParserVCardLoader; +typedef EExtensionClass EMailParserVCardLoaderClass; + +GType e_mail_parser_vcard_get_type (void); + +G_DEFINE_DYNAMIC_TYPE ( + EMailParserVCard, + e_mail_parser_vcard, + E_TYPE_MAIL_PARSER_EXTENSION) + +static const gchar *parser_mime_types[] = { + "text/vcard", + "text/x-vcard", + "text/directory", + NULL +}; + +static void +mail_part_vcard_free (EMailPart *mail_part) +{ + EMailPartVCard *vi_part = (EMailPartVCard *) mail_part; + + g_clear_object (&vi_part->contact_display); + g_clear_object (&vi_part->message_label); + g_clear_object (&vi_part->formatter); + g_clear_object (&vi_part->iframe); + g_clear_object (&vi_part->save_button); + g_clear_object (&vi_part->toggle_button); + g_clear_object (&vi_part->folder); + + if (vi_part->message_uid) { + g_free (vi_part->message_uid); + vi_part->message_uid = NULL; + } +} + +static void +client_connect_cb (GObject *source_object, + GAsyncResult *result, + gpointer user_data) +{ + GSList *contact_list = user_data; + EShell *shell; + EClient *client; + EBookClient *book_client; + ESourceRegistry *registry; + GSList *iter; + GError *error = NULL; + + client = e_book_client_connect_finish (result, &error); + + /* Sanity check. */ + g_return_if_fail ( + ((client != NULL) && (error == NULL)) || + ((client == NULL) && (error != NULL))); + + if (error != NULL) { + g_warning ("%s: %s", G_STRFUNC, error->message); + g_error_free (error); + goto exit; + } + + book_client = E_BOOK_CLIENT (client); + + shell = e_shell_get_default (); + registry = e_shell_get_registry (shell); + + for (iter = contact_list; iter != NULL; iter = iter->next) { + EContact *contact; + + contact = E_CONTACT (iter->data); + eab_merging_book_add_contact ( + registry, book_client, contact, NULL, NULL); + } + + g_object_unref (client); + + exit: + g_slist_free_full (contact_list, (GDestroyNotify) g_object_unref); +} + +static void +save_vcard_cb (WebKitDOMEventTarget *button, + WebKitDOMEvent *event, + EMailPartVCard *vcard_part) +{ + EShell *shell; + ESource *source; + ESourceRegistry *registry; + ESourceSelector *selector; + GSList *contact_list; + const gchar *extension_name; + GtkWidget *dialog; + + shell = e_shell_get_default (); + registry = e_shell_get_registry (shell); + extension_name = E_SOURCE_EXTENSION_ADDRESS_BOOK; + + dialog = e_source_selector_dialog_new (NULL, registry, extension_name); + + selector = e_source_selector_dialog_get_selector ( + E_SOURCE_SELECTOR_DIALOG (dialog)); + + source = e_source_registry_ref_default_address_book (registry); + e_source_selector_set_primary_selection (selector, source); + g_object_unref (source); + + if (gtk_dialog_run (GTK_DIALOG (dialog)) != GTK_RESPONSE_OK) { + gtk_widget_destroy (dialog); + return; + } + + source = e_source_selector_dialog_peek_primary_selection ( + E_SOURCE_SELECTOR_DIALOG (dialog)); + + gtk_widget_destroy (dialog); + + g_return_if_fail (source != NULL); + + contact_list = g_slist_copy_deep ( + vcard_part->contact_list, + (GCopyFunc) g_object_ref, NULL); + + e_book_client_connect ( + source, NULL, client_connect_cb, contact_list); +} + +static void +display_mode_toggle_cb (WebKitDOMEventTarget *button, + WebKitDOMEvent *event, + EMailPartVCard *vcard_part) +{ + EABContactDisplayMode mode; + gchar *uri; + gchar *html_label, *access_key; + + mode = eab_contact_formatter_get_display_mode (vcard_part->formatter); + if (mode == EAB_CONTACT_DISPLAY_RENDER_NORMAL) { + mode = EAB_CONTACT_DISPLAY_RENDER_COMPACT; + + html_label = e_mail_formatter_parse_html_mnemonics ( + _("Show F_ull vCard"), &access_key); + + webkit_dom_html_element_set_inner_html ( + WEBKIT_DOM_HTML_ELEMENT (button), + html_label, NULL); + if (access_key) { + webkit_dom_html_element_set_access_key ( + WEBKIT_DOM_HTML_ELEMENT (button), + access_key); + g_free (access_key); + } + + g_free (html_label); + + } else { + mode = EAB_CONTACT_DISPLAY_RENDER_NORMAL; + + html_label = e_mail_formatter_parse_html_mnemonics ( + _("Show Com_pact vCard"), &access_key); + + webkit_dom_html_element_set_inner_html ( + WEBKIT_DOM_HTML_ELEMENT (button), + html_label, NULL); + if (access_key) { + webkit_dom_html_element_set_access_key ( + WEBKIT_DOM_HTML_ELEMENT (button), + access_key); + g_free (access_key); + } + + g_free (html_label); + } + + eab_contact_formatter_set_display_mode (vcard_part->formatter, mode); + + uri = e_mail_part_build_uri ( + vcard_part->folder, vcard_part->message_uid, + "part_id", G_TYPE_STRING, vcard_part->parent.id, + "mode", G_TYPE_INT, E_MAIL_FORMATTER_MODE_RAW, NULL); + + webkit_dom_html_iframe_element_set_src ( + WEBKIT_DOM_HTML_IFRAME_ELEMENT (vcard_part->iframe), uri); + + g_free (uri); +} + +static void +bind_dom (EMailPartVCard *vcard_part, + WebKitDOMElement *attachment) +{ + WebKitDOMNodeList *list; + WebKitDOMElement *iframe, *toggle_button, *save_button; + + /* IFRAME */ + list = webkit_dom_element_get_elements_by_tag_name (attachment, "iframe"); + if (webkit_dom_node_list_get_length (list) != 1) + return; + iframe = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0)); + if (vcard_part->iframe) + g_object_unref (vcard_part->iframe); + vcard_part->iframe = g_object_ref (iframe); + + /* TOGGLE DISPLAY MODE BUTTON */ + list = webkit_dom_element_get_elements_by_class_name ( + attachment, "org-gnome-vcard-display-mode-button"); + if (webkit_dom_node_list_get_length (list) != 1) + return; + toggle_button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0)); + if (vcard_part->toggle_button) + g_object_unref (vcard_part->toggle_button); + vcard_part->toggle_button = g_object_ref (toggle_button); + + /* SAVE TO ADDRESSBOOK BUTTON */ + list = webkit_dom_element_get_elements_by_class_name ( + attachment, "org-gnome-vcard-save-button"); + if (webkit_dom_node_list_get_length (list) != 1) + return; + save_button = WEBKIT_DOM_ELEMENT (webkit_dom_node_list_item (list, 0)); + if (vcard_part->save_button) + g_object_unref (vcard_part->save_button); + vcard_part->save_button = g_object_ref (save_button); + + webkit_dom_event_target_add_event_listener ( + WEBKIT_DOM_EVENT_TARGET (toggle_button), + "click", G_CALLBACK (display_mode_toggle_cb), + FALSE, vcard_part); + + webkit_dom_event_target_add_event_listener ( + WEBKIT_DOM_EVENT_TARGET (save_button), + "click", G_CALLBACK (save_vcard_cb), + FALSE, vcard_part); + + /* Bind collapse buttons for contact lists. */ + eab_contact_formatter_bind_dom ( + webkit_dom_html_iframe_element_get_content_document ( + WEBKIT_DOM_HTML_IFRAME_ELEMENT (iframe))); +} + +static void +decode_vcard (EMailPartVCard *vcard_part, + CamelMimePart *mime_part) +{ + CamelDataWrapper *data_wrapper; + CamelMedium *medium; + CamelStream *stream; + GSList *contact_list; + GByteArray *array; + const gchar *string; + const guint8 padding[2] = {0}; + + array = g_byte_array_new (); + medium = CAMEL_MEDIUM (mime_part); + + /* Stream takes ownership of the byte array. */ + stream = camel_stream_mem_new_with_byte_array (array); + data_wrapper = camel_medium_get_content (medium); + camel_data_wrapper_decode_to_stream_sync ( + data_wrapper, stream, NULL, NULL); + + /* because the result is not NULL-terminated */ + g_byte_array_append (array, padding, 2); + + string = (gchar *) array->data; + contact_list = eab_contact_list_from_string (string); + vcard_part->contact_list = contact_list; + + g_object_unref (mime_part); + g_object_unref (stream); +} + +static gboolean +empe_vcard_parse (EMailParserExtension *extension, + EMailParser *parser, + CamelMimePart *part, + GString *part_id, + GCancellable *cancellable, + GQueue *out_mail_parts) +{ + EMailPartVCard *vcard_part; + GQueue work_queue = G_QUEUE_INIT; + gint len; + + len = part_id->len; + g_string_append (part_id, ".org-gnome-vcard-display"); + + vcard_part = (EMailPartVCard *) e_mail_part_subclass_new ( + part, part_id->str, sizeof (EMailPartVCard), + (GFreeFunc) mail_part_vcard_free); + vcard_part->parent.mime_type = camel_content_type_simple ( + camel_mime_part_get_content_type (part)); + vcard_part->parent.bind_func = (EMailPartDOMBindFunc) bind_dom; + vcard_part->parent.is_attachment = TRUE; + vcard_part->formatter = g_object_new ( + EAB_TYPE_CONTACT_FORMATTER, + "display-mode", EAB_CONTACT_DISPLAY_RENDER_COMPACT, + "render-maps", FALSE, NULL); + g_object_ref (part); + + decode_vcard (vcard_part, part); + + g_string_truncate (part_id, len); + + g_queue_push_tail (&work_queue, vcard_part); + + e_mail_parser_wrap_as_attachment ( + parser, part, part_id, &work_queue); + + e_queue_transfer (&work_queue, out_mail_parts); + + return TRUE; +} + +static void +e_mail_parser_vcard_class_init (EMailParserExtensionClass *class) +{ + class->mime_types = parser_mime_types; + class->flags = E_MAIL_PARSER_EXTENSION_INLINE_DISPOSITION; + class->parse = empe_vcard_parse; +} + +static void +e_mail_parser_vcard_class_finalize (EMailParserExtensionClass *class) +{ +} + +static void +e_mail_parser_vcard_init (EMailParserExtension *extension) +{ +} + +void +e_mail_parser_vcard_type_register (GTypeModule *type_module) +{ + e_mail_parser_vcard_register_type (type_module); +} + diff --git a/modules/vcard-inline/e-mail-parser-vcard.h b/modules/vcard-inline/e-mail-parser-vcard.h new file mode 100644 index 0000000000..caf57f9316 --- /dev/null +++ b/modules/vcard-inline/e-mail-parser-vcard.h @@ -0,0 +1,30 @@ +/* + * e-mail-parser-vcard.h + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2 of the License, or (at your option) version 3. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with the program; if not, see + * + */ + +#ifndef E_MAIL_PARSER_VCARD_H +#define E_MAIL_PARSER_VCARD_H + +#include + +G_BEGIN_DECLS + +void e_mail_parser_vcard_type_register (GTypeModule *type_module); + +G_END_DECLS + +#endif /* E_MAIL_PARSER_VCARD_H */ diff --git a/modules/vcard-inline/evolution-module-vcard-inline.c b/modules/vcard-inline/evolution-module-vcard-inline.c index bb1196e865..5173833615 100644 --- a/modules/vcard-inline/evolution-module-vcard-inline.c +++ b/modules/vcard-inline/evolution-module-vcard-inline.c @@ -17,7 +17,7 @@ */ #include "e-mail-formatter-vcard-inline.h" -#include "e-mail-parser-vcard-inline.h" +#include "e-mail-parser-vcard.h" #include @@ -29,7 +29,7 @@ G_MODULE_EXPORT void e_module_load (GTypeModule *type_module) { e_mail_formatter_vcard_inline_type_register (type_module); - e_mail_parser_vcard_inline_type_register (type_module); + e_mail_parser_vcard_type_register (type_module); } G_MODULE_EXPORT void -- cgit v1.2.3