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