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