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