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