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