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