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