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