/*
* Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2016 Hiroyuki Yamamoto and the Claws Mail team
+ * Copyright (C) 1999-2018 the Claws Mail team and Hiroyuki Yamamoto
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
#include "autofaces.h"
#include "spell_entry.h"
#include "headers.h"
+#include "file-utils.h"
+
#ifdef USE_LDAP
#include "password.h"
#include "ldapserver.h"
static gint compose_remove_reedit_target (Compose *compose,
gboolean force);
static void compose_remove_draft (Compose *compose);
-static gint compose_queue_sub (Compose *compose,
+static ComposeQueueResult compose_queue_sub (Compose *compose,
gint *msgnum,
FolderItem **item,
gchar **msgpath,
gpointer data);
static void compose_set_privacy_system_cb(GtkWidget *widget, gpointer data);
static void compose_update_privacy_system_menu_item(Compose * compose, gboolean warn);
-static void activate_privacy_system (Compose *compose,
+static void compose_activate_privacy_system (Compose *compose,
PrefsAccount *account,
gboolean warn);
+static void compose_apply_folder_privacy_settings(Compose *compose, FolderItem *folder_item);
static void compose_toggle_return_receipt_cb(GtkToggleAction *action,
gpointer data);
static void compose_toggle_remove_refs_cb(GtkToggleAction *action,
cm_return_val_if_fail(account != NULL, NULL);
compose = compose_create(account, item, COMPOSE_NEW, FALSE);
+ compose_apply_folder_privacy_settings(compose, item);
+
+ if (privacy_system_can_sign(compose->privacy_system) == FALSE &&
+ (account->default_encrypt || account->default_sign))
+ alertpanel_error(_("You have opted to sign and/or encrypt this "
+ "message but have not selected a privacy system.\n\n"
+ "Signing and encrypting have been disabled for this "
+ "message."));
/* override from name if mailto asked for it */
if (mailto_from) {
cm_return_if_fail(compose != NULL);
cm_return_if_fail(account != NULL);
- if (override_pref == FALSE && account->default_encrypt_reply == FALSE)
+ if (privacy_system_can_encrypt(compose->privacy_system) == FALSE ||
+ (override_pref == FALSE && account->default_encrypt_reply == FALSE))
return;
if (account->default_privacy_system && strlen(account->default_privacy_system))
static void compose_force_signing(Compose *compose, PrefsAccount *account, const gchar *system)
{
const gchar *privacy = NULL;
+ if (privacy_system_can_sign(compose->privacy_system) == FALSE)
+ return;
if (account->default_privacy_system && strlen(account->default_privacy_system))
privacy = account->default_privacy_system;
cm_return_val_if_fail(account != NULL, NULL);
compose = compose_create(account, msginfo->folder, COMPOSE_REPLY, FALSE);
+ compose_apply_folder_privacy_settings(compose, msginfo->folder);
compose->updating = TRUE;
}
g_free(s_system);
+ if (privacy_system_can_sign(compose->privacy_system) == FALSE &&
+ (account->default_encrypt_reply || account->default_sign_reply))
+ alertpanel_error(_("You have opted to sign and/or encrypt this "
+ "message but have not selected a privacy system.\n\n"
+ "Signing and encrypting have been disabled for this "
+ "message."));
+
SIGNAL_BLOCK(textbuf);
if (account->auto_sig)
else
mode = COMPOSE_FORWARD;
compose = compose_create(account, msginfo->folder, mode, batch);
+ compose_apply_folder_privacy_settings(compose, msginfo->folder);
compose->updating = TRUE;
compose->fwdinfo = procmsg_msginfo_get_full_info(msginfo);
hooks_invoke(COMPOSE_CREATED_HOOKLIST, compose);
- return compose;
+ return compose;
}
#undef INSERT_FW_HEADER
}
compose = compose_create(account, ((MsgInfo *)msginfo_list->data)->folder, COMPOSE_FORWARD, FALSE);
+ compose_apply_folder_privacy_settings(compose, ((MsgInfo *)msginfo_list->data)->folder);
compose->updating = TRUE;
compose_use_encryption(compose, use_encryption);
compose_update_privacy_system_menu_item(compose, FALSE);
} else {
- activate_privacy_system(compose, account, FALSE);
+ compose_activate_privacy_system(compose, account, FALSE);
}
+ compose_apply_folder_privacy_settings(compose, msginfo->folder);
compose->targetinfo = procmsg_msginfo_copy(msginfo);
+ compose->targetinfo->tags = g_slist_copy(msginfo->tags);
compose_extract_original_charset(compose);
gboolean prev_autowrap;
GtkTextBuffer *buffer;
BLOCK_WRAP();
- while (fgets(buf, sizeof(buf), fp) != NULL) {
+ while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
strcrchomp(buf);
gtk_text_buffer_insert(textbuf, &iter, buf, -1);
}
UNBLOCK_WRAP();
- fclose(fp);
+ claws_fclose(fp);
}
compose_attach_parts(compose, msginfo);
cm_return_val_if_fail(account != NULL, NULL);
compose = compose_create(account, msginfo->folder, COMPOSE_REDIRECT, batch);
+ compose_apply_folder_privacy_settings(compose, msginfo->folder);
compose->updating = TRUE;
if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
procheader_get_header_fields(fp, hentry);
- fclose(fp);
+ claws_fclose(fp);
if (hentry[H_REPLY_TO].body != NULL) {
if (hentry[H_REPLY_TO].body[0] != '\0') {
if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
procheader_get_header_fields(fp, entries);
- fclose(fp);
+ claws_fclose(fp);
he = entries;
while (he != NULL && he->name != NULL) {
}
- if ((fp = g_fopen(file, "rb")) == NULL) {
- FILE_OP_ERROR(file, "fopen");
+ if ((fp = claws_fopen(file, "rb")) == NULL) {
+ FILE_OP_ERROR(file, "claws_fopen");
return COMPOSE_INSERT_READ_ERROR;
}
cur_encoding = conv_get_locale_charset_str_no_utf8();
file_contents = g_string_new("");
- while (fgets(buf, sizeof(buf), fp) != NULL) {
+ while (claws_fgets(buf, sizeof(buf), fp) != NULL) {
gchar *str;
if (g_utf8_validate(buf, -1, NULL) == TRUE)
}
g_string_free(file_contents, TRUE);
- fclose(fp);
+ claws_fclose(fp);
return result;
}
return FALSE;
}
}
- if ((fp = g_fopen(file, "rb")) == NULL) {
+ if ((fp = claws_fopen(file, "rb")) == NULL) {
alertpanel_error(_("Can't read %s."), filename);
return FALSE;
}
- fclose(fp);
+ claws_fclose(fp);
ainfo = g_new0(AttachInfo, 1);
auto_ainfo = g_auto_pointer_new_with_free
compose_set_title(compose);
- if (account->default_sign && compose->mode != COMPOSE_REDIRECT)
+ compose_activate_privacy_system(compose, account, FALSE);
+
+ if (account->default_sign && privacy_system_can_sign(compose->privacy_system) &&
+ compose->mode != COMPOSE_REDIRECT)
cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Sign", TRUE);
else
cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Sign", FALSE);
- if (account->default_encrypt && compose->mode != COMPOSE_REDIRECT)
+ if (account->default_encrypt && privacy_system_can_encrypt(compose->privacy_system) &&
+ compose->mode != COMPOSE_REDIRECT)
cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Encrypt", TRUE);
else
cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Options/Encrypt", FALSE);
-
- activate_privacy_system(compose, account, FALSE);
if (!init && compose->mode != COMPOSE_REDIRECT) {
undo_block(compose->undostruct);
if (*str == '\0' && check_everything == TRUE &&
compose->mode != COMPOSE_REDIRECT) {
AlertValue aval;
- gchar *button_label;
gchar *message;
- if (compose->sending)
- button_label = g_strconcat("+", _("_Send"), NULL);
- else
- button_label = g_strconcat("+", _("_Queue"), NULL);
message = g_strdup_printf(_("Subject is empty. %s"),
compose->sending?_("Send it anyway?"):
_("Queue it anyway?"));
aval = alertpanel_full(compose->sending?_("Send"):_("Send later"), message,
- GTK_STOCK_CANCEL, button_label, NULL, ALERTFOCUS_FIRST,
- TRUE, NULL, ALERT_QUESTION);
+ GTK_STOCK_CANCEL, compose->sending?_("_Send"):_("_Queue"), NULL,
+ ALERTFOCUS_FIRST, TRUE, NULL, ALERT_QUESTION);
g_free(message);
- g_free(button_label);
if (aval & G_ALERTDISABLE) {
aval &= ~G_ALERTDISABLE;
prefs_common.warn_empty_subj = FALSE;
}
if (cnt > prefs_common.warn_sending_many_recipients_num) {
AlertValue aval;
- gchar *button_label;
gchar *message;
- if (compose->sending)
- button_label = g_strconcat("+", _("_Send"), NULL);
- else
- button_label = g_strconcat("+", _("_Queue"), NULL);
message = g_strdup_printf(_("Sending to %d recipients. %s"), cnt,
compose->sending?_("Send it anyway?"):
_("Queue it anyway?"));
aval = alertpanel_full(compose->sending?_("Send"):_("Send later"), message,
- GTK_STOCK_CANCEL, button_label, NULL, ALERTFOCUS_FIRST,
- TRUE, NULL, ALERT_QUESTION);
+ GTK_STOCK_CANCEL, compose->sending?_("_Send"):_("_Queue"), NULL,
+ ALERTFOCUS_FIRST, TRUE, NULL, ALERT_QUESTION);
g_free(message);
if (aval & G_ALERTDISABLE) {
aval &= ~G_ALERTDISABLE;
return TRUE;
}
+static void _display_queue_error(ComposeQueueResult val)
+{
+ switch (val) {
+ case COMPOSE_QUEUE_SUCCESS:
+ break;
+ case COMPOSE_QUEUE_ERROR_NO_MSG:
+ alertpanel_error(_("Could not queue message."));
+ break;
+ case COMPOSE_QUEUE_ERROR_WITH_ERRNO:
+ alertpanel_error(_("Could not queue message:\n\n%s."),
+ g_strerror(errno));
+ break;
+ case COMPOSE_QUEUE_ERROR_SIGNING_FAILED:
+ alertpanel_error(_("Could not queue message for sending:\n\n"
+ "Signature failed: %s"),
+ privacy_peek_error() ? privacy_get_error() : _("Unknown error"));
+ break;
+ case COMPOSE_QUEUE_ERROR_ENCRYPT_FAILED:
+ alertpanel_error(_("Could not queue message for sending:\n\n"
+ "Encryption failed: %s"),
+ privacy_peek_error() ? privacy_get_error() : _("Unknown error"));
+ break;
+ case COMPOSE_QUEUE_ERROR_CHAR_CONVERSION:
+ alertpanel_error(_("Could not queue message for sending:\n\n"
+ "Charset conversion failed."));
+ break;
+ case COMPOSE_QUEUE_ERROR_NO_ENCRYPTION_KEY:
+ alertpanel_error(_("Could not queue message for sending:\n\n"
+ "Couldn't get recipient encryption key."));
+ break;
+ default:
+ /* unhandled error */
+ debug_print("oops, unhandled compose_queue() return value %d\n",
+ val);
+ break;
+ }
+}
+
gint compose_send(Compose *compose)
{
gint msgnum;
FolderItem *folder = NULL;
- gint val = -1;
+ ComposeQueueResult val = COMPOSE_QUEUE_ERROR_NO_MSG;
gchar *msgpath = NULL;
gboolean discard_window = FALSE;
gchar *errstr = NULL;
inc_lock();
val = compose_queue(compose, &msgnum, &folder, &msgpath, TRUE);
- if (val) {
+ if (val != COMPOSE_QUEUE_SUCCESS) {
if (compose->batch) {
gtk_widget_show_all(compose->window);
}
- if (val == -4) {
- alertpanel_error(_("Could not queue message for sending:\n\n"
- "Charset conversion failed."));
- } else if (val == -5) {
- alertpanel_error(_("Could not queue message for sending:\n\n"
- "Couldn't get recipient encryption key."));
- } else if (val == -6) {
- /* silent error */
- } else if (val == -3) {
- if (privacy_peek_error())
- alertpanel_error(_("Could not queue message for sending:\n\n"
- "Signature failed: %s"), privacy_get_error());
- } else if (val == -2 && errno != 0) {
- alertpanel_error(_("Could not queue message for sending:\n\n%s."), g_strerror(errno));
- } else {
- alertpanel_error(_("Could not queue message for sending."));
- }
+
+ _display_queue_error(val);
+
goto bail;
}
return -1;
/* separator between header and body */
- err |= (fputs("\n", fp) == EOF);
+ err |= (claws_fputs("\n", fp) == EOF);
return (err ? -1:0);
}
};
gint ret = 0;
- if ((fp = g_fopen(compose->redirect_filename, "rb")) == NULL) {
- FILE_OP_ERROR(compose->redirect_filename, "fopen");
+ if ((fp = claws_fopen(compose->redirect_filename, "rb")) == NULL) {
+ FILE_OP_ERROR(compose->redirect_filename, "claws_fopen");
return -1;
}
buf = NULL;
continue;
}
- if (fputs(buf, fdest) == -1) {
+ if (claws_fputs(buf, fdest) == -1) {
g_free(buf);
buf = NULL;
goto error;
if (!prefs_common.redirect_keep_from) {
if (g_ascii_strncasecmp(buf, "From:",
strlen("From:")) == 0) {
- err |= (fputs(" (by way of ", fdest) == EOF);
+ err |= (claws_fputs(" (by way of ", fdest) == EOF);
if (compose->account->name
&& *compose->account->name) {
gchar buffer[BUFFSIZE];
} else
err |= (fprintf(fdest, "%s",
compose->account->address) < 0);
- err |= (fputs(")", fdest) == EOF);
+ err |= (claws_fputs(")", fdest) == EOF);
}
}
g_free(buf);
buf = NULL;
- if (fputs("\n", fdest) == -1)
+ if (claws_fputs("\n", fdest) == -1)
goto error;
}
if (compose_redirect_write_headers(compose, fdest))
goto error;
- while ((len = fread(rewrite_buf, sizeof(gchar), sizeof(rewrite_buf), fp)) > 0) {
- if (fwrite(rewrite_buf, sizeof(gchar), len, fdest) != len)
+ while ((len = claws_fread(rewrite_buf, sizeof(gchar), sizeof(rewrite_buf), fp)) > 0) {
+ if (claws_fwrite(rewrite_buf, sizeof(gchar), len, fdest) != len)
goto error;
}
- fclose(fp);
+ claws_fclose(fp);
return 0;
error:
- fclose(fp);
+ claws_fclose(fp);
return -1;
}
if (aval != G_ALERTALTERNATE) {
g_free(chars);
- return -3;
+ return COMPOSE_QUEUE_ERROR_CHAR_CONVERSION;
} else {
buf = chars;
out_codeset = src_codeset;
g_free(msg);
if (aval != G_ALERTALTERNATE) {
g_free(buf);
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
}
g_node_append(mimemsg->node, mimempart->node);
if (compose_add_attachments(compose, mimempart) < 0)
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
} else
g_node_append(mimemsg->node, mimetext->node);
compose->account, from_addr)) {
g_free(from_name);
g_free(from_addr);
- return -2;
+ return COMPOSE_QUEUE_ERROR_SIGNING_FAILED;
}
g_free(from_name);
g_free(from_addr);
debug_print("saving sent message unencrypted...\n");
FILE *tmpfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmp_enc_file);
if (tmpfp) {
- fclose(tmpfp);
+ claws_fclose(tmpfp);
/* fp now points to a file with headers written,
* let's make a copy. */
rewind(fp);
content = file_read_stream_to_str(fp);
- str_write_to_file(content, tmp_enc_file);
+ str_write_to_file(content, tmp_enc_file, TRUE);
g_free(content);
/* Now write the unencrypted body. */
- if ((tmpfp = g_fopen(tmp_enc_file, "a")) != NULL) {
+ if ((tmpfp = claws_fopen(tmp_enc_file, "a")) != NULL) {
procmime_write_mimeinfo(mimemsg, tmpfp);
- fclose(tmpfp);
+ claws_fclose(tmpfp);
outbox = folder_find_item_from_identifier(compose_get_save_to(compose));
if (!outbox)
if (!privacy_encrypt(compose->privacy_system, mimemsg, compose->encdata)) {
debug_print("Couldn't encrypt mime structure: %s.\n",
privacy_get_error());
- alertpanel_error(_("Couldn't encrypt the email: %s"),
- privacy_get_error());
+ return COMPOSE_QUEUE_ERROR_ENCRYPT_FAILED;
}
}
}
size_t len;
gchar *chars, *tmp;
- if ((fp = g_fopen(file, "wb")) == NULL) {
- FILE_OP_ERROR(file, "fopen");
+ if ((fp = claws_fopen(file, "wb")) == NULL) {
+ FILE_OP_ERROR(file, "claws_fopen");
return -1;
}
g_free(tmp);
if (!chars) {
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(file);
return -1;
}
/* write body */
len = strlen(chars);
- if (fwrite(chars, sizeof(gchar), len, fp) != len) {
- FILE_OP_ERROR(file, "fwrite");
+ if (claws_fwrite(chars, sizeof(gchar), len, fp) != len) {
+ FILE_OP_ERROR(file, "claws_fwrite");
g_free(chars);
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(file);
return -1;
}
g_free(chars);
- if (fclose(fp) == EOF) {
- FILE_OP_ERROR(file, "fclose");
+ if (claws_safe_fclose(fp) == EOF) {
+ FILE_OP_ERROR(file, "claws_fclose");
claws_unlink(file);
return -1;
}
}
-gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
+ComposeQueueResult compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **msgpath,
gboolean remove_reedit_target)
{
return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
}
}
-static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
+static ComposeQueueResult compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
gchar **msgpath, gboolean perform_checks,
gboolean remove_reedit_target)
{
if (compose->batch) {
gtk_widget_show_all(compose->window);
}
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
if (!compose->to_list && !compose->newsgroup_list) {
g_warning("can't get recipient list.");
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
if (compose->to_list) {
mailac = cur_account;
else if (!(mailac = compose_current_mail_account())) {
alertpanel_error(_("No account for sending mails available!"));
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
}
newsac = compose->account;
else {
alertpanel_error(_("Selected account isn't NNTP: Posting is impossible."));
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
}
tmp = g_strdup_printf("%s%cqueue.%p%08x", get_tmp_dir(),
G_DIR_SEPARATOR, compose, (guint) rand());
debug_print("queuing to %s\n", tmp);
- if ((fp = g_fopen(tmp, "w+b")) == NULL) {
- FILE_OP_ERROR(tmp, "fopen");
+ if ((fp = claws_fopen(tmp, "w+b")) == NULL) {
+ FILE_OP_ERROR(tmp, "claws_fopen");
g_free(tmp);
- return -2;
+ return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
}
if (change_file_mode_rw(fp, tmp) < 0) {
else
err |= (fprintf(fp, "NSV:\n") < 0);
err |= (fprintf(fp, "SSH:\n") < 0);
- /* write recepient list */
+ /* write recipient list */
if (compose->to_list) {
err |= (fprintf(fp, "R:<%s>", (gchar *)compose->to_list->data) < 0);
for (cur = compose->to_list->next; cur != NULL;
err |= (fprintf(fp, ",%s", (gchar *)cur->data) < 0);
err |= (fprintf(fp, "\n") < 0);
}
- /* Sylpheed account IDs */
+ /* account IDs */
if (mailac)
err |= (fprintf(fp, "MAID:%d\n", mailac->account_id) < 0);
if (newsac)
err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
if (compose->use_encryption) {
if (!compose_warn_encryption(compose)) {
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(tmp);
g_free(tmp);
- return -6;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
if (mailac && mailac->encrypt_to_self) {
GSList *tmp_list = g_slist_copy(compose->to_list);
* key selection */
if (err == TRUE)
g_warning("failed to write queue message");
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(tmp);
g_free(tmp);
- return -5;
+ return COMPOSE_QUEUE_ERROR_NO_ENCRYPTION_KEY;
}
}
}
if (compose->redirect_filename != NULL) {
if (compose_redirect_write_to_file(compose, fp) < 0) {
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(tmp);
g_free(tmp);
- return -2;
+ return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
}
} else {
gint result = 0;
if ((result = compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_SEND, TRUE)) < 0) {
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(tmp);
g_free(tmp);
- return result - 1; /* -2 for a generic error, -3 for signing error, -4 for encoding */
+ return result;
}
}
if (err == TRUE) {
g_warning("failed to write queue message");
- fclose(fp);
+ claws_fclose(fp);
claws_unlink(tmp);
g_free(tmp);
- return -2;
+ return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
}
- if (fclose(fp) == EOF) {
- FILE_OP_ERROR(tmp, "fclose");
+ if (claws_safe_fclose(fp) == EOF) {
+ FILE_OP_ERROR(tmp, "claws_fclose");
claws_unlink(tmp);
g_free(tmp);
- return -2;
+ return COMPOSE_QUEUE_ERROR_WITH_ERRNO;
}
if (item && *item) {
g_warning("can't find queue folder");
claws_unlink(tmp);
g_free(tmp);
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
folder_item_scan(queue);
if ((num = folder_item_add_msg(queue, tmp, NULL, FALSE)) < 0) {
g_warning("can't queue the message");
claws_unlink(tmp);
g_free(tmp);
- return -1;
+ return COMPOSE_QUEUE_ERROR_NO_MSG;
}
if (msgpath == NULL) {
} else
*msgpath = tmp;
+ if (compose->mode == COMPOSE_REEDIT && compose->targetinfo) {
+ MsgInfo *mi = folder_item_get_msginfo(queue, num);
+ if (mi) {
+ procmsg_msginfo_change_flags(mi,
+ compose->targetinfo->flags.perm_flags,
+ compose->targetinfo->flags.tmp_flags & ~(MSG_COPY | MSG_MOVE | MSG_MOVE_DONE),
+ 0, 0);
+
+ g_slist_free(mi->tags);
+ mi->tags = g_slist_copy(compose->targetinfo->tags);
+ procmsg_msginfo_free(&mi);
+ }
+ }
+
if (compose->mode == COMPOSE_REEDIT && remove_reedit_target) {
compose_remove_reedit_target(compose, FALSE);
}
*item = queue;
}
- return 0;
+ return COMPOSE_QUEUE_SUCCESS;
}
static int compose_add_attachments(Compose *compose, MimeInfo *parent)
if (extra_headers == NULL) {
exhrc = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, "extraheaderrc", NULL);
- if ((exh = g_fopen(exhrc, "rb")) == NULL) {
+ if ((exh = claws_fopen(exhrc, "rb")) == NULL) {
debug_print("extra headers file not found\n");
goto extra_headers_done;
}
- while (fgets(buf, BUFFSIZE, exh) != NULL) {
+ while (claws_fgets(buf, BUFFSIZE, exh) != NULL) {
lastc = strlen(buf) - 1; /* remove trailing control chars */
while (lastc >= 0 && buf[lastc] != ':')
buf[lastc--] = '\0';
g_message("invalid extra header line: %s\n", buf);
}
}
- fclose(exh);
+ claws_fclose(exh);
extra_headers_done:
g_free(exhrc);
extra_headers = g_slist_prepend(extra_headers, g_strdup("")); /* end of list */
claws_spell_entry_set_gtkaspell(CLAWS_SPELL_ENTRY(subject_entry), gtkaspell);
#endif
- compose_select_account(compose, account, TRUE);
-
cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoWrap", prefs_common.autowrap);
cm_toggle_menu_set_active_full(compose->ui_manager, "Menu/Edit/AutoIndent", prefs_common.auto_indent);
/* Privacy Systems menu */
compose_update_privacy_systems_menu(compose);
+ compose_activate_privacy_system(compose, account, TRUE);
- activate_privacy_system(compose, account, TRUE);
toolbar_set_style(compose->toolbar->toolbar, compose->handlebox, prefs_common.toolbar_style);
if (batch) {
gtk_widget_realize(window);
/* process the other fields */
- compose_template_apply_fields(compose, tmpl);
compose_attach_from_list(compose, quote_fmt_get_attachments_list(), FALSE);
+ compose_template_apply_fields(compose, tmpl);
quote_fmt_reset_vartable();
quote_fmtlex_destroy();
clipboard = gtk_clipboard_get(GDK_SELECTION_PRIMARY);
gtk_text_buffer_remove_selection_clipboard(buffer, clipboard);
+ message_search_close(compose);
gtk_widget_destroy(compose->window);
toolbar_destroy(compose->toolbar);
g_free(compose->toolbar);
selection = gtk_tree_view_get_selection(tree_view);
sel = gtk_tree_selection_get_selected_rows(selection, &model);
-
- if (!sel)
- return;
+ cm_return_if_fail(sel);
for (cur = sel; cur != NULL; cur = cur->next) {
GtkTreePath *path = cur->data;
return;
sel = gtk_tree_selection_get_selected_rows(selection, &model);
- if (!sel)
- return;
+ cm_return_if_fail(sel);
path = (GtkTreePath *) sel->data;
gtk_tree_model_get_iter(model, &iter, path);
static void compose_send_later_cb(GtkAction *action, gpointer data)
{
Compose *compose = (Compose *)data;
- gint val;
+ ComposeQueueResult val;
inc_lock();
compose_allow_user_actions(compose, FALSE);
compose_allow_user_actions(compose, TRUE);
inc_unlock();
- if (!val) {
+ if (val == COMPOSE_QUEUE_SUCCESS) {
compose_close(compose);
- } else if (val == -1) {
- alertpanel_error(_("Could not queue message."));
- } else if (val == -2) {
- alertpanel_error(_("Could not queue message:\n\n%s."), g_strerror(errno));
- } else if (val == -3) {
- if (privacy_peek_error())
- alertpanel_error(_("Could not queue message for sending:\n\n"
- "Signature failed: %s"), privacy_get_error());
- } else if (val == -4) {
- alertpanel_error(_("Could not queue message for sending:\n\n"
- "Charset conversion failed."));
- } else if (val == -5) {
- alertpanel_error(_("Could not queue message for sending:\n\n"
- "Couldn't get recipient encryption key."));
- } else if (val == -6) {
- /* silent error */
+ } else {
+ _display_queue_error(val);
}
+
toolbar_main_set_sensitive(mainwindow_get_mainwindow());
}
{
gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
DRAFTED_AT_EXIT, NULL);
- FILE *fp = g_fopen(filepath, "ab");
+ FILE *fp = claws_fopen(filepath, "ab");
if (fp) {
fprintf(fp, "%s\t%d\n", folder_item_get_identifier(info->folder),
info->msgnum);
- fclose(fp);
+ claws_fclose(fp);
}
g_free(filepath);
tmp = g_strdup_printf("%s%cdraft.%p", get_tmp_dir(),
G_DIR_SEPARATOR, compose);
- if ((fp = g_fopen(tmp, "wb")) == NULL) {
- FILE_OP_ERROR(tmp, "fopen");
+ if ((fp = claws_fopen(tmp, "wb")) == NULL) {
+ FILE_OP_ERROR(tmp, "claws_fopen");
goto warn_err;
}
err |= (fprintf(fp, "X-Claws-End-Special-Headers: 1\n") < 0);
if (err) {
- fclose(fp);
+ claws_fclose(fp);
goto warn_err;
}
if (compose_write_to_file(compose, fp, COMPOSE_WRITE_FOR_STORE, action != COMPOSE_AUTO_SAVE) < 0) {
- fclose(fp);
+ claws_fclose(fp);
goto warn_err;
}
- if (fclose(fp) == EOF) {
+ if (claws_safe_fclose(fp) == EOF) {
goto warn_err;
}
mtime = tv.tv_sec;
g_object_unref(fi);
g_object_unref(f);
- g_free(path);
#else
if (g_stat(path, &s) < 0) {
FILE_OP_ERROR(path, "stat");
{
gchar *filepath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
DRAFTED_AT_EXIT, NULL);
- FILE *fp = g_fopen(filepath, "rb");
+ FILE *fp = claws_fopen(filepath, "rb");
gchar buf[1024];
if (fp) {
- while (fgets(buf, sizeof(buf), fp)) {
+ while (claws_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;
}
g_strfreev(parts);
}
- fclose(fp);
+ claws_fclose(fp);
}
g_free(filepath);
compose_clear_exit_drafts();
debug_print("couldn't lock mutex, probably sending\n");
return;
}
- if (!reedit) {
+ if (!reedit || compose->folder->stype == F_DRAFT) {
val = alertpanel(_("Discard message"),
_("This message has been modified. Discard it?"),
_("_Discard"), _("_Save to Drafts"), GTK_STOCK_CANCEL,
gint prev_autowrap;
GtkTextBuffer *buffer;
BLOCK_WRAP();
- if (compose->focused_editable &&
+ if (compose->focused_editable
#ifndef GENERIC_UMPC
- gtk_widget_has_focus(compose->focused_editable)
+ && gtk_widget_has_focus(compose->focused_editable)
#endif
)
entry_paste_clipboard(compose, compose->focused_editable,
gtk_toggle_tool_button_set_active(GTK_TOGGLE_TOOL_BUTTON(compose->toolbar->privacy_encrypt_btn), compose->use_encryption);
}
-static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
+static void compose_activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
{
g_free(compose->privacy_system);
g_free(compose->encdata);
compose_update_privacy_system_menu_item(compose, warn);
}
+static void compose_apply_folder_privacy_settings(Compose *compose, FolderItem *folder_item)
+{
+ if (folder_item != NULL) {
+ if (folder_item->prefs->always_sign != SIGN_OR_ENCRYPT_DEFAULT &&
+ privacy_system_can_sign(compose->privacy_system)) {
+ compose_use_signing(compose,
+ (folder_item->prefs->always_sign == SIGN_OR_ENCRYPT_ALWAYS) ? TRUE : FALSE);
+ }
+ if (folder_item->prefs->always_encrypt != SIGN_OR_ENCRYPT_DEFAULT &&
+ privacy_system_can_encrypt(compose->privacy_system)) {
+ compose_use_encryption(compose,
+ (folder_item->prefs->always_encrypt == SIGN_OR_ENCRYPT_ALWAYS) ? TRUE : FALSE);
+ }
+ }
+}
+
static void compose_toggle_ruler_cb(GtkToggleAction *action, gpointer data)
{
Compose *compose = (Compose *)data;
utf8_filename, NULL, NULL);
g_free(utf8_filename);
}
- if (list) compose_changed_cb(NULL, compose);
- list_free_strings(list);
- g_list_free(list);
- } else if (gtk_drag_get_source_widget(context)
+ if (list)
+ compose_changed_cb(NULL, compose);
+ list_free_strings_full(list);
+ } else if (gtk_drag_get_source_widget(context)
== summary_get_main_widget(mainwindow_get_mainwindow()->summaryview)) {
/* comes from our summaryview */
SummaryView * summaryview = NULL;
/* Assume a list of no files, and data has ://, is a remote link */
gchar *tmpdata = g_strstrip(g_strdup(ddata));
gchar *tmpfile = get_tmp_file();
- str_write_to_file(tmpdata, tmpfile);
+ str_write_to_file(tmpdata, tmpfile, TRUE);
g_free(tmpdata);
compose_insert_file(compose, tmpfile);
claws_unlink(tmpfile);
if (val == G_ALERTDEFAULT || val == G_ALERTCANCEL) {
gtk_drag_finish(drag_context, FALSE, FALSE, time);
- list_free_strings(list);
- g_list_free(list);
+ list_free_strings_full(list);
return;
} else if (val == G_ALERTOTHER) {
compose_attach_drag_received_cb(widget, drag_context, x, y, data, info, time, user_data);
- list_free_strings(list);
- g_list_free(list);
+ list_free_strings_full(list);
return;
}
for (tmp = list; tmp != NULL; tmp = tmp->next) {
compose_insert_file(compose, (const gchar *)tmp->data);
}
- list_free_strings(list);
- g_list_free(list);
+ list_free_strings_full(list);
gtk_drag_finish(drag_context, TRUE, FALSE, time);
return;
}
Compose *compose = NULL;
gchar *s_system = NULL;
- cm_return_if_fail(msgview != NULL);
-
cm_return_if_fail(msginfo_list != NULL);
- if (g_slist_length(msginfo_list) == 1 && !opening_multiple) {
+ if (g_slist_length(msginfo_list) == 1 && !opening_multiple && msgview != NULL) {
MimeInfo *mimeinfo = messageview_get_selected_mime_part(msgview);
MsgInfo *orig_msginfo = (MsgInfo *)msginfo_list->data;
}
}
- if (!opening_multiple)
+ if (!opening_multiple && msgview != NULL)
body = messageview_get_selection(msgview);
if (new_msglist) {
guint action)
{
if ((!prefs_common.forward_as_attachment || action != COMPOSE_FORWARD)
+ && msginfo_list != NULL
&& action != COMPOSE_FORWARD_AS_ATTACH && g_slist_length(msginfo_list) > 1) {
GSList *cur = msginfo_list;
gchar *msg = g_strdup_printf(_("You are about to reply to %d "
} else {
/* forwarding multiple mails as attachments is done via a
* single compose window */
- compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
+ if (msginfo_list != NULL) {
+ compose_reply_from_messageview_real(msgview, msginfo_list, action, FALSE);
+ } else if (msgview != NULL) {
+ GSList tmplist;
+ tmplist.data = msgview->msginfo;
+ tmplist.next = NULL;
+ compose_reply_from_messageview_real(msgview, &tmplist, action, FALSE);
+ } else {
+ debug_print("Nothing to reply to\n");
+ }
}
}