sync with 0.9.10cvs11
[claws.git] / src / inc.c
index 6595a1a2b59b0a53b6351229df60d5350b51341f..9f541bb3f1daf53c038a9c419f796873ac040bf4 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -1,6 +1,6 @@
 /*
  * Sylpheed -- a GTK+ based, lightweight, and fast e-mail client
- * Copyright (C) 1999-2003 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2004 Hiroyuki Yamamoto
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -32,6 +32,7 @@
 #include <unistd.h>
 #include <string.h>
 #include <time.h>
+#include <sys/time.h>
 #include <sys/types.h>
 #include <sys/stat.h>
 #include <sys/wait.h>
@@ -81,10 +82,11 @@ static GdkBitmap *okxpmmask;
 
 static void inc_finished               (MainWindow             *mainwin,
                                         gboolean                new_messages);
-static gint inc_account_mail           (PrefsAccount           *account,
-                                        MainWindow             *mainwin);
+static gint inc_account_mail_real      (MainWindow             *mainwin,
+                                        PrefsAccount           *account);
 
-static IncProgressDialog *inc_progress_dialog_create   (void);
+static IncProgressDialog *inc_progress_dialog_create
+                                       (gboolean                autocheck);
 static void inc_progress_dialog_set_list(IncProgressDialog     *inc_dialog);
 static void inc_progress_dialog_destroy        (IncProgressDialog      *inc_dialog);
 
@@ -93,9 +95,25 @@ static void inc_session_destroy              (IncSession             *session);
 static gint inc_start                  (IncProgressDialog      *inc_dialog);
 static IncState inc_pop3_session_do    (IncSession             *session);
 
+static void inc_progress_dialog_update (IncProgressDialog      *inc_dialog,
+                                        IncSession             *inc_session);
+
 static void inc_progress_dialog_set_label
                                        (IncProgressDialog      *inc_dialog,
                                         IncSession             *inc_session);
+static void inc_progress_dialog_set_progress
+                                       (IncProgressDialog      *inc_dialog,
+                                        IncSession             *inc_session);
+
+static void inc_update_folderview      (IncProgressDialog      *inc_dialog,
+                                        IncSession             *inc_session);
+
+static void inc_progress_dialog_update_periodic
+                                       (IncProgressDialog      *inc_dialog,
+                                        IncSession             *inc_session);
+static void inc_update_folderview_periodic
+                                       (IncProgressDialog      *inc_dialog,
+                                        IncSession             *inc_session);
 
 static gint inc_recv_data_progressive  (Session        *session,
                                         guint           cur_len,
@@ -107,6 +125,8 @@ static gint inc_recv_data_finished  (Session        *session,
 static gint inc_recv_message           (Session        *session,
                                         const gchar    *msg,
                                         gpointer        data);
+static gint inc_drop_message           (Pop3Session    *session,
+                                        const gchar    *file);
 
 static void inc_put_error              (IncState        istate,
                                         const gchar    *msg);
@@ -117,7 +137,6 @@ static gint inc_dialog_delete_cb    (GtkWidget      *widget,
                                         GdkEventAny    *event,
                                         gpointer        data);
 
-static gint inc_spool                  (void);
 static gint get_spool                  (FolderItem     *dest,
                                         const gchar    *mbox);
 
@@ -151,6 +170,8 @@ static void inc_finished(MainWindow *mainwin, gboolean new_messages)
                item = cur_account && cur_account->inbox
                        ? folder_find_item_from_identifier(cur_account->inbox)
                        : folder_get_default_inbox();
+               folderview_unselect(mainwin->folderview);
+               folderview_select(mainwin->folderview, item);
        }
 }
 
@@ -178,20 +199,8 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
                        inc_autocheck_timer_set();
                        return;
                }
-
-               if (prefs_common.inc_local) {
-                       account_new_msgs = inc_spool();
-                       if (account_new_msgs > 0)
-                               new_msgs += account_new_msgs;
-               }
        } else {
-               if (prefs_common.inc_local) {
-                       account_new_msgs = inc_spool();
-                       if (account_new_msgs > 0)
-                               new_msgs += account_new_msgs;
-               }
-
-               account_new_msgs = inc_account_mail(cur_account, mainwin);
+               account_new_msgs = inc_account_mail_real(mainwin, cur_account);
                if (account_new_msgs > 0)
                        new_msgs += account_new_msgs;
        }
@@ -206,10 +215,10 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
 void inc_pop_before_smtp(PrefsAccount *acc)
 {
        /* FIXME: assumes to attach to first main window */
-       inc_account_mail(acc, mainwindow_get_mainwindow());
+       inc_account_mail(mainwindow_get_mainwindow(), acc);
 }
 
-static gint inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
+static gint inc_account_mail_real(MainWindow *mainwin, PrefsAccount *account)
 {
        IncProgressDialog *inc_dialog;
        IncSession *session;
@@ -233,7 +242,7 @@ static gint inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
                session = inc_session_new(account);
                if (!session) return 0;
                
-               inc_dialog = inc_progress_dialog_create();
+               inc_dialog = inc_progress_dialog_create(FALSE);
                inc_dialog->queue_list = g_list_append(inc_dialog->queue_list,
                                                       session);
                inc_dialog->mainwin = mainwin;
@@ -255,7 +264,32 @@ static gint inc_account_mail(PrefsAccount *account, MainWindow *mainwin)
        return 0;
 }
 
-void inc_all_account_mail(MainWindow *mainwin, gboolean notify)
+gint inc_account_mail(MainWindow *mainwin, PrefsAccount *account)
+{
+       gint new_msgs;
+
+       if (inc_lock_count) return 0;
+
+       if (prefs_common.work_offline)
+               if (alertpanel(_("Offline warning"), 
+                              _("You're working offline. Override?"),
+                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+               return;
+
+       inc_autocheck_timer_remove();
+       main_window_lock(mainwin);
+
+       new_msgs = inc_account_mail_real(mainwin, account);
+
+       inc_finished(mainwin, new_msgs > 0);
+       main_window_unlock(mainwin);
+       inc_autocheck_timer_set();
+
+       return new_msgs;
+}
+
+void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
+                         gboolean notify)
 {
        GList *list, *queue_list = NULL;
        IncProgressDialog *inc_dialog;
@@ -273,12 +307,6 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean notify)
        inc_autocheck_timer_remove();
        main_window_lock(mainwin);
 
-       if (prefs_common.inc_local) {
-               account_new_msgs = inc_spool();
-               if (account_new_msgs > 0)
-                       new_msgs += account_new_msgs;   
-       }
-
        list = account_get_list();
        if (!list) {
                inc_finished(mainwin, new_msgs > 0);
@@ -322,7 +350,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean notify)
                return;
        }
 
-       inc_dialog = inc_progress_dialog_create();
+       inc_dialog = inc_progress_dialog_create(autocheck);
        inc_dialog->queue_list = queue_list;
        inc_dialog->mainwin = mainwin;
        inc_progress_dialog_set_list(inc_dialog);
@@ -337,7 +365,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean notify)
        inc_autocheck_timer_set();
 }
 
-static IncProgressDialog *inc_progress_dialog_create(void)
+static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
 {
        IncProgressDialog *dialog;
        ProgressDialog *progress;
@@ -363,13 +391,15 @@ static IncProgressDialog *inc_progress_dialog_create(void)
                         &errorxpm, &errorxpmmask);
 
        if (prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS ||
-           (prefs_common.recv_dialog_mode == RECV_DIALOG_ACTIVE &&
-            manage_window_get_focus_window())) {
+           (prefs_common.recv_dialog_mode == RECV_DIALOG_MANUAL &&
+            !autocheck)) {
                dialog->show_dialog = TRUE;
                gtk_widget_show_now(progress->window);
        }
 
        dialog->dialog = progress;
+       gettimeofday(&dialog->progress_tv, NULL);
+       gettimeofday(&dialog->folder_tv, NULL);
        dialog->queue_list = NULL;
        dialog->cur_row = 0;
 
@@ -401,10 +431,7 @@ static void inc_progress_dialog_clear(IncProgressDialog *inc_dialog)
        progress_dialog_set_value(inc_dialog->dialog, 0.0);
        progress_dialog_set_label(inc_dialog->dialog, "");
        if (inc_dialog->mainwin)
-               gtk_progress_set_show_text
-                       (GTK_PROGRESS(inc_dialog->mainwin->progressbar), FALSE);
-       gtk_progress_bar_update
-               (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar), 0.0);
+               main_window_progress_off(inc_dialog->mainwin);
 }
 
 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
@@ -414,11 +441,7 @@ static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
        inc_dialog_list = g_list_remove(inc_dialog_list, inc_dialog);
 
        if (inc_dialog->mainwin)
-               gtk_progress_set_show_text
-                       (GTK_PROGRESS(inc_dialog->mainwin->progressbar), FALSE);
-       gtk_progress_bar_update
-               (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar), 0.0);
-
+               main_window_progress_off(inc_dialog->mainwin);
        progress_dialog_destroy(inc_dialog->dialog);
 
        g_free(inc_dialog);
@@ -436,8 +459,20 @@ static IncSession *inc_session_new(PrefsAccount *account)
                return NULL;
 
        session = g_new0(IncSession, 1);
+
        session->session = pop3_session_new(account);
        session->session->data = session;
+       POP3_SESSION(session->session)->drop_message = inc_drop_message;
+       session_set_recv_message_notify(session->session,
+                                       inc_recv_message, session);
+       session_set_recv_data_progressive_notify(session->session,
+                                                inc_recv_data_progressive,
+                                                session);
+       session_set_recv_data_notify(session->session,
+                                    inc_recv_data_finished, session);
+
+       session->folder_table = g_hash_table_new(NULL, NULL);
+       session->tmp_folder_table = g_hash_table_new(NULL, NULL);
 
        return session;
 }
@@ -447,6 +482,8 @@ static void inc_session_destroy(IncSession *session)
        g_return_if_fail(session != NULL);
 
        session_destroy(session->session);
+       g_hash_table_destroy(session->folder_table);
+       g_hash_table_destroy(session->tmp_folder_table);
        g_free(session);
 }
 
@@ -529,13 +566,6 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                SET_PIXMAP_AND_TEXT(currentxpm, currentxpmmask,
                                    _("Retrieving"));
 
-               session_set_recv_message_notify(session->session,
-                                               inc_recv_message, session);
-               session_set_recv_data_progressive_notify
-                       (session->session, inc_recv_data_progressive, session);
-               session_set_recv_data_notify(session->session,
-                                            inc_recv_data_finished, session);
-
                /* begin POP3 session */
                inc_state = inc_pop3_session_do(session);
 
@@ -580,13 +610,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                if (pop3_session->error_val == PS_AUTHFAIL) {
                        if(!prefs_common.no_recv_err_panel) {
                                if((prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS) ||
-                                   ((prefs_common.recv_dialog_mode == RECV_DIALOG_ACTIVE) && focus_window)) {
+                                   ((prefs_common.recv_dialog_mode == RECV_DIALOG_MANUAL) && focus_window))
                                        manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
-                               }
-                               alertpanel_error
-                                       (_("Authorization for %s on %s failed"),
-                                        pop3_session->user,
-                                        pop3_session->ac_prefs->recv_server);
                        }
                }
 
@@ -605,8 +630,6 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                folder_item_scan(processing);
                msglist = folder_item_get_msg_list(processing);
 
-               folder_item_update_freeze();
-
                /* process messages */
                for(msglist_element = msglist; msglist_element != NULL; msglist_element = msglist_element->next) {
                        msginfo = (MsgInfo *) msglist_element->data;
@@ -616,8 +639,6 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                }
                g_slist_free(msglist);
 
-               folder_item_update_thaw();
-
                statusbar_pop_all();
 
                new_msgs += pop3_session->cur_total_num;
@@ -680,7 +701,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                        g_list_remove(inc_dialog->queue_list, session);
        }
 
-       if (prefs_common.close_recv_dialog)
+       if (prefs_common.close_recv_dialog || !inc_dialog->show_dialog)
                inc_progress_dialog_destroy(inc_dialog);
        else {
                gtk_window_set_title(GTK_WINDOW(inc_dialog->dialog->window),
@@ -737,7 +758,7 @@ static IncState inc_pop3_session_do(IncSession *session)
                            server, port);
                if(!prefs_common.no_recv_err_panel) {
                        if((prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS) ||
-                           ((prefs_common.recv_dialog_mode == RECV_DIALOG_ACTIVE) && focus_window)) {
+                           ((prefs_common.recv_dialog_mode == RECV_DIALOG_MANUAL) && focus_window)) {
                                manage_window_focus_in(inc_dialog->dialog->window, NULL, NULL);
                        }
                        alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
@@ -789,10 +810,16 @@ static IncState inc_pop3_session_do(IncSession *session)
        return session->inc_state;
 }
 
+static void inc_progress_dialog_update(IncProgressDialog *inc_dialog,
+                                      IncSession *inc_session)
+{
+       inc_progress_dialog_set_label(inc_dialog, inc_session);
+       inc_progress_dialog_set_progress(inc_dialog, inc_session);
+}
+
 static void inc_progress_dialog_set_label(IncProgressDialog *inc_dialog,
                                          IncSession *inc_session)
 {
-       gchar buf[MSGBUFSIZE];
        ProgressDialog *dialog = inc_dialog->dialog;
        Pop3Session *session;
 
@@ -807,8 +834,9 @@ static void inc_progress_dialog_set_label(IncProgressDialog *inc_dialog,
        case POP3_GETAUTH_PASS:
        case POP3_GETAUTH_APOP:
                progress_dialog_set_label(dialog, _("Authenticating..."));
-               statusbar_print_all(_("Retrieving messages from %s..."),
-                                   SESSION(session)->server);
+               statusbar_print_all(_("Retrieving messages from %s (%s) ..."),
+                                   SESSION(session)->server,
+                                   session->ac_prefs->account_name);
                break;
        case POP3_GETRANGE_STAT:
                progress_dialog_set_label
@@ -827,24 +855,18 @@ static void inc_progress_dialog_set_label(IncProgressDialog *inc_dialog,
                        (dialog, _("Getting the size of messages (LIST)..."));
                break;
        case POP3_RETR:
-               gtk_progress_set_show_text
-                       (GTK_PROGRESS(inc_dialog->mainwin->progressbar), TRUE);
-               g_snprintf(buf, sizeof(buf), "%d / %d",
-                          session->cur_msg, session->count);
-               gtk_progress_set_format_string
-                       (GTK_PROGRESS(inc_dialog->mainwin->progressbar), buf);
-               inc_recv_data_progressive
-                       (SESSION(session), 0,
-                        session->msg[session->cur_msg].size,
-                        inc_session);
+       case POP3_RETR_RECV:
                break;
        case POP3_DELETE:
+#if 0
                if (session->msg[session->cur_msg].recv_time <
                        session->current_time) {
+                       gchar buf[MSGBUFSIZE];
                        g_snprintf(buf, sizeof(buf), _("Deleting message %d"),
                                   session->cur_msg);
                        progress_dialog_set_label(dialog, buf);
                }
+#endif
                break;
        case POP3_LOGOUT:
                progress_dialog_set_label(dialog, _("Quitting"));
@@ -854,16 +876,125 @@ static void inc_progress_dialog_set_label(IncProgressDialog *inc_dialog,
        }
 }
 
+static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
+                                            IncSession *inc_session)
+{
+       gchar buf[MSGBUFSIZE];
+       Pop3Session *pop3_session = POP3_SESSION(inc_session->session);
+       gchar *total_size_str;
+       gint cur_total;
+       gint total;
+
+       if (!pop3_session->new_msg_exist) return;
+
+       cur_total = inc_session->cur_total_bytes;
+       total = pop3_session->total_bytes;
+       if (pop3_session->state == POP3_RETR ||
+           pop3_session->state == POP3_RETR_RECV ||
+           pop3_session->state == POP3_DELETE) {
+               Xstrdup_a(total_size_str, to_human_readable(total), return);
+               g_snprintf(buf, sizeof(buf),
+                          _("Retrieving message (%d / %d) (%s / %s)"),
+                          pop3_session->cur_msg, pop3_session->count,
+                          to_human_readable(cur_total), total_size_str);
+               progress_dialog_set_label(inc_dialog->dialog, buf);
+       }
+
+       progress_dialog_set_percentage
+               (inc_dialog->dialog,(gfloat)cur_total / (gfloat)total);
+
+       gtk_progress_set_show_text
+               (GTK_PROGRESS(inc_dialog->mainwin->progressbar), TRUE);
+       g_snprintf(buf, sizeof(buf), "%d / %d",
+                  pop3_session->cur_msg, pop3_session->count);
+       gtk_progress_set_format_string
+               (GTK_PROGRESS(inc_dialog->mainwin->progressbar), buf);
+       gtk_progress_bar_update
+               (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar),
+                (gfloat)cur_total / (gfloat)total);
+
+       if (pop3_session->cur_total_num > 0) {
+               g_snprintf(buf, sizeof(buf),
+                          _("Retrieving (%d message(s) (%s) received)"),
+                          pop3_session->cur_total_num,
+                          to_human_readable
+                          (pop3_session->cur_total_recv_bytes));
+               gtk_clist_set_text(GTK_CLIST(inc_dialog->dialog->clist),
+                                  inc_dialog->cur_row, 2, buf);
+       }
+}
+
+static gboolean hash_remove_func(gpointer key, gpointer value, gpointer data)
+{
+       return TRUE;
+}
+
+static void inc_update_folderview(IncProgressDialog *inc_dialog,
+                                 IncSession *inc_session)
+{
+       if (g_hash_table_size(inc_session->tmp_folder_table) > 0) {
+               folderview_update_item_foreach(inc_session->tmp_folder_table,
+                                              FALSE);
+               g_hash_table_foreach_remove(inc_session->tmp_folder_table,
+                                           hash_remove_func, NULL);
+       }
+}
+
+static void inc_progress_dialog_update_periodic(IncProgressDialog *inc_dialog,
+                                               IncSession *inc_session)
+{
+       struct timeval tv_cur;
+       struct timeval tv_result;
+       gint msec;
+
+       gettimeofday(&tv_cur, NULL);
+
+       tv_result.tv_sec = tv_cur.tv_sec - inc_dialog->progress_tv.tv_sec;
+       tv_result.tv_usec = tv_cur.tv_usec - inc_dialog->progress_tv.tv_usec;
+       if (tv_result.tv_usec < 0) {
+               tv_result.tv_sec--;
+               tv_result.tv_usec += 1000000;
+       }
+
+       msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
+       if (msec > PROGRESS_UPDATE_INTERVAL) {
+               inc_progress_dialog_update(inc_dialog, inc_session);
+               inc_dialog->progress_tv.tv_sec = tv_cur.tv_sec;
+               inc_dialog->progress_tv.tv_usec = tv_cur.tv_usec;
+       }
+}
+
+static void inc_update_folderview_periodic(IncProgressDialog *inc_dialog,
+                                          IncSession *inc_session)
+{
+       struct timeval tv_cur;
+       struct timeval tv_result;
+       gint msec;
+
+       gettimeofday(&tv_cur, NULL);
+
+       tv_result.tv_sec = tv_cur.tv_sec - inc_dialog->folder_tv.tv_sec;
+       tv_result.tv_usec = tv_cur.tv_usec - inc_dialog->folder_tv.tv_usec;
+       if (tv_result.tv_usec < 0) {
+               tv_result.tv_sec--;
+               tv_result.tv_usec += 1000000;
+       }
+
+       msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
+       if (msec > FOLDER_UPDATE_INTERVAL) {
+               inc_update_folderview(inc_dialog, inc_session);
+               inc_dialog->folder_tv.tv_sec = tv_cur.tv_sec;
+               inc_dialog->folder_tv.tv_usec = tv_cur.tv_usec;
+       }
+}
+
 static gint inc_recv_data_progressive(Session *session, guint cur_len,
                                      guint total_len, gpointer data)
 {
-       gchar buf[MSGBUFSIZE];
        IncSession *inc_session = (IncSession *)data;
        Pop3Session *pop3_session = POP3_SESSION(session);
        IncProgressDialog *inc_dialog;
-       ProgressDialog *dialog;
        gint cur_total;
-       gchar *total_size;
 
        g_return_val_if_fail(inc_session != NULL, -1);
 
@@ -874,26 +1005,14 @@ static gint inc_recv_data_progressive(Session *session, guint cur_len,
 
        if (!pop3_session->new_msg_exist) return 0;
 
-       inc_dialog = (IncProgressDialog *)inc_session->data;
-       dialog = inc_dialog->dialog;
-
        cur_total = pop3_session->cur_total_bytes + cur_len;
        if (cur_total > pop3_session->total_bytes)
                cur_total = pop3_session->total_bytes;
+       inc_session->cur_total_bytes = cur_total;
 
-       Xstrdup_a(total_size, to_human_readable(pop3_session->total_bytes),
-                 return FALSE);
-       g_snprintf(buf, sizeof(buf),
-                  _("Retrieving message (%d / %d) (%s / %s)"),
-                  pop3_session->cur_msg, pop3_session->count,
-                  to_human_readable(cur_total), total_size);
-       progress_dialog_set_label(dialog, buf);
-       progress_dialog_set_percentage
-               (dialog, (gfloat)cur_total / (gfloat)pop3_session->total_bytes);
-       if (inc_dialog->mainwin)
-               gtk_progress_bar_update
-                       (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar),
-                        (gfloat)cur_total / (gfloat)pop3_session->total_bytes);
+       inc_dialog = (IncProgressDialog *)inc_session->data;
+       inc_progress_dialog_update_periodic(inc_dialog, inc_session);
+       inc_update_folderview_periodic(inc_dialog, inc_session);
 
        return 0;
 }
@@ -901,25 +1020,18 @@ static gint inc_recv_data_progressive(Session *session, guint cur_len,
 static gint inc_recv_data_finished(Session *session, guint len, gpointer data)
 {
        IncSession *inc_session = (IncSession *)data;
-       Pop3Session *pop3_session = POP3_SESSION(session);
        IncProgressDialog *inc_dialog;
-       gchar *msg;
 
        g_return_val_if_fail(inc_session != NULL, -1);
 
        inc_dialog = (IncProgressDialog *)inc_session->data;
-       inc_recv_data_progressive(session, 0, len, inc_session);
-       inc_progress_dialog_set_label(inc_dialog, inc_session);
 
-       if (pop3_session->cur_total_num == 0) return 0;
+       inc_recv_data_progressive(session, 0, 0, inc_session);
 
-       msg = g_strdup_printf(_("Retrieving (%d message(s) (%s) received)"),
-                             pop3_session->cur_total_num,
-                             to_human_readable
-                               (pop3_session->cur_total_recv_bytes));
-       gtk_clist_set_text(GTK_CLIST(inc_dialog->dialog->clist),
-                          inc_dialog->cur_row, 2, msg);
-       g_free(msg);                       
+       if (POP3_SESSION(session)->state == POP3_LOGOUT) {
+               inc_progress_dialog_update(inc_dialog, inc_session);
+               inc_update_folderview(inc_dialog, inc_session);
+       }
 
        return 0;
 }
@@ -932,16 +1044,40 @@ static gint inc_recv_message(Session *session, const gchar *msg, gpointer data)
        g_return_val_if_fail(inc_session != NULL, -1);
 
        inc_dialog = (IncProgressDialog *)inc_session->data;
-       inc_progress_dialog_set_label(inc_dialog, inc_session);
+
+       switch (POP3_SESSION(session)->state) {
+       case POP3_GETAUTH_USER:
+       case POP3_GETAUTH_PASS:
+       case POP3_GETAUTH_APOP:
+       case POP3_GETRANGE_STAT:
+       case POP3_GETRANGE_LAST:
+       case POP3_GETRANGE_UIDL:
+       case POP3_GETSIZE_LIST:
+               inc_progress_dialog_update(inc_dialog, inc_session);
+               break;
+       case POP3_RETR:
+               inc_recv_data_progressive(session, 0, 0, inc_session);
+               break;
+       case POP3_LOGOUT:
+               inc_progress_dialog_update(inc_dialog, inc_session);
+               inc_update_folderview(inc_dialog, inc_session);
+               break;
+       default:
+               break;
+       }
 
        return 0;
 }
 
-gint inc_drop_message(const gchar *file, Pop3Session *session)
+static gint inc_drop_message(Pop3Session *session, const gchar *file)
 {
        FolderItem *inbox;
        FolderItem *dropfolder;
+       IncSession *inc_session = (IncSession *)(SESSION(session)->data);
        gint msgnum;
+       gint val;
+
+       g_return_val_if_fail(inc_session != NULL, -1);
 
        if (session->ac_prefs->inbox) {
                inbox = folder_find_item_from_identifier
@@ -1096,24 +1232,13 @@ static gint inc_dialog_delete_cb(GtkWidget *widget, GdkEventAny *event,
        return TRUE;
 }
 
-static gint inc_spool(void)
+static gint inc_spool_account(PrefsAccount *account)
 {
+       FolderItem *inbox;
        gchar *mbox, *logname;
-       gint msgs;
+       gint result;
 
        logname = g_get_user_name();
-       mbox = g_strconcat(prefs_common.spool_path
-                          ? prefs_common.spool_path : DEFAULT_SPOOL_PATH,
-                          G_DIR_SEPARATOR_S, logname, NULL);
-       msgs = get_spool(folder_get_default_inbox(), mbox);
-       g_free(mbox);
-
-       return msgs;
-}
-
-static gint inc_spool_account(PrefsAccount *account)
-{
-       FolderItem *inbox;
 
        if (account->inbox) {
                inbox = folder_find_item_from_path(account->inbox);
@@ -1122,7 +1247,18 @@ static gint inc_spool_account(PrefsAccount *account)
        } else
                inbox = folder_get_default_inbox();
 
-       return get_spool(inbox, account->local_mbox);
+       if (is_file_exist(account->local_mbox))
+               mbox = g_strdup(account->local_mbox);
+       else 
+               mbox = g_strconcat(account->local_mbox,
+                                  G_DIR_SEPARATOR_S, logname, NULL);
+       
+       result = get_spool(inbox, mbox);
+       g_free(mbox);
+       
+       statusbar_pop_all();
+       
+       return result;
 }
 
 static gint inc_all_spool(void)
@@ -1177,7 +1313,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
        debug_print("Getting new messages from %s into %s...\n",
                    mbox, dest->path);
 
-       msgs = proc_mbox(dest, tmp_mbox);
+       msgs = proc_mbox(dest, tmp_mbox, TRUE);
 
        unlink(tmp_mbox);
        if (msgs >= 0) empty_mbox(mbox);
@@ -1263,7 +1399,7 @@ static gint inc_autocheck_func(gpointer data)
                return FALSE;
        }
 
-       inc_all_account_mail(mainwin, prefs_common.newmail_notify_auto);
+       inc_all_account_mail(mainwin, TRUE, prefs_common.newmail_notify_auto);
 
        return FALSE;
 }