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