revise 'translatable string' policy
[claws.git] / src / inc.c
index 47ab46cc9ce97d22e7da01c1d11fedc2cb2a4752..7b9e33d4325487d26dcf92fb47d50944b958855b 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
@@ -81,10 +81,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 +94,22 @@ 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_timer_start            (IncProgressDialog      *inc_dialog,
+                                        IncSession             *inc_session);
+static void inc_timer_stop             (IncProgressDialog      *inc_dialog);
+
+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 gint inc_progress_timer_func    (gpointer        data);
+static gint inc_folder_timer_func      (gpointer        data);
 
 static gint inc_recv_data_progressive  (Session        *session,
                                         guint           cur_len,
@@ -107,6 +121,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 +133,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);
 
@@ -128,10 +143,6 @@ static gint inc_autocheck_func                     (gpointer        data);
 
 static void inc_notify_cmd             (gint new_msgs, 
                                         gboolean notify);
-
-#define FOLDER_SUMMARY_MISMATCH(f, s) \
-       (f) && (s) ? ((s)->newmsgs != (f)->new_msgs) || ((f)->unread_msgs != (s)->unread) || ((f)->total_msgs != (s)->messages) \
-       : FALSE
        
 /**
  * inc_finished:
@@ -155,10 +166,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();
-               if (FOLDER_SUMMARY_MISMATCH(item, mainwin->summaryview)) {      
-                       folderview_unselect(mainwin->folderview);
-                       folderview_select(mainwin->folderview, item);
-               }       
+               folderview_unselect(mainwin->folderview);
+               folderview_select(mainwin->folderview, item);
        }
 }
 
@@ -186,20 +195,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;
        }
@@ -213,10 +210,11 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
 
 void inc_pop_before_smtp(PrefsAccount *acc)
 {
-       inc_account_mail(acc, NULL);
+       /* FIXME: assumes to attach to first main window */
+       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;
@@ -240,7 +238,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;
@@ -262,7 +260,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;
@@ -280,12 +303,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);
@@ -329,7 +346,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);
@@ -344,7 +361,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;
@@ -370,13 +387,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;
+       dialog->progress_timer_id = 0;
+       dialog->folder_timer_id = 0;
        dialog->queue_list = NULL;
        dialog->cur_row = 0;
 
@@ -407,12 +426,8 @@ 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_bar_update
-                       (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar), 0.0);
-               gtk_progress_set_show_text
-                       (GTK_PROGRESS(inc_dialog->mainwin->progressbar), FALSE);
-       }
+       if (inc_dialog->mainwin)
+               main_window_progress_off(inc_dialog->mainwin);
 }
 
 static void inc_progress_dialog_destroy(IncProgressDialog *inc_dialog)
@@ -421,12 +436,8 @@ 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);
-       }
+       if (inc_dialog->mainwin)
+               main_window_progress_off(inc_dialog->mainwin);
        progress_dialog_destroy(inc_dialog->dialog);
 
        g_free(inc_dialog);
@@ -444,8 +455,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;
 }
@@ -455,6 +478,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);
 }
 
@@ -537,13 +562,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);
 
@@ -575,6 +593,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                case INC_NO_SPACE:
                case INC_IO_ERROR:
                case INC_SOCKET_ERROR:
+               case INC_EOF:
                        SET_PIXMAP_AND_TEXT(errorxpm, errorxpmmask, _("Error"));
                        break;
                case INC_CANCEL:
@@ -587,13 +606,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);
                        }
                }
 
@@ -612,8 +626,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;
@@ -623,8 +635,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;
@@ -687,7 +697,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),
@@ -738,15 +748,13 @@ static IncState inc_pop3_session_do(IncSession *session)
 
        progress_dialog_set_label(inc_dialog->dialog, buf);
        g_free(buf);
-       GTK_EVENTS_FLUSH();
-
 
        if (session_connect(SESSION(pop3_session), server, port) < 0) {
                log_warning(_("Can't connect to POP3 server: %s:%d\n"),
                            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"),
@@ -758,11 +766,11 @@ static IncState inc_pop3_session_do(IncSession *session)
                return INC_CONNECT_ERROR;
        }
 
-       while (SESSION(pop3_session)->state != SESSION_DISCONNECTED &&
-              SESSION(pop3_session)->state != SESSION_ERROR &&
+       while (session_is_connected(SESSION(pop3_session)) &&
               session->inc_state != INC_CANCEL)
                gtk_main_iteration();
 
+       inc_timer_stop(inc_dialog);
        statusbar_pop_all();
 
        if (session->inc_state == INC_SUCCESS) {
@@ -773,7 +781,9 @@ static IncState inc_pop3_session_do(IncSession *session)
                                        session->inc_state = INC_CONNECT_ERROR;
                                else
                                        session->inc_state = INC_ERROR;
-                       } else
+                       } else if (SESSION(pop3_session)->state == SESSION_EOF)
+                               session->inc_state = INC_EOF;
+                       else
                                session->inc_state = INC_SUCCESS;
                        break;
                case PS_AUTHFAIL:
@@ -797,6 +807,40 @@ static IncState inc_pop3_session_do(IncSession *session)
        return session->inc_state;
 }
 
+static void inc_timer_start(IncProgressDialog *inc_dialog,
+                           IncSession *inc_session)
+{
+       if (inc_dialog->progress_timer_id == 0) {
+               inc_dialog->progress_timer_id =
+                       gtk_timeout_add(PROGRESS_UPDATE_INTERVAL,
+                                       inc_progress_timer_func, inc_session);
+       }
+       if (inc_dialog->folder_timer_id == 0) {
+               inc_dialog->folder_timer_id =
+                       gtk_timeout_add(FOLDER_UPDATE_INTERVAL,
+                                       inc_folder_timer_func, inc_session);
+       }
+}
+
+static void inc_timer_stop(IncProgressDialog *inc_dialog)
+{
+       if (inc_dialog->progress_timer_id) {
+               gtk_timeout_remove(inc_dialog->progress_timer_id);
+               inc_dialog->progress_timer_id = 0;
+       }
+       if (inc_dialog->folder_timer_id) {
+               gtk_timeout_remove(inc_dialog->folder_timer_id);
+               inc_dialog->folder_timer_id = 0;
+       }
+}
+
+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)
 {
@@ -835,16 +879,7 @@ 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 (session->msg[session->cur_msg].recv_time <
@@ -862,16 +897,93 @@ 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) {
+               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 gint inc_progress_timer_func(gpointer data)
+{
+       IncSession *inc_session = (IncSession *)data;
+       IncProgressDialog *inc_dialog;
+
+       inc_dialog = (IncProgressDialog *)inc_session->data;
+
+       inc_progress_dialog_update(inc_dialog, inc_session);
+
+       return TRUE;
+}
+
+static gint inc_folder_timer_func(gpointer data)
+{
+       IncSession *inc_session = (IncSession *)data;
+       IncProgressDialog *inc_dialog;
+
+       inc_dialog = (IncProgressDialog *)inc_session->data;
+
+       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);
+       }
+
+       return TRUE;
+}
+
 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);
 
@@ -882,27 +994,10 @@ 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;
-
-       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);
-       GTK_EVENTS_FLUSH();
+       inc_session->cur_total_bytes = cur_total;
 
        return 0;
 }
@@ -910,24 +1005,25 @@ 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);
+       inc_recv_data_progressive(session, 0, 0, inc_session);
 
-       if (pop3_session->cur_total_num == 0) return 0;
-
-       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);
+       if (POP3_SESSION(session)->state == POP3_RETR) {
+               if (inc_dialog->progress_timer_id == 0) {
+                       inc_timer_start(inc_dialog, inc_session);
+                       inc_progress_dialog_update(inc_dialog, inc_session);
+               }
+       } else if (POP3_SESSION(session)->state == POP3_LOGOUT) {
+               inc_progress_dialog_update(inc_dialog, inc_session);
+               if (inc_dialog->progress_timer_id) {
+                       inc_folder_timer_func(data);
+                       inc_timer_stop(inc_dialog);
+               }
+       }
 
        return 0;
 }
@@ -940,16 +1036,48 @@ 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);
+               if (inc_dialog->progress_timer_id == 0) {
+                       inc_timer_start(inc_dialog, inc_session);
+                       inc_progress_dialog_update(inc_dialog, inc_session);
+               }
+               break;
+       case POP3_LOGOUT:
+               inc_progress_dialog_update(inc_dialog, inc_session);
+               if (inc_dialog->progress_timer_id) {
+                       inc_folder_timer_func(data);
+                       inc_timer_stop(inc_dialog);
+               }
+               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);
+       IncProgressDialog *inc_dialog;
        gint msgnum;
+       gint val;
+
+       g_return_val_if_fail(inc_session != NULL, -1);
 
        if (session->ac_prefs->inbox) {
                inbox = folder_find_item_from_identifier
@@ -967,61 +1095,96 @@ gint inc_drop_message(const gchar *file, Pop3Session *session)
        dropfolder = folder_get_default_processing();
 
        /* add msg file to drop folder */
-       if ((msgnum = folder_item_add_msg(dropfolder, file, TRUE)) < 0) {
+       if ((msgnum = folder_item_add_msg(dropfolder, file, NULL, TRUE)) < 0) {
                unlink(file);
                return -1;
        }
 
+       inc_dialog = (IncProgressDialog *)inc_session->data;
+
        return 0;
 }
 
 static void inc_put_error(IncState istate, const gchar *msg)
 {
+       gchar *log_msg = NULL;
+       gchar *err_msg = NULL;
+       gboolean fatal_error = FALSE;
+
        switch (istate) {
        case INC_CONNECT_ERROR:
+               log_msg = _("Connection failed.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               alertpanel_error(_("Connection failed."));
+               err_msg = g_strdup(log_msg);
                break;
        case INC_ERROR:
+               log_msg = _("Error occurred while processing mail.");
                if (prefs_common.no_recv_err_panel)
                        break;
                if (msg)
-                       alertpanel_error(_("Error occurred while processing mail:\n%s"), msg);
+                       err_msg = g_strdup_printf
+                               (_("Error occurred while processing mail:\n%s"),
+                                msg);
                else
-                       alertpanel_error(_("Error occurred while processing mail."));
+                       err_msg = g_strdup(log_msg);
                break;
        case INC_NO_SPACE:
-               alertpanel_error(_("No disk space left."));
+               log_msg = _("No disk space left.");
+               err_msg = g_strdup(log_msg);
+               fatal_error = TRUE;
                break;
        case INC_IO_ERROR:
-               alertpanel_error(_("Can't write file."));
+               log_msg = _("Can't write file.");
+               err_msg = g_strdup(log_msg);
+               fatal_error = TRUE;
                break;
        case INC_SOCKET_ERROR:
+               log_msg = _("Socket error.");
+               if (prefs_common.no_recv_err_panel)
+                       break;
+               err_msg = g_strdup(log_msg);
+               break;
+       case INC_EOF:
+               log_msg = _("Connection closed by the remote host.");
                if (prefs_common.no_recv_err_panel)
                        break;
-               alertpanel_error(_("Socket error."));
+               err_msg = g_strdup(log_msg);
                break;
        case INC_LOCKED:
+               log_msg = _("Mailbox is locked.");
                if (prefs_common.no_recv_err_panel)
                        break;
                if (msg)
-                       alertpanel_error(_("Mailbox is locked:\n%s"), msg);
+                       err_msg = g_strdup_printf(_("Mailbox is locked:\n%s"),
+                                                 msg);
                else
-                       alertpanel_error(_("Mailbox is locked."));
+                       err_msg = g_strdup(log_msg);
                break;
        case INC_AUTH_FAILED:
+               log_msg = _("Authentication failed.");
                if (prefs_common.no_recv_err_panel)
                        break;
                if (msg)
-                       alertpanel_error(_("Authentication failed:\n%s"),
-                                        msg);
+                       err_msg = g_strdup_printf
+                               (_("Authentication failed:\n%s"), msg);
                else
-                       alertpanel_error(_("Authentication failed."));
+                       err_msg = g_strdup(log_msg);
                break;
        default:
                break;
        }
+
+       if (log_msg) {
+               if (fatal_error)
+                       log_error("%s\n", log_msg);
+               else
+                       log_warning("%s\n", log_msg);
+       }
+       if (err_msg) {
+               alertpanel_error_log(err_msg);
+               g_free(err_msg);
+       }
 }
 
 static void inc_cancel(IncProgressDialog *dialog)
@@ -1071,24 +1234,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);
@@ -1097,7 +1249,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)
@@ -1152,7 +1315,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);
@@ -1238,7 +1401,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;
 }