330f258429eb97eeaa4b7d87622304207fe88d3d
[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 Claws Mail team
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <glib/gi18n.h>
28 #include <gtk/gtk.h>
29 #include <gdk/gdkkeysyms.h>
30 #include <gtk/filesel.h>
31 #include <stdio.h>
32 #include <sys/types.h>
33 #include <sys/stat.h>
34 #include <string.h>
35 #include <stdlib.h>
36 #include <ctype.h>
37
38 #include "main.h"
39 #include "prefs_gtk.h"
40 #include "prefs_account.h"
41 #include "prefs_common.h"
42 #include "prefs_customheader.h"
43 #include "account.h"
44 #include "mainwindow.h"
45 #include "manage_window.h"
46 #include "foldersel.h"
47 #include "inc.h"
48 #include "menu.h"
49 #include "gtkutils.h"
50 #include "utils.h"
51 #include "alertpanel.h"
52 #include "colorlabel.h"
53 #include "smtp.h"
54 #include "imap.h"
55 #include "remotefolder.h"
56 #include "base64.h"
57 #include "combobox.h"
58
59 static gboolean cancelled;
60 static gboolean new_account;
61
62 static PrefsAccount tmp_ac_prefs;
63
64 static GtkWidget *notebook;
65 static GtkWidget *sigfile_radiobtn;
66 static GtkWidget *sigcmd_radiobtn;
67 static GtkWidget *entry_sigpath;
68 static GtkWidget *signature_browse_button;
69 static GtkWidget *signature_edit_button;
70
71 static GSList *prefs_pages = NULL;
72
73 struct BasicProtocol {
74         GtkWidget *combobox;
75         GtkWidget *label;
76         GtkWidget *descrlabel;
77         GtkWidget *no_imap_warn_icon;
78         GtkWidget *no_imap_warn_label;
79 };
80
81 static struct Basic {
82         GtkWidget *acname_entry;
83         GtkWidget *default_chkbtn;
84
85         GtkWidget *name_entry;
86         GtkWidget *addr_entry;
87         GtkWidget *org_entry;
88
89         GtkWidget *serv_frame;
90         GtkWidget *serv_table;
91         gpointer *protocol_optmenu;
92         GtkWidget *recvserv_label;
93         GtkWidget *smtpserv_label;
94         GtkWidget *nntpserv_label;
95         GtkWidget *localmbox_label;
96         GtkWidget *mailcmd_label;
97         GtkWidget *recvserv_entry;
98         GtkWidget *smtpserv_entry;
99         GtkWidget *nntpserv_entry;
100         GtkWidget *nntpauth_chkbtn;
101         GtkWidget *nntpauth_onconnect_chkbtn;
102         GtkWidget *localmbox_entry;
103         GtkWidget *mailcmd_chkbtn;
104         GtkWidget *mailcmd_entry;
105         GtkWidget *uid_label;
106         GtkWidget *pass_label;
107         GtkWidget *uid_entry;
108         GtkWidget *pass_entry;
109 } basic;
110
111 static struct Receive {
112         GtkWidget *pop3_frame;
113         GtkWidget *use_apop_chkbtn;
114         GtkWidget *rmmail_chkbtn;
115         GtkWidget *leave_time_entry;
116         GtkWidget *getall_chkbtn;
117         GtkWidget *size_limit_chkbtn;
118         GtkWidget *size_limit_entry;
119         GtkWidget *inbox_label;
120         GtkWidget *inbox_entry;
121         GtkWidget *inbox_btn;
122
123         GtkWidget *local_frame;
124         GtkWidget *local_inbox_label;
125         GtkWidget *local_inbox_entry;
126         GtkWidget *local_inbox_btn;
127
128         GtkWidget *filter_on_recv_chkbtn;
129         GtkWidget *recvatgetall_chkbtn;
130         
131         GtkWidget *imap_frame;
132         GtkWidget *imap_auth_type_optmenu;
133         GtkWidget *imapdir_label;
134         GtkWidget *imapdir_entry;
135
136         GtkWidget *frame_maxarticle;
137         GtkWidget *maxarticle_label;
138         GtkWidget *maxarticle_spinbtn;
139         GtkObject *maxarticle_spinbtn_adj;
140 } receive;
141
142 static struct Send {
143         GtkWidget *msgid_chkbtn;
144         GtkWidget *customhdr_chkbtn;
145         GtkWidget *smtp_auth_chkbtn;
146         GtkWidget *smtp_auth_type_optmenu;
147         GtkWidget *smtp_uid_entry;
148         GtkWidget *smtp_pass_entry;
149         GtkWidget *pop_bfr_smtp_chkbtn;
150         GtkWidget *pop_bfr_smtp_tm_entry;
151         GtkWidget *pop_auth_timeout_lbl;
152         GtkWidget *pop_auth_minutes_lbl;
153 } p_send;
154
155 static struct Compose {
156         GtkWidget *sigfile_radiobtn;
157         GtkWidget *entry_sigpath;
158         GtkWidget *checkbtn_autosig;
159         GtkWidget *entry_sigsep;
160         GtkWidget *autocc_chkbtn;
161         GtkWidget *autocc_entry;
162         GtkWidget *autobcc_chkbtn;
163         GtkWidget *autobcc_entry;
164         GtkWidget *autoreplyto_chkbtn;
165         GtkWidget *autoreplyto_entry;
166 } 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 Claws Mail\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         MENUITEM_ADD (optmenu_menu, menuitem, "GSSAPI", IMAP_AUTH_GSSAPI);
1606
1607         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1608
1609         hbox1 = gtk_hbox_new (FALSE, 8);
1610         gtk_widget_show (hbox1);
1611         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1612
1613         imapdir_label = gtk_label_new (_("IMAP server directory"));
1614         gtk_widget_show (imapdir_label);
1615         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1616
1617         imapdir_label = gtk_label_new(_("(usually empty)"));
1618         gtk_widget_show (imapdir_label);
1619         gtkut_widget_set_small_font_size (imapdir_label);
1620         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1621
1622         imapdir_entry = gtk_entry_new();
1623         gtk_widget_show (imapdir_entry);
1624         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, FALSE, FALSE, 0);
1625
1626         PACK_CHECK_BUTTON (vbox1, filter_on_recv_chkbtn,
1627                            _("Filter messages on receiving"));
1628
1629         PACK_CHECK_BUTTON
1630                 (vbox1, recvatgetall_chkbtn,
1631                  _("'Get Mail' checks for new messages on this account"));
1632
1633         receive.pop3_frame               = frame1;
1634         receive.use_apop_chkbtn          = use_apop_chkbtn;
1635         receive.rmmail_chkbtn            = rmmail_chkbtn;
1636         receive.leave_time_entry         = leave_time_entry;
1637         receive.getall_chkbtn            = getall_chkbtn;
1638         receive.size_limit_chkbtn        = size_limit_chkbtn;
1639         receive.size_limit_entry         = size_limit_entry;
1640         receive.filter_on_recv_chkbtn    = filter_on_recv_chkbtn;
1641         receive.inbox_label              = inbox_label;
1642         receive.inbox_entry              = inbox_entry;
1643         receive.inbox_btn                = inbox_btn;
1644
1645         receive.imap_frame               = imap_frame;
1646         receive.imap_auth_type_optmenu   = optmenu;
1647
1648         receive.imapdir_label           = imapdir_label;
1649         receive.imapdir_entry           = imapdir_entry;
1650
1651         receive.local_frame             = local_frame;
1652         receive.local_inbox_label       = local_inbox_label;
1653         receive.local_inbox_entry       = local_inbox_entry;
1654         receive.local_inbox_btn         = local_inbox_btn;
1655
1656         receive.recvatgetall_chkbtn      = recvatgetall_chkbtn;
1657
1658         receive.frame_maxarticle        = frame2;
1659         receive.maxarticle_spinbtn      = maxarticle_spinbtn;
1660         receive.maxarticle_spinbtn_adj  = maxarticle_spinbtn_adj;
1661 }
1662
1663 static void prefs_account_send_create(void)
1664 {
1665         GtkWidget *vbox1;
1666         GtkWidget *vbox2;
1667         GtkWidget *frame;
1668         GtkWidget *msgid_chkbtn;
1669         GtkWidget *hbox;
1670         GtkWidget *customhdr_chkbtn;
1671         GtkWidget *customhdr_edit_btn;
1672         GtkWidget *vbox3;
1673         GtkWidget *smtp_auth_chkbtn;
1674         GtkWidget *optmenu;
1675         GtkWidget *optmenu_menu;
1676         GtkWidget *menuitem;
1677         GtkWidget *vbox4;
1678         GtkWidget *hbox_spc;
1679         GtkWidget *label;
1680         GtkWidget *smtp_uid_entry;
1681         GtkWidget *smtp_pass_entry;
1682         GtkWidget *vbox_spc;
1683         GtkWidget *pop_bfr_smtp_chkbtn;
1684         GtkWidget *pop_bfr_smtp_tm_entry;
1685         GtkWidget *pop_auth_timeout_lbl;
1686         GtkWidget *pop_auth_minutes_lbl;
1687
1688         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1689         gtk_widget_show (vbox1);
1690         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1691         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1692
1693         PACK_FRAME (vbox1, frame, _("Header"));
1694
1695         vbox2 = gtk_vbox_new (FALSE, 0);
1696         gtk_widget_show (vbox2);
1697         gtk_container_add (GTK_CONTAINER (frame), vbox2);
1698         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1699
1700         PACK_CHECK_BUTTON (vbox2, msgid_chkbtn, _("Generate Message-ID"));
1701
1702         hbox = gtk_hbox_new (FALSE, 12);
1703         gtk_widget_show (hbox);
1704         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1705
1706         PACK_CHECK_BUTTON (hbox, customhdr_chkbtn,
1707                            _("Add user-defined header"));
1708
1709         customhdr_edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT);
1710         gtk_widget_show (customhdr_edit_btn);
1711         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1712                             FALSE, FALSE, 0);
1713         g_signal_connect (G_OBJECT (customhdr_edit_btn), "clicked",
1714                           G_CALLBACK (prefs_account_edit_custom_header),
1715                           NULL);
1716
1717         SET_TOGGLE_SENSITIVITY (customhdr_chkbtn, customhdr_edit_btn);
1718
1719         PACK_FRAME (vbox1, frame, _("Authentication"));
1720
1721         vbox3 = gtk_vbox_new (FALSE, 0);
1722         gtk_widget_show (vbox3);
1723         gtk_container_add (GTK_CONTAINER (frame), vbox3);
1724         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1725
1726         PACK_CHECK_BUTTON (vbox3, smtp_auth_chkbtn,
1727                 _("SMTP Authentication (SMTP AUTH)"));
1728
1729         vbox4 = gtk_vbox_new (FALSE, 0);
1730         gtk_widget_show (vbox4);
1731         gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
1732
1733         hbox = gtk_hbox_new (FALSE, 8);
1734         gtk_widget_show (hbox);
1735         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1736
1737         hbox_spc = gtk_hbox_new (FALSE, 0);
1738         gtk_widget_show (hbox_spc);
1739         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1740         gtk_widget_set_size_request (hbox_spc, 12, -1);
1741
1742         label = gtk_label_new (_("Authentication method"));
1743         gtk_widget_show (label);
1744         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1745
1746         optmenu = gtk_option_menu_new ();
1747         gtk_widget_show (optmenu);
1748         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
1749
1750         optmenu_menu = gtk_menu_new ();
1751
1752         MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
1753         MENUITEM_ADD (optmenu_menu, menuitem, "PLAIN", SMTPAUTH_PLAIN);
1754         MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", SMTPAUTH_LOGIN);
1755         MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
1756         MENUITEM_ADD (optmenu_menu, menuitem, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
1757         gtk_widget_set_sensitive (menuitem, FALSE);
1758
1759         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1760
1761         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1762
1763         hbox = gtk_hbox_new (FALSE, 8);
1764         gtk_widget_show (hbox);
1765         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1766
1767         hbox_spc = gtk_hbox_new (FALSE, 0);
1768         gtk_widget_show (hbox_spc);
1769         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1770         gtk_widget_set_size_request (hbox_spc, 12, -1);
1771
1772         label = gtk_label_new (_("User ID"));
1773         gtk_widget_show (label);
1774         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1775
1776         smtp_uid_entry = gtk_entry_new ();
1777         gtk_widget_show (smtp_uid_entry);
1778         gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1779         gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
1780
1781         label = gtk_label_new (_("Password"));
1782         gtk_widget_show (label);
1783         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1784
1785         smtp_pass_entry = gtk_entry_new ();
1786         gtk_widget_show (smtp_pass_entry);
1787         gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1788         gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
1789         gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
1790
1791         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1792
1793         hbox = gtk_hbox_new (FALSE, 8);
1794         gtk_widget_show (hbox);
1795         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1796
1797         hbox_spc = gtk_hbox_new (FALSE, 0);
1798         gtk_widget_show (hbox_spc);
1799         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1800         gtk_widget_set_size_request (hbox_spc, 12, -1);
1801
1802         label = gtk_label_new
1803                 (_("If you leave these entries empty, the same "
1804                    "user ID and password as receiving will be used."));
1805         gtk_widget_show (label);
1806         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1807         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1808         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1809         gtkut_widget_set_small_font_size (label);
1810
1811         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, vbox4);
1812
1813         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_chkbtn,
1814                 _("Authenticate with POP3 before sending"));
1815         
1816         g_signal_connect (G_OBJECT (pop_bfr_smtp_chkbtn), "clicked",
1817                           G_CALLBACK (pop_bfr_smtp_tm_set_sens),
1818                           NULL);
1819
1820         hbox = gtk_hbox_new (FALSE, 8);
1821         gtk_widget_show (hbox);
1822         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
1823
1824         hbox_spc = gtk_hbox_new (FALSE, 0);
1825         gtk_widget_show (hbox_spc);
1826         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1827         gtk_widget_set_size_request (hbox_spc, 12, -1);
1828
1829         pop_auth_timeout_lbl = gtk_label_new(_("POP authentication timeout: "));
1830         gtk_widget_show (pop_auth_timeout_lbl);
1831         gtk_box_pack_start (GTK_BOX (hbox), pop_auth_timeout_lbl, FALSE, FALSE, 0);
1832
1833         pop_bfr_smtp_tm_entry = gtk_entry_new ();
1834         gtk_widget_show (pop_bfr_smtp_tm_entry);
1835         gtk_widget_set_size_request (pop_bfr_smtp_tm_entry, 30, -1);
1836         gtk_box_pack_start (GTK_BOX (hbox), pop_bfr_smtp_tm_entry, FALSE, FALSE, 0);
1837
1838         pop_auth_minutes_lbl = gtk_label_new(_("minutes"));
1839         gtk_widget_show (pop_auth_minutes_lbl);
1840         gtk_box_pack_start (GTK_BOX (hbox), pop_auth_minutes_lbl, FALSE, FALSE, 0);
1841
1842
1843         
1844         p_send.msgid_chkbtn     = msgid_chkbtn;
1845         p_send.customhdr_chkbtn = customhdr_chkbtn;
1846
1847         p_send.smtp_auth_chkbtn       = smtp_auth_chkbtn;
1848         p_send.smtp_auth_type_optmenu = optmenu;
1849         p_send.smtp_uid_entry         = smtp_uid_entry;
1850         p_send.smtp_pass_entry        = smtp_pass_entry;
1851         p_send.pop_bfr_smtp_chkbtn    = pop_bfr_smtp_chkbtn;
1852         p_send.pop_bfr_smtp_tm_entry  = pop_bfr_smtp_tm_entry;
1853         p_send.pop_auth_timeout_lbl   = pop_auth_timeout_lbl;
1854         p_send.pop_auth_minutes_lbl   = pop_auth_minutes_lbl;
1855 }
1856
1857 static void prefs_account_compose_create(void)
1858 {
1859         GtkWidget *vbox1;
1860         GtkWidget *sig_hbox;
1861         GtkWidget *hbox1;
1862         GtkWidget *hbox2;
1863         GtkWidget *frame_sig;
1864         GtkWidget *vbox_sig;
1865         GtkWidget *label_sigpath;
1866         GtkWidget *checkbtn_autosig;
1867         GtkWidget *label_sigsep;
1868         GtkWidget *entry_sigsep;
1869         GtkWidget *frame;
1870         GtkWidget *table;
1871         GtkWidget *autocc_chkbtn;
1872         GtkWidget *autocc_entry;
1873         GtkWidget *autobcc_chkbtn;
1874         GtkWidget *autobcc_entry;
1875         GtkWidget *autoreplyto_chkbtn;
1876         GtkWidget *autoreplyto_entry;
1877
1878         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1879         gtk_widget_show (vbox1);
1880         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1881         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1882
1883         PACK_FRAME(vbox1, frame_sig, _("Signature"));
1884
1885         vbox_sig = gtk_vbox_new (FALSE, VSPACING_NARROW);
1886         gtk_widget_show (vbox_sig);
1887         gtk_container_add (GTK_CONTAINER (frame_sig), vbox_sig);
1888         gtk_container_set_border_width (GTK_CONTAINER (vbox_sig), 8);
1889
1890         PACK_CHECK_BUTTON (vbox_sig, checkbtn_autosig,
1891                            _("Insert signature automatically"));
1892
1893         hbox1 = gtk_hbox_new (FALSE, 8);
1894         gtk_widget_show (hbox1);
1895         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox1, TRUE, TRUE, 0);
1896         label_sigsep = gtk_label_new (_("Signature separator"));
1897         gtk_widget_show (label_sigsep);
1898         gtk_box_pack_start (GTK_BOX (hbox1), label_sigsep, FALSE, FALSE, 0);
1899
1900         entry_sigsep = gtk_entry_new ();
1901         gtk_widget_show (entry_sigsep);
1902         gtk_box_pack_start (GTK_BOX (hbox1), entry_sigsep, FALSE, FALSE, 0);
1903
1904         gtk_widget_set_size_request (entry_sigsep, 64, -1);
1905
1906         sig_hbox = gtk_hbox_new (FALSE, 8);
1907         gtk_widget_show (sig_hbox);
1908         gtk_box_pack_start (GTK_BOX (vbox_sig), sig_hbox, FALSE, FALSE, 0);
1909
1910         sigfile_radiobtn = gtk_radio_button_new_with_label (NULL, _("File"));
1911         gtk_widget_show (sigfile_radiobtn);
1912         gtk_box_pack_start (GTK_BOX (sig_hbox), sigfile_radiobtn,
1913                             FALSE, FALSE, 0);
1914         g_object_set_data (G_OBJECT (sigfile_radiobtn),
1915                            MENU_VAL_ID,
1916                            GINT_TO_POINTER (SIG_FILE));
1917         g_signal_connect(G_OBJECT(sigfile_radiobtn), "clicked",
1918                          G_CALLBACK(prefs_account_sigfile_radiobtn_cb), NULL);
1919
1920         sigcmd_radiobtn = gtk_radio_button_new_with_label_from_widget
1921                 (GTK_RADIO_BUTTON(sigfile_radiobtn), _("Command output"));
1922         gtk_widget_show (sigcmd_radiobtn);
1923         gtk_box_pack_start (GTK_BOX (sig_hbox), sigcmd_radiobtn,
1924                             FALSE, FALSE, 0);
1925         g_object_set_data (G_OBJECT (sigcmd_radiobtn),
1926                            MENU_VAL_ID,
1927                            GINT_TO_POINTER (SIG_COMMAND));
1928         g_signal_connect(G_OBJECT(sigcmd_radiobtn), "clicked",
1929                          G_CALLBACK(prefs_account_sigcmd_radiobtn_cb), NULL);
1930
1931         hbox2 = gtk_hbox_new (FALSE, 8);
1932         gtk_widget_show (hbox2);
1933         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox2, TRUE, TRUE, 0);
1934         label_sigpath = gtk_label_new (_("Signature"));
1935         gtk_widget_show (label_sigpath);
1936         gtk_box_pack_start (GTK_BOX (hbox2), label_sigpath, FALSE, FALSE, 0);
1937
1938         entry_sigpath = gtk_entry_new ();
1939         gtk_widget_show (entry_sigpath);
1940         gtk_box_pack_start (GTK_BOX (hbox2), entry_sigpath, TRUE, TRUE, 0);
1941
1942         signature_browse_button = gtkut_get_browse_file_btn(_("Bro_wse"));
1943         gtk_widget_show (signature_browse_button);
1944         gtk_box_pack_start (GTK_BOX (hbox2), signature_browse_button, FALSE, FALSE, 0);
1945         g_signal_connect(G_OBJECT(signature_browse_button), "clicked",
1946                          G_CALLBACK(prefs_account_signature_browse_cb), NULL);
1947
1948         signature_edit_button = gtk_button_new_from_stock (GTK_STOCK_EDIT);
1949         gtk_widget_show (signature_edit_button);
1950         gtk_box_pack_start (GTK_BOX (hbox2), signature_edit_button, FALSE, FALSE, 0);
1951         g_signal_connect(G_OBJECT(signature_edit_button), "clicked",
1952                          G_CALLBACK(prefs_account_signature_edit_cb), entry_sigpath);
1953
1954         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
1955
1956         table =  gtk_table_new (3, 2, FALSE);
1957         gtk_widget_show (table);
1958         gtk_container_add (GTK_CONTAINER (frame), table);
1959         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
1960         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
1961         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1962
1963         autocc_chkbtn = gtk_check_button_new_with_label (_("Cc"));
1964         gtk_widget_show (autocc_chkbtn);
1965         gtk_table_attach (GTK_TABLE (table), autocc_chkbtn, 0, 1, 0, 1,
1966                           GTK_FILL, 0, 0, 0);
1967
1968         autocc_entry = gtk_entry_new ();
1969         gtk_widget_show (autocc_entry);
1970         gtk_table_attach (GTK_TABLE (table), autocc_entry, 1, 2, 0, 1,
1971                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1972                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1973
1974         SET_TOGGLE_SENSITIVITY (autocc_chkbtn, autocc_entry);
1975
1976         autobcc_chkbtn = gtk_check_button_new_with_label (_("Bcc"));
1977         gtk_widget_show (autobcc_chkbtn);
1978         gtk_table_attach (GTK_TABLE (table), autobcc_chkbtn, 0, 1, 1, 2,
1979                           GTK_FILL, 0, 0, 0);
1980
1981         autobcc_entry = gtk_entry_new ();
1982         gtk_widget_show (autobcc_entry);
1983         gtk_table_attach (GTK_TABLE (table), autobcc_entry, 1, 2, 1, 2,
1984                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1985                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1986
1987         SET_TOGGLE_SENSITIVITY (autobcc_chkbtn, autobcc_entry);
1988
1989         autoreplyto_chkbtn = gtk_check_button_new_with_label (_("Reply-To"));
1990         gtk_widget_show (autoreplyto_chkbtn);
1991         gtk_table_attach (GTK_TABLE (table), autoreplyto_chkbtn, 0, 1, 2, 3,
1992                           GTK_FILL, 0, 0, 0);
1993
1994         autoreplyto_entry = gtk_entry_new ();
1995         gtk_widget_show (autoreplyto_entry);
1996         gtk_table_attach (GTK_TABLE (table), autoreplyto_entry, 1, 2, 2, 3,
1997                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1998                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1999
2000         SET_TOGGLE_SENSITIVITY (autoreplyto_chkbtn, autoreplyto_entry);
2001
2002         compose.sigfile_radiobtn = sigfile_radiobtn;
2003         compose.entry_sigpath      = entry_sigpath;
2004         compose.checkbtn_autosig   = checkbtn_autosig;
2005         compose.entry_sigsep       = entry_sigsep;
2006
2007         compose.autocc_chkbtn      = autocc_chkbtn;
2008         compose.autocc_entry       = autocc_entry;
2009         compose.autobcc_chkbtn     = autobcc_chkbtn;
2010         compose.autobcc_entry      = autobcc_entry;
2011         compose.autoreplyto_chkbtn = autoreplyto_chkbtn;
2012         compose.autoreplyto_entry  = autoreplyto_entry;
2013 }
2014
2015 static void prefs_account_privacy_create(void)
2016 {
2017         GtkWidget *vbox1;
2018         GtkWidget *vbox2;
2019         GtkWidget *hbox1;
2020         GtkWidget *label;
2021         GtkWidget *default_privacy_system;
2022         GtkWidget *default_encrypt_chkbtn;
2023         GtkWidget *default_encrypt_reply_chkbtn;
2024         GtkWidget *default_sign_chkbtn;
2025         GtkWidget *save_clear_text_chkbtn;
2026         GtkWidget *encrypt_to_self_chkbtn;
2027
2028         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2029         gtk_widget_show (vbox1);
2030         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
2031         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2032
2033         vbox2 = gtk_vbox_new (FALSE, 0);
2034         gtk_widget_show (vbox2);
2035         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2036
2037         hbox1 = gtk_hbox_new(FALSE, 8);
2038         gtk_widget_show (hbox1);
2039         gtk_container_add (GTK_CONTAINER(vbox2), hbox1);
2040
2041         label = gtk_label_new(_("Default privacy system"));
2042         gtk_widget_show(label);
2043         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
2044
2045         default_privacy_system = gtk_option_menu_new();
2046         gtk_widget_show (default_privacy_system);
2047         gtk_box_pack_start (GTK_BOX(hbox1), default_privacy_system, FALSE, TRUE, 0);
2048
2049         PACK_CHECK_BUTTON (vbox2, default_sign_chkbtn,
2050                            _("Always sign messages"));
2051         PACK_CHECK_BUTTON (vbox2, default_encrypt_chkbtn,
2052                            _("Always encrypt messages"));
2053         PACK_CHECK_BUTTON (vbox2, default_encrypt_reply_chkbtn,
2054                            _("Always encrypt messages when replying to an "
2055                              "encrypted message"));
2056         PACK_CHECK_BUTTON (vbox2, encrypt_to_self_chkbtn,
2057                            _("Encrypt sent messages with your own key in addition to recipient's"));
2058         PACK_CHECK_BUTTON (vbox2, save_clear_text_chkbtn,
2059                            _("Save sent encrypted messages as clear text"));
2060
2061         SET_TOGGLE_SENSITIVITY_REVERSE(encrypt_to_self_chkbtn, save_clear_text_chkbtn);
2062
2063         privacy.default_privacy_system = default_privacy_system;
2064         privacy.default_encrypt_chkbtn = default_encrypt_chkbtn;
2065         privacy.default_encrypt_reply_chkbtn = default_encrypt_reply_chkbtn;
2066         privacy.default_sign_chkbtn    = default_sign_chkbtn;
2067         privacy.save_clear_text_chkbtn = save_clear_text_chkbtn;
2068         privacy.encrypt_to_self_chkbtn = encrypt_to_self_chkbtn;
2069 }
2070
2071 #if USE_OPENSSL
2072
2073 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data)               \
2074 {                                                                       \
2075         btn = gtk_radio_button_new_with_label_from_widget               \
2076                 (GTK_RADIO_BUTTON (btn_p), label);                      \
2077         gtk_widget_show (btn);                                          \
2078         gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0);       \
2079         g_object_set_data (G_OBJECT (btn),                              \
2080                            MENU_VAL_ID,                                 \
2081                            GINT_TO_POINTER (data));                     \
2082 }
2083
2084 #define CREATE_RADIO_BUTTONS(box,                                       \
2085                              btn1, btn1_label, btn1_data,               \
2086                              btn2, btn2_label, btn2_data,               \
2087                              btn3, btn3_label, btn3_data)               \
2088 {                                                                       \
2089         btn1 = gtk_radio_button_new_with_label(NULL, btn1_label);       \
2090         gtk_widget_show (btn1);                                         \
2091         gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0);      \
2092         g_object_set_data (G_OBJECT (btn1),                             \
2093                            MENU_VAL_ID,                                 \
2094                            GINT_TO_POINTER (btn1_data));                \
2095                                                                         \
2096         CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data);    \
2097         CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data);    \
2098 }
2099
2100 static void prefs_account_ssl_create(void)
2101 {
2102         GtkWidget *vbox1;
2103
2104         GtkWidget *pop_frame;
2105         GtkWidget *vbox2;
2106         GtkWidget *pop_nossl_radiobtn;
2107         GtkWidget *pop_ssltunnel_radiobtn;
2108         GtkWidget *pop_starttls_radiobtn;
2109
2110         GtkWidget *imap_frame;
2111         GtkWidget *vbox3;
2112         GtkWidget *imap_nossl_radiobtn;
2113         GtkWidget *imap_ssltunnel_radiobtn;
2114         GtkWidget *imap_starttls_radiobtn;
2115
2116         GtkWidget *nntp_frame;
2117         GtkWidget *vbox4;
2118         GtkWidget *nntp_nossl_radiobtn;
2119         GtkWidget *nntp_ssltunnel_radiobtn;
2120
2121         GtkWidget *send_frame;
2122         GtkWidget *vbox5;
2123         GtkWidget *smtp_nossl_radiobtn;
2124         GtkWidget *smtp_ssltunnel_radiobtn;
2125         GtkWidget *smtp_starttls_radiobtn;
2126
2127         GtkWidget *vbox6;
2128         GtkWidget *use_nonblocking_ssl_chkbtn;
2129         GtkWidget *hbox;
2130         GtkWidget *hbox_spc;
2131         GtkWidget *label;
2132
2133         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2134         gtk_widget_show (vbox1);
2135         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
2136         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2137
2138         PACK_FRAME (vbox1, pop_frame, _("POP3"));
2139         vbox2 = gtk_vbox_new (FALSE, 0);
2140         gtk_widget_show (vbox2);
2141         gtk_container_add (GTK_CONTAINER (pop_frame), vbox2);
2142         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
2143
2144         CREATE_RADIO_BUTTONS(vbox2,
2145                              pop_nossl_radiobtn,
2146                              _("Don't use SSL"),
2147                              SSL_NONE,
2148                              pop_ssltunnel_radiobtn,
2149                              _("Use SSL for POP3 connection"),
2150                              SSL_TUNNEL,
2151                              pop_starttls_radiobtn,
2152                              _("Use STARTTLS command to start SSL session"),
2153                              SSL_STARTTLS);
2154
2155         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
2156         vbox3 = gtk_vbox_new (FALSE, 0);
2157         gtk_widget_show (vbox3);
2158         gtk_container_add (GTK_CONTAINER (imap_frame), vbox3);
2159         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
2160
2161         CREATE_RADIO_BUTTONS(vbox3,
2162                              imap_nossl_radiobtn,
2163                              _("Don't use SSL"),
2164                              SSL_NONE,
2165                              imap_ssltunnel_radiobtn,
2166                              _("Use SSL for IMAP4 connection"),
2167                              SSL_TUNNEL,
2168                              imap_starttls_radiobtn,
2169                              _("Use STARTTLS command to start SSL session"),
2170                              SSL_STARTTLS);
2171
2172         PACK_FRAME (vbox1, nntp_frame, _("NNTP"));
2173         vbox4 = gtk_vbox_new (FALSE, 0);
2174         gtk_widget_show (vbox4);
2175         gtk_container_add (GTK_CONTAINER (nntp_frame), vbox4);
2176         gtk_container_set_border_width (GTK_CONTAINER (vbox4), 8);
2177
2178         nntp_nossl_radiobtn =
2179                 gtk_radio_button_new_with_label (NULL, _("Don't use SSL"));
2180         gtk_widget_show (nntp_nossl_radiobtn);
2181         gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
2182                             FALSE, FALSE, 0);
2183         g_object_set_data (G_OBJECT (nntp_nossl_radiobtn),
2184                            MENU_VAL_ID,
2185                            GINT_TO_POINTER (SSL_NONE));
2186
2187         CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
2188                             _("Use SSL for NNTP connection"), SSL_TUNNEL);
2189
2190         PACK_FRAME (vbox1, send_frame, _("Send (SMTP)"));
2191         vbox5 = gtk_vbox_new (FALSE, 0);
2192         gtk_widget_show (vbox5);
2193         gtk_container_add (GTK_CONTAINER (send_frame), vbox5);
2194         gtk_container_set_border_width (GTK_CONTAINER (vbox5), 8);
2195
2196         CREATE_RADIO_BUTTONS(vbox5,
2197                              smtp_nossl_radiobtn,
2198                              _("Don't use SSL (but, if necessary, use STARTTLS)"),
2199                              SSL_NONE,
2200                              smtp_ssltunnel_radiobtn,
2201                              _("Use SSL for SMTP connection"),
2202                              SSL_TUNNEL,
2203                              smtp_starttls_radiobtn,
2204                              _("Use STARTTLS command to start SSL session"),
2205                              SSL_STARTTLS);
2206
2207         vbox6 = gtk_vbox_new (FALSE, 0);
2208         gtk_widget_show (vbox6);
2209         gtk_box_pack_start (GTK_BOX (vbox1), vbox6, FALSE, FALSE, 0);
2210
2211         PACK_CHECK_BUTTON(vbox6, use_nonblocking_ssl_chkbtn,
2212                           _("Use non-blocking SSL"));
2213
2214         hbox = gtk_hbox_new (FALSE, 0);
2215         gtk_widget_show (hbox);
2216         gtk_box_pack_start (GTK_BOX (vbox6), hbox, FALSE, FALSE, 0);
2217
2218         hbox_spc = gtk_hbox_new (FALSE, 0);
2219         gtk_widget_show (hbox_spc);
2220         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2221         gtk_widget_set_size_request (hbox_spc, 16, -1);
2222
2223         label = gtk_label_new
2224                 (_("Turn this off if you have SSL connection problems"));
2225         gtk_widget_show (label);
2226         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2227         gtkut_widget_set_small_font_size (label);
2228
2229         ssl.pop_frame               = pop_frame;
2230         ssl.pop_nossl_radiobtn      = pop_nossl_radiobtn;
2231         ssl.pop_ssltunnel_radiobtn  = pop_ssltunnel_radiobtn;
2232         ssl.pop_starttls_radiobtn   = pop_starttls_radiobtn;
2233
2234         ssl.imap_frame              = imap_frame;
2235         ssl.imap_nossl_radiobtn     = imap_nossl_radiobtn;
2236         ssl.imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
2237         ssl.imap_starttls_radiobtn  = imap_starttls_radiobtn;
2238
2239         ssl.nntp_frame              = nntp_frame;
2240         ssl.nntp_nossl_radiobtn     = nntp_nossl_radiobtn;
2241         ssl.nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
2242
2243         ssl.send_frame              = send_frame;
2244         ssl.smtp_nossl_radiobtn     = smtp_nossl_radiobtn;
2245         ssl.smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
2246         ssl.smtp_starttls_radiobtn  = smtp_starttls_radiobtn;
2247
2248         ssl.use_nonblocking_ssl_chkbtn = use_nonblocking_ssl_chkbtn;
2249 }
2250
2251 #undef CREATE_RADIO_BUTTONS
2252 #undef CREATE_RADIO_BUTTON
2253 #endif /* USE_OPENSSL */
2254
2255 static void crosspost_color_toggled(void)
2256 {
2257         gboolean is_active;
2258
2259         is_active = gtk_toggle_button_get_active
2260                 (GTK_TOGGLE_BUTTON(advanced.crosspost_chkbtn));
2261         gtk_widget_set_sensitive(advanced.crosspost_colormenu, is_active);
2262 }
2263
2264 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam)
2265 {
2266         GtkWidget *menu;
2267         GtkWidget *menuitem;
2268
2269         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(advanced.crosspost_colormenu));
2270         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2271         *((gint *)pparam->data) = GPOINTER_TO_INT
2272                 (g_object_get_data(G_OBJECT(menuitem), "color"));
2273 }
2274
2275 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam)
2276 {
2277         gint colorlabel = *((gint *)pparam->data);
2278         GtkOptionMenu *colormenu = GTK_OPTION_MENU(*pparam->widget);
2279         GtkWidget *menu;
2280         GtkWidget *menuitem;
2281
2282         gtk_option_menu_set_history(colormenu, colorlabel);
2283         menu = gtk_option_menu_get_menu(colormenu);
2284         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2285         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2286 }
2287
2288
2289 static void prefs_account_advanced_create(void)
2290 {
2291         GtkWidget *vbox1;
2292         GtkWidget *vbox2;
2293         GtkWidget *hbox1;
2294         GtkWidget *checkbtn_smtpport;
2295         GtkWidget *entry_smtpport;
2296         GtkWidget *hbox_popport;
2297         GtkWidget *checkbtn_popport;
2298         GtkWidget *entry_popport;
2299         GtkWidget *hbox_imapport;
2300         GtkWidget *checkbtn_imapport;
2301         GtkWidget *entry_imapport;
2302         GtkWidget *hbox_nntpport;
2303         GtkWidget *checkbtn_nntpport;
2304         GtkWidget *entry_nntpport;
2305         GtkWidget *checkbtn_domain;
2306         GtkWidget *entry_domain;
2307         GtkWidget *checkbtn_crosspost;
2308         GtkWidget *colormenu_crosspost;
2309         GtkWidget *menu;
2310         GtkWidget *checkbtn_tunnelcmd;
2311         GtkWidget *entry_tunnelcmd;
2312         GtkWidget *folder_frame;
2313         GtkWidget *vbox3;
2314         GtkWidget *table;
2315         GtkWidget *sent_folder_chkbtn;
2316         GtkWidget *sent_folder_entry;
2317         GtkWidget *queue_folder_chkbtn;
2318         GtkWidget *queue_folder_entry;
2319         GtkWidget *draft_folder_chkbtn;
2320         GtkWidget *draft_folder_entry;
2321         GtkWidget *trash_folder_chkbtn;
2322         GtkWidget *trash_folder_entry;
2323
2324 #define PACK_HBOX(hbox) \
2325         { \
2326         hbox = gtk_hbox_new (FALSE, 8); \
2327         gtk_widget_show (hbox); \
2328         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
2329         }
2330
2331 #define PACK_PORT_ENTRY(box, entry) \
2332         { \
2333         entry = gtk_entry_new (); \
2334         gtk_entry_set_max_length  (GTK_ENTRY(entry), 5); \
2335         gtk_widget_show (entry); \
2336         gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 0); \
2337         gtk_widget_set_size_request (entry, 64, -1); \
2338         }
2339
2340         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2341         gtk_widget_show (vbox1);
2342         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
2343         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2344
2345         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW_2);
2346         gtk_widget_show (vbox2);
2347         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2348
2349         PACK_HBOX (hbox1);
2350         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("SMTP port"));
2351         PACK_PORT_ENTRY (hbox1, entry_smtpport);
2352         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, entry_smtpport);
2353
2354         PACK_HBOX (hbox_popport);
2355         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
2356                            _("POP3 port"));
2357         PACK_PORT_ENTRY (hbox_popport, entry_popport);
2358         SET_TOGGLE_SENSITIVITY (checkbtn_popport, entry_popport);
2359
2360         PACK_HBOX (hbox_imapport);
2361         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
2362                            _("IMAP4 port"));
2363         PACK_PORT_ENTRY (hbox_imapport, entry_imapport);
2364         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, entry_imapport);
2365
2366         PACK_HBOX (hbox_nntpport);
2367         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
2368                            _("NNTP port"));
2369         PACK_PORT_ENTRY (hbox_nntpport, entry_nntpport);
2370         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, entry_nntpport);
2371
2372         PACK_HBOX (hbox1);
2373         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Domain name"));
2374
2375         entry_domain = gtk_entry_new ();
2376         gtk_widget_show (entry_domain);
2377         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
2378         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
2379
2380         
2381         PACK_HBOX (hbox1);
2382         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
2383                            _("Use command to communicate with server"));
2384         entry_tunnelcmd = gtk_entry_new ();
2385         gtk_widget_show (entry_tunnelcmd);
2386         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
2387         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
2388
2389         PACK_HBOX (hbox1);
2390         PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost, 
2391                            _("Mark cross-posted messages as read and color:"));
2392         g_signal_connect (G_OBJECT (checkbtn_crosspost), "toggled",
2393                           G_CALLBACK (crosspost_color_toggled),
2394                           NULL);
2395
2396         colormenu_crosspost = gtk_option_menu_new();
2397         gtk_widget_show (colormenu_crosspost);
2398         gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
2399
2400         menu = colorlabel_create_color_menu();
2401         gtk_option_menu_set_menu (GTK_OPTION_MENU(colormenu_crosspost), menu);
2402         SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
2403
2404         PACK_HBOX (hbox1);
2405 #undef PACK_HBOX
2406 #undef PACK_PORT_ENTRY
2407
2408         /* special folder setting (maybe these options are redundant) */
2409
2410         PACK_FRAME (vbox1, folder_frame, _("Folder"));
2411
2412         vbox3 = gtk_vbox_new (FALSE, 0);
2413         gtk_widget_show (vbox3);
2414         gtk_container_add (GTK_CONTAINER (folder_frame), vbox3);
2415         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
2416
2417         table = gtk_table_new (4, 3, FALSE);
2418         gtk_widget_show (table);
2419         gtk_container_add (GTK_CONTAINER (vbox3), table);
2420         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
2421         gtk_table_set_col_spacings (GTK_TABLE (table), 4);
2422
2423 #define SET_CHECK_BTN_AND_ENTRY(label, chkbtn, entry, n)                \
2424 {                                                                       \
2425         GtkWidget *button;                                              \
2426                                                                         \
2427         chkbtn = gtk_check_button_new_with_label (label);               \
2428         gtk_widget_show (chkbtn);                                       \
2429         gtk_table_attach (GTK_TABLE (table), chkbtn,                    \
2430                           0, 1, n, n + 1, GTK_FILL, 0, 0, 0);           \
2431                                                                         \
2432         entry = gtk_entry_new ();                                       \
2433         gtk_widget_show (entry);                                        \
2434         gtk_table_attach (GTK_TABLE (table), entry, 1, 2, n, n + 1,     \
2435                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,           \
2436                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);    \
2437                                                                         \
2438         button = gtkut_get_browse_file_btn(_("Browse"));                \
2439         gtk_widget_show (button);                                       \
2440         gtk_table_attach (GTK_TABLE (table), button,                    \
2441                           2, 3, n, n + 1, GTK_FILL, 0, 0, 0);           \
2442         g_signal_connect                                                \
2443                 (G_OBJECT (button), "clicked",                  \
2444                  G_CALLBACK (prefs_account_select_folder_cb),           \
2445                  entry);                                                \
2446                                                                         \
2447         SET_TOGGLE_SENSITIVITY (chkbtn, entry);                         \
2448         SET_TOGGLE_SENSITIVITY (chkbtn, button);                        \
2449 }
2450
2451         SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
2452                                 sent_folder_chkbtn, sent_folder_entry, 0);
2453         SET_CHECK_BTN_AND_ENTRY(_("Put queued messages in"),
2454                                 queue_folder_chkbtn, queue_folder_entry, 1);
2455         SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
2456                                 draft_folder_chkbtn, draft_folder_entry, 2);
2457         SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
2458                                 trash_folder_chkbtn, trash_folder_entry, 3);
2459
2460         advanced.smtpport_chkbtn        = checkbtn_smtpport;
2461         advanced.smtpport_entry         = entry_smtpport;
2462         advanced.popport_hbox           = hbox_popport;
2463         advanced.popport_chkbtn         = checkbtn_popport;
2464         advanced.popport_entry          = entry_popport;
2465         advanced.imapport_hbox          = hbox_imapport;
2466         advanced.imapport_chkbtn        = checkbtn_imapport;
2467         advanced.imapport_entry         = entry_imapport;
2468         advanced.nntpport_hbox          = hbox_nntpport;
2469         advanced.nntpport_chkbtn        = checkbtn_nntpport;
2470         advanced.nntpport_entry         = entry_nntpport;
2471         advanced.domain_chkbtn          = checkbtn_domain;
2472         advanced.domain_entry           = entry_domain;
2473         advanced.crosspost_chkbtn       = checkbtn_crosspost;
2474         advanced.crosspost_colormenu    = colormenu_crosspost;
2475
2476         advanced.tunnelcmd_chkbtn       = checkbtn_tunnelcmd;
2477         advanced.tunnelcmd_entry        = entry_tunnelcmd;
2478
2479         advanced.sent_folder_chkbtn  = sent_folder_chkbtn;
2480         advanced.sent_folder_entry   = sent_folder_entry;
2481         advanced.queue_folder_chkbtn  = queue_folder_chkbtn;
2482         advanced.queue_folder_entry   = queue_folder_entry;
2483         advanced.draft_folder_chkbtn = draft_folder_chkbtn;
2484         advanced.draft_folder_entry  = draft_folder_entry;
2485         advanced.trash_folder_chkbtn = trash_folder_chkbtn;
2486         advanced.trash_folder_entry  = trash_folder_entry;
2487 }
2488
2489 static gint prefs_account_apply(void)
2490 {
2491         RecvProtocol protocol;
2492         gchar *old_id = NULL;
2493         gchar *new_id = NULL;
2494         struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *) basic.protocol_optmenu;
2495         GtkWidget *optmenu = protocol_optmenu->combobox;
2496
2497         protocol = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
2498
2499         if (*gtk_entry_get_text(GTK_ENTRY(basic.acname_entry)) == '\0') {
2500                 alertpanel_error(_("Account name is not entered."));
2501                 return -1;
2502         }
2503         if (*gtk_entry_get_text(GTK_ENTRY(basic.addr_entry)) == '\0') {
2504                 alertpanel_error(_("Mail address is not entered."));
2505                 return -1;
2506         }
2507         if (((protocol == A_POP3) || 
2508              (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn))) || 
2509              (protocol == A_NONE)) &&
2510            *gtk_entry_get_text(GTK_ENTRY(basic.smtpserv_entry)) == '\0') {
2511                 alertpanel_error(_("SMTP server is not entered."));
2512                 return -1;
2513         }
2514         if ((protocol == A_POP3 || protocol == A_IMAP4) &&
2515             *gtk_entry_get_text(GTK_ENTRY(basic.uid_entry)) == '\0') {
2516                 alertpanel_error(_("User ID is not entered."));
2517                 return -1;
2518         }
2519         if (protocol == A_POP3 &&
2520             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2521                 alertpanel_error(_("POP3 server is not entered."));
2522                 return -1;
2523         }
2524         if (protocol == A_IMAP4 &&
2525             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2526                 alertpanel_error(_("IMAP4 server is not entered."));
2527                 return -1;
2528         }
2529         if (protocol == A_NNTP &&
2530             *gtk_entry_get_text(GTK_ENTRY(basic.nntpserv_entry)) == '\0') {
2531                 alertpanel_error(_("NNTP server is not entered."));
2532                 return -1;
2533         }
2534
2535         if (protocol == A_LOCAL &&
2536             *gtk_entry_get_text(GTK_ENTRY(basic.localmbox_entry)) == '\0') {
2537                 alertpanel_error(_("local mailbox filename is not entered."));
2538                 return -1;
2539         }
2540
2541         if (protocol == A_LOCAL &&
2542             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic.mailcmd_entry)) == '\0') {
2543                 alertpanel_error(_("mail command is not entered."));
2544                 return -1;
2545         }
2546         
2547         if (protocol == A_IMAP4 || protocol == A_NNTP) 
2548                 old_id = g_strdup_printf("#%s/%s",
2549                                 protocol == A_IMAP4 ? "imap":"nntp",
2550                                 tmp_ac_prefs.account_name ? tmp_ac_prefs.account_name : "(null)");
2551         
2552         prefs_set_data_from_dialog(param);
2553         
2554         if (protocol == A_IMAP4 || protocol == A_NNTP) {
2555                 new_id = g_strdup_printf("#%s/%s",
2556                                 protocol == A_IMAP4 ? "imap":"nntp",
2557                                 tmp_ac_prefs.account_name);
2558                 if (old_id != NULL && new_id != NULL)
2559                         prefs_filtering_rename_path(old_id, new_id);
2560                 g_free(old_id);
2561                 g_free(new_id);
2562         }
2563         return 0;
2564 }
2565
2566 static void pop_bfr_smtp_tm_set_sens(GtkWidget *widget, gpointer data)
2567 {
2568         gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, 
2569                                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn)));
2570         gtk_widget_set_sensitive(p_send.pop_auth_timeout_lbl, 
2571                                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn)));
2572         gtk_widget_set_sensitive(p_send.pop_auth_minutes_lbl, 
2573                                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn)));
2574 }
2575
2576 static void prefs_account_select_folder_cb(GtkWidget *widget, gpointer data)
2577 {
2578         FolderItem *item;
2579         gchar *id;
2580
2581         item = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
2582         if (item && item->path) {
2583                 id = folder_item_get_identifier(item);
2584                 if (id) {
2585                         gtk_entry_set_text(GTK_ENTRY(data), id);
2586                         g_free(id);
2587                 }
2588         }
2589 }
2590
2591 static void prefs_account_sigfile_radiobtn_cb(GtkWidget *widget, gpointer data)
2592 {
2593         gtk_widget_set_sensitive(GTK_WIDGET(signature_browse_button), TRUE);
2594         gtk_widget_set_sensitive(GTK_WIDGET(signature_edit_button), TRUE);
2595 }
2596
2597 static void prefs_account_sigcmd_radiobtn_cb(GtkWidget *widget, gpointer data)
2598 {
2599         gtk_widget_set_sensitive(GTK_WIDGET(signature_browse_button), FALSE);
2600         gtk_widget_set_sensitive(GTK_WIDGET(signature_edit_button), FALSE);
2601 }
2602
2603 static void prefs_account_signature_browse_cb(GtkWidget *widget, gpointer data)
2604 {
2605         gchar *filename;
2606         gchar *utf8_filename;
2607
2608         filename = filesel_select_file_open(_("Select signature file"), NULL);
2609         if (!filename) return;
2610
2611         utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
2612         if (!utf8_filename) {
2613                 g_warning("prefs_account_signature_browse_cb(): failed to convert character set.");
2614                 utf8_filename = g_strdup(filename);
2615         }
2616         gtk_entry_set_text(GTK_ENTRY(entry_sigpath), utf8_filename);
2617         g_free(utf8_filename);
2618 }
2619
2620 static void prefs_account_signature_edit_cb(GtkWidget *widget, gpointer data)
2621 {
2622         const gchar *sigpath = gtk_entry_get_text(GTK_ENTRY(data));
2623         open_txt_editor(sigpath, prefs_common.ext_editor_cmd);
2624 }
2625
2626 static void prefs_account_edit_custom_header(void)
2627 {
2628         prefs_custom_header_open(&tmp_ac_prefs);
2629 }
2630
2631 static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
2632 {
2633         GtkRadioButton *radiobtn;
2634         GSList *group;
2635
2636         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2637         group = gtk_radio_button_get_group (radiobtn);
2638         while (group != NULL) {
2639                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2640                 if (gtk_toggle_button_get_active (btn)) {
2641                         *((gint *)pparam->data) = GPOINTER_TO_INT
2642                                 (g_object_get_data (G_OBJECT (btn), MENU_VAL_ID));
2643                         break;
2644                 }
2645                 group = group->next;
2646         }
2647 }
2648
2649 static void prefs_account_enum_set_radiobtn(PrefParam *pparam)
2650 {
2651         GtkRadioButton *radiobtn;
2652         GSList *group;
2653         gpointer data;
2654
2655         data = GINT_TO_POINTER (*((gint *)pparam->data));
2656         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2657         group = gtk_radio_button_get_group (radiobtn);
2658         while (group != NULL) {
2659                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2660                 gpointer data1 = g_object_get_data (G_OBJECT (btn), MENU_VAL_ID);
2661                 if (data1 == data) {
2662                         gtk_toggle_button_set_active (btn, TRUE);
2663                         break;
2664                 }
2665                 group = group->next;
2666         }
2667 }
2668
2669 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
2670 {
2671         struct BasicProtocol *protocol_optmenu =
2672                 (struct BasicProtocol *)*pparam->widget;
2673         GtkWidget *optmenu = protocol_optmenu->combobox;
2674
2675         *((RecvProtocol *)pparam->data) =
2676                 combobox_get_active_data(GTK_COMBO_BOX(optmenu));
2677 }
2678
2679 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
2680 {
2681         RecvProtocol protocol;
2682         struct BasicProtocol *protocol_optmenu =
2683                 (struct BasicProtocol *)*pparam->widget;
2684         GtkWidget *optmenu = protocol_optmenu->combobox;
2685         GtkWidget *optlabel = protocol_optmenu->label;
2686         GtkWidget *descrlabel = protocol_optmenu->descrlabel;
2687         gchar *label = NULL;
2688
2689         protocol = *((RecvProtocol *)pparam->data);
2690
2691         /* Set combobox to correct value even if it will be hidden, so
2692          * we won't break existing accounts when saving. */
2693         combobox_select_by_data(GTK_COMBO_BOX(optmenu), protocol);
2694
2695         /* Set up widgets accordingly */
2696         if( new_account ) {
2697                 gtk_label_set_text(GTK_LABEL(descrlabel), _("Protocol"));
2698                 gtk_widget_hide(optlabel);
2699                 gtk_widget_show(optmenu);
2700         } else {
2701                 gtk_label_set_text(GTK_LABEL(descrlabel), _("Protocol:"));
2702                 label = g_markup_printf_escaped("<b>%s</b>", protocol_names[protocol]);
2703                 gtk_label_set_markup(GTK_LABEL(optlabel), label);
2704                 g_free(label);
2705                 gtk_widget_hide(optmenu);
2706                 gtk_widget_show(optlabel);
2707 #ifndef HAVE_LIBETPAN
2708                 if (protocol == A_IMAP4) {
2709                         gtk_widget_show(protocol_optmenu->no_imap_warn_icon);
2710                         gtk_widget_show(protocol_optmenu->no_imap_warn_label);
2711                 } else {
2712                         gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
2713                         gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
2714                 }
2715 #endif
2716         }
2717 }
2718
2719 static void prefs_account_imap_auth_type_set_data_from_optmenu(PrefParam *pparam)
2720 {
2721         GtkWidget *menu;
2722         GtkWidget *menuitem;
2723
2724         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2725         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2726         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2727                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2728 }
2729
2730 static void prefs_account_imap_auth_type_set_optmenu(PrefParam *pparam)
2731 {
2732         IMAPAuthType type = *((IMAPAuthType *)pparam->data);
2733         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2734         GtkWidget *menu;
2735         GtkWidget *menuitem;
2736
2737         switch (type) {
2738         case IMAP_AUTH_LOGIN:
2739                 gtk_option_menu_set_history(optmenu, 1);
2740                 break;
2741         case IMAP_AUTH_CRAM_MD5:
2742                 gtk_option_menu_set_history(optmenu, 2);
2743                 break;
2744         case IMAP_AUTH_ANON:
2745                 gtk_option_menu_set_history(optmenu, 3);
2746                 break;
2747         case IMAP_AUTH_GSSAPI:
2748                 gtk_option_menu_set_history(optmenu, 4);
2749                 break;
2750         case 0:
2751         default:
2752                 gtk_option_menu_set_history(optmenu, 0);
2753         }
2754
2755         menu = gtk_option_menu_get_menu(optmenu);
2756         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2757         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2758 }
2759
2760 static void prefs_account_smtp_auth_type_set_data_from_optmenu(PrefParam *pparam)
2761 {
2762         GtkWidget *menu;
2763         GtkWidget *menuitem;
2764
2765         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2766         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2767         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2768                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2769 }
2770
2771 static void prefs_account_smtp_auth_type_set_optmenu(PrefParam *pparam)
2772 {
2773         SMTPAuthType type = *((SMTPAuthType *)pparam->data);
2774         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2775         GtkWidget *menu;
2776         GtkWidget *menuitem;
2777
2778         switch (type) {
2779         case SMTPAUTH_PLAIN:
2780                 gtk_option_menu_set_history(optmenu, 1);
2781                 break;
2782         case SMTPAUTH_LOGIN:
2783                 gtk_option_menu_set_history(optmenu, 2);
2784                 break;
2785         case SMTPAUTH_CRAM_MD5:
2786                 gtk_option_menu_set_history(optmenu, 3);
2787                 break;
2788         case SMTPAUTH_DIGEST_MD5:
2789                 gtk_option_menu_set_history(optmenu, 4);
2790                 break;
2791         case 0:
2792         default:
2793                 gtk_option_menu_set_history(optmenu, 0);
2794         }
2795
2796         menu = gtk_option_menu_get_menu(optmenu);
2797         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2798         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2799 }
2800
2801 static void prefs_account_set_string_from_optmenu(PrefParam *pparam)
2802 {
2803         GtkWidget *menu;
2804         GtkWidget *menuitem;
2805         gchar **str;
2806
2807         g_return_if_fail(*pparam->widget != NULL);
2808
2809         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2810         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2811         if (menuitem == NULL)
2812                 return;
2813
2814         str = (gchar **) pparam->data;
2815         g_free(*str);
2816         *str = g_strdup(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2817 }
2818
2819 static void prefs_account_set_optmenu_from_string(PrefParam *pparam)
2820 {
2821         GtkWidget *optionmenu;
2822         GtkWidget *menu;
2823         gboolean found = FALSE;
2824         GList *children, *cur;
2825         gchar *prefsid;
2826         guint i = 0;
2827
2828         g_return_if_fail(*pparam->widget != NULL);
2829
2830         prefsid = *((gchar **) pparam->data);
2831         if (prefsid == NULL)
2832                 return;
2833
2834         optionmenu = *pparam->widget;
2835         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optionmenu));
2836         children = gtk_container_children(GTK_CONTAINER(menu));
2837         for (cur = children; cur != NULL; cur = g_list_next(cur)) {
2838                 GtkWidget *item = (GtkWidget *) cur->data;
2839                 gchar *id;
2840
2841                 id = g_object_get_data(G_OBJECT(item), MENU_VAL_ID);
2842                 if (id != NULL && strcmp(id, prefsid) == 0) {
2843                         found = TRUE;
2844                         gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), i);
2845                 }
2846                 i++;
2847         }
2848
2849         if (!found) {
2850                 gchar *name;
2851                 GtkWidget *menuitem;
2852
2853                 name = g_strdup_printf(_("Unsupported (%s)"), prefsid);
2854                 menuitem = gtk_menu_item_new_with_label(name);
2855                 gtk_widget_show(menuitem);
2856                 g_object_set_data_full(G_OBJECT(menuitem), MENU_VAL_ID, g_strdup(prefsid), g_free);
2857                 gtk_menu_append(GTK_MENU(menu), menuitem);
2858                 g_free(name);
2859
2860                 gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), i);
2861         }
2862
2863         g_list_free(children);
2864 }
2865
2866 static void prefs_account_protocol_changed(GtkComboBox *combobox, gpointer data)
2867 {
2868         RecvProtocol protocol;
2869         struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *)basic.protocol_optmenu;
2870
2871         protocol = combobox_get_active_data(combobox);
2872
2873         gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
2874         gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
2875         switch(protocol) {
2876         case A_NNTP:
2877                 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
2878                 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
2879                 gtk_widget_show(basic.nntpserv_label);
2880                 gtk_widget_show(basic.nntpserv_entry);
2881                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2882                                            0, VSPACING_NARROW);
2883
2884                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, TRUE);
2885                 gtk_widget_show(basic.nntpauth_chkbtn);
2886
2887                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, TRUE);
2888                 gtk_widget_show(basic.nntpauth_onconnect_chkbtn);
2889
2890                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2891                                            1, VSPACING_NARROW);
2892                 gtk_widget_hide(basic.recvserv_label);
2893                 gtk_widget_hide(basic.recvserv_entry);
2894                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2895                                            2, 0);
2896                 gtk_widget_show(basic.smtpserv_label);
2897                 gtk_widget_show(basic.smtpserv_entry);
2898                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2899                                            4, VSPACING_NARROW);
2900                 gtk_widget_hide(basic.localmbox_label);
2901                 gtk_widget_hide(basic.localmbox_entry);
2902                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2903                                            3, 0);
2904                 gtk_widget_hide(basic.mailcmd_label);
2905                 gtk_widget_hide(basic.mailcmd_entry);
2906                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2907                                            6, 0);
2908                 gtk_widget_hide(basic.mailcmd_chkbtn);
2909                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2910                                            5, 0);
2911                 gtk_widget_show(basic.uid_label);
2912                 gtk_widget_show(basic.pass_label);
2913                 gtk_widget_show(basic.uid_entry);
2914                 gtk_widget_show(basic.pass_entry);
2915                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2916                                            7, VSPACING_NARROW);
2917
2918                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2919                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2920                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2921                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2922
2923                 /* update userid/passwd sensitive state */
2924
2925                 prefs_account_nntpauth_toggled
2926                         (GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
2927                 gtk_widget_hide(receive.pop3_frame);
2928                 gtk_widget_hide(receive.imap_frame);
2929                 gtk_widget_hide(receive.local_frame);
2930                 gtk_widget_show(receive.frame_maxarticle);
2931                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
2932                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2933                 /* update pop_before_smtp sensitivity */
2934                 gtk_toggle_button_set_active
2935                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
2936                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2937                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
2938                 
2939                 if (!tmp_ac_prefs.account_name) {
2940                         gtk_toggle_button_set_active
2941                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
2942                                 TRUE);
2943                         gtk_toggle_button_set_active
2944                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2945                                  FALSE);
2946                 }
2947
2948 #if USE_OPENSSL
2949                 gtk_widget_hide(ssl.pop_frame);
2950                 gtk_widget_hide(ssl.imap_frame);
2951                 gtk_widget_show(ssl.nntp_frame);
2952                 gtk_widget_show(ssl.send_frame);
2953 #endif
2954                 gtk_widget_hide(advanced.popport_hbox);
2955                 gtk_widget_hide(advanced.imapport_hbox);
2956                 gtk_widget_show(advanced.nntpport_hbox);
2957                 gtk_widget_show(advanced.crosspost_chkbtn);
2958                 gtk_widget_show(advanced.crosspost_colormenu);
2959                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
2960                 gtk_widget_hide(advanced.tunnelcmd_entry);
2961                 gtk_widget_hide(receive.imapdir_label);
2962                 gtk_widget_hide(receive.imapdir_entry);
2963                 break;
2964         case A_LOCAL:
2965                 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
2966                 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
2967                 gtk_widget_hide(basic.nntpserv_label);
2968                 gtk_widget_hide(basic.nntpserv_entry);
2969                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2970                                            0, 0);
2971                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2972                 gtk_widget_hide(basic.nntpauth_chkbtn);
2973
2974                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2975                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2976                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2977                                            1, 0);
2978                 gtk_widget_hide(basic.recvserv_label);
2979                 gtk_widget_hide(basic.recvserv_entry);
2980                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2981                                            2, 0);
2982                 gtk_widget_show(basic.smtpserv_label);
2983                 gtk_widget_show(basic.smtpserv_entry);
2984                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2985                                            4, VSPACING_NARROW);
2986                 gtk_widget_show(basic.localmbox_label);
2987                 gtk_widget_show(basic.localmbox_entry);
2988                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2989                                            3, VSPACING_NARROW);
2990                 gtk_widget_show(basic.mailcmd_label);
2991                 gtk_widget_show(basic.mailcmd_entry);
2992                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2993                                            6, VSPACING_NARROW);
2994                 gtk_widget_show(basic.mailcmd_chkbtn);
2995                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2996                                            5, VSPACING_NARROW);
2997                 gtk_widget_hide(basic.uid_label);
2998                 gtk_widget_hide(basic.pass_label);
2999                 gtk_widget_hide(basic.uid_entry);
3000                 gtk_widget_hide(basic.pass_entry);
3001                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3002                                            7, 0);
3003
3004                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
3005                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
3006                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
3007                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
3008                 gtk_widget_hide(receive.pop3_frame);
3009                 gtk_widget_hide(receive.imap_frame);
3010                 gtk_widget_show(receive.local_frame);
3011                 gtk_widget_hide(receive.frame_maxarticle);
3012                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
3013                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
3014                 prefs_account_mailcmd_toggled
3015                         (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
3016
3017                 /* update pop_before_smtp sensitivity */
3018                 gtk_toggle_button_set_active
3019                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
3020                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
3021                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
3022
3023                 if (!tmp_ac_prefs.account_name) {
3024                         gtk_toggle_button_set_active
3025                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
3026                                 TRUE);
3027                         gtk_toggle_button_set_active
3028                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
3029                                  TRUE);
3030                 }
3031
3032 #if USE_OPENSSL
3033                 gtk_widget_hide(ssl.pop_frame);
3034                 gtk_widget_hide(ssl.imap_frame);
3035                 gtk_widget_hide(ssl.nntp_frame);
3036                 gtk_widget_show(ssl.send_frame);
3037 #endif
3038                 gtk_widget_hide(advanced.popport_hbox);
3039                 gtk_widget_hide(advanced.imapport_hbox);
3040                 gtk_widget_hide(advanced.nntpport_hbox);
3041                 gtk_widget_hide(advanced.crosspost_chkbtn);
3042                 gtk_widget_hide(advanced.crosspost_colormenu);
3043                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
3044                 gtk_widget_hide(advanced.tunnelcmd_entry);
3045                 gtk_widget_hide(receive.imapdir_label);
3046                 gtk_widget_hide(receive.imapdir_entry);
3047                 break;
3048         case A_IMAP4:
3049 #ifndef HAVE_LIBETPAN
3050                 gtk_widget_show(protocol_optmenu->no_imap_warn_icon);
3051                 gtk_widget_show(protocol_optmenu->no_imap_warn_label);
3052 #endif
3053                 gtk_widget_hide(basic.nntpserv_label);
3054                 gtk_widget_hide(basic.nntpserv_entry);
3055                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3056                                            0, 0);
3057                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
3058                 gtk_widget_hide(basic.nntpauth_chkbtn);
3059
3060                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
3061                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
3062
3063                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3064                                            1, 0);
3065                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
3066                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
3067                 gtk_widget_show(basic.recvserv_label);
3068                 gtk_widget_show(basic.recvserv_entry);
3069                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3070                                            2, VSPACING_NARROW);
3071                 gtk_widget_show(basic.smtpserv_label);
3072                 gtk_widget_show(basic.smtpserv_entry);
3073                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3074                                            4, VSPACING_NARROW);
3075                 gtk_widget_hide(basic.localmbox_label);
3076                 gtk_widget_hide(basic.localmbox_entry);
3077                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3078                                            3, 0);
3079                 gtk_widget_hide(basic.mailcmd_label);
3080                 gtk_widget_hide(basic.mailcmd_entry);
3081                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3082                                            6, 0);
3083                 gtk_widget_hide(basic.mailcmd_chkbtn);
3084                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3085                                            5, 0);
3086                 gtk_widget_show(basic.uid_label);
3087                 gtk_widget_show(basic.pass_label);
3088                 gtk_widget_show(basic.uid_entry);
3089                 gtk_widget_show(basic.pass_entry);
3090                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3091                                            7, VSPACING_NARROW);
3092
3093                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
3094                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
3095                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
3096                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
3097                 gtk_widget_hide(receive.pop3_frame);
3098                 gtk_widget_show(receive.imap_frame);
3099                 gtk_widget_hide(receive.local_frame);
3100                 gtk_widget_hide(receive.frame_maxarticle);
3101                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
3102                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
3103                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3104                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3105
3106                 /* update pop_before_smtp sensitivity */
3107                 gtk_toggle_button_set_active
3108                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
3109                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
3110                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
3111
3112                 if (!tmp_ac_prefs.account_name) {
3113                         gtk_toggle_button_set_active
3114                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
3115                                 TRUE);
3116                         gtk_toggle_button_set_active
3117                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
3118                                  FALSE);
3119                 }
3120
3121 #if USE_OPENSSL
3122                 gtk_widget_hide(ssl.pop_frame);
3123                 gtk_widget_show(ssl.imap_frame);
3124                 gtk_widget_hide(ssl.nntp_frame);
3125                 gtk_widget_show(ssl.send_frame);
3126 #endif
3127                 gtk_widget_hide(advanced.popport_hbox);
3128                 gtk_widget_show(advanced.imapport_hbox);
3129                 gtk_widget_hide(advanced.nntpport_hbox);
3130                 gtk_widget_hide(advanced.crosspost_chkbtn);
3131                 gtk_widget_hide(advanced.crosspost_colormenu);
3132                 gtk_widget_show(advanced.tunnelcmd_chkbtn);
3133                 gtk_widget_show(advanced.tunnelcmd_entry);
3134                 gtk_widget_show(receive.imapdir_label);
3135                 gtk_widget_show(receive.imapdir_entry);
3136                 break;
3137         case A_NONE:
3138                 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
3139                 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
3140                 gtk_widget_hide(basic.nntpserv_label);
3141                 gtk_widget_hide(basic.nntpserv_entry);
3142                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3143                                            0, 0);
3144                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
3145                 gtk_widget_hide(basic.nntpauth_chkbtn);
3146
3147                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
3148                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
3149
3150                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3151                                            1, 0);
3152                 gtk_widget_set_sensitive(basic.recvserv_label, FALSE);
3153                 gtk_widget_set_sensitive(basic.recvserv_entry, FALSE);
3154                 gtk_widget_hide(basic.recvserv_label);
3155                 gtk_widget_hide(basic.recvserv_entry);
3156                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3157                                            2, VSPACING_NARROW);
3158                 gtk_widget_show(basic.smtpserv_label);
3159                 gtk_widget_show(basic.smtpserv_entry);
3160                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3161                                            4, VSPACING_NARROW);
3162                 gtk_widget_hide(basic.localmbox_label);
3163                 gtk_widget_hide(basic.localmbox_entry);
3164                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3165                                            3, 0);
3166                 gtk_widget_hide(basic.mailcmd_label);
3167                 gtk_widget_hide(basic.mailcmd_entry);
3168                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3169                                            6, 0);
3170                 gtk_widget_hide(basic.mailcmd_chkbtn);
3171                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3172                                            5, 0);
3173                 gtk_widget_hide(basic.uid_label);
3174                 gtk_widget_hide(basic.pass_label);
3175                 gtk_widget_hide(basic.uid_entry);
3176                 gtk_widget_hide(basic.pass_entry);
3177                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3178                                            7, VSPACING_NARROW);
3179
3180                 gtk_widget_set_sensitive(basic.uid_label,  FALSE);
3181                 gtk_widget_set_sensitive(basic.pass_label, FALSE);
3182                 gtk_widget_set_sensitive(basic.uid_entry,  FALSE);
3183                 gtk_widget_set_sensitive(basic.pass_entry, FALSE);
3184                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
3185                 gtk_widget_hide(receive.pop3_frame);
3186                 gtk_widget_hide(receive.imap_frame);
3187                 gtk_widget_hide(receive.local_frame);
3188                 gtk_widget_hide(receive.frame_maxarticle);
3189                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, FALSE);
3190                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, FALSE);
3191
3192                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3193                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3194
3195                 /* update pop_before_smtp sensitivity */
3196                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
3197                 pop_bfr_smtp_tm_set_sens(NULL, NULL);
3198         
3199                 gtk_toggle_button_set_active
3200                         (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), FALSE);
3201                 gtk_toggle_button_set_active
3202                         (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn), FALSE);
3203
3204 #if USE_OPENSSL
3205                 gtk_widget_hide(ssl.pop_frame);
3206                 gtk_widget_hide(ssl.imap_frame);
3207                 gtk_widget_hide(ssl.nntp_frame);
3208                 gtk_widget_show(ssl.send_frame);
3209 #endif
3210                 gtk_widget_hide(advanced.popport_hbox);
3211                 gtk_widget_hide(advanced.imapport_hbox);
3212                 gtk_widget_hide(advanced.nntpport_hbox);
3213                 gtk_widget_hide(advanced.crosspost_chkbtn);
3214                 gtk_widget_hide(advanced.crosspost_colormenu);
3215                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
3216                 gtk_widget_hide(advanced.tunnelcmd_entry);
3217                 gtk_widget_hide(receive.imapdir_label);
3218                 gtk_widget_hide(receive.imapdir_entry);
3219                 break;
3220         case A_POP3:
3221         default:
3222                 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
3223                 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
3224                 gtk_widget_hide(basic.nntpserv_label);
3225                 gtk_widget_hide(basic.nntpserv_entry);
3226                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3227                                            0, 0);
3228                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
3229                 gtk_widget_hide(basic.nntpauth_chkbtn);
3230
3231                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
3232                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
3233
3234                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3235                                            1, 0);
3236                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
3237                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
3238                 gtk_widget_show(basic.recvserv_label);
3239                 gtk_widget_show(basic.recvserv_entry);
3240                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3241                                            2, VSPACING_NARROW);
3242                 gtk_widget_show(basic.smtpserv_label);
3243                 gtk_widget_show(basic.smtpserv_entry);
3244                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3245                                            4, VSPACING_NARROW);
3246                 gtk_widget_hide(basic.localmbox_label);
3247                 gtk_widget_hide(basic.localmbox_entry);
3248                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3249                                            3, 0);
3250                 gtk_widget_hide(basic.mailcmd_label);
3251                 gtk_widget_hide(basic.mailcmd_entry);
3252                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3253                                            6, 0);
3254                 gtk_widget_hide(basic.mailcmd_chkbtn);
3255                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3256                                            5, 0);
3257                 gtk_widget_show(basic.uid_label);
3258                 gtk_widget_show(basic.pass_label);
3259                 gtk_widget_show(basic.uid_entry);
3260                 gtk_widget_show(basic.pass_entry);
3261                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3262                                            7, VSPACING_NARROW);
3263
3264                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
3265                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
3266                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
3267                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
3268                 gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
3269                 gtk_widget_show(receive.pop3_frame);
3270                 gtk_widget_hide(receive.imap_frame);
3271                 gtk_widget_hide(receive.local_frame);
3272                 gtk_widget_hide(receive.frame_maxarticle);
3273                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
3274                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
3275
3276                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3277                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3278
3279                 /* update pop_before_smtp sensitivity */
3280                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, TRUE);
3281                 pop_bfr_smtp_tm_set_sens(NULL, NULL);
3282                 
3283                 if (!tmp_ac_prefs.account_name) {
3284                         gtk_toggle_button_set_active
3285                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
3286                                 TRUE);
3287                         gtk_toggle_button_set_active
3288                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
3289                                  TRUE);
3290                 }
3291
3292 #if USE_OPENSSL
3293                 gtk_widget_show(ssl.pop_frame);
3294                 gtk_widget_hide(ssl.imap_frame);
3295                 gtk_widget_hide(ssl.nntp_frame);
3296                 gtk_widget_show(ssl.send_frame);
3297 #endif
3298                 gtk_widget_show(advanced.popport_hbox);
3299                 gtk_widget_hide(advanced.imapport_hbox);
3300                 gtk_widget_hide(advanced.nntpport_hbox);
3301                 gtk_widget_hide(advanced.crosspost_chkbtn);
3302                 gtk_widget_hide(advanced.crosspost_colormenu);
3303                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
3304                 gtk_widget_hide(advanced.tunnelcmd_entry);
3305                 gtk_widget_hide(receive.imapdir_label);
3306                 gtk_widget_hide(receive.imapdir_entry);
3307                 break;
3308         }
3309
3310         gtk_widget_queue_resize(basic.serv_frame);
3311 }
3312
3313 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
3314                                            gpointer user_data)
3315 {
3316         gboolean auth;
3317
3318         if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (button)))
3319                 return;
3320         auth = gtk_toggle_button_get_active (button);
3321         gtk_widget_set_sensitive(basic.uid_label,  auth);
3322         gtk_widget_set_sensitive(basic.pass_label, auth);
3323         gtk_widget_set_sensitive(basic.uid_entry,  auth);
3324         gtk_widget_set_sensitive(basic.pass_entry, auth);
3325         gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, auth);
3326 }
3327
3328 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
3329                                           gpointer user_data)
3330 {
3331         gboolean use_mailcmd;
3332
3333         use_mailcmd = gtk_toggle_button_get_active (button);
3334
3335         gtk_widget_set_sensitive(basic.mailcmd_entry,  use_mailcmd);
3336         gtk_widget_set_sensitive(basic.mailcmd_label, use_mailcmd);
3337         gtk_widget_set_sensitive(basic.smtpserv_entry, !use_mailcmd);
3338         gtk_widget_set_sensitive(basic.smtpserv_label, !use_mailcmd);
3339         gtk_widget_set_sensitive(basic.uid_entry,  !use_mailcmd);
3340         gtk_widget_set_sensitive(basic.pass_entry, !use_mailcmd);
3341 }
3342
3343 void prefs_account_register_page(PrefsPage *page)
3344 {
3345         prefs_pages = g_slist_append(prefs_pages, page);
3346 }
3347
3348 void prefs_account_unregister_page(PrefsPage *page)
3349 {
3350         prefs_pages = g_slist_remove(prefs_pages, page);
3351 }