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