fix popbeforesmtp checkbutton sensitivity
[claws.git] / src / prefs_account.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2002 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 <gtk/gtk.h>
27 #include <gdk/gdkkeysyms.h>
28 #include <stdio.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #include <string.h>
32 #include <stdlib.h>
33 #include <ctype.h>
34
35 #include "intl.h"
36 #include "main.h"
37 #include "prefs.h"
38 #include "prefs_account.h"
39 #include "prefs_customheader.h"
40 #include "account.h"
41 #include "mainwindow.h"
42 #include "manage_window.h"
43 #include "foldersel.h"
44 #include "inc.h"
45 #include "menu.h"
46 #include "gtkutils.h"
47 #include "utils.h"
48 #include "alertpanel.h"
49 #include "colorlabel.h"
50
51 static gboolean cancelled;
52
53 static PrefsAccount tmp_ac_prefs;
54
55 static PrefsDialog dialog;
56
57 static struct Basic {
58         GtkWidget *acname_entry;
59         GtkWidget *default_chkbtn;
60
61         GtkWidget *name_entry;
62         GtkWidget *addr_entry;
63         GtkWidget *org_entry;
64
65         GtkWidget *serv_frame;
66         GtkWidget *serv_table;
67         GtkWidget *protocol_optmenu;
68         GtkWidget *recvserv_label;
69         GtkWidget *smtpserv_label;
70         GtkWidget *nntpserv_label;
71         GtkWidget *localmbox_label;
72         GtkWidget *mailcmd_label;
73         GtkWidget *recvserv_entry;
74         GtkWidget *smtpserv_entry;
75         GtkWidget *nntpserv_entry;
76         GtkWidget *nntpauth_chkbtn;
77         GtkWidget *localmbox_entry;
78         GtkWidget *mailcmd_chkbtn;
79         GtkWidget *mailcmd_entry;
80         GtkWidget *uid_label;
81         GtkWidget *pass_label;
82         GtkWidget *uid_entry;
83         GtkWidget *pass_entry;
84 } basic;
85
86 static struct Receive {
87         GtkWidget *pop3_frame;
88         GtkWidget *rmmail_chkbtn;
89         GtkWidget *leave_time_entry;
90         GtkWidget *getall_chkbtn;
91         GtkWidget *sd_filter_on_recv_chkbtn;
92         GtkWidget *sd_rmmail_chkbtn;
93         GtkWidget *size_limit_chkbtn;
94         GtkWidget *size_limit_entry;
95         GtkWidget *filter_on_recv_chkbtn;
96         GtkWidget *inbox_label;
97         GtkWidget *inbox_entry;
98         GtkWidget *inbox_btn;
99
100         GtkWidget *recvatgetall_chkbtn;
101 } receive;
102
103 static struct Send {
104         GtkWidget *date_chkbtn;
105         GtkWidget *msgid_chkbtn;
106
107         GtkWidget *customhdr_chkbtn;
108
109         GtkWidget *smtp_auth_chkbtn;
110         GtkWidget *smtp_auth_type_optmenu;
111         GtkWidget *smtp_uid_entry;
112         GtkWidget *smtp_pass_entry;
113         GtkWidget *pop_bfr_smtp_chkbtn;
114 } p_send;
115
116 static struct Compose {
117         GtkWidget *sigpath_entry;
118
119         GtkWidget *autocc_chkbtn;
120         GtkWidget *autocc_entry;
121         GtkWidget *autobcc_chkbtn;
122         GtkWidget *autobcc_entry;
123         GtkWidget *autoreplyto_chkbtn;
124         GtkWidget *autoreplyto_entry;
125 } compose;
126
127 #if USE_GPGME
128 static struct Privacy {
129         GtkWidget *default_encrypt_chkbtn;
130         GtkWidget *default_sign_chkbtn;
131         GtkWidget *ascii_armored_chkbtn;
132         GtkWidget *clearsign_chkbtn;
133         GtkWidget *defaultkey_radiobtn;
134         GtkWidget *emailkey_radiobtn;
135         GtkWidget *customkey_radiobtn;
136         GtkWidget *customkey_entry;
137 } privacy;
138 #endif /* USE_GPGME */
139
140 #if USE_SSL
141 static struct SSLPrefs {
142         GtkWidget *pop_frame;
143         GtkWidget *pop_nossl_radiobtn;
144         GtkWidget *pop_ssltunnel_radiobtn;
145         GtkWidget *pop_starttls_radiobtn;
146
147         GtkWidget *imap_frame;
148         GtkWidget *imap_nossl_radiobtn;
149         GtkWidget *imap_ssltunnel_radiobtn;
150         GtkWidget *imap_starttls_radiobtn;
151
152         GtkWidget *nntp_frame;
153         GtkWidget *nntp_nossl_radiobtn;
154         GtkWidget *nntp_ssltunnel_radiobtn;
155
156         GtkWidget *send_frame;
157         GtkWidget *smtp_nossl_radiobtn;
158         GtkWidget *smtp_ssltunnel_radiobtn;
159         GtkWidget *smtp_starttls_radiobtn;
160 } ssl;
161 #endif /* USE_SSL */
162
163 static struct Advanced {
164         GtkWidget *smtpport_chkbtn;
165         GtkWidget *smtpport_entry;
166         GtkWidget *popport_hbox;
167         GtkWidget *popport_chkbtn;
168         GtkWidget *popport_entry;
169         GtkWidget *imapport_hbox;
170         GtkWidget *imapport_chkbtn;
171         GtkWidget *imapport_entry;
172         GtkWidget *nntpport_hbox;
173         GtkWidget *nntpport_chkbtn;
174         GtkWidget *nntpport_entry;
175         GtkWidget *domain_chkbtn;
176         GtkWidget *domain_entry;
177         GtkWidget *tunnelcmd_chkbtn;
178         GtkWidget *tunnelcmd_entry;
179         GtkWidget *crosspost_chkbtn;
180         GtkWidget *crosspost_colormenu;
181
182         GtkWidget *imap_frame;
183         GtkWidget *imapdir_entry;
184
185         GtkWidget *sent_folder_chkbtn;
186         GtkWidget *sent_folder_entry;
187         GtkWidget *draft_folder_chkbtn;
188         GtkWidget *draft_folder_entry;
189         GtkWidget *trash_folder_chkbtn;
190         GtkWidget *trash_folder_entry;
191 } advanced;
192
193 static void prefs_account_fix_size                      (void);
194
195 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam);
196 static void prefs_account_protocol_set_optmenu          (PrefParam *pparam);
197 static void prefs_account_protocol_activated            (GtkMenuItem *menuitem);
198
199 static void prefs_account_smtp_auth_type_set_data_from_optmenu
200                                                         (PrefParam *pparam);
201 static void prefs_account_smtp_auth_type_set_optmenu    (PrefParam *pparam);
202
203 #if USE_GPGME || USE_SSL
204 static void prefs_account_enum_set_data_from_radiobtn   (PrefParam *pparam);
205 static void prefs_account_enum_set_radiobtn             (PrefParam *pparam);
206 #endif /* USE_GPGME || USE_SSL */
207
208 #if USE_GPGME
209 static void prefs_account_ascii_armored_warning         (GtkWidget *widget);
210 #endif /* USE_GPGME */
211
212 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam);
213 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam);
214
215 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
216                                            gpointer user_data);
217 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
218                                           gpointer user_data);
219 static void prefs_account_smtp_userid_cb(GtkEditable *editable,
220                                          gpointer smtp_passwd);
221
222 static PrefParam param[] = {
223         /* Basic */
224         {"account_name", NULL, &tmp_ac_prefs.account_name, P_STRING,
225          &basic.acname_entry, prefs_set_data_from_entry, prefs_set_entry},
226
227         {"is_default", "FALSE", &tmp_ac_prefs.is_default, P_BOOL,
228          &basic.default_chkbtn,
229          prefs_set_data_from_toggle, prefs_set_toggle},
230
231         {"name", NULL, &tmp_ac_prefs.name, P_STRING,
232          &basic.name_entry, prefs_set_data_from_entry, prefs_set_entry},
233
234         {"address", NULL, &tmp_ac_prefs.address, P_STRING,
235          &basic.addr_entry, prefs_set_data_from_entry, prefs_set_entry},
236
237         {"organization", NULL, &tmp_ac_prefs.organization, P_STRING,
238          &basic.org_entry, prefs_set_data_from_entry, prefs_set_entry},
239
240         {"protocol", NULL, &tmp_ac_prefs.protocol, P_ENUM,
241          &basic.protocol_optmenu,
242          prefs_account_protocol_set_data_from_optmenu,
243          prefs_account_protocol_set_optmenu},
244
245         {"receive_server", NULL, &tmp_ac_prefs.recv_server, P_STRING,
246          &basic.recvserv_entry, prefs_set_data_from_entry, prefs_set_entry},
247
248         {"smtp_server", NULL, &tmp_ac_prefs.smtp_server, P_STRING,
249          &basic.smtpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
250
251         {"nntp_server", NULL, &tmp_ac_prefs.nntp_server, P_STRING,
252          &basic.nntpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
253
254         {"local_mbox", NULL, &tmp_ac_prefs.local_mbox, P_STRING,
255          &basic.localmbox_entry, prefs_set_data_from_entry, prefs_set_entry},
256
257         {"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
258          &basic.mailcmd_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
259
260         {"mail_command", "/usr/sbin/sendmail -t", &tmp_ac_prefs.mail_command, P_STRING,
261          &basic.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
262
263         {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
264          &basic.nntpauth_chkbtn,
265          prefs_set_data_from_toggle, prefs_set_toggle},
266
267         {"user_id", "ENV_USER", &tmp_ac_prefs.userid, P_STRING,
268          &basic.uid_entry, prefs_set_data_from_entry, prefs_set_entry},
269
270         {"password", NULL, &tmp_ac_prefs.passwd, P_STRING,
271          &basic.pass_entry, prefs_set_data_from_entry, prefs_set_entry},
272
273         {"inbox", "inbox", &tmp_ac_prefs.inbox, P_STRING,
274          &receive.inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
275
276         /* Receive */
277         {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
278          &receive.rmmail_chkbtn,
279          prefs_set_data_from_toggle, prefs_set_toggle},
280
281         {"message_leave_time", "0", &tmp_ac_prefs.msg_leave_time, P_INT,
282          &receive.leave_time_entry,
283          prefs_set_data_from_entry, prefs_set_entry},
284
285         {"get_all_mail", "FALSE", &tmp_ac_prefs.getall, P_BOOL,
286          &receive.getall_chkbtn,
287          prefs_set_data_from_toggle, prefs_set_toggle},
288
289         {"enable_size_limit", "FALSE", &tmp_ac_prefs.enable_size_limit, P_BOOL,
290          &receive.size_limit_chkbtn,
291          prefs_set_data_from_toggle, prefs_set_toggle},
292         {"size_limit", "1024", &tmp_ac_prefs.size_limit, P_INT,
293          &receive.size_limit_entry,
294          prefs_set_data_from_entry, prefs_set_entry},
295
296         {"filter_on_receive", "TRUE", &tmp_ac_prefs.filter_on_recv, P_BOOL,
297          &receive.filter_on_recv_chkbtn,
298          prefs_set_data_from_toggle, prefs_set_toggle},
299
300         /* selective download */        
301         {"sd_filter_on_receive", "TRUE", &tmp_ac_prefs.sd_filter_on_recv, P_BOOL,
302          &receive.sd_filter_on_recv_chkbtn,
303          prefs_set_data_from_toggle, prefs_set_toggle},
304         {"sd_remove_mail_on_download", "TRUE", &tmp_ac_prefs.sd_rmmail_on_download, P_BOOL,
305          &receive.sd_rmmail_chkbtn,
306          prefs_set_data_from_toggle, prefs_set_toggle},
307
308         {"receive_at_get_all", "TRUE", &tmp_ac_prefs.recv_at_getall, P_BOOL,
309          &receive.recvatgetall_chkbtn,
310          prefs_set_data_from_toggle, prefs_set_toggle},
311
312         /* Send */
313         {"add_date", "TRUE", &tmp_ac_prefs.add_date, P_BOOL,
314          &p_send.date_chkbtn,
315          prefs_set_data_from_toggle, prefs_set_toggle},
316
317         {"generate_msgid", "TRUE", &tmp_ac_prefs.gen_msgid, P_BOOL,
318          &p_send.msgid_chkbtn,
319          prefs_set_data_from_toggle, prefs_set_toggle},
320
321         {"add_custom_header", "FALSE", &tmp_ac_prefs.add_customhdr, P_BOOL,
322          &p_send.customhdr_chkbtn,
323          prefs_set_data_from_toggle, prefs_set_toggle},
324
325         {"use_smtp_auth", "FALSE", &tmp_ac_prefs.use_smtp_auth, P_BOOL,
326          &p_send.smtp_auth_chkbtn,
327          prefs_set_data_from_toggle, prefs_set_toggle},
328
329         {"smtp_auth_method", "0", &tmp_ac_prefs.smtp_auth_type, P_ENUM,
330          &p_send.smtp_auth_type_optmenu,
331          prefs_account_smtp_auth_type_set_data_from_optmenu,
332          prefs_account_smtp_auth_type_set_optmenu},
333
334         {"smtp_user_id", NULL, &tmp_ac_prefs.smtp_userid, P_STRING,
335          &p_send.smtp_uid_entry, prefs_set_data_from_entry, prefs_set_entry},
336         {"smtp_password", NULL, &tmp_ac_prefs.smtp_passwd, P_STRING,
337          &p_send.smtp_pass_entry, prefs_set_data_from_entry, prefs_set_entry},
338
339         {"pop_before_smtp", "FALSE", &tmp_ac_prefs.pop_before_smtp, P_BOOL,
340          &p_send.pop_bfr_smtp_chkbtn,
341          prefs_set_data_from_toggle, prefs_set_toggle},
342
343         /* Compose */
344         {"signature_path", "~/"DEFAULT_SIGNATURE, &tmp_ac_prefs.sig_path, P_STRING,
345          &compose.sigpath_entry,
346          prefs_set_data_from_entry, prefs_set_entry},
347
348         {"set_autocc", "FALSE", &tmp_ac_prefs.set_autocc, P_BOOL,
349          &compose.autocc_chkbtn,
350          prefs_set_data_from_toggle, prefs_set_toggle},
351
352         {"auto_cc", NULL, &tmp_ac_prefs.auto_cc, P_STRING,
353          &compose.autocc_entry,
354          prefs_set_data_from_entry, prefs_set_entry},
355
356         {"set_autobcc", "FALSE", &tmp_ac_prefs.set_autobcc, P_BOOL,
357          &compose.autobcc_chkbtn,
358          prefs_set_data_from_toggle, prefs_set_toggle},
359
360         {"auto_bcc", NULL, &tmp_ac_prefs.auto_bcc, P_STRING,
361          &compose.autobcc_entry,
362          prefs_set_data_from_entry, prefs_set_entry},
363
364         {"set_autoreplyto", "FALSE", &tmp_ac_prefs.set_autoreplyto, P_BOOL,
365          &compose.autoreplyto_chkbtn,
366          prefs_set_data_from_toggle, prefs_set_toggle},
367
368         {"auto_replyto", NULL, &tmp_ac_prefs.auto_replyto, P_STRING,
369          &compose.autoreplyto_entry,
370          prefs_set_data_from_entry, prefs_set_entry},
371
372 #if USE_GPGME
373         /* Privacy */
374         {"default_encrypt", "FALSE", &tmp_ac_prefs.default_encrypt, P_BOOL,
375          &privacy.default_encrypt_chkbtn,
376          prefs_set_data_from_toggle, prefs_set_toggle},
377         {"default_sign", "FALSE", &tmp_ac_prefs.default_sign, P_BOOL,
378          &privacy.default_sign_chkbtn,
379          prefs_set_data_from_toggle, prefs_set_toggle},
380         {"ascii_armored", "FALSE", &tmp_ac_prefs.ascii_armored, P_BOOL,
381          &privacy.ascii_armored_chkbtn,
382          prefs_set_data_from_toggle, prefs_set_toggle},
383         {"clearsign", "FALSE", &tmp_ac_prefs.clearsign, P_BOOL,
384          &privacy.clearsign_chkbtn,
385          prefs_set_data_from_toggle, prefs_set_toggle},
386         {"sign_key", NULL, &tmp_ac_prefs.sign_key, P_ENUM,
387          &privacy.defaultkey_radiobtn,
388          prefs_account_enum_set_data_from_radiobtn,
389          prefs_account_enum_set_radiobtn},
390         {"sign_key_id", NULL, &tmp_ac_prefs.sign_key_id, P_STRING,
391          &privacy.customkey_entry,
392          prefs_set_data_from_entry, prefs_set_entry},
393 #endif /* USE_GPGME */
394
395 #if USE_SSL
396         /* SSL */
397         {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
398          &ssl.pop_nossl_radiobtn,
399          prefs_account_enum_set_data_from_radiobtn,
400          prefs_account_enum_set_radiobtn},
401         {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
402          &ssl.imap_nossl_radiobtn,
403          prefs_account_enum_set_data_from_radiobtn,
404          prefs_account_enum_set_radiobtn},
405         {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
406          &ssl.nntp_nossl_radiobtn,
407          prefs_account_enum_set_data_from_radiobtn,
408          prefs_account_enum_set_radiobtn},
409         {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
410          &ssl.smtp_nossl_radiobtn,
411          prefs_account_enum_set_data_from_radiobtn,
412          prefs_account_enum_set_radiobtn},
413 #endif /* USE_SSL */
414
415         /* Advanced */
416         {"set_smtpport", "FALSE", &tmp_ac_prefs.set_smtpport, P_BOOL,
417          &advanced.smtpport_chkbtn,
418          prefs_set_data_from_toggle, prefs_set_toggle},
419
420         {"smtp_port", "25", &tmp_ac_prefs.smtpport, P_USHORT,
421          &advanced.smtpport_entry,
422          prefs_set_data_from_entry, prefs_set_entry},
423
424         {"set_popport", "FALSE", &tmp_ac_prefs.set_popport, P_BOOL,
425          &advanced.popport_chkbtn,
426          prefs_set_data_from_toggle, prefs_set_toggle},
427
428         {"pop_port", "110", &tmp_ac_prefs.popport, P_USHORT,
429          &advanced.popport_entry,
430          prefs_set_data_from_entry, prefs_set_entry},
431
432         {"set_imapport", "FALSE", &tmp_ac_prefs.set_imapport, P_BOOL,
433          &advanced.imapport_chkbtn,
434          prefs_set_data_from_toggle, prefs_set_toggle},
435
436         {"imap_port", "143", &tmp_ac_prefs.imapport, P_USHORT,
437          &advanced.imapport_entry,
438          prefs_set_data_from_entry, prefs_set_entry},
439
440         {"set_nntpport", "FALSE", &tmp_ac_prefs.set_nntpport, P_BOOL,
441          &advanced.nntpport_chkbtn,
442          prefs_set_data_from_toggle, prefs_set_toggle},
443
444         {"nntp_port", "119", &tmp_ac_prefs.nntpport, P_USHORT,
445          &advanced.nntpport_entry,
446          prefs_set_data_from_entry, prefs_set_entry},
447
448         {"set_domain", "FALSE", &tmp_ac_prefs.set_domain, P_BOOL,
449          &advanced.domain_chkbtn,
450          prefs_set_data_from_toggle, prefs_set_toggle},
451
452         {"domain", NULL, &tmp_ac_prefs.domain, P_STRING,
453          &advanced.domain_entry,
454          prefs_set_data_from_entry, prefs_set_entry},
455
456         {"set_tunnelcmd", "FALSE", &tmp_ac_prefs.set_tunnelcmd, P_BOOL,
457          &advanced.tunnelcmd_chkbtn,
458          prefs_set_data_from_toggle, prefs_set_toggle},
459
460         {"tunnelcmd", NULL, &tmp_ac_prefs.tunnelcmd, P_STRING,
461          &advanced.tunnelcmd_entry,
462          prefs_set_data_from_entry, prefs_set_entry},
463
464         {"mark_crosspost_read", "FALSE", &tmp_ac_prefs.mark_crosspost_read, P_BOOL,
465          &advanced.crosspost_chkbtn,
466          prefs_set_data_from_toggle, prefs_set_toggle},
467
468         {"crosspost_color", NULL, &tmp_ac_prefs.crosspost_col, P_ENUM,
469          &advanced.crosspost_colormenu,
470          prefs_account_crosspost_set_data_from_colormenu,
471          prefs_account_crosspost_set_colormenu},
472
473         {"imap_directory", NULL, &tmp_ac_prefs.imap_dir, P_STRING,
474          &advanced.imapdir_entry, prefs_set_data_from_entry, prefs_set_entry},
475
476         {"set_sent_folder", "FALSE", &tmp_ac_prefs.set_sent_folder, P_BOOL,
477          &advanced.sent_folder_chkbtn,
478          prefs_set_data_from_toggle, prefs_set_toggle},
479         {"sent_folder", NULL, &tmp_ac_prefs.sent_folder, P_STRING,
480          &advanced.sent_folder_entry,
481          prefs_set_data_from_entry, prefs_set_entry},
482
483         {"set_draft_folder", "FALSE", &tmp_ac_prefs.set_draft_folder, P_BOOL,
484          &advanced.draft_folder_chkbtn,
485          prefs_set_data_from_toggle, prefs_set_toggle},
486         {"draft_folder", NULL, &tmp_ac_prefs.draft_folder, P_STRING,
487          &advanced.draft_folder_entry,
488          prefs_set_data_from_entry, prefs_set_entry},
489
490         {"set_trash_folder", "FALSE", &tmp_ac_prefs.set_trash_folder, P_BOOL,
491          &advanced.trash_folder_chkbtn,
492          prefs_set_data_from_toggle, prefs_set_toggle},
493         {"trash_folder", NULL, &tmp_ac_prefs.trash_folder, P_STRING,
494          &advanced.trash_folder_entry,
495          prefs_set_data_from_entry, prefs_set_entry},
496
497         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
498 };
499
500 static void prefs_account_create                (void);
501 static void prefs_account_basic_create          (void);
502 static void prefs_account_receive_create        (void);
503 static void prefs_account_send_create           (void);
504 static void prefs_account_compose_create        (void);
505 #if USE_GPGME
506 static void prefs_account_privacy_create        (void);
507 #endif /* USE_GPGME */
508 #if USE_SSL
509 static void prefs_account_ssl_create            (void);
510 #endif /* USE_SSL */
511 static void prefs_account_advanced_create       (void);
512
513 static void prefs_account_select_folder_cb      (GtkWidget      *widget,
514                                                  gpointer        data);
515 static void prefs_account_edit_custom_header    (void);
516
517 static gint prefs_account_deleted               (GtkWidget      *widget,
518                                                  GdkEventAny    *event,
519                                                  gpointer        data);
520 static void prefs_account_key_pressed           (GtkWidget      *widget,
521                                                  GdkEventKey    *event,
522                                                  gpointer        data);
523 static void prefs_account_ok                    (void);
524 static gint prefs_account_apply                 (void);
525 static void prefs_account_cancel                (void);
526
527 void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
528 {
529         const gchar *p = label;
530         gint id;
531
532         g_return_if_fail(ac_prefs != NULL);
533         g_return_if_fail(label != NULL);
534
535         memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
536         prefs_read_config(param, label, ACCOUNT_RC);
537         *ac_prefs = tmp_ac_prefs;
538         while (*p && !isdigit(*p)) p++;
539         id = atoi(p);
540         if (id < 0) g_warning("wrong account id: %d\n", id);
541         ac_prefs->account_id = id;
542
543         prefs_custom_header_read_config(ac_prefs);
544 }
545
546 void prefs_account_save_config(PrefsAccount *ac_prefs)
547 {
548         gchar *buf;
549
550         g_return_if_fail(ac_prefs != NULL);
551
552         tmp_ac_prefs = *ac_prefs;
553         buf = g_strdup_printf("Account: %d", ac_prefs->account_id);
554         prefs_save_config(param, buf, ACCOUNT_RC);
555 }
556
557 void prefs_account_save_config_all(GList *account_list)
558 {
559         GList *cur;
560         gchar *rcpath;
561         PrefFile *pfile;
562
563         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
564         if ((pfile = prefs_write_open(rcpath)) == NULL) {
565                 g_free(rcpath);
566                 return;
567         }
568         g_free(rcpath);
569
570         for (cur = account_list; cur != NULL; cur = cur->next) {
571                 tmp_ac_prefs = *(PrefsAccount *)cur->data;
572                 if (fprintf(pfile->fp, "[Account: %d]\n",
573                             tmp_ac_prefs.account_id) <= 0 ||
574                     prefs_write_param(param, pfile->fp) < 0) {
575                         g_warning(_("failed to write configuration to file\n"));
576                         prefs_write_close_revert(pfile);
577                         return;
578                 }
579                 if (cur->next) {
580                         if (fputc('\n', pfile->fp) == EOF) {
581                                 FILE_OP_ERROR(rcpath, "fputc");
582                                 prefs_write_close_revert(pfile);
583                                 return;
584                         }
585                 }
586         }
587
588         if (prefs_write_close(pfile) < 0)
589                 g_warning(_("failed to write configuration to file\n"));
590 }
591
592 void prefs_account_free(PrefsAccount *ac_prefs)
593 {
594         if (!ac_prefs) return;
595
596         tmp_ac_prefs = *ac_prefs;
597         prefs_free(param);
598 }
599
600 static gint prefs_account_get_new_id(void)
601 {
602         GList *ac_list;
603         PrefsAccount *ac;
604         static gint last_id = 0;
605
606         for (ac_list = account_get_list(); ac_list != NULL;
607              ac_list = ac_list->next) {
608                 ac = (PrefsAccount *)ac_list->data;
609                 if (last_id < ac->account_id)
610                         last_id = ac->account_id;
611         }
612
613         return last_id + 1;
614 }
615
616 PrefsAccount *prefs_account_open(PrefsAccount *ac_prefs)
617 {
618         gboolean new_account = FALSE;
619
620         if (prefs_rc_is_readonly(ACCOUNT_RC))
621                 return ac_prefs;
622
623         debug_print("Opening account preferences window...\n");
624
625         inc_lock();
626
627         cancelled = FALSE;
628
629         if (!ac_prefs) {
630                 ac_prefs = g_new0(PrefsAccount, 1);
631                 memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
632                 prefs_set_default(param);
633                 *ac_prefs = tmp_ac_prefs;
634                 ac_prefs->account_id = prefs_account_get_new_id();
635                 new_account = TRUE;
636         }
637
638         if (!dialog.window) {
639                 prefs_account_create();
640         }
641
642         manage_window_set_transient(GTK_WINDOW(dialog.window));
643         gtk_notebook_set_page(GTK_NOTEBOOK(dialog.notebook), 0);
644         gtk_widget_grab_focus(dialog.ok_btn);
645
646         tmp_ac_prefs = *ac_prefs;
647
648         if (new_account) {
649                 PrefsAccount *def_ac;
650                 gchar *buf;
651
652                 prefs_set_dialog_to_default(param);
653                 buf = g_strdup_printf(_("Account%d"), ac_prefs->account_id);
654                 gtk_entry_set_text(GTK_ENTRY(basic.acname_entry), buf);
655                 g_free(buf);
656                 def_ac = account_get_default();
657                 if (def_ac) {
658                         gtk_entry_set_text(GTK_ENTRY(basic.name_entry),
659                                            def_ac->name ? def_ac->name : "");
660                         gtk_entry_set_text(GTK_ENTRY(basic.addr_entry),
661                                            def_ac->address ? def_ac->address : "");
662                         gtk_entry_set_text(GTK_ENTRY(basic.org_entry),
663                                            def_ac->organization ? def_ac->organization : "");
664                 }
665                 menu_set_sensitive_all
666                         (GTK_MENU_SHELL
667                                 (gtk_option_menu_get_menu
668                                         (GTK_OPTION_MENU
669                                                 (basic.protocol_optmenu))),
670                          TRUE);
671                 gtk_window_set_title(GTK_WINDOW(dialog.window),
672                                      _("Preferences for new account"));
673                 gtk_widget_hide(dialog.apply_btn);
674         } else {
675                 prefs_set_dialog(param);
676                 gtk_window_set_title(GTK_WINDOW(dialog.window),
677                                      _("Account preferences"));
678                 gtk_widget_show(dialog.apply_btn);
679         }
680
681         if (ac_prefs->protocol != A_LOCAL) {
682                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
683                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
684         }
685
686         gtk_widget_show(dialog.window);
687         gtk_main();
688         gtk_widget_hide(dialog.window);
689
690         inc_unlock();
691
692         if (cancelled && new_account) {
693                 g_free(ac_prefs);
694                 return NULL;
695         } else {
696                 *ac_prefs = tmp_ac_prefs;
697                 return ac_prefs;
698         }
699 }
700
701 static void prefs_account_create(void)
702 {
703         gint page = 0;
704
705         debug_print("Creating account preferences window...\n");
706
707         /* create dialog */
708         prefs_dialog_create(&dialog);
709         gtk_signal_connect(GTK_OBJECT(dialog.window), "delete_event",
710                            GTK_SIGNAL_FUNC(prefs_account_deleted), NULL);
711         gtk_signal_connect(GTK_OBJECT(dialog.window), "key_press_event",
712                            GTK_SIGNAL_FUNC(prefs_account_key_pressed), NULL);
713         MANAGE_WINDOW_SIGNALS_CONNECT(dialog.window);
714
715         gtk_signal_connect(GTK_OBJECT(dialog.ok_btn), "clicked",
716                            GTK_SIGNAL_FUNC(prefs_account_ok), NULL);
717         gtk_signal_connect(GTK_OBJECT(dialog.apply_btn), "clicked",
718                            GTK_SIGNAL_FUNC(prefs_account_apply), NULL);
719         gtk_signal_connect(GTK_OBJECT(dialog.cancel_btn), "clicked",
720                            GTK_SIGNAL_FUNC(prefs_account_cancel), NULL);
721
722         prefs_account_basic_create();
723         SET_NOTEBOOK_LABEL(dialog.notebook, _("Basic"), page++);
724         prefs_account_receive_create();
725         SET_NOTEBOOK_LABEL(dialog.notebook, _("Receive"), page++);
726         prefs_account_send_create();
727         SET_NOTEBOOK_LABEL(dialog.notebook, _("Send"), page++);
728         prefs_account_compose_create();
729         SET_NOTEBOOK_LABEL(dialog.notebook, _("Compose"), page++);
730 #if USE_GPGME
731         prefs_account_privacy_create();
732         SET_NOTEBOOK_LABEL(dialog.notebook, _("Privacy"), page++);
733 #endif /* USE_GPGME */
734 #if USE_SSL
735         prefs_account_ssl_create();
736         SET_NOTEBOOK_LABEL(dialog.notebook, _("SSL"), page++);
737 #endif /* USE_SSL */
738         prefs_account_advanced_create();
739         SET_NOTEBOOK_LABEL(dialog.notebook, _("Advanced"), page++);
740
741         prefs_account_fix_size();
742 }
743
744 /**
745  * prefs_account_fix_size:
746  * 
747  * Fix the window size after creating widgets by selecting "Local"
748  * protocol (currently it has the largest size of parameter widgets).
749  * Without this the window gets too large.
750  **/
751 static void prefs_account_fix_size(void)
752 {
753         GtkOptionMenu *optmenu = GTK_OPTION_MENU (basic.protocol_optmenu);
754         GtkWidget *menu;
755         GtkWidget *menuitem;
756
757         gtk_option_menu_set_history (optmenu, 4); /* local */
758         menu = gtk_option_menu_get_menu (optmenu);
759         menuitem = gtk_menu_get_active (GTK_MENU (menu));
760         gtk_menu_item_activate (GTK_MENU_ITEM (menuitem));
761 }
762
763 #define SET_ACTIVATE(menuitem) \
764 { \
765         gtk_signal_connect(GTK_OBJECT(menuitem), "activate", \
766                            GTK_SIGNAL_FUNC(prefs_account_protocol_activated), \
767                            NULL); \
768 }
769
770 #define TABLE_YPAD 2
771
772 static void prefs_account_basic_create(void)
773 {
774         GtkWidget *vbox1;
775         GtkWidget *hbox;
776         GtkWidget *label;
777         GtkWidget *acname_entry;
778         GtkWidget *default_chkbtn;
779         GtkWidget *frame1;
780         GtkWidget *table1;
781         GtkWidget *name_entry;
782         GtkWidget *addr_entry;
783         GtkWidget *org_entry;
784
785         GtkWidget *serv_frame;
786         GtkWidget *vbox2;
787         GtkWidget *optmenu;
788         GtkWidget *optmenu_menu;
789         GtkWidget *menuitem;
790         GtkWidget *serv_table;
791         GtkWidget *recvserv_label;
792         GtkWidget *smtpserv_label;
793         GtkWidget *nntpserv_label;
794         GtkWidget *localmbox_label;
795         GtkWidget *mailcmd_label;
796         GtkWidget *recvserv_entry;
797         GtkWidget *smtpserv_entry;
798         GtkWidget *nntpserv_entry;
799         GtkWidget *nntpauth_chkbtn;
800         GtkWidget *localmbox_entry;
801         GtkWidget *mailcmd_chkbtn;
802         GtkWidget *mailcmd_entry;
803         GtkWidget *uid_label;
804         GtkWidget *pass_label;
805         GtkWidget *uid_entry;
806         GtkWidget *pass_entry;
807
808         vbox1 = gtk_vbox_new (FALSE, VSPACING);
809         gtk_widget_show (vbox1);
810         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
811         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
812
813         hbox = gtk_hbox_new (FALSE, 8);
814         gtk_widget_show (hbox);
815         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
816
817         label = gtk_label_new (_("Name of this account"));
818         gtk_widget_show (label);
819         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
820
821         acname_entry = gtk_entry_new ();
822         gtk_widget_show (acname_entry);
823         gtk_widget_set_usize (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
824         gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
825
826         default_chkbtn = gtk_check_button_new_with_label (_("Set as default"));
827         gtk_widget_show (default_chkbtn);
828         gtk_box_pack_end (GTK_BOX (hbox), default_chkbtn, FALSE, FALSE, 0);
829
830         PACK_FRAME (vbox1, frame1, _("Personal information"));
831
832         table1 = gtk_table_new (3, 2, FALSE);
833         gtk_widget_show (table1);
834         gtk_container_add (GTK_CONTAINER (frame1), table1);
835         gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
836         gtk_table_set_row_spacings (GTK_TABLE (table1), VSPACING_NARROW);
837         gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
838
839         label = gtk_label_new (_("Full name"));
840         gtk_widget_show (label);
841         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 0, 1,
842                           GTK_FILL, 0, 0, 0);
843         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
844
845         label = gtk_label_new (_("Mail address"));
846         gtk_widget_show (label);
847         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 1, 2,
848                           GTK_FILL, 0, 0, 0);
849         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
850
851         label = gtk_label_new (_("Organization"));
852         gtk_widget_show (label);
853         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 2, 3,
854                           GTK_FILL, 0, 0, 0);
855         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
856
857         name_entry = gtk_entry_new ();
858         gtk_widget_show (name_entry);
859         gtk_table_attach (GTK_TABLE (table1), name_entry, 1, 2, 0, 1,
860                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
861                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
862
863         addr_entry = gtk_entry_new ();
864         gtk_widget_show (addr_entry);
865         gtk_table_attach (GTK_TABLE (table1), addr_entry, 1, 2, 1, 2,
866                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
867                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
868
869         org_entry = gtk_entry_new ();
870         gtk_widget_show (org_entry);
871         gtk_table_attach (GTK_TABLE (table1), org_entry, 1, 2, 2, 3,
872                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
873                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
874
875         PACK_FRAME (vbox1, serv_frame, _("Server information"));
876
877         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
878         gtk_widget_show (vbox2);
879         gtk_container_add (GTK_CONTAINER (serv_frame), vbox2);
880         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
881
882         hbox = gtk_hbox_new (FALSE, 8);
883         gtk_widget_show (hbox);
884         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
885
886         label = gtk_label_new (_("Protocol"));
887         gtk_widget_show (label);
888         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
889
890         optmenu = gtk_option_menu_new ();
891         gtk_widget_show (optmenu);
892         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
893
894         optmenu_menu = gtk_menu_new ();
895
896         MENUITEM_ADD (optmenu_menu, menuitem, _("POP3 (normal)"),  A_POP3);
897         SET_ACTIVATE (menuitem);
898         MENUITEM_ADD (optmenu_menu, menuitem, _("POP3 (APOP auth)"),  A_APOP);
899         SET_ACTIVATE (menuitem);
900         MENUITEM_ADD (optmenu_menu, menuitem, _("IMAP4"), A_IMAP4);
901         SET_ACTIVATE (menuitem);
902         MENUITEM_ADD (optmenu_menu, menuitem, _("News (NNTP)"), A_NNTP);
903         SET_ACTIVATE (menuitem);
904         MENUITEM_ADD (optmenu_menu, menuitem, _("None (local)"), A_LOCAL);
905         SET_ACTIVATE (menuitem);
906
907         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
908
909         serv_table = gtk_table_new (6, 4, FALSE);
910         gtk_widget_show (serv_table);
911         gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
912         gtk_table_set_row_spacings (GTK_TABLE (serv_table), VSPACING_NARROW);
913         gtk_table_set_row_spacing (GTK_TABLE (serv_table), 3, 0);
914         gtk_table_set_col_spacings (GTK_TABLE (serv_table), 8);
915
916         nntpserv_entry = gtk_entry_new ();
917         gtk_widget_show (nntpserv_entry);
918         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_entry, 1, 4, 0, 1,
919                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
920                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
921 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 0, 0); */
922
923         nntpauth_chkbtn = gtk_check_button_new_with_label
924                 (_("This server requires authentication"));
925         gtk_widget_show (nntpauth_chkbtn);
926         gtk_table_attach (GTK_TABLE (serv_table), nntpauth_chkbtn, 0, 4, 1, 2,
927                           GTK_FILL, 0, 0, 0);
928
929         recvserv_entry = gtk_entry_new ();
930         gtk_widget_show (recvserv_entry);
931         gtk_table_attach (GTK_TABLE (serv_table), recvserv_entry, 1, 4, 2, 3,
932                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
933                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
934
935         localmbox_entry = gtk_entry_new ();
936         gtk_widget_show (localmbox_entry);
937         gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 3, 4,
938                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
939                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
940
941         smtpserv_entry = gtk_entry_new ();
942         gtk_widget_show (smtpserv_entry);
943         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_entry, 1, 4, 4, 5,
944                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
945                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
946
947         mailcmd_entry = gtk_entry_new ();
948         gtk_widget_show (mailcmd_entry);
949         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 6, 7,
950                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
951                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
952
953         uid_entry = gtk_entry_new ();
954         gtk_widget_show (uid_entry);
955         gtk_widget_set_usize (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
956         gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 2, 7, 8,
957                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
958                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
959
960         pass_entry = gtk_entry_new ();
961         gtk_widget_show (pass_entry);
962         gtk_widget_set_usize (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
963         gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 3, 4, 7, 8,
964                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
965                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
966         gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
967
968         nntpserv_label = gtk_label_new (_("News server"));
969         gtk_widget_show (nntpserv_label);
970         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_label, 0, 1, 0, 1,
971                           GTK_FILL, 0, 0, 0);
972         gtk_misc_set_alignment (GTK_MISC (nntpserv_label), 1, 0.5);
973
974         recvserv_label = gtk_label_new (_("Server for receiving"));
975         gtk_widget_show (recvserv_label);
976         gtk_table_attach (GTK_TABLE (serv_table), recvserv_label, 0, 1, 2, 3,
977                           GTK_FILL, 0, 0, 0);
978         gtk_misc_set_alignment (GTK_MISC (recvserv_label), 1, 0.5);
979
980         localmbox_label = gtk_label_new (_("Local mailbox file"));
981         gtk_widget_show (localmbox_label);
982         gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 3, 4,
983                           GTK_FILL, 0, 0, 0);
984         gtk_misc_set_alignment (GTK_MISC (localmbox_label), 1, 0.5);
985 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
986
987         smtpserv_label = gtk_label_new (_("SMTP server (send)"));
988         gtk_widget_show (smtpserv_label);
989         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_label, 0, 1, 4, 5,
990                           GTK_FILL, 0, 0, 0);
991         gtk_misc_set_alignment (GTK_MISC (smtpserv_label), 1, 0.5);
992 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
993
994         mailcmd_chkbtn = gtk_check_button_new_with_label
995                 (_("Use mail command rather than SMTP server"));
996         gtk_widget_show (mailcmd_chkbtn);
997         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_chkbtn, 0, 4, 5, 6,
998                           GTK_EXPAND | GTK_FILL,
999                           0, 0, TABLE_YPAD);
1000         gtk_signal_connect(GTK_OBJECT(mailcmd_chkbtn), "toggled",
1001                            GTK_SIGNAL_FUNC(prefs_account_mailcmd_toggled),
1002                            NULL);
1003
1004         mailcmd_label = gtk_label_new (_("command to send mails"));
1005         gtk_widget_show (mailcmd_label);
1006         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 6, 7,
1007                           GTK_FILL, 0, 0, 0);
1008         gtk_misc_set_alignment (GTK_MISC (mailcmd_label), 1, 0.5);
1009 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
1010
1011         uid_label = gtk_label_new (_("User ID"));
1012         gtk_widget_show (uid_label);
1013         gtk_table_attach (GTK_TABLE (serv_table), uid_label, 0, 1, 7, 8,
1014                           GTK_FILL, 0, 0, 0);
1015         gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
1016
1017         pass_label = gtk_label_new (_("Password"));
1018         gtk_widget_show (pass_label);
1019         gtk_table_attach (GTK_TABLE (serv_table), pass_label, 2, 3, 7, 8,
1020                           0, 0, 0, 0);
1021
1022         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, uid_label);
1023         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, pass_label);
1024         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, uid_entry);
1025         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, pass_entry);
1026
1027         basic.acname_entry   = acname_entry;
1028         basic.default_chkbtn = default_chkbtn;
1029
1030         basic.name_entry = name_entry;
1031         basic.addr_entry = addr_entry;
1032         basic.org_entry  = org_entry;
1033
1034         basic.serv_frame       = serv_frame;
1035         basic.serv_table       = serv_table;
1036         basic.protocol_optmenu = optmenu;
1037         basic.recvserv_label   = recvserv_label;
1038         basic.recvserv_entry   = recvserv_entry;
1039         basic.smtpserv_label   = smtpserv_label;
1040         basic.smtpserv_entry   = smtpserv_entry;
1041         basic.nntpserv_label   = nntpserv_label;
1042         basic.nntpserv_entry   = nntpserv_entry;
1043         basic.nntpauth_chkbtn  = nntpauth_chkbtn;
1044         basic.localmbox_label   = localmbox_label;
1045         basic.localmbox_entry   = localmbox_entry;
1046         basic.mailcmd_chkbtn   = mailcmd_chkbtn;
1047         basic.mailcmd_label   = mailcmd_label;
1048         basic.mailcmd_entry   = mailcmd_entry;
1049         basic.uid_label        = uid_label;
1050         basic.pass_label       = pass_label;
1051         basic.uid_entry        = uid_entry;
1052         basic.pass_entry       = pass_entry;
1053 }
1054
1055 static void prefs_account_receive_create(void)
1056 {
1057         GtkWidget *vbox1;
1058         GtkWidget *frame1;
1059         GtkWidget *vbox2;
1060         GtkWidget *rmmail_chkbtn;
1061         GtkWidget *hbox_spc;
1062         GtkWidget *leave_time_label;
1063         GtkWidget *leave_time_entry;
1064         GtkWidget *getall_chkbtn;
1065         GtkWidget *hbox1;
1066         GtkWidget *size_limit_chkbtn;
1067         GtkWidget *size_limit_entry;
1068         GtkWidget *label;
1069         GtkWidget *filter_on_recv_chkbtn;
1070         GtkWidget *sd_filter_on_recv_chkbtn;
1071         GtkWidget *sd_rmmail_chkbtn;
1072         GtkWidget *vbox3;
1073         GtkWidget *inbox_label;
1074         GtkWidget *inbox_entry;
1075         GtkWidget *inbox_btn;
1076         GtkWidget *recvatgetall_chkbtn;
1077
1078         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1079         gtk_widget_show (vbox1);
1080         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1081         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1082
1083         PACK_FRAME (vbox1, frame1, _("POP3"));
1084
1085         vbox2 = gtk_vbox_new (FALSE, 0);
1086         gtk_widget_show (vbox2);
1087         gtk_container_add (GTK_CONTAINER (frame1), vbox2);
1088         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1089
1090         PACK_CHECK_BUTTON (vbox2, rmmail_chkbtn,
1091                            _("Remove messages on server when received"));
1092
1093         hbox1 = gtk_hbox_new (FALSE, 8);
1094         gtk_widget_show (hbox1);
1095         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1096
1097         hbox_spc = gtk_hbox_new (FALSE, 0);
1098         gtk_widget_show (hbox_spc);
1099         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1100         gtk_widget_set_usize (hbox_spc, 12, -1);
1101
1102         leave_time_label = gtk_label_new (_("Remove after"));
1103         gtk_widget_show (leave_time_label);
1104         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1105
1106         leave_time_entry = gtk_entry_new ();
1107         gtk_widget_show (leave_time_entry);
1108         gtk_widget_set_usize (leave_time_entry, 64, -1);
1109         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_entry, FALSE, FALSE, 0);
1110
1111         leave_time_label = gtk_label_new (_("days"));
1112         gtk_widget_show (leave_time_label);
1113         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1114
1115         SET_TOGGLE_SENSITIVITY (rmmail_chkbtn, hbox1);
1116
1117         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1118
1119         hbox1 = gtk_hbox_new (FALSE, 8);
1120         gtk_widget_show (hbox1);
1121         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1122
1123         hbox_spc = gtk_hbox_new (FALSE, 0);
1124         gtk_widget_show (hbox_spc);
1125         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1126         gtk_widget_set_usize (hbox_spc, 12, -1);
1127
1128         leave_time_label = gtk_label_new (_("(0 days: remove immediately)"));
1129         gtk_widget_show (leave_time_label);
1130         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1131
1132         SET_TOGGLE_SENSITIVITY (rmmail_chkbtn, hbox1);
1133
1134         PACK_CHECK_BUTTON (vbox2, getall_chkbtn,
1135                            _("Download all messages on server"));
1136         PACK_CHECK_BUTTON (vbox2, sd_filter_on_recv_chkbtn,
1137                            _("Use filtering rules with Selective Download"));
1138         PACK_CHECK_BUTTON (vbox2, sd_rmmail_chkbtn,
1139                            _("Remove mail after downloading with Selective Download"));
1140
1141         hbox1 = gtk_hbox_new (FALSE, 8);
1142         gtk_widget_show (hbox1);
1143         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1144
1145         PACK_CHECK_BUTTON (hbox1, size_limit_chkbtn, _("Receive size limit"));
1146
1147         size_limit_entry = gtk_entry_new ();
1148         gtk_widget_show (size_limit_entry);
1149         gtk_widget_set_usize (size_limit_entry, 64, -1);
1150         gtk_box_pack_start (GTK_BOX (hbox1), size_limit_entry, FALSE, FALSE, 0);
1151
1152         label = gtk_label_new ("KB");
1153         gtk_widget_show (label);
1154         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1155
1156         SET_TOGGLE_SENSITIVITY (size_limit_chkbtn, size_limit_entry);
1157
1158         PACK_CHECK_BUTTON (vbox2, filter_on_recv_chkbtn,
1159                            _("Filter messages on receiving"));
1160
1161         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1162
1163         hbox1 = gtk_hbox_new (FALSE, 8);
1164         gtk_widget_show (hbox1);
1165         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1166
1167         inbox_label = gtk_label_new (_("Default inbox"));
1168         gtk_widget_show (inbox_label);
1169         gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
1170
1171         inbox_entry = gtk_entry_new ();
1172         gtk_widget_show (inbox_entry);
1173         gtk_widget_set_usize (inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
1174         gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
1175
1176         inbox_btn = gtk_button_new_with_label (_(" Select... "));
1177         gtk_widget_show (inbox_btn);
1178         gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1179         gtk_signal_connect (GTK_OBJECT (inbox_btn), "clicked",
1180                             GTK_SIGNAL_FUNC (prefs_account_select_folder_cb),
1181                             inbox_entry);
1182
1183         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1184
1185         hbox1 = gtk_hbox_new (FALSE, 8);
1186         gtk_widget_show (hbox1);
1187         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1188
1189         label = gtk_label_new
1190                 (_("(Unfiltered messages will be stored in this folder)"));
1191         gtk_widget_show (label);
1192         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1193         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1194
1195         PACK_CHECK_BUTTON
1196                 (vbox1, recvatgetall_chkbtn,
1197                  _("`Get all' checks for new messages on this account"));
1198
1199         receive.pop3_frame               = frame1;
1200         receive.rmmail_chkbtn            = rmmail_chkbtn;
1201         receive.leave_time_entry         = leave_time_entry;
1202         receive.getall_chkbtn            = getall_chkbtn;
1203         receive.size_limit_chkbtn        = size_limit_chkbtn;
1204         receive.size_limit_entry         = size_limit_entry;
1205         receive.filter_on_recv_chkbtn    = filter_on_recv_chkbtn;
1206         receive.sd_filter_on_recv_chkbtn = sd_filter_on_recv_chkbtn;
1207         receive.sd_rmmail_chkbtn         = sd_rmmail_chkbtn;
1208         receive.inbox_label              = inbox_label;
1209         receive.inbox_entry              = inbox_entry;
1210         receive.inbox_btn                = inbox_btn;
1211
1212         receive.recvatgetall_chkbtn      = recvatgetall_chkbtn;
1213 }
1214
1215 static void prefs_account_send_create(void)
1216 {
1217         GtkWidget *vbox1;
1218         GtkWidget *vbox2;
1219         GtkWidget *frame;
1220         GtkWidget *date_chkbtn;
1221         GtkWidget *msgid_chkbtn;
1222         GtkWidget *hbox;
1223         GtkWidget *customhdr_chkbtn;
1224         GtkWidget *customhdr_edit_btn;
1225         GtkWidget *vbox3;
1226         GtkWidget *smtp_auth_chkbtn;
1227         GtkWidget *optmenu;
1228         GtkWidget *optmenu_menu;
1229         GtkWidget *menuitem;
1230         GtkWidget *vbox4;
1231         GtkWidget *hbox_spc;
1232         GtkWidget *label;
1233         GtkWidget *smtp_uid_entry;
1234         GtkWidget *smtp_pass_entry;
1235         GtkWidget *vbox_spc;
1236         GtkWidget *pop_bfr_smtp_chkbtn;
1237
1238         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1239         gtk_widget_show (vbox1);
1240         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1241         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1242
1243         PACK_FRAME (vbox1, frame, _("Header"));
1244
1245         vbox2 = gtk_vbox_new (FALSE, 0);
1246         gtk_widget_show (vbox2);
1247         gtk_container_add (GTK_CONTAINER (frame), vbox2);
1248         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1249
1250         PACK_CHECK_BUTTON (vbox2, date_chkbtn, _("Add Date header field"));
1251         PACK_CHECK_BUTTON (vbox2, msgid_chkbtn, _("Generate Message-ID"));
1252
1253         hbox = gtk_hbox_new (FALSE, 12);
1254         gtk_widget_show (hbox);
1255         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1256
1257         PACK_CHECK_BUTTON (hbox, customhdr_chkbtn,
1258                            _("Add user-defined header"));
1259
1260         customhdr_edit_btn = gtk_button_new_with_label (_(" Edit... "));
1261         gtk_widget_show (customhdr_edit_btn);
1262         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1263                             FALSE, FALSE, 0);
1264         gtk_signal_connect (GTK_OBJECT (customhdr_edit_btn), "clicked",
1265                             GTK_SIGNAL_FUNC (prefs_account_edit_custom_header),
1266                             NULL);
1267
1268         SET_TOGGLE_SENSITIVITY (customhdr_chkbtn, customhdr_edit_btn);
1269
1270         PACK_FRAME (vbox1, frame, _("Authentication"));
1271
1272         vbox3 = gtk_vbox_new (FALSE, 0);
1273         gtk_widget_show (vbox3);
1274         gtk_container_add (GTK_CONTAINER (frame), vbox3);
1275         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1276
1277         PACK_CHECK_BUTTON (vbox3, smtp_auth_chkbtn,
1278                 _("SMTP Authentication (SMTP AUTH)"));
1279
1280         vbox4 = gtk_vbox_new (FALSE, 0);
1281         gtk_widget_show (vbox4);
1282         gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
1283
1284         hbox = gtk_hbox_new (FALSE, 8);
1285         gtk_widget_show (hbox);
1286         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1287
1288         hbox_spc = gtk_hbox_new (FALSE, 0);
1289         gtk_widget_show (hbox_spc);
1290         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1291         gtk_widget_set_usize (hbox_spc, 12, -1);
1292
1293         label = gtk_label_new (_("Authentication method"));
1294         gtk_widget_show (label);
1295         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1296
1297         optmenu = gtk_option_menu_new ();
1298         gtk_widget_show (optmenu);
1299         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
1300
1301         optmenu_menu = gtk_menu_new ();
1302
1303         MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
1304         MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", SMTPAUTH_LOGIN);
1305         MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
1306         MENUITEM_ADD (optmenu_menu, menuitem, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
1307         gtk_widget_set_sensitive (menuitem, FALSE);
1308
1309         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1310
1311         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1312
1313         hbox = gtk_hbox_new (FALSE, 8);
1314         gtk_widget_show (hbox);
1315         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1316
1317         hbox_spc = gtk_hbox_new (FALSE, 0);
1318         gtk_widget_show (hbox_spc);
1319         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1320         gtk_widget_set_usize (hbox_spc, 12, -1);
1321
1322         label = gtk_label_new (_("User ID"));
1323         gtk_widget_show (label);
1324         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1325
1326         smtp_uid_entry = gtk_entry_new ();
1327         gtk_widget_show (smtp_uid_entry);
1328         gtk_widget_set_usize (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1329         gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
1330
1331         label = gtk_label_new (_("Password"));
1332         gtk_widget_show (label);
1333         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1334
1335         smtp_pass_entry = gtk_entry_new ();
1336         gtk_widget_show (smtp_pass_entry);
1337         gtk_widget_set_usize (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1338         gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
1339         gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
1340
1341         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1342
1343         hbox = gtk_hbox_new (FALSE, 8);
1344         gtk_widget_show (hbox);
1345         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1346
1347         hbox_spc = gtk_hbox_new (FALSE, 0);
1348         gtk_widget_show (hbox_spc);
1349         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1350         gtk_widget_set_usize (hbox_spc, 12, -1);
1351
1352         label = gtk_label_new
1353                 (_("If you leave these entries empty, the same\n"
1354                    "user ID and password as receiving will be used."));
1355         gtk_widget_show (label);
1356         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1357         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1358
1359         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, vbox4);
1360
1361         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_chkbtn,
1362                 _("Authenticate with POP3 before sending"));
1363
1364         p_send.date_chkbtn      = date_chkbtn;
1365         p_send.msgid_chkbtn     = msgid_chkbtn;
1366         p_send.customhdr_chkbtn = customhdr_chkbtn;
1367
1368         p_send.smtp_auth_chkbtn       = smtp_auth_chkbtn;
1369         p_send.smtp_auth_type_optmenu = optmenu;
1370         p_send.smtp_uid_entry         = smtp_uid_entry;
1371         p_send.smtp_pass_entry        = smtp_pass_entry;
1372         p_send.pop_bfr_smtp_chkbtn    = pop_bfr_smtp_chkbtn;
1373 }
1374
1375 static void prefs_account_compose_create(void)
1376 {
1377         GtkWidget *vbox1;
1378         GtkWidget *hbox;
1379         GtkWidget *label;
1380         GtkWidget *sigpath_entry;
1381         GtkWidget *frame;
1382         GtkWidget *table;
1383         GtkWidget *autocc_chkbtn;
1384         GtkWidget *autocc_entry;
1385         GtkWidget *autobcc_chkbtn;
1386         GtkWidget *autobcc_entry;
1387         GtkWidget *autoreplyto_chkbtn;
1388         GtkWidget *autoreplyto_entry;
1389
1390         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1391         gtk_widget_show (vbox1);
1392         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1393         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1394
1395         hbox = gtk_hbox_new (FALSE, 8);
1396         gtk_widget_show (hbox);
1397         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
1398
1399         label = gtk_label_new (_("Signature file"));
1400         gtk_widget_show (label);
1401         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1402
1403         sigpath_entry = gtk_entry_new ();
1404         gtk_widget_show (sigpath_entry);
1405         gtk_box_pack_start (GTK_BOX (hbox), sigpath_entry, TRUE, TRUE, 0);
1406
1407         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
1408
1409         table =  gtk_table_new (3, 2, FALSE);
1410         gtk_widget_show (table);
1411         gtk_container_add (GTK_CONTAINER (frame), table);
1412         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
1413         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
1414         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1415
1416         autocc_chkbtn = gtk_check_button_new_with_label (_("Cc"));
1417         gtk_widget_show (autocc_chkbtn);
1418         gtk_table_attach (GTK_TABLE (table), autocc_chkbtn, 0, 1, 0, 1,
1419                           GTK_FILL, 0, 0, 0);
1420
1421         autocc_entry = gtk_entry_new ();
1422         gtk_widget_show (autocc_entry);
1423         gtk_table_attach (GTK_TABLE (table), autocc_entry, 1, 2, 0, 1,
1424                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1425                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1426
1427         SET_TOGGLE_SENSITIVITY (autocc_chkbtn, autocc_entry);
1428
1429         autobcc_chkbtn = gtk_check_button_new_with_label (_("Bcc"));
1430         gtk_widget_show (autobcc_chkbtn);
1431         gtk_table_attach (GTK_TABLE (table), autobcc_chkbtn, 0, 1, 1, 2,
1432                           GTK_FILL, 0, 0, 0);
1433
1434         autobcc_entry = gtk_entry_new ();
1435         gtk_widget_show (autobcc_entry);
1436         gtk_table_attach (GTK_TABLE (table), autobcc_entry, 1, 2, 1, 2,
1437                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1438                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1439
1440         SET_TOGGLE_SENSITIVITY (autobcc_chkbtn, autobcc_entry);
1441
1442         autoreplyto_chkbtn = gtk_check_button_new_with_label (_("Reply-To"));
1443         gtk_widget_show (autoreplyto_chkbtn);
1444         gtk_table_attach (GTK_TABLE (table), autoreplyto_chkbtn, 0, 1, 2, 3,
1445                           GTK_FILL, 0, 0, 0);
1446
1447         autoreplyto_entry = gtk_entry_new ();
1448         gtk_widget_show (autoreplyto_entry);
1449         gtk_table_attach (GTK_TABLE (table), autoreplyto_entry, 1, 2, 2, 3,
1450                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1451                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1452
1453         SET_TOGGLE_SENSITIVITY (autoreplyto_chkbtn, autoreplyto_entry);
1454
1455         compose.sigpath_entry = sigpath_entry;
1456
1457         compose.autocc_chkbtn      = autocc_chkbtn;
1458         compose.autocc_entry       = autocc_entry;
1459         compose.autobcc_chkbtn     = autobcc_chkbtn;
1460         compose.autobcc_entry      = autobcc_entry;
1461         compose.autoreplyto_chkbtn = autoreplyto_chkbtn;
1462         compose.autoreplyto_entry  = autoreplyto_entry;
1463 }
1464
1465 #if USE_GPGME
1466 static void prefs_account_privacy_create(void)
1467 {
1468         GtkWidget *vbox1;
1469         GtkWidget *frame1;
1470         GtkWidget *vbox2;
1471         GtkWidget *hbox1;
1472         GtkWidget *label;
1473         GtkWidget *default_encrypt_chkbtn;
1474         GtkWidget *default_sign_chkbtn;
1475         GtkWidget *ascii_armored_chkbtn;
1476         GtkWidget *clearsign_chkbtn;
1477         GtkWidget *defaultkey_radiobtn;
1478         GtkWidget *emailkey_radiobtn;
1479         GtkWidget *customkey_radiobtn;
1480         GtkWidget *customkey_entry;
1481
1482         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1483         gtk_widget_show (vbox1);
1484         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1485         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1486
1487         vbox2 = gtk_vbox_new (FALSE, 0);
1488         gtk_widget_show (vbox2);
1489         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1490
1491         PACK_CHECK_BUTTON (vbox2, default_encrypt_chkbtn,
1492                            _("Encrypt message by default"));
1493         PACK_CHECK_BUTTON (vbox2, default_sign_chkbtn,
1494                            _("Sign message by default"));
1495         PACK_CHECK_BUTTON (vbox2, ascii_armored_chkbtn,
1496                            _("Use ASCII-armored format for encryption"));
1497         PACK_CHECK_BUTTON (vbox2, clearsign_chkbtn,
1498                            _("Use clear text signature"));
1499         gtk_signal_connect (GTK_OBJECT (ascii_armored_chkbtn), "toggled",
1500                             prefs_account_ascii_armored_warning, NULL);
1501
1502         PACK_FRAME (vbox1, frame1, _("Sign key"));
1503
1504         vbox2 = gtk_vbox_new (FALSE, 0);
1505         gtk_widget_show (vbox2);
1506         gtk_container_add (GTK_CONTAINER (frame1), vbox2);
1507         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1508
1509         defaultkey_radiobtn = gtk_radio_button_new_with_label
1510                 (NULL, _("Use default GnuPG key"));
1511         gtk_widget_show (defaultkey_radiobtn);
1512         gtk_box_pack_start (GTK_BOX (vbox2), defaultkey_radiobtn,
1513                             FALSE, FALSE, 0);
1514         gtk_object_set_user_data (GTK_OBJECT (defaultkey_radiobtn),
1515                                   GINT_TO_POINTER (SIGN_KEY_DEFAULT));
1516
1517         emailkey_radiobtn = gtk_radio_button_new_with_label_from_widget
1518                 (GTK_RADIO_BUTTON (defaultkey_radiobtn),
1519                  _("Select key by your email address"));
1520         gtk_widget_show (emailkey_radiobtn);
1521         gtk_box_pack_start (GTK_BOX (vbox2), emailkey_radiobtn,
1522                             FALSE, FALSE, 0);
1523         gtk_object_set_user_data (GTK_OBJECT (emailkey_radiobtn),
1524                                   GINT_TO_POINTER (SIGN_KEY_BY_FROM));
1525
1526         customkey_radiobtn = gtk_radio_button_new_with_label_from_widget
1527                 (GTK_RADIO_BUTTON (defaultkey_radiobtn),
1528                  _("Specify key manually"));
1529         gtk_widget_show (customkey_radiobtn);
1530         gtk_box_pack_start (GTK_BOX (vbox2), customkey_radiobtn,
1531                             FALSE, FALSE, 0);
1532         gtk_object_set_user_data (GTK_OBJECT (customkey_radiobtn),
1533                                   GINT_TO_POINTER (SIGN_KEY_CUSTOM));
1534
1535         hbox1 = gtk_hbox_new (FALSE, 8);
1536         gtk_widget_show (hbox1);
1537         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1538
1539         label = gtk_label_new ("");
1540         gtk_widget_show (label);
1541         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1542         gtk_widget_set_usize (label, 16, -1);
1543
1544         label = gtk_label_new (_("User or key ID:"));
1545         gtk_widget_show (label);
1546         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1547
1548         customkey_entry = gtk_entry_new ();
1549         gtk_widget_show (customkey_entry);
1550         gtk_box_pack_start (GTK_BOX (hbox1), customkey_entry,
1551                             TRUE, TRUE, 0);
1552
1553         SET_TOGGLE_SENSITIVITY (customkey_radiobtn, customkey_entry);
1554
1555         privacy.default_encrypt_chkbtn = default_encrypt_chkbtn;
1556         privacy.default_sign_chkbtn    = default_sign_chkbtn;
1557         privacy.ascii_armored_chkbtn   = ascii_armored_chkbtn;
1558         privacy.clearsign_chkbtn       = clearsign_chkbtn;
1559         privacy.defaultkey_radiobtn    = defaultkey_radiobtn;
1560         privacy.emailkey_radiobtn      = emailkey_radiobtn;
1561         privacy.customkey_radiobtn     = customkey_radiobtn;
1562         privacy.customkey_entry        = customkey_entry;
1563 }
1564 #endif /* USE_GPGME */
1565
1566 #if USE_SSL
1567
1568 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data)               \
1569 {                                                                       \
1570         btn = gtk_radio_button_new_with_label_from_widget               \
1571                 (GTK_RADIO_BUTTON (btn_p), label);                      \
1572         gtk_widget_show (btn);                                          \
1573         gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0);       \
1574         gtk_object_set_user_data (GTK_OBJECT (btn),                     \
1575                                   GINT_TO_POINTER (data));              \
1576 }
1577
1578 #define CREATE_RADIO_BUTTONS(box,                                       \
1579                              btn1, btn1_label, btn1_data,               \
1580                              btn2, btn2_label, btn2_data,               \
1581                              btn3, btn3_label, btn3_data)               \
1582 {                                                                       \
1583         btn1 = gtk_radio_button_new_with_label(NULL, btn1_label);       \
1584         gtk_widget_show (btn1);                                         \
1585         gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0);      \
1586         gtk_object_set_user_data (GTK_OBJECT (btn1),                    \
1587                                   GINT_TO_POINTER (btn1_data));         \
1588                                                                         \
1589         CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data);    \
1590         CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data);    \
1591 }
1592
1593 static void prefs_account_ssl_create(void)
1594 {
1595         GtkWidget *vbox1;
1596
1597         GtkWidget *pop_frame;
1598         GtkWidget *vbox2;
1599         GtkWidget *pop_nossl_radiobtn;
1600         GtkWidget *pop_ssltunnel_radiobtn;
1601         GtkWidget *pop_starttls_radiobtn;
1602
1603         GtkWidget *imap_frame;
1604         GtkWidget *vbox3;
1605         GtkWidget *imap_nossl_radiobtn;
1606         GtkWidget *imap_ssltunnel_radiobtn;
1607         GtkWidget *imap_starttls_radiobtn;
1608
1609         GtkWidget *nntp_frame;
1610         GtkWidget *vbox4;
1611         GtkWidget *nntp_nossl_radiobtn;
1612         GtkWidget *nntp_ssltunnel_radiobtn;
1613
1614         GtkWidget *send_frame;
1615         GtkWidget *vbox5;
1616         GtkWidget *smtp_nossl_radiobtn;
1617         GtkWidget *smtp_ssltunnel_radiobtn;
1618         GtkWidget *smtp_starttls_radiobtn;
1619
1620         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1621         gtk_widget_show (vbox1);
1622         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1623         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1624
1625         PACK_FRAME (vbox1, pop_frame, _("POP3"));
1626         vbox2 = gtk_vbox_new (FALSE, 0);
1627         gtk_widget_show (vbox2);
1628         gtk_container_add (GTK_CONTAINER (pop_frame), vbox2);
1629         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1630
1631         CREATE_RADIO_BUTTONS(vbox2,
1632                              pop_nossl_radiobtn,
1633                              _("Don't use SSL"),
1634                              SSL_NONE,
1635                              pop_ssltunnel_radiobtn,
1636                              _("Use SSL for POP3 connection"),
1637                              SSL_TUNNEL,
1638                              pop_starttls_radiobtn,
1639                              _("Use STARTTLS command to start SSL session"),
1640                              SSL_STARTTLS);
1641
1642         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
1643         vbox3 = gtk_vbox_new (FALSE, 0);
1644         gtk_widget_show (vbox3);
1645         gtk_container_add (GTK_CONTAINER (imap_frame), vbox3);
1646         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1647
1648         CREATE_RADIO_BUTTONS(vbox3,
1649                              imap_nossl_radiobtn,
1650                              _("Don't use SSL"),
1651                              SSL_NONE,
1652                              imap_ssltunnel_radiobtn,
1653                              _("Use SSL for IMAP4 connection"),
1654                              SSL_TUNNEL,
1655                              imap_starttls_radiobtn,
1656                              _("Use STARTTLS command to start SSL session"),
1657                              SSL_STARTTLS);
1658
1659         PACK_FRAME (vbox1, nntp_frame, _("NNTP"));
1660         vbox4 = gtk_vbox_new (FALSE, 0);
1661         gtk_widget_show (vbox4);
1662         gtk_container_add (GTK_CONTAINER (nntp_frame), vbox4);
1663         gtk_container_set_border_width (GTK_CONTAINER (vbox4), 8);
1664
1665         nntp_nossl_radiobtn =
1666                 gtk_radio_button_new_with_label (NULL, _("Don't use SSL"));
1667         gtk_widget_show (nntp_nossl_radiobtn);
1668         gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
1669                             FALSE, FALSE, 0);
1670         gtk_object_set_user_data (GTK_OBJECT (nntp_nossl_radiobtn),
1671                                   GINT_TO_POINTER (SSL_NONE));
1672
1673         CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
1674                             _("Use SSL for NNTP connection"), SSL_TUNNEL);
1675
1676         PACK_FRAME (vbox1, send_frame, _("Send (SMTP)"));
1677         vbox5 = gtk_vbox_new (FALSE, 0);
1678         gtk_widget_show (vbox5);
1679         gtk_container_add (GTK_CONTAINER (send_frame), vbox5);
1680         gtk_container_set_border_width (GTK_CONTAINER (vbox5), 8);
1681
1682         CREATE_RADIO_BUTTONS(vbox5,
1683                              smtp_nossl_radiobtn,
1684                              _("Don't use SSL"),
1685                              SSL_NONE,
1686                              smtp_ssltunnel_radiobtn,
1687                              _("Use SSL for SMTP connection"),
1688                              SSL_TUNNEL,
1689                              smtp_starttls_radiobtn,
1690                              _("Use STARTTLS command to start SSL session"),
1691                              SSL_STARTTLS);
1692
1693         ssl.pop_frame               = pop_frame;
1694         ssl.pop_nossl_radiobtn      = pop_nossl_radiobtn;
1695         ssl.pop_ssltunnel_radiobtn  = pop_ssltunnel_radiobtn;
1696         ssl.pop_starttls_radiobtn   = pop_starttls_radiobtn;
1697
1698         ssl.imap_frame              = imap_frame;
1699         ssl.imap_nossl_radiobtn     = imap_nossl_radiobtn;
1700         ssl.imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
1701         ssl.imap_starttls_radiobtn  = imap_starttls_radiobtn;
1702
1703         ssl.nntp_frame              = nntp_frame;
1704         ssl.nntp_nossl_radiobtn     = nntp_nossl_radiobtn;
1705         ssl.nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
1706
1707         ssl.send_frame              = send_frame;
1708         ssl.smtp_nossl_radiobtn     = smtp_nossl_radiobtn;
1709         ssl.smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
1710         ssl.smtp_starttls_radiobtn  = smtp_starttls_radiobtn;
1711 }
1712
1713 #undef CREATE_RADIO_BUTTONS
1714 #undef CREATE_RADIO_BUTTON
1715 #endif /* USE_SSL */
1716
1717 static void crosspost_color_toggled(void)
1718 {
1719         gboolean is_active;
1720
1721         is_active = gtk_toggle_button_get_active
1722                 (GTK_TOGGLE_BUTTON(advanced.crosspost_chkbtn));
1723         gtk_widget_set_sensitive(advanced.crosspost_colormenu, is_active);
1724 }
1725
1726 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam)
1727 {
1728         GtkWidget *menu;
1729         GtkWidget *menuitem;
1730
1731         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(advanced.crosspost_colormenu));
1732         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1733         *((gint *)pparam->data) = GPOINTER_TO_INT
1734                 (gtk_object_get_data(GTK_OBJECT(menuitem), "color"));
1735 }
1736
1737 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam)
1738 {
1739         gint colorlabel = *((gint *)pparam->data);
1740         GtkOptionMenu *colormenu = GTK_OPTION_MENU(*pparam->widget);
1741         GtkWidget *menu;
1742         GtkWidget *menuitem;
1743
1744         gtk_option_menu_set_history(colormenu, colorlabel);
1745         menu = gtk_option_menu_get_menu(colormenu);
1746         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1747         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
1748 }
1749
1750
1751 static void prefs_account_advanced_create(void)
1752 {
1753         GtkWidget *vbox1;
1754         GtkWidget *vbox2;
1755         GtkWidget *hbox1;
1756         GtkWidget *checkbtn_smtpport;
1757         GtkWidget *entry_smtpport;
1758         GtkWidget *hbox_popport;
1759         GtkWidget *checkbtn_popport;
1760         GtkWidget *entry_popport;
1761         GtkWidget *hbox_imapport;
1762         GtkWidget *checkbtn_imapport;
1763         GtkWidget *entry_imapport;
1764         GtkWidget *hbox_nntpport;
1765         GtkWidget *checkbtn_nntpport;
1766         GtkWidget *entry_nntpport;
1767         GtkWidget *checkbtn_domain;
1768         GtkWidget *entry_domain;
1769         GtkWidget *checkbtn_tunnelcmd;
1770         GtkWidget *entry_tunnelcmd;
1771         GtkWidget *checkbtn_crosspost;
1772         GtkWidget *colormenu_crosspost;
1773         GtkWidget *menu;
1774         GtkWidget *imap_frame;
1775         GtkWidget *imapdir_label;
1776         GtkWidget *imapdir_entry;
1777         GtkWidget *folder_frame;
1778         GtkWidget *vbox3;
1779         GtkWidget *table;
1780         GtkWidget *sent_folder_chkbtn;
1781         GtkWidget *sent_folder_entry;
1782         GtkWidget *draft_folder_chkbtn;
1783         GtkWidget *draft_folder_entry;
1784         GtkWidget *trash_folder_chkbtn;
1785         GtkWidget *trash_folder_entry;
1786
1787 #define PACK_HBOX(hbox) \
1788         { \
1789         hbox = gtk_hbox_new (FALSE, 8); \
1790         gtk_widget_show (hbox); \
1791         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
1792         }
1793
1794 #define PACK_PORT_ENTRY(box, entry) \
1795         { \
1796         entry = gtk_entry_new_with_max_length (5); \
1797         gtk_widget_show (entry); \
1798         gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 0); \
1799         gtk_widget_set_usize (entry, 64, -1); \
1800         }
1801
1802         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1803         gtk_widget_show (vbox1);
1804         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1805         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1806
1807         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW_2);
1808         gtk_widget_show (vbox2);
1809         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1810
1811         PACK_HBOX (hbox1);
1812         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("Specify SMTP port"));
1813         PACK_PORT_ENTRY (hbox1, entry_smtpport);
1814         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, entry_smtpport);
1815
1816         PACK_HBOX (hbox_popport);
1817         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
1818                            _("Specify POP3 port"));
1819         PACK_PORT_ENTRY (hbox_popport, entry_popport);
1820         SET_TOGGLE_SENSITIVITY (checkbtn_popport, entry_popport);
1821
1822         PACK_HBOX (hbox_imapport);
1823         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
1824                            _("Specify IMAP4 port"));
1825         PACK_PORT_ENTRY (hbox_imapport, entry_imapport);
1826         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, entry_imapport);
1827
1828         PACK_HBOX (hbox_nntpport);
1829         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
1830                            _("Specify NNTP port"));
1831         PACK_PORT_ENTRY (hbox_nntpport, entry_nntpport);
1832         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, entry_nntpport);
1833
1834         PACK_HBOX (hbox1);
1835         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Specify domain name"));
1836
1837         entry_domain = gtk_entry_new ();
1838         gtk_widget_show (entry_domain);
1839         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
1840         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
1841
1842         
1843         PACK_HBOX (hbox1);
1844         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
1845                            _("Tunnel command to open connection"));
1846         entry_tunnelcmd = gtk_entry_new ();
1847         gtk_widget_show (entry_tunnelcmd);
1848         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
1849         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
1850
1851         PACK_HBOX (hbox1);
1852         PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost, 
1853                            _("Mark cross-posted messages as read and color:"));
1854         gtk_signal_connect (GTK_OBJECT (checkbtn_crosspost), "toggled",
1855                                         GTK_SIGNAL_FUNC (crosspost_color_toggled),
1856                                         NULL);
1857
1858         colormenu_crosspost = gtk_option_menu_new();
1859         gtk_widget_show (colormenu_crosspost);
1860         gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
1861
1862         menu = colorlabel_create_color_menu();
1863         gtk_option_menu_set_menu (GTK_OPTION_MENU(colormenu_crosspost), menu);
1864         SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
1865
1866         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
1867
1868         vbox3 = gtk_vbox_new (FALSE, VSPACING_NARROW);
1869         gtk_widget_show (vbox3);
1870         gtk_container_add (GTK_CONTAINER (imap_frame), vbox3);
1871         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1872
1873         hbox1 = gtk_hbox_new (FALSE, 8);
1874         gtk_widget_show (hbox1);
1875         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
1876
1877         imapdir_label = gtk_label_new (_("IMAP server directory"));
1878         gtk_widget_show (imapdir_label);
1879         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1880
1881         imapdir_entry = gtk_entry_new();
1882         gtk_widget_show (imapdir_entry);
1883         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, TRUE, TRUE, 0);
1884
1885 #undef PACK_HBOX
1886 #undef PACK_PORT_ENTRY
1887
1888         /* special folder setting (maybe these options are redundant) */
1889
1890         PACK_FRAME (vbox1, folder_frame, _("Folder"));
1891
1892         vbox3 = gtk_vbox_new (FALSE, 0);
1893         gtk_widget_show (vbox3);
1894         gtk_container_add (GTK_CONTAINER (folder_frame), vbox3);
1895         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1896
1897         table = gtk_table_new (3, 3, FALSE);
1898         gtk_widget_show (table);
1899         gtk_container_add (GTK_CONTAINER (vbox3), table);
1900         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
1901         gtk_table_set_col_spacings (GTK_TABLE (table), 4);
1902
1903 #define SET_CHECK_BTN_AND_ENTRY(label, chkbtn, entry, n)                \
1904 {                                                                       \
1905         GtkWidget *button;                                              \
1906                                                                         \
1907         chkbtn = gtk_check_button_new_with_label (label);               \
1908         gtk_widget_show (chkbtn);                                       \
1909         gtk_table_attach (GTK_TABLE (table), chkbtn,                    \
1910                           0, 1, n, n + 1, GTK_FILL, 0, 0, 0);           \
1911                                                                         \
1912         entry = gtk_entry_new ();                                       \
1913         gtk_widget_show (entry);                                        \
1914         gtk_table_attach (GTK_TABLE (table), entry, 1, 2, n, n + 1,     \
1915                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,           \
1916                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);    \
1917                                                                         \
1918         button = gtk_button_new_with_label (_(" ... "));                \
1919         gtk_widget_show (button);                                       \
1920         gtk_table_attach (GTK_TABLE (table), button,                    \
1921                           2, 3, n, n + 1, GTK_FILL, 0, 0, 0);           \
1922         gtk_signal_connect                                              \
1923                 (GTK_OBJECT (button), "clicked",                        \
1924                  GTK_SIGNAL_FUNC (prefs_account_select_folder_cb),      \
1925                  entry);                                                \
1926                                                                         \
1927         SET_TOGGLE_SENSITIVITY (chkbtn, entry);                         \
1928         SET_TOGGLE_SENSITIVITY (chkbtn, button);                        \
1929 }
1930
1931         SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
1932                                 sent_folder_chkbtn, sent_folder_entry, 0);
1933         SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
1934                                 draft_folder_chkbtn, draft_folder_entry, 1);
1935         SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
1936                                 trash_folder_chkbtn, trash_folder_entry, 2);
1937
1938         advanced.smtpport_chkbtn        = checkbtn_smtpport;
1939         advanced.smtpport_entry         = entry_smtpport;
1940         advanced.popport_hbox           = hbox_popport;
1941         advanced.popport_chkbtn         = checkbtn_popport;
1942         advanced.popport_entry          = entry_popport;
1943         advanced.imapport_hbox          = hbox_imapport;
1944         advanced.imapport_chkbtn        = checkbtn_imapport;
1945         advanced.imapport_entry         = entry_imapport;
1946         advanced.nntpport_hbox          = hbox_nntpport;
1947         advanced.nntpport_chkbtn        = checkbtn_nntpport;
1948         advanced.nntpport_entry         = entry_nntpport;
1949         advanced.domain_chkbtn          = checkbtn_domain;
1950         advanced.domain_entry           = entry_domain;
1951         advanced.tunnelcmd_chkbtn       = checkbtn_tunnelcmd;
1952         advanced.tunnelcmd_entry        = entry_tunnelcmd;
1953         advanced.crosspost_chkbtn       = checkbtn_crosspost;
1954         advanced.crosspost_colormenu    = colormenu_crosspost;
1955
1956         advanced.imap_frame             = imap_frame;
1957         advanced.imapdir_entry          = imapdir_entry;
1958
1959         advanced.sent_folder_chkbtn  = sent_folder_chkbtn;
1960         advanced.sent_folder_entry   = sent_folder_entry;
1961         advanced.draft_folder_chkbtn = draft_folder_chkbtn;
1962         advanced.draft_folder_entry  = draft_folder_entry;
1963         advanced.trash_folder_chkbtn = trash_folder_chkbtn;
1964         advanced.trash_folder_entry  = trash_folder_entry;
1965 }
1966
1967 static gint prefs_account_deleted(GtkWidget *widget, GdkEventAny *event,
1968                                   gpointer data)
1969 {
1970         prefs_account_cancel();
1971         return TRUE;
1972 }
1973
1974 static void prefs_account_key_pressed(GtkWidget *widget, GdkEventKey *event,
1975                                       gpointer data)
1976 {
1977         if (event && event->keyval == GDK_Escape)
1978                 prefs_account_cancel();
1979 }
1980
1981 static void prefs_account_ok(void)
1982 {
1983         if (prefs_account_apply() == 0)
1984                 gtk_main_quit();
1985 }
1986
1987 static gint prefs_account_apply(void)
1988 {
1989         RecvProtocol protocol;
1990         GtkWidget *menu;
1991         GtkWidget *menuitem;
1992
1993         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(basic.protocol_optmenu));
1994         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1995         protocol = GPOINTER_TO_INT
1996                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
1997
1998         if (*gtk_entry_get_text(GTK_ENTRY(basic.acname_entry)) == '\0') {
1999                 alertpanel_error(_("Account name is not entered."));
2000                 return -1;
2001         }
2002         if (*gtk_entry_get_text(GTK_ENTRY(basic.addr_entry)) == '\0') {
2003                 alertpanel_error(_("Mail address is not entered."));
2004                 return -1;
2005         }
2006         if ((protocol == A_POP3 || protocol == A_APOP || (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)))) &&
2007            *gtk_entry_get_text(GTK_ENTRY(basic.smtpserv_entry)) == '\0') {
2008                 alertpanel_error(_("SMTP server is not entered."));
2009                 return -1;
2010         }
2011         if ((protocol == A_POP3 || protocol == A_APOP || protocol == A_IMAP4) &&
2012             *gtk_entry_get_text(GTK_ENTRY(basic.uid_entry)) == '\0') {
2013                 alertpanel_error(_("User ID is not entered."));
2014                 return -1;
2015         }
2016         if ((protocol == A_POP3 || protocol == A_APOP) &&
2017             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2018                 alertpanel_error(_("POP3 server is not entered."));
2019                 return -1;
2020         }
2021         if (protocol == A_IMAP4 &&
2022             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2023                 alertpanel_error(_("IMAP4 server is not entered."));
2024                 return -1;
2025         }
2026         if (protocol == A_NNTP &&
2027             *gtk_entry_get_text(GTK_ENTRY(basic.nntpserv_entry)) == '\0') {
2028                 alertpanel_error(_("NNTP server is not entered."));
2029                 return -1;
2030         }
2031
2032         if (protocol == A_LOCAL &&
2033             *gtk_entry_get_text(GTK_ENTRY(basic.localmbox_entry)) == '\0') {
2034                 alertpanel_error(_("local mailbox filename is not entered."));
2035                 return -1;
2036         }
2037
2038         if (protocol == A_LOCAL &&
2039             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic.mailcmd_entry)) == '\0') {
2040                 alertpanel_error(_("mail command is not entered."));
2041                 return -1;
2042         }
2043
2044         prefs_set_data_from_dialog(param);
2045         return 0;
2046 }
2047
2048 static void prefs_account_cancel(void)
2049 {
2050         cancelled = TRUE;
2051         gtk_main_quit();
2052 }
2053
2054 static void prefs_account_select_folder_cb(GtkWidget *widget, gpointer data)
2055 {
2056         FolderItem *item;
2057         gchar *id;
2058
2059         item = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
2060         if (item && item->path) {
2061                 id = folder_item_get_identifier(item);
2062                 if (id) {
2063                         gtk_entry_set_text(GTK_ENTRY(data), id);
2064                         g_free(id);
2065                 }
2066         }
2067 }
2068
2069 static void prefs_account_edit_custom_header(void)
2070 {
2071         prefs_custom_header_open(&tmp_ac_prefs);
2072 }
2073
2074 #if USE_GPGME || USE_SSL
2075 static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
2076 {
2077         GtkRadioButton *radiobtn;
2078         GSList *group;
2079
2080         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2081         group = gtk_radio_button_group (radiobtn);
2082         while (group != NULL) {
2083                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2084                 if (gtk_toggle_button_get_active (btn)) {
2085                         *((gint *)pparam->data) = GPOINTER_TO_INT
2086                                 (gtk_object_get_user_data (GTK_OBJECT (btn)));
2087                         break;
2088                 }
2089                 group = group->next;
2090         }
2091 }
2092
2093 static void prefs_account_enum_set_radiobtn(PrefParam *pparam)
2094 {
2095         GtkRadioButton *radiobtn;
2096         GSList *group;
2097         gpointer data;
2098
2099         data = GINT_TO_POINTER (*((gint *)pparam->data));
2100         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2101         group = gtk_radio_button_group (radiobtn);
2102         while (group != NULL) {
2103                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2104                 gpointer data1 = gtk_object_get_user_data (GTK_OBJECT (btn));
2105                 if (data1 == data) {
2106                         gtk_toggle_button_set_active (btn, TRUE);
2107                         break;
2108                 }
2109                 group = group->next;
2110         }
2111 }
2112
2113 #endif /* USE_GPGME || USE_SSL */
2114
2115 #if USE_GPGME
2116 static void prefs_account_ascii_armored_warning(GtkWidget *widget)
2117 {
2118         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget)) &&
2119             gtk_notebook_get_current_page(GTK_NOTEBOOK(dialog.notebook)) > 0)
2120                 alertpanel_warning
2121                         (_("It's not recommended to use the old style ASCII-armored\n"
2122                            "mode for encrypted messages. It doesn't comply with the\n"
2123                            "RFC 3156 - MIME Security with OpenPGP."));
2124 }
2125 #endif /* USE_GPGME */
2126
2127 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
2128 {
2129         GtkWidget *menu;
2130         GtkWidget *menuitem;
2131
2132         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2133         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2134         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2135                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
2136 }
2137
2138 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
2139 {
2140         RecvProtocol protocol;
2141         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2142         GtkWidget *menu;
2143         GtkWidget *menuitem;
2144         GList *children;
2145         gint list_order[] = {
2146                 0,  /* A_POP3  */
2147                 1,  /* A_APOP  */
2148                 -1, /* A_RPOP  */
2149                 2,  /* A_IMAP4 */
2150                 3,  /* A_NNTP  */
2151                 4   /* A_LOCAL */
2152         };
2153
2154         protocol = *((RecvProtocol *)pparam->data);
2155         if (protocol < 0 || protocol > A_LOCAL) return;
2156         if (list_order[protocol] < 0) return;
2157         gtk_option_menu_set_history(optmenu, list_order[protocol]);
2158
2159         menu = gtk_option_menu_get_menu(optmenu);
2160         menu_set_insensitive_all(GTK_MENU_SHELL(menu));
2161
2162 #define SET_NTH_SENSITIVE(proto) \
2163 { \
2164         menuitem = g_list_nth_data(children, list_order[proto]); \
2165         if (menuitem) \
2166                 gtk_widget_set_sensitive(menuitem, TRUE); \
2167 }
2168
2169         children = GTK_MENU_SHELL(menu)->children;
2170         SET_NTH_SENSITIVE(protocol);
2171         if (protocol == A_POP3) {
2172                 SET_NTH_SENSITIVE(A_APOP);
2173         } else if (protocol == A_APOP) {
2174                 SET_NTH_SENSITIVE(A_POP3);
2175         }
2176
2177 #undef SET_NTH_SENSITIVE
2178
2179         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2180         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2181 }
2182
2183 static void prefs_account_smtp_auth_type_set_data_from_optmenu(PrefParam *pparam)
2184 {
2185         GtkWidget *menu;
2186         GtkWidget *menuitem;
2187
2188         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2189         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2190         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2191                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
2192 }
2193
2194 static void prefs_account_smtp_auth_type_set_optmenu(PrefParam *pparam)
2195 {
2196         SMTPAuthType type = *((SMTPAuthType *)pparam->data);
2197         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2198         GtkWidget *menu;
2199         GtkWidget *menuitem;
2200
2201         switch (type) {
2202         case SMTPAUTH_LOGIN:
2203                 gtk_option_menu_set_history(optmenu, 1);
2204                 break;
2205         case SMTPAUTH_CRAM_MD5:
2206                 gtk_option_menu_set_history(optmenu, 2);
2207                 break;
2208         case SMTPAUTH_DIGEST_MD5:
2209                 gtk_option_menu_set_history(optmenu, 3);
2210                 break;
2211         case 0:
2212         default:
2213                 gtk_option_menu_set_history(optmenu, 0);
2214         }
2215
2216         menu = gtk_option_menu_get_menu(optmenu);
2217         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2218         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2219 }
2220
2221 static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
2222 {
2223         RecvProtocol protocol;
2224
2225         protocol = GPOINTER_TO_INT
2226                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
2227
2228         switch(protocol) {
2229         case A_NNTP:
2230                 gtk_widget_show(basic.nntpserv_label);
2231                 gtk_widget_show(basic.nntpserv_entry);
2232                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2233                                            0, VSPACING_NARROW);
2234                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, TRUE);
2235                 gtk_widget_show(basic.nntpauth_chkbtn);
2236                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2237                                            1, VSPACING_NARROW);
2238                 gtk_widget_hide(basic.recvserv_label);
2239                 gtk_widget_hide(basic.recvserv_entry);
2240                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2241                                            2, 0);
2242                 gtk_widget_show(basic.smtpserv_label);
2243                 gtk_widget_show(basic.smtpserv_entry);
2244                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2245                                            4, VSPACING_NARROW);
2246                 gtk_widget_hide(basic.localmbox_label);
2247                 gtk_widget_hide(basic.localmbox_entry);
2248                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2249                                            3, 0);
2250                 gtk_widget_hide(basic.mailcmd_label);
2251                 gtk_widget_hide(basic.mailcmd_entry);
2252                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2253                                            6, 0);
2254                 gtk_widget_hide(basic.mailcmd_chkbtn);
2255                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2256                                            5, 0);
2257                 gtk_widget_show(basic.uid_label);
2258                 gtk_widget_show(basic.pass_label);
2259                 gtk_widget_show(basic.uid_entry);
2260                 gtk_widget_show(basic.pass_entry);
2261                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2262                                            7, VSPACING_NARROW);
2263
2264                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2265                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2266                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2267                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2268
2269                 /* update userid/passwd sensitive state */
2270                 prefs_account_nntpauth_toggled
2271                         (GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
2272                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
2273                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2274
2275                 /* update pop_before_smtp sensitivity */
2276                 gtk_toggle_button_set_active(p_send.pop_bfr_smtp_chkbtn, FALSE);
2277                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2278                 
2279                 if (!tmp_ac_prefs.account_name) {
2280                         gtk_toggle_button_set_active
2281                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2282                                  FALSE);
2283                 }
2284
2285 #if USE_SSL
2286                 gtk_widget_hide(ssl.pop_frame);
2287                 gtk_widget_hide(ssl.imap_frame);
2288                 gtk_widget_show(ssl.nntp_frame);
2289                 gtk_widget_hide(ssl.send_frame);
2290 #endif
2291                 gtk_widget_hide(advanced.popport_hbox);
2292                 gtk_widget_hide(advanced.imapport_hbox);
2293                 gtk_widget_show(advanced.nntpport_hbox);
2294                 gtk_widget_show(advanced.crosspost_chkbtn);
2295                 gtk_widget_show(advanced.crosspost_colormenu);
2296                 gtk_widget_hide(advanced.imap_frame);
2297                 break;
2298         case A_LOCAL:
2299                 gtk_widget_hide(basic.nntpserv_label);
2300                 gtk_widget_hide(basic.nntpserv_entry);
2301                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2302                                            0, 0);
2303                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2304                 gtk_widget_hide(basic.nntpauth_chkbtn);
2305                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2306                                            1, 0);
2307                 gtk_widget_hide(basic.recvserv_label);
2308                 gtk_widget_hide(basic.recvserv_entry);
2309                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2310                                            2, 0);
2311                 gtk_widget_show(basic.smtpserv_label);
2312                 gtk_widget_show(basic.smtpserv_entry);
2313                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2314                                            4, VSPACING_NARROW);
2315                 gtk_widget_show(basic.localmbox_label);
2316                 gtk_widget_show(basic.localmbox_entry);
2317                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2318                                            3, VSPACING_NARROW);
2319                 gtk_widget_show(basic.mailcmd_label);
2320                 gtk_widget_show(basic.mailcmd_entry);
2321                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2322                                            6, VSPACING_NARROW);
2323                 gtk_widget_show(basic.mailcmd_chkbtn);
2324                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2325                                            5, VSPACING_NARROW);
2326                 gtk_widget_hide(basic.uid_label);
2327                 gtk_widget_hide(basic.pass_label);
2328                 gtk_widget_hide(basic.uid_entry);
2329                 gtk_widget_hide(basic.pass_entry);
2330                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2331                                            7, 0);
2332
2333                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2334                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2335                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2336                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2337                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
2338                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, FALSE);
2339                 prefs_account_mailcmd_toggled
2340                         (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
2341
2342                 /* update pop_before_smtp sensitivity */
2343                 gtk_toggle_button_set_active(p_send.pop_bfr_smtp_chkbtn, FALSE);
2344                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2345
2346                 if (!tmp_ac_prefs.account_name) {
2347                         gtk_toggle_button_set_active
2348                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2349                                  TRUE);
2350                 }
2351
2352 #if USE_SSL
2353                 gtk_widget_hide(ssl.pop_frame);
2354                 gtk_widget_hide(ssl.imap_frame);
2355                 gtk_widget_hide(ssl.nntp_frame);
2356                 gtk_widget_show(ssl.send_frame);
2357 #endif
2358                 gtk_widget_hide(advanced.popport_hbox);
2359                 gtk_widget_hide(advanced.imapport_hbox);
2360                 gtk_widget_hide(advanced.nntpport_hbox);
2361                 gtk_widget_hide(advanced.crosspost_chkbtn);
2362                 gtk_widget_hide(advanced.crosspost_colormenu);
2363                 gtk_widget_hide(advanced.imap_frame);
2364                 break;
2365         case A_IMAP4:
2366                 gtk_widget_hide(basic.nntpserv_label);
2367                 gtk_widget_hide(basic.nntpserv_entry);
2368                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2369                                            0, 0);
2370                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2371                 gtk_widget_hide(basic.nntpauth_chkbtn);
2372                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2373                                            1, 0);
2374                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
2375                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
2376                 gtk_widget_show(basic.recvserv_label);
2377                 gtk_widget_show(basic.recvserv_entry);
2378                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2379                                            2, VSPACING_NARROW);
2380                 gtk_widget_show(basic.smtpserv_label);
2381                 gtk_widget_show(basic.smtpserv_entry);
2382                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2383                                            4, VSPACING_NARROW);
2384                 gtk_widget_hide(basic.localmbox_label);
2385                 gtk_widget_hide(basic.localmbox_entry);
2386                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2387                                            3, 0);
2388                 gtk_widget_hide(basic.mailcmd_label);
2389                 gtk_widget_hide(basic.mailcmd_entry);
2390                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2391                                            6, 0);
2392                 gtk_widget_hide(basic.mailcmd_chkbtn);
2393                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2394                                            5, 0);
2395                 gtk_widget_show(basic.uid_label);
2396                 gtk_widget_show(basic.pass_label);
2397                 gtk_widget_show(basic.uid_entry);
2398                 gtk_widget_show(basic.pass_entry);
2399                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2400                                            7, VSPACING_NARROW);
2401
2402                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2403                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2404                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2405                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2406                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
2407                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2408                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
2409                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
2410
2411                 /* update pop_before_smtp sensitivity */
2412                 gtk_toggle_button_set_active(p_send.pop_bfr_smtp_chkbtn, FALSE);
2413                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2414                 
2415                 if (!tmp_ac_prefs.account_name) {
2416                         gtk_toggle_button_set_active
2417                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2418                                  FALSE);
2419                 }
2420
2421 #if USE_SSL
2422                 gtk_widget_hide(ssl.pop_frame);
2423                 gtk_widget_show(ssl.imap_frame);
2424                 gtk_widget_hide(ssl.nntp_frame);
2425                 gtk_widget_show(ssl.send_frame);
2426 #endif
2427                 gtk_widget_hide(advanced.popport_hbox);
2428                 gtk_widget_show(advanced.imapport_hbox);
2429                 gtk_widget_hide(advanced.nntpport_hbox);
2430                 gtk_widget_hide(advanced.crosspost_chkbtn);
2431                 gtk_widget_hide(advanced.crosspost_colormenu);
2432                 gtk_widget_show(advanced.imap_frame);
2433                 break;
2434         case A_POP3:
2435         default:
2436                 gtk_widget_hide(basic.nntpserv_label);
2437                 gtk_widget_hide(basic.nntpserv_entry);
2438                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2439                                            0, 0);
2440                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2441                 gtk_widget_hide(basic.nntpauth_chkbtn);
2442                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2443                                            1, 0);
2444                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
2445                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
2446                 gtk_widget_show(basic.recvserv_label);
2447                 gtk_widget_show(basic.recvserv_entry);
2448                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2449                                            2, VSPACING_NARROW);
2450                 gtk_widget_show(basic.smtpserv_label);
2451                 gtk_widget_show(basic.smtpserv_entry);
2452                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2453                                            4, VSPACING_NARROW);
2454                 gtk_widget_hide(basic.localmbox_label);
2455                 gtk_widget_hide(basic.localmbox_entry);
2456                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2457                                            3, 0);
2458                 gtk_widget_hide(basic.mailcmd_label);
2459                 gtk_widget_hide(basic.mailcmd_entry);
2460                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2461                                            6, 0);
2462                 gtk_widget_hide(basic.mailcmd_chkbtn);
2463                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2464                                            5, 0);
2465                 gtk_widget_show(basic.uid_label);
2466                 gtk_widget_show(basic.pass_label);
2467                 gtk_widget_show(basic.uid_entry);
2468                 gtk_widget_show(basic.pass_entry);
2469                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2470                                            7, VSPACING_NARROW);
2471
2472                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2473                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2474                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2475                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2476                 gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
2477                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2478                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
2479                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
2480
2481                 /* update pop_before_smtp sensitivity */
2482                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, TRUE);
2483                 
2484                 if (!tmp_ac_prefs.account_name) {
2485                         gtk_toggle_button_set_active
2486                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2487                                  TRUE);
2488                 }
2489
2490 #if USE_SSL
2491                 gtk_widget_show(ssl.pop_frame);
2492                 gtk_widget_hide(ssl.imap_frame);
2493                 gtk_widget_hide(ssl.nntp_frame);
2494                 gtk_widget_show(ssl.send_frame);
2495 #endif
2496                 gtk_widget_show(advanced.popport_hbox);
2497                 gtk_widget_hide(advanced.imapport_hbox);
2498                 gtk_widget_hide(advanced.nntpport_hbox);
2499                 gtk_widget_hide(advanced.crosspost_chkbtn);
2500                 gtk_widget_hide(advanced.crosspost_colormenu);
2501                 gtk_widget_hide(advanced.imap_frame);
2502                 break;
2503         }
2504
2505         gtk_widget_queue_resize(basic.serv_frame);
2506 }
2507
2508 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
2509                                            gpointer user_data)
2510 {
2511         gboolean auth;
2512
2513         if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (button)))
2514                 return;
2515         auth = gtk_toggle_button_get_active (button);
2516         gtk_widget_set_sensitive(basic.uid_label,  auth);
2517         gtk_widget_set_sensitive(basic.pass_label, auth);
2518         gtk_widget_set_sensitive(basic.uid_entry,  auth);
2519         gtk_widget_set_sensitive(basic.pass_entry, auth);
2520 }
2521
2522 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
2523                                           gpointer user_data)
2524 {
2525         gboolean use_mailcmd;
2526
2527         use_mailcmd = gtk_toggle_button_get_active (button);
2528
2529         gtk_widget_set_sensitive(basic.mailcmd_entry,  use_mailcmd);
2530         gtk_widget_set_sensitive(basic.mailcmd_label, use_mailcmd);
2531         gtk_widget_set_sensitive(basic.smtpserv_entry, !use_mailcmd);
2532         gtk_widget_set_sensitive(basic.smtpserv_label, !use_mailcmd);
2533         gtk_widget_set_sensitive(basic.uid_entry,  !use_mailcmd);
2534         gtk_widget_set_sensitive(basic.pass_entry, !use_mailcmd);
2535 }