Make Message-ID string generation less confusing.
[claws.git] / src / prefs_account.c
index 5a4deec3d3c559b5fa508c07667d697a26ba05e3..5bd2afd55326ea580c6a5a452168c29e5a2b1f85 100644 (file)
@@ -332,8 +332,6 @@ struct BasicProtocol {
 
 static char *protocol_names[] = {
        N_("POP3"),
-       NULL,           /* APOP, deprecated */
-       NULL,           /* RPOP, deprecated */
        N_("IMAP4"),
        N_("News (NNTP)"),
        N_("Local mbox file"),
@@ -1361,8 +1359,11 @@ static void basic_create_widget_func(PrefsPage * _page,
                /* Passwords are handled outside of PrefParams. */
                buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_RECV);
-               gtk_entry_set_text(GTK_ENTRY(page->pass_entry), buf);
-               g_free(buf);
+               gtk_entry_set_text(GTK_ENTRY(page->pass_entry), buf != NULL ? buf : "");
+               if (buf != NULL) {
+                       memset(buf, 0, strlen(buf));
+                       g_free(buf);
+               }
        }
 
        page->vbox = vbox1;
@@ -1898,8 +1899,11 @@ static void send_create_widget_func(PrefsPage * _page,
                /* Passwords are handled outside of PrefParams. */
                buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_SEND);
-               gtk_entry_set_text(GTK_ENTRY(page->smtp_pass_entry), buf);
-               g_free(buf);
+               gtk_entry_set_text(GTK_ENTRY(page->smtp_pass_entry), buf != NULL ? buf : "");
+               if (buf != NULL) {
+                       memset(buf, 0, strlen(buf));
+                       g_free(buf);
+               }
        }
 
        pop_bfr_smtp_tm_set_sens (NULL, NULL);
@@ -2626,12 +2630,19 @@ static void ssl_create_widget_func(PrefsPage * _page,
                /* Passwords are handled outside of PrefParams. */
                buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_RECV_CERT);
-               gtk_entry_set_text(GTK_ENTRY(page->entry_in_cert_pass), buf);
-               g_free(buf);
+               gtk_entry_set_text(GTK_ENTRY(page->entry_in_cert_pass), buf != NULL ? buf : "");
+               if (buf != NULL) {
+                       memset(buf, 0, strlen(buf));
+                       g_free(buf);
+               }
+
                buf = passwd_store_get_account(ac_prefs->account_id,
                                PWS_ACCOUNT_SEND_CERT);
-               gtk_entry_set_text(GTK_ENTRY(page->entry_out_cert_pass), buf);
-               g_free(buf);
+               gtk_entry_set_text(GTK_ENTRY(page->entry_out_cert_pass), buf != NULL ? buf : "");
+               if (buf != NULL) {
+                       memset(buf, 0, strlen(buf));
+                       g_free(buf);
+               }
        }
 
        page->vbox = vbox1;
@@ -3557,12 +3568,6 @@ void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
        if (id < 0) g_warning("wrong account id: %d", id);
        ac_prefs->account_id = id;
 
-       if (ac_prefs->protocol == A_APOP) {
-               debug_print("converting protocol A_APOP to new prefs.\n");
-               ac_prefs->protocol = A_POP3;
-               ac_prefs->use_apop_auth = TRUE;
-       }
-
        if (privacy_prefs != NULL) {
                strv = g_strsplit(privacy_prefs, ",", 0);
                for (cur = strv; *cur != NULL; cur++) {
@@ -4902,6 +4907,51 @@ static void prefs_account_compose_default_dictionary_set_optmenu_from_string
 }
 #endif
 
+gchar *prefs_account_generate_msgid(PrefsAccount *account)
+{
+       gchar *addr, *tmbuf, *buf = NULL;
+       GDateTime *now;
+       gchar *user_addr = account->msgid_with_addr ? account->address : NULL;
+
+       if (account->set_domain && account->domain) {
+               buf = g_strdup(account->domain);
+       } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
+               buf = g_strdup(
+                               strchr(account->address, '@') ?
+                               strchr(account->address, '@')+1 :
+                               account->address);
+       }
+
+       if (user_addr != NULL) {
+               addr = g_strdup_printf(".%s", user_addr);
+       } else {
+               addr = g_strdup_printf("@%s",
+                               buf != NULL && strlen(buf) > 0 ?
+                               buf : get_domain_name());
+       }
+
+       if (buf != NULL)
+               g_free(buf);
+       if (user_addr != NULL)
+               g_free(user_addr);
+
+       /* Replace all @ but the last one in addr, with underscores.
+        * RFC 2822 States that msg-id syntax only allows one @.
+        */
+       while (strchr(addr, '@') != NULL && strchr(addr, '@') != strrchr(addr, '@'))
+               *(strchr(addr, '@')) = '_';
+
+       now = g_date_time_new_now_local();
+       tmbuf = g_date_time_format(now, "%Y%m%d%H%M%S");
+       buf = g_strdup_printf("%s.%08x%s",
+                       tmbuf, (guint)rand(), addr);
+       g_free(tmbuf);
+       g_free(addr);
+
+       debug_print("Generated Message-ID string '%s'\n", buf);
+       return buf;
+}
+
 void prefs_account_register_page(PrefsPage *page)
 {
        prefs_pages = g_slist_append(prefs_pages, page);