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