sync with sylpheed 0.4.99cvs8
[claws.git] / src / account.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2001 Hiroyuki Yamamoto
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License as published by
7  * the Free Software Foundation; either version 2 of the License, or
8  * (at your option) any later version.
9  *
10  * This program is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13  * GNU General Public License for more details.
14  *
15  * You should have received a copy of the GNU General Public License
16  * along with this program; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #endif
23
24 #include "defs.h"
25
26 #include <glib.h>
27 #include <gtk/gtk.h>
28 #include <gdk/gdkkeysyms.h>
29 #include <stdio.h>
30 #include <errno.h>
31
32 #include "intl.h"
33 #include "main.h"
34 #include "mainwindow.h"
35 #include "folderview.h"
36 #include "folder.h"
37 #include "account.h"
38 #include "prefs.h"
39 #include "prefs_account.h"
40 #include "compose.h"
41 #include "manage_window.h"
42 #include "inc.h"
43 #include "gtkutils.h"
44 #include "utils.h"
45 #include "alertpanel.h"
46
47 typedef enum
48 {
49         COL_DEFAULT     = 0,
50         COL_NAME        = 1,
51         COL_PROTOCOL    = 2,
52         COL_SERVER      = 3
53 } EditAccountColumnPos;
54
55 # define N_EDIT_ACCOUNT_COLS    4
56
57 #define PREFSBUFSIZE            1024
58
59 PrefsAccount *cur_account;
60
61 static GList *account_list = NULL;
62
63 static struct EditAccount {
64         GtkWidget *window;
65         GtkWidget *clist;
66         GtkWidget *close_btn;
67 } edit_account;
68
69 static void account_edit_create         (void);
70
71 static void account_edit_prefs          (void);
72 static void account_delete              (void);
73
74 static void account_up                  (void);
75 static void account_down                (void);
76
77 static void account_set_default         (void);
78
79 static void account_edit_close          (void);
80 static gint account_delete_event        (GtkWidget      *widget,
81                                          GdkEventAny    *event,
82                                          gpointer        data);
83 static void account_key_pressed         (GtkWidget      *widget,
84                                          GdkEventKey    *event,
85                                          gpointer        data);
86
87 static gint account_clist_set_row       (PrefsAccount   *ac_prefs,
88                                          gint            row);
89 static void account_clist_set           (void);
90
91 static void account_list_set            (void);
92
93 void account_read_config_all(void)
94 {
95         GSList *ac_label_list = NULL, *cur;
96         gchar *rcpath;
97         FILE *fp;
98         gchar buf[PREFSBUFSIZE];
99         PrefsAccount *ac_prefs;
100
101         debug_print(_("Reading all config for each account...\n"));
102
103         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
104         if ((fp = fopen(rcpath, "r")) == NULL) {
105                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
106                 g_free(rcpath);
107                 return;
108         }
109         g_free(rcpath);
110
111         while (fgets(buf, sizeof(buf), fp) != NULL) {
112                 if (!strncmp(buf, "[Account: ", 10)) {
113                         strretchomp(buf);
114                         memmove(buf, buf + 1, strlen(buf));
115                         buf[strlen(buf) - 1] = '\0';
116                         debug_print(_("Found label: %s\n"), buf);
117                         ac_label_list = g_slist_append(ac_label_list,
118                                                        g_strdup(buf));
119                 }
120         }
121         fclose(fp);
122
123         /* read config data from file */
124         cur_account = NULL;
125         for (cur = ac_label_list; cur != NULL; cur = cur->next) {
126                 ac_prefs = g_new0(PrefsAccount, 1);
127                 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
128                 account_list = g_list_append(account_list, ac_prefs);
129                 if (ac_prefs->is_default)
130                         cur_account = ac_prefs;
131         }
132         /* if default is not set, assume first account as default */
133         if (!cur_account && account_list) {
134                 ac_prefs = (PrefsAccount *)account_list->data;
135                 account_set_as_default(ac_prefs);
136                 cur_account = ac_prefs;
137         }
138
139         account_set_menu();
140         main_window_reflect_prefs_all();
141
142         while (ac_label_list) {
143                 g_free(ac_label_list->data);
144                 ac_label_list = g_slist_remove(ac_label_list,
145                                                ac_label_list->data);
146         }
147 }
148
149 void account_save_config_all(void)
150 {
151         prefs_account_save_config_all(account_list);
152 }
153
154 PrefsAccount *account_find_from_smtp_server(const gchar *address,
155                                             const gchar *smtp_server)
156 {
157         GList *cur;
158         PrefsAccount *ac;
159
160         for (cur = account_list; cur != NULL; cur = cur->next) {
161                 ac = (PrefsAccount *)cur->data;
162                 if (!strcmp2(address, ac->address) &&
163                     !strcmp2(smtp_server, ac->smtp_server))
164                         return ac;
165         }
166
167         return NULL;
168 }
169
170 /**
171  * account_find_mail_from_address:
172  * @address: Email address string.
173  * 
174  * Find a mail (not news) account with the specified email address.
175  * 
176  * Return value: The found account, or NULL if not found.
177  **/
178 PrefsAccount *account_find_mail_from_address(const gchar *address)
179 {
180         GList *cur;
181         PrefsAccount *ac;
182
183         for (cur = account_list; cur != NULL; cur = cur->next) {
184                 ac = (PrefsAccount *)cur->data;
185                 if (ac->protocol != A_NNTP &&
186                     !strcmp2(address, ac->address))
187                         return ac;
188         }
189
190         return NULL;
191 }
192
193 PrefsAccount *account_find_from_id(gint id)
194 {
195         GList *cur;
196         PrefsAccount *ac;
197
198         for (cur = account_list; cur != NULL; cur = cur->next) {
199                 ac = (PrefsAccount *)cur->data;
200                 if (id == ac->account_id)
201                         return ac;
202         }
203
204         return NULL;
205 }
206
207 void account_set_menu(void)
208 {
209         main_window_set_account_menu(account_list);
210 }
211
212 void account_foreach(AccountFunc func, gpointer user_data)
213 {
214         GList *cur;
215
216         for (cur = account_list; cur != NULL; cur = cur->next)
217                 if (func((PrefsAccount *)cur->data, user_data) != 0)
218                         return;
219 }
220
221 GList *account_get_list(void)
222 {
223         return account_list;
224 }
225
226 void account_edit_open(void)
227 {
228         inc_autocheck_timer_remove();
229
230         if (compose_get_compose_list()) {
231                 alertpanel_notice(_("Some composing windows are open.\n"
232                                     "Please close all the composing windows before editing the accounts."));
233                 inc_autocheck_timer_set();
234                 return;
235         }
236
237         debug_print(_("Opening account edit window...\n"));
238
239         if (!edit_account.window)
240                 account_edit_create();
241
242         account_clist_set();
243
244         manage_window_set_transient(GTK_WINDOW(edit_account.window));
245         gtk_widget_grab_focus(edit_account.close_btn);
246         gtk_widget_show(edit_account.window);
247
248         manage_window_focus_in(edit_account.window, NULL, NULL);
249 }
250
251 void account_add(void)
252 {
253         PrefsAccount *ac_prefs;
254
255         ac_prefs = prefs_account_open(NULL);
256         inc_autocheck_timer_remove();
257
258         if (!ac_prefs) return;
259
260         account_list = g_list_append(account_list, ac_prefs);
261
262         if (ac_prefs->is_default)
263                 account_set_as_default(ac_prefs);
264
265         account_clist_set();
266
267         if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
268                 Folder *folder;
269
270                 if (ac_prefs->protocol == A_IMAP4) {
271                         folder = folder_new(F_IMAP, ac_prefs->account_name,
272                                             ac_prefs->recv_server);
273                         folder_item_append(FOLDER_ITEM(folder->node->data),
274                                            folder_item_new("INBOX", "INBOX"));
275                 } else {
276                         folder = folder_new(F_NEWS, ac_prefs->account_name,
277                                             ac_prefs->nntp_server);
278                 }
279
280                 folder->account = ac_prefs;
281                 ac_prefs->folder = REMOTE_FOLDER(folder);
282                 folder_add(folder);
283                 folderview_update_all();
284         }
285 }
286
287 void account_set_as_default(PrefsAccount *ac_prefs)
288 {
289         PrefsAccount *ap;
290         GList *cur;
291
292         for (cur = account_list; cur != NULL; cur = cur->next) {
293                 ap = (PrefsAccount *)cur->data;
294                 if (ap->is_default)
295                         ap->is_default = FALSE;
296         }
297
298         ac_prefs->is_default = TRUE;
299 }
300
301 PrefsAccount *account_get_default(void)
302 {
303         PrefsAccount *ap;
304         GList *cur;
305
306         for (cur = account_list; cur != NULL; cur = cur->next) {
307                 ap = (PrefsAccount *)cur->data;
308                 if (ap->is_default)
309                         return ap;
310         }
311
312         return NULL;
313 }
314
315 void account_set_missing_folder(void)
316 {
317         PrefsAccount *ap;
318         GList *cur;
319
320         for (cur = account_list; cur != NULL; cur = cur->next) {
321                 ap = (PrefsAccount *)cur->data;
322                 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
323                     !ap->folder) {
324                         Folder *folder;
325
326                         if (ap->protocol == A_IMAP4) {
327                                 folder = folder_new(F_IMAP, ap->account_name,
328                                                     ap->recv_server);
329                                 folder_item_append
330                                         (FOLDER_ITEM(folder->node->data),
331                                          folder_item_new("INBOX", "INBOX"));
332                         } else {
333                                 folder = folder_new(F_NEWS, ap->account_name,
334                                                     ap->nntp_server);
335                         }
336                         folder->account = ap;
337                         ap->folder = REMOTE_FOLDER(folder);
338                         folder_add(folder);
339                 }
340         }
341 }
342
343 void account_destroy(PrefsAccount *ac_prefs)
344 {
345         g_return_if_fail(ac_prefs != NULL);
346
347         prefs_account_free(ac_prefs);
348         account_list = g_list_remove(account_list, ac_prefs);
349
350         if (cur_account == ac_prefs) cur_account = NULL;
351         if (!cur_account && account_list) {
352                 cur_account = account_get_default();
353                 if (!cur_account) {
354                         ac_prefs = (PrefsAccount *)account_list->data;
355                         account_set_as_default(ac_prefs);
356                         cur_account = ac_prefs;
357                 }
358         }
359 }
360
361
362 static void account_edit_create(void)
363 {
364         GtkWidget *window;
365         GtkWidget *vbox;
366         GtkWidget *hbox;
367         GtkWidget *scrolledwin;
368         GtkWidget *clist;
369         gchar *titles[N_EDIT_ACCOUNT_COLS];
370         gint i;
371
372         GtkWidget *vbox2;
373         GtkWidget *add_btn;
374         GtkWidget *edit_btn;
375         GtkWidget *del_btn;
376         GtkWidget *up_btn;
377         GtkWidget *down_btn;
378
379         GtkWidget *default_btn;
380
381         GtkWidget *hbbox;
382         GtkWidget *close_btn;
383
384         debug_print(_("Creating account edit window...\n"));
385
386         window = gtk_window_new (GTK_WINDOW_DIALOG);
387         gtk_widget_set_usize (window, 500, 320);
388         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
389         gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
390         gtk_window_set_modal (GTK_WINDOW (window), TRUE);
391         gtk_signal_connect (GTK_OBJECT (window), "delete_event",
392                             GTK_SIGNAL_FUNC (account_delete_event), NULL);
393         gtk_signal_connect (GTK_OBJECT (window), "key_press_event",
394                             GTK_SIGNAL_FUNC (account_key_pressed), NULL);
395         gtk_signal_connect (GTK_OBJECT (window), "focus_in_event",
396                             GTK_SIGNAL_FUNC (manage_window_focus_in), NULL);
397         gtk_signal_connect (GTK_OBJECT (window), "focus_out_event",
398                             GTK_SIGNAL_FUNC (manage_window_focus_out), NULL);
399
400         vbox = gtk_vbox_new (FALSE, 12);
401         gtk_widget_show (vbox);
402         gtk_container_add (GTK_CONTAINER (window), vbox);
403
404         hbox = gtk_hbox_new (FALSE, 8);
405         gtk_widget_show (hbox);
406         gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
407         gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
408
409         scrolledwin = gtk_scrolled_window_new (NULL, NULL);
410         gtk_widget_show (scrolledwin);
411         gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
412         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
413                                         GTK_POLICY_AUTOMATIC,
414                                         GTK_POLICY_AUTOMATIC);
415
416         titles[COL_DEFAULT]  = "";
417         titles[COL_NAME]     = _("Name");
418         titles[COL_PROTOCOL] = _("Protocol");
419         titles[COL_SERVER]   = _("Server");
420
421         clist = gtk_clist_new_with_titles (N_EDIT_ACCOUNT_COLS, titles);
422         gtk_widget_show (clist);
423         gtk_container_add (GTK_CONTAINER (scrolledwin), clist);
424         gtk_clist_set_column_width (GTK_CLIST(clist), COL_DEFAULT , 16);
425         gtk_clist_set_column_width (GTK_CLIST(clist), COL_NAME    , 100);
426         gtk_clist_set_column_width (GTK_CLIST(clist), COL_PROTOCOL, 70);
427         gtk_clist_set_column_width (GTK_CLIST(clist), COL_SERVER  , 100);
428         gtk_clist_set_selection_mode (GTK_CLIST(clist), GTK_SELECTION_BROWSE);
429
430         for (i = 0; i < N_EDIT_ACCOUNT_COLS; i++)
431                 GTK_WIDGET_UNSET_FLAGS(GTK_CLIST(clist)->column[i].button,
432                                        GTK_CAN_FOCUS);
433
434         vbox2 = gtk_vbox_new (FALSE, 0);
435         gtk_widget_show (vbox2);
436         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
437
438         add_btn = gtk_button_new_with_label (_("Add"));
439         gtk_widget_show (add_btn);
440         gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
441         gtk_signal_connect (GTK_OBJECT(add_btn), "clicked",
442                             GTK_SIGNAL_FUNC (account_add), NULL);
443
444         edit_btn = gtk_button_new_with_label (_("Edit"));
445         gtk_widget_show (edit_btn);
446         gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
447         gtk_signal_connect (GTK_OBJECT(edit_btn), "clicked",
448                             GTK_SIGNAL_FUNC (account_edit_prefs), NULL);
449
450         del_btn = gtk_button_new_with_label (_(" Delete "));
451         gtk_widget_show (del_btn);
452         gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
453         gtk_signal_connect (GTK_OBJECT(del_btn), "clicked",
454                             GTK_SIGNAL_FUNC (account_delete), NULL);
455
456         down_btn = gtk_button_new_with_label (_("Down"));
457         gtk_widget_show (down_btn);
458         gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
459         gtk_signal_connect (GTK_OBJECT(down_btn), "clicked",
460                             GTK_SIGNAL_FUNC (account_down), NULL);
461
462         up_btn = gtk_button_new_with_label (_("Up"));
463         gtk_widget_show (up_btn);
464         gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
465         gtk_signal_connect (GTK_OBJECT(up_btn), "clicked",
466                             GTK_SIGNAL_FUNC (account_up), NULL);
467
468         hbox = gtk_hbox_new (FALSE, 8);
469         gtk_widget_show (hbox);
470         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
471
472         vbox2 = gtk_vbox_new(FALSE, 0);
473         gtk_widget_show (vbox2);
474         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
475
476         default_btn = gtk_button_new_with_label (_(" Set as usually used account "));
477         gtk_widget_show (default_btn);
478         gtk_box_pack_start (GTK_BOX (vbox2), default_btn, TRUE, FALSE, 0);
479         gtk_signal_connect (GTK_OBJECT(default_btn), "clicked",
480                             GTK_SIGNAL_FUNC (account_set_default), NULL);
481
482         gtkut_button_set_create(&hbbox, &close_btn, _("Close"),
483                                 NULL, NULL, NULL, NULL);
484         gtk_widget_show(hbbox);
485         gtk_box_pack_end (GTK_BOX (hbox), hbbox, FALSE, FALSE, 0);
486         gtk_widget_grab_default (close_btn);
487
488         gtk_signal_connect (GTK_OBJECT (close_btn), "clicked",
489                             GTK_SIGNAL_FUNC (account_edit_close),
490                             NULL);
491
492         edit_account.window    = window;
493         edit_account.clist     = clist;
494         edit_account.close_btn = close_btn;
495 }
496
497 static void account_edit_prefs(void)
498 {
499         GtkCList *clist = GTK_CLIST(edit_account.clist);
500         PrefsAccount *ac_prefs;
501         gint row;
502         gboolean prev_default;
503         gchar *ac_name;
504
505         if (!clist->selection) return;
506
507         row = GPOINTER_TO_INT(clist->selection->data);
508         ac_prefs = gtk_clist_get_row_data(clist, row);
509         prev_default = ac_prefs->is_default;
510         Xstrdup_a(ac_name, ac_prefs->account_name, return);
511
512         prefs_account_open(ac_prefs);
513         inc_autocheck_timer_remove();
514
515         if (!prev_default && ac_prefs->is_default)
516                 account_set_as_default(ac_prefs);
517
518         if ((ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) &&
519             ac_prefs->folder && strcmp(ac_name, ac_prefs->account_name) != 0) {
520                 folder_set_name(FOLDER(ac_prefs->folder),
521                                 ac_prefs->account_name);
522                 folderview_update_all();
523         }
524
525         account_clist_set();
526 }
527
528 static void account_delete(void)
529 {
530         GtkCList *clist = GTK_CLIST(edit_account.clist);
531         PrefsAccount *ac_prefs;
532         gint row;
533
534         if (!clist->selection) return;
535
536         if (alertpanel(_("Delete account"),
537                        _("Do you really want to delete this account?"),
538                        _("Yes"), _("+No"), NULL) != G_ALERTDEFAULT)
539                 return;
540
541         row = GPOINTER_TO_INT(clist->selection->data);
542         ac_prefs = gtk_clist_get_row_data(clist, row);
543         if (ac_prefs->folder) {
544                 folder_destroy(FOLDER(ac_prefs->folder));
545                 folderview_update_all();
546         }
547         account_destroy(ac_prefs);
548         account_clist_set();
549 }
550
551 static void account_up(void)
552 {
553         GtkCList *clist = GTK_CLIST(edit_account.clist);
554         gint row;
555
556         if (!clist->selection) return;
557
558         row = GPOINTER_TO_INT(clist->selection->data);
559         if (row > 0) {
560                 gtk_clist_row_move(clist, row, row - 1);
561                 account_list_set();
562         }
563 }
564
565 static void account_down(void)
566 {
567         GtkCList *clist = GTK_CLIST(edit_account.clist);
568         gint row;
569
570         if (!clist->selection) return;
571
572         row = GPOINTER_TO_INT(clist->selection->data);
573         if (row < clist->rows - 1) {
574                 gtk_clist_row_move(clist, row, row + 1);
575                 account_list_set();
576         }
577 }
578
579 static void account_set_default(void)
580 {
581         GtkCList *clist = GTK_CLIST(edit_account.clist);
582         gint row;
583         PrefsAccount *ac_prefs;
584
585         if (!clist->selection) return;
586
587         row = GPOINTER_TO_INT(clist->selection->data);
588         ac_prefs = gtk_clist_get_row_data(clist, row);
589         account_set_as_default(ac_prefs);
590         account_clist_set();
591
592         cur_account = ac_prefs;
593         account_set_menu();
594         main_window_reflect_prefs_all();
595 }
596
597 static void account_edit_close(void)
598 {
599         account_list_set();
600         account_save_config_all();
601
602         if (!cur_account && account_list) {
603                 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
604                 account_set_as_default(ac_prefs);
605                 cur_account = ac_prefs;
606         }
607
608         account_set_menu();
609         main_window_reflect_prefs_all();
610
611         gtk_widget_hide(edit_account.window);
612
613         inc_autocheck_timer_set();
614 }
615
616 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
617                                  gpointer data)
618 {
619         account_edit_close();
620         return TRUE;
621 }
622
623 static void account_key_pressed(GtkWidget *widget, GdkEventKey *event,
624                                 gpointer data)
625 {
626         if (event && event->keyval == GDK_Escape)
627                 account_edit_close();
628 }
629
630 /* set one CList row or add new row */
631 static gint account_clist_set_row(PrefsAccount *ac_prefs, gint row)
632 {
633         GtkCList *clist = GTK_CLIST(edit_account.clist);
634         gchar *text[N_EDIT_ACCOUNT_COLS];
635
636         text[COL_DEFAULT] = ac_prefs->is_default ? "*" : "";
637         text[COL_NAME] = ac_prefs->account_name;
638         text[COL_PROTOCOL] = ac_prefs->protocol == A_POP3  ? "POP3"  :
639                              ac_prefs->protocol == A_APOP  ? "APOP"  :
640                              ac_prefs->protocol == A_IMAP4 ? "IMAP4" :
641                              ac_prefs->protocol == A_LOCAL ? "Local" :
642                              ac_prefs->protocol == A_NNTP  ? "NNTP"  :  "";
643         text[COL_SERVER] = ac_prefs->protocol == A_NNTP
644                 ? ac_prefs->nntp_server : ac_prefs->recv_server;
645
646         if (row < 0)
647                 row = gtk_clist_append(clist, text);
648         else {
649                 gtk_clist_set_text(clist, row, COL_DEFAULT, text[COL_DEFAULT]);
650                 gtk_clist_set_text(clist, row, COL_NAME, text[COL_NAME]);
651                 gtk_clist_set_text(clist, row, COL_PROTOCOL, text[COL_PROTOCOL]);
652                 gtk_clist_set_text(clist, row, COL_SERVER, text[COL_SERVER]);
653         }
654
655         gtk_clist_set_row_data(clist, row, ac_prefs);
656
657         return row;
658 }
659
660 /* set CList from account list */
661 static void account_clist_set(void)
662 {
663         GtkCList *clist = GTK_CLIST(edit_account.clist);
664         GList *cur;
665         gint prev_row;
666
667         if (clist->selection)
668                 prev_row = GPOINTER_TO_INT(clist->selection->data);
669         else
670                 prev_row = -1;
671
672         gtk_clist_freeze(clist);
673         gtk_clist_clear(clist);
674
675         for (cur = account_list; cur != NULL; cur = cur->next) {
676                 gint row;
677
678                 row = account_clist_set_row((PrefsAccount *)cur->data, -1);
679                 if ((PrefsAccount *)cur->data == cur_account)
680                         gtk_clist_select_row(clist, row, -1);
681         }
682
683         if (prev_row >= 0)
684                 gtk_clist_select_row(clist, prev_row, -1);
685
686         gtk_clist_thaw(clist);
687 }
688
689 /* set account list from CList */
690 static void account_list_set(void)
691 {
692         GtkCList *clist = GTK_CLIST(edit_account.clist);
693         gint row;
694         PrefsAccount *ac_prefs;
695
696         while (account_list)
697                 account_list = g_list_remove(account_list, account_list->data);
698
699         for (row = 0; (ac_prefs = gtk_clist_get_row_data(clist, row)) != NULL;
700              row++)
701                 account_list = g_list_append(account_list, ac_prefs);
702 }