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