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