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