2007-08-12 [wwp] 2.10.0cvs116
[claws.git] / src / plugins / pgpcore / prefs_gpg.c
index fca79dba2babe801b4b2c7a51ec43fe4488c815f..ffdb1062918558147035f3d296450488f84f47f8 100644 (file)
@@ -1,10 +1,10 @@
 /*
- * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 2004-2007 Hiroyuki Yamamoto & the Claws Mail team
+ * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
+ * Copyright (C) 2004-2007 the Claws Mail team
  *
  * 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
- * the Free Software Foundation; either version 2 of the License, or
+ * the Free Software Foundation; either version 3 of the License, or
  * (at your option) any later version.
  *
  * This program is distributed in the hope that it will be useful,
@@ -13,8 +13,8 @@
  * GNU General Public License for more details.
  *
  * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ * 
  */
 
 #include <gtk/gtk.h>
@@ -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}
 };
@@ -528,9 +530,13 @@ void prefs_gpg_enable_agent(gboolean enable)
                        debug_print("Can't enable gpg agent (no GPG_AGENT_INFO)\n");
                }
        } else {
+               if (saved_gpg_agent_info) {
                        g_unsetenv("GPG_AGENT_INFO");
                        debug_print("unset GPG_AGENT_INFO=%s\n", 
                                saved_gpg_agent_info);
+               } else {
+                       debug_print("Can't disable gpg agent (no GPG_AGENT_INFO)\n");
+               }
        }
 }
 
@@ -538,7 +544,7 @@ void prefs_gpg_init()
 {
        static gchar *path[3];
        gchar *rcpath;
-       gchar *tmp = NULL;
+       const gchar *tmp = NULL;
 
        prefs_set_default(param);
        rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
@@ -578,3 +584,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();
+}