GList *listAddress );
static Compose *compose_create (PrefsAccount *account,
+ FolderItem *item,
ComposeMode mode,
gboolean batch);
GtkTextBuffer *textbuf;
GtkTextIter iter;
GtkItemFactory *ifactory;
- gchar *subject_format = NULL;
- gchar *body_format = NULL;
+ const gchar *subject_format = NULL;
+ const gchar *body_format = NULL;
if (item && item->prefs && item->prefs->enable_default_account)
account = account_find_from_id(item->prefs->default_account);
if (!account) account = cur_account;
g_return_val_if_fail(account != NULL, NULL);
- compose = compose_create(account, COMPOSE_NEW, FALSE);
+ compose = compose_create(account, item, COMPOSE_NEW, FALSE);
ifactory = gtk_item_factory_from_widget(compose->menubar);
GtkTextView *textview;
GtkTextBuffer *textbuf;
gboolean quote = FALSE;
- gchar *qmark = NULL;
- gchar *body_fmt = NULL;
+ const gchar *qmark = NULL;
+ const gchar *body_fmt = NULL;
g_return_val_if_fail(msginfo != NULL, NULL);
g_return_val_if_fail(msginfo->folder != NULL, NULL);
g_return_val_if_fail(account != NULL, NULL);
- compose = compose_create(account, COMPOSE_REPLY, FALSE);
+ compose = compose_create(account, msginfo->folder, COMPOSE_REPLY, FALSE);
compose->updating = TRUE;
(msginfo)))
account = cur_account;
- compose = compose_create(account, COMPOSE_FORWARD, batch);
+ compose = compose_create(account, msginfo->folder, COMPOSE_FORWARD, batch);
compose->updating = TRUE;
compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
g_free(msgfile);
} else {
- gchar *qmark = NULL;
- gchar *body_fmt = prefs_common.fw_quotefmt;
+ const gchar *qmark = NULL;
+ const gchar *body_fmt = prefs_common.fw_quotefmt;
MsgInfo *full_msginfo;
full_msginfo = procmsg_msginfo_get_full_info(msginfo);
}
/* empty quotemark is not allowed */
- if (qmark && !*qmark)
+ if (qmark == NULL || *qmark == '\0')
qmark = "> ";
compose_quote_fmt(compose, full_msginfo,
MSG_SET_PERM_FLAGS(((MsgInfo *)msginfo->data)->flags, MSG_FORWARDED);
}
- compose = compose_create(account, COMPOSE_FORWARD, FALSE);
+ compose = compose_create(account, ((MsgInfo *)msginfo_list->data)->folder, COMPOSE_FORWARD, FALSE);
compose->updating = TRUE;
}
g_return_val_if_fail(account != NULL, NULL);
- compose = compose_create(account, COMPOSE_REEDIT, batch);
+ compose = compose_create(account, msginfo->folder, COMPOSE_REEDIT, batch);
compose->replyinfo = replyinfo;
compose->fwdinfo = fwdinfo;
prefs_common.reply_account_autosel);
g_return_val_if_fail(account != NULL, NULL);
- compose = compose_create(account, COMPOSE_REDIRECT, batch);
+ compose = compose_create(account, msginfo->folder, COMPOSE_REDIRECT, batch);
compose->updating = TRUE;
}
static gboolean compose_force_window_origin = TRUE;
-static Compose *compose_create(PrefsAccount *account, ComposeMode mode,
+static Compose *compose_create(PrefsAccount *account,
+ FolderItem *folder,
+ ComposeMode mode,
gboolean batch)
{
Compose *compose;
compose->batch = batch;
compose->account = account;
+ compose->folder = folder;
compose->mutex = g_mutex_new();
compose->set_cursor_pos = -1;
}
}
+static const gchar *compose_quote_char_from_context(Compose *compose)
+{
+ const gchar *qmark = NULL;
+
+ g_return_val_if_fail(compose != NULL, NULL);
+
+ switch (compose->mode) {
+ /* use forward-specific quote char */
+ case COMPOSE_FORWARD:
+ case COMPOSE_FORWARD_AS_ATTACH:
+ case COMPOSE_FORWARD_INLINE:
+ if (compose->folder && compose->folder->prefs &&
+ compose->folder->prefs->forward_with_format)
+ qmark = compose->folder->prefs->forward_quotemark;
+ else if (compose->account->forward_with_format)
+ qmark = compose->account->forward_quotemark;
+ else
+ qmark = prefs_common.fw_quotemark;
+ break;
+
+ /* use reply-specific quote char in all other modes */
+ default:
+ if (compose->folder && compose->folder->prefs &&
+ compose->folder->prefs->reply_with_format)
+ qmark = compose->folder->prefs->reply_quotemark;
+ else if (compose->account->reply_with_format)
+ qmark = compose->account->reply_quotemark;
+ else
+ qmark = prefs_common.quotemark;
+ break;
+ }
+
+ if (qmark == NULL || *qmark == '\0')
+ qmark = "> ";
+
+ return qmark;
+}
+
static void compose_template_apply(Compose *compose, Template *tmpl,
gboolean replace)
{
GtkTextBuffer *buffer;
GtkTextMark *mark;
GtkTextIter iter;
- gchar *qmark;
+ const gchar *qmark;
gchar *parsed_str = NULL;
gint cursor_pos = 0;
const gchar *err_msg = _("Template body format error at line %d.");
buffer = gtk_text_view_get_buffer(text);
if (tmpl->value) {
- if (prefs_common.quotemark && *prefs_common.quotemark)
- qmark = prefs_common.quotemark;
- else
- qmark = "> ";
+ qmark = compose_quote_char_from_context(compose);
if (compose->replyinfo != NULL) {
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)
compose);
if (paste_as_quotation) {
gchar *new_text;
- gchar *qmark;
+ const gchar *qmark;
if (len < 0)
len = strlen(text);
new_text = g_strndup(text, len);
- if (prefs_common.quotemark && *prefs_common.quotemark)
- qmark = prefs_common.quotemark;
- else
- qmark = "> ";
+
+ qmark = compose_quote_char_from_context(compose);
mark = gtk_text_buffer_create_mark(buffer, NULL, iter, FALSE);
gtk_text_buffer_place_cursor(buffer, iter);