diff options
-rw-r--r-- | composer/e-composer-actions.c | 18 | ||||
-rw-r--r-- | composer/e-msg-composer.c | 119 | ||||
-rw-r--r-- | composer/e-msg-composer.h | 8 | ||||
-rw-r--r-- | composer/mail-composer.error.xml | 14 | ||||
-rw-r--r-- | mail/e-mail-session-utils.c | 109 | ||||
-rw-r--r-- | mail/e-mail-session-utils.h | 3 | ||||
-rw-r--r-- | mail/em-composer-utils.c | 213 |
7 files changed, 281 insertions, 203 deletions
diff --git a/composer/e-composer-actions.c b/composer/e-composer-actions.c index b47b60241a..5e57e6df2f 100644 --- a/composer/e-composer-actions.c +++ b/composer/e-composer-actions.c @@ -193,14 +193,28 @@ static void action_save_draft_cb (GtkAction *action, EMsgComposer *composer) { - e_msg_composer_save_draft (composer); + e_msg_composer_save_to_drafts (composer); } static void action_send_cb (GtkAction *action, EMsgComposer *composer) { - e_msg_composer_send (composer); + CamelSession *session; + + session = e_msg_composer_get_session (composer); + + /* If we're online, send the message now. + * Otherwise write the message to Outbox. */ + if (camel_session_get_online (session)) + e_msg_composer_send (composer); + else { + /* Inform the user. */ + e_alert_run_dialog_for_args ( + GTK_WINDOW (composer), + "mail-composer:saving-to-outbox", NULL); + e_msg_composer_save_to_outbox (composer); + } } static void diff --git a/composer/e-msg-composer.c b/composer/e-msg-composer.c index 34cf70597a..faa99acf1d 100644 --- a/composer/e-msg-composer.c +++ b/composer/e-msg-composer.c @@ -94,7 +94,8 @@ enum { enum { PRESEND, SEND, - SAVE_DRAFT, + SAVE_TO_DRAFTS, + SAVE_TO_OUTBOX, PRINT, LAST_SIGNAL }; @@ -2530,11 +2531,22 @@ e_msg_composer_class_init (EMsgComposerClass *class) CAMEL_TYPE_MIME_MESSAGE, E_TYPE_ACTIVITY); - signals[SAVE_DRAFT] = g_signal_new ( - "save-draft", + signals[SAVE_TO_DRAFTS] = g_signal_new ( + "save-to-drafts", G_OBJECT_CLASS_TYPE (class), G_SIGNAL_RUN_LAST, - G_STRUCT_OFFSET (EMsgComposerClass, save_draft), + G_STRUCT_OFFSET (EMsgComposerClass, save_to_drafts), + NULL, NULL, + e_marshal_VOID__OBJECT_OBJECT, + G_TYPE_NONE, 2, + CAMEL_TYPE_MIME_MESSAGE, + E_TYPE_ACTIVITY); + + signals[SAVE_TO_OUTBOX] = g_signal_new ( + "save-to-outbox", + G_OBJECT_CLASS_TYPE (class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EMsgComposerClass, save_to_outbox), NULL, NULL, e_marshal_VOID__OBJECT_OBJECT, G_TYPE_NONE, 2, @@ -3562,9 +3574,9 @@ e_msg_composer_send (EMsgComposer *composer) } static void -msg_composer_save_draft_cb (EMsgComposer *composer, - GAsyncResult *result, - AsyncContext *context) +msg_composer_save_to_drafts_cb (EMsgComposer *composer, + GAsyncResult *result, + AsyncContext *context) { CamelMimeMessage *message; GtkhtmlEditor *editor; @@ -3595,8 +3607,8 @@ msg_composer_save_draft_cb (EMsgComposer *composer, g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); g_signal_emit ( - composer, signals[SAVE_DRAFT], 0, - message, context->activity); + composer, signals[SAVE_TO_DRAFTS], + 0, message, context->activity); g_object_unref (message); @@ -3608,13 +3620,13 @@ msg_composer_save_draft_cb (EMsgComposer *composer, } /** - * e_msg_composer_save_draft: + * e_msg_composer_save_to_drafts: * @composer: an #EMsgComposer * * Save the message in @composer to the selected account's Drafts folder. **/ void -e_msg_composer_save_draft (EMsgComposer *composer) +e_msg_composer_save_to_drafts (EMsgComposer *composer) { AsyncContext *context; EActivityBar *activity_bar; @@ -3634,7 +3646,90 @@ e_msg_composer_save_draft (EMsgComposer *composer) e_msg_composer_get_message_draft ( composer, G_PRIORITY_DEFAULT, cancellable, - (GAsyncReadyCallback) msg_composer_save_draft_cb, + (GAsyncReadyCallback) msg_composer_save_to_drafts_cb, + context); +} + +static void +msg_composer_save_to_outbox_cb (EMsgComposer *composer, + GAsyncResult *result, + AsyncContext *context) +{ + CamelMimeMessage *message; + GtkhtmlEditor *editor; + GError *error = NULL; + + message = e_msg_composer_get_message_finish (composer, result, &error); + + /* Ignore cancellations. */ + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + g_warn_if_fail (message == NULL); + async_context_free (context); + g_error_free (error); + return; + } + + if (error != NULL) { + g_warn_if_fail (message == NULL); + async_context_free (context); + e_alert_submit ( + GTK_WIDGET (composer), + "mail-composer:no-build-message", + error->message, NULL); + g_error_free (error); + return; + } + + g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); + + g_signal_emit ( + composer, signals[SAVE_TO_OUTBOX], + 0, message, context->activity); + + g_object_unref (message); + + async_context_free (context); + + /* XXX This should be elsewhere. */ + editor = GTKHTML_EDITOR (composer); + gtkhtml_editor_set_changed (editor, FALSE); +} + +/** + * e_msg_composer_save_to_outbox: + * @composer: an #EMsgComposer + * + * Save the message in @composer to the local Outbox folder. + **/ +void +e_msg_composer_save_to_outbox (EMsgComposer *composer) +{ + AsyncContext *context; + EActivityBar *activity_bar; + GCancellable *cancellable; + gboolean proceed_with_save = TRUE; + + g_return_if_fail (E_IS_MSG_COMPOSER (composer)); + + /* This gives the user a chance to abort the save. */ + g_signal_emit (composer, signals[PRESEND], 0, &proceed_with_save); + + if (!proceed_with_save) + return; + + context = g_slice_new0 (AsyncContext); + context->activity = e_composer_activity_new (composer); + + cancellable = camel_operation_new (); + e_activity_set_cancellable (context->activity, cancellable); + g_object_unref (cancellable); + + activity_bar = E_ACTIVITY_BAR (composer->priv->activity_bar); + e_activity_bar_set_activity (activity_bar, context->activity); + + e_msg_composer_get_message ( + composer, G_PRIORITY_DEFAULT, cancellable, + (GAsyncReadyCallback) msg_composer_save_to_outbox_cb, context); } diff --git a/composer/e-msg-composer.h b/composer/e-msg-composer.h index 7b782c2c3a..2fe912d7a8 100644 --- a/composer/e-msg-composer.h +++ b/composer/e-msg-composer.h @@ -74,7 +74,10 @@ struct _EMsgComposerClass { GtkPrintOperationAction print_action, CamelMimeMessage *message, EActivity *activity); - void (*save_draft) (EMsgComposer *composer, + void (*save_to_drafts) (EMsgComposer *composer, + CamelMimeMessage *message, + EActivity *activity); + void (*save_to_outbox) (EMsgComposer *composer, CamelMimeMessage *message, EActivity *activity); void (*send) (EMsgComposer *composer, @@ -100,7 +103,8 @@ EShell * e_msg_composer_get_shell (EMsgComposer *composer); EWebView * e_msg_composer_get_web_view (EMsgComposer *composer); void e_msg_composer_send (EMsgComposer *composer); -void e_msg_composer_save_draft (EMsgComposer *composer); +void e_msg_composer_save_to_drafts (EMsgComposer *composer); +void e_msg_composer_save_to_outbox (EMsgComposer *composer); void e_msg_composer_print (EMsgComposer *composer, GtkPrintOperationAction print_action); diff --git a/composer/mail-composer.error.xml b/composer/mail-composer.error.xml index 90f0187b0e..e265aaad02 100644 --- a/composer/mail-composer.error.xml +++ b/composer/mail-composer.error.xml @@ -63,19 +63,23 @@ <_secondary>The reported error was "{0}". The message has not been sent.</_secondary> </error> - <error id="save-draft-error" type="error"> + <error id="save-to-drafts-error" type="error"> <_primary>An error occurred while saving to your Drafts folder.</_primary> <_secondary>The reported error was "{0}". The message has most likely not been saved.</_secondary> </error> <error id="send-error" type="error"> - <_primary>An error occurred while sending.</_primary> + <_primary>An error occurred while sending. How do you want to proceed?</_primary> <_secondary>The reported error was "{0}".</_secondary> + <!-- Response codes were chosen somewhat arbitrarily. --> + <button _label="_Continue Editing" response="GTK_RESPONSE_CLOSE"/> + <button _label="_Save to Outbox" response="GTK_RESPONSE_ACCEPT"/> + <button _label="_Try Again" response="GTK_RESPONSE_OK"/> </error> - <error id="saved-to-outbox" type="info"> - <_primary>Message saved to Outbox.</_primary> - <_secondary>Because you are working offline, the message has been saved to your local Outbox folder. When you are back online you can send the message by clicking the Send/Receive button in Evolution's toolbar.</_secondary> + <error id="saving-to-outbox" type="info"> + <_primary>Saving message to Outbox.</_primary> + <_secondary>Because you are working offline, the message will be saved to your local Outbox folder. When you are back online you can send the message by clicking the Send/Receive button in Evolution's toolbar.</_secondary> </error> </error-list> diff --git a/mail/e-mail-session-utils.c b/mail/e-mail-session-utils.c index b436243c10..2369a69d35 100644 --- a/mail/e-mail-session-utils.c +++ b/mail/e-mail-session-utils.c @@ -33,7 +33,6 @@ typedef struct _AsyncContext AsyncContext; struct _AsyncContext { CamelFolder *sent_folder; - CamelFolder *outbox_folder; CamelMimeMessage *message; CamelMessageInfo *info; @@ -63,9 +62,6 @@ async_context_free (AsyncContext *context) if (context->sent_folder != NULL) g_object_unref (context->sent_folder); - if (context->outbox_folder != NULL) - g_object_unref (context->outbox_folder); - if (context->message != NULL) g_object_unref (context->message); @@ -564,19 +560,6 @@ cleanup: /* The send operation was successful; ignore cleanup errors. */ - /* Mark the Outbox message for deletion. */ - camel_folder_set_message_flags ( - context->outbox_folder, context->message_uid, - CAMEL_MESSAGE_DELETED | CAMEL_MESSAGE_SEEN, ~0); - - /* Synchronize the Outbox folder. */ - camel_folder_synchronize_sync ( - context->outbox_folder, FALSE, cancellable, &error); - if (error != NULL) { - g_warning ("%s", error->message); - g_clear_error (&error); - } - /* Mark the draft message for deletion, if present. */ e_mail_session_handle_draft_headers_sync ( session, context->message, cancellable, &error); @@ -617,17 +600,23 @@ exit: g_string_free (error_messages, TRUE); } -static void -mail_session_send_to_prepare (CamelFolder *outbox_folder, - GAsyncResult *result, - GSimpleAsyncResult *simple) +void +e_mail_session_send_to (EMailSession *session, + CamelMimeMessage *message, + const gchar *destination, + gint io_priority, + GCancellable *cancellable, + CamelFilterGetFolderFunc get_folder_func, + gpointer get_folder_data, + GAsyncReadyCallback callback, + gpointer user_data) { + GSimpleAsyncResult *simple; AsyncContext *context; CamelAddress *from; CamelAddress *recipients; CamelMedium *medium; CamelMessageInfo *info; - CamelMimeMessage *message; EAccount *account = NULL; GPtrArray *post_to_uris; struct _camel_header_raw *xev; @@ -638,20 +627,7 @@ mail_session_send_to_prepare (CamelFolder *outbox_folder, gchar *sent_folder_uri = NULL; GError *error = NULL; - context = g_simple_async_result_get_op_res_gpointer (simple); - - message = camel_folder_get_message_finish ( - outbox_folder, result, &error); - - if (error != NULL) { - g_warn_if_fail (message == NULL); - g_simple_async_result_set_from_error (simple, error); - g_simple_async_result_complete (simple); - g_object_unref (simple); - g_error_free (error); - return; - } - + g_return_if_fail (E_IS_MAIL_SESSION (session)); g_return_if_fail (CAMEL_IS_MIME_MESSAGE (message)); medium = CAMEL_MEDIUM (message); @@ -686,7 +662,7 @@ mail_session_send_to_prepare (CamelFolder *outbox_folder, sent_folder_uri = g_strstrip (g_strdup (string)); if (transport_uri == NULL) - transport_uri = g_strdup (context->destination); + transport_uri = g_strdup (destination); post_to_uris = g_ptr_array_new (); for (header = xev; header != NULL; header = header->next) { @@ -750,6 +726,10 @@ mail_session_send_to_prepare (CamelFolder *outbox_folder, /* The rest of the processing happens in a thread. */ + context = g_slice_new0 (AsyncContext); + context->message = g_object_ref (message); + context->destination = g_strdup (destination); + context->io_priority = io_priority; context->from = from; context->recipients = recipients; context->message = g_object_ref (message); @@ -759,46 +739,10 @@ mail_session_send_to_prepare (CamelFolder *outbox_folder, context->transport_uri = transport_uri; context->sent_folder_uri = sent_folder_uri; - g_simple_async_result_run_in_thread ( - simple, (GSimpleAsyncThreadFunc) - mail_session_send_to_thread, - context->io_priority, - context->cancellable); - - g_object_unref (simple); -} - -void -e_mail_session_send_to (EMailSession *session, - CamelFolder *outbox_folder, - const gchar *message_uid, - const gchar *destination, - gint io_priority, - GCancellable *cancellable, - CamelFilterGetFolderFunc get_folder_func, - gpointer get_folder_data, - GAsyncReadyCallback callback, - gpointer user_data) -{ - GSimpleAsyncResult *simple; - AsyncContext *context; - GError *error = NULL; - - g_return_if_fail (E_IS_MAIL_SESSION (session)); - g_return_if_fail (CAMEL_IS_FOLDER (outbox_folder)); - g_return_if_fail (message_uid != NULL); - - context = g_slice_new0 (AsyncContext); - context->outbox_folder = g_object_ref (outbox_folder); - context->message_uid = g_strdup (message_uid); - context->destination = g_strdup (destination); - context->io_priority = io_priority; - if (G_IS_CANCELLABLE (cancellable)) context->cancellable = g_object_ref (cancellable); - /* More convenient to do this here than in the prepare function. - * Failure here emits a runtime warning but is non-fatal. */ + /* Failure here emits a runtime warning but is non-fatal. */ context->driver = camel_session_get_filter_driver ( CAMEL_SESSION (session), E_FILTER_SOURCE_OUTGOING, &error); if (context->driver != NULL) @@ -810,6 +754,10 @@ e_mail_session_send_to (EMailSession *session, g_error_free (error); } + /* This gets popped in async_context_free(). */ + camel_operation_push_message ( + context->cancellable, _("Sending message")); + simple = g_simple_async_result_new ( G_OBJECT (session), callback, user_data, e_mail_session_send_to); @@ -817,14 +765,13 @@ e_mail_session_send_to (EMailSession *session, g_simple_async_result_set_op_res_gpointer ( simple, context, (GDestroyNotify) async_context_free); - /* This gets popped in async_context_free(). */ - camel_operation_push_message ( - context->cancellable, _("Sending message")); + g_simple_async_result_run_in_thread ( + simple, (GSimpleAsyncThreadFunc) + mail_session_send_to_thread, + context->io_priority, + context->cancellable); - camel_folder_get_message ( - outbox_folder, message_uid, io_priority, - context->cancellable, (GAsyncReadyCallback) - mail_session_send_to_prepare, simple); + g_object_unref (simple); } gboolean diff --git a/mail/e-mail-session-utils.h b/mail/e-mail-session-utils.h index fcbc2636f7..4d97524f5d 100644 --- a/mail/e-mail-session-utils.h +++ b/mail/e-mail-session-utils.h @@ -58,8 +58,7 @@ gboolean e_mail_session_handle_source_headers_finish GAsyncResult *result, GError **error); void e_mail_session_send_to (EMailSession *session, - CamelFolder *outbox_folder, - const gchar *message_uid, + CamelMimeMessage *message, const gchar *destination, gint io_priority, GCancellable *cancellable, diff --git a/mail/em-composer-utils.c b/mail/em-composer-utils.c index 02eb039916..91480a38eb 100644 --- a/mail/em-composer-utils.c +++ b/mail/em-composer-utils.c @@ -488,10 +488,21 @@ composer_send_completed (EMailSession *session, } if (error != NULL) { - e_alert_submit ( - GTK_WIDGET (context->composer), + gint response; + + /* Clear the activity bar before + * presenting the error dialog. */ + g_object_unref (context->activity); + context->activity = NULL; + + response = e_alert_run_dialog_for_args ( + GTK_WINDOW (context->composer), "mail-composer:send-error", error->message, NULL); + if (response == GTK_RESPONSE_OK) /* Try Again */ + e_msg_composer_send (context->composer); + if (response == GTK_RESPONSE_ACCEPT) /* Save to Outbox */ + e_msg_composer_save_to_outbox (context->composer); g_error_free (error); goto exit; } @@ -509,75 +520,12 @@ exit: } static void -composer_send_appended (CamelFolder *outbox_folder, - GAsyncResult *result, - AsyncContext *context) -{ - CamelSession *session; - GCancellable *cancellable; - gchar *message_uid = NULL; - GError *error = NULL; - - e_mail_folder_append_message_finish ( - outbox_folder, result, &message_uid, &error); - - /* Ignore cancellations. */ - if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { - g_warn_if_fail (message_uid == NULL); - async_context_free (context); - g_error_free (error); - return; - } - - if (error != NULL) { - g_warn_if_fail (message_uid == NULL); - e_alert_submit ( - GTK_WIDGET (context->composer), - "mail-composer:append-to-outbox-error", - error->message, NULL); - g_warning ("%s", error->message); - async_context_free (context); - g_error_free (error); - return; - } - - session = e_msg_composer_get_session (context->composer); - cancellable = e_activity_get_cancellable (context->activity); - - /* If we're online, go ahead and send the message now. */ - if (camel_session_get_online (session)) - e_mail_session_send_to ( - E_MAIL_SESSION (session), - outbox_folder, message_uid, NULL, - G_PRIORITY_DEFAULT, cancellable, NULL, NULL, - (GAsyncReadyCallback) composer_send_completed, - context); - - /* If we're offline, writing the message to the Outbox - * folder is as much as we can do. Tell the user. */ - else { - g_object_unref (context->activity); - context->activity = NULL; - - e_alert_run_dialog_for_args ( - GTK_WINDOW (context->composer), - "mail-composer:saved-to-outbox", NULL); - - gtk_widget_destroy (GTK_WIDGET (context->composer)); - async_context_free (context); - } - - g_free (message_uid); -} - -static void em_utils_composer_send_cb (EMsgComposer *composer, CamelMimeMessage *message, EActivity *activity) { AsyncContext *context; - CamelFolder *outbox_folder; - CamelMessageInfo *info; + CamelSession *session; GCancellable *cancellable; context = g_slice_new0 (AsyncContext); @@ -586,18 +534,13 @@ em_utils_composer_send_cb (EMsgComposer *composer, context->activity = g_object_ref (activity); cancellable = e_activity_get_cancellable (activity); - outbox_folder = e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_OUTBOX); - - info = camel_message_info_new (NULL); - camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0); + session = e_msg_composer_get_session (context->composer); - e_mail_folder_append_message ( - outbox_folder, message, info, - G_PRIORITY_DEFAULT, cancellable, - (GAsyncReadyCallback) composer_send_appended, + e_mail_session_send_to ( + E_MAIL_SESSION (session), message, NULL, + G_PRIORITY_DEFAULT, cancellable, NULL, NULL, + (GAsyncReadyCallback) composer_send_completed, context); - - camel_message_info_free (info); } static void @@ -614,9 +557,9 @@ composer_set_no_change (EMsgComposer *composer) } static void -composer_save_draft_complete (EMailSession *session, - GAsyncResult *result, - AsyncContext *context) +composer_save_to_drafts_complete (EMailSession *session, + GAsyncResult *result, + AsyncContext *context) { GError *error = NULL; @@ -649,9 +592,9 @@ composer_save_draft_complete (EMailSession *session, } static void -composer_save_draft_cleanup (CamelFolder *drafts_folder, - GAsyncResult *result, - AsyncContext *context) +composer_save_to_drafts_cleanup (CamelFolder *drafts_folder, + GAsyncResult *result, + AsyncContext *context) { CamelSession *session; GCancellable *cancellable; @@ -672,7 +615,7 @@ composer_save_draft_cleanup (CamelFolder *drafts_folder, g_warn_if_fail (context->message_uid == NULL); e_alert_submit ( GTK_WIDGET (context->composer), - "mail-composer:save-draft-error", + "mail-composer:save-to-drafts-error", error->message, NULL); async_context_free (context); g_error_free (error); @@ -687,12 +630,12 @@ composer_save_draft_cleanup (CamelFolder *drafts_folder, e_mail_session_handle_draft_headers ( E_MAIL_SESSION (session), context->message, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) - composer_save_draft_complete, context); + composer_save_to_drafts_complete, context); } static void -composer_save_draft_append_mail (AsyncContext *context, - CamelFolder *drafts_folder) +composer_save_to_drafts_append_mail (AsyncContext *context, + CamelFolder *drafts_folder) { CamelFolder *local_drafts_folder; GCancellable *cancellable; @@ -714,7 +657,7 @@ composer_save_draft_append_mail (AsyncContext *context, e_mail_folder_append_message ( drafts_folder, context->message, info, G_PRIORITY_DEFAULT, cancellable, - (GAsyncReadyCallback) composer_save_draft_cleanup, + (GAsyncReadyCallback) composer_save_to_drafts_cleanup, context); camel_message_info_free (info); @@ -723,9 +666,9 @@ composer_save_draft_append_mail (AsyncContext *context, } static void -composer_save_draft_got_folder (EMailSession *session, - GAsyncResult *result, - AsyncContext *context) +composer_save_to_drafts_got_folder (EMailSession *session, + GAsyncResult *result, + AsyncContext *context) { CamelFolder *drafts_folder; GError *error = NULL; @@ -761,13 +704,13 @@ composer_save_draft_got_folder (EMailSession *session, } } - composer_save_draft_append_mail (context, drafts_folder); + composer_save_to_drafts_append_mail (context, drafts_folder); } static void -em_utils_composer_save_draft_cb (EMsgComposer *composer, - CamelMimeMessage *message, - EActivity *activity) +em_utils_composer_save_to_drafts_cb (EMsgComposer *composer, + CamelMimeMessage *message, + EActivity *activity) { AsyncContext *context; EComposerHeaderTable *table; @@ -796,7 +739,7 @@ em_utils_composer_save_draft_cb (EMsgComposer *composer, drafts_folder_uri = NULL; if (drafts_folder_uri == NULL) { - composer_save_draft_append_mail (context, NULL); + composer_save_to_drafts_append_mail (context, NULL); context->folder_uri = g_strdup (local_drafts_folder_uri); } else { GCancellable *cancellable; @@ -808,11 +751,79 @@ em_utils_composer_save_draft_cb (EMsgComposer *composer, E_MAIL_SESSION (session), drafts_folder_uri, 0, G_PRIORITY_DEFAULT, cancellable, (GAsyncReadyCallback) - composer_save_draft_got_folder, context); + composer_save_to_drafts_got_folder, context); } } static void +composer_save_to_outbox_completed (CamelFolder *outbox_folder, + GAsyncResult *result, + AsyncContext *context) +{ + GError *error = NULL; + + e_mail_folder_append_message_finish ( + outbox_folder, result, NULL, &error); + + /* Ignore cancellations. */ + if (g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED)) { + e_activity_set_state (context->activity, E_ACTIVITY_CANCELLED); + g_error_free (error); + goto exit; + } + + if (error != NULL) { + e_alert_submit ( + GTK_WIDGET (context->composer), + "mail-composer:append-to-outbox-error", + error->message, NULL); + g_error_free (error); + goto exit; + } + + e_activity_set_state (context->activity, E_ACTIVITY_COMPLETED); + + /* Wait for the EActivity's completion message to + * time out and then destroy the composer window. */ + g_object_weak_ref ( + G_OBJECT (context->activity), (GWeakNotify) + gtk_widget_destroy, context->composer); + +exit: + async_context_free (context); +} + +static void +em_utils_composer_save_to_outbox_cb (EMsgComposer *composer, + CamelMimeMessage *message, + EActivity *activity) +{ + AsyncContext *context; + CamelFolder *outbox_folder; + CamelMessageInfo *info; + GCancellable *cancellable; + + context = g_slice_new0 (AsyncContext); + context->message = g_object_ref (message); + context->composer = g_object_ref (composer); + context->activity = g_object_ref (activity); + + cancellable = e_activity_get_cancellable (activity); + outbox_folder = e_mail_local_get_folder (E_MAIL_LOCAL_FOLDER_OUTBOX); + + info = camel_message_info_new (NULL); + camel_message_info_set_flags (info, CAMEL_MESSAGE_SEEN, ~0); + + e_mail_folder_append_message ( + outbox_folder, message, info, + G_PRIORITY_DEFAULT, cancellable, + (GAsyncReadyCallback) composer_save_to_outbox_completed, + context); + + camel_message_info_free (info); +} + +static void em_utils_composer_print_cb (EMsgComposer *composer, GtkPrintOperationAction action, CamelMimeMessage *message, @@ -1260,7 +1271,7 @@ setup_forward_attached_callbacks (EMsgComposer *composer, composer, "send", G_CALLBACK (update_forwarded_flags_cb), data); g_signal_connect ( - composer, "save-draft", + composer, "save-to-drafts", G_CALLBACK (update_forwarded_flags_cb), data); g_object_set_data_full ( @@ -2707,8 +2718,12 @@ em_configure_new_composer (EMsgComposer *composer) G_CALLBACK (em_utils_composer_send_cb), NULL); g_signal_connect ( - composer, "save-draft", - G_CALLBACK (em_utils_composer_save_draft_cb), NULL); + composer, "save-to-drafts", + G_CALLBACK (em_utils_composer_save_to_drafts_cb), NULL); + + g_signal_connect ( + composer, "save-to-outbox", + G_CALLBACK (em_utils_composer_save_to_outbox_cb), NULL); g_signal_connect ( composer, "print", |