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