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