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