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