2005-12-04 [paul] 1.9.100cvs60
[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 *label_maxarticle;
128         GtkWidget *spinbtn_maxarticle;
129         GtkObject *spinbtn_maxarticle_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.spinbtn_maxarticle,
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         GtkWidget *leave_time_label;
1357         GtkWidget *leave_time_entry;
1358         GtkWidget *getall_chkbtn;
1359         GtkWidget *hbox1;
1360         GtkWidget *size_limit_chkbtn;
1361         GtkWidget *size_limit_entry;
1362         GtkWidget *label;
1363         GtkWidget *filter_on_recv_chkbtn;
1364         GtkWidget *vbox3;
1365         GtkWidget *inbox_label;
1366         GtkWidget *inbox_entry;
1367         GtkWidget *inbox_btn;
1368         GtkWidget *imap_frame;
1369         GtkWidget *imapdir_label;
1370         GtkWidget *imapdir_entry;
1371         GtkWidget *local_frame;
1372         GtkWidget *local_vbox;
1373         GtkWidget *local_hbox;
1374         GtkWidget *local_inbox_label;
1375         GtkWidget *local_inbox_entry;
1376         GtkWidget *local_inbox_btn;
1377
1378         GtkWidget *optmenu;
1379         GtkWidget *optmenu_menu;
1380         GtkWidget *menuitem;
1381         GtkWidget *recvatgetall_chkbtn;
1382
1383         GtkWidget *hbox2;
1384         GtkWidget *frame2;
1385         GtkWidget *label_maxarticle;
1386         GtkWidget *spinbtn_maxarticle;
1387         GtkObject *spinbtn_maxarticle_adj;
1388
1389         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1390         gtk_widget_show (vbox1);
1391         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1392         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1393
1394         PACK_FRAME (vbox1, local_frame, _("Local"));
1395
1396         local_vbox = gtk_vbox_new (FALSE, 0);
1397         gtk_widget_show (local_vbox);
1398         gtk_container_add (GTK_CONTAINER (local_frame), local_vbox);
1399         gtk_container_set_border_width (GTK_CONTAINER (local_vbox), VBOX_BORDER);
1400
1401         local_hbox = gtk_hbox_new (FALSE, 8);
1402         gtk_widget_show (local_hbox);
1403         gtk_box_pack_start (GTK_BOX (local_vbox), local_hbox, FALSE, FALSE, 0);
1404
1405         local_inbox_label = gtk_label_new (_("Default inbox"));
1406         gtk_widget_show (local_inbox_label);
1407         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_label, FALSE, FALSE, 0);
1408
1409         local_inbox_entry = gtk_entry_new ();
1410         gtk_widget_show (local_inbox_entry);
1411         gtk_widget_set_size_request (local_inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
1412         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_entry, TRUE, TRUE, 0);
1413
1414         local_inbox_btn = gtk_button_new_with_label (_(" Select... "));
1415         gtk_widget_show (local_inbox_btn);
1416         gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_btn, FALSE, FALSE, 0);
1417         g_signal_connect (G_OBJECT (local_inbox_btn), "clicked",
1418                           G_CALLBACK (prefs_account_select_folder_cb),
1419                           local_inbox_entry);
1420
1421         PACK_FRAME (vbox1, frame1, _("POP3"));
1422
1423         vbox2 = gtk_vbox_new (FALSE, 0);
1424         gtk_widget_show (vbox2);
1425         gtk_container_add (GTK_CONTAINER (frame1), vbox2);
1426         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
1427
1428         PACK_CHECK_BUTTON (vbox2, use_apop_chkbtn,
1429                            _("Use secure authentication (APOP)"));
1430
1431         PACK_CHECK_BUTTON (vbox2, rmmail_chkbtn,
1432                            _("Remove messages on server when received"));
1433
1434         hbox1 = gtk_hbox_new (FALSE, 8);
1435         gtk_widget_show (hbox1);
1436         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1437
1438         hbox_spc = gtk_hbox_new (FALSE, 0);
1439         gtk_widget_show (hbox_spc);
1440         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1441         gtk_widget_set_size_request (hbox_spc, 12, -1);
1442
1443         leave_time_label = gtk_label_new (_("Remove after"));
1444         gtk_widget_show (leave_time_label);
1445         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1446
1447         leave_time_entry = gtk_entry_new ();
1448         gtk_widget_show (leave_time_entry);
1449         gtk_widget_set_size_request (leave_time_entry, 64, -1);
1450         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_entry, FALSE, FALSE, 0);
1451
1452         leave_time_label = gtk_label_new (_("days"));
1453         gtk_widget_show (leave_time_label);
1454         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1455
1456         SET_TOGGLE_SENSITIVITY (rmmail_chkbtn, hbox1);
1457
1458         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1459
1460         hbox1 = gtk_hbox_new (FALSE, 8);
1461         gtk_widget_show (hbox1);
1462         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1463
1464         hbox_spc = gtk_hbox_new (FALSE, 0);
1465         gtk_widget_show (hbox_spc);
1466         gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1467         gtk_widget_set_size_request (hbox_spc, 12, -1);
1468
1469         leave_time_label = gtk_label_new (_("(0 days: remove immediately)"));
1470         gtk_label_set_justify (GTK_LABEL (leave_time_label), GTK_JUSTIFY_LEFT);
1471         gtkut_widget_set_small_font_size (leave_time_label);
1472         gtk_widget_show (leave_time_label);
1473         gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1474
1475         SET_TOGGLE_SENSITIVITY (rmmail_chkbtn, hbox1);
1476
1477         PACK_CHECK_BUTTON (vbox2, getall_chkbtn,
1478                            _("Download all messages on server"));
1479
1480         hbox1 = gtk_hbox_new (FALSE, 8);
1481         gtk_widget_show (hbox1);
1482         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1483
1484         PACK_CHECK_BUTTON (hbox1, size_limit_chkbtn, _("Receive size limit"));
1485
1486         size_limit_entry = gtk_entry_new ();
1487         gtk_widget_show (size_limit_entry);
1488         gtk_widget_set_size_request (size_limit_entry, 64, -1);
1489         gtk_box_pack_start (GTK_BOX (hbox1), size_limit_entry, FALSE, FALSE, 0);
1490
1491         label = gtk_label_new (_("KB"));
1492         gtk_widget_show (label);
1493         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1494
1495         SET_TOGGLE_SENSITIVITY (size_limit_chkbtn, size_limit_entry);
1496
1497         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1498
1499         hbox1 = gtk_hbox_new (FALSE, 8);
1500         gtk_widget_show (hbox1);
1501         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1502
1503         inbox_label = gtk_label_new (_("Default inbox"));
1504         gtk_widget_show (inbox_label);
1505         gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
1506
1507         inbox_entry = gtk_entry_new ();
1508         gtk_widget_show (inbox_entry);
1509         gtk_widget_set_size_request (inbox_entry, DEFAULT_ENTRY_WIDTH, -1);
1510         gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
1511
1512         inbox_btn = gtk_button_new_with_label (_(" Select... "));
1513         gtk_widget_show (inbox_btn);
1514         gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1515         g_signal_connect (G_OBJECT (inbox_btn), "clicked",
1516                           G_CALLBACK (prefs_account_select_folder_cb),
1517                           inbox_entry);
1518
1519         PACK_VSPACER(vbox2, vbox3, VSPACING_NARROW_2);
1520
1521         hbox1 = gtk_hbox_new (FALSE, 8);
1522         gtk_widget_show (hbox1);
1523         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1524
1525         label = gtk_label_new
1526                 (_("(Unfiltered messages will be stored in this folder)"));
1527         gtk_widget_show (label);
1528         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1529         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1530         gtkut_widget_set_small_font_size (label);
1531
1532         PACK_FRAME(vbox1, frame2, _("Maximum number of articles to download"));
1533
1534         hbox2 = gtk_hbox_new (FALSE, 8);
1535         gtk_widget_show (hbox2);
1536         gtk_container_add (GTK_CONTAINER (frame2), hbox2);
1537         gtk_container_set_border_width (GTK_CONTAINER (hbox2), 8);
1538
1539         spinbtn_maxarticle_adj =
1540                 gtk_adjustment_new (300, 0, 10000, 10, 100, 100);
1541         spinbtn_maxarticle = gtk_spin_button_new
1542                 (GTK_ADJUSTMENT (spinbtn_maxarticle_adj), 10, 0);
1543         gtk_widget_show (spinbtn_maxarticle);
1544         gtk_box_pack_start (GTK_BOX (hbox2), spinbtn_maxarticle,
1545                             FALSE, FALSE, 0);
1546         gtk_widget_set_size_request (spinbtn_maxarticle, 64, -1);
1547         gtk_spin_button_set_numeric
1548                 (GTK_SPIN_BUTTON (spinbtn_maxarticle), TRUE);
1549
1550         label_maxarticle = gtk_label_new
1551                 (_("unlimited if 0 is specified"));
1552         gtk_widget_show (label_maxarticle);
1553         gtk_box_pack_start (GTK_BOX (hbox2), label_maxarticle, FALSE, FALSE, 0);
1554         gtk_label_set_justify (GTK_LABEL (label_maxarticle), GTK_JUSTIFY_LEFT);
1555
1556         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
1557
1558         vbox2 = gtk_vbox_new (FALSE, 0);
1559         gtk_widget_show (vbox2);
1560         gtk_container_add (GTK_CONTAINER (imap_frame), vbox2);
1561         gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
1562
1563         hbox1 = gtk_hbox_new (FALSE, 8);
1564         gtk_widget_show (hbox1);
1565         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1566
1567         label = gtk_label_new (_("Authentication method"));
1568         gtk_widget_show (label);
1569         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1570
1571         optmenu = gtk_option_menu_new ();
1572         gtk_widget_show (optmenu);
1573         gtk_box_pack_start (GTK_BOX (hbox1), optmenu, FALSE, FALSE, 0);
1574
1575         optmenu_menu = gtk_menu_new ();
1576
1577         MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
1578         MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", IMAP_AUTH_LOGIN);
1579         MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", IMAP_AUTH_CRAM_MD5);
1580
1581         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1582
1583         hbox1 = gtk_hbox_new (FALSE, 8);
1584         gtk_widget_show (hbox1);
1585         gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1586
1587         imapdir_label = gtk_label_new (_("IMAP server directory (usually empty)"));
1588         gtk_widget_show (imapdir_label);
1589         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1590
1591         imapdir_entry = gtk_entry_new();
1592         gtk_widget_show (imapdir_entry);
1593         gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, FALSE, FALSE, 0);
1594
1595         PACK_CHECK_BUTTON (vbox1, filter_on_recv_chkbtn,
1596                            _("Filter messages on receiving"));
1597
1598         PACK_CHECK_BUTTON
1599                 (vbox1, recvatgetall_chkbtn,
1600                  _("'Get all' checks for new messages on this account"));
1601
1602         receive.pop3_frame               = frame1;
1603         receive.use_apop_chkbtn          = use_apop_chkbtn;
1604         receive.rmmail_chkbtn            = rmmail_chkbtn;
1605         receive.leave_time_entry         = leave_time_entry;
1606         receive.getall_chkbtn            = getall_chkbtn;
1607         receive.size_limit_chkbtn        = size_limit_chkbtn;
1608         receive.size_limit_entry         = size_limit_entry;
1609         receive.filter_on_recv_chkbtn    = filter_on_recv_chkbtn;
1610         receive.inbox_label              = inbox_label;
1611         receive.inbox_entry              = inbox_entry;
1612         receive.inbox_btn                = inbox_btn;
1613
1614         receive.imap_frame               = imap_frame;
1615         receive.imap_auth_type_optmenu   = optmenu;
1616
1617         receive.imapdir_label           = imapdir_label;
1618         receive.imapdir_entry           = imapdir_entry;
1619
1620         receive.local_frame             = local_frame;
1621         receive.local_inbox_label       = local_inbox_label;
1622         receive.local_inbox_entry       = local_inbox_entry;
1623         receive.local_inbox_btn         = local_inbox_btn;
1624
1625         receive.recvatgetall_chkbtn      = recvatgetall_chkbtn;
1626
1627         receive.frame_maxarticle        = frame2;
1628         receive.spinbtn_maxarticle      = spinbtn_maxarticle;
1629         receive.spinbtn_maxarticle_adj  = spinbtn_maxarticle_adj;
1630 }
1631
1632 static void prefs_account_send_create(void)
1633 {
1634         GtkWidget *vbox1;
1635         GtkWidget *vbox2;
1636         GtkWidget *frame;
1637         GtkWidget *date_chkbtn;
1638         GtkWidget *msgid_chkbtn;
1639         GtkWidget *hbox;
1640         GtkWidget *customhdr_chkbtn;
1641         GtkWidget *customhdr_edit_btn;
1642         GtkWidget *vbox3;
1643         GtkWidget *smtp_auth_chkbtn;
1644         GtkWidget *optmenu;
1645         GtkWidget *optmenu_menu;
1646         GtkWidget *menuitem;
1647         GtkWidget *vbox4;
1648         GtkWidget *hbox_spc;
1649         GtkWidget *label;
1650         GtkWidget *smtp_uid_entry;
1651         GtkWidget *smtp_pass_entry;
1652         GtkWidget *vbox_spc;
1653         GtkWidget *pop_bfr_smtp_chkbtn;
1654         GtkWidget *pop_bfr_smtp_tm_entry;
1655
1656         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1657         gtk_widget_show (vbox1);
1658         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1659         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1660
1661         PACK_FRAME (vbox1, frame, _("Header"));
1662
1663         vbox2 = gtk_vbox_new (FALSE, 0);
1664         gtk_widget_show (vbox2);
1665         gtk_container_add (GTK_CONTAINER (frame), vbox2);
1666         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
1667
1668         PACK_CHECK_BUTTON (vbox2, date_chkbtn, _("Add Date"));
1669         PACK_CHECK_BUTTON (vbox2, msgid_chkbtn, _("Generate Message-ID"));
1670
1671         hbox = gtk_hbox_new (FALSE, 12);
1672         gtk_widget_show (hbox);
1673         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1674
1675         PACK_CHECK_BUTTON (hbox, customhdr_chkbtn,
1676                            _("Add user-defined header"));
1677
1678         customhdr_edit_btn = gtk_button_new_with_label (_(" Edit... "));
1679         gtk_widget_show (customhdr_edit_btn);
1680         gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
1681                             FALSE, FALSE, 0);
1682         g_signal_connect (G_OBJECT (customhdr_edit_btn), "clicked",
1683                           G_CALLBACK (prefs_account_edit_custom_header),
1684                           NULL);
1685
1686         SET_TOGGLE_SENSITIVITY (customhdr_chkbtn, customhdr_edit_btn);
1687
1688         PACK_FRAME (vbox1, frame, _("Authentication"));
1689
1690         vbox3 = gtk_vbox_new (FALSE, 0);
1691         gtk_widget_show (vbox3);
1692         gtk_container_add (GTK_CONTAINER (frame), vbox3);
1693         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
1694
1695         PACK_CHECK_BUTTON (vbox3, smtp_auth_chkbtn,
1696                 _("SMTP Authentication (SMTP AUTH)"));
1697
1698         vbox4 = gtk_vbox_new (FALSE, 0);
1699         gtk_widget_show (vbox4);
1700         gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
1701
1702         hbox = gtk_hbox_new (FALSE, 8);
1703         gtk_widget_show (hbox);
1704         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1705
1706         hbox_spc = gtk_hbox_new (FALSE, 0);
1707         gtk_widget_show (hbox_spc);
1708         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1709         gtk_widget_set_size_request (hbox_spc, 12, -1);
1710
1711         label = gtk_label_new (_("Authentication method"));
1712         gtk_widget_show (label);
1713         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1714
1715         optmenu = gtk_option_menu_new ();
1716         gtk_widget_show (optmenu);
1717         gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
1718
1719         optmenu_menu = gtk_menu_new ();
1720
1721         MENUITEM_ADD (optmenu_menu, menuitem, _("Automatic"), 0);
1722         MENUITEM_ADD (optmenu_menu, menuitem, "PLAIN", SMTPAUTH_PLAIN);
1723         MENUITEM_ADD (optmenu_menu, menuitem, "LOGIN", SMTPAUTH_LOGIN);
1724         MENUITEM_ADD (optmenu_menu, menuitem, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
1725         MENUITEM_ADD (optmenu_menu, menuitem, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
1726         gtk_widget_set_sensitive (menuitem, FALSE);
1727
1728         gtk_option_menu_set_menu (GTK_OPTION_MENU (optmenu), optmenu_menu);
1729
1730         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1731
1732         hbox = gtk_hbox_new (FALSE, 8);
1733         gtk_widget_show (hbox);
1734         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1735
1736         hbox_spc = gtk_hbox_new (FALSE, 0);
1737         gtk_widget_show (hbox_spc);
1738         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1739         gtk_widget_set_size_request (hbox_spc, 12, -1);
1740
1741         label = gtk_label_new (_("User ID"));
1742         gtk_widget_show (label);
1743         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1744
1745         smtp_uid_entry = gtk_entry_new ();
1746         gtk_widget_show (smtp_uid_entry);
1747         gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1748         gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
1749
1750         label = gtk_label_new (_("Password"));
1751         gtk_widget_show (label);
1752         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1753
1754         smtp_pass_entry = gtk_entry_new ();
1755         gtk_widget_show (smtp_pass_entry);
1756         gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1757         gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
1758         gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
1759
1760         PACK_VSPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
1761
1762         hbox = gtk_hbox_new (FALSE, 8);
1763         gtk_widget_show (hbox);
1764         gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
1765
1766         hbox_spc = gtk_hbox_new (FALSE, 0);
1767         gtk_widget_show (hbox_spc);
1768         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1769         gtk_widget_set_size_request (hbox_spc, 12, -1);
1770
1771         label = gtk_label_new
1772                 (_("If you leave these entries empty, the same "
1773                    "user ID and password as receiving will be used."));
1774         gtk_widget_show (label);
1775         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1776         gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
1777         gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
1778         gtkut_widget_set_small_font_size (label);
1779
1780         SET_TOGGLE_SENSITIVITY (smtp_auth_chkbtn, vbox4);
1781
1782         PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_chkbtn,
1783                 _("Authenticate with POP3 before sending"));
1784         
1785         g_signal_connect (G_OBJECT (pop_bfr_smtp_chkbtn), "clicked",
1786                           G_CALLBACK (pop_bfr_smtp_tm_set_sens),
1787                           NULL);
1788
1789         hbox = gtk_hbox_new (FALSE, 8);
1790         gtk_widget_show (hbox);
1791         gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
1792
1793         hbox_spc = gtk_hbox_new (FALSE, 0);
1794         gtk_widget_show (hbox_spc);
1795         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
1796         gtk_widget_set_size_request (hbox_spc, 12, -1);
1797
1798         label = gtk_label_new(_("POP authentication timeout: "));
1799         gtk_widget_show (label);
1800         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1801
1802         pop_bfr_smtp_tm_entry = gtk_entry_new ();
1803         gtk_widget_show (pop_bfr_smtp_tm_entry);
1804         gtk_widget_set_size_request (pop_bfr_smtp_tm_entry, 30, -1);
1805         gtk_box_pack_start (GTK_BOX (hbox), pop_bfr_smtp_tm_entry, FALSE, FALSE, 0);
1806
1807         label = gtk_label_new(_("minutes"));
1808         gtk_widget_show (label);
1809         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1810
1811
1812         
1813         p_send.date_chkbtn      = date_chkbtn;
1814         p_send.msgid_chkbtn     = msgid_chkbtn;
1815         p_send.customhdr_chkbtn = customhdr_chkbtn;
1816
1817         p_send.smtp_auth_chkbtn       = smtp_auth_chkbtn;
1818         p_send.smtp_auth_type_optmenu = optmenu;
1819         p_send.smtp_uid_entry         = smtp_uid_entry;
1820         p_send.smtp_pass_entry        = smtp_pass_entry;
1821         p_send.pop_bfr_smtp_chkbtn    = pop_bfr_smtp_chkbtn;
1822         p_send.pop_bfr_smtp_tm_entry  = pop_bfr_smtp_tm_entry;
1823 }
1824
1825 static void prefs_account_compose_create(void)
1826 {
1827         GtkWidget *vbox1;
1828         GtkWidget *sig_hbox;
1829         GtkWidget *hbox1;
1830         GtkWidget *hbox2;
1831         GtkWidget *frame_sig;
1832         GtkWidget *vbox_sig;
1833         GtkWidget *label_sigpath;
1834         GtkWidget *checkbtn_autosig;
1835         GtkWidget *label_sigsep;
1836         GtkWidget *entry_sigsep;
1837         GtkWidget *frame;
1838         GtkWidget *table;
1839         GtkWidget *autocc_chkbtn;
1840         GtkWidget *autocc_entry;
1841         GtkWidget *autobcc_chkbtn;
1842         GtkWidget *autobcc_entry;
1843         GtkWidget *autoreplyto_chkbtn;
1844         GtkWidget *autoreplyto_entry;
1845
1846         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1847         gtk_widget_show (vbox1);
1848         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1849         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1850
1851         PACK_FRAME(vbox1, frame_sig, _("Signature"));
1852
1853         vbox_sig = gtk_vbox_new (FALSE, VSPACING_NARROW);
1854         gtk_widget_show (vbox_sig);
1855         gtk_container_add (GTK_CONTAINER (frame_sig), vbox_sig);
1856         gtk_container_set_border_width (GTK_CONTAINER (vbox_sig), 8);
1857
1858         PACK_CHECK_BUTTON (vbox_sig, checkbtn_autosig,
1859                            _("Insert signature automatically"));
1860
1861         hbox1 = gtk_hbox_new (FALSE, 8);
1862         gtk_widget_show (hbox1);
1863         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox1, TRUE, TRUE, 0);
1864         label_sigsep = gtk_label_new (_("Signature separator"));
1865         gtk_widget_show (label_sigsep);
1866         gtk_box_pack_start (GTK_BOX (hbox1), label_sigsep, FALSE, FALSE, 0);
1867
1868         entry_sigsep = gtk_entry_new ();
1869         gtk_widget_show (entry_sigsep);
1870         gtk_box_pack_start (GTK_BOX (hbox1), entry_sigsep, FALSE, FALSE, 0);
1871
1872         gtk_widget_set_size_request (entry_sigsep, 64, -1);
1873
1874         sig_hbox = gtk_hbox_new (FALSE, 8);
1875         gtk_widget_show (sig_hbox);
1876         gtk_box_pack_start (GTK_BOX (vbox_sig), sig_hbox, FALSE, FALSE, 0);
1877
1878         sigfile_radiobtn = gtk_radio_button_new_with_label (NULL, _("File"));
1879         gtk_widget_show (sigfile_radiobtn);
1880         gtk_box_pack_start (GTK_BOX (sig_hbox), sigfile_radiobtn,
1881                             FALSE, FALSE, 0);
1882         g_object_set_data (G_OBJECT (sigfile_radiobtn),
1883                            MENU_VAL_ID,
1884                            GINT_TO_POINTER (SIG_FILE));
1885         g_signal_connect(G_OBJECT(sigfile_radiobtn), "clicked",
1886                          G_CALLBACK(prefs_account_sigfile_radiobtn_cb), NULL);
1887
1888         sigcmd_radiobtn = gtk_radio_button_new_with_label_from_widget
1889                 (GTK_RADIO_BUTTON(sigfile_radiobtn), _("Command output"));
1890         gtk_widget_show (sigcmd_radiobtn);
1891         gtk_box_pack_start (GTK_BOX (sig_hbox), sigcmd_radiobtn,
1892                             FALSE, FALSE, 0);
1893         g_object_set_data (G_OBJECT (sigcmd_radiobtn),
1894                            MENU_VAL_ID,
1895                            GINT_TO_POINTER (SIG_COMMAND));
1896         g_signal_connect(G_OBJECT(sigcmd_radiobtn), "clicked",
1897                          G_CALLBACK(prefs_account_sigcmd_radiobtn_cb), NULL);
1898
1899         hbox2 = gtk_hbox_new (FALSE, 8);
1900         gtk_widget_show (hbox2);
1901         gtk_box_pack_start (GTK_BOX (vbox_sig), hbox2, TRUE, TRUE, 0);
1902         label_sigpath = gtk_label_new (_("Signature"));
1903         gtk_widget_show (label_sigpath);
1904         gtk_box_pack_start (GTK_BOX (hbox2), label_sigpath, FALSE, FALSE, 0);
1905
1906         entry_sigpath = gtk_entry_new ();
1907         gtk_widget_show (entry_sigpath);
1908         gtk_box_pack_start (GTK_BOX (hbox2), entry_sigpath, TRUE, TRUE, 0);
1909
1910         signature_browse_button = gtkut_get_browse_file_btn(_("_Browse"));
1911         gtk_widget_show (signature_browse_button);
1912         gtk_box_pack_start (GTK_BOX (hbox2), signature_browse_button, FALSE, FALSE, 0);
1913         g_signal_connect(G_OBJECT(signature_browse_button), "clicked",
1914                          G_CALLBACK(prefs_account_signature_browse_cb), NULL);
1915
1916         PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
1917
1918         table =  gtk_table_new (3, 2, FALSE);
1919         gtk_widget_show (table);
1920         gtk_container_add (GTK_CONTAINER (frame), table);
1921         gtk_container_set_border_width (GTK_CONTAINER (table), 8);
1922         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
1923         gtk_table_set_col_spacings (GTK_TABLE (table), 8);
1924
1925         autocc_chkbtn = gtk_check_button_new_with_label (_("Cc"));
1926         gtk_widget_show (autocc_chkbtn);
1927         gtk_table_attach (GTK_TABLE (table), autocc_chkbtn, 0, 1, 0, 1,
1928                           GTK_FILL, 0, 0, 0);
1929
1930         autocc_entry = gtk_entry_new ();
1931         gtk_widget_show (autocc_entry);
1932         gtk_table_attach (GTK_TABLE (table), autocc_entry, 1, 2, 0, 1,
1933                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1934                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1935
1936         SET_TOGGLE_SENSITIVITY (autocc_chkbtn, autocc_entry);
1937
1938         autobcc_chkbtn = gtk_check_button_new_with_label (_("Bcc"));
1939         gtk_widget_show (autobcc_chkbtn);
1940         gtk_table_attach (GTK_TABLE (table), autobcc_chkbtn, 0, 1, 1, 2,
1941                           GTK_FILL, 0, 0, 0);
1942
1943         autobcc_entry = gtk_entry_new ();
1944         gtk_widget_show (autobcc_entry);
1945         gtk_table_attach (GTK_TABLE (table), autobcc_entry, 1, 2, 1, 2,
1946                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1947                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1948
1949         SET_TOGGLE_SENSITIVITY (autobcc_chkbtn, autobcc_entry);
1950
1951         autoreplyto_chkbtn = gtk_check_button_new_with_label (_("Reply-To"));
1952         gtk_widget_show (autoreplyto_chkbtn);
1953         gtk_table_attach (GTK_TABLE (table), autoreplyto_chkbtn, 0, 1, 2, 3,
1954                           GTK_FILL, 0, 0, 0);
1955
1956         autoreplyto_entry = gtk_entry_new ();
1957         gtk_widget_show (autoreplyto_entry);
1958         gtk_table_attach (GTK_TABLE (table), autoreplyto_entry, 1, 2, 2, 3,
1959                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,
1960                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);
1961
1962         SET_TOGGLE_SENSITIVITY (autoreplyto_chkbtn, autoreplyto_entry);
1963
1964         compose.sigfile_radiobtn = sigfile_radiobtn;
1965         compose.entry_sigpath      = entry_sigpath;
1966         compose.checkbtn_autosig   = checkbtn_autosig;
1967         compose.entry_sigsep       = entry_sigsep;
1968
1969         compose.autocc_chkbtn      = autocc_chkbtn;
1970         compose.autocc_entry       = autocc_entry;
1971         compose.autobcc_chkbtn     = autobcc_chkbtn;
1972         compose.autobcc_entry      = autobcc_entry;
1973         compose.autoreplyto_chkbtn = autoreplyto_chkbtn;
1974         compose.autoreplyto_entry  = autoreplyto_entry;
1975 }
1976
1977 static void prefs_account_privacy_create(void)
1978 {
1979         GtkWidget *vbox1;
1980         GtkWidget *vbox2;
1981         GtkWidget *hbox1;
1982         GtkWidget *label;
1983         GtkWidget *default_privacy_system;
1984         GtkWidget *default_encrypt_chkbtn;
1985         GtkWidget *default_encrypt_reply_chkbtn;
1986         GtkWidget *default_sign_chkbtn;
1987         GtkWidget *save_clear_text_chkbtn;
1988
1989         vbox1 = gtk_vbox_new (FALSE, VSPACING);
1990         gtk_widget_show (vbox1);
1991         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
1992         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1993
1994         vbox2 = gtk_vbox_new (FALSE, 0);
1995         gtk_widget_show (vbox2);
1996         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
1997
1998         hbox1 = gtk_hbox_new(FALSE, 8);
1999         gtk_widget_show (hbox1);
2000         gtk_container_add (GTK_CONTAINER(vbox2), hbox1);
2001
2002         label = gtk_label_new(_("Default privacy system"));
2003         gtk_widget_show(label);
2004         gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
2005
2006         default_privacy_system = gtk_option_menu_new();
2007         gtk_widget_show (default_privacy_system);
2008         gtk_box_pack_start (GTK_BOX(hbox1), default_privacy_system, FALSE, TRUE, 0);
2009
2010         PACK_CHECK_BUTTON (vbox2, default_encrypt_chkbtn,
2011                            _("Encrypt message by default"));
2012         PACK_CHECK_BUTTON (vbox2, default_encrypt_reply_chkbtn,
2013                            _("Encrypt message by default when replying to an "
2014                              "encrypted message"));
2015         PACK_CHECK_BUTTON (vbox2, default_sign_chkbtn,
2016                            _("Sign message by default"));
2017         PACK_CHECK_BUTTON (vbox2, save_clear_text_chkbtn,
2018                            _("Save sent encrypted messages as clear text"));
2019
2020         privacy.default_privacy_system = default_privacy_system;
2021         privacy.default_encrypt_chkbtn = default_encrypt_chkbtn;
2022         privacy.default_encrypt_reply_chkbtn = default_encrypt_reply_chkbtn;
2023         privacy.default_sign_chkbtn    = default_sign_chkbtn;
2024         privacy.save_clear_text_chkbtn = save_clear_text_chkbtn;
2025 }
2026
2027 #if USE_OPENSSL
2028
2029 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data)               \
2030 {                                                                       \
2031         btn = gtk_radio_button_new_with_label_from_widget               \
2032                 (GTK_RADIO_BUTTON (btn_p), label);                      \
2033         gtk_widget_show (btn);                                          \
2034         gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0);       \
2035         g_object_set_data (G_OBJECT (btn),                              \
2036                            MENU_VAL_ID,                                 \
2037                            GINT_TO_POINTER (data));                     \
2038 }
2039
2040 #define CREATE_RADIO_BUTTONS(box,                                       \
2041                              btn1, btn1_label, btn1_data,               \
2042                              btn2, btn2_label, btn2_data,               \
2043                              btn3, btn3_label, btn3_data)               \
2044 {                                                                       \
2045         btn1 = gtk_radio_button_new_with_label(NULL, btn1_label);       \
2046         gtk_widget_show (btn1);                                         \
2047         gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0);      \
2048         g_object_set_data (G_OBJECT (btn1),                             \
2049                            MENU_VAL_ID,                                 \
2050                            GINT_TO_POINTER (btn1_data));                \
2051                                                                         \
2052         CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data);    \
2053         CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data);    \
2054 }
2055
2056 static void prefs_account_ssl_create(void)
2057 {
2058         GtkWidget *vbox1;
2059
2060         GtkWidget *pop_frame;
2061         GtkWidget *vbox2;
2062         GtkWidget *pop_nossl_radiobtn;
2063         GtkWidget *pop_ssltunnel_radiobtn;
2064         GtkWidget *pop_starttls_radiobtn;
2065
2066         GtkWidget *imap_frame;
2067         GtkWidget *vbox3;
2068         GtkWidget *imap_nossl_radiobtn;
2069         GtkWidget *imap_ssltunnel_radiobtn;
2070         GtkWidget *imap_starttls_radiobtn;
2071
2072         GtkWidget *nntp_frame;
2073         GtkWidget *vbox4;
2074         GtkWidget *nntp_nossl_radiobtn;
2075         GtkWidget *nntp_ssltunnel_radiobtn;
2076
2077         GtkWidget *send_frame;
2078         GtkWidget *vbox5;
2079         GtkWidget *smtp_nossl_radiobtn;
2080         GtkWidget *smtp_ssltunnel_radiobtn;
2081         GtkWidget *smtp_starttls_radiobtn;
2082
2083         GtkWidget *vbox6;
2084         GtkWidget *use_nonblocking_ssl_chkbtn;
2085         GtkWidget *hbox;
2086         GtkWidget *hbox_spc;
2087         GtkWidget *label;
2088
2089         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2090         gtk_widget_show (vbox1);
2091         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
2092         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2093
2094         PACK_FRAME (vbox1, pop_frame, _("POP3"));
2095         vbox2 = gtk_vbox_new (FALSE, 0);
2096         gtk_widget_show (vbox2);
2097         gtk_container_add (GTK_CONTAINER (pop_frame), vbox2);
2098         gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
2099
2100         CREATE_RADIO_BUTTONS(vbox2,
2101                              pop_nossl_radiobtn,
2102                              _("Don't use SSL"),
2103                              SSL_NONE,
2104                              pop_ssltunnel_radiobtn,
2105                              _("Use SSL for POP3 connection"),
2106                              SSL_TUNNEL,
2107                              pop_starttls_radiobtn,
2108                              _("Use STARTTLS command to start SSL session"),
2109                              SSL_STARTTLS);
2110
2111         PACK_FRAME (vbox1, imap_frame, _("IMAP4"));
2112         vbox3 = gtk_vbox_new (FALSE, 0);
2113         gtk_widget_show (vbox3);
2114         gtk_container_add (GTK_CONTAINER (imap_frame), vbox3);
2115         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
2116
2117         CREATE_RADIO_BUTTONS(vbox3,
2118                              imap_nossl_radiobtn,
2119                              _("Don't use SSL"),
2120                              SSL_NONE,
2121                              imap_ssltunnel_radiobtn,
2122                              _("Use SSL for IMAP4 connection"),
2123                              SSL_TUNNEL,
2124                              imap_starttls_radiobtn,
2125                              _("Use STARTTLS command to start SSL session"),
2126                              SSL_STARTTLS);
2127
2128         PACK_FRAME (vbox1, nntp_frame, _("NNTP"));
2129         vbox4 = gtk_vbox_new (FALSE, 0);
2130         gtk_widget_show (vbox4);
2131         gtk_container_add (GTK_CONTAINER (nntp_frame), vbox4);
2132         gtk_container_set_border_width (GTK_CONTAINER (vbox4), 8);
2133
2134         nntp_nossl_radiobtn =
2135                 gtk_radio_button_new_with_label (NULL, _("Don't use SSL"));
2136         gtk_widget_show (nntp_nossl_radiobtn);
2137         gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
2138                             FALSE, FALSE, 0);
2139         g_object_set_data (G_OBJECT (nntp_nossl_radiobtn),
2140                            MENU_VAL_ID,
2141                            GINT_TO_POINTER (SSL_NONE));
2142
2143         CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
2144                             _("Use SSL for NNTP connection"), SSL_TUNNEL);
2145
2146         PACK_FRAME (vbox1, send_frame, _("Send (SMTP)"));
2147         vbox5 = gtk_vbox_new (FALSE, 0);
2148         gtk_widget_show (vbox5);
2149         gtk_container_add (GTK_CONTAINER (send_frame), vbox5);
2150         gtk_container_set_border_width (GTK_CONTAINER (vbox5), 8);
2151
2152         CREATE_RADIO_BUTTONS(vbox5,
2153                              smtp_nossl_radiobtn,
2154                              _("Don't use SSL (but, if necessary, use STARTTLS)"),
2155                              SSL_NONE,
2156                              smtp_ssltunnel_radiobtn,
2157                              _("Use SSL for SMTP connection"),
2158                              SSL_TUNNEL,
2159                              smtp_starttls_radiobtn,
2160                              _("Use STARTTLS command to start SSL session"),
2161                              SSL_STARTTLS);
2162
2163         vbox6 = gtk_vbox_new (FALSE, 0);
2164         gtk_widget_show (vbox6);
2165         gtk_box_pack_start (GTK_BOX (vbox1), vbox6, FALSE, FALSE, 0);
2166
2167         PACK_CHECK_BUTTON(vbox6, use_nonblocking_ssl_chkbtn,
2168                           _("Use non-blocking SSL"));
2169
2170         hbox = gtk_hbox_new (FALSE, 0);
2171         gtk_widget_show (hbox);
2172         gtk_box_pack_start (GTK_BOX (vbox6), hbox, FALSE, FALSE, 0);
2173
2174         hbox_spc = gtk_hbox_new (FALSE, 0);
2175         gtk_widget_show (hbox_spc);
2176         gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2177         gtk_widget_set_size_request (hbox_spc, 16, -1);
2178
2179         label = gtk_label_new
2180                 (_("(Turn this off if you have SSL connection problems)"));
2181         gtk_widget_show (label);
2182         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2183         gtkut_widget_set_small_font_size (label);
2184
2185         ssl.pop_frame               = pop_frame;
2186         ssl.pop_nossl_radiobtn      = pop_nossl_radiobtn;
2187         ssl.pop_ssltunnel_radiobtn  = pop_ssltunnel_radiobtn;
2188         ssl.pop_starttls_radiobtn   = pop_starttls_radiobtn;
2189
2190         ssl.imap_frame              = imap_frame;
2191         ssl.imap_nossl_radiobtn     = imap_nossl_radiobtn;
2192         ssl.imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
2193         ssl.imap_starttls_radiobtn  = imap_starttls_radiobtn;
2194
2195         ssl.nntp_frame              = nntp_frame;
2196         ssl.nntp_nossl_radiobtn     = nntp_nossl_radiobtn;
2197         ssl.nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
2198
2199         ssl.send_frame              = send_frame;
2200         ssl.smtp_nossl_radiobtn     = smtp_nossl_radiobtn;
2201         ssl.smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
2202         ssl.smtp_starttls_radiobtn  = smtp_starttls_radiobtn;
2203
2204         ssl.use_nonblocking_ssl_chkbtn = use_nonblocking_ssl_chkbtn;
2205 }
2206
2207 #undef CREATE_RADIO_BUTTONS
2208 #undef CREATE_RADIO_BUTTON
2209 #endif /* USE_OPENSSL */
2210
2211 static void crosspost_color_toggled(void)
2212 {
2213         gboolean is_active;
2214
2215         is_active = gtk_toggle_button_get_active
2216                 (GTK_TOGGLE_BUTTON(advanced.crosspost_chkbtn));
2217         gtk_widget_set_sensitive(advanced.crosspost_colormenu, is_active);
2218 }
2219
2220 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam)
2221 {
2222         GtkWidget *menu;
2223         GtkWidget *menuitem;
2224
2225         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(advanced.crosspost_colormenu));
2226         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2227         *((gint *)pparam->data) = GPOINTER_TO_INT
2228                 (g_object_get_data(G_OBJECT(menuitem), "color"));
2229 }
2230
2231 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam)
2232 {
2233         gint colorlabel = *((gint *)pparam->data);
2234         GtkOptionMenu *colormenu = GTK_OPTION_MENU(*pparam->widget);
2235         GtkWidget *menu;
2236         GtkWidget *menuitem;
2237
2238         gtk_option_menu_set_history(colormenu, colorlabel);
2239         menu = gtk_option_menu_get_menu(colormenu);
2240         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2241         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2242 }
2243
2244
2245 static void prefs_account_advanced_create(void)
2246 {
2247         GtkWidget *vbox1;
2248         GtkWidget *vbox2;
2249         GtkWidget *hbox1;
2250         GtkWidget *checkbtn_smtpport;
2251         GtkWidget *entry_smtpport;
2252         GtkWidget *hbox_popport;
2253         GtkWidget *checkbtn_popport;
2254         GtkWidget *entry_popport;
2255         GtkWidget *hbox_imapport;
2256         GtkWidget *checkbtn_imapport;
2257         GtkWidget *entry_imapport;
2258         GtkWidget *hbox_nntpport;
2259         GtkWidget *checkbtn_nntpport;
2260         GtkWidget *entry_nntpport;
2261         GtkWidget *checkbtn_domain;
2262         GtkWidget *entry_domain;
2263         GtkWidget *checkbtn_crosspost;
2264         GtkWidget *colormenu_crosspost;
2265         GtkWidget *menu;
2266         GtkWidget *checkbtn_tunnelcmd;
2267         GtkWidget *entry_tunnelcmd;
2268         GtkWidget *folder_frame;
2269         GtkWidget *vbox3;
2270         GtkWidget *table;
2271         GtkWidget *sent_folder_chkbtn;
2272         GtkWidget *sent_folder_entry;
2273         GtkWidget *queue_folder_chkbtn;
2274         GtkWidget *queue_folder_entry;
2275         GtkWidget *draft_folder_chkbtn;
2276         GtkWidget *draft_folder_entry;
2277         GtkWidget *trash_folder_chkbtn;
2278         GtkWidget *trash_folder_entry;
2279
2280 #define PACK_HBOX(hbox) \
2281         { \
2282         hbox = gtk_hbox_new (FALSE, 8); \
2283         gtk_widget_show (hbox); \
2284         gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
2285         }
2286
2287 #define PACK_PORT_ENTRY(box, entry) \
2288         { \
2289         entry = gtk_entry_new (); \
2290         gtk_entry_set_max_length  (GTK_ENTRY(entry), 5); \
2291         gtk_widget_show (entry); \
2292         gtk_box_pack_start (GTK_BOX (box), entry, FALSE, FALSE, 0); \
2293         gtk_widget_set_size_request (entry, 64, -1); \
2294         }
2295
2296         vbox1 = gtk_vbox_new (FALSE, VSPACING);
2297         gtk_widget_show (vbox1);
2298         gtk_container_add (GTK_CONTAINER (notebook), vbox1);
2299         gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2300
2301         vbox2 = gtk_vbox_new (FALSE, VSPACING_NARROW_2);
2302         gtk_widget_show (vbox2);
2303         gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2304
2305         PACK_HBOX (hbox1);
2306         PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("Specify SMTP port"));
2307         PACK_PORT_ENTRY (hbox1, entry_smtpport);
2308         SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, entry_smtpport);
2309
2310         PACK_HBOX (hbox_popport);
2311         PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
2312                            _("Specify POP3 port"));
2313         PACK_PORT_ENTRY (hbox_popport, entry_popport);
2314         SET_TOGGLE_SENSITIVITY (checkbtn_popport, entry_popport);
2315
2316         PACK_HBOX (hbox_imapport);
2317         PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
2318                            _("Specify IMAP4 port"));
2319         PACK_PORT_ENTRY (hbox_imapport, entry_imapport);
2320         SET_TOGGLE_SENSITIVITY (checkbtn_imapport, entry_imapport);
2321
2322         PACK_HBOX (hbox_nntpport);
2323         PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
2324                            _("Specify NNTP port"));
2325         PACK_PORT_ENTRY (hbox_nntpport, entry_nntpport);
2326         SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, entry_nntpport);
2327
2328         PACK_HBOX (hbox1);
2329         PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Specify domain name"));
2330
2331         entry_domain = gtk_entry_new ();
2332         gtk_widget_show (entry_domain);
2333         gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
2334         SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
2335
2336         
2337         PACK_HBOX (hbox1);
2338         PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
2339                            _("Use command to communicate with server"));
2340         entry_tunnelcmd = gtk_entry_new ();
2341         gtk_widget_show (entry_tunnelcmd);
2342         gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
2343         SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
2344
2345         PACK_HBOX (hbox1);
2346         PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost, 
2347                            _("Mark cross-posted messages as read and color:"));
2348         g_signal_connect (G_OBJECT (checkbtn_crosspost), "toggled",
2349                           G_CALLBACK (crosspost_color_toggled),
2350                           NULL);
2351
2352         colormenu_crosspost = gtk_option_menu_new();
2353         gtk_widget_show (colormenu_crosspost);
2354         gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
2355
2356         menu = colorlabel_create_color_menu();
2357         gtk_option_menu_set_menu (GTK_OPTION_MENU(colormenu_crosspost), menu);
2358         SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
2359
2360         PACK_HBOX (hbox1);
2361 #undef PACK_HBOX
2362 #undef PACK_PORT_ENTRY
2363
2364         /* special folder setting (maybe these options are redundant) */
2365
2366         PACK_FRAME (vbox1, folder_frame, _("Folder"));
2367
2368         vbox3 = gtk_vbox_new (FALSE, 0);
2369         gtk_widget_show (vbox3);
2370         gtk_container_add (GTK_CONTAINER (folder_frame), vbox3);
2371         gtk_container_set_border_width (GTK_CONTAINER (vbox3), 8);
2372
2373         table = gtk_table_new (4, 3, FALSE);
2374         gtk_widget_show (table);
2375         gtk_container_add (GTK_CONTAINER (vbox3), table);
2376         gtk_table_set_row_spacings (GTK_TABLE (table), VSPACING_NARROW_2);
2377         gtk_table_set_col_spacings (GTK_TABLE (table), 4);
2378
2379 #define SET_CHECK_BTN_AND_ENTRY(label, chkbtn, entry, n)                \
2380 {                                                                       \
2381         GtkWidget *button;                                              \
2382                                                                         \
2383         chkbtn = gtk_check_button_new_with_label (label);               \
2384         gtk_widget_show (chkbtn);                                       \
2385         gtk_table_attach (GTK_TABLE (table), chkbtn,                    \
2386                           0, 1, n, n + 1, GTK_FILL, 0, 0, 0);           \
2387                                                                         \
2388         entry = gtk_entry_new ();                                       \
2389         gtk_widget_show (entry);                                        \
2390         gtk_table_attach (GTK_TABLE (table), entry, 1, 2, n, n + 1,     \
2391                           GTK_EXPAND | GTK_SHRINK | GTK_FILL,           \
2392                           GTK_EXPAND | GTK_SHRINK | GTK_FILL, 0, 0);    \
2393                                                                         \
2394         button = gtk_button_new_with_label (_(" ... "));                \
2395         gtk_widget_show (button);                                       \
2396         gtk_table_attach (GTK_TABLE (table), button,                    \
2397                           2, 3, n, n + 1, GTK_FILL, 0, 0, 0);           \
2398         g_signal_connect                                                \
2399                 (G_OBJECT (button), "clicked",                  \
2400                  G_CALLBACK (prefs_account_select_folder_cb),           \
2401                  entry);                                                \
2402                                                                         \
2403         SET_TOGGLE_SENSITIVITY (chkbtn, entry);                         \
2404         SET_TOGGLE_SENSITIVITY (chkbtn, button);                        \
2405 }
2406
2407         SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
2408                                 sent_folder_chkbtn, sent_folder_entry, 0);
2409         SET_CHECK_BTN_AND_ENTRY(_("Put queued messages in"),
2410                                 queue_folder_chkbtn, queue_folder_entry, 1);
2411         SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
2412                                 draft_folder_chkbtn, draft_folder_entry, 2);
2413         SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
2414                                 trash_folder_chkbtn, trash_folder_entry, 3);
2415
2416         advanced.smtpport_chkbtn        = checkbtn_smtpport;
2417         advanced.smtpport_entry         = entry_smtpport;
2418         advanced.popport_hbox           = hbox_popport;
2419         advanced.popport_chkbtn         = checkbtn_popport;
2420         advanced.popport_entry          = entry_popport;
2421         advanced.imapport_hbox          = hbox_imapport;
2422         advanced.imapport_chkbtn        = checkbtn_imapport;
2423         advanced.imapport_entry         = entry_imapport;
2424         advanced.nntpport_hbox          = hbox_nntpport;
2425         advanced.nntpport_chkbtn        = checkbtn_nntpport;
2426         advanced.nntpport_entry         = entry_nntpport;
2427         advanced.domain_chkbtn          = checkbtn_domain;
2428         advanced.domain_entry           = entry_domain;
2429         advanced.crosspost_chkbtn       = checkbtn_crosspost;
2430         advanced.crosspost_colormenu    = colormenu_crosspost;
2431
2432         advanced.tunnelcmd_chkbtn       = checkbtn_tunnelcmd;
2433         advanced.tunnelcmd_entry        = entry_tunnelcmd;
2434
2435         advanced.sent_folder_chkbtn  = sent_folder_chkbtn;
2436         advanced.sent_folder_entry   = sent_folder_entry;
2437         advanced.queue_folder_chkbtn  = queue_folder_chkbtn;
2438         advanced.queue_folder_entry   = queue_folder_entry;
2439         advanced.draft_folder_chkbtn = draft_folder_chkbtn;
2440         advanced.draft_folder_entry  = draft_folder_entry;
2441         advanced.trash_folder_chkbtn = trash_folder_chkbtn;
2442         advanced.trash_folder_entry  = trash_folder_entry;
2443 }
2444
2445 static gint prefs_account_apply(void)
2446 {
2447         RecvProtocol protocol;
2448         GtkWidget *menu;
2449         GtkWidget *menuitem;
2450         gchar *old_id = NULL;
2451         gchar *new_id = NULL;
2452         
2453         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(basic.protocol_optmenu));
2454         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2455         protocol = GPOINTER_TO_INT
2456                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2457
2458         if (*gtk_entry_get_text(GTK_ENTRY(basic.acname_entry)) == '\0') {
2459                 alertpanel_error(_("Account name is not entered."));
2460                 return -1;
2461         }
2462         if (*gtk_entry_get_text(GTK_ENTRY(basic.addr_entry)) == '\0') {
2463                 alertpanel_error(_("Mail address is not entered."));
2464                 return -1;
2465         }
2466         if (((protocol == A_POP3) || 
2467              (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn))) || 
2468              (protocol == A_NONE)) &&
2469            *gtk_entry_get_text(GTK_ENTRY(basic.smtpserv_entry)) == '\0') {
2470                 alertpanel_error(_("SMTP server is not entered."));
2471                 return -1;
2472         }
2473         if ((protocol == A_POP3 || protocol == A_IMAP4) &&
2474             *gtk_entry_get_text(GTK_ENTRY(basic.uid_entry)) == '\0') {
2475                 alertpanel_error(_("User ID is not entered."));
2476                 return -1;
2477         }
2478         if (protocol == A_POP3 &&
2479             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2480                 alertpanel_error(_("POP3 server is not entered."));
2481                 return -1;
2482         }
2483         if (protocol == A_IMAP4 &&
2484             *gtk_entry_get_text(GTK_ENTRY(basic.recvserv_entry)) == '\0') {
2485                 alertpanel_error(_("IMAP4 server is not entered."));
2486                 return -1;
2487         }
2488         if (protocol == A_NNTP &&
2489             *gtk_entry_get_text(GTK_ENTRY(basic.nntpserv_entry)) == '\0') {
2490                 alertpanel_error(_("NNTP server is not entered."));
2491                 return -1;
2492         }
2493
2494         if (protocol == A_LOCAL &&
2495             *gtk_entry_get_text(GTK_ENTRY(basic.localmbox_entry)) == '\0') {
2496                 alertpanel_error(_("local mailbox filename is not entered."));
2497                 return -1;
2498         }
2499
2500         if (protocol == A_LOCAL &&
2501             gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic.mailcmd_entry)) == '\0') {
2502                 alertpanel_error(_("mail command is not entered."));
2503                 return -1;
2504         }
2505         
2506         if (protocol == A_IMAP4 || protocol == A_NNTP) 
2507                 old_id = g_strdup_printf("#%s/%s",
2508                                 protocol == A_IMAP4 ? "imap":"nntp",
2509                                 tmp_ac_prefs.account_name ? tmp_ac_prefs.account_name : "(null)");
2510         
2511         prefs_set_data_from_dialog(param);
2512         
2513         if (protocol == A_IMAP4 || protocol == A_NNTP) {
2514                 new_id = g_strdup_printf("#%s/%s",
2515                                 protocol == A_IMAP4 ? "imap":"nntp",
2516                                 tmp_ac_prefs.account_name);
2517                 if (old_id != NULL && new_id != NULL)
2518                         prefs_filtering_rename_path(old_id, new_id);
2519                 g_free(old_id);
2520                 g_free(new_id);
2521         }
2522         return 0;
2523 }
2524
2525 static void pop_bfr_smtp_tm_set_sens(GtkWidget *widget, gpointer data)
2526 {
2527         gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, 
2528                                  gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn)));
2529 }
2530
2531 static void prefs_account_select_folder_cb(GtkWidget *widget, gpointer data)
2532 {
2533         FolderItem *item;
2534         gchar *id;
2535
2536         item = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL);
2537         if (item && item->path) {
2538                 id = folder_item_get_identifier(item);
2539                 if (id) {
2540                         gtk_entry_set_text(GTK_ENTRY(data), id);
2541                         g_free(id);
2542                 }
2543         }
2544 }
2545
2546 static void prefs_account_sigfile_radiobtn_cb(GtkWidget *widget, gpointer data)
2547 {
2548         gtk_widget_set_sensitive(GTK_WIDGET(signature_browse_button), TRUE);
2549 }
2550
2551 static void prefs_account_sigcmd_radiobtn_cb(GtkWidget *widget, gpointer data)
2552 {
2553         gtk_widget_set_sensitive(GTK_WIDGET(signature_browse_button), FALSE);
2554 }
2555
2556 static void prefs_account_signature_browse_cb(GtkWidget *widget, gpointer data)
2557 {
2558         gchar *filename;
2559         gchar *utf8_filename;
2560
2561         filename = filesel_select_file_open(_("Select signature file"), NULL);
2562         if (!filename) return;
2563
2564         utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
2565         if (!utf8_filename) {
2566                 g_warning("prefs_account_signature_browse_cb(): failed to convert character set.");
2567                 utf8_filename = g_strdup(filename);
2568         }
2569         gtk_entry_set_text(GTK_ENTRY(entry_sigpath), utf8_filename);
2570         g_free(utf8_filename);
2571 }
2572
2573 static void prefs_account_edit_custom_header(void)
2574 {
2575         prefs_custom_header_open(&tmp_ac_prefs);
2576 }
2577
2578 static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
2579 {
2580         GtkRadioButton *radiobtn;
2581         GSList *group;
2582
2583         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2584         group = gtk_radio_button_get_group (radiobtn);
2585         while (group != NULL) {
2586                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2587                 if (gtk_toggle_button_get_active (btn)) {
2588                         *((gint *)pparam->data) = GPOINTER_TO_INT
2589                                 (g_object_get_data (G_OBJECT (btn), MENU_VAL_ID));
2590                         break;
2591                 }
2592                 group = group->next;
2593         }
2594 }
2595
2596 static void prefs_account_enum_set_radiobtn(PrefParam *pparam)
2597 {
2598         GtkRadioButton *radiobtn;
2599         GSList *group;
2600         gpointer data;
2601
2602         data = GINT_TO_POINTER (*((gint *)pparam->data));
2603         radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
2604         group = gtk_radio_button_get_group (radiobtn);
2605         while (group != NULL) {
2606                 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
2607                 gpointer data1 = g_object_get_data (G_OBJECT (btn), MENU_VAL_ID);
2608                 if (data1 == data) {
2609                         gtk_toggle_button_set_active (btn, TRUE);
2610                         break;
2611                 }
2612                 group = group->next;
2613         }
2614 }
2615
2616 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
2617 {
2618         GtkWidget *menu;
2619         GtkWidget *menuitem;
2620
2621         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2622         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2623         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2624                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2625 }
2626
2627 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
2628 {
2629         RecvProtocol protocol;
2630         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2631         GtkWidget *menu;
2632         GtkWidget *menuitem;
2633         gint index;
2634
2635         protocol = *((RecvProtocol *)pparam->data);
2636         index = menu_find_option_menu_index
2637                 (optmenu, GINT_TO_POINTER(protocol), NULL);
2638         if (index < 0) return;
2639         gtk_option_menu_set_history(optmenu, index);
2640
2641         menu = gtk_option_menu_get_menu(optmenu);
2642         menu_set_insensitive_all(GTK_MENU_SHELL(menu));
2643
2644         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2645         gtk_widget_set_sensitive(menuitem, TRUE);
2646         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2647 }
2648
2649 static void prefs_account_imap_auth_type_set_data_from_optmenu(PrefParam *pparam)
2650 {
2651         GtkWidget *menu;
2652         GtkWidget *menuitem;
2653
2654         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2655         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2656         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2657                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2658 }
2659
2660 static void prefs_account_imap_auth_type_set_optmenu(PrefParam *pparam)
2661 {
2662         IMAPAuthType type = *((IMAPAuthType *)pparam->data);
2663         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2664         GtkWidget *menu;
2665         GtkWidget *menuitem;
2666
2667         switch (type) {
2668         case IMAP_AUTH_LOGIN:
2669                 gtk_option_menu_set_history(optmenu, 1);
2670                 break;
2671         case IMAP_AUTH_CRAM_MD5:
2672                 gtk_option_menu_set_history(optmenu, 2);
2673                 break;
2674         case 0:
2675         default:
2676                 gtk_option_menu_set_history(optmenu, 0);
2677         }
2678
2679         menu = gtk_option_menu_get_menu(optmenu);
2680         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2681         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2682 }
2683
2684 static void prefs_account_smtp_auth_type_set_data_from_optmenu(PrefParam *pparam)
2685 {
2686         GtkWidget *menu;
2687         GtkWidget *menuitem;
2688
2689         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2690         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2691         *((RecvProtocol *)pparam->data) = GPOINTER_TO_INT
2692                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2693 }
2694
2695 static void prefs_account_smtp_auth_type_set_optmenu(PrefParam *pparam)
2696 {
2697         SMTPAuthType type = *((SMTPAuthType *)pparam->data);
2698         GtkOptionMenu *optmenu = GTK_OPTION_MENU(*pparam->widget);
2699         GtkWidget *menu;
2700         GtkWidget *menuitem;
2701
2702         switch (type) {
2703         case SMTPAUTH_PLAIN:
2704                 gtk_option_menu_set_history(optmenu, 1);
2705                 break;
2706         case SMTPAUTH_LOGIN:
2707                 gtk_option_menu_set_history(optmenu, 2);
2708                 break;
2709         case SMTPAUTH_CRAM_MD5:
2710                 gtk_option_menu_set_history(optmenu, 3);
2711                 break;
2712         case SMTPAUTH_DIGEST_MD5:
2713                 gtk_option_menu_set_history(optmenu, 4);
2714                 break;
2715         case 0:
2716         default:
2717                 gtk_option_menu_set_history(optmenu, 0);
2718         }
2719
2720         menu = gtk_option_menu_get_menu(optmenu);
2721         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2722         gtk_menu_item_activate(GTK_MENU_ITEM(menuitem));
2723 }
2724
2725 static void prefs_account_set_string_from_optmenu(PrefParam *pparam)
2726 {
2727         GtkWidget *menu;
2728         GtkWidget *menuitem;
2729         gchar **str;
2730
2731         g_return_if_fail(*pparam->widget != NULL);
2732
2733         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(*pparam->widget));
2734         menuitem = gtk_menu_get_active(GTK_MENU(menu));
2735         if (menuitem == NULL)
2736                 return;
2737
2738         str = (gchar **) pparam->data;
2739         g_free(*str);
2740         *str = g_strdup(g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2741 }
2742
2743 static void prefs_account_set_optmenu_from_string(PrefParam *pparam)
2744 {
2745         GtkWidget *optionmenu;
2746         GtkWidget *menu;
2747         gboolean found = FALSE;
2748         GList *children, *cur;
2749         gchar *prefsid;
2750         guint i = 0;
2751
2752         g_return_if_fail(*pparam->widget != NULL);
2753
2754         prefsid = *((gchar **) pparam->data);
2755         if (prefsid == NULL)
2756                 return;
2757
2758         optionmenu = *pparam->widget;
2759         menu = gtk_option_menu_get_menu(GTK_OPTION_MENU(optionmenu));
2760         children = gtk_container_children(GTK_CONTAINER(menu));
2761         for (cur = children; cur != NULL; cur = g_list_next(cur)) {
2762                 GtkWidget *item = (GtkWidget *) cur->data;
2763                 gchar *id;
2764
2765                 id = g_object_get_data(G_OBJECT(item), MENU_VAL_ID);
2766                 if (id != NULL && strcmp(id, prefsid) == 0) {
2767                         found = TRUE;
2768                         gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), i);
2769                 }
2770                 i++;
2771         }
2772
2773         if (!found) {
2774                 gchar *name;
2775                 GtkWidget *menuitem;
2776
2777                 name = g_strdup_printf(_("Unsupported (%s)"), prefsid);
2778                 menuitem = gtk_menu_item_new_with_label(name);
2779                 gtk_widget_show(menuitem);
2780                 g_object_set_data_full(G_OBJECT(menuitem), MENU_VAL_ID, g_strdup(prefsid), g_free);
2781                 gtk_menu_append(GTK_MENU(menu), menuitem);
2782                 g_free(name);
2783
2784                 gtk_option_menu_set_history(GTK_OPTION_MENU(optionmenu), i);
2785         }
2786
2787         g_list_free(children);
2788 }
2789
2790 static void prefs_account_protocol_activated(GtkMenuItem *menuitem)
2791 {
2792         RecvProtocol protocol;
2793
2794         protocol = GPOINTER_TO_INT
2795                 (g_object_get_data(G_OBJECT(menuitem), MENU_VAL_ID));
2796
2797         switch(protocol) {
2798         case A_NNTP:
2799                 gtk_widget_show(basic.nntpserv_label);
2800                 gtk_widget_show(basic.nntpserv_entry);
2801                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2802                                            0, VSPACING_NARROW);
2803
2804                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, TRUE);
2805                 gtk_widget_show(basic.nntpauth_chkbtn);
2806
2807                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, TRUE);
2808                 gtk_widget_show(basic.nntpauth_onconnect_chkbtn);
2809
2810                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2811                                            1, VSPACING_NARROW);
2812                 gtk_widget_hide(basic.recvserv_label);
2813                 gtk_widget_hide(basic.recvserv_entry);
2814                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2815                                            2, 0);
2816                 gtk_widget_show(basic.smtpserv_label);
2817                 gtk_widget_show(basic.smtpserv_entry);
2818                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2819                                            4, VSPACING_NARROW);
2820                 gtk_widget_hide(basic.localmbox_label);
2821                 gtk_widget_hide(basic.localmbox_entry);
2822                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2823                                            3, 0);
2824                 gtk_widget_hide(basic.mailcmd_label);
2825                 gtk_widget_hide(basic.mailcmd_entry);
2826                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2827                                            6, 0);
2828                 gtk_widget_hide(basic.mailcmd_chkbtn);
2829                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2830                                            5, 0);
2831                 gtk_widget_show(basic.uid_label);
2832                 gtk_widget_show(basic.pass_label);
2833                 gtk_widget_show(basic.uid_entry);
2834                 gtk_widget_show(basic.pass_entry);
2835                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2836                                            7, VSPACING_NARROW);
2837
2838                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2839                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2840                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2841                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2842
2843                 /* update userid/passwd sensitive state */
2844
2845                 prefs_account_nntpauth_toggled
2846                         (GTK_TOGGLE_BUTTON(basic.nntpauth_chkbtn), NULL);
2847                 gtk_widget_hide(receive.pop3_frame);
2848                 gtk_widget_hide(receive.imap_frame);
2849                 gtk_widget_hide(receive.local_frame);
2850                 gtk_widget_show(receive.frame_maxarticle);
2851                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
2852                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2853                 /* update pop_before_smtp sensitivity */
2854                 gtk_toggle_button_set_active
2855                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
2856                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2857                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
2858                 
2859                 if (!tmp_ac_prefs.account_name) {
2860                         gtk_toggle_button_set_active
2861                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
2862                                 TRUE);
2863                         gtk_toggle_button_set_active
2864                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2865                                  FALSE);
2866                 }
2867
2868 #if USE_OPENSSL
2869                 gtk_widget_hide(ssl.pop_frame);
2870                 gtk_widget_hide(ssl.imap_frame);
2871                 gtk_widget_show(ssl.nntp_frame);
2872                 gtk_widget_show(ssl.send_frame);
2873 #endif
2874                 gtk_widget_hide(advanced.popport_hbox);
2875                 gtk_widget_hide(advanced.imapport_hbox);
2876                 gtk_widget_show(advanced.nntpport_hbox);
2877                 gtk_widget_show(advanced.crosspost_chkbtn);
2878                 gtk_widget_show(advanced.crosspost_colormenu);
2879                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
2880                 gtk_widget_hide(advanced.tunnelcmd_entry);
2881                 gtk_widget_hide(receive.imapdir_label);
2882                 gtk_widget_hide(receive.imapdir_entry);
2883                 break;
2884         case A_LOCAL:
2885                 gtk_widget_hide(basic.nntpserv_label);
2886                 gtk_widget_hide(basic.nntpserv_entry);
2887                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2888                                            0, 0);
2889                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2890                 gtk_widget_hide(basic.nntpauth_chkbtn);
2891
2892                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2893                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2894                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2895                                            1, 0);
2896                 gtk_widget_hide(basic.recvserv_label);
2897                 gtk_widget_hide(basic.recvserv_entry);
2898                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2899                                            2, 0);
2900                 gtk_widget_show(basic.smtpserv_label);
2901                 gtk_widget_show(basic.smtpserv_entry);
2902                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2903                                            4, VSPACING_NARROW);
2904                 gtk_widget_show(basic.localmbox_label);
2905                 gtk_widget_show(basic.localmbox_entry);
2906                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2907                                            3, VSPACING_NARROW);
2908                 gtk_widget_show(basic.mailcmd_label);
2909                 gtk_widget_show(basic.mailcmd_entry);
2910                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2911                                            6, VSPACING_NARROW);
2912                 gtk_widget_show(basic.mailcmd_chkbtn);
2913                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2914                                            5, VSPACING_NARROW);
2915                 gtk_widget_hide(basic.uid_label);
2916                 gtk_widget_hide(basic.pass_label);
2917                 gtk_widget_hide(basic.uid_entry);
2918                 gtk_widget_hide(basic.pass_entry);
2919                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2920                                            7, 0);
2921
2922                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
2923                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
2924                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
2925                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
2926                 gtk_widget_hide(receive.pop3_frame);
2927                 gtk_widget_hide(receive.imap_frame);
2928                 gtk_widget_show(receive.local_frame);
2929                 gtk_widget_hide(receive.frame_maxarticle);
2930                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
2931                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
2932                 prefs_account_mailcmd_toggled
2933                         (GTK_TOGGLE_BUTTON(basic.mailcmd_chkbtn), NULL);
2934
2935                 /* update pop_before_smtp sensitivity */
2936                 gtk_toggle_button_set_active
2937                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
2938                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
2939                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
2940
2941                 if (!tmp_ac_prefs.account_name) {
2942                         gtk_toggle_button_set_active
2943                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
2944                                 TRUE);
2945                         gtk_toggle_button_set_active
2946                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
2947                                  TRUE);
2948                 }
2949
2950 #if USE_OPENSSL
2951                 gtk_widget_hide(ssl.pop_frame);
2952                 gtk_widget_hide(ssl.imap_frame);
2953                 gtk_widget_hide(ssl.nntp_frame);
2954                 gtk_widget_show(ssl.send_frame);
2955 #endif
2956                 gtk_widget_hide(advanced.popport_hbox);
2957                 gtk_widget_hide(advanced.imapport_hbox);
2958                 gtk_widget_hide(advanced.nntpport_hbox);
2959                 gtk_widget_hide(advanced.crosspost_chkbtn);
2960                 gtk_widget_hide(advanced.crosspost_colormenu);
2961                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
2962                 gtk_widget_hide(advanced.tunnelcmd_entry);
2963                 gtk_widget_hide(receive.imapdir_label);
2964                 gtk_widget_hide(receive.imapdir_entry);
2965                 break;
2966         case A_IMAP4:
2967                 gtk_widget_hide(basic.nntpserv_label);
2968                 gtk_widget_hide(basic.nntpserv_entry);
2969                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2970                                            0, 0);
2971                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
2972                 gtk_widget_hide(basic.nntpauth_chkbtn);
2973
2974                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
2975                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
2976
2977                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2978                                            1, 0);
2979                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
2980                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
2981                 gtk_widget_show(basic.recvserv_label);
2982                 gtk_widget_show(basic.recvserv_entry);
2983                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2984                                            2, VSPACING_NARROW);
2985                 gtk_widget_show(basic.smtpserv_label);
2986                 gtk_widget_show(basic.smtpserv_entry);
2987                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2988                                            4, VSPACING_NARROW);
2989                 gtk_widget_hide(basic.localmbox_label);
2990                 gtk_widget_hide(basic.localmbox_entry);
2991                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2992                                            3, 0);
2993                 gtk_widget_hide(basic.mailcmd_label);
2994                 gtk_widget_hide(basic.mailcmd_entry);
2995                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2996                                            6, 0);
2997                 gtk_widget_hide(basic.mailcmd_chkbtn);
2998                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
2999                                            5, 0);
3000                 gtk_widget_show(basic.uid_label);
3001                 gtk_widget_show(basic.pass_label);
3002                 gtk_widget_show(basic.uid_entry);
3003                 gtk_widget_show(basic.pass_entry);
3004                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3005                                            7, VSPACING_NARROW);
3006
3007                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
3008                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
3009                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
3010                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
3011                 gtk_widget_hide(receive.pop3_frame);
3012                 gtk_widget_show(receive.imap_frame);
3013                 gtk_widget_hide(receive.local_frame);
3014                 gtk_widget_hide(receive.frame_maxarticle);
3015                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
3016                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
3017                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3018                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3019
3020                 /* update pop_before_smtp sensitivity */
3021                 gtk_toggle_button_set_active
3022                         (GTK_TOGGLE_BUTTON(p_send.pop_bfr_smtp_chkbtn), FALSE);
3023                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
3024                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_tm_entry, FALSE);
3025
3026                 if (!tmp_ac_prefs.account_name) {
3027                         gtk_toggle_button_set_active
3028                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
3029                                 TRUE);
3030                         gtk_toggle_button_set_active
3031                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
3032                                  FALSE);
3033                 }
3034
3035 #if USE_OPENSSL
3036                 gtk_widget_hide(ssl.pop_frame);
3037                 gtk_widget_show(ssl.imap_frame);
3038                 gtk_widget_hide(ssl.nntp_frame);
3039                 gtk_widget_show(ssl.send_frame);
3040 #endif
3041                 gtk_widget_hide(advanced.popport_hbox);
3042                 gtk_widget_show(advanced.imapport_hbox);
3043                 gtk_widget_hide(advanced.nntpport_hbox);
3044                 gtk_widget_hide(advanced.crosspost_chkbtn);
3045                 gtk_widget_hide(advanced.crosspost_colormenu);
3046                 gtk_widget_show(advanced.tunnelcmd_chkbtn);
3047                 gtk_widget_show(advanced.tunnelcmd_entry);
3048                 gtk_widget_show(receive.imapdir_label);
3049                 gtk_widget_show(receive.imapdir_entry);
3050                 break;
3051         case A_NONE:
3052                 gtk_widget_hide(basic.nntpserv_label);
3053                 gtk_widget_hide(basic.nntpserv_entry);
3054                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3055                                            0, 0);
3056                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
3057                 gtk_widget_hide(basic.nntpauth_chkbtn);
3058
3059                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
3060                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
3061
3062                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3063                                            1, 0);
3064                 gtk_widget_set_sensitive(basic.recvserv_label, FALSE);
3065                 gtk_widget_set_sensitive(basic.recvserv_entry, FALSE);
3066                 gtk_widget_hide(basic.recvserv_label);
3067                 gtk_widget_hide(basic.recvserv_entry);
3068                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3069                                            2, VSPACING_NARROW);
3070                 gtk_widget_show(basic.smtpserv_label);
3071                 gtk_widget_show(basic.smtpserv_entry);
3072                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3073                                            4, VSPACING_NARROW);
3074                 gtk_widget_hide(basic.localmbox_label);
3075                 gtk_widget_hide(basic.localmbox_entry);
3076                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3077                                            3, 0);
3078                 gtk_widget_hide(basic.mailcmd_label);
3079                 gtk_widget_hide(basic.mailcmd_entry);
3080                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3081                                            6, 0);
3082                 gtk_widget_hide(basic.mailcmd_chkbtn);
3083                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3084                                            5, 0);
3085                 gtk_widget_hide(basic.uid_label);
3086                 gtk_widget_hide(basic.pass_label);
3087                 gtk_widget_hide(basic.uid_entry);
3088                 gtk_widget_hide(basic.pass_entry);
3089                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3090                                            7, VSPACING_NARROW);
3091
3092                 gtk_widget_set_sensitive(basic.uid_label,  FALSE);
3093                 gtk_widget_set_sensitive(basic.pass_label, FALSE);
3094                 gtk_widget_set_sensitive(basic.uid_entry,  FALSE);
3095                 gtk_widget_set_sensitive(basic.pass_entry, FALSE);
3096                 gtk_widget_set_sensitive(receive.pop3_frame, FALSE);
3097                 gtk_widget_hide(receive.pop3_frame);
3098                 gtk_widget_hide(receive.imap_frame);
3099                 gtk_widget_hide(receive.local_frame);
3100                 gtk_widget_hide(receive.frame_maxarticle);
3101                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, FALSE);
3102                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, FALSE);
3103
3104                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3105                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3106
3107                 /* update pop_before_smtp sensitivity */
3108                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, FALSE);
3109                 pop_bfr_smtp_tm_set_sens(NULL, NULL);
3110         
3111                 gtk_toggle_button_set_active
3112                         (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), FALSE);
3113                 gtk_toggle_button_set_active
3114                         (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn), FALSE);
3115
3116 #if USE_OPENSSL
3117                 gtk_widget_hide(ssl.pop_frame);
3118                 gtk_widget_hide(ssl.imap_frame);
3119                 gtk_widget_hide(ssl.nntp_frame);
3120                 gtk_widget_show(ssl.send_frame);
3121 #endif
3122                 gtk_widget_hide(advanced.popport_hbox);
3123                 gtk_widget_hide(advanced.imapport_hbox);
3124                 gtk_widget_hide(advanced.nntpport_hbox);
3125                 gtk_widget_hide(advanced.crosspost_chkbtn);
3126                 gtk_widget_hide(advanced.crosspost_colormenu);
3127                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
3128                 gtk_widget_hide(advanced.tunnelcmd_entry);
3129                 gtk_widget_hide(receive.imapdir_label);
3130                 gtk_widget_hide(receive.imapdir_entry);
3131                 break;
3132         case A_POP3:
3133         default:
3134                 gtk_widget_hide(basic.nntpserv_label);
3135                 gtk_widget_hide(basic.nntpserv_entry);
3136                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3137                                            0, 0);
3138                 gtk_widget_set_sensitive(basic.nntpauth_chkbtn, FALSE);
3139                 gtk_widget_hide(basic.nntpauth_chkbtn);
3140
3141                 gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, FALSE);
3142                 gtk_widget_hide(basic.nntpauth_onconnect_chkbtn);
3143
3144                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3145                                            1, 0);
3146                 gtk_widget_set_sensitive(basic.recvserv_label, TRUE);
3147                 gtk_widget_set_sensitive(basic.recvserv_entry, TRUE);
3148                 gtk_widget_show(basic.recvserv_label);
3149                 gtk_widget_show(basic.recvserv_entry);
3150                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3151                                            2, VSPACING_NARROW);
3152                 gtk_widget_show(basic.smtpserv_label);
3153                 gtk_widget_show(basic.smtpserv_entry);
3154                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3155                                            4, VSPACING_NARROW);
3156                 gtk_widget_hide(basic.localmbox_label);
3157                 gtk_widget_hide(basic.localmbox_entry);
3158                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3159                                            3, 0);
3160                 gtk_widget_hide(basic.mailcmd_label);
3161                 gtk_widget_hide(basic.mailcmd_entry);
3162                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3163                                            6, 0);
3164                 gtk_widget_hide(basic.mailcmd_chkbtn);
3165                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3166                                            5, 0);
3167                 gtk_widget_show(basic.uid_label);
3168                 gtk_widget_show(basic.pass_label);
3169                 gtk_widget_show(basic.uid_entry);
3170                 gtk_widget_show(basic.pass_entry);
3171                 gtk_table_set_row_spacing (GTK_TABLE (basic.serv_table),
3172                                            7, VSPACING_NARROW);
3173
3174                 gtk_widget_set_sensitive(basic.uid_label,  TRUE);
3175                 gtk_widget_set_sensitive(basic.pass_label, TRUE);
3176                 gtk_widget_set_sensitive(basic.uid_entry,  TRUE);
3177                 gtk_widget_set_sensitive(basic.pass_entry, TRUE);
3178                 gtk_widget_set_sensitive(receive.pop3_frame, TRUE);
3179                 gtk_widget_show(receive.pop3_frame);
3180                 gtk_widget_hide(receive.imap_frame);
3181                 gtk_widget_hide(receive.local_frame);
3182                 gtk_widget_hide(receive.frame_maxarticle);
3183                 gtk_widget_set_sensitive(receive.filter_on_recv_chkbtn, TRUE);
3184                 gtk_widget_set_sensitive(receive.recvatgetall_chkbtn, TRUE);
3185
3186                 gtk_widget_set_sensitive(basic.smtpserv_entry, TRUE);
3187                 gtk_widget_set_sensitive(basic.smtpserv_label, TRUE);
3188
3189                 /* update pop_before_smtp sensitivity */
3190                 gtk_widget_set_sensitive(p_send.pop_bfr_smtp_chkbtn, TRUE);
3191                 pop_bfr_smtp_tm_set_sens(NULL, NULL);
3192                 
3193                 if (!tmp_ac_prefs.account_name) {
3194                         gtk_toggle_button_set_active
3195                                 (GTK_TOGGLE_BUTTON(receive.filter_on_recv_chkbtn), 
3196                                 TRUE);
3197                         gtk_toggle_button_set_active
3198                                 (GTK_TOGGLE_BUTTON(receive.recvatgetall_chkbtn),
3199                                  TRUE);
3200                 }
3201
3202 #if USE_OPENSSL
3203                 gtk_widget_show(ssl.pop_frame);
3204                 gtk_widget_hide(ssl.imap_frame);
3205                 gtk_widget_hide(ssl.nntp_frame);
3206                 gtk_widget_show(ssl.send_frame);
3207 #endif
3208                 gtk_widget_show(advanced.popport_hbox);
3209                 gtk_widget_hide(advanced.imapport_hbox);
3210                 gtk_widget_hide(advanced.nntpport_hbox);
3211                 gtk_widget_hide(advanced.crosspost_chkbtn);
3212                 gtk_widget_hide(advanced.crosspost_colormenu);
3213                 gtk_widget_hide(advanced.tunnelcmd_chkbtn);
3214                 gtk_widget_hide(advanced.tunnelcmd_entry);
3215                 gtk_widget_hide(receive.imapdir_label);
3216                 gtk_widget_hide(receive.imapdir_entry);
3217                 break;
3218         }
3219
3220         gtk_widget_queue_resize(basic.serv_frame);
3221 }
3222
3223 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
3224                                            gpointer user_data)
3225 {
3226         gboolean auth;
3227
3228         if (!GTK_WIDGET_SENSITIVE (GTK_WIDGET (button)))
3229                 return;
3230         auth = gtk_toggle_button_get_active (button);
3231         gtk_widget_set_sensitive(basic.uid_label,  auth);
3232         gtk_widget_set_sensitive(basic.pass_label, auth);
3233         gtk_widget_set_sensitive(basic.uid_entry,  auth);
3234         gtk_widget_set_sensitive(basic.pass_entry, auth);
3235         gtk_widget_set_sensitive(basic.nntpauth_onconnect_chkbtn, auth);
3236 }
3237
3238 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
3239                                           gpointer user_data)
3240 {
3241         gboolean use_mailcmd;
3242
3243         use_mailcmd = gtk_toggle_button_get_active (button);
3244
3245         gtk_widget_set_sensitive(basic.mailcmd_entry,  use_mailcmd);
3246         gtk_widget_set_sensitive(basic.mailcmd_label, use_mailcmd);
3247         gtk_widget_set_sensitive(basic.smtpserv_entry, !use_mailcmd);
3248         gtk_widget_set_sensitive(basic.smtpserv_label, !use_mailcmd);
3249         gtk_widget_set_sensitive(basic.uid_entry,  !use_mailcmd);
3250         gtk_widget_set_sensitive(basic.pass_entry, !use_mailcmd);
3251 }
3252
3253 void prefs_account_register_page(PrefsPage *page)
3254 {
3255         prefs_pages = g_slist_append(prefs_pages, page);
3256 }
3257
3258 void prefs_account_unregister_page(PrefsPage *page)
3259 {
3260         prefs_pages = g_slist_remove(prefs_pages, page);
3261 }