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