Remove extravagant debug message
[claws.git] / src / plugins / managesieve / sieve_prefs.c
index 69d8aa4af60eeaf25fe6cdb6591e93416e85e4ea..914e8459e672939299a0eba0df32c71d1172e5a0 100644 (file)
 #include "sieve_prefs.h"
 #include "managesieve.h"
 
+#define PREFS_BLOCK_NAME "ManageSieve"
+
+SieveConfig sieve_config;
+
+static PrefParam prefs[] = {
+        {"manager_win_width", "-1", &sieve_config.manager_win_width,
+               P_INT, NULL, NULL, NULL},
+        {"manager_win_height", "-1", &sieve_config.manager_win_height,
+               P_INT, NULL, NULL, NULL},
+        {0,0,0,0}
+};
+
 #define PACK_HBOX(hbox, vbox) \
 { \
        hbox = gtk_hbox_new (FALSE, 5); \
@@ -151,6 +163,7 @@ static void sieve_prefs_account_create_widget_func(PrefsPage *_page,
        gtk_size_group_add_widget(size_group, host_checkbtn);
 
        host_entry = gtk_entry_new();
+       gtk_entry_set_max_length(GTK_ENTRY(host_entry), 255);
        gtk_widget_show (host_entry);
        gtk_box_pack_start (GTK_BOX (hbox), host_entry, TRUE, TRUE, 0);
        SET_TOGGLE_SENSITIVITY (host_checkbtn, host_entry);
@@ -392,6 +405,9 @@ static gboolean sieve_prefs_account_can_close(PrefsPage *_page)
 
 void sieve_prefs_init()
 {
+       gchar *rcpath;
+
+       /* Account prefs */
        static gchar *path[3];
        path[0] = _("Plugins");
        path[1] = _("Sieve");
@@ -404,11 +420,40 @@ void sieve_prefs_init()
        account_page.page.can_close = sieve_prefs_account_can_close;
        account_page.page.weight = 30.0;
        prefs_account_register_page((PrefsPage *) &account_page);
+
+       /* Common prefs */
+       prefs_set_default(prefs);
+       rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, COMMON_RC, NULL);
+       prefs_read_config(prefs, PREFS_BLOCK_NAME, rcpath, NULL);
+       g_free(rcpath);
 }
 
 void sieve_prefs_done(void)
 {
+       PrefFile *pref_file;
+       gchar *rc_file_path;
+
        prefs_account_unregister_page((PrefsPage *) &account_page);
+
+       rc_file_path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
+                                  COMMON_RC, NULL);
+       pref_file = prefs_write_open(rc_file_path);
+       g_free(rc_file_path);
+
+       if (!pref_file || prefs_set_block_label(pref_file, PREFS_BLOCK_NAME) < 0)
+               return;
+
+       if (prefs_write_param(prefs, pref_file->fp) < 0) {
+               g_warning("failed to write ManageSieve Plugin configuration\n");
+               prefs_file_close_revert(pref_file);
+               return;
+       }
+
+       if (fprintf(pref_file->fp, "\n") < 0) {
+               FILE_OP_ERROR(rc_file_path, "fprintf");
+               prefs_file_close_revert(pref_file);
+       } else
+               prefs_file_close(pref_file);
 }
 
 struct SieveAccountConfig *sieve_prefs_account_get_config(
@@ -419,6 +464,13 @@ struct SieveAccountConfig *sieve_prefs_account_get_config(
        gchar enc_userid[256], enc_passwd[256];
        gchar enable, use_host, use_port;
        gsize len;
+#ifdef G_OS_WIN32
+       /* Windows sscanf() does not understand the %ms format yet, so we
+        * have to do the allocation of target buffer ourselves before
+        * calling sscanf(), and copy the host string to config->host.
+        */
+       gchar tmphost[256];
+#endif
 
        config = g_new0(SieveAccountConfig, 1);
 
@@ -437,10 +489,17 @@ struct SieveAccountConfig *sieve_prefs_account_get_config(
        if (confstr == NULL)
                return config;
 
-
-       sscanf(confstr, "%c%c %ms %c%hu %hhu %hhu %hhu %256s %256s",
+#ifdef G_OS_WIN32
+       sscanf(confstr, "%c%c %255s %c%hu %hhu %hhu %hhu %255s %255s",
+#else
+       sscanf(confstr, "%c%c %ms %c%hu %hhu %hhu %hhu %255s %255s",
+#endif
                        &enable, &use_host,
+#ifdef G_OS_WIN32
+                       tmphost,
+#else
                        &config->host,
+#endif
                        &use_port, &config->port,
                        (char *)&config->tls_type,
                        (char *)&config->auth,
@@ -448,6 +507,10 @@ struct SieveAccountConfig *sieve_prefs_account_get_config(
                        enc_userid,
                        enc_passwd);
 
+#ifdef G_OS_WIN32
+       config->host = g_strndup(tmphost, 255);
+#endif
+
        config->enable = enable == 'y';
        config->use_host = use_host == 'y';
        config->use_port = use_port == 'y';