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