diff options
-rw-r--r-- | mail/ChangeLog | 8 | ||||
-rw-r--r-- | mail/folder-browser-factory.c | 2 | ||||
-rw-r--r-- | mail/mail-ops.c | 122 | ||||
-rw-r--r-- | mail/mail-ops.h | 1 | ||||
-rw-r--r-- | mail/message-list.c | 1 |
5 files changed, 134 insertions, 0 deletions
diff --git a/mail/ChangeLog b/mail/ChangeLog index 03b9784f45..a39cc0bfd2 100644 --- a/mail/ChangeLog +++ b/mail/ChangeLog @@ -1,3 +1,11 @@ +2000-11-16 Jeffrey Stedfast <fejj@helixcode.com> + + * folder-browser-factory.c: Added the MessageViewSource bonobo + menu verb. + + * mail-ops.c (mail_do_save_messages): New async function to save + messages as individual files in a given path. + 2000-11-15 Jeffrey Stedfast <fejj@helixcode.com> * folder-browser-factory.c: Added a new Forward as Attachment diff --git a/mail/folder-browser-factory.c b/mail/folder-browser-factory.c index d500c1cfb5..1ca2a2c906 100644 --- a/mail/folder-browser-factory.c +++ b/mail/folder-browser-factory.c @@ -80,6 +80,8 @@ BonoboUIVerb verbs [] = { BONOBO_UI_UNSAFE_VERB ("MessageFilterSndr", filter_sender), BONOBO_UI_UNSAFE_VERB ("MessageFilterRecip", filter_recipient), + BONOBO_UI_UNSAFE_VERB ("MessageViewSource", view_source), + /* Folder Menu */ BONOBO_UI_UNSAFE_VERB ("FolderExpunge", expunge_folder), BONOBO_UI_UNSAFE_VERB ("FolderConfig", configure_folder), diff --git a/mail/mail-ops.c b/mail/mail-ops.c index 5b60be09f8..49b36f3eee 100644 --- a/mail/mail-ops.c +++ b/mail/mail-ops.c @@ -2528,3 +2528,125 @@ mail_do_view_message_sources (CamelFolder *folder, GPtrArray *uids, mail_operation_queue (&op_view_message_sources, input, TRUE); } + +/* ** SAVE MESSAGES ******************************************************* */ + +typedef struct save_messages_input_s { + CamelFolder *folder; + GPtrArray *uids; + gchar *path; +} save_messages_input_t; + +typedef struct save_messages_data_s { + GPtrArray *messages; +} save_messages_data_t; + +static gchar * +describe_save_messages (gpointer in_data, gboolean gerund) +{ + save_messages_input_t *input = (save_messages_input_t *) in_data; + + if (gerund) + return g_strdup_printf (_("Saving messages from folder \"%s\""), + mail_tool_get_folder_name (input->folder)); + else + return g_strdup_printf (_("Saving messages from \"%s\""), + mail_tool_get_folder_name (input->folder)); +} + +static void +setup_save_messages (gpointer in_data, gpointer op_data, CamelException *ex) +{ + save_messages_input_t *input = (save_messages_input_t *) in_data; + + camel_object_ref (CAMEL_OBJECT (input->folder)); +} + +static void +do_save_messages (gpointer in_data, gpointer op_data, CamelException *ex) +{ + save_messages_input_t *input = (save_messages_input_t *) in_data; + save_messages_data_t *data = (save_messages_data_t *) op_data; + int i; + + data->messages = g_ptr_array_new (); + + for (i = 0; i < input->uids->len; i++) { + CamelMimeMessage *message; + + mail_op_set_message (_("Retrieving message %d of %d (uid \"%s\")"), + i + 1, input->uids->len, (char *)input->uids->pdata[i]); + + mail_tool_camel_lock_up (); + message = camel_folder_get_message (input->folder, input->uids->pdata[i], ex); + mail_tool_camel_lock_down (); + + g_ptr_array_add (data->messages, message); + } +} + +static void +cleanup_save_messages (gpointer in_data, gpointer op_data, + CamelException *ex) +{ + save_messages_input_t *input = (save_messages_input_t *) in_data; + save_messages_data_t *data = (save_messages_data_t *) op_data; + int i; + + for (i = 0; i < data->messages->len; i++) { + CamelMimeMessage *msg; + CamelStream *stream; + char *filename; + + if (data->messages->pdata[i] == NULL) + continue; + + msg = data->messages->pdata[i]; + + /* if we are saving a single message, use the filename the user selected */ + if (input->uids->len == 1) + filename = g_strdup (input->path); + else + filename = g_strdup_printf ("%s/[%s] %s.eml", input->path, + camel_mime_message_get_subject (msg), + (char *) input->uids->pdata[i]); + + stream = camel_stream_fs_new_with_name (filename, O_WRONLY | O_CREAT | O_TRUNC, 0600); + camel_data_wrapper_write_to_stream (CAMEL_DATA_WRAPPER (msg), stream); + camel_stream_flush (stream); + g_free (filename); + + camel_object_unref (CAMEL_OBJECT (stream)); + camel_object_unref (CAMEL_OBJECT (data->messages->pdata[i])); + g_free (input->uids->pdata[i]); + } + + g_ptr_array_free (input->uids, TRUE); + g_ptr_array_free (data->messages, TRUE); + camel_object_unref (CAMEL_OBJECT (input->folder)); +} + +static const mail_operation_spec op_save_messages = { + describe_save_messages, + sizeof (save_messages_data_t), + setup_save_messages, + do_save_messages, + cleanup_save_messages +}; + +void +mail_do_save_messages (CamelFolder *folder, GPtrArray *uids, gchar *path) +{ + save_messages_input_t *input; + + g_return_if_fail (CAMEL_IS_FOLDER (folder)); + g_return_if_fail (uids != NULL); + g_return_if_fail (path != NULL); + + input = g_new (save_messages_input_t, 1); + input->folder = folder; + input->uids = uids; + input->path = path; + + mail_operation_queue (&op_save_messages, input, TRUE); +} diff --git a/mail/mail-ops.h b/mail/mail-ops.h index 0209d10529..de56198e7b 100644 --- a/mail/mail-ops.h +++ b/mail/mail-ops.h @@ -73,3 +73,4 @@ void mail_do_view_messages (CamelFolder *folder, GPtrArray *uids, FolderBrowser *fb); void mail_do_view_message_sources (CamelFolder *folder, GPtrArray *uids, FolderBrowser *fb); +void mail_do_save_messages (CamelFolder *folder, GPtrArray *uids, gchar *path); diff --git a/mail/message-list.c b/mail/message-list.c index 8ea8c35677..685bfa6be0 100644 --- a/mail/message-list.c +++ b/mail/message-list.c @@ -360,6 +360,7 @@ message_list_drag_data_get (ETable *table, switch (info) { case DND_TARGET_LIST_TYPE_URI: + /* drag & drop into nautilus */ mktemp (dirname); filename = g_strdup_printf ("%s.eml", info->subject); url = g_strdup_printf ("file:%s", dirname); |