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