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