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