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