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