diff options
author | Jeffrey Stedfast <fejj@helixcode.com> | 2000-11-17 07:05:32 +0800 |
---|---|---|
committer | Jeffrey Stedfast <fejj@src.gnome.org> | 2000-11-17 07:05:32 +0800 |
commit | 4db080e17f7f6637cf184a84d3e07a97b6e6904a (patch) | |
tree | 04c6a4e2392bd18f79661aa5a1ad3b39b7f919fd /mail/mail-ops.c | |
parent | c953cc6fe34092d3e0509ed45375de8cf1172910 (diff) | |
download | gsoc2013-evolution-4db080e17f7f6637cf184a84d3e07a97b6e6904a.tar.gz gsoc2013-evolution-4db080e17f7f6637cf184a84d3e07a97b6e6904a.tar.zst gsoc2013-evolution-4db080e17f7f6637cf184a84d3e07a97b6e6904a.zip |
Added the MessageViewSource bonobo menu verb.
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.
svn path=/trunk/; revision=6596
Diffstat (limited to 'mail/mail-ops.c')
-rw-r--r-- | mail/mail-ops.c | 122 |
1 files changed, 122 insertions, 0 deletions
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); +} |