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