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