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