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