Sync Spanish manual
[claws.git] / src / prefs_account.c
blobb9a14c2a8fb58c56a273a4ee88014fa20d6441ba
1 /*
2 * Claws Mail -- a GTK based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2023 the Claws Mail team and Hiroyuki Yamamoto
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 3 of the License, or
8 * (at your option) any later version.
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.
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
19 #ifdef HAVE_CONFIG_H
20 # include "config.h"
21 #include "claws-features.h"
22 #endif
24 #include "defs.h"
26 #ifdef G_OS_WIN32
27 #include <winsock2.h>
28 #include <ws2tcpip.h>
29 #else
30 #include <sys/socket.h>
31 #include <netinet/in.h>
32 #endif
34 #include <glib.h>
35 #include <glib/gi18n.h>
36 #include <gtk/gtk.h>
37 #include <gdk/gdkkeysyms.h>
38 #include <gtk/filesel.h>
39 #include <stdio.h>
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <string.h>
43 #include <stdlib.h>
44 #include <ctype.h>
45 #include "main.h"
46 #include "prefs_gtk.h"
47 #include "prefs_account.h"
48 #include "prefs_receive.h"
49 #include "prefs_common.h"
50 #include "prefs_customheader.h"
51 #include "account.h"
52 #include "mainwindow.h"
53 #include "manage_window.h"
54 #include "folder.h"
55 #include "foldersel.h"
56 #include "inc.h"
57 #include "menu.h"
58 #include "gtkutils.h"
59 #include "utils.h"
60 #include "alertpanel.h"
61 #include "colorlabel.h"
62 #include "smtp.h"
63 #include "imap.h"
64 #include "pop.h"
65 #ifdef USE_OAUTH2
66 #include "oauth2.h"
67 #endif
68 #include "remotefolder.h"
69 #include "combobox.h"
70 #include "setup.h"
71 #include "quote_fmt.h"
72 #include "hooks.h"
73 #include "privacy.h"
74 #include "inputdialog.h"
75 #include "ssl_certificate.h"
76 #include "passwordstore.h"
77 #include "file-utils.h"
78 #ifdef USE_GNUTLS
79 #include <gnutls/gnutls.h>
80 #endif
82 static gboolean cancelled;
83 static gboolean new_account;
85 static PrefsAccount tmp_ac_prefs;
87 static GtkWidget *sigfile_radiobtn;
88 static GtkWidget *sigcmd_radiobtn;
89 static GtkWidget *entry_sigpath;
90 static GtkWidget *signature_browse_button;
91 static GtkWidget *signature_edit_button;
93 #ifdef USE_GNUTLS
94 static GtkWidget *entry_in_cert_file;
95 static GtkWidget *entry_out_cert_file;
96 static GtkWidget *in_ssl_cert_browse_button;
97 static GtkWidget *out_ssl_cert_browse_button;
98 #endif
100 struct AutocheckWidgets {
101 GtkWidget *autochk_hour_spinbtn;
102 GtkWidget *autochk_min_spinbtn;
103 GtkWidget *autochk_sec_spinbtn;
106 static GSList *prefs_pages = NULL;
108 #ifdef USE_OAUTH2
109 static GTask *oauth2_listener_task;
110 static int oauth2_listener_cancel = 0;
111 static int oauth2_listener_closed = 0;
112 #endif
114 typedef struct BasicPage
116 PrefsPage page;
118 GtkWidget *vbox;
120 GtkWidget *acname_entry;
121 GtkWidget *default_checkbtn;
123 GtkWidget *name_entry;
124 GtkWidget *addr_entry;
125 GtkWidget *org_entry;
127 GtkWidget *serv_frame;
128 GtkWidget *serv_table;
129 gpointer *protocol_optmenu;
130 GtkWidget *recvserv_label;
131 GtkWidget *smtpserv_label;
132 GtkWidget *nntpserv_label;
133 GtkWidget *localmbox_label;
134 GtkWidget *mailcmd_label;
135 GtkWidget *recvserv_entry;
136 GtkWidget *smtpserv_entry;
137 GtkWidget *nntpserv_entry;
138 GtkWidget *nntpauth_checkbtn;
139 GtkWidget *nntpauth_onconnect_checkbtn;
140 GtkWidget *localmbox_entry;
141 GtkWidget *mailcmd_checkbtn;
142 GtkWidget *mailcmd_entry;
143 GtkWidget *uid_label;
144 GtkWidget *pass_label;
145 GtkWidget *uid_entry;
146 GtkWidget *pass_entry;
147 GtkWidget *showpwd_checkbtn;
148 GtkWidget *auto_configure_btn;
149 GtkWidget *auto_configure_cancel_btn;
150 GtkWidget *auto_configure_lbl;
151 } BasicPage;
153 typedef struct ReceivePage
155 PrefsPage page;
157 GtkWidget *vbox;
159 GtkWidget *pop3_frame;
160 GtkWidget *pop_auth_checkbtn;
161 GtkWidget *pop_auth_type_optmenu;
162 GtkWidget *rmmail_checkbtn;
163 GtkWidget *leave_time_spinbtn;
164 GtkWidget *leave_hour_spinbtn;
165 GtkWidget *size_limit_checkbtn;
166 GtkWidget *size_limit_spinbtn;
167 GtkWidget *inbox_label;
168 GtkWidget *inbox_entry;
169 GtkWidget *inbox_btn;
171 GtkWidget *autochk_frame;
173 GtkWidget *local_frame;
174 GtkWidget *local_inbox_label;
175 GtkWidget *local_inbox_entry;
176 GtkWidget *local_inbox_btn;
178 GtkWidget *filter_on_recv_checkbtn;
179 GtkWidget *filterhook_on_recv_checkbtn;
180 GtkWidget *recvatgetall_checkbtn;
182 GtkWidget *imap_frame;
183 GtkWidget *imap_auth_type_optmenu;
184 GtkWidget *imapdir_label;
185 GtkWidget *imapdir_entry;
186 GtkWidget *subsonly_checkbtn;
187 GtkWidget *low_bandwidth_checkbtn;
188 GtkWidget *imap_batch_size_spinbtn;
190 GtkWidget *frame_maxarticle;
191 GtkWidget *maxarticle_label;
192 GtkWidget *maxarticle_spinbtn;
193 GtkAdjustment *maxarticle_spinbtn_adj;
195 GtkWidget *autochk_checkbtn;
196 GtkWidget *autochk_use_default_checkbtn;
197 struct AutocheckWidgets *autochk_widgets;
198 } ReceivePage;
200 typedef struct SendPage
202 PrefsPage page;
204 GtkWidget *vbox;
206 GtkWidget *msgid_checkbtn;
207 GtkWidget *xmailer_checkbtn;
208 GtkWidget *customhdr_checkbtn;
209 GtkWidget *msgid_with_addr_checkbtn;
210 GtkWidget *smtp_auth_checkbtn;
211 GtkWidget *smtp_auth_type_optmenu;
212 GtkWidget *smtp_uid_entry;
213 GtkWidget *smtp_pass_entry;
214 GtkWidget *pop_bfr_smtp_checkbtn;
215 GtkWidget *pop_bfr_smtp_tm_spinbtn;
216 GtkWidget *pop_auth_timeout_lbl;
217 GtkWidget *pop_auth_minutes_lbl;
218 } SendPage;
220 #ifdef USE_OAUTH2
221 typedef struct Oauth2Page
223 PrefsPage page;
225 GtkWidget *vbox;
226 GtkWidget *oauth2_sensitive;
228 GtkWidget *oauth2_authorise_btn;
229 GtkWidget *oauth2_deauthorise_btn;
230 GtkWidget *oauth2_authcode_entry;
231 GtkWidget *oauth2_auth_optmenu;
232 GtkWidget *oauth2_link_button;
233 GtkWidget *oauth2_link_copy_button;
234 gpointer *protocol_optmenu;
235 GtkWidget *oauth2_client_id_entry;
236 GtkWidget *oauth2_client_secret_entry;
237 } Oauth2Page;
238 #endif
240 typedef struct
242 gchar *auth_uri;
243 GtkWidget *entry;
244 } AuthCodeQueryButtonData;
246 typedef struct ComposePage
248 PrefsPage page;
250 GtkWidget *vbox;
252 GtkWidget *sigfile_radiobtn;
253 GtkWidget *entry_sigpath;
254 GtkWidget *checkbtn_autosig;
255 GtkWidget *entry_sigsep;
256 GtkWidget *autocc_checkbtn;
257 GtkWidget *autocc_entry;
258 GtkWidget *autobcc_checkbtn;
259 GtkWidget *autobcc_entry;
260 GtkWidget *autoreplyto_checkbtn;
261 GtkWidget *autoreplyto_entry;
262 #if USE_ENCHANT
263 GtkWidget *checkbtn_enable_default_dictionary;
264 GtkWidget *combo_default_dictionary;
265 GtkWidget *checkbtn_enable_default_alt_dictionary;
266 GtkWidget *combo_default_alt_dictionary;
267 #endif
268 } ComposePage;
270 typedef struct TemplatesPage
272 PrefsPage page;
274 GtkWidget *vbox;
276 GtkWidget *checkbtn_compose_with_format;
277 GtkWidget *compose_subject_format;
278 GtkWidget *compose_body_format;
279 GtkWidget *checkbtn_reply_with_format;
280 GtkWidget *reply_quotemark;
281 GtkWidget *reply_body_format;
282 GtkWidget *checkbtn_forward_with_format;
283 GtkWidget *forward_quotemark;
284 GtkWidget *forward_body_format;
285 } TemplatesPage;
287 typedef struct PrivacyPage
289 PrefsPage page;
291 GtkWidget *vbox;
293 GtkWidget *default_privacy_system;
294 GtkWidget *default_encrypt_checkbtn;
295 GtkWidget *default_encrypt_reply_checkbtn;
296 GtkWidget *default_sign_checkbtn;
297 GtkWidget *default_sign_reply_checkbtn;
298 GtkWidget *save_clear_text_checkbtn;
299 GtkWidget *encrypt_to_self_checkbtn;
300 } PrivacyPage;
302 typedef struct SSLPage
304 PrefsPage page;
306 GtkWidget *vbox;
308 GtkWidget *pop_frame;
309 GtkWidget *pop_nossl_radiobtn;
310 GtkWidget *pop_ssltunnel_radiobtn;
311 GtkWidget *pop_starttls_radiobtn;
313 GtkWidget *imap_frame;
314 GtkWidget *imap_nossl_radiobtn;
315 GtkWidget *imap_ssltunnel_radiobtn;
316 GtkWidget *imap_starttls_radiobtn;
318 GtkWidget *nntp_frame;
319 GtkWidget *nntp_nossl_radiobtn;
320 GtkWidget *nntp_ssltunnel_radiobtn;
322 GtkWidget *send_frame;
323 GtkWidget *smtp_nossl_radiobtn;
324 GtkWidget *smtp_ssltunnel_radiobtn;
325 GtkWidget *smtp_starttls_radiobtn;
327 GtkWidget *entry_in_cert_file;
328 GtkWidget *entry_in_cert_pass;
329 GtkWidget *entry_out_cert_file;
330 GtkWidget *entry_out_cert_pass;
332 GtkWidget *ssl_certs_auto_accept_checkbtn;
333 GtkWidget *use_nonblocking_ssl_checkbtn;
334 } SSLPage;
336 typedef struct ProxyPage
338 PrefsPage page;
340 GtkWidget *vbox;
342 GtkWidget *proxy_checkbtn;
343 GtkWidget *default_proxy_checkbtn;
344 GtkWidget *socks4_radiobtn;
345 GtkWidget *socks5_radiobtn;
346 GtkWidget *proxy_host_entry;
347 GtkWidget *proxy_port_spinbtn;
348 GtkWidget *proxy_auth_checkbtn;
349 GtkWidget *proxy_name_entry;
350 GtkWidget *proxy_pass_entry;
351 GtkWidget *proxy_send_checkbtn;
352 } ProxyPage;
354 typedef struct AdvancedPage
356 PrefsPage page;
358 GtkWidget *vbox;
360 GtkWidget *smtpport_checkbtn;
361 GtkWidget *smtpport_spinbtn;
362 GtkWidget *popport_hbox;
363 GtkWidget *popport_checkbtn;
364 GtkWidget *popport_spinbtn;
365 GtkWidget *imapport_hbox;
366 GtkWidget *imapport_checkbtn;
367 GtkWidget *imapport_spinbtn;
368 GtkWidget *nntpport_hbox;
369 GtkWidget *nntpport_checkbtn;
370 GtkWidget *nntpport_spinbtn;
371 GtkWidget *domain_checkbtn;
372 GtkWidget *domain_entry;
373 GtkWidget *crosspost_checkbtn;
374 GtkWidget *crosspost_colormenu;
376 #ifndef G_OS_WIN32
377 GtkWidget *tunnelcmd_checkbtn;
378 GtkWidget *tunnelcmd_entry;
379 #endif
381 GtkWidget *sent_folder_checkbtn;
382 GtkWidget *sent_folder_entry;
383 GtkWidget *queue_folder_checkbtn;
384 GtkWidget *queue_folder_entry;
385 GtkWidget *draft_folder_checkbtn;
386 GtkWidget *draft_folder_entry;
387 GtkWidget *trash_folder_checkbtn;
388 GtkWidget *trash_folder_entry;
389 } AdvancedPage;
391 static BasicPage basic_page;
392 static ReceivePage receive_page;
393 static SendPage send_page;
394 #ifdef USE_OAUTH2
395 static Oauth2Page oauth2_page;
396 #endif
397 static ComposePage compose_page;
398 static TemplatesPage templates_page;
399 static PrivacyPage privacy_page;
400 #ifdef USE_GNUTLS
401 static SSLPage ssl_page;
402 #endif
403 static ProxyPage proxy_page;
404 static AdvancedPage advanced_page;
406 struct BasicProtocol {
407 GtkWidget *combobox;
408 GtkWidget *label;
409 GtkWidget *descrlabel;
410 GtkWidget *no_imap_warn_icon;
411 GtkWidget *no_imap_warn_label;
414 static char *protocol_names[] = {
415 N_("POP"),
416 N_("IMAP"),
417 N_("News (NNTP)"),
418 N_("Local mbox file"),
419 N_("None (SMTP only)")
422 #ifdef USE_OAUTH2
423 struct Oauth2Listener {
424 int success;
425 Oauth2Service service;
426 OAUTH2Data *OAUTH2Data;
427 gchar *trim_text;
429 #endif
431 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam);
432 static void prefs_account_protocol_set_optmenu (PrefParam *pparam);
433 static void prefs_account_protocol_changed (GtkComboBox *combobox, gpointer data);
435 static void prefs_account_set_string_from_combobox (PrefParam *pparam);
436 static void prefs_account_set_privacy_combobox_from_string (PrefParam *pparam);
438 static void prefs_account_imap_auth_type_set_data_from_optmenu (PrefParam *pparam);
439 static void prefs_account_imap_auth_type_set_optmenu (PrefParam *pparam);
440 static void prefs_account_smtp_auth_type_set_data_from_optmenu (PrefParam *pparam);
441 static void prefs_account_smtp_auth_type_set_optmenu (PrefParam *pparam);
442 static void prefs_account_pop_auth_type_set_data_from_optmenu (PrefParam *pparam);
443 static void prefs_account_pop_auth_type_set_optmenu (PrefParam *pparam);
444 #ifdef USE_OAUTH2
445 static void prefs_account_oauth2_provider_set_data_from_optmenu (PrefParam *pparam);
446 static void prefs_account_oauth2_provider_set_optmenu (PrefParam *pparam);
447 static void prefs_account_oauth2_copy_url (GtkButton *button, gpointer data);
448 static void prefs_account_oauth2_listener(GTask *task, gpointer source, gpointer task_data, GCancellable *cancellable);
449 static void prefs_account_oauth2_callback(GObject *source, GAsyncResult *res, gpointer user_data);
450 static int prefs_account_oauth2_get_line(int sock, char *buf, int size);
451 static void prefs_account_oauth2_set_sensitivity(void);
452 static void prefs_account_oauth2_set_auth_sensitivity(void);
453 static void prefs_account_oauth2_obtain_tokens(GtkButton *button, gpointer data);
454 #endif
455 static void prefs_account_set_autochk_interval_from_widgets(PrefParam *pparam);
456 static void prefs_account_set_autochk_interval_to_widgets(PrefParam *pparam);
458 static void prefs_account_enum_set_data_from_radiobtn (PrefParam *pparam);
459 static void prefs_account_enum_set_radiobtn (PrefParam *pparam);
461 static void crosspost_color_toggled(void);
462 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam);
463 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam);
465 static void prefs_account_nntpauth_toggled(GtkToggleButton *button, gpointer user_data);
466 static void prefs_account_mailcmd_toggled(GtkToggleButton *button, gpointer user_data);
467 static void prefs_account_showpwd_checkbtn_toggled(GtkToggleButton *button, gpointer user_data);
468 static void prefs_account_entry_changed_newline_check_cb(GtkWidget *entry, gpointer user_data);
469 static void prefs_account_filter_on_recv_toggled(GtkToggleButton *button, gpointer user_data);
471 #if USE_ENCHANT
472 static void prefs_account_compose_default_dictionary_set_string_from_optmenu (PrefParam *pparam);
473 static void prefs_account_compose_default_dictionary_set_optmenu_from_string (PrefParam *pparam);
474 #endif
476 static gchar *privacy_prefs;
478 static PrefParam basic_param[] = {
479 {"account_name", NULL, &tmp_ac_prefs.account_name, P_STRING,
480 &basic_page.acname_entry, prefs_set_data_from_entry, prefs_set_entry},
482 {"is_default", "FALSE", &tmp_ac_prefs.is_default, P_BOOL,
483 &basic_page.default_checkbtn,
484 prefs_set_data_from_toggle, prefs_set_toggle},
486 {"name", NULL, &tmp_ac_prefs.name, P_STRING,
487 &basic_page.name_entry, prefs_set_data_from_entry, prefs_set_entry},
489 {"address", NULL, &tmp_ac_prefs.address, P_STRING,
490 &basic_page.addr_entry, prefs_set_data_from_entry, prefs_set_entry},
492 {"organization", NULL, &tmp_ac_prefs.organization, P_STRING,
493 &basic_page.org_entry, prefs_set_data_from_entry, prefs_set_entry},
495 {"protocol", NULL, &tmp_ac_prefs.protocol, P_ENUM,
496 (GtkWidget **)&basic_page.protocol_optmenu,
497 prefs_account_protocol_set_data_from_optmenu,
498 prefs_account_protocol_set_optmenu},
500 {"receive_server", NULL, &tmp_ac_prefs.recv_server, P_STRING,
501 &basic_page.recvserv_entry, prefs_set_data_from_entry, prefs_set_entry},
503 {"smtp_server", NULL, &tmp_ac_prefs.smtp_server, P_STRING,
504 &basic_page.smtpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
506 {"nntp_server", NULL, &tmp_ac_prefs.nntp_server, P_STRING,
507 &basic_page.nntpserv_entry, prefs_set_data_from_entry, prefs_set_entry},
509 {"local_mbox", "/var/mail", &tmp_ac_prefs.local_mbox, P_STRING,
510 &basic_page.localmbox_entry, prefs_set_data_from_entry, prefs_set_entry},
512 {"use_mail_command", "FALSE", &tmp_ac_prefs.use_mail_command, P_BOOL,
513 &basic_page.mailcmd_checkbtn, prefs_set_data_from_toggle, prefs_set_toggle},
515 {"mail_command", DEFAULT_SENDMAIL_CMD, &tmp_ac_prefs.mail_command, P_STRING,
516 &basic_page.mailcmd_entry, prefs_set_data_from_entry, prefs_set_entry},
518 {"use_nntp_auth", "FALSE", &tmp_ac_prefs.use_nntp_auth, P_BOOL,
519 &basic_page.nntpauth_checkbtn,
520 prefs_set_data_from_toggle, prefs_set_toggle},
522 {"use_nntp_auth_onconnect", "FALSE", &tmp_ac_prefs.use_nntp_auth_onconnect, P_BOOL,
523 &basic_page.nntpauth_onconnect_checkbtn,
524 prefs_set_data_from_toggle, prefs_set_toggle},
526 {"user_id", NULL, &tmp_ac_prefs.userid, P_STRING,
527 &basic_page.uid_entry, prefs_set_data_from_entry, prefs_set_entry},
529 {"password", NULL, &tmp_ac_prefs.passwd, P_PASSWORD,
530 NULL, NULL, NULL},
532 {"config_version", "-1", &tmp_ac_prefs.config_version, P_INT,
533 NULL, NULL, NULL},
535 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
538 static PrefParam receive_param[] = {
539 {"use_apop_auth", "FALSE", &tmp_ac_prefs.use_apop_auth, P_BOOL,
540 NULL, NULL}, /* deprecated */
542 {"use_pop_auth", "FALSE", &tmp_ac_prefs.use_pop_auth, P_BOOL,
543 &receive_page.pop_auth_checkbtn,
544 prefs_set_data_from_toggle, prefs_set_toggle},
546 {"pop_auth_method", "0", &tmp_ac_prefs.pop_auth_type, P_ENUM,
547 &receive_page.pop_auth_type_optmenu,
548 prefs_account_pop_auth_type_set_data_from_optmenu,
549 prefs_account_pop_auth_type_set_optmenu},
551 {"remove_mail", "TRUE", &tmp_ac_prefs.rmmail, P_BOOL,
552 &receive_page.rmmail_checkbtn,
553 prefs_set_data_from_toggle, prefs_set_toggle},
555 #ifndef GENERIC_UMPC
556 {"message_leave_time", "7", &tmp_ac_prefs.msg_leave_time, P_INT,
557 &receive_page.leave_time_spinbtn,
558 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
559 #else
560 {"message_leave_time", "30", &tmp_ac_prefs.msg_leave_time, P_INT,
561 &receive_page.leave_time_spinbtn,
562 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
563 #endif
564 {"message_leave_hour", "0", &tmp_ac_prefs.msg_leave_hour, P_INT,
565 &receive_page.leave_hour_spinbtn,
566 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
568 {"enable_size_limit", "FALSE", &tmp_ac_prefs.enable_size_limit, P_BOOL,
569 &receive_page.size_limit_checkbtn,
570 prefs_set_data_from_toggle, prefs_set_toggle},
571 {"size_limit", "1024", &tmp_ac_prefs.size_limit, P_INT,
572 &receive_page.size_limit_spinbtn,
573 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
575 {"filter_on_receive", "TRUE", &tmp_ac_prefs.filter_on_recv, P_BOOL,
576 &receive_page.filter_on_recv_checkbtn,
577 prefs_set_data_from_toggle, prefs_set_toggle},
579 {"filterhook_on_receive", "TRUE", &tmp_ac_prefs.filterhook_on_recv, P_BOOL,
580 &receive_page.filterhook_on_recv_checkbtn,
581 prefs_set_data_from_toggle, prefs_set_toggle},
583 {"imap_auth_method", "0", &tmp_ac_prefs.imap_auth_type, P_ENUM,
584 &receive_page.imap_auth_type_optmenu,
585 prefs_account_imap_auth_type_set_data_from_optmenu,
586 prefs_account_imap_auth_type_set_optmenu},
588 {"receive_at_get_all", "TRUE", &tmp_ac_prefs.recv_at_getall, P_BOOL,
589 &receive_page.recvatgetall_checkbtn,
590 prefs_set_data_from_toggle, prefs_set_toggle},
592 {"max_news_articles", "300", &tmp_ac_prefs.max_articles, P_INT,
593 &receive_page.maxarticle_spinbtn,
594 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
596 {"inbox", "#mh/Mailbox/inbox", &tmp_ac_prefs.inbox, P_STRING,
597 &receive_page.inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
599 {"local_inbox", "#mh/Mailbox/inbox", &tmp_ac_prefs.local_inbox, P_STRING,
600 &receive_page.local_inbox_entry, prefs_set_data_from_entry, prefs_set_entry},
602 {"imap_directory", NULL, &tmp_ac_prefs.imap_dir, P_STRING,
603 &receive_page.imapdir_entry, prefs_set_data_from_entry, prefs_set_entry},
605 {"imap_subsonly", "TRUE", &tmp_ac_prefs.imap_subsonly, P_BOOL,
606 &receive_page.subsonly_checkbtn,
607 prefs_set_data_from_toggle, prefs_set_toggle},
609 {"low_bandwidth", "FALSE", &tmp_ac_prefs.low_bandwidth, P_BOOL,
610 &receive_page.low_bandwidth_checkbtn,
611 prefs_set_data_from_toggle, prefs_set_toggle},
613 {"imap_batch_size", "500", &tmp_ac_prefs.imap_batch_size, P_INT,
614 &receive_page.imap_batch_size_spinbtn,
615 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
617 {"autochk_use_default", "TRUE", &tmp_ac_prefs.autochk_use_default, P_BOOL,
618 &receive_page.autochk_use_default_checkbtn,
619 prefs_set_data_from_toggle, prefs_set_toggle},
621 {"autochk_use_custom", "FALSE", &tmp_ac_prefs.autochk_use_custom, P_BOOL,
622 &receive_page.autochk_checkbtn,
623 prefs_set_data_from_toggle, prefs_set_toggle},
625 /* Here we lie a bit, passing a pointer to our custom struct,
626 * disguised as a GtkWidget pointer, to get around the
627 * inflexibility of PrefParam system. */
628 {"autochk_interval", "600", &tmp_ac_prefs.autochk_itv, P_INT,
629 (GtkWidget **)&receive_page.autochk_widgets,
630 prefs_account_set_autochk_interval_from_widgets,
631 prefs_account_set_autochk_interval_to_widgets},
633 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
636 static PrefParam send_param[] = {
637 {"generate_msgid", "TRUE", &tmp_ac_prefs.gen_msgid, P_BOOL,
638 &send_page.msgid_checkbtn,
639 prefs_set_data_from_toggle, prefs_set_toggle},
641 {"generate_xmailer", "TRUE", &tmp_ac_prefs.gen_xmailer, P_BOOL,
642 &send_page.xmailer_checkbtn,
643 prefs_set_data_from_toggle, prefs_set_toggle},
645 {"add_custom_header", "FALSE", &tmp_ac_prefs.add_customhdr, P_BOOL,
646 &send_page.customhdr_checkbtn,
647 prefs_set_data_from_toggle, prefs_set_toggle},
649 {"msgid_with_addr", "FALSE", &tmp_ac_prefs.msgid_with_addr, P_BOOL,
650 &send_page.msgid_with_addr_checkbtn,
651 prefs_set_data_from_toggle, prefs_set_toggle},
653 {"use_smtp_auth", "FALSE", &tmp_ac_prefs.use_smtp_auth, P_BOOL,
654 &send_page.smtp_auth_checkbtn,
655 prefs_set_data_from_toggle, prefs_set_toggle},
657 {"smtp_auth_method", "0", &tmp_ac_prefs.smtp_auth_type, P_ENUM,
658 &send_page.smtp_auth_type_optmenu,
659 prefs_account_smtp_auth_type_set_data_from_optmenu,
660 prefs_account_smtp_auth_type_set_optmenu},
662 {"smtp_user_id", NULL, &tmp_ac_prefs.smtp_userid, P_STRING,
663 &send_page.smtp_uid_entry, prefs_set_data_from_entry, prefs_set_entry},
664 {"smtp_password", NULL, &tmp_ac_prefs.smtp_passwd, P_PASSWORD,
665 NULL, NULL, NULL},
667 {"pop_before_smtp", "FALSE", &tmp_ac_prefs.pop_before_smtp, P_BOOL,
668 &send_page.pop_bfr_smtp_checkbtn,
669 prefs_set_data_from_toggle, prefs_set_toggle},
671 {"pop_before_smtp_timeout", "5", &tmp_ac_prefs.pop_before_smtp_timeout, P_INT,
672 &send_page.pop_bfr_smtp_tm_spinbtn,
673 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
675 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
678 static PrefParam oauth2_param[] = {
679 #ifdef USE_OAUTH2
680 {"oauth2_auth_provider", "0", &tmp_ac_prefs.oauth2_provider, P_ENUM,
681 &oauth2_page.oauth2_auth_optmenu,
682 prefs_account_oauth2_provider_set_data_from_optmenu,
683 prefs_account_oauth2_provider_set_optmenu},
685 {"oauth2_date", 0, &tmp_ac_prefs.oauth2_date, P_INT,
686 NULL, NULL, NULL},
688 {"oauth2_authcode", NULL, &tmp_ac_prefs.oauth2_authcode, P_PASSWORD,
689 NULL, NULL, NULL},
691 {"oauth2_client_id", NULL, &tmp_ac_prefs.oauth2_client_id, P_STRING,
692 &oauth2_page.oauth2_client_id_entry, prefs_set_data_from_entry, prefs_set_entry},
694 {"oauth2_client_secret", NULL, &tmp_ac_prefs.oauth2_client_secret, P_STRING,
695 &oauth2_page.oauth2_client_secret_entry, prefs_set_data_from_entry, prefs_set_entry},
696 #else
697 {"oauth2_auth_provider", "0", &tmp_ac_prefs.oauth2_provider, P_ENUM,
698 NULL, NULL, NULL},
700 {"oauth2_date", 0, &tmp_ac_prefs.oauth2_date, P_INT,
701 NULL, NULL, NULL},
703 {"oauth2_authcode", NULL, &tmp_ac_prefs.oauth2_authcode, P_PASSWORD,
704 NULL, NULL, NULL},
706 {"oauth2_client_id", NULL, &tmp_ac_prefs.oauth2_client_id, P_STRING,
707 NULL, NULL, NULL},
709 {"oauth2_client_secret", NULL, &tmp_ac_prefs.oauth2_client_secret, P_STRING,
710 NULL, NULL, NULL},
712 #endif
714 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
717 static PrefParam compose_param[] = {
718 {"signature_type", "0", &tmp_ac_prefs.sig_type, P_ENUM,
719 &compose_page.sigfile_radiobtn,
720 prefs_account_enum_set_data_from_radiobtn,
721 prefs_account_enum_set_radiobtn},
722 {"signature_path", "~" G_DIR_SEPARATOR_S DEFAULT_SIGNATURE,
723 &tmp_ac_prefs.sig_path, P_STRING, &compose_page.entry_sigpath,
724 prefs_set_data_from_entry, prefs_set_entry},
726 {"auto_signature", "TRUE", &tmp_ac_prefs.auto_sig, P_BOOL,
727 &compose_page.checkbtn_autosig,
728 prefs_set_data_from_toggle, prefs_set_toggle},
730 {"signature_separator", "-- ", &tmp_ac_prefs.sig_sep, P_STRING,
731 &compose_page.entry_sigsep,
732 prefs_set_data_from_entry, prefs_set_entry},
734 {"set_autocc", "FALSE", &tmp_ac_prefs.set_autocc, P_BOOL,
735 &compose_page.autocc_checkbtn,
736 prefs_set_data_from_toggle, prefs_set_toggle},
738 {"auto_cc", NULL, &tmp_ac_prefs.auto_cc, P_STRING,
739 &compose_page.autocc_entry,
740 prefs_set_data_from_entry, prefs_set_entry},
742 {"set_autobcc", "FALSE", &tmp_ac_prefs.set_autobcc, P_BOOL,
743 &compose_page.autobcc_checkbtn,
744 prefs_set_data_from_toggle, prefs_set_toggle},
746 {"auto_bcc", NULL, &tmp_ac_prefs.auto_bcc, P_STRING,
747 &compose_page.autobcc_entry,
748 prefs_set_data_from_entry, prefs_set_entry},
750 {"set_autoreplyto", "FALSE", &tmp_ac_prefs.set_autoreplyto, P_BOOL,
751 &compose_page.autoreplyto_checkbtn,
752 prefs_set_data_from_toggle, prefs_set_toggle},
754 {"auto_replyto", NULL, &tmp_ac_prefs.auto_replyto, P_STRING,
755 &compose_page.autoreplyto_entry,
756 prefs_set_data_from_entry, prefs_set_entry},
758 #if USE_ENCHANT
759 {"enable_default_dictionary", "", &tmp_ac_prefs.enable_default_dictionary, P_BOOL,
760 &compose_page.checkbtn_enable_default_dictionary,
761 prefs_set_data_from_toggle, prefs_set_toggle},
763 {"default_dictionary", NULL, &tmp_ac_prefs.default_dictionary, P_STRING,
764 &compose_page.combo_default_dictionary,
765 prefs_account_compose_default_dictionary_set_string_from_optmenu,
766 prefs_account_compose_default_dictionary_set_optmenu_from_string},
768 {"enable_default_alt_dictionary", "", &tmp_ac_prefs.enable_default_alt_dictionary, P_BOOL,
769 &compose_page.checkbtn_enable_default_alt_dictionary,
770 prefs_set_data_from_toggle, prefs_set_toggle},
772 {"default_alt_dictionary", NULL, &tmp_ac_prefs.default_alt_dictionary, P_STRING,
773 &compose_page.combo_default_alt_dictionary,
774 prefs_account_compose_default_dictionary_set_string_from_optmenu,
775 prefs_account_compose_default_dictionary_set_optmenu_from_string},
776 #else
777 {"enable_default_dictionary", "", &tmp_ac_prefs.enable_default_dictionary, P_BOOL,
778 NULL, NULL, NULL},
780 {"default_dictionary", NULL, &tmp_ac_prefs.default_dictionary, P_STRING,
781 NULL, NULL, NULL},
783 {"enable_default_alt_dictionary", "", &tmp_ac_prefs.enable_default_alt_dictionary, P_BOOL,
784 NULL, NULL, NULL},
786 {"default_alt_dictionary", NULL, &tmp_ac_prefs.default_alt_dictionary, P_STRING,
787 NULL, NULL, NULL},
788 #endif
790 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
793 static PrefParam templates_param[] = {
794 {"compose_with_format", "FALSE", &tmp_ac_prefs.compose_with_format, P_BOOL,
795 &templates_page.checkbtn_compose_with_format,
796 prefs_set_data_from_toggle, prefs_set_toggle},
798 {"compose_subject_format", NULL, &tmp_ac_prefs.compose_subject_format, P_STRING,
799 &templates_page.compose_subject_format,
800 prefs_set_escaped_data_from_entry, prefs_set_entry_from_escaped},
802 {"compose_body_format", NULL, &tmp_ac_prefs.compose_body_format, P_STRING,
803 &templates_page.compose_body_format,
804 prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
806 {"reply_with_format", "FALSE", &tmp_ac_prefs.reply_with_format, P_BOOL,
807 &templates_page.checkbtn_reply_with_format,
808 prefs_set_data_from_toggle, prefs_set_toggle},
810 {"reply_quotemark", NULL, &tmp_ac_prefs.reply_quotemark, P_STRING,
811 &templates_page.reply_quotemark,
812 prefs_set_data_from_entry, prefs_set_entry_from_escaped},
814 {"reply_body_format", NULL, &tmp_ac_prefs.reply_body_format, P_STRING,
815 &templates_page.reply_body_format,
816 prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
818 {"forward_with_format", "FALSE", &tmp_ac_prefs.forward_with_format, P_BOOL,
819 &templates_page.checkbtn_forward_with_format,
820 prefs_set_data_from_toggle, prefs_set_toggle},
822 {"forward_quotemark", NULL, &tmp_ac_prefs.forward_quotemark, P_STRING,
823 &templates_page.forward_quotemark,
824 prefs_set_data_from_entry, prefs_set_entry_from_escaped},
826 {"forward_body_format", NULL, &tmp_ac_prefs.forward_body_format, P_STRING,
827 &templates_page.forward_body_format,
828 prefs_set_escaped_data_from_text, prefs_set_text_from_escaped},
830 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
833 static PrefParam privacy_param[] = {
834 {"default_privacy_system", "", &tmp_ac_prefs.default_privacy_system, P_STRING,
835 &privacy_page.default_privacy_system,
836 prefs_account_set_string_from_combobox,
837 prefs_account_set_privacy_combobox_from_string},
839 {"default_encrypt", "FALSE", &tmp_ac_prefs.default_encrypt, P_BOOL,
840 &privacy_page.default_encrypt_checkbtn,
841 prefs_set_data_from_toggle, prefs_set_toggle},
843 {"default_encrypt_reply", "TRUE", &tmp_ac_prefs.default_encrypt_reply, P_BOOL,
844 &privacy_page.default_encrypt_reply_checkbtn,
845 prefs_set_data_from_toggle, prefs_set_toggle},
847 {"default_sign", "FALSE", &tmp_ac_prefs.default_sign, P_BOOL,
848 &privacy_page.default_sign_checkbtn,
849 prefs_set_data_from_toggle, prefs_set_toggle},
850 #ifdef G_OS_UNIX
851 {"default_sign_reply", "TRUE", &tmp_ac_prefs.default_sign_reply, P_BOOL,
852 &privacy_page.default_sign_reply_checkbtn,
853 prefs_set_data_from_toggle, prefs_set_toggle},
854 #else
855 /* Bug 2367: disturbing for Win32 users with no keypair */
856 {"default_sign_reply", "FALSE", &tmp_ac_prefs.default_sign_reply, P_BOOL,
857 &privacy_page.default_sign_reply_checkbtn,
858 prefs_set_data_from_toggle, prefs_set_toggle},
859 #endif
860 {"save_clear_text", "FALSE", &tmp_ac_prefs.save_encrypted_as_clear_text, P_BOOL,
861 &privacy_page.save_clear_text_checkbtn,
862 prefs_set_data_from_toggle, prefs_set_toggle},
864 {"encrypt_to_self", "FALSE", &tmp_ac_prefs.encrypt_to_self, P_BOOL,
865 &privacy_page.encrypt_to_self_checkbtn,
866 prefs_set_data_from_toggle, prefs_set_toggle},
868 {"privacy_prefs", "", &privacy_prefs, P_STRING,
869 NULL, NULL, NULL},
871 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
874 static PrefParam ssl_param[] = {
875 #ifdef USE_GNUTLS
876 {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
877 &ssl_page.pop_nossl_radiobtn,
878 prefs_account_enum_set_data_from_radiobtn,
879 prefs_account_enum_set_radiobtn},
881 {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
882 &ssl_page.imap_nossl_radiobtn,
883 prefs_account_enum_set_data_from_radiobtn,
884 prefs_account_enum_set_radiobtn},
886 {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
887 &ssl_page.nntp_nossl_radiobtn,
888 prefs_account_enum_set_data_from_radiobtn,
889 prefs_account_enum_set_radiobtn},
891 {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
892 &ssl_page.smtp_nossl_radiobtn,
893 prefs_account_enum_set_data_from_radiobtn,
894 prefs_account_enum_set_radiobtn},
896 {"ssl_certs_auto_accept", "0", &tmp_ac_prefs.ssl_certs_auto_accept, P_BOOL,
897 &ssl_page.ssl_certs_auto_accept_checkbtn,
898 prefs_set_data_from_toggle, prefs_set_toggle},
900 {"use_nonblocking_ssl", "1", &tmp_ac_prefs.use_nonblocking_ssl, P_BOOL,
901 &ssl_page.use_nonblocking_ssl_checkbtn,
902 prefs_set_data_from_toggle, prefs_set_toggle},
904 {"use_tls_sni", "1", &tmp_ac_prefs.use_tls_sni, P_BOOL,
905 NULL, NULL, NULL},
907 {"in_ssl_client_cert_file", "", &tmp_ac_prefs.in_ssl_client_cert_file, P_STRING,
908 &ssl_page.entry_in_cert_file, prefs_set_data_from_entry, prefs_set_entry},
910 {"in_ssl_client_cert_pass", "", &tmp_ac_prefs.in_ssl_client_cert_pass, P_PASSWORD,
911 NULL, NULL, NULL},
913 {"out_ssl_client_cert_file", "", &tmp_ac_prefs.out_ssl_client_cert_file, P_STRING,
914 &ssl_page.entry_out_cert_file, prefs_set_data_from_entry, prefs_set_entry},
916 {"out_ssl_client_cert_pass", "", &tmp_ac_prefs.out_ssl_client_cert_pass, P_PASSWORD,
917 NULL, NULL, NULL},
918 #else
919 {"ssl_pop", "0", &tmp_ac_prefs.ssl_pop, P_ENUM,
920 NULL, NULL, NULL},
922 {"ssl_imap", "0", &tmp_ac_prefs.ssl_imap, P_ENUM,
923 NULL, NULL, NULL},
925 {"ssl_nntp", "0", &tmp_ac_prefs.ssl_nntp, P_ENUM,
926 NULL, NULL, NULL},
928 {"ssl_smtp", "0", &tmp_ac_prefs.ssl_smtp, P_ENUM,
929 NULL, NULL, NULL},
931 {"in_ssl_client_cert_file", "", &tmp_ac_prefs.in_ssl_client_cert_file, P_STRING,
932 NULL, NULL, NULL},
934 {"in_ssl_client_cert_pass", "", &tmp_ac_prefs.in_ssl_client_cert_pass, P_PASSWORD,
935 NULL, NULL, NULL},
937 {"out_ssl_client_cert_file", "", &tmp_ac_prefs.out_ssl_client_cert_file, P_STRING,
938 NULL, NULL, NULL},
940 {"out_ssl_client_cert_pass", "", &tmp_ac_prefs.out_ssl_client_cert_pass, P_PASSWORD,
941 NULL, NULL, NULL},
943 {"ssl_certs_auto_accept", "0", &tmp_ac_prefs.ssl_certs_auto_accept, P_BOOL,
944 NULL, NULL, NULL},
946 {"use_nonblocking_ssl", "1", &tmp_ac_prefs.use_nonblocking_ssl, P_BOOL,
947 NULL, NULL, NULL},
948 #endif /* USE_GNUTLS */
950 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
953 static PrefParam proxy_param[] = {
954 /* SOCKS proxy */
955 {"use_proxy", "FALSE", &tmp_ac_prefs.use_proxy, P_BOOL,
956 &proxy_page.proxy_checkbtn,
957 prefs_set_data_from_toggle, prefs_set_toggle},
959 {"use_default_proxy", "TRUE", &tmp_ac_prefs.use_default_proxy, P_BOOL,
960 &proxy_page.default_proxy_checkbtn,
961 prefs_set_data_from_toggle, prefs_set_toggle},
963 {"use_proxy_for_send", "TRUE", &tmp_ac_prefs.use_proxy_for_send, P_BOOL,
964 &proxy_page.proxy_send_checkbtn,
965 prefs_set_data_from_toggle, prefs_set_toggle},
967 {"proxy_type", "1", &tmp_ac_prefs.proxy_info.proxy_type, P_ENUM,
968 &proxy_page.socks4_radiobtn,
969 prefs_account_enum_set_data_from_radiobtn,
970 prefs_account_enum_set_radiobtn},
972 {"proxy_host", "localhost", &tmp_ac_prefs.proxy_info.proxy_host, P_STRING,
973 &proxy_page.proxy_host_entry,
974 prefs_set_data_from_entry, prefs_set_entry},
976 {"proxy_port", "1080", &tmp_ac_prefs.proxy_info.proxy_port, P_USHORT,
977 &proxy_page.proxy_port_spinbtn,
978 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
980 {"use_proxy_auth", "FALSE", &tmp_ac_prefs.proxy_info.use_proxy_auth, P_BOOL,
981 &proxy_page.proxy_auth_checkbtn,
982 prefs_set_data_from_toggle, prefs_set_toggle},
984 {"proxy_name", "", &tmp_ac_prefs.proxy_info.proxy_name, P_STRING,
985 &proxy_page.proxy_name_entry,
986 prefs_set_data_from_entry, prefs_set_entry},
988 {"proxy_pass", NULL, &tmp_ac_prefs.proxy_info.proxy_pass, P_PASSWORD,
989 NULL, NULL, NULL},
992 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
995 static PrefParam advanced_param[] = {
996 {"set_smtpport", "FALSE", &tmp_ac_prefs.set_smtpport, P_BOOL,
997 &advanced_page.smtpport_checkbtn,
998 prefs_set_data_from_toggle, prefs_set_toggle},
1000 {"smtp_port", "25", &tmp_ac_prefs.smtpport, P_USHORT,
1001 &advanced_page.smtpport_spinbtn,
1002 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
1004 {"set_popport", "FALSE", &tmp_ac_prefs.set_popport, P_BOOL,
1005 &advanced_page.popport_checkbtn,
1006 prefs_set_data_from_toggle, prefs_set_toggle},
1008 {"pop_port", "110", &tmp_ac_prefs.popport, P_USHORT,
1009 &advanced_page.popport_spinbtn,
1010 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
1012 {"set_imapport", "FALSE", &tmp_ac_prefs.set_imapport, P_BOOL,
1013 &advanced_page.imapport_checkbtn,
1014 prefs_set_data_from_toggle, prefs_set_toggle},
1016 {"imap_port", "143", &tmp_ac_prefs.imapport, P_USHORT,
1017 &advanced_page.imapport_spinbtn,
1018 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
1020 {"set_nntpport", "FALSE", &tmp_ac_prefs.set_nntpport, P_BOOL,
1021 &advanced_page.nntpport_checkbtn,
1022 prefs_set_data_from_toggle, prefs_set_toggle},
1024 {"nntp_port", "119", &tmp_ac_prefs.nntpport, P_USHORT,
1025 &advanced_page.nntpport_spinbtn,
1026 prefs_set_data_from_spinbtn, prefs_set_spinbtn},
1028 {"set_domain", "FALSE", &tmp_ac_prefs.set_domain, P_BOOL,
1029 &advanced_page.domain_checkbtn,
1030 prefs_set_data_from_toggle, prefs_set_toggle},
1032 {"domain", NULL, &tmp_ac_prefs.domain, P_STRING,
1033 &advanced_page.domain_entry,
1034 prefs_set_data_from_entry, prefs_set_entry},
1036 #ifdef USE_GNUTLS
1037 {"gnutls_set_priority", "FALSE", &tmp_ac_prefs.set_gnutls_priority, P_BOOL,
1038 NULL, NULL, NULL},
1040 {"gnutls_priority", NULL, &tmp_ac_prefs.gnutls_priority, P_STRING,
1041 NULL, NULL, NULL},
1042 #endif
1044 #ifndef G_OS_WIN32
1045 {"set_tunnelcmd", "FALSE", &tmp_ac_prefs.set_tunnelcmd, P_BOOL,
1046 &advanced_page.tunnelcmd_checkbtn,
1047 prefs_set_data_from_toggle, prefs_set_toggle},
1049 {"tunnelcmd", NULL, &tmp_ac_prefs.tunnelcmd, P_STRING,
1050 &advanced_page.tunnelcmd_entry,
1051 prefs_set_data_from_entry, prefs_set_entry},
1052 #endif
1053 {"mark_crosspost_read", "FALSE", &tmp_ac_prefs.mark_crosspost_read, P_BOOL,
1054 &advanced_page.crosspost_checkbtn,
1055 prefs_set_data_from_toggle, prefs_set_toggle},
1057 {"crosspost_color", NULL, &tmp_ac_prefs.crosspost_col, P_ENUM,
1058 &advanced_page.crosspost_colormenu,
1059 prefs_account_crosspost_set_data_from_colormenu,
1060 prefs_account_crosspost_set_colormenu},
1062 {"set_sent_folder", "FALSE", &tmp_ac_prefs.set_sent_folder, P_BOOL,
1063 &advanced_page.sent_folder_checkbtn,
1064 prefs_set_data_from_toggle, prefs_set_toggle},
1065 {"sent_folder", NULL, &tmp_ac_prefs.sent_folder, P_STRING,
1066 &advanced_page.sent_folder_entry,
1067 prefs_set_data_from_entry, prefs_set_entry},
1069 {"set_queue_folder", "FALSE", &tmp_ac_prefs.set_queue_folder, P_BOOL,
1070 &advanced_page.queue_folder_checkbtn,
1071 prefs_set_data_from_toggle, prefs_set_toggle},
1072 {"queue_folder", NULL, &tmp_ac_prefs.queue_folder, P_STRING,
1073 &advanced_page.queue_folder_entry,
1074 prefs_set_data_from_entry, prefs_set_entry},
1076 {"set_draft_folder", "FALSE", &tmp_ac_prefs.set_draft_folder, P_BOOL,
1077 &advanced_page.draft_folder_checkbtn,
1078 prefs_set_data_from_toggle, prefs_set_toggle},
1079 {"draft_folder", NULL, &tmp_ac_prefs.draft_folder, P_STRING,
1080 &advanced_page.draft_folder_entry,
1081 prefs_set_data_from_entry, prefs_set_entry},
1083 {"set_trash_folder", "FALSE", &tmp_ac_prefs.set_trash_folder, P_BOOL,
1084 &advanced_page.trash_folder_checkbtn,
1085 prefs_set_data_from_toggle, prefs_set_toggle},
1086 {"trash_folder", NULL, &tmp_ac_prefs.trash_folder, P_STRING,
1087 &advanced_page.trash_folder_entry,
1088 prefs_set_data_from_entry, prefs_set_entry},
1091 {NULL, NULL, NULL, P_OTHER, NULL, NULL, NULL}
1094 static gint prefs_account_get_new_id (void);
1096 static void prefs_account_select_folder_cb (GtkWidget *widget, gpointer data);
1098 static void prefs_account_sigfile_radiobtn_cb (GtkWidget *widget, gpointer data);
1100 static void prefs_account_sigcmd_radiobtn_cb (GtkWidget *widget, gpointer data);
1102 static void prefs_account_signature_browse_cb (GtkWidget *widget, gpointer data);
1103 #ifdef USE_GNUTLS
1104 static void prefs_account_in_cert_browse_cb (GtkWidget *widget, gpointer data);
1106 static void prefs_account_out_cert_browse_cb (GtkWidget *widget, gpointer data);
1107 #endif
1108 static void prefs_account_signature_edit_cb (GtkWidget *widget, gpointer data);
1110 static void pop_bfr_smtp_tm_set_sens (GtkWidget *widget, gpointer data);
1112 #if (defined USE_GNUTLS)
1113 static void auto_configure_cb (GtkWidget *widget, gpointer data);
1115 #endif
1116 static void prefs_account_edit_custom_header (void);
1118 static void prefs_account_receive_itv_spinbutton_value_changed_cb(GtkWidget *w, gpointer data);
1120 #define COMBOBOX_PRIVACY_PLUGIN_ID 3
1122 /* Enable/disable necessary preference widgets based on current privacy
1123 * system choice. */
1124 static void privacy_system_activated(GtkWidget *combobox)
1126 gtk_widget_set_sensitive (privacy_page.save_clear_text_checkbtn,
1127 !gtk_toggle_button_get_active(
1128 GTK_TOGGLE_BUTTON(privacy_page.encrypt_to_self_checkbtn)));
1131 /* Populate the privacy system choice combobox with valid choices */
1132 static void update_privacy_system_menu() {
1133 GtkListStore *menu;
1134 GtkTreeIter iter;
1135 GSList *system_ids, *cur;
1137 menu = GTK_LIST_STORE(gtk_combo_box_get_model(
1138 GTK_COMBO_BOX(privacy_page.default_privacy_system)));
1140 /* First add "None", as that one is always available. :) */
1141 gtk_list_store_append(menu, &iter);
1142 gtk_list_store_set(menu, &iter,
1143 COMBOBOX_TEXT, _("None"),
1144 COMBOBOX_DATA, 0,
1145 COMBOBOX_SENS, TRUE,
1146 COMBOBOX_PRIVACY_PLUGIN_ID, "",
1147 -1);
1149 /* Now go through list of available privacy systems and add an entry
1150 * for each. */
1151 system_ids = privacy_get_system_ids();
1152 for (cur = system_ids; cur != NULL; cur = g_slist_next(cur)) {
1153 gchar *id = (gchar *) cur->data;
1154 const gchar *name;
1156 name = privacy_system_get_name(id);
1157 gtk_list_store_append(menu, &iter);
1158 gtk_list_store_set(menu, &iter,
1159 COMBOBOX_TEXT, name,
1160 COMBOBOX_DATA, 1,
1161 COMBOBOX_SENS, TRUE,
1162 COMBOBOX_PRIVACY_PLUGIN_ID, id,
1163 -1);
1164 g_free(id);
1166 g_slist_free(system_ids);
1170 #define TABLE_YPAD 2
1172 static void basic_create_widget_func(PrefsPage * _page,
1173 GtkWindow * window,
1174 gpointer data)
1176 BasicPage *page = (BasicPage *) _page;
1177 PrefsAccount *ac_prefs = (PrefsAccount *) data;
1179 GtkWidget *vbox1;
1180 GtkWidget *hbox;
1181 GtkWidget *label;
1182 GtkWidget *acname_entry;
1183 GtkWidget *default_checkbtn;
1184 GtkWidget *frame1;
1185 GtkWidget *table1;
1186 GtkWidget *name_entry;
1187 GtkWidget *addr_entry;
1188 GtkWidget *org_entry;
1190 GtkWidget *serv_frame;
1191 GtkWidget *vbox2;
1192 GtkWidget *optmenubox;
1193 GtkWidget *optmenu;
1194 GtkWidget *optlabel;
1195 GtkWidget *no_imap_warn_icon;
1196 GtkWidget *no_imap_warn_label;
1197 GtkWidget *serv_table;
1198 GtkWidget *recvserv_label;
1199 GtkWidget *smtpserv_label;
1200 GtkWidget *nntpserv_label;
1201 GtkWidget *localmbox_label;
1202 GtkWidget *mailcmd_label;
1203 GtkWidget *recvserv_entry;
1204 GtkWidget *smtpserv_entry;
1205 GtkWidget *nntpserv_entry;
1206 GtkWidget *nntpauth_checkbtn;
1207 GtkWidget *nntpauth_onconnect_checkbtn;
1208 GtkWidget *localmbox_entry;
1209 GtkWidget *mailcmd_checkbtn;
1210 GtkWidget *mailcmd_entry;
1211 GtkWidget *uid_label;
1212 GtkWidget *pass_label;
1213 GtkWidget *uid_entry;
1214 GtkWidget *pass_entry;
1215 GtkWidget *auto_configure_btn;
1216 GtkWidget *auto_configure_cancel_btn;
1217 GtkWidget *auto_configure_lbl;
1218 GtkWidget *showpwd_checkbtn;
1219 GtkListStore *menu;
1220 GtkTreeIter iter;
1221 gchar *buf;
1223 struct BasicProtocol *protocol_optmenu;
1224 gint i;
1226 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
1227 gtk_widget_show (vbox1);
1228 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1230 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1231 gtk_widget_show (hbox);
1232 gtk_box_pack_start (GTK_BOX (vbox1), hbox, FALSE, FALSE, 0);
1234 label = gtk_label_new (_("Name of account"));
1235 gtk_widget_show (label);
1236 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1238 acname_entry = gtk_entry_new ();
1239 gtk_widget_show (acname_entry);
1240 gtk_widget_set_size_request (acname_entry, DEFAULT_ENTRY_WIDTH, -1);
1241 gtk_box_pack_start (GTK_BOX (hbox), acname_entry, TRUE, TRUE, 0);
1243 default_checkbtn = gtk_check_button_new_with_label (_("Set as default"));
1244 gtk_widget_show (default_checkbtn);
1245 #ifndef GENERIC_UMPC
1246 gtk_box_pack_end (GTK_BOX (hbox), default_checkbtn, TRUE, FALSE, 0);
1247 #else
1248 gtk_box_pack_start (GTK_BOX (vbox1), default_checkbtn, FALSE, FALSE, 0);
1250 #endif
1251 PACK_FRAME (vbox1, frame1, _("Personal information"));
1253 table1 = gtk_grid_new();
1254 gtk_widget_show (table1);
1255 gtk_container_add (GTK_CONTAINER (frame1), table1);
1256 gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
1257 gtk_grid_set_row_spacing(GTK_GRID(table1), VSPACING_NARROW);
1258 gtk_grid_set_column_spacing(GTK_GRID(table1), 8);
1260 label = gtk_label_new (_("Full name"));
1261 gtk_widget_show (label);
1262 gtk_label_set_xalign(GTK_LABEL (label), 1.0);
1263 gtk_grid_attach(GTK_GRID(table1), label, 0, 0, 1, 1);
1265 label = gtk_label_new (_("Mail address"));
1266 gtk_widget_show (label);
1267 gtk_label_set_xalign(GTK_LABEL (label), 1.0);
1268 gtk_grid_attach(GTK_GRID(table1), label, 0, 1, 1, 1);
1270 label = gtk_label_new (_("Organization"));
1271 gtk_widget_show (label);
1272 gtk_label_set_xalign(GTK_LABEL (label), 1.0);
1273 gtk_grid_attach(GTK_GRID(table1), label, 0, 2, 1, 1);
1275 name_entry = gtk_entry_new ();
1276 gtk_widget_show (name_entry);
1277 gtk_grid_attach(GTK_GRID(table1), name_entry, 1, 0, 1, 1);
1278 gtk_widget_set_hexpand(name_entry, TRUE);
1279 gtk_widget_set_halign(name_entry, GTK_ALIGN_FILL);
1281 addr_entry = gtk_entry_new ();
1282 gtk_widget_show (addr_entry);
1283 gtk_grid_attach(GTK_GRID(table1), addr_entry, 1, 1, 1, 1);
1284 gtk_widget_set_hexpand(addr_entry, TRUE);
1285 gtk_widget_set_halign(addr_entry, GTK_ALIGN_FILL);
1287 org_entry = gtk_entry_new ();
1288 gtk_widget_show (org_entry);
1289 gtk_grid_attach(GTK_GRID(table1), org_entry, 1, 2, 1, 1);
1290 gtk_widget_set_hexpand(org_entry, TRUE);
1291 gtk_widget_set_halign(org_entry, GTK_ALIGN_FILL);
1293 vbox2 = gtkut_get_options_frame(vbox1, &serv_frame, _("Server information"));
1295 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1296 gtk_widget_show (hbox);
1297 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
1299 label = gtk_label_new (_("Protocol"));
1300 gtk_widget_show (label);
1301 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
1303 /* Create GtkHBox for protocol combobox and label */
1304 optmenubox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 20);
1305 gtk_widget_show(optmenubox);
1306 gtk_box_pack_start (GTK_BOX (hbox), optmenubox, FALSE, FALSE, 0);
1308 /* Create and populate the combobox */
1309 optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1310 gtk_box_pack_start(GTK_BOX (optmenubox), optmenu, FALSE, FALSE, 0);
1312 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1313 for( i = 0; i < NUM_RECV_PROTOCOLS; i++ )
1314 if( protocol_names[i] != NULL )
1315 COMBOBOX_ADD (menu, _(protocol_names[i]), i);
1317 g_signal_connect(G_OBJECT(optmenu), "changed",
1318 G_CALLBACK(prefs_account_protocol_changed), NULL);
1320 /* Create protocol label, empty for now */
1321 optlabel = gtk_label_new("");
1322 gtk_label_set_use_markup(GTK_LABEL(optlabel), TRUE);
1323 gtk_label_set_justify(GTK_LABEL(optlabel), GTK_JUSTIFY_CENTER);
1324 gtk_box_pack_start(GTK_BOX (optmenubox), optlabel, FALSE, FALSE, 0);
1326 auto_configure_btn = gtk_button_new_with_label(_("Auto-configure"));
1327 gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_btn, FALSE, FALSE, 0);
1328 auto_configure_cancel_btn = gtk_button_new_with_label(_("Cancel"));
1329 gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_cancel_btn, FALSE, FALSE, 0);
1330 auto_configure_lbl = gtk_label_new("");
1331 gtk_label_set_justify(GTK_LABEL(auto_configure_lbl), GTK_JUSTIFY_LEFT);
1332 gtk_box_pack_start(GTK_BOX (optmenubox), auto_configure_lbl, FALSE, FALSE, 0);
1333 #if (defined USE_GNUTLS)
1334 gtk_widget_show(auto_configure_btn);
1335 gtk_widget_show(auto_configure_lbl);
1336 g_signal_connect (G_OBJECT (auto_configure_btn), "clicked",
1337 G_CALLBACK (auto_configure_cb), NULL);
1338 g_signal_connect (G_OBJECT (auto_configure_cancel_btn), "clicked",
1339 G_CALLBACK (auto_configure_cb), NULL);
1340 #endif
1342 no_imap_warn_icon = gtk_image_new_from_icon_name
1343 ("dialog-warning", GTK_ICON_SIZE_SMALL_TOOLBAR);
1344 buf = g_strconcat("<span weight=\"bold\">",
1345 _("Warning: this version of Claws Mail\n"
1346 "has been built without IMAP and News support."), "</span>", NULL);
1347 no_imap_warn_label = gtk_label_new(buf);
1348 g_free(buf);
1349 gtk_label_set_use_markup(GTK_LABEL(no_imap_warn_label), TRUE);
1351 gtk_box_pack_start(GTK_BOX (optmenubox), no_imap_warn_icon, FALSE, FALSE, 0);
1352 gtk_box_pack_start(GTK_BOX (optmenubox), no_imap_warn_label, FALSE, FALSE, 0);
1353 /* Set up a struct to store pointers to necessary widgets */
1354 protocol_optmenu = g_new(struct BasicProtocol, 1);
1355 protocol_optmenu->combobox = optmenu;
1356 protocol_optmenu->label = optlabel;
1357 protocol_optmenu->descrlabel = label;
1358 protocol_optmenu->no_imap_warn_icon = no_imap_warn_icon;
1359 protocol_optmenu->no_imap_warn_label = no_imap_warn_label;
1361 serv_table = gtk_grid_new ();
1362 gtk_widget_show (serv_table);
1363 gtk_grid_set_row_spacing(GTK_GRID(serv_table), VSPACING_NARROW);
1364 gtk_grid_set_column_spacing(GTK_GRID(serv_table), 8);
1365 gtk_box_pack_start (GTK_BOX (vbox2), serv_table, FALSE, FALSE, 0);
1367 nntpserv_entry = gtk_entry_new ();
1368 gtk_widget_show (nntpserv_entry);
1369 gtk_grid_attach(GTK_GRID(serv_table), nntpserv_entry, 1, 0, 2, 1);
1370 gtk_widget_set_hexpand(nntpserv_entry, TRUE);
1371 gtk_widget_set_halign(nntpserv_entry, GTK_ALIGN_FILL);
1373 nntpauth_checkbtn = gtk_check_button_new_with_label
1374 (_("This server requires authentication"));
1375 gtk_widget_show (nntpauth_checkbtn);
1377 gtk_grid_attach(GTK_GRID(serv_table), nntpauth_checkbtn, 0, 6, 2, 1);
1379 nntpauth_onconnect_checkbtn = gtk_check_button_new_with_label
1380 (_("Authenticate on connect"));
1381 gtk_widget_show (nntpauth_onconnect_checkbtn);
1383 gtk_grid_attach(GTK_GRID(serv_table), nntpauth_onconnect_checkbtn, 2, 6, 1, 1);
1385 recvserv_entry = gtk_entry_new ();
1386 gtk_widget_show (recvserv_entry);
1387 gtk_grid_attach(GTK_GRID(serv_table), recvserv_entry, 1, 2, 2, 1);
1388 gtk_widget_set_hexpand(recvserv_entry, TRUE);
1389 gtk_widget_set_halign(recvserv_entry, GTK_ALIGN_FILL);
1391 localmbox_entry = gtk_entry_new ();
1392 gtk_widget_show (localmbox_entry);
1393 gtk_grid_attach(GTK_GRID(serv_table), localmbox_entry, 1, 3, 2, 1);
1394 gtk_widget_set_hexpand(localmbox_entry, TRUE);
1395 gtk_widget_set_halign(localmbox_entry, GTK_ALIGN_FILL);
1397 smtpserv_entry = gtk_entry_new ();
1398 gtk_widget_show (smtpserv_entry);
1399 gtk_grid_attach(GTK_GRID(serv_table), smtpserv_entry, 1, 4, 2, 1);
1400 gtk_widget_set_hexpand(smtpserv_entry, TRUE);
1401 gtk_widget_set_halign(smtpserv_entry, GTK_ALIGN_FILL);
1403 mailcmd_entry = gtk_entry_new ();
1404 gtk_widget_show (mailcmd_entry);
1405 gtk_grid_attach(GTK_GRID(serv_table), mailcmd_entry, 1, 6, 2, 1);
1406 gtk_widget_set_hexpand(mailcmd_entry, TRUE);
1407 gtk_widget_set_halign(mailcmd_entry, GTK_ALIGN_FILL);
1409 uid_entry = gtk_entry_new ();
1410 gtk_widget_show (uid_entry);
1411 gtk_widget_set_size_request (uid_entry, DEFAULT_ENTRY_WIDTH, -1);
1412 gtk_grid_attach(GTK_GRID(serv_table), uid_entry, 1, 7, 1, 1);
1413 gtk_widget_set_hexpand(uid_entry, TRUE);
1414 gtk_widget_set_halign(uid_entry, GTK_ALIGN_FILL);
1415 g_signal_connect(G_OBJECT(uid_entry), "changed",
1416 G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1417 GINT_TO_POINTER(ac_prefs->protocol));
1419 pass_entry = gtk_entry_new ();
1420 gtk_widget_show (pass_entry);
1421 gtk_widget_set_size_request (pass_entry, DEFAULT_ENTRY_WIDTH, -1);
1422 gtk_grid_attach(GTK_GRID(serv_table), pass_entry, 1, 8, 1, 1);
1423 gtk_widget_set_hexpand(pass_entry, TRUE);
1424 gtk_widget_set_halign(pass_entry, GTK_ALIGN_FILL);
1425 gtk_entry_set_visibility (GTK_ENTRY (pass_entry), FALSE);
1426 g_signal_connect(G_OBJECT(pass_entry), "changed",
1427 G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
1428 GINT_TO_POINTER(ac_prefs->protocol));
1430 nntpserv_label = gtk_label_new (_("News server"));
1431 gtk_widget_show (nntpserv_label);
1432 gtk_label_set_xalign(GTK_LABEL (nntpserv_label), 1.0);
1433 gtk_grid_attach(GTK_GRID(serv_table), nntpserv_label, 0, 0, 1, 1);
1435 recvserv_label = gtk_label_new (_("Server for receiving"));
1436 gtk_widget_show (recvserv_label);
1437 gtk_label_set_xalign(GTK_LABEL (recvserv_label), 1.0);
1438 gtk_grid_attach(GTK_GRID(serv_table), recvserv_label, 0, 2, 1, 1);
1440 localmbox_label = gtk_label_new (_("Local mailbox"));
1441 gtk_widget_show (localmbox_label);
1442 gtk_label_set_xalign(GTK_LABEL (localmbox_label), 1.0);
1443 gtk_grid_attach(GTK_GRID(serv_table), localmbox_label, 0, 3, 1, 1);
1445 smtpserv_label = gtk_label_new (_("SMTP server (send)"));
1446 gtk_widget_show (smtpserv_label);
1447 gtk_label_set_xalign(GTK_LABEL (smtpserv_label), 1.0);
1448 gtk_grid_attach(GTK_GRID(serv_table), smtpserv_label, 0, 4, 1, 1);
1450 mailcmd_checkbtn = gtk_check_button_new_with_label
1451 (_("Use mail command rather than SMTP server"));
1452 gtk_widget_show (mailcmd_checkbtn);
1453 gtk_grid_attach(GTK_GRID(serv_table), mailcmd_checkbtn, 0, 5, 2, 1);
1455 g_signal_connect(G_OBJECT(mailcmd_checkbtn), "toggled",
1456 G_CALLBACK(prefs_account_mailcmd_toggled),
1457 NULL);
1459 mailcmd_label = gtk_label_new (_("command to send mails"));
1460 gtk_widget_show (mailcmd_label);
1461 gtk_label_set_xalign(GTK_LABEL (mailcmd_label), 1.0);
1462 gtk_grid_attach(GTK_GRID(serv_table), mailcmd_label, 0, 6, 1, 1);
1464 uid_label = gtk_label_new (_("User ID"));
1465 gtk_widget_show (uid_label);
1466 gtk_label_set_xalign(GTK_LABEL (uid_label), 1.0);
1467 gtk_grid_attach(GTK_GRID(serv_table), uid_label, 0, 7, 1, 1);
1469 pass_label = gtk_label_new (_("Password"));
1470 gtk_widget_show (pass_label);
1471 #ifdef GENERIC_UMPC
1472 gtk_label_set_xalign(GTK_LABEL (pass_label), 1.0);
1473 #endif
1474 gtk_grid_attach(GTK_GRID(serv_table), pass_label, 0, 8, 1, 1);
1476 showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
1477 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
1478 gtk_widget_show(showpwd_checkbtn);
1479 gtk_grid_attach(GTK_GRID(serv_table), showpwd_checkbtn, 2, 8, 1, 1);
1480 g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
1481 G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), pass_entry);
1483 SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, uid_label);
1484 SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, pass_label);
1485 SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, uid_entry);
1486 SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, pass_entry);
1487 SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, showpwd_checkbtn);
1488 SET_TOGGLE_SENSITIVITY (nntpauth_checkbtn, nntpauth_onconnect_checkbtn);
1490 page->acname_entry = acname_entry;
1491 page->default_checkbtn = default_checkbtn;
1493 page->name_entry = name_entry;
1494 page->addr_entry = addr_entry;
1495 page->org_entry = org_entry;
1497 page->serv_frame = serv_frame;
1498 page->serv_table = serv_table;
1499 page->protocol_optmenu = (gpointer)protocol_optmenu;
1500 page->recvserv_label = recvserv_label;
1501 page->recvserv_entry = recvserv_entry;
1502 page->smtpserv_label = smtpserv_label;
1503 page->smtpserv_entry = smtpserv_entry;
1504 page->nntpserv_label = nntpserv_label;
1505 page->nntpserv_entry = nntpserv_entry;
1506 page->nntpauth_checkbtn = nntpauth_checkbtn;
1507 page->nntpauth_onconnect_checkbtn = nntpauth_onconnect_checkbtn;
1508 page->localmbox_label = localmbox_label;
1509 page->localmbox_entry = localmbox_entry;
1510 page->mailcmd_checkbtn = mailcmd_checkbtn;
1511 page->mailcmd_label = mailcmd_label;
1512 page->mailcmd_entry = mailcmd_entry;
1513 page->uid_label = uid_label;
1514 page->pass_label = pass_label;
1515 page->uid_entry = uid_entry;
1516 page->pass_entry = pass_entry;
1517 page->showpwd_checkbtn = showpwd_checkbtn;
1518 page->auto_configure_btn = auto_configure_btn;
1519 page->auto_configure_cancel_btn = auto_configure_cancel_btn;
1520 page->auto_configure_lbl = auto_configure_lbl;
1522 if (new_account) {
1523 prefs_set_dialog_to_default(basic_param);
1524 buf = g_strdup_printf(_("Account%d"), ac_prefs->account_id);
1525 gtk_entry_set_text(GTK_ENTRY(basic_page.acname_entry), buf);
1526 g_free(buf);
1527 } else {
1528 prefs_set_dialog(basic_param);
1530 /* Passwords are handled outside of PrefParams. */
1531 buf = passwd_store_get_account(ac_prefs->account_id,
1532 PWS_ACCOUNT_RECV);
1533 gtk_entry_set_text(GTK_ENTRY(page->pass_entry), buf != NULL ? buf : "");
1534 if (buf != NULL) {
1535 memset(buf, 0, strlen(buf));
1536 g_free(buf);
1540 page->vbox = vbox1;
1542 page->page.widget = vbox1;
1545 static void receive_create_widget_func(PrefsPage * _page,
1546 GtkWindow * window,
1547 gpointer data)
1549 ReceivePage *page = (ReceivePage *) _page;
1550 PrefsAccount *ac_prefs = (PrefsAccount *) data;
1552 GtkWidget *vbox1, *vbox2, *vbox3, *vbox4, *vbox5;
1553 GtkWidget *hbox1, *hbox2, *hbox3;
1554 GtkWidget *frame1;
1555 GtkWidget *pop_auth_checkbtn;
1556 GtkWidget *rmmail_checkbtn;
1557 GtkWidget *hbox_spc;
1558 GtkWidget *leave_time_label;
1559 GtkWidget *leave_time_spinbtn;
1560 GtkWidget *leave_hour_label;
1561 GtkWidget *leave_hour_spinbtn;
1562 GtkWidget *size_limit_checkbtn;
1563 GtkWidget *size_limit_spinbtn;
1564 GtkWidget *label;
1565 GtkWidget *filter_on_recv_checkbtn;
1566 GtkWidget *filterhook_on_recv_checkbtn;
1567 GtkWidget *inbox_label;
1568 GtkWidget *inbox_entry;
1569 GtkWidget *inbox_btn;
1570 GtkWidget *imap_frame;
1571 GtkWidget *imapdir_label;
1572 GtkWidget *imapdir_entry;
1573 GtkWidget *subsonly_checkbtn;
1574 GtkWidget *low_bandwidth_checkbtn;
1575 GtkWidget *imap_batch_size_spinbtn;
1576 GtkWidget *local_frame;
1577 GtkWidget *local_vbox;
1578 GtkWidget *local_hbox;
1579 GtkWidget *local_inbox_label;
1580 GtkWidget *local_inbox_entry;
1581 GtkWidget *local_inbox_btn;
1582 GtkWidget *autochk_checkbtn;
1583 GtkWidget *autochk_hour_spinbtn, *autochk_hour_label;
1584 GtkWidget *autochk_min_spinbtn, *autochk_min_label;
1585 GtkWidget *autochk_sec_spinbtn, *autochk_sec_label;
1586 GtkWidget *autochk_use_default_checkbtn;
1587 GtkAdjustment *adj;
1588 struct AutocheckWidgets *autochk_widgets;
1590 GtkWidget *optmenu, *optmenu2;
1591 GtkListStore *menu, *menu2;
1592 GtkTreeIter iter;
1593 GtkWidget *recvatgetall_checkbtn;
1595 GtkWidget *frame, *frame2;
1596 GtkWidget *maxarticle_label;
1597 GtkWidget *maxarticle_spinbtn;
1598 GtkAdjustment *maxarticle_spinbtn_adj;
1600 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
1601 gtk_widget_show (vbox1);
1602 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
1604 local_vbox = gtkut_get_options_frame(vbox1, &local_frame, _("Local"));
1606 local_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1607 gtk_widget_show (local_hbox);
1608 gtk_box_pack_start (GTK_BOX (local_vbox), local_hbox, TRUE, TRUE, 0);
1610 local_inbox_label = gtk_label_new (_("Default Inbox"));
1611 gtk_widget_show (local_inbox_label);
1612 gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_label, FALSE, FALSE, 0);
1614 local_inbox_entry = gtk_entry_new ();
1615 gtk_widget_show (local_inbox_entry);
1616 CLAWS_SET_TIP(local_inbox_entry,
1617 _("Unfiltered messages will be stored in this folder"));
1618 gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_entry, TRUE, TRUE, 0);
1620 local_inbox_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
1621 gtk_widget_show (local_inbox_btn);
1622 CLAWS_SET_TIP(local_inbox_btn,
1623 _("Unfiltered messages will be stored in this folder"));
1624 gtk_box_pack_start (GTK_BOX (local_hbox), local_inbox_btn, FALSE, FALSE, 0);
1625 g_signal_connect (G_OBJECT (local_inbox_btn), "clicked",
1626 G_CALLBACK (prefs_account_select_folder_cb),
1627 local_inbox_entry);
1629 vbox2 = gtkut_get_options_frame(vbox1, &frame1, _("POP"));
1631 PACK_CHECK_BUTTON (vbox2, pop_auth_checkbtn,
1632 _("Authenticate before POP connection"));
1634 //vbox5 = gtk_vbox_new (FALSE, 0);
1635 vbox5 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 8);
1636 gtk_widget_show (vbox5);
1637 gtk_box_pack_start (GTK_BOX (vbox2), vbox5, FALSE, FALSE, 0);
1639 hbox3 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1640 gtk_widget_show (hbox3);
1641 gtk_box_pack_start (GTK_BOX (vbox5), hbox3, FALSE, FALSE, 0);
1643 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1644 gtk_widget_show (hbox_spc);
1645 gtk_box_pack_start (GTK_BOX (hbox3), hbox_spc, FALSE, FALSE, 0);
1646 gtk_widget_set_size_request (hbox_spc, 12, -1);
1648 label = gtk_label_new (_("Authentication method"));
1649 gtk_widget_show (label);
1650 gtk_box_pack_start (GTK_BOX (hbox3), label, FALSE, FALSE, 0);
1652 optmenu2 = gtkut_sc_combobox_create(NULL, FALSE);
1653 menu2 = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu2)));
1654 gtk_widget_show (optmenu2);
1655 gtk_box_pack_start (GTK_BOX (hbox3), optmenu2, FALSE, FALSE, 0);
1657 COMBOBOX_ADD (menu2, _("Select"), 0);
1658 COMBOBOX_ADD (menu2, NULL, 0);
1659 COMBOBOX_ADD (menu2, "APOP", POPAUTH_APOP);
1660 COMBOBOX_ADD (menu2, "OAuth2", POPAUTH_OAUTH2);
1661 #ifndef USE_OAUTH2
1662 gtk_list_store_set(menu2, &iter, COMBOBOX_SENS, FALSE, -1);
1663 #endif
1665 SET_TOGGLE_SENSITIVITY (pop_auth_checkbtn, vbox5);
1667 PACK_CHECK_BUTTON (vbox2, rmmail_checkbtn,
1668 _("Remove messages on server when received"));
1670 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1671 gtk_widget_show (hbox1);
1672 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1674 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
1675 gtk_widget_show (hbox_spc);
1676 gtk_box_pack_start (GTK_BOX (hbox1), hbox_spc, FALSE, FALSE, 0);
1677 gtk_widget_set_size_request (hbox_spc, 12, -1);
1679 leave_time_label = gtk_label_new (_("Remove after"));
1680 gtk_widget_show (leave_time_label);
1681 gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1683 leave_time_spinbtn = gtk_spin_button_new_with_range(0, 365, 1);
1684 gtk_widget_show (leave_time_spinbtn);
1685 CLAWS_SET_TIP(leave_time_spinbtn,
1686 _("0 days and 0 hours : remove immediately"));
1687 gtk_box_pack_start (GTK_BOX (hbox1), leave_time_spinbtn, FALSE, FALSE, 0);
1689 leave_time_label = gtk_label_new (_("days"));
1690 gtk_widget_show (leave_time_label);
1691 gtk_box_pack_start (GTK_BOX (hbox1), leave_time_label, FALSE, FALSE, 0);
1693 leave_hour_spinbtn = gtk_spin_button_new_with_range(0, 23, 1);
1694 gtk_widget_show (leave_hour_spinbtn);
1695 CLAWS_SET_TIP(leave_hour_spinbtn,
1696 _("0 days and 0 hours : remove immediately"));
1697 gtk_box_pack_start (GTK_BOX (hbox1), leave_hour_spinbtn, FALSE, FALSE, 0);
1699 leave_hour_label = gtk_label_new (_("hours"));
1700 gtk_widget_show (leave_hour_label);
1701 gtk_box_pack_start (GTK_BOX (hbox1), leave_hour_label, FALSE, FALSE, 0);
1703 SET_TOGGLE_SENSITIVITY (rmmail_checkbtn, hbox1);
1705 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1706 gtk_widget_show (hbox1);
1707 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1709 PACK_CHECK_BUTTON (hbox1, size_limit_checkbtn, _("Receive size limit"));
1711 CLAWS_SET_TIP(size_limit_checkbtn,
1712 _("Messages over this limit will be partially retrieved. "
1713 "When selecting them you will be able to download them fully "
1714 "or delete them."));
1716 size_limit_spinbtn = gtk_spin_button_new_with_range(0, 100000, 1);
1717 gtk_widget_show (size_limit_spinbtn);
1718 gtk_box_pack_start (GTK_BOX (hbox1), size_limit_spinbtn, FALSE, FALSE, 0);
1720 label = gtk_label_new (_("KiB"));
1721 gtk_widget_show (label);
1722 gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1724 SET_TOGGLE_SENSITIVITY (size_limit_checkbtn, size_limit_spinbtn);
1726 PACK_SPACER(vbox2, vbox3, VSPACING_NARROW_2);
1728 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1729 gtk_widget_show (hbox1);
1730 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, TRUE, TRUE, 0);
1732 inbox_label = gtk_label_new (_("Default Inbox"));
1733 gtk_widget_show (inbox_label);
1734 gtk_box_pack_start (GTK_BOX (hbox1), inbox_label, FALSE, FALSE, 0);
1736 inbox_entry = gtk_entry_new ();
1737 gtk_widget_show (inbox_entry);
1738 CLAWS_SET_TIP(inbox_entry,
1739 _("Unfiltered messages will be stored in this folder"));
1740 gtk_box_pack_start (GTK_BOX (hbox1), inbox_entry, TRUE, TRUE, 0);
1742 inbox_btn = gtkut_get_browse_file_btn(_("Bro_wse"));
1743 gtk_widget_show (inbox_btn);
1744 CLAWS_SET_TIP(inbox_btn,
1745 _("Unfiltered messages will be stored in this folder"));
1746 gtk_box_pack_start (GTK_BOX (hbox1), inbox_btn, FALSE, FALSE, 0);
1747 g_signal_connect (G_OBJECT (inbox_btn), "clicked",
1748 G_CALLBACK (prefs_account_select_folder_cb),
1749 inbox_entry);
1751 vbox2 = gtkut_get_options_frame(vbox1, &frame2, _("NNTP"));
1753 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1754 gtk_widget_show (hbox2);
1755 gtk_box_pack_start (GTK_BOX (vbox2), hbox2, FALSE, FALSE, 0);
1757 maxarticle_label = gtk_label_new
1758 (_("Maximum number of articles to download"));
1759 gtk_widget_show (maxarticle_label);
1760 gtk_box_pack_start (GTK_BOX (hbox2), maxarticle_label, FALSE, FALSE, 0);
1762 maxarticle_spinbtn_adj =
1763 GTK_ADJUSTMENT(gtk_adjustment_new (300, 0, 10000, 10, 100, 0));
1764 maxarticle_spinbtn = gtk_spin_button_new
1765 (GTK_ADJUSTMENT (maxarticle_spinbtn_adj), 10, 0);
1766 gtk_widget_show (maxarticle_spinbtn);
1767 CLAWS_SET_TIP(maxarticle_spinbtn,
1768 _("unlimited if 0 is specified"));
1769 gtk_box_pack_start (GTK_BOX (hbox2), maxarticle_spinbtn,
1770 FALSE, FALSE, 0);
1771 gtk_widget_set_size_request (maxarticle_spinbtn, 64, -1);
1772 gtk_spin_button_set_numeric
1773 (GTK_SPIN_BUTTON (maxarticle_spinbtn), TRUE);
1775 vbox2 = gtkut_get_options_frame(vbox1, &imap_frame, _("IMAP"));
1777 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1778 gtk_widget_show (hbox1);
1779 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 0);
1781 label = gtk_label_new (_("Authentication method"));
1782 gtk_widget_show (label);
1783 gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
1786 optmenu = gtkut_sc_combobox_create(NULL, FALSE);
1787 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
1788 gtk_widget_show (optmenu);
1789 gtk_box_pack_start (GTK_BOX (hbox1), optmenu, FALSE, FALSE, 0);
1791 COMBOBOX_ADD (menu, _("Automatic"), 0);
1792 COMBOBOX_ADD (menu, NULL, 0);
1793 COMBOBOX_ADD (menu, _("Plain text"), IMAP_AUTH_PLAINTEXT);
1794 COMBOBOX_ADD (menu, "CRAM-MD5", IMAP_AUTH_CRAM_MD5);
1795 COMBOBOX_ADD (menu, "ANONYMOUS", IMAP_AUTH_ANON);
1796 COMBOBOX_ADD (menu, "GSSAPI", IMAP_AUTH_GSSAPI);
1797 COMBOBOX_ADD (menu, "DIGEST-MD5", IMAP_AUTH_DIGEST_MD5);
1798 COMBOBOX_ADD (menu, "SCRAM-SHA-1", IMAP_AUTH_SCRAM_SHA1);
1799 COMBOBOX_ADD (menu, "SCRAM-SHA-224", IMAP_AUTH_SCRAM_SHA224);
1800 COMBOBOX_ADD (menu, "SCRAM-SHA-256", IMAP_AUTH_SCRAM_SHA256);
1801 COMBOBOX_ADD (menu, "SCRAM-SHA-384", IMAP_AUTH_SCRAM_SHA384);
1802 COMBOBOX_ADD (menu, "SCRAM-SHA-512", IMAP_AUTH_SCRAM_SHA512);
1803 COMBOBOX_ADD (menu, "PLAIN", IMAP_AUTH_PLAIN);
1804 COMBOBOX_ADD (menu, "LOGIN", IMAP_AUTH_LOGIN);
1805 COMBOBOX_ADD (menu, "OAUTH2", IMAP_AUTH_OAUTH2);
1806 #ifndef USE_OAUTH2
1807 gtk_list_store_set(menu, &iter, COMBOBOX_SENS, FALSE, -1);
1808 #endif
1810 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1811 gtk_widget_show (hbox1);
1812 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1814 imapdir_label = gtk_label_new (_("IMAP server directory"));
1815 gtk_widget_show (imapdir_label);
1816 gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1818 imapdir_label = gtk_label_new(_("(usually empty)"));
1819 gtk_widget_show (imapdir_label);
1820 gtkut_widget_set_small_font_size (imapdir_label);
1821 gtk_box_pack_start (GTK_BOX (hbox1), imapdir_label, FALSE, FALSE, 0);
1823 imapdir_entry = gtk_entry_new();
1824 gtk_widget_show (imapdir_entry);
1825 gtk_box_pack_start (GTK_BOX (hbox1), imapdir_entry, FALSE, FALSE, 0);
1827 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1828 gtk_widget_show (hbox1);
1829 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1831 PACK_CHECK_BUTTON (hbox1, subsonly_checkbtn,
1832 _("Show subscribed folders only"));
1834 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1835 gtk_widget_show (hbox1);
1836 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1838 PACK_CHECK_BUTTON (hbox1, low_bandwidth_checkbtn,
1839 _("Bandwidth-efficient mode (prevents retrieving remote tags)"));
1840 CLAWS_SET_TIP(low_bandwidth_checkbtn,
1841 _("This mode uses less bandwidth, but can be slower with some servers."));
1843 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1844 gtk_widget_show (hbox1);
1845 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1847 label = gtk_label_new(_("Batch size"));
1848 gtk_widget_show (label);
1849 gtk_box_pack_start(GTK_BOX(hbox1), label, FALSE, FALSE, 0);
1851 imap_batch_size_spinbtn = gtk_spin_button_new_with_range(0, 1000000, 1);
1852 gtk_widget_set_size_request(imap_batch_size_spinbtn, 64, -1);
1853 gtk_widget_show (imap_batch_size_spinbtn);
1854 gtk_box_pack_start(GTK_BOX(hbox1), imap_batch_size_spinbtn, FALSE, FALSE, 0);
1856 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1857 gtk_widget_show (hbox1);
1858 gtk_box_pack_start (GTK_BOX (vbox2), hbox1, FALSE, FALSE, 4);
1860 /* Auto-checking */
1861 vbox4 = gtkut_get_options_frame(vbox1, &frame, _("Automatic checking"));
1863 PACK_CHECK_BUTTON(vbox4, autochk_use_default_checkbtn,
1864 _("Use global settings"));
1866 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
1867 gtk_box_pack_start(GTK_BOX(vbox4), hbox2, FALSE, FALSE, 0);
1869 PACK_CHECK_BUTTON(hbox2, autochk_checkbtn,
1870 _("Check for new mail every"));
1872 adj = gtk_adjustment_new(5, 0, 99, 1, 10, 0);
1873 autochk_hour_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1874 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(autochk_hour_spinbtn), TRUE);
1875 gtk_box_pack_start(GTK_BOX(hbox2), autochk_hour_spinbtn, FALSE, FALSE, 0);
1876 autochk_hour_label = gtk_label_new(_("hours"));
1877 gtk_box_pack_start(GTK_BOX(hbox2), autochk_hour_label, FALSE, FALSE, 0);
1879 adj = gtk_adjustment_new(5, 0, 99, 1, 10, 0);
1880 autochk_min_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1881 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(autochk_min_spinbtn), TRUE);
1882 gtk_box_pack_start(GTK_BOX(hbox2), autochk_min_spinbtn, FALSE, FALSE, 0);
1883 autochk_min_label = gtk_label_new(_("minutes"));
1884 gtk_box_pack_start(GTK_BOX(hbox2), autochk_min_label, FALSE, FALSE, 0);
1886 adj = gtk_adjustment_new(5, 0, 99, 1, 10, 0);
1887 autochk_sec_spinbtn = gtk_spin_button_new(GTK_ADJUSTMENT(adj), 1, 0);
1888 gtk_spin_button_set_numeric(GTK_SPIN_BUTTON(autochk_sec_spinbtn), TRUE);
1889 gtk_box_pack_start(GTK_BOX(hbox2), autochk_sec_spinbtn, FALSE, FALSE, 0);
1890 autochk_sec_label = gtk_label_new(_("seconds"));
1891 gtk_box_pack_start(GTK_BOX(hbox2), autochk_sec_label, FALSE, FALSE, 0);
1893 autochk_widgets = g_new0(struct AutocheckWidgets, 1);
1894 autochk_widgets->autochk_hour_spinbtn = autochk_hour_spinbtn;
1895 autochk_widgets->autochk_min_spinbtn = autochk_min_spinbtn;
1896 autochk_widgets->autochk_sec_spinbtn = autochk_sec_spinbtn;
1898 gtk_widget_show_all(vbox4);
1900 SET_TOGGLE_SENSITIVITY_REVERSE(autochk_use_default_checkbtn, hbox2);
1901 SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_hour_spinbtn);
1902 SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_min_spinbtn);
1903 SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_sec_spinbtn);
1904 SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_hour_label);
1905 SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_min_label);
1906 SET_TOGGLE_SENSITIVITY(autochk_checkbtn, autochk_sec_label);
1908 PACK_CHECK_BUTTON (vbox1, filter_on_recv_checkbtn,
1909 _("Filter messages on receiving"));
1911 g_signal_connect(G_OBJECT(filter_on_recv_checkbtn), "toggled",
1912 G_CALLBACK(prefs_account_filter_on_recv_toggled),
1913 NULL);
1914 g_signal_connect(G_OBJECT(autochk_hour_spinbtn), "value-changed",
1915 G_CALLBACK(prefs_account_receive_itv_spinbutton_value_changed_cb),
1916 (gpointer) page);
1917 g_signal_connect(G_OBJECT(autochk_min_spinbtn), "value-changed",
1918 G_CALLBACK(prefs_account_receive_itv_spinbutton_value_changed_cb),
1919 (gpointer) page);
1920 g_signal_connect(G_OBJECT(autochk_sec_spinbtn), "value-changed",
1921 G_CALLBACK(prefs_account_receive_itv_spinbutton_value_changed_cb),
1922 (gpointer) page);
1924 PACK_CHECK_BUTTON (vbox1, filterhook_on_recv_checkbtn,
1925 _("Allow filtering using plugins on receiving"));
1927 PACK_CHECK_BUTTON
1928 (vbox1, recvatgetall_checkbtn,
1929 _("'Get Mail' checks for new messages on this account"));
1931 page->pop3_frame = frame1;
1932 page->pop_auth_checkbtn = pop_auth_checkbtn;
1933 page->pop_auth_type_optmenu = optmenu2;
1934 page->rmmail_checkbtn = rmmail_checkbtn;
1935 page->leave_time_spinbtn = leave_time_spinbtn;
1936 page->leave_hour_spinbtn = leave_hour_spinbtn;
1937 page->size_limit_checkbtn = size_limit_checkbtn;
1938 page->size_limit_spinbtn = size_limit_spinbtn;
1939 page->filter_on_recv_checkbtn = filter_on_recv_checkbtn;
1940 page->filterhook_on_recv_checkbtn = filterhook_on_recv_checkbtn;
1941 page->inbox_label = inbox_label;
1942 page->inbox_entry = inbox_entry;
1943 page->inbox_btn = inbox_btn;
1945 page->autochk_frame = frame;
1947 page->imap_frame = imap_frame;
1948 page->imap_auth_type_optmenu = optmenu;
1950 page->imapdir_label = imapdir_label;
1951 page->imapdir_entry = imapdir_entry;
1952 page->subsonly_checkbtn = subsonly_checkbtn;
1953 page->low_bandwidth_checkbtn = low_bandwidth_checkbtn;
1954 page->imap_batch_size_spinbtn = imap_batch_size_spinbtn;
1955 page->local_frame = local_frame;
1956 page->local_inbox_label = local_inbox_label;
1957 page->local_inbox_entry = local_inbox_entry;
1958 page->local_inbox_btn = local_inbox_btn;
1960 page->recvatgetall_checkbtn = recvatgetall_checkbtn;
1962 page->frame_maxarticle = frame2;
1963 page->maxarticle_spinbtn = maxarticle_spinbtn;
1964 page->maxarticle_spinbtn_adj = maxarticle_spinbtn_adj;
1966 page->autochk_checkbtn = autochk_checkbtn;
1967 page->autochk_widgets = autochk_widgets;
1968 page->autochk_use_default_checkbtn = autochk_use_default_checkbtn;
1970 tmp_ac_prefs = *ac_prefs;
1972 if (new_account) {
1973 prefs_set_dialog_to_default(receive_param);
1974 } else
1975 prefs_set_dialog(receive_param);
1977 page->vbox = vbox1;
1979 page->page.widget = vbox1;
1982 static void send_create_widget_func(PrefsPage * _page,
1983 GtkWindow * window,
1984 gpointer data)
1986 SendPage *page = (SendPage *) _page;
1987 PrefsAccount *ac_prefs = (PrefsAccount *) data;
1989 GtkWidget *vbox1;
1990 GtkWidget *vbox2;
1991 GtkWidget *frame;
1992 GtkWidget *msgid_checkbtn;
1993 GtkWidget *xmailer_checkbtn;
1994 GtkWidget *hbox;
1995 GtkWidget *customhdr_checkbtn;
1996 GtkWidget *customhdr_edit_btn;
1997 GtkWidget *checkbtn_msgid_with_addr;
1998 GtkWidget *vbox3;
1999 GtkWidget *smtp_auth_checkbtn;
2000 GtkWidget *showpwd_checkbtn;
2001 GtkWidget *optmenu;
2002 GtkListStore *menu;
2003 GtkTreeIter iter;
2004 GtkWidget *vbox4;
2005 GtkWidget *hbox_spc;
2006 GtkWidget *label;
2007 GtkWidget *smtp_uid_entry;
2008 GtkWidget *smtp_pass_entry;
2009 GtkWidget *vbox_spc;
2010 GtkWidget *pop_bfr_smtp_checkbtn;
2011 GtkWidget *pop_bfr_smtp_tm_spinbtn;
2012 GtkWidget *pop_auth_timeout_lbl;
2013 GtkWidget *pop_auth_minutes_lbl;
2014 gchar *buf;
2016 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2017 gtk_widget_show (vbox1);
2018 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2020 vbox2 = gtkut_get_options_frame(vbox1, &frame, _("Header"));
2022 PACK_CHECK_BUTTON (vbox2, msgid_checkbtn, _("Generate Message-ID"));
2024 PACK_CHECK_BUTTON (vbox2, checkbtn_msgid_with_addr,
2025 _("Send account mail address in Message-ID"));
2027 PACK_CHECK_BUTTON (vbox2, xmailer_checkbtn,
2028 _("Add user agent header"));
2030 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 12);
2031 gtk_widget_show (hbox);
2032 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0);
2034 PACK_CHECK_BUTTON (hbox, customhdr_checkbtn,
2035 _("Add user-defined header"));
2037 customhdr_edit_btn = gtk_button_new_with_mnemonic("_Edit");
2038 gtk_widget_show (customhdr_edit_btn);
2039 gtk_box_pack_start (GTK_BOX (hbox), customhdr_edit_btn,
2040 FALSE, FALSE, 0);
2041 g_signal_connect (G_OBJECT (customhdr_edit_btn), "clicked",
2042 G_CALLBACK (prefs_account_edit_custom_header),
2043 NULL);
2045 SET_TOGGLE_SENSITIVITY (customhdr_checkbtn, customhdr_edit_btn);
2047 vbox3 = gtkut_get_options_frame(vbox1, &frame, _("Authentication"));
2049 PACK_CHECK_BUTTON (vbox3, smtp_auth_checkbtn,
2050 _("SMTP Authentication (SMTP AUTH)"));
2052 vbox4 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2053 gtk_widget_show (vbox4);
2054 gtk_box_pack_start (GTK_BOX (vbox3), vbox4, FALSE, FALSE, 0);
2056 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2057 gtk_widget_show (hbox);
2058 gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2060 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2061 gtk_widget_show (hbox_spc);
2062 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2063 gtk_widget_set_size_request (hbox_spc, 12, -1);
2065 label = gtk_label_new (_("Authentication method"));
2066 gtk_widget_show (label);
2067 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2069 optmenu = gtkut_sc_combobox_create(NULL, FALSE);
2070 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optmenu)));
2071 gtk_widget_show (optmenu);
2072 gtk_box_pack_start (GTK_BOX (hbox), optmenu, FALSE, FALSE, 0);
2074 COMBOBOX_ADD (menu, _("Automatic"), 0);
2075 COMBOBOX_ADD (menu, NULL, 0);
2076 COMBOBOX_ADD (menu, "PLAIN", SMTPAUTH_PLAIN);
2077 COMBOBOX_ADD (menu, "LOGIN", SMTPAUTH_LOGIN);
2078 COMBOBOX_ADD (menu, "CRAM-MD5", SMTPAUTH_CRAM_MD5);
2079 COMBOBOX_ADD (menu, "OAUTH2", SMTPAUTH_OAUTH2);
2080 #ifndef USE_OAUTH2
2081 gtk_list_store_set(menu, &iter, COMBOBOX_SENS, FALSE, -1);
2082 #endif
2083 COMBOBOX_ADD (menu, "DIGEST-MD5", SMTPAUTH_DIGEST_MD5);
2084 gtk_list_store_set(menu, &iter, COMBOBOX_SENS, FALSE, -1);
2086 PACK_SPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
2088 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2089 gtk_widget_show (hbox);
2090 gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2092 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2093 gtk_widget_show (hbox_spc);
2094 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2095 gtk_widget_set_size_request (hbox_spc, 12, -1);
2097 label = gtk_label_new (_("User ID"));
2098 gtk_widget_show (label);
2099 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2101 smtp_uid_entry = gtk_entry_new ();
2102 gtk_widget_show (smtp_uid_entry);
2103 gtk_widget_set_size_request (smtp_uid_entry, DEFAULT_ENTRY_WIDTH, -1);
2104 gtk_box_pack_start (GTK_BOX (hbox), smtp_uid_entry, TRUE, TRUE, 0);
2105 g_signal_connect(G_OBJECT(smtp_uid_entry), "changed",
2106 G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
2107 GINT_TO_POINTER(ac_prefs->protocol));
2109 #ifdef GENERIC_UMPC
2110 PACK_SPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
2111 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2112 gtk_widget_show (hbox);
2113 gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2115 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2116 gtk_widget_show (hbox_spc);
2117 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2118 gtk_widget_set_size_request (hbox_spc, 12, -1);
2119 #endif
2120 label = gtk_label_new (_("Password"));
2121 gtk_widget_show (label);
2122 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2124 smtp_pass_entry = gtk_entry_new ();
2125 gtk_widget_show (smtp_pass_entry);
2126 gtk_widget_set_size_request (smtp_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
2127 gtk_box_pack_start (GTK_BOX (hbox), smtp_pass_entry, TRUE, TRUE, 0);
2128 gtk_entry_set_visibility (GTK_ENTRY (smtp_pass_entry), FALSE);
2129 g_signal_connect(G_OBJECT(smtp_pass_entry), "changed",
2130 G_CALLBACK(prefs_account_entry_changed_newline_check_cb),
2131 GINT_TO_POINTER(ac_prefs->protocol));
2133 showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
2134 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
2135 gtk_widget_show(showpwd_checkbtn);
2136 gtk_box_pack_start(GTK_BOX (hbox), showpwd_checkbtn, FALSE, FALSE, 0);
2137 g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
2138 G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), smtp_pass_entry);
2140 PACK_SPACER(vbox4, vbox_spc, VSPACING_NARROW_2);
2142 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2143 gtk_widget_show (hbox);
2144 gtk_box_pack_start (GTK_BOX (vbox4), hbox, FALSE, FALSE, 0);
2146 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2147 gtk_widget_show (hbox_spc);
2148 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2149 gtk_widget_set_size_request (hbox_spc, 12, -1);
2151 label = gtk_label_new
2152 (_("If you leave these entries empty, the same "
2153 "user ID and password as receiving will be used."));
2154 gtk_widget_show (label);
2155 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2156 gtk_label_set_justify (GTK_LABEL (label), GTK_JUSTIFY_LEFT);
2157 gtk_label_set_line_wrap (GTK_LABEL (label), TRUE);
2158 gtkut_widget_set_small_font_size (label);
2160 SET_TOGGLE_SENSITIVITY (smtp_auth_checkbtn, vbox4);
2162 PACK_CHECK_BUTTON (vbox3, pop_bfr_smtp_checkbtn,
2163 _("Authenticate with POP before sending"));
2165 g_signal_connect (G_OBJECT (pop_bfr_smtp_checkbtn), "clicked",
2166 G_CALLBACK (pop_bfr_smtp_tm_set_sens),
2167 NULL);
2169 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2170 gtk_widget_show (hbox);
2171 gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2173 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2174 gtk_widget_show (hbox_spc);
2175 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2176 gtk_widget_set_size_request (hbox_spc, 12, -1);
2178 pop_auth_timeout_lbl = gtk_label_new(_("POP authentication timeout"));
2179 gtk_widget_show (pop_auth_timeout_lbl);
2180 gtk_box_pack_start (GTK_BOX (hbox), pop_auth_timeout_lbl, FALSE, FALSE, 0);
2182 pop_bfr_smtp_tm_spinbtn = gtk_spin_button_new_with_range(0, 1440, 1);
2183 gtk_widget_show (pop_bfr_smtp_tm_spinbtn);
2184 gtk_box_pack_start (GTK_BOX (hbox), pop_bfr_smtp_tm_spinbtn, FALSE, FALSE, 0);
2186 pop_auth_minutes_lbl = gtk_label_new(_("minutes"));
2187 gtk_widget_show (pop_auth_minutes_lbl);
2188 gtk_box_pack_start (GTK_BOX (hbox), pop_auth_minutes_lbl, FALSE, FALSE, 0);
2190 page->msgid_checkbtn = msgid_checkbtn;
2191 page->xmailer_checkbtn = xmailer_checkbtn;
2192 page->customhdr_checkbtn = customhdr_checkbtn;
2193 page->msgid_with_addr_checkbtn = checkbtn_msgid_with_addr;
2195 page->smtp_auth_checkbtn = smtp_auth_checkbtn;
2196 page->smtp_auth_type_optmenu = optmenu;
2197 page->smtp_uid_entry = smtp_uid_entry;
2198 page->smtp_pass_entry = smtp_pass_entry;
2199 page->pop_bfr_smtp_checkbtn = pop_bfr_smtp_checkbtn;
2200 page->pop_bfr_smtp_tm_spinbtn = pop_bfr_smtp_tm_spinbtn;
2201 page->pop_auth_timeout_lbl = pop_auth_timeout_lbl;
2202 page->pop_auth_minutes_lbl = pop_auth_minutes_lbl;
2204 tmp_ac_prefs = *ac_prefs;
2206 if (new_account) {
2207 prefs_set_dialog_to_default(send_param);
2208 } else {
2209 prefs_set_dialog(send_param);
2211 /* Passwords are handled outside of PrefParams. */
2212 buf = passwd_store_get_account(ac_prefs->account_id,
2213 PWS_ACCOUNT_SEND);
2214 gtk_entry_set_text(GTK_ENTRY(page->smtp_pass_entry), buf != NULL ? buf : "");
2215 if (buf != NULL) {
2216 memset(buf, 0, strlen(buf));
2217 g_free(buf);
2221 pop_bfr_smtp_tm_set_sens (NULL, NULL);
2223 page->vbox = vbox1;
2225 page->page.widget = vbox1;
2228 #ifdef USE_OAUTH2
2229 static void oauth2_create_widget_func(PrefsPage * _page,
2230 GtkWindow * window,
2231 gpointer data)
2233 Oauth2Page *page = (Oauth2Page *) _page;
2234 PrefsAccount *ac_prefs = (PrefsAccount *) data;
2236 GtkWidget *vbox1, *vbox2, *vbox3;
2237 GtkWidget *hbox;
2238 GtkWidget *hbox_spc;
2239 GtkWidget *oauth2_authorise_btn;
2240 GtkWidget *auth_vbox, *auth_frame;
2241 GtkWidget *label;
2242 GtkWidget *oauth2_authcode_entry;
2243 GtkWidget *oauth2_auth_optmenu;
2244 GtkWidget *oauth2_link_button;
2245 GtkWidget *oauth2_link_copy_button;
2246 GtkWidget *oauth2_client_id_entry;
2247 GtkWidget *oauth2_client_secret_entry;
2248 GtkWidget *table1;
2249 GtkListStore *menu;
2250 GtkTreeIter iter;
2251 char *buf;
2252 struct BasicProtocol *protocol_optmenu;
2254 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2255 gtk_widget_show (vbox1);
2256 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2258 auth_vbox = gtkut_get_options_frame(vbox1, &auth_frame,
2259 _("Authorization"));
2261 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2262 gtk_widget_show (hbox);
2263 gtk_box_pack_start (GTK_BOX (auth_vbox), hbox, FALSE, FALSE, 0);
2265 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2266 gtk_widget_show (hbox_spc);
2267 gtk_widget_set_size_request (hbox_spc, 12, -1);
2268 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2270 /* Email service provider */
2272 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2273 gtk_widget_show (hbox);
2274 gtk_box_pack_start (GTK_BOX (auth_vbox), hbox, FALSE, FALSE, 0);
2276 label = gtk_label_new (_("Select OAuth2 Email Service Provider"));
2277 gtk_widget_show (label);
2278 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2280 oauth2_auth_optmenu = gtkut_sc_combobox_create(NULL, FALSE);
2281 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(oauth2_auth_optmenu)));
2282 gtk_widget_show (oauth2_auth_optmenu);
2283 gtk_box_pack_start (GTK_BOX (hbox), oauth2_auth_optmenu, FALSE, FALSE, 0);
2285 COMBOBOX_ADD (menu, _("Select"), NULL);
2286 COMBOBOX_ADD (menu, NULL, 0);
2287 COMBOBOX_ADD (menu, "Google/Gmail", OAUTH2AUTH_GOOGLE);
2288 COMBOBOX_ADD (menu, "MS Outlook", OAUTH2AUTH_OUTLOOK);
2289 COMBOBOX_ADD (menu, "MS Exchange", OAUTH2AUTH_EXCHANGE);
2290 COMBOBOX_ADD (menu, "Yahoo", OAUTH2AUTH_YAHOO);
2292 protocol_optmenu = g_new(struct BasicProtocol, 1);
2293 protocol_optmenu->combobox = oauth2_auth_optmenu;
2294 protocol_optmenu->label = label;
2295 protocol_optmenu->descrlabel = label;
2297 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2298 gtk_widget_show (hbox);
2299 gtk_box_pack_start (GTK_BOX (auth_vbox), hbox, FALSE, FALSE, 0);
2301 vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2302 gtk_widget_show (vbox3);
2303 gtk_box_pack_start (GTK_BOX (auth_vbox), vbox3, FALSE, FALSE, 0);
2305 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2306 gtk_widget_show (vbox2);
2307 gtk_box_pack_start (GTK_BOX (vbox3), vbox2, FALSE, FALSE, 0);
2309 table1 = gtk_grid_new();
2310 gtk_widget_show (table1);
2311 gtk_container_add (GTK_CONTAINER (vbox2), table1);
2312 gtk_container_set_border_width (GTK_CONTAINER (table1), 8);
2313 gtk_grid_set_row_spacing(GTK_GRID(table1), VSPACING_NARROW);
2314 gtk_grid_set_column_spacing(GTK_GRID(table1), 8);
2316 label = gtk_label_new (_("Client ID"));
2317 gtk_widget_show (label);
2318 gtk_label_set_xalign(GTK_LABEL (label), 1.0);
2319 gtk_grid_attach(GTK_GRID(table1), label, 0, 0, 1, 1);
2321 oauth2_client_id_entry = gtk_entry_new();
2322 gtk_widget_show (oauth2_client_id_entry);
2323 gtk_grid_attach(GTK_GRID(table1), oauth2_client_id_entry, 1, 0, 1, 1);
2324 gtk_widget_set_hexpand(oauth2_client_id_entry, TRUE);
2325 gtk_widget_set_halign(oauth2_client_id_entry, GTK_ALIGN_FILL);
2327 label = gtk_label_new (_("Client secret"));
2328 gtk_widget_show (label);
2329 gtk_label_set_xalign(GTK_LABEL (label), 1.0);
2330 gtk_grid_attach(GTK_GRID(table1), label, 0, 1, 1, 1);
2332 oauth2_client_secret_entry = gtk_entry_new ();
2333 gtk_widget_show (oauth2_client_secret_entry);
2334 gtk_grid_attach(GTK_GRID(table1), oauth2_client_secret_entry, 1, 1, 1, 1);
2335 gtk_widget_set_hexpand(oauth2_client_secret_entry, TRUE);
2336 gtk_widget_set_halign(oauth2_client_secret_entry, GTK_ALIGN_FILL);
2338 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2339 gtk_widget_show (hbox_spc);
2340 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
2341 //gtk_widget_set_size_request (hbox_spc, 12, -1);
2343 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
2344 gtk_widget_show (hbox_spc);
2345 gtk_box_pack_start (GTK_BOX (vbox2), hbox_spc, FALSE, FALSE, 0);
2346 //gtk_widget_set_size_request (hbox_spc, 12, 10);
2348 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2349 gtk_widget_show (hbox);
2350 gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2352 label = gtk_label_new (_("Obtain authorization code"));
2353 gtk_widget_show (label);
2354 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2356 oauth2_link_button = gtk_button_new_with_label(_("Open default browser with request"));
2357 g_signal_connect(G_OBJECT(oauth2_link_button), "clicked", G_CALLBACK(prefs_account_oauth2_copy_url), NULL);
2358 gtk_widget_set_sensitive(oauth2_link_button, TRUE);
2359 gtk_widget_set_margin_bottom(oauth2_link_button, 8);
2360 gtk_widget_show (oauth2_link_button);
2361 gtk_box_pack_start (GTK_BOX (hbox), oauth2_link_button, FALSE, FALSE, 0);
2363 oauth2_link_copy_button = gtk_button_new_with_label(_("Copy link"));
2364 g_signal_connect(G_OBJECT(oauth2_link_copy_button), "clicked", G_CALLBACK(prefs_account_oauth2_copy_url), NULL);
2365 gtk_widget_set_sensitive(oauth2_link_copy_button, TRUE);
2366 gtk_widget_set_margin_bottom(oauth2_link_copy_button, 8);
2367 gtk_widget_show (oauth2_link_copy_button);
2368 gtk_box_pack_start (GTK_BOX (hbox), oauth2_link_copy_button, FALSE, FALSE, 0);
2370 /* Authorisation code */
2371 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2372 gtk_widget_show (hbox);
2373 gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2374 //gtk_widget_set_size_request (hbox, -1, 50);
2376 label = gtk_label_new (_("Authorization code"));
2377 gtk_widget_show (label);
2378 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2380 oauth2_authcode_entry = gtk_entry_new ();
2381 gtk_widget_show (oauth2_authcode_entry);
2382 gtk_widget_set_margin_bottom(oauth2_authcode_entry, 8);
2383 //gtk_widget_set_size_request (oauth2_authcode_entry, DEFAULT_ENTRY_WIDTH, -1);
2384 gtk_widget_set_tooltip_text(oauth2_authcode_entry,
2385 _("Paste complete URL from browser or the provided authorization token"));
2386 gtk_box_pack_start (GTK_BOX (hbox), oauth2_authcode_entry, TRUE, TRUE, 0);
2388 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2389 gtk_widget_show (hbox);
2390 gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
2392 label = gtk_label_new (_("Complete authorization"));
2393 gtk_widget_show (label);
2394 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
2396 oauth2_authorise_btn = gtk_button_new_with_label(_("Authorize"));
2397 gtk_box_pack_start(GTK_BOX(hbox), oauth2_authorise_btn, FALSE, FALSE, 0);
2398 g_signal_connect(G_OBJECT(oauth2_authorise_btn), "clicked",
2399 G_CALLBACK(prefs_account_oauth2_obtain_tokens), NULL);
2400 gtk_widget_show(oauth2_authorise_btn);
2402 /* Add items to page struct */
2404 page->oauth2_link_button = oauth2_link_button;
2405 page->oauth2_link_copy_button = oauth2_link_copy_button;
2406 page->oauth2_authcode_entry = oauth2_authcode_entry;
2407 page->oauth2_auth_optmenu = oauth2_auth_optmenu;
2408 page->protocol_optmenu = (gpointer)protocol_optmenu;
2409 page->oauth2_authorise_btn = oauth2_authorise_btn;
2410 page->oauth2_client_id_entry = oauth2_client_id_entry;
2411 page->oauth2_client_secret_entry = oauth2_client_secret_entry;
2412 page->vbox = vbox1;
2413 page->page.widget = vbox1;
2414 page->oauth2_sensitive = vbox3;
2416 tmp_ac_prefs = *ac_prefs;
2418 g_signal_connect(G_OBJECT(oauth2_auth_optmenu), "changed",
2419 G_CALLBACK(prefs_account_oauth2_set_sensitivity), NULL);
2420 g_signal_connect(G_OBJECT(oauth2_authcode_entry), "changed",
2421 G_CALLBACK(prefs_account_oauth2_set_auth_sensitivity), NULL);
2422 prefs_account_oauth2_set_auth_sensitivity();
2424 if (new_account) {
2425 prefs_set_dialog_to_default(oauth2_param);
2426 } else {
2427 prefs_set_dialog(oauth2_param);
2429 /* Passwords are handled outside of PrefParams. */
2430 buf = passwd_store_get_account(ac_prefs->account_id,
2431 PWS_ACCOUNT_OAUTH2_AUTH);
2432 gtk_entry_set_text(GTK_ENTRY(page->oauth2_authcode_entry), buf != NULL ? buf : "");
2433 if (buf != NULL) {
2434 memset(buf, 0, strlen(buf));
2435 g_free(buf);
2439 /* For testing */
2440 /* oauth2_encode(OAUTH2info[0][OA2_CLIENT_ID]); */
2443 #endif
2445 static void compose_create_widget_func(PrefsPage * _page,
2446 GtkWindow * window,
2447 gpointer data)
2449 ComposePage *page = (ComposePage *) _page;
2450 PrefsAccount *ac_prefs = (PrefsAccount *) data;
2452 GtkWidget *vbox1;
2453 GtkWidget *sig_hbox;
2454 GtkWidget *hbox1;
2455 GtkWidget *hbox2;
2456 GtkWidget *frame_sig;
2457 GtkWidget *vbox_sig;
2458 GtkWidget *label_sigpath;
2459 GtkWidget *checkbtn_autosig;
2460 GtkWidget *label_sigsep;
2461 GtkWidget *entry_sigsep;
2462 GtkWidget *frame;
2463 GtkWidget *table;
2464 GtkWidget *autocc_checkbtn;
2465 GtkWidget *autocc_entry;
2466 GtkWidget *autobcc_checkbtn;
2467 GtkWidget *autobcc_entry;
2468 GtkWidget *autoreplyto_checkbtn;
2469 GtkWidget *autoreplyto_entry;
2470 #if USE_ENCHANT
2471 GtkWidget *frame_dict;
2472 GtkWidget *table_dict;
2473 GtkWidget *checkbtn_enable_default_dictionary = NULL;
2474 GtkWidget *combo_default_dictionary = NULL;
2475 GtkWidget *checkbtn_enable_default_alt_dictionary = NULL;
2476 GtkWidget *combo_default_alt_dictionary = NULL;
2477 #endif
2479 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2480 gtk_widget_show (vbox1);
2481 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2483 vbox_sig = gtkut_get_options_frame(vbox1, &frame_sig, _("Signature"));
2485 PACK_CHECK_BUTTON (vbox_sig, checkbtn_autosig,
2486 _("Automatically insert signature"));
2488 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2489 gtk_widget_show (hbox1);
2490 gtk_box_pack_start (GTK_BOX (vbox_sig), hbox1, TRUE, TRUE, 0);
2491 label_sigsep = gtk_label_new (_("Signature separator"));
2492 gtk_widget_show (label_sigsep);
2493 gtk_box_pack_start (GTK_BOX (hbox1), label_sigsep, FALSE, FALSE, 0);
2495 entry_sigsep = gtk_entry_new ();
2496 gtk_widget_show (entry_sigsep);
2497 gtk_box_pack_start (GTK_BOX (hbox1), entry_sigsep, FALSE, FALSE, 0);
2499 gtk_widget_set_size_request (entry_sigsep, 64, -1);
2501 sig_hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2502 gtk_widget_show (sig_hbox);
2503 gtk_box_pack_start (GTK_BOX (vbox_sig), sig_hbox, FALSE, FALSE, 0);
2505 sigfile_radiobtn = gtk_radio_button_new_with_label (NULL, _("File"));
2506 gtk_widget_show (sigfile_radiobtn);
2507 gtk_box_pack_start (GTK_BOX (sig_hbox), sigfile_radiobtn,
2508 FALSE, FALSE, 0);
2509 g_object_set_data (G_OBJECT (sigfile_radiobtn),
2510 MENU_VAL_ID,
2511 GINT_TO_POINTER (SIG_FILE));
2512 g_signal_connect(G_OBJECT(sigfile_radiobtn), "clicked",
2513 G_CALLBACK(prefs_account_sigfile_radiobtn_cb), NULL);
2515 sigcmd_radiobtn = gtk_radio_button_new_with_label_from_widget
2516 (GTK_RADIO_BUTTON(sigfile_radiobtn), _("Command output"));
2517 gtk_widget_show (sigcmd_radiobtn);
2518 gtk_box_pack_start (GTK_BOX (sig_hbox), sigcmd_radiobtn,
2519 FALSE, FALSE, 0);
2520 g_object_set_data (G_OBJECT (sigcmd_radiobtn),
2521 MENU_VAL_ID,
2522 GINT_TO_POINTER (SIG_COMMAND));
2523 g_signal_connect(G_OBJECT(sigcmd_radiobtn), "clicked",
2524 G_CALLBACK(prefs_account_sigcmd_radiobtn_cb), NULL);
2526 hbox2 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2527 gtk_widget_show (hbox2);
2528 gtk_box_pack_start (GTK_BOX (vbox_sig), hbox2, TRUE, TRUE, 0);
2529 label_sigpath = gtk_label_new (_("Signature"));
2530 gtk_widget_show (label_sigpath);
2531 gtk_box_pack_start (GTK_BOX (hbox2), label_sigpath, FALSE, FALSE, 0);
2533 entry_sigpath = gtk_entry_new ();
2534 gtk_widget_show (entry_sigpath);
2535 gtk_box_pack_start (GTK_BOX (hbox2), entry_sigpath, TRUE, TRUE, 0);
2537 signature_browse_button = gtkut_get_browse_file_btn(_("Bro_wse"));
2538 gtk_widget_show (signature_browse_button);
2539 gtk_box_pack_start (GTK_BOX (hbox2), signature_browse_button, FALSE, FALSE, 0);
2540 g_signal_connect(G_OBJECT(signature_browse_button), "clicked",
2541 G_CALLBACK(prefs_account_signature_browse_cb), NULL);
2543 signature_edit_button = gtk_button_new_with_mnemonic("_Edit");
2544 gtk_widget_show (signature_edit_button);
2545 gtk_box_pack_start (GTK_BOX (hbox2), signature_edit_button, FALSE, FALSE, 0);
2546 g_signal_connect(G_OBJECT(signature_edit_button), "clicked",
2547 G_CALLBACK(prefs_account_signature_edit_cb), entry_sigpath);
2549 PACK_FRAME (vbox1, frame, _("Automatically set the following addresses"));
2551 table = gtk_grid_new();
2552 gtk_widget_show (table);
2553 gtk_container_add (GTK_CONTAINER (frame), table);
2554 gtk_container_set_border_width (GTK_CONTAINER (table), 8);
2555 gtk_grid_set_row_spacing(GTK_GRID(table), VSPACING_NARROW_2);
2556 gtk_grid_set_column_spacing(GTK_GRID(table), 8);
2558 autocc_checkbtn = gtk_check_button_new_with_label (
2559 prefs_common_translated_header_name("Cc:"));
2560 gtk_widget_show (autocc_checkbtn);
2561 gtk_grid_attach(GTK_GRID(table), autocc_checkbtn, 0, 0, 1, 1);
2563 autocc_entry = gtk_entry_new ();
2564 gtk_widget_show (autocc_entry);
2565 gtk_grid_attach(GTK_GRID(table), autocc_entry, 1, 0, 1, 1);
2566 gtk_widget_set_hexpand(autocc_entry, TRUE);
2567 gtk_widget_set_halign(autocc_entry, GTK_ALIGN_FILL);
2569 SET_TOGGLE_SENSITIVITY (autocc_checkbtn, autocc_entry);
2571 autobcc_checkbtn = gtk_check_button_new_with_label (
2572 prefs_common_translated_header_name("Bcc:"));
2573 gtk_widget_show (autobcc_checkbtn);
2574 gtk_grid_attach(GTK_GRID(table), autobcc_checkbtn, 0, 1, 1, 1);
2576 autobcc_entry = gtk_entry_new ();
2577 gtk_widget_show (autobcc_entry);
2578 gtk_grid_attach(GTK_GRID(table), autobcc_entry, 1, 1, 1, 1);
2579 gtk_widget_set_hexpand(autobcc_entry, TRUE);
2580 gtk_widget_set_halign(autobcc_entry, GTK_ALIGN_FILL);
2582 SET_TOGGLE_SENSITIVITY (autobcc_checkbtn, autobcc_entry);
2584 autoreplyto_checkbtn = gtk_check_button_new_with_label (
2585 prefs_common_translated_header_name("Reply-To:"));
2586 gtk_widget_show (autoreplyto_checkbtn);
2587 gtk_grid_attach(GTK_GRID(table), autoreplyto_checkbtn, 0, 2, 1, 1);
2589 autoreplyto_entry = gtk_entry_new ();
2590 gtk_widget_show (autoreplyto_entry);
2591 gtk_grid_attach(GTK_GRID(table), autoreplyto_entry, 1, 2, 1, 1);
2592 gtk_widget_set_hexpand(autoreplyto_entry, TRUE);
2593 gtk_widget_set_halign(autoreplyto_entry, GTK_ALIGN_FILL);
2595 SET_TOGGLE_SENSITIVITY (autoreplyto_checkbtn, autoreplyto_entry);
2597 #if USE_ENCHANT
2598 PACK_FRAME (vbox1, frame_dict, _("Spell check dictionaries"));
2600 table_dict = gtk_grid_new();
2601 gtk_widget_show (table_dict);
2602 gtk_container_add (GTK_CONTAINER (frame_dict), table_dict);
2603 gtk_container_set_border_width (GTK_CONTAINER (table_dict), 8);
2604 gtk_grid_set_row_spacing(GTK_GRID(table_dict), VSPACING_NARROW_2);
2605 gtk_grid_set_column_spacing(GTK_GRID(table_dict), 8);
2607 /* Default dictionary */
2608 checkbtn_enable_default_dictionary = gtk_check_button_new_with_label(_("Default dictionary"));
2609 gtk_grid_attach(GTK_GRID(table_dict), checkbtn_enable_default_dictionary, 0, 0, 1, 1);
2611 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_dictionary),
2612 tmp_ac_prefs.enable_default_dictionary);
2614 combo_default_dictionary = gtkaspell_dictionary_combo_new(TRUE);
2615 gtk_grid_attach(GTK_GRID(table_dict), combo_default_dictionary, 1, 0, 1, 1);
2617 SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_dictionary, combo_default_dictionary);
2619 /* Default dictionary */
2620 checkbtn_enable_default_alt_dictionary = gtk_check_button_new_with_label(_("Default alternate dictionary"));
2621 gtk_grid_attach(GTK_GRID(table_dict), checkbtn_enable_default_alt_dictionary, 0, 1, 1, 1);
2623 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(checkbtn_enable_default_alt_dictionary),
2624 tmp_ac_prefs.enable_default_alt_dictionary);
2626 combo_default_alt_dictionary = gtkaspell_dictionary_combo_new(FALSE);
2627 gtk_grid_attach(GTK_GRID(table_dict), combo_default_alt_dictionary, 1, 1, 1, 1);
2629 SET_TOGGLE_SENSITIVITY(checkbtn_enable_default_alt_dictionary, combo_default_alt_dictionary);
2631 gtk_widget_show_all(table_dict);
2632 #endif
2634 page->sigfile_radiobtn = sigfile_radiobtn;
2635 page->entry_sigpath = entry_sigpath;
2636 page->checkbtn_autosig = checkbtn_autosig;
2637 page->entry_sigsep = entry_sigsep;
2639 page->autocc_checkbtn = autocc_checkbtn;
2640 page->autocc_entry = autocc_entry;
2641 page->autobcc_checkbtn = autobcc_checkbtn;
2642 page->autobcc_entry = autobcc_entry;
2643 page->autoreplyto_checkbtn = autoreplyto_checkbtn;
2644 page->autoreplyto_entry = autoreplyto_entry;
2645 #ifdef USE_ENCHANT
2646 page->checkbtn_enable_default_dictionary = checkbtn_enable_default_dictionary;
2647 page->combo_default_dictionary = combo_default_dictionary;
2648 page->checkbtn_enable_default_alt_dictionary = checkbtn_enable_default_alt_dictionary;
2649 page->combo_default_alt_dictionary = combo_default_alt_dictionary;
2650 #endif
2652 #ifdef USE_ENCHANT
2653 /* reset gtkaspell menus */
2654 if (compose_page.combo_default_dictionary != NULL) {
2655 gtk_combo_box_set_model(GTK_COMBO_BOX(compose_page.combo_default_dictionary),
2656 gtkaspell_dictionary_store_new());
2657 gtk_combo_box_set_model(GTK_COMBO_BOX(compose_page.combo_default_alt_dictionary),
2658 gtkaspell_dictionary_store_new_with_refresh(
2659 FALSE));
2661 #endif
2663 tmp_ac_prefs = *ac_prefs;
2665 if (new_account) {
2666 prefs_set_dialog_to_default(compose_param);
2667 } else
2668 prefs_set_dialog(compose_param);
2670 page->vbox = vbox1;
2672 page->page.widget = vbox1;
2675 static void templates_create_widget_func(PrefsPage * _page,
2676 GtkWindow * window,
2677 gpointer data)
2679 TemplatesPage *page = (TemplatesPage *) _page;
2680 PrefsAccount *ac_prefs = (PrefsAccount *) data;
2681 GtkWidget *vbox;
2682 GtkWidget *vbox2;
2683 GtkWidget *notebook;
2685 vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2686 gtk_widget_show(vbox);
2688 notebook = gtk_notebook_new();
2689 gtk_widget_show(notebook);
2690 gtk_box_pack_start(GTK_BOX(vbox), notebook, TRUE, TRUE, 0);
2692 /* compose format */
2693 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2694 gtk_widget_show (vbox2);
2695 gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2697 quotefmt_create_new_msg_fmt_widgets(
2698 window,
2699 vbox2,
2700 &page->checkbtn_compose_with_format,
2701 NULL,
2702 &page->compose_subject_format,
2703 &page->compose_body_format,
2704 TRUE, NULL);
2705 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Compose")));
2707 /* reply format */
2708 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2709 gtk_widget_show (vbox2);
2710 gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2712 quotefmt_create_reply_fmt_widgets(
2713 window,
2714 vbox2,
2715 &page->checkbtn_reply_with_format,
2716 NULL,
2717 &page->reply_quotemark,
2718 &page->reply_body_format,
2719 TRUE, NULL);
2720 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Reply")));
2722 /* forward format */
2723 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2724 gtk_widget_show (vbox2);
2725 gtk_container_set_border_width (GTK_CONTAINER (vbox2), VBOX_BORDER);
2727 quotefmt_create_forward_fmt_widgets(
2728 window,
2729 vbox2,
2730 &page->checkbtn_forward_with_format,
2731 NULL,
2732 &page->forward_quotemark,
2733 &page->forward_body_format,
2734 TRUE, NULL);
2735 gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("Forward")));
2737 tmp_ac_prefs = *ac_prefs;
2739 if (new_account) {
2740 prefs_set_dialog_to_default(templates_param);
2741 } else
2742 prefs_set_dialog(templates_param);
2744 page->vbox = vbox;
2746 page->page.widget = vbox;
2749 static void privacy_create_widget_func(PrefsPage * _page,
2750 GtkWindow * window,
2751 gpointer data)
2753 PrivacyPage *page = (PrivacyPage *) _page;
2754 PrefsAccount *ac_prefs = (PrefsAccount *) data;
2756 GtkWidget *vbox1;
2757 GtkWidget *vbox2;
2758 GtkWidget *hbox1;
2759 GtkWidget *label;
2760 GtkWidget *default_privacy_system;
2761 GtkListStore *menu;
2762 GtkCellRenderer *rend;
2763 GtkWidget *default_encrypt_checkbtn;
2764 GtkWidget *default_encrypt_reply_checkbtn;
2765 GtkWidget *default_sign_checkbtn;
2766 GtkWidget *default_sign_reply_checkbtn;
2767 GtkWidget *save_clear_text_checkbtn;
2768 GtkWidget *encrypt_to_self_checkbtn;
2770 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2771 gtk_widget_show (vbox1);
2772 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2774 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
2775 gtk_widget_show (vbox2);
2776 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
2778 hbox1 = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
2779 gtk_widget_show (hbox1);
2780 gtk_container_add (GTK_CONTAINER(vbox2), hbox1);
2782 label = gtk_label_new(_("Default privacy system"));
2783 gtk_widget_show(label);
2784 gtk_box_pack_start (GTK_BOX (hbox1), label, FALSE, FALSE, 0);
2786 /* Can't use gtkut_sc_combobox_create() here, because model for this
2787 * combobox needs an extra string column to store privacy plugin id. */
2788 menu = gtk_list_store_new(4,
2789 G_TYPE_STRING,
2790 G_TYPE_INT,
2791 G_TYPE_BOOLEAN,
2792 G_TYPE_STRING); /* This is where we store the privacy plugin id. */
2793 default_privacy_system = gtk_combo_box_new_with_model(GTK_TREE_MODEL(menu));
2795 rend = gtk_cell_renderer_text_new();
2796 gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(default_privacy_system), rend, TRUE);
2797 gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(default_privacy_system), rend,
2798 "text", COMBOBOX_TEXT,
2799 "sensitive", COMBOBOX_SENS,
2800 NULL);
2801 gtk_widget_set_focus_on_click(GTK_WIDGET(default_privacy_system), FALSE);
2803 gtk_widget_show (default_privacy_system);
2804 gtk_box_pack_start (GTK_BOX(hbox1), default_privacy_system, FALSE, TRUE, 0);
2806 g_signal_connect(G_OBJECT(default_privacy_system), "changed",
2807 G_CALLBACK(privacy_system_activated),
2808 NULL);
2810 PACK_CHECK_BUTTON (vbox2, default_sign_checkbtn,
2811 _("Always sign messages"));
2812 PACK_CHECK_BUTTON (vbox2, default_encrypt_checkbtn,
2813 _("Always encrypt messages"));
2814 PACK_CHECK_BUTTON (vbox2, default_sign_reply_checkbtn,
2815 _("Always sign messages when replying to a "
2816 "signed message"));
2817 PACK_CHECK_BUTTON (vbox2, default_encrypt_reply_checkbtn,
2818 _("Always encrypt messages when replying to an "
2819 "encrypted message"));
2820 PACK_CHECK_BUTTON (vbox2, encrypt_to_self_checkbtn,
2821 _("Encrypt sent messages with your own key in addition to recipient's"));
2822 PACK_CHECK_BUTTON (vbox2, save_clear_text_checkbtn,
2823 _("Save sent encrypted messages as clear text"));
2825 SET_TOGGLE_SENSITIVITY_REVERSE(encrypt_to_self_checkbtn, save_clear_text_checkbtn);
2826 SET_TOGGLE_SENSITIVITY_REVERSE(save_clear_text_checkbtn, encrypt_to_self_checkbtn);
2828 page->default_privacy_system = default_privacy_system;
2829 page->default_encrypt_checkbtn = default_encrypt_checkbtn;
2830 page->default_encrypt_reply_checkbtn = default_encrypt_reply_checkbtn;
2831 page->default_sign_reply_checkbtn = default_sign_reply_checkbtn;
2832 page->default_sign_checkbtn = default_sign_checkbtn;
2833 page->save_clear_text_checkbtn = save_clear_text_checkbtn;
2834 page->encrypt_to_self_checkbtn = encrypt_to_self_checkbtn;
2836 update_privacy_system_menu();
2838 tmp_ac_prefs = *ac_prefs;
2840 if (new_account) {
2841 prefs_set_dialog_to_default(privacy_param);
2842 } else
2843 prefs_set_dialog(privacy_param);
2845 page->vbox = vbox1;
2847 page->page.widget = vbox1;
2850 #define CREATE_RADIO_BUTTON(box, btn, btn_p, label, data) \
2852 btn = gtk_radio_button_new_with_label_from_widget \
2853 (GTK_RADIO_BUTTON (btn_p), label); \
2854 gtk_widget_show (btn); \
2855 gtk_box_pack_start (GTK_BOX (box), btn, FALSE, FALSE, 0); \
2856 g_object_set_data (G_OBJECT (btn), \
2857 MENU_VAL_ID, \
2858 GINT_TO_POINTER (data)); \
2861 #ifdef USE_GNUTLS
2863 #define CREATE_RADIO_BUTTONS(box, \
2864 btn1, btn1_label, btn1_data, \
2865 btn2, btn2_label, btn2_data, \
2866 btn3, btn3_label, btn3_data) \
2868 btn1 = gtk_radio_button_new_with_label(NULL, btn1_label); \
2869 gtk_widget_show (btn1); \
2870 gtk_box_pack_start (GTK_BOX (box), btn1, FALSE, FALSE, 0); \
2871 g_object_set_data (G_OBJECT (btn1), \
2872 MENU_VAL_ID, \
2873 GINT_TO_POINTER (btn1_data)); \
2875 CREATE_RADIO_BUTTON(box, btn2, btn1, btn2_label, btn2_data); \
2876 CREATE_RADIO_BUTTON(box, btn3, btn1, btn3_label, btn3_data); \
2879 static void pop_ssltunnel_toggled(GtkToggleButton *button,
2880 gpointer data)
2882 gboolean active = gtk_toggle_button_get_active(button);
2884 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2885 advanced_page.popport_checkbtn)) == TRUE)
2886 return;
2887 gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.popport_spinbtn),
2888 active ? 995 : 110);
2891 static void imap_ssltunnel_toggled(GtkToggleButton *button,
2892 gpointer data)
2894 gboolean active = gtk_toggle_button_get_active(button);
2896 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2897 advanced_page.imapport_checkbtn)) == TRUE)
2898 return;
2899 gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.imapport_spinbtn),
2900 active ? 993 : 143);
2903 static void nntp_ssltunnel_toggled(GtkToggleButton *button,
2904 gpointer data)
2906 gboolean active = gtk_toggle_button_get_active(button);
2908 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2909 advanced_page.nntpport_checkbtn)) == TRUE)
2910 return;
2911 gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.nntpport_spinbtn),
2912 active ? 563 : 119);
2915 static void smtp_ssltunnel_toggled(GtkToggleButton *button,
2916 gpointer data)
2918 gboolean active = gtk_toggle_button_get_active(button);
2920 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(
2921 advanced_page.smtpport_checkbtn)) == TRUE)
2922 return;
2923 gtk_spin_button_set_value(GTK_SPIN_BUTTON(advanced_page.smtpport_spinbtn),
2924 active ? 465 : 25);
2927 static void ssl_create_widget_func(PrefsPage * _page,
2928 GtkWindow * window,
2929 gpointer data)
2931 SSLPage *page = (SSLPage *) _page;
2932 PrefsAccount *ac_prefs = (PrefsAccount *) data;
2934 GtkWidget *vbox1;
2936 GtkWidget *pop_frame;
2937 GtkWidget *vbox2;
2938 GtkWidget *pop_nossl_radiobtn;
2939 GtkWidget *pop_ssltunnel_radiobtn;
2940 GtkWidget *pop_starttls_radiobtn;
2942 GtkWidget *imap_frame;
2943 GtkWidget *vbox3;
2944 GtkWidget *imap_nossl_radiobtn;
2945 GtkWidget *imap_ssltunnel_radiobtn;
2946 GtkWidget *imap_starttls_radiobtn;
2948 GtkWidget *nntp_frame;
2949 GtkWidget *vbox4;
2950 GtkWidget *nntp_nossl_radiobtn;
2951 GtkWidget *nntp_ssltunnel_radiobtn;
2953 GtkWidget *send_frame;
2954 GtkWidget *vbox5;
2955 GtkWidget *smtp_nossl_radiobtn;
2956 GtkWidget *smtp_ssltunnel_radiobtn;
2957 GtkWidget *smtp_starttls_radiobtn;
2959 GtkWidget *cert_frame;
2960 GtkWidget *cert_table;
2961 GtkWidget *entry_in_cert_pass;
2962 GtkWidget *entry_out_cert_pass;
2963 GtkWidget *showpwd_checkbtn;
2965 GtkWidget *vbox7;
2966 GtkWidget *ssl_certs_auto_accept_checkbtn;
2967 GtkWidget *use_nonblocking_ssl_checkbtn;
2968 GtkWidget *hbox;
2969 GtkWidget *hbox_spc;
2970 GtkWidget *label;
2971 gchar *buf;
2973 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
2974 gtk_widget_show (vbox1);
2975 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
2977 vbox2 = gtkut_get_options_frame(vbox1, &pop_frame, _("POP"));
2979 CREATE_RADIO_BUTTONS(vbox2,
2980 pop_nossl_radiobtn,
2981 _("Don't use TLS"),
2982 SSL_NONE,
2983 pop_ssltunnel_radiobtn,
2984 _("Use TLS"),
2985 SSL_TUNNEL,
2986 pop_starttls_radiobtn,
2987 _("Use STARTTLS command to start encrypted session"),
2988 SSL_STARTTLS);
2989 g_signal_connect(G_OBJECT(pop_ssltunnel_radiobtn), "toggled",
2990 G_CALLBACK(pop_ssltunnel_toggled), NULL);
2992 vbox3 = gtkut_get_options_frame(vbox1, &imap_frame, _("IMAP"));
2994 CREATE_RADIO_BUTTONS(vbox3,
2995 imap_nossl_radiobtn,
2996 _("Don't use TLS"),
2997 SSL_NONE,
2998 imap_ssltunnel_radiobtn,
2999 _("Use TLS"),
3000 SSL_TUNNEL,
3001 imap_starttls_radiobtn,
3002 _("Use STARTTLS command to start encrypted session"),
3003 SSL_STARTTLS);
3004 g_signal_connect(G_OBJECT(imap_ssltunnel_radiobtn), "toggled",
3005 G_CALLBACK(imap_ssltunnel_toggled), NULL);
3007 vbox4 = gtkut_get_options_frame(vbox1, &nntp_frame, _("NNTP"));
3009 nntp_nossl_radiobtn =
3010 gtk_radio_button_new_with_label (NULL, _("Don't use TLS"));
3011 gtk_widget_show (nntp_nossl_radiobtn);
3012 gtk_box_pack_start (GTK_BOX (vbox4), nntp_nossl_radiobtn,
3013 FALSE, FALSE, 0);
3014 g_object_set_data (G_OBJECT (nntp_nossl_radiobtn),
3015 MENU_VAL_ID,
3016 GINT_TO_POINTER (SSL_NONE));
3018 CREATE_RADIO_BUTTON(vbox4, nntp_ssltunnel_radiobtn, nntp_nossl_radiobtn,
3019 _("Use TLS"), SSL_TUNNEL);
3020 g_signal_connect(G_OBJECT(nntp_ssltunnel_radiobtn), "toggled",
3021 G_CALLBACK(nntp_ssltunnel_toggled), NULL);
3023 vbox5 = gtkut_get_options_frame(vbox1, &send_frame, _("Send (SMTP)"));
3025 CREATE_RADIO_BUTTONS(vbox5,
3026 smtp_nossl_radiobtn,
3027 _("Don't use TLS (but, if necessary, use STARTTLS)"),
3028 SSL_NONE,
3029 smtp_ssltunnel_radiobtn,
3030 _("Use TLS"),
3031 SSL_TUNNEL,
3032 smtp_starttls_radiobtn,
3033 _("Use STARTTLS command to start encrypted session"),
3034 SSL_STARTTLS);
3035 g_signal_connect(G_OBJECT(smtp_ssltunnel_radiobtn), "toggled",
3036 G_CALLBACK(smtp_ssltunnel_toggled), NULL);
3038 PACK_FRAME(vbox1, cert_frame, _("Client certificates"));
3040 cert_table = gtk_grid_new();
3041 gtk_container_add(GTK_CONTAINER(cert_frame), cert_table);
3042 gtk_container_set_border_width(GTK_CONTAINER(cert_table), 8);
3043 gtk_grid_set_row_spacing(GTK_GRID(cert_table), VSPACING_NARROW_2);
3044 gtk_grid_set_column_spacing(GTK_GRID(cert_table), 8);
3046 label = gtk_label_new(_("Certificate for receiving"));
3047 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3048 entry_in_cert_file = gtk_entry_new();
3049 in_ssl_cert_browse_button = gtkut_get_browse_file_btn(_("Browse"));
3050 CLAWS_SET_TIP(label,
3051 _("Client certificate file as a PKCS12 or PEM file"));
3052 CLAWS_SET_TIP(entry_in_cert_file,
3053 _("Client certificate file as a PKCS12 or PEM file"));
3054 gtk_grid_attach(GTK_GRID(cert_table), label, 0, 0, 1, 1);
3055 gtk_grid_attach(GTK_GRID(cert_table), entry_in_cert_file, 1, 0, 1, 1);
3056 gtk_widget_set_hexpand(entry_in_cert_file, TRUE);
3057 gtk_widget_set_halign(entry_in_cert_file, GTK_ALIGN_FILL);
3058 gtk_grid_attach(GTK_GRID(cert_table), in_ssl_cert_browse_button, 2, 0, 1, 1);
3060 label = gtk_label_new(_("Password"));
3061 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3062 entry_in_cert_pass = gtk_entry_new();
3063 gtk_entry_set_visibility(GTK_ENTRY(entry_in_cert_pass), FALSE);
3064 showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
3065 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
3066 g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
3067 G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), entry_in_cert_pass);
3068 gtk_grid_attach(GTK_GRID(cert_table), label, 0, 1, 1, 1);
3069 gtk_grid_attach(GTK_GRID(cert_table), entry_in_cert_pass, 1, 1, 1, 1);
3070 gtk_widget_set_hexpand(entry_in_cert_pass, TRUE);
3071 gtk_widget_set_halign(entry_in_cert_pass, GTK_ALIGN_FILL);
3072 gtk_grid_attach(GTK_GRID(cert_table), showpwd_checkbtn, 2, 1, 1, 1);
3074 label = gtk_label_new(_("Certificate for sending"));
3075 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3076 entry_out_cert_file = gtk_entry_new();
3077 out_ssl_cert_browse_button = gtkut_get_browse_file_btn(_("Browse"));
3078 CLAWS_SET_TIP(label,
3079 _("Client certificate file as a PKCS12 or PEM file"));
3080 CLAWS_SET_TIP(entry_out_cert_file,
3081 _("Client certificate file as a PKCS12 or PEM file"));
3082 gtk_grid_attach(GTK_GRID(cert_table), label, 0, 2, 1, 1);
3083 gtk_grid_attach(GTK_GRID(cert_table), entry_out_cert_file, 1, 2, 1, 1);
3084 gtk_widget_set_hexpand(entry_out_cert_file, TRUE);
3085 gtk_widget_set_halign(entry_out_cert_file, GTK_ALIGN_FILL);
3086 gtk_grid_attach(GTK_GRID(cert_table), out_ssl_cert_browse_button, 2, 2, 1, 1);
3088 label = gtk_label_new(_("Password"));
3089 gtk_label_set_xalign(GTK_LABEL(label), 1.0);
3090 entry_out_cert_pass = gtk_entry_new();
3091 gtk_entry_set_visibility(GTK_ENTRY(entry_out_cert_pass), FALSE);
3092 showpwd_checkbtn = gtk_check_button_new_with_label (_("Show password"));
3093 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(showpwd_checkbtn), FALSE);
3094 g_signal_connect(G_OBJECT(showpwd_checkbtn), "toggled",
3095 G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), entry_out_cert_pass);
3096 gtk_grid_attach(GTK_GRID(cert_table), label, 0, 3, 1, 1);
3097 gtk_grid_attach(GTK_GRID(cert_table), entry_out_cert_pass, 1, 3, 1, 1);
3098 gtk_widget_set_hexpand(entry_out_cert_pass, TRUE);
3099 gtk_widget_set_halign(entry_out_cert_pass, GTK_ALIGN_FILL);
3100 gtk_grid_attach(GTK_GRID(cert_table), showpwd_checkbtn, 2, 3, 1, 1);
3102 gtk_widget_show_all(cert_table);
3104 g_signal_connect(G_OBJECT(in_ssl_cert_browse_button), "clicked",
3105 G_CALLBACK(prefs_account_in_cert_browse_cb), NULL);
3106 g_signal_connect(G_OBJECT(out_ssl_cert_browse_button), "clicked",
3107 G_CALLBACK(prefs_account_out_cert_browse_cb), NULL);
3109 vbox7 = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
3110 gtk_widget_show (vbox7);
3111 gtk_box_pack_start (GTK_BOX (vbox1), vbox7, FALSE, FALSE, 0);
3113 PACK_CHECK_BUTTON(vbox7, ssl_certs_auto_accept_checkbtn,
3114 _("Automatically accept valid TLS certificates"));
3116 PACK_CHECK_BUTTON(vbox7, use_nonblocking_ssl_checkbtn,
3117 _("Use non-blocking TLS"));
3119 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
3120 gtk_widget_show (hbox);
3121 gtk_box_pack_start (GTK_BOX (vbox7), hbox, FALSE, FALSE, 0);
3123 hbox_spc = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 0);
3124 gtk_widget_show (hbox_spc);
3125 gtk_box_pack_start (GTK_BOX (hbox), hbox_spc, FALSE, FALSE, 0);
3126 gtk_widget_set_size_request (hbox_spc, 16, -1);
3128 label = gtk_label_new
3129 (_("Turn this off if you have TLS connection problems"));
3130 gtk_widget_show (label);
3131 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 0);
3132 gtkut_widget_set_small_font_size (label);
3134 page->pop_frame = pop_frame;
3135 page->pop_nossl_radiobtn = pop_nossl_radiobtn;
3136 page->pop_ssltunnel_radiobtn = pop_ssltunnel_radiobtn;
3137 page->pop_starttls_radiobtn = pop_starttls_radiobtn;
3139 page->imap_frame = imap_frame;
3140 page->imap_nossl_radiobtn = imap_nossl_radiobtn;
3141 page->imap_ssltunnel_radiobtn = imap_ssltunnel_radiobtn;
3142 page->imap_starttls_radiobtn = imap_starttls_radiobtn;
3144 page->nntp_frame = nntp_frame;
3145 page->nntp_nossl_radiobtn = nntp_nossl_radiobtn;
3146 page->nntp_ssltunnel_radiobtn = nntp_ssltunnel_radiobtn;
3148 page->send_frame = send_frame;
3149 page->smtp_nossl_radiobtn = smtp_nossl_radiobtn;
3150 page->smtp_ssltunnel_radiobtn = smtp_ssltunnel_radiobtn;
3151 page->smtp_starttls_radiobtn = smtp_starttls_radiobtn;
3153 page->entry_in_cert_file = entry_in_cert_file;
3154 page->entry_in_cert_pass = entry_in_cert_pass;
3155 page->entry_out_cert_file = entry_out_cert_file;
3156 page->entry_out_cert_pass = entry_out_cert_pass;
3158 page->ssl_certs_auto_accept_checkbtn = ssl_certs_auto_accept_checkbtn;
3159 page->use_nonblocking_ssl_checkbtn = use_nonblocking_ssl_checkbtn;
3161 tmp_ac_prefs = *ac_prefs;
3163 if (new_account) {
3164 prefs_set_dialog_to_default(ssl_param);
3165 } else {
3166 prefs_set_dialog(ssl_param);
3168 /* Passwords are handled outside of PrefParams. */
3169 buf = passwd_store_get_account(ac_prefs->account_id,
3170 PWS_ACCOUNT_RECV_CERT);
3171 gtk_entry_set_text(GTK_ENTRY(page->entry_in_cert_pass), buf != NULL ? buf : "");
3172 if (buf != NULL) {
3173 memset(buf, 0, strlen(buf));
3174 g_free(buf);
3177 buf = passwd_store_get_account(ac_prefs->account_id,
3178 PWS_ACCOUNT_SEND_CERT);
3179 gtk_entry_set_text(GTK_ENTRY(page->entry_out_cert_pass), buf != NULL ? buf : "");
3180 if (buf != NULL) {
3181 memset(buf, 0, strlen(buf));
3182 g_free(buf);
3186 page->vbox = vbox1;
3188 page->page.widget = vbox1;
3191 #undef CREATE_RADIO_BUTTONS
3192 #endif /* USE_GNUTLS */
3194 static void proxy_create_widget_func(PrefsPage * _page,
3195 GtkWindow * window,
3196 gpointer data)
3198 ProxyPage *page = (ProxyPage *) _page;
3199 PrefsAccount *ac_prefs = (PrefsAccount *) data;
3200 GtkWidget *vbox1, *vbox2, *vbox3, *vbox4;
3201 GtkWidget *proxy_frame;
3202 GtkWidget *proxy_checkbtn;
3203 GtkWidget *default_proxy_checkbtn;
3204 GtkWidget *hbox;
3205 GtkWidget *label;
3206 GtkWidget *socks4_radiobtn;
3207 GtkWidget *socks5_radiobtn;
3208 GtkWidget *proxy_host_entry;
3209 GtkWidget *proxy_port_spinbtn;
3210 GtkWidget *proxy_auth_checkbtn;
3211 GtkWidget *proxy_name_entry;
3212 GtkWidget *proxy_pass_entry;
3213 GtkWidget *proxy_send_checkbtn;
3214 GtkWidget *table;
3215 GtkWidget *button;
3216 gchar *buf;
3218 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
3219 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
3221 proxy_checkbtn = gtk_check_button_new_with_label (_("Use proxy server"));
3222 PACK_FRAME (vbox1, proxy_frame, NULL);
3223 gtk_frame_set_label_widget (GTK_FRAME(proxy_frame), proxy_checkbtn);
3225 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
3226 gtk_container_add (GTK_CONTAINER (proxy_frame), vbox2);
3227 gtk_container_set_border_width (GTK_CONTAINER (vbox2), 8);
3229 default_proxy_checkbtn =
3230 gtk_check_button_new_with_label (C_("In account preferences, referring to whether or not use proxy settings from common preferences", "Use default settings"));
3231 CLAWS_SET_TIP(default_proxy_checkbtn,
3232 _("Use global proxy server settings"));
3233 gtk_box_pack_start (GTK_BOX (vbox2), default_proxy_checkbtn, FALSE, FALSE, 0);
3235 vbox3 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
3236 gtk_box_pack_start (GTK_BOX (vbox2), vbox3, FALSE, FALSE, 0);
3238 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
3239 gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
3241 socks4_radiobtn = gtk_radio_button_new_with_label(NULL, "SOCKS4");
3242 gtk_box_pack_start (GTK_BOX (hbox), socks4_radiobtn, FALSE, FALSE, 0);
3243 g_object_set_data(G_OBJECT(socks4_radiobtn), MENU_VAL_ID,
3244 GINT_TO_POINTER(PROXY_SOCKS4));
3246 CREATE_RADIO_BUTTON(hbox, socks5_radiobtn, socks4_radiobtn, "SOCKS5",
3247 PROXY_SOCKS5);
3249 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8);
3250 gtk_box_pack_start (GTK_BOX (vbox3), hbox, FALSE, FALSE, 0);
3252 label = gtk_label_new(_("Hostname"));
3253 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3255 proxy_host_entry = gtk_entry_new();
3256 gtk_widget_set_size_request(proxy_host_entry, DEFAULT_ENTRY_WIDTH, -1);
3257 gtk_box_pack_start(GTK_BOX(hbox), proxy_host_entry, TRUE, TRUE, 0);
3259 label = gtk_label_new(_("Port"));
3260 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0);
3262 proxy_port_spinbtn = gtk_spin_button_new_with_range(0, 65535, 1080);
3263 gtk_widget_set_size_request(proxy_port_spinbtn, 64, -1);
3264 gtk_box_pack_start(GTK_BOX(hbox), proxy_port_spinbtn, FALSE, FALSE, 0);
3266 vbox4 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW);
3267 gtk_box_pack_start(GTK_BOX(vbox3), vbox4, FALSE, FALSE, 0);
3269 PACK_CHECK_BUTTON (vbox4, proxy_auth_checkbtn, _("Use authentication"));
3271 table = gtk_grid_new();
3272 gtk_box_pack_start (GTK_BOX (vbox4), table, FALSE, FALSE, 0);
3274 label = gtk_label_new(_("Username"));
3275 gtk_grid_attach(GTK_GRID(table), label, 0, 0, 1, 1);
3277 proxy_name_entry = gtk_entry_new();
3278 gtk_widget_set_size_request(proxy_name_entry, DEFAULT_ENTRY_WIDTH, -1);
3279 gtk_grid_attach(GTK_GRID(table), proxy_name_entry, 1, 0, 1, 1);
3280 gtk_widget_set_hexpand(proxy_name_entry, TRUE);
3281 gtk_widget_set_halign(proxy_name_entry, GTK_ALIGN_FILL);
3283 label = gtk_label_new(_("Password"));
3284 gtk_grid_attach(GTK_GRID(table), label, 2, 0, 1, 1);
3286 proxy_pass_entry = gtk_entry_new();
3287 gtk_widget_set_size_request(proxy_pass_entry, DEFAULT_ENTRY_WIDTH, -1);
3288 gtk_entry_set_visibility(GTK_ENTRY(proxy_pass_entry), FALSE);
3289 gtk_grid_attach(GTK_GRID(table), proxy_pass_entry, 3, 0, 1, 1);
3290 gtk_widget_set_hexpand(proxy_pass_entry, TRUE);
3291 gtk_widget_set_halign(proxy_pass_entry, GTK_ALIGN_FILL);
3293 button = gtk_check_button_new_with_label(_("Show password"));
3294 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), FALSE);
3295 gtk_grid_attach(GTK_GRID(table), button, 3, 1, 1, 1);
3297 g_signal_connect(G_OBJECT(button), "toggled",
3298 G_CALLBACK(prefs_account_showpwd_checkbtn_toggled), proxy_pass_entry);
3300 gtk_box_pack_start(GTK_BOX(vbox2), gtk_separator_new(GTK_ORIENTATION_HORIZONTAL), FALSE, FALSE, 0);
3302 PACK_CHECK_BUTTON(vbox2, proxy_send_checkbtn,
3303 _("Use proxy server for sending"));
3304 CLAWS_SET_TIP(proxy_send_checkbtn,
3305 _("If disabled, messages will be sent using direct connection to configured outgoing server, bypassing any configured proxy server."));
3307 SET_TOGGLE_SENSITIVITY(proxy_auth_checkbtn, table);
3308 SET_TOGGLE_SENSITIVITY(socks5_radiobtn, vbox4);
3309 SET_TOGGLE_SENSITIVITY(proxy_checkbtn, vbox2);
3310 SET_TOGGLE_SENSITIVITY_REVERSE(default_proxy_checkbtn, vbox3);
3312 gtk_widget_show_all(vbox1);
3314 page->proxy_checkbtn = proxy_checkbtn;
3315 page->default_proxy_checkbtn = default_proxy_checkbtn;
3316 page->socks4_radiobtn = socks4_radiobtn;
3317 page->socks5_radiobtn = socks5_radiobtn;
3318 page->proxy_host_entry = proxy_host_entry;
3319 page->proxy_port_spinbtn = proxy_port_spinbtn;
3320 page->proxy_auth_checkbtn = proxy_auth_checkbtn;
3321 page->proxy_name_entry = proxy_name_entry;
3322 page->proxy_pass_entry = proxy_pass_entry;
3323 page->proxy_send_checkbtn = proxy_send_checkbtn;
3324 page->vbox = vbox1;
3325 page->page.widget = vbox1;
3327 tmp_ac_prefs = *ac_prefs;
3329 if (new_account) {
3330 prefs_set_dialog_to_default(proxy_param);
3331 } else {
3332 prefs_set_dialog(proxy_param);
3334 /* Passwords are handled outside of PrefParams. */
3335 buf = passwd_store_get_account(ac_prefs->account_id,
3336 PWS_ACCOUNT_PROXY_PASS);
3337 gtk_entry_set_text(GTK_ENTRY(page->proxy_pass_entry),
3338 buf != NULL ? buf : "");
3339 if (buf != NULL) {
3340 memset(buf, 0, strlen(buf));
3341 g_free(buf);
3345 page->vbox = vbox1;
3347 page->page.widget = vbox1;
3350 static void advanced_create_widget_func(PrefsPage * _page,
3351 GtkWindow * window,
3352 gpointer data)
3354 AdvancedPage *page = (AdvancedPage *) _page;
3355 PrefsAccount *ac_prefs = (PrefsAccount *) data;
3357 GtkWidget *vbox1;
3358 GtkWidget *vbox2;
3359 GtkWidget *hbox1;
3360 GtkWidget *checkbtn_smtpport;
3361 GtkWidget *spinbtn_smtpport;
3362 GtkWidget *hbox_popport;
3363 GtkWidget *checkbtn_popport;
3364 GtkWidget *spinbtn_popport;
3365 GtkWidget *hbox_imapport;
3366 GtkWidget *checkbtn_imapport;
3367 GtkWidget *spinbtn_imapport;
3368 GtkWidget *hbox_nntpport;
3369 GtkWidget *checkbtn_nntpport;
3370 GtkWidget *spinbtn_nntpport;
3371 GtkWidget *checkbtn_domain;
3372 GtkWidget *entry_domain;
3373 gchar *tip_domain;
3374 GtkWidget *checkbtn_crosspost;
3375 GtkWidget *colormenu_crosspost;
3376 #ifndef G_OS_WIN32
3377 GtkWidget *checkbtn_tunnelcmd;
3378 GtkWidget *entry_tunnelcmd;
3379 #endif
3380 GtkWidget *folder_frame;
3381 GtkWidget *vbox3;
3382 GtkWidget *table;
3383 GtkWidget *sent_folder_checkbtn;
3384 GtkWidget *sent_folder_entry;
3385 GtkWidget *queue_folder_checkbtn;
3386 GtkWidget *queue_folder_entry;
3387 GtkWidget *draft_folder_checkbtn;
3388 GtkWidget *draft_folder_entry;
3389 GtkWidget *trash_folder_checkbtn;
3390 GtkWidget *trash_folder_entry;
3391 GtkSizeGroup *size_group = gtk_size_group_new(GTK_SIZE_GROUP_HORIZONTAL);
3393 #define PACK_HBOX(hbox) \
3395 hbox = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 8); \
3396 gtk_widget_show (hbox); \
3397 gtk_box_pack_start (GTK_BOX (vbox2), hbox, FALSE, FALSE, 0); \
3400 #define PACK_PORT_SPINBTN(box, spinbtn) \
3402 spinbtn = gtk_spin_button_new_with_range(0, 65535, 1); \
3403 gtk_widget_show (spinbtn); \
3404 gtk_box_pack_start (GTK_BOX (box), spinbtn, FALSE, FALSE, 0); \
3407 vbox1 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING);
3408 gtk_widget_show (vbox1);
3409 gtk_container_set_border_width (GTK_CONTAINER (vbox1), VBOX_BORDER);
3411 vbox2 = gtk_box_new(GTK_ORIENTATION_VERTICAL, VSPACING_NARROW_2);
3412 gtk_widget_show (vbox2);
3413 gtk_box_pack_start (GTK_BOX (vbox1), vbox2, FALSE, FALSE, 0);
3415 PACK_HBOX (hbox1);
3416 PACK_CHECK_BUTTON (hbox1, checkbtn_smtpport, _("SMTP port"));
3417 PACK_PORT_SPINBTN (hbox1, spinbtn_smtpport);
3418 SET_TOGGLE_SENSITIVITY (checkbtn_smtpport, spinbtn_smtpport);
3419 gtk_size_group_add_widget(size_group, checkbtn_smtpport);
3421 PACK_HBOX (hbox_popport);
3422 PACK_CHECK_BUTTON (hbox_popport, checkbtn_popport,
3423 _("POP port"));
3424 PACK_PORT_SPINBTN (hbox_popport, spinbtn_popport);
3425 SET_TOGGLE_SENSITIVITY (checkbtn_popport, spinbtn_popport);
3426 gtk_size_group_add_widget(size_group, checkbtn_popport);
3428 PACK_HBOX (hbox_imapport);
3429 PACK_CHECK_BUTTON (hbox_imapport, checkbtn_imapport,
3430 _("IMAP port"));
3431 PACK_PORT_SPINBTN (hbox_imapport, spinbtn_imapport);
3432 SET_TOGGLE_SENSITIVITY (checkbtn_imapport, spinbtn_imapport);
3433 gtk_size_group_add_widget(size_group, checkbtn_imapport);
3435 PACK_HBOX (hbox_nntpport);
3436 PACK_CHECK_BUTTON (hbox_nntpport, checkbtn_nntpport,
3437 _("NNTP port"));
3438 PACK_PORT_SPINBTN (hbox_nntpport, spinbtn_nntpport);
3439 SET_TOGGLE_SENSITIVITY (checkbtn_nntpport, spinbtn_nntpport);
3440 gtk_size_group_add_widget(size_group, checkbtn_nntpport);
3442 PACK_HBOX (hbox1);
3443 PACK_CHECK_BUTTON (hbox1, checkbtn_domain, _("Domain name"));
3444 gtk_size_group_add_widget(size_group, checkbtn_domain);
3446 tip_domain = _("The domain name will be used in the generated "
3447 "Message-ID, and when connecting to SMTP servers.");
3449 CLAWS_SET_TIP(checkbtn_domain, tip_domain);
3451 entry_domain = gtk_entry_new ();
3452 gtk_widget_show (entry_domain);
3453 gtk_box_pack_start (GTK_BOX (hbox1), entry_domain, TRUE, TRUE, 0);
3454 SET_TOGGLE_SENSITIVITY (checkbtn_domain, entry_domain);
3455 CLAWS_SET_TIP(entry_domain, tip_domain);
3457 #ifndef G_OS_WIN32
3458 PACK_HBOX (hbox1);
3459 PACK_CHECK_BUTTON (hbox1, checkbtn_tunnelcmd,
3460 _("Use command to communicate with server"));
3461 entry_tunnelcmd = gtk_entry_new ();
3462 gtk_widget_show (entry_tunnelcmd);
3463 gtk_box_pack_start (GTK_BOX (hbox1), entry_tunnelcmd, TRUE, TRUE, 0);
3464 SET_TOGGLE_SENSITIVITY (checkbtn_tunnelcmd, entry_tunnelcmd);
3465 #endif
3467 PACK_HBOX (hbox1);
3468 PACK_CHECK_BUTTON (hbox1, checkbtn_crosspost,
3469 _("Mark cross-posted messages as read and color:"));
3470 g_signal_connect (G_OBJECT (checkbtn_crosspost), "toggled",
3471 G_CALLBACK (crosspost_color_toggled),
3472 NULL);
3474 colormenu_crosspost = colorlabel_create_combobox_colormenu();
3475 gtk_widget_show (colormenu_crosspost);
3476 gtk_box_pack_start (GTK_BOX (hbox1), colormenu_crosspost, FALSE, FALSE, 0);
3478 SET_TOGGLE_SENSITIVITY(checkbtn_crosspost, colormenu_crosspost);
3479 #undef PACK_HBOX
3480 #undef PACK_PORT_SPINBTN
3482 /* special folder setting (maybe these options are redundant) */
3484 vbox3 = gtkut_get_options_frame(vbox1, &folder_frame, _("Folder"));
3486 table = gtk_grid_new();
3487 gtk_widget_show (table);
3488 gtk_container_add (GTK_CONTAINER (vbox3), table);
3489 gtk_grid_set_row_spacing(GTK_GRID(table), VSPACING_NARROW_2);
3490 gtk_grid_set_column_spacing(GTK_GRID(table), 4);
3492 #define SET_CHECK_BTN_AND_ENTRY(label, checkbtn, entry, n) \
3494 GtkWidget *button; \
3496 checkbtn = gtk_check_button_new_with_label (label); \
3497 gtk_widget_show (checkbtn); \
3498 gtk_grid_attach(GTK_GRID(table), checkbtn, 0, n, 1, 1); \
3500 entry = gtk_entry_new (); \
3501 gtk_widget_show (entry); \
3502 gtk_grid_attach(GTK_GRID(table), entry, 1, n, 1, 1); \
3503 gtk_widget_set_hexpand(entry, TRUE); \
3504 gtk_widget_set_halign(entry, GTK_ALIGN_FILL); \
3506 button = gtkut_get_browse_file_btn(_("Browse")); \
3507 gtk_widget_show (button); \
3508 gtk_grid_attach(GTK_GRID(table), button, 2, n, 1, 1); \
3509 g_signal_connect \
3510 (G_OBJECT (button), "clicked", \
3511 G_CALLBACK (prefs_account_select_folder_cb), \
3512 entry); \
3514 SET_TOGGLE_SENSITIVITY (checkbtn, entry); \
3515 SET_TOGGLE_SENSITIVITY (checkbtn, button); \
3518 SET_CHECK_BTN_AND_ENTRY(_("Put sent messages in"),
3519 sent_folder_checkbtn, sent_folder_entry, 0);
3520 SET_CHECK_BTN_AND_ENTRY(_("Put queued messages in"),
3521 queue_folder_checkbtn, queue_folder_entry, 1);
3522 SET_CHECK_BTN_AND_ENTRY(_("Put draft messages in"),
3523 draft_folder_checkbtn, draft_folder_entry, 2);
3524 SET_CHECK_BTN_AND_ENTRY(_("Put deleted messages in"),
3525 trash_folder_checkbtn, trash_folder_entry, 3);
3527 page->smtpport_checkbtn = checkbtn_smtpport;
3528 page->smtpport_spinbtn = spinbtn_smtpport;
3529 page->popport_hbox = hbox_popport;
3530 page->popport_checkbtn = checkbtn_popport;
3531 page->popport_spinbtn = spinbtn_popport;
3532 page->imapport_hbox = hbox_imapport;
3533 page->imapport_checkbtn = checkbtn_imapport;
3534 page->imapport_spinbtn = spinbtn_imapport;
3535 page->nntpport_hbox = hbox_nntpport;
3536 page->nntpport_checkbtn = checkbtn_nntpport;
3537 page->nntpport_spinbtn = spinbtn_nntpport;
3538 page->domain_checkbtn = checkbtn_domain;
3539 page->domain_entry = entry_domain;
3540 page->crosspost_checkbtn = checkbtn_crosspost;
3541 page->crosspost_colormenu = colormenu_crosspost;
3543 #ifndef G_OS_WIN32
3544 page->tunnelcmd_checkbtn = checkbtn_tunnelcmd;
3545 page->tunnelcmd_entry = entry_tunnelcmd;
3546 #endif
3547 page->sent_folder_checkbtn = sent_folder_checkbtn;
3548 page->sent_folder_entry = sent_folder_entry;
3549 page->queue_folder_checkbtn = queue_folder_checkbtn;
3550 page->queue_folder_entry = queue_folder_entry;
3551 page->draft_folder_checkbtn = draft_folder_checkbtn;
3552 page->draft_folder_entry = draft_folder_entry;
3553 page->trash_folder_checkbtn = trash_folder_checkbtn;
3554 page->trash_folder_entry = trash_folder_entry;
3556 tmp_ac_prefs = *ac_prefs;
3558 if (new_account) {
3559 prefs_set_dialog_to_default(advanced_param);
3560 } else
3561 prefs_set_dialog(advanced_param);
3563 page->vbox = vbox1;
3565 page->page.widget = vbox1;
3567 g_object_unref(G_OBJECT(size_group));
3570 static gint prefs_basic_apply(void)
3572 RecvProtocol protocol;
3573 gchar *old_id = NULL;
3574 gchar *new_id = NULL;
3575 struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *) basic_page.protocol_optmenu;
3576 GtkWidget *optmenu = protocol_optmenu->combobox;
3578 protocol = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
3580 if (*gtk_entry_get_text(GTK_ENTRY(basic_page.acname_entry)) == '\0') {
3581 alertpanel_error(_("Account name is not entered."));
3582 return -1;
3584 if (*gtk_entry_get_text(GTK_ENTRY(basic_page.addr_entry)) == '\0') {
3585 alertpanel_error(_("Mail address is not entered."));
3586 return -1;
3589 if (((protocol == A_POP3) ||
3590 (protocol == A_LOCAL && !gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic_page.mailcmd_checkbtn))) ||
3591 (protocol == A_NONE)) &&
3592 *gtk_entry_get_text(GTK_ENTRY(basic_page.smtpserv_entry)) == '\0') {
3593 alertpanel_error(_("SMTP server is not entered."));
3594 return -1;
3596 if ((protocol == A_POP3 || protocol == A_IMAP4) &&
3597 *gtk_entry_get_text(GTK_ENTRY(basic_page.uid_entry)) == '\0') {
3598 alertpanel_error(_("User ID is not entered."));
3599 return -1;
3601 if (protocol == A_POP3 &&
3602 *gtk_entry_get_text(GTK_ENTRY(basic_page.recvserv_entry)) == '\0') {
3603 alertpanel_error(_("POP server is not entered."));
3604 return -1;
3606 if (protocol == A_POP3 || protocol == A_LOCAL) {
3607 GtkWidget *inbox_entry = (protocol == A_POP3 ? receive_page.inbox_entry : receive_page.local_inbox_entry );
3608 const gchar *mailbox = gtk_entry_get_text(GTK_ENTRY(inbox_entry));
3609 FolderItem *inbox = folder_find_item_from_identifier(mailbox);
3610 if (!inbox) {
3611 gchar *id = NULL;
3612 setup_write_mailbox_path(mainwindow_get_mainwindow(), "Mail");
3613 id = folder_item_get_identifier(folder_get_default_inbox_for_class(F_MH));
3614 gtk_entry_set_text(GTK_ENTRY(receive_page.inbox_entry),
3615 id);
3616 gtk_entry_set_text(GTK_ENTRY(receive_page.local_inbox_entry),
3617 id);
3618 g_free(id);
3619 mailbox = gtk_entry_get_text(GTK_ENTRY(inbox_entry));
3620 inbox = folder_find_item_from_identifier(mailbox);
3622 if (inbox == NULL) {
3623 alertpanel_error(_("The default Inbox folder doesn't exist."));
3624 return -1;
3627 if (protocol == A_IMAP4 &&
3628 *gtk_entry_get_text(GTK_ENTRY(basic_page.recvserv_entry)) == '\0') {
3629 alertpanel_error(_("IMAP server is not entered."));
3630 return -1;
3632 if (protocol == A_NNTP &&
3633 *gtk_entry_get_text(GTK_ENTRY(basic_page.nntpserv_entry)) == '\0') {
3634 alertpanel_error(_("NNTP server is not entered."));
3635 return -1;
3638 if (protocol == A_LOCAL &&
3639 *gtk_entry_get_text(GTK_ENTRY(basic_page.localmbox_entry)) == '\0') {
3640 alertpanel_error(_("local mailbox filename is not entered."));
3641 return -1;
3644 if (protocol == A_LOCAL &&
3645 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(basic_page.mailcmd_checkbtn)) && *gtk_entry_get_text(GTK_ENTRY(basic_page.mailcmd_entry)) == '\0') {
3646 alertpanel_error(_("mail command is not entered."));
3647 return -1;
3650 if (protocol == A_IMAP4 || protocol == A_NNTP)
3651 old_id = g_strdup_printf("#%s/%s",
3652 protocol == A_IMAP4 ? "imap":"news",
3653 tmp_ac_prefs.account_name ? tmp_ac_prefs.account_name : "(null)");
3655 if (strchr(gtk_entry_get_text(GTK_ENTRY(basic_page.uid_entry)), '\n') != NULL) {
3656 alertpanel_error(_("User ID cannot contain a newline character."));
3657 if (old_id)
3658 g_free(old_id);
3659 return -1;
3662 if (strchr(gtk_entry_get_text(GTK_ENTRY(basic_page.pass_entry)), '\n') != NULL) {
3663 alertpanel_error(_("Password cannot contain a newline character."));
3664 if (old_id)
3665 g_free(old_id);
3666 return -1;
3669 prefs_set_data_from_dialog(basic_param);
3671 /* Passwords are stored outside of PrefParams. */
3672 passwd_store_set_account(tmp_ac_prefs.account_id,
3673 PWS_ACCOUNT_RECV,
3674 gtk_entry_get_text(GTK_ENTRY(basic_page.pass_entry)),
3675 FALSE);
3677 #ifdef USE_OAUTH2
3678 /* Manual password change - reset expiry on OAUTH2 tokens*/
3679 passwd_store_set_account(tmp_ac_prefs.account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, "0", FALSE);
3680 #endif
3682 if (protocol == A_IMAP4 || protocol == A_NNTP) {
3683 new_id = g_strdup_printf("#%s/%s",
3684 protocol == A_IMAP4 ? "imap":"news",
3685 tmp_ac_prefs.account_name);
3686 if (old_id != NULL && new_id != NULL)
3687 prefs_filtering_rename_path(old_id, new_id);
3688 if (old_id)
3689 g_free(old_id);
3690 if (new_id)
3691 g_free(new_id);
3694 return 0;
3697 static gint prefs_receive_apply(void)
3699 if (strchr(gtk_entry_get_text(GTK_ENTRY(send_page.smtp_uid_entry)), '\n') != NULL) {
3700 alertpanel_error(_("SMTP user ID cannot contain a newline character."));
3701 return -1;
3704 if (strchr(gtk_entry_get_text(GTK_ENTRY(send_page.smtp_pass_entry)), '\n') != NULL) {
3705 alertpanel_error(_("SMTP password cannot contain a newline character."));
3706 return -1;
3709 prefs_set_data_from_dialog(receive_param);
3711 return 0;
3714 static gint prefs_send_apply(void)
3716 prefs_set_data_from_dialog(send_param);
3718 /* Passwords are stored outside of PrefParams. */
3719 passwd_store_set_account(tmp_ac_prefs.account_id,
3720 PWS_ACCOUNT_SEND,
3721 gtk_entry_get_text(GTK_ENTRY(send_page.smtp_pass_entry)),
3722 FALSE);
3723 #ifdef USE_OAUTH2
3724 /* Manual password change - reset expiry on OAUTH2 tokens*/
3725 if (tmp_ac_prefs.use_smtp_auth && tmp_ac_prefs.smtp_auth_type == SMTPAUTH_OAUTH2)
3726 passwd_store_set_account(tmp_ac_prefs.account_id, PWS_ACCOUNT_OAUTH2_EXPIRY, "0", FALSE);
3727 #endif
3729 return 0;
3732 #ifdef USE_OAUTH2
3733 static gint prefs_oauth2_apply(void)
3735 prefs_set_data_from_dialog(oauth2_param);
3737 /* Passwords are stored outside of PrefParams. */
3738 passwd_store_set_account(tmp_ac_prefs.account_id,
3739 PWS_ACCOUNT_OAUTH2_AUTH,
3740 gtk_entry_get_text(GTK_ENTRY(oauth2_page.oauth2_authcode_entry)),
3741 FALSE);
3743 return 0;
3745 #endif
3747 static gint prefs_compose_apply(void)
3749 prefs_set_data_from_dialog(compose_param);
3750 return 0;
3753 static gint prefs_templates_apply(void)
3755 prefs_set_data_from_dialog(templates_param);
3756 return 0;
3759 static gint prefs_privacy_apply(void)
3761 prefs_set_data_from_dialog(privacy_param);
3762 return 0;
3765 #ifdef USE_GNUTLS
3766 static gint prefs_ssl_apply(void)
3768 prefs_set_data_from_dialog(ssl_param);
3770 /* Passwords are stored outside of PrefParams. */
3771 passwd_store_set_account(tmp_ac_prefs.account_id,
3772 PWS_ACCOUNT_RECV_CERT,
3773 gtk_entry_get_text(GTK_ENTRY(ssl_page.entry_in_cert_pass)),
3774 FALSE);
3775 passwd_store_set_account(tmp_ac_prefs.account_id,
3776 PWS_ACCOUNT_SEND_CERT,
3777 gtk_entry_get_text(GTK_ENTRY(ssl_page.entry_out_cert_pass)),
3778 FALSE);
3780 return 0;
3782 #endif
3784 static gint prefs_proxy_apply(void)
3786 prefs_set_data_from_dialog(proxy_param);
3788 /* Passwords are stored outside of PrefParams. */
3789 passwd_store_set_account(tmp_ac_prefs.account_id,
3790 PWS_ACCOUNT_PROXY_PASS,
3791 gtk_entry_get_text(GTK_ENTRY(proxy_page.proxy_pass_entry)),
3792 FALSE);
3794 return 0;
3797 static gint prefs_advanced_apply(void)
3799 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(advanced_page.domain_checkbtn)) &&
3800 *gtk_entry_get_text(GTK_ENTRY(advanced_page.domain_entry)) == '\0') {
3801 alertpanel_error(_("domain is not specified."));
3802 return -1;
3804 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(advanced_page.sent_folder_checkbtn)) &&
3805 *gtk_entry_get_text(GTK_ENTRY(advanced_page.sent_folder_entry)) == '\0') {
3806 alertpanel_error(_("sent folder is not selected."));
3807 return -1;
3809 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(advanced_page.queue_folder_checkbtn)) &&
3810 *gtk_entry_get_text(GTK_ENTRY(advanced_page.queue_folder_entry)) == '\0') {
3811 alertpanel_error(_("queue folder is not selected."));
3812 return -1;
3814 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(advanced_page.draft_folder_checkbtn)) &&
3815 *gtk_entry_get_text(GTK_ENTRY(advanced_page.draft_folder_entry)) == '\0') {
3816 alertpanel_error(_("draft folder is not selected."));
3817 return -1;
3819 if (gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(advanced_page.trash_folder_checkbtn)) &&
3820 *gtk_entry_get_text(GTK_ENTRY(advanced_page.trash_folder_entry)) == '\0') {
3821 alertpanel_error(_("trash folder is not selected."));
3822 return -1;
3825 prefs_set_data_from_dialog(advanced_param);
3826 return 0;
3829 static void basic_destroy_widget_func(PrefsPage *_page)
3831 /* BasicPage *page = (BasicPage *) _page; */
3834 static void receive_destroy_widget_func(PrefsPage *_page)
3836 /* ReceivePage *page = (ReceivePage *) _page; */
3839 static void send_destroy_widget_func(PrefsPage *_page)
3841 /* SendPage *page = (SendPage *) _page; */
3844 #ifdef USE_OAUTH2
3845 static void oauth2_destroy_widget_func(PrefsPage *_page)
3847 /* Oauth2Page *page = (Oauth2Page *) _page; */
3849 if(oauth2_listener_task){
3850 debug_print("Closing oauth2 listener task\n");
3851 oauth2_listener_cancel = 1;
3854 #endif
3856 static void compose_destroy_widget_func(PrefsPage *_page)
3858 /* ComposePage *page = (ComposePage *) _page; */
3861 static void templates_destroy_widget_func(PrefsPage *_page)
3863 /* TemplatesPage *page = (TemplatesPage *) _page; */
3866 static void privacy_destroy_widget_func(PrefsPage *_page)
3868 /* PrivacyPage *page = (PrivacyPage *) _page; */
3871 #ifdef USE_GNUTLS
3872 static void ssl_destroy_widget_func(PrefsPage *_page)
3874 /* SSLPage *page = (SSLPage *) _page; */
3876 #endif
3878 static void proxy_destroy_widget_func(PrefsPage *_page)
3880 /* ProxyPage *page = (ProxyPage *) _page; */
3883 static void advanced_destroy_widget_func(PrefsPage *_page)
3885 /* AdvancedPage *page = (AdvancedPage *) _page; */
3888 static gboolean basic_can_close_func(PrefsPage *_page)
3890 BasicPage *page = (BasicPage *) _page;
3892 if (!page->page.page_open)
3893 return TRUE;
3895 return prefs_basic_apply() >= 0;
3898 static gboolean receive_can_close_func(PrefsPage *_page)
3900 ReceivePage *page = (ReceivePage *) _page;
3902 if (!page->page.page_open)
3903 return TRUE;
3905 return prefs_receive_apply() >= 0;
3908 static gboolean send_can_close_func(PrefsPage *_page)
3910 SendPage *page = (SendPage *) _page;
3912 if (!page->page.page_open)
3913 return TRUE;
3915 return prefs_send_apply() >= 0;
3918 #ifdef USE_OAUTH2
3919 static gboolean oauth2_can_close_func(PrefsPage *_page)
3921 Oauth2Page *page = (Oauth2Page *) _page;
3923 if (!page->page.page_open)
3924 return TRUE;
3926 return prefs_oauth2_apply() >= 0;
3928 #endif
3930 static gboolean compose_can_close_func(PrefsPage *_page)
3932 ComposePage *page = (ComposePage *) _page;
3934 if (!page->page.page_open)
3935 return TRUE;
3937 return prefs_compose_apply() >= 0;
3940 static gboolean templates_can_close_func(PrefsPage *_page)
3942 TemplatesPage *page = (TemplatesPage *) _page;
3944 if (!page->page.page_open)
3945 return TRUE;
3947 return prefs_templates_apply() >= 0;
3950 static gboolean privacy_can_close_func(PrefsPage *_page)
3952 PrivacyPage *page = (PrivacyPage *) _page;
3954 if (!page->page.page_open)
3955 return TRUE;
3957 return prefs_privacy_apply() >= 0;
3960 #ifdef USE_GNUTLS
3961 static gboolean ssl_can_close_func(PrefsPage *_page)
3963 SSLPage *page = (SSLPage *) _page;
3965 if (!page->page.page_open)
3966 return TRUE;
3968 return prefs_ssl_apply() >= 0;
3970 #endif
3972 static gboolean proxy_can_close_func(PrefsPage *_page)
3974 ProxyPage *page = (ProxyPage *) _page;
3976 if (!page->page.page_open)
3977 return TRUE;
3979 return prefs_proxy_apply() >= 0;
3982 static gboolean advanced_can_close_func(PrefsPage *_page)
3984 AdvancedPage *page = (AdvancedPage *) _page;
3986 if (!page->page.page_open)
3987 return TRUE;
3989 return prefs_advanced_apply() >= 0;
3992 static void basic_save_func(PrefsPage *_page)
3994 BasicPage *page = (BasicPage *) _page;
3996 if (!page->page.page_open)
3997 return;
3999 if (prefs_basic_apply() >= 0)
4000 cancelled = FALSE;
4003 static void receive_save_func(PrefsPage *_page)
4005 ReceivePage *page = (ReceivePage *) _page;
4007 if (!page->page.page_open)
4008 return;
4010 if (prefs_receive_apply() >= 0)
4011 cancelled = FALSE;
4014 static void send_save_func(PrefsPage *_page)
4016 SendPage *page = (SendPage *) _page;
4018 if (!page->page.page_open)
4019 return;
4021 if (prefs_send_apply() >= 0)
4022 cancelled = FALSE;
4025 #ifdef USE_OAUTH2
4026 static void oauth2_save_func(PrefsPage *_page)
4028 Oauth2Page *page = (Oauth2Page *) _page;
4030 if (!page->page.page_open)
4031 return;
4033 if (prefs_oauth2_apply() >= 0)
4034 cancelled = FALSE;
4036 #endif
4038 static void compose_save_func(PrefsPage *_page)
4040 ComposePage *page = (ComposePage *) _page;
4042 if (!page->page.page_open)
4043 return;
4045 if (prefs_compose_apply() >= 0)
4046 cancelled = FALSE;
4049 static void templates_save_func(PrefsPage *_page)
4051 TemplatesPage *page = (TemplatesPage *) _page;
4053 if (!page->page.page_open)
4054 return;
4056 quotefmt_check_new_msg_formats(tmp_ac_prefs.compose_with_format,
4057 NULL,
4058 tmp_ac_prefs.compose_subject_format,
4059 tmp_ac_prefs.compose_body_format);
4060 quotefmt_check_reply_formats(tmp_ac_prefs.reply_with_format,
4061 NULL,
4062 tmp_ac_prefs.reply_quotemark,
4063 tmp_ac_prefs.reply_body_format);
4064 quotefmt_check_forward_formats(tmp_ac_prefs.forward_with_format,
4065 NULL,
4066 tmp_ac_prefs.forward_quotemark,
4067 tmp_ac_prefs.forward_body_format);
4068 if (prefs_templates_apply() >= 0)
4069 cancelled = FALSE;
4072 static void privacy_save_func(PrefsPage *_page)
4074 PrivacyPage *page = (PrivacyPage *) _page;
4076 if (!page->page.page_open)
4077 return;
4079 if (prefs_privacy_apply() >= 0)
4080 cancelled = FALSE;
4083 #ifdef USE_GNUTLS
4084 static void ssl_save_func(PrefsPage *_page)
4086 SSLPage *page = (SSLPage *) _page;
4088 if (!page->page.page_open)
4089 return;
4091 if (prefs_ssl_apply() >= 0)
4092 cancelled = FALSE;
4094 #endif
4096 static void proxy_save_func(PrefsPage *_page)
4098 ProxyPage *page = (ProxyPage *) _page;
4100 if (!page->page.page_open)
4101 return;
4103 if (prefs_proxy_apply() >= 0)
4104 cancelled = FALSE;
4107 static void advanced_save_func(PrefsPage *_page)
4109 AdvancedPage *page = (AdvancedPage *) _page;
4111 if (!page->page.page_open)
4112 return;
4114 if (prefs_advanced_apply() >= 0)
4115 cancelled = FALSE;
4118 static void register_basic_page(void)
4120 static gchar *path[3];
4122 path[0] = _("Account");
4123 path[1] = _("Basic");
4124 path[2] = NULL;
4126 basic_page.page.path = path;
4127 basic_page.page.weight = 1000.0;
4128 basic_page.page.create_widget = basic_create_widget_func;
4129 basic_page.page.destroy_widget = basic_destroy_widget_func;
4130 basic_page.page.save_page = basic_save_func;
4131 basic_page.page.can_close = basic_can_close_func;
4133 prefs_account_register_page((PrefsPage *) &basic_page);
4136 static void register_receive_page(void)
4138 static gchar *path[3];
4140 path[0] = _("Account");
4141 path[1] = _("Receive");
4142 path[2] = NULL;
4144 receive_page.page.path = path;
4145 receive_page.page.weight = 1000.0;
4146 receive_page.page.create_widget = receive_create_widget_func;
4147 receive_page.page.destroy_widget = receive_destroy_widget_func;
4148 receive_page.page.save_page = receive_save_func;
4149 receive_page.page.can_close = receive_can_close_func;
4151 prefs_account_register_page((PrefsPage *) &receive_page);
4154 static void register_send_page(void)
4156 static gchar *path[3];
4158 path[0] = _("Account");
4159 path[1] = (gchar *) C_("Preferences menu item", "Send");
4160 path[2] = NULL;
4162 send_page.page.path = path;
4163 send_page.page.weight = 1000.0;
4164 send_page.page.create_widget = send_create_widget_func;
4165 send_page.page.destroy_widget = send_destroy_widget_func;
4166 send_page.page.save_page = send_save_func;
4167 send_page.page.can_close = send_can_close_func;
4169 prefs_account_register_page((PrefsPage *) &send_page);
4172 #ifdef USE_OAUTH2
4173 static void register_oauth2_page(void)
4175 static gchar *path[3];
4177 path[0] = _("Account");
4178 path[1] = _("OAuth2");
4179 path[2] = NULL;
4181 oauth2_page.page.path = path;
4182 oauth2_page.page.weight = 1000.0;
4183 oauth2_page.page.create_widget = oauth2_create_widget_func;
4184 oauth2_page.page.destroy_widget = oauth2_destroy_widget_func;
4185 oauth2_page.page.save_page = oauth2_save_func;
4186 oauth2_page.page.can_close = oauth2_can_close_func;
4188 prefs_account_register_page((PrefsPage *) &oauth2_page);
4190 #endif
4192 static void register_compose_page(void)
4194 static gchar *path[3];
4196 path[0] = _("Account");
4197 path[1] = _("Compose");
4198 path[2] = NULL;
4200 compose_page.page.path = path;
4201 compose_page.page.weight = 1000.0;
4202 compose_page.page.create_widget = compose_create_widget_func;
4203 compose_page.page.destroy_widget = compose_destroy_widget_func;
4204 compose_page.page.save_page = compose_save_func;
4205 compose_page.page.can_close = compose_can_close_func;
4207 prefs_account_register_page((PrefsPage *) &compose_page);
4210 static void register_templates_page(void)
4212 static gchar *path[3];
4214 path[0] = _("Account");
4215 path[1] = _("Templates");
4216 path[2] = NULL;
4218 templates_page.page.path = path;
4219 templates_page.page.weight = 1000.0;
4220 templates_page.page.create_widget = templates_create_widget_func;
4221 templates_page.page.destroy_widget = templates_destroy_widget_func;
4222 templates_page.page.save_page = templates_save_func;
4223 templates_page.page.can_close = templates_can_close_func;
4225 prefs_account_register_page((PrefsPage *) &templates_page);
4228 static void register_privacy_page(void)
4230 static gchar *path[3];
4232 path[0] = _("Account");
4233 path[1] = _("Privacy");
4234 path[2] = NULL;
4236 privacy_page.page.path = path;
4237 privacy_page.page.weight = 1000.0;
4238 privacy_page.page.create_widget = privacy_create_widget_func;
4239 privacy_page.page.destroy_widget = privacy_destroy_widget_func;
4240 privacy_page.page.save_page = privacy_save_func;
4241 privacy_page.page.can_close = privacy_can_close_func;
4243 prefs_account_register_page((PrefsPage *) &privacy_page);
4246 #ifdef USE_GNUTLS
4247 static void register_ssl_page(void)
4249 static gchar *path[3];
4251 path[0] = _("Account");
4252 path[1] = _("TLS");
4253 path[2] = NULL;
4255 ssl_page.page.path = path;
4256 ssl_page.page.weight = 1000.0;
4257 ssl_page.page.create_widget = ssl_create_widget_func;
4258 ssl_page.page.destroy_widget = ssl_destroy_widget_func;
4259 ssl_page.page.save_page = ssl_save_func;
4260 ssl_page.page.can_close = ssl_can_close_func;
4262 prefs_account_register_page((PrefsPage *) &ssl_page);
4265 static gboolean sslcert_get_client_cert_hook(gpointer source, gpointer data)
4267 SSLClientCertHookData *hookdata = (SSLClientCertHookData *)source;
4268 PrefsAccount *account = (PrefsAccount *)hookdata->account;
4269 gchar *pwd_id;
4271 hookdata->cert_path = NULL;
4272 hookdata->password = NULL;
4274 if (!g_list_find(account_get_list(), account)) {
4275 g_warning("can't find account");
4276 return TRUE;
4279 if (hookdata->is_smtp) {
4280 if (account->out_ssl_client_cert_file && *account->out_ssl_client_cert_file)
4281 hookdata->cert_path = account->out_ssl_client_cert_file;
4282 pwd_id = PWS_ACCOUNT_SEND_CERT;
4283 } else {
4284 if (account->in_ssl_client_cert_file && *account->in_ssl_client_cert_file)
4285 hookdata->cert_path = account->in_ssl_client_cert_file;
4286 pwd_id = PWS_ACCOUNT_RECV_CERT;
4289 hookdata->password = passwd_store_get_account(account->account_id, pwd_id);
4290 return TRUE;
4293 struct GetPassData {
4294 GCond cond;
4295 GMutex mutex;
4296 gchar **pass;
4300 static gboolean do_get_pass(gpointer data)
4302 struct GetPassData *pass_data = (struct GetPassData *)data;
4303 g_mutex_lock(&pass_data->mutex);
4304 *(pass_data->pass) = input_dialog_query_password("the PKCS12 client certificate", NULL);
4305 g_cond_signal(&pass_data->cond);
4306 g_mutex_unlock(&pass_data->mutex);
4307 return FALSE;
4309 static gboolean sslcert_get_password(gpointer source, gpointer data)
4311 struct GetPassData pass_data;
4312 /* do complicated stuff to be able to call GTK from the mainloop */
4313 g_cond_init(&pass_data.cond);
4314 g_mutex_init(&pass_data.mutex);
4315 pass_data.pass = (gchar **)source;
4317 g_mutex_lock(&pass_data.mutex);
4319 g_idle_add(do_get_pass, &pass_data);
4321 g_cond_wait(&pass_data.cond, &pass_data.mutex);
4322 g_cond_clear(&pass_data.cond);
4323 g_mutex_unlock(&pass_data.mutex);
4324 g_mutex_clear(&pass_data.mutex);
4326 return TRUE;
4328 #endif
4330 static void register_proxy_page(void)
4332 static gchar *path[3];
4334 path[0] = _("Account");
4335 path[1] = _("Proxy");
4336 path[2] = NULL;
4338 proxy_page.page.path = path;
4339 proxy_page.page.weight = 1000.0;
4340 proxy_page.page.create_widget = proxy_create_widget_func;
4341 proxy_page.page.destroy_widget = proxy_destroy_widget_func;
4342 proxy_page.page.save_page = proxy_save_func;
4343 proxy_page.page.can_close = proxy_can_close_func;
4345 prefs_account_register_page((PrefsPage *) &proxy_page);
4348 static void register_advanced_page(void)
4350 static gchar *path[3];
4352 path[0] = _("Account");
4353 path[1] = _("Advanced");
4354 path[2] = NULL;
4356 advanced_page.page.path = path;
4357 advanced_page.page.weight = 1000.0;
4358 advanced_page.page.create_widget = advanced_create_widget_func;
4359 advanced_page.page.destroy_widget = advanced_destroy_widget_func;
4360 advanced_page.page.save_page = advanced_save_func;
4361 advanced_page.page.can_close = advanced_can_close_func;
4363 prefs_account_register_page((PrefsPage *) &advanced_page);
4366 void prefs_account_init()
4368 register_basic_page();
4369 register_receive_page();
4370 register_send_page();
4371 register_compose_page();
4372 register_templates_page();
4373 register_privacy_page();
4374 #ifdef USE_GNUTLS
4375 register_ssl_page();
4376 hooks_register_hook(SSLCERT_GET_CLIENT_CERT_HOOKLIST, sslcert_get_client_cert_hook, NULL);
4377 hooks_register_hook(SSL_CERT_GET_PASSWORD, sslcert_get_password, NULL);
4378 #endif
4379 register_proxy_page();
4380 #ifdef USE_OAUTH2
4381 register_oauth2_page();
4382 #endif
4383 register_advanced_page();
4386 PrefsAccount *prefs_account_new(void)
4388 PrefsAccount *ac_prefs;
4390 ac_prefs = g_new0(PrefsAccount, 1);
4391 memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
4392 prefs_set_default(basic_param);
4393 prefs_set_default(receive_param);
4394 prefs_set_default(send_param);
4395 prefs_set_default(oauth2_param);
4396 prefs_set_default(compose_param);
4397 prefs_set_default(templates_param);
4398 prefs_set_default(privacy_param);
4399 prefs_set_default(ssl_param);
4400 prefs_set_default(proxy_param);
4401 prefs_set_default(advanced_param);
4402 *ac_prefs = tmp_ac_prefs;
4403 ac_prefs->account_id = prefs_account_get_new_id();
4405 ac_prefs->privacy_prefs = g_hash_table_new(g_str_hash, g_str_equal);
4407 return ac_prefs;
4410 PrefsAccount *prefs_account_new_from_config(const gchar *label)
4412 const gchar *p = label;
4413 gchar *rcpath;
4414 gint id;
4415 gchar **strv, **cur;
4416 gsize len;
4417 PrefsAccount *ac_prefs;
4419 cm_return_val_if_fail(label != NULL, NULL);
4421 ac_prefs = g_new0(PrefsAccount, 1);
4423 /* Load default values to tmp_ac_prefs first, ... */
4424 memset(&tmp_ac_prefs, 0, sizeof(PrefsAccount));
4425 prefs_set_default(basic_param);
4426 prefs_set_default(receive_param);
4427 prefs_set_default(send_param);
4428 prefs_set_default(oauth2_param);
4429 prefs_set_default(compose_param);
4430 prefs_set_default(templates_param);
4431 prefs_set_default(privacy_param);
4432 prefs_set_default(ssl_param);
4433 prefs_set_default(advanced_param);
4435 /* ... overriding them with values from stored config file. */
4436 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
4437 prefs_read_config(basic_param, label, rcpath, NULL);
4438 prefs_read_config(receive_param, label, rcpath, NULL);
4439 prefs_read_config(send_param, label, rcpath, NULL);
4440 prefs_read_config(oauth2_param, label, rcpath, NULL);
4441 prefs_read_config(compose_param, label, rcpath, NULL);
4442 prefs_read_config(templates_param, label, rcpath, NULL);
4443 prefs_read_config(privacy_param, label, rcpath, NULL);
4444 prefs_read_config(ssl_param, label, rcpath, NULL);
4445 prefs_read_config(proxy_param, label, rcpath, NULL);
4446 prefs_read_config(advanced_param, label, rcpath, NULL);
4447 g_free(rcpath);
4449 *ac_prefs = tmp_ac_prefs;
4451 while (*p && !g_ascii_isdigit(*p)) p++;
4452 id = atoi(p);
4453 if (id < 0) g_warning("wrong account id: %d", id);
4454 ac_prefs->account_id = id;
4456 /* Now parse privacy_prefs. */
4457 ac_prefs->privacy_prefs = g_hash_table_new(g_str_hash, g_str_equal);
4458 if (privacy_prefs != NULL) {
4459 strv = g_strsplit(privacy_prefs, ",", 0);
4460 for (cur = strv; *cur != NULL; cur++) {
4461 gchar *encvalue, *tmp;
4463 encvalue = strchr(*cur, '=');
4464 if (encvalue == NULL)
4465 continue;
4466 encvalue[0] = '\0';
4467 encvalue++;
4469 tmp = g_base64_decode_zero(encvalue, &len);
4470 if (len > 0)
4471 g_hash_table_insert(ac_prefs->privacy_prefs, g_strdup(*cur), tmp);
4472 else
4473 g_free(tmp);
4475 g_strfreev(strv);
4476 g_free(privacy_prefs);
4477 privacy_prefs = NULL;
4480 /* For older configurations, move stored passwords into the
4481 * password store. */
4482 gboolean passwords_migrated = FALSE;
4484 if (ac_prefs->passwd != NULL && strlen(ac_prefs->passwd) > 1) {
4485 passwd_store_set_account(ac_prefs->account_id,
4486 PWS_ACCOUNT_RECV, ac_prefs->passwd, TRUE);
4487 passwords_migrated = TRUE;
4489 if (ac_prefs->smtp_passwd != NULL && strlen(ac_prefs->smtp_passwd) > 1) {
4490 passwd_store_set_account(ac_prefs->account_id,
4491 PWS_ACCOUNT_SEND, ac_prefs->smtp_passwd, TRUE);
4492 passwords_migrated = TRUE;
4494 if (ac_prefs->in_ssl_client_cert_pass != NULL
4495 && strlen(ac_prefs->in_ssl_client_cert_pass) > 1) {
4496 passwd_store_set_account(ac_prefs->account_id,
4497 PWS_ACCOUNT_RECV_CERT, ac_prefs->in_ssl_client_cert_pass, TRUE);
4498 passwords_migrated = TRUE;
4500 if (ac_prefs->out_ssl_client_cert_pass != NULL
4501 && strlen(ac_prefs->out_ssl_client_cert_pass) > 1) {
4502 passwd_store_set_account(ac_prefs->account_id,
4503 PWS_ACCOUNT_SEND_CERT, ac_prefs->out_ssl_client_cert_pass, TRUE);
4504 passwords_migrated = TRUE;
4507 /* Write out password store to file immediately, to prevent
4508 * their loss. */
4509 if (passwords_migrated)
4510 passwd_store_write_config();
4512 ac_prefs->receive_in_progress = FALSE;
4514 prefs_custom_header_read_config(ac_prefs);
4516 /* Start the auto-check interval, if needed. */
4517 if (!ac_prefs->autochk_use_default && ac_prefs->autochk_use_custom
4518 && ac_prefs->autochk_itv > PREFS_RECV_AUTOCHECK_MIN_INTERVAL) {
4519 inc_account_autocheck_timer_set_interval(ac_prefs);
4522 return ac_prefs;
4525 static void create_privacy_prefs(gpointer key, gpointer _value, gpointer user_data)
4527 GString *str = (GString *) user_data;
4528 gchar *encvalue;
4529 gchar *value = (gchar *) _value;
4531 if (str->len > 0)
4532 g_string_append_c(str, ',');
4534 encvalue = g_base64_encode(value, strlen(value));
4535 g_string_append_printf(str, "%s=%s", (gchar *) key, encvalue);
4536 g_free(encvalue);
4539 #define WRITE_PARAM(PARAM_TABLE) \
4540 if (prefs_write_param(PARAM_TABLE, pfile->fp) < 0) { \
4541 g_warning("failed to write configuration to file"); \
4542 prefs_file_close_revert(pfile); \
4543 g_free(privacy_prefs); \
4544 privacy_prefs = NULL; \
4545 g_free(rcpath); \
4546 return; \
4549 void prefs_account_write_config_all(GList *account_list)
4551 GList *cur;
4552 gchar *rcpath;
4553 PrefFile *pfile;
4555 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
4556 if ((pfile = prefs_write_open(rcpath)) == NULL) {
4557 g_free(rcpath);
4558 return;
4561 for (cur = account_list; cur != NULL; cur = cur->next) {
4562 GString *str;
4564 tmp_ac_prefs = *(PrefsAccount *)cur->data;
4565 if (fprintf(pfile->fp, "[Account: %d]\n",
4566 tmp_ac_prefs.account_id) <= 0) {
4567 g_free(pfile);
4568 g_free(rcpath);
4569 return;
4572 str = g_string_sized_new(32);
4573 g_hash_table_foreach(tmp_ac_prefs.privacy_prefs, create_privacy_prefs, str);
4574 privacy_prefs = g_string_free(str, FALSE);
4576 WRITE_PARAM(basic_param)
4577 WRITE_PARAM(receive_param)
4578 WRITE_PARAM(send_param)
4579 WRITE_PARAM(oauth2_param)
4580 WRITE_PARAM(compose_param)
4581 WRITE_PARAM(templates_param)
4582 WRITE_PARAM(privacy_param)
4583 WRITE_PARAM(ssl_param)
4584 WRITE_PARAM(proxy_param)
4585 WRITE_PARAM(advanced_param)
4587 g_free(privacy_prefs);
4588 privacy_prefs = NULL;
4590 if (cur->next) {
4591 if (claws_fputc('\n', pfile->fp) == EOF) {
4592 FILE_OP_ERROR(rcpath, "claws_fputc");
4593 prefs_file_close_revert(pfile);
4594 g_free(rcpath);
4595 return;
4599 g_free(rcpath);
4601 if (prefs_file_close(pfile) < 0)
4602 g_warning("failed to write configuration to file");
4604 passwd_store_write_config();
4606 #undef WRITE_PARAM
4608 static gboolean free_privacy_prefs(gpointer key, gpointer value, gpointer user_data)
4610 g_free(key);
4611 g_free(value);
4613 return TRUE;
4616 void prefs_account_free(PrefsAccount *ac_prefs)
4618 if (!ac_prefs) return;
4620 g_hash_table_foreach_remove(ac_prefs->privacy_prefs, free_privacy_prefs, NULL);
4622 tmp_ac_prefs = *ac_prefs;
4623 prefs_free(basic_param);
4624 prefs_free(receive_param);
4625 prefs_free(send_param);
4626 prefs_free(oauth2_param);
4627 prefs_free(compose_param);
4628 prefs_free(templates_param);
4629 prefs_free(privacy_param);
4630 prefs_free(ssl_param);
4631 prefs_free(proxy_param);
4632 prefs_free(advanced_param);
4635 const gchar *prefs_account_get_privacy_prefs(PrefsAccount *account, gchar *id)
4637 return g_hash_table_lookup(account->privacy_prefs, id);
4640 void prefs_account_set_privacy_prefs(PrefsAccount *account, gchar *id, gchar *new_value)
4642 gchar *orig_key = NULL, *value;
4644 if (g_hash_table_lookup_extended(account->privacy_prefs, id, (gpointer *)(gchar *) &orig_key, (gpointer *)(gchar *) &value)) {
4645 g_hash_table_remove(account->privacy_prefs, id);
4647 g_free(orig_key);
4648 g_free(value);
4651 if (new_value != NULL)
4652 g_hash_table_insert(account->privacy_prefs, g_strdup(id), g_strdup(new_value));
4655 static gint prefs_account_get_new_id(void)
4657 GList *ac_list;
4658 PrefsAccount *ac;
4659 static gint last_id = 0;
4661 for (ac_list = account_get_list(); ac_list != NULL;
4662 ac_list = ac_list->next) {
4663 ac = (PrefsAccount *)ac_list->data;
4664 if (last_id < ac->account_id)
4665 last_id = ac->account_id;
4668 return last_id + 1;
4671 static void destroy_dialog(gpointer data)
4673 PrefsAccount *ac_prefs = (PrefsAccount *) data;
4674 if (!cancelled) {
4675 gboolean update_fld_list = FALSE;
4676 if (ac_prefs->protocol == A_IMAP4 && !new_account) {
4677 if ((&tmp_ac_prefs)->imap_subsonly != ac_prefs->imap_subsonly) {
4678 update_fld_list = TRUE;
4681 *ac_prefs = tmp_ac_prefs;
4682 if (update_fld_list)
4683 folderview_rescan_tree(ac_prefs->folder, FALSE);
4685 inc_account_autocheck_timer_set_interval(ac_prefs);
4687 } else /* the customhdr_list may have changed, update it anyway */
4688 ac_prefs->customhdr_list = (&tmp_ac_prefs)->customhdr_list;
4691 gtk_main_quit();
4694 PrefsAccount *prefs_account_open(PrefsAccount *ac_prefs, gboolean *dirty)
4696 gchar *title;
4698 if (prefs_rc_is_readonly(ACCOUNT_RC))
4699 return ac_prefs;
4701 debug_print("Opening account preferences window...\n");
4703 inc_lock();
4705 cancelled = TRUE;
4707 if (!ac_prefs) {
4708 ac_prefs = prefs_account_new();
4709 new_account = TRUE;
4710 } else
4711 new_account = FALSE;
4713 if (new_account)
4714 title = g_strdup (_("Preferences for new account"));
4715 else
4716 title = g_strdup_printf (_("%s - Account preferences"),
4717 ac_prefs->account_name);
4719 prefswindow_open_full(title, prefs_pages, ac_prefs, destroy_dialog,
4720 &prefs_common.editaccountwin_width, &prefs_common.editaccountwin_height,
4721 TRUE, NULL, NULL, NULL);
4722 g_free(title);
4723 gtk_main();
4725 inc_unlock();
4727 if (!cancelled && dirty != NULL)
4728 *dirty = TRUE;
4729 if (cancelled && new_account)
4730 return NULL;
4731 else {
4732 if (ac_prefs->recv_server)
4733 g_strstrip(ac_prefs->recv_server);
4734 if (ac_prefs->smtp_server)
4735 g_strstrip(ac_prefs->smtp_server);
4736 if (ac_prefs->nntp_server)
4737 g_strstrip(ac_prefs->nntp_server);
4739 return ac_prefs;
4743 static void crosspost_color_toggled(void)
4745 gboolean is_active;
4747 is_active = gtk_toggle_button_get_active
4748 (GTK_TOGGLE_BUTTON(advanced_page.crosspost_checkbtn));
4749 gtk_widget_set_sensitive(advanced_page.crosspost_colormenu, is_active);
4752 static void prefs_account_crosspost_set_data_from_colormenu(PrefParam *pparam)
4754 gint color;
4755 GtkWidget *combobox = *pparam->widget;
4757 color = colorlabel_get_combobox_colormenu_active(GTK_COMBO_BOX(combobox));
4758 *((gint *)pparam->data) = color;
4761 static void prefs_account_crosspost_set_colormenu(PrefParam *pparam)
4763 gint color = *((gint *)pparam->data);
4764 GtkWidget *combobox = *pparam->widget;
4766 colorlabel_set_combobox_colormenu_active(GTK_COMBO_BOX(combobox), color);
4769 static void pop_bfr_smtp_tm_set_sens(GtkWidget *widget, gpointer data)
4771 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_tm_spinbtn,
4772 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(send_page.pop_bfr_smtp_checkbtn)));
4773 gtk_widget_set_sensitive(send_page.pop_auth_timeout_lbl,
4774 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(send_page.pop_bfr_smtp_checkbtn)));
4775 gtk_widget_set_sensitive(send_page.pop_auth_minutes_lbl,
4776 gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(send_page.pop_bfr_smtp_checkbtn)));
4779 static void prefs_account_select_folder_cb(GtkWidget *widget, gpointer data)
4781 FolderItem *item;
4782 gchar *id;
4784 item = foldersel_folder_sel(NULL, FOLDER_SEL_COPY, NULL, FALSE, NULL);
4785 if (item && item->path) {
4786 id = folder_item_get_identifier(item);
4787 if (id) {
4788 gtk_entry_set_text(GTK_ENTRY(data), id);
4789 g_free(id);
4794 #if (defined USE_GNUTLS)
4795 static void auto_configure_cb (GtkWidget *widget, gpointer data)
4797 gchar *address = NULL;
4798 AutoConfigureData *recv_data;
4799 AutoConfigureData *send_data;
4800 static GCancellable *recv_cancel = NULL;
4801 static GCancellable *send_cancel = NULL;
4802 RecvProtocol protocol;
4803 struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *) basic_page.protocol_optmenu;
4804 GtkWidget *optmenu = protocol_optmenu->combobox;
4806 if (!recv_cancel) {
4807 recv_cancel = g_cancellable_new();
4808 send_cancel = g_cancellable_new();
4811 if (widget == basic_page.auto_configure_cancel_btn) {
4812 g_cancellable_cancel(recv_cancel);
4813 g_cancellable_cancel(send_cancel);
4814 g_object_unref(recv_cancel);
4815 g_object_unref(send_cancel);
4816 recv_cancel = NULL;
4817 send_cancel = NULL;
4818 return;
4821 protocol = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
4823 address = gtk_editable_get_chars(GTK_EDITABLE(basic_page.addr_entry), 0, -1);
4825 if (strchr(address, '@') == NULL) {
4826 g_free(address);
4827 gtk_label_set_text(GTK_LABEL(basic_page.auto_configure_lbl),
4828 _("Failed (wrong address)"));
4829 return;
4832 if (protocol == A_POP3 || protocol == A_IMAP4) {
4833 recv_data = g_new0(AutoConfigureData, 1);
4834 recv_data->configure_button = GTK_BUTTON(basic_page.auto_configure_btn);
4835 recv_data->cancel_button = GTK_BUTTON(basic_page.auto_configure_cancel_btn);
4836 recv_data->info_label = GTK_LABEL(basic_page.auto_configure_lbl);
4837 recv_data->cancel = recv_cancel;
4838 switch(protocol) {
4839 case A_POP3:
4840 recv_data->ssl_service = "pop3s";
4841 recv_data->tls_service = "pop3";
4842 recv_data->address = g_strdup(address);
4843 recv_data->hostname_entry = GTK_ENTRY(basic_page.recvserv_entry);
4844 recv_data->set_port = GTK_TOGGLE_BUTTON(advanced_page.popport_checkbtn);
4845 recv_data->port = GTK_SPIN_BUTTON(advanced_page.popport_spinbtn);
4846 recv_data->tls_checkbtn = GTK_TOGGLE_BUTTON(ssl_page.pop_starttls_radiobtn);
4847 recv_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(ssl_page.pop_ssltunnel_radiobtn);
4848 recv_data->default_port = 110;
4849 recv_data->default_ssl_port = 995;
4850 recv_data->uid_entry = GTK_ENTRY(basic_page.uid_entry);
4851 break;
4852 case A_IMAP4:
4853 recv_data->ssl_service = "imaps";
4854 recv_data->tls_service = "imap";
4855 recv_data->address = g_strdup(address);
4856 recv_data->hostname_entry = GTK_ENTRY(basic_page.recvserv_entry);
4857 recv_data->set_port = GTK_TOGGLE_BUTTON(advanced_page.imapport_checkbtn);
4858 recv_data->port = GTK_SPIN_BUTTON(advanced_page.imapport_spinbtn);
4859 recv_data->tls_checkbtn = GTK_TOGGLE_BUTTON(ssl_page.imap_starttls_radiobtn);
4860 recv_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(ssl_page.imap_ssltunnel_radiobtn);
4861 recv_data->default_port = 143;
4862 recv_data->default_ssl_port = 993;
4863 recv_data->uid_entry = GTK_ENTRY(basic_page.uid_entry);
4864 break;
4865 default:
4866 cm_return_if_fail(FALSE);
4868 auto_configure_service(recv_data);
4871 send_data = g_new0(AutoConfigureData, 1);
4872 send_data->configure_button = GTK_BUTTON(basic_page.auto_configure_btn);
4873 send_data->cancel_button = GTK_BUTTON(basic_page.auto_configure_cancel_btn);
4874 send_data->info_label = GTK_LABEL(basic_page.auto_configure_lbl);
4875 send_data->cancel = send_cancel;
4877 send_data->ssl_service = NULL;
4878 send_data->tls_service = "submission";
4879 send_data->address = g_strdup(address);
4880 send_data->hostname_entry = GTK_ENTRY(basic_page.smtpserv_entry);
4881 send_data->set_port = GTK_TOGGLE_BUTTON(advanced_page.smtpport_checkbtn);
4882 send_data->port = GTK_SPIN_BUTTON(advanced_page.smtpport_spinbtn);
4883 send_data->tls_checkbtn = GTK_TOGGLE_BUTTON(ssl_page.smtp_starttls_radiobtn);
4884 send_data->ssl_checkbtn = GTK_TOGGLE_BUTTON(ssl_page.smtp_ssltunnel_radiobtn);
4885 send_data->default_port = 25;
4886 send_data->default_ssl_port = -1;
4887 send_data->uid_entry = NULL;
4888 send_data->auth_checkbtn = GTK_TOGGLE_BUTTON(send_page.smtp_auth_checkbtn);
4890 auto_configure_service(send_data);
4892 g_free(address);
4894 #endif
4896 static void prefs_account_sigfile_radiobtn_cb(GtkWidget *widget, gpointer data)
4898 gtk_widget_set_sensitive(GTK_WIDGET(signature_browse_button), TRUE);
4899 gtk_widget_set_sensitive(GTK_WIDGET(signature_edit_button), TRUE);
4902 static void prefs_account_sigcmd_radiobtn_cb(GtkWidget *widget, gpointer data)
4904 gtk_widget_set_sensitive(GTK_WIDGET(signature_browse_button), FALSE);
4905 gtk_widget_set_sensitive(GTK_WIDGET(signature_edit_button), FALSE);
4908 static void prefs_account_signature_browse_cb(GtkWidget *widget, gpointer data)
4910 gchar *filename;
4911 gchar *utf8_filename;
4913 filename = filesel_select_file_open(_("Select signature file"), NULL);
4914 if (!filename) return;
4916 utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
4917 if (!utf8_filename) {
4918 g_warning("prefs_account_signature_browse_cb(): failed to convert character set");
4919 utf8_filename = g_strdup(filename);
4921 gtk_entry_set_text(GTK_ENTRY(entry_sigpath), utf8_filename);
4922 g_free(utf8_filename);
4925 #ifdef USE_GNUTLS
4926 static void prefs_account_in_cert_browse_cb(GtkWidget *widget, gpointer data)
4928 gchar *filename;
4929 gchar *utf8_filename;
4931 filename = filesel_select_file_open(_("Select certificate file"), NULL);
4932 if (!filename) return;
4934 utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
4935 if (!utf8_filename) {
4936 g_warning("prefs_account_cert_browse_cb(): failed to convert character set");
4937 utf8_filename = g_strdup(filename);
4939 gtk_entry_set_text(GTK_ENTRY(entry_in_cert_file), utf8_filename);
4940 g_free(utf8_filename);
4943 static void prefs_account_out_cert_browse_cb(GtkWidget *widget, gpointer data)
4945 gchar *filename;
4946 gchar *utf8_filename;
4948 filename = filesel_select_file_open(_("Select certificate file"), NULL);
4949 if (!filename) return;
4951 utf8_filename = g_filename_to_utf8(filename, -1, NULL, NULL, NULL);
4952 if (!utf8_filename) {
4953 g_warning("prefs_account_cert_browse_cb(): failed to convert character set");
4954 utf8_filename = g_strdup(filename);
4956 gtk_entry_set_text(GTK_ENTRY(entry_out_cert_file), utf8_filename);
4957 g_free(utf8_filename);
4959 #endif
4961 static void prefs_account_signature_edit_cb(GtkWidget *widget, gpointer data)
4963 const gchar *sigpath = gtk_entry_get_text(GTK_ENTRY(data));
4964 if (!is_file_exist(sigpath))
4965 str_write_to_file(sigpath, "", TRUE);
4966 open_txt_editor(sigpath, prefs_common_get_ext_editor_cmd());
4969 static void prefs_account_edit_custom_header(void)
4971 prefs_custom_header_open(&tmp_ac_prefs);
4974 static void prefs_account_enum_set_data_from_radiobtn(PrefParam *pparam)
4976 GtkRadioButton *radiobtn;
4977 GSList *group;
4979 radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
4980 group = gtk_radio_button_get_group (radiobtn);
4981 while (group != NULL) {
4982 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
4983 if (gtk_toggle_button_get_active (btn)) {
4984 *((gint *)pparam->data) = GPOINTER_TO_INT
4985 (g_object_get_data (G_OBJECT (btn), MENU_VAL_ID));
4986 break;
4988 group = group->next;
4992 static void prefs_account_enum_set_radiobtn(PrefParam *pparam)
4994 GtkRadioButton *radiobtn;
4995 GSList *group;
4996 gpointer data;
4998 data = GINT_TO_POINTER (*((gint *)pparam->data));
4999 radiobtn = GTK_RADIO_BUTTON (*pparam->widget);
5000 group = gtk_radio_button_get_group (radiobtn);
5001 while (group != NULL) {
5002 GtkToggleButton *btn = GTK_TOGGLE_BUTTON (group->data);
5003 gpointer data1 = g_object_get_data (G_OBJECT (btn), MENU_VAL_ID);
5004 if (data1 == data) {
5005 gtk_toggle_button_set_active (btn, TRUE);
5006 break;
5008 group = group->next;
5012 static void prefs_account_protocol_set_data_from_optmenu(PrefParam *pparam)
5014 struct BasicProtocol *protocol_optmenu =
5015 (struct BasicProtocol *)*pparam->widget;
5016 GtkWidget *optmenu = protocol_optmenu->combobox;
5018 *((RecvProtocol *)pparam->data) =
5019 combobox_get_active_data(GTK_COMBO_BOX(optmenu));
5022 static void prefs_account_protocol_set_optmenu(PrefParam *pparam)
5024 RecvProtocol protocol;
5025 struct BasicProtocol *protocol_optmenu =
5026 (struct BasicProtocol *)*pparam->widget;
5027 GtkWidget *optmenu = protocol_optmenu->combobox;
5028 GtkWidget *optlabel = protocol_optmenu->label;
5029 GtkWidget *descrlabel = protocol_optmenu->descrlabel;
5030 gchar *label = NULL;
5032 protocol = *((RecvProtocol *)pparam->data);
5034 /* Set combobox to correct value even if it will be hidden, so
5035 * we won't break existing accounts when saving. */
5036 combobox_select_by_data(GTK_COMBO_BOX(optmenu), protocol);
5038 /* Set up widgets accordingly */
5039 if( new_account ) {
5040 gtk_label_set_text(GTK_LABEL(descrlabel), _("Protocol"));
5041 gtk_widget_hide(optlabel);
5042 gtk_widget_show(optmenu);
5043 } else {
5044 gtk_label_set_text(GTK_LABEL(descrlabel), _("Protocol:"));
5045 label = g_markup_printf_escaped("<b>%s</b>", protocol_names[protocol]);
5046 gtk_label_set_markup(GTK_LABEL(optlabel), label);
5047 g_free(label);
5048 gtk_widget_hide(optmenu);
5049 gtk_widget_show(optlabel);
5050 #ifndef HAVE_LIBETPAN
5051 if (protocol == A_IMAP4 || protocol == A_NNTP) {
5052 gtk_widget_show(protocol_optmenu->no_imap_warn_icon);
5053 gtk_widget_show(protocol_optmenu->no_imap_warn_label);
5054 } else {
5055 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
5056 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
5058 #endif
5059 if (protocol == A_IMAP4) {
5060 if (new_account)
5061 gtk_toggle_button_set_active(
5062 GTK_TOGGLE_BUTTON(send_page.msgid_checkbtn),
5063 TRUE);
5064 gtk_widget_hide(send_page.msgid_checkbtn);
5065 } else
5066 gtk_widget_show(send_page.msgid_checkbtn);
5068 gtk_widget_show(send_page.xmailer_checkbtn);
5072 static void prefs_account_imap_auth_type_set_data_from_optmenu(PrefParam *pparam)
5074 *((RecvProtocol *)pparam->data) =
5075 combobox_get_active_data(GTK_COMBO_BOX(*pparam->widget));
5078 static void prefs_account_imap_auth_type_set_optmenu(PrefParam *pparam)
5080 IMAPAuthType type = *((IMAPAuthType *)pparam->data);
5081 GtkComboBox *optmenu = GTK_COMBO_BOX(*pparam->widget);
5083 combobox_select_by_data(optmenu, type);
5086 static void prefs_account_smtp_auth_type_set_data_from_optmenu(PrefParam *pparam)
5088 *((RecvProtocol *)pparam->data) =
5089 combobox_get_active_data(GTK_COMBO_BOX(*pparam->widget));
5092 static void prefs_account_smtp_auth_type_set_optmenu(PrefParam *pparam)
5094 SMTPAuthType type = *((SMTPAuthType *)pparam->data);
5095 GtkComboBox *optmenu = GTK_COMBO_BOX(*pparam->widget);
5097 combobox_select_by_data(optmenu, type);
5100 static void prefs_account_set_autochk_interval_from_widgets(PrefParam *pparam)
5102 struct AutocheckWidgets *autochk_widgets =
5103 (struct AutocheckWidgets *)*pparam->widget;
5105 *(gint *)pparam->data =
5106 (3600 * gtk_spin_button_get_value_as_int(
5107 GTK_SPIN_BUTTON(autochk_widgets->autochk_hour_spinbtn)))
5108 + (60 * gtk_spin_button_get_value_as_int(
5109 GTK_SPIN_BUTTON(autochk_widgets->autochk_min_spinbtn)))
5110 + gtk_spin_button_get_value_as_int(
5111 GTK_SPIN_BUTTON(autochk_widgets->autochk_sec_spinbtn));
5114 static void prefs_account_pop_auth_type_set_data_from_optmenu(PrefParam *pparam)
5116 *((RecvProtocol *)pparam->data) =
5117 combobox_get_active_data(GTK_COMBO_BOX(*pparam->widget));
5120 static void prefs_account_pop_auth_type_set_optmenu(PrefParam *pparam)
5122 POPAuthType type = *((POPAuthType *)pparam->data);
5123 GtkComboBox *optmenu = GTK_COMBO_BOX(*pparam->widget);
5125 combobox_select_by_data(optmenu, type);
5128 #ifdef USE_OAUTH2
5129 static void prefs_account_oauth2_provider_set_data_from_optmenu(PrefParam *pparam)
5131 *((Oauth2Service *)pparam->data) =
5132 combobox_get_active_data(GTK_COMBO_BOX(*pparam->widget));
5135 static void prefs_account_oauth2_provider_set_optmenu(PrefParam *pparam)
5137 Oauth2Service type = *((Oauth2Service *)pparam->data);
5138 GtkComboBox *optmenu = GTK_COMBO_BOX(*pparam->widget);
5140 combobox_select_by_data(optmenu, type);
5143 static void prefs_account_oauth2_set_auth_sensitivity(void)
5145 const gchar *authcode = gtk_entry_get_text((GtkEntry *)oauth2_page.oauth2_authcode_entry);
5146 gchar *trim_text = g_strdup(authcode);
5147 g_strstrip(trim_text);
5148 gtk_widget_set_sensitive(oauth2_page.oauth2_authorise_btn, (*trim_text != 0));
5149 g_free(trim_text);
5152 static void prefs_account_oauth2_set_sensitivity(void)
5154 struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *)oauth2_page.protocol_optmenu;
5155 GtkWidget *optmenu = protocol_optmenu->combobox;
5156 Oauth2Service service;
5158 service = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
5160 if(service == OAUTH2AUTH_NONE)
5161 gtk_widget_set_sensitive(oauth2_page.oauth2_sensitive, FALSE);
5162 else
5163 gtk_widget_set_sensitive(oauth2_page.oauth2_sensitive, TRUE);
5166 static void prefs_account_oauth2_copy_url(GtkButton *button, gpointer data)
5168 struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *)oauth2_page.protocol_optmenu;
5170 GtkWidget *optmenu = protocol_optmenu->combobox;
5172 GtkWidget *win;
5173 GtkClipboard *clip, *clip2;
5174 gint len;
5175 gchar *url;
5176 url = g_malloc(OAUTH2BUFSIZE+1);
5177 Oauth2Service service;
5178 const gchar * custom_client_id = NULL;
5179 struct Oauth2Listener *oauth2_listener_data;
5181 service = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
5182 custom_client_id = gtk_entry_get_text((GtkEntry *)oauth2_page.oauth2_client_id_entry);
5184 oauth2_authorisation_url(service, &url, custom_client_id);
5186 win = gtk_widget_get_toplevel (optmenu);
5187 len = strlen(url);
5189 clip = gtk_widget_get_clipboard (win, GDK_SELECTION_PRIMARY);
5190 clip2 = gtk_widget_get_clipboard (win, GDK_SELECTION_CLIPBOARD);
5191 gtk_clipboard_set_text (clip, url, len);
5192 gtk_clipboard_set_text (clip2, url, len);
5194 if (strcmp(gtk_button_get_label(button), "Copy link") != 0)
5195 open_uri(url, prefs_common_get_uri_cmd());
5197 g_free(url);
5199 //Start listener task for authorisation reply using a separate task
5200 //Avoids hanging while we wait, and to allow cancellation of the process
5201 //If task already exists gracefully close it
5202 if(oauth2_listener_task){
5203 debug_print("Closing oauth2 listener task\n");
5204 oauth2_listener_cancel = 1;
5205 while (oauth2_listener_closed == 0)
5206 gtk_main_iteration();
5209 debug_print("Starting oauth2 listener task\n");
5211 oauth2_listener_data = g_new(struct Oauth2Listener, 1);
5212 oauth2_listener_data->success = FALSE;
5213 oauth2_listener_data->trim_text = NULL;
5214 oauth2_listener_data->service = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
5215 oauth2_listener_data->OAUTH2Data = g_malloc(sizeof(* oauth2_listener_data->OAUTH2Data));
5216 oauth2_init (oauth2_listener_data->OAUTH2Data);
5217 oauth2_listener_data->OAUTH2Data->custom_client_secret =
5218 g_strdup(gtk_entry_get_text((GtkEntry *)oauth2_page.oauth2_client_secret_entry));
5219 oauth2_listener_data->OAUTH2Data->custom_client_id =
5220 g_strdup(gtk_entry_get_text((GtkEntry *)oauth2_page.oauth2_client_id_entry));
5222 oauth2_listener_cancel = 0;
5223 oauth2_listener_closed = 0;
5225 oauth2_listener_task = g_task_new(NULL, NULL, prefs_account_oauth2_callback, oauth2_listener_data);
5226 g_task_set_task_data(oauth2_listener_task, oauth2_listener_data, NULL);
5227 g_task_run_in_thread(oauth2_listener_task, prefs_account_oauth2_listener);
5230 static void prefs_account_oauth2_obtain_tokens(GtkButton *button, gpointer data)
5232 struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *)oauth2_page.protocol_optmenu;
5234 GtkWidget *optmenu = protocol_optmenu->combobox;
5235 Oauth2Service service;
5236 OAUTH2Data *OAUTH2Data = g_malloc(sizeof(* OAUTH2Data));
5237 const gchar *authcode = gtk_entry_get_text ((GtkEntry *)oauth2_page.oauth2_authcode_entry);
5238 gchar *trim_text = g_strdup(authcode);
5239 g_strstrip(trim_text);
5240 gint ret;
5242 oauth2_init (OAUTH2Data);
5245 OAUTH2Data->custom_client_secret =
5246 g_strdup(gtk_entry_get_text((GtkEntry *)oauth2_page.oauth2_client_secret_entry));
5247 OAUTH2Data->custom_client_id =
5248 g_strdup(gtk_entry_get_text((GtkEntry *)oauth2_page.oauth2_client_id_entry));
5251 service = combobox_get_active_data(GTK_COMBO_BOX(optmenu));
5252 ret = oauth2_obtain_tokens (service, OAUTH2Data, trim_text);
5254 if(!ret){
5255 if(OAUTH2Data->refresh_token != NULL){
5256 passwd_store_set_account(tmp_ac_prefs.account_id,
5257 PWS_ACCOUNT_OAUTH2_REFRESH, OAUTH2Data->refresh_token, FALSE);
5258 log_message(LOG_PROTOCOL, "OAuth2 refresh token stored\n");
5261 if(OAUTH2Data->access_token != NULL){
5262 passwd_store_set_account(tmp_ac_prefs.account_id,
5263 PWS_ACCOUNT_RECV, OAUTH2Data->access_token, FALSE);
5264 gtk_entry_set_text(GTK_ENTRY(basic_page.pass_entry), OAUTH2Data->access_token);
5266 if (tmp_ac_prefs.use_smtp_auth && tmp_ac_prefs.smtp_auth_type == SMTPAUTH_OAUTH2) {
5267 passwd_store_set_account(tmp_ac_prefs.account_id,
5268 PWS_ACCOUNT_SEND, OAUTH2Data->access_token, FALSE);
5269 gtk_entry_set_text(GTK_ENTRY(send_page.smtp_pass_entry), OAUTH2Data->access_token);
5271 log_message(LOG_PROTOCOL, "OAuth2 access token stored\n");
5274 if(OAUTH2Data->expiry_str != NULL){
5275 passwd_store_set_account(tmp_ac_prefs.account_id,
5276 PWS_ACCOUNT_OAUTH2_EXPIRY, OAUTH2Data->expiry_str, FALSE);
5277 log_message(LOG_PROTOCOL, "OAuth2 access token expiry stored\n");
5280 tmp_ac_prefs.oauth2_date = g_get_real_time () / G_USEC_PER_SEC;
5282 g_free(trim_text);
5283 g_free(OAUTH2Data);
5285 #endif
5287 static void prefs_account_set_autochk_interval_to_widgets(PrefParam *pparam)
5289 gint val = *((gint *)pparam->data);
5290 struct AutocheckWidgets *autochk_widgets =
5291 (struct AutocheckWidgets *)*pparam->widget;
5293 gtk_spin_button_set_value(
5294 GTK_SPIN_BUTTON(autochk_widgets->autochk_hour_spinbtn),
5295 val / 3600);
5296 gtk_spin_button_set_value(
5297 GTK_SPIN_BUTTON(autochk_widgets->autochk_min_spinbtn),
5298 (val % 3600) / 60);
5299 gtk_spin_button_set_value(
5300 GTK_SPIN_BUTTON(autochk_widgets->autochk_sec_spinbtn),
5301 (val % 3600) % 60);
5304 static void prefs_account_set_string_from_combobox(PrefParam *pparam)
5306 GtkWidget *combobox;
5307 GtkListStore *menu;
5308 GtkTreeIter iter;
5309 gchar **str;
5311 cm_return_if_fail(*pparam->widget != NULL);
5313 combobox = *pparam->widget;
5314 cm_return_if_fail(gtk_combo_box_get_active_iter(
5315 GTK_COMBO_BOX(combobox), &iter));
5317 str = (gchar **)pparam->data;
5318 g_free(*str);
5319 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(combobox)));
5320 gtk_tree_model_get(GTK_TREE_MODEL(menu), &iter,
5321 COMBOBOX_PRIVACY_PLUGIN_ID, &(*str),
5322 -1);
5325 /* Context struct and internal function called by gtk_tree_model_foreach().
5326 * This is used in prefs_account_set_privacy_combobox_from_string() to find
5327 * correct combobox entry to activate when account preferences are displayed
5328 * and their values are set according to preferences. */
5329 typedef struct _privacy_system_set_ctx {
5330 GtkWidget *combobox;
5331 gchar *prefsid;
5332 gboolean found;
5333 } PrivacySystemSetCtx;
5335 static gboolean _privacy_system_set_func(GtkTreeModel *model, GtkTreePath *path,
5336 GtkTreeIter *iter, PrivacySystemSetCtx *ctx)
5338 GtkWidget *combobox = ctx->combobox;
5339 gchar *prefsid = ctx->prefsid;
5340 gchar *curid;
5342 /* We're searching for correct privacy plugin ID. */
5343 gtk_tree_model_get(model, iter, COMBOBOX_PRIVACY_PLUGIN_ID, &curid, -1);
5344 if( strcmp(prefsid, curid) == 0 ) {
5345 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combobox), iter);
5346 g_free(curid);
5347 ctx->found = TRUE;
5348 return TRUE;
5351 g_free(curid);
5352 return FALSE;
5355 static void prefs_account_set_privacy_combobox_from_string(PrefParam *pparam)
5357 GtkWidget *optionmenu;
5358 GtkListStore *menu;
5359 GtkTreeIter iter;
5360 gboolean found = FALSE;
5361 gchar *prefsid;
5362 PrivacySystemSetCtx *ctx = NULL;
5364 cm_return_if_fail(*pparam->widget != NULL);
5366 prefsid = *((gchar **) pparam->data);
5367 if (prefsid == NULL)
5368 return;
5370 optionmenu = *pparam->widget;
5371 menu = GTK_LIST_STORE(gtk_combo_box_get_model(GTK_COMBO_BOX(optionmenu)));
5373 ctx = g_new(PrivacySystemSetCtx, sizeof(PrivacySystemSetCtx));
5374 ctx->combobox = optionmenu;
5375 ctx->prefsid = prefsid;
5376 ctx->found = FALSE;
5378 gtk_tree_model_foreach(GTK_TREE_MODEL(menu),
5379 (GtkTreeModelForeachFunc)_privacy_system_set_func, ctx);
5380 found = ctx->found;
5381 g_free(ctx);
5383 /* If chosen privacy system is not available, add a dummy entry with
5384 * "not loaded" note and make it active. */
5385 if (!found) {
5386 gchar *name;
5388 name = g_strdup_printf(_("%s (plugin not loaded)"), prefsid);
5389 gtk_list_store_append(menu, &iter);
5390 gtk_list_store_set(menu, &iter,
5391 COMBOBOX_TEXT, name,
5392 COMBOBOX_DATA, 0,
5393 COMBOBOX_SENS, TRUE,
5394 COMBOBOX_PRIVACY_PLUGIN_ID, prefsid,
5395 -1);
5396 g_free(name);
5398 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(optionmenu), &iter);
5402 static void prefs_account_protocol_changed(GtkComboBox *combobox, gpointer data)
5404 RecvProtocol protocol;
5405 struct BasicProtocol *protocol_optmenu = (struct BasicProtocol *)basic_page.protocol_optmenu;
5407 protocol = combobox_get_active_data(combobox);
5409 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
5410 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
5412 switch(protocol) {
5413 case A_NNTP:
5414 #ifndef HAVE_LIBETPAN
5415 gtk_widget_show(protocol_optmenu->no_imap_warn_icon);
5416 gtk_widget_show(protocol_optmenu->no_imap_warn_label);
5417 #else
5418 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
5419 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
5420 #endif
5421 gtk_widget_show(send_page.msgid_checkbtn);
5422 gtk_widget_show(send_page.xmailer_checkbtn);
5423 gtk_widget_show(basic_page.nntpserv_label);
5424 gtk_widget_show(basic_page.nntpserv_entry);
5425 gtk_grid_set_row_spacing(GTK_GRID(basic_page.serv_table), VSPACING_NARROW);
5427 gtk_widget_set_sensitive(basic_page.nntpauth_checkbtn, TRUE);
5428 gtk_widget_show(basic_page.nntpauth_checkbtn);
5430 gtk_widget_set_sensitive(basic_page.nntpauth_onconnect_checkbtn, TRUE);
5431 gtk_widget_show(basic_page.nntpauth_onconnect_checkbtn);
5433 gtk_widget_hide(basic_page.recvserv_label);
5434 gtk_widget_hide(basic_page.recvserv_entry);
5435 gtk_widget_show(basic_page.smtpserv_label);
5436 gtk_widget_show(basic_page.smtpserv_entry);
5437 gtk_widget_hide(basic_page.localmbox_label);
5438 gtk_widget_hide(basic_page.localmbox_entry);
5439 gtk_widget_hide(basic_page.mailcmd_label);
5440 gtk_widget_hide(basic_page.mailcmd_entry);
5441 gtk_widget_hide(basic_page.mailcmd_checkbtn);
5442 gtk_widget_show(basic_page.uid_label);
5443 gtk_widget_show(basic_page.pass_label);
5444 gtk_widget_show(basic_page.uid_entry);
5445 gtk_widget_show(basic_page.pass_entry);
5446 gtk_widget_show(basic_page.showpwd_checkbtn);
5448 gtk_widget_set_sensitive(basic_page.uid_label, TRUE);
5449 gtk_widget_set_sensitive(basic_page.pass_label, TRUE);
5450 gtk_widget_set_sensitive(basic_page.uid_entry, TRUE);
5451 gtk_widget_set_sensitive(basic_page.pass_entry, TRUE);
5452 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, TRUE);
5454 /* update userid/passwd sensitive state */
5456 prefs_account_nntpauth_toggled
5457 (GTK_TOGGLE_BUTTON(basic_page.nntpauth_checkbtn), NULL);
5458 gtk_widget_hide(receive_page.pop3_frame);
5459 gtk_widget_hide(receive_page.imap_frame);
5460 gtk_widget_hide(receive_page.local_frame);
5461 gtk_widget_show(receive_page.autochk_frame);
5462 gtk_widget_show(receive_page.frame_maxarticle);
5463 gtk_widget_set_sensitive(receive_page.filter_on_recv_checkbtn, TRUE);
5464 prefs_account_filter_on_recv_toggled
5465 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn), NULL);
5466 gtk_widget_set_sensitive(receive_page.recvatgetall_checkbtn, TRUE);
5467 /* update pop_before_smtp sensitivity */
5468 gtk_toggle_button_set_active
5469 (GTK_TOGGLE_BUTTON(send_page.pop_bfr_smtp_checkbtn), FALSE);
5470 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_checkbtn, FALSE);
5471 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_tm_spinbtn, FALSE);
5473 if (!tmp_ac_prefs.account_name) {
5474 gtk_toggle_button_set_active
5475 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn),
5476 TRUE);
5477 gtk_toggle_button_set_active
5478 (GTK_TOGGLE_BUTTON(receive_page.filterhook_on_recv_checkbtn),
5479 TRUE);
5480 gtk_toggle_button_set_active
5481 (GTK_TOGGLE_BUTTON(receive_page.recvatgetall_checkbtn),
5482 FALSE);
5485 #ifdef USE_GNUTLS
5486 gtk_widget_hide(ssl_page.pop_frame);
5487 gtk_widget_hide(ssl_page.imap_frame);
5488 gtk_widget_show(ssl_page.nntp_frame);
5489 gtk_widget_show(ssl_page.send_frame);
5490 #endif
5491 gtk_widget_hide(advanced_page.popport_hbox);
5492 gtk_widget_hide(advanced_page.imapport_hbox);
5493 gtk_widget_show(advanced_page.nntpport_hbox);
5494 gtk_widget_show(advanced_page.crosspost_checkbtn);
5495 gtk_widget_show(advanced_page.crosspost_colormenu);
5496 #ifndef G_OS_WIN32
5497 gtk_widget_hide(advanced_page.tunnelcmd_checkbtn);
5498 gtk_widget_hide(advanced_page.tunnelcmd_entry);
5499 #endif
5500 gtk_widget_hide(receive_page.imapdir_label);
5501 gtk_widget_hide(receive_page.imapdir_entry);
5502 gtk_widget_hide(receive_page.subsonly_checkbtn);
5503 gtk_widget_hide(receive_page.low_bandwidth_checkbtn);
5504 gtk_widget_hide(receive_page.imap_batch_size_spinbtn);
5505 break;
5506 case A_LOCAL:
5507 gtk_widget_show(send_page.msgid_checkbtn);
5508 gtk_widget_show(send_page.xmailer_checkbtn);
5509 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
5510 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
5511 gtk_widget_hide(basic_page.nntpserv_label);
5512 gtk_widget_hide(basic_page.nntpserv_entry);
5513 gtk_widget_set_sensitive(basic_page.nntpauth_checkbtn, FALSE);
5514 gtk_widget_hide(basic_page.nntpauth_checkbtn);
5515 gtk_grid_set_row_spacing(GTK_GRID(basic_page.serv_table), VSPACING_NARROW);
5517 gtk_widget_set_sensitive(basic_page.nntpauth_onconnect_checkbtn, FALSE);
5518 gtk_widget_hide(basic_page.nntpauth_onconnect_checkbtn);
5519 gtk_widget_hide(basic_page.recvserv_label);
5520 gtk_widget_hide(basic_page.recvserv_entry);
5521 gtk_widget_show(basic_page.smtpserv_label);
5522 gtk_widget_show(basic_page.smtpserv_entry);
5523 gtk_widget_show(basic_page.localmbox_label);
5524 gtk_widget_show(basic_page.localmbox_entry);
5525 gtk_widget_show(basic_page.mailcmd_label);
5526 gtk_widget_show(basic_page.mailcmd_entry);
5527 gtk_widget_show(basic_page.mailcmd_checkbtn);
5528 gtk_widget_hide(basic_page.uid_label);
5529 gtk_widget_hide(basic_page.pass_label);
5530 gtk_widget_hide(basic_page.uid_entry);
5531 gtk_widget_hide(basic_page.pass_entry);
5532 gtk_widget_hide(basic_page.showpwd_checkbtn);
5534 gtk_widget_set_sensitive(basic_page.uid_label, TRUE);
5535 gtk_widget_set_sensitive(basic_page.pass_label, TRUE);
5536 gtk_widget_set_sensitive(basic_page.uid_entry, TRUE);
5537 gtk_widget_set_sensitive(basic_page.pass_entry, TRUE);
5538 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, TRUE);
5539 gtk_widget_hide(receive_page.pop3_frame);
5540 gtk_widget_hide(receive_page.imap_frame);
5541 gtk_widget_show(receive_page.local_frame);
5542 gtk_widget_show(receive_page.autochk_frame);
5543 gtk_widget_hide(receive_page.frame_maxarticle);
5544 gtk_widget_set_sensitive(receive_page.filter_on_recv_checkbtn, TRUE);
5545 prefs_account_filter_on_recv_toggled
5546 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn), NULL);
5547 gtk_widget_set_sensitive(receive_page.recvatgetall_checkbtn, TRUE);
5548 prefs_account_mailcmd_toggled
5549 (GTK_TOGGLE_BUTTON(basic_page.mailcmd_checkbtn), NULL);
5551 /* update pop_before_smtp sensitivity */
5552 gtk_toggle_button_set_active
5553 (GTK_TOGGLE_BUTTON(send_page.pop_bfr_smtp_checkbtn), FALSE);
5554 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_checkbtn, FALSE);
5555 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_tm_spinbtn, FALSE);
5557 if (!tmp_ac_prefs.account_name) {
5558 gtk_toggle_button_set_active
5559 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn),
5560 TRUE);
5561 gtk_toggle_button_set_active
5562 (GTK_TOGGLE_BUTTON(receive_page.filterhook_on_recv_checkbtn),
5563 TRUE);
5564 gtk_toggle_button_set_active
5565 (GTK_TOGGLE_BUTTON(receive_page.recvatgetall_checkbtn),
5566 TRUE);
5569 #ifdef USE_GNUTLS
5570 gtk_widget_hide(ssl_page.pop_frame);
5571 gtk_widget_hide(ssl_page.imap_frame);
5572 gtk_widget_hide(ssl_page.nntp_frame);
5573 gtk_widget_show(ssl_page.send_frame);
5574 #endif
5575 gtk_widget_hide(advanced_page.popport_hbox);
5576 gtk_widget_hide(advanced_page.imapport_hbox);
5577 gtk_widget_hide(advanced_page.nntpport_hbox);
5578 gtk_widget_hide(advanced_page.crosspost_checkbtn);
5579 gtk_widget_hide(advanced_page.crosspost_colormenu);
5580 #ifndef G_OS_WIN32
5581 gtk_widget_hide(advanced_page.tunnelcmd_checkbtn);
5582 gtk_widget_hide(advanced_page.tunnelcmd_entry);
5583 #endif
5584 gtk_widget_hide(receive_page.imapdir_label);
5585 gtk_widget_hide(receive_page.imapdir_entry);
5586 gtk_widget_hide(receive_page.subsonly_checkbtn);
5587 gtk_widget_hide(receive_page.low_bandwidth_checkbtn);
5588 gtk_widget_hide(receive_page.imap_batch_size_spinbtn);
5589 break;
5590 case A_IMAP4:
5591 #ifndef HAVE_LIBETPAN
5592 gtk_widget_show(protocol_optmenu->no_imap_warn_icon);
5593 gtk_widget_show(protocol_optmenu->no_imap_warn_label);
5594 #endif
5595 if (new_account)
5596 gtk_toggle_button_set_active(
5597 GTK_TOGGLE_BUTTON(send_page.msgid_checkbtn),
5598 TRUE);
5599 gtk_widget_hide(send_page.msgid_checkbtn);
5600 gtk_widget_show(send_page.xmailer_checkbtn);
5601 gtk_widget_hide(basic_page.nntpserv_label);
5602 gtk_widget_hide(basic_page.nntpserv_entry);
5603 gtk_grid_set_row_spacing(GTK_GRID(basic_page.serv_table), VSPACING_NARROW);
5604 gtk_widget_set_sensitive(basic_page.nntpauth_checkbtn, FALSE);
5605 gtk_widget_hide(basic_page.nntpauth_checkbtn);
5607 gtk_widget_set_sensitive(basic_page.nntpauth_onconnect_checkbtn, FALSE);
5608 gtk_widget_hide(basic_page.nntpauth_onconnect_checkbtn);
5610 gtk_widget_set_sensitive(basic_page.recvserv_label, TRUE);
5611 gtk_widget_set_sensitive(basic_page.recvserv_entry, TRUE);
5612 gtk_widget_show(basic_page.recvserv_label);
5613 gtk_widget_show(basic_page.recvserv_entry);
5614 gtk_widget_show(basic_page.smtpserv_label);
5615 gtk_widget_show(basic_page.smtpserv_entry);
5616 gtk_widget_hide(basic_page.localmbox_label);
5617 gtk_widget_hide(basic_page.localmbox_entry);
5618 gtk_widget_hide(basic_page.mailcmd_label);
5619 gtk_widget_hide(basic_page.mailcmd_entry);
5620 gtk_widget_hide(basic_page.mailcmd_checkbtn);
5621 gtk_widget_show(basic_page.uid_label);
5622 gtk_widget_show(basic_page.pass_label);
5623 gtk_widget_show(basic_page.uid_entry);
5624 gtk_widget_show(basic_page.pass_entry);
5625 gtk_widget_show(basic_page.showpwd_checkbtn);
5627 gtk_widget_set_sensitive(basic_page.uid_label, TRUE);
5628 gtk_widget_set_sensitive(basic_page.pass_label, TRUE);
5629 gtk_widget_set_sensitive(basic_page.uid_entry, TRUE);
5630 gtk_widget_set_sensitive(basic_page.pass_entry, TRUE);
5631 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, TRUE);
5632 gtk_widget_hide(receive_page.pop3_frame);
5633 gtk_widget_show(receive_page.imap_frame);
5634 gtk_widget_hide(receive_page.local_frame);
5635 gtk_widget_show(receive_page.autochk_frame);
5636 gtk_widget_hide(receive_page.frame_maxarticle);
5637 gtk_widget_set_sensitive(receive_page.filter_on_recv_checkbtn, TRUE);
5638 prefs_account_filter_on_recv_toggled
5639 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn), NULL);
5640 gtk_widget_set_sensitive(receive_page.recvatgetall_checkbtn, TRUE);
5641 gtk_widget_set_sensitive(basic_page.smtpserv_entry, TRUE);
5642 gtk_widget_set_sensitive(basic_page.smtpserv_label, TRUE);
5644 /* update pop_before_smtp sensitivity */
5645 gtk_toggle_button_set_active
5646 (GTK_TOGGLE_BUTTON(send_page.pop_bfr_smtp_checkbtn), FALSE);
5647 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_checkbtn, FALSE);
5648 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_tm_spinbtn, FALSE);
5650 if (!tmp_ac_prefs.account_name) {
5651 gtk_toggle_button_set_active
5652 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn),
5653 TRUE);
5654 gtk_toggle_button_set_active
5655 (GTK_TOGGLE_BUTTON(receive_page.filterhook_on_recv_checkbtn),
5656 TRUE);
5657 gtk_toggle_button_set_active
5658 (GTK_TOGGLE_BUTTON(receive_page.recvatgetall_checkbtn),
5659 FALSE);
5662 #ifdef USE_GNUTLS
5663 gtk_widget_hide(ssl_page.pop_frame);
5664 gtk_widget_show(ssl_page.imap_frame);
5665 gtk_widget_hide(ssl_page.nntp_frame);
5666 gtk_widget_show(ssl_page.send_frame);
5667 #endif
5668 gtk_widget_hide(advanced_page.popport_hbox);
5669 gtk_widget_show(advanced_page.imapport_hbox);
5670 gtk_widget_hide(advanced_page.nntpport_hbox);
5671 gtk_widget_hide(advanced_page.crosspost_checkbtn);
5672 gtk_widget_hide(advanced_page.crosspost_colormenu);
5673 #ifndef G_OS_WIN32
5674 gtk_widget_show(advanced_page.tunnelcmd_checkbtn);
5675 gtk_widget_show(advanced_page.tunnelcmd_entry);
5676 #endif
5677 gtk_widget_show(receive_page.imapdir_label);
5678 gtk_widget_show(receive_page.imapdir_entry);
5679 gtk_widget_show(receive_page.subsonly_checkbtn);
5680 gtk_widget_show(receive_page.low_bandwidth_checkbtn);
5681 gtk_widget_show(receive_page.imap_batch_size_spinbtn);
5682 break;
5683 case A_NONE:
5684 gtk_widget_show(send_page.msgid_checkbtn);
5685 gtk_widget_show(send_page.xmailer_checkbtn);
5686 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
5687 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
5688 gtk_widget_hide(basic_page.nntpserv_label);
5689 gtk_widget_hide(basic_page.nntpserv_entry);
5690 gtk_grid_set_row_spacing(GTK_GRID(basic_page.serv_table), VSPACING_NARROW);
5691 gtk_widget_set_sensitive(basic_page.nntpauth_checkbtn, FALSE);
5692 gtk_widget_hide(basic_page.nntpauth_checkbtn);
5694 gtk_widget_set_sensitive(basic_page.nntpauth_onconnect_checkbtn, FALSE);
5695 gtk_widget_hide(basic_page.nntpauth_onconnect_checkbtn);
5697 gtk_widget_set_sensitive(basic_page.recvserv_label, FALSE);
5698 gtk_widget_set_sensitive(basic_page.recvserv_entry, FALSE);
5699 gtk_widget_hide(basic_page.recvserv_label);
5700 gtk_widget_hide(basic_page.recvserv_entry);
5701 gtk_widget_show(basic_page.smtpserv_label);
5702 gtk_widget_show(basic_page.smtpserv_entry);
5703 gtk_widget_hide(basic_page.localmbox_label);
5704 gtk_widget_hide(basic_page.localmbox_entry);
5705 gtk_widget_hide(basic_page.mailcmd_label);
5706 gtk_widget_hide(basic_page.mailcmd_entry);
5707 gtk_widget_hide(basic_page.mailcmd_checkbtn);
5708 gtk_widget_hide(basic_page.uid_label);
5709 gtk_widget_hide(basic_page.pass_label);
5710 gtk_widget_hide(basic_page.uid_entry);
5711 gtk_widget_hide(basic_page.pass_entry);
5712 gtk_widget_hide(basic_page.showpwd_checkbtn);
5714 gtk_widget_set_sensitive(basic_page.uid_label, FALSE);
5715 gtk_widget_set_sensitive(basic_page.pass_label, FALSE);
5716 gtk_widget_set_sensitive(basic_page.uid_entry, FALSE);
5717 gtk_widget_set_sensitive(basic_page.pass_entry, FALSE);
5718 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, FALSE);
5719 gtk_widget_set_sensitive(receive_page.pop3_frame, FALSE);
5720 gtk_widget_hide(receive_page.pop3_frame);
5721 gtk_widget_hide(receive_page.imap_frame);
5722 gtk_widget_hide(receive_page.local_frame);
5723 gtk_widget_hide(receive_page.autochk_frame);
5724 gtk_widget_hide(receive_page.frame_maxarticle);
5725 gtk_widget_set_sensitive(receive_page.filter_on_recv_checkbtn, FALSE);
5726 prefs_account_filter_on_recv_toggled
5727 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn), NULL);
5728 gtk_widget_set_sensitive(receive_page.recvatgetall_checkbtn, FALSE);
5730 gtk_widget_set_sensitive(basic_page.smtpserv_entry, TRUE);
5731 gtk_widget_set_sensitive(basic_page.smtpserv_label, TRUE);
5733 /* update pop_before_smtp sensitivity */
5734 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_checkbtn, FALSE);
5735 pop_bfr_smtp_tm_set_sens(NULL, NULL);
5737 gtk_toggle_button_set_active
5738 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn), FALSE);
5739 gtk_toggle_button_set_active
5740 (GTK_TOGGLE_BUTTON(receive_page.filterhook_on_recv_checkbtn), FALSE);
5741 gtk_toggle_button_set_active
5742 (GTK_TOGGLE_BUTTON(receive_page.recvatgetall_checkbtn), FALSE);
5744 #ifdef USE_GNUTLS
5745 gtk_widget_hide(ssl_page.pop_frame);
5746 gtk_widget_hide(ssl_page.imap_frame);
5747 gtk_widget_hide(ssl_page.nntp_frame);
5748 gtk_widget_show(ssl_page.send_frame);
5749 #endif
5750 gtk_widget_hide(advanced_page.popport_hbox);
5751 gtk_widget_hide(advanced_page.imapport_hbox);
5752 gtk_widget_hide(advanced_page.nntpport_hbox);
5753 gtk_widget_hide(advanced_page.crosspost_checkbtn);
5754 gtk_widget_hide(advanced_page.crosspost_colormenu);
5755 #ifndef G_OS_WIN32
5756 gtk_widget_hide(advanced_page.tunnelcmd_checkbtn);
5757 gtk_widget_hide(advanced_page.tunnelcmd_entry);
5758 #endif
5759 gtk_widget_hide(receive_page.imapdir_label);
5760 gtk_widget_hide(receive_page.imapdir_entry);
5761 gtk_widget_hide(receive_page.subsonly_checkbtn);
5762 gtk_widget_hide(receive_page.low_bandwidth_checkbtn);
5763 gtk_widget_hide(receive_page.imap_batch_size_spinbtn);
5764 break;
5765 case A_POP3:
5766 /* continue to default: */
5767 default:
5768 gtk_widget_show(send_page.msgid_checkbtn);
5769 gtk_widget_show(send_page.xmailer_checkbtn);
5770 gtk_widget_hide(protocol_optmenu->no_imap_warn_icon);
5771 gtk_widget_hide(protocol_optmenu->no_imap_warn_label);
5772 gtk_widget_hide(basic_page.nntpserv_label);
5773 gtk_widget_hide(basic_page.nntpserv_entry);
5774 gtk_grid_set_row_spacing(GTK_GRID(basic_page.serv_table), VSPACING_NARROW);
5775 gtk_widget_set_sensitive(basic_page.nntpauth_checkbtn, FALSE);
5776 gtk_widget_hide(basic_page.nntpauth_checkbtn);
5778 gtk_widget_set_sensitive(basic_page.nntpauth_onconnect_checkbtn, FALSE);
5779 gtk_widget_hide(basic_page.nntpauth_onconnect_checkbtn);
5781 gtk_widget_set_sensitive(basic_page.recvserv_label, TRUE);
5782 gtk_widget_set_sensitive(basic_page.recvserv_entry, TRUE);
5783 gtk_widget_show(basic_page.recvserv_label);
5784 gtk_widget_show(basic_page.recvserv_entry);
5785 gtk_widget_show(basic_page.smtpserv_label);
5786 gtk_widget_show(basic_page.smtpserv_entry);
5787 gtk_widget_hide(basic_page.localmbox_label);
5788 gtk_widget_hide(basic_page.localmbox_entry);
5789 gtk_widget_hide(basic_page.mailcmd_label);
5790 gtk_widget_hide(basic_page.mailcmd_entry);
5791 gtk_widget_hide(basic_page.mailcmd_checkbtn);
5792 gtk_widget_show(basic_page.uid_label);
5793 gtk_widget_show(basic_page.pass_label);
5794 gtk_widget_show(basic_page.uid_entry);
5795 gtk_widget_show(basic_page.pass_entry);
5796 gtk_widget_show(basic_page.showpwd_checkbtn);
5798 gtk_widget_set_sensitive(basic_page.uid_label, TRUE);
5799 gtk_widget_set_sensitive(basic_page.pass_label, TRUE);
5800 gtk_widget_set_sensitive(basic_page.uid_entry, TRUE);
5801 gtk_widget_set_sensitive(basic_page.pass_entry, TRUE);
5802 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, TRUE);
5803 gtk_widget_set_sensitive(receive_page.pop3_frame, TRUE);
5804 gtk_widget_show(receive_page.pop3_frame);
5805 gtk_widget_hide(receive_page.imap_frame);
5806 gtk_widget_hide(receive_page.local_frame);
5807 gtk_widget_show(receive_page.autochk_frame);
5808 gtk_widget_hide(receive_page.frame_maxarticle);
5809 gtk_widget_set_sensitive(receive_page.filter_on_recv_checkbtn, TRUE);
5810 prefs_account_filter_on_recv_toggled
5811 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn), NULL);
5812 gtk_widget_set_sensitive(receive_page.recvatgetall_checkbtn, TRUE);
5814 gtk_widget_set_sensitive(basic_page.smtpserv_entry, TRUE);
5815 gtk_widget_set_sensitive(basic_page.smtpserv_label, TRUE);
5817 /* update pop_before_smtp sensitivity */
5818 gtk_widget_set_sensitive(send_page.pop_bfr_smtp_checkbtn, TRUE);
5819 pop_bfr_smtp_tm_set_sens(NULL, NULL);
5821 if (!tmp_ac_prefs.account_name) {
5822 gtk_toggle_button_set_active
5823 (GTK_TOGGLE_BUTTON(receive_page.filter_on_recv_checkbtn),
5824 TRUE);
5825 gtk_toggle_button_set_active
5826 (GTK_TOGGLE_BUTTON(receive_page.filterhook_on_recv_checkbtn),
5827 TRUE);
5828 gtk_toggle_button_set_active
5829 (GTK_TOGGLE_BUTTON(receive_page.recvatgetall_checkbtn),
5830 TRUE);
5833 #ifdef USE_GNUTLS
5834 gtk_widget_show(ssl_page.pop_frame);
5835 gtk_widget_hide(ssl_page.imap_frame);
5836 gtk_widget_hide(ssl_page.nntp_frame);
5837 gtk_widget_show(ssl_page.send_frame);
5838 #endif
5839 gtk_widget_show(advanced_page.popport_hbox);
5840 gtk_widget_hide(advanced_page.imapport_hbox);
5841 gtk_widget_hide(advanced_page.nntpport_hbox);
5842 gtk_widget_hide(advanced_page.crosspost_checkbtn);
5843 gtk_widget_hide(advanced_page.crosspost_colormenu);
5844 #ifndef G_OS_WIN32
5845 gtk_widget_hide(advanced_page.tunnelcmd_checkbtn);
5846 gtk_widget_hide(advanced_page.tunnelcmd_entry);
5847 #endif
5848 gtk_widget_hide(receive_page.imapdir_label);
5849 gtk_widget_hide(receive_page.imapdir_entry);
5850 gtk_widget_hide(receive_page.subsonly_checkbtn);
5851 gtk_widget_hide(receive_page.low_bandwidth_checkbtn);
5852 gtk_widget_hide(receive_page.imap_batch_size_spinbtn);
5853 break;
5856 gtk_widget_queue_resize(basic_page.serv_frame);
5859 static void prefs_account_nntpauth_toggled(GtkToggleButton *button,
5860 gpointer user_data)
5862 gboolean auth;
5864 if (!gtk_widget_get_sensitive (GTK_WIDGET (button)))
5865 return;
5866 auth = gtk_toggle_button_get_active (button);
5867 gtk_widget_set_sensitive(basic_page.uid_label, auth);
5868 gtk_widget_set_sensitive(basic_page.pass_label, auth);
5869 gtk_widget_set_sensitive(basic_page.uid_entry, auth);
5870 gtk_widget_set_sensitive(basic_page.pass_entry, auth);
5871 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, auth);
5872 gtk_widget_set_sensitive(basic_page.nntpauth_onconnect_checkbtn, auth);
5875 static void prefs_account_mailcmd_toggled(GtkToggleButton *button,
5876 gpointer user_data)
5878 gboolean use_mailcmd;
5880 use_mailcmd = gtk_toggle_button_get_active (button);
5882 gtk_widget_set_sensitive(basic_page.mailcmd_entry, use_mailcmd);
5883 gtk_widget_set_sensitive(basic_page.mailcmd_label, use_mailcmd);
5884 gtk_widget_set_sensitive(basic_page.smtpserv_entry, !use_mailcmd);
5885 gtk_widget_set_sensitive(basic_page.smtpserv_label, !use_mailcmd);
5886 gtk_widget_set_sensitive(basic_page.uid_entry, !use_mailcmd);
5887 gtk_widget_set_sensitive(basic_page.pass_entry, !use_mailcmd);
5888 gtk_widget_set_sensitive(basic_page.showpwd_checkbtn, !use_mailcmd);
5891 static void prefs_account_showpwd_checkbtn_toggled(GtkToggleButton *button,
5892 gpointer user_data)
5894 gboolean active = gtk_toggle_button_get_active(button);
5895 GtkWidget *entry = GTK_WIDGET(user_data);
5897 gtk_entry_set_visibility(GTK_ENTRY(entry), active);
5900 static void prefs_account_entry_changed_newline_check_cb(GtkWidget *entry,
5901 gpointer user_data)
5903 static GdkColor red = { (guint32)0, (guint16)0xff, (guint16)0x70, (guint16)0x70 };
5905 if (strchr(gtk_entry_get_text(GTK_ENTRY(entry)), '\n') != NULL) {
5906 /* Entry contains a newline, light it up. */
5907 debug_print("found newline in string, painting entry red\n");
5908 gtk_widget_modify_base(entry, GTK_STATE_NORMAL, &red);
5909 } else {
5910 gtk_widget_modify_base(entry, GTK_STATE_NORMAL, NULL);
5914 static void prefs_account_filter_on_recv_toggled(GtkToggleButton *button,
5915 gpointer user_data)
5917 gboolean do_filter;
5919 do_filter = gtk_toggle_button_get_active (button);
5920 gtk_widget_set_sensitive(receive_page.filterhook_on_recv_checkbtn, do_filter);
5923 #if USE_ENCHANT
5924 static void prefs_account_compose_default_dictionary_set_string_from_optmenu
5925 (PrefParam *pparam)
5927 GtkWidget *combo;
5928 gchar **str;
5930 cm_return_if_fail(*pparam->widget != NULL);
5932 combo = *pparam->widget;
5933 str = (gchar **) pparam->data;
5935 g_free(*str);
5936 *str = gtkaspell_get_dictionary_menu_active_item(GTK_COMBO_BOX(combo));
5939 static void prefs_account_compose_default_dictionary_set_optmenu_from_string
5940 (PrefParam *pparam)
5942 GtkWidget *combo;
5943 gchar *dictionary;
5945 cm_return_if_fail(*pparam->widget != NULL);
5947 dictionary = *((gchar **) pparam->data);
5948 if (dictionary != NULL) {
5949 if (strrchr(dictionary, '/')) {
5950 dictionary = g_strdup(strrchr(dictionary, '/')+1);
5953 if (strchr(dictionary, '-')) {
5954 *(strchr(dictionary, '-')) = '\0';
5957 combo = *pparam->widget;
5958 if (dictionary && *dictionary)
5959 gtkaspell_set_dictionary_menu_active_item(GTK_COMBO_BOX(combo),
5960 dictionary);
5961 else {
5962 GtkTreeModel *model;
5963 GtkTreeIter iter;
5964 if((model = gtk_combo_box_get_model(GTK_COMBO_BOX(combo))) == NULL)
5965 return;
5966 if((gtk_tree_model_get_iter_first(model, &iter)) == FALSE)
5967 return;
5968 gtk_combo_box_set_active_iter(GTK_COMBO_BOX(combo), &iter);
5971 #endif
5973 gchar *prefs_account_generate_msgid(PrefsAccount *account)
5975 gchar *addr, *tmbuf, *buf = NULL;
5976 GDateTime *now;
5977 gchar *user_addr = account->msgid_with_addr ? g_strdup(account->address) : NULL;
5979 if (account->set_domain && account->domain) {
5980 buf = g_strdup(account->domain);
5981 } else if (!strncmp(get_domain_name(), "localhost", strlen("localhost"))) {
5982 buf = g_strdup(
5983 strchr(account->address, '@') ?
5984 strchr(account->address, '@')+1 :
5985 account->address);
5988 if (user_addr != NULL) {
5989 addr = g_strdup_printf(".%s", user_addr);
5990 } else {
5991 addr = g_strdup_printf("@%s",
5992 buf != NULL && strlen(buf) > 0 ?
5993 buf : get_domain_name());
5996 if (buf != NULL)
5997 g_free(buf);
5998 if (user_addr != NULL)
5999 g_free(user_addr);
6001 /* Replace all @ but the last one in addr, with underscores.
6002 * RFC 2822 States that msg-id syntax only allows one @.
6004 while (strchr(addr, '@') != NULL && strchr(addr, '@') != strrchr(addr, '@'))
6005 *(strchr(addr, '@')) = '_';
6007 now = (prefs_common.hide_timezone)? g_date_time_new_now_utc() :
6008 g_date_time_new_now_local();
6009 tmbuf = g_date_time_format(now, "%Y%m%d%H%M%S");
6010 buf = g_strdup_printf("%s.%08x%s",
6011 tmbuf, (guint)rand(), addr);
6012 g_date_time_unref(now);
6013 g_free(tmbuf);
6014 g_free(addr);
6016 debug_print("Generated Message-ID string '%s'\n", buf);
6017 return buf;
6020 void prefs_account_register_page(PrefsPage *page)
6022 prefs_pages = g_slist_append(prefs_pages, page);
6026 void prefs_account_unregister_page(PrefsPage *page)
6028 prefs_pages = g_slist_remove(prefs_pages, page);
6031 gchar *prefs_account_cache_dir(PrefsAccount *ac_prefs, gboolean for_server)
6033 gchar *dir = NULL;
6034 #ifdef G_OS_WIN32
6035 gchar *sanitized_server;
6036 #endif
6038 if (ac_prefs->protocol == A_IMAP4) {
6039 #ifdef G_OS_WIN32
6040 sanitized_server = g_strdup(ac_prefs->recv_server);
6041 g_strdelimit(sanitized_server, ":", ',');
6042 #endif
6043 if (for_server) {
6044 dir = g_strconcat(get_imap_cache_dir(),
6045 G_DIR_SEPARATOR_S,
6046 #ifdef G_OS_WIN32
6047 sanitized_server,
6048 #else
6049 ac_prefs->recv_server,
6050 #endif
6051 NULL);
6052 } else {
6053 dir = g_strconcat(get_imap_cache_dir(),
6054 G_DIR_SEPARATOR_S,
6055 #ifdef G_OS_WIN32
6056 sanitized_server,
6057 #else
6058 ac_prefs->recv_server,
6059 #endif
6060 G_DIR_SEPARATOR_S,
6061 ac_prefs->userid,
6062 NULL);
6064 #ifdef G_OS_WIN32
6065 g_free(sanitized_server);
6066 #endif
6069 return dir;
6072 static void prefs_account_receive_itv_spinbutton_value_changed_cb(GtkWidget *w, gpointer data)
6074 ReceivePage *page = (ReceivePage *)data;
6075 gint seconds = gtk_spin_button_get_value_as_int (
6076 GTK_SPIN_BUTTON (page->autochk_widgets->autochk_sec_spinbtn));
6077 gint minutes = gtk_spin_button_get_value_as_int (
6078 GTK_SPIN_BUTTON (page->autochk_widgets->autochk_min_spinbtn));
6079 gint hours = gtk_spin_button_get_value_as_int (
6080 GTK_SPIN_BUTTON(page->autochk_widgets->autochk_hour_spinbtn));
6081 if (seconds < PREFS_RECV_AUTOCHECK_MIN_INTERVAL && minutes == 0 && hours == 0) {
6082 gtk_spin_button_set_value (
6083 GTK_SPIN_BUTTON (page->autochk_widgets->autochk_sec_spinbtn),
6084 PREFS_RECV_AUTOCHECK_MIN_INTERVAL);
6088 #ifdef USE_OAUTH2
6089 //Automation of the oauth2 authorisation process to receive loopback callback generated by redirect in browser
6090 static void prefs_account_oauth2_listener(GTask *task, gpointer source, gpointer task_data, GCancellable *cancellable)
6092 struct Oauth2Listener *oauth2_listener_data = (struct Oauth2Listener *)task_data;
6093 unsigned int socket_desc;
6094 int client_sock, c;
6095 struct sockaddr_in server , client;
6096 char client_message[2000];
6097 char *reply;
6098 char *reply_message;
6099 char *title;
6100 char *body;
6101 fd_set rfds;
6102 gint ret = 1;
6103 struct timeval timeout;
6105 debug_print("oauth2 listener task running\n");
6107 //Create socket
6108 socket_desc = socket(AF_INET , SOCK_STREAM , 0);
6109 if (socket_desc == -1)
6111 debug_print("oauth2 listener could not create socket\n");
6112 g_task_return_boolean (task, TRUE);
6113 g_object_unref (task);
6114 return;
6116 debug_print("oauth2 listener socket created\n");
6118 //Prepare the sockaddr_in structure
6119 server.sin_family = AF_INET;
6120 server.sin_addr.s_addr = INADDR_ANY;
6121 server.sin_port = htons( 8888 );
6123 //Bind
6124 if( bind(socket_desc,(struct sockaddr *)&server , sizeof(server)) < 0)
6126 close(socket_desc);
6127 debug_print("oauth2 listener bind failed\n");
6128 g_task_return_boolean (task, TRUE);
6129 g_object_unref (task);
6130 return;
6132 debug_print("oauth2 listener bind done\n");
6134 listen(socket_desc , 1);
6136 //Accept and incoming connection
6137 debug_print("oauth2 listener waiting for incoming connections...\n");
6138 c = sizeof(struct sockaddr_in);
6141 FD_ZERO(&rfds);
6142 FD_SET(socket_desc, &rfds);
6143 timeout.tv_sec = 1;
6144 timeout.tv_usec = 0;
6146 select(socket_desc+1, &rfds, NULL, NULL, &timeout);
6148 //select woke up, maybe accept connection from an incoming client
6149 if(FD_ISSET(socket_desc, &rfds)){
6150 client_sock = accept(socket_desc, (struct sockaddr *)&client, (socklen_t*)&c);
6151 if (client_sock < 0){
6152 debug_print("oauth2 listener accept failed\n");
6153 g_task_return_boolean (task, TRUE);
6154 g_object_unref (task);
6155 return;
6157 debug_print("oauth2 listener connection accepted\n");
6159 //Receive message sent to the loopback address by the authorisation page
6160 prefs_account_oauth2_get_line(client_sock, client_message, sizeof(client_message));
6161 oauth2_listener_data->trim_text = g_strdup(client_message);
6162 g_strstrip(oauth2_listener_data->trim_text);
6164 ret = oauth2_obtain_tokens (oauth2_listener_data->service, oauth2_listener_data->OAUTH2Data, oauth2_listener_data->trim_text);
6166 if(!ret){
6167 oauth2_listener_data->success = TRUE;
6168 title = _("Authorisation complete");
6169 body = _("Your OAuth2 authorisation code has been received by Claws Mail");
6170 }else{
6171 //Something went wrong
6172 title = _("Authorisation NOT completed");
6173 body = _("Your OAuth2 authorisation code was not received by Claws Mail");
6174 log_message(LOG_PROTOCOL, "OAuth2 authorisation code not received\n");
6176 reply_message = g_strconcat("<html><head><title>", title,
6177 "</title><meta charset=\"utf-8\"></head><body><h1>", title,
6178 "</h1><p>", body, "</p></body></html>", NULL);
6179 reply = g_strdup_printf(
6180 "HTTP/1.0 200 OK\r\nContent-Type: text/html\r\nContent-Length: %" G_GSIZE_FORMAT "\r\n\r\n%s",
6181 strlen(reply_message), reply_message);
6182 g_free(reply_message);
6183 write(client_sock, reply, strlen(reply));
6184 g_free(reply);
6185 close(client_sock);
6187 }while(ret && !oauth2_listener_cancel);
6189 close(socket_desc);
6190 debug_print("oauth2 closing task\n");
6191 g_task_return_boolean (task, TRUE);
6192 g_object_unref (task);
6195 static void prefs_account_oauth2_callback(GObject *source, GAsyncResult *res, gpointer user_data)
6197 struct Oauth2Listener *oauth2_listener_data = (struct Oauth2Listener *)user_data;
6199 if(oauth2_listener_data->success){
6200 debug_print("oauth2 listener callback storing data and updating GUI\n");
6202 if(oauth2_listener_data->OAUTH2Data->refresh_token != NULL){
6203 passwd_store_set_account(tmp_ac_prefs.account_id,
6204 PWS_ACCOUNT_OAUTH2_REFRESH,
6205 oauth2_listener_data->OAUTH2Data->refresh_token,
6206 FALSE);
6207 log_message(LOG_PROTOCOL, "OAuth2 refresh token stored\n");
6210 if(oauth2_listener_data->OAUTH2Data->access_token != NULL){
6211 passwd_store_set_account(tmp_ac_prefs.account_id,
6212 PWS_ACCOUNT_RECV,
6213 oauth2_listener_data->OAUTH2Data->access_token,
6214 FALSE);
6215 if (tmp_ac_prefs.use_smtp_auth && tmp_ac_prefs.smtp_auth_type == SMTPAUTH_OAUTH2)
6216 passwd_store_set_account(tmp_ac_prefs.account_id,
6217 PWS_ACCOUNT_SEND,
6218 oauth2_listener_data->OAUTH2Data->access_token,
6219 FALSE);
6220 log_message(LOG_PROTOCOL, "OAuth2 access token stored\n");
6223 if(oauth2_listener_data->OAUTH2Data->expiry_str != NULL){
6224 passwd_store_set_account(tmp_ac_prefs.account_id,
6225 PWS_ACCOUNT_OAUTH2_EXPIRY,
6226 oauth2_listener_data->OAUTH2Data->expiry_str,
6227 FALSE);
6228 log_message(LOG_PROTOCOL, "OAuth2 access token expiry stored\n");
6231 tmp_ac_prefs.oauth2_date = g_get_real_time () / G_USEC_PER_SEC;
6233 gtk_entry_set_text(GTK_ENTRY(oauth2_page.oauth2_authcode_entry), oauth2_listener_data->trim_text != NULL ? oauth2_listener_data->trim_text : "");
6234 gtk_widget_set_sensitive(oauth2_page.oauth2_authcode_entry, FALSE);
6235 gtk_widget_set_sensitive(oauth2_page.oauth2_authorise_btn, FALSE);
6236 gtk_entry_set_text(GTK_ENTRY(basic_page.pass_entry), oauth2_listener_data->OAUTH2Data->access_token);
6237 gtk_entry_set_text(GTK_ENTRY(send_page.smtp_pass_entry), oauth2_listener_data->OAUTH2Data->access_token);
6240 debug_print("oauth2 listener callback freeing resources\n");
6241 g_free(oauth2_listener_data->trim_text);
6242 g_free(oauth2_listener_data->OAUTH2Data);
6243 g_free(oauth2_listener_data);
6244 oauth2_listener_cancel = 0;
6245 oauth2_listener_closed = 1;
6248 static int prefs_account_oauth2_get_line(int sock, char *buf, int size)
6250 int i = 0;
6251 char c = '\0';
6252 int n;
6254 while ((i < size - 1) && (c != '\n')) {
6255 n = recv(sock, &c, 1, 0);
6256 //printf("%02X\n", c);
6257 if (n > 0) {
6258 if (c == '\r') {
6259 n = recv(sock, &c, 1, MSG_PEEK);
6260 //printf("%02X\n", c);
6261 if ((n > 0) && (c == '\n')) {
6262 n = recv(sock, &c, 1, 0);
6263 if (n < 0)
6264 log_message(LOG_PROTOCOL, "Receiving from pipe failed\n");
6266 else
6267 c = '\n';
6269 buf[i] = c;
6270 i++;
6272 else
6273 c = '\n';
6275 buf[i] = '\0';
6277 return (i);
6279 #endif