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