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