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