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