bring in Simon Schubert's general GPG clean up patch
[claws.git] / src / prefs_account.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 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
50 static gboolean cancelled;
51
52 static PrefsAccount tmp_ac_prefs;
53
54 static PrefsDialog dialog;
55
56 static struct Basic {
57         GtkWidget *acname_entry;
58         GtkWidget *default_chkbtn;
59
60         GtkWidget *name_entry;
61         GtkWidget *addr_entry;
62         GtkWidget *org_entry;
63
64         GtkWidget *serv_frame;
65         GtkWidget *serv_table;
66         GtkWidget *protocol_optmenu;
67         GtkWidget *recvserv_label;
68         GtkWidget *smtpserv_label;
69         GtkWidget *nntpserv_label;
70         GtkWidget *localmbox_label;
71         GtkWidget *mailcmd_label;
72         GtkWidget *recvserv_entry;
73         GtkWidget *smtpserv_entry;
74         GtkWidget *nntpserv_entry;
75         GtkWidget *nntpauth_chkbtn;
76         GtkWidget *localmbox_entry;
77         GtkWidget *mailcmd_chkbtn;
78         GtkWidget *mailcmd_entry;
79         GtkWidget *uid_label;
80         GtkWidget *pass_label;
81         GtkWidget *uid_entry;
82         GtkWidget *pass_entry;
83 } basic;
84
85 static struct Receive {
86         GtkWidget *pop3_frame;
87         GtkWidget *rmmail_chkbtn;
88         GtkWidget *getall_chkbtn;
89         GtkWidget *recvatgetall_chkbtn;
90         GtkWidget *filter_on_recv_chkbtn;
91         GtkWidget *inbox_label;
92         GtkWidget *inbox_entry;
93         GtkWidget *inbox_btn;
94
95         GtkWidget *imap_frame;
96         GtkWidget *imapdir_entry;
97 } receive;
98
99 static struct Send {
100         GtkWidget *date_chkbtn;
101         GtkWidget *msgid_chkbtn;
102
103         GtkWidget *customhdr_chkbtn;
104
105         GtkWidget *smtp_auth_chkbtn;
106         GtkWidget *smtp_userid_entry;
107         GtkWidget *smtp_passwd_entry;
108         GtkWidget *pop_bfr_smtp_chkbtn;
109 } send;
110
111 static struct Compose {
112         GtkWidget *sigpath_entry;
113         
114         GtkWidget *autocc_chkbtn;
115         GtkWidget *autocc_entry;
116         GtkWidget *autobcc_chkbtn;
117         GtkWidget *autobcc_entry;
118         GtkWidget *autoreplyto_chkbtn;
119         GtkWidget *autoreplyto_entry;
120 } compose;
121
122 #if USE_GPGME
123 static struct Privacy {
124         GtkWidget *checkbtn_default_encrypt;
125         GtkWidget *checkbtn_ascii_armored;
126         GtkWidget *checkbtn_default_sign;
127         GtkWidget *defaultkey_radiobtn;
128         GtkWidget *emailkey_radiobtn;
129         GtkWidget *customkey_radiobtn;
130         GtkWidget *customkey_entry;
131 } privacy;
132 #endif /* USE_GPGME */
133
134 #if USE_SSL
135 static struct SSLPrefs {
136         GtkWidget *receive_frame;
137         GtkWidget *pop_chkbtn;
138         GtkWidget *imap_chkbtn;
139
140         GtkWidget *send_frame;
141         GtkWidget *smtp_nossl_radiobtn;
142         GtkWidget *smtp_ssltunnel_radiobtn;
143         GtkWidget *smtp_sslstarttls_radiobtn;
144 } ssl;
145 #endif /* USE_SSL */
146
147 static struct Advanced {
148         GtkWidget *smtpport_chkbtn;
149         GtkWidget *smtpport_entry;
150         GtkWidget *popport_hbox;
151         GtkWidget *popport_chkbtn;
152         GtkWidget *popport_entry;
153         GtkWidget *imapport_hbox;
154         GtkWidget *imapport_chkbtn;
155         GtkWidget *imapport_entry;
156         GtkWidget *nntpport_hbox;
157         GtkWidget *nntpport_chkbtn;
158         GtkWidget *nntpport_entry;
159         GtkWidget *domain_chkbtn;
160         GtkWidget *domain_entry;
161         GtkWidget *tunnelcmd_chkbtn;
162         GtkWidget *tunnelcmd_entry;
163 } advanced;
164
165 static void prefs_account_fix_size                      (void);
166
167 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam);
168 static void prefs_account_protocol_set_optmenu          (PrefParam *pparam);
169 static void prefs_account_protocol_activated            (GtkMenuItem *menuitem);
170 #if USE_GPGME || USE_SSL
171 static void prefs_account_enum_set_data_from_radiobtn   (PrefParam *pparam);
172 static void prefs_account_enum_set_radiobtn             (PrefParam *pparam);
173 static void prefs_account_ascii_armored_warning(GtkWidget* widget, 
174                                                gpointer unused);
175 #endif /* USE_GPGME || USE_SSL */
176
177 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
178                                            gpointer user_data);
179 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
180                                           gpointer user_data);
181
182 static PrefParam param[] = {
183         /* Basic */
184         {"account_name", NULL, &tmp_ac_prefs.account_name, P_STRING,
185          &basic.acname_entry, prefs_set_data_from_entry, prefs_set_entry},
186
187         {"is_default", "FALSE", &tmp_ac_prefs.is_default, P_BOOL,
188          &basic.default_chkbtn,
189          prefs_set_data_from_toggle, prefs_set_toggle},
190
191         {"name", NULL, &tmp_ac_prefs.name, P_STRING,
192          &basic.name_entry, prefs_set_data_from_entry, prefs_set_entry},
193
194         {"address", NULL, &tmp_ac_prefs.address, P_STRING,
195          &basic.addr_entry, prefs_set_data_from_entry, prefs_set_entry},
196
197         {"organization", NULL, &tmp_ac_prefs.organization, P_STRING,
198          &basic.org_entry, prefs_set_data_from_entry, prefs_set_entry},
199
200         {"protocol", NULL, &tmp_ac_prefs.protocol, P_ENUM,
201          &basic.protocol_optmenu,
202          prefs_account_protocol_set_data_from_optmenu,
203          prefs_account_protocol_set_optmenu},
204
205         {"receive_server", NULL, &tmp_ac_prefs.recv_server, P_STRING,
206          &basic.recvserv_entry, prefs_set_data_from_entry, prefs_set_entry},
207
208         {"smtp_server", NULL, &tmp_ac_prefs.smtp_server, P_STRING,
209          &basic.smtpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
210
211         {"nntp_server", NULL, &tmp_ac_prefs.nntp_server, P_STRING,
212          &basic.nntpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
213
214         {"local_mbox", NULL, &tmp_ac_prefs.local_mbox, P_STRING,
215          &basic.localmbox_entry, prefs_set_data_from_entry, prefs_set_entry},
216
217         {"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
218          &basic.mailcmd_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
219
220         {"mail_command", "/usr/sbin/sendmail", &tmp_ac_prefs.mail_command, P_STRING,
221          &basic.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
222
223         {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
224          &basic.nntpauth_chkbtn,
225          prefs_set_data_from_toggle, prefs_set_toggle},
226
227         {"user_id", "ENV_USER", &tmp_ac_prefs.userid, P_STRING,
228          &basic.uid_entry, prefs_set_data_from_entry, prefs_set_entry},
229
230         {"password", NULL, &tmp_ac_prefs.passwd, P_STRING,
231          &basic.pass_entry, prefs_set_data_from_entry, prefs_set_entry},
232
233         {"inbox", "inbox", &tmp_ac_prefs.inbox, P_STRING,
234          &receive.inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
235
236         /* Receive */
237         {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
238          &receive.rmmail_chkbtn,
239          prefs_set_data_from_toggle, prefs_set_toggle},
240
241         {"get_all_mail", "FALSE", &tmp_ac_prefs.getall, P_BOOL,
242          &receive.getall_chkbtn,
243          prefs_set_data_from_toggle, prefs_set_toggle},
244
245         {"receive_at_get_all", "TRUE", &tmp_ac_prefs.recv_at_getall, P_BOOL,
246          &receive.recvatgetall_chkbtn,
247          prefs_set_data_from_toggle, prefs_set_toggle},
248
249         {"filter_on_receive", "TRUE", &tmp_ac_prefs.filter_on_recv, P_BOOL,
250          &receive.filter_on_recv_chkbtn,
251          prefs_set_data_from_toggle, prefs_set_toggle},
252
253         {"imap_directory", NULL, &tmp_ac_prefs.imap_dir, P_STRING,
254          &receive.imapdir_entry, prefs_set_data_from_entry, prefs_set_entry},
255
256         /* Send */
257         {"add_date", "TRUE", &tmp_ac_prefs.add_date, P_BOOL,
258          &send.date_chkbtn,
259          prefs_set_data_from_toggle, prefs_set_toggle},
260
261         {"generate_msgid", "TRUE", &tmp_ac_prefs.gen_msgid, P_BOOL,
262          &send.msgid_chkbtn,
263          prefs_set_data_from_toggle, prefs_set_toggle},
264
265         {"add_custom_header", "FALSE", &tmp_ac_prefs.add_customhdr, P_BOOL,
266          &send.customhdr_chkbtn,
267          prefs_set_data_from_toggle, prefs_set_toggle},
268
269         {"use_smtp_auth", "FALSE", &tmp_ac_prefs.use_smtp_auth, P_BOOL,
270          &send.smtp_auth_chkbtn,
271          prefs_set_data_from_toggle, prefs_set_toggle},
272
273         {"smtp_user_id", "ENV_USER", &tmp_ac_prefs.smtp_userid, P_STRING,
274          &send.smtp_userid_entry, prefs_set_data_from_entry, prefs_set_entry},
275
276         {"smtp_password", NULL, &tmp_ac_prefs.smtp_passwd, P_STRING,
277          &send.smtp_passwd_entry, prefs_set_data_from_entry, prefs_set_entry},
278
279         {"pop_before_smtp", "FALSE", &tmp_ac_prefs.pop_before_smtp, P_BOOL,
280          &send.pop_bfr_smtp_chkbtn,
281          prefs_set_data_from_toggle, prefs_set_toggle},
282
283         /* Compose */
284         {"signature_path", "~/"DEFAULT_SIGNATURE, &tmp_ac_prefs.sig_path, P_STRING,
285          &compose.sigpath_entry,
286          prefs_set_data_from_entry, prefs_set_entry},
287
288         {"set_autocc", "FALSE", &tmp_ac_prefs.set_autocc, P_BOOL,
289          &compose.autocc_chkbtn,
290          prefs_set_data_from_toggle, prefs_set_toggle},
291
292         {"auto_cc", NULL, &tmp_ac_prefs.auto_cc, P_STRING,
293          &compose.autocc_entry,
294          prefs_set_data_from_entry, prefs_set_entry},
295
296         {"set_autobcc", "FALSE", &tmp_ac_prefs.set_autobcc, P_BOOL,
297          &compose.autobcc_chkbtn,
298          prefs_set_data_from_toggle, prefs_set_toggle},
299
300         {"auto_bcc", NULL, &tmp_ac_prefs.auto_bcc, P_STRING,
301          &compose.autobcc_entry,
302          prefs_set_data_from_entry, prefs_set_entry},
303
304         {"set_autoreplyto", "FALSE", &tmp_ac_prefs.set_autoreplyto, P_BOOL,
305          &compose.autoreplyto_chkbtn,
306          prefs_set_data_from_toggle, prefs_set_toggle},
307
308         {"auto_replyto", NULL, &tmp_ac_prefs.auto_replyto, P_STRING,
309          &compose.autoreplyto_entry,
310
311          prefs_set_data_from_entry, prefs_set_entry},
312
313 #if USE_GPGME
314         /* Privacy */
315         {"default_encrypt", "FALSE", &tmp_ac_prefs.default_encrypt, P_BOOL,
316          &privacy.checkbtn_default_encrypt,
317          prefs_set_data_from_toggle, prefs_set_toggle},
318         {"ascii_armored", "FALSE", &tmp_ac_prefs.ascii_armored, P_BOOL,
319          &privacy.checkbtn_ascii_armored,
320          prefs_set_data_from_toggle, prefs_set_toggle},
321         {"default_sign", "FALSE", &tmp_ac_prefs.default_sign, P_BOOL,
322          &privacy.checkbtn_default_sign,
323          prefs_set_data_from_toggle, prefs_set_toggle},
324         {"sign_key", NULL, &tmp_ac_prefs.sign_key, P_ENUM,
325          &privacy.defaultkey_radiobtn,
326          prefs_account_enum_set_data_from_radiobtn,
327          prefs_account_enum_set_radiobtn},
328         {"sign_key_id", NULL, &tmp_ac_prefs.sign_key_id, P_STRING,
329          &privacy.customkey_entry,
330          prefs_set_data_from_entry, prefs_set_entry},
331 #endif /* USE_GPGME */
332
333 #if USE_SSL
334         /* SSL */
335         {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
336          &ssl.smtp_nossl_radiobtn,
337          prefs_account_enum_set_data_from_radiobtn,
338          prefs_account_enum_set_radiobtn},
339         {"ssl_pop", "FALSE", &tmp_ac_prefs.ssl_pop, P_BOOL,
340          &ssl.pop_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
341         {"ssl_imap", "FALSE", &tmp_ac_prefs.ssl_imap, P_BOOL,
342          &ssl.imap_chkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
343 #endif /* USE_SSL */
344
345         /* Advanced */
346         {"set_smtpport", "FALSE", &tmp_ac_prefs.set_smtpport, P_BOOL,
347          &advanced.smtpport_chkbtn,
348          prefs_set_data_from_toggle, prefs_set_toggle},
349
350         {"smtp_port", "25", &tmp_ac_prefs.smtpport, P_USHORT,
351          &advanced.smtpport_entry,
352          prefs_set_data_from_entry, prefs_set_entry},
353
354         {"set_popport", "FALSE", &tmp_ac_prefs.set_popport, P_BOOL,
355          &advanced.popport_chkbtn,
356          prefs_set_data_from_toggle, prefs_set_toggle},
357
358         {"pop_port", "110", &tmp_ac_prefs.popport, P_USHORT,
359          &advanced.popport_entry,
360          prefs_set_data_from_entry, prefs_set_entry},
361
362         {"set_imapport", "FALSE", &tmp_ac_prefs.set_imapport, P_BOOL,
363          &advanced.imapport_chkbtn,
364          prefs_set_data_from_toggle, prefs_set_toggle},
365
366         {"imap_port", "143", &tmp_ac_prefs.imapport, P_USHORT,
367          &advanced.imapport_entry,
368          prefs_set_data_from_entry, prefs_set_entry},
369
370         {"set_nntpport", "FALSE", &tmp_ac_prefs.set_nntpport, P_BOOL,
371          &advanced.nntpport_chkbtn,
372          prefs_set_data_from_toggle, prefs_set_toggle},
373
374         {"nntp_port", "119", &tmp_ac_prefs.nntpport, P_USHORT,
375          &advanced.nntpport_entry,
376          prefs_set_data_from_entry, prefs_set_entry},
377
378         {"set_domain", "FALSE", &tmp_ac_prefs.set_domain, P_BOOL,
379          &advanced.domain_chkbtn,
380          prefs_set_data_from_toggle, prefs_set_toggle},
381
382         {"domain", NULL, &tmp_ac_prefs.domain, P_STRING,
383          &advanced.domain_entry,
384          prefs_set_data_from_entry, prefs_set_entry},
385
386         {"set_tunnelcmd", "FALSE", &tmp_ac_prefs.set_tunnelcmd, P_BOOL,
387          &advanced.tunnelcmd_chkbtn,
388          prefs_set_data_from_toggle, prefs_set_toggle},
389
390         {"tunnelcmd", NULL, &tmp_ac_prefs.tunnelcmd, P_STRING,
391          &advanced.tunnelcmd_entry,
392          prefs_set_data_from_entry, prefs_set_entry},
393
394         {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
395 };
396
397 static void prefs_account_create                (void);
398 static void prefs_account_basic_create          (void);
399 static void prefs_account_receive_create        (void);
400 static void prefs_account_send_create           (void);
401 static void prefs_account_compose_create        (void);
402 #if USE_GPGME
403 static void prefs_account_privacy_create        (void);
404 #endif /* USE_GPGME */
405 #if USE_SSL
406 static void prefs_account_ssl_create            (void);
407 #endif /* USE_SSL */
408 static void prefs_account_advanced_create       (void);
409
410 static void prefs_account_select_inbox_cb       (void);
411 static void prefs_account_edit_custom_header    (void);
412
413 static gint prefs_account_deleted               (GtkWidget      *widget,
414                                                  GdkEventAny    *event,
415                                                  gpointer        data);
416 static void prefs_account_key_pressed           (GtkWidget      *widget,
417                                                  GdkEventKey    *event,
418                                                  gpointer        data);
419 static void prefs_account_ok                    (void);
420 static gint prefs_account_apply                 (void);
421 static void prefs_account_cancel                (void);
422
423 void prefs_account_read_config(PrefsAccount *ac_prefs, const gchar *label)
424 {
425         const gchar *p = label;
426         gint id;
427
428         g_return_if_fail(ac_prefs != NULL);
429         g_return_if_fail(label != NULL);
430
431         memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
432         prefs_read_config(param, label, ACCOUNT_RC);
433         *ac_prefs = tmp_ac_prefs;
434         while (*p && !isdigit(*p)) p++;
435         id = atoi(p);
436         if (id < 0) g_warning("wrong account id: %d\n", id);
437         ac_prefs->account_id = id;
438
439         prefs_custom_header_read_config(ac_prefs);
440 }
441
442 void prefs_account_save_config(PrefsAccount *ac_prefs)
443 {
444         gchar *buf;
445
446         g_return_if_fail(ac_prefs != NULL);
447
448         tmp_ac_prefs = *ac_prefs;
449         buf = g_strdup_printf("Account: %d", ac_prefs->account_id);
450         prefs_save_config(param, buf, ACCOUNT_RC);
451 }
452
453 void prefs_account_save_config_all(GList *account_list)
454 {
455         GList *cur;
456         gchar *rcpath;
457         PrefFile *pfile;
458
459         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
460         if ((pfile = prefs_write_open(rcpath)) == NULL) {
461                 g_free(rcpath);
462                 return;
463         }
464         g_free(rcpath);
465
466         for (cur = account_list; cur != NULL; cur = cur->next) {
467                 tmp_ac_prefs = *(PrefsAccount *)cur->data;
468                 if (fprintf(pfile->fp, "[Account: %d]\n",
469                             tmp_ac_prefs.account_id) <= 0 ||
470                     prefs_write_param(param, pfile->fp) < 0) {
471                         g_warning(_("failed to write configuration to file\n"));
472                         prefs_write_close_revert(pfile);
473                         return;
474                 }
475                 if (cur->next) {
476                         if (fputc('\n', pfile->fp) == EOF) {
477                                 FILE_OP_ERROR(rcpath, "fputc");
478                                 prefs_write_close_revert(pfile);
479                                 return;
480                         }
481                 }
482         }
483
484         if (prefs_write_close(pfile) < 0)
485                 g_warning(_("failed to write configuration to file\n"));
486 }
487
488 void prefs_account_free(PrefsAccount *ac_prefs)
489 {
490         if (!ac_prefs) return;
491
492         tmp_ac_prefs = *ac_prefs;
493         prefs_free(param);
494 }
495
496 static gint prefs_account_get_new_id(void)
497 {
498         GList *ac_list;
499         PrefsAccount *ac;
500         static gint last_id = 0;
501
502         for (ac_list = account_get_list(); ac_list != NULL;
503              ac_list = ac_list->next) {
504                 ac = (PrefsAccount *)ac_list->data;
505                 if (last_id < ac->account_id)
506                         last_id = ac->account_id;
507         }
508
509         return last_id + 1;
510 }
511
512 PrefsAccount *prefs_account_open(PrefsAccount *ac_prefs)
513 {
514         gboolean new_account = FALSE;
515
516         if (prefs_rc_is_readonly(ACCOUNT_RC))
517                 return ac_prefs;
518
519         debug_print(_("Opening account preferences window...\n"));
520
521         inc_lock();
522
523         cancelled = FALSE;
524
525         if (!ac_prefs) {
526                 ac_prefs = g_new0(PrefsAccount, 1);
527                 ac_prefs->account_id = prefs_account_get_new_id();
528                 new_account = TRUE;
529         }
530
531         if (!dialog.window) {
532                 prefs_account_create();
533         }
534
535         manage_window_set_transient(GTK_WINDOW(dialog.window));
536         gtk_notebook_set_page(GTK_NOTEBOOK(dialog.notebook), 0);
537         gtk_widget_grab_focus(dialog.ok_btn);
538
539         tmp_ac_prefs = *ac_prefs;
540
541         if (new_account) {
542                 PrefsAccount *def_ac;
543                 gchar *buf;
544
545                 prefs_set_dialog_to_default(param);
546                 buf = g_strdup_printf(_("Account%d"), ac_prefs->account_id);
547                 gtk_entry_set_text(GTK_ENTRY(basic.acname_entry), buf);
548                 g_free(buf);
549                 def_ac = account_get_default();
550                 if (def_ac) {
551                         gtk_entry_set_text(GTK_ENTRY(basic.name_entry),
552                                            def_ac->name ? def_ac->name : "");
553                         gtk_entry_set_text(GTK_ENTRY(basic.addr_entry),
554                                            def_ac->address ? def_ac->address : "");
555                         gtk_entry_set_text(GTK_ENTRY(basic.org_entry),
556                                            def_ac->organization ? def_ac->organization : "");
557                 }
558                 gtk_window_set_title(GTK_WINDOW(dialog.window),
559                                      _("Preferences for new account"));
560                 gtk_widget_hide(dialog.apply_btn);
561         } else {
562                 prefs_set_dialog(param);
563                 gtk_window_set_title(GTK_WINDOW(dialog.window),
564                                      _("Account preferences"));
565                 gtk_widget_show(dialog.apply_btn);
566         }
567
568         if (ac_prefs->protocol != A_LOCAL) {
569                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
570                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
571         }
572
573         gtk_widget_show(dialog.window);
574         gtk_main();
575         gtk_widget_hide(dialog.window);
576
577         inc_unlock();
578
579         if (cancelled && new_account) {
580                 g_free(ac_prefs);
581                 return NULL;
582         } else {
583                 *ac_prefs = tmp_ac_prefs;
584                 return ac_prefs;
585         }
586 }
587
588 static void prefs_account_create(void)
589 {
590         gint page = 0;
591
592         debug_print(_("Creating account preferences window...\n"));
593
594         /* create dialog */
595         prefs_dialog_create(&dialog);
596         gtk_signal_connect(GTK_OBJECT(dialog.window), "delete_event",
597                            GTK_SIGNAL_FUNC(prefs_account_deleted), NULL);
598         gtk_signal_connect(GTK_OBJECT(dialog.window), "key_press_event",
599                            GTK_SIGNAL_FUNC(prefs_account_key_pressed), NULL);
600         gtk_signal_connect(GTK_OBJECT(dialog.window), "focus_in_event",
601                            GTK_SIGNAL_FUNC(manage_window_focus_in), NULL);
602         gtk_signal_connect(GTK_OBJECT(dialog.window), "focus_out_event",
603                            GTK_SIGNAL_FUNC(manage_window_focus_out), NULL);
604         gtk_signal_connect(GTK_OBJECT(dialog.ok_btn), "clicked",
605                            GTK_SIGNAL_FUNC(prefs_account_ok), NULL);
606         gtk_signal_connect(GTK_OBJECT(dialog.apply_btn), "clicked",
607                            GTK_SIGNAL_FUNC(prefs_account_apply), NULL);
608         gtk_signal_connect(GTK_OBJECT(dialog.cancel_btn), "clicked",
609                            GTK_SIGNAL_FUNC(prefs_account_cancel), NULL);
610
611         prefs_account_basic_create();
612         SET_NOTEBOOK_LABEL(dialog.notebook, _("Basic"), page++);
613         prefs_account_receive_create();
614         SET_NOTEBOOK_LABEL(dialog.notebook, _("Receive"), page++);
615         prefs_account_send_create();
616         SET_NOTEBOOK_LABEL(dialog.notebook, _("Send"), page++);
617         prefs_account_compose_create();
618         SET_NOTEBOOK_LABEL(dialog.notebook, _("Compose"), page++);
619 #if USE_GPGME
620         prefs_account_privacy_create();
621         SET_NOTEBOOK_LABEL(dialog.notebook, _("Privacy"), page++);
622 #endif /* USE_GPGME */
623 #if USE_SSL
624         prefs_account_ssl_create();
625         SET_NOTEBOOK_LABEL(dialog.notebook, _("SSL"), page++);
626 #endif /* USE_SSL */
627         prefs_account_advanced_create();
628         SET_NOTEBOOK_LABEL(dialog.notebook, _("Advanced"), page++);
629
630         prefs_account_fix_size();
631 }
632
633 /**
634  * prefs_account_fix_size:
635  * 
636  * Fix the window size after creating widgets by selecting "Local"
637  * protocol (currently it has the largest size of parameter widgets).
638  * Without this the window gets too large.
639  **/
640 static void prefs_account_fix_size(void)
641 {
642         GtkOptionMenu *optmenu = GTK_OPTION_MENU (basic.protocol_optmenu);
643         GtkWidget *menu;
644         GtkWidget *menuitem;
645
646         gtk_option_menu_set_history (optmenu, 4); /* local */
647         menu = gtk_option_menu_get_menu (optmenu);
648         menuitem = gtk_menu_get_active (GTK_MENU (menu));
649         gtk_menu_item_activate (GTK_MENU_ITEM (menuitem));
650 }
651
652 #define SET_ACTIVATE(menuitem) \
653 { \
654         gtk_signal_connect(GTK_OBJECT(menuitem), "activate", \
655                            GTK_SIGNAL_FUNC(prefs_account_protocol_activated), \
656                            NULL); \
657 }
658
659 #define TABLE_YPAD 2
660
661 static void prefs_account_basic_create(void)
662 {
663         GtkWidget *vbox1;
664         GtkWidget *hbox;
665         GtkWidget *label;
666         GtkWidget *acname_entry;
667         GtkWidget *default_chkbtn;
668         GtkWidget *frame1;
669         GtkWidget *table1;
670         GtkWidget *name_entry;
671         GtkWidget *addr_entry;
672         GtkWidget *org_entry;
673
674         GtkWidget *serv_frame;
675         GtkWidget *vbox2;
676         GtkWidget *optmenu;
677         GtkWidget *optmenu_menu;
678         GtkWidget *menuitem;
679         GtkWidget *serv_table;
680         GtkWidget *recvserv_label;
681         GtkWidget *smtpserv_label;
682         GtkWidget *nntpserv_label;
683         GtkWidget *localmbox_label;
684         GtkWidget *mailcmd_label;
685         GtkWidget *recvserv_entry;
686         GtkWidget *smtpserv_entry;
687         GtkWidget *nntpserv_entry;
688         GtkWidget *nntpauth_chkbtn;
689         GtkWidget *localmbox_entry;
690         GtkWidget *mailcmd_chkbtn;
691         GtkWidget *mailcmd_entry;
692         GtkWidget *uid_label;
693         GtkWidget *pass_label;
694         GtkWidget *uid_entry;
695         GtkWidget *pass_entry;
696
697         vbox1 = gtk_vbox_new (FALSE, VSPACING);
698         gtk_widget_show (vbox1);
699         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
700         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
701
702         hbox = gtk_hbox_new (FALSE, 8);
703         gtk_widget_show (hbox);
704         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
705
706         label = gtk_label_new (_("Name of this account"));
707         gtk_widget_show (label);
708         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
709
710         acname_entry = gtk_entry_new ();
711         gtk_widget_show (acname_entry);
712         gtk_widget_set_usize (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
713         gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
714
715         default_chkbtn = gtk_check_button_new_with_label (_("Set as default"));
716         gtk_widget_show (default_chkbtn);
717         gtk_box_pack_end (GTK_BOX (hbox), default_chkbtn, FALSE, FALSE, 0);
718
719         PACK_FRAME (vbox1, frame1, _("Personal information"));
720
721         table1 = gtk_table_new (3, 2, FALSE);
722         gtk_widget_show (table1);
723         gtk_container_add (GTK_CONTAINER (frame1), table1);
724         gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
725         gtk_table_set_row_spacings (GTK_TABLE (table1), VSPACING_NARROW);
726         gtk_table_set_col_spacings (GTK_TABLE (table1), 8);
727
728         label = gtk_label_new (_("Full name"));
729         gtk_widget_show (label);
730         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 0, 1,
731                           GTK_FILL, 0, 0, 0);
732         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
733
734         label = gtk_label_new (_("Mail address"));
735         gtk_widget_show (label);
736         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 1, 2,
737                           GTK_FILL, 0, 0, 0);
738         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
739
740         label = gtk_label_new (_("Organization"));
741         gtk_widget_show (label);
742         gtk_table_attach (GTK_TABLE (table1), label, 0, 1, 2, 3,
743                           GTK_FILL, 0, 0, 0);
744         gtk_misc_set_alignment (GTK_MISC (label), 1, 0.5);
745
746         name_entry = gtk_entry_new ();
747         gtk_widget_show (name_entry);
748         gtk_table_attach (GTK_TABLE (table1), name_entry, 1, 2, 0, 1,
749                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
750                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
751
752         addr_entry = gtk_entry_new ();
753         gtk_widget_show (addr_entry);
754         gtk_table_attach (GTK_TABLE (table1), addr_entry, 1, 2, 1, 2,
755                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
756                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
757
758         org_entry = gtk_entry_new ();
759         gtk_widget_show (org_entry);
760         gtk_table_attach (GTK_TABLE (table1), org_entry, 1, 2, 2, 3,
761                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
762                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
763
764         PACK_FRAME (vbox1, serv_frame, _("Server information"));
765
766         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
767         gtk_widget_show (vbox2);
768         gtk_container_add (GTK_CONTAINER (serv_frame), vbox2);
769         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
770
771         hbox = gtk_hbox_new (FALSE, 8);
772         gtk_widget_show (hbox);
773         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
774
775         label = gtk_label_new (_("Protocol"));
776         gtk_widget_show (label);
777         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
778
779         optmenu = gtk_option_menu_new ();
780         gtk_widget_show (optmenu);
781         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
782
783         optmenu_menu = gtk_menu_new ();
784
785         MENUITEM_ADD (optmenu_menu, menuitem, _("POP3 (normal)"),  A_POP3);
786         SET_ACTIVATE (menuitem);
787         MENUITEM_ADD (optmenu_menu, menuitem, _("POP3 (APOP auth)"),  A_APOP);
788         SET_ACTIVATE (menuitem);
789         MENUITEM_ADD (optmenu_menu, menuitem, _("IMAP4"), A_IMAP4);
790         SET_ACTIVATE (menuitem);
791         MENUITEM_ADD (optmenu_menu, menuitem, _("News (NNTP)"), A_NNTP);
792         SET_ACTIVATE (menuitem);
793         MENUITEM_ADD (optmenu_menu, menuitem, _("None (local)"), A_LOCAL);
794         SET_ACTIVATE (menuitem);
795
796         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
797
798         serv_table = gtk_table_new (6, 4, FALSE);
799         gtk_widget_show (serv_table);
800         gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
801         gtk_table_set_row_spacings (GTK_TABLE (serv_table), VSPACING_NARROW);
802         gtk_table_set_row_spacing (GTK_TABLE (serv_table), 3, 0);
803         gtk_table_set_col_spacings (GTK_TABLE (serv_table), 8);
804
805         nntpserv_entry = gtk_entry_new ();
806         gtk_widget_show (nntpserv_entry);
807         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_entry, 1, 4, 0, 1,
808                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
809                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
810 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 0, 0); */
811
812         nntpauth_chkbtn = gtk_check_button_new_with_label
813                 (_("This server requires authentication"));
814         gtk_widget_show (nntpauth_chkbtn);
815         gtk_table_attach (GTK_TABLE (serv_table), nntpauth_chkbtn, 0, 4, 1, 2,
816                           GTK_FILL, 0, 0, 0);
817
818         recvserv_entry = gtk_entry_new ();
819         gtk_widget_show (recvserv_entry);
820         gtk_table_attach (GTK_TABLE (serv_table), recvserv_entry, 1, 4, 2, 3,
821                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
822                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
823
824         localmbox_entry = gtk_entry_new ();
825         gtk_widget_show (localmbox_entry);
826         gtk_table_attach (GTK_TABLE (serv_table), localmbox_entry, 1, 4, 3, 4,
827                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
828                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
829
830         smtpserv_entry = gtk_entry_new ();
831         gtk_widget_show (smtpserv_entry);
832         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_entry, 1, 4, 4, 5,
833                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
834                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
835
836         mailcmd_entry = gtk_entry_new ();
837         gtk_widget_show (mailcmd_entry);
838         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_entry, 1, 4, 6, 7,
839                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
840                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
841
842         uid_entry = gtk_entry_new ();
843         gtk_widget_show (uid_entry);
844         gtk_widget_set_usize (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
845         gtk_table_attach (GTK_TABLE (serv_table), uid_entry, 1, 2, 7, 8,
846                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
847                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
848
849         pass_entry = gtk_entry_new ();
850         gtk_widget_show (pass_entry);
851         gtk_widget_set_usize (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
852         gtk_table_attach (GTK_TABLE (serv_table), pass_entry, 3, 4, 7, 8,
853                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
854                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
855         gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
856
857         nntpserv_label = gtk_label_new (_("News server"));
858         gtk_widget_show (nntpserv_label);
859         gtk_table_attach (GTK_TABLE (serv_table), nntpserv_label, 0, 1, 0, 1,
860                           GTK_FILL, 0, 0, 0);
861         gtk_misc_set_alignment (GTK_MISC (nntpserv_label), 1, 0.5);
862
863         recvserv_label = gtk_label_new (_("Server for receiving"));
864         gtk_widget_show (recvserv_label);
865         gtk_table_attach (GTK_TABLE (serv_table), recvserv_label, 0, 1, 2, 3,
866                           GTK_FILL, 0, 0, 0);
867         gtk_misc_set_alignment (GTK_MISC (recvserv_label), 1, 0.5);
868
869         localmbox_label = gtk_label_new (_("Local mailbox file"));
870         gtk_widget_show (localmbox_label);
871         gtk_table_attach (GTK_TABLE (serv_table), localmbox_label, 0, 1, 3, 4,
872                           GTK_FILL, 0, 0, 0);
873         gtk_misc_set_alignment (GTK_MISC (localmbox_label), 1, 0.5);
874 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
875
876         smtpserv_label = gtk_label_new (_("SMTP server (send)"));
877         gtk_widget_show (smtpserv_label);
878         gtk_table_attach (GTK_TABLE (serv_table), smtpserv_label, 0, 1, 4, 5,
879                           GTK_FILL, 0, 0, 0);
880         gtk_misc_set_alignment (GTK_MISC (smtpserv_label), 1, 0.5);
881 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
882
883         mailcmd_chkbtn = gtk_check_button_new_with_label
884                 (_("Use mail command rather than SMTP server"));
885         gtk_widget_show (mailcmd_chkbtn);
886         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_chkbtn, 0, 4, 5, 6,
887                           GTK_EXPAND | GTK_FILL,
888                           0, 0, TABLE_YPAD);
889         gtk_signal_connect(GTK_OBJECT(mailcmd_chkbtn), "toggled",
890                            GTK_SIGNAL_FUNC(prefs_account_mailcmd_toggled),
891                            NULL);
892
893         mailcmd_label = gtk_label_new (_("command to send mails"));
894         gtk_widget_show (mailcmd_label);
895         gtk_table_attach (GTK_TABLE (serv_table), mailcmd_label, 0, 1, 6, 7,
896                           GTK_FILL, 0, 0, 0);
897         gtk_misc_set_alignment (GTK_MISC (mailcmd_label), 1, 0.5);
898 /*      gtk_table_set_row_spacing (GTK_TABLE (serv_table), 2, 0); */
899
900         uid_label = gtk_label_new (_("User ID"));
901         gtk_widget_show (uid_label);
902         gtk_table_attach (GTK_TABLE (serv_table), uid_label, 0, 1, 7, 8,
903                           GTK_FILL, 0, 0, 0);
904         gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
905
906         pass_label = gtk_label_new (_("Password"));
907         gtk_widget_show (pass_label);
908         gtk_table_attach (GTK_TABLE (serv_table), pass_label, 2, 3, 7, 8,
909                           0, 0, 0, 0);
910
911         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, uid_label);
912         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, pass_label);
913         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, uid_entry);
914         SET_TOGGLE_SENSITIVITY (nntpauth_chkbtn, pass_entry);
915
916         basic.acname_entry   = acname_entry;
917         basic.default_chkbtn = default_chkbtn;
918
919         basic.name_entry = name_entry;
920         basic.addr_entry = addr_entry;
921         basic.org_entry  = org_entry;
922
923         basic.serv_frame       = serv_frame;
924         basic.serv_table       = serv_table;
925         basic.protocol_optmenu = optmenu;
926         basic.recvserv_label   = recvserv_label;
927         basic.recvserv_entry   = recvserv_entry;
928         basic.smtpserv_label   = smtpserv_label;
929         basic.smtpserv_entry   = smtpserv_entry;
930         basic.nntpserv_label   = nntpserv_label;
931         basic.nntpserv_entry   = nntpserv_entry;
932         basic.nntpauth_chkbtn  = nntpauth_chkbtn;
933         basic.localmbox_label   = localmbox_label;
934         basic.localmbox_entry   = localmbox_entry;
935         basic.mailcmd_chkbtn   = mailcmd_chkbtn;
936         basic.mailcmd_label   = mailcmd_label;
937         basic.mailcmd_entry   = mailcmd_entry;
938         basic.uid_label        = uid_label;
939         basic.pass_label       = pass_label;
940         basic.uid_entry        = uid_entry;
941         basic.pass_entry       = pass_entry;
942 }
943
944 static void prefs_account_receive_create(void)
945 {
946         GtkWidget *vbox1;
947         GtkWidget *frame1;
948         GtkWidget *vbox2;
949         GtkWidget *rmmail_chkbtn;
950         GtkWidget *getall_chkbtn;
951         GtkWidget *recvatgetall_chkbtn;
952         GtkWidget *filter_on_recv_chkbtn;
953         GtkWidget *vbox3;
954         GtkWidget *hbox1;
955         GtkWidget *inbox_label;
956         GtkWidget *inbox_entry;
957         GtkWidget *inbox_btn;
958         GtkWidget *label;
959         GtkWidget *frame2;
960         GtkWidget *imapdir_label;
961         GtkWidget *imapdir_entry;
962
963         vbox1 = gtk_vbox_new (FALSE, VSPACING);
964         gtk_widget_show (vbox1);
965         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
966         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
967
968         PACK_FRAME (vbox1, frame1, _("POP3"));
969
970         vbox2 = gtk_vbox_new (FALSE, 0);
971         gtk_widget_show (vbox2);
972         gtk_container_add (GTK_CONTAINER (frame1), vbox2);
973         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
974
975         PACK_CHECK_BUTTON (vbox2, rmmail_chkbtn,
976                            _("Remove messages on server when received"));
977         PACK_CHECK_BUTTON (vbox2, getall_chkbtn,
978                            _("Download all messages on server"));
979         PACK_CHECK_BUTTON
980                 (vbox2, recvatgetall_chkbtn,
981                  _("`Get all' checks for new mail on this account"));
982         PACK_CHECK_BUTTON (vbox2, filter_on_recv_chkbtn,
983                            _("Filter messages on receiving"));
984
985         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
986
987         hbox1 = gtk_hbox_new (FALSE, 8);
988         gtk_widget_show (hbox1);
989         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
990
991         inbox_label = gtk_label_new (_("Default inbox"));
992         gtk_widget_show (inbox_label);
993         gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
994
995         inbox_entry = gtk_entry_new ();
996         gtk_widget_show (inbox_entry);
997         gtk_widget_set_usize (inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
998         gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
999
1000         inbox_btn = gtk_button_new_with_label (_(" Select... "));
1001         gtk_widget_show (inbox_btn);
1002         gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1003         gtk_signal_connect (GTK_OBJECT (inbox_btn), "clicked",
1004                             GTK_SIGNAL_FUNC (prefs_account_select_inbox_cb),
1005                             NULL);
1006
1007         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1008
1009         hbox1 = gtk_hbox_new (FALSE, 8);
1010         gtk_widget_show (hbox1);
1011         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1012
1013         label = gtk_label_new
1014                 (_("(Unfiltered messages will be stored in this folder)"));
1015         gtk_widget_show (label);
1016         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1017         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1018
1019         PACK_FRAME (vbox1, frame2, _("IMAP4"));
1020
1021         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW);
1022         gtk_widget_show (vbox2);
1023         gtk_container_add (GTK_CONTAINER (frame2), vbox2);
1024         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1025
1026         hbox1 = gtk_hbox_new (FALSE, 8);
1027         gtk_widget_show (hbox1);
1028         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1029
1030         imapdir_label = gtk_label_new (_("IMAP server directory"));
1031         gtk_widget_show (imapdir_label);
1032         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1033
1034         imapdir_entry = gtk_entry_new();
1035         gtk_widget_show (imapdir_entry);
1036         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, TRUE, TRUE, 0);
1037
1038         receive.pop3_frame            = frame1;
1039         receive.rmmail_chkbtn         = rmmail_chkbtn;
1040         receive.getall_chkbtn         = getall_chkbtn;
1041         receive.recvatgetall_chkbtn   = recvatgetall_chkbtn;
1042         receive.filter_on_recv_chkbtn = filter_on_recv_chkbtn;
1043         receive.inbox_label           = inbox_label;
1044         receive.inbox_entry           = inbox_entry;
1045         receive.inbox_btn             = inbox_btn;
1046
1047         receive.imap_frame    = frame2;
1048         receive.imapdir_entry = imapdir_entry;
1049 }
1050
1051 static void prefs_account_send_create(void)
1052 {
1053         GtkWidget *vbox1;
1054         GtkWidget *vbox2;
1055         GtkWidget *frame;
1056         GtkWidget *date_chkbtn;
1057         GtkWidget *msgid_chkbtn;
1058         GtkWidget *hbox;
1059         GtkWidget *customhdr_chkbtn;
1060         GtkWidget *customhdr_edit_btn;
1061         GtkWidget *frame3;
1062         GtkWidget *vbox3;
1063         GtkWidget *smtp_auth_chkbtn;
1064         GtkWidget *smtp_auth_hbox;
1065         GtkWidget *label;
1066         GtkWidget *uid_label;
1067         GtkWidget *smtp_userid_entry;
1068         GtkWidget *pass_label;
1069         GtkWidget *smtp_passwd_entry;
1070         GtkWidget *pop_bfr_smtp_chkbtn;
1071
1072         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1073         gtk_widget_show (vbox1);
1074         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1075         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1076
1077         PACK_FRAME (vbox1, frame, _("Header"));
1078
1079         vbox2 = gtk_vbox_new (FALSE, 0);
1080         gtk_widget_show (vbox2);
1081         gtk_container_add (GTK_CONTAINER (frame), vbox2);
1082         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1083
1084         PACK_CHECK_BUTTON (vbox2, date_chkbtn, _("Add Date header field"));
1085         PACK_CHECK_BUTTON (vbox2, msgid_chkbtn, _("Generate Message-ID"));
1086
1087         hbox = gtk_hbox_new (FALSE, 12);
1088         gtk_widget_show (hbox);
1089         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1090
1091         PACK_CHECK_BUTTON (hbox, customhdr_chkbtn,
1092                            _("Add user-defined header"));
1093
1094         customhdr_edit_btn = gtk_button_new_with_label (_(" Edit... "));
1095         gtk_widget_show (customhdr_edit_btn);
1096         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1097                             FALSE, FALSE, 0);
1098         gtk_signal_connect (GTK_OBJECT (customhdr_edit_btn), "clicked",
1099                             GTK_SIGNAL_FUNC (prefs_account_edit_custom_header),
1100                             NULL);
1101
1102         SET_TOGGLE_SENSITIVITY (customhdr_chkbtn, customhdr_edit_btn);
1103
1104         PACK_FRAME (vbox1, frame3, _("Authentication"));
1105
1106         vbox3 = gtk_vbox_new (FALSE, 0);
1107         gtk_widget_show (vbox3);
1108         gtk_container_add (GTK_CONTAINER (frame3), vbox3);
1109         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1110
1111         PACK_CHECK_BUTTON (vbox3, smtp_auth_chkbtn,
1112                 _("SMTP Authentication (SMTP AUTH)"));
1113
1114         smtp_auth_hbox = gtk_hbox_new (FALSE, 8);
1115         gtk_widget_show (smtp_auth_hbox);
1116         gtk_box_pack_start (GTK_BOX (vbox3), smtp_auth_hbox, FALSE, FALSE, 0);
1117
1118         label = gtk_label_new ("");
1119         gtk_widget_show (label);
1120         gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), label, FALSE, FALSE, 0);
1121         gtk_widget_set_usize (label, 16, -1);
1122
1123         uid_label = gtk_label_new (_("User ID"));
1124         gtk_widget_show (uid_label);
1125         gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), uid_label,
1126                             FALSE, FALSE, 0);
1127         gtk_misc_set_alignment (GTK_MISC (uid_label), 1, 0.5);
1128         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, uid_label);
1129
1130         smtp_userid_entry = gtk_entry_new ();
1131         gtk_widget_show (smtp_userid_entry);
1132         gtk_widget_set_usize (smtp_userid_entry, DEFAULT_ENTRY_WIDTH, -1);
1133         gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), smtp_userid_entry,
1134                             TRUE, TRUE, 0);
1135         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, smtp_userid_entry);
1136
1137         pass_label = gtk_label_new (_("Password"));
1138         gtk_widget_show (pass_label);
1139         gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), pass_label,
1140                             FALSE, FALSE, 0);
1141         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, pass_label);
1142
1143         smtp_passwd_entry = gtk_entry_new ();
1144         gtk_widget_show (smtp_passwd_entry);
1145         gtk_widget_set_usize (smtp_passwd_entry, DEFAULT_ENTRY_WIDTH, -1);
1146         gtk_box_pack_start (GTK_BOX (smtp_auth_hbox), smtp_passwd_entry,
1147                             TRUE, TRUE, 0);
1148         gtk_entry_set_visibility (GTK_ENTRY (smtp_passwd_entry), FALSE);
1149         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, smtp_passwd_entry);
1150
1151         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_chkbtn,
1152                 _("Authenticate with POP3 before sending"));
1153         gtk_widget_set_sensitive(pop_bfr_smtp_chkbtn, FALSE);
1154
1155         send.date_chkbtn      = date_chkbtn;
1156         send.msgid_chkbtn     = msgid_chkbtn;
1157         send.customhdr_chkbtn = customhdr_chkbtn;
1158
1159         send.smtp_auth_chkbtn    = smtp_auth_chkbtn;
1160         send.smtp_userid_entry   = smtp_userid_entry;
1161         send.smtp_passwd_entry   = smtp_passwd_entry;
1162         send.pop_bfr_smtp_chkbtn = pop_bfr_smtp_chkbtn;
1163 }
1164
1165 static void prefs_account_compose_create(void)
1166 {
1167         GtkWidget *vbox1;
1168         GtkWidget *hbox;
1169         GtkWidget *label;
1170         GtkWidget *sigpath_entry;
1171         GtkWidget *frame;
1172         GtkWidget *table;
1173         GtkWidget *autocc_chkbtn;
1174         GtkWidget *autocc_entry;
1175         GtkWidget *autobcc_chkbtn;
1176         GtkWidget *autobcc_entry;
1177         GtkWidget *autoreplyto_chkbtn;
1178         GtkWidget *autoreplyto_entry;
1179
1180         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1181         gtk_widget_show (vbox1);
1182         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1183         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1184
1185         hbox = gtk_hbox_new (FALSE, 8);
1186         gtk_widget_show (hbox);
1187         gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
1188
1189         label = gtk_label_new (_("Signature file"));
1190         gtk_widget_show (label);
1191         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1192
1193         sigpath_entry = gtk_entry_new ();
1194         gtk_widget_show (sigpath_entry);
1195         gtk_box_pack_start (GTK_BOX (hbox), sigpath_entry, TRUE, TRUE, 0);
1196
1197         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
1198
1199         table =  gtk_table_new (3, 2, FALSE);
1200         gtk_widget_show (table);
1201         gtk_container_add (GTK_CONTAINER (frame), table);
1202         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
1203         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
1204         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1205
1206         autocc_chkbtn = gtk_check_button_new_with_label (_("Cc"));
1207         gtk_widget_show (autocc_chkbtn);
1208         gtk_table_attach (GTK_TABLE (table), autocc_chkbtn, 0, 1, 0, 1,
1209                           GTK_FILL, 0, 0, 0);
1210
1211         autocc_entry = gtk_entry_new ();
1212         gtk_widget_show (autocc_entry);
1213         gtk_table_attach (GTK_TABLE (table), autocc_entry, 1, 2, 0, 1,
1214                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1215                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1216
1217         SET_TOGGLE_SENSITIVITY (autocc_chkbtn, autocc_entry);
1218
1219         autobcc_chkbtn = gtk_check_button_new_with_label (_("Bcc"));
1220         gtk_widget_show (autobcc_chkbtn);
1221         gtk_table_attach (GTK_TABLE (table), autobcc_chkbtn, 0, 1, 1, 2,
1222                           GTK_FILL, 0, 0, 0);
1223
1224         autobcc_entry = gtk_entry_new ();
1225         gtk_widget_show (autobcc_entry);
1226         gtk_table_attach (GTK_TABLE (table), autobcc_entry, 1, 2, 1, 2,
1227                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1228                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1229
1230         SET_TOGGLE_SENSITIVITY (autobcc_chkbtn, autobcc_entry);
1231
1232         autoreplyto_chkbtn = gtk_check_button_new_with_label (_("Reply-To"));
1233         gtk_widget_show (autoreplyto_chkbtn);
1234         gtk_table_attach (GTK_TABLE (table), autoreplyto_chkbtn, 0, 1, 2, 3,
1235                           GTK_FILL, 0, 0, 0);
1236
1237         autoreplyto_entry = gtk_entry_new ();
1238         gtk_widget_show (autoreplyto_entry);
1239         gtk_table_attach (GTK_TABLE (table), autoreplyto_entry, 1, 2, 2, 3,
1240                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1241                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1242
1243         SET_TOGGLE_SENSITIVITY (autoreplyto_chkbtn, autoreplyto_entry);
1244
1245         compose.sigpath_entry = sigpath_entry;
1246
1247         compose.autocc_chkbtn      = autocc_chkbtn;
1248         compose.autocc_entry       = autocc_entry;
1249         compose.autobcc_chkbtn     = autobcc_chkbtn;
1250         compose.autobcc_entry      = autobcc_entry;
1251         compose.autoreplyto_chkbtn = autoreplyto_chkbtn;
1252         compose.autoreplyto_entry  = autoreplyto_entry;
1253 }
1254
1255 #if USE_GPGME
1256 static void prefs_account_privacy_create(void)
1257 {
1258         GtkWidget *vbox1;
1259         GtkWidget *frame1;
1260         GtkWidget *vbox2;
1261         GtkWidget *frame2;
1262         GtkWidget *vbox3;
1263         GtkWidget *hbox1;
1264         GtkWidget *label;
1265         GtkWidget *checkbtn_default_encrypt;
1266         GtkWidget *checkbtn_ascii_armored;
1267         GtkWidget *checkbtn_default_sign;
1268         GtkWidget *defaultkey_radiobtn;
1269         GtkWidget *emailkey_radiobtn;
1270         GtkWidget *customkey_radiobtn;
1271         GtkWidget *customkey_entry;
1272
1273         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1274         gtk_widget_show (vbox1);
1275         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1276         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1277
1278         PACK_FRAME (vbox1, frame1, _("Default Actions"));
1279
1280         vbox2 = gtk_vbox_new (FALSE, 0);
1281         gtk_widget_show (vbox2);
1282         gtk_container_add (GTK_CONTAINER (frame1), vbox2);
1283         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1284
1285         PACK_CHECK_BUTTON (vbox2, checkbtn_default_encrypt,
1286                            _("Encrypt message by default"));
1287
1288         PACK_CHECK_BUTTON (vbox2, checkbtn_ascii_armored,
1289                            _("Plain ASCII armored"));
1290         gtk_signal_connect(GTK_OBJECT(checkbtn_ascii_armored), "toggled",
1291                                 prefs_account_ascii_armored_warning, (gpointer)0);
1292
1293         PACK_CHECK_BUTTON (vbox2, checkbtn_default_sign,
1294                            _("Sign message by default"));
1295
1296         PACK_FRAME (vbox1, frame2, _("Sign key"));
1297
1298         vbox3 = gtk_vbox_new (FALSE, VSPACING_NARROW);
1299         gtk_widget_show (vbox3);
1300         gtk_container_add (GTK_CONTAINER (frame2), vbox3);
1301         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1302
1303         defaultkey_radiobtn = gtk_radio_button_new_with_label
1304                 (NULL, _("Use default GnuPG key"));
1305         gtk_widget_show (defaultkey_radiobtn);
1306         gtk_box_pack_start (GTK_BOX (vbox3), defaultkey_radiobtn,
1307                             FALSE, FALSE, 0);
1308         gtk_object_set_user_data (GTK_OBJECT (defaultkey_radiobtn),
1309                                   GINT_TO_POINTER (SIGN_KEY_DEFAULT));
1310
1311         emailkey_radiobtn = gtk_radio_button_new_with_label_from_widget
1312                 (GTK_RADIO_BUTTON (defaultkey_radiobtn),
1313                  _("Select key by your email address"));
1314         gtk_widget_show (emailkey_radiobtn);
1315         gtk_box_pack_start (GTK_BOX (vbox3), emailkey_radiobtn,
1316                             FALSE, FALSE, 0);
1317         gtk_object_set_user_data (GTK_OBJECT (emailkey_radiobtn),
1318                                   GINT_TO_POINTER (SIGN_KEY_BY_FROM));
1319
1320         customkey_radiobtn = gtk_radio_button_new_with_label_from_widget
1321                 (GTK_RADIO_BUTTON (defaultkey_radiobtn),
1322                  _("Specify key manually"));
1323         gtk_widget_show (customkey_radiobtn);
1324         gtk_box_pack_start (GTK_BOX (vbox3), customkey_radiobtn,
1325                             FALSE, FALSE, 0);
1326         gtk_object_set_user_data (GTK_OBJECT (customkey_radiobtn),
1327                                   GINT_TO_POINTER (SIGN_KEY_CUSTOM));
1328
1329         hbox1 = gtk_hbox_new (FALSE, 8);
1330         gtk_widget_show (hbox1);
1331         gtk_box_pack_start (GTK_BOX (vbox3), hbox1, FALSE, FALSE, 0);
1332
1333         label = gtk_label_new ("");
1334         gtk_widget_show (label);
1335         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1336         gtk_widget_set_usize (label, 16, -1);
1337
1338         label = gtk_label_new (_("User or key ID:"));
1339         gtk_widget_show (label);
1340         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1341
1342         customkey_entry = gtk_entry_new ();
1343         gtk_widget_show (customkey_entry);
1344         gtk_box_pack_start (GTK_BOX (hbox1), customkey_entry,
1345                             TRUE, TRUE, 0);
1346
1347         SET_TOGGLE_SENSITIVITY (customkey_radiobtn, customkey_entry);
1348
1349         privacy.checkbtn_default_encrypt = checkbtn_default_encrypt;
1350         privacy.checkbtn_ascii_armored   = checkbtn_ascii_armored;
1351         privacy.checkbtn_default_sign    = checkbtn_default_sign;
1352         privacy.defaultkey_radiobtn = defaultkey_radiobtn;
1353         privacy.emailkey_radiobtn = emailkey_radiobtn;
1354         privacy.customkey_radiobtn = customkey_radiobtn;
1355         privacy.customkey_entry = customkey_entry;
1356 }
1357
1358 static void prefs_account_ascii_armored_warning(GtkWidget* widget,
1359                                                gpointer unused)
1360 {
1361         if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(widget))
1362                 && gtk_notebook_get_current_page(GTK_NOTEBOOK(dialog.notebook))) {
1363                 alertpanel_message(_("Warning - Privacy/Plain ASCII armored"),
1364                         _("Its not recommend to use the old style plain ASCII\n"
1365                         "armored mode for encypted messages. It doesn't comply\n"
1366                         "with the RFC 3156 - MIME security with OpenPGP."));
1367         }
1368 }
1369 #endif /* USE_GPGME */
1370
1371 #if USE_SSL
1372 static void prefs_account_ssl_create(void)
1373 {
1374         GtkWidget *vbox1;
1375
1376         GtkWidget *receive_frame;
1377         GtkWidget *vbox2;
1378         GtkWidget *pop_chkbtn;
1379         GtkWidget *imap_chkbtn;
1380
1381         GtkWidget *send_frame;
1382         GtkWidget *vbox3;
1383         GtkWidget *smtp_nossl_radiobtn;
1384         GtkWidget *smtp_ssltunnel_radiobtn;
1385         GtkWidget *smtp_sslstarttls_radiobtn;
1386
1387         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1388         gtk_widget_show (vbox1);
1389         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1390         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1391
1392         PACK_FRAME (vbox1, receive_frame, _("Receive"));
1393
1394         vbox2 = gtk_vbox_new (FALSE, 0);
1395         gtk_widget_show (vbox2);
1396         gtk_container_add (GTK_CONTAINER (receive_frame), vbox2);
1397         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1398
1399         PACK_CHECK_BUTTON (vbox2, pop_chkbtn,
1400                            _("Use SSL for POP3 connection"));
1401         PACK_CHECK_BUTTON (vbox2, imap_chkbtn,
1402                            _("Use SSL for IMAP4 connection"));
1403
1404         PACK_FRAME (vbox1, send_frame, _("Send (SMTP)"));
1405
1406         vbox3 = gtk_vbox_new (FALSE, 0);
1407         gtk_widget_show (vbox3);
1408         gtk_container_add (GTK_CONTAINER (send_frame), vbox3);
1409         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1410
1411         smtp_nossl_radiobtn =
1412                 gtk_radio_button_new_with_label(NULL, _("Don't use SSL"));
1413         gtk_widget_show (smtp_nossl_radiobtn);
1414         gtk_box_pack_start (GTK_BOX (vbox3), smtp_nossl_radiobtn,
1415                             FALSE, FALSE, 0);
1416         gtk_object_set_user_data (GTK_OBJECT (smtp_nossl_radiobtn),
1417                                   GINT_TO_POINTER (SSL_SMTP_NONE));
1418
1419         smtp_ssltunnel_radiobtn = gtk_radio_button_new_with_label_from_widget
1420                 (GTK_RADIO_BUTTON (smtp_nossl_radiobtn),
1421                  _("Use SSL for SMTP connection"));
1422         gtk_widget_show (smtp_ssltunnel_radiobtn);
1423         gtk_box_pack_start (GTK_BOX (vbox3), smtp_ssltunnel_radiobtn,
1424                             FALSE, FALSE, 0);
1425         gtk_object_set_user_data (GTK_OBJECT (smtp_ssltunnel_radiobtn),
1426                                   GINT_TO_POINTER (SSL_SMTP_TUNNEL));
1427
1428         smtp_sslstarttls_radiobtn = gtk_radio_button_new_with_label_from_widget
1429                 (GTK_RADIO_BUTTON (smtp_nossl_radiobtn),
1430                  _("Use STARTTLS command to start SSL session"));
1431         gtk_widget_show (smtp_sslstarttls_radiobtn);
1432         gtk_box_pack_start (GTK_BOX (vbox3), smtp_sslstarttls_radiobtn,
1433                             FALSE, FALSE, 0);
1434         gtk_object_set_user_data (GTK_OBJECT (smtp_sslstarttls_radiobtn),
1435                                   GINT_TO_POINTER (SSL_SMTP_STARTTLS));
1436
1437         ssl.receive_frame = receive_frame;
1438         ssl.pop_chkbtn    = pop_chkbtn;
1439         ssl.imap_chkbtn   = imap_chkbtn;
1440
1441         ssl.send_frame                = send_frame;
1442         ssl.smtp_nossl_radiobtn       = smtp_nossl_radiobtn;
1443         ssl.smtp_ssltunnel_radiobtn   = smtp_ssltunnel_radiobtn;
1444         ssl.smtp_sslstarttls_radiobtn = smtp_sslstarttls_radiobtn;
1445 }
1446 #endif /* USE_SSL */
1447
1448 static void prefs_account_advanced_create(void)
1449 {
1450         GtkWidget *vbox1;
1451         GtkWidget *vbox2;
1452         GtkWidget *hbox1;
1453         GtkWidget *checkbtn_smtpport;
1454         GtkWidget *entry_smtpport;
1455         GtkWidget *hbox_popport;
1456         GtkWidget *checkbtn_popport;
1457         GtkWidget *entry_popport;
1458         GtkWidget *hbox_imapport;
1459         GtkWidget *checkbtn_imapport;
1460         GtkWidget *entry_imapport;
1461         GtkWidget *hbox_nntpport;
1462         GtkWidget *checkbtn_nntpport;
1463         GtkWidget *entry_nntpport;
1464         GtkWidget *checkbtn_domain;
1465         GtkWidget *entry_domain;
1466         GtkWidget *checkbtn_tunnelcmd;
1467         GtkWidget *entry_tunnelcmd;
1468
1469 #define PACK_HBOX(hbox) \
1470         { \
1471         hbox = gtk_hbox_new (FALSE, 8); \
1472         gtk_widget_show (hbox); \
1473         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
1474         }
1475
1476 #define PACK_PORT_ENTRY(box, entry) \
1477         { \
1478         entry = gtk_entry_new_with_max_length (5); \
1479         gtk_widget_show (entry); \
1480         gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 0); \
1481         gtk_widget_set_usize (entry, 64, -1); \
1482         }
1483
1484         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1485         gtk_widget_show (vbox1);
1486         gtk_container_add (GTK_CONTAINER (dialog.notebook), vbox1);
1487         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1488
1489         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW_2);
1490         gtk_widget_show (vbox2);
1491         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1492
1493         PACK_HBOX (hbox1);
1494         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("Specify SMTP port"));
1495         PACK_PORT_ENTRY (hbox1, entry_smtpport);
1496         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, entry_smtpport);
1497
1498         PACK_HBOX (hbox_popport);
1499         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
1500                            _("Specify POP3 port"));
1501         PACK_PORT_ENTRY (hbox_popport, entry_popport);
1502         SET_TOGGLE_SENSITIVITY (checkbtn_popport, entry_popport);
1503
1504         PACK_HBOX (hbox_imapport);
1505         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
1506                            _("Specify IMAP4 port"));
1507         PACK_PORT_ENTRY (hbox_imapport, entry_imapport);
1508         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, entry_imapport);
1509
1510         PACK_HBOX (hbox_nntpport);
1511         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
1512                            _("Specify NNTP port"));
1513         PACK_PORT_ENTRY (hbox_nntpport, entry_nntpport);
1514         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, entry_nntpport);
1515
1516         PACK_HBOX (hbox1);
1517         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Specify domain name"));
1518
1519         entry_domain = gtk_entry_new ();
1520         gtk_widget_show (entry_domain);
1521         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
1522         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
1523
1524         
1525         PACK_HBOX (hbox1);
1526         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
1527                            _("Tunnel command to open connection"));
1528         entry_tunnelcmd = gtk_entry_new ();
1529         gtk_widget_show (entry_tunnelcmd);
1530         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
1531         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
1532
1533 #undef PACK_HBOX
1534 #undef PACK_PORT_ENTRY
1535
1536         advanced.smtpport_chkbtn        = checkbtn_smtpport;
1537         advanced.smtpport_entry         = entry_smtpport;
1538         advanced.popport_hbox           = hbox_popport;
1539         advanced.popport_chkbtn         = checkbtn_popport;
1540         advanced.popport_entry          = entry_popport;
1541         advanced.imapport_hbox          = hbox_imapport;
1542         advanced.imapport_chkbtn        = checkbtn_imapport;
1543         advanced.imapport_entry         = entry_imapport;
1544         advanced.nntpport_hbox          = hbox_nntpport;
1545         advanced.nntpport_chkbtn        = checkbtn_nntpport;
1546         advanced.nntpport_entry         = entry_nntpport;
1547         advanced.domain_chkbtn          = checkbtn_domain;
1548         advanced.domain_entry           = entry_domain;
1549         advanced.tunnelcmd_chkbtn       = checkbtn_tunnelcmd;
1550         advanced.tunnelcmd_entry        = entry_tunnelcmd;
1551 }
1552
1553 static gint prefs_account_deleted(GtkWidget *widget, GdkEventAny *event,
1554                                   gpointer data)
1555 {
1556         prefs_account_cancel();
1557         return TRUE;
1558 }
1559
1560 static void prefs_account_key_pressed(GtkWidget *widget, GdkEventKey *event,
1561                                       gpointer data)
1562 {
1563         if (event && event->keyval == GDK_Escape)
1564                 prefs_account_cancel();
1565 }
1566
1567 static void prefs_account_ok(void)
1568 {
1569         if (prefs_account_apply() == 0)
1570                 gtk_main_quit();
1571 }
1572
1573 static gint prefs_account_apply(void)
1574 {
1575         RecvProtocol protocol;
1576         GtkWidget *menu;
1577         GtkWidget *menuitem;
1578
1579         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(basic.protocol_optmenu));
1580         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1581         protocol = GPOINTER_TO_INT
1582                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
1583
1584         if (*gtk_entry_get_text(GTK_ENTRY(basic.addr_entry)) == '\0') {
1585                 alertpanel_error(_("Mail address is not entered."));
1586                 return -1;
1587         }
1588         if ((protocol == A_POP3 || protocol == A_APOP || (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)))) &&
1589            *gtk_entry_get_text(GTK_ENTRY(basic.smtpserv_entry)) == '\0') {
1590                 alertpanel_error(_("SMTP server is not entered."));
1591                 return -1;
1592         }
1593         if ((protocol == A_POP3 || protocol == A_APOP || protocol == A_IMAP4) &&
1594             *gtk_entry_get_text(GTK_ENTRY(basic.uid_entry)) == '\0') {
1595                 alertpanel_error(_("User ID is not entered."));
1596                 return -1;
1597         }
1598         if ((protocol == A_POP3 || protocol == A_APOP) &&
1599             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
1600                 alertpanel_error(_("POP3 server is not entered."));
1601                 return -1;
1602         }
1603         if (protocol == A_IMAP4 &&
1604             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
1605                 alertpanel_error(_("IMAP4 server is not entered."));
1606                 return -1;
1607         }
1608         if (protocol == A_NNTP &&
1609             *gtk_entry_get_text(GTK_ENTRY(basic.nntpserv_entry)) == '\0') {
1610                 alertpanel_error(_("NNTP server is not entered."));
1611                 return -1;
1612         }
1613
1614         if (protocol == A_LOCAL &&
1615             *gtk_entry_get_text(GTK_ENTRY(basic.localmbox_entry)) == '\0') {
1616                 alertpanel_error(_("local mailbox filename is not entered."));
1617                 return -1;
1618         }
1619
1620         if (protocol == A_LOCAL &&
1621             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic.mailcmd_entry)) == '\0') {
1622                 alertpanel_error(_("mail command is not entered."));
1623                 return -1;
1624         }
1625
1626         prefs_set_data_from_dialog(param);
1627         return 0;
1628 }
1629
1630 static void prefs_account_cancel(void)
1631 {
1632         cancelled = TRUE;
1633         gtk_main_quit();
1634 }
1635
1636 static void prefs_account_select_inbox_cb(void)
1637 {
1638         FolderItem *item;
1639         gchar      *path;
1640
1641         item = foldersel_folder_sel(NULL, NULL);
1642         if (item) {
1643                 path = folder_item_get_identifier(item);
1644                 gtk_entry_set_text(GTK_ENTRY(receive.inbox_entry), path);
1645                 g_free(path);
1646         }       
1647 }
1648
1649 static void prefs_account_edit_custom_header(void)
1650 {
1651         prefs_custom_header_open(&tmp_ac_prefs);
1652 }
1653
1654 #if USE_GPGME || USE_SSL
1655 static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
1656 {
1657         GtkRadioButton *radiobtn;
1658         GSList *group;
1659
1660         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
1661         group = gtk_radio_button_group (radiobtn);
1662         while (group != NULL) {
1663                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
1664                 if (gtk_toggle_button_get_active (btn)) {
1665                         *((gint *)pparam->data) = GPOINTER_TO_INT
1666                                 (gtk_object_get_user_data (GTK_OBJECT (btn)));
1667                         break;
1668                 }
1669                 group = group->next;
1670         }
1671 }
1672
1673 static void prefs_account_enum_set_radiobtn(PrefParam *pparam)
1674 {
1675         GtkRadioButton *radiobtn;
1676         GSList *group;
1677         gpointer data;
1678
1679         data = GINT_TO_POINTER (*((gint *)pparam->data));
1680         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
1681         group = gtk_radio_button_group (radiobtn);
1682         while (group != NULL) {
1683                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
1684                 gpointer data1 = gtk_object_get_user_data (GTK_OBJECT (btn));
1685                 if (data1 == data) {
1686                         gtk_toggle_button_set_active (btn, TRUE);
1687                         break;
1688                 }
1689                 group = group->next;
1690         }
1691 }
1692
1693 #endif /* USE_GPGME */
1694
1695 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
1696 {
1697         GtkWidget *menu;
1698         GtkWidget *menuitem;
1699
1700         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
1701         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1702         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
1703                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
1704 }
1705
1706 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
1707 {
1708         RecvProtocol protocol;
1709         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
1710         GtkWidget *menu;
1711         GtkWidget *menuitem;
1712
1713         protocol = *((RecvProtocol *)pparam->data);
1714
1715         switch (protocol) {
1716         case A_POP3:
1717                 gtk_option_menu_set_history(optmenu, 0);
1718                 break;
1719         case A_APOP:
1720                 gtk_option_menu_set_history(optmenu, 1);
1721                 break;
1722         case A_IMAP4:
1723                 gtk_option_menu_set_history(optmenu, 2);
1724                 break;
1725         case A_NNTP:
1726                 gtk_option_menu_set_history(optmenu, 3);
1727                 break;
1728         case A_LOCAL:
1729                 gtk_option_menu_set_history(optmenu, 4);
1730                 break;
1731                 /*
1732         case A_LOCAL_CMD:
1733                 gtk_option_menu_set_history(optmenu, 5);
1734                 break;
1735                 */
1736         default:
1737                 break;
1738         }
1739
1740         menu = gtk_option_menu_get_menu(optmenu);
1741         menuitem = gtk_menu_get_active(GTK_MENU(menu));
1742         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
1743 }
1744
1745 static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
1746 {
1747         RecvProtocol protocol;
1748         gboolean active;
1749         gint auth;
1750
1751         protocol = GPOINTER_TO_INT
1752                 (gtk_object_get_user_data(GTK_OBJECT(menuitem)));
1753
1754         switch(protocol) {
1755         case A_NNTP:
1756                 gtk_widget_show(basic.nntpserv_label);
1757                 gtk_widget_show(basic.nntpserv_entry);
1758                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1759                                            0, VSPACING_NARROW);
1760                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, TRUE);
1761                 gtk_widget_show(basic.nntpauth_chkbtn);
1762                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1763                                            1, VSPACING_NARROW);
1764                 gtk_widget_hide(basic.recvserv_label);
1765                 gtk_widget_hide(basic.recvserv_entry);
1766                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1767                                            2, 0);
1768                 gtk_widget_show(basic.smtpserv_label);
1769                 gtk_widget_show(basic.smtpserv_entry);
1770                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1771                                            4, VSPACING_NARROW);
1772                 gtk_widget_hide(basic.localmbox_label);
1773                 gtk_widget_hide(basic.localmbox_entry);
1774                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1775                                            3, 0);
1776                 gtk_widget_hide(basic.mailcmd_label);
1777                 gtk_widget_hide(basic.mailcmd_entry);
1778                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1779                                            6, 0);
1780                 gtk_widget_hide(basic.mailcmd_chkbtn);
1781                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1782                                            5, 0);
1783                 gtk_widget_show(basic.uid_label);
1784                 gtk_widget_show(basic.pass_label);
1785                 gtk_widget_show(basic.uid_entry);
1786                 gtk_widget_show(basic.pass_entry);
1787                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1788                                            7, VSPACING_NARROW);
1789
1790                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
1791                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
1792                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
1793                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
1794
1795                 /* update userid/passwd sensitive state */
1796                 prefs_account_nntpauth_toggled
1797                         (GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
1798                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
1799                 gtk_widget_set_sensitive(receive.imap_frame, FALSE);
1800 #if USE_SSL
1801                 gtk_widget_set_sensitive(ssl.receive_frame, FALSE);
1802                 gtk_widget_set_sensitive(ssl.pop_chkbtn, FALSE);
1803                 gtk_widget_set_sensitive(ssl.imap_chkbtn, FALSE);
1804                 gtk_widget_set_sensitive(ssl.send_frame, FALSE);
1805 #endif
1806                 gtk_widget_hide(advanced.popport_hbox);
1807                 gtk_widget_hide(advanced.imapport_hbox);
1808                 gtk_widget_show(advanced.nntpport_hbox);
1809                 break;
1810         case A_LOCAL:
1811                 gtk_widget_hide(basic.nntpserv_label);
1812                 gtk_widget_hide(basic.nntpserv_entry);
1813                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1814                                            0, 0);
1815                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
1816                 gtk_widget_hide(basic.nntpauth_chkbtn);
1817                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1818                                            1, 0);
1819                 gtk_widget_hide(basic.recvserv_label);
1820                 gtk_widget_hide(basic.recvserv_entry);
1821                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1822                                            2, 0);
1823                 gtk_widget_show(basic.smtpserv_label);
1824                 gtk_widget_show(basic.smtpserv_entry);
1825                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1826                                            4, VSPACING_NARROW);
1827                 gtk_widget_show(basic.localmbox_label);
1828                 gtk_widget_show(basic.localmbox_entry);
1829                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1830                                            3, VSPACING_NARROW);
1831                 gtk_widget_show(basic.mailcmd_label);
1832                 gtk_widget_show(basic.mailcmd_entry);
1833                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1834                                            6, VSPACING_NARROW);
1835                 gtk_widget_show(basic.mailcmd_chkbtn);
1836                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1837                                            5, VSPACING_NARROW);
1838                 gtk_widget_hide(basic.uid_label);
1839                 gtk_widget_hide(basic.pass_label);
1840                 gtk_widget_hide(basic.uid_entry);
1841                 gtk_widget_hide(basic.pass_entry);
1842                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1843                                            7, 0);
1844
1845                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
1846                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
1847                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
1848                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
1849                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
1850                 gtk_widget_set_sensitive(receive.imap_frame, FALSE);
1851                 prefs_account_mailcmd_toggled
1852                         (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
1853
1854 #if USE_SSL
1855                 gtk_widget_set_sensitive(ssl.receive_frame, FALSE);
1856                 gtk_widget_set_sensitive(ssl.pop_chkbtn, FALSE);
1857                 gtk_widget_set_sensitive(ssl.imap_chkbtn, FALSE);
1858                 gtk_widget_set_sensitive(ssl.send_frame, TRUE);
1859 #endif
1860                 gtk_widget_hide(advanced.popport_hbox);
1861                 gtk_widget_hide(advanced.imapport_hbox);
1862                 gtk_widget_hide(advanced.nntpport_hbox);
1863                 break;
1864         case A_IMAP4:
1865                 gtk_widget_hide(basic.nntpserv_label);
1866                 gtk_widget_hide(basic.nntpserv_entry);
1867                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1868                                            0, 0);
1869                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
1870                 gtk_widget_hide(basic.nntpauth_chkbtn);
1871                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1872                                            1, 0);
1873                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
1874                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
1875                 gtk_widget_show(basic.recvserv_label);
1876                 gtk_widget_show(basic.recvserv_entry);
1877                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1878                                            2, VSPACING_NARROW);
1879                 gtk_widget_show(basic.smtpserv_label);
1880                 gtk_widget_show(basic.smtpserv_entry);
1881                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1882                                            4, VSPACING_NARROW);
1883                 gtk_widget_hide(basic.localmbox_label);
1884                 gtk_widget_hide(basic.localmbox_entry);
1885                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1886                                            3, 0);
1887                 gtk_widget_hide(basic.mailcmd_label);
1888                 gtk_widget_hide(basic.mailcmd_entry);
1889                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1890                                            6, 0);
1891                 gtk_widget_hide(basic.mailcmd_chkbtn);
1892                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1893                                            5, 0);
1894                 gtk_widget_show(basic.uid_label);
1895                 gtk_widget_show(basic.pass_label);
1896                 gtk_widget_show(basic.uid_entry);
1897                 gtk_widget_show(basic.pass_entry);
1898                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1899                                            7, VSPACING_NARROW);
1900
1901                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
1902                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
1903                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
1904                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
1905                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
1906                 gtk_widget_set_sensitive(receive.imap_frame, TRUE);
1907                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
1908                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
1909
1910 #if USE_SSL
1911                 gtk_widget_set_sensitive(ssl.receive_frame, TRUE);
1912                 gtk_widget_set_sensitive(ssl.pop_chkbtn, FALSE);
1913                 gtk_widget_set_sensitive(ssl.imap_chkbtn, TRUE);
1914                 gtk_widget_set_sensitive(ssl.send_frame, TRUE);
1915 #endif
1916                 gtk_widget_hide(advanced.popport_hbox);
1917                 gtk_widget_show(advanced.imapport_hbox);
1918                 gtk_widget_hide(advanced.nntpport_hbox);
1919                 break;
1920         case A_POP3:
1921         default:
1922                 gtk_widget_hide(basic.nntpserv_label);
1923                 gtk_widget_hide(basic.nntpserv_entry);
1924                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1925                                            0, 0);
1926                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
1927                 gtk_widget_hide(basic.nntpauth_chkbtn);
1928                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1929                                            1, 0);
1930                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
1931                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
1932                 gtk_widget_show(basic.recvserv_label);
1933                 gtk_widget_show(basic.recvserv_entry);
1934                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1935                                            2, VSPACING_NARROW);
1936                 gtk_widget_show(basic.smtpserv_label);
1937                 gtk_widget_show(basic.smtpserv_entry);
1938                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1939                                            4, VSPACING_NARROW);
1940                 gtk_widget_hide(basic.localmbox_label);
1941                 gtk_widget_hide(basic.localmbox_entry);
1942                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1943                                            3, 0);
1944                 gtk_widget_hide(basic.mailcmd_label);
1945                 gtk_widget_hide(basic.mailcmd_entry);
1946                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1947                                            6, 0);
1948                 gtk_widget_hide(basic.mailcmd_chkbtn);
1949                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1950                                            5, 0);
1951                 gtk_widget_show(basic.uid_label);
1952                 gtk_widget_show(basic.pass_label);
1953                 gtk_widget_show(basic.uid_entry);
1954                 gtk_widget_show(basic.pass_entry);
1955                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
1956                                            7, VSPACING_NARROW);
1957
1958                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
1959                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
1960                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
1961                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
1962                 gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
1963                 gtk_widget_set_sensitive(receive.imap_frame, FALSE);
1964                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
1965                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
1966
1967 #if USE_SSL
1968                 gtk_widget_set_sensitive(ssl.receive_frame, TRUE);
1969                 gtk_widget_set_sensitive(ssl.pop_chkbtn, TRUE);
1970                 gtk_widget_set_sensitive(ssl.imap_chkbtn, FALSE);
1971                 gtk_widget_set_sensitive(ssl.send_frame, TRUE);
1972 #endif
1973                 gtk_widget_show(advanced.popport_hbox);
1974                 gtk_widget_hide(advanced.imapport_hbox);
1975                 gtk_widget_hide(advanced.nntpport_hbox);
1976                 break;
1977         }
1978
1979         gtk_widget_queue_resize(basic.serv_frame);
1980 }
1981
1982 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
1983                                            gpointer user_data)
1984 {
1985         gboolean auth;
1986
1987         if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (button)))
1988                 return;
1989         auth = gtk_toggle_button_get_active (button);
1990         gtk_widget_set_sensitive(basic.uid_label,  auth);
1991         gtk_widget_set_sensitive(basic.pass_label, auth);
1992         gtk_widget_set_sensitive(basic.uid_entry,  auth);
1993         gtk_widget_set_sensitive(basic.pass_entry, auth);
1994 }
1995
1996 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
1997                                           gpointer user_data)
1998 {
1999         gboolean use_mailcmd;
2000
2001         use_mailcmd = gtk_toggle_button_get_active (button);
2002
2003         gtk_widget_set_sensitive(basic.mailcmd_entry,  use_mailcmd);
2004         gtk_widget_set_sensitive(basic.mailcmd_label, use_mailcmd);
2005         gtk_widget_set_sensitive(basic.smtpserv_entry, !use_mailcmd);
2006         gtk_widget_set_sensitive(basic.smtpserv_label, !use_mailcmd);
2007         gtk_widget_set_sensitive(basic.uid_entry,  !use_mailcmd);
2008         gtk_widget_set_sensitive(basic.pass_entry, !use_mailcmd);
2009 }