if (system) {
g_free(compose->privacy_system);
compose->privacy_system = NULL;
+ g_free(compose->encdata);
+ compose->encdata = NULL;
}
if (compose->privacy_system == NULL)
compose->privacy_system = g_strdup(privacy);
else if (*(compose->privacy_system) == '\0') {
g_free(compose->privacy_system);
+ g_free(compose->encdata);
+ compose->encdata = NULL;
compose->privacy_system = g_strdup(privacy);
}
compose_update_privacy_system_menu_item(compose, FALSE);
if (system) {
g_free(compose->privacy_system);
compose->privacy_system = NULL;
+ g_free(compose->encdata);
+ compose->encdata = NULL;
}
if (compose->privacy_system == NULL)
compose->privacy_system = g_strdup(privacy);
{
GtkTextBuffer *buffer;
GtkTextIter start, end;
- gchar *chars;
- gchar *buf;
+ gchar *chars, *tmp_enc_file, *content;
+ gchar *buf, *msg;
const gchar *out_codeset;
EncodingType encoding = ENC_UNKNOWN;
MimeInfo *mimemsg, *mimetext;
const gchar *src_codeset = CS_INTERNAL;
gchar *from_addr = NULL;
gchar *from_name = NULL;
+ FolderItem *outbox;
if (action == COMPOSE_WRITE_FOR_SEND)
attach_parts = TRUE;
if (!buf) {
AlertValue aval;
- gchar *msg;
msg = g_strdup_printf(_("Can't convert the character encoding of the message \n"
"to the specified %s charset.\n"
encoding != ENC_QUOTED_PRINTABLE && encoding != ENC_BASE64 &&
check_line_length(buf, 1000, &line) < 0) {
AlertValue aval;
- gchar *msg;
msg = g_strdup_printf
(_("Line %d exceeds the line length limit (998 bytes).\n"
}
g_free(from_name);
g_free(from_addr);
+
+ if (compose->use_encryption) {
+ if (compose->encdata != NULL &&
+ strcmp(compose->encdata, "_DONT_ENCRYPT_")) {
+
+ /* First, write an unencrypted copy and save it to outbox, if
+ * user wants that. */
+ if (compose->account->save_encrypted_as_clear_text) {
+ debug_print("saving sent message unencrypted...\n");
+ FILE *tmpfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmp_enc_file);
+ if (tmpfp) {
+ 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);
+ g_free(content);
+
+ /* Now write the unencrypted body. */
+ tmpfp = g_fopen(tmp_enc_file, "a");
+ procmime_write_mimeinfo(mimemsg, tmpfp);
+ fclose(tmpfp);
+
+ outbox = folder_find_item_from_identifier(compose_get_save_to(compose));
+ if (!outbox)
+ outbox = folder_get_default_outbox();
+
+ procmsg_save_to_outbox(outbox, tmp_enc_file, TRUE);
+ claws_unlink(tmp_enc_file);
+ } else {
+ g_warning("couldn't get tempfile\n");
+ }
+ }
+ if (!privacy_encrypt(compose->privacy_system, mimemsg, compose->encdata)) {
+ debug_print("Couldn't encrypt mime structure: %s.\n",
+ privacy_get_error());
+ msg = g_strdup_printf("Couldn't encrypt the email: %s",
+ privacy_get_error());
+ alertpanel_error(msg);
+ g_free(msg);
+ }
+ }
+ }
+
procmime_write_mimeinfo(mimemsg, fp);
procmime_mimeinfo_free_all(mimemsg);
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, "wb")) == NULL) {
+ if ((fp = g_fopen(tmp, "w+b")) == NULL) {
FILE_OP_ERROR(tmp, "fopen");
g_free(tmp);
return -2;
err |= (fprintf(fp, "X-Claws-Privacy-System:%s\n", compose->privacy_system) < 0);
err |= (fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing) < 0);
if (compose->use_encryption) {
- gchar *encdata;
if (!compose_warn_encryption(compose)) {
fclose(fp);
claws_unlink(tmp);
if (mailac && mailac->encrypt_to_self) {
GSList *tmp_list = g_slist_copy(compose->to_list);
tmp_list = g_slist_append(tmp_list, compose->account->address);
- encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
+ compose->encdata = privacy_get_encrypt_data(compose->privacy_system, tmp_list);
g_slist_free(tmp_list);
} else {
- encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
+ compose->encdata = privacy_get_encrypt_data(compose->privacy_system, compose->to_list);
}
- if (encdata != NULL) {
- if (strcmp(encdata, "_DONT_ENCRYPT_")) {
+ if (compose->encdata != NULL) {
+ if (strcmp(compose->encdata, "_DONT_ENCRYPT_")) {
err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
err |= (fprintf(fp, "X-Claws-Encrypt-Data:%s\n",
- encdata) < 0);
+ compose->encdata) < 0);
} /* else we finally dont want to encrypt */
} else {
err |= (fprintf(fp, "X-Claws-Encrypt:%d\n", compose->use_encryption) < 0);
g_free(tmp);
return -5;
}
- g_free(encdata);
}
}
compose->use_signing = FALSE;
compose->use_encryption = FALSE;
compose->privacy_system = NULL;
+ compose->encdata = NULL;
compose->modified = FALSE;
systemid = g_object_get_data(G_OBJECT(widget), "privacy_system");
g_free(compose->privacy_system);
compose->privacy_system = NULL;
+ g_free(compose->encdata);
+ compose->encdata = NULL;
if (systemid != NULL) {
compose->privacy_system = g_strdup(systemid);
g_free(compose->orig_charset);
g_free(compose->privacy_system);
+ g_free(compose->encdata);
#ifndef USE_NEW_ADDRBOOK
if (addressbook_get_target_compose() == compose)
static void activate_privacy_system(Compose *compose, PrefsAccount *account, gboolean warn)
{
g_free(compose->privacy_system);
+ g_free(compose->encdata);
compose->privacy_system = g_strdup(account->default_privacy_system);
compose_update_privacy_system_menu_item(compose, warn);
return 0;
}
-static gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
+gint procmsg_save_to_outbox(FolderItem *outbox, const gchar *file,
gboolean is_queued)
{
gint num;
static gint procmsg_send_message_queue_full(const gchar *file, gboolean keep_session, gchar **errstr,
FolderItem *queue, gint msgnum, gboolean *queued_removed)
{
- static HeaderEntry qentry[] = {{"S:", NULL, FALSE},
+ static HeaderEntry qentry[] = {
+ {"S:", NULL, FALSE}, /* 0 */
{"SSV:", NULL, FALSE},
{"R:", NULL, FALSE},
{"NG:", NULL, FALSE},
{"MAID:", NULL, FALSE},
- {"NAID:", NULL, FALSE},
+ {"NAID:", NULL, FALSE}, /* 5 */
{"SCF:", NULL, FALSE},
{"RMID:", NULL, FALSE},
{"FMID:", NULL, FALSE},
{"X-Claws-Privacy-System:", NULL, FALSE},
- {"X-Claws-Encrypt:", NULL, FALSE},
+ {"X-Claws-Encrypt:", NULL, FALSE}, /* 10 */
{"X-Claws-Encrypt-Data:", NULL, FALSE},
{"X-Claws-End-Special-Headers:", NULL, FALSE},
{"X-Sylpheed-Privacy-System:", NULL, FALSE},
{"X-Sylpheed-Encrypt:", NULL, FALSE},
- {"X-Sylpheed-Encrypt-Data:", NULL, FALSE},
+ {"X-Sylpheed-Encrypt-Data:", NULL, FALSE}, /* 15 */
{"X-Sylpheed-End-Special-Headers:", NULL, FALSE},
{NULL, NULL, FALSE}};
FILE *fp;
gchar *savecopyfolder = NULL;
gchar *replymessageid = NULL;
gchar *fwdmessageid = NULL;
- gchar *privacy_system = NULL;
- gboolean encrypt = FALSE;
- gchar *encrypt_data = NULL;
gchar buf[BUFFSIZE];
gint hnum;
PrefsAccount *mailac = NULL, *newsac = NULL;
- gboolean save_clear_text = TRUE;
- gchar *tmp_enc_file = NULL;
+ gboolean encrypt = FALSE;
+ FolderItem *outbox;
cm_return_val_if_fail(file != NULL, -1);
if (fwdmessageid == NULL)
fwdmessageid = g_strdup(p);
break;
- case Q_PRIVACY_SYSTEM:
- case Q_PRIVACY_SYSTEM_OLD:
- if (privacy_system == NULL)
- privacy_system = g_strdup(p);
- break;
case Q_ENCRYPT:
case Q_ENCRYPT_OLD:
if (p[0] == '1')
encrypt = TRUE;
break;
- case Q_ENCRYPT_DATA:
- case Q_ENCRYPT_DATA_OLD:
- if (encrypt_data == NULL)
- encrypt_data = g_strdup(p);
- break;
case Q_CLAWS_HDRS:
case Q_CLAWS_HDRS_OLD:
/* end of special headers reached */
return -1;
}
- if (encrypt) {
- MimeInfo *mimeinfo;
-
- if (mailac && mailac->save_encrypted_as_clear_text
- && !mailac->encrypt_to_self)
- save_clear_text = TRUE;
- else
- save_clear_text = FALSE;
-
- fclose(fp);
- fp = NULL;
-
- mimeinfo = procmime_scan_queue_file(file);
- if (!privacy_encrypt(privacy_system, mimeinfo, encrypt_data)
- || (fp = my_tmpfile()) == NULL
- || procmime_write_mimeinfo(mimeinfo, fp) < 0) {
- if (fp)
- fclose(fp);
- procmime_mimeinfo_free_all(mimeinfo);
- g_free(from);
- g_free(smtpserver);
- slist_free_strings_full(to_list);
- slist_free_strings_full(newsgroup_list);
- g_free(savecopyfolder);
- g_free(replymessageid);
- g_free(fwdmessageid);
- g_free(privacy_system);
- g_free(encrypt_data);
- if (errstr) {
- if (*errstr) g_free(*errstr);
- *errstr = g_strdup_printf(_("Couldn't encrypt the email: %s"),
- privacy_get_error());
- }
- return -1;
- }
-
- rewind(fp);
- if (!save_clear_text) {
- gchar *content = NULL;
- FILE *tmpfp = get_tmpfile_in_dir(get_mime_tmp_dir(), &tmp_enc_file);
- if (tmpfp) {
- fclose(tmpfp);
-
- content = file_read_stream_to_str(fp);
- rewind(fp);
-
- str_write_to_file(content, tmp_enc_file);
- g_free(content);
- } else {
- g_warning("couldn't get tempfile\n");
- }
- }
-
- procmime_mimeinfo_free_all(mimeinfo);
-
- filepos = 0;
- }
-
if (to_list) {
debug_print("Sending message by mail\n");
if (!from) {
/* save message to outbox */
if (mailval == 0 && newsval == 0 && savecopyfolder) {
- FolderItem *outbox;
-
debug_print("saving sent message...\n");
- outbox = folder_find_item_from_identifier(savecopyfolder);
- if (!outbox)
- outbox = folder_get_default_outbox();
-
- if (save_clear_text || tmp_enc_file == NULL) {
+ if (!encrypt || !mailac->save_encrypted_as_clear_text) {
+ outbox = folder_find_item_from_identifier(savecopyfolder);
+ if (!outbox)
+ outbox = folder_get_default_outbox();
+
+ /* Mail was not saved to outbox before encrypting, save it now. */
gboolean saved = FALSE;
*queued_removed = FALSE;
if (queue && msgnum > 0) {
procmsg_msginfo_free(queued_mail);
}
if (!saved) {
- debug_print("resaving clear text queued mail to sent folder\n");
+ debug_print("resaving queued mail to sent folder\n");
procmsg_save_to_outbox(outbox, file, TRUE);
}
- } else {
- debug_print("saving encrpyted queued mail to sent folder\n");
- procmsg_save_to_outbox(outbox, tmp_enc_file, FALSE);
}
}
- if (tmp_enc_file != NULL) {
- claws_unlink(tmp_enc_file);
- free(tmp_enc_file);
- tmp_enc_file = NULL;
- }
-
if (replymessageid != NULL || fwdmessageid != NULL) {
gchar **tokens;
FolderItem *item;
g_free(savecopyfolder);
g_free(replymessageid);
g_free(fwdmessageid);
- g_free(privacy_system);
- g_free(encrypt_data);
return (newsval != 0 ? newsval : mailval);
}