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