5c4104f7b8d7251b39df7f4bb4849f64b15b4d7b
[claws.git] / src / prefs_account.c
1 /*
2  * Claws Mail -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 3 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18
19 #ifdef HAVE_CONFIG_H
20 #  include "config.h"
21 #include "claws-features.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/filesel.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37 #if !GTK_CHECK_VERSION(3, 0, 0)
38 #include "gtkcmoptionmenu.h"
39 #endif
40 #include "main.h"
41 #include "prefs_gtk.h"
42 #include "prefs_account.h"
43 #include "prefs_common.h"
44 #include "prefs_customheader.h"
45 #include "account.h"
46 #include "mainwindow.h"
47 #include "manage_window.h"
48 #include "folder.h"
49 #include "foldersel.h"
50 #include "inc.h"
51 #include "menu.h"
52 #include "gtkutils.h"
53 #include "utils.h"
54 #include "alertpanel.h"
55 #include "colorlabel.h"
56 #include "smtp.h"
57 #include "imap.h"
58 #include "remotefolder.h"
59 #include "combobox.h"
60 #include "setup.h"
61 #include "quote_fmt.h"
62 #include "hooks.h"
63 #include "privacy.h"
64 #include "inputdialog.h"
65 #include "ssl_certificate.h"
66 #include "passwordstore.h"
67
68 static gboolean cancelled;
69 static gboolean new_account;
70
71 static PrefsAccount tmp_ac_prefs;
72
73 static GtkWidget *sigfile_radiobtn;
74 static GtkWidget *sigcmd_radiobtn;
75 static GtkWidget *entry_sigpath;
76 static GtkWidget *signature_browse_button;
77 static GtkWidget *signature_edit_button;
78
79 #ifdef USE_GNUTLS
80 static GtkWidget *entry_in_cert_file;
81 static GtkWidget *entry_out_cert_file;
82 static GtkWidget *in_ssl_cert_browse_button;
83 static GtkWidget *out_ssl_cert_browse_button;
84 #endif
85
86 static GSList *prefs_pages = NULL;
87
88 typedef struct BasicPage
89 {
90     PrefsPage page;
91
92     GtkWidget *vbox;
93
94         GtkWidget *acname_entry;
95         GtkWidget *default_checkbtn;
96
97         GtkWidget *name_entry;
98         GtkWidget *addr_entry;
99         GtkWidget *org_entry;
100
101         GtkWidget *serv_frame;
102         GtkWidget *serv_table;
103         gpointer *protocol_optmenu;
104         GtkWidget *recvserv_label;
105         GtkWidget *smtpserv_label;
106         GtkWidget *nntpserv_label;
107         GtkWidget *localmbox_label;
108         GtkWidget *mailcmd_label;
109         GtkWidget *recvserv_entry;
110         GtkWidget *smtpserv_entry;
111         GtkWidget *nntpserv_entry;
112         GtkWidget *nntpauth_checkbtn;
113         GtkWidget *nntpauth_onconnect_checkbtn;
114         GtkWidget *localmbox_entry;
115         GtkWidget *mailcmd_checkbtn;
116         GtkWidget *mailcmd_entry;
117         GtkWidget *uid_label;
118         GtkWidget *pass_label;
119         GtkWidget *uid_entry;
120         GtkWidget *pass_entry;
121         GtkWidget *showpwd_checkbtn;
122         GtkWidget *auto_configure_btn;
123         GtkWidget *auto_configure_cancel_btn;
124         GtkWidget *auto_configure_lbl;
125 } BasicPage;
126
127 typedef struct ReceivePage
128 {
129     PrefsPage page;
130
131     GtkWidget *vbox;
132
133         GtkWidget *pop3_frame;
134         GtkWidget *use_apop_checkbtn;
135         GtkWidget *rmmail_checkbtn;
136         GtkWidget *leave_time_spinbtn;
137         GtkWidget *leave_hour_spinbtn;
138         GtkWidget *size_limit_checkbtn;
139         GtkWidget *size_limit_spinbtn;
140         GtkWidget *inbox_label;
141         GtkWidget *inbox_entry;
142         GtkWidget *inbox_btn;
143
144         GtkWidget *local_frame;
145         GtkWidget *local_inbox_label;
146         GtkWidget *local_inbox_entry;
147         GtkWidget *local_inbox_btn;
148
149         GtkWidget *filter_on_recv_checkbtn;
150         GtkWidget *filterhook_on_recv_checkbtn;
151         GtkWidget *recvatgetall_checkbtn;
152         
153         GtkWidget *imap_frame;
154         GtkWidget *imap_auth_type_optmenu;
155         GtkWidget *imapdir_label;
156         GtkWidget *imapdir_entry;
157         GtkWidget *subsonly_checkbtn;
158         GtkWidget *low_bandwidth_checkbtn;
159
160         GtkWidget *frame_maxarticle;
161         GtkWidget *maxarticle_label;
162         GtkWidget *maxarticle_spinbtn;
163         GtkAdjustment *maxarticle_spinbtn_adj;
164 } ReceivePage;
165
166 typedef struct SendPage
167 {
168     PrefsPage page;
169
170     GtkWidget *vbox;
171
172         GtkWidget *msgid_checkbtn;
173         GtkWidget *xmailer_checkbtn;
174         GtkWidget *customhdr_checkbtn;
175         GtkWidget *msgid_with_addr_checkbtn;
176         GtkWidget *smtp_auth_checkbtn;
177         GtkWidget *smtp_auth_type_optmenu;
178         GtkWidget *smtp_uid_entry;
179         GtkWidget *smtp_pass_entry;
180         GtkWidget *pop_bfr_smtp_checkbtn;
181         GtkWidget *pop_bfr_smtp_tm_spinbtn;
182         GtkWidget *pop_auth_timeout_lbl;
183         GtkWidget *pop_auth_minutes_lbl;
184 } SendPage;
185
186 typedef struct ComposePage
187 {
188     PrefsPage page;
189
190     GtkWidget *vbox;
191
192         GtkWidget *sigfile_radiobtn;
193         GtkWidget *entry_sigpath;
194         GtkWidget *checkbtn_autosig;
195         GtkWidget *entry_sigsep;
196         GtkWidget *autocc_checkbtn;
197         GtkWidget *autocc_entry;
198         GtkWidget *autobcc_checkbtn;
199         GtkWidget *autobcc_entry;
200         GtkWidget *autoreplyto_checkbtn;
201         GtkWidget *autoreplyto_entry;
202 #if USE_ENCHANT
203         GtkWidget *checkbtn_enable_default_dictionary;
204         GtkWidget *combo_default_dictionary;
205         GtkWidget *checkbtn_enable_default_alt_dictionary;
206         GtkWidget *combo_default_alt_dictionary;
207 #endif
208 } ComposePage;
209
210 typedef struct TemplatesPage
211 {
212     PrefsPage page;
213
214     GtkWidget *vbox;
215
216         GtkWidget *checkbtn_compose_with_format;
217         GtkWidget *compose_subject_format;
218         GtkWidget *compose_body_format;
219         GtkWidget *checkbtn_reply_with_format;
220         GtkWidget *reply_quotemark;
221         GtkWidget *reply_body_format;
222         GtkWidget *checkbtn_forward_with_format;
223         GtkWidget *forward_quotemark;
224         GtkWidget *forward_body_format;
225 } TemplatesPage;
226
227 typedef struct PrivacyPage
228 {
229     PrefsPage page;
230
231     GtkWidget *vbox;
232
233         GtkWidget *default_privacy_system;
234         GtkWidget *default_encrypt_checkbtn;
235         GtkWidget *default_encrypt_reply_checkbtn;
236         GtkWidget *default_sign_checkbtn;
237         GtkWidget *default_sign_reply_checkbtn;
238         GtkWidget *save_clear_text_checkbtn;
239         GtkWidget *encrypt_to_self_checkbtn;
240 } PrivacyPage;
241
242 typedef struct SSLPage
243 {
244     PrefsPage page;
245
246     GtkWidget *vbox;
247
248         GtkWidget *pop_frame;
249         GtkWidget *pop_nossl_radiobtn;
250         GtkWidget *pop_ssltunnel_radiobtn;
251         GtkWidget *pop_starttls_radiobtn;
252
253         GtkWidget *imap_frame;
254         GtkWidget *imap_nossl_radiobtn;
255         GtkWidget *imap_ssltunnel_radiobtn;
256         GtkWidget *imap_starttls_radiobtn;
257
258         GtkWidget *nntp_frame;
259         GtkWidget *nntp_nossl_radiobtn;
260         GtkWidget *nntp_ssltunnel_radiobtn;
261
262         GtkWidget *send_frame;
263         GtkWidget *smtp_nossl_radiobtn;
264         GtkWidget *smtp_ssltunnel_radiobtn;
265         GtkWidget *smtp_starttls_radiobtn;
266
267         GtkWidget *entry_in_cert_file;
268         GtkWidget *entry_in_cert_pass;
269         GtkWidget *entry_out_cert_file;
270         GtkWidget *entry_out_cert_pass;
271
272         GtkWidget *ssl_certs_auto_accept_checkbtn;
273         GtkWidget *use_nonblocking_ssl_checkbtn;
274 } SSLPage;
275
276 typedef struct ProxyPage
277 {
278         PrefsPage page;
279
280         GtkWidget *vbox;
281
282         GtkWidget *proxy_checkbtn;
283         GtkWidget *default_proxy_checkbtn;
284         GtkWidget *socks4_radiobtn;
285         GtkWidget *socks5_radiobtn;
286         GtkWidget *proxy_host_entry;
287         GtkWidget *proxy_port_spinbtn;
288         GtkWidget *proxy_auth_checkbtn;
289         GtkWidget *proxy_name_entry;
290         GtkWidget *proxy_pass_entry;
291         GtkWidget *proxy_send_checkbtn;
292 } ProxyPage;
293
294 typedef struct AdvancedPage
295 {
296     PrefsPage page;
297
298     GtkWidget *vbox;
299
300         GtkWidget *smtpport_checkbtn;
301         GtkWidget *smtpport_spinbtn;
302         GtkWidget *popport_hbox;
303         GtkWidget *popport_checkbtn;
304         GtkWidget *popport_spinbtn;
305         GtkWidget *imapport_hbox;
306         GtkWidget *imapport_checkbtn;
307         GtkWidget *imapport_spinbtn;
308         GtkWidget *nntpport_hbox;
309         GtkWidget *nntpport_checkbtn;
310         GtkWidget *nntpport_spinbtn;
311         GtkWidget *domain_checkbtn;
312         GtkWidget *domain_entry;
313 #if !GTK_CHECK_VERSION(3, 0, 0)
314         GtkWidget *crosspost_checkbtn;
315         GtkWidget *crosspost_colormenu;
316 #endif
317
318 #ifndef G_OS_WIN32
319         GtkWidget *tunnelcmd_checkbtn;
320         GtkWidget *tunnelcmd_entry;
321 #endif
322
323         GtkWidget *sent_folder_checkbtn;
324         GtkWidget *sent_folder_entry;
325         GtkWidget *queue_folder_checkbtn;
326         GtkWidget *queue_folder_entry;
327         GtkWidget *draft_folder_checkbtn;
328         GtkWidget *draft_folder_entry;
329         GtkWidget *trash_folder_checkbtn;
330         GtkWidget *trash_folder_entry;
331 } AdvancedPage;
332
333 static BasicPage basic_page;
334 static ReceivePage receive_page;
335 static SendPage send_page;
336 static ComposePage compose_page;
337 static TemplatesPage templates_page;
338 static PrivacyPage privacy_page;
339 #ifdef USE_GNUTLS
340 static SSLPage ssl_page;
341 #endif
342 static ProxyPage proxy_page;
343 static AdvancedPage advanced_page;
344
345 struct BasicProtocol {
346         GtkWidget *combobox;
347         GtkWidget *label;
348         GtkWidget *descrlabel;
349         GtkWidget *no_imap_warn_icon;
350         GtkWidget *no_imap_warn_label;
351 };
352
353 static char *protocol_names[] = {
354         N_("POP"),
355         N_("IMAP"),
356         N_("News (NNTP)"),
357         N_("Local mbox file"),
358         N_("None (SMTP only)")
359 };
360
361 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam);
362 static void prefs_account_protocol_set_optmenu          (PrefParam *pparam);
363 static void prefs_account_protocol_changed              (GtkComboBox *combobox,
364                                                         gpointer data);
365
366 static void prefs_account_set_string_from_combobox (PrefParam *pparam);
367 static void prefs_account_set_privacy_combobox_from_string (PrefParam *pparam);
368
369 static void prefs_account_imap_auth_type_set_data_from_optmenu
370                                                         (PrefParam *pparam);
371 static void prefs_account_imap_auth_type_set_optmenu    (PrefParam *pparam);
372 static void prefs_account_smtp_auth_type_set_data_from_optmenu
373                                                         (PrefParam *pparam);
374 static void prefs_account_smtp_auth_type_set_optmenu    (PrefParam *pparam);
375
376 static void prefs_account_enum_set_data_from_radiobtn   (PrefParam *pparam);
377 static void prefs_account_enum_set_radiobtn             (PrefParam *pparam);
378
379 #if !GTK_CHECK_VERSION(3, 0, 0)
380 static void crosspost_color_toggled(void);
381 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam);
382 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam);
383 #endif
384
385 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
386                                            gpointer user_data);
387 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
388                                           gpointer user_data);
389 static void prefs_account_showpwd_checkbtn_toggled(GtkToggleButton *button,
390                                           gpointer user_data);
391 static void prefs_account_entry_changed_newline_check_cb(GtkWidget *entry,
392                                                 gpointer user_data);
393 static void prefs_account_filter_on_recv_toggled(GtkToggleButton *button,
394                                           gpointer user_data);
395
396 #if USE_ENCHANT
397 static void prefs_account_compose_default_dictionary_set_string_from_optmenu
398                                                         (PrefParam *pparam);
399 static void prefs_account_compose_default_dictionary_set_optmenu_from_string
400                                                         (PrefParam *pparam);
401 #endif
402
403 static gchar *privacy_prefs;
404
405 static PrefParam basic_param[] = {
406         {"account_name", NULL, &tmp_ac_prefs.account_name, P_STRING,
407          &basic_page.acname_entry, prefs_set_data_from_entry, prefs_set_entry},
408
409         {"is_default", "FALSE", &tmp_ac_prefs.is_default, P_BOOL,
410          &basic_page.default_checkbtn,
411          prefs_set_data_from_toggle, prefs_set_toggle},
412
413         {"name", NULL, &tmp_ac_prefs.name, P_STRING,
414          &basic_page.name_entry, prefs_set_data_from_entry, prefs_set_entry},
415
416         {"address", NULL, &tmp_ac_prefs.address, P_STRING,
417          &basic_page.addr_entry, prefs_set_data_from_entry, prefs_set_entry},
418
419         {"organization", NULL, &tmp_ac_prefs.organization, P_STRING,
420          &basic_page.org_entry, prefs_set_data_from_entry, prefs_set_entry},
421
422         {"protocol", NULL, &tmp_ac_prefs.protocol, P_ENUM,
423          (GtkWidget **)&basic_page.protocol_optmenu,
424          prefs_account_protocol_set_data_from_optmenu,
425          prefs_account_protocol_set_optmenu},
426
427         {"receive_server", NULL, &tmp_ac_prefs.recv_server, P_STRING,
428          &basic_page.recvserv_entry, prefs_set_data_from_entry, prefs_set_entry},
429
430         {"smtp_server", NULL, &tmp_ac_prefs.smtp_server, P_STRING,
431          &basic_page.smtpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
432
433         {"nntp_server", NULL, &tmp_ac_prefs.nntp_server, P_STRING,
434          &basic_page.nntpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
435
436         {"local_mbox", "/var/mail", &tmp_ac_prefs.local_mbox, P_STRING,
437          &basic_page.localmbox_entry, prefs_set_data_from_entry, prefs_set_entry},
438
439         {"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
440          &basic_page.mailcmd_checkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
441
442         {"mail_command", DEFAULT_SENDMAIL_CMD, &tmp_ac_prefs.mail_command, P_STRING,
443          &basic_page.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
444
445         {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
446          &basic_page.nntpauth_checkbtn,
447          prefs_set_data_from_toggle, prefs_set_toggle},
448         
449         {"use_nntp_auth_onconnect", "FALSE", &tmp_ac_prefs.use_nntp_auth_onconnect, P_BOOL,
450          &basic_page.nntpauth_onconnect_checkbtn,
451          prefs_set_data_from_toggle, prefs_set_toggle},
452
453         {"user_id", "ENV_USER", &tmp_ac_prefs.userid, P_STRING,
454          &basic_page.uid_entry, prefs_set_data_from_entry, prefs_set_entry},
455
456         {"password", NULL, &tmp_ac_prefs.passwd, P_PASSWORD,
457          NULL, NULL, NULL},
458
459         {"config_version", "-1", &tmp_ac_prefs.config_version, P_INT,
460                 NULL, NULL, NULL},
461
462         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
463 };
464
465 static PrefParam receive_param[] = {
466         {"use_apop_auth", "FALSE", &tmp_ac_prefs.use_apop_auth, P_BOOL,
467          &receive_page.use_apop_checkbtn,
468          prefs_set_data_from_toggle, prefs_set_toggle},
469
470         {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
471          &receive_page.rmmail_checkbtn,
472          prefs_set_data_from_toggle, prefs_set_toggle},
473
474 #ifndef GENERIC_UMPC
475         {"message_leave_time", "7", &tmp_ac_prefs.msg_leave_time, P_INT,
476          &receive_page.leave_time_spinbtn,
477          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
478 #else
479         {"message_leave_time", "30", &tmp_ac_prefs.msg_leave_time, P_INT,
480          &receive_page.leave_time_spinbtn,
481          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
482 #endif
483         {"message_leave_hour", "0", &tmp_ac_prefs.msg_leave_hour, P_INT,
484          &receive_page.leave_hour_spinbtn,
485          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
486
487         {"enable_size_limit", "FALSE", &tmp_ac_prefs.enable_size_limit, P_BOOL,
488          &receive_page.size_limit_checkbtn,
489          prefs_set_data_from_toggle, prefs_set_toggle},
490         {"size_limit", "1024", &tmp_ac_prefs.size_limit, P_INT,
491          &receive_page.size_limit_spinbtn,
492          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
493
494         {"filter_on_receive", "TRUE", &tmp_ac_prefs.filter_on_recv, P_BOOL,
495          &receive_page.filter_on_recv_checkbtn,
496          prefs_set_data_from_toggle, prefs_set_toggle},
497
498         {"filterhook_on_receive", "TRUE", &tmp_ac_prefs.filterhook_on_recv, P_BOOL,
499          &receive_page.filterhook_on_recv_checkbtn,
500          prefs_set_data_from_toggle, prefs_set_toggle},
501
502         {"imap_auth_method", "0", &tmp_ac_prefs.imap_auth_type, P_ENUM,
503          &receive_page.imap_auth_type_optmenu,
504          prefs_account_imap_auth_type_set_data_from_optmenu,
505          prefs_account_imap_auth_type_set_optmenu},
506
507         {"receive_at_get_all", "TRUE", &tmp_ac_prefs.recv_at_getall, P_BOOL,
508          &receive_page.recvatgetall_checkbtn,
509          prefs_set_data_from_toggle, prefs_set_toggle},
510
511         {"max_news_articles", "300", &tmp_ac_prefs.max_articles, P_INT,
512          &receive_page.maxarticle_spinbtn,
513          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
514
515         {"inbox", "#mh/Mailbox/inbox", &tmp_ac_prefs.inbox, P_STRING,
516          &receive_page.inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
517
518         {"local_inbox", "#mh/Mailbox/inbox", &tmp_ac_prefs.local_inbox, P_STRING,
519          &receive_page.local_inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
520
521         {"imap_directory", NULL, &tmp_ac_prefs.imap_dir, P_STRING,
522          &receive_page.imapdir_entry, prefs_set_data_from_entry, prefs_set_entry},
523
524         {"imap_subsonly", "TRUE", &tmp_ac_prefs.imap_subsonly, P_BOOL,
525          &receive_page.subsonly_checkbtn,
526          prefs_set_data_from_toggle, prefs_set_toggle},
527
528         {"low_bandwidth", "FALSE", &tmp_ac_prefs.low_bandwidth, P_BOOL,
529          &receive_page.low_bandwidth_checkbtn,
530          prefs_set_data_from_toggle, prefs_set_toggle},
531
532         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
533 };
534
535 static PrefParam send_param[] = {
536         {"generate_msgid", "TRUE", &tmp_ac_prefs.gen_msgid, P_BOOL,
537          &send_page.msgid_checkbtn,
538          prefs_set_data_from_toggle, prefs_set_toggle},
539
540         {"generate_xmailer", "TRUE", &tmp_ac_prefs.gen_xmailer, P_BOOL,
541          &send_page.xmailer_checkbtn,
542          prefs_set_data_from_toggle, prefs_set_toggle},
543
544         {"add_custom_header", "FALSE", &tmp_ac_prefs.add_customhdr, P_BOOL,
545          &send_page.customhdr_checkbtn,
546          prefs_set_data_from_toggle, prefs_set_toggle},
547
548         {"msgid_with_addr", "FALSE", &tmp_ac_prefs.msgid_with_addr, P_BOOL,
549          &send_page.msgid_with_addr_checkbtn,
550          prefs_set_data_from_toggle, prefs_set_toggle},
551
552          {"use_smtp_auth", "FALSE", &tmp_ac_prefs.use_smtp_auth, P_BOOL,
553          &send_page.smtp_auth_checkbtn,
554          prefs_set_data_from_toggle, prefs_set_toggle},
555
556         {"smtp_auth_method", "0", &tmp_ac_prefs.smtp_auth_type, P_ENUM,
557          &send_page.smtp_auth_type_optmenu,
558          prefs_account_smtp_auth_type_set_data_from_optmenu,
559          prefs_account_smtp_auth_type_set_optmenu},
560
561         {"smtp_user_id", NULL, &tmp_ac_prefs.smtp_userid, P_STRING,
562          &send_page.smtp_uid_entry, prefs_set_data_from_entry, prefs_set_entry},
563         {"smtp_password", NULL, &tmp_ac_prefs.smtp_passwd, P_PASSWORD,
564          NULL, NULL, NULL},
565
566         {"pop_before_smtp", "FALSE", &tmp_ac_prefs.pop_before_smtp, P_BOOL,
567          &send_page.pop_bfr_smtp_checkbtn,
568          prefs_set_data_from_toggle, prefs_set_toggle},
569
570         {"pop_before_smtp_timeout", "5", &tmp_ac_prefs.pop_before_smtp_timeout, P_INT,
571          &send_page.pop_bfr_smtp_tm_spinbtn,
572          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
573
574         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
575 };
576
577 static PrefParam compose_param[] = {
578         {"signature_type", "0", &tmp_ac_prefs.sig_type, P_ENUM,
579          &compose_page.sigfile_radiobtn,
580          prefs_account_enum_set_data_from_radiobtn,
581          prefs_account_enum_set_radiobtn},
582         {"signature_path", "~" G_DIR_SEPARATOR_S DEFAULT_SIGNATURE,
583          &tmp_ac_prefs.sig_path, P_STRING, &compose_page.entry_sigpath,
584          prefs_set_data_from_entry, prefs_set_entry},
585
586         {"auto_signature", "TRUE", &tmp_ac_prefs.auto_sig, P_BOOL,
587          &compose_page.checkbtn_autosig,
588          prefs_set_data_from_toggle, prefs_set_toggle},
589          
590         {"signature_separator", "-- ", &tmp_ac_prefs.sig_sep, P_STRING,
591          &compose_page.entry_sigsep, 
592          prefs_set_data_from_entry, prefs_set_entry},
593
594         {"set_autocc", "FALSE", &tmp_ac_prefs.set_autocc, P_BOOL,
595          &compose_page.autocc_checkbtn,
596          prefs_set_data_from_toggle, prefs_set_toggle},
597
598         {"auto_cc", NULL, &tmp_ac_prefs.auto_cc, P_STRING,
599          &compose_page.autocc_entry,
600          prefs_set_data_from_entry, prefs_set_entry},
601
602         {"set_autobcc", "FALSE", &tmp_ac_prefs.set_autobcc, P_BOOL,
603          &compose_page.autobcc_checkbtn,
604          prefs_set_data_from_toggle, prefs_set_toggle},
605
606         {"auto_bcc", NULL, &tmp_ac_prefs.auto_bcc, P_STRING,
607          &compose_page.autobcc_entry,
608          prefs_set_data_from_entry, prefs_set_entry},
609
610         {"set_autoreplyto", "FALSE", &tmp_ac_prefs.set_autoreplyto, P_BOOL,
611          &compose_page.autoreplyto_checkbtn,
612          prefs_set_data_from_toggle, prefs_set_toggle},
613
614         {"auto_replyto", NULL, &tmp_ac_prefs.auto_replyto, P_STRING,
615          &compose_page.autoreplyto_entry,
616          prefs_set_data_from_entry, prefs_set_entry},
617
618 #if USE_ENCHANT
619         {"enable_default_dictionary", "", &tmp_ac_prefs.enable_default_dictionary, P_BOOL,
620          &compose_page.checkbtn_enable_default_dictionary,
621          prefs_set_data_from_toggle, prefs_set_toggle},
622
623         {"default_dictionary", NULL, &tmp_ac_prefs.default_dictionary, P_STRING,
624          &compose_page.combo_default_dictionary,
625          prefs_account_compose_default_dictionary_set_string_from_optmenu,
626          prefs_account_compose_default_dictionary_set_optmenu_from_string},
627
628         {"enable_default_alt_dictionary", "", &tmp_ac_prefs.enable_default_alt_dictionary, P_BOOL,
629          &compose_page.checkbtn_enable_default_alt_dictionary,
630          prefs_set_data_from_toggle, prefs_set_toggle},
631
632         {"default_alt_dictionary", NULL, &tmp_ac_prefs.default_alt_dictionary, P_STRING,
633          &compose_page.combo_default_alt_dictionary,
634          prefs_account_compose_default_dictionary_set_string_from_optmenu,
635          prefs_account_compose_default_dictionary_set_optmenu_from_string},
636 #else
637         {"enable_default_dictionary", "", &tmp_ac_prefs.enable_default_dictionary, P_BOOL,
638          NULL, NULL, NULL},
639
640         {"default_dictionary", NULL, &tmp_ac_prefs.default_dictionary, P_STRING,
641          NULL, NULL, NULL},
642
643         {"enable_default_alt_dictionary", "", &tmp_ac_prefs.enable_default_alt_dictionary, P_BOOL,
644          NULL, NULL, NULL},
645
646         {"default_alt_dictionary", NULL, &tmp_ac_prefs.default_alt_dictionary, P_STRING,
647          NULL, NULL, NULL},
648 #endif   
649
650         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
651 };
652
653 static PrefParam templates_param[] = {
654         {"compose_with_format", "FALSE", &tmp_ac_prefs.compose_with_format, P_BOOL,
655          &templates_page.checkbtn_compose_with_format,
656          prefs_set_data_from_toggle, prefs_set_toggle},
657
658         {"compose_subject_format", NULL, &tmp_ac_prefs.compose_subject_format, P_STRING,
659          &templates_page.compose_subject_format,
660          prefs_set_escaped_data_from_entry, prefs_set_entry_from_escaped},
661
662         {"compose_body_format", NULL, &tmp_ac_prefs.compose_body_format, P_STRING,
663          &templates_page.compose_body_format,
664          prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
665
666         {"reply_with_format", "FALSE", &tmp_ac_prefs.reply_with_format, P_BOOL,
667          &templates_page.checkbtn_reply_with_format,
668          prefs_set_data_from_toggle, prefs_set_toggle},
669
670         {"reply_quotemark", NULL, &tmp_ac_prefs.reply_quotemark, P_STRING,
671          &templates_page.reply_quotemark,
672          prefs_set_data_from_entry, prefs_set_entry_from_escaped},
673
674         {"reply_body_format", NULL, &tmp_ac_prefs.reply_body_format, P_STRING,
675          &templates_page.reply_body_format,
676          prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
677
678         {"forward_with_format", "FALSE", &tmp_ac_prefs.forward_with_format, P_BOOL,
679          &templates_page.checkbtn_forward_with_format,
680          prefs_set_data_from_toggle, prefs_set_toggle},
681
682         {"forward_quotemark", NULL, &tmp_ac_prefs.forward_quotemark, P_STRING,
683          &templates_page.forward_quotemark,
684          prefs_set_data_from_entry, prefs_set_entry_from_escaped},
685
686         {"forward_body_format", NULL, &tmp_ac_prefs.forward_body_format, P_STRING,
687          &templates_page.forward_body_format,
688          prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
689
690         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
691 };
692
693 static PrefParam privacy_param[] = {
694         {"default_privacy_system", "", &tmp_ac_prefs.default_privacy_system, P_STRING,
695          &privacy_page.default_privacy_system,
696          prefs_account_set_string_from_combobox,
697          prefs_account_set_privacy_combobox_from_string},
698
699         {"default_encrypt", "FALSE", &tmp_ac_prefs.default_encrypt, P_BOOL,
700          &privacy_page.default_encrypt_checkbtn,
701          prefs_set_data_from_toggle, prefs_set_toggle},
702
703         {"default_encrypt_reply", "TRUE", &tmp_ac_prefs.default_encrypt_reply, P_BOOL,
704          &privacy_page.default_encrypt_reply_checkbtn,
705          prefs_set_data_from_toggle, prefs_set_toggle},
706
707         {"default_sign", "FALSE", &tmp_ac_prefs.default_sign, P_BOOL,
708          &privacy_page.default_sign_checkbtn,
709          prefs_set_data_from_toggle, prefs_set_toggle},
710 #ifdef G_OS_UNIX
711         {"default_sign_reply", "TRUE", &tmp_ac_prefs.default_sign_reply, P_BOOL,
712          &privacy_page.default_sign_reply_checkbtn,
713          prefs_set_data_from_toggle, prefs_set_toggle},
714 #else
715         /* Bug 2367: disturbing for Win32 users with no keypair */
716         {"default_sign_reply", "FALSE", &tmp_ac_prefs.default_sign_reply, P_BOOL,
717          &privacy_page.default_sign_reply_checkbtn,
718          prefs_set_data_from_toggle, prefs_set_toggle},
719 #endif
720         {"save_clear_text", "FALSE", &tmp_ac_prefs.save_encrypted_as_clear_text, P_BOOL,
721          &privacy_page.save_clear_text_checkbtn,
722          prefs_set_data_from_toggle, prefs_set_toggle},
723
724         {"encrypt_to_self", "FALSE", &tmp_ac_prefs.encrypt_to_self, P_BOOL,
725          &privacy_page.encrypt_to_self_checkbtn,
726          prefs_set_data_from_toggle, prefs_set_toggle},
727
728         {"privacy_prefs", "", &privacy_prefs, P_STRING,
729          NULL, NULL, NULL},
730
731         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
732 };
733
734 static PrefParam ssl_param[] = {
735 #ifdef USE_GNUTLS
736         {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
737          &ssl_page.pop_nossl_radiobtn,
738          prefs_account_enum_set_data_from_radiobtn,
739          prefs_account_enum_set_radiobtn},
740
741         {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
742          &ssl_page.imap_nossl_radiobtn,
743          prefs_account_enum_set_data_from_radiobtn,
744          prefs_account_enum_set_radiobtn},
745
746         {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
747          &ssl_page.nntp_nossl_radiobtn,
748          prefs_account_enum_set_data_from_radiobtn,
749          prefs_account_enum_set_radiobtn},
750
751         {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
752          &ssl_page.smtp_nossl_radiobtn,
753          prefs_account_enum_set_data_from_radiobtn,
754          prefs_account_enum_set_radiobtn},
755
756         {"ssl_certs_auto_accept", "0", &tmp_ac_prefs.ssl_certs_auto_accept, P_BOOL,
757          &ssl_page.ssl_certs_auto_accept_checkbtn,
758          prefs_set_data_from_toggle, prefs_set_toggle},
759
760         {"use_nonblocking_ssl", "1", &tmp_ac_prefs.use_nonblocking_ssl, P_BOOL,
761          &ssl_page.use_nonblocking_ssl_checkbtn,
762          prefs_set_data_from_toggle, prefs_set_toggle},
763
764         {"in_ssl_client_cert_file", "", &tmp_ac_prefs.in_ssl_client_cert_file, P_STRING,
765          &ssl_page.entry_in_cert_file, prefs_set_data_from_entry, prefs_set_entry},
766
767         {"in_ssl_client_cert_pass", "", &tmp_ac_prefs.in_ssl_client_cert_pass, P_PASSWORD,
768          NULL, NULL, NULL},
769
770         {"out_ssl_client_cert_file", "", &tmp_ac_prefs.out_ssl_client_cert_file, P_STRING,
771          &ssl_page.entry_out_cert_file, prefs_set_data_from_entry, prefs_set_entry},
772
773         {"out_ssl_client_cert_pass", "", &tmp_ac_prefs.out_ssl_client_cert_pass, P_PASSWORD,
774          NULL, NULL, NULL},
775 #else
776         {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
777          NULL, NULL, NULL},
778
779         {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
780          NULL, NULL, NULL},
781
782         {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
783          NULL, NULL, NULL},
784
785         {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
786          NULL, NULL, NULL},
787
788         {"in_ssl_client_cert_file", "", &tmp_ac_prefs.in_ssl_client_cert_file, P_STRING,
789          NULL, NULL, NULL},
790
791         {"in_ssl_client_cert_pass", "", &tmp_ac_prefs.in_ssl_client_cert_pass, P_PASSWORD,
792          NULL, NULL, NULL},
793
794         {"out_ssl_client_cert_file", "", &tmp_ac_prefs.out_ssl_client_cert_file, P_STRING,
795          NULL, NULL, NULL},
796
797         {"out_ssl_client_cert_pass", "", &tmp_ac_prefs.out_ssl_client_cert_pass, P_PASSWORD,
798          NULL, NULL, NULL},
799
800         {"ssl_certs_auto_accept", "0", &tmp_ac_prefs.ssl_certs_auto_accept, P_BOOL,
801          NULL, NULL, NULL},
802
803         {"use_nonblocking_ssl", "1", &tmp_ac_prefs.use_nonblocking_ssl, P_BOOL,
804          NULL, NULL, NULL},
805 #endif /* USE_GNUTLS */
806
807         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
808 };
809
810 static PrefParam proxy_param[] = {
811         /* SOCKS proxy */
812         {"use_proxy", "FALSE", &tmp_ac_prefs.use_proxy, P_BOOL,
813         &proxy_page.proxy_checkbtn,
814         prefs_set_data_from_toggle, prefs_set_toggle},
815
816         {"use_default_proxy", "TRUE", &tmp_ac_prefs.use_default_proxy, P_BOOL,
817         &proxy_page.default_proxy_checkbtn,
818         prefs_set_data_from_toggle, prefs_set_toggle},
819
820         {"use_proxy_for_send", "TRUE", &tmp_ac_prefs.use_proxy_for_send, P_BOOL,
821         &proxy_page.proxy_send_checkbtn,
822         prefs_set_data_from_toggle, prefs_set_toggle},
823
824         {"proxy_type", "1", &tmp_ac_prefs.proxy_info.proxy_type, P_ENUM,
825         &proxy_page.socks4_radiobtn,
826         prefs_account_enum_set_data_from_radiobtn,
827         prefs_account_enum_set_radiobtn},
828
829         {"proxy_host", "localhost", &tmp_ac_prefs.proxy_info.proxy_host, P_STRING,
830         &proxy_page.proxy_host_entry,
831         prefs_set_data_from_entry, prefs_set_entry},
832
833         {"proxy_port", "1080", &tmp_ac_prefs.proxy_info.proxy_port, P_USHORT,
834         &proxy_page.proxy_port_spinbtn,
835         prefs_set_data_from_spinbtn, prefs_set_spinbtn},
836
837         {"use_proxy_auth", "FALSE", &tmp_ac_prefs.proxy_info.use_proxy_auth, P_BOOL,
838         &proxy_page.proxy_auth_checkbtn,
839         prefs_set_data_from_toggle, prefs_set_toggle},
840
841         {"proxy_name", "", &tmp_ac_prefs.proxy_info.proxy_name, P_STRING,
842         &proxy_page.proxy_name_entry,
843         prefs_set_data_from_entry, prefs_set_entry},
844
845         {"proxy_pass", "", &tmp_ac_prefs.proxy_info.proxy_pass, P_PASSWORD,
846         NULL, NULL, NULL},
847
848
849         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
850 };
851
852 static PrefParam advanced_param[] = {
853         {"set_smtpport", "FALSE", &tmp_ac_prefs.set_smtpport, P_BOOL,
854          &advanced_page.smtpport_checkbtn,
855          prefs_set_data_from_toggle, prefs_set_toggle},
856
857         {"smtp_port", "25", &tmp_ac_prefs.smtpport, P_USHORT,
858          &advanced_page.smtpport_spinbtn,
859          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
860
861         {"set_popport", "FALSE", &tmp_ac_prefs.set_popport, P_BOOL,
862          &advanced_page.popport_checkbtn,
863          prefs_set_data_from_toggle, prefs_set_toggle},
864
865         {"pop_port", "110", &tmp_ac_prefs.popport, P_USHORT,
866          &advanced_page.popport_spinbtn,
867          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
868
869         {"set_imapport", "FALSE", &tmp_ac_prefs.set_imapport, P_BOOL,
870          &advanced_page.imapport_checkbtn,
871          prefs_set_data_from_toggle, prefs_set_toggle},
872
873         {"imap_port", "143", &tmp_ac_prefs.imapport, P_USHORT,
874          &advanced_page.imapport_spinbtn,
875          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
876
877         {"set_nntpport", "FALSE", &tmp_ac_prefs.set_nntpport, P_BOOL,
878          &advanced_page.nntpport_checkbtn,
879          prefs_set_data_from_toggle, prefs_set_toggle},
880
881         {"nntp_port", "119", &tmp_ac_prefs.nntpport, P_USHORT,
882          &advanced_page.nntpport_spinbtn,
883          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
884
885         {"set_domain", "FALSE", &tmp_ac_prefs.set_domain, P_BOOL,
886          &advanced_page.domain_checkbtn,
887          prefs_set_data_from_toggle, prefs_set_toggle},
888
889         {"domain", NULL, &tmp_ac_prefs.domain, P_STRING,
890          &advanced_page.domain_entry,
891          prefs_set_data_from_entry, prefs_set_entry},
892
893 #ifdef USE_GNUTLS
894         {"gnutls_set_priority", "FALSE", &tmp_ac_prefs.set_gnutls_priority, P_BOOL,
895          NULL, NULL, NULL},
896
897         {"gnutls_priority", NULL, &tmp_ac_prefs.gnutls_priority, P_STRING,
898          NULL, NULL, NULL},
899 #endif
900
901 #ifndef G_OS_WIN32
902         {"set_tunnelcmd", "FALSE", &tmp_ac_prefs.set_tunnelcmd, P_BOOL,
903          &advanced_page.tunnelcmd_checkbtn,
904          prefs_set_data_from_toggle, prefs_set_toggle},
905
906         {"tunnelcmd", NULL, &tmp_ac_prefs.tunnelcmd, P_STRING,
907          &advanced_page.tunnelcmd_entry,
908          prefs_set_data_from_entry, prefs_set_entry},
909 #endif
910 #if !GTK_CHECK_VERSION(3, 0, 0)
911         {"mark_crosspost_read", "FALSE", &tmp_ac_prefs.mark_crosspost_read, P_BOOL,
912          &advanced_page.crosspost_checkbtn,
913          prefs_set_data_from_toggle, prefs_set_toggle},
914
915         {"crosspost_color", NULL, &tmp_ac_prefs.crosspost_col, P_ENUM,
916          &advanced_page.crosspost_colormenu,
917          prefs_account_crosspost_set_data_from_colormenu,
918          prefs_account_crosspost_set_colormenu},
919 #endif
920
921         {"set_sent_folder", "FALSE", &tmp_ac_prefs.set_sent_folder, P_BOOL,
922          &advanced_page.sent_folder_checkbtn,
923          prefs_set_data_from_toggle, prefs_set_toggle},
924         {"sent_folder", NULL, &tmp_ac_prefs.sent_folder, P_STRING,
925          &advanced_page.sent_folder_entry,
926          prefs_set_data_from_entry, prefs_set_entry},
927
928         {"set_queue_folder", "FALSE", &tmp_ac_prefs.set_queue_folder, P_BOOL,
929          &advanced_page.queue_folder_checkbtn,
930          prefs_set_data_from_toggle, prefs_set_toggle},
931         {"queue_folder", NULL, &tmp_ac_prefs.queue_folder, P_STRING,
932          &advanced_page.queue_folder_entry,
933          prefs_set_data_from_entry, prefs_set_entry},
934
935         {"set_draft_folder", "FALSE", &tmp_ac_prefs.set_draft_folder, P_BOOL,
936          &advanced_page.draft_folder_checkbtn,
937          prefs_set_data_from_toggle, prefs_set_toggle},
938         {"draft_folder", NULL, &tmp_ac_prefs.draft_folder, P_STRING,
939          &advanced_page.draft_folder_entry,
940          prefs_set_data_from_entry, prefs_set_entry},
941
942         {"set_trash_folder", "FALSE", &tmp_ac_prefs.set_trash_folder, P_BOOL,
943          &advanced_page.trash_folder_checkbtn,
944          prefs_set_data_from_toggle, prefs_set_toggle},
945         {"trash_folder", NULL, &tmp_ac_prefs.trash_folder, P_STRING,
946          &advanced_page.trash_folder_entry,
947          prefs_set_data_from_entry, prefs_set_entry},
948          
949
950         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
951 };
952
953 static gint prefs_account_get_new_id            (void);
954
955 static void prefs_account_select_folder_cb      (GtkWidget      *widget,
956                                                  gpointer        data);
957
958 static void prefs_account_sigfile_radiobtn_cb   (GtkWidget      *widget,
959                                                  gpointer        data);
960
961 static void prefs_account_sigcmd_radiobtn_cb    (GtkWidget      *widget,
962                                                  gpointer        data);
963
964 static void prefs_account_signature_browse_cb   (GtkWidget      *widget,
965                                                  gpointer        data);
966 #ifdef USE_GNUTLS
967 static void prefs_account_in_cert_browse_cb     (GtkWidget      *widget,
968                                                  gpointer        data);
969
970 static void prefs_account_out_cert_browse_cb    (GtkWidget      *widget,
971                                                  gpointer        data);
972 #endif
973 static void prefs_account_signature_edit_cb     (GtkWidget      *widget,
974                                                  gpointer        data);
975
976 static void pop_bfr_smtp_tm_set_sens            (GtkWidget      *widget,
977                                                  gpointer        data);
978
979 #if (defined USE_GNUTLS)
980 static void auto_configure_cb                   (GtkWidget      *widget,
981                                                  gpointer        data);
982
983 #endif
984 static void prefs_account_edit_custom_header    (void);
985
986
987 #define COMBOBOX_PRIVACY_PLUGIN_ID 3
988
989 /* Enable/disable necessary preference widgets based on current privacy
990  * system choice. */
991 static void privacy_system_activated(GtkWidget *combobox)
992 {
993         gtk_widget_set_sensitive (privacy_page.save_clear_text_checkbtn, 
994                 !gtk_toggle_button_get_active(
995                                 GTK_TOGGLE_BUTTON(privacy_page.encrypt_to_self_checkbtn)));
996 }
997
998 /* Populate the privacy system choice combobox with valid choices */
999 static void update_privacy_system_menu() {
1000         GtkListStore *menu;
1001         GtkTreeIter iter;
1002         GSList *system_ids, *cur;
1003
1004         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
1005                         GTK_COMBO_BOX(privacy_page.default_privacy_system)));
1006
1007         /* First add "None", as that one is always available. :) */
1008         gtk_list_store_append(menu, &iter);
1009         gtk_list_store_set(menu, &iter,
1010                         COMBOBOX_TEXT, _("None"),
1011                         COMBOBOX_DATA, 0,
1012                         COMBOBOX_SENS, TRUE,
1013                         COMBOBOX_PRIVACY_PLUGIN_ID, "",
1014                         -1);
1015
1016         /* Now go through list of available privacy systems and add an entry
1017          * for each. */
1018         system_ids = privacy_get_system_ids();
1019         for (cur = system_ids; cur != NULL; cur = g_slist_next(cur)) {
1020                 gchar *id = (gchar *) cur->data;
1021                 const gchar *name;
1022                 
1023                 name = privacy_system_get_name(id);
1024                 gtk_list_store_append(menu, &iter);
1025                 gtk_list_store_set(menu, &iter,
1026                                 COMBOBOX_TEXT, name,
1027                                 COMBOBOX_DATA, 1,
1028                                 COMBOBOX_SENS, TRUE,
1029                                 COMBOBOX_PRIVACY_PLUGIN_ID, id,
1030                                 -1);
1031                 g_free(id);
1032         }
1033         g_slist_free(system_ids);
1034
1035 }
1036
1037 #define TABLE_YPAD 2
1038
1039 static void basic_create_widget_func(PrefsPage * _page,
1040                                            GtkWindow * window,
1041                                            gpointer data)
1042 {
1043         BasicPage *page = (BasicPage *) _page;
1044         PrefsAccount *ac_prefs = (PrefsAccount *) data;
1045
1046         GtkWidget *vbox1;
1047         GtkWidget *hbox;
1048         GtkWidget *label;
1049         GtkWidget *acname_entry;
1050         GtkWidget *default_checkbtn;
1051         GtkWidget *frame1;
1052         GtkWidget *table1;
1053         GtkWidget *name_entry;
1054         GtkWidget *addr_entry;
1055         GtkWidget *org_entry;
1056
1057         GtkWidget *serv_frame;
1058         GtkWidget *vbox2;
1059         GtkWidget *optmenubox;
1060         GtkWidget *optmenu;
1061         GtkWidget *optlabel;
1062         GtkWidget *no_imap_warn_icon;
1063         GtkWidget *no_imap_warn_label;
1064         GtkWidget *serv_table;
1065         GtkWidget *recvserv_label;
1066         GtkWidget *smtpserv_label;
1067         GtkWidget *nntpserv_label;
1068         GtkWidget *localmbox_label;
1069         GtkWidget *mailcmd_label;
1070         GtkWidget *recvserv_entry;
1071         GtkWidget *smtpserv_entry;
1072         GtkWidget *nntpserv_entry;
1073         GtkWidget *nntpauth_checkbtn;
1074         GtkWidget *nntpauth_onconnect_checkbtn;
1075         GtkWidget *localmbox_entry;
1076         GtkWidget *mailcmd_checkbtn;
1077         GtkWidget *mailcmd_entry;
1078         GtkWidget *uid_label;
1079         GtkWidget *pass_label;
1080         GtkWidget *uid_entry;
1081         GtkWidget *pass_entry;
1082         GtkWidget *auto_configure_btn;
1083         GtkWidget *auto_configure_cancel_btn;
1084         GtkWidget *auto_configure_lbl;
1085         GtkWidget *showpwd_checkbtn;
1086         GtkListStore *menu;
1087         GtkTreeIter iter;
1088         gchar *buf;
1089
1090         struct BasicProtocol *protocol_optmenu;
1091         gint i;
1092
1093         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1094         gtk_widget_show (vbox1);
1095         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1096
1097         hbox = gtk_hbox_new (FALSE, 8);
1098         gtk_widget_show (hbox);
1099         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
1100
1101         label = gtk_label_new (_("Name of account"));
1102         gtk_widget_show (label);
1103         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1104
1105         acname_entry = gtk_entry_new ();
1106         gtk_widget_show (acname_entry);
1107         gtk_widget_set_size_request (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
1108         gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
1109
1110         default_checkbtn = gtk_check_button_new_with_label (_("Set as default"));
1111         gtk_widget_show (default_checkbtn);
1112 #ifndef GENERIC_UMPC
1113         gtk_box_pack_end (GTK_BOX (hbox), default_checkbtn, TRUE, FALSE, 0);
1114 #else
1115         gtk_box_pack_start (GTK_BOX (vbox1), default_checkbtn, FALSE, FALSE, 0);
1116         
1117 #endif
1118         PACK_FRAME (vbox1, frame1, _("Personal information"));
1119
1120         table1 = gtk_table_new (3, 2, FALSE);
1121         gtk_widget_show (table1);
1122         gtk_container_add (GTK_CONTAINER (frame1), table1);
1123         gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
1124         gtk_table_set_row_spacings (GTK_TABLE (table1), VSPACING_NARROW);
1125         gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
1126
1127         label = gtk_label_new (_("Full name"));
1128         gtk_widget_show (label);
1129         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 0, 1,
1130                           GTK_FILL, 0, 0, 0);
1131         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
1132
1133         label = gtk_label_new (_("Mail address"));
1134         gtk_widget_show (label);
1135         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 1, 2,
1136                           GTK_FILL, 0, 0, 0);
1137         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
1138
1139         label = gtk_label_new (_("Organization"));
1140         gtk_widget_show (label);
1141         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 2, 3,
1142                           GTK_FILL, 0, 0, 0);
1143         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
1144
1145         name_entry = gtk_entry_new ();
1146         gtk_widget_show (name_entry);
1147         gtk_table_attach (GTK_TABLE (table1), name_entry, 1, 2, 0, 1,
1148                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1149                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1150
1151         addr_entry = gtk_entry_new ();
1152         gtk_widget_show (addr_entry);
1153         gtk_table_attach (GTK_TABLE (table1), addr_entry, 1, 2, 1, 2,
1154                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1155                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1156
1157         org_entry = gtk_entry_new ();
1158         gtk_widget_show (org_entry);
1159         gtk_table_attach (GTK_TABLE (table1), org_entry, 1, 2, 2, 3,
1160                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1161                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1162
1163         vbox2 = gtkut_get_options_frame(vbox1, &serv_frame, _("Server information"));
1164
1165         hbox = gtk_hbox_new (FALSE, 8);
1166         gtk_widget_show (hbox);
1167         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1168
1169         label = gtk_label_new (_("Protocol"));
1170         gtk_widget_show (label);
1171         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1172
1173         /* Create GtkHBox for protocol combobox and label */
1174         optmenubox = gtk_hbox_new(FALSE, 20);
1175         gtk_widget_show(optmenubox);
1176         gtk_box_pack_start (GTK_BOX (hbox), optmenubox, FALSE, FALSE, 0);
1177
1178         /* Create and populate the combobox */
1179         optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1180         gtk_box_pack_start(GTK_BOX (optmenubox), optmenu, FALSE, FALSE, 0);
1181
1182         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1183         for( i = 0; i < NUM_RECV_PROTOCOLS; i++ )
1184                 if( protocol_names[i] != NULL )
1185                         COMBOBOX_ADD (menu, _(protocol_names[i]), i);
1186
1187         g_signal_connect(G_OBJECT(optmenu), "changed",
1188                         G_CALLBACK(prefs_account_protocol_changed), NULL);
1189
1190         /* Create protocol label, empty for now */
1191         optlabel = gtk_label_new("");
1192         gtk_label_set_use_markup(GTK_LABEL(optlabel), TRUE);
1193         gtk_label_set_justify(GTK_LABEL(optlabel), GTK_JUSTIFY_CENTER);
1194         gtk_box_pack_start(GTK_BOX (optmenubox), optlabel, FALSE, FALSE, 0);
1195
1196         auto_configure_btn = gtk_button_new_with_label(_("Auto-configure"));
1197         gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_btn, FALSE, FALSE, 0);
1198         auto_configure_cancel_btn = gtk_button_new_with_label(_("Cancel"));
1199         gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_cancel_btn, FALSE, FALSE, 0);
1200         auto_configure_lbl = gtk_label_new("");
1201         gtk_label_set_justify(GTK_LABEL(auto_configure_lbl), GTK_JUSTIFY_LEFT);
1202         gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_lbl, FALSE, FALSE, 0);
1203 #if (defined USE_GNUTLS)
1204         gtk_widget_show(auto_configure_btn);
1205         gtk_widget_show(auto_configure_lbl);
1206         g_signal_connect (G_OBJECT (auto_configure_btn), "clicked",
1207                           G_CALLBACK (auto_configure_cb), NULL);
1208         g_signal_connect (G_OBJECT (auto_configure_cancel_btn), "clicked",
1209                           G_CALLBACK (auto_configure_cb), NULL);
1210 #endif
1211
1212         no_imap_warn_icon = gtk_image_new_from_stock
1213                         (GTK_STOCK_DIALOG_WARNING, GTK_ICON_SIZE_SMALL_TOOLBAR);
1214         buf = g_strconcat("<span weight=\"bold\">",
1215                         _("Warning: this version of Claws Mail\n"
1216                           "has been built without IMAP and News support."), "</span>", NULL);
1217         no_imap_warn_label = gtk_label_new(buf);
1218         g_free(buf);
1219         gtk_label_set_use_markup(GTK_LABEL(no_imap_warn_label), TRUE);
1220
1221         gtk_box_pack_start(GTK_BOX (optmenubox), no_imap_warn_icon, FALSE, FALSE, 0);
1222         gtk_box_pack_start(GTK_BOX (optmenubox), no_imap_warn_label, FALSE, FALSE, 0);
1223         /* Set up a struct to store pointers to necessary widgets */
1224         protocol_optmenu = g_new(struct BasicProtocol, 1);
1225         protocol_optmenu->combobox = optmenu;
1226         protocol_optmenu->label = optlabel;
1227         protocol_optmenu->descrlabel = label;
1228         protocol_optmenu->no_imap_warn_icon = no_imap_warn_icon;
1229         protocol_optmenu->no_imap_warn_label = no_imap_warn_label;
1230
1231         serv_table = gtk_table_new (10, 4, FALSE);
1232         gtk_widget_show (serv_table);
1233         gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
1234         gtk_table_set_row_spacings (GTK_TABLE (serv_table), VSPACING_NARROW);
1235         gtk_table_set_row_spacing (GTK_TABLE (serv_table), 3, 0);
1236         gtk_table_set_col_spacings (GTK_TABLE (serv_table), 8);
1237
1238         nntpserv_entry = gtk_entry_new ();
1239         gtk_widget_show (nntpserv_entry);
1240         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_entry, 1, 4, 0, 1,
1241                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1242                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1243 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 0, 0); */
1244
1245         nntpauth_checkbtn = gtk_check_button_new_with_label
1246                 (_("This server requires authentication"));
1247         gtk_widget_show (nntpauth_checkbtn);
1248         
1249         gtk_table_attach (GTK_TABLE (serv_table), nntpauth_checkbtn, 0, 2, 6, 7,
1250                           GTK_FILL, 0, 0, 0);
1251
1252         nntpauth_onconnect_checkbtn = gtk_check_button_new_with_label
1253                 (_("Authenticate on connect"));
1254         gtk_widget_show (nntpauth_onconnect_checkbtn);
1255
1256         gtk_table_attach (GTK_TABLE (serv_table), nntpauth_onconnect_checkbtn, 2, 4, 6, 7,
1257                           GTK_FILL, 0, 0, 0);
1258
1259         recvserv_entry = gtk_entry_new ();
1260         gtk_widget_show (recvserv_entry);
1261         gtk_table_attach (GTK_TABLE (serv_table), recvserv_entry, 1, 4, 2, 3,
1262                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1263                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1264
1265         localmbox_entry = gtk_entry_new ();
1266         gtk_widget_show (localmbox_entry);
1267         gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 3, 4,
1268                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1269                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1270
1271         smtpserv_entry = gtk_entry_new ();
1272         gtk_widget_show (smtpserv_entry);
1273         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_entry, 1, 4, 4, 5,
1274                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1275                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1276
1277         mailcmd_entry = gtk_entry_new ();
1278         gtk_widget_show (mailcmd_entry);
1279         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 6, 7,
1280                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1281                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1282
1283         uid_entry = gtk_entry_new ();
1284         gtk_widget_show (uid_entry);
1285         gtk_widget_set_size_request (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1286         g_signal_connect(G_OBJECT(uid_entry), "changed",
1287                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1288                         GINT_TO_POINTER(ac_prefs->protocol));
1289
1290         pass_entry = gtk_entry_new ();
1291         gtk_widget_show (pass_entry);
1292         gtk_widget_set_size_request (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1293         g_signal_connect(G_OBJECT(pass_entry), "changed",
1294                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1295                         GINT_TO_POINTER(ac_prefs->protocol));
1296
1297 #ifndef GENERIC_UMPC
1298         gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 2, 7, 8,
1299                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1300                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1301
1302         gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 3, 4, 7, 8,
1303                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1304                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1305 #else
1306         gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 4, 7, 8,
1307                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1308                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1309         gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 1, 4, 8, 9,
1310                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1311                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1312 #endif
1313         gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
1314
1315         nntpserv_label = gtk_label_new (_("News server"));
1316         gtk_widget_show (nntpserv_label);
1317         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_label, 0, 1, 0, 1,
1318                           GTK_FILL, 0, 0, 0);
1319         gtk_misc_set_alignment (GTK_MISC (nntpserv_label), 1, 0.5);
1320
1321         recvserv_label = gtk_label_new (_("Server for receiving"));
1322         gtk_widget_show (recvserv_label);
1323         gtk_table_attach (GTK_TABLE (serv_table), recvserv_label, 0, 1, 2, 3,
1324                           GTK_FILL, 0, 0, 0);
1325         gtk_misc_set_alignment (GTK_MISC (recvserv_label), 1, 0.5);
1326
1327         localmbox_label = gtk_label_new (_("Local mailbox"));
1328         gtk_widget_show (localmbox_label);
1329         gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 3, 4,
1330                           GTK_FILL, 0, 0, 0);
1331         gtk_misc_set_alignment (GTK_MISC (localmbox_label), 1, 0.5);
1332 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1333
1334         smtpserv_label = gtk_label_new (_("SMTP server (send)"));
1335         gtk_widget_show (smtpserv_label);
1336         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_label, 0, 1, 4, 5,
1337                           GTK_FILL, 0, 0, 0);
1338         gtk_misc_set_alignment (GTK_MISC (smtpserv_label), 1, 0.5);
1339 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1340
1341         mailcmd_checkbtn = gtk_check_button_new_with_label
1342                 (_("Use mail command rather than SMTP server"));
1343         gtk_widget_show (mailcmd_checkbtn);
1344         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_checkbtn, 0, 4, 5, 6,
1345                           GTK_EXPAND | GTK_FILL,
1346                           0, 0, TABLE_YPAD);
1347         g_signal_connect(G_OBJECT(mailcmd_checkbtn), "toggled",
1348                          G_CALLBACK(prefs_account_mailcmd_toggled),
1349                          NULL);
1350
1351         mailcmd_label = gtk_label_new (_("command to send mails"));
1352         gtk_widget_show (mailcmd_label);
1353         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 6, 7,
1354                           GTK_FILL, 0, 0, 0);
1355         gtk_misc_set_alignment (GTK_MISC (mailcmd_label), 1, 0.5);
1356 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1357
1358         uid_label = gtk_label_new (_("User ID"));
1359         gtk_widget_show (uid_label);
1360         gtk_table_attach (GTK_TABLE (serv_table), uid_label, 0, 1, 7, 8,
1361                           GTK_FILL, 0, 0, 0);
1362         gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
1363
1364         pass_label = gtk_label_new (_("Password"));
1365         gtk_widget_show (pass_label);
1366 #ifndef GENERIC_UMPC
1367         gtk_table_attach (GTK_TABLE (serv_table), pass_label, 2, 3, 7, 8,
1368                           0, 0, 0, 0);
1369 #else
1370         gtk_misc_set_alignment (GTK_MISC (pass_label), 1, 0.5);
1371         gtk_table_attach (GTK_TABLE (serv_table), pass_label, 0, 1, 8, 9,
1372                           GTK_FILL, 0, 0, 0);
1373 #endif
1374
1375         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
1376         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
1377         gtk_widget_show(showpwd_checkbtn);
1378         gtk_table_attach (GTK_TABLE (serv_table), showpwd_checkbtn, 3, 4, 9, 10,
1379                         GTK_FILL, 0, 0, 0);
1380         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
1381                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), pass_entry);
1382
1383         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, uid_label);
1384         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, pass_label);
1385         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, uid_entry);
1386         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, pass_entry);
1387         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, showpwd_checkbtn);
1388         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, nntpauth_onconnect_checkbtn);
1389
1390         page->acname_entry   = acname_entry;
1391         page->default_checkbtn = default_checkbtn;
1392
1393         page->name_entry = name_entry;
1394         page->addr_entry = addr_entry;
1395         page->org_entry  = org_entry;
1396
1397         page->serv_frame       = serv_frame;
1398         page->serv_table       = serv_table;
1399         page->protocol_optmenu = (gpointer)protocol_optmenu;
1400         page->recvserv_label   = recvserv_label;
1401         page->recvserv_entry   = recvserv_entry;
1402         page->smtpserv_label   = smtpserv_label;
1403         page->smtpserv_entry   = smtpserv_entry;
1404         page->nntpserv_label   = nntpserv_label;
1405         page->nntpserv_entry   = nntpserv_entry;
1406         page->nntpauth_checkbtn  = nntpauth_checkbtn;
1407         page->nntpauth_onconnect_checkbtn  = nntpauth_onconnect_checkbtn;
1408         page->localmbox_label   = localmbox_label;
1409         page->localmbox_entry   = localmbox_entry;
1410         page->mailcmd_checkbtn   = mailcmd_checkbtn;
1411         page->mailcmd_label   = mailcmd_label;
1412         page->mailcmd_entry   = mailcmd_entry;
1413         page->uid_label        = uid_label;
1414         page->pass_label       = pass_label;
1415         page->uid_entry        = uid_entry;
1416         page->pass_entry       = pass_entry;
1417         page->showpwd_checkbtn = showpwd_checkbtn;
1418         page->auto_configure_btn = auto_configure_btn;
1419         page->auto_configure_cancel_btn = auto_configure_cancel_btn;
1420         page->auto_configure_lbl = auto_configure_lbl;
1421
1422         if (new_account) {
1423                 PrefsAccount *def_ac;
1424
1425                 prefs_set_dialog_to_default(basic_param);
1426                 buf = g_strdup_printf(_("Account%d"), ac_prefs->account_id);
1427                 gtk_entry_set_text(GTK_ENTRY(basic_page.acname_entry), buf);
1428                 g_free(buf);
1429                 def_ac = account_get_default();
1430                 if (def_ac) {
1431                         FolderItem *item = folder_get_default_inbox_for_class(F_MH);
1432                         gtk_entry_set_text(GTK_ENTRY(basic_page.name_entry),
1433                                            def_ac->name ? def_ac->name : "");
1434                         gtk_entry_set_text(GTK_ENTRY(basic_page.addr_entry),
1435                                            def_ac->address ? def_ac->address : "");
1436                         gtk_entry_set_text(GTK_ENTRY(basic_page.org_entry),
1437                                            def_ac->organization ? def_ac->organization : "");
1438                         if (!item) {
1439                                 item = folder_get_default_inbox();
1440                         }
1441                         if (item) {
1442                                 gchar *id = folder_item_get_identifier(item);
1443                                 gtk_entry_set_text(GTK_ENTRY(receive_page.inbox_entry),
1444                                         id);
1445                                 gtk_entry_set_text(GTK_ENTRY(receive_page.local_inbox_entry),
1446                                         id);
1447                                 g_free(id);
1448                         }
1449                 }
1450         } else {
1451                 prefs_set_dialog(basic_param);
1452
1453                 /* Passwords are handled outside of PrefParams. */
1454                 buf = passwd_store_get_account(ac_prefs->account_id,
1455                                 PWS_ACCOUNT_RECV);
1456                 gtk_entry_set_text(GTK_ENTRY(page->pass_entry), buf != NULL ? buf : "");
1457                 if (buf != NULL) {
1458                         memset(buf, 0, strlen(buf));
1459                         g_free(buf);
1460                 }
1461         }
1462
1463         page->vbox = vbox1;
1464
1465         page->page.widget = vbox1;
1466 }
1467
1468 static void receive_create_widget_func(PrefsPage * _page,
1469                                            GtkWindow * window,
1470                                            gpointer data)
1471 {
1472         ReceivePage *page = (ReceivePage *) _page;
1473         PrefsAccount *ac_prefs = (PrefsAccount *) data;
1474
1475         GtkWidget *vbox1;
1476         GtkWidget *frame1;
1477         GtkWidget *vbox2;
1478         GtkWidget *use_apop_checkbtn;
1479         GtkWidget *rmmail_checkbtn;
1480         GtkWidget *hbox_spc;
1481         GtkWidget *leave_time_label;
1482         GtkWidget *leave_time_spinbtn;
1483         GtkWidget *leave_hour_label;
1484         GtkWidget *leave_hour_spinbtn;
1485         GtkWidget *hbox1;
1486         GtkWidget *size_limit_checkbtn;
1487         GtkWidget *size_limit_spinbtn;
1488         GtkWidget *label;
1489         GtkWidget *filter_on_recv_checkbtn;
1490         GtkWidget *filterhook_on_recv_checkbtn;
1491         GtkWidget *vbox3;
1492         GtkWidget *inbox_label;
1493         GtkWidget *inbox_entry;
1494         GtkWidget *inbox_btn;
1495         GtkWidget *imap_frame;
1496         GtkWidget *imapdir_label;
1497         GtkWidget *imapdir_entry;
1498         GtkWidget *subsonly_checkbtn;
1499         GtkWidget *low_bandwidth_checkbtn;
1500         GtkWidget *local_frame;
1501         GtkWidget *local_vbox;
1502         GtkWidget *local_hbox;
1503         GtkWidget *local_inbox_label;
1504         GtkWidget *local_inbox_entry;
1505         GtkWidget *local_inbox_btn;
1506
1507         GtkWidget *optmenu;
1508         GtkListStore *menu;
1509         GtkTreeIter iter;
1510         GtkWidget *recvatgetall_checkbtn;
1511
1512         GtkWidget *hbox2;
1513         GtkWidget *frame2;
1514         GtkWidget *maxarticle_label;
1515         GtkWidget *maxarticle_spinbtn;
1516         GtkAdjustment *maxarticle_spinbtn_adj;
1517
1518         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1519         gtk_widget_show (vbox1);
1520         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1521
1522         local_vbox = gtkut_get_options_frame(vbox1, &local_frame, _("Local"));
1523
1524         local_hbox = gtk_hbox_new (FALSE, 8);
1525         gtk_widget_show (local_hbox);
1526         gtk_box_pack_start (GTK_BOX (local_vbox), local_hbox, FALSE, FALSE, 0);
1527
1528         local_inbox_label = gtk_label_new (_("Default Inbox"));
1529         gtk_widget_show (local_inbox_label);
1530         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_label, FALSE, FALSE, 0);
1531
1532         local_inbox_entry = gtk_entry_new ();
1533         gtk_widget_show (local_inbox_entry);
1534         CLAWS_SET_TIP(local_inbox_entry,
1535                              _("Unfiltered messages will be stored in this folder"));
1536         gtk_widget_set_size_request (local_inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
1537         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_entry, TRUE, TRUE, 0);
1538
1539         local_inbox_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
1540         gtk_widget_show (local_inbox_btn);
1541         CLAWS_SET_TIP(local_inbox_btn,
1542                              _("Unfiltered messages will be stored in this folder"));
1543         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_btn, FALSE, FALSE, 0);
1544         g_signal_connect (G_OBJECT (local_inbox_btn), "clicked",
1545                           G_CALLBACK (prefs_account_select_folder_cb),
1546                           local_inbox_entry);
1547
1548         vbox2 = gtkut_get_options_frame(vbox1, &frame1, _("POP"));
1549         PACK_CHECK_BUTTON (vbox2, use_apop_checkbtn,
1550                            _("Use secure authentication (APOP)"));
1551
1552         PACK_CHECK_BUTTON (vbox2, rmmail_checkbtn,
1553                            _("Remove messages on server when received"));
1554
1555         hbox1 = gtk_hbox_new (FALSE, 8);
1556         gtk_widget_show (hbox1);
1557         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1558
1559         hbox_spc = gtk_hbox_new (FALSE, 0);
1560         gtk_widget_show (hbox_spc);
1561         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1562         gtk_widget_set_size_request (hbox_spc, 12, -1);
1563
1564         leave_time_label = gtk_label_new (_("Remove after"));
1565         gtk_widget_show (leave_time_label);
1566         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1567
1568         leave_time_spinbtn = gtk_spin_button_new_with_range(0, 365, 1);
1569         gtk_widget_show (leave_time_spinbtn);
1570         CLAWS_SET_TIP(leave_time_spinbtn,
1571                              _("0 days and 0 hours : remove immediately"));
1572         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_spinbtn, FALSE, FALSE, 0);
1573
1574         leave_time_label = gtk_label_new (_("days"));
1575         gtk_widget_show (leave_time_label);
1576         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1577
1578         leave_hour_spinbtn = gtk_spin_button_new_with_range(0, 23, 1);
1579         gtk_widget_show (leave_hour_spinbtn);
1580         CLAWS_SET_TIP(leave_hour_spinbtn,
1581                              _("0 days and 0 hours : remove immediately"));
1582         gtk_box_pack_start (GTK_BOX (hbox1), leave_hour_spinbtn, FALSE, FALSE, 0);
1583
1584         leave_hour_label = gtk_label_new (_("hours"));
1585         gtk_widget_show (leave_hour_label);
1586         gtk_box_pack_start (GTK_BOX (hbox1), leave_hour_label, FALSE, FALSE, 0);
1587
1588         SET_TOGGLE_SENSITIVITY (rmmail_checkbtn, hbox1);
1589
1590         hbox1 = gtk_hbox_new (FALSE, 8);
1591         gtk_widget_show (hbox1);
1592         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1593
1594         PACK_CHECK_BUTTON (hbox1, size_limit_checkbtn, _("Receive size limit"));
1595
1596         CLAWS_SET_TIP(size_limit_checkbtn,
1597                              _("Messages over this limit will be partially retrieved. "
1598                                "When selecting them you will be able to download them fully "
1599                                "or delete them."));
1600
1601         size_limit_spinbtn = gtk_spin_button_new_with_range(0, 100000, 1);
1602         gtk_widget_show (size_limit_spinbtn);
1603         gtk_box_pack_start (GTK_BOX (hbox1), size_limit_spinbtn, FALSE, FALSE, 0);
1604
1605         label = gtk_label_new (_("KB"));
1606         gtk_widget_show (label);
1607         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1608
1609         SET_TOGGLE_SENSITIVITY (size_limit_checkbtn, size_limit_spinbtn);
1610
1611         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1612
1613         hbox1 = gtk_hbox_new (FALSE, 8);
1614         gtk_widget_show (hbox1);
1615         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1616
1617         inbox_label = gtk_label_new (_("Default Inbox"));
1618         gtk_widget_show (inbox_label);
1619         gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
1620
1621         inbox_entry = gtk_entry_new ();
1622         gtk_widget_show (inbox_entry);
1623         CLAWS_SET_TIP(inbox_entry,
1624                              _("Unfiltered messages will be stored in this folder"));
1625         gtk_widget_set_size_request (inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
1626         gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
1627
1628         inbox_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
1629         gtk_widget_show (inbox_btn);
1630         CLAWS_SET_TIP(inbox_btn,
1631                              _("Unfiltered messages will be stored in this folder"));
1632         gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1633         g_signal_connect (G_OBJECT (inbox_btn), "clicked",
1634                           G_CALLBACK (prefs_account_select_folder_cb),
1635                           inbox_entry);
1636
1637         vbox2 = gtkut_get_options_frame(vbox1, &frame2, _("NNTP"));
1638
1639         hbox2 = gtk_hbox_new (FALSE, 8);
1640         gtk_widget_show (hbox2);
1641         gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
1642
1643         maxarticle_label = gtk_label_new
1644                 (_("Maximum number of articles to download"));
1645         gtk_widget_show (maxarticle_label);
1646         gtk_box_pack_start (GTK_BOX (hbox2), maxarticle_label, FALSE, FALSE, 0);
1647
1648         maxarticle_spinbtn_adj =
1649                 GTK_ADJUSTMENT(gtk_adjustment_new (300, 0, 10000, 10, 100, 0));
1650         maxarticle_spinbtn = gtk_spin_button_new
1651                 (GTK_ADJUSTMENT (maxarticle_spinbtn_adj), 10, 0);
1652         gtk_widget_show (maxarticle_spinbtn);
1653         CLAWS_SET_TIP(maxarticle_spinbtn,
1654                              _("unlimited if 0 is specified"));
1655         gtk_box_pack_start (GTK_BOX (hbox2), maxarticle_spinbtn,
1656                             FALSE, FALSE, 0);
1657         gtk_widget_set_size_request (maxarticle_spinbtn, 64, -1);
1658         gtk_spin_button_set_numeric
1659                 (GTK_SPIN_BUTTON (maxarticle_spinbtn), TRUE);
1660
1661         vbox2 = gtkut_get_options_frame(vbox1, &imap_frame, _("IMAP"));
1662
1663         hbox1 = gtk_hbox_new (FALSE, 8);
1664         gtk_widget_show (hbox1);
1665         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1666
1667         label = gtk_label_new (_("Authentication method"));
1668         gtk_widget_show (label);
1669         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1670
1671
1672         optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1673         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1674         gtk_widget_show (optmenu);
1675         gtk_box_pack_start (GTK_BOX (hbox1), optmenu, FALSE, FALSE, 0);
1676
1677         COMBOBOX_ADD (menu, _("Automatic"), 0);
1678         COMBOBOX_ADD (menu, NULL, 0);
1679         COMBOBOX_ADD (menu, _("Plain text"), IMAP_AUTH_PLAINTEXT);
1680         COMBOBOX_ADD (menu, "CRAM-MD5", IMAP_AUTH_CRAM_MD5);
1681         COMBOBOX_ADD (menu, "ANONYMOUS", IMAP_AUTH_ANON);
1682         COMBOBOX_ADD (menu, "GSSAPI", IMAP_AUTH_GSSAPI);
1683         COMBOBOX_ADD (menu, "DIGEST-MD5", IMAP_AUTH_DIGEST_MD5);
1684         COMBOBOX_ADD (menu, "SCRAM-SHA-1", IMAP_AUTH_SCRAM_SHA1);
1685         COMBOBOX_ADD (menu, "PLAIN", IMAP_AUTH_PLAIN);
1686         COMBOBOX_ADD (menu, "LOGIN", IMAP_AUTH_LOGIN);
1687
1688         hbox1 = gtk_hbox_new (FALSE, 8);
1689         gtk_widget_show (hbox1);
1690         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1691
1692         imapdir_label = gtk_label_new (_("IMAP server directory"));
1693         gtk_widget_show (imapdir_label);
1694         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1695
1696         imapdir_label = gtk_label_new(_("(usually empty)"));
1697         gtk_widget_show (imapdir_label);
1698         gtkut_widget_set_small_font_size (imapdir_label);
1699         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1700
1701         imapdir_entry = gtk_entry_new();
1702         gtk_widget_show (imapdir_entry);
1703         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, FALSE, FALSE, 0);
1704
1705         hbox1 = gtk_hbox_new (FALSE, 8);
1706         gtk_widget_show (hbox1);
1707         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1708
1709         PACK_CHECK_BUTTON (hbox1, subsonly_checkbtn,
1710                            _("Show subscribed folders only"));
1711
1712         hbox1 = gtk_hbox_new (FALSE, 8);
1713         gtk_widget_show (hbox1);
1714         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1715
1716         PACK_CHECK_BUTTON (hbox1, low_bandwidth_checkbtn,
1717                            _("Bandwidth-efficient mode (prevents retrieving remote tags)"));
1718         CLAWS_SET_TIP(low_bandwidth_checkbtn,
1719                              _("This mode uses less bandwidth, but can be slower with some servers."));
1720
1721         hbox1 = gtk_hbox_new (FALSE, 8);
1722         gtk_widget_show (hbox1);
1723         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1724
1725         PACK_CHECK_BUTTON (vbox1, filter_on_recv_checkbtn,
1726                            _("Filter messages on receiving"));
1727
1728         g_signal_connect(G_OBJECT(filter_on_recv_checkbtn), "toggled",
1729                          G_CALLBACK(prefs_account_filter_on_recv_toggled),
1730                          NULL);
1731
1732         PACK_CHECK_BUTTON (vbox1, filterhook_on_recv_checkbtn,
1733                            _("Allow filtering using plugins on receiving"));
1734
1735         PACK_CHECK_BUTTON
1736                 (vbox1, recvatgetall_checkbtn,
1737                  _("'Get Mail' checks for new messages on this account"));
1738
1739         page->pop3_frame               = frame1;
1740         page->use_apop_checkbtn          = use_apop_checkbtn;
1741         page->rmmail_checkbtn            = rmmail_checkbtn;
1742         page->leave_time_spinbtn         = leave_time_spinbtn;
1743         page->leave_hour_spinbtn         = leave_hour_spinbtn;
1744         page->size_limit_checkbtn        = size_limit_checkbtn;
1745         page->size_limit_spinbtn         = size_limit_spinbtn;
1746         page->filter_on_recv_checkbtn    = filter_on_recv_checkbtn;
1747         page->filterhook_on_recv_checkbtn = filterhook_on_recv_checkbtn;
1748         page->inbox_label              = inbox_label;
1749         page->inbox_entry              = inbox_entry;
1750         page->inbox_btn                = inbox_btn;
1751
1752         page->imap_frame               = imap_frame;
1753         page->imap_auth_type_optmenu   = optmenu;
1754
1755         page->imapdir_label             = imapdir_label;
1756         page->imapdir_entry             = imapdir_entry;
1757         page->subsonly_checkbtn         = subsonly_checkbtn;
1758         page->low_bandwidth_checkbtn    = low_bandwidth_checkbtn;
1759         page->local_frame               = local_frame;
1760         page->local_inbox_label = local_inbox_label;
1761         page->local_inbox_entry = local_inbox_entry;
1762         page->local_inbox_btn           = local_inbox_btn;
1763
1764         page->recvatgetall_checkbtn      = recvatgetall_checkbtn;
1765
1766         page->frame_maxarticle  = frame2;
1767         page->maxarticle_spinbtn        = maxarticle_spinbtn;
1768         page->maxarticle_spinbtn_adj    = maxarticle_spinbtn_adj;
1769
1770         tmp_ac_prefs = *ac_prefs;
1771
1772         if (new_account) {
1773                 prefs_set_dialog_to_default(receive_param);
1774         } else
1775                 prefs_set_dialog(receive_param);
1776
1777         page->vbox = vbox1;
1778
1779         page->page.widget = vbox1;
1780 }
1781
1782 static void send_create_widget_func(PrefsPage * _page,
1783                                            GtkWindow * window,
1784                                            gpointer data)
1785 {
1786         SendPage *page = (SendPage *) _page;
1787         PrefsAccount *ac_prefs = (PrefsAccount *) data;
1788
1789         GtkWidget *vbox1;
1790         GtkWidget *vbox2;
1791         GtkWidget *frame;
1792         GtkWidget *msgid_checkbtn;
1793         GtkWidget *xmailer_checkbtn;
1794         GtkWidget *hbox;
1795         GtkWidget *customhdr_checkbtn;
1796         GtkWidget *customhdr_edit_btn;
1797         GtkWidget *checkbtn_msgid_with_addr;
1798         GtkWidget *vbox3;
1799         GtkWidget *smtp_auth_checkbtn;
1800         GtkWidget *showpwd_checkbtn;
1801         GtkWidget *optmenu;
1802         GtkListStore *menu;
1803         GtkTreeIter iter;
1804         GtkWidget *vbox4;
1805         GtkWidget *hbox_spc;
1806         GtkWidget *label;
1807         GtkWidget *smtp_uid_entry;
1808         GtkWidget *smtp_pass_entry;
1809         GtkWidget *vbox_spc;
1810         GtkWidget *pop_bfr_smtp_checkbtn;
1811         GtkWidget *pop_bfr_smtp_tm_spinbtn;
1812         GtkWidget *pop_auth_timeout_lbl;
1813         GtkWidget *pop_auth_minutes_lbl;
1814         gchar *buf;
1815
1816         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1817         gtk_widget_show (vbox1);
1818         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1819
1820         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Header"));
1821
1822         PACK_CHECK_BUTTON (vbox2, msgid_checkbtn, _("Generate Message-ID"));
1823
1824         PACK_CHECK_BUTTON (vbox2, checkbtn_msgid_with_addr,
1825                            _("Send account mail address in Message-ID"));
1826
1827         PACK_CHECK_BUTTON (vbox2, xmailer_checkbtn,
1828                            _("Add user agent header"));
1829
1830         hbox = gtk_hbox_new (FALSE, 12);
1831         gtk_widget_show (hbox);
1832         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1833
1834         PACK_CHECK_BUTTON (hbox, customhdr_checkbtn,
1835                            _("Add user-defined header"));
1836
1837         customhdr_edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT);
1838         gtk_widget_show (customhdr_edit_btn);
1839         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1840                             FALSE, FALSE, 0);
1841         g_signal_connect (G_OBJECT (customhdr_edit_btn), "clicked",
1842                           G_CALLBACK (prefs_account_edit_custom_header),
1843                           NULL);
1844
1845         SET_TOGGLE_SENSITIVITY (customhdr_checkbtn, customhdr_edit_btn);
1846
1847         vbox3 = gtkut_get_options_frame(vbox1, &frame, _("Authentication"));
1848
1849         PACK_CHECK_BUTTON (vbox3, smtp_auth_checkbtn,
1850                 _("SMTP Authentication (SMTP AUTH)"));
1851
1852         vbox4 = gtk_vbox_new (FALSE, 0);
1853         gtk_widget_show (vbox4);
1854         gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
1855
1856         hbox = gtk_hbox_new (FALSE, 8);
1857         gtk_widget_show (hbox);
1858         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1859
1860         hbox_spc = gtk_hbox_new (FALSE, 0);
1861         gtk_widget_show (hbox_spc);
1862         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1863         gtk_widget_set_size_request (hbox_spc, 12, -1);
1864
1865         label = gtk_label_new (_("Authentication method"));
1866         gtk_widget_show (label);
1867         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1868
1869         optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1870         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1871         gtk_widget_show (optmenu);
1872         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
1873
1874         COMBOBOX_ADD (menu, _("Automatic"), 0);
1875         COMBOBOX_ADD (menu, NULL, 0);
1876         COMBOBOX_ADD (menu, "PLAIN", SMTPAUTH_PLAIN);
1877         COMBOBOX_ADD (menu, "LOGIN", SMTPAUTH_LOGIN);
1878         COMBOBOX_ADD (menu, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
1879         COMBOBOX_ADD (menu, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
1880         gtk_list_store_set(menu, &iter, COMBOBOX_SENS, FALSE, -1);
1881
1882         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1883
1884         hbox = gtk_hbox_new (FALSE, 8);
1885         gtk_widget_show (hbox);
1886         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1887
1888         hbox_spc = gtk_hbox_new (FALSE, 0);
1889         gtk_widget_show (hbox_spc);
1890         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1891         gtk_widget_set_size_request (hbox_spc, 12, -1);
1892
1893         label = gtk_label_new (_("User ID"));
1894         gtk_widget_show (label);
1895         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1896
1897         smtp_uid_entry = gtk_entry_new ();
1898         gtk_widget_show (smtp_uid_entry);
1899         gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1900         gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
1901         g_signal_connect(G_OBJECT(smtp_uid_entry), "changed",
1902                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1903                         GINT_TO_POINTER(ac_prefs->protocol));
1904
1905 #ifdef GENERIC_UMPC
1906         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1907         hbox = gtk_hbox_new (FALSE, 8);
1908         gtk_widget_show (hbox);
1909         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1910
1911         hbox_spc = gtk_hbox_new (FALSE, 0);
1912         gtk_widget_show (hbox_spc);
1913         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1914         gtk_widget_set_size_request (hbox_spc, 12, -1);
1915 #endif
1916         label = gtk_label_new (_("Password"));
1917         gtk_widget_show (label);
1918         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1919
1920         smtp_pass_entry = gtk_entry_new ();
1921         gtk_widget_show (smtp_pass_entry);
1922         gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1923         gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
1924         gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
1925         g_signal_connect(G_OBJECT(smtp_pass_entry), "changed",
1926                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1927                         GINT_TO_POINTER(ac_prefs->protocol));
1928
1929         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
1930         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
1931         gtk_widget_show(showpwd_checkbtn);
1932         gtk_box_pack_start(GTK_BOX (hbox), showpwd_checkbtn, FALSE, FALSE, 0);
1933         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
1934                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), smtp_pass_entry);
1935
1936         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1937
1938         hbox = gtk_hbox_new (FALSE, 8);
1939         gtk_widget_show (hbox);
1940         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1941
1942         hbox_spc = gtk_hbox_new (FALSE, 0);
1943         gtk_widget_show (hbox_spc);
1944         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1945         gtk_widget_set_size_request (hbox_spc, 12, -1);
1946
1947         label = gtk_label_new
1948                 (_("If you leave these entries empty, the same "
1949                    "user ID and password as receiving will be used."));
1950         gtk_widget_show (label);
1951         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1952         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1953         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1954         gtkut_widget_set_small_font_size (label);
1955
1956         SET_TOGGLE_SENSITIVITY (smtp_auth_checkbtn, vbox4);
1957
1958         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_checkbtn,
1959                 _("Authenticate with POP before sending"));
1960         
1961         g_signal_connect (G_OBJECT (pop_bfr_smtp_checkbtn), "clicked",
1962                           G_CALLBACK (pop_bfr_smtp_tm_set_sens),
1963                           NULL);
1964
1965         hbox = gtk_hbox_new (FALSE, 8);
1966         gtk_widget_show (hbox);
1967         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
1968
1969         hbox_spc = gtk_hbox_new (FALSE, 0);
1970         gtk_widget_show (hbox_spc);
1971         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1972         gtk_widget_set_size_request (hbox_spc, 12, -1);
1973
1974         pop_auth_timeout_lbl = gtk_label_new(_("POP authentication timeout"));
1975         gtk_widget_show (pop_auth_timeout_lbl);
1976         gtk_box_pack_start (GTK_BOX (hbox), pop_auth_timeout_lbl, FALSE, FALSE, 0);
1977
1978         pop_bfr_smtp_tm_spinbtn = gtk_spin_button_new_with_range(0, 1440, 1);
1979         gtk_widget_show (pop_bfr_smtp_tm_spinbtn);
1980         gtk_box_pack_start (GTK_BOX (hbox), pop_bfr_smtp_tm_spinbtn, FALSE, FALSE, 0);
1981
1982         pop_auth_minutes_lbl = gtk_label_new(_("minutes"));
1983         gtk_widget_show (pop_auth_minutes_lbl);
1984         gtk_box_pack_start (GTK_BOX (hbox), pop_auth_minutes_lbl, FALSE, FALSE, 0);
1985         
1986         page->msgid_checkbtn     = msgid_checkbtn;
1987         page->xmailer_checkbtn   = xmailer_checkbtn;
1988         page->customhdr_checkbtn = customhdr_checkbtn;
1989         page->msgid_with_addr_checkbtn  = checkbtn_msgid_with_addr;
1990
1991         page->smtp_auth_checkbtn       = smtp_auth_checkbtn;
1992         page->smtp_auth_type_optmenu = optmenu;
1993         page->smtp_uid_entry         = smtp_uid_entry;
1994         page->smtp_pass_entry        = smtp_pass_entry;
1995         page->pop_bfr_smtp_checkbtn    = pop_bfr_smtp_checkbtn;
1996         page->pop_bfr_smtp_tm_spinbtn  = pop_bfr_smtp_tm_spinbtn;
1997         page->pop_auth_timeout_lbl   = pop_auth_timeout_lbl;
1998         page->pop_auth_minutes_lbl   = pop_auth_minutes_lbl;
1999
2000         tmp_ac_prefs = *ac_prefs;
2001
2002         if (new_account) {
2003                 prefs_set_dialog_to_default(send_param);
2004         } else {
2005                 prefs_set_dialog(send_param);
2006
2007                 /* Passwords are handled outside of PrefParams. */
2008                 buf = passwd_store_get_account(ac_prefs->account_id,
2009                                 PWS_ACCOUNT_SEND);
2010                 gtk_entry_set_text(GTK_ENTRY(page->smtp_pass_entry), buf != NULL ? buf : "");
2011                 if (buf != NULL) {
2012                         memset(buf, 0, strlen(buf));
2013                         g_free(buf);
2014                 }
2015         }
2016
2017         pop_bfr_smtp_tm_set_sens (NULL, NULL);
2018
2019         page->vbox = vbox1;
2020
2021         page->page.widget = vbox1;
2022 }
2023         
2024 static void compose_create_widget_func(PrefsPage * _page,
2025                                            GtkWindow * window,
2026                                            gpointer data)
2027 {
2028         ComposePage *page = (ComposePage *) _page;
2029         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2030
2031         GtkWidget *vbox1;
2032         GtkWidget *sig_hbox;
2033         GtkWidget *hbox1;
2034         GtkWidget *hbox2;
2035         GtkWidget *frame_sig;
2036         GtkWidget *vbox_sig;
2037         GtkWidget *label_sigpath;
2038         GtkWidget *checkbtn_autosig;
2039         GtkWidget *label_sigsep;
2040         GtkWidget *entry_sigsep;
2041         GtkWidget *frame;
2042         GtkWidget *table;
2043         GtkWidget *autocc_checkbtn;
2044         GtkWidget *autocc_entry;
2045         GtkWidget *autobcc_checkbtn;
2046         GtkWidget *autobcc_entry;
2047         GtkWidget *autoreplyto_checkbtn;
2048         GtkWidget *autoreplyto_entry;
2049 #if USE_ENCHANT
2050         GtkWidget *frame_dict;
2051         GtkWidget *table_dict;
2052         GtkWidget *checkbtn_enable_default_dictionary = NULL;
2053         GtkWidget *combo_default_dictionary = NULL;
2054         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
2055         GtkWidget *combo_default_alt_dictionary = NULL;
2056 #endif
2057
2058         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2059         gtk_widget_show (vbox1);
2060         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2061
2062         vbox_sig = gtkut_get_options_frame(vbox1, &frame_sig, _("Signature"));
2063
2064         PACK_CHECK_BUTTON (vbox_sig, checkbtn_autosig,
2065                            _("Automatically insert signature"));
2066
2067         hbox1 = gtk_hbox_new (FALSE, 8);
2068         gtk_widget_show (hbox1);
2069         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox1, TRUE, TRUE, 0);
2070         label_sigsep = gtk_label_new (_("Signature separator"));
2071         gtk_widget_show (label_sigsep);
2072         gtk_box_pack_start (GTK_BOX (hbox1), label_sigsep, FALSE, FALSE, 0);
2073
2074         entry_sigsep = gtk_entry_new ();
2075         gtk_widget_show (entry_sigsep);
2076         gtk_box_pack_start (GTK_BOX (hbox1), entry_sigsep, FALSE, FALSE, 0);
2077
2078         gtk_widget_set_size_request (entry_sigsep, 64, -1);
2079
2080         sig_hbox = gtk_hbox_new (FALSE, 8);
2081         gtk_widget_show (sig_hbox);
2082         gtk_box_pack_start (GTK_BOX (vbox_sig), sig_hbox, FALSE, FALSE, 0);
2083
2084         sigfile_radiobtn = gtk_radio_button_new_with_label (NULL, _("File"));
2085         gtk_widget_show (sigfile_radiobtn);
2086         gtk_box_pack_start (GTK_BOX (sig_hbox), sigfile_radiobtn,
2087                             FALSE, FALSE, 0);
2088         g_object_set_data (G_OBJECT (sigfile_radiobtn),
2089                            MENU_VAL_ID,
2090                            GINT_TO_POINTER (SIG_FILE));
2091         g_signal_connect(G_OBJECT(sigfile_radiobtn), "clicked",
2092                          G_CALLBACK(prefs_account_sigfile_radiobtn_cb), NULL);
2093
2094         sigcmd_radiobtn = gtk_radio_button_new_with_label_from_widget
2095                 (GTK_RADIO_BUTTON(sigfile_radiobtn), _("Command output"));
2096         gtk_widget_show (sigcmd_radiobtn);
2097         gtk_box_pack_start (GTK_BOX (sig_hbox), sigcmd_radiobtn,
2098                             FALSE, FALSE, 0);
2099         g_object_set_data (G_OBJECT (sigcmd_radiobtn),
2100                            MENU_VAL_ID,
2101                            GINT_TO_POINTER (SIG_COMMAND));
2102         g_signal_connect(G_OBJECT(sigcmd_radiobtn), "clicked",
2103                          G_CALLBACK(prefs_account_sigcmd_radiobtn_cb), NULL);
2104
2105         hbox2 = gtk_hbox_new (FALSE, 8);
2106         gtk_widget_show (hbox2);
2107         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox2, TRUE, TRUE, 0);
2108         label_sigpath = gtk_label_new (_("Signature"));
2109         gtk_widget_show (label_sigpath);
2110         gtk_box_pack_start (GTK_BOX (hbox2), label_sigpath, FALSE, FALSE, 0);
2111
2112         entry_sigpath = gtk_entry_new ();
2113         gtk_widget_show (entry_sigpath);
2114         gtk_box_pack_start (GTK_BOX (hbox2), entry_sigpath, TRUE, TRUE, 0);
2115
2116         signature_browse_button = gtkut_get_browse_file_btn(_("Bro_wse"));
2117         gtk_widget_show (signature_browse_button);
2118         gtk_box_pack_start (GTK_BOX (hbox2), signature_browse_button, FALSE, FALSE, 0);
2119         g_signal_connect(G_OBJECT(signature_browse_button), "clicked",
2120                          G_CALLBACK(prefs_account_signature_browse_cb), NULL);
2121
2122         signature_edit_button = gtk_button_new_from_stock (GTK_STOCK_EDIT);
2123         gtk_widget_show (signature_edit_button);
2124         gtk_box_pack_start (GTK_BOX (hbox2), signature_edit_button, FALSE, FALSE, 0);
2125         g_signal_connect(G_OBJECT(signature_edit_button), "clicked",
2126                          G_CALLBACK(prefs_account_signature_edit_cb), entry_sigpath);
2127
2128         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
2129
2130         table =  gtk_table_new (3, 2, FALSE);
2131         gtk_widget_show (table);
2132         gtk_container_add (GTK_CONTAINER (frame), table);
2133         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
2134         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
2135         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
2136
2137         autocc_checkbtn = gtk_check_button_new_with_label (
2138                                 prefs_common_translated_header_name("Cc:"));
2139         gtk_widget_show (autocc_checkbtn);
2140         gtk_table_attach (GTK_TABLE (table), autocc_checkbtn, 0, 1, 0, 1,
2141                           GTK_FILL, 0, 0, 0);
2142
2143         autocc_entry = gtk_entry_new ();
2144         gtk_widget_show (autocc_entry);
2145         gtk_table_attach (GTK_TABLE (table), autocc_entry, 1, 2, 0, 1,
2146                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2147                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
2148
2149         SET_TOGGLE_SENSITIVITY (autocc_checkbtn, autocc_entry);
2150
2151         autobcc_checkbtn = gtk_check_button_new_with_label (
2152                                 prefs_common_translated_header_name("Bcc:"));
2153         gtk_widget_show (autobcc_checkbtn);
2154         gtk_table_attach (GTK_TABLE (table), autobcc_checkbtn, 0, 1, 1, 2,
2155                           GTK_FILL, 0, 0, 0);
2156
2157         autobcc_entry = gtk_entry_new ();
2158         gtk_widget_show (autobcc_entry);
2159         gtk_table_attach (GTK_TABLE (table), autobcc_entry, 1, 2, 1, 2,
2160                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2161                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
2162
2163         SET_TOGGLE_SENSITIVITY (autobcc_checkbtn, autobcc_entry);
2164
2165         autoreplyto_checkbtn = gtk_check_button_new_with_label (
2166                                 prefs_common_translated_header_name("Reply-To:"));
2167         gtk_widget_show (autoreplyto_checkbtn);
2168         gtk_table_attach (GTK_TABLE (table), autoreplyto_checkbtn, 0, 1, 2, 3,
2169                           GTK_FILL, 0, 0, 0);
2170
2171         autoreplyto_entry = gtk_entry_new ();
2172         gtk_widget_show (autoreplyto_entry);
2173         gtk_table_attach (GTK_TABLE (table), autoreplyto_entry, 1, 2, 2, 3,
2174                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2175                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
2176
2177         SET_TOGGLE_SENSITIVITY (autoreplyto_checkbtn, autoreplyto_entry);
2178
2179 #if USE_ENCHANT
2180         PACK_FRAME (vbox1, frame_dict, _("Spell check dictionaries"));
2181
2182         table_dict =  gtk_table_new (2, 2, FALSE);
2183         gtk_widget_show (table_dict);
2184         gtk_container_add (GTK_CONTAINER (frame_dict), table_dict);
2185         gtk_container_set_border_width (GTK_CONTAINER (table_dict), 8);
2186         gtk_table_set_row_spacings (GTK_TABLE (table_dict), VSPACING_NARROW_2);
2187         gtk_table_set_col_spacings (GTK_TABLE (table_dict), 8);
2188
2189         /* Default dictionary */
2190         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
2191         gtk_table_attach(GTK_TABLE(table_dict), checkbtn_enable_default_dictionary, 0, 1,
2192                         0, 1, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
2193         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
2194                         tmp_ac_prefs.enable_default_dictionary);
2195
2196         combo_default_dictionary = gtkaspell_dictionary_combo_new(TRUE);
2197         gtk_table_attach(GTK_TABLE(table_dict), combo_default_dictionary, 1, 2,
2198                         0, 1, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
2199
2200         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, combo_default_dictionary);
2201
2202         /* Default dictionary */
2203         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
2204         gtk_table_attach(GTK_TABLE(table_dict), checkbtn_enable_default_alt_dictionary, 0, 1,
2205                         1, 2, GTK_SHRINK | GTK_FILL, GTK_SHRINK, 0, 0);
2206         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
2207                         tmp_ac_prefs.enable_default_alt_dictionary);
2208
2209         combo_default_alt_dictionary = gtkaspell_dictionary_combo_new(FALSE);
2210         gtk_table_attach(GTK_TABLE(table_dict), combo_default_alt_dictionary, 1, 2,
2211                         1, 2, GTK_EXPAND | GTK_FILL, GTK_SHRINK, 0, 0);
2212
2213         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, combo_default_alt_dictionary);
2214
2215         gtk_widget_show_all(table_dict);
2216 #endif
2217
2218         page->sigfile_radiobtn = sigfile_radiobtn;
2219         page->entry_sigpath      = entry_sigpath;
2220         page->checkbtn_autosig   = checkbtn_autosig;
2221         page->entry_sigsep       = entry_sigsep;
2222
2223         page->autocc_checkbtn      = autocc_checkbtn;
2224         page->autocc_entry       = autocc_entry;
2225         page->autobcc_checkbtn     = autobcc_checkbtn;
2226         page->autobcc_entry      = autobcc_entry;
2227         page->autoreplyto_checkbtn = autoreplyto_checkbtn;
2228         page->autoreplyto_entry  = autoreplyto_entry;
2229 #ifdef USE_ENCHANT
2230         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
2231         page->combo_default_dictionary = combo_default_dictionary;
2232         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
2233         page->combo_default_alt_dictionary = combo_default_alt_dictionary;
2234 #endif
2235
2236 #ifdef USE_ENCHANT
2237         /* reset gtkaspell menus */
2238         if (compose_page.combo_default_dictionary != NULL) {
2239                 gtk_combo_box_set_model(GTK_COMBO_BOX(compose_page.combo_default_dictionary),
2240                                         gtkaspell_dictionary_store_new());
2241                 gtk_combo_box_set_model(GTK_COMBO_BOX(compose_page.combo_default_alt_dictionary),
2242                                         gtkaspell_dictionary_store_new_with_refresh(
2243                                                 FALSE));
2244         }
2245 #endif
2246
2247         tmp_ac_prefs = *ac_prefs;
2248
2249         if (new_account) {
2250                 prefs_set_dialog_to_default(compose_param);
2251         } else
2252                 prefs_set_dialog(compose_param);
2253
2254         page->vbox = vbox1;
2255
2256         page->page.widget = vbox1;
2257 }
2258         
2259 static void templates_create_widget_func(PrefsPage * _page,
2260                                            GtkWindow * window,
2261                                            gpointer data)
2262 {
2263         TemplatesPage *page = (TemplatesPage *) _page;
2264         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2265         GtkWidget *vbox;
2266         GtkWidget *vbox2;
2267         GtkWidget *notebook;
2268
2269         vbox = gtk_vbox_new(FALSE, 0);
2270         gtk_widget_show(vbox);
2271         
2272         notebook = gtk_notebook_new();
2273         gtk_widget_show(notebook);
2274         gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
2275
2276         /* compose format */
2277         vbox2 = gtk_vbox_new (FALSE, VSPACING);
2278         gtk_widget_show (vbox2);
2279         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2280
2281         quotefmt_create_new_msg_fmt_widgets(
2282                                 window,
2283                                 vbox2,
2284                                 &page->checkbtn_compose_with_format,
2285                                 NULL,
2286                                 &page->compose_subject_format,
2287                                 &page->compose_body_format,
2288                                 TRUE, NULL);
2289         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Compose")));
2290
2291         /* reply format */      
2292         vbox2 = gtk_vbox_new (FALSE, VSPACING);
2293         gtk_widget_show (vbox2);
2294         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2295         
2296         quotefmt_create_reply_fmt_widgets(
2297                                 window,
2298                                 vbox2,
2299                                 &page->checkbtn_reply_with_format,
2300                                 NULL,
2301                                 &page->reply_quotemark,
2302                                 &page->reply_body_format,
2303                                 TRUE, NULL);
2304         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Reply")));
2305
2306         /* forward format */    
2307         vbox2 = gtk_vbox_new (FALSE, VSPACING);
2308         gtk_widget_show (vbox2);
2309         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2310
2311         quotefmt_create_forward_fmt_widgets(
2312                                 window,
2313                                 vbox2,
2314                                 &page->checkbtn_forward_with_format,
2315                                 NULL,
2316                                 &page->forward_quotemark,
2317                                 &page->forward_body_format,
2318                                 TRUE, NULL);
2319         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Forward")));
2320
2321         tmp_ac_prefs = *ac_prefs;
2322
2323         if (new_account) {
2324                 prefs_set_dialog_to_default(templates_param);
2325         } else
2326                 prefs_set_dialog(templates_param);
2327
2328         page->vbox = vbox;
2329
2330         page->page.widget = vbox;
2331 }
2332
2333 static void privacy_create_widget_func(PrefsPage * _page,
2334                                            GtkWindow * window,
2335                                            gpointer data)
2336 {
2337         PrivacyPage *page = (PrivacyPage *) _page;
2338         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2339
2340         GtkWidget *vbox1;
2341         GtkWidget *vbox2;
2342         GtkWidget *hbox1;
2343         GtkWidget *label;
2344         GtkWidget *default_privacy_system;
2345         GtkListStore *menu;
2346         GtkCellRenderer *rend;
2347         GtkWidget *default_encrypt_checkbtn;
2348         GtkWidget *default_encrypt_reply_checkbtn;
2349         GtkWidget *default_sign_checkbtn;
2350         GtkWidget *default_sign_reply_checkbtn;
2351         GtkWidget *save_clear_text_checkbtn;
2352         GtkWidget *encrypt_to_self_checkbtn;
2353
2354         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2355         gtk_widget_show (vbox1);
2356         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2357
2358         vbox2 = gtk_vbox_new (FALSE, 0);
2359         gtk_widget_show (vbox2);
2360         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2361
2362         hbox1 = gtk_hbox_new(FALSE, 8);
2363         gtk_widget_show (hbox1);
2364         gtk_container_add (GTK_CONTAINER(vbox2), hbox1);
2365
2366         label = gtk_label_new(_("Default privacy system"));
2367         gtk_widget_show(label);
2368         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
2369
2370         /* Can't use gtkut_sc_combobox_create() here, because model for this
2371          * combobox needs an extra string column to store privacy plugin id. */
2372         menu = gtk_list_store_new(4,
2373                         G_TYPE_STRING,
2374                         G_TYPE_INT,
2375                         G_TYPE_BOOLEAN,
2376                         G_TYPE_STRING); /* This is where we store the privacy plugin id. */
2377         default_privacy_system = gtk_combo_box_new_with_model(GTK_TREE_MODEL(menu));
2378
2379         rend = gtk_cell_renderer_text_new();
2380         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(default_privacy_system), rend, TRUE);
2381         gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(default_privacy_system), rend,
2382                         "text", COMBOBOX_TEXT,
2383                         "sensitive", COMBOBOX_SENS,
2384                         NULL);
2385         gtk_combo_box_set_focus_on_click(GTK_COMBO_BOX(default_privacy_system), FALSE);
2386
2387         gtk_widget_show (default_privacy_system);
2388         gtk_box_pack_start (GTK_BOX(hbox1), default_privacy_system, FALSE, TRUE, 0);
2389
2390         g_signal_connect(G_OBJECT(default_privacy_system), "changed",
2391                          G_CALLBACK(privacy_system_activated),
2392                          NULL);
2393
2394         PACK_CHECK_BUTTON (vbox2, default_sign_checkbtn,
2395                            _("Always sign messages"));
2396         PACK_CHECK_BUTTON (vbox2, default_encrypt_checkbtn,
2397                            _("Always encrypt messages"));
2398         PACK_CHECK_BUTTON (vbox2, default_sign_reply_checkbtn,
2399                            _("Always sign messages when replying to a "
2400                              "signed message"));
2401         PACK_CHECK_BUTTON (vbox2, default_encrypt_reply_checkbtn,
2402                            _("Always encrypt messages when replying to an "
2403                              "encrypted message"));
2404         PACK_CHECK_BUTTON (vbox2, encrypt_to_self_checkbtn,
2405                            _("Encrypt sent messages with your own key in addition to recipient's"));
2406         PACK_CHECK_BUTTON (vbox2, save_clear_text_checkbtn,
2407                            _("Save sent encrypted messages as clear text"));
2408
2409         SET_TOGGLE_SENSITIVITY_REVERSE(encrypt_to_self_checkbtn, save_clear_text_checkbtn);
2410         SET_TOGGLE_SENSITIVITY_REVERSE(save_clear_text_checkbtn, encrypt_to_self_checkbtn);
2411
2412         page->default_privacy_system = default_privacy_system;
2413         page->default_encrypt_checkbtn = default_encrypt_checkbtn;
2414         page->default_encrypt_reply_checkbtn = default_encrypt_reply_checkbtn;
2415         page->default_sign_reply_checkbtn = default_sign_reply_checkbtn;
2416         page->default_sign_checkbtn    = default_sign_checkbtn;
2417         page->save_clear_text_checkbtn = save_clear_text_checkbtn;
2418         page->encrypt_to_self_checkbtn = encrypt_to_self_checkbtn;
2419
2420         update_privacy_system_menu();
2421
2422         tmp_ac_prefs = *ac_prefs;
2423
2424         if (new_account) {
2425                 prefs_set_dialog_to_default(privacy_param);
2426         } else
2427                 prefs_set_dialog(privacy_param);
2428
2429         page->vbox = vbox1;
2430
2431         page->page.widget = vbox1;
2432 }
2433
2434 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data)               \
2435 {                                                                       \
2436         btn = gtk_radio_button_new_with_label_from_widget               \
2437                 (GTK_RADIO_BUTTON (btn_p), label);                      \
2438         gtk_widget_show (btn);                                          \
2439         gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0);       \
2440         g_object_set_data (G_OBJECT (btn),                              \
2441                            MENU_VAL_ID,                                 \
2442                            GINT_TO_POINTER (data));                     \
2443 }
2444
2445 #ifdef USE_GNUTLS
2446
2447 #define CREATE_RADIO_BUTTONS(box,                                       \
2448                              btn1, btn1_label, btn1_data,               \
2449                              btn2, btn2_label, btn2_data,               \
2450                              btn3, btn3_label, btn3_data)               \
2451 {                                                                       \
2452         btn1 = gtk_radio_button_new_with_label(NULL, btn1_label);       \
2453         gtk_widget_show (btn1);                                         \
2454         gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0);      \
2455         g_object_set_data (G_OBJECT (btn1),                             \
2456                            MENU_VAL_ID,                                 \
2457                            GINT_TO_POINTER (btn1_data));                \
2458                                                                         \
2459         CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data);    \
2460         CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data);    \
2461 }
2462
2463 static void pop_ssltunnel_toggled(GtkToggleButton *button,
2464                                         gpointer data)
2465 {
2466         gboolean active = gtk_toggle_button_get_active(button);
2467         
2468         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2469                         advanced_page.popport_checkbtn)) == TRUE)
2470                 return;
2471         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.popport_spinbtn),
2472                                   active ? 995 : 110);
2473 }
2474
2475 static void imap_ssltunnel_toggled(GtkToggleButton *button,
2476                                         gpointer data)
2477 {
2478         gboolean active = gtk_toggle_button_get_active(button);
2479         
2480         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2481                         advanced_page.imapport_checkbtn)) == TRUE)
2482                 return;
2483         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.imapport_spinbtn),
2484                                   active ? 993 : 143);
2485 }
2486
2487 static void nntp_ssltunnel_toggled(GtkToggleButton *button,
2488                                         gpointer data)
2489 {
2490         gboolean active = gtk_toggle_button_get_active(button);
2491         
2492         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2493                         advanced_page.nntpport_checkbtn)) == TRUE)
2494                 return;
2495         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.nntpport_spinbtn),
2496                                   active ? 563 : 119);
2497 }       
2498
2499 static void smtp_ssltunnel_toggled(GtkToggleButton *button,
2500                                         gpointer data)
2501 {
2502         gboolean active = gtk_toggle_button_get_active(button);
2503         
2504         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2505                         advanced_page.smtpport_checkbtn)) == TRUE)
2506                 return;
2507         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.smtpport_spinbtn),
2508                                   active ? 465 : 25);   
2509 }
2510
2511 static void ssl_create_widget_func(PrefsPage * _page,
2512                                            GtkWindow * window,
2513                                            gpointer data)
2514 {
2515         SSLPage *page = (SSLPage *) _page;
2516         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2517
2518         GtkWidget *vbox1;
2519
2520         GtkWidget *pop_frame;
2521         GtkWidget *vbox2;
2522         GtkWidget *pop_nossl_radiobtn;
2523         GtkWidget *pop_ssltunnel_radiobtn;
2524         GtkWidget *pop_starttls_radiobtn;
2525
2526         GtkWidget *imap_frame;
2527         GtkWidget *vbox3;
2528         GtkWidget *imap_nossl_radiobtn;
2529         GtkWidget *imap_ssltunnel_radiobtn;
2530         GtkWidget *imap_starttls_radiobtn;
2531
2532         GtkWidget *nntp_frame;
2533         GtkWidget *vbox4;
2534         GtkWidget *nntp_nossl_radiobtn;
2535         GtkWidget *nntp_ssltunnel_radiobtn;
2536
2537         GtkWidget *send_frame;
2538         GtkWidget *vbox5;
2539         GtkWidget *smtp_nossl_radiobtn;
2540         GtkWidget *smtp_ssltunnel_radiobtn;
2541         GtkWidget *smtp_starttls_radiobtn;
2542
2543         GtkWidget *cert_frame;
2544         GtkWidget *cert_table;
2545         GtkWidget *entry_in_cert_pass;
2546         GtkWidget *entry_out_cert_pass;
2547         GtkWidget *showpwd_checkbtn;
2548
2549         GtkWidget *vbox7;
2550         GtkWidget *ssl_certs_auto_accept_checkbtn;
2551         GtkWidget *use_nonblocking_ssl_checkbtn;
2552         GtkWidget *hbox;
2553         GtkWidget *hbox_spc;
2554         GtkWidget *label;
2555         gchar *buf;
2556
2557         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2558         gtk_widget_show (vbox1);
2559         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2560
2561         vbox2 = gtkut_get_options_frame(vbox1, &pop_frame, _("POP"));
2562
2563         CREATE_RADIO_BUTTONS(vbox2,
2564                              pop_nossl_radiobtn,
2565                              _("Don't use SSL/TLS"),
2566                              SSL_NONE,
2567                              pop_ssltunnel_radiobtn,
2568                              _("Use SSL/TLS"),
2569                              SSL_TUNNEL,
2570                              pop_starttls_radiobtn,
2571                              _("Use STARTTLS command to start encrypted session"),
2572                              SSL_STARTTLS);
2573         g_signal_connect(G_OBJECT(pop_ssltunnel_radiobtn), "toggled",
2574                          G_CALLBACK(pop_ssltunnel_toggled), NULL);
2575         
2576         vbox3 = gtkut_get_options_frame(vbox1, &imap_frame, _("IMAP"));
2577
2578         CREATE_RADIO_BUTTONS(vbox3,
2579                              imap_nossl_radiobtn,
2580                              _("Don't use SSL/TLS"),
2581                              SSL_NONE,
2582                              imap_ssltunnel_radiobtn,
2583                              _("Use SSL/TLS"),
2584                              SSL_TUNNEL,
2585                              imap_starttls_radiobtn,
2586                              _("Use STARTTLS command to start encrypted session"),
2587                              SSL_STARTTLS);
2588         g_signal_connect(G_OBJECT(imap_ssltunnel_radiobtn), "toggled",
2589                          G_CALLBACK(imap_ssltunnel_toggled), NULL);
2590
2591         vbox4 = gtkut_get_options_frame(vbox1, &nntp_frame, _("NNTP"));
2592
2593         nntp_nossl_radiobtn =
2594                 gtk_radio_button_new_with_label (NULL, _("Don't use SSL/TLS"));
2595         gtk_widget_show (nntp_nossl_radiobtn);
2596         gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
2597                             FALSE, FALSE, 0);
2598         g_object_set_data (G_OBJECT (nntp_nossl_radiobtn),
2599                            MENU_VAL_ID,
2600                            GINT_TO_POINTER (SSL_NONE));
2601
2602         CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
2603                             _("Use SSL/TLS"), SSL_TUNNEL);
2604         g_signal_connect(G_OBJECT(nntp_ssltunnel_radiobtn), "toggled",
2605                          G_CALLBACK(nntp_ssltunnel_toggled), NULL);
2606
2607         vbox5 = gtkut_get_options_frame(vbox1, &send_frame, _("Send (SMTP)"));
2608
2609         CREATE_RADIO_BUTTONS(vbox5,
2610                              smtp_nossl_radiobtn,
2611                              _("Don't use SSL/TLS (but, if necessary, use STARTTLS)"),
2612                              SSL_NONE,
2613                              smtp_ssltunnel_radiobtn,
2614                              _("Use SSL/TLS"),
2615                              SSL_TUNNEL,
2616                              smtp_starttls_radiobtn,
2617                              _("Use STARTTLS command to start encrypted session"),
2618                              SSL_STARTTLS);
2619         g_signal_connect(G_OBJECT(smtp_ssltunnel_radiobtn), "toggled",
2620                          G_CALLBACK(smtp_ssltunnel_toggled), NULL);
2621
2622         PACK_FRAME(vbox1, cert_frame, _("Client certificates"));
2623
2624         cert_table = gtk_table_new(4,3, FALSE);
2625         gtk_container_add(GTK_CONTAINER(cert_frame), cert_table);
2626         gtk_container_set_border_width(GTK_CONTAINER(cert_table), 8);
2627         gtk_table_set_row_spacings(GTK_TABLE(cert_table), VSPACING_NARROW_2);
2628         gtk_table_set_col_spacings(GTK_TABLE(cert_table), 8);
2629         
2630         label = gtk_label_new(_("Certificate for receiving"));
2631         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
2632         entry_in_cert_file = gtk_entry_new();
2633         in_ssl_cert_browse_button = gtkut_get_browse_file_btn(_("Browse"));
2634         CLAWS_SET_TIP(label,
2635                              _("Client certificate file as a PKCS12 or PEM file"));
2636         CLAWS_SET_TIP(entry_in_cert_file,
2637                              _("Client certificate file as a PKCS12 or PEM file"));     
2638         gtk_table_attach(GTK_TABLE(cert_table), label, 0, 1, 0, 1, GTK_FILL, 0, 0, 0);
2639         gtk_table_attach(GTK_TABLE(cert_table), entry_in_cert_file, 1, 2, 0, 1,
2640                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
2641         gtk_table_attach(GTK_TABLE(cert_table), in_ssl_cert_browse_button, 2, 3, 0, 1,
2642                          GTK_FILL, 0, 0, 0);
2643
2644         label = gtk_label_new(_("Password"));
2645         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
2646         entry_in_cert_pass = gtk_entry_new();
2647         gtk_entry_set_visibility(GTK_ENTRY(entry_in_cert_pass), FALSE);
2648         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
2649         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
2650         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
2651                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), entry_in_cert_pass);
2652         gtk_table_attach(GTK_TABLE(cert_table), label, 0, 1, 1, 2, GTK_FILL, 0, 0, 0);
2653         gtk_table_attach(GTK_TABLE(cert_table), entry_in_cert_pass, 1, 2, 1, 2,
2654                          GTK_FILL, 0, 0, 0);
2655         gtk_table_attach(GTK_TABLE(cert_table), showpwd_checkbtn, 2, 3, 1, 2,
2656                         GTK_FILL, 0, 0, 0);
2657
2658         label = gtk_label_new(_("Certificate for sending"));
2659         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
2660         entry_out_cert_file = gtk_entry_new();
2661         out_ssl_cert_browse_button = gtkut_get_browse_file_btn(_("Browse"));
2662         CLAWS_SET_TIP(label,
2663                              _("Client certificate file as a PKCS12 or PEM file"));
2664         CLAWS_SET_TIP(entry_out_cert_file,
2665                              _("Client certificate file as a PKCS12 or PEM file"));
2666         gtk_table_attach(GTK_TABLE(cert_table), label, 0, 1, 2, 3, GTK_FILL, 0, 0, 0);
2667         gtk_table_attach(GTK_TABLE(cert_table), entry_out_cert_file, 1, 2, 2, 3,
2668                          GTK_EXPAND|GTK_FILL, 0, 0, 0);
2669         gtk_table_attach(GTK_TABLE(cert_table), out_ssl_cert_browse_button, 2, 3, 2, 3,
2670                          GTK_FILL, 0, 0, 0);
2671
2672         label = gtk_label_new(_("Password"));
2673         gtk_misc_set_alignment(GTK_MISC(label), 1, 0.5);
2674         entry_out_cert_pass = gtk_entry_new();
2675         gtk_entry_set_visibility(GTK_ENTRY(entry_out_cert_pass), FALSE);
2676         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
2677         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
2678         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
2679                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), entry_out_cert_pass);
2680         gtk_table_attach(GTK_TABLE(cert_table), label, 0, 1, 3, 4, GTK_FILL, 0, 0, 0);
2681         gtk_table_attach(GTK_TABLE(cert_table), entry_out_cert_pass, 1, 2, 3, 4,
2682                          GTK_FILL, 0, 0, 0);
2683         gtk_table_attach(GTK_TABLE(cert_table), showpwd_checkbtn, 2, 3, 3, 4,
2684                         GTK_FILL, 0, 0, 0);
2685
2686         gtk_widget_show_all(cert_table);
2687
2688         g_signal_connect(G_OBJECT(in_ssl_cert_browse_button), "clicked",
2689                          G_CALLBACK(prefs_account_in_cert_browse_cb), NULL);
2690         g_signal_connect(G_OBJECT(out_ssl_cert_browse_button), "clicked",
2691                          G_CALLBACK(prefs_account_out_cert_browse_cb), NULL);
2692         
2693         vbox7 = gtk_vbox_new (FALSE, 0);
2694         gtk_widget_show (vbox7);
2695         gtk_box_pack_start (GTK_BOX (vbox1), vbox7, FALSE, FALSE, 0);
2696
2697         PACK_CHECK_BUTTON(vbox7, ssl_certs_auto_accept_checkbtn,
2698                           _("Automatically accept valid SSL/TLS certificates"));
2699
2700         PACK_CHECK_BUTTON(vbox7, use_nonblocking_ssl_checkbtn,
2701                           _("Use non-blocking SSL/TLS"));
2702
2703         hbox = gtk_hbox_new (FALSE, 0);
2704         gtk_widget_show (hbox);
2705         gtk_box_pack_start (GTK_BOX (vbox7), hbox, FALSE, FALSE, 0);
2706
2707         hbox_spc = gtk_hbox_new (FALSE, 0);
2708         gtk_widget_show (hbox_spc);
2709         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2710         gtk_widget_set_size_request (hbox_spc, 16, -1);
2711
2712         label = gtk_label_new
2713                 (_("Turn this off if you have SSL/TLS connection problems"));
2714         gtk_widget_show (label);
2715         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2716         gtkut_widget_set_small_font_size (label);
2717
2718         page->pop_frame               = pop_frame;
2719         page->pop_nossl_radiobtn      = pop_nossl_radiobtn;
2720         page->pop_ssltunnel_radiobtn  = pop_ssltunnel_radiobtn;
2721         page->pop_starttls_radiobtn   = pop_starttls_radiobtn;
2722
2723         page->imap_frame              = imap_frame;
2724         page->imap_nossl_radiobtn     = imap_nossl_radiobtn;
2725         page->imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
2726         page->imap_starttls_radiobtn  = imap_starttls_radiobtn;
2727
2728         page->nntp_frame              = nntp_frame;
2729         page->nntp_nossl_radiobtn     = nntp_nossl_radiobtn;
2730         page->nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
2731
2732         page->send_frame              = send_frame;
2733         page->smtp_nossl_radiobtn     = smtp_nossl_radiobtn;
2734         page->smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
2735         page->smtp_starttls_radiobtn  = smtp_starttls_radiobtn;
2736
2737         page->entry_in_cert_file      = entry_in_cert_file;
2738         page->entry_in_cert_pass      = entry_in_cert_pass;
2739         page->entry_out_cert_file     = entry_out_cert_file;
2740         page->entry_out_cert_pass     = entry_out_cert_pass;
2741
2742         page->ssl_certs_auto_accept_checkbtn = ssl_certs_auto_accept_checkbtn;
2743         page->use_nonblocking_ssl_checkbtn = use_nonblocking_ssl_checkbtn;
2744
2745         tmp_ac_prefs = *ac_prefs;
2746
2747         if (new_account) {
2748                 prefs_set_dialog_to_default(ssl_param);
2749         } else {
2750                 prefs_set_dialog(ssl_param);
2751
2752                 /* Passwords are handled outside of PrefParams. */
2753                 buf = passwd_store_get_account(ac_prefs->account_id,
2754                                 PWS_ACCOUNT_RECV_CERT);
2755                 gtk_entry_set_text(GTK_ENTRY(page->entry_in_cert_pass), buf != NULL ? buf : "");
2756                 if (buf != NULL) {
2757                         memset(buf, 0, strlen(buf));
2758                         g_free(buf);
2759                 }
2760
2761                 buf = passwd_store_get_account(ac_prefs->account_id,
2762                                 PWS_ACCOUNT_SEND_CERT);
2763                 gtk_entry_set_text(GTK_ENTRY(page->entry_out_cert_pass), buf != NULL ? buf : "");
2764                 if (buf != NULL) {
2765                         memset(buf, 0, strlen(buf));
2766                         g_free(buf);
2767                 }
2768         }
2769
2770         page->vbox = vbox1;
2771
2772         page->page.widget = vbox1;
2773 }
2774
2775 #undef CREATE_RADIO_BUTTONS
2776 #endif /* USE_GNUTLS */
2777
2778 static void proxy_create_widget_func(PrefsPage * _page,
2779                                            GtkWindow * window,
2780                                            gpointer data)
2781 {
2782         ProxyPage *page = (ProxyPage *) _page;
2783         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2784         GtkWidget *vbox1, *vbox2, *vbox3, *vbox4;
2785         GtkWidget *proxy_frame;
2786         GtkWidget *proxy_checkbtn;
2787         GtkWidget *default_proxy_checkbtn;
2788         GtkWidget *hbox;
2789         GtkWidget *label;
2790         GtkWidget *socks4_radiobtn;
2791         GtkWidget *socks5_radiobtn;
2792         GtkWidget *proxy_host_entry;
2793         GtkWidget *proxy_port_spinbtn;
2794         GtkWidget *proxy_auth_checkbtn;
2795         GtkWidget *proxy_name_entry;
2796         GtkWidget *proxy_pass_entry;
2797         GtkWidget *proxy_send_checkbtn;
2798         GtkWidget *table;
2799         GtkWidget *button;
2800         gchar *buf;
2801
2802         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2803         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2804
2805         proxy_checkbtn = gtk_check_button_new_with_label (_("Use proxy server"));
2806         PACK_FRAME (vbox1, proxy_frame, NULL);
2807         gtk_frame_set_label_widget (GTK_FRAME(proxy_frame), proxy_checkbtn);
2808
2809         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
2810         gtk_container_add (GTK_CONTAINER (proxy_frame), vbox2);
2811         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
2812
2813         default_proxy_checkbtn =
2814                 gtk_check_button_new_with_label (C_("In account preferences, referring to whether or not use proxy settings from common preferences", "Use default settings"));
2815         CLAWS_SET_TIP(default_proxy_checkbtn,
2816                         _("Use global proxy server settings"));
2817         gtk_box_pack_start (GTK_BOX (vbox2), default_proxy_checkbtn, FALSE, FALSE, 0);
2818
2819         vbox3 = gtk_vbox_new (FALSE, VSPACING_NARROW);
2820         gtk_box_pack_start (GTK_BOX (vbox2), vbox3, FALSE, FALSE, 0);
2821
2822         hbox = gtk_hbox_new (FALSE, 8);
2823         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2824
2825         socks4_radiobtn = gtk_radio_button_new_with_label(NULL, "SOCKS4");
2826         gtk_box_pack_start (GTK_BOX (hbox), socks4_radiobtn, FALSE, FALSE, 0);
2827         g_object_set_data(G_OBJECT(socks4_radiobtn), MENU_VAL_ID,
2828                           GINT_TO_POINTER(PROXY_SOCKS4));
2829
2830         CREATE_RADIO_BUTTON(hbox, socks5_radiobtn, socks4_radiobtn, "SOCKS5",
2831                             PROXY_SOCKS5);
2832
2833         hbox = gtk_hbox_new (FALSE, 8);
2834         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2835
2836         label = gtk_label_new(_("Hostname"));
2837         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2838
2839         proxy_host_entry = gtk_entry_new();
2840         gtk_widget_set_size_request(proxy_host_entry, DEFAULT_ENTRY_WIDTH, -1);
2841         gtk_box_pack_start(GTK_BOX(hbox), proxy_host_entry, TRUE, TRUE, 0);
2842
2843         label = gtk_label_new(_("Port"));
2844         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
2845
2846         proxy_port_spinbtn = gtk_spin_button_new_with_range(0, 65535, 1080);
2847         gtk_widget_set_size_request(proxy_port_spinbtn, 64, -1);
2848         gtk_box_pack_start(GTK_BOX(hbox), proxy_port_spinbtn, FALSE, FALSE, 0);
2849
2850         vbox4 = gtk_vbox_new (FALSE, VSPACING_NARROW);
2851         gtk_box_pack_start(GTK_BOX(vbox3), vbox4, FALSE, FALSE, 0);
2852
2853         PACK_CHECK_BUTTON (vbox4, proxy_auth_checkbtn, _("Use authentication"));
2854
2855         table = gtk_table_new(2, 4, FALSE);
2856         gtk_box_pack_start (GTK_BOX (vbox4), table, FALSE, FALSE, 0);
2857
2858         label = gtk_label_new(_("Username"));
2859         gtk_table_attach(GTK_TABLE(table), label, 0, 1, 0, 1,
2860                         GTK_SHRINK | GTK_FILL,
2861                         GTK_SHRINK | GTK_FILL, 0, 0);
2862
2863         proxy_name_entry = gtk_entry_new();
2864         gtk_widget_set_size_request(proxy_name_entry, DEFAULT_ENTRY_WIDTH, -1);
2865         gtk_table_attach(GTK_TABLE(table), proxy_name_entry, 1, 2, 0, 1,
2866                         GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2867                         GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
2868
2869         label = gtk_label_new(_("Password"));
2870         gtk_table_attach(GTK_TABLE(table), label, 2, 3, 0, 1,
2871                         GTK_SHRINK | GTK_FILL,
2872                         GTK_SHRINK | GTK_FILL, 0, 0);
2873
2874         proxy_pass_entry = gtk_entry_new();
2875         gtk_widget_set_size_request(proxy_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
2876         gtk_entry_set_visibility(GTK_ENTRY(proxy_pass_entry), FALSE);
2877         gtk_table_attach(GTK_TABLE(table), proxy_pass_entry, 3, 4, 0, 1,
2878                         GTK_EXPAND | GTK_SHRINK | GTK_FILL,
2879                         GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
2880
2881         button = gtk_check_button_new_with_label(_("Show password"));
2882         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
2883         gtk_table_attach(GTK_TABLE(table), button, 3, 4, 1, 2,
2884                         GTK_SHRINK | GTK_FILL,
2885                         GTK_SHRINK | GTK_FILL, 0, 0);
2886         g_signal_connect(G_OBJECT(button), "toggled",
2887                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), proxy_pass_entry);
2888
2889         gtk_box_pack_start(GTK_BOX(vbox2), gtk_hseparator_new(), FALSE, FALSE, 0);
2890
2891         PACK_CHECK_BUTTON(vbox2, proxy_send_checkbtn,
2892                           _("Use proxy server for sending"));
2893         CLAWS_SET_TIP(proxy_send_checkbtn,
2894                         _("If disabled, messages will be sent using direct connection to configured outgoing server, bypassing any configured proxy server."));
2895
2896         SET_TOGGLE_SENSITIVITY(proxy_auth_checkbtn, table);
2897         SET_TOGGLE_SENSITIVITY(socks5_radiobtn, vbox4);
2898         SET_TOGGLE_SENSITIVITY(proxy_checkbtn, vbox2);
2899         SET_TOGGLE_SENSITIVITY_REVERSE(default_proxy_checkbtn, vbox3);
2900
2901         gtk_widget_show_all(vbox1);
2902
2903         page->proxy_checkbtn = proxy_checkbtn;
2904         page->default_proxy_checkbtn = default_proxy_checkbtn;
2905         page->socks4_radiobtn = socks4_radiobtn;
2906         page->socks5_radiobtn = socks5_radiobtn;
2907         page->proxy_host_entry = proxy_host_entry;
2908         page->proxy_port_spinbtn = proxy_port_spinbtn;
2909         page->proxy_auth_checkbtn = proxy_auth_checkbtn;
2910         page->proxy_name_entry = proxy_name_entry;
2911         page->proxy_pass_entry = proxy_pass_entry;
2912         page->proxy_send_checkbtn = proxy_send_checkbtn;
2913         page->vbox = vbox1;
2914         page->page.widget = vbox1;
2915
2916         tmp_ac_prefs = *ac_prefs;
2917
2918         if (new_account) {
2919                 prefs_set_dialog_to_default(proxy_param);
2920         } else
2921                 prefs_set_dialog(proxy_param);
2922
2923                 /* Passwords are handled outside of PrefParams. */
2924                 buf = passwd_store_get_account(ac_prefs->account_id,
2925                                 PWS_ACCOUNT_PROXY_PASS);
2926                 gtk_entry_set_text(GTK_ENTRY(page->proxy_pass_entry),
2927                                 buf != NULL ? buf : "");
2928                 if (buf != NULL) {
2929                         memset(buf, 0, strlen(buf));
2930                         g_free(buf);
2931                 }
2932
2933         page->vbox = vbox1;
2934
2935         page->page.widget = vbox1;
2936 }
2937
2938 static void advanced_create_widget_func(PrefsPage * _page,
2939                                            GtkWindow * window,
2940                                            gpointer data)
2941 {
2942         AdvancedPage *page = (AdvancedPage *) _page;
2943         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2944
2945         GtkWidget *vbox1;
2946         GtkWidget *vbox2;
2947         GtkWidget *hbox1;
2948         GtkWidget *checkbtn_smtpport;
2949         GtkWidget *spinbtn_smtpport;
2950         GtkWidget *hbox_popport;
2951         GtkWidget *checkbtn_popport;
2952         GtkWidget *spinbtn_popport;
2953         GtkWidget *hbox_imapport;
2954         GtkWidget *checkbtn_imapport;
2955         GtkWidget *spinbtn_imapport;
2956         GtkWidget *hbox_nntpport;
2957         GtkWidget *checkbtn_nntpport;
2958         GtkWidget *spinbtn_nntpport;
2959         GtkWidget *checkbtn_domain;
2960         GtkWidget *entry_domain;
2961         gchar *tip_domain;
2962 #if !GTK_CHECK_VERSION(3, 0, 0)
2963         GtkWidget *checkbtn_crosspost;
2964         GtkWidget *colormenu_crosspost;
2965         GtkWidget *menu;
2966 #endif
2967 #ifndef G_OS_WIN32
2968         GtkWidget *checkbtn_tunnelcmd;
2969         GtkWidget *entry_tunnelcmd;
2970 #endif
2971         GtkWidget *folder_frame;
2972         GtkWidget *vbox3;
2973         GtkWidget *table;
2974         GtkWidget *sent_folder_checkbtn;
2975         GtkWidget *sent_folder_entry;
2976         GtkWidget *queue_folder_checkbtn;
2977         GtkWidget *queue_folder_entry;
2978         GtkWidget *draft_folder_checkbtn;
2979         GtkWidget *draft_folder_entry;
2980         GtkWidget *trash_folder_checkbtn;
2981         GtkWidget *trash_folder_entry;
2982         GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
2983
2984 #define PACK_HBOX(hbox) \
2985         { \
2986         hbox = gtk_hbox_new (FALSE, 8); \
2987         gtk_widget_show (hbox); \
2988         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
2989         }
2990
2991 #define PACK_PORT_SPINBTN(box, spinbtn) \
2992         { \
2993         spinbtn = gtk_spin_button_new_with_range(0, 65535, 1); \
2994         gtk_widget_show (spinbtn); \
2995         gtk_box_pack_start (GTK_BOX (box), spinbtn, FALSE, FALSE, 0); \
2996         }
2997
2998         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2999         gtk_widget_show (vbox1);
3000         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
3001
3002         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW_2);
3003         gtk_widget_show (vbox2);
3004         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
3005
3006         PACK_HBOX (hbox1);
3007         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("SMTP port"));
3008         PACK_PORT_SPINBTN (hbox1, spinbtn_smtpport);
3009         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, spinbtn_smtpport);
3010         gtk_size_group_add_widget(size_group, checkbtn_smtpport);
3011         
3012         PACK_HBOX (hbox_popport);
3013         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
3014                            _("POP port"));
3015         PACK_PORT_SPINBTN (hbox_popport, spinbtn_popport);
3016         SET_TOGGLE_SENSITIVITY (checkbtn_popport, spinbtn_popport);
3017         gtk_size_group_add_widget(size_group, checkbtn_popport);
3018
3019         PACK_HBOX (hbox_imapport);
3020         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
3021                            _("IMAP port"));
3022         PACK_PORT_SPINBTN (hbox_imapport, spinbtn_imapport);
3023         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, spinbtn_imapport);
3024         gtk_size_group_add_widget(size_group, checkbtn_imapport);
3025
3026         PACK_HBOX (hbox_nntpport);
3027         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
3028                            _("NNTP port"));
3029         PACK_PORT_SPINBTN (hbox_nntpport, spinbtn_nntpport);
3030         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, spinbtn_nntpport);
3031         gtk_size_group_add_widget(size_group, checkbtn_nntpport);
3032
3033         PACK_HBOX (hbox1);
3034         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Domain name"));
3035         gtk_size_group_add_widget(size_group, checkbtn_domain); 
3036
3037         tip_domain = _("The domain name will be used in the generated "
3038                         "Message-ID, and when connecting to SMTP servers.");
3039
3040         CLAWS_SET_TIP(checkbtn_domain, tip_domain);
3041
3042         entry_domain = gtk_entry_new ();
3043         gtk_widget_show (entry_domain);
3044         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
3045         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
3046         CLAWS_SET_TIP(entry_domain, tip_domain);
3047
3048 #ifndef G_OS_WIN32      
3049         PACK_HBOX (hbox1);
3050         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
3051                            _("Use command to communicate with server"));
3052         entry_tunnelcmd = gtk_entry_new ();
3053         gtk_widget_show (entry_tunnelcmd);
3054         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
3055         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
3056 #endif
3057
3058 #if !GTK_CHECK_VERSION(3, 0, 0)
3059         PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost, 
3060                            _("Mark cross-posted messages as read and color:"));
3061         g_signal_connect (G_OBJECT (checkbtn_crosspost), "toggled",
3062                           G_CALLBACK (crosspost_color_toggled),
3063                           NULL);
3064
3065         colormenu_crosspost = gtk_cmoption_menu_new();
3066         gtk_widget_show (colormenu_crosspost);
3067         gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
3068
3069         menu = colorlabel_create_color_menu();
3070         gtk_cmoption_menu_set_menu (GTK_CMOPTION_MENU(colormenu_crosspost), menu);
3071         SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
3072 #endif
3073
3074         PACK_HBOX (hbox1);
3075 #undef PACK_HBOX
3076 #undef PACK_PORT_SPINBTN
3077
3078         /* special folder setting (maybe these options are redundant) */
3079
3080         vbox3 = gtkut_get_options_frame(vbox1, &folder_frame, _("Folder"));
3081
3082         table = gtk_table_new (4, 3, FALSE);
3083         gtk_widget_show (table);
3084         gtk_container_add (GTK_CONTAINER (vbox3), table);
3085         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
3086         gtk_table_set_col_spacings (GTK_TABLE (table), 4);
3087
3088 #define SET_CHECK_BTN_AND_ENTRY(label, checkbtn, entry, n)              \
3089 {                                                                       \
3090         GtkWidget *button;                                              \
3091                                                                         \
3092         checkbtn = gtk_check_button_new_with_label (label);             \
3093         gtk_widget_show (checkbtn);                                     \
3094         gtk_table_attach (GTK_TABLE (table), checkbtn,                  \
3095                           0, 1, n, n + 1, GTK_FILL, 0, 0, 0);           \
3096                                                                         \
3097         entry = gtk_entry_new ();                                       \
3098         gtk_widget_show (entry);                                        \
3099         gtk_table_attach (GTK_TABLE (table), entry, 1, 2, n, n + 1,     \
3100                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,           \
3101                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);    \
3102                                                                         \
3103         button = gtkut_get_browse_file_btn(_("Browse"));                \
3104         gtk_widget_show (button);                                       \
3105         gtk_table_attach (GTK_TABLE (table), button,                    \
3106                           2, 3, n, n + 1, GTK_FILL, 0, 0, 0);           \
3107         g_signal_connect                                                \
3108                 (G_OBJECT (button), "clicked",                  \
3109                  G_CALLBACK (prefs_account_select_folder_cb),           \
3110                  entry);                                                \
3111                                                                         \
3112         SET_TOGGLE_SENSITIVITY (checkbtn, entry);                               \
3113         SET_TOGGLE_SENSITIVITY (checkbtn, button);                      \
3114 }
3115
3116         SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
3117                                 sent_folder_checkbtn, sent_folder_entry, 0);
3118         SET_CHECK_BTN_AND_ENTRY(_("Put queued messages in"),
3119                                 queue_folder_checkbtn, queue_folder_entry, 1);
3120         SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
3121                                 draft_folder_checkbtn, draft_folder_entry, 2);
3122         SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
3123                                 trash_folder_checkbtn, trash_folder_entry, 3);
3124
3125         page->smtpport_checkbtn = checkbtn_smtpport;
3126         page->smtpport_spinbtn          = spinbtn_smtpport;
3127         page->popport_hbox              = hbox_popport;
3128         page->popport_checkbtn          = checkbtn_popport;
3129         page->popport_spinbtn           = spinbtn_popport;
3130         page->imapport_hbox             = hbox_imapport;
3131         page->imapport_checkbtn = checkbtn_imapport;
3132         page->imapport_spinbtn          = spinbtn_imapport;
3133         page->nntpport_hbox             = hbox_nntpport;
3134         page->nntpport_checkbtn = checkbtn_nntpport;
3135         page->nntpport_spinbtn          = spinbtn_nntpport;
3136         page->domain_checkbtn           = checkbtn_domain;
3137         page->domain_entry              = entry_domain;
3138 #if !GTK_CHECK_VERSION(3, 0, 0)
3139         page->crosspost_checkbtn        = checkbtn_crosspost;
3140         page->crosspost_colormenu       = colormenu_crosspost;
3141 #endif
3142
3143 #ifndef G_OS_WIN32
3144         page->tunnelcmd_checkbtn        = checkbtn_tunnelcmd;
3145         page->tunnelcmd_entry   = entry_tunnelcmd;
3146 #endif
3147         page->sent_folder_checkbtn  = sent_folder_checkbtn;
3148         page->sent_folder_entry   = sent_folder_entry;
3149         page->queue_folder_checkbtn  = queue_folder_checkbtn;
3150         page->queue_folder_entry   = queue_folder_entry;
3151         page->draft_folder_checkbtn = draft_folder_checkbtn;
3152         page->draft_folder_entry  = draft_folder_entry;
3153         page->trash_folder_checkbtn = trash_folder_checkbtn;
3154         page->trash_folder_entry  = trash_folder_entry;
3155
3156         tmp_ac_prefs = *ac_prefs;
3157
3158         if (new_account) {
3159                 prefs_set_dialog_to_default(advanced_param);
3160         } else
3161                 prefs_set_dialog(advanced_param);
3162
3163         page->vbox = vbox1;
3164
3165         page->page.widget = vbox1;
3166         
3167         g_object_unref(G_OBJECT(size_group));
3168 }
3169         
3170 static gint prefs_basic_apply(void)
3171 {
3172         RecvProtocol protocol;
3173         gchar *old_id = NULL;
3174         gchar *new_id = NULL;
3175         struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *) basic_page.protocol_optmenu;
3176         GtkWidget *optmenu = protocol_optmenu->combobox;
3177
3178         protocol = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
3179
3180         if (*gtk_entry_get_text(GTK_ENTRY(basic_page.acname_entry)) == '\0') {
3181                 alertpanel_error(_("Account name is not entered."));
3182                 return -1;
3183         }
3184         if (*gtk_entry_get_text(GTK_ENTRY(basic_page.addr_entry)) == '\0') {
3185                 alertpanel_error(_("Mail address is not entered."));
3186                 return -1;
3187         }
3188
3189         if (((protocol == A_POP3) || 
3190              (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic_page.mailcmd_checkbtn))) || 
3191              (protocol == A_NONE)) &&
3192            *gtk_entry_get_text(GTK_ENTRY(basic_page.smtpserv_entry)) == '\0') {
3193                 alertpanel_error(_("SMTP server is not entered."));
3194                 return -1;
3195         }
3196         if ((protocol == A_POP3 || protocol == A_IMAP4) &&
3197             *gtk_entry_get_text(GTK_ENTRY(basic_page.uid_entry)) == '\0') {
3198                 alertpanel_error(_("User ID is not entered."));
3199                 return -1;
3200         }
3201         if (protocol == A_POP3 &&
3202             *gtk_entry_get_text(GTK_ENTRY(basic_page.recvserv_entry)) == '\0') {
3203                 alertpanel_error(_("POP server is not entered."));
3204                 return -1;
3205         }
3206         if (protocol == A_POP3 || protocol == A_LOCAL) {
3207                 GtkWidget *inbox_entry = (protocol == A_POP3 ? receive_page.inbox_entry : receive_page.local_inbox_entry );
3208                 const gchar *mailbox = gtk_entry_get_text(GTK_ENTRY(inbox_entry));
3209                 FolderItem *inbox =  folder_find_item_from_identifier(mailbox);
3210                 if (!inbox) {
3211                         gchar *id = NULL;
3212                         setup_write_mailbox_path(mainwindow_get_mainwindow(), "Mail");
3213                         id = folder_item_get_identifier(folder_get_default_inbox_for_class(F_MH));
3214                         gtk_entry_set_text(GTK_ENTRY(receive_page.inbox_entry),
3215                                 id);
3216                         gtk_entry_set_text(GTK_ENTRY(receive_page.local_inbox_entry),
3217                                 id);
3218                         g_free(id);
3219                         mailbox = gtk_entry_get_text(GTK_ENTRY(inbox_entry));
3220                         inbox =  folder_find_item_from_identifier(mailbox);
3221                 }
3222                 if (inbox == NULL) {
3223                         alertpanel_error(_("The default Inbox folder doesn't exist."));
3224                         return -1;
3225                 }
3226         }
3227         if (protocol == A_IMAP4 &&
3228             *gtk_entry_get_text(GTK_ENTRY(basic_page.recvserv_entry)) == '\0') {
3229                 alertpanel_error(_("IMAP server is not entered."));
3230                 return -1;
3231         }
3232         if (protocol == A_NNTP &&
3233             *gtk_entry_get_text(GTK_ENTRY(basic_page.nntpserv_entry)) == '\0') {
3234                 alertpanel_error(_("NNTP server is not entered."));
3235                 return -1;
3236         }
3237
3238         if (protocol == A_LOCAL &&
3239             *gtk_entry_get_text(GTK_ENTRY(basic_page.localmbox_entry)) == '\0') {
3240                 alertpanel_error(_("local mailbox filename is not entered."));
3241                 return -1;
3242         }
3243
3244         if (protocol == A_LOCAL &&
3245             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic_page.mailcmd_checkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic_page.mailcmd_entry)) == '\0') {
3246                 alertpanel_error(_("mail command is not entered."));
3247                 return -1;
3248         }
3249         
3250         if (protocol == A_IMAP4 || protocol == A_NNTP) 
3251                 old_id = g_strdup_printf("#%s/%s",
3252                                 protocol == A_IMAP4 ? "imap":"news",
3253                                 tmp_ac_prefs.account_name ? tmp_ac_prefs.account_name : "(null)");
3254         
3255         if (strchr(gtk_entry_get_text(GTK_ENTRY(basic_page.uid_entry)), '\n') != NULL) {
3256                 alertpanel_error(_("User ID cannot contain a newline character."));
3257                 return -1;
3258         }
3259
3260         if (strchr(gtk_entry_get_text(GTK_ENTRY(basic_page.pass_entry)), '\n') != NULL) {
3261                 alertpanel_error(_("Password cannot contain a newline character."));
3262                 return -1;
3263         }
3264
3265         prefs_set_data_from_dialog(basic_param);
3266
3267         /* Passwords are stored outside of PrefParams. */
3268         passwd_store_set_account(tmp_ac_prefs.account_id,
3269                         PWS_ACCOUNT_RECV,
3270                         gtk_entry_get_text(GTK_ENTRY(basic_page.pass_entry)),
3271                         FALSE);
3272         
3273         if (protocol == A_IMAP4 || protocol == A_NNTP) {
3274                 new_id = g_strdup_printf("#%s/%s",
3275                                 protocol == A_IMAP4 ? "imap":"news",
3276                                 tmp_ac_prefs.account_name);
3277                 if (old_id != NULL && new_id != NULL)
3278                         prefs_filtering_rename_path(old_id, new_id);
3279                 g_free(old_id);
3280                 g_free(new_id);
3281         }
3282         
3283         return 0;
3284 }
3285
3286 static gint prefs_receive_apply(void)
3287 {
3288         if (strchr(gtk_entry_get_text(GTK_ENTRY(send_page.smtp_uid_entry)), '\n') != NULL) {
3289                 alertpanel_error(_("SMTP user ID cannot contain a newline character."));
3290                 return -1;
3291         }
3292
3293         if (strchr(gtk_entry_get_text(GTK_ENTRY(send_page.smtp_pass_entry)), '\n') != NULL) {
3294                 alertpanel_error(_("SMTP password cannot contain a newline character."));
3295                 return -1;
3296         }
3297
3298         prefs_set_data_from_dialog(receive_param);
3299         return 0;
3300 }
3301
3302 static gint prefs_send_apply(void)
3303 {
3304         prefs_set_data_from_dialog(send_param);
3305
3306         /* Passwords are stored outside of PrefParams. */
3307         passwd_store_set_account(tmp_ac_prefs.account_id,
3308                         PWS_ACCOUNT_SEND,
3309                         gtk_entry_get_text(GTK_ENTRY(send_page.smtp_pass_entry)),
3310                         FALSE);
3311
3312         return 0;
3313 }
3314
3315 static gint prefs_compose_apply(void)
3316 {
3317         prefs_set_data_from_dialog(compose_param);
3318         return 0;
3319 }
3320
3321 static gint prefs_templates_apply(void)
3322 {
3323         prefs_set_data_from_dialog(templates_param);
3324         return 0;
3325 }
3326
3327 static gint prefs_privacy_apply(void)
3328 {
3329         prefs_set_data_from_dialog(privacy_param);
3330         return 0;
3331 }
3332
3333 #ifdef USE_GNUTLS
3334 static gint prefs_ssl_apply(void)
3335 {
3336         prefs_set_data_from_dialog(ssl_param);
3337
3338         /* Passwords are stored outside of PrefParams. */
3339         passwd_store_set_account(tmp_ac_prefs.account_id,
3340                         PWS_ACCOUNT_RECV_CERT,
3341                         gtk_entry_get_text(GTK_ENTRY(ssl_page.entry_in_cert_pass)),
3342                         FALSE);
3343         passwd_store_set_account(tmp_ac_prefs.account_id,
3344                         PWS_ACCOUNT_SEND_CERT,
3345                         gtk_entry_get_text(GTK_ENTRY(ssl_page.entry_out_cert_pass)),
3346                         FALSE);
3347
3348         return 0;
3349 }
3350 #endif
3351
3352 static gint prefs_proxy_apply(void)
3353 {
3354         prefs_set_data_from_dialog(proxy_param);
3355
3356         /* Passwords are stored outside of PrefParams. */
3357         passwd_store_set_account(tmp_ac_prefs.account_id,
3358                         PWS_ACCOUNT_PROXY_PASS,
3359                         gtk_entry_get_text(GTK_ENTRY(proxy_page.proxy_pass_entry)),
3360                         FALSE);
3361
3362         return 0;
3363 }
3364
3365 static gint prefs_advanced_apply(void)
3366 {
3367         prefs_set_data_from_dialog(advanced_param);
3368         return 0;
3369 }
3370
3371 static void basic_destroy_widget_func(PrefsPage *_page)
3372 {
3373         /* BasicPage *page = (BasicPage *) _page; */
3374 }
3375
3376 static void receive_destroy_widget_func(PrefsPage *_page)
3377 {
3378         /* ReceivePage *page = (ReceivePage *) _page; */
3379 }
3380
3381 static void send_destroy_widget_func(PrefsPage *_page)
3382 {
3383         /* SendPage *page = (SendPage *) _page; */
3384 }
3385
3386 static void compose_destroy_widget_func(PrefsPage *_page)
3387 {
3388         /* ComposePage *page = (ComposePage *) _page; */
3389 }
3390
3391 static void templates_destroy_widget_func(PrefsPage *_page)
3392 {
3393         /* TemplatesPage *page = (TemplatesPage *) _page; */
3394 }
3395
3396 static void privacy_destroy_widget_func(PrefsPage *_page)
3397 {
3398         /* PrivacyPage *page = (PrivacyPage *) _page; */
3399 }
3400
3401 #ifdef USE_GNUTLS
3402 static void ssl_destroy_widget_func(PrefsPage *_page)
3403 {
3404         /* SSLPage *page = (SSLPage *) _page; */
3405 }
3406 #endif
3407
3408 static void proxy_destroy_widget_func(PrefsPage *_page)
3409 {
3410         /* ProxyPage *page = (ProxyPage *) _page; */
3411 }
3412
3413 static void advanced_destroy_widget_func(PrefsPage *_page)
3414 {
3415         /* AdvancedPage *page = (AdvancedPage *) _page; */
3416 }
3417
3418 static gboolean basic_can_close_func(PrefsPage *_page)
3419 {       
3420         BasicPage *page = (BasicPage *) _page;
3421
3422         if (!page->page.page_open)
3423                 return TRUE;
3424
3425         return prefs_basic_apply() >= 0;
3426 }
3427
3428 static gboolean receive_can_close_func(PrefsPage *_page)
3429 {       
3430         ReceivePage *page = (ReceivePage *) _page;
3431
3432         if (!page->page.page_open)
3433                 return TRUE;
3434
3435         return prefs_receive_apply() >= 0;
3436 }
3437
3438 static gboolean send_can_close_func(PrefsPage *_page)
3439 {       
3440         SendPage *page = (SendPage *) _page;
3441
3442         if (!page->page.page_open)
3443                 return TRUE;
3444
3445         return prefs_send_apply() >= 0;
3446 }
3447
3448 static gboolean compose_can_close_func(PrefsPage *_page)
3449 {       
3450         ComposePage *page = (ComposePage *) _page;
3451
3452         if (!page->page.page_open)
3453                 return TRUE;
3454
3455         return prefs_compose_apply() >= 0;
3456 }
3457
3458 static gboolean templates_can_close_func(PrefsPage *_page)
3459 {
3460         TemplatesPage *page = (TemplatesPage *) _page;
3461
3462         if (!page->page.page_open)
3463                 return TRUE;
3464
3465         return prefs_templates_apply() >= 0;
3466 }
3467
3468 static gboolean privacy_can_close_func(PrefsPage *_page)
3469 {
3470         PrivacyPage *page = (PrivacyPage *) _page;
3471
3472         if (!page->page.page_open)
3473                 return TRUE;
3474
3475         return prefs_privacy_apply() >= 0;
3476 }
3477
3478 #ifdef USE_GNUTLS
3479 static gboolean ssl_can_close_func(PrefsPage *_page)
3480 {
3481         SSLPage *page = (SSLPage *) _page;
3482
3483         if (!page->page.page_open)
3484                 return TRUE;
3485
3486         return prefs_ssl_apply() >= 0;
3487 }
3488 #endif
3489
3490 static gboolean proxy_can_close_func(PrefsPage *_page)
3491 {
3492         ProxyPage *page = (ProxyPage *) _page;
3493
3494         if (!page->page.page_open)
3495                 return TRUE;
3496
3497         return prefs_proxy_apply() >= 0;
3498 }
3499
3500 static gboolean advanced_can_close_func(PrefsPage *_page)
3501 {
3502         AdvancedPage *page = (AdvancedPage *) _page;
3503
3504         if (!page->page.page_open)
3505                 return TRUE;
3506
3507         return prefs_advanced_apply() >= 0;
3508 }
3509
3510 static void basic_save_func(PrefsPage *_page)
3511 {
3512         BasicPage *page = (BasicPage *) _page;
3513
3514         if (!page->page.page_open)
3515                 return;
3516
3517         if (prefs_basic_apply() >= 0)
3518                 cancelled = FALSE;
3519 }
3520
3521 static void receive_save_func(PrefsPage *_page)
3522 {
3523         ReceivePage *page = (ReceivePage *) _page;
3524
3525         if (!page->page.page_open)
3526                 return;
3527
3528         if (prefs_receive_apply() >= 0)
3529                 cancelled = FALSE;
3530 }
3531
3532 static void send_save_func(PrefsPage *_page)
3533 {
3534         SendPage *page = (SendPage *) _page;
3535
3536         if (!page->page.page_open)
3537                 return;
3538
3539         if (prefs_send_apply() >= 0)
3540                 cancelled = FALSE;
3541 }
3542
3543 static void compose_save_func(PrefsPage *_page)
3544 {
3545         ComposePage *page = (ComposePage *) _page;
3546
3547         if (!page->page.page_open)
3548                 return;
3549
3550         if (prefs_compose_apply() >= 0)
3551                 cancelled = FALSE;
3552 }
3553
3554 static void templates_save_func(PrefsPage *_page)
3555 {
3556         TemplatesPage *page = (TemplatesPage *) _page;
3557
3558         if (!page->page.page_open)
3559                 return;
3560
3561         quotefmt_check_new_msg_formats(tmp_ac_prefs.compose_with_format,
3562                                                                         NULL,
3563                                                                         tmp_ac_prefs.compose_subject_format,
3564                                                                         tmp_ac_prefs.compose_body_format);
3565         quotefmt_check_reply_formats(tmp_ac_prefs.reply_with_format,
3566                                                                         NULL,
3567                                                                         tmp_ac_prefs.reply_quotemark,
3568                                                                         tmp_ac_prefs.reply_body_format);
3569         quotefmt_check_forward_formats(tmp_ac_prefs.forward_with_format,
3570                                                                         NULL,
3571                                                                         tmp_ac_prefs.forward_quotemark,
3572                                                                         tmp_ac_prefs.forward_body_format);
3573         if (prefs_templates_apply() >= 0)
3574                 cancelled = FALSE;
3575 }
3576
3577 static void privacy_save_func(PrefsPage *_page)
3578 {
3579         PrivacyPage *page = (PrivacyPage *) _page;
3580
3581         if (!page->page.page_open)
3582                 return;
3583
3584         if (prefs_privacy_apply() >= 0)
3585                 cancelled = FALSE;
3586 }
3587
3588 #ifdef USE_GNUTLS
3589 static void ssl_save_func(PrefsPage *_page)
3590 {
3591         SSLPage *page = (SSLPage *) _page;
3592
3593         if (!page->page.page_open)
3594                 return;
3595
3596         if (prefs_ssl_apply() >= 0)
3597                 cancelled = FALSE;
3598 }
3599 #endif
3600
3601 static void proxy_save_func(PrefsPage *_page)
3602 {
3603         ProxyPage *page = (ProxyPage *) _page;
3604
3605         if (!page->page.page_open)
3606                 return;
3607
3608         if (prefs_proxy_apply() >= 0)
3609                 cancelled = FALSE;
3610 }
3611
3612 static void advanced_save_func(PrefsPage *_page)
3613 {
3614         AdvancedPage *page = (AdvancedPage *) _page;
3615
3616         if (!page->page.page_open)
3617                 return;
3618
3619         if (prefs_advanced_apply() >= 0)
3620                 cancelled = FALSE;
3621 }
3622
3623 static void register_basic_page(void)
3624 {
3625         static gchar *path[3];
3626
3627         path[0] = _("Account");
3628         path[1] = _("Basic");
3629         path[2] = NULL;
3630         
3631         basic_page.page.path = path;
3632         basic_page.page.weight = 1000.0;
3633         basic_page.page.create_widget = basic_create_widget_func;
3634         basic_page.page.destroy_widget = basic_destroy_widget_func;
3635         basic_page.page.save_page = basic_save_func;
3636         basic_page.page.can_close = basic_can_close_func;
3637
3638         prefs_account_register_page((PrefsPage *) &basic_page);
3639 }
3640
3641 static void register_receive_page(void)
3642 {
3643         static gchar *path[3];
3644
3645         path[0] = _("Account");
3646         path[1] = _("Receive");
3647         path[2] = NULL;
3648         
3649         receive_page.page.path = path;
3650         receive_page.page.weight = 1000.0;
3651         receive_page.page.create_widget = receive_create_widget_func;
3652         receive_page.page.destroy_widget = receive_destroy_widget_func;
3653         receive_page.page.save_page = receive_save_func;
3654         receive_page.page.can_close = receive_can_close_func;
3655
3656         prefs_account_register_page((PrefsPage *) &receive_page);
3657 }
3658
3659 static void register_send_page(void)
3660 {
3661         static gchar *path[3];
3662
3663         path[0] = _("Account");
3664         path[1] = _("Send");
3665         path[2] = NULL;
3666         
3667         send_page.page.path = path;
3668         send_page.page.weight = 1000.0;
3669         send_page.page.create_widget = send_create_widget_func;
3670         send_page.page.destroy_widget = send_destroy_widget_func;
3671         send_page.page.save_page = send_save_func;
3672         send_page.page.can_close = send_can_close_func;
3673
3674         prefs_account_register_page((PrefsPage *) &send_page);
3675 }
3676
3677 static void register_compose_page(void)
3678 {
3679         static gchar *path[3];
3680
3681         path[0] = _("Account");
3682         path[1] = _("Compose");
3683         path[2] = NULL;
3684         
3685         compose_page.page.path = path;
3686         compose_page.page.weight = 1000.0;
3687         compose_page.page.create_widget = compose_create_widget_func;
3688         compose_page.page.destroy_widget = compose_destroy_widget_func;
3689         compose_page.page.save_page = compose_save_func;
3690         compose_page.page.can_close = compose_can_close_func;
3691
3692         prefs_account_register_page((PrefsPage *) &compose_page);
3693 }
3694
3695 static void register_templates_page(void)
3696 {
3697         static gchar *path[3];
3698
3699         path[0] = _("Account");
3700         path[1] = _("Templates");
3701         path[2] = NULL;
3702         
3703         templates_page.page.path = path;
3704         templates_page.page.weight = 1000.0;
3705         templates_page.page.create_widget = templates_create_widget_func;
3706         templates_page.page.destroy_widget = templates_destroy_widget_func;
3707         templates_page.page.save_page = templates_save_func;
3708         templates_page.page.can_close = templates_can_close_func;
3709
3710         prefs_account_register_page((PrefsPage *) &templates_page);
3711 }
3712
3713 static void register_privacy_page(void)
3714 {
3715         static gchar *path[3];
3716
3717         path[0] = _("Account");
3718         path[1] = _("Privacy");
3719         path[2] = NULL;
3720         
3721         privacy_page.page.path = path;
3722         privacy_page.page.weight = 1000.0;
3723         privacy_page.page.create_widget = privacy_create_widget_func;
3724         privacy_page.page.destroy_widget = privacy_destroy_widget_func;
3725         privacy_page.page.save_page = privacy_save_func;
3726         privacy_page.page.can_close = privacy_can_close_func;
3727
3728         prefs_account_register_page((PrefsPage *) &privacy_page);
3729 }
3730
3731 #ifdef USE_GNUTLS
3732 static void register_ssl_page(void)
3733 {
3734         static gchar *path[3];
3735
3736         path[0] = _("Account");
3737         path[1] = _("SSL/TLS");
3738         path[2] = NULL;
3739         
3740         ssl_page.page.path = path;
3741         ssl_page.page.weight = 1000.0;
3742         ssl_page.page.create_widget = ssl_create_widget_func;
3743         ssl_page.page.destroy_widget = ssl_destroy_widget_func;
3744         ssl_page.page.save_page = ssl_save_func;
3745         ssl_page.page.can_close = ssl_can_close_func;
3746
3747         prefs_account_register_page((PrefsPage *) &ssl_page);
3748 }
3749
3750 static gboolean sslcert_get_client_cert_hook(gpointer source, gpointer data)
3751 {
3752         SSLClientCertHookData *hookdata = (SSLClientCertHookData *)source;
3753         PrefsAccount *account = (PrefsAccount *)hookdata->account;
3754         gchar *pwd_id;
3755
3756         hookdata->cert_path = NULL;
3757         hookdata->password = NULL;
3758
3759         if (!g_list_find(account_get_list(), account)) {
3760                 g_warning("can't find account");
3761                 return TRUE;
3762         }
3763         
3764         if (hookdata->is_smtp) {
3765                 if (account->out_ssl_client_cert_file && *account->out_ssl_client_cert_file)
3766                         hookdata->cert_path = account->out_ssl_client_cert_file;
3767                 pwd_id = PWS_ACCOUNT_SEND_CERT;
3768         } else {
3769                 if (account->in_ssl_client_cert_file && *account->in_ssl_client_cert_file)
3770                         hookdata->cert_path = account->in_ssl_client_cert_file;
3771                 pwd_id = PWS_ACCOUNT_RECV_CERT;
3772         }
3773
3774         hookdata->password = passwd_store_get_account(account->account_id, pwd_id);
3775         return TRUE;
3776 }
3777
3778 struct GetPassData {
3779         GCond *cond;
3780         GMutex* mutex;
3781         gchar **pass;
3782 };
3783
3784
3785 static gboolean do_get_pass(gpointer data)
3786 {
3787         struct GetPassData *pass_data = (struct GetPassData *)data;
3788         g_mutex_lock(pass_data->mutex);
3789         *(pass_data->pass) = input_dialog_query_password("the PKCS12 client certificate", NULL);
3790         g_cond_signal(pass_data->cond);
3791         g_mutex_unlock(pass_data->mutex);
3792         return FALSE;
3793 }
3794 static gboolean sslcert_get_password(gpointer source, gpointer data)
3795
3796         struct GetPassData pass_data;
3797         /* do complicated stuff to be able to call GTK from the mainloop */
3798 #if !GLIB_CHECK_VERSION(2,32,0)
3799         pass_data.cond = g_cond_new();
3800 #else
3801         pass_data.cond = g_new0(GCond, 1);
3802         g_cond_init(pass_data.cond);
3803 #endif
3804         pass_data.mutex = cm_mutex_new();
3805         pass_data.pass = (gchar **)source;
3806
3807         g_mutex_lock(pass_data.mutex);
3808
3809         g_idle_add(do_get_pass, &pass_data);
3810
3811         g_cond_wait(pass_data.cond, pass_data.mutex);
3812 #if !GLIB_CHECK_VERSION(2,32,0)
3813         g_cond_free(pass_data.cond);
3814 #else
3815         g_cond_clear(pass_data.cond);
3816         g_free(pass_data.cond);
3817 #endif
3818         g_mutex_unlock(pass_data.mutex);
3819         cm_mutex_free(pass_data.mutex);
3820
3821         return TRUE;
3822 }
3823 #endif
3824
3825 static void register_proxy_page(void)
3826 {
3827         static gchar *path[3];
3828
3829         path[0] = _("Account");
3830         path[1] = _("Proxy");
3831         path[2] = NULL;
3832
3833         proxy_page.page.path = path;
3834         proxy_page.page.weight = 1000.0;
3835         proxy_page.page.create_widget = proxy_create_widget_func;
3836         proxy_page.page.destroy_widget = proxy_destroy_widget_func;
3837         proxy_page.page.save_page = proxy_save_func;
3838         proxy_page.page.can_close = proxy_can_close_func;
3839
3840         prefs_account_register_page((PrefsPage *) &proxy_page);
3841 }
3842
3843 static void register_advanced_page(void)
3844 {
3845         static gchar *path[3];
3846
3847         path[0] = _("Account");
3848         path[1] = _("Advanced");
3849         path[2] = NULL;
3850         
3851         advanced_page.page.path = path;
3852         advanced_page.page.weight = 1000.0;
3853         advanced_page.page.create_widget = advanced_create_widget_func;
3854         advanced_page.page.destroy_widget = advanced_destroy_widget_func;
3855         advanced_page.page.save_page = advanced_save_func;
3856         advanced_page.page.can_close = advanced_can_close_func;
3857
3858         prefs_account_register_page((PrefsPage *) &advanced_page);
3859 }
3860
3861 void prefs_account_init()
3862 {
3863         register_basic_page();
3864         register_receive_page();
3865         register_send_page();
3866         register_compose_page();
3867         register_templates_page();
3868         register_privacy_page();
3869 #ifdef USE_GNUTLS
3870         register_ssl_page();
3871         hooks_register_hook(SSLCERT_GET_CLIENT_CERT_HOOKLIST, sslcert_get_client_cert_hook, NULL);
3872         hooks_register_hook(SSL_CERT_GET_PASSWORD, sslcert_get_password, NULL);
3873 #endif
3874         register_proxy_page();
3875         register_advanced_page();
3876 }
3877
3878 PrefsAccount *prefs_account_new(void)
3879 {
3880         PrefsAccount *ac_prefs;
3881
3882         ac_prefs = g_new0(PrefsAccount, 1);
3883         memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
3884         prefs_set_default(basic_param);
3885         prefs_set_default(receive_param);
3886         prefs_set_default(send_param);
3887         prefs_set_default(compose_param);
3888         prefs_set_default(templates_param);
3889         prefs_set_default(privacy_param);
3890         prefs_set_default(ssl_param);
3891         prefs_set_default(proxy_param);
3892         prefs_set_default(advanced_param);
3893         *ac_prefs = tmp_ac_prefs;
3894         ac_prefs->account_id = prefs_account_get_new_id();
3895
3896         ac_prefs->privacy_prefs = g_hash_table_new(g_str_hash, g_str_equal);
3897
3898         return ac_prefs;
3899 }
3900
3901 PrefsAccount *prefs_account_new_from_config(const gchar *label)
3902 {
3903         const gchar *p = label;
3904         gchar *rcpath;
3905         gint id;
3906         gchar **strv, **cur;
3907         gsize len;
3908         PrefsAccount *ac_prefs;
3909
3910         cm_return_val_if_fail(label != NULL, NULL);
3911
3912         ac_prefs = g_new0(PrefsAccount, 1);
3913
3914         /* Load default values to tmp_ac_prefs first, ... */
3915         memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
3916         prefs_set_default(basic_param);
3917         prefs_set_default(receive_param);
3918         prefs_set_default(send_param);
3919         prefs_set_default(compose_param);
3920         prefs_set_default(templates_param);
3921         prefs_set_default(privacy_param);
3922         prefs_set_default(ssl_param);
3923         prefs_set_default(advanced_param);
3924
3925         /* ... overriding them with values from stored config file. */
3926         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
3927         prefs_read_config(basic_param, label, rcpath, NULL);
3928         prefs_read_config(receive_param, label, rcpath, NULL);
3929         prefs_read_config(send_param, label, rcpath, NULL);
3930         prefs_read_config(compose_param, label, rcpath, NULL);
3931         prefs_read_config(templates_param, label, rcpath, NULL);
3932         prefs_read_config(privacy_param, label, rcpath, NULL);
3933         prefs_read_config(ssl_param, label, rcpath, NULL);
3934         prefs_read_config(proxy_param, label, rcpath, NULL);
3935         prefs_read_config(advanced_param, label, rcpath, NULL);
3936         g_free(rcpath);
3937
3938         *ac_prefs = tmp_ac_prefs;
3939
3940         while (*p && !g_ascii_isdigit(*p)) p++;
3941         id = atoi(p);
3942         if (id < 0) g_warning("wrong account id: %d", id);
3943         ac_prefs->account_id = id;
3944
3945         /* Now parse privacy_prefs. */
3946         ac_prefs->privacy_prefs = g_hash_table_new(g_str_hash, g_str_equal);
3947         if (privacy_prefs != NULL) {
3948                 strv = g_strsplit(privacy_prefs, ",", 0);
3949                 for (cur = strv; *cur != NULL; cur++) {
3950                         gchar *encvalue, *tmp;
3951
3952                         encvalue = strchr(*cur, '=');
3953                         if (encvalue == NULL)
3954                                 continue;
3955                         encvalue[0] = '\0';
3956                         encvalue++;
3957
3958                         tmp = g_base64_decode_zero(encvalue, &len);
3959                         if (len > 0)
3960                                 g_hash_table_insert(ac_prefs->privacy_prefs, g_strdup(*cur), tmp);
3961                         else
3962                                 g_free(tmp);
3963                 }
3964                 g_strfreev(strv);
3965                 g_free(privacy_prefs);
3966                 privacy_prefs = NULL;
3967         }
3968
3969         /* For older configurations, move stored passwords into the
3970          * password store. */
3971         gboolean passwords_migrated = FALSE;
3972
3973         if (ac_prefs->passwd != NULL && strlen(ac_prefs->passwd) > 1) {
3974                 passwd_store_set_account(ac_prefs->account_id,
3975                                 PWS_ACCOUNT_RECV, ac_prefs->passwd, TRUE);
3976                 passwords_migrated = TRUE;
3977         }
3978         if (ac_prefs->smtp_passwd != NULL && strlen(ac_prefs->smtp_passwd) > 1) {
3979                 passwd_store_set_account(ac_prefs->account_id,
3980                                 PWS_ACCOUNT_SEND, ac_prefs->smtp_passwd, TRUE);
3981                 passwords_migrated = TRUE;
3982         }
3983         if (ac_prefs->in_ssl_client_cert_pass != NULL
3984                         && strlen(ac_prefs->in_ssl_client_cert_pass) > 1) {
3985                 passwd_store_set_account(ac_prefs->account_id,
3986                                 PWS_ACCOUNT_RECV_CERT, ac_prefs->in_ssl_client_cert_pass, TRUE);
3987                 passwords_migrated = TRUE;
3988         }
3989         if (ac_prefs->out_ssl_client_cert_pass != NULL
3990                         && strlen(ac_prefs->out_ssl_client_cert_pass) > 1) {
3991                 passwd_store_set_account(ac_prefs->account_id,
3992                                 PWS_ACCOUNT_SEND_CERT, ac_prefs->out_ssl_client_cert_pass, TRUE);
3993                 passwords_migrated = TRUE;
3994         }
3995
3996         /* Write out password store to file immediately, to prevent
3997          * their loss. */
3998         if (passwords_migrated)
3999                 passwd_store_write_config();
4000
4001         ac_prefs->receive_in_progress = FALSE;
4002
4003         prefs_custom_header_read_config(ac_prefs);
4004
4005         return ac_prefs;
4006 }
4007
4008 static void create_privacy_prefs(gpointer key, gpointer _value, gpointer user_data)
4009 {
4010         GString *str = (GString *) user_data;
4011         gchar *encvalue;
4012         gchar *value = (gchar *) _value;
4013
4014         if (str->len > 0)
4015                 g_string_append_c(str, ',');
4016
4017         encvalue = g_base64_encode(value, strlen(value));
4018         g_string_append_printf(str, "%s=%s", (gchar *) key, encvalue);
4019         g_free(encvalue);
4020 }
4021
4022 #define WRITE_PARAM(PARAM_TABLE) \
4023                 if (prefs_write_param(PARAM_TABLE, pfile->fp) < 0) { \
4024                         g_warning("failed to write configuration to file"); \
4025                         prefs_file_close_revert(pfile); \
4026                         g_free(privacy_prefs); \
4027                         privacy_prefs = NULL; \
4028                         return; \
4029                 }
4030
4031 void prefs_account_write_config_all(GList *account_list)
4032 {
4033         GList *cur;
4034         gchar *rcpath;
4035         PrefFile *pfile;
4036
4037         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
4038         if ((pfile = prefs_write_open(rcpath)) == NULL) {
4039                 g_free(rcpath);
4040                 return;
4041         }
4042         g_free(rcpath);
4043
4044         for (cur = account_list; cur != NULL; cur = cur->next) {
4045                 GString *str;
4046
4047                 tmp_ac_prefs = *(PrefsAccount *)cur->data;
4048                 if (fprintf(pfile->fp, "[Account: %d]\n",
4049                             tmp_ac_prefs.account_id) <= 0)
4050                         return;
4051
4052                 str = g_string_sized_new(32);
4053                 g_hash_table_foreach(tmp_ac_prefs.privacy_prefs, create_privacy_prefs, str);
4054                 privacy_prefs = str->str;                   
4055                 g_string_free(str, FALSE);
4056
4057                 WRITE_PARAM(basic_param)
4058                 WRITE_PARAM(receive_param)
4059                 WRITE_PARAM(send_param)
4060                 WRITE_PARAM(compose_param)
4061                 WRITE_PARAM(templates_param)
4062                 WRITE_PARAM(privacy_param)
4063                 WRITE_PARAM(ssl_param)
4064                 WRITE_PARAM(proxy_param)
4065                 WRITE_PARAM(advanced_param)
4066
4067                 g_free(privacy_prefs);
4068                 privacy_prefs = NULL;
4069
4070                 if (cur->next) {
4071                         if (fputc('\n', pfile->fp) == EOF) {
4072                                 FILE_OP_ERROR(rcpath, "fputc");
4073                                 prefs_file_close_revert(pfile);
4074                                 return;
4075                         }
4076                 }
4077         }
4078
4079         if (prefs_file_close(pfile) < 0)
4080                 g_warning("failed to write configuration to file");
4081
4082         passwd_store_write_config();
4083 }
4084 #undef WRITE_PARAM
4085
4086 static gboolean free_privacy_prefs(gpointer key, gpointer value, gpointer user_data)
4087 {
4088         g_free(key);
4089         g_free(value);
4090
4091         return TRUE;
4092 }
4093
4094 void prefs_account_free(PrefsAccount *ac_prefs)
4095 {
4096         if (!ac_prefs) return;
4097
4098         g_hash_table_foreach_remove(ac_prefs->privacy_prefs, free_privacy_prefs, NULL);
4099
4100         tmp_ac_prefs = *ac_prefs;
4101         prefs_free(basic_param);
4102         prefs_free(receive_param);
4103         prefs_free(send_param);
4104         prefs_free(compose_param);
4105         prefs_free(templates_param);
4106         prefs_free(privacy_param);
4107         prefs_free(ssl_param);
4108         prefs_free(proxy_param);
4109         prefs_free(advanced_param);
4110 }
4111
4112 const gchar *prefs_account_get_privacy_prefs(PrefsAccount *account, gchar *id)