warn about privacy system 'none' and auto sign/encrypt being enabled in all applicabl...
[claws.git] / src / compose.c
index e6d94973a65e3dcd91bcf60618930c83773a708d..1df165aa9084ef46c29c9dc47d7517c4c5de8768 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2018 the Claws Mail team and Hiroyuki Yamamoto
+ * Copyright (C) 1999-2020 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
@@ -191,6 +191,13 @@ typedef enum {
 #define COMPOSE_DRAFT_TIMEOUT_UNSET -1
 #define COMPOSE_DRAFT_TIMEOUT_FORBIDDEN -2
 
+#define COMPOSE_PRIVACY_WARNING() {                                                    \
+       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."));                                                \
+}
+
 static GdkColor default_header_bgcolor = {
        (gulong)0,
        (gushort)0,
@@ -1012,10 +1019,7 @@ Compose *compose_generic_new(PrefsAccount *account, const gchar *mailto, FolderI
 
        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."));
+               COMPOSE_PRIVACY_WARNING();
 
        /* override from name if mailto asked for it */
        if (mailto_from) {
@@ -1692,11 +1696,10 @@ 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."));
+           ((account->default_encrypt || account->default_sign) ||
+            (account->default_encrypt_reply && MSG_IS_ENCRYPTED(compose->replyinfo->flags)) ||
+            (account->default_sign_reply && MSG_IS_SIGNED(compose->replyinfo->flags))))
+               COMPOSE_PRIVACY_WARNING();
 
        SIGNAL_BLOCK(textbuf);
        
@@ -1901,6 +1904,10 @@ Compose *compose_forward(PrefsAccount *account, MsgInfo *msginfo,
 #endif
        SIGNAL_UNBLOCK(textbuf);
        
+       if (privacy_system_can_sign(compose->privacy_system) == FALSE &&
+           (account->default_encrypt || account->default_sign))
+               COMPOSE_PRIVACY_WARNING();
+
        cursor_pos = quote_fmt_get_cursor_pos();
        if (cursor_pos == -1)
                gtk_widget_grab_focus(compose->header_last->entry);
@@ -1982,6 +1989,9 @@ static Compose *compose_forward_multiple(PrefsAccount *account, GSList *msginfo_
 
        compose = compose_create(account, ((MsgInfo *)msginfo_list->data)->folder, COMPOSE_FORWARD, FALSE);
        compose_apply_folder_privacy_settings(compose, ((MsgInfo *)msginfo_list->data)->folder);
+       if (privacy_system_can_sign(compose->privacy_system) == FALSE &&
+           (account->default_encrypt || account->default_sign))
+               COMPOSE_PRIVACY_WARNING();
 
        compose->updating = TRUE;
 
@@ -2392,6 +2402,9 @@ Compose *compose_reedit(MsgInfo *msginfo, gboolean batch)
                compose_activate_privacy_system(compose, account, FALSE);
        }
        compose_apply_folder_privacy_settings(compose, msginfo->folder);
+       if (privacy_system_can_sign(compose->privacy_system) == FALSE &&
+           (account->default_encrypt || account->default_sign))
+               COMPOSE_PRIVACY_WARNING();
 
        compose->targetinfo = procmsg_msginfo_copy(msginfo);
        compose->targetinfo->tags = g_slist_copy(msginfo->tags);
@@ -2519,7 +2532,6 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *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;
 
@@ -2597,6 +2609,10 @@ Compose *compose_redirect(PrefsAccount *account, MsgInfo *msginfo,
                gtk_widget_set_sensitive(compose->toolbar->linewrap_current_btn, FALSE);
        if (compose->toolbar->linewrap_all_btn)
                gtk_widget_set_sensitive(compose->toolbar->linewrap_all_btn, FALSE);
+       if (compose->toolbar->privacy_sign_btn)
+               gtk_widget_set_sensitive(compose->toolbar->privacy_sign_btn, FALSE);
+       if (compose->toolbar->privacy_encrypt_btn)
+               gtk_widget_set_sensitive(compose->toolbar->privacy_encrypt_btn, FALSE);
 
        compose->modified = FALSE;
        compose_set_title(compose);
@@ -2893,7 +2909,7 @@ static gint compose_parse_header(Compose *compose, MsgInfo *msginfo)
 
        cm_return_val_if_fail(msginfo != NULL, -1);
 
-       if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
+       if ((fp = procmsg_open_message(msginfo, FALSE)) == NULL) return -1;
        procheader_get_header_fields(fp, hentry);
        claws_fclose(fp);
 
@@ -3018,7 +3034,7 @@ static gint compose_parse_manual_headers(Compose *compose, MsgInfo *msginfo, Hea
 
        cm_return_val_if_fail(msginfo != NULL, -1);
 
-       if ((fp = procmsg_open_message(msginfo)) == NULL) return -1;
+       if ((fp = procmsg_open_message(msginfo, FALSE)) == NULL) return -1;
        procheader_get_header_fields(fp, entries);
        claws_fclose(fp);
 
@@ -4255,10 +4271,16 @@ static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
 
        for (; *p != '\0' && i < len; i++) {
                PangoLogAttr *attr = attrs + i;
-               gunichar wc;
+               gunichar wc = g_utf8_get_char(p);
                gint uri_len;
 
-               if (attr->is_line_break && can_break && was_white && !prev_dont_break)
+               /* attr->is_line_break will be false for some characters that
+                * we want to break a line before, like '/' or ':', so we
+                * also allow breaking on any non-wide character. The
+                * mentioned pango attribute is still useful to decide on
+                * line breaks when wide characters are involved. */
+               if ((!g_unichar_iswide(wc) || attr->is_line_break)
+                               && can_break && was_white && !prev_dont_break)
                        pos = i;
                
                was_white = attr->is_white;
@@ -4276,7 +4298,6 @@ static gboolean compose_get_line_break_pos(GtkTextBuffer *buffer,
                        continue;
                }
 
-               wc = g_utf8_get_char(p);
                if (g_unichar_iswide(wc)) {
                        col += 2;
                        if (prev_dont_break && can_break && attr->is_line_break)
@@ -4330,7 +4351,7 @@ static gboolean compose_join_next_line(Compose *compose,
        next_quote_str = compose_get_quote_str(buffer, &iter_, &quote_len);
 
        if ((quote_str || next_quote_str) &&
-           strcmp2(quote_str, next_quote_str) != 0) {
+           g_strcmp0(quote_str, next_quote_str) != 0) {
                g_free(next_quote_str);
                return FALSE;
        }
@@ -5268,6 +5289,9 @@ static void _display_queue_error(ComposeQueueResult val)
                        alertpanel_error(_("Could not queue message for sending:\n\n"
                                                "Couldn't get recipient encryption key."));
                        break;
+               case COMPOSE_QUEUE_SIGNING_CANCELLED:
+                       debug_print("signing cancelled\n");
+                       break;
                default:
                        /* unhandled error */
                        debug_print("oops, unhandled compose_queue() return value %d\n",
@@ -5906,7 +5930,10 @@ static gint compose_write_to_file(Compose *compose, FILE *fp, gint action, gbool
                        compose->account, from_addr)) {
                        g_free(from_name);
                        g_free(from_addr);
-                       return COMPOSE_QUEUE_ERROR_SIGNING_FAILED;
+                       if (!privacy_peek_error())
+                               return COMPOSE_QUEUE_SIGNING_CANCELLED;
+                       else
+                               return COMPOSE_QUEUE_ERROR_SIGNING_FAILED;
        }
        g_free(from_name);
        g_free(from_addr);
@@ -6452,7 +6479,7 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                }
                if (ainfo->name && mimepart->type != MIMETYPE_MESSAGE) {
                        if (mimepart->type == MIMETYPE_APPLICATION && 
-                          !strcmp2(mimepart->subtype, "octet-stream"))
+                          !g_strcmp0(mimepart->subtype, "octet-stream"))
                                g_hash_table_insert(mimepart->typeparameters,
                                                g_strdup("name"), g_strdup(ainfo->name));
                        g_hash_table_insert(mimepart->dispositionparameters,
@@ -6463,7 +6490,7 @@ static int compose_add_attachments(Compose *compose, MimeInfo *parent)
                if (mimepart->type == MIMETYPE_MESSAGE
                    || mimepart->type == MIMETYPE_MULTIPART)
                        ainfo->encoding = ENC_BINARY;
-               else if (compose->use_signing) {
+               else if (compose->use_signing || compose->fwdinfo != NULL) {
                        if (ainfo->encoding == ENC_7BIT)
                                ainfo->encoding = ENC_QUOTED_PRINTABLE;
                        else if (ainfo->encoding == ENC_8BIT)
@@ -7534,7 +7561,7 @@ static GtkWidget *compose_create_others(Compose *compose)
        g_signal_connect_after(G_OBJECT(savemsg_combo), "grab_focus",
                         G_CALLBACK(compose_grab_focus_cb), compose);
        if (account_get_special_folder(compose->account, F_OUTBOX)) {
-               if (compose->account->set_sent_folder)
+               if (compose->account->set_sent_folder || prefs_common.savemsg)
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), TRUE);
                else
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(savemsg_checkbtn), FALSE);
@@ -9448,6 +9475,7 @@ static void compose_attach_property_create(gboolean *cancelled)
        gtk_container_set_border_width(GTK_CONTAINER(window), 8);
        gtk_window_set_title(GTK_WINDOW(window), _("Properties"));
        gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
+       gtk_window_set_type_hint(GTK_WINDOW(window), GDK_WINDOW_TYPE_HINT_DIALOG);
        g_signal_connect(G_OBJECT(window), "delete_event",
                         G_CALLBACK(attach_property_delete_event),
                         cancelled);
@@ -9480,11 +9508,11 @@ static void compose_attach_property_create(gboolean *cancelled)
 
                tmp = g_strdup_printf("%s/%s", type->type, type->sub_type);
 
-               if (g_list_find_custom(strlist, tmp, (GCompareFunc)strcmp2))
+               if (g_list_find_custom(strlist, tmp, (GCompareFunc)g_strcmp0))
                        g_free(tmp);
                else
                        strlist = g_list_insert_sorted(strlist, (gpointer)tmp,
-                                       (GCompareFunc)strcmp2);
+                                       (GCompareFunc)g_strcmp0);
        }
 
        for (mime_type_list = strlist; mime_type_list != NULL; 
@@ -10144,7 +10172,7 @@ static void account_activated(GtkComboBox *optmenu, gpointer data)
                compose_set_save_to(compose, folderidentifier);
                g_free(folderidentifier);
        } else if (account_get_special_folder(compose->account, F_OUTBOX)) {
-               if (compose->account->set_sent_folder)
+               if (compose->account->set_sent_folder || prefs_common.savemsg)
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), TRUE);
                else
                        gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(compose->savemsg_checkbtn), FALSE);
@@ -10892,15 +10920,15 @@ static void entry_copy_clipboard(GtkWidget *entry)
 }
 
 static void entry_paste_clipboard(Compose *compose, GtkWidget *entry, 
-                                 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
+                                 gboolean wrap, GdkAtom clip, GtkTextIter *insert_place)
 {
-       if (GTK_IS_TEXT_VIEW(entry)) {
+       if (GTK_IS_TEXT_VIEW(entry)) {
                GtkTextBuffer *buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(entry));
                GtkTextMark *mark_start = gtk_text_buffer_get_insert(buffer);
                GtkTextIter start_iter, end_iter;
                gint start, end;
                gchar *contents = gtk_clipboard_wait_for_text(gtk_clipboard_get(clip));
-
                if (contents == NULL)
                        return;
        
@@ -10924,7 +10952,7 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
                        gtk_text_buffer_insert(buffer, insert_place, contents, strlen(contents));
                        if (prefs_common.primary_paste_unselects)
                                gtk_text_buffer_select_range(buffer, insert_place, insert_place);
-               }
+               }
                
                if (!wrap) {
                        /* paste unwrapped: mark the paste so it's not wrapped later */
@@ -10938,13 +10966,13 @@ static void entry_paste_clipboard(Compose *compose, GtkWidget *entry,
                        gtk_text_buffer_get_iter_at_mark(buffer, &start_iter, mark_start);
                        gtk_text_iter_backward_char(&start_iter);
                        compose_beautify_paragraph(compose, &start_iter, TRUE);
-               }
+               }
        } else if (GTK_IS_EDITABLE(entry))
                gtk_editable_paste_clipboard (GTK_EDITABLE(entry));
-
        compose->modified = TRUE;
 }
-
 static void entry_allsel(GtkWidget *entry)
 {
        if (GTK_IS_EDITABLE(entry))