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