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