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