2007-05-04 [colin] 2.9.1cvs43
authorColin Leroy <colin@colino.net>
Fri, 4 May 2007 17:16:35 +0000 (17:16 +0000)
committerColin Leroy <colin@colino.net>
Fri, 4 May 2007 17:16:35 +0000 (17:16 +0000)
* src/compose.c
* src/privacy.c
* src/privacy.h
* src/plugins/pgpcore/prefs_gpg.c
* src/plugins/pgpcore/prefs_gpg.h
* src/plugins/pgpinline/pgpinline.c
* src/plugins/pgpmime/pgpmime.c
Add an API to warn about encryption limits,
and allow to disable these warnings

ChangeLog
PATCHSETS
configure.ac
src/compose.c
src/plugins/pgpcore/prefs_gpg.c
src/plugins/pgpcore/prefs_gpg.h
src/plugins/pgpinline/pgpinline.c
src/plugins/pgpmime/pgpmime.c
src/privacy.c
src/privacy.h

index b1ead22b7e572fbab6e90c71de53ae8269621d20..44007c44ff3f351c0378f88d83da4904eee3715a 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+2007-05-04 [colin]     2.9.1cvs43
+
+       * src/compose.c
+       * src/privacy.c
+       * src/privacy.h
+       * src/plugins/pgpcore/prefs_gpg.c
+       * src/plugins/pgpcore/prefs_gpg.h
+       * src/plugins/pgpinline/pgpinline.c
+       * src/plugins/pgpmime/pgpmime.c
+               Add an API to warn about encryption limits,
+               and allow to disable these warnings
+
 2007-05-03 [colin]     2.9.1cvs42
 
        * src/summaryview.c
index 69b5123c4e27ea8bb796f937f6781c3832a037d2..450b66af350536e3d349cd9f45fbb53c75c0d0c3 100644 (file)
--- a/PATCHSETS
+++ b/PATCHSETS
 ( cvs diff -u -r 1.18.2.51 -r 1.18.2.52 src/plugins/spamassassin/spamassassin.c;  cvs diff -u -r 1.4.2.14 -r 1.4.2.15 src/plugins/spamassassin/spamassassin.h;  cvs diff -u -r 1.23.2.37 -r 1.23.2.38 src/plugins/spamassassin/spamassassin_gtk.c;  cvs diff -u -r 1.1.2.29 -r 1.1.2.30 src/plugins/bogofilter/bogofilter.c;  cvs diff -u -r 1.1.2.11 -r 1.1.2.12 src/plugins/bogofilter/bogofilter.h;  cvs diff -u -r 1.1.2.23 -r 1.1.2.24 src/plugins/bogofilter/bogofilter_gtk.c;  ) > 2.9.1cvs40.patchset
 ( cvs diff -u -r 1.204.2.132 -r 1.204.2.133 src/prefs_common.c;  cvs diff -u -r 1.59.2.55 -r 1.59.2.56 src/prefs_filtering.c;  cvs diff -u -r 1.12.2.40 -r 1.12.2.41 src/prefs_template.c;  cvs diff -u -r 1.2.4.18 -r 1.2.4.19 src/common/template.c;  cvs diff -u -r 1.1.4.4 -r 1.1.4.5 src/common/template.h;  cvs diff -u -r 1.5.2.57 -r 1.5.2.58 src/gtk/gtkutils.c;  cvs diff -u -r 1.4.2.34 -r 1.4.2.35 src/gtk/gtkutils.h;  ) > 2.9.1cvs41.patchset
 ( cvs diff -u -r 1.395.2.299 -r 1.395.2.300 src/summaryview.c;  cvs diff -u -r 1.274.2.188 -r 1.274.2.189 src/mainwindow.c;  ) > 2.9.1cvs42.patchset
+( cvs diff -u -r 1.382.2.375 -r 1.382.2.376 src/compose.c;  cvs diff -u -r 1.10.2.13 -r 1.10.2.14 src/privacy.c;  cvs diff -u -r 1.10.2.11 -r 1.10.2.12 src/privacy.h;  cvs diff -u -r 1.1.2.22 -r 1.1.2.23 src/plugins/pgpcore/prefs_gpg.c;  cvs diff -u -r 1.1.2.9 -r 1.1.2.10 src/plugins/pgpcore/prefs_gpg.h;  cvs diff -u -r 1.1.2.33 -r 1.1.2.34 src/plugins/pgpinline/pgpinline.c;  cvs diff -u -r 1.1.2.47 -r 1.1.2.48 src/plugins/pgpmime/pgpmime.c;  ) > 2.9.1cvs43.patchset
index b45d8afb2aae6183b2f363aeea8954924e4f74e2..fcc676ecae3f184f0b1ac34a8dd1733d774dd1c6 100644 (file)
@@ -11,7 +11,7 @@ MINOR_VERSION=9
 MICRO_VERSION=1
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=42
+EXTRA_VERSION=43
 EXTRA_RELEASE=
 EXTRA_GTK2_VERSION=
 
index 7ebe66e7f7cd04240733ec078659ab28cc538846..3a0d58a27a0481001d41746fe697bef7b20c9aa6 100644 (file)
@@ -4343,6 +4343,8 @@ gint compose_send(Compose *compose)
                } 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"
@@ -4975,6 +4977,32 @@ gint compose_queue(Compose *compose, gint *msgnum, FolderItem **item, gchar **ms
 {
        return compose_queue_sub (compose, msgnum, item, msgpath, FALSE, remove_reedit_target);
 }
+
+static gboolean compose_warn_encryption(Compose *compose)
+{
+       const gchar *warning = privacy_get_encrypt_warning(compose->privacy_system);
+       AlertValue val = G_ALERTALTERNATE;
+       
+       if (warning == NULL)
+               return TRUE;
+
+       val = alertpanel_full(_("Encryption warning"), warning,
+                 GTK_STOCK_CANCEL, _("+C_ontinue"), NULL,
+                 TRUE, NULL, ALERT_WARNING, G_ALERTALTERNATE);
+       if (val & G_ALERTDISABLE) {
+               val &= ~G_ALERTDISABLE;
+               if (val == G_ALERTALTERNATE)
+                       privacy_inhibit_encrypt_warning(compose->privacy_system,
+                               TRUE);
+       }
+
+       if (val == G_ALERTALTERNATE) {
+               return TRUE;
+       } else {
+               return FALSE;
+       } 
+}
+
 static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item, 
                              gchar **msgpath, gboolean check_subject,
                              gboolean remove_reedit_target)
@@ -5095,6 +5123,13 @@ static gint compose_queue_sub(Compose *compose, gint *msgnum, FolderItem **item,
                fprintf(fp, "X-Claws-Sign:%d\n", compose->use_signing);
                if (compose->use_encryption) {
                        gchar *encdata;
+                       if (!compose_warn_encryption(compose)) {
+                               lock = FALSE;
+                               fclose(fp);
+                               g_unlink(tmp);
+                               g_free(tmp);
+                               return -6;
+                       }
                        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);
@@ -8088,6 +8123,8 @@ static void compose_send_later_cb(gpointer data, guint action,
        } 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 */
        }
        toolbar_main_set_sensitive(mainwindow_get_mainwindow());
 }
index f8d0f7f2b9519ac66651ad6333e5a66cc49683b2..5fe4eec4f85e04030644c176d5fb12f52a92bd89 100644 (file)
@@ -49,6 +49,8 @@ static PrefParam param[] = {
         NULL, NULL, NULL},
        {"gpg_ask_create_key", "TRUE", &prefs_gpg.gpg_ask_create_key, P_BOOL,
         NULL, NULL, NULL},
+       {"skip_encryption_warning", "", &prefs_gpg.skip_encryption_warning, P_STRING,
+        NULL, NULL, NULL},
 
        {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
 };
@@ -578,3 +580,66 @@ void prefs_gpg_done()
        prefs_account_unregister_page((PrefsPage *) &gpg_account_page);
        prefs_gpg_enable_agent(TRUE);
 }
+
+gboolean prefs_gpg_should_skip_encryption_warning(const gchar *systemid)
+{
+       gchar **systems = NULL;
+       int i = 0;
+       if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
+               return FALSE;
+       systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
+                               ",", -1);
+       while (systems && systems[i]) {
+               printf(" cmp %s %s\n", systems[i], systemid);
+               if (!strcmp(systems[i],systemid)) {
+                       g_strfreev(systems);
+                       return TRUE;
+               }
+               i++;
+       }
+       g_strfreev(systems);
+       return FALSE;
+}
+
+void prefs_gpg_add_skip_encryption_warning(const gchar *systemid)
+{
+       gchar *tmp = NULL;
+       if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
+               prefs_gpg_get_config()->skip_encryption_warning =
+                       g_strdup_printf("%s,", systemid);
+       else if (!prefs_gpg_should_skip_encryption_warning(systemid)) {
+               tmp = g_strdup_printf("%s%s,",
+                       prefs_gpg_get_config()->skip_encryption_warning,
+                       systemid);
+               g_free(prefs_gpg_get_config()->skip_encryption_warning);
+               prefs_gpg_get_config()->skip_encryption_warning = tmp;
+       }
+       prefs_gpg_save_config();
+}
+
+void prefs_gpg_remove_skip_encryption_warning(const gchar *systemid)
+{
+       gchar **systems = NULL;
+       int i = 0;
+       if (prefs_gpg_get_config()->skip_encryption_warning == NULL)
+               return;
+
+       if (prefs_gpg_should_skip_encryption_warning(systemid)) {
+               systems = g_strsplit(prefs_gpg_get_config()->skip_encryption_warning,
+                               ",", -1);
+               g_free(prefs_gpg_get_config()->skip_encryption_warning);
+               prefs_gpg_get_config()->skip_encryption_warning = NULL;
+
+               while (systems && systems[i]) {
+                       if (!strcmp(systems[i],systemid)) {
+                               i++;
+                               continue;
+                       }
+                       prefs_gpg_add_skip_encryption_warning(systems[i]);
+                       i++;
+               }
+               
+               g_strfreev(systems);
+       }
+       prefs_gpg_save_config();
+}
index cd76461b135eb36517a14884ae395cfa8c23d7de..6ace35eb0f3453d012cf0b4ea53d73294e317570 100644 (file)
@@ -37,6 +37,7 @@ struct GPGConfig
        gboolean         passphrase_grab;
        gboolean         gpg_warning;
        gboolean         gpg_ask_create_key;
+       gchar           *skip_encryption_warning;
 };
 
 struct GPGAccountConfig
@@ -53,3 +54,6 @@ struct GPGAccountConfig *prefs_gpg_account_get_config(PrefsAccount *account);
 void prefs_gpg_account_set_config(PrefsAccount *account, GPGAccountConfig *config);
 void prefs_gpg_account_free_config(GPGAccountConfig *config);
 void prefs_gpg_enable_agent(gboolean enable);
+void prefs_gpg_add_skip_encryption_warning(const gchar *systemid);
+void prefs_gpg_remove_skip_encryption_warning(const gchar *systemid);
+gboolean prefs_gpg_should_skip_encryption_warning(const gchar *systemid);
index b02dac9a314eb878400382a063c90d099caf5e7f..d2d72a231c7fcfa36a263bf153e60172ed7983ab 100644 (file)
@@ -651,6 +651,23 @@ static gchar *pgpinline_get_encrypt_data(GSList *recp_names)
        return sgpgme_get_encrypt_data(recp_names, GPGME_PROTOCOL_OpenPGP);
 }
 
+static const gchar *pgpinline_get_encrypt_warning(void)
+{
+       if (prefs_gpg_should_skip_encryption_warning(pgpinline_system.id))
+               return NULL;
+       else
+               return _("Please note that attachments are not encrypted by "
+                "the PGP/Inline system, nor are email headers, like Subject.");
+}
+
+static void pgpinline_inhibit_encrypt_warning(gboolean inhibit)
+{
+       if (inhibit)
+               prefs_gpg_add_skip_encryption_warning(pgpinline_system.id);
+       else
+               prefs_gpg_remove_skip_encryption_warning(pgpinline_system.id);
+}
+
 static gboolean pgpinline_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
 {
        MimeInfo *msgcontent;
@@ -781,6 +798,8 @@ static PrivacySystem pgpinline_system = {
        TRUE,
        pgpinline_get_encrypt_data,
        pgpinline_encrypt,
+       pgpinline_get_encrypt_warning,
+       pgpinline_inhibit_encrypt_warning,
 };
 
 void pgpinline_init()
index 7669d768115888639d6419dcc2a0698acf91eccf..5265642a21ba446b13bcbba1ca65e38c06b5a49e 100644 (file)
@@ -569,6 +569,23 @@ gchar *pgpmime_get_encrypt_data(GSList *recp_names)
        return sgpgme_get_encrypt_data(recp_names, GPGME_PROTOCOL_OpenPGP);
 }
 
+static const gchar *pgpmime_get_encrypt_warning(void)
+{
+       if (prefs_gpg_should_skip_encryption_warning(pgpmime_system.id))
+               return NULL;
+       else
+               return _("Please note that email headers, like Subject, "
+                        "are not encrypted by the PGP/Mime system.");
+}
+
+static void pgpmime_inhibit_encrypt_warning(gboolean inhibit)
+{
+       if (inhibit)
+               prefs_gpg_add_skip_encryption_warning(pgpmime_system.id);
+       else
+               prefs_gpg_remove_skip_encryption_warning(pgpmime_system.id);
+}
+
 gboolean pgpmime_encrypt(MimeInfo *mimeinfo, const gchar *encrypt_data)
 {
        MimeInfo *msgcontent, *encmultipart, *newinfo;
@@ -706,6 +723,8 @@ static PrivacySystem pgpmime_system = {
        TRUE,
        pgpmime_get_encrypt_data,
        pgpmime_encrypt,
+       pgpmime_get_encrypt_warning,
+       pgpmime_inhibit_encrypt_warning,
 };
 
 void pgpmime_init()
index e3b37b434db2c60762d8a3b83193453fa5b8399a..3dc94f9a89f692814798665384a3c789441a5fe6 100644 (file)
@@ -396,6 +396,40 @@ gchar *privacy_get_encrypt_data(const gchar *id, GSList *recp_names)
        return system->get_encrypt_data(recp_names);
 }
 
+const gchar *privacy_get_encrypt_warning(const gchar *id)
+{
+       PrivacySystem *system;
+
+       g_return_val_if_fail(id != NULL, NULL);
+
+       system = privacy_get_system(id);
+       if (system == NULL)
+               return NULL;
+       if (!system->can_encrypt)
+               return NULL;
+       if (system->get_encrypt_warning == NULL)
+               return NULL;
+
+       return system->get_encrypt_warning();
+}
+
+void privacy_inhibit_encrypt_warning(const gchar *id, gboolean inhibit)
+{
+       PrivacySystem *system;
+
+       g_return_if_fail(id != NULL);
+
+       system = privacy_get_system(id);
+       if (system == NULL)
+               return;
+       if (!system->can_encrypt)
+               return;
+       if (system->inhibit_encrypt_warning == NULL)
+               return;
+
+       system->inhibit_encrypt_warning(inhibit);
+}
+
 gboolean privacy_encrypt(const gchar *id, MimeInfo *mimeinfo, const gchar *encdata)
 {
        PrivacySystem *system;
index 50fd2f0e43411dff0412d23cdff9f0ab79597d49..be16b9ae43593cc81b34e1f4b2a1164c2bfef012 100644 (file)
@@ -61,6 +61,7 @@ gboolean privacy_sign                         (const gchar  *system,
                                                 PrefsAccount *account);
 gchar *privacy_get_encrypt_data                        (const gchar  *system,
                                                 GSList       *recp_names);
+const gchar *privacy_get_encrypt_warning       (const gchar  *system);
 gboolean privacy_encrypt                       (const gchar  *system,
                                                 MimeInfo     *mimeinfo,
                                                 const gchar  *encdata);
@@ -95,6 +96,8 @@ struct _PrivacySystem {
        gchar           *(*get_encrypt_data)    (GSList *recp_names);
        gboolean         (*encrypt)             (MimeInfo *mimeinfo,
                                                 const gchar *encrypt_data);
+       const gchar     *(*get_encrypt_warning) (void);
+       void             (*inhibit_encrypt_warning)     (gboolean inhibit);
 };
 
 struct _PrivacyData {