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