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