2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
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/>.
22 #include "claws-features.h"
28 #include <glib/gi18n.h>
30 #include <gdk/gdkkeysyms.h>
35 #include "mainwindow.h"
36 #include "folderview.h"
39 #include "prefs_gtk.h"
40 #include "prefs_account.h"
41 #include "prefs_common.h"
42 #include "folder_item_prefs.h"
44 #include "manage_window.h"
45 #include "stock_pixmap.h"
49 #include "alertpanel.h"
50 #include "procheader.h"
51 #include "customheader.h"
52 #include "remotefolder.h"
54 #include "filtering.h"
55 #include "prefs_actions.h"
57 #include "passwordstore.h"
58 #include "file-utils.h"
62 ACCOUNT_ENABLE_GET_ALL
,
79 } EditAccountColumnPos
;
81 PrefsAccount
*cur_account
;
83 static GList
*account_list
= NULL
;
84 static gboolean account_list_dirty
= FALSE
;
86 static struct EditAccount
{
92 static void account_edit_create (void);
93 static void account_destroy (PrefsAccount
*ac_prefs
);
94 static void account_set_as_default (PrefsAccount
*ac_prefs
);
95 static void account_set_menu (void);
97 static void account_edit_prefs (GtkWidget
*widget
, gpointer data
);
98 static void account_delete (GtkWidget
*widget
, gpointer data
);
99 static void account_clone (GtkWidget
*widget
, gpointer data
);
101 static void account_up (GtkWidget
*widget
, gpointer data
);
102 static void account_down (GtkWidget
*widget
, gpointer data
);
104 static void account_set_default (GtkWidget
*widget
, gpointer data
);
106 static void account_edit_close (GtkWidget
*widget
, gpointer data
);
108 static gint
account_delete_event (GtkWidget
*widget
,
111 static void account_size_allocate_cb(GtkWidget
*widget
,
112 GtkAllocation
*allocation
);
113 static gboolean
account_key_pressed (GtkWidget
*widget
,
116 static gboolean
account_search_func_cb (GtkTreeModel
*model
, gint column
,
117 const gchar
*key
, GtkTreeIter
*iter
,
118 gpointer search_data
);
119 static void account_list_view_set (void);
121 static void account_list_set (void);
123 typedef struct FindAccountInStore
{
127 } FindAccountInStore
;
129 static GtkListStore
* account_create_data_store (void);
131 static void account_list_store_insert_account_item (GtkListStore
*list_store
,
132 PrefsAccount
*account_data
);
134 static GtkWidget
*account_list_view_create (void);
135 static void account_create_list_view_columns (GtkWidget
*list_view
);
137 static gint
account_list_view_get_selected_account_id (GtkWidget
*list_view
);
138 static GtkTreePath
*account_list_view_get_selected_account_path (GtkWidget
*list_view
);
139 static PrefsAccount
*account_list_view_get_selected_account (GtkWidget
*list_view
);
140 static gboolean
account_list_view_select_account (GtkWidget
*list_view
,
143 static void account_list_view_set_default_by_id(GtkWidget
*list_view
,
146 static gboolean
set_new_default_account (GtkTreeModel
*model
,
151 static gboolean
find_account_in_store (GtkTreeModel
*model
,
154 FindAccountInStore
*data
);
156 static void account_get_all_toggled (GtkCellRendererToggle
*widget
,
158 GtkWidget
*list_view
);
160 static void account_double_clicked (GtkTreeView
*list_view
,
162 GtkTreeViewColumn
*column
,
165 static void drag_begin (GtkTreeView
*list_view
,
166 GdkDragContext
*context
,
169 static void drag_end (GtkTreeView
*list_view
,
170 GdkDragContext
*context
,
173 static void account_row_changed_while_drag_drop (GtkTreeModel
*model
,
177 GtkTreeView
*list_view
);
179 static void account_flush_state(void)
182 main_window_reflect_prefs_all();
184 account_list_dirty
= FALSE
;
187 void account_read_config_all(void)
189 GSList
*ac_label_list
= NULL
, *cur
;
192 gchar buf
[PREFSBUFSIZE
];
193 PrefsAccount
*ac_prefs
;
195 debug_print("Reading all config for each account...\n");
197 rcpath
= g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S
, ACCOUNT_RC
, NULL
);
198 if ((fp
= claws_fopen(rcpath
, "rb")) == NULL
) {
199 if (ENOENT
!= errno
) FILE_OP_ERROR(rcpath
, "claws_fopen");
205 while (claws_fgets(buf
, sizeof(buf
), fp
) != NULL
) {
206 if (!strncmp(buf
, "[Account: ", 10)) {
208 memmove(buf
, buf
+ 1, sizeof(buf
) - 1);
209 buf
[strlen(buf
) - 1] = '\0';
210 debug_print("Found label: %s\n", buf
);
211 ac_label_list
= g_slist_append(ac_label_list
,
217 /* read config data from file */
219 for (cur
= ac_label_list
; cur
!= NULL
; cur
= cur
->next
) {
220 ac_prefs
= prefs_account_new_from_config((gchar
*)cur
->data
);
221 account_list
= g_list_append(account_list
, ac_prefs
);
222 if (ac_prefs
->is_default
)
223 cur_account
= ac_prefs
;
225 /* if default is not set, assume first account as default */
226 if (!cur_account
&& account_list
) {
227 ac_prefs
= (PrefsAccount
*)account_list
->data
;
228 account_set_as_default(ac_prefs
);
229 cur_account
= ac_prefs
;
233 main_window_reflect_prefs_all_now();
235 while (ac_label_list
) {
236 g_free(ac_label_list
->data
);
237 ac_label_list
= g_slist_remove(ac_label_list
,
238 ac_label_list
->data
);
242 void account_write_config_all(void)
244 prefs_account_write_config_all(account_list
);
248 * account_find_all_from_address:
249 * @ac_list: initial list of accounts. NULL to create a new one.
250 * Accounts found in the @address will be appended to this list.
251 * @address: Email address string.
253 * Find all the mail (not news) accounts within the specified address.
255 * Return value: the original accounts list with the found accounts appended.
257 GList
*account_find_all_from_address(GList
*ac_list
, const gchar
*address
)
265 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
266 ac
= (PrefsAccount
*)cur
->data
;
267 if (ac
->protocol
!= A_NNTP
&& ac
->address
&&
268 strcasestr(address
, ac
->address
) != NULL
)
269 ac_list
= g_list_append(ac_list
, ac
);
274 GList
*account_find_all(void)
278 GList
*ac_list
= NULL
;
280 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
281 ac
= (PrefsAccount
*)cur
->data
;
282 ac_list
= g_list_append(ac_list
, ac
);
287 PrefsAccount
*account_find_from_smtp_server(const gchar
*address
,
288 const gchar
*smtp_server
)
293 cm_return_val_if_fail(address
!= NULL
, NULL
);
294 cm_return_val_if_fail(smtp_server
!= NULL
, NULL
);
296 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
297 ac
= (PrefsAccount
*)cur
->data
;
298 if (!g_strcmp0(address
, ac
->address
) &&
299 !g_strcmp0(smtp_server
, ac
->smtp_server
))
307 * account_find_from_address:
308 * @address: Email address string.
310 * Find a mail (not news if newsgroups_ok is FALSE) account with the specified email address.
312 * Return value: The found account, or NULL if not found.
314 PrefsAccount
*account_find_from_address(const gchar
*address
, gboolean newsgroups_ok
)
319 cm_return_val_if_fail(address
!= NULL
, NULL
);
321 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
322 ac
= (PrefsAccount
*)cur
->data
;
323 if ((ac
->protocol
!= A_NNTP
|| newsgroups_ok
) && ac
->address
&&
324 g_ascii_strcasecmp(address
, ac
->address
) == 0)
331 PrefsAccount
*account_find_from_id(gint id
)
336 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
337 ac
= (PrefsAccount
*)cur
->data
;
338 if (id
== ac
->account_id
)
345 PrefsAccount
*account_find_from_item(FolderItem
*item
)
349 cm_return_val_if_fail(item
!= NULL
, NULL
);
353 FolderItem
*cur_item
= folder_item_parent(item
);
354 while (cur_item
!= NULL
) {
355 if (cur_item
->account
&& cur_item
->apply_sub
) {
356 ac
= cur_item
->account
;
359 cur_item
= folder_item_parent(cur_item
);
363 ac
= item
->folder
->account
;
368 static void account_set_menu(void)
370 main_window_set_account_menu(account_list
);
373 void account_set_menu_only_toolbar(void)
375 main_window_set_account_menu_only_toolbar(account_list
);
378 GList
*account_get_list(void)
383 void account_edit_focus(void)
385 if (edit_account
.window
== NULL
) {
388 manage_window_set_transient(GTK_WINDOW(edit_account
.window
));
389 gtk_widget_grab_focus(edit_account
.close_btn
);
390 gtk_widget_show(edit_account
.window
);
391 gtk_window_set_modal(GTK_WINDOW(edit_account
.window
), TRUE
);
392 manage_window_focus_in(edit_account
.window
, NULL
, NULL
);
395 void account_edit_open(gpointer a
, gpointer b
)
399 account_list_dirty
= FALSE
;
401 if (compose_get_compose_list()) {
402 alertpanel_error(_("Some composing windows are open.\n"
403 "Please close all the composing "
404 "windows before editing accounts."));
409 debug_print("Opening account edit window...\n");
411 if (!edit_account
.window
)
412 account_edit_create();
414 account_list_view_set();
416 account_edit_focus();
419 void account_add(void)
421 PrefsAccount
*ac_prefs
;
423 ac_prefs
= prefs_account_open(NULL
, &account_list_dirty
);
425 if (!ac_prefs
) return;
427 account_edit_focus();
429 account_list
= g_list_append(account_list
, ac_prefs
);
431 if (ac_prefs
->is_default
)
432 account_set_as_default(ac_prefs
);
434 account_list_view_set();
436 if (ac_prefs
->protocol
== A_IMAP4
|| ac_prefs
->protocol
== A_NNTP
) {
439 if (ac_prefs
->protocol
== A_IMAP4
) {
440 folder
= folder_new(folder_get_class_from_string("imap"), ac_prefs
->account_name
,
441 ac_prefs
->recv_server
);
443 folder
= folder_new(folder_get_class_from_string("news"), ac_prefs
->account_name
,
444 ac_prefs
->nntp_server
);
446 if (folder
== NULL
) {
447 alertpanel_error(_("Can't create folder."));
450 folder
->account
= ac_prefs
;
451 ac_prefs
->folder
= folder
;
453 if (ac_prefs
->protocol
== A_IMAP4
)
454 folder
->klass
->create_tree(folder
);
455 folderview_set_all();
460 void account_open(PrefsAccount
*ac_prefs
, gboolean called_from_acc_list
)
462 gboolean prev_default
;
463 gchar
*ac_name
, *old_prefix
, *new_prefix
;
464 gboolean account_dirty
= FALSE
;
466 cm_return_if_fail(ac_prefs
!= NULL
);
468 if (compose_get_compose_list()) {
469 alertpanel_error(_("Some composing windows are open.\n"
470 "Please close all the composing "
471 "windows before editing accounts."));
475 prev_default
= ac_prefs
->is_default
;
476 Xstrdup_a(ac_name
, ac_prefs
->account_name
? ac_prefs
->account_name
: "",
479 prefs_account_open(ac_prefs
, &account_dirty
);
481 if (called_from_acc_list
)
482 account_edit_focus();
485 if (!prev_default
&& ac_prefs
->is_default
)
486 account_set_as_default(ac_prefs
);
488 if (ac_prefs
->folder
&& g_strcmp0(ac_name
, ac_prefs
->account_name
) != 0) {
489 old_prefix
= folder_get_identifier(FOLDER(ac_prefs
->folder
));
490 folder_set_name(FOLDER(ac_prefs
->folder
),
491 ac_prefs
->account_name
);
492 folderview_set_all();
493 folder_prefs_save_config_recursive(FOLDER(ac_prefs
->folder
));
494 new_prefix
= folder_get_identifier(FOLDER(ac_prefs
->folder
));
496 account_rename_path(old_prefix
, new_prefix
);
497 prefs_filtering_rename_path(old_prefix
, new_prefix
);
498 prefs_actions_rename_path(old_prefix
, new_prefix
);
504 account_write_config_all();
506 account_flush_state();
510 static void account_set_as_default(PrefsAccount
*ac_prefs
)
515 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
516 ap
= (PrefsAccount
*)cur
->data
;
518 ap
->is_default
= FALSE
;
521 ac_prefs
->is_default
= TRUE
;
524 PrefsAccount
*account_get_default(void)
529 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
530 ap
= (PrefsAccount
*)cur
->data
;
538 void account_set_missing_folder(void)
543 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
544 ap
= (PrefsAccount
*)cur
->data
;
545 if ((ap
->protocol
== A_IMAP4
|| ap
->protocol
== A_NNTP
) &&
549 if (ap
->protocol
== A_IMAP4
) {
550 folder
= folder_new(folder_get_class_from_string("imap"), ap
->account_name
,
553 folder
= folder_new(folder_get_class_from_string("news"), ap
->account_name
,
558 folder
->account
= ap
;
561 if (ap
->protocol
== A_IMAP4
)
562 folder
->klass
->create_tree(folder
);
569 #define CHECK_CHANGE_FOLDER(folder) { \
570 if (folder && !strncmp(folder, old_id, strlen(old_id))) { \
571 if (strlen(folder) == strlen(old_id)) { \
573 folder = g_strdup(new_id); \
574 } else if (strlen(folder) > strlen(old_id) \
575 && folder[strlen(old_id)] == G_DIR_SEPARATOR) { \
576 gchar *new_path = g_strdup_printf("%s%s", \
577 new_id, (folder + strlen(old_id))); \
584 void account_rename_path(const gchar
*old_id
, const gchar
*new_id
)
586 GList
*cur
= account_list
;
587 for (; cur
!= NULL
; cur
= g_list_next(cur
)) {
588 PrefsAccount
*ap
= (PrefsAccount
*)cur
->data
;
589 CHECK_CHANGE_FOLDER(ap
->inbox
);
590 CHECK_CHANGE_FOLDER(ap
->local_inbox
);
591 CHECK_CHANGE_FOLDER(ap
->queue_folder
);
592 CHECK_CHANGE_FOLDER(ap
->sent_folder
);
593 CHECK_CHANGE_FOLDER(ap
->draft_folder
);
594 CHECK_CHANGE_FOLDER(ap
->trash_folder
);
598 FolderItem
*account_get_special_folder(PrefsAccount
*ac_prefs
,
599 SpecialFolderItemType type
)
601 FolderItem
*item
= NULL
;
603 cm_return_val_if_fail(ac_prefs
!= NULL
, NULL
);
607 if (ac_prefs
->folder
)
608 item
= FOLDER(ac_prefs
->folder
)->inbox
;
610 item
= folder_get_default_inbox();
613 if (ac_prefs
->set_sent_folder
&& ac_prefs
->sent_folder
) {
614 item
= folder_find_item_from_identifier
615 (ac_prefs
->sent_folder
);
618 if (ac_prefs
->folder
)
619 item
= FOLDER(ac_prefs
->folder
)->outbox
;
621 item
= folder_get_default_outbox_for_class(F_MH
);
623 item
= folder_get_default_outbox();
627 if (ac_prefs
->set_draft_folder
&& ac_prefs
->draft_folder
) {
628 item
= folder_find_item_from_identifier
629 (ac_prefs
->draft_folder
);
632 if (ac_prefs
->folder
)
633 item
= FOLDER(ac_prefs
->folder
)->draft
;
635 item
= folder_get_default_draft_for_class(F_MH
);
637 item
= folder_get_default_draft();
641 if (ac_prefs
->set_queue_folder
&& ac_prefs
->queue_folder
) {
642 item
= folder_find_item_from_identifier
643 (ac_prefs
->queue_folder
);
646 if (ac_prefs
->folder
)
647 item
= FOLDER(ac_prefs
->folder
)->queue
;
649 item
= folder_get_default_queue_for_class(F_MH
);
651 item
= folder_get_default_queue();
655 if (ac_prefs
->set_trash_folder
&& ac_prefs
->trash_folder
) {
656 item
= folder_find_item_from_identifier
657 (ac_prefs
->trash_folder
);
660 if (ac_prefs
->folder
)
661 item
= FOLDER(ac_prefs
->folder
)->trash
;
663 item
= folder_get_default_trash_for_class(F_MH
);
665 item
= folder_get_default_trash();
675 void account_destroy(PrefsAccount
*ac_prefs
)
677 cm_return_if_fail(ac_prefs
!= NULL
);
679 folder_unref_account_all(ac_prefs
);
681 account_list
= g_list_remove(account_list
, ac_prefs
);
683 if (cur_account
== ac_prefs
) cur_account
= NULL
;
684 if (!cur_account
&& account_list
) {
685 cur_account
= account_get_default();
687 ac_prefs
= (PrefsAccount
*)account_list
->data
;
688 account_set_as_default(ac_prefs
);
689 cur_account
= ac_prefs
;
695 *\brief Save Gtk object size to prefs dataset
697 static void account_size_allocate_cb(GtkWidget
*widget
,
698 GtkAllocation
*allocation
)
700 cm_return_if_fail(allocation
!= NULL
);
702 prefs_common
.accountswin_width
= allocation
->width
;
703 prefs_common
.accountswin_height
= allocation
->height
;
706 static void account_edit_create(void)
712 GtkWidget
*scrolledwin
;
713 GtkWidget
*list_view
;
719 GtkWidget
*clone_btn
;
723 GtkWidget
*default_btn
;
725 GtkWidget
*confirm_area
;
727 GtkWidget
*close_btn
;
729 static GdkGeometry geometry
;
731 debug_print("Creating account edit window...\n");
733 window
= gtkut_window_new(GTK_WINDOW_TOPLEVEL
, "account");
734 gtk_container_set_border_width (GTK_CONTAINER (window
), 8);
735 gtk_window_set_title (GTK_WINDOW (window
), _("Edit accounts"));
736 g_signal_connect (G_OBJECT (window
), "delete_event",
737 G_CALLBACK (account_delete_event
), NULL
);
738 g_signal_connect (G_OBJECT (window
), "key_press_event",
739 G_CALLBACK (account_key_pressed
), NULL
);
740 MANAGE_WINDOW_SIGNALS_CONNECT (window
);
741 gtk_widget_realize(window
);
743 vbox
= gtk_vbox_new (FALSE
, 10);
744 gtk_widget_show (vbox
);
745 gtk_container_add (GTK_CONTAINER (window
), vbox
);
747 hbox
= gtk_hbox_new (FALSE
, 0);
748 gtk_widget_show (hbox
);
749 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
751 label
= gtk_label_new
752 (_("Using 'Get Mail' will retrieve messages from your Accounts "
753 "in the order given, the checkbox indicates which accounts "
754 "will be included. Bold text indicates the default account."));
755 gtk_widget_show (label
);
756 gtk_widget_set_size_request(GTK_WIDGET(label
),
757 prefs_common
.accountswin_width
-8, -1);
758 gtk_box_pack_start (GTK_BOX (hbox
), label
, FALSE
, FALSE
, 4);
759 gtk_label_set_justify(GTK_LABEL(label
), GTK_JUSTIFY_LEFT
);
760 gtk_label_set_line_wrap(GTK_LABEL(label
), TRUE
);
762 hbox
= gtk_hbox_new (FALSE
, 8);
763 gtk_widget_show (hbox
);
764 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, TRUE
, TRUE
, 0);
765 gtk_container_set_border_width (GTK_CONTAINER (hbox
), 2);
767 scrolledwin
= gtk_scrolled_window_new (NULL
, NULL
);
768 gtk_widget_show (scrolledwin
);
769 gtk_box_pack_start (GTK_BOX (hbox
), scrolledwin
, TRUE
, TRUE
, 0);
770 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin
),
771 GTK_POLICY_AUTOMATIC
,
772 GTK_POLICY_AUTOMATIC
);
774 list_view
= account_list_view_create();
775 gtk_widget_show(list_view
);
776 gtk_container_add(GTK_CONTAINER(scrolledwin
), list_view
);
778 vbox2
= gtk_vbox_new (FALSE
, 0);
779 gtk_widget_show (vbox2
);
780 gtk_box_pack_start (GTK_BOX (hbox
), vbox2
, FALSE
, FALSE
, 0);
782 add_btn
= gtk_button_new_from_stock(GTK_STOCK_NEW
);
783 gtk_widget_show (add_btn
);
784 gtk_box_pack_start (GTK_BOX (vbox2
), add_btn
, FALSE
, FALSE
, 4);
785 g_signal_connect (G_OBJECT(add_btn
), "clicked",
786 G_CALLBACK (account_add
), NULL
);
788 edit_btn
= gtk_button_new_from_stock (GTK_STOCK_EDIT
);
789 gtk_widget_show (edit_btn
);
790 gtk_box_pack_start (GTK_BOX (vbox2
), edit_btn
, FALSE
, FALSE
, 4);
791 g_signal_connect (G_OBJECT(edit_btn
), "clicked",
792 G_CALLBACK (account_edit_prefs
), NULL
);
794 del_btn
= gtk_button_new_from_stock(GTK_STOCK_DELETE
);
795 gtk_widget_show (del_btn
);
796 gtk_box_pack_start (GTK_BOX (vbox2
), del_btn
, FALSE
, FALSE
, 4);
797 g_signal_connect (G_OBJECT(del_btn
), "clicked",
798 G_CALLBACK (account_delete
), NULL
);
800 clone_btn
= gtk_button_new_from_stock(GTK_STOCK_COPY
);
801 gtk_widget_show (clone_btn
);
802 gtk_box_pack_start (GTK_BOX (vbox2
), clone_btn
, FALSE
, FALSE
, 4);
803 g_signal_connect(G_OBJECT(clone_btn
), "clicked",
804 G_CALLBACK(account_clone
), NULL
);
806 down_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_DOWN
);
807 gtk_widget_show (down_btn
);
808 gtk_box_pack_end (GTK_BOX (vbox2
), down_btn
, FALSE
, FALSE
, 4);
809 g_signal_connect (G_OBJECT(down_btn
), "clicked",
810 G_CALLBACK (account_down
), NULL
);
812 up_btn
= gtk_button_new_from_stock(GTK_STOCK_GO_UP
);
813 gtk_widget_show (up_btn
);
814 gtk_box_pack_end (GTK_BOX (vbox2
), up_btn
, FALSE
, FALSE
, 4);
815 g_signal_connect (G_OBJECT(up_btn
), "clicked",
816 G_CALLBACK (account_up
), NULL
);
818 hbox
= gtk_hbox_new (FALSE
, 8);
819 gtk_widget_show (hbox
);
820 gtk_box_pack_start (GTK_BOX (vbox
), hbox
, FALSE
, FALSE
, 0);
822 default_btn
= gtk_button_new_with_mnemonic
823 (_(" _Set as default account "));
824 gtk_widget_show (default_btn
);
825 gtk_box_pack_start (GTK_BOX (hbox
), default_btn
, FALSE
, FALSE
, 0);
826 g_signal_connect (G_OBJECT(default_btn
), "clicked",
827 G_CALLBACK (account_set_default
), NULL
);
829 gtkut_stock_button_set_create_with_help(&confirm_area
, &help_btn
,
830 &close_btn
, GTK_STOCK_CLOSE
,
831 NULL
, NULL
, NULL
, NULL
);
832 gtk_widget_show(confirm_area
);
834 gtk_box_pack_end (GTK_BOX (hbox
), confirm_area
, FALSE
, FALSE
, 0);
835 gtk_widget_grab_default (close_btn
);
837 g_signal_connect (G_OBJECT (close_btn
), "clicked",
838 G_CALLBACK (account_edit_close
),
840 g_signal_connect(G_OBJECT(help_btn
), "clicked",
841 G_CALLBACK(manual_open_with_anchor_cb
),
842 MANUAL_ANCHOR_ACCOUNTPREFS
);
845 g_signal_connect(G_OBJECT(window
), "size_allocate",
846 G_CALLBACK(account_size_allocate_cb
), NULL
);
848 if (!geometry
.min_height
) {
849 geometry
.min_width
= 500;
850 geometry
.min_height
= 380;
853 gtk_window_set_geometry_hints(GTK_WINDOW(window
), NULL
, &geometry
,
855 gtk_widget_set_size_request(window
, prefs_common
.accountswin_width
,
856 prefs_common
.accountswin_height
);
858 gtk_window_move(GTK_WINDOW(window
), 48, 48);
861 edit_account
.window
= window
;
862 edit_account
.list_view
= list_view
;
863 edit_account
.close_btn
= close_btn
;
866 static void account_edit_prefs(GtkWidget
*widget
, gpointer data
)
868 PrefsAccount
*ac_prefs
;
870 ac_prefs
= account_list_view_get_selected_account(edit_account
.list_view
);
873 account_open(ac_prefs
, TRUE
);
874 account_list_view_set();
878 static gboolean
account_delete_references_func(GNode
*node
, gpointer data
)
883 cm_return_val_if_fail(node
->data
!= NULL
, FALSE
);
885 item
= FOLDER_ITEM(node
->data
);
886 account
= GPOINTER_TO_INT(data
);
888 if(!item
->prefs
) /* && item->prefs->stype == F_NORMAL */
890 if(item
->prefs
->default_account
!= account
)
893 item
->prefs
->enable_default_account
= FALSE
;
894 item
->prefs
->default_account
= 0;
895 folder_item_prefs_save_config(item
);
901 #define ACP_FDUP(fld) ac_clon->fld = ((ac_prefs->fld) != NULL)?\
902 g_strdup(ac_prefs->fld): NULL
903 #define ACP_FASSIGN(fld) ac_clon->fld = ac_prefs->fld
904 static void account_clone(GtkWidget
*widget
, gpointer data
)
906 PrefsAccount
*ac_prefs
, *ac_clon
;
908 CustomHeader
*cch
= NULL
, *ch
= NULL
;
910 ac_prefs
= account_list_view_get_selected_account(edit_account
.list_view
);
911 if (ac_prefs
== NULL
)
914 if (ac_prefs
->protocol
== A_IMAP4
|| ac_prefs
->protocol
== A_NNTP
) {
915 alertpanel_error(_("Accounts with remote folders cannot be copied."));
918 account_list_dirty
= TRUE
;
920 ac_clon
= prefs_account_new();
922 ac_clon
->account_name
= g_strdup_printf(_("Copy of %s"),
923 ac_prefs
->account_name
);
927 ACP_FDUP(organization
);
930 ACP_FASSIGN(protocol
);
931 ACP_FDUP(recv_server
);
932 ACP_FDUP(smtp_server
);
933 ACP_FDUP(nntp_server
);
934 ACP_FASSIGN(use_nntp_auth
);
935 ACP_FASSIGN(use_nntp_auth_onconnect
);
939 ACP_FDUP(local_mbox
);
940 ACP_FASSIGN(use_mail_command
);
941 ACP_FDUP(mail_command
);
943 ACP_FASSIGN(ssl_pop
);
944 ACP_FASSIGN(ssl_imap
);
945 ACP_FASSIGN(ssl_nntp
);
946 ACP_FASSIGN(ssl_smtp
);
947 ACP_FASSIGN(ssl_certs_auto_accept
);
948 ACP_FASSIGN(use_nonblocking_ssl
);
949 ACP_FASSIGN(use_tls_sni
);
950 ACP_FASSIGN(in_ssl_client_cert_file
);
951 ACP_FASSIGN(in_ssl_client_cert_pass
);
952 ACP_FASSIGN(out_ssl_client_cert_file
);
953 ACP_FASSIGN(out_ssl_client_cert_pass
);
956 ACP_FASSIGN(use_apop_auth
);
958 ACP_FASSIGN(msg_leave_time
);
959 ACP_FASSIGN(msg_leave_hour
);
960 ACP_FASSIGN(recv_at_getall
);
961 ACP_FASSIGN(sd_rmmail_on_download
);
962 ACP_FASSIGN(enable_size_limit
);
963 ACP_FASSIGN(size_limit
);
964 ACP_FASSIGN(filter_on_recv
);
965 ACP_FASSIGN(filterhook_on_recv
);
967 ACP_FDUP(local_inbox
);
968 ACP_FASSIGN(max_articles
);
969 ACP_FASSIGN(autochk_use_default
);
970 ACP_FASSIGN(autochk_use_custom
);
971 ACP_FASSIGN(autochk_itv
);
972 ac_clon
->autocheck_timer
= 0;
974 ACP_FASSIGN(imap_auth_type
);
977 ACP_FASSIGN(gen_msgid
);
978 ACP_FASSIGN(gen_xmailer
);
979 ACP_FASSIGN(add_customhdr
);
980 ACP_FASSIGN(use_smtp_auth
);
981 ACP_FASSIGN(smtp_auth_type
);
982 ACP_FDUP(smtp_userid
);
983 ACP_FDUP(smtp_passwd
);
985 ACP_FASSIGN(pop_before_smtp
);
986 ACP_FASSIGN(pop_before_smtp_timeout
);
987 ACP_FASSIGN(last_pop_login_time
);
989 ac_clon
->customhdr_list
= NULL
;
990 hdrs
= ac_prefs
->customhdr_list
;
991 while (hdrs
!= NULL
) {
992 ch
= (CustomHeader
*)hdrs
->data
;
994 cch
= g_new0(CustomHeader
, 1);
995 cch
->account_id
= ac_clon
->account_id
;
996 cch
->name
= (ch
->name
!= NULL
) ? g_strdup(ch
->name
) : NULL
;
997 cch
->value
= (ch
->value
!= NULL
) ? g_strdup(ch
->value
) : NULL
;
999 ac_clon
->customhdr_list
= g_slist_append(ac_clon
->customhdr_list
, cch
);
1001 hdrs
= g_slist_next(hdrs
);
1005 ACP_FASSIGN(sig_type
);
1007 ACP_FASSIGN(auto_sig
);
1009 ACP_FASSIGN(set_autocc
);
1011 ACP_FASSIGN(set_autobcc
);
1013 ACP_FASSIGN(set_autoreplyto
);
1014 ACP_FDUP(auto_replyto
);
1015 ACP_FASSIGN(enable_default_dictionary
);
1016 ACP_FDUP(default_dictionary
);
1017 ACP_FASSIGN(enable_default_alt_dictionary
);
1018 ACP_FDUP(default_alt_dictionary
);
1019 ACP_FASSIGN(compose_with_format
);
1020 ACP_FDUP(compose_subject_format
);
1021 ACP_FDUP(compose_body_format
);
1022 ACP_FASSIGN(reply_with_format
);
1023 ACP_FDUP(reply_quotemark
);
1024 ACP_FDUP(reply_body_format
);
1025 ACP_FASSIGN(forward_with_format
);
1026 ACP_FDUP(forward_quotemark
);
1027 ACP_FDUP(forward_body_format
);
1030 ACP_FDUP(default_privacy_system
);
1031 ACP_FASSIGN(default_encrypt
);
1032 ACP_FASSIGN(default_encrypt_reply
);
1033 ACP_FASSIGN(default_sign
);
1034 ACP_FASSIGN(default_sign_reply
);
1035 ACP_FASSIGN(save_encrypted_as_clear_text
);
1036 ACP_FASSIGN(encrypt_to_self
);
1039 ACP_FASSIGN(set_smtpport
);
1040 ACP_FASSIGN(smtpport
);
1041 ACP_FASSIGN(set_popport
);
1042 ACP_FASSIGN(popport
);
1043 ACP_FASSIGN(set_imapport
);
1044 ACP_FASSIGN(imapport
);
1045 ACP_FASSIGN(set_nntpport
);
1046 ACP_FASSIGN(nntpport
);
1047 ACP_FASSIGN(set_domain
);
1049 ACP_FASSIGN(mark_crosspost_read
);
1050 ACP_FASSIGN(crosspost_col
);
1053 ACP_FASSIGN(set_tunnelcmd
);
1054 ACP_FDUP(tunnelcmd
);
1058 ACP_FASSIGN(imap_subsonly
);
1059 ACP_FASSIGN(low_bandwidth
);
1061 ACP_FASSIGN(set_sent_folder
);
1062 ACP_FDUP(sent_folder
);
1063 ACP_FASSIGN(set_queue_folder
);
1064 ACP_FDUP(queue_folder
);
1065 ACP_FASSIGN(set_draft_folder
);
1066 ACP_FDUP(draft_folder
);
1067 ACP_FASSIGN(set_trash_folder
);
1068 ACP_FDUP(trash_folder
);
1069 /* don't want two default accounts */
1070 ac_clon
->is_default
= FALSE
;
1071 ACP_FASSIGN(folder
);
1073 ACP_FASSIGN(config_version
);
1075 ACP_FASSIGN(use_proxy
);
1076 ACP_FASSIGN(use_default_proxy
);
1077 ACP_FASSIGN(use_proxy_for_send
);
1078 ACP_FASSIGN(proxy_info
.proxy_type
);
1079 ACP_FDUP(proxy_info
.proxy_host
);
1080 ACP_FASSIGN(proxy_info
.proxy_port
);
1081 ACP_FASSIGN(proxy_info
.use_proxy_auth
);
1082 ACP_FDUP(proxy_info
.proxy_name
);
1083 ACP_FDUP(proxy_info
.proxy_pass
);
1085 account_list
= g_list_append(account_list
, ac_clon
);
1086 account_list_view_set();
1091 static void account_empty_cache(PrefsAccount
*ac_prefs
)
1095 cache_dir
= prefs_account_cache_dir(ac_prefs
, FALSE
);
1096 if (cache_dir
== NULL
)
1097 return; /* no cache dir, nothing to do */
1099 if (is_dir_exist(cache_dir
) && remove_dir_recursive(cache_dir
) < 0) {
1100 g_warning("can't remove directory '%s'", cache_dir
);
1102 gchar
*server_dir
= prefs_account_cache_dir(ac_prefs
, TRUE
);
1103 if (g_rmdir(server_dir
) == 0)
1104 debug_print("Removed empty cache server directory\n");
1106 debug_print("Cache server directory not empty: not removed\n");
1112 static void account_delete(GtkWidget
*widget
, gpointer data
)
1114 PrefsAccount
*ac_prefs
;
1115 gchar buf
[BUFFSIZE
];
1120 ac_prefs
= account_list_view_get_selected_account(edit_account
.list_view
);
1121 if (ac_prefs
== NULL
)
1124 g_snprintf(buf
, sizeof(buf
),
1125 _("Do you really want to delete the account '%s'?"),
1126 ac_prefs
->account_name
? ac_prefs
->account_name
:
1128 if (alertpanel_full(_("Delete account"), buf
,
1129 GTK_STOCK_CANCEL
, GTK_STOCK_DELETE
, NULL
, ALERTFOCUS_FIRST
, FALSE
,
1130 NULL
, ALERT_WARNING
) != G_ALERTALTERNATE
)
1132 account_list_dirty
= TRUE
;
1134 if (ac_prefs
->folder
) {
1137 item
= mainwindow_get_mainwindow()->summaryview
->folder_item
;
1138 if (item
&& item
->folder
== FOLDER(ac_prefs
->folder
))
1139 summary_clear_all(mainwindow_get_mainwindow()->summaryview
);
1140 folder_destroy(FOLDER(ac_prefs
->folder
));
1141 folderview_set_all();
1144 inc_account_autocheck_timer_remove(ac_prefs
);
1146 account_destroy(ac_prefs
);
1147 account_list_view_set();
1149 debug_print("Removing deleted account references for all the folders...\n");
1150 list
= folder_get_list();
1151 for (; list
!= NULL
; list
= list
->next
) {
1152 folder
= FOLDER(list
->data
);
1153 if (folder
->node
) /* && folder->type == F_? */
1154 g_node_traverse(folder
->node
, G_PRE_ORDER
,
1156 account_delete_references_func
,
1157 GINT_TO_POINTER(ac_prefs
->account_id
));
1160 gchar
*uid
= g_strdup_printf("%d", ac_prefs
->account_id
);
1161 passwd_store_delete_block(PWS_ACCOUNT
, uid
);
1164 debug_print("Removing filter rules relative to this account...\n");
1165 for(cur
= filtering_rules
; cur
!= NULL
;) {
1166 FilteringProp
* prop
= (FilteringProp
*) cur
->data
;
1168 if (prop
&& (prop
->account_id
== ac_prefs
->account_id
)) {
1169 /* get next item before we kill the current one */
1170 cur
= g_slist_next(cur
);
1172 /* unallocate filteringprop and unchain it from the list */
1173 filteringprop_free(prop
);
1174 filtering_rules
= g_slist_remove(filtering_rules
, prop
);
1176 cur
= g_slist_next(cur
);
1180 debug_print("Removing cache directory of this account...\n");
1181 account_empty_cache(ac_prefs
);
1183 folder_write_list();
1186 static void account_up(GtkWidget
*widget
, gpointer data
)
1188 GtkTreePath
*sel
= account_list_view_get_selected_account_path
1189 (edit_account
.list_view
),
1191 GtkTreeIter isel
, iup
;
1192 GtkTreeModel
*model
= gtk_tree_view_get_model
1193 (GTK_TREE_VIEW(edit_account
.list_view
));
1197 account_list_dirty
= TRUE
;
1199 up
= gtk_tree_path_copy(sel
);
1201 gtk_tree_path_free(sel
);
1205 if (!gtk_tree_path_prev(up
)) {
1206 gtk_tree_path_free(up
);
1207 gtk_tree_path_free(sel
);
1211 if (!gtk_tree_model_get_iter(model
, &isel
, sel
)
1212 || !gtk_tree_model_get_iter(model
, &iup
, up
)) {
1213 gtk_tree_path_free(up
);
1214 gtk_tree_path_free(sel
);
1218 gtk_list_store_swap(GTK_LIST_STORE(model
), &isel
, &iup
);
1222 gtk_tree_path_free(up
);
1223 gtk_tree_path_free(sel
);
1226 static void account_down(GtkWidget
*widget
, gpointer data
)
1228 GtkTreePath
*sel
= account_list_view_get_selected_account_path
1229 (edit_account
.list_view
),
1231 GtkTreeIter isel
, idn
;
1232 GtkTreeModel
*model
= gtk_tree_view_get_model
1233 (GTK_TREE_VIEW(edit_account
.list_view
));
1237 account_list_dirty
= TRUE
;
1239 dn
= gtk_tree_path_copy(sel
);
1241 gtk_tree_path_free(sel
);
1245 /* XXX no check possible??? however, if down but at bottom, then
1246 * nothing seems to happen much anyway, so the following seems to
1248 gtk_tree_path_next(dn
);
1250 if (!gtk_tree_model_get_iter(model
, &isel
, sel
)
1251 || !gtk_tree_model_get_iter(model
, &idn
, dn
)) {
1252 gtk_tree_path_free(dn
);
1253 gtk_tree_path_free(sel
);
1257 gtk_list_store_swap(GTK_LIST_STORE(model
), &isel
, &idn
);
1261 gtk_tree_path_free(dn
);
1262 gtk_tree_path_free(sel
);
1265 static void account_set_default(GtkWidget
*widget
, gpointer data
)
1267 PrefsAccount
*ac_prefs
;
1269 if (NULL
== (ac_prefs
= account_list_view_get_selected_account
1270 (edit_account
.list_view
)))
1273 /* we need to change the store variables by resetting everything
1274 * and setting the new default one */
1275 account_list_view_set_default_by_id(edit_account
.list_view
,
1276 ac_prefs
->account_id
);
1278 account_set_as_default(ac_prefs
);
1279 account_list_view_set();
1281 cur_account
= ac_prefs
;
1282 account_flush_state();
1285 static void account_edit_close(GtkWidget
*widget
, gpointer data
)
1288 account_write_config_all();
1290 if (!cur_account
&& account_list
) {
1291 PrefsAccount
*ac_prefs
= (PrefsAccount
*)account_list
->data
;
1292 account_set_as_default(ac_prefs
);
1293 cur_account
= ac_prefs
;
1296 if (account_list_dirty
)
1297 account_flush_state();
1299 gtk_widget_hide(edit_account
.window
);
1300 gtk_window_set_modal(GTK_WINDOW(edit_account
.window
), FALSE
);
1304 static gint
account_delete_event(GtkWidget
*widget
, GdkEventAny
*event
,
1307 account_edit_close(NULL
, NULL
);
1311 static gboolean
account_key_pressed(GtkWidget
*widget
, GdkEventKey
*event
,
1314 if (event
&& event
->keyval
== GDK_KEY_Escape
)
1315 account_edit_close(NULL
, NULL
);
1319 static gboolean
account_search_func_cb (GtkTreeModel
*model
, gint column
, const gchar
*key
,
1320 GtkTreeIter
*iter
, gpointer search_data
)
1325 gtk_tree_model_get (model
, iter
, ACCOUNT_DATA
, &ac
, -1);
1327 if (!ac
->name
|| !key
) return FALSE
;
1329 retval
= (strncmp (key
, ac
->account_name
, strlen(key
)) != 0);
1331 debug_print("selecting row\n");
1332 account_list_view_select_account(edit_account
.list_view
, ac
->account_id
);
1337 static void account_list_view_set(void)
1340 gint prev_sel_account
;
1341 GtkListStore
*store
;
1343 store
= GTK_LIST_STORE(gtk_tree_view_get_model
1344 (GTK_TREE_VIEW(edit_account
.list_view
)));
1346 prev_sel_account
= account_list_view_get_selected_account_id
1347 (edit_account
.list_view
);
1349 gtk_list_store_clear(store
);
1351 for (cur
= account_list
; cur
!= NULL
; cur
= cur
->next
) {
1352 account_list_store_insert_account_item(store
, (PrefsAccount
*)cur
->data
);
1353 if ((PrefsAccount
*)cur
->data
== cur_account
)
1354 account_list_view_select_account
1355 (edit_account
.list_view
,
1356 cur_account
->account_id
);
1359 if (prev_sel_account
>= 0)
1360 account_list_view_select_account(edit_account
.list_view
,
1364 /* set account list from CList */
1365 static void account_list_set(void)
1367 /* want to make sure we iterate *IN ORDER*, so therefore using
1368 * gtk_tree_model_XXXX_nth_child() */
1370 PrefsAccount
*ac_prefs
;
1371 GtkTreeModel
*model
= gtk_tree_view_get_model
1372 (GTK_TREE_VIEW(edit_account
.list_view
));
1374 while (account_list
)
1375 account_list
= g_list_remove(account_list
, account_list
->data
);
1377 n_rows
= gtk_tree_model_iter_n_children(model
, NULL
);
1379 for (row
= 0; row
< n_rows
; row
++) {
1382 if (!gtk_tree_model_iter_nth_child(model
, &iter
, NULL
, row
)) {
1383 g_warning("%s(%d) - no iter found???", __FILE__
, __LINE__
);
1388 gtk_tree_model_get(model
, &iter
,
1389 ACCOUNT_DATA
, &ac_prefs
,
1392 account_list
= g_list_append(account_list
, ac_prefs
);
1397 *\brief finds the PrefsAccounts which should be used to answer a mail
1399 *\param msginfo The message to be answered
1400 *\param reply_autosel Indicates whether reply account autoselection is on
1402 *\return PrefsAccount * the correct account, NULL if not found
1404 PrefsAccount
*account_get_reply_account(MsgInfo
*msginfo
, gboolean reply_autosel
)
1406 PrefsAccount
*account
= NULL
;
1407 /* select the account set in folderitem's property (if enabled) */
1408 if (msginfo
->folder
->prefs
&& msginfo
->folder
->prefs
->enable_default_account
)
1409 account
= account_find_from_id(msginfo
->folder
->prefs
->default_account
);
1410 else if (folder_has_parent_of_type(msginfo
->folder
, F_QUEUE
) ||
1411 folder_has_parent_of_type(msginfo
->folder
, F_OUTBOX
) ||
1412 folder_has_parent_of_type(msginfo
->folder
, F_DRAFT
)) {
1414 if (!procheader_get_header_from_msginfo
1415 (msginfo
, &from
, "From:")) {
1416 gchar
*buf
= from
+ strlen("From:");
1417 extract_address(buf
);
1418 account
= account_find_from_address(buf
, FALSE
);
1422 /* select account by to: and cc: header if enabled */
1423 if (reply_autosel
) {
1424 gchar
* field
= NULL
;
1426 for (field
= msginfo
->to
; fieldno
++ < 2; field
= msginfo
->cc
) {
1427 if (!account
&& field
) {
1428 gchar
*f
= g_strdup(field
);
1434 next
= strchr_with_skip_quote(cur
, '"', ',');
1437 Xstrdup_a(to
, cur
, return NULL
);
1438 extract_address(to
);
1439 account
= account_find_from_address(to
, FALSE
);
1450 gchar
*deliveredto
= NULL
;
1451 if (!procheader_get_header_from_msginfo
1452 (msginfo
, &deliveredto
, "Delivered-To:")) {
1453 gchar
*buf
= deliveredto
+ strlen("Delivered-To:");
1454 extract_address(buf
);
1455 account
= account_find_from_address(buf
, FALSE
);
1456 g_free(deliveredto
);
1461 /* select the account for the whole folder (IMAP / NNTP) */
1463 /* FIXME: this is not right, because folder may be nested. we should
1464 * ascend the tree until we find a parent with proper account
1466 account
= msginfo
->folder
->folder
->account
;
1468 /* select current account */
1469 if (!account
) account
= cur_account
;
1475 *\brief Create data store
1477 static GtkListStore
* account_create_data_store(void)
1479 return gtk_list_store_new(N_ACCOUNT_COLUMNS
,
1480 G_TYPE_INT
, /* ACCOUNT_IS_DEFAULT */
1481 G_TYPE_BOOLEAN
, /* ACCOUNT_ENABLE_GET_ALL */
1482 G_TYPE_STRING
, /* ACCOUNT_NAME */
1483 G_TYPE_STRING
, /* ACCOUNT_PROTOCOL */
1484 G_TYPE_STRING
, /* ACCOUNT_SERVER */
1485 G_TYPE_POINTER
, /* ACCOUNT_DATA */
1490 *\brief Insert an account item in the list.
1492 *\return GtkTreeRowReference * A tree row reference, which is guaranteed to
1493 * stable whatever operations are performed on the list.
1495 static void account_list_store_insert_account_item(GtkListStore
*list_store
,
1496 PrefsAccount
*ac_prefs
)
1499 gboolean is_get_all
= (ac_prefs
->protocol
== A_POP3
||
1500 ac_prefs
->protocol
== A_IMAP4
||
1501 ac_prefs
->protocol
== A_NNTP
||
1502 ac_prefs
->protocol
== A_LOCAL
) &&
1503 ac_prefs
->recv_at_getall
;
1504 gchar
*protocol
, *server
;
1507 protocol
= ac_prefs
->protocol
== A_POP3
?
1508 (ac_prefs
->ssl_pop
== SSL_TUNNEL
?
1510 ac_prefs
->ssl_pop
== SSL_STARTTLS
?
1511 "POP (STARTTLS)" : "POP") :
1512 ac_prefs
->protocol
== A_IMAP4
?
1513 (ac_prefs
->ssl_imap
== SSL_TUNNEL
?
1515 ac_prefs
->ssl_imap
== SSL_STARTTLS
?
1516 "IMAP (STARTTLS)" : "IMAP") :
1517 ac_prefs
->protocol
== A_NNTP
?
1518 (ac_prefs
->ssl_nntp
== SSL_TUNNEL
?
1519 "NNTP (SSL/TLS)" : "NNTP") :
1520 ac_prefs
->protocol
== A_LOCAL
? "Local" :
1521 ac_prefs
->protocol
== A_NONE
? "SMTP" : "-";
1523 protocol
= ac_prefs
->protocol
== A_POP3
? "POP" :
1524 ac_prefs
->protocol
== A_IMAP4
? "IMAP" :
1525 ac_prefs
->protocol
== A_LOCAL
? "Local" :
1526 ac_prefs
->protocol
== A_NNTP
? "NNTP" :
1527 ac_prefs
->protocol
== A_NONE
? "SMTP" : "-";
1530 server
= ac_prefs
->protocol
== A_NNTP
? ac_prefs
->nntp_server
:
1531 ac_prefs
->protocol
== A_LOCAL
? "-" :
1532 ac_prefs
->protocol
== A_NONE
? ac_prefs
->smtp_server
:
1533 ac_prefs
->recv_server
;
1535 gtk_list_store_append(list_store
, &iter
);
1536 gtk_list_store_set(list_store
, &iter
,
1537 ACCOUNT_IS_DEFAULT
, ac_prefs
->is_default
? PANGO_WEIGHT_BOLD
: PANGO_WEIGHT_NORMAL
,
1538 ACCOUNT_ENABLE_GET_ALL
, is_get_all
,
1539 ACCOUNT_NAME
, ac_prefs
->account_name
,
1540 ACCOUNT_PROTOCOL
, protocol
,
1541 ACCOUNT_SERVER
, server
,
1542 ACCOUNT_DATA
, ac_prefs
,
1547 *\brief Create and set up account list view, including tasks like
1548 * creating the data store (\ref account_create_data_store()),
1549 * and setting up the account list's individual columns (\ref
1550 * account_create_list_view_columns()).
1552 *\return GtkWidget * The created list view widget.
1554 static GtkWidget
*account_list_view_create(void)
1556 GtkTreeView
*list_view
;
1557 GtkTreeSelection
*selector
;
1558 GtkListStore
*store
= account_create_data_store();
1560 list_view
= GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store
)));
1561 g_object_unref(G_OBJECT(store
));
1563 g_object_set(list_view
, "allow-checkbox-mode", FALSE
, NULL
);
1565 gtk_tree_view_set_rules_hint(list_view
, prefs_common
.use_stripes_everywhere
);
1566 gtk_tree_view_set_reorderable(list_view
, TRUE
);
1568 selector
= gtk_tree_view_get_selection(list_view
);
1569 gtk_tree_selection_set_mode(selector
, GTK_SELECTION_BROWSE
);
1571 /* create the columns */
1572 account_create_list_view_columns(GTK_WIDGET(list_view
));
1574 /* set a double click listener */
1575 g_signal_connect(G_OBJECT(list_view
), "row_activated",
1576 G_CALLBACK(account_double_clicked
),
1579 g_signal_connect(G_OBJECT(list_view
), "drag_begin",
1580 G_CALLBACK(drag_begin
),
1583 g_signal_connect(G_OBJECT(list_view
), "drag_end",
1584 G_CALLBACK(drag_end
),
1587 gtk_tree_view_set_reorderable(list_view
, TRUE
);
1588 return GTK_WIDGET(list_view
);
1591 static void account_create_list_view_columns(GtkWidget
*list_view
)
1593 GtkTreeViewColumn
*column
;
1594 GtkCellRenderer
*renderer
;
1596 renderer
= gtk_cell_renderer_toggle_new();
1597 g_object_set(renderer
,
1599 "activatable", TRUE
,
1601 column
= gtk_tree_view_column_new_with_attributes
1602 (C_("Accounts List Get Column Name", "G"), renderer
,
1603 "active", ACCOUNT_ENABLE_GET_ALL
,
1605 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1606 gtk_tree_view_column_set_alignment (column
, 0.5);
1607 CLAWS_SET_TIP(gtk_tree_view_column_get_widget(column
),
1608 _("'Get Mail' retrieves mail from the checked accounts"));
1609 g_signal_connect(G_OBJECT(renderer
), "toggled",
1610 G_CALLBACK(account_get_all_toggled
),
1613 renderer
= gtk_cell_renderer_text_new();
1614 column
= gtk_tree_view_column_new_with_attributes
1615 (_("Name"), renderer
,
1616 "text", ACCOUNT_NAME
,
1617 "weight", ACCOUNT_IS_DEFAULT
,
1619 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1621 renderer
= gtk_cell_renderer_text_new();
1622 column
= gtk_tree_view_column_new_with_attributes
1623 (_("Protocol"), renderer
,
1624 "text", ACCOUNT_PROTOCOL
,
1625 "weight", ACCOUNT_IS_DEFAULT
,
1627 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1629 renderer
= gtk_cell_renderer_text_new();
1630 column
= gtk_tree_view_column_new_with_attributes
1631 (_("Server"), renderer
,
1632 "text", ACCOUNT_SERVER
,
1633 "weight", ACCOUNT_IS_DEFAULT
,
1635 gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view
), ACCOUNT_NAME
);
1636 gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(list_view
), account_search_func_cb
, NULL
, NULL
);
1637 gtk_tree_view_append_column(GTK_TREE_VIEW(list_view
), column
);
1641 *\brief Get currently selected account (by its unique ID)
1643 static gint
account_list_view_get_selected_account_id(GtkWidget
*list_view
)
1645 PrefsAccount
*res
= NULL
;
1647 res
= (PrefsAccount
*)gtkut_tree_view_get_selected_pointer(
1648 GTK_TREE_VIEW(list_view
), ACCOUNT_DATA
,
1651 return (res
!= NULL
? res
->account_id
: -1);
1655 *\brief Get the tree path of the currently selected account
1657 static GtkTreePath
*account_list_view_get_selected_account_path(GtkWidget
*list_view
)
1659 GtkTreeSelection
*selector
;
1660 GtkTreeModel
*model
;
1663 selector
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
1665 if (!gtk_tree_selection_get_selected(selector
, &model
, &iter
))
1668 return gtk_tree_model_get_path(gtk_tree_view_get_model
1669 (GTK_TREE_VIEW(list_view
)), &iter
);
1673 *\brief Get the account data of the currently selected account
1675 static PrefsAccount
*account_list_view_get_selected_account(GtkWidget
*list_view
)
1678 (PrefsAccount
*)gtkut_tree_view_get_selected_pointer(
1679 GTK_TREE_VIEW(list_view
), ACCOUNT_DATA
,
1686 *\brief Select a row by the account it represents
1688 *\return gboolean TRUE if found and selected, FALSE if not.
1690 static gboolean
account_list_view_select_account(GtkWidget
*list_view
, gint account_id
)
1692 FindAccountInStore fis
;
1693 GtkTreeModel
*model
;
1695 fis
.account_id
= account_id
;
1698 model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1700 gtk_tree_model_foreach(model
, (GtkTreeModelForeachFunc
) find_account_in_store
,
1704 GtkTreeSelection
*selection
;
1707 selection
= gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view
));
1708 gtk_tree_selection_select_iter(selection
, &fis
.iter
);
1709 path
= gtk_tree_model_get_path(model
, &fis
.iter
);
1710 /* XXX returned path may not be valid??? create new one to be sure */
1711 gtk_tree_view_set_cursor(GTK_TREE_VIEW(list_view
), path
, NULL
, FALSE
);
1712 gtk_tree_path_free(path
);
1715 return fis
.path
!= NULL
;
1719 *\brief Set a new default account by its ID. (There is only one
1722 static void account_list_view_set_default_by_id(GtkWidget
*list_view
,
1725 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1727 gtk_tree_model_foreach
1728 (model
, (GtkTreeModelForeachFunc
) set_new_default_account
,
1732 static gboolean
set_new_default_account(GtkTreeModel
*model
,
1737 PrefsAccount
*account
= NULL
;
1740 gtk_tree_model_get(model
, iter
,
1741 ACCOUNT_DATA
, &account
,
1744 if (*account_id
== account
->account_id
)
1745 weight
= PANGO_WEIGHT_NORMAL
;
1747 weight
= PANGO_WEIGHT_BOLD
;
1749 gtk_list_store_set(GTK_LIST_STORE(model
), iter
,
1750 ACCOUNT_IS_DEFAULT
, weight
, -1);
1755 static gboolean
find_account_in_store(GtkTreeModel
*model
,
1758 FindAccountInStore
*data
)
1760 PrefsAccount
*account
= NULL
;
1761 gtk_tree_model_get(model
, iter
, ACCOUNT_DATA
, &account
, -1);
1763 if (data
->account_id
== account
->account_id
) {
1764 data
->path
= path
; /* signal we found it */
1773 *\brief Triggered when "get all" column is activated or de-activated
1775 static void account_get_all_toggled(GtkCellRendererToggle
*widget
,
1777 GtkWidget
*list_view
)
1780 GtkTreeModel
*model
= gtk_tree_view_get_model(GTK_TREE_VIEW(list_view
));
1781 PrefsAccount
*ac
= NULL
;
1784 if (!gtk_tree_model_get_iter_from_string(model
, &iter
, path
))
1787 gtk_tree_model_get(model
, &iter
,
1789 ACCOUNT_ENABLE_GET_ALL
, &get_all
,
1792 /* check if the account has a selectable get all checkbox anyway... */
1793 if (!(ac
->protocol
== A_POP3
||
1794 ac
->protocol
== A_IMAP4
||
1795 ac
->protocol
== A_NNTP
||
1796 ac
->protocol
== A_LOCAL
))
1799 /* set value in store */
1800 gtk_list_store_set(GTK_LIST_STORE(model
), &iter
,
1801 ACCOUNT_ENABLE_GET_ALL
, !get_all
,
1804 /* set value in account */
1805 ac
->recv_at_getall
^= TRUE
;
1808 static void account_double_clicked(GtkTreeView
*list_view
,
1810 GtkTreeViewColumn
*column
,
1813 account_edit_prefs(NULL
, NULL
);
1816 static void drag_begin(GtkTreeView
*list_view
,
1817 GdkDragContext
*context
,
1820 /* XXX unfortunately a completed drag & drop does not emit
1821 * a "rows_reordered" signal, but a "row_changed" signal.
1822 * So during drag and drop, listen to "row_changed", and
1823 * update the account list accordingly */
1825 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1826 g_signal_connect(G_OBJECT(model
), "row_changed",
1827 G_CALLBACK(account_row_changed_while_drag_drop
),
1831 static void drag_end(GtkTreeView
*list_view
,
1832 GdkDragContext
*context
,
1835 GtkTreeModel
*model
= gtk_tree_view_get_model(list_view
);
1836 g_signal_handlers_disconnect_by_func(G_OBJECT(model
),
1837 G_CALLBACK(account_row_changed_while_drag_drop
),
1841 static void account_row_changed_while_drag_drop(GtkTreeModel
*model
,
1845 GtkTreeView
*list_view
)
1850 gchar
*account_get_signature_str(PrefsAccount
*account
)
1852 gchar
*sig_body
= NULL
;
1853 gchar
*sig_str
= NULL
;
1854 gchar
*utf8_sig_str
= NULL
;
1856 cm_return_val_if_fail(account
!= NULL
, NULL
);
1858 if (!account
->sig_path
)
1861 if (account
->sig_type
== SIG_FILE
) {
1862 gchar
*sig_full_path
;
1863 if (!g_path_is_absolute(account
->sig_path
)) {
1864 sig_full_path
= g_build_filename(get_home_dir(), account
->sig_path
, NULL
);
1866 sig_full_path
= g_strdup(account
->sig_path
);
1869 if (!is_file_or_fifo_exist(sig_full_path
)) {
1870 g_warning("can't open signature file: '%s'", sig_full_path
);
1871 g_free(sig_full_path
);
1875 debug_print("Reading signature from file '%s'\n", sig_full_path
);
1876 gchar
*tmp
= file_read_to_str(sig_full_path
);
1877 g_free(sig_full_path
);
1882 sig_body
= normalize_newlines(tmp
);
1885 sig_body
= get_command_output(account
->sig_path
);
1888 if (account
->sig_sep
) {
1889 sig_str
= g_strconcat("\n", account
->sig_sep
, "\n", sig_body
,
1893 sig_str
= g_strconcat("\n", sig_body
, NULL
);
1896 if (g_utf8_validate(sig_str
, -1, NULL
) == TRUE
)
1897 utf8_sig_str
= sig_str
;
1899 utf8_sig_str
= conv_codeset_strdup
1900 (sig_str
, conv_get_locale_charset_str_no_utf8(),
1906 return utf8_sig_str
;
1909 PrefsAccount
*account_get_cur_account (void)
1914 gboolean
password_get(const gchar
*user
,
1915 const gchar
*server
,
1916 const gchar
*protocol
,
1920 PasswordRequest req
;
1922 /* all have to be set */
1923 cm_return_val_if_fail(user
!= NULL
, FALSE
);
1924 cm_return_val_if_fail(server
!= NULL
, FALSE
);
1925 cm_return_val_if_fail(protocol
!= NULL
, FALSE
);
1926 cm_return_val_if_fail(port
!= 0, FALSE
);
1929 req
.server
= server
;
1930 req
.protocol
= protocol
;
1933 if (hooks_invoke(PASSWORD_GET_HOOKLIST
, &req
)) {
1934 *password
= req
.password
;
1940 static GSList
*account_sigsep_list
= NULL
;
1942 /* create a list of unique signatures from accounts list */
1943 void account_sigsep_matchlist_create(void)
1945 GList
*cur_ac
= NULL
;
1946 PrefsAccount
*ac_prefs
= NULL
;
1948 if (account_sigsep_list
)
1951 account_sigsep_list
= g_slist_prepend(account_sigsep_list
, g_strdup("-- "));
1952 for (cur_ac
= account_get_list();
1954 cur_ac
= g_list_next(cur_ac
)) {
1955 ac_prefs
= (PrefsAccount
*)cur_ac
->data
;
1957 if (ac_prefs
->sig_sep
&& *ac_prefs
->sig_sep
!= '\0') {
1958 if (!g_slist_find_custom(account_sigsep_list
, ac_prefs
->sig_sep
,
1959 (GCompareFunc
)g_strcmp0
)) {
1960 account_sigsep_list
= g_slist_prepend(account_sigsep_list
,
1961 g_strdup(ac_prefs
->sig_sep
));
1967 /* delete the list of signatures created by account_sigsep_matchlist_create() */
1968 void account_sigsep_matchlist_delete(void)
1970 if (account_sigsep_list
) {
1971 slist_free_strings_full(account_sigsep_list
);
1972 account_sigsep_list
= NULL
;
1976 /* match a string against all signatures in list, using the specified format */
1977 gboolean
account_sigsep_matchlist_str_found(const gchar
*str
, const gchar
*format
)
1980 gboolean found
= FALSE
;
1983 for (item
= account_sigsep_list
;
1984 item
!= NULL
&& !found
;
1985 item
= g_slist_next(item
)) {
1986 tmp
= g_strdup_printf(format
, (gchar
*)item
->data
);
1988 found
= (strcmp(tmp
, str
) == 0);
1991 g_warning("account_sigsep_matchlist_str_found: g_strdup_printf failed, check format '%s'",
1999 /* match M first char of a string against all signatures in list, using the specified format */
2000 gboolean
account_sigsep_matchlist_nchar_found(const gchar
*str
, const gchar
*format
)
2003 gboolean found
= FALSE
;
2007 for (item
= account_sigsep_list
;
2008 item
!= NULL
&& !found
;
2009 item
= g_slist_next(item
)) {
2010 tmp
= g_strdup_printf(format
, (gchar
*)item
->data
);
2013 found
= (strncmp(tmp
, str
, len
) == 0);
2016 g_warning("account_sigsep_matchlist_nchar_found: g_strdup_printf failed, check format '%s'",