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