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