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