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