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