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