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