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