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