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