if (prefs_common.auto_exteditor)
compose_exec_ext_editor(compose);
+ compose->draft_timeout_tag = -1;
compose->modified = FALSE;
compose_set_title(compose);
return compose;
compose_set_title(compose);
compose->updating = FALSE;
+ compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
if (compose->deferred_destroy) {
compose_destroy(compose);
compose_set_title(compose);
compose->updating = FALSE;
+ compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
if (compose->deferred_destroy) {
compose_destroy(compose);
compose_set_title(compose);
compose->updating = FALSE;
+ compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
if (compose->deferred_destroy) {
compose_destroy(compose);
compose_set_title(compose);
compose->updating = FALSE;
+ compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
if (compose->deferred_destroy) {
compose_destroy(compose);
compose->modified = FALSE;
compose_set_title(compose);
compose->updating = FALSE;
+ compose->draft_timeout_tag = -1; /* desinhibit auto-drafting after loading */
if (compose->deferred_destroy) {
compose_destroy(compose);
compose->exteditor_file = NULL;
compose->exteditor_pid = -1;
compose->exteditor_tag = -1;
- compose->draft_timeout_tag = -1;
+ compose->draft_timeout_tag = -2; /* inhibit auto-drafting while loading */
#if USE_ASPELL
menu_set_sensitive(ifactory, "/Spelling", FALSE);
"to send this email.")))
return;
- if (compose->draft_timeout_tag != -1) { /* CLAWS: disable draft timeout */
+ if (compose->draft_timeout_tag >= 0) { /* CLAWS: disable draft timeout */
g_source_remove(compose->draft_timeout_tag);
compose->draft_timeout_tag = -1;
}
toolbar_main_set_sensitive(mainwindow_get_mainwindow());
}
-void compose_draft (gpointer data, guint action)
-{
- compose_draft_cb(data, action, NULL);
-}
-
#define DRAFTED_AT_EXIT "drafted_at_exit"
-void compose_clear_exit_drafts(void)
-{
- gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- DRAFTED_AT_EXIT, NULL);
- if (is_file_exist(filepath))
- g_unlink(filepath);
-
- g_free(filepath);
-}
-
static void compose_register_draft(MsgInfo *info)
{
gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
g_free(filepath);
}
-void compose_reopen_exit_drafts(void)
-{
- gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
- DRAFTED_AT_EXIT, NULL);
- FILE *fp = fopen(filepath, "rb");
- gchar buf[1024];
-
- if (fp) {
- while (fgets(buf, sizeof(buf), fp)) {
- gchar **parts = g_strsplit(buf, "\t", 2);
- const gchar *folder = parts[0];
- int msgnum = parts[1] ? atoi(parts[1]):-1;
-
- if (folder && *folder && msgnum > -1) {
- FolderItem *item = folder_find_item_from_identifier(folder);
- MsgInfo *info = folder_item_get_msginfo(item, msgnum);
- if (info)
- compose_reedit(info, FALSE);
- }
- g_strfreev(parts);
- }
- fclose(fp);
- }
- g_free(filepath);
- compose_clear_exit_drafts();
-}
-
-static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
+gboolean compose_draft (gpointer data, guint action)
{
Compose *compose = (Compose *)data;
FolderItem *draft;
FILE *fp;
gboolean target_locked = FALSE;
- if (lock) return;
+ if (lock) return FALSE;
+
+ if (compose->sending)
+ return TRUE;
draft = account_get_special_folder(compose->account, F_DRAFT);
- g_return_if_fail(draft != NULL);
+ g_return_val_if_fail(draft != NULL, FALSE);
if (!g_mutex_trylock(compose->mutex)) {
/* we don't want to lock the mutex once it's available,
* it is compose_close - which means once unlocked,
* the compose struct will be freed */
debug_print("couldn't lock mutex, probably sending\n");
- return;
+ return FALSE;
}
lock = TRUE;
if ((msgnum = folder_item_add_msg(draft, tmp, &flag, TRUE)) < 0) {
g_unlink(tmp);
g_free(tmp);
- if (action != COMPOSE_AUTO_SAVE)
- alertpanel_error(_("Could not save draft."));
+ if (action != COMPOSE_AUTO_SAVE) {
+ if (action != COMPOSE_DRAFT_FOR_EXIT)
+ alertpanel_error(_("Could not save draft."));
+ else {
+ AlertValue val;
+ gtkut_window_popup(compose->window);
+ val = alertpanel_full(_("Could not save draft"),
+ _("Could not save draft.\n"
+ "Do you want to cancel exit or discard this email?"),
+ _("_Cancel exit"), _("_Discard email"), NULL,
+ FALSE, NULL, ALERT_QUESTION, G_ALERTDEFAULT);
+ if (val == G_ALERTALTERNATE) {
+ lock = FALSE;
+ g_mutex_unlock(compose->mutex); /* must be done before closing */
+ compose_close(compose);
+ return TRUE;
+ } else {
+ lock = FALSE;
+ g_mutex_unlock(compose->mutex); /* must be done before closing */
+ return FALSE;
+ }
+ }
+ }
goto unlock;
}
g_free(tmp);
lock = FALSE;
g_mutex_unlock(compose->mutex); /* must be done before closing */
compose_close(compose);
- return;
+ return TRUE;
} else {
struct stat s;
gchar *path;
unlock:
lock = FALSE;
g_mutex_unlock(compose->mutex);
+ return TRUE;
+}
+
+void compose_clear_exit_drafts(void)
+{
+ gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ DRAFTED_AT_EXIT, NULL);
+ if (is_file_exist(filepath))
+ g_unlink(filepath);
+
+ g_free(filepath);
+}
+
+void compose_reopen_exit_drafts(void)
+{
+ gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+ DRAFTED_AT_EXIT, NULL);
+ FILE *fp = fopen(filepath, "rb");
+ gchar buf[1024];
+
+ if (fp) {
+ while (fgets(buf, sizeof(buf), fp)) {
+ gchar **parts = g_strsplit(buf, "\t", 2);
+ const gchar *folder = parts[0];
+ int msgnum = parts[1] ? atoi(parts[1]):-1;
+
+ if (folder && *folder && msgnum > -1) {
+ FolderItem *item = folder_find_item_from_identifier(folder);
+ MsgInfo *info = folder_item_get_msginfo(item, msgnum);
+ if (info)
+ compose_reedit(info, FALSE);
+ }
+ g_strfreev(parts);
+ }
+ fclose(fp);
+ }
+ g_free(filepath);
+ compose_clear_exit_drafts();
+}
+
+static void compose_draft_cb(gpointer data, guint action, GtkWidget *widget)
+{
+ compose_draft(data, action);
}
static void compose_attach_cb(gpointer data, guint action, GtkWidget *widget)
g_signal_stop_emission_by_name(G_OBJECT(buffer), "insert-text");
if (prefs_common.autosave &&
- gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0)
+ gtk_text_buffer_get_char_count(buffer) % prefs_common.autosave_length == 0 &&
+ compose->draft_timeout_tag != -2 /* disabled while loading */)
compose->draft_timeout_tag = g_timeout_add
(500, (GtkFunction) compose_defer_auto_save_draft, compose);
}
* drafting to be done, before destroying the compose under
* it. */
debug_print("waiting for drafting to finish...\n");
+ compose_allow_user_actions(compose, FALSE);
g_timeout_add (500, (GSourceFunc) compose_close, compose);
return FALSE;
}
}
tmp_msginfo->folder = orig_msginfo->folder;
tmp_msginfo->msgnum = orig_msginfo->msgnum;
+ if (orig_msginfo->tags)
+ tmp_msginfo->tags = g_slist_copy(orig_msginfo->tags);
}
}
}