Fix bug #3741: Deleting an account doesn't delete imapcache
[claws.git] / src / account.c
1 /*
2  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
3  * Copyright (C) 1999-2015 Hiroyuki Yamamoto and the Claws Mail team
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 3 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, see <http://www.gnu.org/licenses/>.
17  * 
18  */
19
20 #ifdef HAVE_CONFIG_H
21 #  include "config.h"
22 #include "claws-features.h"
23 #endif
24
25 #include "defs.h"
26
27 #include <glib.h>
28 #include <glib/gi18n.h>
29 #include <gtk/gtk.h>
30 #include <gdk/gdkkeysyms.h>
31 #include <stdio.h>
32 #include <errno.h>
33
34 #include "main.h"
35 #include "mainwindow.h"
36 #include "folderview.h"
37 #include "folder.h"
38 #include "account.h"
39 #include "prefs_gtk.h"
40 #include "prefs_account.h"
41 #include "prefs_common.h"
42 #include "folder_item_prefs.h"
43 #include "compose.h"
44 #include "manage_window.h"
45 #include "stock_pixmap.h"
46 #include "inc.h"
47 #include "gtkutils.h"
48 #include "utils.h"
49 #include "alertpanel.h"
50 #include "procheader.h"
51 #include "customheader.h"
52 #include "remotefolder.h"
53 #include "manual.h"
54 #include "filtering.h"
55 #include "prefs_actions.h"
56 #include "hooks.h"
57 #include "passwordstore.h"
58
59 enum {
60         ACCOUNT_IS_DEFAULT,
61         ACCOUNT_ENABLE_GET_ALL, 
62         ACCOUNT_NAME,
63         ACCOUNT_PROTOCOL,
64         ACCOUNT_SERVER,
65         ACCOUNT_DATA,
66         N_ACCOUNT_COLUMNS
67 };
68
69
70 typedef enum
71 {
72         COL_DEFAULT     = 0,
73         COL_GETALL      = 1,
74         COL_NAME        = 2,
75         COL_PROTOCOL    = 3,
76         COL_SERVER      = 4
77 } EditAccountColumnPos;
78
79 # define N_EDIT_ACCOUNT_COLS    5
80
81 PrefsAccount *cur_account;
82
83 static GList *account_list = NULL;
84 static gboolean account_list_dirty = FALSE;
85
86 static struct EditAccount {
87         GtkWidget *window;
88         GtkWidget *list_view;
89         GtkWidget *close_btn;
90 } edit_account;
91
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);
96
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);
100
101 static void account_up                  (GtkWidget *widget, gpointer data);
102 static void account_down                (GtkWidget *widget, gpointer data);
103
104 static void account_set_default         (GtkWidget *widget, gpointer data);
105
106 static void account_edit_close          (GtkWidget *widget, gpointer data);
107
108 static gint account_delete_event        (GtkWidget      *widget,
109                                          GdkEventAny    *event,
110                                          gpointer        data);
111 static void account_size_allocate_cb(GtkWidget *widget,
112                                          GtkAllocation *allocation);
113 static gboolean account_key_pressed     (GtkWidget      *widget,
114                                          GdkEventKey    *event,
115                                          gpointer        data);
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_add       (PrefsAccount   *ac_prefs);
120 static void account_list_view_set       (void);
121
122 static void account_list_set            (void);
123
124 typedef struct FindAccountInStore {
125         gint             account_id;
126         GtkTreePath     *path;
127         GtkTreeIter      iter;
128 } FindAccountInStore;
129
130 static GtkListStore* account_create_data_store  (void);
131
132 static void account_list_view_insert_account_item (GtkListStore *list_store, 
133                                                    const gchar  *account_name,
134                                                    const gchar  *protocol, 
135                                                    const gchar  *server_name,
136                                                    gboolean      is_default, 
137                                                    gboolean      is_get_all,
138                                                    PrefsAccount *account_data);
139
140 static GtkWidget *account_list_view_create      (void);
141 static void account_create_list_view_columns    (GtkWidget *list_view);
142
143 static gint account_list_view_get_selected_account_id           (GtkWidget *list_view);
144 static GtkTreePath *account_list_view_get_selected_account_path (GtkWidget *list_view);
145 static PrefsAccount *account_list_view_get_selected_account             (GtkWidget *list_view);
146 static gboolean account_list_view_select_account                        (GtkWidget *list_view, 
147                                                                  gint       account_id);
148
149 static void account_list_view_set_default_by_id(GtkWidget *list_view,
150                                                 gint account_id);
151
152 static gboolean set_new_default_account         (GtkTreeModel *model,
153                                                  GtkTreePath  *path,
154                                                  GtkTreeIter  *iter,
155                                                  gint         *account_id);
156
157 static gboolean find_account_in_store           (GtkTreeModel *model,
158                                                  GtkTreePath  *path,
159                                                  GtkTreeIter  *iter,
160                                                  FindAccountInStore *data);
161
162 static void account_get_all_toggled             (GtkCellRendererToggle  *widget, 
163                                                  gchar                  *path, 
164                                                  GtkWidget              *list_view);
165                                                  
166 static void account_double_clicked              (GtkTreeView            *list_view,
167                                                  GtkTreePath            *path,
168                                                  GtkTreeViewColumn      *column,
169                                                  gpointer                data);
170                                                  
171 static void drag_begin                          (GtkTreeView *list_view,
172                                                  GdkDragContext *context,
173                                                  gpointer data);
174
175 static void drag_end                            (GtkTreeView *list_view,
176                                                  GdkDragContext *context,
177                                                  gpointer data);
178                       
179 static void account_row_changed_while_drag_drop (GtkTreeModel *model, 
180                                                  GtkTreePath  *path,
181                                                  GtkTreeIter  *iter,
182                                                  gpointer      arg3,
183                                                  GtkTreeView  *list_view);
184
185 static void account_flush_state(void)
186 {
187         account_set_menu();
188         main_window_reflect_prefs_all();
189
190         account_list_dirty = FALSE;
191 }
192
193 void account_read_config_all(void)
194 {
195         GSList *ac_label_list = NULL, *cur;
196         gchar *rcpath;
197         FILE *fp;
198         gchar buf[PREFSBUFSIZE];
199         PrefsAccount *ac_prefs;
200
201         debug_print("Reading all config for each account...\n");
202
203         rcpath = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S, ACCOUNT_RC, NULL);
204         if ((fp = g_fopen(rcpath, "rb")) == NULL) {
205                 if (ENOENT != errno) FILE_OP_ERROR(rcpath, "fopen");
206                 g_free(rcpath);
207                 return;
208         }
209         g_free(rcpath);
210
211         while (fgets(buf, sizeof(buf), fp) != NULL) {
212                 if (!strncmp(buf, "[Account: ", 10)) {
213                         strretchomp(buf);
214                         memmove(buf, buf + 1, sizeof(buf) - 1);
215                         buf[strlen(buf) - 1] = '\0';
216                         debug_print("Found label: %s\n", buf);
217                         ac_label_list = g_slist_append(ac_label_list,
218                                                        g_strdup(buf));
219                 }
220         }
221         fclose(fp);
222
223         /* read config data from file */
224         cur_account = NULL;
225         for (cur = ac_label_list; cur != NULL; cur = cur->next) {
226                 ac_prefs = prefs_account_new();
227                 prefs_account_read_config(ac_prefs, (gchar *)cur->data);
228                 account_list = g_list_append(account_list, ac_prefs);
229                 if (ac_prefs->is_default)
230                         cur_account = ac_prefs;
231         }
232         /* if default is not set, assume first account as default */
233         if (!cur_account && account_list) {
234                 ac_prefs = (PrefsAccount *)account_list->data;
235                 account_set_as_default(ac_prefs);
236                 cur_account = ac_prefs;
237         }
238
239         account_set_menu();
240         main_window_reflect_prefs_all_now();
241
242         while (ac_label_list) {
243                 g_free(ac_label_list->data);
244                 ac_label_list = g_slist_remove(ac_label_list,
245                                                ac_label_list->data);
246         }
247 }
248
249 void account_write_config_all(void)
250 {
251         prefs_account_write_config_all(account_list);
252 }
253
254 /*
255  * account_find_all_from_address:
256  * @ac_list: initial list of accounts. NULL to create a new one.
257  * Accounts found in the @address will be appended to this list.
258  * @address: Email address string.
259  *
260  * Find all the mail (not news) accounts within the specified address.
261  *
262  * Return value: the original accounts list with the found accounts appended.
263  */
264 GList *account_find_all_from_address(GList *ac_list, const gchar *address)
265 {
266         GList *cur;
267         PrefsAccount *ac;
268
269         if (address == NULL)
270                 return ac_list;
271
272         for (cur = account_list; cur != NULL; cur = cur->next) {
273                 ac = (PrefsAccount *)cur->data;
274                 if (ac->protocol != A_NNTP && ac->address &&
275                     strcasestr(address, ac->address) != NULL)
276                         ac_list = g_list_append(ac_list, ac);
277         }
278         return ac_list;
279 }
280         
281 PrefsAccount *account_find_from_smtp_server(const gchar *address,
282                                             const gchar *smtp_server)
283 {
284         GList *cur;
285         PrefsAccount *ac;
286
287         cm_return_val_if_fail(address != NULL, NULL);
288         cm_return_val_if_fail(smtp_server != NULL, NULL);
289
290         for (cur = account_list; cur != NULL; cur = cur->next) {
291                 ac = (PrefsAccount *)cur->data;
292                 if (!strcmp2(address, ac->address) &&
293                     !strcmp2(smtp_server, ac->smtp_server))
294                         return ac;
295         }
296
297         return NULL;
298 }
299
300 /*
301  * account_find_from_address:
302  * @address: Email address string.
303  *
304  * Find a mail (not news if newsgroups_ok is FALSE) account with the specified email address.
305  *
306  * Return value: The found account, or NULL if not found.
307  */
308 PrefsAccount *account_find_from_address(const gchar *address, gboolean newsgroups_ok)
309 {
310         GList *cur;
311         PrefsAccount *ac;
312
313         cm_return_val_if_fail(address != NULL, NULL);
314
315         for (cur = account_list; cur != NULL; cur = cur->next) {
316                 ac = (PrefsAccount *)cur->data;
317                 if ((ac->protocol != A_NNTP || newsgroups_ok) && ac->address &&
318                     g_ascii_strcasecmp(address, ac->address) == 0)
319                         return ac;
320         }
321
322         return NULL;
323 }
324
325 PrefsAccount *account_find_from_id(gint id)
326 {
327         GList *cur;
328         PrefsAccount *ac;
329
330         for (cur = account_list; cur != NULL; cur = cur->next) {
331                 ac = (PrefsAccount *)cur->data;
332                 if (id == ac->account_id)
333                         return ac;
334         }
335
336         return NULL;
337 }
338
339 PrefsAccount *account_find_from_item(FolderItem *item)
340 {
341         PrefsAccount *ac;
342
343         cm_return_val_if_fail(item != NULL, NULL);
344
345         ac = item->account;
346         if (!ac) {
347                 FolderItem *cur_item = folder_item_parent(item);
348                 while (cur_item != NULL) {
349                         if (cur_item->account && cur_item->apply_sub) {
350                                 ac = cur_item->account;
351                                 break;
352                         }                               
353                         cur_item = folder_item_parent(cur_item);
354                 }
355         }
356         if (!ac)
357                 ac = item->folder->account;
358
359         return ac;
360 }
361
362 static void account_set_menu(void)
363 {
364         main_window_set_account_menu(account_list);
365 }
366
367 void account_set_menu_only_toolbar(void)
368 {
369         main_window_set_account_menu_only_toolbar(account_list);
370 }
371
372 GList *account_get_list(void)
373 {
374         return account_list;
375 }
376
377 void account_edit_focus(void)
378 {
379         if (edit_account.window == NULL) {
380                 return;
381         }
382         manage_window_set_transient(GTK_WINDOW(edit_account.window));
383         gtk_widget_grab_focus(edit_account.close_btn);
384         gtk_widget_show(edit_account.window);
385         gtk_window_set_modal(GTK_WINDOW(edit_account.window), TRUE);
386         manage_window_focus_in(edit_account.window, NULL, NULL);
387 }
388
389 void account_edit_open(gpointer a, gpointer b)
390 {
391         inc_lock();
392
393         account_list_dirty = FALSE;
394
395         if (compose_get_compose_list()) {
396                 alertpanel_error(_("Some composing windows are open.\n"
397                                    "Please close all the composing "
398                                    "windows before editing accounts."));
399                 inc_unlock();
400                 return;
401         }
402
403         debug_print("Opening account edit window...\n");
404
405         if (!edit_account.window)
406                 account_edit_create();
407
408         account_list_view_set();
409
410         account_edit_focus();
411 }
412
413 void account_add(void)
414 {
415         PrefsAccount *ac_prefs;
416
417         ac_prefs = prefs_account_open(NULL, &account_list_dirty);
418
419         if (!ac_prefs) return;
420
421         account_edit_focus();
422
423         account_list = g_list_append(account_list, ac_prefs);
424
425         if (ac_prefs->is_default)
426                 account_set_as_default(ac_prefs);
427
428         account_list_view_set();
429
430         if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
431                 Folder *folder;
432
433                 if (ac_prefs->protocol == A_IMAP4) {
434                         folder = folder_new(folder_get_class_from_string("imap"), ac_prefs->account_name,
435                                             ac_prefs->recv_server);
436                 } else {
437                         folder = folder_new(folder_get_class_from_string("news"), ac_prefs->account_name,
438                                             ac_prefs->nntp_server);
439                 }
440                 if (folder == NULL) {
441                         alertpanel_error(_("Can't create folder."));
442                         return;
443                 }
444                 folder->account = ac_prefs;
445                 ac_prefs->folder = folder;
446                 folder_add(folder);
447                 if (ac_prefs->protocol == A_IMAP4)
448                         folder->klass->create_tree(folder);
449                 folderview_set_all();
450                 folder_write_list();
451         }
452 }
453
454 void account_open(PrefsAccount *ac_prefs)
455 {
456         gboolean prev_default;
457         gchar *ac_name, *old_prefix, *new_prefix;
458         gboolean account_dirty = FALSE;
459
460         cm_return_if_fail(ac_prefs != NULL);
461
462         if (compose_get_compose_list()) {
463                 alertpanel_error(_("Some composing windows are open.\n"
464                                    "Please close all the composing "
465                                    "windows before editing accounts."));
466                 return;
467         }
468
469         prev_default = ac_prefs->is_default;
470         Xstrdup_a(ac_name, ac_prefs->account_name ? ac_prefs->account_name : "",
471                   return);
472
473         prefs_account_open(ac_prefs, &account_dirty);
474
475         account_edit_focus();
476
477         if (account_dirty) {
478                 if (!prev_default && ac_prefs->is_default)
479                         account_set_as_default(ac_prefs);
480
481                 if (ac_prefs->folder && strcmp2(ac_name, ac_prefs->account_name) != 0) {
482                         old_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
483                         folder_set_name(FOLDER(ac_prefs->folder),
484                                         ac_prefs->account_name);
485                         folderview_set_all();
486                         folder_prefs_save_config_recursive(FOLDER(ac_prefs->folder));
487                         new_prefix = folder_get_identifier(FOLDER(ac_prefs->folder));
488
489                         account_rename_path(old_prefix, new_prefix);
490                         prefs_filtering_rename_path(old_prefix, new_prefix);
491                         prefs_actions_rename_path(old_prefix, new_prefix);
492                         
493                         g_free(old_prefix);
494                         g_free(new_prefix);
495                 }
496
497                 account_write_config_all();
498
499                 account_flush_state();
500         }
501 }
502
503 static void account_set_as_default(PrefsAccount *ac_prefs)
504 {
505         PrefsAccount *ap;
506         GList *cur;
507
508         for (cur = account_list; cur != NULL; cur = cur->next) {
509                 ap = (PrefsAccount *)cur->data;
510                 if (ap->is_default)
511                         ap->is_default = FALSE;
512         }
513
514         ac_prefs->is_default = TRUE;
515 }
516
517 PrefsAccount *account_get_default(void)
518 {
519         PrefsAccount *ap;
520         GList *cur;
521
522         for (cur = account_list; cur != NULL; cur = cur->next) {
523                 ap = (PrefsAccount *)cur->data;
524                 if (ap->is_default)
525                         return ap;
526         }
527
528         return NULL;
529 }
530
531 void account_set_missing_folder(void)
532 {
533         PrefsAccount *ap;
534         GList *cur;
535
536         for (cur = account_list; cur != NULL; cur = cur->next) {
537                 ap = (PrefsAccount *)cur->data;
538                 if ((ap->protocol == A_IMAP4 || ap->protocol == A_NNTP) &&
539                     !ap->folder) {
540                         Folder *folder;
541
542                         if (ap->protocol == A_IMAP4) {
543                                 folder = folder_new(folder_get_class_from_string("imap"), ap->account_name,
544                                                     ap->recv_server);
545                         } else {
546                                 folder = folder_new(folder_get_class_from_string("news"), ap->account_name,
547                                                     ap->nntp_server);
548                         }
549                         if (folder == NULL)
550                                 return;
551                         folder->account = ap;
552                         ap->folder = folder;
553                         folder_add(folder);
554                         if (ap->protocol == A_IMAP4)
555                                 folder->klass->create_tree(folder);
556                         folder_write_list();
557
558                 }
559         }
560 }
561
562 #define CHECK_CHANGE_FOLDER(folder) {                                           \
563         if (folder && !strncmp(folder, old_id, strlen(old_id))) {               \
564                 if (strlen(folder) == strlen(old_id)) {                         \
565                         g_free(folder);                                         \
566                         folder = g_strdup(new_id);                              \
567                 } else if (strlen(folder) > strlen(old_id)                      \
568                   && folder[strlen(old_id)] == G_DIR_SEPARATOR) {               \
569                         gchar *new_path = g_strdup_printf("%s%s",               \
570                                         new_id, (folder + strlen(old_id)));     \
571                         g_free(folder);                                         \
572                         folder = new_path;                                      \
573                 }                                                               \
574         }                                                                       \
575 }
576
577 void account_rename_path(const gchar *old_id, const gchar *new_id)
578 {
579         GList *cur = account_list;
580         for (; cur != NULL; cur = g_list_next(cur)) {
581                 PrefsAccount *ap = (PrefsAccount *)cur->data;
582                 CHECK_CHANGE_FOLDER(ap->inbox);
583                 CHECK_CHANGE_FOLDER(ap->local_inbox);
584                 CHECK_CHANGE_FOLDER(ap->queue_folder);
585                 CHECK_CHANGE_FOLDER(ap->sent_folder);
586                 CHECK_CHANGE_FOLDER(ap->draft_folder);
587                 CHECK_CHANGE_FOLDER(ap->trash_folder);
588         }
589 }
590
591 FolderItem *account_get_special_folder(PrefsAccount *ac_prefs,
592                                        SpecialFolderItemType type)
593 {
594         FolderItem *item = NULL;
595
596         cm_return_val_if_fail(ac_prefs != NULL, NULL);
597
598         switch (type) {
599         case F_INBOX:
600                 if (ac_prefs->folder)
601                         item = FOLDER(ac_prefs->folder)->inbox;
602                 if (!item)
603                         item = folder_get_default_inbox();
604                 break;
605         case F_OUTBOX:
606                 if (ac_prefs->set_sent_folder && ac_prefs->sent_folder) {
607                         item = folder_find_item_from_identifier
608                                 (ac_prefs->sent_folder);
609                 }
610                 if (!item) {
611                         if (ac_prefs->folder)
612                                 item = FOLDER(ac_prefs->folder)->outbox;
613                         if (!item)
614                                 item = folder_get_default_outbox_for_class(F_MH);
615                         if (!item)
616                                 item = folder_get_default_outbox();
617                 }
618                 break;
619         case F_DRAFT:
620                 if (ac_prefs->set_draft_folder && ac_prefs->draft_folder) {
621                         item = folder_find_item_from_identifier
622                                 (ac_prefs->draft_folder);
623                 }
624                 if (!item) {
625                         if (ac_prefs->folder)
626                                 item = FOLDER(ac_prefs->folder)->draft;
627                         if (!item)
628                                 item = folder_get_default_draft_for_class(F_MH);
629                         if (!item)
630                                 item = folder_get_default_draft();
631                 }
632                 break;
633         case F_QUEUE:
634                 if (ac_prefs->set_queue_folder && ac_prefs->queue_folder) {
635                         item = folder_find_item_from_identifier
636                                 (ac_prefs->queue_folder);
637                 }
638                 if (!item) {
639                         if (ac_prefs->folder)
640                                 item = FOLDER(ac_prefs->folder)->queue;
641                         if (!item)
642                                 item = folder_get_default_queue_for_class(F_MH);
643                         if (!item)
644                                 item = folder_get_default_queue();
645                 }
646                 break;
647         case F_TRASH:
648                 if (ac_prefs->set_trash_folder && ac_prefs->trash_folder) {
649                         item = folder_find_item_from_identifier
650                                 (ac_prefs->trash_folder);
651                 }
652                 if (!item) {
653                         if (ac_prefs->folder)
654                                 item = FOLDER(ac_prefs->folder)->trash;
655                         if (!item)
656                                 item = folder_get_default_trash_for_class(F_MH);
657                         if (!item)
658                                 item = folder_get_default_trash();
659                 }
660                 break;
661         default:
662                 break;
663         }
664
665         return item;
666 }
667
668 void account_destroy(PrefsAccount *ac_prefs)
669 {
670         cm_return_if_fail(ac_prefs != NULL);
671
672         folder_unref_account_all(ac_prefs);
673
674         account_list = g_list_remove(account_list, ac_prefs);
675
676         if (cur_account == ac_prefs) cur_account = NULL;
677         if (!cur_account && account_list) {
678                 cur_account = account_get_default();
679                 if (!cur_account) {
680                         ac_prefs = (PrefsAccount *)account_list->data;
681                         account_set_as_default(ac_prefs);
682                         cur_account = ac_prefs;
683                 }
684         }
685 }
686
687 /*!
688  *\brief        Save Gtk object size to prefs dataset
689  */
690 static void account_size_allocate_cb(GtkWidget *widget,
691                                          GtkAllocation *allocation)
692 {
693         cm_return_if_fail(allocation != NULL);
694
695         prefs_common.accountswin_width = allocation->width;
696         prefs_common.accountswin_height = allocation->height;
697 }
698
699 static void account_edit_create(void)
700 {
701         GtkWidget *window;
702         GtkWidget *vbox;
703         GtkWidget *label;
704         GtkWidget *hbox;
705         GtkWidget *scrolledwin;
706         GtkWidget *list_view;
707
708         GtkWidget *vbox2;
709         GtkWidget *add_btn;
710         GtkWidget *edit_btn;
711         GtkWidget *del_btn;
712         GtkWidget *clone_btn;
713         GtkWidget *up_btn;
714         GtkWidget *down_btn;
715
716         GtkWidget *default_btn;
717
718         GtkWidget *confirm_area;
719         GtkWidget *help_btn;
720         GtkWidget *close_btn;
721
722         static GdkGeometry geometry;
723
724         debug_print("Creating account edit window...\n");
725
726         window = gtkut_window_new(GTK_WINDOW_TOPLEVEL, "account");
727         gtk_container_set_border_width (GTK_CONTAINER (window), 8);
728         gtk_window_set_title (GTK_WINDOW (window), _("Edit accounts"));
729         g_signal_connect (G_OBJECT (window), "delete_event",
730                           G_CALLBACK (account_delete_event), NULL);
731         g_signal_connect (G_OBJECT (window), "key_press_event",
732                           G_CALLBACK (account_key_pressed), NULL);
733         MANAGE_WINDOW_SIGNALS_CONNECT (window);
734         gtk_widget_realize(window);
735
736         vbox = gtk_vbox_new (FALSE, 10);
737         gtk_widget_show (vbox);
738         gtk_container_add (GTK_CONTAINER (window), vbox);
739
740         hbox = gtk_hbox_new (FALSE, 0);
741         gtk_widget_show (hbox);
742         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
743
744         label = gtk_label_new
745                 (_("Using 'Get Mail' will retrieve messages from your Accounts "
746                    "in the order given, the checkbox indicates which accounts "
747                    "will be included. Bold text indicates the default account."));
748         gtk_widget_show (label);
749         gtk_widget_set_size_request(GTK_WIDGET(label), 
750                                     prefs_common.accountswin_width-8, -1);
751         gtk_box_pack_start (GTK_BOX (hbox), label, FALSE, FALSE, 4);
752         gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_LEFT);
753         gtk_label_set_line_wrap(GTK_LABEL(label), TRUE);
754
755         hbox = gtk_hbox_new (FALSE, 8);
756         gtk_widget_show (hbox);
757         gtk_box_pack_start (GTK_BOX (vbox), hbox, TRUE, TRUE, 0);
758         gtk_container_set_border_width (GTK_CONTAINER (hbox), 2);
759
760         scrolledwin = gtk_scrolled_window_new (NULL, NULL);
761         gtk_widget_show (scrolledwin);
762         gtk_box_pack_start (GTK_BOX (hbox), scrolledwin, TRUE, TRUE, 0);
763         gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolledwin),
764                                         GTK_POLICY_AUTOMATIC,
765                                         GTK_POLICY_AUTOMATIC);
766
767         list_view = account_list_view_create();
768         gtk_widget_show(list_view);
769         gtk_container_add(GTK_CONTAINER(scrolledwin), list_view);
770
771         vbox2 = gtk_vbox_new (FALSE, 0);
772         gtk_widget_show (vbox2);
773         gtk_box_pack_start (GTK_BOX (hbox), vbox2, FALSE, FALSE, 0);
774
775         add_btn = gtk_button_new_from_stock(GTK_STOCK_NEW);
776         gtk_widget_show (add_btn);
777         gtk_box_pack_start (GTK_BOX (vbox2), add_btn, FALSE, FALSE, 4);
778         g_signal_connect (G_OBJECT(add_btn), "clicked",
779                           G_CALLBACK (account_add), NULL);
780
781         edit_btn = gtk_button_new_from_stock (GTK_STOCK_EDIT);
782         gtk_widget_show (edit_btn);
783         gtk_box_pack_start (GTK_BOX (vbox2), edit_btn, FALSE, FALSE, 4);
784         g_signal_connect (G_OBJECT(edit_btn), "clicked",
785                           G_CALLBACK (account_edit_prefs), NULL);
786
787         del_btn = gtk_button_new_from_stock(GTK_STOCK_DELETE);
788         gtk_widget_show (del_btn);
789         gtk_box_pack_start (GTK_BOX (vbox2), del_btn, FALSE, FALSE, 4);
790         g_signal_connect (G_OBJECT(del_btn), "clicked",
791                           G_CALLBACK (account_delete), NULL);
792
793         clone_btn = gtk_button_new_from_stock(GTK_STOCK_COPY);
794         gtk_widget_show (clone_btn);
795         gtk_box_pack_start (GTK_BOX (vbox2), clone_btn, FALSE, FALSE, 4);
796         g_signal_connect(G_OBJECT(clone_btn), "clicked",
797                          G_CALLBACK(account_clone), NULL);
798         
799         down_btn = gtk_button_new_from_stock(GTK_STOCK_GO_DOWN);
800         gtk_widget_show (down_btn);
801         gtk_box_pack_end (GTK_BOX (vbox2), down_btn, FALSE, FALSE, 4);
802         g_signal_connect (G_OBJECT(down_btn), "clicked",
803                           G_CALLBACK (account_down), NULL);
804
805         up_btn = gtk_button_new_from_stock(GTK_STOCK_GO_UP);
806         gtk_widget_show (up_btn);
807         gtk_box_pack_end (GTK_BOX (vbox2), up_btn, FALSE, FALSE, 4);
808         g_signal_connect (G_OBJECT(up_btn), "clicked",
809                           G_CALLBACK (account_up), NULL);
810
811         hbox = gtk_hbox_new (FALSE, 8);
812         gtk_widget_show (hbox);
813         gtk_box_pack_start (GTK_BOX (vbox), hbox, FALSE, FALSE, 0);
814
815         default_btn = gtk_button_new_with_mnemonic
816                 (_(" _Set as default account "));
817         gtk_widget_show (default_btn);
818         gtk_box_pack_start (GTK_BOX (hbox), default_btn, FALSE, FALSE, 0);
819         g_signal_connect (G_OBJECT(default_btn), "clicked",
820                           G_CALLBACK (account_set_default), NULL);
821
822         gtkut_stock_button_set_create_with_help(&confirm_area, &help_btn,
823                         &close_btn, GTK_STOCK_CLOSE,
824                         NULL, NULL, NULL, NULL);
825         gtk_widget_show(confirm_area);
826
827         gtk_box_pack_end (GTK_BOX (hbox), confirm_area, FALSE, FALSE, 0);
828         gtk_widget_grab_default (close_btn);
829
830         g_signal_connect (G_OBJECT (close_btn), "clicked",
831                           G_CALLBACK (account_edit_close),
832                           NULL);
833         g_signal_connect(G_OBJECT(help_btn), "clicked",
834                         G_CALLBACK(manual_open_with_anchor_cb),
835                         MANUAL_ANCHOR_ACCOUNTPREFS);
836
837
838         g_signal_connect(G_OBJECT(window), "size_allocate",
839                          G_CALLBACK(account_size_allocate_cb), NULL);
840
841         if (!geometry.min_height) {
842                 geometry.min_width = 500;
843                 geometry.min_height = 380;
844         }
845
846         gtk_window_set_geometry_hints(GTK_WINDOW(window), NULL, &geometry,
847                                       GDK_HINT_MIN_SIZE);
848         gtk_widget_set_size_request(window, prefs_common.accountswin_width,
849                                     prefs_common.accountswin_height);
850 #ifdef G_OS_WIN32
851         gtk_window_move(GTK_WINDOW(window), 48, 48);
852 #endif
853
854         edit_account.window    = window;
855         edit_account.list_view = list_view;
856         edit_account.close_btn = close_btn;
857 }
858
859 static void account_edit_prefs(GtkWidget *widget, gpointer data)
860 {
861         PrefsAccount *ac_prefs;
862
863         ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
864         
865         if (ac_prefs) {
866                 account_open(ac_prefs);
867                 account_list_view_set();
868         }               
869 }
870
871 static gboolean account_delete_references_func(GNode *node, gpointer data)
872 {
873         FolderItem *item;
874         gint account;
875
876         cm_return_val_if_fail(node->data != NULL, FALSE);
877
878         item = FOLDER_ITEM(node->data);
879         account = GPOINTER_TO_INT(data);
880
881         if(!item->prefs) /* && item->prefs->stype == F_NORMAL */
882                 return FALSE;
883         if(item->prefs->default_account != account)
884                 return FALSE;
885         
886         item->prefs->enable_default_account = FALSE;
887         item->prefs->default_account = 0;
888         folder_item_prefs_save_config(item);
889
890         return FALSE;
891 }
892
893         
894 #define ACP_FDUP(fld) ac_clon->fld = ((ac_prefs->fld) != NULL)?\
895                                      g_strdup(ac_prefs->fld): NULL
896 #define ACP_FASSIGN(fld) ac_clon->fld = ac_prefs->fld
897 static void account_clone(GtkWidget *widget, gpointer data)
898 {
899         PrefsAccount *ac_prefs, *ac_clon;
900         GSList *hdrs = NULL;
901         CustomHeader *cch = NULL, *ch = NULL;
902         
903         ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
904         if (ac_prefs == NULL)
905                 return;
906
907         if (ac_prefs->protocol == A_IMAP4 || ac_prefs->protocol == A_NNTP) {
908                 alertpanel_error(_("Accounts with remote folders cannot be copied."));
909                 return;
910         }
911         account_list_dirty = TRUE;
912         
913         ac_clon = prefs_account_new();
914         /* copy fields */
915         ac_clon->account_name = g_strdup_printf(_("Copy of %s"),
916                                                 ac_prefs->account_name);
917         /* personal */
918         ACP_FDUP(name);
919         ACP_FDUP(address);
920         ACP_FDUP(organization);
921
922         /* server */
923         ACP_FASSIGN(protocol);
924         ACP_FDUP(recv_server);
925         ACP_FDUP(smtp_server);
926         ACP_FDUP(nntp_server);
927         ACP_FASSIGN(use_nntp_auth);
928         ACP_FASSIGN(use_nntp_auth_onconnect);
929         ACP_FDUP(userid);
930         ACP_FDUP(passwd);
931
932         ACP_FDUP(local_mbox);
933         ACP_FASSIGN(use_mail_command);
934         ACP_FDUP(mail_command);
935         
936         ACP_FASSIGN(ssl_pop);
937         ACP_FASSIGN(ssl_imap);
938         ACP_FASSIGN(ssl_nntp);
939         ACP_FASSIGN(ssl_smtp);
940         ACP_FASSIGN(use_nonblocking_ssl);
941         
942         /* receive */
943         ACP_FASSIGN(use_apop_auth);
944         ACP_FASSIGN(rmmail);
945         ACP_FASSIGN(msg_leave_time);
946         ACP_FASSIGN(msg_leave_hour);
947         ACP_FASSIGN(recv_at_getall);
948         ACP_FASSIGN(sd_rmmail_on_download);
949         ACP_FASSIGN(enable_size_limit);
950         ACP_FASSIGN(size_limit);
951         ACP_FASSIGN(filter_on_recv);
952         ACP_FASSIGN(filterhook_on_recv);
953         ACP_FDUP(inbox);
954         ACP_FDUP(local_inbox);
955         ACP_FASSIGN(max_articles);
956
957         ACP_FASSIGN(imap_auth_type);
958
959         /* send */
960         ACP_FASSIGN(gen_msgid);
961         ACP_FASSIGN(gen_xmailer);
962         ACP_FASSIGN(add_customhdr);
963         ACP_FASSIGN(use_smtp_auth);
964         ACP_FASSIGN(smtp_auth_type);
965         ACP_FDUP(smtp_userid);
966         ACP_FDUP(smtp_passwd);
967
968         ACP_FASSIGN(pop_before_smtp);
969         ACP_FASSIGN(pop_before_smtp_timeout);
970         ACP_FASSIGN(last_pop_login_time);
971
972         ac_clon->customhdr_list = NULL;
973         hdrs = ac_prefs->customhdr_list;
974         while (hdrs != NULL) {
975                 ch = (CustomHeader *)hdrs->data;
976
977                 cch = g_new0(CustomHeader, 1);
978                 cch->account_id = ac_clon->account_id;  
979                 cch->name = (ch->name != NULL) ? g_strdup(ch->name) : NULL;
980                 cch->value = (ch->value != NULL) ? g_strdup(ch->value) : NULL;
981                 
982                 ac_clon->customhdr_list = g_slist_append(ac_clon->customhdr_list, cch);
983                 
984                 hdrs = g_slist_next(hdrs);
985         }
986
987         /* compose */
988         ACP_FASSIGN(sig_type);
989         ACP_FDUP(sig_path);
990         ACP_FASSIGN(auto_sig);
991         ACP_FDUP(sig_sep);
992         ACP_FASSIGN(set_autocc);
993         ACP_FDUP(auto_cc);
994         ACP_FASSIGN(set_autobcc);
995         ACP_FDUP(auto_bcc);
996         ACP_FASSIGN(set_autoreplyto);
997         ACP_FDUP(auto_replyto);
998         ACP_FASSIGN(enable_default_dictionary);
999         ACP_FDUP(default_dictionary);
1000         ACP_FASSIGN(enable_default_alt_dictionary);
1001         ACP_FDUP(default_alt_dictionary);
1002         ACP_FASSIGN(compose_with_format);
1003         ACP_FDUP(compose_subject_format);
1004         ACP_FDUP(compose_body_format);
1005         ACP_FASSIGN(reply_with_format);
1006         ACP_FDUP(reply_quotemark);
1007         ACP_FDUP(reply_body_format);
1008         ACP_FASSIGN(forward_with_format);
1009         ACP_FDUP(forward_quotemark);
1010         ACP_FDUP(forward_body_format);
1011
1012         /* privacy */
1013         ACP_FDUP(default_privacy_system);
1014         ACP_FASSIGN(default_encrypt);
1015         ACP_FASSIGN(default_encrypt_reply);
1016         ACP_FASSIGN(default_sign);
1017         ACP_FASSIGN(default_sign_reply);
1018         ACP_FASSIGN(save_encrypted_as_clear_text);
1019         ACP_FASSIGN(encrypt_to_self);
1020         
1021         /* advanced */
1022         ACP_FASSIGN(set_smtpport);
1023         ACP_FASSIGN(smtpport);
1024         ACP_FASSIGN(set_popport);
1025         ACP_FASSIGN(popport);
1026         ACP_FASSIGN(set_imapport);
1027         ACP_FASSIGN(imapport);
1028         ACP_FASSIGN(set_nntpport);
1029         ACP_FASSIGN(nntpport);
1030         ACP_FASSIGN(set_domain);
1031         ACP_FDUP(domain);
1032         ACP_FASSIGN(mark_crosspost_read);
1033         ACP_FASSIGN(crosspost_col);
1034
1035 #ifndef G_OS_WIN32
1036         ACP_FASSIGN(set_tunnelcmd);
1037         ACP_FDUP(tunnelcmd);
1038 #endif
1039
1040         ACP_FDUP(imap_dir);
1041         ACP_FASSIGN(imap_subsonly);
1042         ACP_FASSIGN(low_bandwidth);
1043
1044         ACP_FASSIGN(set_sent_folder);
1045         ACP_FDUP(sent_folder);
1046         ACP_FASSIGN(set_queue_folder);
1047         ACP_FDUP(queue_folder);
1048         ACP_FASSIGN(set_draft_folder);
1049         ACP_FDUP(draft_folder);
1050         ACP_FASSIGN(set_trash_folder);
1051         ACP_FDUP(trash_folder);
1052         /* don't want two default accounts */
1053         ac_clon->is_default = FALSE;
1054         ACP_FASSIGN(folder);
1055
1056         account_list = g_list_append(account_list, ac_clon);
1057         account_list_view_set();
1058 }
1059 #undef ACP_FDUP
1060 #undef ACP_FASSIGN
1061
1062 static void account_empty_cache(PrefsAccount *ac_prefs)
1063 {
1064         gchar *cache_dir;
1065
1066         cache_dir = prefs_account_cache_dir(ac_prefs, FALSE);
1067         if (cache_dir == NULL)
1068                 return; /* no cache dir, nothing to do */
1069
1070         if (is_dir_exist(cache_dir) && remove_dir_recursive(cache_dir) < 0) {
1071                 g_warning("can't remove directory '%s'", cache_dir);
1072         } else {
1073                 gchar *server_dir =  prefs_account_cache_dir(ac_prefs, TRUE);
1074                 if (g_rmdir(server_dir) == 0)
1075                         debug_print("Removed empty cache server directory\n");
1076                 else
1077                         debug_print("Cache server directory not empty: not removed\n");
1078                 g_free(server_dir);
1079         }
1080         g_free(cache_dir);
1081 }
1082
1083 static void account_delete(GtkWidget *widget, gpointer data)
1084 {
1085         PrefsAccount *ac_prefs;
1086         gchar buf[BUFFSIZE];
1087         GList *list;
1088         Folder *folder;
1089         GSList *cur;
1090
1091         ac_prefs = account_list_view_get_selected_account(edit_account.list_view);
1092         if (ac_prefs == NULL)
1093                 return;
1094
1095         g_snprintf(buf, sizeof(buf),
1096                    _("Do you really want to delete the account '%s'?"),
1097                    ac_prefs->account_name ? ac_prefs->account_name :
1098                    _("(Untitled)"));
1099         if (alertpanel_full(_("Delete account"), buf,
1100                             GTK_STOCK_CANCEL, GTK_STOCK_DELETE, NULL, FALSE,
1101                             NULL, ALERT_WARNING, G_ALERTDEFAULT) != G_ALERTALTERNATE)
1102                 return;
1103         account_list_dirty = TRUE;
1104
1105         if (ac_prefs->folder) {
1106                 FolderItem *item;
1107
1108                 item = mainwindow_get_mainwindow()->summaryview->folder_item;
1109                 if (item && item->folder == FOLDER(ac_prefs->folder))
1110                         summary_clear_all(mainwindow_get_mainwindow()->summaryview);
1111                 folder_destroy(FOLDER(ac_prefs->folder));
1112                 folderview_set_all();
1113         }
1114         account_destroy(ac_prefs);
1115         account_list_view_set();
1116
1117         debug_print("Removing deleted account references for all the folders...\n");
1118         list = folder_get_list();
1119         for (; list != NULL; list = list->next) {
1120                 folder = FOLDER(list->data);
1121                 if (folder->node)  /* && folder->type == F_? */
1122                         g_node_traverse(folder->node, G_PRE_ORDER,
1123                                 G_TRAVERSE_ALL, -1,
1124                                 account_delete_references_func,
1125                                 GINT_TO_POINTER(ac_prefs->account_id));
1126         }
1127
1128         gchar *uid = g_strdup_printf("%d", ac_prefs->account_id);
1129         passwd_store_delete_block(PWS_ACCOUNT, uid);
1130         g_free(uid);
1131
1132         debug_print("Removing filter rules relative to this account...\n");
1133         for(cur = filtering_rules ; cur != NULL ;) {
1134                 FilteringProp * prop = (FilteringProp *) cur->data;
1135
1136                 if (prop && (prop->account_id == ac_prefs->account_id)) {
1137                         /* get next item before we kill the current one */
1138                         cur = g_slist_next(cur);
1139
1140                         /* unallocate filteringprop and unchain it from the list */
1141                         filteringprop_free(prop);
1142                         filtering_rules = g_slist_remove(filtering_rules, prop);
1143                 } else {
1144                         cur = g_slist_next(cur);
1145                 }
1146         }
1147
1148         debug_print("Removing cache directory of this account...\n");
1149         account_empty_cache(ac_prefs);
1150
1151         folder_write_list();
1152 }
1153
1154 static void account_up(GtkWidget *widget, gpointer data)
1155 {
1156         GtkTreePath *sel = account_list_view_get_selected_account_path
1157                                 (edit_account.list_view),
1158                     *up;
1159         GtkTreeIter isel, iup;
1160         GtkTreeModel *model = gtk_tree_view_get_model
1161                                 (GTK_TREE_VIEW(edit_account.list_view));
1162         
1163         if (!sel) 
1164                 return;
1165         account_list_dirty = TRUE;
1166
1167         up = gtk_tree_path_copy(sel);
1168         if (!up) {
1169                 gtk_tree_path_free(sel);
1170                 return;
1171         }
1172
1173         if (!gtk_tree_path_prev(up)) {
1174                 gtk_tree_path_free(up);
1175                 gtk_tree_path_free(sel);
1176                 return;
1177         }
1178
1179         if (!gtk_tree_model_get_iter(model, &isel, sel)
1180         ||  !gtk_tree_model_get_iter(model, &iup,  up)) {
1181                 gtk_tree_path_free(up);
1182                 gtk_tree_path_free(sel);
1183                 return;
1184         }
1185
1186         gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &iup);
1187
1188         account_list_set();
1189         
1190         gtk_tree_path_free(up);
1191         gtk_tree_path_free(sel);
1192 }
1193
1194 static void account_down(GtkWidget *widget, gpointer data)
1195 {
1196         GtkTreePath *sel = account_list_view_get_selected_account_path
1197                                 (edit_account.list_view),
1198                     *dn;
1199         GtkTreeIter isel, idn;
1200         GtkTreeModel *model = gtk_tree_view_get_model
1201                                 (GTK_TREE_VIEW(edit_account.list_view));
1202         
1203         if (!sel) 
1204                 return;
1205         account_list_dirty = TRUE;
1206
1207         dn = gtk_tree_path_copy(sel);
1208         if (!dn) {
1209                 gtk_tree_path_free(sel);
1210                 return;
1211         }
1212
1213         /* XXX no check possible??? however, if down but at bottom, then 
1214          * nothing seems to happen much anyway, so the following seems to 
1215          * be okay */
1216         gtk_tree_path_next(dn);
1217
1218         if (!gtk_tree_model_get_iter(model, &isel, sel)
1219         ||  !gtk_tree_model_get_iter(model, &idn,  dn)) {
1220                 gtk_tree_path_free(dn);
1221                 gtk_tree_path_free(sel);
1222                 return;
1223         }
1224
1225         gtk_list_store_swap(GTK_LIST_STORE(model), &isel, &idn);
1226
1227         account_list_set();
1228         
1229         gtk_tree_path_free(dn);
1230         gtk_tree_path_free(sel);
1231 }
1232
1233 static void account_set_default(GtkWidget *widget, gpointer data)
1234 {
1235         PrefsAccount *ac_prefs;
1236
1237         if (NULL == (ac_prefs = account_list_view_get_selected_account
1238                                         (edit_account.list_view))) 
1239                 return; 
1240
1241         /* we need to change the store variables by resetting everything
1242          * and setting the new default one */
1243         account_list_view_set_default_by_id(edit_account.list_view,
1244                                             ac_prefs->account_id);               
1245         
1246         account_set_as_default(ac_prefs);
1247         account_list_view_set();
1248         
1249         cur_account = ac_prefs;
1250         account_flush_state();
1251 }
1252
1253 static void account_edit_close(GtkWidget *widget, gpointer data)
1254 {
1255         account_list_set();
1256         account_write_config_all();
1257
1258         if (!cur_account && account_list) {
1259                 PrefsAccount *ac_prefs = (PrefsAccount *)account_list->data;
1260                 account_set_as_default(ac_prefs);
1261                 cur_account = ac_prefs;
1262         }
1263
1264         if (account_list_dirty)
1265                 account_flush_state();
1266
1267         gtk_widget_hide(edit_account.window);
1268         gtk_window_set_modal(GTK_WINDOW(edit_account.window), FALSE);
1269         inc_unlock();
1270 }
1271
1272 static gint account_delete_event(GtkWidget *widget, GdkEventAny *event,
1273                                  gpointer data)
1274 {
1275         account_edit_close(NULL, NULL);
1276         return TRUE;
1277 }
1278
1279 static gboolean account_key_pressed(GtkWidget *widget, GdkEventKey *event,
1280                                     gpointer data)
1281 {
1282         if (event && event->keyval == GDK_KEY_Escape)
1283                 account_edit_close(NULL, NULL);
1284         return FALSE;
1285 }
1286
1287 static gboolean account_search_func_cb (GtkTreeModel *model, gint column, const gchar *key, 
1288                                                 GtkTreeIter *iter, gpointer search_data) 
1289 {
1290         gboolean retval;
1291         PrefsAccount *ac;
1292
1293         gtk_tree_model_get (model, iter, ACCOUNT_DATA, &ac, -1);
1294
1295         if (!ac->name || !key) return FALSE;
1296
1297         retval = (strncmp (key, ac->account_name, strlen(key)) != 0);
1298
1299         debug_print("selecting row\n");
1300         account_list_view_select_account(edit_account.list_view, ac->account_id);
1301
1302         return retval;
1303 }
1304 static void account_list_view_add(PrefsAccount *ac_prefs)
1305 {
1306         GtkTreeView *list_view = GTK_TREE_VIEW(edit_account.list_view);
1307         GtkListStore *list_store = GTK_LIST_STORE(gtk_tree_view_get_model(list_view));
1308         gchar *name, *protocol, *server;
1309         gboolean has_getallbox;
1310         gboolean getall;
1311
1312         name = ac_prefs->account_name;
1313 #ifdef USE_GNUTLS
1314         protocol = ac_prefs->protocol == A_POP3 ?
1315                   (ac_prefs->ssl_pop == SSL_TUNNEL ?
1316                    "POP (SSL/TLS)" :
1317                    ac_prefs->ssl_pop == SSL_STARTTLS ?
1318                    "POP (STARTTLS)" : "POP") :
1319                    ac_prefs->protocol == A_IMAP4 ?
1320                   (ac_prefs->ssl_imap == SSL_TUNNEL ?
1321                    "IMAP (SSL/TLS)" :
1322                    ac_prefs->ssl_imap == SSL_STARTTLS ?
1323                    "IMAP (STARTTLS)" : "IMAP") :
1324                    ac_prefs->protocol == A_NNTP ?
1325                   (ac_prefs->ssl_nntp == SSL_TUNNEL ?
1326                    "NNTP (SSL/TLS)" : "NNTP") :
1327                    ac_prefs->protocol == A_LOCAL ? "Local" :
1328                    ac_prefs->protocol == A_NONE ?  "SMTP" : "-";
1329 #else
1330         protocol = ac_prefs->protocol == A_POP3  ? "POP" :
1331                    ac_prefs->protocol == A_IMAP4 ? "IMAP" :
1332                    ac_prefs->protocol == A_LOCAL ? "Local" :
1333                    ac_prefs->protocol == A_NNTP  ? "NNTP" :
1334                    ac_prefs->protocol == A_NONE ?  "SMTP" : "-";
1335 #endif
1336         server= ac_prefs->protocol == A_NNTP ? ac_prefs->nntp_server :
1337                    ac_prefs->protocol == A_LOCAL ?  "-" :
1338                    ac_prefs->protocol == A_NONE ? ac_prefs->smtp_server :
1339                    ac_prefs->recv_server;
1340
1341         has_getallbox = (ac_prefs->protocol == A_POP3  ||
1342                          ac_prefs->protocol == A_IMAP4 ||
1343                          ac_prefs->protocol == A_NNTP  ||
1344                          ac_prefs->protocol == A_LOCAL);
1345         getall = has_getallbox && ac_prefs->recv_at_getall;
1346
1347         account_list_view_insert_account_item(list_store,
1348                                              name, protocol, server,
1349                                              ac_prefs->is_default,
1350                                              getall, ac_prefs);
1351         return;
1352 }
1353
1354 static void account_list_view_set(void)
1355 {
1356         GList *cur;
1357         gint prev_sel_account;
1358         GtkListStore *store;
1359         
1360         store = GTK_LIST_STORE(gtk_tree_view_get_model
1361                 (GTK_TREE_VIEW(edit_account.list_view)));
1362
1363         prev_sel_account = account_list_view_get_selected_account_id
1364                 (edit_account.list_view); 
1365
1366         gtk_list_store_clear(store);
1367         
1368         for (cur = account_list; cur != NULL; cur = cur->next) {
1369                 account_list_view_add((PrefsAccount *)cur->data);
1370                 if ((PrefsAccount *)cur->data == cur_account)
1371                         account_list_view_select_account
1372                                 (edit_account.list_view, 
1373                                  cur_account->account_id);
1374         }
1375         
1376         if (prev_sel_account >= 0)
1377                 account_list_view_select_account(edit_account.list_view, 
1378                                                  prev_sel_account); 
1379 }
1380
1381 /* set account list from CList */
1382 static void account_list_set(void)
1383 {
1384         /* want to make sure we iterate *IN ORDER*, so therefore using
1385          * gtk_tree_model_XXXX_nth_child() */
1386         gint row, n_rows;
1387         PrefsAccount *ac_prefs;
1388         GtkTreeModel *model = gtk_tree_view_get_model
1389                                 (GTK_TREE_VIEW(edit_account.list_view));
1390         
1391         while (account_list)
1392                 account_list = g_list_remove(account_list, account_list->data);
1393
1394         n_rows = gtk_tree_model_iter_n_children(model, NULL);
1395
1396         for (row = 0; row < n_rows; row++) {
1397                 GtkTreeIter iter;
1398
1399                 if (!gtk_tree_model_iter_nth_child(model, &iter, NULL, row)) {
1400                         g_warning("%s(%d) - no iter found???", __FILE__, __LINE__);
1401                         continue;
1402                 }
1403         
1404                 ac_prefs = NULL;
1405                 gtk_tree_model_get(model, &iter,
1406                                    ACCOUNT_DATA, &ac_prefs,
1407                                    -1);
1408                 if (ac_prefs)
1409                         account_list = g_list_append(account_list, ac_prefs);
1410         }
1411 }
1412
1413 /*!
1414  *\brief        finds the PrefsAccounts which should be used to answer a mail
1415  *
1416  *\param        msginfo The message to be answered
1417  *\param        reply_autosel Indicates whether reply account autoselection is on
1418  *
1419  *\return       PrefsAccount * the correct account, NULL if not found
1420  */
1421 PrefsAccount *account_get_reply_account(MsgInfo *msginfo, gboolean reply_autosel)
1422 {
1423         PrefsAccount *account = NULL;
1424         /* select the account set in folderitem's property (if enabled) */
1425         if (msginfo->folder->prefs && msginfo->folder->prefs->enable_default_account)
1426                 account = account_find_from_id(msginfo->folder->prefs->default_account);
1427         else if (folder_has_parent_of_type(msginfo->folder, F_QUEUE) ||
1428                  folder_has_parent_of_type(msginfo->folder, F_OUTBOX) ||
1429                  folder_has_parent_of_type(msginfo->folder, F_DRAFT)) {
1430                         gchar *from = NULL;
1431                         if (!procheader_get_header_from_msginfo
1432                                 (msginfo, &from, "From:")) {
1433                                 gchar *buf = from + strlen("From:");
1434                                 extract_address(buf);
1435                                 account = account_find_from_address(buf, FALSE);
1436                         g_free(from);
1437                         }
1438         }
1439         /* select account by to: and cc: header if enabled */
1440         if (reply_autosel) {
1441                 gchar * field = NULL;
1442                 int fieldno = 0;
1443                 for (field = msginfo->to; fieldno++ < 2; field = msginfo->cc) {
1444                         if (!account && field) {
1445                                 gchar *f = g_strdup(field);
1446                                 if (f) {
1447                                         gchar *cur = f;
1448                                         gchar *next = NULL;
1449                                         gchar *to = NULL;
1450                                         do {
1451                                                 next = strchr_with_skip_quote(cur, '"', ',');
1452                                                 if (next)
1453                                                         (*next) = 0;
1454                                                 Xstrdup_a(to, cur, return NULL);
1455                                                 extract_address(to);
1456                                                 account = account_find_from_address(to, FALSE);
1457                                                 if (next)
1458                                                         cur = next + 1;
1459                                                 else
1460                                                         break;
1461                                         } while (!account);
1462                                         g_free(f);
1463                                 }
1464                         }
1465                 }
1466                 if (!account) {
1467                         gchar *deliveredto = NULL;
1468                         if (!procheader_get_header_from_msginfo
1469                                 (msginfo, &deliveredto, "Delivered-To:")) {
1470                                 gchar *buf = deliveredto + strlen("Delivered-To:");
1471                                 extract_address(buf);
1472                                 account = account_find_from_address(buf, FALSE);
1473                         g_free(deliveredto);
1474                         }
1475                 }
1476         }
1477
1478         /* select the account for the whole folder (IMAP / NNTP) */
1479         if (!account) 
1480                 /* FIXME: this is not right, because folder may be nested. we should
1481                  * ascend the tree until we find a parent with proper account 
1482                  * information */
1483                 account = msginfo->folder->folder->account;
1484
1485         /* select current account */
1486         if (!account) account = cur_account;
1487         
1488         return account;
1489 }
1490
1491 /*!
1492  *\brief        Create data store
1493  */
1494 static GtkListStore* account_create_data_store(void)
1495 {
1496         return gtk_list_store_new(N_ACCOUNT_COLUMNS,
1497                                  G_TYPE_INT,            /* ACCOUNT_IS_DEFAULT */
1498                                  G_TYPE_BOOLEAN,        /* ACCOUNT_ENABLE_GET_ALL */
1499                                  G_TYPE_STRING,         /* ACCOUNT_NAME */
1500                                  G_TYPE_STRING,         /* ACCOUNT_PROTOCOL */
1501                                  G_TYPE_STRING,         /* ACCOUNT_SERVER */
1502                                  G_TYPE_POINTER,        /* ACCOUNT_DATA */
1503                                  -1);
1504 }
1505
1506 /*!
1507  *\brief        Insert an account item in the list. 
1508  *
1509  *\return       GtkTreeRowReference * A tree row reference, which is guaranteed to 
1510  *              stable whatever operations are performed on the list.
1511  */
1512 static void account_list_view_insert_account_item(GtkListStore *list_store, 
1513                                                   const gchar *account_name,
1514                                                   const gchar *protocol, 
1515                                                   const gchar *server_name,
1516                                                   gboolean is_default, 
1517                                                   gboolean is_get_all,
1518                                                   PrefsAccount *account_data)
1519 {
1520         GtkTreeIter iter;
1521         
1522         gtk_list_store_append(list_store, &iter);
1523         gtk_list_store_set(list_store, &iter, 
1524                            ACCOUNT_IS_DEFAULT,     is_default ? PANGO_WEIGHT_BOLD : PANGO_WEIGHT_NORMAL,
1525                            ACCOUNT_ENABLE_GET_ALL, is_get_all,
1526                            ACCOUNT_NAME,           account_name,
1527                            ACCOUNT_PROTOCOL,       protocol,
1528                            ACCOUNT_SERVER,         server_name,
1529                            ACCOUNT_DATA,           account_data,
1530                            -1);
1531 }
1532
1533 /*!
1534  *\brief        Create and set up account list view, including tasks like
1535  *              creating the data store (\ref account_create_data_store()),
1536  *              and setting up the account list's individual columns (\ref 
1537  *              account_create_list_view_columns()).
1538  *
1539  *\return       GtkWidget * The created list view widget.
1540  */
1541 static GtkWidget *account_list_view_create(void)
1542 {
1543         GtkTreeView *list_view;
1544         GtkTreeSelection *selector;
1545         GtkListStore *store = account_create_data_store();
1546
1547         list_view = GTK_TREE_VIEW(gtk_tree_view_new_with_model(GTK_TREE_MODEL(store)));
1548         g_object_unref(G_OBJECT(store));
1549 #ifdef GENERIC_UMPC
1550         g_object_set(list_view, "allow-checkbox-mode", FALSE, NULL);
1551 #endif
1552         gtk_tree_view_set_rules_hint(list_view, prefs_common.use_stripes_everywhere);
1553         gtk_tree_view_set_reorderable(list_view, TRUE);
1554         
1555         selector = gtk_tree_view_get_selection(list_view);
1556         gtk_tree_selection_set_mode(selector, GTK_SELECTION_BROWSE);
1557
1558         /* create the columns */
1559         account_create_list_view_columns(GTK_WIDGET(list_view));
1560
1561         /* set a double click listener */
1562         g_signal_connect(G_OBJECT(list_view), "row_activated",
1563                          G_CALLBACK(account_double_clicked),
1564                          list_view);
1565
1566         g_signal_connect(G_OBJECT(list_view), "drag_begin",                      
1567                          G_CALLBACK(drag_begin),
1568                          list_view);
1569                          
1570         g_signal_connect(G_OBJECT(list_view), "drag_end",                        
1571                          G_CALLBACK(drag_end),
1572                          list_view);
1573                          
1574         gtk_tree_view_set_reorderable(list_view, TRUE);
1575         return GTK_WIDGET(list_view);
1576 }
1577
1578 static void account_create_list_view_columns(GtkWidget *list_view)
1579 {
1580         GtkTreeViewColumn *column;
1581         GtkCellRenderer *renderer;
1582
1583         renderer = gtk_cell_renderer_toggle_new();
1584         g_object_set(renderer, 
1585                      "radio", FALSE, 
1586                      "activatable", TRUE,
1587                       NULL);
1588         column = gtk_tree_view_column_new_with_attributes
1589                 (C_("Accounts List Get Column Name", "G"), renderer,
1590                  "active", ACCOUNT_ENABLE_GET_ALL,
1591                  NULL);
1592         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
1593         gtk_tree_view_column_set_alignment (column, 0.5);
1594         CLAWS_SET_TIP(gtk_tree_view_column_get_widget(column),
1595                         _("'Get Mail' retrieves mail from the checked accounts"));
1596         g_signal_connect(G_OBJECT(renderer), "toggled",                      
1597                          G_CALLBACK(account_get_all_toggled),
1598                          list_view);
1599
1600         renderer = gtk_cell_renderer_text_new();
1601         column = gtk_tree_view_column_new_with_attributes
1602                 (_("Name"), renderer,
1603                  "text", ACCOUNT_NAME,
1604                  "weight", ACCOUNT_IS_DEFAULT,
1605                  NULL);
1606         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);          
1607         
1608         renderer = gtk_cell_renderer_text_new();
1609         column = gtk_tree_view_column_new_with_attributes
1610                 (_("Protocol"), renderer,
1611                  "text", ACCOUNT_PROTOCOL,
1612                  "weight", ACCOUNT_IS_DEFAULT,
1613                  NULL);
1614         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);           
1615         
1616         renderer = gtk_cell_renderer_text_new();
1617         column = gtk_tree_view_column_new_with_attributes
1618                 (_("Server"), renderer,
1619                  "text", ACCOUNT_SERVER,
1620                  "weight", ACCOUNT_IS_DEFAULT,
1621                  NULL);
1622         gtk_tree_view_set_search_column(GTK_TREE_VIEW(list_view), ACCOUNT_NAME);
1623         gtk_tree_view_set_search_equal_func(GTK_TREE_VIEW(list_view), account_search_func_cb , NULL, NULL);
1624         gtk_tree_view_append_column(GTK_TREE_VIEW(list_view), column);           
1625 }
1626
1627 /*!
1628  *\brief        Get currently selected account (by its unique ID)
1629  */
1630 static gint account_list_view_get_selected_account_id(GtkWidget *list_view)
1631 {
1632         GtkTreeSelection *selector;
1633         GtkTreeModel *model;
1634         GtkTreeIter iter;
1635         PrefsAccount *res = NULL;
1636
1637         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1638         
1639         if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1640                 return -1;
1641
1642         gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
1643
1644         return res->account_id;                    
1645 }
1646
1647 /*!
1648  *\brief        Get the tree path of the currently selected account
1649  */
1650 static GtkTreePath *account_list_view_get_selected_account_path(GtkWidget *list_view)
1651 {
1652         GtkTreeSelection *selector;
1653         GtkTreeModel *model;
1654         GtkTreeIter iter;
1655
1656         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1657         
1658         if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1659                 return NULL;
1660
1661         return gtk_tree_model_get_path(gtk_tree_view_get_model
1662                 (GTK_TREE_VIEW(list_view)), &iter);
1663 }
1664
1665 /*!
1666  *\brief        Get the account data of the currently selected account
1667  */
1668 static PrefsAccount *account_list_view_get_selected_account(GtkWidget *list_view)
1669 {
1670         GtkTreeSelection *selector;
1671         GtkTreeModel *model;
1672         GtkTreeIter iter;
1673         PrefsAccount *res = NULL;
1674
1675         selector = gtk_tree_view_get_selection(GTK_TREE_VIEW(list_view));
1676         
1677         if (!gtk_tree_selection_get_selected(selector, &model, &iter))
1678                 return NULL;
1679
1680         gtk_tree_model_get(model, &iter, ACCOUNT_DATA, &res, -1);
1681
1682         return res;                        
1683 }
1684
1685 /*!
1686  *\brief        Select a row by the account it represents
1687  *
1688  *\return       gboolean TRUE if found and selected, FALSE if not.
1689  */
1690 static gboolean account_list_view_select_account(GtkWidget *list_view, gint account_id)
1691 {
1692         FindAccountInStore fis;
1693         GtkTreeModel *model;
1694         
1695         fis.account_id = account_id;
1696         fis.path = NULL;
1697
1698         model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1699
1700         gtk_tree_model_foreach(model, (GtkTreeModelForeachFunc) find_account_in_store,
1701                                &fis);
1702                                
1703         if (fis.path) {
1704                 GtkTreeSelection *selection;
1705                 GtkTreePath* path;
1706
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);
1713         }
1714
1715         return fis.path != NULL;
1716 }
1717
1718 /*!
1719  *\brief        Set a new default account by its ID. (There is only one
1720  *              default account.)
1721  */
1722 static void account_list_view_set_default_by_id(GtkWidget *list_view,
1723                                                 gint account_id)
1724 {
1725         GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1726         
1727         gtk_tree_model_foreach
1728                 (model, (GtkTreeModelForeachFunc) set_new_default_account,
1729                  &account_id);
1730 }
1731
1732 static gboolean set_new_default_account(GtkTreeModel *model,
1733                                         GtkTreePath  *path,
1734                                         GtkTreeIter  *iter,
1735                                         gint         *account_id)
1736 {
1737         PrefsAccount *account = NULL;
1738         PangoWeight weight;
1739         
1740         gtk_tree_model_get(model, iter, 
1741                            ACCOUNT_DATA, &account, 
1742                            -1);
1743
1744         if (*account_id == account->account_id)
1745                 weight = PANGO_WEIGHT_NORMAL;
1746         else
1747                 weight = PANGO_WEIGHT_BOLD;
1748
1749         gtk_list_store_set(GTK_LIST_STORE(model), iter, 
1750                            ACCOUNT_IS_DEFAULT, weight, -1);
1751
1752         return FALSE;
1753 }
1754                                         
1755 static gboolean find_account_in_store(GtkTreeModel *model,
1756                                       GtkTreePath  *path,
1757                                       GtkTreeIter  *iter,
1758                                       FindAccountInStore *data)
1759 {
1760         PrefsAccount *account = NULL;
1761         gtk_tree_model_get(model, iter, ACCOUNT_DATA, &account, -1);
1762
1763         if (data->account_id == account->account_id) {
1764                 data->path = path; /* signal we found it */
1765                 data->iter = *iter;
1766                 return TRUE;
1767         }
1768
1769         return FALSE; 
1770 }
1771
1772 /*!
1773  *\brief        Triggered when "get all" column is activated or de-activated
1774  */
1775 static void account_get_all_toggled(GtkCellRendererToggle *widget, 
1776                                     gchar *path, 
1777                                     GtkWidget *list_view)
1778 {
1779         GtkTreeIter iter;
1780         GtkTreeModel *model = gtk_tree_view_get_model(GTK_TREE_VIEW(list_view));
1781         PrefsAccount *ac = NULL;
1782         gboolean get_all;
1783         
1784         if (!gtk_tree_model_get_iter_from_string(model, &iter, path))
1785                 return;
1786
1787         gtk_tree_model_get(model, &iter, 
1788                            ACCOUNT_DATA, &ac,
1789                            ACCOUNT_ENABLE_GET_ALL, &get_all,
1790                            -1);
1791
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))
1797                 return;       
1798
1799         /* set value in store */
1800         gtk_list_store_set(GTK_LIST_STORE(model), &iter,
1801                            ACCOUNT_ENABLE_GET_ALL, !get_all,
1802                            -1);
1803
1804         /* set value in account */
1805         ac->recv_at_getall ^= TRUE;
1806 }
1807
1808 static void account_double_clicked(GtkTreeView          *list_view,
1809                                    GtkTreePath          *path,
1810                                    GtkTreeViewColumn    *column,
1811                                    gpointer              data)
1812 {
1813         account_edit_prefs(NULL, NULL); 
1814 }
1815
1816 static void drag_begin(GtkTreeView *list_view,
1817                       GdkDragContext *context,
1818                       gpointer data)
1819 {
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 */
1824
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),
1828                          list_view);
1829 }
1830
1831 static void drag_end(GtkTreeView *list_view,
1832                     GdkDragContext *context,
1833                     gpointer data)
1834 {
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),
1838                                              list_view);
1839 }
1840
1841 static void account_row_changed_while_drag_drop(GtkTreeModel *model, 
1842                                    GtkTreePath  *path,
1843                                    GtkTreeIter  *iter,
1844                                    gpointer      arg3,
1845                                    GtkTreeView  *list_view)
1846 {       
1847         account_list_set();     
1848 }
1849
1850 gchar *account_get_signature_str(PrefsAccount *account)
1851 {
1852         gchar *sig_body = NULL;
1853         gchar *sig_str = NULL;
1854         gchar *utf8_sig_str = NULL;
1855
1856         cm_return_val_if_fail(account != NULL, NULL);
1857
1858         if (!account->sig_path)
1859                 return NULL;
1860
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);
1865                 } else {
1866                         sig_full_path = g_strdup(account->sig_path);
1867                 }
1868
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);
1872                         return NULL;
1873                 }
1874
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);
1878
1879                 if (!tmp)
1880                         return NULL;
1881
1882                 sig_body = normalize_newlines(tmp);
1883                 g_free(tmp);
1884         } else {
1885                 sig_body = get_command_output(account->sig_path);
1886         }
1887
1888         if (account->sig_sep) {
1889                 sig_str = g_strconcat("\n", account->sig_sep, "\n", sig_body,
1890                                       NULL);
1891                 g_free(sig_body);
1892         } else
1893                 sig_str = g_strconcat("\n", sig_body, NULL);
1894
1895         if (sig_str) {
1896                 if (g_utf8_validate(sig_str, -1, NULL) == TRUE)
1897                         utf8_sig_str = sig_str;
1898                 else {
1899                         utf8_sig_str = conv_codeset_strdup
1900                                 (sig_str, conv_get_locale_charset_str_no_utf8(),
1901                                  CS_INTERNAL);
1902                         g_free(sig_str);
1903                 }
1904         }
1905
1906         return utf8_sig_str;
1907 }
1908
1909 PrefsAccount *account_get_cur_account (void)
1910 {
1911         return cur_account;
1912 }
1913
1914 gboolean password_get(const gchar *user,
1915                     const gchar *server,
1916                     const gchar *protocol,
1917                     guint16 port,
1918                     gchar **password)
1919 {
1920         PasswordRequest req;
1921
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);
1927
1928         req.user = user;
1929         req.server = server;
1930         req.protocol = protocol;
1931         req.port = port;
1932
1933         if (hooks_invoke(PASSWORD_GET_HOOKLIST, &req)) {
1934                 *password = req.password;
1935                 return TRUE;
1936         }
1937         return FALSE;
1938 }