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