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