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