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