2 * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3 * Copyright (C) 1999-2002 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 2 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, write to the Free Software
17 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
28 #include <gdk/gdkkeysyms.h>
34 #include "mainwindow.h"
35 #include "folderview.h"
38 #include "prefs_gtk.h"
39 #include "prefs_account.h"
40 #include "folder_item_prefs.h"
42 #include "manage_window.h"
43 #include "stock_pixmap.h"
47 #include "alertpanel.h"
48 #include "procheader.h"
57 } EditAccountColumnPos;
59 # define N_EDIT_ACCOUNT_COLS 5
61 #define PREFSBUFSIZE 1024
63 PrefsAccount *cur_account;
65 static GList *account_list = NULL;
67 static struct EditAccount {
73 static GdkPixmap *markxpm;
74 static GdkBitmap *markxpmmask;
75 static GdkPixmap *checkboxonxpm;
76 static GdkPixmap *checkboxonxpmmask;
77 static GdkPixmap *checkboxoffxpm;
78 static GdkPixmap *checkboxoffxpmmask;
80 static void account_edit_create (void);
82 static void account_edit_prefs (void);
83 static void account_delete (void);
85 static void account_up (void);
86 static void account_down (void);
88 static void account_set_default (void);
90 static void account_edit_close (void);
91 static gint account_delete_event (GtkWidget *widget,
94 static void account_selected (GtkCList *clist,
99 static void account_row_moved (GtkCList *clist,
102 static void account_key_pressed (GtkWidget *widget,
106 static gint account_clist_set_row (PrefsAccount *ac_prefs,
108 static void account_clist_set (void);
110 static void account_list_set (void);
112 void account_read_config_all(void)
114 GSList *ac_label_list = NULL, *cur;
117 gchar buf[PREFSBUFSIZE];
118 PrefsAccount *ac_prefs;
120 debug_print("Reading all config for each account...\n");
122 rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
123 if ((fp = fopen(rcpath, "rb")) == NULL) {
124 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
130 while (fgets(buf, sizeof(buf), fp) != NULL) {
131 if (!strncmp(buf, "[Account: ", 10)) {
133 memmove(buf, buf + 1, strlen(buf));
134 buf[strlen(buf) - 1] = '\0';
135 debug_print("Found label: %s\n", buf);
136 ac_label_list = g_slist_append(ac_label_list,
142 /* read config data from file */
144 for (cur = ac_label_list; cur != NULL; cur = cur->next) {
145 ac_prefs = prefs_account_new();
146 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
147 account_list = g_list_append(account_list, ac_prefs);
148 if (ac_prefs->is_default)
149 cur_account = ac_prefs;
151 /* if default is not set, assume first account as default */
152 if (!cur_account && account_list) {
153 ac_prefs = (PrefsAccount *)account_list->data;
154 account_set_as_default(ac_prefs);
155 cur_account = ac_prefs;
159 main_window_reflect_prefs_all();
161 while (ac_label_list) {
162 g_free(ac_label_list->data);
163 ac_label_list = g_slist_remove(ac_label_list,
164 ac_label_list->data);
168 void account_save_config_all(void)
170 prefs_account_save_config_all(account_list);
174 * account_find_all_from_address:
175 * @ac_list: initial list of accounts. NULL to create a new one.
176 * Accounts found in the @address will be appended to this list.
177 * @address: Email address string.
179 * Find all the mail (not news) accounts within the specified address.
181 * Return value: the original accounts list with the found accounts appended.
183 GList *account_find_all_from_address(GList *ac_list, const gchar *address)
191 for (cur = account_list; cur != NULL; cur = cur->next) {
192 ac = (PrefsAccount *)cur->data;
193 if (ac->protocol != A_NNTP && ac->address &&
194 strcasestr(address, ac->address) != NULL)
195 ac_list = g_list_append(ac_list, ac);
200 PrefsAccount *account_find_from_smtp_server(const gchar *address,
201 const gchar *smtp_server)
206 g_return_val_if_fail(address != NULL, NULL);
207 g_return_val_if_fail(smtp_server != NULL, NULL);
209 for (cur = account_list; cur != NULL; cur = cur->next) {
210 ac = (PrefsAccount *)cur->data;
211 if (!strcmp2(address, ac->address) &&
212 !strcmp2(smtp_server, ac->smtp_server))
220 * account_find_from_address:
221 * @address: Email address string.
223 * Find a mail (not news) account with the specified email address.
225 * Return value: The found account, or NULL if not found.
227 PrefsAccount *account_find_from_address(const gchar *address)
232 g_return_val_if_fail(address != NULL, NULL);
234 for (cur = account_list; cur != NULL; cur = cur->next) {
235 ac = (PrefsAccount *)cur->data;
236 if (ac->protocol != A_NNTP && ac->address &&
237 g_strcasecmp(address, ac->address) == 0)
244 PrefsAccount *account_find_from_id(gint id)
249 for (cur = account_list; cur != NULL; cur = cur->next) {
250 ac = (PrefsAccount *)cur->data;
251 if (id == ac->account_id)
258 PrefsAccount *account_find_from_item(FolderItem *item)
262 g_return_val_if_fail(item != NULL, NULL);
266 FolderItem *cur_item = item->parent;
267 while (cur_item != NULL) {
268 if (cur_item->account && cur_item->apply_sub) {
269 ac = cur_item->account;
272 cur_item = cur_item->parent;
276 ac = item->folder->account;
281 void account_set_menu(void)
283 main_window_set_account_menu(account_list);
286 void account_foreach(AccountFunc func, gpointer user_data)
290 for (cur = account_list; cur != NULL; cur = cur->next)
291 if (func((PrefsAccount *)cur->data, user_data) != 0)
295 GList *account_get_list(void)
300 void account_edit_open(void)
304 if (compose_get_compose_list()) {
305 alertpanel_notice(_("Some composing windows are open.\n"
306 "Please close all the composing windows before editing the accounts."));
311 debug_print("Opening account edit window...\n");
313 if (!edit_account.window)
314 account_edit_create();
318 manage_window_set_transient(GTK_WINDOW(edit_account.window));
319 gtk_widget_grab_focus(edit_account.close_btn);
320 gtk_widget_show(edit_account.window);
322 manage_window_focus_in(edit_account.window, NULL, NULL);
325 void account_add(void)
327 PrefsAccount *ac_prefs;
329 ac_prefs = prefs_account_open(NULL);
331 if (!ac_prefs) return;
333 account_list = g_list_append(account_list, ac_prefs);
335 if (ac_prefs->is_default)
336 account_set_as_default(ac_prefs);
340 if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
343 if (ac_prefs->protocol == A_IMAP4) {
344 folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
345 ac_prefs->recv_server);
347 folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
348 ac_prefs->nntp_server);
351 folder->account = ac_prefs;
352 ac_prefs->folder = REMOTE_FOLDER(folder);
354 if (ac_prefs->protocol == A_IMAP4)
355 folder->klass->create_tree(folder);
356 folderview_set_all();
360 void account_open(PrefsAccount *ac_prefs)
362 gboolean prev_default;
365 g_return_if_fail(ac_prefs != NULL);
367 prev_default = ac_prefs->is_default;
368 Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
371 prefs_account_open(ac_prefs);
373 if (!prev_default && ac_prefs->is_default)
374 account_set_as_default(ac_prefs);
376 if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
377 folder_set_name(FOLDER(ac_prefs->folder),
378 ac_prefs->account_name);
379 folderview_set_all();
382 account_save_config_all();
384 main_window_reflect_prefs_all();
387 void account_set_as_default(PrefsAccount *ac_prefs)
392 for (cur = account_list; cur != NULL; cur = cur->next) {
393 ap = (PrefsAccount *)cur->data;
395 ap->is_default = FALSE;
398 ac_prefs->is_default = TRUE;
401 PrefsAccount *account_get_default(void)
406 for (cur = account_list; cur != NULL; cur = cur->next) {
407 ap = (PrefsAccount *)cur->data;
415 void account_set_missing_folder(void)
420 for (cur = account_list; cur != NULL; cur = cur->next) {
421 ap = (PrefsAccount *)cur->data;
422 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
426 if (ap->protocol == A_IMAP4) {
427 folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
430 folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
434 folder->account = ap;
435 ap->folder = REMOTE_FOLDER(folder);
437 if (ap->protocol == A_IMAP4)
438 folder->klass->create_tree(folder);
443 FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
444 SpecialFolderItemType type)
446 FolderItem *item = NULL;
448 g_return_val_if_fail(ac_prefs != NULL, NULL);
452 if (ac_prefs->folder)
453 item = FOLDER(ac_prefs->folder)->inbox;
455 item = folder_get_default_inbox();
458 if (ac_prefs->set_sent_folder && ac_prefs->sent_folder) {
459 item = folder_find_item_from_identifier
460 (ac_prefs->sent_folder);
463 if (ac_prefs->folder)
464 item = FOLDER(ac_prefs->folder)->outbox;
466 item = folder_get_default_outbox();
470 if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
471 item = folder_find_item_from_identifier
472 (ac_prefs->draft_folder);
475 if (ac_prefs->folder)
476 item = FOLDER(ac_prefs->folder)->draft;
478 item = folder_get_default_draft();
482 if (ac_prefs->folder)
483 item = FOLDER(ac_prefs->folder)->queue;
485 item = folder_get_default_queue();
488 if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
489 item = folder_find_item_from_identifier
490 (ac_prefs->trash_folder);
493 if (ac_prefs->folder)
494 item = FOLDER(ac_prefs->folder)->trash;
496 item = folder_get_default_trash();
506 void account_destroy(PrefsAccount *ac_prefs)
508 g_return_if_fail(ac_prefs != NULL);
510 folder_unref_account_all(ac_prefs);
512 prefs_account_free(ac_prefs);
513 account_list = g_list_remove(account_list, ac_prefs);
515 if (cur_account == ac_prefs) cur_account = NULL;
516 if (!cur_account && account_list) {
517 cur_account = account_get_default();
519 ac_prefs = (PrefsAccount *)account_list->data;
520 account_set_as_default(ac_prefs);
521 cur_account = ac_prefs;
527 static void account_edit_create(void)
533 GtkWidget *scrolledwin;
535 gchar *titles[N_EDIT_ACCOUNT_COLS];
545 GtkWidget *default_btn;
548 GtkWidget *close_btn;
550 debug_print("Creating account edit window...\n");
552 window = gtk_window_new (GTK_WINDOW_DIALOG);
553 gtk_widget_set_usize (window, 500, 320);
554 gtk_container_set_border_width (GTK_CONTAINER (window), 8);
555 gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
556 gtk_window_set_modal (GTK_WINDOW (window), TRUE);
557 gtk_signal_connect (GTK_OBJECT (window), "delete_event",
558 GTK_SIGNAL_FUNC (account_delete_event), NULL);
559 gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
560 GTK_SIGNAL_FUNC (account_key_pressed), NULL);
561 MANAGE_WINDOW_SIGNALS_CONNECT (window);
562 gtk_widget_realize(window);
564 vbox = gtk_vbox_new (FALSE, 10);
565 gtk_widget_show (vbox);
566 gtk_container_add (GTK_CONTAINER (window), vbox);
568 hbox = gtk_hbox_new (FALSE, 0);
569 gtk_widget_show (hbox);
570 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
572 label = gtk_label_new
573 (_("New messages will be checked in this order. Check the boxes\n"
574 "on the `G' column to enable message retrieval by `Get all'."));
575 gtk_widget_show (label);
576 gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
577 gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
579 hbox = gtk_hbox_new (FALSE, 8);
580 gtk_widget_show (hbox);
581 gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
582 gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
584 scrolledwin = gtk_scrolled_window_new (NULL, NULL);
585 gtk_widget_show (scrolledwin);
586 gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
587 gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
588 GTK_POLICY_AUTOMATIC,
589 GTK_POLICY_AUTOMATIC);
591 titles[COL_DEFAULT] = "D";
592 titles[COL_GETALL] = "G";
593 titles[COL_NAME] = _("Name");
594 titles[COL_PROTOCOL] = _("Protocol");
595 titles[COL_SERVER] = _("Server");
597 clist = gtk_clist_new_with_titles (N_EDIT_ACCOUNT_COLS, titles);
598 gtk_widget_show (clist);
599 gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
600 gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 10);
601 gtk_clist_set_column_width (GTK_CLIST(clist), COL_GETALL , 11);
602 gtk_clist_set_column_width (GTK_CLIST(clist), COL_NAME , 100);
603 gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 100);
604 gtk_clist_set_column_width (GTK_CLIST(clist), COL_SERVER , 100);
605 gtk_clist_set_column_justification (GTK_CLIST(clist), COL_DEFAULT,
607 gtk_clist_set_column_justification (GTK_CLIST(clist), COL_GETALL,
609 gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
611 for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
612 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
615 gtk_signal_connect (GTK_OBJECT (clist), "select_row",
616 GTK_SIGNAL_FUNC (account_selected), NULL);
617 gtk_signal_connect_after (GTK_OBJECT (clist), "row_move",
618 GTK_SIGNAL_FUNC (account_row_moved), NULL);
620 vbox2 = gtk_vbox_new (FALSE, 0);
621 gtk_widget_show (vbox2);
622 gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
624 add_btn = gtk_button_new_with_label (_("Add"));
625 gtk_widget_show (add_btn);
626 gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
627 gtk_signal_connect (GTK_OBJECT(add_btn), "clicked",
628 GTK_SIGNAL_FUNC (account_add), NULL);
630 edit_btn = gtk_button_new_with_label (_("Edit"));
631 gtk_widget_show (edit_btn);
632 gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
633 gtk_signal_connect (GTK_OBJECT(edit_btn), "clicked",
634 GTK_SIGNAL_FUNC (account_edit_prefs), NULL);
636 del_btn = gtk_button_new_with_label (_(" Delete "));
637 gtk_widget_show (del_btn);
638 gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
639 gtk_signal_connect (GTK_OBJECT(del_btn), "clicked",
640 GTK_SIGNAL_FUNC (account_delete), NULL);
642 down_btn = gtk_button_new_with_label (_("Down"));
643 gtk_widget_show (down_btn);
644 gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
645 gtk_signal_connect (GTK_OBJECT(down_btn), "clicked",
646 GTK_SIGNAL_FUNC (account_down), NULL);
648 up_btn = gtk_button_new_with_label (_("Up"));
649 gtk_widget_show (up_btn);
650 gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
651 gtk_signal_connect (GTK_OBJECT(up_btn), "clicked",
652 GTK_SIGNAL_FUNC (account_up), NULL);
654 hbox = gtk_hbox_new (FALSE, 8);
655 gtk_widget_show (hbox);
656 gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
658 vbox2 = gtk_vbox_new(FALSE, 0);
659 gtk_widget_show (vbox2);
660 gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
662 default_btn = gtk_button_new_with_label (_(" Set as default account "));
663 gtk_widget_show (default_btn);
664 gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
665 gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
666 GTK_SIGNAL_FUNC (account_set_default), NULL);
668 gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
669 NULL, NULL, NULL, NULL);
670 gtk_widget_show(hbbox);
671 gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
672 gtk_widget_grab_default (close_btn);
674 gtk_signal_connect (GTK_OBJECT (close_btn), "clicked",
675 GTK_SIGNAL_FUNC (account_edit_close),
678 stock_pixmap_gdk(clist, STOCK_PIXMAP_MARK, &markxpm, &markxpmmask);
679 stock_pixmap_gdk(clist, STOCK_PIXMAP_CHECKBOX_ON,
680 &checkboxonxpm, &checkboxonxpmmask);
681 stock_pixmap_gdk(clist, STOCK_PIXMAP_CHECKBOX_OFF,
682 &checkboxoffxpm, &checkboxoffxpmmask);
684 edit_account.window = window;
685 edit_account.clist = clist;
686 edit_account.close_btn = close_btn;
689 static void account_edit_prefs(void)
691 GtkCList *clist = GTK_CLIST(edit_account.clist);
692 PrefsAccount *ac_prefs;
695 if (!clist->selection) return;
697 row = GPOINTER_TO_INT(clist->selection->data);
698 ac_prefs = gtk_clist_get_row_data(clist, row);
699 account_open(ac_prefs);
704 static gboolean account_delete_references_func(GNode *node, gpointer data)
709 g_return_val_if_fail(node->data != NULL, FALSE);
711 item = FOLDER_ITEM(node->data);
712 account = GPOINTER_TO_INT(data);
714 if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
716 if(item->prefs->default_account != account)
719 item->prefs->enable_default_account = FALSE;
720 item->prefs->default_account = 0;
721 folder_item_prefs_save_config(item);
726 static void account_delete(void)
728 GtkCList *clist = GTK_CLIST(edit_account.clist);
729 PrefsAccount *ac_prefs;
734 if (!clist->selection) return;
736 if (alertpanel(_("Delete account"),
737 _("Do you really want to delete this account?"),
738 _("Yes"), _("+No"), NULL) != G_ALERTDEFAULT)
741 row = GPOINTER_TO_INT(clist->selection->data);
742 ac_prefs = gtk_clist_get_row_data(clist, row);
743 if (ac_prefs->folder) {
744 folder_destroy(FOLDER(ac_prefs->folder));
745 folderview_set_all();
747 account_destroy(ac_prefs);
750 debug_print("Removing deleted account references for all the folders...\n");
751 list = folder_get_list();
752 for (; list != NULL; list = list->next) {
753 folder = FOLDER(list->data);
754 if (folder->node) /* && folder->type == F_? */
755 g_node_traverse(folder->node, G_PRE_ORDER,
757 account_delete_references_func,
758 GINT_TO_POINTER(ac_prefs->account_id));
762 static void account_up(void)
764 GtkCList *clist = GTK_CLIST(edit_account.clist);
767 if (!clist->selection) return;
769 row = GPOINTER_TO_INT(clist->selection->data);
771 gtk_clist_row_move(clist, row, row - 1);
774 static void account_down(void)
776 GtkCList *clist = GTK_CLIST(edit_account.clist);
779 if (!clist->selection) return;
781 row = GPOINTER_TO_INT(clist->selection->data);
782 if (row < clist->rows - 1)
783 gtk_clist_row_move(clist, row, row + 1);
786 static void account_set_default(void)
788 GtkCList *clist = GTK_CLIST(edit_account.clist);
790 PrefsAccount *ac_prefs;
792 if (!clist->selection) return;
794 row = GPOINTER_TO_INT(clist->selection->data);
795 ac_prefs = gtk_clist_get_row_data(clist, row);
796 account_set_as_default(ac_prefs);
799 cur_account = ac_prefs;
801 main_window_reflect_prefs_all();
804 static void account_edit_close(void)
807 account_save_config_all();
809 if (!cur_account && account_list) {
810 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
811 account_set_as_default(ac_prefs);
812 cur_account = ac_prefs;
816 main_window_reflect_prefs_all();
818 gtk_widget_hide(edit_account.window);
823 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
826 account_edit_close();
830 static void account_selected(GtkCList *clist, gint row, gint column,
831 GdkEvent *event, gpointer data)
833 if (event && event->type == GDK_2BUTTON_PRESS)
834 account_edit_prefs();
836 if (column == COL_GETALL) {
839 ac = gtk_clist_get_row_data(clist, row);
840 if (ac->protocol == A_POP3 || ac->protocol == A_APOP ||
841 ac->protocol == A_IMAP4 || ac->protocol == A_NNTP ||
842 ac->protocol == A_LOCAL) {
843 ac->recv_at_getall ^= TRUE;
844 account_clist_set_row(ac, row);
849 static void account_row_moved(GtkCList *clist, gint source_row, gint dest_row)
852 if (gtk_clist_row_is_visible(clist, dest_row) != GTK_VISIBILITY_FULL)
853 gtk_clist_moveto(clist, dest_row, -1, 0.5, 0.0);
856 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
859 if (event && event->keyval == GDK_Escape)
860 account_edit_close();
863 /* set one CList row or add new row */
864 static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
866 GtkCList *clist = GTK_CLIST(edit_account.clist);
867 gchar *text[N_EDIT_ACCOUNT_COLS];
868 gboolean has_getallbox;
871 text[COL_DEFAULT] = "";
872 text[COL_GETALL] = "";
873 text[COL_NAME] = ac_prefs->account_name;
875 text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3 ?
876 (ac_prefs->ssl_pop == SSL_TUNNEL ?
878 ac_prefs->ssl_pop == SSL_STARTTLS ?
879 "POP3 (TLS)" : "POP3") :
880 ac_prefs->protocol == A_APOP ?
881 (ac_prefs->ssl_pop == SSL_TUNNEL ?
883 ac_prefs->ssl_pop == SSL_STARTTLS ?
884 "POP3 (APOP, TLS)" : "POP3 (APOP)") :
885 ac_prefs->protocol == A_IMAP4 ?
886 (ac_prefs->ssl_imap == SSL_TUNNEL ?
888 ac_prefs->ssl_imap == SSL_STARTTLS ?
889 "IMAP4 (TLS)" : "IMAP4") :
890 ac_prefs->protocol == A_NNTP ?
891 (ac_prefs->ssl_nntp == SSL_TUNNEL ?
892 "NNTP (SSL)" : "NNTP") :
895 text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3 ? "POP3" :
896 ac_prefs->protocol == A_APOP ? "POP3 (APOP)" :
897 ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
898 ac_prefs->protocol == A_LOCAL ? "Local" :
899 ac_prefs->protocol == A_NNTP ? "NNTP" : "";
901 text[COL_SERVER] = ac_prefs->protocol == A_NNTP
902 ? ac_prefs->nntp_server : ac_prefs->recv_server;
905 row = gtk_clist_append(clist, text);
907 gtk_clist_set_text(clist, row, COL_DEFAULT, text[COL_DEFAULT]);
908 gtk_clist_set_text(clist, row, COL_GETALL, text[COL_GETALL]);
909 gtk_clist_set_text(clist, row, COL_NAME, text[COL_NAME]);
910 gtk_clist_set_text(clist, row, COL_PROTOCOL, text[COL_PROTOCOL]);
911 gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
914 has_getallbox = (ac_prefs->protocol == A_POP3 ||
915 ac_prefs->protocol == A_APOP ||
916 ac_prefs->protocol == A_IMAP4 ||
917 ac_prefs->protocol == A_NNTP ||
918 ac_prefs->protocol == A_LOCAL);
919 getall = has_getallbox && ac_prefs->recv_at_getall;
921 if (ac_prefs->is_default)
922 gtk_clist_set_pixmap(clist, row, COL_DEFAULT,
923 markxpm, markxpmmask);
925 gtk_clist_set_pixmap(clist, row, COL_GETALL,
926 checkboxonxpm, checkboxonxpmmask);
927 else if (has_getallbox)
928 gtk_clist_set_pixmap(clist, row, COL_GETALL,
929 checkboxoffxpm, checkboxoffxpmmask);
931 gtk_clist_set_row_data(clist, row, ac_prefs);
936 /* set CList from account list */
937 static void account_clist_set(void)
939 GtkCList *clist = GTK_CLIST(edit_account.clist);
941 gint row = -1, prev_row = -1;
943 if (clist->selection)
944 prev_row = GPOINTER_TO_INT(clist->selection->data);
946 gtk_clist_freeze(clist);
947 gtk_clist_clear(clist);
949 for (cur = account_list; cur != NULL; cur = cur->next) {
950 row = account_clist_set_row((PrefsAccount *)cur->data, -1);
951 if ((PrefsAccount *)cur->data == cur_account) {
952 gtk_clist_select_row(clist, row, -1);
953 gtkut_clist_set_focus_row(clist, row);
959 gtk_clist_select_row(clist, row, -1);
960 gtkut_clist_set_focus_row(clist, row);
964 gtk_clist_row_is_visible(clist, row) != GTK_VISIBILITY_FULL)
965 gtk_clist_moveto(clist, row, -1, 0.5, 0);
967 gtk_clist_thaw(clist);
970 /* set account list from CList */
971 static void account_list_set(void)
973 GtkCList *clist = GTK_CLIST(edit_account.clist);
975 PrefsAccount *ac_prefs;
978 account_list = g_list_remove(account_list, account_list->data);
980 for (row = 0; (ac_prefs = gtk_clist_get_row_data(clist, row)) != NULL;
982 account_list = g_list_append(account_list, ac_prefs);
986 *\brief finds the PrefsAccounts which should be used to answer a mail
988 *\param msginfo The message to be answered
989 *\param reply_autosel Indicates whether reply account autoselection is on
991 *\return PrefsAccount * the correct account, NULL if not found
993 PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel)
995 PrefsAccount *account = NULL;
996 /* select the account set in folderitem's property (if enabled) */
997 if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
998 account = account_find_from_id(msginfo->folder->prefs->default_account);
1000 /* select the account for the whole folder (IMAP / NNTP) */
1002 /* FIXME: this is not right, because folder may be nested. we should
1003 * ascend the tree until we find a parent with proper account
1005 account = msginfo->folder->folder->account;
1007 /* select account by to: and cc: header if enabled */
1008 if (reply_autosel) {
1009 if (!account && msginfo->to) {
1011 Xstrdup_a(to, msginfo->to, return NULL);
1012 extract_address(to);
1013 account = account_find_from_address(to);
1017 if (!procheader_get_header_from_msginfo(msginfo, cc, sizeof(cc), "CC:")) { /* Found a CC header */
1018 extract_address(cc);
1019 account = account_find_from_address(cc);
1024 /* select current account */
1025 if (!account) account = cur_account;