0f94467460c7abf8296897d254ad5d513ff1dc61
[claws.git] / src / prefs_account.c
1 /*
2  * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2021 the Claws Mail team and Hiroyuki Yamamoto
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 #include "main.h"
38 #include "prefs_gtk.h"
39 #include "prefs_account.h"
40 #include "prefs_receive.h"
41 #include "prefs_common.h"
42 #include "prefs_customheader.h"
43 #include "account.h"
44 #include "mainwindow.h"
45 #include "manage_window.h"
46 #include "folder.h"
47 #include "foldersel.h"
48 #include "inc.h"
49 #include "menu.h"
50 #include "gtkutils.h"
51 #include "utils.h"
52 #include "alertpanel.h"
53 #include "colorlabel.h"
54 #include "smtp.h"
55 #include "imap.h"
56 #include "pop.h"
57 #include "oauth2.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 #include "file-utils.h"
68 #ifdef USE_GNUTLS
69 #include <gnutls/gnutls.h>
70 #endif
71 #include <pthread.h> 
72
73 static gboolean cancelled;
74 static gboolean new_account;
75
76 static PrefsAccount tmp_ac_prefs;
77
78 static GtkWidget *sigfile_radiobtn;
79 static GtkWidget *sigcmd_radiobtn;
80 static GtkWidget *entry_sigpath;
81 static GtkWidget *signature_browse_button;
82 static GtkWidget *signature_edit_button;
83
84 #ifdef USE_GNUTLS
85 static GtkWidget *entry_in_cert_file;
86 static GtkWidget *entry_out_cert_file;
87 static GtkWidget *in_ssl_cert_browse_button;
88 static GtkWidget *out_ssl_cert_browse_button;
89 #endif
90
91 struct AutocheckWidgets {
92         GtkWidget *autochk_hour_spinbtn;
93         GtkWidget *autochk_min_spinbtn;
94         GtkWidget *autochk_sec_spinbtn;
95 };
96
97 static GSList *prefs_pages = NULL;
98
99 static pthread_t oauth2_listener_tid;
100 static int oauth2_listener_cancel = 0;
101
102 typedef struct BasicPage
103 {
104     PrefsPage page;
105
106     GtkWidget *vbox;
107
108         GtkWidget *acname_entry;
109         GtkWidget *default_checkbtn;
110
111         GtkWidget *name_entry;
112         GtkWidget *addr_entry;
113         GtkWidget *org_entry;
114
115         GtkWidget *serv_frame;
116         GtkWidget *serv_table;
117         gpointer *protocol_optmenu;
118         GtkWidget *recvserv_label;
119         GtkWidget *smtpserv_label;
120         GtkWidget *nntpserv_label;
121         GtkWidget *localmbox_label;
122         GtkWidget *mailcmd_label;
123         GtkWidget *recvserv_entry;
124         GtkWidget *smtpserv_entry;
125         GtkWidget *nntpserv_entry;
126         GtkWidget *nntpauth_checkbtn;
127         GtkWidget *nntpauth_onconnect_checkbtn;
128         GtkWidget *localmbox_entry;
129         GtkWidget *mailcmd_checkbtn;
130         GtkWidget *mailcmd_entry;
131         GtkWidget *uid_label;
132         GtkWidget *pass_label;
133         GtkWidget *uid_entry;
134         GtkWidget *pass_entry;
135         GtkWidget *showpwd_checkbtn;
136         GtkWidget *auto_configure_btn;
137         GtkWidget *auto_configure_cancel_btn;
138         GtkWidget *auto_configure_lbl;
139 } BasicPage;
140
141 typedef struct ReceivePage
142 {
143     PrefsPage page;
144
145     GtkWidget *vbox;
146
147         GtkWidget *pop3_frame;
148         GtkWidget *pop_auth_checkbtn;
149         GtkWidget *pop_auth_type_optmenu;
150         GtkWidget *rmmail_checkbtn;
151         GtkWidget *leave_time_spinbtn;
152         GtkWidget *leave_hour_spinbtn;
153         GtkWidget *size_limit_checkbtn;
154         GtkWidget *size_limit_spinbtn;
155         GtkWidget *inbox_label;
156         GtkWidget *inbox_entry;
157         GtkWidget *inbox_btn;
158
159         GtkWidget *autochk_frame;
160
161         GtkWidget *local_frame;
162         GtkWidget *local_inbox_label;
163         GtkWidget *local_inbox_entry;
164         GtkWidget *local_inbox_btn;
165
166         GtkWidget *filter_on_recv_checkbtn;
167         GtkWidget *filterhook_on_recv_checkbtn;
168         GtkWidget *recvatgetall_checkbtn;
169         
170         GtkWidget *imap_frame;
171         GtkWidget *imap_auth_type_optmenu;
172         GtkWidget *imapdir_label;
173         GtkWidget *imapdir_entry;
174         GtkWidget *subsonly_checkbtn;
175         GtkWidget *low_bandwidth_checkbtn;
176
177         GtkWidget *frame_maxarticle;
178         GtkWidget *maxarticle_label;
179         GtkWidget *maxarticle_spinbtn;
180         GtkAdjustment *maxarticle_spinbtn_adj;
181
182         GtkWidget *autochk_checkbtn;
183         GtkWidget *autochk_use_default_checkbtn;
184         struct AutocheckWidgets *autochk_widgets;
185 } ReceivePage;
186
187 typedef struct SendPage
188 {
189     PrefsPage page;
190
191     GtkWidget *vbox;
192
193         GtkWidget *msgid_checkbtn;
194         GtkWidget *xmailer_checkbtn;
195         GtkWidget *customhdr_checkbtn;
196         GtkWidget *msgid_with_addr_checkbtn;
197         GtkWidget *smtp_auth_checkbtn;
198         GtkWidget *smtp_auth_type_optmenu;
199         GtkWidget *smtp_uid_entry;
200         GtkWidget *smtp_pass_entry;
201         GtkWidget *pop_bfr_smtp_checkbtn;
202         GtkWidget *pop_bfr_smtp_tm_spinbtn;
203         GtkWidget *pop_auth_timeout_lbl;
204         GtkWidget *pop_auth_minutes_lbl;
205 } SendPage;
206
207 typedef struct Oauth2Page
208 {
209         PrefsPage page;
210
211         GtkWidget *vbox;
212         GtkWidget *oauth2_sensitive;
213
214         GtkWidget *oauth2_authorise_btn;
215         GtkWidget *oauth2_deauthorise_btn;
216         GtkWidget *oauth2_authcode_entry;
217         GtkWidget *oauth2_auth_optmenu; 
218         GtkWidget *oauth2_link_button;
219         GtkWidget *oauth2_link_copy_button;
220         gpointer *protocol_optmenu;
221         GtkWidget *oauth2_client_id_entry;
222         GtkWidget *oauth2_client_secret_entry;
223
224 } Oauth2Page;
225
226 typedef struct
227 {
228         gchar *auth_uri;
229         GtkWidget *entry;
230 } AuthCodeQueryButtonData;
231
232 typedef struct ComposePage
233 {
234     PrefsPage page;
235
236     GtkWidget *vbox;
237
238         GtkWidget *sigfile_radiobtn;
239         GtkWidget *entry_sigpath;
240         GtkWidget *checkbtn_autosig;
241         GtkWidget *entry_sigsep;
242         GtkWidget *autocc_checkbtn;
243         GtkWidget *autocc_entry;
244         GtkWidget *autobcc_checkbtn;
245         GtkWidget *autobcc_entry;
246         GtkWidget *autoreplyto_checkbtn;
247         GtkWidget *autoreplyto_entry;
248 #if USE_ENCHANT
249         GtkWidget *checkbtn_enable_default_dictionary;
250         GtkWidget *combo_default_dictionary;
251         GtkWidget *checkbtn_enable_default_alt_dictionary;
252         GtkWidget *combo_default_alt_dictionary;
253 #endif
254 } ComposePage;
255
256 typedef struct TemplatesPage
257 {
258     PrefsPage page;
259
260     GtkWidget *vbox;
261
262         GtkWidget *checkbtn_compose_with_format;
263         GtkWidget *compose_subject_format;
264         GtkWidget *compose_body_format;
265         GtkWidget *checkbtn_reply_with_format;
266         GtkWidget *reply_quotemark;
267         GtkWidget *reply_body_format;
268         GtkWidget *checkbtn_forward_with_format;
269         GtkWidget *forward_quotemark;
270         GtkWidget *forward_body_format;
271 } TemplatesPage;
272
273 typedef struct PrivacyPage
274 {
275     PrefsPage page;
276
277     GtkWidget *vbox;
278
279         GtkWidget *default_privacy_system;
280         GtkWidget *default_encrypt_checkbtn;
281         GtkWidget *default_encrypt_reply_checkbtn;
282         GtkWidget *default_sign_checkbtn;
283         GtkWidget *default_sign_reply_checkbtn;
284         GtkWidget *save_clear_text_checkbtn;
285         GtkWidget *encrypt_to_self_checkbtn;
286 } PrivacyPage;
287
288 typedef struct SSLPage
289 {
290     PrefsPage page;
291
292     GtkWidget *vbox;
293
294         GtkWidget *pop_frame;
295         GtkWidget *pop_nossl_radiobtn;
296         GtkWidget *pop_ssltunnel_radiobtn;
297         GtkWidget *pop_starttls_radiobtn;
298
299         GtkWidget *imap_frame;
300         GtkWidget *imap_nossl_radiobtn;
301         GtkWidget *imap_ssltunnel_radiobtn;
302         GtkWidget *imap_starttls_radiobtn;
303
304         GtkWidget *nntp_frame;
305         GtkWidget *nntp_nossl_radiobtn;
306         GtkWidget *nntp_ssltunnel_radiobtn;
307
308         GtkWidget *send_frame;
309         GtkWidget *smtp_nossl_radiobtn;
310         GtkWidget *smtp_ssltunnel_radiobtn;
311         GtkWidget *smtp_starttls_radiobtn;
312
313         GtkWidget *entry_in_cert_file;
314         GtkWidget *entry_in_cert_pass;
315         GtkWidget *entry_out_cert_file;
316         GtkWidget *entry_out_cert_pass;
317
318         GtkWidget *ssl_certs_auto_accept_checkbtn;
319         GtkWidget *use_nonblocking_ssl_checkbtn;
320 } SSLPage;
321
322 typedef struct ProxyPage
323 {
324         PrefsPage page;
325
326         GtkWidget *vbox;
327
328         GtkWidget *proxy_checkbtn;
329         GtkWidget *default_proxy_checkbtn;
330         GtkWidget *socks4_radiobtn;
331         GtkWidget *socks5_radiobtn;
332         GtkWidget *proxy_host_entry;
333         GtkWidget *proxy_port_spinbtn;
334         GtkWidget *proxy_auth_checkbtn;
335         GtkWidget *proxy_name_entry;
336         GtkWidget *proxy_pass_entry;
337         GtkWidget *proxy_send_checkbtn;
338 } ProxyPage;
339
340 typedef struct AdvancedPage
341 {
342     PrefsPage page;
343
344     GtkWidget *vbox;
345
346         GtkWidget *smtpport_checkbtn;
347         GtkWidget *smtpport_spinbtn;
348         GtkWidget *popport_hbox;
349         GtkWidget *popport_checkbtn;
350         GtkWidget *popport_spinbtn;
351         GtkWidget *imapport_hbox;
352         GtkWidget *imapport_checkbtn;
353         GtkWidget *imapport_spinbtn;
354         GtkWidget *nntpport_hbox;
355         GtkWidget *nntpport_checkbtn;
356         GtkWidget *nntpport_spinbtn;
357         GtkWidget *domain_checkbtn;
358         GtkWidget *domain_entry;
359         GtkWidget *crosspost_checkbtn;
360         GtkWidget *crosspost_colormenu;
361
362 #ifndef G_OS_WIN32
363         GtkWidget *tunnelcmd_checkbtn;
364         GtkWidget *tunnelcmd_entry;
365 #endif
366
367         GtkWidget *sent_folder_checkbtn;
368         GtkWidget *sent_folder_entry;
369         GtkWidget *queue_folder_checkbtn;
370         GtkWidget *queue_folder_entry;
371         GtkWidget *draft_folder_checkbtn;
372         GtkWidget *draft_folder_entry;
373         GtkWidget *trash_folder_checkbtn;
374         GtkWidget *trash_folder_entry;
375 } AdvancedPage;
376
377 static BasicPage basic_page;
378 static ReceivePage receive_page;
379 static SendPage send_page;
380 static Oauth2Page oauth2_page;
381 static ComposePage compose_page;
382 static TemplatesPage templates_page;
383 static PrivacyPage privacy_page;
384 #ifdef USE_GNUTLS
385 static SSLPage ssl_page;
386 #endif
387 static ProxyPage proxy_page;
388 static AdvancedPage advanced_page;
389
390 struct BasicProtocol {
391         GtkWidget *combobox;
392         GtkWidget *label;
393         GtkWidget *descrlabel;
394         GtkWidget *no_imap_warn_icon;
395         GtkWidget *no_imap_warn_label;
396 };
397
398 static char *protocol_names[] = {
399         N_("POP"),
400         N_("IMAP"),
401         N_("News (NNTP)"),
402         N_("Local mbox file"),
403         N_("None (SMTP only)")
404 };
405
406 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam);
407 static void prefs_account_protocol_set_optmenu          (PrefParam *pparam);
408 static void prefs_account_protocol_changed              (GtkComboBox *combobox,
409                                                         gpointer data);
410
411 static void prefs_account_set_string_from_combobox (PrefParam *pparam);
412 static void prefs_account_set_privacy_combobox_from_string (PrefParam *pparam);
413
414 static void prefs_account_imap_auth_type_set_data_from_optmenu
415                                                         (PrefParam *pparam);
416 static void prefs_account_imap_auth_type_set_optmenu    (PrefParam *pparam);
417 static void prefs_account_smtp_auth_type_set_data_from_optmenu
418                                                         (PrefParam *pparam);
419 static void prefs_account_smtp_auth_type_set_optmenu    (PrefParam *pparam);
420 static void prefs_account_pop_auth_type_set_data_from_optmenu
421                                                         (PrefParam *pparam);
422 static void prefs_account_pop_auth_type_set_optmenu     (PrefParam *pparam);
423  
424 static void prefs_account_oauth2_provider_set_data_from_optmenu
425                                                         (PrefParam *pparam);
426 static void prefs_account_oauth2_provider_set_optmenu   (PrefParam *pparam);
427 static void prefs_account_oauth2_copy_url                       (GtkButton *button, 
428                                                          gpointer data);
429 static void * prefs_account_oauth2_listener(void *params);
430 static int  prefs_account_oauth2_get_line(int sock, char *buf, int size);
431 static void prefs_account_oauth2_set_sensitivity(void);
432 static void prefs_account_oauth2_set_auth_sensitivity(void);
433 static void prefs_account_oauth2_obtain_tokens(GtkButton *button, gpointer data);
434 static void prefs_account_set_autochk_interval_from_widgets(PrefParam *pparam);
435 static void prefs_account_set_autochk_interval_to_widgets(PrefParam *pparam);
436
437 static void prefs_account_enum_set_data_from_radiobtn   (PrefParam *pparam);
438 static void prefs_account_enum_set_radiobtn             (PrefParam *pparam);
439
440 static void crosspost_color_toggled(void);
441 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam);
442 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam);
443
444 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
445                                            gpointer user_data);
446 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
447                                           gpointer user_data);
448 static void prefs_account_showpwd_checkbtn_toggled(GtkToggleButton *button,
449                                           gpointer user_data);
450 static void prefs_account_entry_changed_newline_check_cb(GtkWidget *entry,
451                                                 gpointer user_data);
452 static void prefs_account_filter_on_recv_toggled(GtkToggleButton *button,
453                                           gpointer user_data);
454
455 #if USE_ENCHANT
456 static void prefs_account_compose_default_dictionary_set_string_from_optmenu
457                                                         (PrefParam *pparam);
458 static void prefs_account_compose_default_dictionary_set_optmenu_from_string
459                                                         (PrefParam *pparam);
460 #endif
461
462 static gchar *privacy_prefs;
463
464 static PrefParam basic_param[] = {
465         {"account_name", NULL, &tmp_ac_prefs.account_name, P_STRING,
466          &basic_page.acname_entry, prefs_set_data_from_entry, prefs_set_entry},
467
468         {"is_default", "FALSE", &tmp_ac_prefs.is_default, P_BOOL,
469          &basic_page.default_checkbtn,
470          prefs_set_data_from_toggle, prefs_set_toggle},
471
472         {"name", NULL, &tmp_ac_prefs.name, P_STRING,
473          &basic_page.name_entry, prefs_set_data_from_entry, prefs_set_entry},
474
475         {"address", NULL, &tmp_ac_prefs.address, P_STRING,
476          &basic_page.addr_entry, prefs_set_data_from_entry, prefs_set_entry},
477
478         {"organization", NULL, &tmp_ac_prefs.organization, P_STRING,
479          &basic_page.org_entry, prefs_set_data_from_entry, prefs_set_entry},
480
481         {"protocol", NULL, &tmp_ac_prefs.protocol, P_ENUM,
482          (GtkWidget **)&basic_page.protocol_optmenu,
483          prefs_account_protocol_set_data_from_optmenu,
484          prefs_account_protocol_set_optmenu},
485
486         {"receive_server", NULL, &tmp_ac_prefs.recv_server, P_STRING,
487          &basic_page.recvserv_entry, prefs_set_data_from_entry, prefs_set_entry},
488
489         {"smtp_server", NULL, &tmp_ac_prefs.smtp_server, P_STRING,
490          &basic_page.smtpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
491
492         {"nntp_server", NULL, &tmp_ac_prefs.nntp_server, P_STRING,
493          &basic_page.nntpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
494
495         {"local_mbox", "/var/mail", &tmp_ac_prefs.local_mbox, P_STRING,
496          &basic_page.localmbox_entry, prefs_set_data_from_entry, prefs_set_entry},
497
498         {"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
499          &basic_page.mailcmd_checkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
500
501         {"mail_command", DEFAULT_SENDMAIL_CMD, &tmp_ac_prefs.mail_command, P_STRING,
502          &basic_page.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
503
504         {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
505          &basic_page.nntpauth_checkbtn,
506          prefs_set_data_from_toggle, prefs_set_toggle},
507         
508         {"use_nntp_auth_onconnect", "FALSE", &tmp_ac_prefs.use_nntp_auth_onconnect, P_BOOL,
509          &basic_page.nntpauth_onconnect_checkbtn,
510          prefs_set_data_from_toggle, prefs_set_toggle},
511
512         {"user_id", NULL, &tmp_ac_prefs.userid, P_STRING,
513          &basic_page.uid_entry, prefs_set_data_from_entry, prefs_set_entry},
514
515         {"password", NULL, &tmp_ac_prefs.passwd, P_PASSWORD,
516          NULL, NULL, NULL},
517
518         {"config_version", "-1", &tmp_ac_prefs.config_version, P_INT,
519                 NULL, NULL, NULL},
520
521         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
522 };
523
524 static PrefParam receive_param[] = {
525         {"use_apop_auth", "FALSE", &tmp_ac_prefs.use_apop_auth, P_BOOL,
526          NULL, NULL}, /* deprecated */
527
528         {"use_pop_auth", "FALSE", &tmp_ac_prefs.use_pop_auth, P_BOOL,
529          &receive_page.pop_auth_checkbtn,
530          prefs_set_data_from_toggle, prefs_set_toggle},
531
532         {"pop_auth_method", "0", &tmp_ac_prefs.pop_auth_type, P_ENUM,
533          &receive_page.pop_auth_type_optmenu,
534          prefs_account_pop_auth_type_set_data_from_optmenu,
535          prefs_account_pop_auth_type_set_optmenu},
536
537         {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
538          &receive_page.rmmail_checkbtn,
539          prefs_set_data_from_toggle, prefs_set_toggle},
540
541 #ifndef GENERIC_UMPC
542         {"message_leave_time", "7", &tmp_ac_prefs.msg_leave_time, P_INT,
543          &receive_page.leave_time_spinbtn,
544          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
545 #else
546         {"message_leave_time", "30", &tmp_ac_prefs.msg_leave_time, P_INT,
547          &receive_page.leave_time_spinbtn,
548          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
549 #endif
550         {"message_leave_hour", "0", &tmp_ac_prefs.msg_leave_hour, P_INT,
551          &receive_page.leave_hour_spinbtn,
552          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
553
554         {"enable_size_limit", "FALSE", &tmp_ac_prefs.enable_size_limit, P_BOOL,
555          &receive_page.size_limit_checkbtn,
556          prefs_set_data_from_toggle, prefs_set_toggle},
557         {"size_limit", "1024", &tmp_ac_prefs.size_limit, P_INT,
558          &receive_page.size_limit_spinbtn,
559          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
560
561         {"filter_on_receive", "TRUE", &tmp_ac_prefs.filter_on_recv, P_BOOL,
562          &receive_page.filter_on_recv_checkbtn,
563          prefs_set_data_from_toggle, prefs_set_toggle},
564
565         {"filterhook_on_receive", "TRUE", &tmp_ac_prefs.filterhook_on_recv, P_BOOL,
566          &receive_page.filterhook_on_recv_checkbtn,
567          prefs_set_data_from_toggle, prefs_set_toggle},
568
569         {"imap_auth_method", "0", &tmp_ac_prefs.imap_auth_type, P_ENUM,
570          &receive_page.imap_auth_type_optmenu,
571          prefs_account_imap_auth_type_set_data_from_optmenu,
572          prefs_account_imap_auth_type_set_optmenu},
573
574         {"receive_at_get_all", "TRUE", &tmp_ac_prefs.recv_at_getall, P_BOOL,
575          &receive_page.recvatgetall_checkbtn,
576          prefs_set_data_from_toggle, prefs_set_toggle},
577
578         {"max_news_articles", "300", &tmp_ac_prefs.max_articles, P_INT,
579          &receive_page.maxarticle_spinbtn,
580          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
581
582         {"inbox", "#mh/Mailbox/inbox", &tmp_ac_prefs.inbox, P_STRING,
583          &receive_page.inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
584
585         {"local_inbox", "#mh/Mailbox/inbox", &tmp_ac_prefs.local_inbox, P_STRING,
586          &receive_page.local_inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
587
588         {"imap_directory", NULL, &tmp_ac_prefs.imap_dir, P_STRING,
589          &receive_page.imapdir_entry, prefs_set_data_from_entry, prefs_set_entry},
590
591         {"imap_subsonly", "TRUE", &tmp_ac_prefs.imap_subsonly, P_BOOL,
592          &receive_page.subsonly_checkbtn,
593          prefs_set_data_from_toggle, prefs_set_toggle},
594
595         {"low_bandwidth", "FALSE", &tmp_ac_prefs.low_bandwidth, P_BOOL,
596          &receive_page.low_bandwidth_checkbtn,
597          prefs_set_data_from_toggle, prefs_set_toggle},
598
599         {"autochk_use_default", "TRUE", &tmp_ac_prefs.autochk_use_default, P_BOOL,
600                 &receive_page.autochk_use_default_checkbtn,
601                 prefs_set_data_from_toggle, prefs_set_toggle},
602
603         {"autochk_use_custom", "FALSE", &tmp_ac_prefs.autochk_use_custom, P_BOOL,
604                 &receive_page.autochk_checkbtn,
605                 prefs_set_data_from_toggle, prefs_set_toggle},
606
607         /* Here we lie a bit, passing a pointer to our custom struct,
608          * disguised as a GtkWidget pointer, to get around the
609          * inflexibility of PrefParam system. */
610         {"autochk_interval", "600", &tmp_ac_prefs.autochk_itv, P_INT,
611                 (GtkWidget **)&receive_page.autochk_widgets,
612                 prefs_account_set_autochk_interval_from_widgets,
613                 prefs_account_set_autochk_interval_to_widgets},
614
615         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
616 };
617
618 static PrefParam send_param[] = {
619         {"generate_msgid", "TRUE", &tmp_ac_prefs.gen_msgid, P_BOOL,
620          &send_page.msgid_checkbtn,
621          prefs_set_data_from_toggle, prefs_set_toggle},
622
623         {"generate_xmailer", "TRUE", &tmp_ac_prefs.gen_xmailer, P_BOOL,
624          &send_page.xmailer_checkbtn,
625          prefs_set_data_from_toggle, prefs_set_toggle},
626
627         {"add_custom_header", "FALSE", &tmp_ac_prefs.add_customhdr, P_BOOL,
628          &send_page.customhdr_checkbtn,
629          prefs_set_data_from_toggle, prefs_set_toggle},
630
631         {"msgid_with_addr", "FALSE", &tmp_ac_prefs.msgid_with_addr, P_BOOL,
632          &send_page.msgid_with_addr_checkbtn,
633          prefs_set_data_from_toggle, prefs_set_toggle},
634
635          {"use_smtp_auth", "FALSE", &tmp_ac_prefs.use_smtp_auth, P_BOOL,
636          &send_page.smtp_auth_checkbtn,
637          prefs_set_data_from_toggle, prefs_set_toggle},
638
639         {"smtp_auth_method", "0", &tmp_ac_prefs.smtp_auth_type, P_ENUM,
640          &send_page.smtp_auth_type_optmenu,
641          prefs_account_smtp_auth_type_set_data_from_optmenu,
642          prefs_account_smtp_auth_type_set_optmenu},
643
644         {"smtp_user_id", NULL, &tmp_ac_prefs.smtp_userid, P_STRING,
645          &send_page.smtp_uid_entry, prefs_set_data_from_entry, prefs_set_entry},
646         {"smtp_password", NULL, &tmp_ac_prefs.smtp_passwd, P_PASSWORD,
647          NULL, NULL, NULL},
648
649         {"pop_before_smtp", "FALSE", &tmp_ac_prefs.pop_before_smtp, P_BOOL,
650          &send_page.pop_bfr_smtp_checkbtn,
651          prefs_set_data_from_toggle, prefs_set_toggle},
652
653         {"pop_before_smtp_timeout", "5", &tmp_ac_prefs.pop_before_smtp_timeout, P_INT,
654          &send_page.pop_bfr_smtp_tm_spinbtn,
655          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
656
657         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
658 };
659
660 static PrefParam oauth2_param[] = {
661         {"oauth2_auth_provider", "0", &tmp_ac_prefs.oauth2_provider, P_ENUM,
662          &oauth2_page.oauth2_auth_optmenu,
663          prefs_account_oauth2_provider_set_data_from_optmenu,
664          prefs_account_oauth2_provider_set_optmenu},
665
666         {"oauth2_date", 0, &tmp_ac_prefs.oauth2_date, P_INT,
667          NULL, NULL, NULL},
668
669         {"oauth2_authcode", NULL, &tmp_ac_prefs.oauth2_authcode, P_PASSWORD,
670          NULL, NULL, NULL},
671
672         {"oauth2_client_id", NULL, &tmp_ac_prefs.oauth2_client_id, P_STRING,
673          &oauth2_page.oauth2_client_id_entry, prefs_set_data_from_entry, prefs_set_entry},
674
675         {"oauth2_client_secret", NULL, &tmp_ac_prefs.oauth2_client_secret, P_STRING,
676          &oauth2_page.oauth2_client_secret_entry, prefs_set_data_from_entry, prefs_set_entry},
677
678         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
679 };
680
681 static PrefParam compose_param[] = {
682         {"signature_type", "0", &tmp_ac_prefs.sig_type, P_ENUM,
683          &compose_page.sigfile_radiobtn,
684          prefs_account_enum_set_data_from_radiobtn,
685          prefs_account_enum_set_radiobtn},
686         {"signature_path", "~" G_DIR_SEPARATOR_S DEFAULT_SIGNATURE,
687          &tmp_ac_prefs.sig_path, P_STRING, &compose_page.entry_sigpath,
688          prefs_set_data_from_entry, prefs_set_entry},
689
690         {"auto_signature", "TRUE", &tmp_ac_prefs.auto_sig, P_BOOL,
691          &compose_page.checkbtn_autosig,
692          prefs_set_data_from_toggle, prefs_set_toggle},
693          
694         {"signature_separator", "-- ", &tmp_ac_prefs.sig_sep, P_STRING,
695          &compose_page.entry_sigsep, 
696          prefs_set_data_from_entry, prefs_set_entry},
697
698         {"set_autocc", "FALSE", &tmp_ac_prefs.set_autocc, P_BOOL,
699          &compose_page.autocc_checkbtn,
700          prefs_set_data_from_toggle, prefs_set_toggle},
701
702         {"auto_cc", NULL, &tmp_ac_prefs.auto_cc, P_STRING,
703          &compose_page.autocc_entry,
704          prefs_set_data_from_entry, prefs_set_entry},
705
706         {"set_autobcc", "FALSE", &tmp_ac_prefs.set_autobcc, P_BOOL,
707          &compose_page.autobcc_checkbtn,
708          prefs_set_data_from_toggle, prefs_set_toggle},
709
710         {"auto_bcc", NULL, &tmp_ac_prefs.auto_bcc, P_STRING,
711          &compose_page.autobcc_entry,
712          prefs_set_data_from_entry, prefs_set_entry},
713
714         {"set_autoreplyto", "FALSE", &tmp_ac_prefs.set_autoreplyto, P_BOOL,
715          &compose_page.autoreplyto_checkbtn,
716          prefs_set_data_from_toggle, prefs_set_toggle},
717
718         {"auto_replyto", NULL, &tmp_ac_prefs.auto_replyto, P_STRING,
719          &compose_page.autoreplyto_entry,
720          prefs_set_data_from_entry, prefs_set_entry},
721
722 #if USE_ENCHANT
723         {"enable_default_dictionary", "", &tmp_ac_prefs.enable_default_dictionary, P_BOOL,
724          &compose_page.checkbtn_enable_default_dictionary,
725          prefs_set_data_from_toggle, prefs_set_toggle},
726
727         {"default_dictionary", NULL, &tmp_ac_prefs.default_dictionary, P_STRING,
728          &compose_page.combo_default_dictionary,
729          prefs_account_compose_default_dictionary_set_string_from_optmenu,
730          prefs_account_compose_default_dictionary_set_optmenu_from_string},
731
732         {"enable_default_alt_dictionary", "", &tmp_ac_prefs.enable_default_alt_dictionary, P_BOOL,
733          &compose_page.checkbtn_enable_default_alt_dictionary,
734          prefs_set_data_from_toggle, prefs_set_toggle},
735
736         {"default_alt_dictionary", NULL, &tmp_ac_prefs.default_alt_dictionary, P_STRING,
737          &compose_page.combo_default_alt_dictionary,
738          prefs_account_compose_default_dictionary_set_string_from_optmenu,
739          prefs_account_compose_default_dictionary_set_optmenu_from_string},
740 #else
741         {"enable_default_dictionary", "", &tmp_ac_prefs.enable_default_dictionary, P_BOOL,
742          NULL, NULL, NULL},
743
744         {"default_dictionary", NULL, &tmp_ac_prefs.default_dictionary, P_STRING,
745          NULL, NULL, NULL},
746
747         {"enable_default_alt_dictionary", "", &tmp_ac_prefs.enable_default_alt_dictionary, P_BOOL,
748          NULL, NULL, NULL},
749
750         {"default_alt_dictionary", NULL, &tmp_ac_prefs.default_alt_dictionary, P_STRING,
751          NULL, NULL, NULL},
752 #endif   
753
754         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
755 };
756
757 static PrefParam templates_param[] = {
758         {"compose_with_format", "FALSE", &tmp_ac_prefs.compose_with_format, P_BOOL,
759          &templates_page.checkbtn_compose_with_format,
760          prefs_set_data_from_toggle, prefs_set_toggle},
761
762         {"compose_subject_format", NULL, &tmp_ac_prefs.compose_subject_format, P_STRING,
763          &templates_page.compose_subject_format,
764          prefs_set_escaped_data_from_entry, prefs_set_entry_from_escaped},
765
766         {"compose_body_format", NULL, &tmp_ac_prefs.compose_body_format, P_STRING,
767          &templates_page.compose_body_format,
768          prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
769
770         {"reply_with_format", "FALSE", &tmp_ac_prefs.reply_with_format, P_BOOL,
771          &templates_page.checkbtn_reply_with_format,
772          prefs_set_data_from_toggle, prefs_set_toggle},
773
774         {"reply_quotemark", NULL, &tmp_ac_prefs.reply_quotemark, P_STRING,
775          &templates_page.reply_quotemark,
776          prefs_set_data_from_entry, prefs_set_entry_from_escaped},
777
778         {"reply_body_format", NULL, &tmp_ac_prefs.reply_body_format, P_STRING,
779          &templates_page.reply_body_format,
780          prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
781
782         {"forward_with_format", "FALSE", &tmp_ac_prefs.forward_with_format, P_BOOL,
783          &templates_page.checkbtn_forward_with_format,
784          prefs_set_data_from_toggle, prefs_set_toggle},
785
786         {"forward_quotemark", NULL, &tmp_ac_prefs.forward_quotemark, P_STRING,
787          &templates_page.forward_quotemark,
788          prefs_set_data_from_entry, prefs_set_entry_from_escaped},
789
790         {"forward_body_format", NULL, &tmp_ac_prefs.forward_body_format, P_STRING,
791          &templates_page.forward_body_format,
792          prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
793
794         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
795 };
796
797 static PrefParam privacy_param[] = {
798         {"default_privacy_system", "", &tmp_ac_prefs.default_privacy_system, P_STRING,
799          &privacy_page.default_privacy_system,
800          prefs_account_set_string_from_combobox,
801          prefs_account_set_privacy_combobox_from_string},
802
803         {"default_encrypt", "FALSE", &tmp_ac_prefs.default_encrypt, P_BOOL,
804          &privacy_page.default_encrypt_checkbtn,
805          prefs_set_data_from_toggle, prefs_set_toggle},
806
807         {"default_encrypt_reply", "TRUE", &tmp_ac_prefs.default_encrypt_reply, P_BOOL,
808          &privacy_page.default_encrypt_reply_checkbtn,
809          prefs_set_data_from_toggle, prefs_set_toggle},
810
811         {"default_sign", "FALSE", &tmp_ac_prefs.default_sign, P_BOOL,
812          &privacy_page.default_sign_checkbtn,
813          prefs_set_data_from_toggle, prefs_set_toggle},
814 #ifdef G_OS_UNIX
815         {"default_sign_reply", "TRUE", &tmp_ac_prefs.default_sign_reply, P_BOOL,
816          &privacy_page.default_sign_reply_checkbtn,
817          prefs_set_data_from_toggle, prefs_set_toggle},
818 #else
819         /* Bug 2367: disturbing for Win32 users with no keypair */
820         {"default_sign_reply", "FALSE", &tmp_ac_prefs.default_sign_reply, P_BOOL,
821          &privacy_page.default_sign_reply_checkbtn,
822          prefs_set_data_from_toggle, prefs_set_toggle},
823 #endif
824         {"save_clear_text", "FALSE", &tmp_ac_prefs.save_encrypted_as_clear_text, P_BOOL,
825          &privacy_page.save_clear_text_checkbtn,
826          prefs_set_data_from_toggle, prefs_set_toggle},
827
828         {"encrypt_to_self", "FALSE", &tmp_ac_prefs.encrypt_to_self, P_BOOL,
829          &privacy_page.encrypt_to_self_checkbtn,
830          prefs_set_data_from_toggle, prefs_set_toggle},
831
832         {"privacy_prefs", "", &privacy_prefs, P_STRING,
833          NULL, NULL, NULL},
834
835         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
836 };
837
838 static PrefParam ssl_param[] = {
839 #ifdef USE_GNUTLS
840         {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
841          &ssl_page.pop_nossl_radiobtn,
842          prefs_account_enum_set_data_from_radiobtn,
843          prefs_account_enum_set_radiobtn},
844
845         {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
846          &ssl_page.imap_nossl_radiobtn,
847          prefs_account_enum_set_data_from_radiobtn,
848          prefs_account_enum_set_radiobtn},
849
850         {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
851          &ssl_page.nntp_nossl_radiobtn,
852          prefs_account_enum_set_data_from_radiobtn,
853          prefs_account_enum_set_radiobtn},
854
855         {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
856          &ssl_page.smtp_nossl_radiobtn,
857          prefs_account_enum_set_data_from_radiobtn,
858          prefs_account_enum_set_radiobtn},
859
860         {"ssl_certs_auto_accept", "0", &tmp_ac_prefs.ssl_certs_auto_accept, P_BOOL,
861          &ssl_page.ssl_certs_auto_accept_checkbtn,
862          prefs_set_data_from_toggle, prefs_set_toggle},
863
864         {"use_nonblocking_ssl", "1", &tmp_ac_prefs.use_nonblocking_ssl, P_BOOL,
865          &ssl_page.use_nonblocking_ssl_checkbtn,
866          prefs_set_data_from_toggle, prefs_set_toggle},
867
868         {"use_tls_sni", "1", &tmp_ac_prefs.use_tls_sni, P_BOOL,
869          NULL, NULL, NULL},
870
871         {"in_ssl_client_cert_file", "", &tmp_ac_prefs.in_ssl_client_cert_file, P_STRING,
872          &ssl_page.entry_in_cert_file, prefs_set_data_from_entry, prefs_set_entry},
873
874         {"in_ssl_client_cert_pass", "", &tmp_ac_prefs.in_ssl_client_cert_pass, P_PASSWORD,
875          NULL, NULL, NULL},
876
877         {"out_ssl_client_cert_file", "", &tmp_ac_prefs.out_ssl_client_cert_file, P_STRING,
878          &ssl_page.entry_out_cert_file, prefs_set_data_from_entry, prefs_set_entry},
879
880         {"out_ssl_client_cert_pass", "", &tmp_ac_prefs.out_ssl_client_cert_pass, P_PASSWORD,
881          NULL, NULL, NULL},
882 #else
883         {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
884          NULL, NULL, NULL},
885
886         {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
887          NULL, NULL, NULL},
888
889         {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
890          NULL, NULL, NULL},
891
892         {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
893          NULL, NULL, NULL},
894
895         {"in_ssl_client_cert_file", "", &tmp_ac_prefs.in_ssl_client_cert_file, P_STRING,
896          NULL, NULL, NULL},
897
898         {"in_ssl_client_cert_pass", "", &tmp_ac_prefs.in_ssl_client_cert_pass, P_PASSWORD,
899          NULL, NULL, NULL},
900
901         {"out_ssl_client_cert_file", "", &tmp_ac_prefs.out_ssl_client_cert_file, P_STRING,
902          NULL, NULL, NULL},
903
904         {"out_ssl_client_cert_pass", "", &tmp_ac_prefs.out_ssl_client_cert_pass, P_PASSWORD,
905          NULL, NULL, NULL},
906
907         {"ssl_certs_auto_accept", "0", &tmp_ac_prefs.ssl_certs_auto_accept, P_BOOL,
908          NULL, NULL, NULL},
909
910         {"use_nonblocking_ssl", "1", &tmp_ac_prefs.use_nonblocking_ssl, P_BOOL,
911          NULL, NULL, NULL},
912 #endif /* USE_GNUTLS */
913
914         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
915 };
916
917 static PrefParam proxy_param[] = {
918         /* SOCKS proxy */
919         {"use_proxy", "FALSE", &tmp_ac_prefs.use_proxy, P_BOOL,
920         &proxy_page.proxy_checkbtn,
921         prefs_set_data_from_toggle, prefs_set_toggle},
922
923         {"use_default_proxy", "TRUE", &tmp_ac_prefs.use_default_proxy, P_BOOL,
924         &proxy_page.default_proxy_checkbtn,
925         prefs_set_data_from_toggle, prefs_set_toggle},
926
927         {"use_proxy_for_send", "TRUE", &tmp_ac_prefs.use_proxy_for_send, P_BOOL,
928         &proxy_page.proxy_send_checkbtn,
929         prefs_set_data_from_toggle, prefs_set_toggle},
930
931         {"proxy_type", "1", &tmp_ac_prefs.proxy_info.proxy_type, P_ENUM,
932         &proxy_page.socks4_radiobtn,
933         prefs_account_enum_set_data_from_radiobtn,
934         prefs_account_enum_set_radiobtn},
935
936         {"proxy_host", "localhost", &tmp_ac_prefs.proxy_info.proxy_host, P_STRING,
937         &proxy_page.proxy_host_entry,
938         prefs_set_data_from_entry, prefs_set_entry},
939
940         {"proxy_port", "1080", &tmp_ac_prefs.proxy_info.proxy_port, P_USHORT,
941         &proxy_page.proxy_port_spinbtn,
942         prefs_set_data_from_spinbtn, prefs_set_spinbtn},
943
944         {"use_proxy_auth", "FALSE", &tmp_ac_prefs.proxy_info.use_proxy_auth, P_BOOL,
945         &proxy_page.proxy_auth_checkbtn,
946         prefs_set_data_from_toggle, prefs_set_toggle},
947
948         {"proxy_name", "", &tmp_ac_prefs.proxy_info.proxy_name, P_STRING,
949         &proxy_page.proxy_name_entry,
950         prefs_set_data_from_entry, prefs_set_entry},
951
952         {"proxy_pass", NULL, &tmp_ac_prefs.proxy_info.proxy_pass, P_PASSWORD,
953         NULL, NULL, NULL},
954
955
956         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
957 };
958
959 static PrefParam advanced_param[] = {
960         {"set_smtpport", "FALSE", &tmp_ac_prefs.set_smtpport, P_BOOL,
961          &advanced_page.smtpport_checkbtn,
962          prefs_set_data_from_toggle, prefs_set_toggle},
963
964         {"smtp_port", "25", &tmp_ac_prefs.smtpport, P_USHORT,
965          &advanced_page.smtpport_spinbtn,
966          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
967
968         {"set_popport", "FALSE", &tmp_ac_prefs.set_popport, P_BOOL,
969          &advanced_page.popport_checkbtn,
970          prefs_set_data_from_toggle, prefs_set_toggle},
971
972         {"pop_port", "110", &tmp_ac_prefs.popport, P_USHORT,
973          &advanced_page.popport_spinbtn,
974          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
975
976         {"set_imapport", "FALSE", &tmp_ac_prefs.set_imapport, P_BOOL,
977          &advanced_page.imapport_checkbtn,
978          prefs_set_data_from_toggle, prefs_set_toggle},
979
980         {"imap_port", "143", &tmp_ac_prefs.imapport, P_USHORT,
981          &advanced_page.imapport_spinbtn,
982          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
983
984         {"set_nntpport", "FALSE", &tmp_ac_prefs.set_nntpport, P_BOOL,
985          &advanced_page.nntpport_checkbtn,
986          prefs_set_data_from_toggle, prefs_set_toggle},
987
988         {"nntp_port", "119", &tmp_ac_prefs.nntpport, P_USHORT,
989          &advanced_page.nntpport_spinbtn,
990          prefs_set_data_from_spinbtn, prefs_set_spinbtn},
991
992         {"set_domain", "FALSE", &tmp_ac_prefs.set_domain, P_BOOL,
993          &advanced_page.domain_checkbtn,
994          prefs_set_data_from_toggle, prefs_set_toggle},
995
996         {"domain", NULL, &tmp_ac_prefs.domain, P_STRING,
997          &advanced_page.domain_entry,
998          prefs_set_data_from_entry, prefs_set_entry},
999
1000 #ifdef USE_GNUTLS
1001         {"gnutls_set_priority", "FALSE", &tmp_ac_prefs.set_gnutls_priority, P_BOOL,
1002          NULL, NULL, NULL},
1003
1004         {"gnutls_priority", NULL, &tmp_ac_prefs.gnutls_priority, P_STRING,
1005          NULL, NULL, NULL},
1006 #endif
1007
1008 #ifndef G_OS_WIN32
1009         {"set_tunnelcmd", "FALSE", &tmp_ac_prefs.set_tunnelcmd, P_BOOL,
1010          &advanced_page.tunnelcmd_checkbtn,
1011          prefs_set_data_from_toggle, prefs_set_toggle},
1012
1013         {"tunnelcmd", NULL, &tmp_ac_prefs.tunnelcmd, P_STRING,
1014          &advanced_page.tunnelcmd_entry,
1015          prefs_set_data_from_entry, prefs_set_entry},
1016 #endif
1017         {"mark_crosspost_read", "FALSE", &tmp_ac_prefs.mark_crosspost_read, P_BOOL,
1018          &advanced_page.crosspost_checkbtn,
1019          prefs_set_data_from_toggle, prefs_set_toggle},
1020
1021         {"crosspost_color", NULL, &tmp_ac_prefs.crosspost_col, P_ENUM,
1022          &advanced_page.crosspost_colormenu,
1023          prefs_account_crosspost_set_data_from_colormenu,
1024          prefs_account_crosspost_set_colormenu},
1025
1026         {"set_sent_folder", "FALSE", &tmp_ac_prefs.set_sent_folder, P_BOOL,
1027          &advanced_page.sent_folder_checkbtn,
1028          prefs_set_data_from_toggle, prefs_set_toggle},
1029         {"sent_folder", NULL, &tmp_ac_prefs.sent_folder, P_STRING,
1030          &advanced_page.sent_folder_entry,
1031          prefs_set_data_from_entry, prefs_set_entry},
1032
1033         {"set_queue_folder", "FALSE", &tmp_ac_prefs.set_queue_folder, P_BOOL,
1034          &advanced_page.queue_folder_checkbtn,
1035          prefs_set_data_from_toggle, prefs_set_toggle},
1036         {"queue_folder", NULL, &tmp_ac_prefs.queue_folder, P_STRING,
1037          &advanced_page.queue_folder_entry,
1038          prefs_set_data_from_entry, prefs_set_entry},
1039
1040         {"set_draft_folder", "FALSE", &tmp_ac_prefs.set_draft_folder, P_BOOL,
1041          &advanced_page.draft_folder_checkbtn,
1042          prefs_set_data_from_toggle, prefs_set_toggle},
1043         {"draft_folder", NULL, &tmp_ac_prefs.draft_folder, P_STRING,
1044          &advanced_page.draft_folder_entry,
1045          prefs_set_data_from_entry, prefs_set_entry},
1046
1047         {"set_trash_folder", "FALSE", &tmp_ac_prefs.set_trash_folder, P_BOOL,
1048          &advanced_page.trash_folder_checkbtn,
1049          prefs_set_data_from_toggle, prefs_set_toggle},
1050         {"trash_folder", NULL, &tmp_ac_prefs.trash_folder, P_STRING,
1051          &advanced_page.trash_folder_entry,
1052          prefs_set_data_from_entry, prefs_set_entry},
1053          
1054
1055         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
1056 };
1057
1058 static gint prefs_account_get_new_id            (void);
1059
1060 static void prefs_account_select_folder_cb      (GtkWidget      *widget,
1061                                                  gpointer        data);
1062
1063 static void prefs_account_sigfile_radiobtn_cb   (GtkWidget      *widget,
1064                                                  gpointer        data);
1065
1066 static void prefs_account_sigcmd_radiobtn_cb    (GtkWidget      *widget,
1067                                                  gpointer        data);
1068
1069 static void prefs_account_signature_browse_cb   (GtkWidget      *widget,
1070                                                  gpointer        data);
1071 #ifdef USE_GNUTLS
1072 static void prefs_account_in_cert_browse_cb     (GtkWidget      *widget,
1073                                                  gpointer        data);
1074
1075 static void prefs_account_out_cert_browse_cb    (GtkWidget      *widget,
1076                                                  gpointer        data);
1077 #endif
1078 static void prefs_account_signature_edit_cb     (GtkWidget      *widget,
1079                                                  gpointer        data);
1080
1081 static void pop_bfr_smtp_tm_set_sens            (GtkWidget      *widget,
1082                                                  gpointer        data);
1083
1084 #if (defined USE_GNUTLS)
1085 static void auto_configure_cb                   (GtkWidget      *widget,
1086                                                  gpointer        data);
1087
1088 #endif
1089 static void prefs_account_edit_custom_header    (void);
1090
1091 static void prefs_account_receive_itv_spinbutton_value_changed_cb(GtkWidget *w,
1092                                           gpointer data);
1093
1094 #define COMBOBOX_PRIVACY_PLUGIN_ID 3
1095
1096 /* Enable/disable necessary preference widgets based on current privacy
1097  * system choice. */
1098 static void privacy_system_activated(GtkWidget *combobox)
1099 {
1100         gtk_widget_set_sensitive (privacy_page.save_clear_text_checkbtn, 
1101                 !gtk_toggle_button_get_active(
1102                                 GTK_TOGGLE_BUTTON(privacy_page.encrypt_to_self_checkbtn)));
1103 }
1104
1105 /* Populate the privacy system choice combobox with valid choices */
1106 static void update_privacy_system_menu() {
1107         GtkListStore *menu;
1108         GtkTreeIter iter;
1109         GSList *system_ids, *cur;
1110
1111         menu = GTK_LIST_STORE(gtk_combo_box_get_model(
1112                         GTK_COMBO_BOX(privacy_page.default_privacy_system)));
1113
1114         /* First add "None", as that one is always available. :) */
1115         gtk_list_store_append(menu, &iter);
1116         gtk_list_store_set(menu, &iter,
1117                         COMBOBOX_TEXT, _("None"),
1118                         COMBOBOX_DATA, 0,
1119                         COMBOBOX_SENS, TRUE,
1120                         COMBOBOX_PRIVACY_PLUGIN_ID, "",
1121                         -1);
1122
1123         /* Now go through list of available privacy systems and add an entry
1124          * for each. */
1125         system_ids = privacy_get_system_ids();
1126         for (cur = system_ids; cur != NULL; cur = g_slist_next(cur)) {
1127                 gchar *id = (gchar *) cur->data;
1128                 const gchar *name;
1129                 
1130                 name = privacy_system_get_name(id);
1131                 gtk_list_store_append(menu, &iter);
1132                 gtk_list_store_set(menu, &iter,
1133                                 COMBOBOX_TEXT, name,
1134                                 COMBOBOX_DATA, 1,
1135                                 COMBOBOX_SENS, TRUE,
1136                                 COMBOBOX_PRIVACY_PLUGIN_ID, id,
1137                                 -1);
1138                 g_free(id);
1139         }
1140         g_slist_free(system_ids);
1141
1142 }
1143
1144 #define TABLE_YPAD 2
1145
1146 static void basic_create_widget_func(PrefsPage * _page,
1147                                            GtkWindow * window,
1148                                            gpointer data)
1149 {
1150         BasicPage *page = (BasicPage *) _page;
1151         PrefsAccount *ac_prefs = (PrefsAccount *) data;
1152
1153         GtkWidget *vbox1;
1154         GtkWidget *hbox;
1155         GtkWidget *label;
1156         GtkWidget *acname_entry;
1157         GtkWidget *default_checkbtn;
1158         GtkWidget *frame1;
1159         GtkWidget *table1;
1160         GtkWidget *name_entry;
1161         GtkWidget *addr_entry;
1162         GtkWidget *org_entry;
1163
1164         GtkWidget *serv_frame;
1165         GtkWidget *vbox2;
1166         GtkWidget *optmenubox;
1167         GtkWidget *optmenu;
1168         GtkWidget *optlabel;
1169         GtkWidget *no_imap_warn_icon;
1170         GtkWidget *no_imap_warn_label;
1171         GtkWidget *serv_table;
1172         GtkWidget *recvserv_label;
1173         GtkWidget *smtpserv_label;
1174         GtkWidget *nntpserv_label;
1175         GtkWidget *localmbox_label;
1176         GtkWidget *mailcmd_label;
1177         GtkWidget *recvserv_entry;
1178         GtkWidget *smtpserv_entry;
1179         GtkWidget *nntpserv_entry;
1180         GtkWidget *nntpauth_checkbtn;
1181         GtkWidget *nntpauth_onconnect_checkbtn;
1182         GtkWidget *localmbox_entry;
1183         GtkWidget *mailcmd_checkbtn;
1184         GtkWidget *mailcmd_entry;
1185         GtkWidget *uid_label;
1186         GtkWidget *pass_label;
1187         GtkWidget *uid_entry;
1188         GtkWidget *pass_entry;
1189         GtkWidget *auto_configure_btn;
1190         GtkWidget *auto_configure_cancel_btn;
1191         GtkWidget *auto_configure_lbl;
1192         GtkWidget *showpwd_checkbtn;
1193         GtkListStore *menu;
1194         GtkTreeIter iter;
1195         gchar *buf;
1196
1197         struct BasicProtocol *protocol_optmenu;
1198         gint i;
1199
1200         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
1201         gtk_widget_show (vbox1);
1202         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1203
1204         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1205         gtk_widget_show (hbox);
1206         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
1207
1208         label = gtk_label_new (_("Name of account"));
1209         gtk_widget_show (label);
1210         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1211
1212         acname_entry = gtk_entry_new ();
1213         gtk_widget_show (acname_entry);
1214         gtk_widget_set_size_request (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
1215         gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
1216
1217         default_checkbtn = gtk_check_button_new_with_label (_("Set as default"));
1218         gtk_widget_show (default_checkbtn);
1219 #ifndef GENERIC_UMPC
1220         gtk_box_pack_end (GTK_BOX (hbox), default_checkbtn, TRUE, FALSE, 0);
1221 #else
1222         gtk_box_pack_start (GTK_BOX (vbox1), default_checkbtn, FALSE, FALSE, 0);
1223         
1224 #endif
1225         PACK_FRAME (vbox1, frame1, _("Personal information"));
1226
1227         table1 = gtk_grid_new();
1228         gtk_widget_show (table1);
1229         gtk_container_add (GTK_CONTAINER (frame1), table1);
1230         gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
1231         gtk_grid_set_row_spacing(GTK_GRID(table1), VSPACING_NARROW);
1232         gtk_grid_set_column_spacing(GTK_GRID(table1), 8);
1233
1234         label = gtk_label_new (_("Full name"));
1235         gtk_widget_show (label);
1236         gtk_label_set_xalign(GTK_LABEL (label), 1.0);
1237         gtk_grid_attach(GTK_GRID(table1), label, 0, 0, 1, 1);
1238
1239         label = gtk_label_new (_("Mail address"));
1240         gtk_widget_show (label);
1241         gtk_label_set_xalign(GTK_LABEL (label), 1.0);
1242         gtk_grid_attach(GTK_GRID(table1), label, 0, 1, 1, 1);
1243
1244         label = gtk_label_new (_("Organization"));
1245         gtk_widget_show (label);
1246         gtk_label_set_xalign(GTK_LABEL (label), 1.0);
1247         gtk_grid_attach(GTK_GRID(table1), label, 0, 2, 1, 1);
1248
1249         name_entry = gtk_entry_new ();
1250         gtk_widget_show (name_entry);
1251         gtk_grid_attach(GTK_GRID(table1), name_entry, 1, 0, 1, 1);
1252         gtk_widget_set_hexpand(name_entry, TRUE);
1253         gtk_widget_set_halign(name_entry, GTK_ALIGN_FILL);
1254
1255         addr_entry = gtk_entry_new ();
1256         gtk_widget_show (addr_entry);
1257         gtk_grid_attach(GTK_GRID(table1), addr_entry, 1, 1, 1, 1);
1258         gtk_widget_set_hexpand(addr_entry, TRUE);
1259         gtk_widget_set_halign(addr_entry, GTK_ALIGN_FILL);
1260
1261         org_entry = gtk_entry_new ();
1262         gtk_widget_show (org_entry);
1263         gtk_grid_attach(GTK_GRID(table1), org_entry, 1, 2, 1, 1);
1264         gtk_widget_set_hexpand(org_entry, TRUE);
1265         gtk_widget_set_halign(org_entry, GTK_ALIGN_FILL);
1266
1267         vbox2 = gtkut_get_options_frame(vbox1, &serv_frame, _("Server information"));
1268
1269         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1270         gtk_widget_show (hbox);
1271         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1272
1273         label = gtk_label_new (_("Protocol"));
1274         gtk_widget_show (label);
1275         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1276
1277         /* Create GtkHBox for protocol combobox and label */
1278         optmenubox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 20);
1279         gtk_widget_show(optmenubox);
1280         gtk_box_pack_start (GTK_BOX (hbox), optmenubox, FALSE, FALSE, 0);
1281
1282         /* Create and populate the combobox */
1283         optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1284         gtk_box_pack_start(GTK_BOX (optmenubox), optmenu, FALSE, FALSE, 0);
1285
1286         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1287         for( i = 0; i < NUM_RECV_PROTOCOLS; i++ )
1288                 if( protocol_names[i] != NULL )
1289                         COMBOBOX_ADD (menu, _(protocol_names[i]), i);
1290
1291         g_signal_connect(G_OBJECT(optmenu), "changed",
1292                         G_CALLBACK(prefs_account_protocol_changed), NULL);
1293
1294         /* Create protocol label, empty for now */
1295         optlabel = gtk_label_new("");
1296         gtk_label_set_use_markup(GTK_LABEL(optlabel), TRUE);
1297         gtk_label_set_justify(GTK_LABEL(optlabel), GTK_JUSTIFY_CENTER);
1298         gtk_box_pack_start(GTK_BOX (optmenubox), optlabel, FALSE, FALSE, 0);
1299
1300         auto_configure_btn = gtk_button_new_with_label(_("Auto-configure"));
1301         gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_btn, FALSE, FALSE, 0);
1302         auto_configure_cancel_btn = gtk_button_new_with_label(_("Cancel"));
1303         gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_cancel_btn, FALSE, FALSE, 0);
1304         auto_configure_lbl = gtk_label_new("");
1305         gtk_label_set_justify(GTK_LABEL(auto_configure_lbl), GTK_JUSTIFY_LEFT);
1306         gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_lbl, FALSE, FALSE, 0);
1307 #if (defined USE_GNUTLS)
1308         gtk_widget_show(auto_configure_btn);
1309         gtk_widget_show(auto_configure_lbl);
1310         g_signal_connect (G_OBJECT (auto_configure_btn), "clicked",
1311                           G_CALLBACK (auto_configure_cb), NULL);
1312         g_signal_connect (G_OBJECT (auto_configure_cancel_btn), "clicked",
1313                           G_CALLBACK (auto_configure_cb), NULL);
1314 #endif
1315
1316         no_imap_warn_icon = gtk_image_new_from_icon_name
1317                         ("dialog-warning", GTK_ICON_SIZE_SMALL_TOOLBAR);
1318         buf = g_strconcat("<span weight=\"bold\">",
1319                         _("Warning: this version of Claws Mail\n"
1320                           "has been built without IMAP and News support."), "</span>", NULL);
1321         no_imap_warn_label = gtk_label_new(buf);
1322         g_free(buf);
1323         gtk_label_set_use_markup(GTK_LABEL(no_imap_warn_label), TRUE);
1324
1325         gtk_box_pack_start(GTK_BOX (optmenubox), no_imap_warn_icon, FALSE, FALSE, 0);
1326         gtk_box_pack_start(GTK_BOX (optmenubox), no_imap_warn_label, FALSE, FALSE, 0);
1327         /* Set up a struct to store pointers to necessary widgets */
1328         protocol_optmenu = g_new(struct BasicProtocol, 1);
1329         protocol_optmenu->combobox = optmenu;
1330         protocol_optmenu->label = optlabel;
1331         protocol_optmenu->descrlabel = label;
1332         protocol_optmenu->no_imap_warn_icon = no_imap_warn_icon;
1333         protocol_optmenu->no_imap_warn_label = no_imap_warn_label;
1334
1335         serv_table = gtk_grid_new ();
1336         gtk_widget_show (serv_table);
1337         gtk_grid_set_row_spacing(GTK_GRID(serv_table), VSPACING_NARROW);
1338         gtk_grid_set_column_spacing(GTK_GRID(serv_table), 8);
1339         gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
1340
1341         nntpserv_entry = gtk_entry_new ();
1342         gtk_widget_show (nntpserv_entry);
1343         gtk_grid_attach(GTK_GRID(serv_table), nntpserv_entry, 1, 0, 2, 1);
1344         gtk_widget_set_hexpand(nntpserv_entry, TRUE);
1345         gtk_widget_set_halign(nntpserv_entry, GTK_ALIGN_FILL);
1346
1347         nntpauth_checkbtn = gtk_check_button_new_with_label
1348                 (_("This server requires authentication"));
1349         gtk_widget_show (nntpauth_checkbtn);
1350         
1351         gtk_grid_attach(GTK_GRID(serv_table), nntpauth_checkbtn, 0, 6, 2, 1);
1352
1353         nntpauth_onconnect_checkbtn = gtk_check_button_new_with_label
1354                 (_("Authenticate on connect"));
1355         gtk_widget_show (nntpauth_onconnect_checkbtn);
1356
1357         gtk_grid_attach(GTK_GRID(serv_table), nntpauth_onconnect_checkbtn, 2, 6, 1, 1);
1358
1359         recvserv_entry = gtk_entry_new ();
1360         gtk_widget_show (recvserv_entry);
1361         gtk_grid_attach(GTK_GRID(serv_table), recvserv_entry, 1, 2, 2, 1);
1362         gtk_widget_set_hexpand(recvserv_entry, TRUE);
1363         gtk_widget_set_halign(recvserv_entry, GTK_ALIGN_FILL);
1364
1365         localmbox_entry = gtk_entry_new ();
1366         gtk_widget_show (localmbox_entry);
1367         gtk_grid_attach(GTK_GRID(serv_table), localmbox_entry, 1, 3, 2, 1);
1368         gtk_widget_set_hexpand(localmbox_entry, TRUE);
1369         gtk_widget_set_halign(localmbox_entry, GTK_ALIGN_FILL);
1370
1371         smtpserv_entry = gtk_entry_new ();
1372         gtk_widget_show (smtpserv_entry);
1373         gtk_grid_attach(GTK_GRID(serv_table), smtpserv_entry, 1, 4, 2, 1);
1374         gtk_widget_set_hexpand(smtpserv_entry, TRUE);
1375         gtk_widget_set_halign(smtpserv_entry, GTK_ALIGN_FILL);
1376
1377         mailcmd_entry = gtk_entry_new ();
1378         gtk_widget_show (mailcmd_entry);
1379         gtk_grid_attach(GTK_GRID(serv_table), mailcmd_entry, 1, 6, 2, 1);
1380         gtk_widget_set_hexpand(mailcmd_entry, TRUE);
1381         gtk_widget_set_halign(mailcmd_entry, GTK_ALIGN_FILL);
1382
1383         uid_entry = gtk_entry_new ();
1384         gtk_widget_show (uid_entry);
1385         gtk_widget_set_size_request (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1386         gtk_grid_attach(GTK_GRID(serv_table), uid_entry, 1, 7, 1, 1);
1387         gtk_widget_set_hexpand(uid_entry, TRUE);
1388         gtk_widget_set_halign(uid_entry, GTK_ALIGN_FILL);
1389         g_signal_connect(G_OBJECT(uid_entry), "changed",
1390                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1391                         GINT_TO_POINTER(ac_prefs->protocol));
1392
1393         pass_entry = gtk_entry_new ();
1394         gtk_widget_show (pass_entry);
1395         gtk_widget_set_size_request (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1396         gtk_grid_attach(GTK_GRID(serv_table), pass_entry, 1, 8, 1, 1);
1397         gtk_widget_set_hexpand(pass_entry, TRUE);
1398         gtk_widget_set_halign(pass_entry, GTK_ALIGN_FILL);
1399         gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
1400         g_signal_connect(G_OBJECT(pass_entry), "changed",
1401                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1402                         GINT_TO_POINTER(ac_prefs->protocol));
1403
1404         nntpserv_label = gtk_label_new (_("News server"));
1405         gtk_widget_show (nntpserv_label);
1406         gtk_label_set_xalign(GTK_LABEL (nntpserv_label), 1.0);
1407         gtk_grid_attach(GTK_GRID(serv_table), nntpserv_label, 0, 0, 1, 1);
1408
1409         recvserv_label = gtk_label_new (_("Server for receiving"));
1410         gtk_widget_show (recvserv_label);
1411         gtk_label_set_xalign(GTK_LABEL (recvserv_label), 1.0);
1412         gtk_grid_attach(GTK_GRID(serv_table), recvserv_label, 0, 2, 1, 1);
1413
1414         localmbox_label = gtk_label_new (_("Local mailbox"));
1415         gtk_widget_show (localmbox_label);
1416         gtk_label_set_xalign(GTK_LABEL (localmbox_label), 1.0);
1417         gtk_grid_attach(GTK_GRID(serv_table), localmbox_label, 0, 3, 1, 1);
1418
1419         smtpserv_label = gtk_label_new (_("SMTP server (send)"));
1420         gtk_widget_show (smtpserv_label);
1421         gtk_label_set_xalign(GTK_LABEL (smtpserv_label), 1.0);
1422         gtk_grid_attach(GTK_GRID(serv_table), smtpserv_label, 0, 4, 1, 1);
1423
1424         mailcmd_checkbtn = gtk_check_button_new_with_label
1425                 (_("Use mail command rather than SMTP server"));
1426         gtk_widget_show (mailcmd_checkbtn);
1427         gtk_grid_attach(GTK_GRID(serv_table), mailcmd_checkbtn, 0, 5, 2, 1);
1428
1429         g_signal_connect(G_OBJECT(mailcmd_checkbtn), "toggled",
1430                          G_CALLBACK(prefs_account_mailcmd_toggled),
1431                          NULL);
1432
1433         mailcmd_label = gtk_label_new (_("command to send mails"));
1434         gtk_widget_show (mailcmd_label);
1435         gtk_label_set_xalign(GTK_LABEL (mailcmd_label), 1.0);
1436         gtk_grid_attach(GTK_GRID(serv_table), mailcmd_label, 0, 6, 1, 1);
1437
1438         uid_label = gtk_label_new (_("User ID"));
1439         gtk_widget_show (uid_label);
1440         gtk_label_set_xalign(GTK_LABEL (uid_label), 1.0);
1441         gtk_grid_attach(GTK_GRID(serv_table), uid_label, 0, 7, 1, 1);
1442
1443         pass_label = gtk_label_new (_("Password"));
1444         gtk_widget_show (pass_label);
1445 #ifdef GENERIC_UMPC
1446         gtk_label_set_xalign(GTK_LABEL (pass_label), 1.0);
1447 #endif
1448         gtk_grid_attach(GTK_GRID(serv_table), pass_label, 0, 8, 1, 1);
1449
1450         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
1451         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
1452         gtk_widget_show(showpwd_checkbtn);
1453         gtk_grid_attach(GTK_GRID(serv_table), showpwd_checkbtn, 2, 8, 1, 1);
1454         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
1455                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), pass_entry);
1456
1457         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, uid_label);
1458         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, pass_label);
1459         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, uid_entry);
1460         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, pass_entry);
1461         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, showpwd_checkbtn);
1462         SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, nntpauth_onconnect_checkbtn);
1463
1464         page->acname_entry   = acname_entry;
1465         page->default_checkbtn = default_checkbtn;
1466
1467         page->name_entry = name_entry;
1468         page->addr_entry = addr_entry;
1469         page->org_entry  = org_entry;
1470
1471         page->serv_frame       = serv_frame;
1472         page->serv_table       = serv_table;
1473         page->protocol_optmenu = (gpointer)protocol_optmenu;
1474         page->recvserv_label   = recvserv_label;
1475         page->recvserv_entry   = recvserv_entry;
1476         page->smtpserv_label   = smtpserv_label;
1477         page->smtpserv_entry   = smtpserv_entry;
1478         page->nntpserv_label   = nntpserv_label;
1479         page->nntpserv_entry   = nntpserv_entry;
1480         page->nntpauth_checkbtn  = nntpauth_checkbtn;
1481         page->nntpauth_onconnect_checkbtn  = nntpauth_onconnect_checkbtn;
1482         page->localmbox_label   = localmbox_label;
1483         page->localmbox_entry   = localmbox_entry;
1484         page->mailcmd_checkbtn   = mailcmd_checkbtn;
1485         page->mailcmd_label   = mailcmd_label;
1486         page->mailcmd_entry   = mailcmd_entry;
1487         page->uid_label        = uid_label;
1488         page->pass_label       = pass_label;
1489         page->uid_entry        = uid_entry;
1490         page->pass_entry       = pass_entry;
1491         page->showpwd_checkbtn = showpwd_checkbtn;
1492         page->auto_configure_btn = auto_configure_btn;
1493         page->auto_configure_cancel_btn = auto_configure_cancel_btn;
1494         page->auto_configure_lbl = auto_configure_lbl;
1495
1496         if (new_account) {
1497                 prefs_set_dialog_to_default(basic_param);
1498                 buf = g_strdup_printf(_("Account%d"), ac_prefs->account_id);
1499                 gtk_entry_set_text(GTK_ENTRY(basic_page.acname_entry), buf);
1500                 g_free(buf);
1501         } else {
1502                 prefs_set_dialog(basic_param);
1503
1504                 /* Passwords are handled outside of PrefParams. */
1505                 buf = passwd_store_get_account(ac_prefs->account_id,
1506                                 PWS_ACCOUNT_RECV);
1507                 gtk_entry_set_text(GTK_ENTRY(page->pass_entry), buf != NULL ? buf : "");
1508                 if (buf != NULL) {
1509                         memset(buf, 0, strlen(buf));
1510                         g_free(buf);
1511                 }
1512         }
1513
1514         page->vbox = vbox1;
1515
1516         page->page.widget = vbox1;
1517 }
1518
1519 static void receive_create_widget_func(PrefsPage * _page,
1520                                            GtkWindow * window,
1521                                            gpointer data)
1522 {
1523         ReceivePage *page = (ReceivePage *) _page;
1524         PrefsAccount *ac_prefs = (PrefsAccount *) data;
1525
1526         GtkWidget *vbox1, *vbox2, *vbox3, *vbox4, *vbox5;
1527         GtkWidget *hbox1, *hbox2, *hbox3;
1528         GtkWidget *frame1;
1529         GtkWidget *pop_auth_checkbtn;
1530         GtkWidget *rmmail_checkbtn;
1531         GtkWidget *hbox_spc;
1532         GtkWidget *leave_time_label;
1533         GtkWidget *leave_time_spinbtn;
1534         GtkWidget *leave_hour_label;
1535         GtkWidget *leave_hour_spinbtn;
1536         GtkWidget *size_limit_checkbtn;
1537         GtkWidget *size_limit_spinbtn;
1538         GtkWidget *label;
1539         GtkWidget *filter_on_recv_checkbtn;
1540         GtkWidget *filterhook_on_recv_checkbtn;
1541         GtkWidget *inbox_label;
1542         GtkWidget *inbox_entry;
1543         GtkWidget *inbox_btn;
1544         GtkWidget *imap_frame;
1545         GtkWidget *imapdir_label;
1546         GtkWidget *imapdir_entry;
1547         GtkWidget *subsonly_checkbtn;
1548         GtkWidget *low_bandwidth_checkbtn;
1549         GtkWidget *local_frame;
1550         GtkWidget *local_vbox;
1551         GtkWidget *local_hbox;
1552         GtkWidget *local_inbox_label;
1553         GtkWidget *local_inbox_entry;
1554         GtkWidget *local_inbox_btn;
1555         GtkWidget *autochk_checkbtn;
1556         GtkWidget *autochk_hour_spinbtn, *autochk_hour_label;
1557         GtkWidget *autochk_min_spinbtn, *autochk_min_label;
1558         GtkWidget *autochk_sec_spinbtn, *autochk_sec_label;
1559         GtkWidget *autochk_use_default_checkbtn;
1560         GtkAdjustment *adj;
1561         struct AutocheckWidgets *autochk_widgets;
1562
1563         GtkWidget *optmenu, *optmenu2;
1564         GtkListStore *menu, *menu2;
1565         GtkTreeIter iter;
1566         GtkWidget *recvatgetall_checkbtn;
1567
1568         GtkWidget *frame, *frame2;
1569         GtkWidget *maxarticle_label;
1570         GtkWidget *maxarticle_spinbtn;
1571         GtkAdjustment *maxarticle_spinbtn_adj;
1572
1573         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
1574         gtk_widget_show (vbox1);
1575         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1576
1577         local_vbox = gtkut_get_options_frame(vbox1, &local_frame, _("Local"));
1578
1579         local_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1580         gtk_widget_show (local_hbox);
1581         gtk_box_pack_start (GTK_BOX (local_vbox), local_hbox, TRUE, TRUE, 0);
1582
1583         local_inbox_label = gtk_label_new (_("Default Inbox"));
1584         gtk_widget_show (local_inbox_label);
1585         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_label, FALSE, FALSE, 0);
1586
1587         local_inbox_entry = gtk_entry_new ();
1588         gtk_widget_show (local_inbox_entry);
1589         CLAWS_SET_TIP(local_inbox_entry,
1590                              _("Unfiltered messages will be stored in this folder"));
1591         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_entry, TRUE, TRUE, 0);
1592
1593         local_inbox_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
1594         gtk_widget_show (local_inbox_btn);
1595         CLAWS_SET_TIP(local_inbox_btn,
1596                              _("Unfiltered messages will be stored in this folder"));
1597         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_btn, FALSE, FALSE, 0);
1598         g_signal_connect (G_OBJECT (local_inbox_btn), "clicked",
1599                           G_CALLBACK (prefs_account_select_folder_cb),
1600                           local_inbox_entry);
1601
1602         vbox2 = gtkut_get_options_frame(vbox1, &frame1, _("POP"));
1603
1604         PACK_CHECK_BUTTON (vbox2, pop_auth_checkbtn,
1605                            _("Authenticate before POP connection"));
1606
1607         //vbox5 = gtk_vbox_new (FALSE, 0);
1608         vbox5 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
1609         gtk_widget_show (vbox5);
1610         gtk_box_pack_start (GTK_BOX (vbox2), vbox5, FALSE, FALSE, 0);
1611
1612         hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1613         gtk_widget_show (hbox3);
1614         gtk_box_pack_start (GTK_BOX (vbox5), hbox3, FALSE, FALSE, 0);
1615
1616         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1617         gtk_widget_show (hbox_spc);
1618         gtk_box_pack_start (GTK_BOX (hbox3), hbox_spc, FALSE, FALSE, 0);
1619         gtk_widget_set_size_request (hbox_spc, 12, -1);
1620
1621         label = gtk_label_new (_("Authentication method"));
1622         gtk_widget_show (label);
1623         gtk_box_pack_start (GTK_BOX (hbox3), label, FALSE, FALSE, 0);
1624
1625         optmenu2 = gtkut_sc_combobox_create(NULL, FALSE);
1626         menu2 = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu2)));
1627         gtk_widget_show (optmenu2);
1628         gtk_box_pack_start (GTK_BOX (hbox3), optmenu2, FALSE, FALSE, 0);
1629
1630         COMBOBOX_ADD (menu2, _("Select"), 0);
1631         COMBOBOX_ADD (menu2, NULL, 0);
1632         COMBOBOX_ADD (menu2, "APOP", POPAUTH_APOP);
1633         COMBOBOX_ADD (menu2, "OAuth2", POPAUTH_OAUTH2);
1634
1635         SET_TOGGLE_SENSITIVITY (pop_auth_checkbtn, vbox5);
1636
1637         PACK_CHECK_BUTTON (vbox2, rmmail_checkbtn,
1638                            _("Remove messages on server when received"));
1639
1640         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1641         gtk_widget_show (hbox1);
1642         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1643
1644         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1645         gtk_widget_show (hbox_spc);
1646         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1647         gtk_widget_set_size_request (hbox_spc, 12, -1);
1648
1649         leave_time_label = gtk_label_new (_("Remove after"));
1650         gtk_widget_show (leave_time_label);
1651         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1652
1653         leave_time_spinbtn = gtk_spin_button_new_with_range(0, 365, 1);
1654         gtk_widget_show (leave_time_spinbtn);
1655         CLAWS_SET_TIP(leave_time_spinbtn,
1656                              _("0 days and 0 hours : remove immediately"));
1657         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_spinbtn, FALSE, FALSE, 0);
1658
1659         leave_time_label = gtk_label_new (_("days"));
1660         gtk_widget_show (leave_time_label);
1661         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1662
1663         leave_hour_spinbtn = gtk_spin_button_new_with_range(0, 23, 1);
1664         gtk_widget_show (leave_hour_spinbtn);
1665         CLAWS_SET_TIP(leave_hour_spinbtn,
1666                              _("0 days and 0 hours : remove immediately"));
1667         gtk_box_pack_start (GTK_BOX (hbox1), leave_hour_spinbtn, FALSE, FALSE, 0);
1668
1669         leave_hour_label = gtk_label_new (_("hours"));
1670         gtk_widget_show (leave_hour_label);
1671         gtk_box_pack_start (GTK_BOX (hbox1), leave_hour_label, FALSE, FALSE, 0);
1672
1673         SET_TOGGLE_SENSITIVITY (rmmail_checkbtn, hbox1);
1674
1675         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1676         gtk_widget_show (hbox1);
1677         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1678
1679         PACK_CHECK_BUTTON (hbox1, size_limit_checkbtn, _("Receive size limit"));
1680
1681         CLAWS_SET_TIP(size_limit_checkbtn,
1682                              _("Messages over this limit will be partially retrieved. "
1683                                "When selecting them you will be able to download them fully "
1684                                "or delete them."));
1685
1686         size_limit_spinbtn = gtk_spin_button_new_with_range(0, 100000, 1);
1687         gtk_widget_show (size_limit_spinbtn);
1688         gtk_box_pack_start (GTK_BOX (hbox1), size_limit_spinbtn, FALSE, FALSE, 0);
1689
1690         label = gtk_label_new (_("KiB"));
1691         gtk_widget_show (label);
1692         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1693
1694         SET_TOGGLE_SENSITIVITY (size_limit_checkbtn, size_limit_spinbtn);
1695
1696         PACK_SPACER(vbox2, vbox3, VSPACING_NARROW_2);
1697
1698         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1699         gtk_widget_show (hbox1);
1700         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0);
1701
1702         inbox_label = gtk_label_new (_("Default Inbox"));
1703         gtk_widget_show (inbox_label);
1704         gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
1705
1706         inbox_entry = gtk_entry_new ();
1707         gtk_widget_show (inbox_entry);
1708         CLAWS_SET_TIP(inbox_entry,
1709                              _("Unfiltered messages will be stored in this folder"));
1710         gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
1711
1712         inbox_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
1713         gtk_widget_show (inbox_btn);
1714         CLAWS_SET_TIP(inbox_btn,
1715                              _("Unfiltered messages will be stored in this folder"));
1716         gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1717         g_signal_connect (G_OBJECT (inbox_btn), "clicked",
1718                           G_CALLBACK (prefs_account_select_folder_cb),
1719                           inbox_entry);
1720
1721         vbox2 = gtkut_get_options_frame(vbox1, &frame2, _("NNTP"));
1722
1723         hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1724         gtk_widget_show (hbox2);
1725         gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
1726
1727         maxarticle_label = gtk_label_new
1728                 (_("Maximum number of articles to download"));
1729         gtk_widget_show (maxarticle_label);
1730         gtk_box_pack_start (GTK_BOX (hbox2), maxarticle_label, FALSE, FALSE, 0);
1731
1732         maxarticle_spinbtn_adj =
1733                 GTK_ADJUSTMENT(gtk_adjustment_new (300, 0, 10000, 10, 100, 0));
1734         maxarticle_spinbtn = gtk_spin_button_new
1735                 (GTK_ADJUSTMENT (maxarticle_spinbtn_adj), 10, 0);
1736         gtk_widget_show (maxarticle_spinbtn);
1737         CLAWS_SET_TIP(maxarticle_spinbtn,
1738                              _("unlimited if 0 is specified"));
1739         gtk_box_pack_start (GTK_BOX (hbox2), maxarticle_spinbtn,
1740                             FALSE, FALSE, 0);
1741         gtk_widget_set_size_request (maxarticle_spinbtn, 64, -1);
1742         gtk_spin_button_set_numeric
1743                 (GTK_SPIN_BUTTON (maxarticle_spinbtn), TRUE);
1744
1745         vbox2 = gtkut_get_options_frame(vbox1, &imap_frame, _("IMAP"));
1746
1747         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1748         gtk_widget_show (hbox1);
1749         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1750
1751         label = gtk_label_new (_("Authentication method"));
1752         gtk_widget_show (label);
1753         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1754
1755
1756         optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1757         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1758         gtk_widget_show (optmenu);
1759         gtk_box_pack_start (GTK_BOX (hbox1), optmenu, FALSE, FALSE, 0);
1760
1761         COMBOBOX_ADD (menu, _("Automatic"), 0);
1762         COMBOBOX_ADD (menu, NULL, 0);
1763         COMBOBOX_ADD (menu, _("Plain text"), IMAP_AUTH_PLAINTEXT);
1764         COMBOBOX_ADD (menu, "CRAM-MD5", IMAP_AUTH_CRAM_MD5);
1765         COMBOBOX_ADD (menu, "ANONYMOUS", IMAP_AUTH_ANON);
1766         COMBOBOX_ADD (menu, "GSSAPI", IMAP_AUTH_GSSAPI);
1767         COMBOBOX_ADD (menu, "DIGEST-MD5", IMAP_AUTH_DIGEST_MD5);
1768         COMBOBOX_ADD (menu, "SCRAM-SHA-1", IMAP_AUTH_SCRAM_SHA1);
1769         COMBOBOX_ADD (menu, "PLAIN", IMAP_AUTH_PLAIN);
1770         COMBOBOX_ADD (menu, "LOGIN", IMAP_AUTH_LOGIN);
1771         COMBOBOX_ADD (menu, "OAUTH2", IMAP_AUTH_OAUTH2);
1772
1773         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1774         gtk_widget_show (hbox1);
1775         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1776
1777         imapdir_label = gtk_label_new (_("IMAP server directory"));
1778         gtk_widget_show (imapdir_label);
1779         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1780
1781         imapdir_label = gtk_label_new(_("(usually empty)"));
1782         gtk_widget_show (imapdir_label);
1783         gtkut_widget_set_small_font_size (imapdir_label);
1784         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1785
1786         imapdir_entry = gtk_entry_new();
1787         gtk_widget_show (imapdir_entry);
1788         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, FALSE, FALSE, 0);
1789
1790         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1791         gtk_widget_show (hbox1);
1792         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1793
1794         PACK_CHECK_BUTTON (hbox1, subsonly_checkbtn,
1795                            _("Show subscribed folders only"));
1796
1797         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1798         gtk_widget_show (hbox1);
1799         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1800
1801         PACK_CHECK_BUTTON (hbox1, low_bandwidth_checkbtn,
1802                            _("Bandwidth-efficient mode (prevents retrieving remote tags)"));
1803         CLAWS_SET_TIP(low_bandwidth_checkbtn,
1804                              _("This mode uses less bandwidth, but can be slower with some servers."));
1805
1806         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1807         gtk_widget_show (hbox1);
1808         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1809
1810         /* Auto-checking */
1811         vbox4 = gtkut_get_options_frame(vbox1, &frame, _("Automatic checking"));
1812
1813         PACK_CHECK_BUTTON(vbox4, autochk_use_default_checkbtn,
1814                         _("Use global settings"));
1815
1816         hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1817         gtk_box_pack_start(GTK_BOX(vbox4), hbox2, FALSE, FALSE, 0);
1818
1819         PACK_CHECK_BUTTON(hbox2, autochk_checkbtn,
1820                         _("Check for new mail every"));
1821
1822         adj = gtk_adjustment_new(5, 0, 99, 1, 10, 0);
1823         autochk_hour_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1824         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(autochk_hour_spinbtn), TRUE);
1825         gtk_box_pack_start(GTK_BOX(hbox2), autochk_hour_spinbtn, FALSE, FALSE, 0);
1826         autochk_hour_label = gtk_label_new(_("hours"));
1827         gtk_box_pack_start(GTK_BOX(hbox2), autochk_hour_label, FALSE, FALSE, 0);
1828
1829         adj = gtk_adjustment_new(5, 0, 99, 1, 10, 0);
1830         autochk_min_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1831         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(autochk_min_spinbtn), TRUE);
1832         gtk_box_pack_start(GTK_BOX(hbox2), autochk_min_spinbtn, FALSE, FALSE, 0);
1833         autochk_min_label = gtk_label_new(_("minutes"));
1834         gtk_box_pack_start(GTK_BOX(hbox2), autochk_min_label, FALSE, FALSE, 0);
1835
1836         adj = gtk_adjustment_new(5, 0, 99, 1, 10, 0);
1837         autochk_sec_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1838         gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(autochk_sec_spinbtn), TRUE);
1839         gtk_box_pack_start(GTK_BOX(hbox2), autochk_sec_spinbtn, FALSE, FALSE, 0);
1840         autochk_sec_label = gtk_label_new(_("seconds"));
1841         gtk_box_pack_start(GTK_BOX(hbox2), autochk_sec_label, FALSE, FALSE, 0);
1842
1843         autochk_widgets = g_new0(struct AutocheckWidgets, 1);
1844         autochk_widgets->autochk_hour_spinbtn = autochk_hour_spinbtn;
1845         autochk_widgets->autochk_min_spinbtn = autochk_min_spinbtn;
1846         autochk_widgets->autochk_sec_spinbtn = autochk_sec_spinbtn;
1847
1848         gtk_widget_show_all(vbox4);
1849
1850         SET_TOGGLE_SENSITIVITY_REVERSE(autochk_use_default_checkbtn, hbox2);
1851         SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_hour_spinbtn);
1852         SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_min_spinbtn);
1853         SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_sec_spinbtn);
1854         SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_hour_label);
1855         SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_min_label);
1856         SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_sec_label);
1857
1858         PACK_CHECK_BUTTON (vbox1, filter_on_recv_checkbtn,
1859                            _("Filter messages on receiving"));
1860
1861         g_signal_connect(G_OBJECT(filter_on_recv_checkbtn), "toggled",
1862                          G_CALLBACK(prefs_account_filter_on_recv_toggled),
1863                          NULL);
1864         g_signal_connect(G_OBJECT(autochk_hour_spinbtn), "value-changed",
1865                 G_CALLBACK(prefs_account_receive_itv_spinbutton_value_changed_cb),
1866                 (gpointer) page);
1867         g_signal_connect(G_OBJECT(autochk_min_spinbtn), "value-changed",
1868                 G_CALLBACK(prefs_account_receive_itv_spinbutton_value_changed_cb),
1869                 (gpointer) page);
1870         g_signal_connect(G_OBJECT(autochk_sec_spinbtn), "value-changed",
1871                 G_CALLBACK(prefs_account_receive_itv_spinbutton_value_changed_cb),
1872                 (gpointer) page);
1873
1874         PACK_CHECK_BUTTON (vbox1, filterhook_on_recv_checkbtn,
1875                            _("Allow filtering using plugins on receiving"));
1876
1877         PACK_CHECK_BUTTON
1878                 (vbox1, recvatgetall_checkbtn,
1879                  _("'Get Mail' checks for new messages on this account"));
1880
1881         page->pop3_frame               = frame1;
1882         page->pop_auth_checkbtn          = pop_auth_checkbtn;
1883         page->pop_auth_type_optmenu      = optmenu2;
1884         page->rmmail_checkbtn            = rmmail_checkbtn;
1885         page->leave_time_spinbtn         = leave_time_spinbtn;
1886         page->leave_hour_spinbtn         = leave_hour_spinbtn;
1887         page->size_limit_checkbtn        = size_limit_checkbtn;
1888         page->size_limit_spinbtn         = size_limit_spinbtn;
1889         page->filter_on_recv_checkbtn    = filter_on_recv_checkbtn;
1890         page->filterhook_on_recv_checkbtn = filterhook_on_recv_checkbtn;
1891         page->inbox_label              = inbox_label;
1892         page->inbox_entry              = inbox_entry;
1893         page->inbox_btn                = inbox_btn;
1894
1895         page->autochk_frame            = frame;
1896
1897         page->imap_frame               = imap_frame;
1898         page->imap_auth_type_optmenu   = optmenu;
1899
1900         page->imapdir_label             = imapdir_label;
1901         page->imapdir_entry             = imapdir_entry;
1902         page->subsonly_checkbtn         = subsonly_checkbtn;
1903         page->low_bandwidth_checkbtn    = low_bandwidth_checkbtn;
1904         page->local_frame               = local_frame;
1905         page->local_inbox_label = local_inbox_label;
1906         page->local_inbox_entry = local_inbox_entry;
1907         page->local_inbox_btn           = local_inbox_btn;
1908
1909         page->recvatgetall_checkbtn      = recvatgetall_checkbtn;
1910
1911         page->frame_maxarticle  = frame2;
1912         page->maxarticle_spinbtn        = maxarticle_spinbtn;
1913         page->maxarticle_spinbtn_adj    = maxarticle_spinbtn_adj;
1914
1915         page->autochk_checkbtn = autochk_checkbtn;
1916         page->autochk_widgets = autochk_widgets;
1917         page->autochk_use_default_checkbtn = autochk_use_default_checkbtn;
1918
1919         tmp_ac_prefs = *ac_prefs;
1920
1921         if (new_account) {
1922                 prefs_set_dialog_to_default(receive_param);
1923         } else
1924                 prefs_set_dialog(receive_param);
1925
1926         page->vbox = vbox1;
1927
1928         page->page.widget = vbox1;
1929 }
1930
1931 static void send_create_widget_func(PrefsPage * _page,
1932                                            GtkWindow * window,
1933                                            gpointer data)
1934 {
1935         SendPage *page = (SendPage *) _page;
1936         PrefsAccount *ac_prefs = (PrefsAccount *) data;
1937
1938         GtkWidget *vbox1;
1939         GtkWidget *vbox2;
1940         GtkWidget *frame;
1941         GtkWidget *msgid_checkbtn;
1942         GtkWidget *xmailer_checkbtn;
1943         GtkWidget *hbox;
1944         GtkWidget *customhdr_checkbtn;
1945         GtkWidget *customhdr_edit_btn;
1946         GtkWidget *checkbtn_msgid_with_addr;
1947         GtkWidget *vbox3;
1948         GtkWidget *smtp_auth_checkbtn;
1949         GtkWidget *showpwd_checkbtn;
1950         GtkWidget *optmenu;
1951         GtkListStore *menu;
1952         GtkTreeIter iter;
1953         GtkWidget *vbox4;
1954         GtkWidget *hbox_spc;
1955         GtkWidget *label;
1956         GtkWidget *smtp_uid_entry;
1957         GtkWidget *smtp_pass_entry;
1958         GtkWidget *vbox_spc;
1959         GtkWidget *pop_bfr_smtp_checkbtn;
1960         GtkWidget *pop_bfr_smtp_tm_spinbtn;
1961         GtkWidget *pop_auth_timeout_lbl;
1962         GtkWidget *pop_auth_minutes_lbl;
1963         gchar *buf;
1964
1965         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
1966         gtk_widget_show (vbox1);
1967         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1968
1969         vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Header"));
1970
1971         PACK_CHECK_BUTTON (vbox2, msgid_checkbtn, _("Generate Message-ID"));
1972
1973         PACK_CHECK_BUTTON (vbox2, checkbtn_msgid_with_addr,
1974                            _("Send account mail address in Message-ID"));
1975
1976         PACK_CHECK_BUTTON (vbox2, xmailer_checkbtn,
1977                            _("Add user agent header"));
1978
1979         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
1980         gtk_widget_show (hbox);
1981         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1982
1983         PACK_CHECK_BUTTON (hbox, customhdr_checkbtn,
1984                            _("Add user-defined header"));
1985
1986         customhdr_edit_btn = gtk_button_new_with_mnemonic("_Edit");
1987         gtk_widget_show (customhdr_edit_btn);
1988         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1989                             FALSE, FALSE, 0);
1990         g_signal_connect (G_OBJECT (customhdr_edit_btn), "clicked",
1991                           G_CALLBACK (prefs_account_edit_custom_header),
1992                           NULL);
1993
1994         SET_TOGGLE_SENSITIVITY (customhdr_checkbtn, customhdr_edit_btn);
1995
1996         vbox3 = gtkut_get_options_frame(vbox1, &frame, _("Authentication"));
1997
1998         PACK_CHECK_BUTTON (vbox3, smtp_auth_checkbtn,
1999                 _("SMTP Authentication (SMTP AUTH)"));
2000
2001         vbox4 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2002         gtk_widget_show (vbox4);
2003         gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
2004
2005         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2006         gtk_widget_show (hbox);
2007         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2008
2009         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2010         gtk_widget_show (hbox_spc);
2011         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2012         gtk_widget_set_size_request (hbox_spc, 12, -1);
2013
2014         label = gtk_label_new (_("Authentication method"));
2015         gtk_widget_show (label);
2016         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2017
2018         optmenu = gtkut_sc_combobox_create(NULL, FALSE);
2019         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
2020         gtk_widget_show (optmenu);
2021         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
2022
2023         COMBOBOX_ADD (menu, _("Automatic"), 0);
2024         COMBOBOX_ADD (menu, NULL, 0);
2025         COMBOBOX_ADD (menu, "PLAIN", SMTPAUTH_PLAIN);
2026         COMBOBOX_ADD (menu, "LOGIN", SMTPAUTH_LOGIN);
2027         COMBOBOX_ADD (menu, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
2028         COMBOBOX_ADD (menu, "OAUTH2", SMTPAUTH_OAUTH2);
2029         COMBOBOX_ADD (menu, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
2030         gtk_list_store_set(menu, &iter, COMBOBOX_SENS, FALSE, -1);
2031
2032         PACK_SPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
2033
2034         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2035         gtk_widget_show (hbox);
2036         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2037
2038         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2039         gtk_widget_show (hbox_spc);
2040         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2041         gtk_widget_set_size_request (hbox_spc, 12, -1);
2042
2043         label = gtk_label_new (_("User ID"));
2044         gtk_widget_show (label);
2045         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2046
2047         smtp_uid_entry = gtk_entry_new ();
2048         gtk_widget_show (smtp_uid_entry);
2049         gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
2050         gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
2051         g_signal_connect(G_OBJECT(smtp_uid_entry), "changed",
2052                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
2053                         GINT_TO_POINTER(ac_prefs->protocol));
2054
2055 #ifdef GENERIC_UMPC
2056         PACK_SPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
2057         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2058         gtk_widget_show (hbox);
2059         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2060
2061         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2062         gtk_widget_show (hbox_spc);
2063         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2064         gtk_widget_set_size_request (hbox_spc, 12, -1);
2065 #endif
2066         label = gtk_label_new (_("Password"));
2067         gtk_widget_show (label);
2068         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2069
2070         smtp_pass_entry = gtk_entry_new ();
2071         gtk_widget_show (smtp_pass_entry);
2072         gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
2073         gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
2074         gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
2075         g_signal_connect(G_OBJECT(smtp_pass_entry), "changed",
2076                         G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
2077                         GINT_TO_POINTER(ac_prefs->protocol));
2078
2079         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
2080         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
2081         gtk_widget_show(showpwd_checkbtn);
2082         gtk_box_pack_start(GTK_BOX (hbox), showpwd_checkbtn, FALSE, FALSE, 0);
2083         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
2084                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), smtp_pass_entry);
2085
2086         PACK_SPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
2087
2088         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2089         gtk_widget_show (hbox);
2090         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2091
2092         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2093         gtk_widget_show (hbox_spc);
2094         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2095         gtk_widget_set_size_request (hbox_spc, 12, -1);
2096
2097         label = gtk_label_new
2098                 (_("If you leave these entries empty, the same "
2099                    "user ID and password as receiving will be used."));
2100         gtk_widget_show (label);
2101         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2102         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
2103         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2104         gtkut_widget_set_small_font_size (label);
2105
2106         SET_TOGGLE_SENSITIVITY (smtp_auth_checkbtn, vbox4);
2107
2108         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_checkbtn,
2109                 _("Authenticate with POP before sending"));
2110         
2111         g_signal_connect (G_OBJECT (pop_bfr_smtp_checkbtn), "clicked",
2112                           G_CALLBACK (pop_bfr_smtp_tm_set_sens),
2113                           NULL);
2114
2115         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2116         gtk_widget_show (hbox);
2117         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2118
2119         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2120         gtk_widget_show (hbox_spc);
2121         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2122         gtk_widget_set_size_request (hbox_spc, 12, -1);
2123
2124         pop_auth_timeout_lbl = gtk_label_new(_("POP authentication timeout"));
2125         gtk_widget_show (pop_auth_timeout_lbl);
2126         gtk_box_pack_start (GTK_BOX (hbox), pop_auth_timeout_lbl, FALSE, FALSE, 0);
2127
2128         pop_bfr_smtp_tm_spinbtn = gtk_spin_button_new_with_range(0, 1440, 1);
2129         gtk_widget_show (pop_bfr_smtp_tm_spinbtn);
2130         gtk_box_pack_start (GTK_BOX (hbox), pop_bfr_smtp_tm_spinbtn, FALSE, FALSE, 0);
2131
2132         pop_auth_minutes_lbl = gtk_label_new(_("minutes"));
2133         gtk_widget_show (pop_auth_minutes_lbl);
2134         gtk_box_pack_start (GTK_BOX (hbox), pop_auth_minutes_lbl, FALSE, FALSE, 0);
2135         
2136         page->msgid_checkbtn     = msgid_checkbtn;
2137         page->xmailer_checkbtn   = xmailer_checkbtn;
2138         page->customhdr_checkbtn = customhdr_checkbtn;
2139         page->msgid_with_addr_checkbtn  = checkbtn_msgid_with_addr;
2140
2141         page->smtp_auth_checkbtn       = smtp_auth_checkbtn;
2142         page->smtp_auth_type_optmenu = optmenu;
2143         page->smtp_uid_entry         = smtp_uid_entry;
2144         page->smtp_pass_entry        = smtp_pass_entry;
2145         page->pop_bfr_smtp_checkbtn    = pop_bfr_smtp_checkbtn;
2146         page->pop_bfr_smtp_tm_spinbtn  = pop_bfr_smtp_tm_spinbtn;
2147         page->pop_auth_timeout_lbl   = pop_auth_timeout_lbl;
2148         page->pop_auth_minutes_lbl   = pop_auth_minutes_lbl;
2149
2150         tmp_ac_prefs = *ac_prefs;
2151
2152         if (new_account) {
2153                 prefs_set_dialog_to_default(send_param);
2154         } else {
2155                 prefs_set_dialog(send_param);
2156
2157                 /* Passwords are handled outside of PrefParams. */
2158                 buf = passwd_store_get_account(ac_prefs->account_id,
2159                                 PWS_ACCOUNT_SEND);
2160                 gtk_entry_set_text(GTK_ENTRY(page->smtp_pass_entry), buf != NULL ? buf : "");
2161                 if (buf != NULL) {
2162                         memset(buf, 0, strlen(buf));
2163                         g_free(buf);
2164                 }
2165         }
2166
2167         pop_bfr_smtp_tm_set_sens (NULL, NULL);
2168
2169         page->vbox = vbox1;
2170
2171         page->page.widget = vbox1;
2172 }
2173
2174 static void oauth2_create_widget_func(PrefsPage * _page,
2175                                            GtkWindow * window,
2176                                            gpointer data)
2177 {
2178         Oauth2Page *page = (Oauth2Page *) _page;
2179         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2180
2181         GtkWidget *vbox1, *vbox2, *vbox3;
2182         GtkWidget *hbox;
2183         GtkWidget *hbox_spc;
2184         GtkWidget *oauth2_authorise_btn;
2185         GtkWidget *auth_vbox, *auth_frame;
2186         GtkWidget *label;
2187         GtkWidget *oauth2_authcode_entry;
2188         GtkWidget *oauth2_auth_optmenu;
2189         GtkWidget *oauth2_link_button;
2190         GtkWidget *oauth2_link_copy_button;
2191         GtkWidget *oauth2_client_id_entry;
2192         GtkWidget *oauth2_client_secret_entry;
2193         GtkWidget *table1;
2194         GtkListStore *menu;
2195         GtkTreeIter iter;
2196         char *buf;
2197         struct BasicProtocol *protocol_optmenu;
2198
2199         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2200         gtk_widget_show (vbox1);
2201         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2202
2203         auth_vbox = gtkut_get_options_frame(vbox1, &auth_frame,
2204                         _("Authorization"));
2205         
2206         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2207         gtk_widget_show (hbox);
2208         gtk_box_pack_start (GTK_BOX (auth_vbox), hbox, FALSE, FALSE, 0);
2209
2210         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2211         gtk_widget_show (hbox_spc);
2212         gtk_widget_set_size_request (hbox_spc, 12, -1);
2213         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2214
2215         /* Email service provider */
2216
2217         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2218         gtk_widget_show (hbox);
2219         gtk_box_pack_start (GTK_BOX (auth_vbox), hbox, FALSE, FALSE, 0);
2220
2221         label = gtk_label_new (_("Select OAuth2 Email Service Provider"));
2222         gtk_widget_show (label);
2223         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2224
2225         oauth2_auth_optmenu = gtkut_sc_combobox_create(NULL, FALSE);
2226         menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(oauth2_auth_optmenu)));
2227         gtk_widget_show (oauth2_auth_optmenu);
2228         gtk_box_pack_start (GTK_BOX (hbox), oauth2_auth_optmenu, FALSE, FALSE, 0);
2229
2230         COMBOBOX_ADD (menu, _("Select"), NULL);
2231         COMBOBOX_ADD (menu, NULL, 0);
2232         COMBOBOX_ADD (menu, "Google/Gmail", OAUTH2AUTH_GOOGLE);
2233         COMBOBOX_ADD (menu, "MS Outlook", OAUTH2AUTH_OUTLOOK);
2234         COMBOBOX_ADD (menu, "MS Exchange", OAUTH2AUTH_EXCHANGE);
2235         COMBOBOX_ADD (menu, "Yahoo", OAUTH2AUTH_YAHOO);
2236
2237         protocol_optmenu = g_new(struct BasicProtocol, 1);
2238         protocol_optmenu->combobox = oauth2_auth_optmenu;
2239         protocol_optmenu->label = label;
2240         protocol_optmenu->descrlabel = label;
2241
2242         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2243         gtk_widget_show (hbox);
2244         gtk_box_pack_start (GTK_BOX (auth_vbox), hbox, FALSE, FALSE, 0);
2245
2246         vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2247         gtk_widget_show (vbox3);
2248         gtk_box_pack_start (GTK_BOX (auth_vbox), vbox3, FALSE, FALSE, 0);
2249  
2250         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2251         gtk_widget_show (vbox2);
2252         gtk_box_pack_start (GTK_BOX (vbox3), vbox2, FALSE, FALSE, 0);
2253
2254         table1 = gtk_grid_new();
2255         gtk_widget_show (table1);
2256         gtk_container_add (GTK_CONTAINER (vbox2), table1);
2257         gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
2258         gtk_grid_set_row_spacing(GTK_GRID(table1), VSPACING_NARROW);
2259         gtk_grid_set_column_spacing(GTK_GRID(table1), 8);
2260
2261         label = gtk_label_new (_("Client ID"));
2262         gtk_widget_show (label);
2263         gtk_label_set_xalign(GTK_LABEL (label), 1.0);
2264         gtk_grid_attach(GTK_GRID(table1), label, 0, 0, 1, 1);
2265
2266         oauth2_client_id_entry = gtk_entry_new();
2267         gtk_widget_show (oauth2_client_id_entry);
2268         gtk_grid_attach(GTK_GRID(table1), oauth2_client_id_entry, 1, 0, 1, 1);
2269         gtk_widget_set_hexpand(oauth2_client_id_entry, TRUE);
2270         gtk_widget_set_halign(oauth2_client_id_entry, GTK_ALIGN_FILL);
2271
2272         label = gtk_label_new (_("Client secret"));
2273         gtk_widget_show (label);
2274         gtk_label_set_xalign(GTK_LABEL (label), 1.0);
2275         gtk_grid_attach(GTK_GRID(table1), label, 0, 1, 1, 1);
2276
2277         oauth2_client_secret_entry = gtk_entry_new ();
2278         gtk_widget_show (oauth2_client_secret_entry);
2279         gtk_grid_attach(GTK_GRID(table1), oauth2_client_secret_entry, 1, 1, 1, 1);
2280         gtk_widget_set_hexpand(oauth2_client_secret_entry, TRUE);
2281         gtk_widget_set_halign(oauth2_client_secret_entry, GTK_ALIGN_FILL);
2282
2283         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2284         gtk_widget_show (hbox_spc);
2285         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2286         //gtk_widget_set_size_request (hbox_spc, 12, -1);
2287
2288         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2289         gtk_widget_show (hbox_spc);
2290         gtk_box_pack_start (GTK_BOX (vbox2), hbox_spc, FALSE, FALSE, 0);
2291         //gtk_widget_set_size_request (hbox_spc, 12, 10);
2292
2293         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2294         gtk_widget_show (hbox);
2295         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2296
2297         label = gtk_label_new (_("Obtain authorization code"));
2298         gtk_widget_show (label);
2299         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2300
2301         oauth2_link_button = gtk_button_new_with_label(_("Open default browser with request"));
2302         g_signal_connect(G_OBJECT(oauth2_link_button), "clicked", G_CALLBACK(prefs_account_oauth2_copy_url), NULL);
2303         gtk_widget_set_sensitive(oauth2_link_button, TRUE);
2304         gtk_widget_set_margin_bottom(oauth2_link_button, 8);
2305         gtk_widget_show (oauth2_link_button);
2306         gtk_box_pack_start (GTK_BOX (hbox), oauth2_link_button, FALSE, FALSE, 0);
2307
2308         oauth2_link_copy_button = gtk_button_new_with_label(_("Copy link"));
2309         g_signal_connect(G_OBJECT(oauth2_link_copy_button), "clicked", G_CALLBACK(prefs_account_oauth2_copy_url), NULL);
2310         gtk_widget_set_sensitive(oauth2_link_copy_button, TRUE);
2311         gtk_widget_set_margin_bottom(oauth2_link_copy_button, 8);
2312         gtk_widget_show (oauth2_link_copy_button);
2313         gtk_box_pack_start (GTK_BOX (hbox), oauth2_link_copy_button, FALSE, FALSE, 0);
2314
2315         /* Authorisation code */
2316         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2317         gtk_widget_show (hbox);
2318         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2319         //gtk_widget_set_size_request (hbox, -1, 50);
2320
2321         label = gtk_label_new (_("Authorization code"));
2322         gtk_widget_show (label);
2323         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2324
2325         oauth2_authcode_entry = gtk_entry_new ();
2326         gtk_widget_show (oauth2_authcode_entry);
2327         gtk_widget_set_margin_bottom(oauth2_authcode_entry, 8);
2328         //gtk_widget_set_size_request (oauth2_authcode_entry, DEFAULT_ENTRY_WIDTH, -1);
2329         gtk_widget_set_tooltip_text(oauth2_authcode_entry,
2330                 _("Paste complete URL from browser or the provided authorization token"));
2331         gtk_box_pack_start (GTK_BOX (hbox), oauth2_authcode_entry, TRUE, TRUE, 0);
2332
2333         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2334         gtk_widget_show (hbox);
2335         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2336
2337         label = gtk_label_new (_("Complete authorization"));
2338         gtk_widget_show (label);
2339         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2340
2341         oauth2_authorise_btn = gtk_button_new_with_label(_("Authorize"));
2342         gtk_box_pack_start(GTK_BOX(hbox), oauth2_authorise_btn, FALSE, FALSE, 0);
2343         g_signal_connect(G_OBJECT(oauth2_authorise_btn), "clicked",
2344                          G_CALLBACK(prefs_account_oauth2_obtain_tokens), NULL);
2345         gtk_widget_show(oauth2_authorise_btn);
2346
2347         /* Add items to page struct */
2348
2349         page->oauth2_link_button = oauth2_link_button;
2350         page->oauth2_link_copy_button = oauth2_link_copy_button;
2351         page->oauth2_authcode_entry = oauth2_authcode_entry;
2352         page->oauth2_auth_optmenu = oauth2_auth_optmenu;
2353         page->protocol_optmenu = (gpointer)protocol_optmenu;
2354         page->oauth2_authorise_btn = oauth2_authorise_btn;
2355         page->oauth2_client_id_entry = oauth2_client_id_entry;
2356         page->oauth2_client_secret_entry = oauth2_client_secret_entry;
2357         page->vbox = vbox1;
2358         page->page.widget = vbox1;
2359         page->oauth2_sensitive = vbox3;
2360
2361         tmp_ac_prefs = *ac_prefs;
2362
2363         g_signal_connect(G_OBJECT(oauth2_auth_optmenu), "changed", 
2364                          G_CALLBACK(prefs_account_oauth2_set_sensitivity), NULL);
2365         g_signal_connect(G_OBJECT(oauth2_authcode_entry), "changed", 
2366                          G_CALLBACK(prefs_account_oauth2_set_auth_sensitivity), NULL);
2367         prefs_account_oauth2_set_auth_sensitivity();
2368
2369         if (new_account) {
2370                 prefs_set_dialog_to_default(oauth2_param);
2371         } else {
2372                 prefs_set_dialog(oauth2_param);
2373
2374                 /* Passwords are handled outside of PrefParams. */
2375                 buf = passwd_store_get_account(ac_prefs->account_id,
2376                                 PWS_ACCOUNT_OAUTH2_AUTH);
2377                 gtk_entry_set_text(GTK_ENTRY(page->oauth2_authcode_entry), buf != NULL ? buf : "");
2378                 if (buf != NULL) {
2379                         memset(buf, 0, strlen(buf));
2380                         g_free(buf);
2381                 }
2382         }
2383
2384         /* For testing */
2385         /*      oauth2_encode(OAUTH2info[0][OA2_CLIENT_ID]); */
2386
2387 }
2388
2389 static void compose_create_widget_func(PrefsPage * _page,
2390                                            GtkWindow * window,
2391                                            gpointer data)
2392 {
2393         ComposePage *page = (ComposePage *) _page;
2394         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2395
2396         GtkWidget *vbox1;
2397         GtkWidget *sig_hbox;
2398         GtkWidget *hbox1;
2399         GtkWidget *hbox2;
2400         GtkWidget *frame_sig;
2401         GtkWidget *vbox_sig;
2402         GtkWidget *label_sigpath;
2403         GtkWidget *checkbtn_autosig;
2404         GtkWidget *label_sigsep;
2405         GtkWidget *entry_sigsep;
2406         GtkWidget *frame;
2407         GtkWidget *table;
2408         GtkWidget *autocc_checkbtn;
2409         GtkWidget *autocc_entry;
2410         GtkWidget *autobcc_checkbtn;
2411         GtkWidget *autobcc_entry;
2412         GtkWidget *autoreplyto_checkbtn;
2413         GtkWidget *autoreplyto_entry;
2414 #if USE_ENCHANT
2415         GtkWidget *frame_dict;
2416         GtkWidget *table_dict;
2417         GtkWidget *checkbtn_enable_default_dictionary = NULL;
2418         GtkWidget *combo_default_dictionary = NULL;
2419         GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
2420         GtkWidget *combo_default_alt_dictionary = NULL;
2421 #endif
2422
2423         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2424         gtk_widget_show (vbox1);
2425         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2426
2427         vbox_sig = gtkut_get_options_frame(vbox1, &frame_sig, _("Signature"));
2428
2429         PACK_CHECK_BUTTON (vbox_sig, checkbtn_autosig,
2430                            _("Automatically insert signature"));
2431
2432         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2433         gtk_widget_show (hbox1);
2434         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox1, TRUE, TRUE, 0);
2435         label_sigsep = gtk_label_new (_("Signature separator"));
2436         gtk_widget_show (label_sigsep);
2437         gtk_box_pack_start (GTK_BOX (hbox1), label_sigsep, FALSE, FALSE, 0);
2438
2439         entry_sigsep = gtk_entry_new ();
2440         gtk_widget_show (entry_sigsep);
2441         gtk_box_pack_start (GTK_BOX (hbox1), entry_sigsep, FALSE, FALSE, 0);
2442
2443         gtk_widget_set_size_request (entry_sigsep, 64, -1);
2444
2445         sig_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2446         gtk_widget_show (sig_hbox);
2447         gtk_box_pack_start (GTK_BOX (vbox_sig), sig_hbox, FALSE, FALSE, 0);
2448
2449         sigfile_radiobtn = gtk_radio_button_new_with_label (NULL, _("File"));
2450         gtk_widget_show (sigfile_radiobtn);
2451         gtk_box_pack_start (GTK_BOX (sig_hbox), sigfile_radiobtn,
2452                             FALSE, FALSE, 0);
2453         g_object_set_data (G_OBJECT (sigfile_radiobtn),
2454                            MENU_VAL_ID,
2455                            GINT_TO_POINTER (SIG_FILE));
2456         g_signal_connect(G_OBJECT(sigfile_radiobtn), "clicked",
2457                          G_CALLBACK(prefs_account_sigfile_radiobtn_cb), NULL);
2458
2459         sigcmd_radiobtn = gtk_radio_button_new_with_label_from_widget
2460                 (GTK_RADIO_BUTTON(sigfile_radiobtn), _("Command output"));
2461         gtk_widget_show (sigcmd_radiobtn);
2462         gtk_box_pack_start (GTK_BOX (sig_hbox), sigcmd_radiobtn,
2463                             FALSE, FALSE, 0);
2464         g_object_set_data (G_OBJECT (sigcmd_radiobtn),
2465                            MENU_VAL_ID,
2466                            GINT_TO_POINTER (SIG_COMMAND));
2467         g_signal_connect(G_OBJECT(sigcmd_radiobtn), "clicked",
2468                          G_CALLBACK(prefs_account_sigcmd_radiobtn_cb), NULL);
2469
2470         hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2471         gtk_widget_show (hbox2);
2472         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox2, TRUE, TRUE, 0);
2473         label_sigpath = gtk_label_new (_("Signature"));
2474         gtk_widget_show (label_sigpath);
2475         gtk_box_pack_start (GTK_BOX (hbox2), label_sigpath, FALSE, FALSE, 0);
2476
2477         entry_sigpath = gtk_entry_new ();
2478         gtk_widget_show (entry_sigpath);
2479         gtk_box_pack_start (GTK_BOX (hbox2), entry_sigpath, TRUE, TRUE, 0);
2480
2481         signature_browse_button = gtkut_get_browse_file_btn(_("Bro_wse"));
2482         gtk_widget_show (signature_browse_button);
2483         gtk_box_pack_start (GTK_BOX (hbox2), signature_browse_button, FALSE, FALSE, 0);
2484         g_signal_connect(G_OBJECT(signature_browse_button), "clicked",
2485                          G_CALLBACK(prefs_account_signature_browse_cb), NULL);
2486
2487         signature_edit_button = gtk_button_new_with_mnemonic("_Edit");
2488         gtk_widget_show (signature_edit_button);
2489         gtk_box_pack_start (GTK_BOX (hbox2), signature_edit_button, FALSE, FALSE, 0);
2490         g_signal_connect(G_OBJECT(signature_edit_button), "clicked",
2491                          G_CALLBACK(prefs_account_signature_edit_cb), entry_sigpath);
2492
2493         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
2494
2495         table =  gtk_grid_new();
2496         gtk_widget_show (table);
2497         gtk_container_add (GTK_CONTAINER (frame), table);
2498         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
2499         gtk_grid_set_row_spacing(GTK_GRID(table), VSPACING_NARROW_2);
2500         gtk_grid_set_column_spacing(GTK_GRID(table), 8);
2501
2502         autocc_checkbtn = gtk_check_button_new_with_label (
2503                                 prefs_common_translated_header_name("Cc:"));
2504         gtk_widget_show (autocc_checkbtn);
2505         gtk_grid_attach(GTK_GRID(table), autocc_checkbtn, 0, 0, 1, 1);
2506
2507         autocc_entry = gtk_entry_new ();
2508         gtk_widget_show (autocc_entry);
2509         gtk_grid_attach(GTK_GRID(table), autocc_entry, 1, 0, 1, 1);
2510         gtk_widget_set_hexpand(autocc_entry, TRUE);
2511         gtk_widget_set_halign(autocc_entry, GTK_ALIGN_FILL);
2512
2513         SET_TOGGLE_SENSITIVITY (autocc_checkbtn, autocc_entry);
2514
2515         autobcc_checkbtn = gtk_check_button_new_with_label (
2516                                 prefs_common_translated_header_name("Bcc:"));
2517         gtk_widget_show (autobcc_checkbtn);
2518         gtk_grid_attach(GTK_GRID(table), autobcc_checkbtn, 0, 1, 1, 1);
2519
2520         autobcc_entry = gtk_entry_new ();
2521         gtk_widget_show (autobcc_entry);
2522         gtk_grid_attach(GTK_GRID(table), autobcc_entry, 1, 1, 1, 1);
2523         gtk_widget_set_hexpand(autobcc_entry, TRUE);
2524         gtk_widget_set_halign(autobcc_entry, GTK_ALIGN_FILL);
2525
2526         SET_TOGGLE_SENSITIVITY (autobcc_checkbtn, autobcc_entry);
2527
2528         autoreplyto_checkbtn = gtk_check_button_new_with_label (
2529                                 prefs_common_translated_header_name("Reply-To:"));
2530         gtk_widget_show (autoreplyto_checkbtn);
2531         gtk_grid_attach(GTK_GRID(table), autoreplyto_checkbtn, 0, 2, 1, 1);
2532
2533         autoreplyto_entry = gtk_entry_new ();
2534         gtk_widget_show (autoreplyto_entry);
2535         gtk_grid_attach(GTK_GRID(table), autoreplyto_entry, 1, 2, 1, 1);
2536         gtk_widget_set_hexpand(autoreplyto_entry, TRUE);
2537         gtk_widget_set_halign(autoreplyto_entry, GTK_ALIGN_FILL);
2538
2539         SET_TOGGLE_SENSITIVITY (autoreplyto_checkbtn, autoreplyto_entry);
2540
2541 #if USE_ENCHANT
2542         PACK_FRAME (vbox1, frame_dict, _("Spell check dictionaries"));
2543
2544         table_dict =  gtk_grid_new();
2545         gtk_widget_show (table_dict);
2546         gtk_container_add (GTK_CONTAINER (frame_dict), table_dict);
2547         gtk_container_set_border_width (GTK_CONTAINER (table_dict), 8);
2548         gtk_grid_set_row_spacing(GTK_GRID(table_dict), VSPACING_NARROW_2);
2549         gtk_grid_set_column_spacing(GTK_GRID(table_dict), 8);
2550
2551         /* Default dictionary */
2552         checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
2553         gtk_grid_attach(GTK_GRID(table_dict), checkbtn_enable_default_dictionary, 0, 0, 1, 1);
2554
2555         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
2556                         tmp_ac_prefs.enable_default_dictionary);
2557
2558         combo_default_dictionary = gtkaspell_dictionary_combo_new(TRUE);
2559         gtk_grid_attach(GTK_GRID(table_dict), combo_default_dictionary, 1, 0, 1, 1);
2560
2561         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, combo_default_dictionary);
2562
2563         /* Default dictionary */
2564         checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
2565         gtk_grid_attach(GTK_GRID(table_dict), checkbtn_enable_default_alt_dictionary, 0, 1, 1, 1);
2566
2567         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
2568                         tmp_ac_prefs.enable_default_alt_dictionary);
2569
2570         combo_default_alt_dictionary = gtkaspell_dictionary_combo_new(FALSE);
2571         gtk_grid_attach(GTK_GRID(table_dict), combo_default_alt_dictionary, 1, 1, 1, 1);
2572
2573         SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, combo_default_alt_dictionary);
2574
2575         gtk_widget_show_all(table_dict);
2576 #endif
2577
2578         page->sigfile_radiobtn = sigfile_radiobtn;
2579         page->entry_sigpath      = entry_sigpath;
2580         page->checkbtn_autosig   = checkbtn_autosig;
2581         page->entry_sigsep       = entry_sigsep;
2582
2583         page->autocc_checkbtn      = autocc_checkbtn;
2584         page->autocc_entry       = autocc_entry;
2585         page->autobcc_checkbtn     = autobcc_checkbtn;
2586         page->autobcc_entry      = autobcc_entry;
2587         page->autoreplyto_checkbtn = autoreplyto_checkbtn;
2588         page->autoreplyto_entry  = autoreplyto_entry;
2589 #ifdef USE_ENCHANT
2590         page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
2591         page->combo_default_dictionary = combo_default_dictionary;
2592         page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
2593         page->combo_default_alt_dictionary = combo_default_alt_dictionary;
2594 #endif
2595
2596 #ifdef USE_ENCHANT
2597         /* reset gtkaspell menus */
2598         if (compose_page.combo_default_dictionary != NULL) {
2599                 gtk_combo_box_set_model(GTK_COMBO_BOX(compose_page.combo_default_dictionary),
2600                                         gtkaspell_dictionary_store_new());
2601                 gtk_combo_box_set_model(GTK_COMBO_BOX(compose_page.combo_default_alt_dictionary),
2602                                         gtkaspell_dictionary_store_new_with_refresh(
2603                                                 FALSE));
2604         }
2605 #endif
2606
2607         tmp_ac_prefs = *ac_prefs;
2608
2609         if (new_account) {
2610                 prefs_set_dialog_to_default(compose_param);
2611         } else
2612                 prefs_set_dialog(compose_param);
2613
2614         page->vbox = vbox1;
2615
2616         page->page.widget = vbox1;
2617 }
2618         
2619 static void templates_create_widget_func(PrefsPage * _page,
2620                                            GtkWindow * window,
2621                                            gpointer data)
2622 {
2623         TemplatesPage *page = (TemplatesPage *) _page;
2624         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2625         GtkWidget *vbox;
2626         GtkWidget *vbox2;
2627         GtkWidget *notebook;
2628
2629         vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2630         gtk_widget_show(vbox);
2631         
2632         notebook = gtk_notebook_new();
2633         gtk_widget_show(notebook);
2634         gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
2635
2636         /* compose format */
2637         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2638         gtk_widget_show (vbox2);
2639         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2640
2641         quotefmt_create_new_msg_fmt_widgets(
2642                                 window,
2643                                 vbox2,
2644                                 &page->checkbtn_compose_with_format,
2645                                 NULL,
2646                                 &page->compose_subject_format,
2647                                 &page->compose_body_format,
2648                                 TRUE, NULL);
2649         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Compose")));
2650
2651         /* reply format */      
2652         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2653         gtk_widget_show (vbox2);
2654         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2655         
2656         quotefmt_create_reply_fmt_widgets(
2657                                 window,
2658                                 vbox2,
2659                                 &page->checkbtn_reply_with_format,
2660                                 NULL,
2661                                 &page->reply_quotemark,
2662                                 &page->reply_body_format,
2663                                 TRUE, NULL);
2664         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Reply")));
2665
2666         /* forward format */    
2667         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2668         gtk_widget_show (vbox2);
2669         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2670
2671         quotefmt_create_forward_fmt_widgets(
2672                                 window,
2673                                 vbox2,
2674                                 &page->checkbtn_forward_with_format,
2675                                 NULL,
2676                                 &page->forward_quotemark,
2677                                 &page->forward_body_format,
2678                                 TRUE, NULL);
2679         gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Forward")));
2680
2681         tmp_ac_prefs = *ac_prefs;
2682
2683         if (new_account) {
2684                 prefs_set_dialog_to_default(templates_param);
2685         } else
2686                 prefs_set_dialog(templates_param);
2687
2688         page->vbox = vbox;
2689
2690         page->page.widget = vbox;
2691 }
2692
2693 static void privacy_create_widget_func(PrefsPage * _page,
2694                                            GtkWindow * window,
2695                                            gpointer data)
2696 {
2697         PrivacyPage *page = (PrivacyPage *) _page;
2698         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2699
2700         GtkWidget *vbox1;
2701         GtkWidget *vbox2;
2702         GtkWidget *hbox1;
2703         GtkWidget *label;
2704         GtkWidget *default_privacy_system;
2705         GtkListStore *menu;
2706         GtkCellRenderer *rend;
2707         GtkWidget *default_encrypt_checkbtn;
2708         GtkWidget *default_encrypt_reply_checkbtn;
2709         GtkWidget *default_sign_checkbtn;
2710         GtkWidget *default_sign_reply_checkbtn;
2711         GtkWidget *save_clear_text_checkbtn;
2712         GtkWidget *encrypt_to_self_checkbtn;
2713
2714         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2715         gtk_widget_show (vbox1);
2716         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2717
2718         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2719         gtk_widget_show (vbox2);
2720         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2721
2722         hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2723         gtk_widget_show (hbox1);
2724         gtk_container_add (GTK_CONTAINER(vbox2), hbox1);
2725
2726         label = gtk_label_new(_("Default privacy system"));
2727         gtk_widget_show(label);
2728         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
2729
2730         /* Can't use gtkut_sc_combobox_create() here, because model for this
2731          * combobox needs an extra string column to store privacy plugin id. */
2732         menu = gtk_list_store_new(4,
2733                         G_TYPE_STRING,
2734                         G_TYPE_INT,
2735                         G_TYPE_BOOLEAN,
2736                         G_TYPE_STRING); /* This is where we store the privacy plugin id. */
2737         default_privacy_system = gtk_combo_box_new_with_model(GTK_TREE_MODEL(menu));
2738
2739         rend = gtk_cell_renderer_text_new();
2740         gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(default_privacy_system), rend, TRUE);
2741         gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(default_privacy_system), rend,
2742                         "text", COMBOBOX_TEXT,
2743                         "sensitive", COMBOBOX_SENS,
2744                         NULL);
2745         gtk_widget_set_focus_on_click(GTK_WIDGET(default_privacy_system), FALSE);
2746
2747         gtk_widget_show (default_privacy_system);
2748         gtk_box_pack_start (GTK_BOX(hbox1), default_privacy_system, FALSE, TRUE, 0);
2749
2750         g_signal_connect(G_OBJECT(default_privacy_system), "changed",
2751                          G_CALLBACK(privacy_system_activated),
2752                          NULL);
2753
2754         PACK_CHECK_BUTTON (vbox2, default_sign_checkbtn,
2755                            _("Always sign messages"));
2756         PACK_CHECK_BUTTON (vbox2, default_encrypt_checkbtn,
2757                            _("Always encrypt messages"));
2758         PACK_CHECK_BUTTON (vbox2, default_sign_reply_checkbtn,
2759                            _("Always sign messages when replying to a "
2760                              "signed message"));
2761         PACK_CHECK_BUTTON (vbox2, default_encrypt_reply_checkbtn,
2762                            _("Always encrypt messages when replying to an "
2763                              "encrypted message"));
2764         PACK_CHECK_BUTTON (vbox2, encrypt_to_self_checkbtn,
2765                            _("Encrypt sent messages with your own key in addition to recipient's"));
2766         PACK_CHECK_BUTTON (vbox2, save_clear_text_checkbtn,
2767                            _("Save sent encrypted messages as clear text"));
2768
2769         SET_TOGGLE_SENSITIVITY_REVERSE(encrypt_to_self_checkbtn, save_clear_text_checkbtn);
2770         SET_TOGGLE_SENSITIVITY_REVERSE(save_clear_text_checkbtn, encrypt_to_self_checkbtn);
2771
2772         page->default_privacy_system = default_privacy_system;
2773         page->default_encrypt_checkbtn = default_encrypt_checkbtn;
2774         page->default_encrypt_reply_checkbtn = default_encrypt_reply_checkbtn;
2775         page->default_sign_reply_checkbtn = default_sign_reply_checkbtn;
2776         page->default_sign_checkbtn    = default_sign_checkbtn;
2777         page->save_clear_text_checkbtn = save_clear_text_checkbtn;
2778         page->encrypt_to_self_checkbtn = encrypt_to_self_checkbtn;
2779
2780         update_privacy_system_menu();
2781
2782         tmp_ac_prefs = *ac_prefs;
2783
2784         if (new_account) {
2785                 prefs_set_dialog_to_default(privacy_param);
2786         } else
2787                 prefs_set_dialog(privacy_param);
2788
2789         page->vbox = vbox1;
2790
2791         page->page.widget = vbox1;
2792 }
2793
2794 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data)               \
2795 {                                                                       \
2796         btn = gtk_radio_button_new_with_label_from_widget               \
2797                 (GTK_RADIO_BUTTON (btn_p), label);                      \
2798         gtk_widget_show (btn);                                          \
2799         gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0);       \
2800         g_object_set_data (G_OBJECT (btn),                              \
2801                            MENU_VAL_ID,                                 \
2802                            GINT_TO_POINTER (data));                     \
2803 }
2804
2805 #ifdef USE_GNUTLS
2806
2807 #define CREATE_RADIO_BUTTONS(box,                                       \
2808                              btn1, btn1_label, btn1_data,               \
2809                              btn2, btn2_label, btn2_data,               \
2810                              btn3, btn3_label, btn3_data)               \
2811 {                                                                       \
2812         btn1 = gtk_radio_button_new_with_label(NULL, btn1_label);       \
2813         gtk_widget_show (btn1);                                         \
2814         gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0);      \
2815         g_object_set_data (G_OBJECT (btn1),                             \
2816                            MENU_VAL_ID,                                 \
2817                            GINT_TO_POINTER (btn1_data));                \
2818                                                                         \
2819         CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data);    \
2820         CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data);    \
2821 }
2822
2823 static void pop_ssltunnel_toggled(GtkToggleButton *button,
2824                                         gpointer data)
2825 {
2826         gboolean active = gtk_toggle_button_get_active(button);
2827         
2828         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2829                         advanced_page.popport_checkbtn)) == TRUE)
2830                 return;
2831         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.popport_spinbtn),
2832                                   active ? 995 : 110);
2833 }
2834
2835 static void imap_ssltunnel_toggled(GtkToggleButton *button,
2836                                         gpointer data)
2837 {
2838         gboolean active = gtk_toggle_button_get_active(button);
2839         
2840         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2841                         advanced_page.imapport_checkbtn)) == TRUE)
2842                 return;
2843         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.imapport_spinbtn),
2844                                   active ? 993 : 143);
2845 }
2846
2847 static void nntp_ssltunnel_toggled(GtkToggleButton *button,
2848                                         gpointer data)
2849 {
2850         gboolean active = gtk_toggle_button_get_active(button);
2851         
2852         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2853                         advanced_page.nntpport_checkbtn)) == TRUE)
2854                 return;
2855         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.nntpport_spinbtn),
2856                                   active ? 563 : 119);
2857 }       
2858
2859 static void smtp_ssltunnel_toggled(GtkToggleButton *button,
2860                                         gpointer data)
2861 {
2862         gboolean active = gtk_toggle_button_get_active(button);
2863         
2864         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2865                         advanced_page.smtpport_checkbtn)) == TRUE)
2866                 return;
2867         gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.smtpport_spinbtn),
2868                                   active ? 465 : 25);   
2869 }
2870
2871 static void ssl_create_widget_func(PrefsPage * _page,
2872                                            GtkWindow * window,
2873                                            gpointer data)
2874 {
2875         SSLPage *page = (SSLPage *) _page;
2876         PrefsAccount *ac_prefs = (PrefsAccount *) data;
2877
2878         GtkWidget *vbox1;
2879
2880         GtkWidget *pop_frame;
2881         GtkWidget *vbox2;
2882         GtkWidget *pop_nossl_radiobtn;
2883         GtkWidget *pop_ssltunnel_radiobtn;
2884         GtkWidget *pop_starttls_radiobtn;
2885
2886         GtkWidget *imap_frame;
2887         GtkWidget *vbox3;
2888         GtkWidget *imap_nossl_radiobtn;
2889         GtkWidget *imap_ssltunnel_radiobtn;
2890         GtkWidget *imap_starttls_radiobtn;
2891
2892         GtkWidget *nntp_frame;
2893         GtkWidget *vbox4;
2894         GtkWidget *nntp_nossl_radiobtn;
2895         GtkWidget *nntp_ssltunnel_radiobtn;
2896
2897         GtkWidget *send_frame;
2898         GtkWidget *vbox5;
2899         GtkWidget *smtp_nossl_radiobtn;
2900         GtkWidget *smtp_ssltunnel_radiobtn;
2901         GtkWidget *smtp_starttls_radiobtn;
2902
2903         GtkWidget *cert_frame;
2904         GtkWidget *cert_table;
2905         GtkWidget *entry_in_cert_pass;
2906         GtkWidget *entry_out_cert_pass;
2907         GtkWidget *showpwd_checkbtn;
2908
2909         GtkWidget *vbox7;
2910         GtkWidget *ssl_certs_auto_accept_checkbtn;
2911         GtkWidget *use_nonblocking_ssl_checkbtn;
2912         GtkWidget *hbox;
2913         GtkWidget *hbox_spc;
2914         GtkWidget *label;
2915         gchar *buf;
2916
2917         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2918         gtk_widget_show (vbox1);
2919         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2920
2921         vbox2 = gtkut_get_options_frame(vbox1, &pop_frame, _("POP"));
2922
2923         CREATE_RADIO_BUTTONS(vbox2,
2924                              pop_nossl_radiobtn,
2925                              _("Don't use TLS"),
2926                              SSL_NONE,
2927                              pop_ssltunnel_radiobtn,
2928                              _("Use TLS"),
2929                              SSL_TUNNEL,
2930                              pop_starttls_radiobtn,
2931                              _("Use STARTTLS command to start encrypted session"),
2932                              SSL_STARTTLS);
2933         g_signal_connect(G_OBJECT(pop_ssltunnel_radiobtn), "toggled",
2934                          G_CALLBACK(pop_ssltunnel_toggled), NULL);
2935         
2936         vbox3 = gtkut_get_options_frame(vbox1, &imap_frame, _("IMAP"));
2937
2938         CREATE_RADIO_BUTTONS(vbox3,
2939                              imap_nossl_radiobtn,
2940                              _("Don't use TLS"),
2941                              SSL_NONE,
2942                              imap_ssltunnel_radiobtn,
2943                              _("Use TLS"),
2944                              SSL_TUNNEL,
2945                              imap_starttls_radiobtn,
2946                              _("Use STARTTLS command to start encrypted session"),
2947                              SSL_STARTTLS);
2948         g_signal_connect(G_OBJECT(imap_ssltunnel_radiobtn), "toggled",
2949                          G_CALLBACK(imap_ssltunnel_toggled), NULL);
2950
2951         vbox4 = gtkut_get_options_frame(vbox1, &nntp_frame, _("NNTP"));
2952
2953         nntp_nossl_radiobtn =
2954                 gtk_radio_button_new_with_label (NULL, _("Don't use TLS"));
2955         gtk_widget_show (nntp_nossl_radiobtn);
2956         gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
2957                             FALSE, FALSE, 0);
2958         g_object_set_data (G_OBJECT (nntp_nossl_radiobtn),
2959                            MENU_VAL_ID,
2960                            GINT_TO_POINTER (SSL_NONE));
2961
2962         CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
2963                             _("Use TLS"), SSL_TUNNEL);
2964         g_signal_connect(G_OBJECT(nntp_ssltunnel_radiobtn), "toggled",
2965                          G_CALLBACK(nntp_ssltunnel_toggled), NULL);
2966
2967         vbox5 = gtkut_get_options_frame(vbox1, &send_frame, _("Send (SMTP)"));
2968
2969         CREATE_RADIO_BUTTONS(vbox5,
2970                              smtp_nossl_radiobtn,
2971                              _("Don't use TLS (but, if necessary, use STARTTLS)"),
2972                              SSL_NONE,
2973                              smtp_ssltunnel_radiobtn,
2974                              _("Use TLS"),
2975                              SSL_TUNNEL,
2976                              smtp_starttls_radiobtn,
2977                              _("Use STARTTLS command to start encrypted session"),
2978                              SSL_STARTTLS);
2979         g_signal_connect(G_OBJECT(smtp_ssltunnel_radiobtn), "toggled",
2980                          G_CALLBACK(smtp_ssltunnel_toggled), NULL);
2981
2982         PACK_FRAME(vbox1, cert_frame, _("Client certificates"));
2983
2984         cert_table = gtk_grid_new();
2985         gtk_container_add(GTK_CONTAINER(cert_frame), cert_table);
2986         gtk_container_set_border_width(GTK_CONTAINER(cert_table), 8);
2987         gtk_grid_set_row_spacing(GTK_GRID(cert_table), VSPACING_NARROW_2);
2988         gtk_grid_set_column_spacing(GTK_GRID(cert_table), 8);
2989
2990         label = gtk_label_new(_("Certificate for receiving"));
2991         gtk_label_set_xalign(GTK_LABEL(label), 1.0);
2992         entry_in_cert_file = gtk_entry_new();
2993         in_ssl_cert_browse_button = gtkut_get_browse_file_btn(_("Browse"));
2994         CLAWS_SET_TIP(label,
2995                              _("Client certificate file as a PKCS12 or PEM file"));
2996         CLAWS_SET_TIP(entry_in_cert_file,
2997                              _("Client certificate file as a PKCS12 or PEM file"));
2998         gtk_grid_attach(GTK_GRID(cert_table), label, 0, 0, 1, 1);
2999         gtk_grid_attach(GTK_GRID(cert_table), entry_in_cert_file, 1, 0, 1, 1);
3000         gtk_widget_set_hexpand(entry_in_cert_file, TRUE);
3001         gtk_widget_set_halign(entry_in_cert_file, GTK_ALIGN_FILL);
3002         gtk_grid_attach(GTK_GRID(cert_table), in_ssl_cert_browse_button, 2, 0, 1, 1);
3003
3004         label = gtk_label_new(_("Password"));
3005         gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3006         entry_in_cert_pass = gtk_entry_new();
3007         gtk_entry_set_visibility(GTK_ENTRY(entry_in_cert_pass), FALSE);
3008         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
3009         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
3010         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
3011                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), entry_in_cert_pass);
3012         gtk_grid_attach(GTK_GRID(cert_table), label, 0, 1, 1, 1);
3013         gtk_grid_attach(GTK_GRID(cert_table), entry_in_cert_pass, 1, 1, 1, 1);
3014         gtk_widget_set_hexpand(entry_in_cert_pass, TRUE);
3015         gtk_widget_set_halign(entry_in_cert_pass, GTK_ALIGN_FILL);
3016         gtk_grid_attach(GTK_GRID(cert_table), showpwd_checkbtn, 2, 1, 1, 1);
3017
3018         label = gtk_label_new(_("Certificate for sending"));
3019         gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3020         entry_out_cert_file = gtk_entry_new();
3021         out_ssl_cert_browse_button = gtkut_get_browse_file_btn(_("Browse"));
3022         CLAWS_SET_TIP(label,
3023                              _("Client certificate file as a PKCS12 or PEM file"));
3024         CLAWS_SET_TIP(entry_out_cert_file,
3025                              _("Client certificate file as a PKCS12 or PEM file"));
3026         gtk_grid_attach(GTK_GRID(cert_table), label, 0, 2, 1, 1);
3027         gtk_grid_attach(GTK_GRID(cert_table), entry_out_cert_file, 1, 2, 1, 1);
3028         gtk_widget_set_hexpand(entry_out_cert_file, TRUE);
3029         gtk_widget_set_halign(entry_out_cert_file, GTK_ALIGN_FILL);
3030         gtk_grid_attach(GTK_GRID(cert_table), out_ssl_cert_browse_button, 2, 2, 1, 1);
3031
3032         label = gtk_label_new(_("Password"));
3033         gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3034         entry_out_cert_pass = gtk_entry_new();
3035         gtk_entry_set_visibility(GTK_ENTRY(entry_out_cert_pass), FALSE);
3036         showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
3037         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
3038         g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
3039                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), entry_out_cert_pass);
3040         gtk_grid_attach(GTK_GRID(cert_table), label, 0, 3, 1, 1);
3041         gtk_grid_attach(GTK_GRID(cert_table), entry_out_cert_pass, 1, 3, 1, 1);
3042         gtk_widget_set_hexpand(entry_out_cert_pass, TRUE);
3043         gtk_widget_set_halign(entry_out_cert_pass, GTK_ALIGN_FILL);
3044         gtk_grid_attach(GTK_GRID(cert_table), showpwd_checkbtn, 2, 3, 1, 1);
3045
3046         gtk_widget_show_all(cert_table);
3047
3048         g_signal_connect(G_OBJECT(in_ssl_cert_browse_button), "clicked",
3049                          G_CALLBACK(prefs_account_in_cert_browse_cb), NULL);
3050         g_signal_connect(G_OBJECT(out_ssl_cert_browse_button), "clicked",
3051                          G_CALLBACK(prefs_account_out_cert_browse_cb), NULL);
3052         
3053         vbox7 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
3054         gtk_widget_show (vbox7);
3055         gtk_box_pack_start (GTK_BOX (vbox1), vbox7, FALSE, FALSE, 0);
3056
3057         PACK_CHECK_BUTTON(vbox7, ssl_certs_auto_accept_checkbtn,
3058                           _("Automatically accept valid TLS certificates"));
3059
3060         PACK_CHECK_BUTTON(vbox7, use_nonblocking_ssl_checkbtn,
3061                           _("Use non-blocking TLS"));
3062
3063         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
3064         gtk_widget_show (hbox);
3065         gtk_box_pack_start (GTK_BOX (vbox7), hbox, FALSE, FALSE, 0);
3066
3067         hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
3068         gtk_widget_show (hbox_spc);
3069         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
3070         gtk_widget_set_size_request (hbox_spc, 16, -1);
3071
3072         label = gtk_label_new
3073                 (_("Turn this off if you have TLS connection problems"));
3074         gtk_widget_show (label);
3075         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
3076         gtkut_widget_set_small_font_size (label);
3077
3078         page->pop_frame               = pop_frame;
3079         page->pop_nossl_radiobtn      = pop_nossl_radiobtn;
3080         page->pop_ssltunnel_radiobtn  = pop_ssltunnel_radiobtn;
3081         page->pop_starttls_radiobtn   = pop_starttls_radiobtn;
3082
3083         page->imap_frame              = imap_frame;
3084         page->imap_nossl_radiobtn     = imap_nossl_radiobtn;
3085         page->imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
3086         page->imap_starttls_radiobtn  = imap_starttls_radiobtn;
3087
3088         page->nntp_frame              = nntp_frame;
3089         page->nntp_nossl_radiobtn     = nntp_nossl_radiobtn;
3090         page->nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
3091
3092         page->send_frame              = send_frame;
3093         page->smtp_nossl_radiobtn     = smtp_nossl_radiobtn;
3094         page->smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
3095         page->smtp_starttls_radiobtn  = smtp_starttls_radiobtn;
3096
3097         page->entry_in_cert_file      = entry_in_cert_file;
3098         page->entry_in_cert_pass      = entry_in_cert_pass;
3099         page->entry_out_cert_file     = entry_out_cert_file;
3100         page->entry_out_cert_pass     = entry_out_cert_pass;
3101
3102         page->ssl_certs_auto_accept_checkbtn = ssl_certs_auto_accept_checkbtn;
3103         page->use_nonblocking_ssl_checkbtn = use_nonblocking_ssl_checkbtn;
3104
3105         tmp_ac_prefs = *ac_prefs;
3106
3107         if (new_account) {
3108                 prefs_set_dialog_to_default(ssl_param);
3109         } else {
3110                 prefs_set_dialog(ssl_param);
3111
3112                 /* Passwords are handled outside of PrefParams. */
3113                 buf = passwd_store_get_account(ac_prefs->account_id,
3114                                 PWS_ACCOUNT_RECV_CERT);
3115                 gtk_entry_set_text(GTK_ENTRY(page->entry_in_cert_pass), buf != NULL ? buf : "");
3116                 if (buf != NULL) {
3117                         memset(buf, 0, strlen(buf));
3118                         g_free(buf);
3119                 }
3120
3121                 buf = passwd_store_get_account(ac_prefs->account_id,
3122                                 PWS_ACCOUNT_SEND_CERT);
3123                 gtk_entry_set_text(GTK_ENTRY(page->entry_out_cert_pass), buf != NULL ? buf : "");
3124                 if (buf != NULL) {
3125                         memset(buf, 0, strlen(buf));
3126                         g_free(buf);
3127                 }
3128         }
3129
3130         page->vbox = vbox1;
3131
3132         page->page.widget = vbox1;
3133 }
3134
3135 #undef CREATE_RADIO_BUTTONS
3136 #endif /* USE_GNUTLS */
3137
3138 static void proxy_create_widget_func(PrefsPage * _page,
3139                                            GtkWindow * window,
3140                                            gpointer data)
3141 {
3142         ProxyPage *page = (ProxyPage *) _page;
3143         PrefsAccount *ac_prefs = (PrefsAccount *) data;
3144         GtkWidget *vbox1, *vbox2, *vbox3, *vbox4;
3145         GtkWidget *proxy_frame;
3146         GtkWidget *proxy_checkbtn;
3147         GtkWidget *default_proxy_checkbtn;
3148         GtkWidget *hbox;
3149         GtkWidget *label;
3150         GtkWidget *socks4_radiobtn;
3151         GtkWidget *socks5_radiobtn;
3152         GtkWidget *proxy_host_entry;
3153         GtkWidget *proxy_port_spinbtn;
3154         GtkWidget *proxy_auth_checkbtn;
3155         GtkWidget *proxy_name_entry;
3156         GtkWidget *proxy_pass_entry;
3157         GtkWidget *proxy_send_checkbtn;
3158         GtkWidget *table;
3159         GtkWidget *button;
3160         gchar *buf;
3161
3162         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
3163         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
3164
3165         proxy_checkbtn = gtk_check_button_new_with_label (_("Use proxy server"));
3166         PACK_FRAME (vbox1, proxy_frame, NULL);
3167         gtk_frame_set_label_widget (GTK_FRAME(proxy_frame), proxy_checkbtn);
3168
3169         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
3170         gtk_container_add (GTK_CONTAINER (proxy_frame), vbox2);
3171         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
3172
3173         default_proxy_checkbtn =
3174                 gtk_check_button_new_with_label (C_("In account preferences, referring to whether or not use proxy settings from common preferences", "Use default settings"));
3175         CLAWS_SET_TIP(default_proxy_checkbtn,
3176                         _("Use global proxy server settings"));
3177         gtk_box_pack_start (GTK_BOX (vbox2), default_proxy_checkbtn, FALSE, FALSE, 0);
3178
3179         vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
3180         gtk_box_pack_start (GTK_BOX (vbox2), vbox3, FALSE, FALSE, 0);
3181
3182         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
3183         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
3184
3185         socks4_radiobtn = gtk_radio_button_new_with_label(NULL, "SOCKS4");
3186         gtk_box_pack_start (GTK_BOX (hbox), socks4_radiobtn, FALSE, FALSE, 0);
3187         g_object_set_data(G_OBJECT(socks4_radiobtn), MENU_VAL_ID,
3188                           GINT_TO_POINTER(PROXY_SOCKS4));
3189
3190         CREATE_RADIO_BUTTON(hbox, socks5_radiobtn, socks4_radiobtn, "SOCKS5",
3191                             PROXY_SOCKS5);
3192
3193         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
3194         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
3195
3196         label = gtk_label_new(_("Hostname"));
3197         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3198
3199         proxy_host_entry = gtk_entry_new();
3200         gtk_widget_set_size_request(proxy_host_entry, DEFAULT_ENTRY_WIDTH, -1);
3201         gtk_box_pack_start(GTK_BOX(hbox), proxy_host_entry, TRUE, TRUE, 0);
3202
3203         label = gtk_label_new(_("Port"));
3204         gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3205
3206         proxy_port_spinbtn = gtk_spin_button_new_with_range(0, 65535, 1080);
3207         gtk_widget_set_size_request(proxy_port_spinbtn, 64, -1);
3208         gtk_box_pack_start(GTK_BOX(hbox), proxy_port_spinbtn, FALSE, FALSE, 0);
3209
3210         vbox4 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
3211         gtk_box_pack_start(GTK_BOX(vbox3), vbox4, FALSE, FALSE, 0);
3212
3213         PACK_CHECK_BUTTON (vbox4, proxy_auth_checkbtn, _("Use authentication"));
3214
3215         table = gtk_grid_new();
3216         gtk_box_pack_start (GTK_BOX (vbox4), table, FALSE, FALSE, 0);
3217
3218         label = gtk_label_new(_("Username"));
3219         gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
3220
3221         proxy_name_entry = gtk_entry_new();
3222         gtk_widget_set_size_request(proxy_name_entry, DEFAULT_ENTRY_WIDTH, -1);
3223         gtk_grid_attach(GTK_GRID(table), proxy_name_entry, 1, 0, 1, 1);
3224         gtk_widget_set_hexpand(proxy_name_entry, TRUE);
3225         gtk_widget_set_halign(proxy_name_entry, GTK_ALIGN_FILL);
3226
3227         label = gtk_label_new(_("Password"));
3228         gtk_grid_attach(GTK_GRID(table), label, 2, 0, 1, 1);
3229
3230         proxy_pass_entry = gtk_entry_new();
3231         gtk_widget_set_size_request(proxy_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
3232         gtk_entry_set_visibility(GTK_ENTRY(proxy_pass_entry), FALSE);
3233         gtk_grid_attach(GTK_GRID(table), proxy_pass_entry, 3, 0, 1, 1);
3234         gtk_widget_set_hexpand(proxy_pass_entry, TRUE);
3235         gtk_widget_set_halign(proxy_pass_entry, GTK_ALIGN_FILL);
3236
3237         button = gtk_check_button_new_with_label(_("Show password"));
3238         gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
3239         gtk_grid_attach(GTK_GRID(table), button, 3, 1, 1, 1);
3240
3241         g_signal_connect(G_OBJECT(button), "toggled",
3242                         G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), proxy_pass_entry);
3243
3244         gtk_box_pack_start(GTK_BOX(vbox2), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 0);
3245
3246         PACK_CHECK_BUTTON(vbox2, proxy_send_checkbtn,
3247                           _("Use proxy server for sending"));
3248         CLAWS_SET_TIP(proxy_send_checkbtn,
3249                         _("If disabled, messages will be sent using direct connection to configured outgoing server, bypassing any configured proxy server."));
3250
3251         SET_TOGGLE_SENSITIVITY(proxy_auth_checkbtn, table);
3252         SET_TOGGLE_SENSITIVITY(socks5_radiobtn, vbox4);
3253         SET_TOGGLE_SENSITIVITY(proxy_checkbtn, vbox2);
3254         SET_TOGGLE_SENSITIVITY_REVERSE(default_proxy_checkbtn, vbox3);
3255
3256         gtk_widget_show_all(vbox1);
3257
3258         page->proxy_checkbtn = proxy_checkbtn;
3259         page->default_proxy_checkbtn = default_proxy_checkbtn;
3260         page->socks4_radiobtn = socks4_radiobtn;
3261         page->socks5_radiobtn = socks5_radiobtn;
3262         page->proxy_host_entry = proxy_host_entry;
3263         page->proxy_port_spinbtn = proxy_port_spinbtn;
3264         page->proxy_auth_checkbtn = proxy_auth_checkbtn;
3265         page->proxy_name_entry = proxy_name_entry;
3266         page->proxy_pass_entry = proxy_pass_entry;
3267         page->proxy_send_checkbtn = proxy_send_checkbtn;
3268         page->vbox = vbox1;
3269         page->page.widget = vbox1;
3270
3271         tmp_ac_prefs = *ac_prefs;
3272
3273         if (new_account) {
3274                 prefs_set_dialog_to_default(proxy_param);
3275         } else {
3276                 prefs_set_dialog(proxy_param);
3277
3278                 /* Passwords are handled outside of PrefParams. */
3279                 buf = passwd_store_get_account(ac_prefs->account_id,
3280                                 PWS_ACCOUNT_PROXY_PASS);
3281                 gtk_entry_set_text(GTK_ENTRY(page->proxy_pass_entry),
3282                                 buf != NULL ? buf : "");
3283                 if (buf != NULL) {
3284                         memset(buf, 0, strlen(buf));
3285                         g_free(buf);
3286                 }
3287         }
3288
3289         page->vbox = vbox1;
3290
3291         page->page.widget = vbox1;
3292 }
3293
3294 static void advanced_create_widget_func(PrefsPage * _page,
3295                                            GtkWindow * window,
3296                                            gpointer data)
3297 {
3298         AdvancedPage *page = (AdvancedPage *) _page;
3299         PrefsAccount *ac_prefs = (PrefsAccount *) data;
3300
3301         GtkWidget *vbox1;
3302         GtkWidget *vbox2;
3303         GtkWidget *hbox1;
3304         GtkWidget *checkbtn_smtpport;
3305         GtkWidget *spinbtn_smtpport;
3306         GtkWidget *hbox_popport;
3307         GtkWidget *checkbtn_popport;
3308         GtkWidget *spinbtn_popport;
3309         GtkWidget *hbox_imapport;
3310         GtkWidget *checkbtn_imapport;
3311         GtkWidget *spinbtn_imapport;
3312         GtkWidget *hbox_nntpport;
3313         GtkWidget *checkbtn_nntpport;
3314         GtkWidget *spinbtn_nntpport;
3315         GtkWidget *checkbtn_domain;
3316         GtkWidget *entry_domain;
3317         gchar *tip_domain;
3318         GtkWidget *checkbtn_crosspost;
3319         GtkWidget *colormenu_crosspost;
3320 #ifndef G_OS_WIN32
3321         GtkWidget *checkbtn_tunnelcmd;
3322         GtkWidget *entry_tunnelcmd;
3323 #endif
3324         GtkWidget *folder_frame;
3325         GtkWidget *vbox3;
3326         GtkWidget *table;
3327         GtkWidget *sent_folder_checkbtn;
3328         GtkWidget *sent_folder_entry;
3329         GtkWidget *queue_folder_checkbtn;
3330         GtkWidget *queue_folder_entry;
3331         GtkWidget *draft_folder_checkbtn;
3332         GtkWidget *draft_folder_entry;
3333         GtkWidget *trash_folder_checkbtn;
3334         GtkWidget *trash_folder_entry;
3335         GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3336
3337 #define PACK_HBOX(hbox) \
3338         { \
3339         hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); \
3340         gtk_widget_show (hbox); \
3341         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
3342         }
3343
3344 #define PACK_PORT_SPINBTN(box, spinbtn) \
3345         { \
3346         spinbtn = gtk_spin_button_new_with_range(0, 65535, 1); \
3347         gtk_widget_show (spinbtn); \
3348         gtk_box_pack_start (GTK_BOX (box), spinbtn, FALSE, FALSE, 0); \
3349         }
3350
3351         vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
3352         gtk_widget_show (vbox1);
3353         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
3354
3355         vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW_2);
3356         gtk_widget_show (vbox2);
3357         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
3358
3359         PACK_HBOX (hbox1);
3360         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("SMTP port"));
3361         PACK_PORT_SPINBTN (hbox1, spinbtn_smtpport);
3362         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, spinbtn_smtpport);
3363         gtk_size_group_add_widget(size_group, checkbtn_smtpport);
3364         
3365         PACK_HBOX (hbox_popport);
3366         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
3367                            _("POP port"));
3368         PACK_PORT_SPINBTN (hbox_popport, spinbtn_popport);
3369         SET_TOGGLE_SENSITIVITY (checkbtn_popport, spinbtn_popport);
3370         gtk_size_group_add_widget(size_group, checkbtn_popport);
3371
3372         PACK_HBOX (hbox_imapport);
3373         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
3374                            _("IMAP port"));
3375         PACK_PORT_SPINBTN (hbox_imapport, spinbtn_imapport);
3376         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, spinbtn_imapport);
3377         gtk_size_group_add_widget(size_group, checkbtn_imapport);
3378
3379         PACK_HBOX (hbox_nntpport);
3380         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
3381                            _("NNTP port"));
3382         PACK_PORT_SPINBTN (hbox_nntpport, spinbtn_nntpport);
3383         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, spinbtn_nntpport);
3384         gtk_size_group_add_widget(size_group, checkbtn_nntpport);
3385
3386         PACK_HBOX (hbox1);
3387         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Domain name"));
3388         gtk_size_group_add_widget(size_group, checkbtn_domain); 
3389
3390         tip_domain = _("The domain name will be used in the generated "
3391                         "Message-ID, and when connecting to SMTP servers.");
3392
3393         CLAWS_SET_TIP(checkbtn_domain, tip_domain);
3394
3395         entry_domain = gtk_entry_new ();
3396         gtk_widget_show (entry_domain);
3397         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
3398         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
3399         CLAWS_SET_TIP(entry_domain, tip_domain);
3400
3401 #ifndef G_OS_WIN32      
3402         PACK_HBOX (hbox1);
3403         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
3404                            _("Use command to communicate with server"));
3405         entry_tunnelcmd = gtk_entry_new ();
3406         gtk_widget_show (entry_tunnelcmd);
3407         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
3408         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
3409 #endif
3410
3411         PACK_HBOX (hbox1);
3412         PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost, 
3413                            _("Mark cross-posted messages as read and color:"));
3414         g_signal_connect (G_OBJECT (checkbtn_crosspost), "toggled",
3415                           G_CALLBACK (crosspost_color_toggled),
3416                           NULL);
3417
3418         colormenu_crosspost = colorlabel_create_combobox_colormenu();
3419         gtk_widget_show (colormenu_crosspost);
3420         gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
3421
3422         SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
3423 #undef PACK_HBOX
3424 #undef PACK_PORT_SPINBTN
3425
3426         /* special folder setting (maybe these options are redundant) */
3427
3428         vbox3 = gtkut_get_options_frame(vbox1, &folder_frame, _("Folder"));
3429
3430         table = gtk_grid_new();
3431         gtk_widget_show (table);
3432         gtk_container_add (GTK_CONTAINER (vbox3), table);
3433         gtk_grid_set_row_spacing(GTK_GRID(table), VSPACING_NARROW_2);
3434         gtk_grid_set_column_spacing(GTK_GRID(table), 4);
3435
3436 #define SET_CHECK_BTN_AND_ENTRY(label, checkbtn, entry, n)              \
3437 {                                                                       \
3438         GtkWidget *button;                                              \
3439                                                                         \
3440         checkbtn = gtk_check_button_new_with_label (label);             \
3441         gtk_widget_show (checkbtn);                                     \
3442         gtk_grid_attach(GTK_GRID(table), checkbtn, 0, n, 1, 1);         \
3443                                                                         \
3444         entry = gtk_entry_new ();                                       \
3445         gtk_widget_show (entry);                                        \
3446         gtk_grid_attach(GTK_GRID(table), entry, 1, n, 1, 1);            \
3447         gtk_widget_set_hexpand(entry, TRUE);                            \
3448         gtk_widget_set_halign(entry, GTK_ALIGN_FILL);                   \
3449                                                                         \
3450         button = gtkut_get_browse_file_btn(_("Browse"));                \
3451         gtk_widget_show (button);                                       \
3452         gtk_grid_attach(GTK_GRID(table), button, 2, n, 1, 1);           \
3453         g_signal_connect                                                \
3454                 (G_OBJECT (button), "clicked",                          \
3455                  G_CALLBACK (prefs_account_select_folder_cb),           \
3456                  entry);                                                \
3457                                                                         \
3458         SET_TOGGLE_SENSITIVITY (checkbtn, entry);                       \
3459         SET_TOGGLE_SENSITIVITY (checkbtn, button);                      \
3460 }
3461
3462         SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
3463                                 sent_folder_checkbtn, sent_folder_entry, 0);
3464         SET_CHECK_BTN_AND_ENTRY(_("Put queued messages in"),
3465                                 queue_folder_checkbtn, queue_folder_entry, 1);
3466         SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
3467                                 draft_folder_checkbtn, draft_folder_entry, 2);
3468         SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
3469                                 trash_folder_checkbtn, trash_folder_entry, 3);
3470
3471         page->smtpport_checkbtn = checkbtn_smtpport;
3472         page->smtpport_spinbtn          = spinbtn_smtpport;
3473         page->popport_hbox              = hbox_popport;
3474         page->popport_checkbtn          = checkbtn_popport;
3475         page->popport_spinbtn           = spinbtn_popport;
3476         page->imapport_hbox             = hbox_imapport;
3477         page->imapport_checkbtn = checkbtn_imapport;
3478         page->imapport_spinbtn          = spinbtn_imapport;
3479         page->nntpport_hbox             = hbox_nntpport;
3480         page->nntpport_checkbtn = checkbtn_nntpport;
3481         page->nntpport_spinbtn          = spinbtn_nntpport;
3482         page->domain_checkbtn           = checkbtn_domain;
3483         page->domain_entry              = entry_domain;
3484         page->crosspost_checkbtn        = checkbtn_crosspost;
3485         page->crosspost_colormenu       = colormenu_crosspost;
3486
3487 #ifndef G_OS_WIN32
3488         page->tunnelcmd_checkbtn        = checkbtn_tunnelcmd;
3489         page->tunnelcmd_entry   = entry_tunnelcmd;
3490 #endif
3491         page->sent_folder_checkbtn  = sent_folder_checkbtn;
3492         page->sent_folder_entry   = sent_folder_entry;
3493         page->queue_folder_checkbtn  = queue_folder_checkbtn;
3494         page->queue_folder_entry   = queue_folder_entry;