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