From 58431fb115969b527e04db2a8cdae7af94113a01 Mon Sep 17 00:00:00 2001 From: Rodrigo Moya Date: Thu, 21 Oct 2004 18:12:22 +0000 Subject: new functions. (do_mail_to_task): set attendees and organizer on the task 2004-10-21 Rodrigo Moya * mail-to-task.c (set_attendees, set_organizer): new functions. (do_mail_to_task): set attendees and organizer on the task from the recipients in the mail message. svn path=/trunk/; revision=27686 --- plugins/mail-to-task/mail-to-task.c | 60 ++++++++++++++++++++++++++++++++++++- 1 file changed, 59 insertions(+), 1 deletion(-) (limited to 'plugins/mail-to-task/mail-to-task.c') diff --git a/plugins/mail-to-task/mail-to-task.c b/plugins/mail-to-task/mail-to-task.c index c4b51fd9de..595d64d974 100644 --- a/plugins/mail-to-task/mail-to-task.c +++ b/plugins/mail-to-task/mail-to-task.c @@ -22,6 +22,59 @@ #include "camel/camel-mime-message.h" #include "mail/em-popup.h" +static void +add_attendee_cb (gpointer key, gpointer value, gpointer user_data) +{ + ECalComponentAttendee *ca; + const char *str, *name; + GList **attendees = user_data; + + if (!camel_internet_address_get (value, 0, &name, &str)) + return; + + ca = g_new0 (ECalComponentAttendee, 1); + ca->value = str; + ca->cn = name; + /* FIXME: missing many fields */ + + *attendees = g_slist_append (*attendees, ca); +} + +static void +set_attendees (ECalComponent *comp, CamelMimeMessage *message) +{ + GSList *attendees = NULL, *l; + + g_hash_table_foreach (message->recipients, (GHFunc) add_attendee_cb, &attendees); + e_cal_component_set_attendee_list (comp, attendees); + + for (l = attendees; l != NULL; l = l->next) + g_free (l->data); + g_slist_free (attendees); +} + +static void +set_organizer (ECalComponent *comp, CamelMimeMessage *message) +{ + const CamelInternetAddress *address; + const char *str, *name; + ECalComponentOrganizer organizer = {NULL, NULL, NULL, NULL}; + + if (message->reply_to) + address = message->reply_to; + else if (message->from) + address = message->from; + else + return; + + if (!camel_internet_address_get (address, 0, &name, &str)) + return; + + organizer.value = str; + organizer.cn = name; + e_cal_component_set_organizer (comp, &organizer); +} + static void do_mail_to_task (EMPopupTargetSelect *t, ESource *tasks_source) { @@ -36,8 +89,8 @@ do_mail_to_task (EMPopupTargetSelect *t, ESource *tasks_source) CamelMimeMessage *message; ECalComponent *comp; ECalComponentText text; - char *str; GSList sl; + char *str; /* retrieve the message from the CamelFolder */ message = camel_folder_get_message (t->folder, g_ptr_array_index (t->uids, i), NULL); @@ -48,6 +101,7 @@ do_mail_to_task (EMPopupTargetSelect *t, ESource *tasks_source) e_cal_component_set_new_vtype (comp, E_CAL_COMPONENT_TODO); e_cal_component_set_uid (comp, camel_mime_message_get_message_id (message)); + /* set the task's summary */ text.value = camel_mime_message_get_subject (message); text.altrep = NULL; e_cal_component_set_summary (comp, &text); @@ -61,6 +115,10 @@ do_mail_to_task (EMPopupTargetSelect *t, ESource *tasks_source) g_free (str); + /* set the organizer, and the attendees */ + set_organizer (comp, message); + set_attendees (comp, message); + /* save the task to the selected source */ e_cal_create_object (client, e_cal_component_get_icalcomponent (comp), NULL, NULL); -- cgit v1.2.3