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