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