2005-02-25 [paul] 1.0.1cvs19.1
[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 gboolean can_close_func(PrefsPage *page_)
662 {       
663         return prefs_account_apply() >= 0;
664 }
665
666 static void save_func(PrefsPage * _page)
667 {
668         if (prefs_account_apply() >= 0)
669                 cancelled = FALSE;
670 }
671
672 void prefs_account_init()
673 {
674         static gchar *path[2];
675
676         path[0] = _("Account");
677         path[2] = NULL;
678         
679         account_page.page.path = path;
680         account_page.page.weight = 1000.0;
681         account_page.page.create_widget = create_widget_func;
682         account_page.page.destroy_widget = destroy_widget_func;
683         account_page.page.save_page = save_func;
684         account_page.page.can_close = can_close_func;
685
686         prefs_account_register_page((PrefsPage *) &account_page);
687 }
688
689 PrefsAccount *prefs_account_new(void)
690 {
691         PrefsAccount *ac_prefs;
692
693         ac_prefs = g_new0(PrefsAccount, 1);
694         memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
695         prefs_set_default(param);
696         *ac_prefs = tmp_ac_prefs;
697         ac_prefs->account_id = prefs_account_get_new_id();
698
699         ac_prefs->privacy_prefs = g_hash_table_new(g_str_hash, g_str_equal);
700
701         return ac_prefs;
702 }
703
704 void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
705 {
706         const guchar *p = label;
707         gchar *rcpath;
708         gint id;
709         gchar **strv, **cur;
710
711         g_return_if_fail(ac_prefs != NULL);
712         g_return_if_fail(label != NULL);
713
714         memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
715         tmp_ac_prefs.privacy_prefs = ac_prefs->privacy_prefs;
716
717         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
718         prefs_read_config(param, label, rcpath, NULL);
719         g_free(rcpath);
720
721         *ac_prefs = tmp_ac_prefs;
722         while (*p && !isdigit(*p)) p++;
723         id = atoi(p);
724         if (id < 0) g_warning("wrong account id: %d\n", id);
725         ac_prefs->account_id = id;
726
727         if (ac_prefs->protocol == A_APOP) {
728                 debug_print("converting protocol A_APOP to new prefs.\n");
729                 ac_prefs->protocol = A_POP3;
730                 ac_prefs->use_apop_auth = TRUE;
731         }
732
733         if (privacy_prefs != NULL) {
734                 strv = g_strsplit(privacy_prefs, ",", 0);
735                 for (cur = strv; *cur != NULL; cur++) {
736                         gchar *encvalue, *value;
737
738                         encvalue = strchr(*cur, '=');
739                         if (encvalue == NULL)
740                                 continue;
741                         encvalue[0] = '\0';
742                         encvalue++;
743
744                         value = g_malloc0(strlen(encvalue));
745                         if (base64_decode(value, encvalue, strlen(encvalue)) > 0)
746                                 g_hash_table_insert(ac_prefs->privacy_prefs, g_strdup(*cur), g_strdup(value));
747                         g_free(value);
748                 }
749                 g_strfreev(strv);
750                 g_free(privacy_prefs);
751                 privacy_prefs = NULL;
752         }
753
754         prefs_custom_header_read_config(ac_prefs);
755 }
756
757 static void create_privacy_prefs(gpointer key, gpointer _value, gpointer user_data)
758 {
759         GString *str = (GString *) user_data;
760         gchar *encvalue;
761         gchar *value = (gchar *) _value;
762
763         if (str->len > 0)
764                 g_string_append_c(str, ',');
765
766         encvalue = g_malloc0(B64LEN(strlen(value)) + 1);
767         base64_encode(encvalue, (gchar *) value, strlen(value));
768         g_string_sprintfa(str, "%s=%s", (gchar *) key, encvalue);
769         g_free(encvalue);
770 }
771
772 void prefs_account_write_config_all(GList *account_list)
773 {
774         GList *cur;
775         gchar *rcpath;
776         PrefFile *pfile;
777
778         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
779         if ((pfile = prefs_write_open(rcpath)) == NULL) {
780                 g_free(rcpath);
781                 return;
782         }
783         g_free(rcpath);
784
785         for (cur = account_list; cur != NULL; cur = cur->next) {
786                 GString *str;
787
788                 tmp_ac_prefs = *(PrefsAccount *)cur->data;
789                 if (fprintf(pfile->fp, "[Account: %d]\n",
790                             tmp_ac_prefs.account_id) <= 0)
791                         return;
792
793                 str = g_string_sized_new(32);
794                 g_hash_table_foreach(tmp_ac_prefs.privacy_prefs, create_privacy_prefs, str);
795                 privacy_prefs = str->str;                   
796                 g_string_free(str, FALSE);
797
798                 if (prefs_write_param(param, pfile->fp) < 0) {
799                         g_warning("failed to write configuration to file\n");
800                         prefs_file_close_revert(pfile);
801                         g_free(privacy_prefs);
802                         privacy_prefs = NULL;
803                         return;
804                 }
805                 g_free(privacy_prefs);
806                 privacy_prefs = NULL;
807
808                 if (cur->next) {
809                         if (fputc('\n', pfile->fp) == EOF) {
810                                 FILE_OP_ERROR(rcpath, "fputc");
811                                 prefs_file_close_revert(pfile);
812                                 return;
813                         }
814                 }
815         }
816
817         if (prefs_file_close(pfile) < 0)
818                 g_warning("failed to write configuration to file\n");
819 }
820
821 static gboolean free_privacy_prefs(gpointer key, gpointer value, gpointer user_data)
822 {
823         g_free(key);
824         g_free(value);
825
826         return TRUE;
827 }
828
829 void prefs_account_free(PrefsAccount *ac_prefs)
830 {
831         if (!ac_prefs) return;
832
833         g_hash_table_foreach_remove(ac_prefs->privacy_prefs, free_privacy_prefs, NULL);
834
835         tmp_ac_prefs = *ac_prefs;
836         prefs_free(param);
837 }
838
839 const gchar *prefs_account_get_privacy_prefs(PrefsAccount *account, gchar *id)
840 {
841         return g_hash_table_lookup(account->privacy_prefs, id);
842 }
843
844 void prefs_account_set_privacy_prefs(PrefsAccount *account, gchar *id, gchar *new_value)
845 {
846         gchar *orig_key = NULL, *value;
847
848         if (g_hash_table_lookup_extended(account->privacy_prefs, id, (gpointer *) &orig_key, (gpointer *) &value)) {
849                 g_hash_table_remove(account->privacy_prefs, id);
850
851                 g_free(orig_key);
852                 g_free(value);
853         }
854
855         if (new_value != NULL)
856                 g_hash_table_insert(account->privacy_prefs, g_strdup(id), g_strdup(new_value));
857 }
858
859 static gint prefs_account_get_new_id(void)
860 {
861         GList *ac_list;
862         PrefsAccount *ac;
863         static gint last_id = 0;
864
865         for (ac_list = account_get_list(); ac_list != NULL;
866              ac_list = ac_list->next) {
867                 ac = (PrefsAccount *)ac_list->data;
868                 if (last_id < ac->account_id)
869                         last_id = ac->account_id;
870         }
871
872         return last_id + 1;
873 }
874
875 void destroy_dialog(gpointer data)
876 {
877         PrefsAccount *ac_prefs = (PrefsAccount *) data;
878         if (!cancelled)
879                 *ac_prefs = tmp_ac_prefs;
880
881         gtk_main_quit();
882 }
883
884 PrefsAccount *prefs_account_open(PrefsAccount *ac_prefs)
885 {
886         gchar *title;
887
888         if (prefs_rc_is_readonly(ACCOUNT_RC))
889                 return ac_prefs;
890
891         debug_print("Opening account preferences window...\n");
892
893         inc_lock();
894
895         cancelled = TRUE;
896
897         if (!ac_prefs) {
898                 ac_prefs = prefs_account_new();
899                 new_account = TRUE;
900         } else
901                 new_account = FALSE;
902
903         if (new_account)
904                 title = g_strdup (_("Preferences for new account"));
905         else
906                 title = g_strdup_printf (_("%s - Account preferences"),
907                                 ac_prefs->account_name);
908
909         prefswindow_open_full(title, prefs_pages, ac_prefs, destroy_dialog);
910         g_free(title);
911         gtk_main();
912
913         inc_unlock();
914
915         if (cancelled && new_account) {
916                 prefs_account_free(ac_prefs);
917                 return NULL;
918         } else 
919                 return ac_prefs;
920 }
921
922 static void prefs_account_create(void)
923 {
924         gint page = 0;
925
926         debug_print("Creating account preferences window...\n");
927
928         notebook = gtk_notebook_new ();
929         gtk_widget_show(notebook);
930         gtk_container_set_border_width (GTK_CONTAINER (notebook), 2);
931         /* GTK_WIDGET_UNSET_FLAGS (notebook, GTK_CAN_FOCUS); */
932         gtk_notebook_set_scrollable (GTK_NOTEBOOK (notebook), TRUE);
933         
934         gtk_notebook_popup_enable (GTK_NOTEBOOK (notebook));
935
936         gtk_widget_ref(notebook);
937
938         /* create all widgets on notebook */
939         prefs_account_basic_create();
940         SET_NOTEBOOK_LABEL(notebook, _("Basic"), page++);
941         prefs_account_receive_create();
942         SET_NOTEBOOK_LABEL(notebook, _("Receive"), page++);
943         prefs_account_send_create();
944         SET_NOTEBOOK_LABEL(notebook, _("Send"), page++);
945         prefs_account_compose_create();
946         SET_NOTEBOOK_LABEL(notebook, _("Compose"), page++);
947         prefs_account_privacy_create();
948         SET_NOTEBOOK_LABEL(notebook, _("Privacy"), page++);
949 #if USE_OPENSSL
950         prefs_account_ssl_create();
951         SET_NOTEBOOK_LABEL(notebook, _("SSL"), page++);
952 #endif /* USE_OPENSSL */
953         prefs_account_advanced_create();
954         SET_NOTEBOOK_LABEL(notebook, _("Advanced"), page++);
955
956         prefs_account_fix_size();
957 }
958
959 /**
960  * prefs_account_fix_size:
961  * 
962  * Fix the window size after creating widgets by selecting "Local"
963  * protocol (currently it has the largest size of parameter widgets).
964  * Without this the window gets too large.
965  **/
966 static void prefs_account_fix_size(void)
967 {
968         GtkOptionMenu *optmenu = GTK_OPTION_MENU (basic.protocol_optmenu);
969         GtkWidget *menu;
970         GtkWidget *menuitem;
971
972         gtk_option_menu_set_history (optmenu, 4); /* local */
973         menu = gtk_option_menu_get_menu (optmenu);
974         menuitem = gtk_menu_get_active (GTK_MENU (menu));
975         gtk_menu_item_activate (GTK_MENU_ITEM (menuitem));
976 }
977
978 #define SET_ACTIVATE(menuitem) \
979 { \
980         g_signal_connect(G_OBJECT(menuitem), "activate", \
981                          G_CALLBACK(prefs_account_protocol_activated), \
982                          NULL); \
983 }
984
985 #define TABLE_YPAD 2
986
987 static void prefs_account_basic_create(void)
988 {
989         GtkWidget *vbox1;
990         GtkWidget *hbox;
991         GtkWidget *label;
992         GtkWidget *acname_entry;
993         GtkWidget *default_chkbtn;
994         GtkWidget *frame1;
995         GtkWidget *table1;
996         GtkWidget *name_entry;
997         GtkWidget *addr_entry;
998         GtkWidget *org_entry;
999
1000         GtkWidget *serv_frame;
1001         GtkWidget *vbox2;
1002         GtkWidget *optmenu;
1003         GtkWidget *optmenu_menu;
1004         GtkWidget *menuitem;
1005         GtkWidget *serv_table;
1006         GtkWidget *recvserv_label;
1007         GtkWidget *smtpserv_label;
1008         GtkWidget *nntpserv_label;
1009         GtkWidget *localmbox_label;
1010         GtkWidget *mailcmd_label;
1011         GtkWidget *recvserv_entry;
1012         GtkWidget *smtpserv_entry;
1013         GtkWidget *nntpserv_entry;
1014         GtkWidget *nntpauth_chkbtn;
1015         GtkWidget *nntpauth_onconnect_chkbtn;
1016         GtkWidget *localmbox_entry;
1017         GtkWidget *mailcmd_chkbtn;
1018         GtkWidget *mailcmd_entry;
1019         GtkWidget *uid_label;
1020         GtkWidget *pass_label;
1021         GtkWidget *uid_entry;
1022         GtkWidget *pass_entry;
1023
1024         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1025         gtk_widget_show (vbox1);
1026         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1027         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1028
1029         hbox = gtk_hbox_new (FALSE, 8);
1030         gtk_widget_show (hbox);
1031         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
1032
1033         label = gtk_label_new (_("Name of account"));
1034         gtk_widget_show (label);
1035         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1036
1037         acname_entry = gtk_entry_new ();
1038         gtk_widget_show (acname_entry);
1039         gtk_widget_set_size_request (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
1040         gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
1041
1042         default_chkbtn = gtk_check_button_new_with_label (_("Set as default"));
1043         gtk_widget_show (default_chkbtn);
1044         gtk_box_pack_end (GTK_BOX (hbox), default_chkbtn, FALSE, FALSE, 0);
1045
1046         PACK_FRAME (vbox1, frame1, _("Personal information"));
1047
1048         table1 = gtk_table_new (3, 2, FALSE);
1049         gtk_widget_show (table1);
1050         gtk_container_add (GTK_CONTAINER (frame1), table1);
1051         gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
1052         gtk_table_set_row_spacings (GTK_TABLE (table1), VSPACING_NARROW);
1053         gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
1054
1055         label = gtk_label_new (_("Full name"));
1056         gtk_widget_show (label);
1057         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 0, 1,
1058                           GTK_FILL, 0, 0, 0);
1059         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
1060
1061         label = gtk_label_new (_("Mail address"));
1062         gtk_widget_show (label);
1063         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 1, 2,
1064                           GTK_FILL, 0, 0, 0);
1065         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
1066
1067         label = gtk_label_new (_("Organization"));
1068         gtk_widget_show (label);
1069         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 2, 3,
1070                           GTK_FILL, 0, 0, 0);
1071         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
1072
1073         name_entry = gtk_entry_new ();
1074         gtk_widget_show (name_entry);
1075         gtk_table_attach (GTK_TABLE (table1), name_entry, 1, 2, 0, 1,
1076                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1077                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1078
1079         addr_entry = gtk_entry_new ();
1080         gtk_widget_show (addr_entry);
1081         gtk_table_attach (GTK_TABLE (table1), addr_entry, 1, 2, 1, 2,
1082                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1083                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1084
1085         org_entry = gtk_entry_new ();
1086         gtk_widget_show (org_entry);
1087         gtk_table_attach (GTK_TABLE (table1), org_entry, 1, 2, 2, 3,
1088                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1089                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1090
1091         PACK_FRAME (vbox1, serv_frame, _("Server information"));
1092
1093         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
1094         gtk_widget_show (vbox2);
1095         gtk_container_add (GTK_CONTAINER (serv_frame), vbox2);
1096         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1097
1098         hbox = gtk_hbox_new (FALSE, 8);
1099         gtk_widget_show (hbox);
1100         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1101
1102         label = gtk_label_new (_("Protocol"));
1103         gtk_widget_show (label);
1104         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1105
1106         optmenu = gtk_option_menu_new ();
1107         gtk_widget_show (optmenu);
1108         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
1109
1110         optmenu_menu = gtk_menu_new ();
1111
1112         MENUITEM_ADD (optmenu_menu, menuitem, _("POP3"),  A_POP3);
1113         SET_ACTIVATE (menuitem);
1114         MENUITEM_ADD (optmenu_menu, menuitem, _("IMAP4"), A_IMAP4);
1115         SET_ACTIVATE (menuitem);
1116         MENUITEM_ADD (optmenu_menu, menuitem, _("News (NNTP)"), A_NNTP);
1117         SET_ACTIVATE (menuitem);
1118         MENUITEM_ADD (optmenu_menu, menuitem, _("Local mbox file"), A_LOCAL);
1119         SET_ACTIVATE (menuitem);
1120         MENUITEM_ADD (optmenu_menu, menuitem, _("None (SMTP only)"), A_NONE);
1121         SET_ACTIVATE (menuitem);
1122
1123         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1124
1125         serv_table = gtk_table_new (6, 4, FALSE);
1126         gtk_widget_show (serv_table);
1127         gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
1128         gtk_table_set_row_spacings (GTK_TABLE (serv_table), VSPACING_NARROW);
1129         gtk_table_set_row_spacing (GTK_TABLE (serv_table), 3, 0);
1130         gtk_table_set_col_spacings (GTK_TABLE (serv_table), 8);
1131
1132         nntpserv_entry = gtk_entry_new ();
1133         gtk_widget_show (nntpserv_entry);
1134         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_entry, 1, 4, 0, 1,
1135                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1136                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1137 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 0, 0); */
1138
1139         nntpauth_chkbtn = gtk_check_button_new_with_label
1140                 (_("This server requires authentication"));
1141         gtk_widget_show (nntpauth_chkbtn);
1142         
1143         gtk_table_attach (GTK_TABLE (serv_table), nntpauth_chkbtn, 0, 2, 1, 2,
1144                           GTK_FILL, 0, 0, 0);
1145
1146         nntpauth_onconnect_chkbtn = gtk_check_button_new_with_label
1147                 (_("Authenticate on connect"));
1148         gtk_widget_show (nntpauth_onconnect_chkbtn);
1149
1150         gtk_table_attach (GTK_TABLE (serv_table), nntpauth_onconnect_chkbtn, 2, 4, 1, 2,
1151                           GTK_FILL, 0, 0, 0);
1152
1153         recvserv_entry = gtk_entry_new ();
1154         gtk_widget_show (recvserv_entry);
1155         gtk_table_attach (GTK_TABLE (serv_table), recvserv_entry, 1, 4, 2, 3,
1156                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1157                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1158
1159         localmbox_entry = gtk_entry_new ();
1160         gtk_widget_show (localmbox_entry);
1161         gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 3, 4,
1162                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1163                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1164
1165         smtpserv_entry = gtk_entry_new ();
1166         gtk_widget_show (smtpserv_entry);
1167         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_entry, 1, 4, 4, 5,
1168                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1169                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1170
1171         mailcmd_entry = gtk_entry_new ();
1172         gtk_widget_show (mailcmd_entry);
1173         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 6, 7,
1174                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1175                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1176
1177         uid_entry = gtk_entry_new ();
1178         gtk_widget_show (uid_entry);
1179         gtk_widget_set_size_request (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1180         gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 2, 7, 8,
1181                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1182                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1183
1184         pass_entry = gtk_entry_new ();
1185         gtk_widget_show (pass_entry);
1186         gtk_widget_set_size_request (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1187         gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 3, 4, 7, 8,
1188                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1189                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1190         gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
1191
1192         nntpserv_label = gtk_label_new (_("News server"));
1193         gtk_widget_show (nntpserv_label);
1194         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_label, 0, 1, 0, 1,
1195                           GTK_FILL, 0, 0, 0);
1196         gtk_misc_set_alignment (GTK_MISC (nntpserv_label), 1, 0.5);
1197
1198         recvserv_label = gtk_label_new (_("Server for receiving"));
1199         gtk_widget_show (recvserv_label);
1200         gtk_table_attach (GTK_TABLE (serv_table), recvserv_label, 0, 1, 2, 3,
1201                           GTK_FILL, 0, 0, 0);
1202         gtk_misc_set_alignment (GTK_MISC (recvserv_label), 1, 0.5);
1203
1204         localmbox_label = gtk_label_new (_("Local mailbox"));
1205         gtk_widget_show (localmbox_label);
1206         gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 3, 4,
1207                           GTK_FILL, 0, 0, 0);
1208         gtk_misc_set_alignment (GTK_MISC (localmbox_label), 1, 0.5);
1209 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1210
1211         smtpserv_label = gtk_label_new (_("SMTP server (send)"));
1212         gtk_widget_show (smtpserv_label);
1213         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_label, 0, 1, 4, 5,
1214                           GTK_FILL, 0, 0, 0);
1215         gtk_misc_set_alignment (GTK_MISC (smtpserv_label), 1, 0.5);
1216 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1217
1218         mailcmd_chkbtn = gtk_check_button_new_with_label
1219                 (_("Use mail command rather than SMTP server"));
1220         gtk_widget_show (mailcmd_chkbtn);
1221         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_chkbtn, 0, 4, 5, 6,
1222                           GTK_EXPAND | GTK_FILL,
1223                           0, 0, TABLE_YPAD);
1224         g_signal_connect(G_OBJECT(mailcmd_chkbtn), "toggled",
1225                          G_CALLBACK(prefs_account_mailcmd_toggled),
1226                          NULL);
1227
1228         mailcmd_label = gtk_label_new (_("command to send mails"));
1229         gtk_widget_show (mailcmd_label);
1230         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 6, 7,
1231                           GTK_FILL, 0, 0, 0);
1232         gtk_misc_set_alignment (GTK_MISC (mailcmd_label), 1, 0.5);
1233 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1234
1235         uid_label = gtk_label_new (_("User ID"));
1236         gtk_widget_show (uid_label);
1237         gtk_table_attach (GTK_TABLE (serv_table), uid_label, 0, 1, 7, 8,
1238                           GTK_FILL, 0, 0, 0);
1239         gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
1240
1241         pass_label = gtk_label_new (_("Password"));
1242         gtk_widget_show (pass_label);
1243         gtk_table_attach (GTK_TABLE (serv_table), pass_label, 2, 3, 7, 8,
1244                           0, 0, 0, 0);
1245
1246         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, uid_label);
1247         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, pass_label);
1248         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, uid_entry);
1249         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, pass_entry);
1250         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, nntpauth_onconnect_chkbtn);
1251
1252         basic.acname_entry   = acname_entry;
1253         basic.default_chkbtn = default_chkbtn;
1254
1255         basic.name_entry = name_entry;
1256         basic.addr_entry = addr_entry;
1257         basic.org_entry  = org_entry;
1258
1259         basic.serv_frame       = serv_frame;
1260         basic.serv_table       = serv_table;
1261         basic.protocol_optmenu = optmenu;
1262         basic.recvserv_label   = recvserv_label;
1263         basic.recvserv_entry   = recvserv_entry;
1264         basic.smtpserv_label   = smtpserv_label;
1265         basic.smtpserv_entry   = smtpserv_entry;
1266         basic.nntpserv_label   = nntpserv_label;
1267         basic.nntpserv_entry   = nntpserv_entry;
1268         basic.nntpauth_chkbtn  = nntpauth_chkbtn;
1269         basic.nntpauth_onconnect_chkbtn  = nntpauth_onconnect_chkbtn;
1270         basic.localmbox_label   = localmbox_label;
1271         basic.localmbox_entry   = localmbox_entry;
1272         basic.mailcmd_chkbtn   = mailcmd_chkbtn;
1273         basic.mailcmd_label   = mailcmd_label;
1274         basic.mailcmd_entry   = mailcmd_entry;
1275         basic.uid_label        = uid_label;
1276         basic.pass_label       = pass_label;
1277         basic.uid_entry        = uid_entry;
1278         basic.pass_entry       = pass_entry;
1279 }
1280
1281 static void prefs_account_receive_create(void)
1282 {
1283         GtkWidget *vbox1;
1284         GtkWidget *frame1;
1285         GtkWidget *vbox2;
1286         GtkWidget *use_apop_chkbtn;
1287         GtkWidget *rmmail_chkbtn;
1288         GtkWidget *hbox_spc;
1289         GtkWidget *leave_time_label;
1290         GtkWidget *leave_time_entry;
1291         GtkWidget *getall_chkbtn;
1292         GtkWidget *hbox1;
1293         GtkWidget *size_limit_chkbtn;
1294         GtkWidget *size_limit_entry;
1295         GtkWidget *label;
1296         GtkWidget *filter_on_recv_chkbtn;
1297         GtkWidget *vbox3;
1298         GtkWidget *inbox_label;
1299         GtkWidget *inbox_entry;
1300         GtkWidget *inbox_btn;
1301         GtkWidget *imap_frame;
1302         GtkWidget *optmenu;
1303         GtkWidget *optmenu_menu;
1304         GtkWidget *menuitem;
1305         GtkWidget *recvatgetall_chkbtn;
1306
1307         GtkWidget *hbox2;
1308         GtkWidget *frame2;
1309         GtkWidget *label_maxarticle;
1310         GtkWidget *spinbtn_maxarticle;
1311         GtkObject *spinbtn_maxarticle_adj;
1312
1313         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1314         gtk_widget_show (vbox1);
1315         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1316         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1317
1318         PACK_FRAME (vbox1, frame1, _("POP3"));
1319
1320         vbox2 = gtk_vbox_new (FALSE, 0);
1321         gtk_widget_show (vbox2);
1322         gtk_container_add (GTK_CONTAINER (frame1), vbox2);
1323         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1324
1325         PACK_CHECK_BUTTON (vbox2, use_apop_chkbtn,
1326                            _("Use secure authentication (APOP)"));
1327
1328         PACK_CHECK_BUTTON (vbox2, rmmail_chkbtn,
1329                            _("Remove messages on server when received"));
1330
1331         hbox1 = gtk_hbox_new (FALSE, 8);
1332         gtk_widget_show (hbox1);
1333         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1334
1335         hbox_spc = gtk_hbox_new (FALSE, 0);
1336         gtk_widget_show (hbox_spc);
1337         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1338         gtk_widget_set_size_request (hbox_spc, 12, -1);
1339
1340         leave_time_label = gtk_label_new (_("Remove after"));
1341         gtk_widget_show (leave_time_label);
1342         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1343
1344         leave_time_entry = gtk_entry_new ();
1345         gtk_widget_show (leave_time_entry);
1346         gtk_widget_set_size_request (leave_time_entry, 64, -1);
1347         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_entry, FALSE, FALSE, 0);
1348
1349         leave_time_label = gtk_label_new (_("days"));
1350         gtk_widget_show (leave_time_label);
1351         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1352
1353         SET_TOGGLE_SENSITIVITY (rmmail_chkbtn, hbox1);
1354
1355         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1356
1357         hbox1 = gtk_hbox_new (FALSE, 8);
1358         gtk_widget_show (hbox1);
1359         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1360
1361         hbox_spc = gtk_hbox_new (FALSE, 0);
1362         gtk_widget_show (hbox_spc);
1363         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1364         gtk_widget_set_size_request (hbox_spc, 12, -1);
1365
1366         leave_time_label = gtk_label_new (_("(0 days: remove immediately)"));
1367         gtk_label_set_justify (GTK_LABEL (leave_time_label), GTK_JUSTIFY_LEFT);
1368         gtkut_widget_set_small_font_size (leave_time_label);
1369         gtk_widget_show (leave_time_label);
1370         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1371
1372         SET_TOGGLE_SENSITIVITY (rmmail_chkbtn, hbox1);
1373
1374         PACK_CHECK_BUTTON (vbox2, getall_chkbtn,
1375                            _("Download all messages on server"));
1376
1377         hbox1 = gtk_hbox_new (FALSE, 8);
1378         gtk_widget_show (hbox1);
1379         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1380
1381         PACK_CHECK_BUTTON (hbox1, size_limit_chkbtn, _("Receive size limit"));
1382
1383         size_limit_entry = gtk_entry_new ();
1384         gtk_widget_show (size_limit_entry);
1385         gtk_widget_set_size_request (size_limit_entry, 64, -1);
1386         gtk_box_pack_start (GTK_BOX (hbox1), size_limit_entry, FALSE, FALSE, 0);
1387
1388         label = gtk_label_new (_("KB"));
1389         gtk_widget_show (label);
1390         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1391
1392         SET_TOGGLE_SENSITIVITY (size_limit_chkbtn, size_limit_entry);
1393
1394         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1395
1396         hbox1 = gtk_hbox_new (FALSE, 8);
1397         gtk_widget_show (hbox1);
1398         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1399
1400         inbox_label = gtk_label_new (_("Default inbox"));
1401         gtk_widget_show (inbox_label);
1402         gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
1403
1404         inbox_entry = gtk_entry_new ();
1405         gtk_widget_show (inbox_entry);
1406         gtk_widget_set_size_request (inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
1407         gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
1408
1409         inbox_btn = gtk_button_new_with_label (_(" Select... "));
1410         gtk_widget_show (inbox_btn);
1411         gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1412         g_signal_connect (G_OBJECT (inbox_btn), "clicked",
1413                           G_CALLBACK (prefs_account_select_folder_cb),
1414                           inbox_entry);
1415
1416         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1417
1418         hbox1 = gtk_hbox_new (FALSE, 8);
1419         gtk_widget_show (hbox1);
1420         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1421
1422         label = gtk_label_new
1423                 (_("(Unfiltered messages will be stored in this folder)"));
1424         gtk_widget_show (label);
1425         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1426         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1427         gtkut_widget_set_small_font_size (label);
1428
1429         PACK_FRAME(vbox1, frame2, _("Maximum number of articles to download"));
1430
1431         hbox2 = gtk_hbox_new (FALSE, 8);
1432         gtk_widget_show (hbox2);
1433         gtk_container_add (GTK_CONTAINER (frame2), hbox2);
1434         gtk_container_set_border_width (GTK_CONTAINER (hbox2), 8);
1435
1436         spinbtn_maxarticle_adj =
1437                 gtk_adjustment_new (300, 0, 10000, 10, 100, 100);
1438         spinbtn_maxarticle = gtk_spin_button_new
1439                 (GTK_ADJUSTMENT (spinbtn_maxarticle_adj), 10, 0);
1440         gtk_widget_show (spinbtn_maxarticle);
1441         gtk_box_pack_start (GTK_BOX (hbox2), spinbtn_maxarticle,
1442                             FALSE, FALSE, 0);
1443         gtk_widget_set_size_request (spinbtn_maxarticle, 64, -1);
1444         gtk_spin_button_set_numeric
1445                 (GTK_SPIN_BUTTON (spinbtn_maxarticle), TRUE);
1446
1447         label_maxarticle = gtk_label_new
1448                 (_("unlimited if 0 is specified"));
1449         gtk_widget_show (label_maxarticle);
1450         gtk_box_pack_start (GTK_BOX (hbox2), label_maxarticle, FALSE, FALSE, 0);
1451         gtk_label_set_justify (GTK_LABEL (label_maxarticle), GTK_JUSTIFY_LEFT);
1452
1453         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
1454
1455         vbox2 = gtk_vbox_new (FALSE, 0);
1456         gtk_widget_show (vbox2);
1457         gtk_container_add (GTK_CONTAINER (imap_frame), vbox2);
1458         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1459
1460         hbox1 = gtk_hbox_new (FALSE, 8);
1461         gtk_widget_show (hbox1);
1462         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1463
1464         label = gtk_label_new (_("Authentication method"));
1465         gtk_widget_show (label);
1466         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1467
1468         optmenu = gtk_option_menu_new ();
1469         gtk_widget_show (optmenu);
1470         gtk_box_pack_start (GTK_BOX (hbox1), optmenu, FALSE, FALSE, 0);
1471
1472         optmenu_menu = gtk_menu_new ();
1473
1474         MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
1475         MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", IMAP_AUTH_LOGIN);
1476         MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", IMAP_AUTH_CRAM_MD5);
1477
1478         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1479
1480         PACK_CHECK_BUTTON (vbox1, filter_on_recv_chkbtn,
1481                            _("Filter messages on receiving"));
1482
1483         PACK_CHECK_BUTTON
1484                 (vbox1, recvatgetall_chkbtn,
1485                  _("`Get all' checks for new messages on this account"));
1486
1487         receive.pop3_frame               = frame1;
1488         receive.use_apop_chkbtn          = use_apop_chkbtn;
1489         receive.rmmail_chkbtn            = rmmail_chkbtn;
1490         receive.leave_time_entry         = leave_time_entry;
1491         receive.getall_chkbtn            = getall_chkbtn;
1492         receive.size_limit_chkbtn        = size_limit_chkbtn;
1493         receive.size_limit_entry         = size_limit_entry;
1494         receive.filter_on_recv_chkbtn    = filter_on_recv_chkbtn;
1495         receive.inbox_label              = inbox_label;
1496         receive.inbox_entry              = inbox_entry;
1497         receive.inbox_btn                = inbox_btn;
1498
1499         receive.imap_frame               = imap_frame;
1500         receive.imap_auth_type_optmenu   = optmenu;
1501
1502         receive.recvatgetall_chkbtn      = recvatgetall_chkbtn;
1503
1504         receive.frame_maxarticle        = frame2;
1505         receive.spinbtn_maxarticle      = spinbtn_maxarticle;
1506         receive.spinbtn_maxarticle_adj  = spinbtn_maxarticle_adj;
1507 }
1508
1509 static void prefs_account_send_create(void)
1510 {
1511         GtkWidget *vbox1;
1512         GtkWidget *vbox2;
1513         GtkWidget *frame;
1514         GtkWidget *date_chkbtn;
1515         GtkWidget *msgid_chkbtn;
1516         GtkWidget *hbox;
1517         GtkWidget *customhdr_chkbtn;
1518         GtkWidget *customhdr_edit_btn;
1519         GtkWidget *vbox3;
1520         GtkWidget *smtp_auth_chkbtn;
1521         GtkWidget *optmenu;
1522         GtkWidget *optmenu_menu;
1523         GtkWidget *menuitem;
1524         GtkWidget *vbox4;
1525         GtkWidget *hbox_spc;
1526         GtkWidget *label;
1527         GtkWidget *smtp_uid_entry;
1528         GtkWidget *smtp_pass_entry;
1529         GtkWidget *vbox_spc;
1530         GtkWidget *pop_bfr_smtp_chkbtn;
1531         GtkWidget *pop_bfr_smtp_tm_entry;
1532
1533         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1534         gtk_widget_show (vbox1);
1535         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1536         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1537
1538         PACK_FRAME (vbox1, frame, _("Header"));
1539
1540         vbox2 = gtk_vbox_new (FALSE, 0);
1541         gtk_widget_show (vbox2);
1542         gtk_container_add (GTK_CONTAINER (frame), vbox2);
1543         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1544
1545         PACK_CHECK_BUTTON (vbox2, date_chkbtn, _("Add Date"));
1546         PACK_CHECK_BUTTON (vbox2, msgid_chkbtn, _("Generate Message-ID"));
1547
1548         hbox = gtk_hbox_new (FALSE, 12);
1549         gtk_widget_show (hbox);
1550         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1551
1552         PACK_CHECK_BUTTON (hbox, customhdr_chkbtn,
1553                            _("Add user-defined header"));
1554
1555         customhdr_edit_btn = gtk_button_new_with_label (_(" Edit... "));
1556         gtk_widget_show (customhdr_edit_btn);
1557         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1558                             FALSE, FALSE, 0);
1559         g_signal_connect (G_OBJECT (customhdr_edit_btn), "clicked",
1560                           G_CALLBACK (prefs_account_edit_custom_header),
1561                           NULL);
1562
1563         SET_TOGGLE_SENSITIVITY (customhdr_chkbtn, customhdr_edit_btn);
1564
1565         PACK_FRAME (vbox1, frame, _("Authentication"));
1566
1567         vbox3 = gtk_vbox_new (FALSE, 0);
1568         gtk_widget_show (vbox3);
1569         gtk_container_add (GTK_CONTAINER (frame), vbox3);
1570         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1571
1572         PACK_CHECK_BUTTON (vbox3, smtp_auth_chkbtn,
1573                 _("SMTP Authentication (SMTP AUTH)"));
1574
1575         vbox4 = gtk_vbox_new (FALSE, 0);
1576         gtk_widget_show (vbox4);
1577         gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
1578
1579         hbox = gtk_hbox_new (FALSE, 8);
1580         gtk_widget_show (hbox);
1581         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1582
1583         hbox_spc = gtk_hbox_new (FALSE, 0);
1584         gtk_widget_show (hbox_spc);
1585         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1586         gtk_widget_set_size_request (hbox_spc, 12, -1);
1587
1588         label = gtk_label_new (_("Authentication method"));
1589         gtk_widget_show (label);
1590         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1591
1592         optmenu = gtk_option_menu_new ();
1593         gtk_widget_show (optmenu);
1594         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
1595
1596         optmenu_menu = gtk_menu_new ();
1597
1598         MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
1599         MENUITEM_ADD (optmenu_menu, menuitem, "PLAIN", SMTPAUTH_PLAIN);
1600         MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", SMTPAUTH_LOGIN);
1601         MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
1602         MENUITEM_ADD (optmenu_menu, menuitem, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
1603         gtk_widget_set_sensitive (menuitem, FALSE);
1604
1605         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1606
1607         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1608
1609         hbox = gtk_hbox_new (FALSE, 8);
1610         gtk_widget_show (hbox);
1611         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1612
1613         hbox_spc = gtk_hbox_new (FALSE, 0);
1614         gtk_widget_show (hbox_spc);
1615         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1616         gtk_widget_set_size_request (hbox_spc, 12, -1);
1617
1618         label = gtk_label_new (_("User ID"));
1619         gtk_widget_show (label);
1620         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1621
1622         smtp_uid_entry = gtk_entry_new ();
1623         gtk_widget_show (smtp_uid_entry);
1624         gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1625         gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
1626
1627         label = gtk_label_new (_("Password"));
1628         gtk_widget_show (label);
1629         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1630
1631         smtp_pass_entry = gtk_entry_new ();
1632         gtk_widget_show (smtp_pass_entry);
1633         gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1634         gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
1635         gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
1636
1637         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1638
1639         hbox = gtk_hbox_new (FALSE, 8);
1640         gtk_widget_show (hbox);
1641         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1642
1643         hbox_spc = gtk_hbox_new (FALSE, 0);
1644         gtk_widget_show (hbox_spc);
1645         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1646         gtk_widget_set_size_request (hbox_spc, 12, -1);
1647
1648         label = gtk_label_new
1649                 (_("If you leave these entries empty, the same "
1650                    "user ID and password as receiving will be used."));
1651         gtk_widget_show (label);
1652         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1653         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1654         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1655         gtkut_widget_set_small_font_size (label);
1656
1657         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, vbox4);
1658
1659         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_chkbtn,
1660                 _("Authenticate with POP3 before sending"));
1661         
1662         g_signal_connect (G_OBJECT (pop_bfr_smtp_chkbtn), "clicked",
1663                           G_CALLBACK (pop_bfr_smtp_tm_set_sens),
1664                           NULL);
1665
1666         hbox = gtk_hbox_new (FALSE, 8);
1667         gtk_widget_show (hbox);
1668         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
1669
1670         hbox_spc = gtk_hbox_new (FALSE, 0);
1671         gtk_widget_show (hbox_spc);
1672         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1673         gtk_widget_set_size_request (hbox_spc, 12, -1);
1674
1675         label = gtk_label_new(_("POP authentication timeout: "));
1676         gtk_widget_show (label);
1677         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1678
1679         pop_bfr_smtp_tm_entry = gtk_entry_new ();
1680         gtk_widget_show (pop_bfr_smtp_tm_entry);
1681         gtk_widget_set_size_request (pop_bfr_smtp_tm_entry, 30, -1);
1682         gtk_box_pack_start (GTK_BOX (hbox), pop_bfr_smtp_tm_entry, FALSE, FALSE, 0);
1683
1684         label = gtk_label_new(_("minutes"));
1685         gtk_widget_show (label);
1686         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1687
1688
1689         
1690         p_send.date_chkbtn      = date_chkbtn;
1691         p_send.msgid_chkbtn     = msgid_chkbtn;
1692         p_send.customhdr_chkbtn = customhdr_chkbtn;
1693
1694         p_send.smtp_auth_chkbtn       = smtp_auth_chkbtn;
1695         p_send.smtp_auth_type_optmenu = optmenu;
1696         p_send.smtp_uid_entry         = smtp_uid_entry;
1697         p_send.smtp_pass_entry        = smtp_pass_entry;
1698         p_send.pop_bfr_smtp_chkbtn    = pop_bfr_smtp_chkbtn;
1699         p_send.pop_bfr_smtp_tm_entry  = pop_bfr_smtp_tm_entry;
1700 }
1701
1702 static void prefs_account_compose_create(void)
1703 {
1704         GtkWidget *vbox1;
1705         GtkWidget *sig_hbox;
1706         GtkWidget *hbox1;
1707         GtkWidget *hbox2;
1708         GtkWidget *frame_sig;
1709         GtkWidget *vbox_sig;
1710         GtkWidget *label_sigpath;
1711         GtkWidget *entry_sigpath;
1712         GtkWidget *checkbtn_autosig;
1713         GtkWidget *label_sigsep;
1714         GtkWidget *entry_sigsep;
1715         GtkWidget *sigfile_radiobtn;
1716         GtkWidget *sigcmd_radiobtn;
1717         GtkWidget *frame;
1718         GtkWidget *table;
1719         GtkWidget *autocc_chkbtn;
1720         GtkWidget *autocc_entry;
1721         GtkWidget *autobcc_chkbtn;
1722         GtkWidget *autobcc_entry;
1723         GtkWidget *autoreplyto_chkbtn;
1724         GtkWidget *autoreplyto_entry;
1725
1726         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1727         gtk_widget_show (vbox1);
1728         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1729         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1730
1731         PACK_FRAME(vbox1, frame_sig, _("Signature"));
1732
1733         vbox_sig = gtk_vbox_new (FALSE, VSPACING_NARROW);
1734         gtk_widget_show (vbox_sig);
1735         gtk_container_add (GTK_CONTAINER (frame_sig), vbox_sig);
1736         gtk_container_set_border_width (GTK_CONTAINER (vbox_sig), 8);
1737
1738         PACK_CHECK_BUTTON (vbox_sig, checkbtn_autosig,
1739                            _("Insert signature automatically"));
1740
1741         hbox1 = gtk_hbox_new (FALSE, 8);
1742         gtk_widget_show (hbox1);
1743         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox1, TRUE, TRUE, 0);
1744         label_sigsep = gtk_label_new (_("Signature separator"));
1745         gtk_widget_show (label_sigsep);
1746         gtk_box_pack_start (GTK_BOX (hbox1), label_sigsep, FALSE, FALSE, 0);
1747
1748         entry_sigsep = gtk_entry_new ();
1749         gtk_widget_show (entry_sigsep);
1750         gtk_box_pack_start (GTK_BOX (hbox1), entry_sigsep, FALSE, FALSE, 0);
1751
1752         gtk_widget_set_size_request (entry_sigsep, 64, -1);
1753
1754         sig_hbox = gtk_hbox_new (FALSE, 8);
1755         gtk_widget_show (sig_hbox);
1756         gtk_box_pack_start (GTK_BOX (vbox_sig), sig_hbox, FALSE, FALSE, 0);
1757
1758         sigfile_radiobtn = gtk_radio_button_new_with_label (NULL, _("File"));
1759         gtk_widget_show (sigfile_radiobtn);
1760         gtk_box_pack_start (GTK_BOX (sig_hbox), sigfile_radiobtn,
1761                             FALSE, FALSE, 0);
1762         g_object_set_data (G_OBJECT (sigfile_radiobtn),
1763                            MENU_VAL_ID,
1764                            GINT_TO_POINTER (SIG_FILE));
1765
1766         sigcmd_radiobtn = gtk_radio_button_new_with_label_from_widget
1767                 (GTK_RADIO_BUTTON(sigfile_radiobtn), _("Command output"));
1768         gtk_widget_show (sigcmd_radiobtn);
1769         gtk_box_pack_start (GTK_BOX (sig_hbox), sigcmd_radiobtn,
1770                             FALSE, FALSE, 0);
1771         g_object_set_data (G_OBJECT (sigcmd_radiobtn),
1772                            MENU_VAL_ID,
1773                            GINT_TO_POINTER (SIG_COMMAND));
1774
1775         hbox2 = gtk_hbox_new (FALSE, 8);
1776         gtk_widget_show (hbox2);
1777         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox2, TRUE, TRUE, 0);
1778         label_sigpath = gtk_label_new (_("Signature"));
1779         gtk_widget_show (label_sigpath);
1780         gtk_box_pack_start (GTK_BOX (hbox2), label_sigpath, FALSE, FALSE, 0);
1781
1782         entry_sigpath = gtk_entry_new ();
1783         gtk_widget_show (entry_sigpath);
1784         gtk_box_pack_start (GTK_BOX (hbox2), entry_sigpath, TRUE, TRUE, 0);
1785
1786         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
1787
1788         table =  gtk_table_new (3, 2, FALSE);
1789         gtk_widget_show (table);
1790         gtk_container_add (GTK_CONTAINER (frame), table);
1791         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
1792         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
1793         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1794
1795         autocc_chkbtn = gtk_check_button_new_with_label (_("Cc"));
1796         gtk_widget_show (autocc_chkbtn);
1797         gtk_table_attach (GTK_TABLE (table), autocc_chkbtn, 0, 1, 0, 1,
1798                           GTK_FILL, 0, 0, 0);
1799
1800         autocc_entry = gtk_entry_new ();
1801         gtk_widget_show (autocc_entry);
1802         gtk_table_attach (GTK_TABLE (table), autocc_entry, 1, 2, 0, 1,
1803                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1804                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1805
1806         SET_TOGGLE_SENSITIVITY (autocc_chkbtn, autocc_entry);
1807
1808         autobcc_chkbtn = gtk_check_button_new_with_label (_("Bcc"));
1809         gtk_widget_show (autobcc_chkbtn);
1810         gtk_table_attach (GTK_TABLE (table), autobcc_chkbtn, 0, 1, 1, 2,
1811                           GTK_FILL, 0, 0, 0);
1812
1813         autobcc_entry = gtk_entry_new ();
1814         gtk_widget_show (autobcc_entry);
1815         gtk_table_attach (GTK_TABLE (table), autobcc_entry, 1, 2, 1, 2,
1816                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1817                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1818
1819         SET_TOGGLE_SENSITIVITY (autobcc_chkbtn, autobcc_entry);
1820
1821         autoreplyto_chkbtn = gtk_check_button_new_with_label (_("Reply-To"));
1822         gtk_widget_show (autoreplyto_chkbtn);
1823         gtk_table_attach (GTK_TABLE (table), autoreplyto_chkbtn, 0, 1, 2, 3,
1824                           GTK_FILL, 0, 0, 0);
1825
1826         autoreplyto_entry = gtk_entry_new ();
1827         gtk_widget_show (autoreplyto_entry);
1828         gtk_table_attach (GTK_TABLE (table), autoreplyto_entry, 1, 2, 2, 3,
1829                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1830                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1831
1832         SET_TOGGLE_SENSITIVITY (autoreplyto_chkbtn, autoreplyto_entry);
1833
1834         compose.sigfile_radiobtn = sigfile_radiobtn;
1835         compose.entry_sigpath      = entry_sigpath;
1836         compose.checkbtn_autosig   = checkbtn_autosig;
1837         compose.entry_sigsep       = entry_sigsep;
1838
1839         compose.autocc_chkbtn      = autocc_chkbtn;
1840         compose.autocc_entry       = autocc_entry;
1841         compose.autobcc_chkbtn     = autobcc_chkbtn;
1842         compose.autobcc_entry      = autobcc_entry;
1843         compose.autoreplyto_chkbtn = autoreplyto_chkbtn;
1844         compose.autoreplyto_entry  = autoreplyto_entry;
1845 }
1846
1847 static void prefs_account_privacy_create(void)
1848 {
1849         GtkWidget *vbox1;
1850         GtkWidget *vbox2;
1851         GtkWidget *hbox1;
1852         GtkWidget *label;
1853         GtkWidget *default_privacy_system;
1854         GtkWidget *default_encrypt_chkbtn;
1855         GtkWidget *default_sign_chkbtn;
1856         GtkWidget *save_clear_text_chkbtn;
1857
1858         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1859         gtk_widget_show (vbox1);
1860         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1861         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1862
1863         vbox2 = gtk_vbox_new (FALSE, 0);
1864         gtk_widget_show (vbox2);
1865         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1866
1867         hbox1 = gtk_hbox_new(FALSE, 8);
1868         gtk_widget_show (hbox1);
1869         gtk_container_add (GTK_CONTAINER(vbox2), hbox1);
1870
1871         label = gtk_label_new(_("Default privacy system"));
1872         gtk_widget_show(label);
1873         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1874
1875         default_privacy_system = gtk_option_menu_new();
1876         gtk_widget_show (default_privacy_system);
1877         gtk_box_pack_start (GTK_BOX(hbox1), default_privacy_system, TRUE, TRUE, 0);
1878
1879         PACK_CHECK_BUTTON (vbox2, default_encrypt_chkbtn,
1880                            _("Encrypt message by default"));
1881         PACK_CHECK_BUTTON (vbox2, default_sign_chkbtn,
1882                            _("Sign message by default"));
1883         PACK_CHECK_BUTTON (vbox2, save_clear_text_chkbtn,
1884                            _("Save sent encrypted messages as clear text"));
1885
1886         privacy.default_privacy_system = default_privacy_system;
1887         privacy.default_encrypt_chkbtn = default_encrypt_chkbtn;
1888         privacy.default_sign_chkbtn    = default_sign_chkbtn;
1889         privacy.save_clear_text_chkbtn = save_clear_text_chkbtn;
1890 }
1891
1892 #if USE_OPENSSL
1893
1894 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data)               \
1895 {                                                                       \
1896         btn = gtk_radio_button_new_with_label_from_widget               \
1897                 (GTK_RADIO_BUTTON (btn_p), label);                      \
1898         gtk_widget_show (btn);                                          \
1899         gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0);       \
1900         g_object_set_data (G_OBJECT (btn),                              \
1901                            MENU_VAL_ID,                                 \
1902                            GINT_TO_POINTER (data));                     \
1903 }
1904
1905 #define CREATE_RADIO_BUTTONS(box,                                       \
1906                              btn1, btn1_label, btn1_data,               \
1907                              btn2, btn2_label, btn2_data,               \
1908                              btn3, btn3_label, btn3_data)               \
1909 {                                                                       \
1910         btn1 = gtk_radio_button_new_with_label(NULL, btn1_label);       \
1911         gtk_widget_show (btn1);                                         \
1912         gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0);      \
1913         g_object_set_data (G_OBJECT (btn1),                             \
1914                            MENU_VAL_ID,                                 \
1915                            GINT_TO_POINTER (btn1_data));                \
1916                                                                         \
1917         CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data);    \
1918         CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data);    \
1919 }
1920
1921 static void prefs_account_ssl_create(void)
1922 {
1923         GtkWidget *vbox1;
1924
1925         GtkWidget *pop_frame;
1926         GtkWidget *vbox2;
1927         GtkWidget *pop_nossl_radiobtn;
1928         GtkWidget *pop_ssltunnel_radiobtn;
1929         GtkWidget *pop_starttls_radiobtn;
1930
1931         GtkWidget *imap_frame;
1932         GtkWidget *vbox3;
1933         GtkWidget *imap_nossl_radiobtn;
1934         GtkWidget *imap_ssltunnel_radiobtn;
1935         GtkWidget *imap_starttls_radiobtn;
1936
1937         GtkWidget *nntp_frame;
1938         GtkWidget *vbox4;
1939         GtkWidget *nntp_nossl_radiobtn;
1940         GtkWidget *nntp_ssltunnel_radiobtn;
1941
1942         GtkWidget *send_frame;
1943         GtkWidget *vbox5;
1944         GtkWidget *smtp_nossl_radiobtn;
1945         GtkWidget *smtp_ssltunnel_radiobtn;
1946         GtkWidget *smtp_starttls_radiobtn;
1947
1948         GtkWidget *vbox6;
1949         GtkWidget *use_nonblocking_ssl_chkbtn;
1950         GtkWidget *hbox;
1951         GtkWidget *hbox_spc;
1952         GtkWidget *label;
1953
1954         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1955         gtk_widget_show (vbox1);
1956         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1957         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1958
1959         PACK_FRAME (vbox1, pop_frame, _("POP3"));
1960         vbox2 = gtk_vbox_new (FALSE, 0);
1961         gtk_widget_show (vbox2);
1962         gtk_container_add (GTK_CONTAINER (pop_frame), vbox2);
1963         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1964
1965         CREATE_RADIO_BUTTONS(vbox2,
1966                              pop_nossl_radiobtn,
1967                              _("Don't use SSL"),
1968                              SSL_NONE,
1969                              pop_ssltunnel_radiobtn,
1970                              _("Use SSL for POP3 connection"),
1971                              SSL_TUNNEL,
1972                              pop_starttls_radiobtn,
1973                              _("Use STARTTLS command to start SSL session"),
1974                              SSL_STARTTLS);
1975
1976         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
1977         vbox3 = gtk_vbox_new (FALSE, 0);
1978         gtk_widget_show (vbox3);
1979         gtk_container_add (GTK_CONTAINER (imap_frame), vbox3);
1980         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1981
1982         CREATE_RADIO_BUTTONS(vbox3,
1983                              imap_nossl_radiobtn,
1984                              _("Don't use SSL"),
1985                              SSL_NONE,
1986                              imap_ssltunnel_radiobtn,
1987                              _("Use SSL for IMAP4 connection"),
1988                              SSL_TUNNEL,
1989                              imap_starttls_radiobtn,
1990                              _("Use STARTTLS command to start SSL session"),
1991                              SSL_STARTTLS);
1992
1993         PACK_FRAME (vbox1, nntp_frame, _("NNTP"));
1994         vbox4 = gtk_vbox_new (FALSE, 0);
1995         gtk_widget_show (vbox4);
1996         gtk_container_add (GTK_CONTAINER (nntp_frame), vbox4);
1997         gtk_container_set_border_width (GTK_CONTAINER (vbox4), 8);
1998
1999         nntp_nossl_radiobtn =
2000                 gtk_radio_button_new_with_label (NULL, _("Don't use SSL"));
2001         gtk_widget_show (nntp_nossl_radiobtn);
2002         gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
2003                             FALSE, FALSE, 0);
2004         g_object_set_data (G_OBJECT (nntp_nossl_radiobtn),
2005                            MENU_VAL_ID,
2006                            GINT_TO_POINTER (SSL_NONE));
2007
2008         CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
2009                             _("Use SSL for NNTP connection"), SSL_TUNNEL);
2010
2011         PACK_FRAME (vbox1, send_frame, _("Send (SMTP)"));
2012         vbox5 = gtk_vbox_new (FALSE, 0);
2013         gtk_widget_show (vbox5);
2014         gtk_container_add (GTK_CONTAINER (send_frame), vbox5);
2015         gtk_container_set_border_width (GTK_CONTAINER (vbox5), 8);
2016
2017         CREATE_RADIO_BUTTONS(vbox5,
2018                              smtp_nossl_radiobtn,
2019                              _("Don't use SSL (but, if necessary, use STARTTLS)"),
2020                              SSL_NONE,
2021                              smtp_ssltunnel_radiobtn,
2022                              _("Use SSL for SMTP connection"),
2023                              SSL_TUNNEL,
2024                              smtp_starttls_radiobtn,
2025                              _("Use STARTTLS command to start SSL session"),
2026                              SSL_STARTTLS);
2027
2028         vbox6 = gtk_vbox_new (FALSE, 0);
2029         gtk_widget_show (vbox6);
2030         gtk_box_pack_start (GTK_BOX (vbox1), vbox6, FALSE, FALSE, 0);
2031
2032         PACK_CHECK_BUTTON(vbox6, use_nonblocking_ssl_chkbtn,
2033                           _("Use non-blocking SSL"));
2034
2035         hbox = gtk_hbox_new (FALSE, 0);
2036         gtk_widget_show (hbox);
2037         gtk_box_pack_start (GTK_BOX (vbox6), hbox, FALSE, FALSE, 0);
2038
2039         hbox_spc = gtk_hbox_new (FALSE, 0);
2040         gtk_widget_show (hbox_spc);
2041         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2042         gtk_widget_set_size_request (hbox_spc, 16, -1);
2043
2044         label = gtk_label_new
2045                 (_("(Turn this off if you have SSL connection problems)"));
2046         gtk_widget_show (label);
2047         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2048         gtkut_widget_set_small_font_size (label);
2049
2050         ssl.pop_frame               = pop_frame;
2051         ssl.pop_nossl_radiobtn      = pop_nossl_radiobtn;
2052         ssl.pop_ssltunnel_radiobtn  = pop_ssltunnel_radiobtn;
2053         ssl.pop_starttls_radiobtn   = pop_starttls_radiobtn;
2054
2055         ssl.imap_frame              = imap_frame;
2056         ssl.imap_nossl_radiobtn     = imap_nossl_radiobtn;
2057         ssl.imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
2058         ssl.imap_starttls_radiobtn  = imap_starttls_radiobtn;
2059
2060         ssl.nntp_frame              = nntp_frame;
2061         ssl.nntp_nossl_radiobtn     = nntp_nossl_radiobtn;
2062         ssl.nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
2063
2064         ssl.send_frame              = send_frame;
2065         ssl.smtp_nossl_radiobtn     = smtp_nossl_radiobtn;
2066         ssl.smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
2067         ssl.smtp_starttls_radiobtn  = smtp_starttls_radiobtn;
2068
2069         ssl.use_nonblocking_ssl_chkbtn = use_nonblocking_ssl_chkbtn;
2070 }
2071
2072 #undef CREATE_RADIO_BUTTONS
2073 #undef CREATE_RADIO_BUTTON
2074 #endif /* USE_OPENSSL */
2075
2076 static void crosspost_color_toggled(void)
2077 {
2078         gboolean is_active;
2079
2080         is_active = gtk_toggle_button_get_active
2081                 (GTK_TOGGLE_BUTTON(advanced.crosspost_chkbtn));
2082         gtk_widget_set_sensitive(advanced.crosspost_colormenu, is_active);
2083 }
2084
2085 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam)
2086 {
2087         GtkWidget *menu;
2088         GtkWidget *menuitem;
2089
2090         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(advanced.crosspost_colormenu));
2091         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2092         *((gint *)pparam->data) = GPOINTER_TO_INT
2093                 (g_object_get_data(G_OBJECT(menuitem), "color"));
2094 }
2095
2096 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam)
2097 {
2098         gint colorlabel = *((gint *)pparam->data);
2099         GtkOptionMenu *colormenu = GTK_OPTION_MENU(*pparam->widget);
2100         GtkWidget *menu;
2101         GtkWidget *menuitem;
2102
2103         gtk_option_menu_set_history(colormenu, colorlabel);
2104         menu = gtk_option_menu_get_menu(colormenu);
2105         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2106         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2107 }
2108
2109
2110 static void prefs_account_advanced_create(void)
2111 {
2112         GtkWidget *vbox1;
2113         GtkWidget *vbox2;
2114         GtkWidget *hbox1;
2115         GtkWidget *checkbtn_smtpport;
2116         GtkWidget *entry_smtpport;
2117         GtkWidget *hbox_popport;
2118         GtkWidget *checkbtn_popport;
2119         GtkWidget *entry_popport;
2120         GtkWidget *hbox_imapport;
2121         GtkWidget *checkbtn_imapport;
2122         GtkWidget *entry_imapport;
2123         GtkWidget *hbox_nntpport;
2124         GtkWidget *checkbtn_nntpport;
2125         GtkWidget *entry_nntpport;
2126         GtkWidget *checkbtn_domain;
2127         GtkWidget *entry_domain;
2128         GtkWidget *checkbtn_crosspost;
2129         GtkWidget *colormenu_crosspost;
2130         GtkWidget *menu;
2131         GtkWidget *checkbtn_tunnelcmd;
2132         GtkWidget *entry_tunnelcmd;
2133         GtkWidget *imapdir_label;
2134         GtkWidget *imapdir_entry;
2135         GtkWidget *folder_frame;
2136         GtkWidget *vbox3;
2137         GtkWidget *table;
2138         GtkWidget *sent_folder_chkbtn;
2139         GtkWidget *sent_folder_entry;
2140         GtkWidget *draft_folder_chkbtn;
2141         GtkWidget *draft_folder_entry;
2142         GtkWidget *trash_folder_chkbtn;
2143         GtkWidget *trash_folder_entry;
2144
2145 #define PACK_HBOX(hbox) \
2146         { \
2147         hbox = gtk_hbox_new (FALSE, 8); \
2148         gtk_widget_show (hbox); \
2149         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
2150         }
2151
2152 #define PACK_PORT_ENTRY(box, entry) \
2153         { \
2154         entry = gtk_entry_new (); \
2155         gtk_entry_set_max_length  (GTK_ENTRY(entry), 5); \
2156         gtk_widget_show (entry); \
2157         gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 0); \
2158         gtk_widget_set_size_request (entry, 64, -1); \
2159         }
2160
2161         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2162         gtk_widget_show (vbox1);
2163         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
2164         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2165
2166         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW_2);
2167         gtk_widget_show (vbox2);
2168         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2169
2170         PACK_HBOX (hbox1);
2171         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("Specify SMTP port"));
2172         PACK_PORT_ENTRY (hbox1, entry_smtpport);
2173         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, entry_smtpport);
2174
2175         PACK_HBOX (hbox_popport);
2176         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
2177                            _("Specify POP3 port"));
2178         PACK_PORT_ENTRY (hbox_popport, entry_popport);
2179         SET_TOGGLE_SENSITIVITY (checkbtn_popport, entry_popport);
2180
2181         PACK_HBOX (hbox_imapport);
2182         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
2183                            _("Specify IMAP4 port"));
2184         PACK_PORT_ENTRY (hbox_imapport, entry_imapport);
2185         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, entry_imapport);
2186
2187         PACK_HBOX (hbox_nntpport);
2188         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
2189                            _("Specify NNTP port"));
2190         PACK_PORT_ENTRY (hbox_nntpport, entry_nntpport);
2191         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, entry_nntpport);
2192
2193         PACK_HBOX (hbox1);
2194         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Specify domain name"));
2195
2196         entry_domain = gtk_entry_new ();
2197         gtk_widget_show (entry_domain);
2198         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
2199         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
2200
2201         
2202         PACK_HBOX (hbox1);
2203         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
2204                            _("Use command to communicate with server"));
2205         entry_tunnelcmd = gtk_entry_new ();
2206         gtk_widget_show (entry_tunnelcmd);
2207         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
2208         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
2209
2210         PACK_HBOX (hbox1);
2211         PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost, 
2212                            _("Mark cross-posted messages as read and color:"));
2213         g_signal_connect (G_OBJECT (checkbtn_crosspost), "toggled",
2214                           G_CALLBACK (crosspost_color_toggled),
2215                           NULL);
2216
2217         colormenu_crosspost = gtk_option_menu_new();
2218         gtk_widget_show (colormenu_crosspost);
2219         gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
2220
2221         menu = colorlabel_create_color_menu();
2222         gtk_option_menu_set_menu (GTK_OPTION_MENU(colormenu_crosspost), menu);
2223         SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
2224
2225         PACK_HBOX (hbox1);
2226         imapdir_label = gtk_label_new (_("IMAP server directory"));
2227         gtk_widget_show (imapdir_label);
2228         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
2229
2230         imapdir_entry = gtk_entry_new();
2231         gtk_widget_show (imapdir_entry);
2232         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, TRUE, TRUE, 0);
2233
2234 #undef PACK_HBOX
2235 #undef PACK_PORT_ENTRY
2236
2237         /* special folder setting (maybe these options are redundant) */
2238
2239         PACK_FRAME (vbox1, folder_frame, _("Folder"));
2240
2241         vbox3 = gtk_vbox_new (FALSE, 0);
2242         gtk_widget_show (vbox3);
2243         gtk_container_add (GTK_CONTAINER (folder_frame), vbox3);
2244         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
2245
2246         table = gtk_table_new (3, 3, FALSE);
2247         gtk_widget_show (table);
2248         gtk_container_add (GTK_CONTAINER (vbox3), table);
2249         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
2250         gtk_table_set_col_spacings (GTK_TABLE (table), 4);
2251
2252 #define SET_CHECK_BTN_AND_ENTRY(label, chkbtn, entry, n)                \
2253 {                                                                       \
2254         GtkWidget *button;                                              \
2255                                                                         \
2256         chkbtn = gtk_check_button_new_with_label (label);               \
2257         gtk_widget_show (chkbtn);                                       \
2258         gtk_table_attach (GTK_TABLE (table), chkbtn,                    \
2259                           0, 1, n, n + 1, GTK_FILL, 0, 0, 0);           \
2260                                                                         \
2261         entry = gtk_entry_new ();                                       \
2262         gtk_widget_show (entry);                                        \
2263         gtk_table_attach (GTK_TABLE (table), entry, 1, 2, n, n + 1,     \
2264                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,           \
2265                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);    \
2266                                                                         \
2267         button = gtk_button_new_with_label (_(" ... "));                \
2268         gtk_widget_show (button);                                       \
2269         gtk_table_attach (GTK_TABLE (table), button,                    \
2270                           2, 3, n, n + 1, GTK_FILL, 0, 0, 0);           \
2271         g_signal_connect                                                \
2272                 (G_OBJECT (button), "clicked",                  \
2273                  G_CALLBACK (prefs_account_select_folder_cb),           \
2274                  entry);                                                \
2275                                                                         \
2276         SET_TOGGLE_SENSITIVITY (chkbtn, entry);                         \
2277         SET_TOGGLE_SENSITIVITY (chkbtn, button);                        \
2278 }
2279
2280         SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
2281                                 sent_folder_chkbtn, sent_folder_entry, 0);
2282         SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
2283                                 draft_folder_chkbtn, draft_folder_entry, 1);
2284         SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
2285                                 trash_folder_chkbtn, trash_folder_entry, 2);
2286
2287         advanced.smtpport_chkbtn        = checkbtn_smtpport;
2288         advanced.smtpport_entry         = entry_smtpport;
2289         advanced.popport_hbox           = hbox_popport;
2290         advanced.popport_chkbtn         = checkbtn_popport;
2291         advanced.popport_entry          = entry_popport;
2292         advanced.imapport_hbox          = hbox_imapport;
2293         advanced.imapport_chkbtn        = checkbtn_imapport;
2294         advanced.imapport_entry         = entry_imapport;
2295         advanced.nntpport_hbox          = hbox_nntpport;
2296         advanced.nntpport_chkbtn        = checkbtn_nntpport;
2297         advanced.nntpport_entry         = entry_nntpport;
2298         advanced.domain_chkbtn          = checkbtn_domain;
2299         advanced.domain_entry           = entry_domain;
2300         advanced.crosspost_chkbtn       = checkbtn_crosspost;
2301         advanced.crosspost_colormenu    = colormenu_crosspost;
2302
2303         advanced.tunnelcmd_chkbtn       = checkbtn_tunnelcmd;
2304         advanced.tunnelcmd_entry        = entry_tunnelcmd;
2305         advanced.imapdir_label          = imapdir_label;
2306         advanced.imapdir_entry          = imapdir_entry;
2307
2308         advanced.sent_folder_chkbtn  = sent_folder_chkbtn;
2309         advanced.sent_folder_entry   = sent_folder_entry;
2310         advanced.draft_folder_chkbtn = draft_folder_chkbtn;
2311         advanced.draft_folder_entry  = draft_folder_entry;
2312         advanced.trash_folder_chkbtn = trash_folder_chkbtn;
2313         advanced.trash_folder_entry  = trash_folder_entry;
2314 }
2315
2316 static gint prefs_account_deleted(GtkWidget *widget, GdkEventAny *event,
2317                                   gpointer data)
2318 {
2319         prefs_account_cancel();
2320         return TRUE;
2321 }
2322
2323 static gboolean prefs_account_key_pressed(GtkWidget *widget, GdkEventKey *event,
2324                                           gpointer data)
2325 {
2326         if (event && event->keyval == GDK_Escape)
2327                 prefs_account_cancel();
2328         return FALSE;
2329 }
2330
2331 static void prefs_account_ok(void)
2332 {
2333         if (prefs_account_apply() == 0)
2334                 gtk_main_quit();
2335 }
2336
2337 static gint prefs_account_apply(void)
2338 {
2339         RecvProtocol protocol;
2340         GtkWidget *menu;
2341         GtkWidget *menuitem;
2342
2343         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(basic.protocol_optmenu));
2344         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2345         protocol = GPOINTER_TO_INT
2346                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2347
2348         if (*gtk_entry_get_text(GTK_ENTRY(basic.acname_entry)) == '\0') {
2349                 alertpanel_error(_("Account name is not entered."));
2350                 return -1;
2351         }
2352         if (*gtk_entry_get_text(GTK_ENTRY(basic.addr_entry)) == '\0') {
2353                 alertpanel_error(_("Mail address is not entered."));
2354                 return -1;
2355         }
2356         if (((protocol == A_POP3) || 
2357              (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn))) || 
2358              (protocol == A_NONE)) &&
2359            *gtk_entry_get_text(GTK_ENTRY(basic.smtpserv_entry)) == '\0') {
2360                 alertpanel_error(_("SMTP server is not entered."));
2361                 return -1;
2362         }
2363         if ((protocol == A_POP3 || protocol == A_IMAP4) &&
2364             *gtk_entry_get_text(GTK_ENTRY(basic.uid_entry)) == '\0') {
2365                 alertpanel_error(_("User ID is not entered."));
2366                 return -1;
2367         }
2368         if (protocol == A_POP3 &&
2369             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2370                 alertpanel_error(_("POP3 server is not entered."));
2371                 return -1;
2372         }
2373         if (protocol == A_IMAP4 &&
2374             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2375                 alertpanel_error(_("IMAP4 server is not entered."));
2376                 return -1;
2377         }
2378         if (protocol == A_NNTP &&
2379             *gtk_entry_get_text(GTK_ENTRY(basic.nntpserv_entry)) == '\0') {
2380                 alertpanel_error(_("NNTP server is not entered."));
2381                 return -1;
2382         }
2383
2384         if (protocol == A_LOCAL &&
2385             *gtk_entry_get_text(GTK_ENTRY(basic.localmbox_entry)) == '\0') {
2386                 alertpanel_error(_("local mailbox filename is not entered."));
2387                 return -1;
2388         }
2389
2390         if (protocol == A_LOCAL &&
2391             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic.mailcmd_entry)) == '\0') {
2392                 alertpanel_error(_("mail command is not entered."));
2393                 return -1;
2394         }
2395
2396         prefs_set_data_from_dialog(param);
2397         return 0;
2398 }
2399
2400 static void prefs_account_cancel(void)
2401 {
2402         cancelled = TRUE;
2403         gtk_main_quit();
2404 }
2405
2406 static void pop_bfr_smtp_tm_set_sens(GtkWidget *widget, gpointer data)
2407 {
2408         gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, 
2409                                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn)));
2410 }
2411
2412 static void prefs_account_select_folder_cb(GtkWidget *widget, gpointer data)
2413 {
2414         FolderItem *item;
2415         gchar *id;
2416
2417         item = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
2418         if (item && item->path) {
2419                 id = folder_item_get_identifier(item);
2420                 if (id) {
2421                         gtk_entry_set_text(GTK_ENTRY(data), id);
2422                         g_free(id);
2423                 }
2424         }
2425 }
2426
2427 static void prefs_account_edit_custom_header(void)
2428 {
2429         prefs_custom_header_open(&tmp_ac_prefs);
2430 }
2431
2432 static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
2433 {
2434         GtkRadioButton *radiobtn;
2435         GSList *group;
2436
2437         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2438         group = gtk_radio_button_get_group (radiobtn);
2439         while (group != NULL) {
2440                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2441                 if (gtk_toggle_button_get_active (btn)) {
2442                         *((gint *)pparam->data) = GPOINTER_TO_INT
2443                                 (g_object_get_data (G_OBJECT (btn), MENU_VAL_ID));
2444                         break;
2445                 }
2446                 group = group->next;
2447         }
2448 }
2449
2450 static void prefs_account_enum_set_radiobtn(PrefParam *pparam)
2451 {
2452         GtkRadioButton *radiobtn;
2453         GSList *group;
2454         gpointer data;
2455
2456         data = GINT_TO_POINTER (*((gint *)pparam->data));
2457         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2458         group = gtk_radio_button_get_group (radiobtn);
2459         while (group != NULL) {
2460                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2461                 gpointer data1 = g_object_get_data (G_OBJECT (btn), MENU_VAL_ID);
2462                 if (data1 == data) {
2463                         gtk_toggle_button_set_active (btn, TRUE);
2464                         break;
2465                 }
2466                 group = group->next;
2467         }
2468 }
2469
2470 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
2471 {
2472         GtkWidget *menu;
2473         GtkWidget *menuitem;
2474
2475         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2476         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2477         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2478                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2479 }
2480
2481 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
2482 {
2483         RecvProtocol protocol;
2484         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2485         GtkWidget *menu;
2486         GtkWidget *menuitem;
2487         gint index;
2488
2489         protocol = *((RecvProtocol *)pparam->data);
2490         index = menu_find_option_menu_index
2491                 (optmenu, GINT_TO_POINTER(protocol), NULL);
2492         if (index < 0) return;
2493         gtk_option_menu_set_history(optmenu, index);
2494
2495         menu = gtk_option_menu_get_menu(optmenu);
2496         menu_set_insensitive_all(GTK_MENU_SHELL(menu));
2497
2498         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2499         gtk_widget_set_sensitive(menuitem, TRUE);
2500         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2501 }
2502
2503 static void prefs_account_imap_auth_type_set_data_from_optmenu(PrefParam *pparam)
2504 {
2505         GtkWidget *menu;
2506         GtkWidget *menuitem;
2507
2508         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2509         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2510         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2511                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2512 }
2513
2514 static void prefs_account_imap_auth_type_set_optmenu(PrefParam *pparam)
2515 {
2516         IMAPAuthType type = *((IMAPAuthType *)pparam->data);
2517         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2518         GtkWidget *menu;
2519         GtkWidget *menuitem;
2520
2521         switch (type) {
2522         case IMAP_AUTH_LOGIN:
2523                 gtk_option_menu_set_history(optmenu, 1);
2524                 break;
2525         case IMAP_AUTH_CRAM_MD5:
2526                 gtk_option_menu_set_history(optmenu, 2);
2527                 break;
2528         case 0:
2529         default:
2530                 gtk_option_menu_set_history(optmenu, 0);
2531         }
2532
2533         menu = gtk_option_menu_get_menu(optmenu);
2534         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2535         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2536 }
2537
2538 static void prefs_account_smtp_auth_type_set_data_from_optmenu(PrefParam *pparam)
2539 {
2540         GtkWidget *menu;
2541         GtkWidget *menuitem;
2542
2543         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2544         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2545         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2546                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2547 }
2548
2549 static void prefs_account_smtp_auth_type_set_optmenu(PrefParam *pparam)
2550 {
2551         SMTPAuthType type = *((SMTPAuthType *)pparam->data);
2552         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2553         GtkWidget *menu;
2554         GtkWidget *menuitem;
2555
2556         switch (type) {
2557         case SMTPAUTH_LOGIN:
2558                 gtk_option_menu_set_history(optmenu, 1);
2559                 break;
2560         case SMTPAUTH_CRAM_MD5:
2561                 gtk_option_menu_set_history(optmenu, 2);
2562                 break;
2563         case SMTPAUTH_DIGEST_MD5:
2564                 gtk_option_menu_set_history(optmenu, 3);
2565                 break;
2566         case 0:
2567         default:
2568                 gtk_option_menu_set_history(optmenu, 0);
2569         }
2570
2571         menu = gtk_option_menu_get_menu(optmenu);
2572         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2573         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2574 }
2575
2576 static void prefs_account_set_string_from_optmenu(PrefParam *pparam)
2577 {
2578         GtkWidget *menu;
2579         GtkWidget *menuitem;
2580         gchar **str;
2581
2582         g_return_if_fail(*pparam->widget != NULL);
2583
2584         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2585         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2586         if (menuitem == NULL)
2587                 return;
2588
2589         str = (gchar **) pparam->data;
2590         g_free(*str);
2591         *str = g_strdup(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2592 }
2593
2594 static void prefs_account_set_optmenu_from_string(PrefParam *pparam)
2595 {
2596         GtkWidget *optionmenu;
2597         GtkWidget *menu;
2598         gboolean found = FALSE;
2599         GList *children, *cur;
2600         gchar *prefsid;
2601         guint i = 0;
2602
2603         g_return_if_fail(*pparam->widget != NULL);
2604
2605         prefsid = *((gchar **) pparam->data);
2606         if (prefsid == NULL)
2607                 return;
2608
2609         optionmenu = *pparam->widget;
2610         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optionmenu));
2611         children = gtk_container_children(GTK_CONTAINER(menu));
2612         for (cur = children; cur != NULL; cur = g_list_next(cur)) {
2613                 GtkWidget *item = (GtkWidget *) cur->data;
2614                 gchar *id;
2615
2616                 id = g_object_get_data(G_OBJECT(item), MENU_VAL_ID);
2617                 if (id != NULL && strcmp(id, prefsid) == 0) {
2618                         found = TRUE;
2619                         gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), i);
2620                 }
2621                 i++;
2622         }
2623
2624         if (!found) {
2625                 gchar *name;
2626                 GtkWidget *menuitem;
2627
2628                 name = g_strdup_printf(_("Unsupported (%s)"), prefsid);
2629                 menuitem = gtk_menu_item_new_with_label(name);
2630                 gtk_widget_show(menuitem);
2631                 g_object_set_data_full(G_OBJECT(menuitem), MENU_VAL_ID, g_strdup(prefsid), g_free);
2632                 gtk_menu_append(GTK_MENU(menu), menuitem);
2633                 g_free(name);
2634
2635                 gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), i);
2636         }
2637
2638         g_list_free(children);
2639 }
2640
2641 static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
2642 {
2643         RecvProtocol protocol;
2644
2645         protocol = GPOINTER_TO_INT
2646                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2647
2648         switch(protocol) {
2649         case A_NNTP:
2650                 gtk_widget_show(basic.nntpserv_label);
2651                 gtk_widget_show(basic.nntpserv_entry);
2652                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2653                                            0, VSPACING_NARROW);
2654
2655                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, TRUE);
2656                 gtk_widget_show(basic.nntpauth_chkbtn);
2657
2658                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, TRUE);
2659                 gtk_widget_show(basic.nntpauth_onconnect_chkbtn);
2660
2661                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2662                                            1, VSPACING_NARROW);
2663                 gtk_widget_hide(basic.recvserv_label);
2664                 gtk_widget_hide(basic.recvserv_entry);
2665                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2666                                            2, 0);
2667                 gtk_widget_show(basic.smtpserv_label);
2668                 gtk_widget_show(basic.smtpserv_entry);
2669                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2670                                            4, VSPACING_NARROW);
2671                 gtk_widget_hide(basic.localmbox_label);
2672                 gtk_widget_hide(basic.localmbox_entry);
2673                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2674                                            3, 0);
2675                 gtk_widget_hide(basic.mailcmd_label);
2676                 gtk_widget_hide(basic.mailcmd_entry);
2677                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2678                                            6, 0);
2679                 gtk_widget_hide(basic.mailcmd_chkbtn);
2680                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2681                                            5, 0);
2682                 gtk_widget_show(basic.uid_label);
2683                 gtk_widget_show(basic.pass_label);
2684                 gtk_widget_show(basic.uid_entry);
2685                 gtk_widget_show(basic.pass_entry);
2686                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2687                                            7, VSPACING_NARROW);
2688
2689                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2690                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2691                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2692                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2693
2694                 /* update userid/passwd sensitive state */
2695
2696                 prefs_account_nntpauth_toggled
2697                         (GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
2698                 gtk_widget_hide(receive.pop3_frame);
2699                 gtk_widget_hide(receive.imap_frame);
2700                 gtk_widget_show(receive.frame_maxarticle);
2701                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2702                 /* update pop_before_smtp sensitivity */
2703                 gtk_toggle_button_set_active
2704                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
2705                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2706                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
2707                 
2708                 if (!tmp_ac_prefs.account_name) {
2709                         gtk_toggle_button_set_active
2710                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2711                                  FALSE);
2712                 }
2713
2714 #if USE_OPENSSL
2715                 gtk_widget_hide(ssl.pop_frame);
2716                 gtk_widget_hide(ssl.imap_frame);
2717                 gtk_widget_show(ssl.nntp_frame);
2718                 gtk_widget_hide(ssl.send_frame);
2719 #endif
2720                 gtk_widget_hide(advanced.popport_hbox);
2721                 gtk_widget_hide(advanced.imapport_hbox);
2722                 gtk_widget_show(advanced.nntpport_hbox);
2723                 gtk_widget_show(advanced.crosspost_chkbtn);
2724                 gtk_widget_show(advanced.crosspost_colormenu);
2725                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
2726                 gtk_widget_hide(advanced.tunnelcmd_entry);
2727                 gtk_widget_hide(advanced.imapdir_label);
2728                 gtk_widget_hide(advanced.imapdir_entry);
2729                 break;
2730         case A_LOCAL:
2731                 gtk_widget_hide(basic.nntpserv_label);
2732                 gtk_widget_hide(basic.nntpserv_entry);
2733                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2734                                            0, 0);
2735                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2736                 gtk_widget_hide(basic.nntpauth_chkbtn);
2737
2738                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2739                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2740                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2741                                            1, 0);
2742                 gtk_widget_hide(basic.recvserv_label);
2743                 gtk_widget_hide(basic.recvserv_entry);
2744                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2745                                            2, 0);
2746                 gtk_widget_show(basic.smtpserv_label);
2747                 gtk_widget_show(basic.smtpserv_entry);
2748                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2749                                            4, VSPACING_NARROW);
2750                 gtk_widget_show(basic.localmbox_label);
2751                 gtk_widget_show(basic.localmbox_entry);
2752                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2753                                            3, VSPACING_NARROW);
2754                 gtk_widget_show(basic.mailcmd_label);
2755                 gtk_widget_show(basic.mailcmd_entry);
2756                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2757                                            6, VSPACING_NARROW);
2758                 gtk_widget_show(basic.mailcmd_chkbtn);
2759                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2760                                            5, VSPACING_NARROW);
2761                 gtk_widget_hide(basic.uid_label);
2762                 gtk_widget_hide(basic.pass_label);
2763                 gtk_widget_hide(basic.uid_entry);
2764                 gtk_widget_hide(basic.pass_entry);
2765                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2766                                            7, 0);
2767
2768                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2769                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2770                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2771                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2772                 gtk_widget_hide(receive.pop3_frame);
2773                 gtk_widget_hide(receive.imap_frame);
2774                 gtk_widget_hide(receive.frame_maxarticle);
2775                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2776                 prefs_account_mailcmd_toggled
2777                         (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
2778
2779                 /* update pop_before_smtp sensitivity */
2780                 gtk_toggle_button_set_active
2781                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
2782                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2783                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
2784
2785                 if (!tmp_ac_prefs.account_name) {
2786                         gtk_toggle_button_set_active
2787                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2788                                  TRUE);
2789                 }
2790
2791 #if USE_OPENSSL
2792                 gtk_widget_hide(ssl.pop_frame);
2793                 gtk_widget_hide(ssl.imap_frame);
2794                 gtk_widget_hide(ssl.nntp_frame);
2795                 gtk_widget_show(ssl.send_frame);
2796 #endif
2797                 gtk_widget_hide(advanced.popport_hbox);
2798                 gtk_widget_hide(advanced.imapport_hbox);
2799                 gtk_widget_hide(advanced.nntpport_hbox);
2800                 gtk_widget_hide(advanced.crosspost_chkbtn);
2801                 gtk_widget_hide(advanced.crosspost_colormenu);
2802                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
2803                 gtk_widget_hide(advanced.tunnelcmd_entry);
2804                 gtk_widget_hide(advanced.imapdir_label);
2805                 gtk_widget_hide(advanced.imapdir_entry);
2806                 break;
2807         case A_IMAP4:
2808                 gtk_widget_hide(basic.nntpserv_label);
2809                 gtk_widget_hide(basic.nntpserv_entry);
2810                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2811                                            0, 0);
2812                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2813                 gtk_widget_hide(basic.nntpauth_chkbtn);
2814
2815                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2816                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2817
2818                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2819                                            1, 0);
2820                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
2821                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
2822                 gtk_widget_show(basic.recvserv_label);
2823                 gtk_widget_show(basic.recvserv_entry);
2824                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2825                                            2, VSPACING_NARROW);
2826                 gtk_widget_show(basic.smtpserv_label);
2827                 gtk_widget_show(basic.smtpserv_entry);
2828                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2829                                            4, VSPACING_NARROW);
2830                 gtk_widget_hide(basic.localmbox_label);
2831                 gtk_widget_hide(basic.localmbox_entry);
2832                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2833                                            3, 0);
2834                 gtk_widget_hide(basic.mailcmd_label);
2835                 gtk_widget_hide(basic.mailcmd_entry);
2836                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2837                                            6, 0);
2838                 gtk_widget_hide(basic.mailcmd_chkbtn);
2839                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2840                                            5, 0);
2841                 gtk_widget_show(basic.uid_label);
2842                 gtk_widget_show(basic.pass_label);
2843                 gtk_widget_show(basic.uid_entry);
2844                 gtk_widget_show(basic.pass_entry);
2845                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2846                                            7, VSPACING_NARROW);
2847
2848                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2849                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2850                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2851                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2852                 gtk_widget_hide(receive.pop3_frame);
2853                 gtk_widget_show(receive.imap_frame);
2854                 gtk_widget_hide(receive.frame_maxarticle);
2855                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2856                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
2857                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
2858
2859                 /* update pop_before_smtp sensitivity */
2860                 gtk_toggle_button_set_active
2861                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
2862                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2863                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
2864
2865                 if (!tmp_ac_prefs.account_name) {
2866                         gtk_toggle_button_set_active
2867                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2868                                  FALSE);
2869                 }
2870
2871 #if USE_OPENSSL
2872                 gtk_widget_hide(ssl.pop_frame);
2873                 gtk_widget_show(ssl.imap_frame);
2874                 gtk_widget_hide(ssl.nntp_frame);
2875                 gtk_widget_show(ssl.send_frame);
2876 #endif
2877                 gtk_widget_hide(advanced.popport_hbox);
2878                 gtk_widget_show(advanced.imapport_hbox);
2879                 gtk_widget_hide(advanced.nntpport_hbox);
2880                 gtk_widget_hide(advanced.crosspost_chkbtn);
2881                 gtk_widget_hide(advanced.crosspost_colormenu);
2882                 gtk_widget_show(advanced.tunnelcmd_chkbtn);
2883                 gtk_widget_show(advanced.tunnelcmd_entry);
2884                 gtk_widget_show(advanced.imapdir_label);
2885                 gtk_widget_show(advanced.imapdir_entry);
2886                 break;
2887         case A_NONE:
2888                 gtk_widget_hide(basic.nntpserv_label);
2889                 gtk_widget_hide(basic.nntpserv_entry);
2890                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2891                                            0, 0);
2892                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2893                 gtk_widget_hide(basic.nntpauth_chkbtn);
2894
2895                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2896                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2897
2898                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2899                                            1, 0);
2900                 gtk_widget_set_sensitive(basic.recvserv_label, FALSE);
2901                 gtk_widget_set_sensitive(basic.recvserv_entry, FALSE);
2902                 gtk_widget_hide(basic.recvserv_label);
2903                 gtk_widget_hide(basic.recvserv_entry);
2904                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2905                                            2, VSPACING_NARROW);
2906                 gtk_widget_show(basic.smtpserv_label);
2907                 gtk_widget_show(basic.smtpserv_entry);
2908                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2909                                            4, VSPACING_NARROW);
2910                 gtk_widget_hide(basic.localmbox_label);
2911                 gtk_widget_hide(basic.localmbox_entry);
2912                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2913                                            3, 0);
2914                 gtk_widget_hide(basic.mailcmd_label);
2915                 gtk_widget_hide(basic.mailcmd_entry);
2916                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2917                                            6, 0);
2918                 gtk_widget_hide(basic.mailcmd_chkbtn);
2919                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2920                                            5, 0);
2921                 gtk_widget_hide(basic.uid_label);
2922                 gtk_widget_hide(basic.pass_label);
2923                 gtk_widget_hide(basic.uid_entry);
2924                 gtk_widget_hide(basic.pass_entry);
2925                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2926                                            7, VSPACING_NARROW);
2927
2928                 gtk_widget_set_sensitive(basic.uid_label,  FALSE);
2929                 gtk_widget_set_sensitive(basic.pass_label, FALSE);
2930                 gtk_widget_set_sensitive(basic.uid_entry,  FALSE);
2931                 gtk_widget_set_sensitive(basic.pass_entry, FALSE);
2932                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
2933                 gtk_widget_hide(receive.pop3_frame);
2934                 gtk_widget_hide(receive.imap_frame);
2935                 gtk_widget_hide(receive.frame_maxarticle);
2936                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, FALSE);
2937
2938                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
2939                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
2940
2941                 /* update pop_before_smtp sensitivity */
2942                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2943                 pop_bfr_smtp_tm_set_sens(NULL, NULL);
2944                 
2945                 gtk_toggle_button_set_active
2946                         (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn), FALSE);
2947
2948 #if USE_OPENSSL
2949                 gtk_widget_hide(ssl.pop_frame);
2950                 gtk_widget_hide(ssl.imap_frame);
2951                 gtk_widget_hide(ssl.nntp_frame);
2952                 gtk_widget_show(ssl.send_frame);
2953 #endif
2954                 gtk_widget_hide(advanced.popport_hbox);
2955                 gtk_widget_hide(advanced.imapport_hbox);
2956                 gtk_widget_hide(advanced.nntpport_hbox);
2957                 gtk_widget_hide(advanced.crosspost_chkbtn);
2958                 gtk_widget_hide(advanced.crosspost_colormenu);
2959                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
2960                 gtk_widget_hide(advanced.tunnelcmd_entry);
2961                 gtk_widget_hide(advanced.imapdir_label);
2962                 gtk_widget_hide(advanced.imapdir_entry);
2963                 break;
2964         case A_POP3:
2965         default:
2966                 gtk_widget_hide(basic.nntpserv_label);
2967                 gtk_widget_hide(basic.nntpserv_entry);
2968                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2969                                            0, 0);
2970                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2971                 gtk_widget_hide(basic.nntpauth_chkbtn);
2972
2973                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2974                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2975
2976                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2977                                            1, 0);
2978                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
2979                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
2980                 gtk_widget_show(basic.recvserv_label);
2981                 gtk_widget_show(basic.recvserv_entry);
2982                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2983                                            2, VSPACING_NARROW);
2984                 gtk_widget_show(basic.smtpserv_label);
2985                 gtk_widget_show(basic.smtpserv_entry);
2986                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2987                                            4, VSPACING_NARROW);
2988                 gtk_widget_hide(basic.localmbox_label);
2989                 gtk_widget_hide(basic.localmbox_entry);
2990                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2991                                            3, 0);
2992                 gtk_widget_hide(basic.mailcmd_label);
2993                 gtk_widget_hide(basic.mailcmd_entry);
2994                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2995                                            6, 0);
2996                 gtk_widget_hide(basic.mailcmd_chkbtn);
2997                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2998                                            5, 0);
2999                 gtk_widget_show(basic.uid_label);
3000                 gtk_widget_show(basic.pass_label);
3001                 gtk_widget_show(basic.uid_entry);
3002                 gtk_widget_show(basic.pass_entry);
3003                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3004                                            7, VSPACING_NARROW);
3005
3006                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
3007                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
3008                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
3009                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
3010                 gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
3011                 gtk_widget_show(receive.pop3_frame);
3012                 gtk_widget_hide(receive.imap_frame);
3013                 gtk_widget_hide(receive.frame_maxarticle);
3014                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
3015
3016                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3017                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3018
3019                 /* update pop_before_smtp sensitivity */
3020                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, TRUE);
3021                 pop_bfr_smtp_tm_set_sens(NULL, NULL);
3022                 
3023                 if (!tmp_ac_prefs.account_name) {
3024                         gtk_toggle_button_set_active
3025                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
3026                                  TRUE);
3027                 }
3028
3029 #if USE_OPENSSL
3030                 gtk_widget_show(ssl.pop_frame);
3031                 gtk_widget_hide(ssl.imap_frame);
3032                 gtk_widget_hide(ssl.nntp_frame);
3033                 gtk_widget_show(ssl.send_frame);
3034 #endif
3035                 gtk_widget_show(advanced.popport_hbox);
3036                 gtk_widget_hide(advanced.imapport_hbox);
3037                 gtk_widget_hide(advanced.nntpport_hbox);
3038                 gtk_widget_hide(advanced.crosspost_chkbtn);
3039                 gtk_widget_hide(advanced.crosspost_colormenu);
3040                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
3041                 gtk_widget_hide(advanced.tunnelcmd_entry);
3042                 gtk_widget_hide(advanced.imapdir_label);
3043                 gtk_widget_hide(advanced.imapdir_entry);
3044                 break;
3045         }
3046
3047         gtk_widget_queue_resize(basic.serv_frame);
3048 }
3049
3050 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
3051                                            gpointer user_data)
3052 {
3053         gboolean auth;
3054
3055         if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (button)))
3056                 return;
3057         auth = gtk_toggle_button_get_active (button);
3058         gtk_widget_set_sensitive(basic.uid_label,  auth);
3059         gtk_widget_set_sensitive(basic.pass_label, auth);
3060         gtk_widget_set_sensitive(basic.uid_entry,  auth);
3061         gtk_widget_set_sensitive(basic.pass_entry, auth);
3062         gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, auth);
3063 }
3064
3065 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
3066                                           gpointer user_data)
3067 {
3068         gboolean use_mailcmd;
3069
3070         use_mailcmd = gtk_toggle_button_get_active (button);
3071
3072         gtk_widget_set_sensitive(basic.mailcmd_entry,  use_mailcmd);
3073         gtk_widget_set_sensitive(basic.mailcmd_label, use_mailcmd);
3074         gtk_widget_set_sensitive(basic.smtpserv_entry, !use_mailcmd);
3075         gtk_widget_set_sensitive(basic.smtpserv_label, !use_mailcmd);
3076         gtk_widget_set_sensitive(basic.uid_entry,  !use_mailcmd);
3077         gtk_widget_set_sensitive(basic.pass_entry, !use_mailcmd);
3078 }
3079
3080 void prefs_account_register_page(PrefsPage *page)
3081 {
3082         prefs_pages = g_slist_append(prefs_pages, page);
3083 }
3084
3085 void prefs_acount_unregister_page(PrefsPage *page)
3086 {
3087         prefs_pages = g_slist_remove(prefs_pages, page);
3088 }