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