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