remove wrongly pushed change in bfc95529975d50e8cda7a85b439aab23f2021c53
[claws.git] / src / compose.c
index bf3300773f5554e394ef9312e17dd3ccdde48212..090981e80b48bce6352a8f215e0a87e570bbaa02 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * 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
@@ -1010,6 +1010,13 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
        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) {
                gtk_entry_set_text(GTK_ENTRY(compose->from_name), mailto_from);
@@ -1273,7 +1280,8 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
        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))
@@ -1310,6 +1318,8 @@ static void compose_force_encryption(Compose *compose, PrefsAccount *account,
 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;
@@ -1679,6 +1689,13 @@ static Compose *compose_generic_reply(MsgInfo *msginfo,
        }
        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)
@@ -4951,16 +4968,18 @@ static void compose_select_account(Compose *compose, PrefsAccount *account,
 
        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);
-                                      
-       compose_activate_privacy_system(compose, account, FALSE);
 
        if (!init && compose->mode != COMPOSE_REDIRECT) {
                undo_block(compose->undostruct);
@@ -5904,7 +5923,7 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                                        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. */
@@ -8270,8 +8289,6 @@ static Compose *compose_create(PrefsAccount *account,
        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);
 
@@ -9160,6 +9177,7 @@ static void compose_destroy(Compose *compose)
        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);
@@ -11539,11 +11557,13 @@ static void compose_activate_privacy_system(Compose *compose, PrefsAccount *acco
 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) {
+               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) {
+               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);
                }
@@ -11674,7 +11694,7 @@ static void compose_insert_drag_received_cb (GtkWidget          *widget,
                        /* 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);