2006-09-27 [wwp] 2.5.2cvs9
[claws.git] / src / inc.c
index 371cb1758c8ebd2dd10f2544ced3da76dd4c3946..c86a6c59864f2fc4bcd977ea9e04a02a659b4f5d 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -50,6 +50,7 @@
 #include "utils.h"
 #include "gtkutils.h"
 #include "statusbar.h"
+#include "msgcache.h"
 #include "manage_window.h"
 #include "stock_pixmap.h"
 #include "progressdialog.h"
@@ -122,7 +123,8 @@ static gint inc_dialog_delete_cb    (GtkWidget      *widget,
                                         gpointer        data);
 
 static gint get_spool                  (FolderItem     *dest,
-                                        const gchar    *mbox);
+                                        const gchar    *mbox,
+                                        PrefsAccount   *account);
 
 static gint inc_spool_account(PrefsAccount *account);
 static gint inc_all_spool(void);
@@ -360,10 +362,20 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
        inc_autocheck_timer_set();
 }
 
+static void inc_progress_dialog_size_allocate_cb(GtkWidget *widget,
+                                        GtkAllocation *allocation)
+{
+       g_return_if_fail(allocation != NULL);
+
+       prefs_common.receivewin_width = allocation->width;
+       prefs_common.receivewin_height = allocation->height;
+}
+
 static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
 {
        IncProgressDialog *dialog;
        ProgressDialog *progress;
+       static GdkGeometry geometry;
 
        dialog = g_new0(IncProgressDialog, 1);
 
@@ -374,7 +386,9 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
                         G_CALLBACK(inc_cancel_cb), dialog);
        g_signal_connect(G_OBJECT(progress->window), "delete_event",
                         G_CALLBACK(inc_dialog_delete_cb), dialog);
-       /* manage_window_set_transient(GTK_WINDOW(progress->window)); */
+       g_signal_connect(G_OBJECT(progress->window), "size_allocate",
+                        G_CALLBACK(inc_progress_dialog_size_allocate_cb), NULL);
+       /* manage_window_set_transient(GTK_WINDOW(progress->window)); */
 
        progress_dialog_get_fraction(progress);
 
@@ -385,6 +399,16 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
        stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_ERROR,
                         &errorpix);
 
+       if (!geometry.min_height) {
+               geometry.min_width = 460;
+               geometry.min_height = 250;
+       }
+
+       gtk_window_set_geometry_hints(GTK_WINDOW(progress->window), NULL, &geometry,
+                                     GDK_HINT_MIN_SIZE);
+       gtk_widget_set_size_request(progress->window, prefs_common.receivewin_width,
+                                   prefs_common.receivewin_height);
+
        if (prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS ||
            (prefs_common.recv_dialog_mode == RECV_DIALOG_MANUAL &&
             !autocheck)) {
@@ -487,7 +511,6 @@ static gint inc_start(IncProgressDialog *inc_dialog)
        gchar *msg;
        gchar *fin_msg;
        FolderItem *processing, *inbox;
-       MsgInfo *msginfo;
        GSList *msglist, *msglist_element;
        gboolean cancelled = FALSE;
 
@@ -541,9 +564,9 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 }
 
        for (; inc_dialog->queue_list != NULL && !cancelled; inc_dialog->cur_row++) {
-               int cur = 0, total = 0;
                session = inc_dialog->queue_list->data;
                pop3_session = POP3_SESSION(session->session);
+               GSList *filtered, *unfiltered;
 
                if (pop3_session->pass == NULL) {
                        SET_PIXMAP_AND_TEXT(okpix, _("Cancelled"));
@@ -629,25 +652,16 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 
                /* process messages */
                folder_item_update_freeze();
-               if (pop3_session->ac_prefs->filter_on_recv)
-                       statusbar_print_all(_("Filtering messages...\n"));
-               total = g_slist_length(msglist);
-
-               for(msglist_element = msglist; msglist_element != NULL; 
-                   msglist_element = msglist_element->next) {
-                       gchar *filename;
-                       msginfo = (MsgInfo *) msglist_element->data;
-                       filename = folder_item_fetch_msg(processing, msginfo->msgnum);
-                       g_free(filename);
+               
+               procmsg_msglist_filter(msglist, pop3_session->ac_prefs, 
+                               &filtered, &unfiltered, 
+                               pop3_session->ac_prefs->filter_on_recv);
 
-                       if (pop3_session->ac_prefs->filter_on_recv)
-                               statusbar_progress_all(cur++,total, prefs_common.statusbar_update_step);
+               if (filtered != NULL)
+                       filtering_move_and_copy_msgs(filtered);
+               if (unfiltered != NULL)
+                       folder_item_move_msgs(inbox, unfiltered);
 
-                       if (!pop3_session->ac_prefs->filter_on_recv || 
-                           !procmsg_msginfo_filter(msginfo))
-                               folder_item_move_msg(inbox, msginfo);
-               }
-               filtering_move_and_copy_msgs(msglist);
                for(msglist_element = msglist; msglist_element != NULL; 
                    msglist_element = msglist_element->next) {
                        MsgInfo *msginfo = (MsgInfo *)msglist_element->data;
@@ -655,10 +669,9 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                }
                folder_item_update_thaw();
                
-               statusbar_progress_all(0,0,0);
-               statusbar_pop_all();
-
                g_slist_free(msglist);
+               g_slist_free(filtered);
+               g_slist_free(unfiltered);
 
                statusbar_pop_all();
 
@@ -687,6 +700,7 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                            inc_state == INC_IO_ERROR)
                                break;
                }
+               folder_item_free_cache(processing, TRUE);
 
                inc_session_destroy(session);
                inc_dialog->queue_list =
@@ -761,10 +775,9 @@ static IncState inc_pop3_session_do(IncSession *session)
                          "Do you want to continue connecting to this "
                          "server? The communication would not be "
                          "secure."),
-                         _("Con_tinue connecting"), 
-                         GTK_STOCK_CANCEL, NULL,
-                         FALSE, NULL, ALERT_WARNING,
-                         G_ALERTALTERNATE) != G_ALERTDEFAULT)
+                         GTK_STOCK_CANCEL, _("Con_tinue connecting"), 
+                         NULL, FALSE, NULL, ALERT_WARNING,
+                         G_ALERTDEFAULT) != G_ALERTALTERNATE)
                        return INC_CANCEL;
        }
        port = pop3_session->ac_prefs->set_popport ?
@@ -772,17 +785,17 @@ static IncState inc_pop3_session_do(IncSession *session)
 #endif
 
        buf = g_strdup_printf(_("Connecting to POP3 server: %s..."), server);
+       statusbar_print_all("%s", buf);
        log_message("%s\n", buf);
 
        progress_dialog_set_label(inc_dialog->dialog, buf);
+       GTK_EVENTS_FLUSH();
        g_free(buf);
 
        session_set_timeout(SESSION(pop3_session),
                            prefs_common.io_timeout_secs * 1000);
-
+       
        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_MANUAL) && focus_window)) {
@@ -791,6 +804,9 @@ static IncState inc_pop3_session_do(IncSession *session)
                        alertpanel_error(_("Can't connect to POP3 server: %s:%d"),
                                         server, port);
                        manage_window_focus_out(inc_dialog->dialog->window, NULL, NULL);
+               } else {
+                       log_error(_("Can't connect to POP3 server: %s:%d\n"),
+                           server, port);
                }
                session->inc_state = INC_CONNECT_ERROR;
                statusbar_pop_all();
@@ -870,6 +886,7 @@ 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_pop_all();
                statusbar_print_all(_("Retrieving messages from %s (%s) ..."),
                                    SESSION(session)->server,
                                    session->ac_prefs->account_name);
@@ -927,7 +944,7 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
        }
 
        progress_dialog_set_fraction
-               (inc_dialog->dialog,(gfloat)cur_total / (gfloat)total);
+               (inc_dialog->dialog, (total == 0) ? 0: (gfloat)cur_total / (gfloat)total);
 
        g_snprintf(buf, sizeof(buf), "%d / %d",
                   pop3_session->cur_msg, pop3_session->count);
@@ -935,7 +952,7 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
                (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar), buf);
        gtk_progress_bar_set_fraction
                (GTK_PROGRESS_BAR(inc_dialog->mainwin->progressbar),
-                (gfloat)cur_total / (gfloat)total);
+                (total == 0) ? 0 : (gfloat)cur_total / (gfloat)total);
 
        if (pop3_session->cur_total_num > 0) {
                g_snprintf(buf, sizeof(buf),
@@ -1096,6 +1113,7 @@ static void inc_put_error(IncState istate, Pop3Session *session)
        switch (istate) {
        case INC_CONNECT_ERROR:
                log_msg = _("Connection failed.");
+               fatal_error = TRUE;
                if (prefs_common.no_recv_err_panel)
                        break;
                err_msg = g_strdup_printf(_("Connection to %s:%d failed."),
@@ -1104,6 +1122,7 @@ static void inc_put_error(IncState istate, Pop3Session *session)
                break;
        case INC_ERROR:
                log_msg = _("Error occurred while processing mail.");
+               fatal_error = TRUE;
                if (prefs_common.no_recv_err_panel)
                        break;
                if (session->error_msg)
@@ -1151,6 +1170,7 @@ static void inc_put_error(IncState istate, Pop3Session *session)
                break;
        case INC_AUTH_FAILED:
                log_msg = _("Authentication failed.");
+               fatal_error = TRUE;
                if (prefs_common.no_recv_err_panel)
                        break;
                if (session->error_msg)
@@ -1177,6 +1197,9 @@ static void inc_put_error(IncState istate, Pop3Session *session)
                else
                        log_warning("%s\n", log_msg);
        }
+       if (prefs_common.no_recv_err_panel && fatal_error)
+               mainwindow_show_error();
+
        if (err_msg) {
                alertpanel_error_log(err_msg);
                g_free(err_msg);
@@ -1254,7 +1277,7 @@ static gint inc_spool_account(PrefsAccount *account)
                return -1;
        }
        
-       result = get_spool(inbox, mbox);
+       result = get_spool(inbox, mbox, account);
        g_free(mbox);
        
        statusbar_pop_all();
@@ -1285,7 +1308,7 @@ static gint inc_all_spool(void)
        return new_msgs;
 }
 
-static gint get_spool(FolderItem *dest, const gchar *mbox)
+static gint get_spool(FolderItem *dest, const gchar *mbox, PrefsAccount *account)
 {
        gint msgs, size;
        gint lockfd;
@@ -1314,7 +1337,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, TRUE);
+       msgs = proc_mbox(dest, tmp_mbox, TRUE, account);
 
        g_unlink(tmp_mbox);
        if (msgs >= 0) empty_mbox(mbox);