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