Sign Up
Log In
Log In
or
Sign Up
Places
All Projects
Status Monitor
Collapse sidebar
home:shashish
evolution
bnc-189346-convert-to-task-gw-calendar.diff
Overview
Repositories
Revisions
Requests
Users
Attributes
Meta
File bnc-189346-convert-to-task-gw-calendar.diff of Package evolution
--- plugins/mail-to-task/mail-to-task.c 2006-03-04 15:46:29.000000000 +0530 +++ plugins/mail-to-task/mail-to-task.c 2008-03-20 15:13:51.000000000 +0530 @@ -21,10 +21,13 @@ #include <camel/camel-folder.h> #include <camel/camel-medium.h> #include <camel/camel-mime-message.h> +#include <camel/camel-multipart.h> #include <camel/camel-stream.h> #include <camel/camel-stream-mem.h> +#include <camel/camel-utf8.h> #include "mail/em-menu.h" #include "mail/em-popup.h" +#include "mail/em-utils.h" #include <calendar/common/authentication.h> typedef struct { @@ -33,10 +36,30 @@ typedef struct { GPtrArray *uids; }AsyncData; +static char * +clean_name(const unsigned char *s) +{ + GString *out = g_string_new(""); + guint32 c; + char *r; + + while ((c = camel_utf8_getc ((const unsigned char **)&s))) + { + if (!g_unichar_isprint (c) || ( c < 0x7f && strchr (" /'\"`&();|<>$%{}!", c ))) + c = '_'; + g_string_append_u (out, c); + } + + r = g_strdup (out->str); + g_string_free (out, TRUE); + + return r; +} + static void set_attendees (ECalComponent *comp, CamelMimeMessage *message) { - GSList *attendees = NULL, *l; + GSList *attendees = NULL, *l, *to_free = NULL; ECalComponentAttendee *ca; const CamelInternetAddress *to, *cc, *bcc, *arr[3]; int len, i, j; @@ -54,8 +77,12 @@ set_attendees (ECalComponent *comp, Came const char *name, *addr; if (camel_internet_address_get (arr[j], i, &name, &addr)) { + char *temp; ca = g_new0 (ECalComponentAttendee, 1); - ca->value = addr; + temp = g_strconcat ("mailto:", addr, NULL); + ca->value = temp; + to_free = g_slist_prepend (to_free, temp); + ca->cn = name; /* FIXME: missing many fields */ @@ -68,7 +95,10 @@ set_attendees (ECalComponent *comp, Came for (l = attendees; l != NULL; l = l->next) g_free (l->data); - + + g_slist_foreach (to_free, (GFunc) g_free, NULL); + + g_slist_free (to_free); g_slist_free (attendees); } @@ -77,19 +107,36 @@ set_description (ECalComponent *comp, Ca { CamelDataWrapper *content; CamelStream *mem; + CamelContentType *type; + CamelMimePart *mime_part = CAMEL_MIME_PART (message); ECalComponentText text; GSList sl; char *str, *convert_str = NULL; - int bytes_read, bytes_written; + gsize bytes_read, bytes_written; + gint count = 2; content = camel_medium_get_content_object ((CamelMedium *) message); if (!content) return; + /* + * Get non-multipart content from multipart message. + */ + while (CAMEL_IS_MULTIPART (content) && count > 0) + { + mime_part = camel_multipart_get_part (CAMEL_MULTIPART (content), 0); + content = camel_medium_get_content_object (CAMEL_MEDIUM (mime_part)); + count--; + } + + type = camel_mime_part_get_content_type (mime_part); + if (!camel_content_type_is (type, "text", "plain")) + return; + mem = camel_stream_mem_new (); camel_data_wrapper_decode_to_stream (content, mem); - str = g_strndup (((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len); + str = g_strndup ((const gchar*)((CamelStreamMem *) mem)->buffer->data, ((CamelStreamMem *) mem)->buffer->len); camel_object_unref (mem); /* convert to UTF-8 string */ @@ -121,6 +168,7 @@ set_organizer (ECalComponent *comp, Came const CamelInternetAddress *address; const char *str, *name; ECalComponentOrganizer organizer = {NULL, NULL, NULL, NULL}; + char *temp; if (message->reply_to) address = message->reply_to; @@ -132,9 +180,67 @@ set_organizer (ECalComponent *comp, Came if (!camel_internet_address_get (address, 0, &name, &str)) return; - organizer.value = str; + temp = g_strconcat ("mailto:", str, NULL); + organizer.value = temp; organizer.cn = name; e_cal_component_set_organizer (comp, &organizer); + + g_free (temp); +} + +static void +set_attachments (ECal *client, ECalComponent *comp, CamelMimeMessage *message) +{ + int parts, i; + GSList *list = NULL; + const char *uid; + char *store_dir; + CamelDataWrapper *content; + + content = camel_medium_get_content_object ((CamelMedium *) message); + if (!content || !CAMEL_IS_MULTIPART (content)) + return; + + parts = camel_multipart_get_number (CAMEL_MULTIPART (content)); + if (parts < 1) + return; + + e_cal_component_get_uid (comp, &uid); + store_dir = g_filename_from_uri (e_cal_get_local_attachment_store (client), NULL, NULL); + + for (i = 1; i < parts; i++) + { + char *filename, *path, *tmp; + const char *orig_filename; + CamelMimePart *mime_part; + + mime_part = camel_multipart_get_part (CAMEL_MULTIPART (content), i); + + orig_filename = camel_mime_part_get_filename (mime_part); + if (!orig_filename) + continue; + + tmp = clean_name ((const unsigned char *)orig_filename); + filename = g_strdup_printf ("%s-%s", uid, tmp); + path = g_build_filename (store_dir, filename, NULL); + + + if (em_utils_save_part_to_file (NULL, path, mime_part)) + { + char *uri; + uri = g_filename_to_uri (path, NULL, NULL); + list = g_slist_append (list, g_strdup (uri)); + g_free (uri); + } + + g_free (tmp); + g_free (filename); + g_free (path); + } + + g_free (store_dir); + + e_cal_component_set_attachment_list (comp, list); } static gboolean @@ -152,6 +258,8 @@ do_mail_to_task (AsyncData *data) CamelMimeMessage *message; ECalComponent *comp; ECalComponentText text; + icalproperty *icalprop; + icalcomponent *icalcomp; /* retrieve the message from the CamelFolder */ message = camel_folder_get_message (folder, g_ptr_array_index (uids, i), NULL); @@ -172,10 +280,18 @@ do_mail_to_task (AsyncData *data) set_description (comp, message); set_organizer (comp, message); set_attendees (comp, message); + + /* set attachment files */ + set_attachments (client, comp, message); + + icalcomp = e_cal_component_get_icalcomponent (comp); + + icalprop = icalproperty_new_x ("1"); + icalproperty_set_x_name (icalprop, "X-EVOLUTION-MOVE-CALENDAR"); + icalcomponent_add_property (icalcomp, icalprop); /* save the task to the selected source */ - e_cal_create_object (client, e_cal_component_get_icalcomponent (comp), NULL, NULL); - + e_cal_create_object (client, icalcomp, NULL, NULL); g_object_unref (comp); } }
Locations
Projects
Search
Status Monitor
Help
OpenBuildService.org
Documentation
API Documentation
Code of Conduct
Contact
Support
@OBShq
Terms
openSUSE Build Service is sponsored by
The Open Build Service is an
openSUSE project
.
Sign Up
Log In
Places
Places
All Projects
Status Monitor