fix 'pop before smtp' timeout
[claws.git] / src / inc.c
index c59b7a3f5179d27336668ce1b69e7ec557e5c1e9..32a6263292b305ec2c45a2a1b67342f7fbf6c2db 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-2002 Hiroyuki Yamamoto
+ * Copyright (C) 1999-2003 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
@@ -103,7 +103,8 @@ static gint inc_recv_message                (Session        *session,
                                         const gchar    *msg,
                                         gpointer        data);
 
-static void inc_put_error              (IncState        istate);
+static void inc_put_error              (IncState        istate,
+                                        const gchar    *msg);
 
 static void inc_cancel_cb              (GtkWidget      *widget,
                                         gpointer        data);
@@ -124,7 +125,7 @@ static void inc_notify_cmd          (gint new_msgs,
                                         gboolean notify);
 
 #define FOLDER_SUMMARY_MISMATCH(f, s) \
-       (f) && (s) ? ((s)->newmsgs != (f)->new) || ((f)->unread != (s)->unread) || ((f)->total != (s)->messages) \
+       (f) && (s) ? ((s)->newmsgs != (f)->new_msgs) || ((f)->unread_msgs != (s)->unread) || ((f)->total_msgs != (s)->messages) \
        : FALSE
        
 /**
@@ -192,7 +193,7 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
                        if (account_new_msgs > 0)
                                new_msgs += account_new_msgs;
                }
-               cur_account->session = STYPE_NORMAL;
+
                account_new_msgs = inc_account_mail(cur_account, mainwin);
                if (account_new_msgs > 0)
                        new_msgs += account_new_msgs;
@@ -207,7 +208,6 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
 
 void inc_pop_before_smtp(PrefsAccount *acc)
 {
-       acc->session = STYPE_POP_BEFORE_SMTP;
        inc_account_mail(acc, NULL);
 }
 
@@ -314,7 +314,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean notify)
        for (list = account_get_list(); list != NULL; list = list->next) {
                IncSession *session;
                PrefsAccount *account = list->data;
-               account->session = STYPE_NORMAL;
+
                if (account->recv_at_getall) {
                        session = inc_session_new(account);
                        if (session)
@@ -582,20 +582,9 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 
                /* process messages */
                for(msglist_element = msglist; msglist_element != NULL; msglist_element = msglist_element->next) {
-                       MailFilteringData mail_filtering_data;
                        msginfo = (MsgInfo *) msglist_element->data;
-                       
-                       mail_filtering_data.msginfo = msginfo;
-                       
-                       if (!hooks_invoke(MAIL_FILTERING_HOOKLIST, &mail_filtering_data)) {
-                               /* filter if enabled in prefs or move to inbox if not */
-                               if(global_processing && pop3_session->ac_prefs->filter_on_recv) {
-                                       filter_message_by_msginfo_with_inbox(global_processing, msginfo,
-                                                                            inbox);
-                               } else {
-                                       folder_item_move_msg(inbox, msginfo);
-                               }
-                       }
+                       if (!pop3_session->ac_prefs->filter_on_recv || !procmsg_msginfo_filter(msginfo))
+                               folder_item_move_msg(inbox, msginfo);
                        procmsg_msginfo_free(msginfo);
                }
                g_slist_free(msglist);
@@ -615,14 +604,18 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 
                if (inc_state != INC_SUCCESS && inc_state != INC_CANCEL) {
                        error_num++;
-                       if (inc_state == INC_ERROR    ||
-                           inc_state == INC_IO_ERROR ||
-                           inc_state == INC_SOCKET_ERROR) {
-                               inc_put_error(inc_state);
-                       } else if (inc_state == INC_NO_SPACE) {
-                               inc_put_error(inc_state);
+                       if (inc_dialog->show_dialog)
+                               manage_window_focus_in
+                                       (inc_dialog->dialog->window,
+                                        NULL, NULL);
+                       inc_put_error(inc_state, pop3_session->error_msg);
+                       if (inc_dialog->show_dialog)
+                               manage_window_focus_out
+                                       (inc_dialog->dialog->window,
+                                        NULL, NULL);
+                       if (inc_state == INC_NO_SPACE ||
+                           inc_state == INC_IO_ERROR)
                                break;
-                       }
                }
 
                inc_session_destroy(session);
@@ -681,6 +674,8 @@ static IncState inc_pop3_session_do(IncSession *session)
 
        debug_print("getting new messages of account %s...\n",
                    pop3_session->ac_prefs->account_name);
+                   
+       pop3_session->ac_prefs->last_pop_login_time = time(NULL);
 
        buf = g_strdup_printf(_("%s: Retrieving new messages"),
                              pop3_session->ac_prefs->recv_server);
@@ -727,7 +722,8 @@ static IncState inc_pop3_session_do(IncSession *session)
        statusbar_verbosity_set(TRUE);
 
        while (SESSION(pop3_session)->state != SESSION_DISCONNECTED &&
-              SESSION(pop3_session)->state != SESSION_ERROR)
+              SESSION(pop3_session)->state != SESSION_ERROR &&
+              session->inc_state != INC_CANCEL)
                gtk_main_iteration();
 
 
@@ -735,7 +731,13 @@ static IncState inc_pop3_session_do(IncSession *session)
        if (session->inc_state == INC_SUCCESS) {
                switch (pop3_session->error_val) {
                case PS_SUCCESS:
-                       session->inc_state = INC_SUCCESS;
+                       if (SESSION(pop3_session)->state == SESSION_ERROR) {
+                               if (pop3_session->state == POP3_READY)
+                                       session->inc_state = INC_CONNECT_ERROR;
+                               else
+                                       session->inc_state = INC_ERROR;
+                       } else
+                               session->inc_state = INC_SUCCESS;
                        break;
                case PS_AUTHFAIL:
                        session->inc_state = INC_AUTH_FAILED;
@@ -764,11 +766,16 @@ static gint inc_recv_data_progressive(Session *session, guint cur_len,
        gchar buf[MSGBUFSIZE];
        IncSession *inc_session = (IncSession *)data;
        Pop3Session *pop3_session = POP3_SESSION(session);
-       IncProgressDialog *inc_dialog = (IncProgressDialog *)inc_session->data;
-       ProgressDialog *dialog = inc_dialog->dialog;
+       IncProgressDialog *inc_dialog;
+       ProgressDialog *dialog;
        gint cur_total;
        gchar *total_size;
 
+       g_return_val_if_fail(inc_session != NULL, -1);
+
+       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;
@@ -793,7 +800,11 @@ static gint inc_recv_data_progressive(Session *session, guint cur_len,
 
 static gint inc_recv_data_finished(Session *session, guint len, gpointer data)
 {
-       inc_recv_data_progressive(session, 0, len, data);
+       IncSession *inc_session = (IncSession *)data;
+
+       g_return_val_if_fail(inc_session != NULL, -1);
+
+       inc_recv_data_progressive(session, 0, len, inc_session);
        return 0;
 }
 
@@ -802,8 +813,13 @@ static gint inc_recv_message(Session *session, const gchar *msg, gpointer data)
        gchar buf[MSGBUFSIZE];
        IncSession *inc_session = (IncSession *)data;
        Pop3Session *pop3_session = POP3_SESSION(session);
-       IncProgressDialog *inc_dialog = (IncProgressDialog *)inc_session->data;
-       ProgressDialog *dialog = inc_dialog->dialog;
+       IncProgressDialog *inc_dialog;
+       ProgressDialog *dialog;
+
+       g_return_val_if_fail(inc_session != NULL, -1);
+
+       inc_dialog = (IncProgressDialog *)inc_session->data;
+       dialog = inc_dialog->dialog;
 
        switch (pop3_session->state) {
        case POP3_GREETING:
@@ -884,13 +900,16 @@ gint inc_drop_message(const gchar *file, Pop3Session *session)
        return 0;
 }
 
-static void inc_put_error(IncState istate)
+static void inc_put_error(IncState istate, const gchar *msg)
 {
        switch (istate) {
        case INC_ERROR:
-               if (!prefs_common.no_recv_err_panel)
-                       alertpanel_error
-                               (_("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);
+               else
+                       alertpanel_error(_("Error occurred while processing mail."));
                break;
        case INC_NO_SPACE:
                alertpanel_error(_("No disk space left."));
@@ -899,12 +918,27 @@ static void inc_put_error(IncState istate)
                alertpanel_error(_("Can't write file."));
                break;
        case INC_SOCKET_ERROR:
+               if (prefs_common.no_recv_err_panel)
+                       break;
                alertpanel_error(_("Socket error."));
                break;
        case INC_LOCKED:
-               if (!prefs_common.no_recv_err_panel)
+               if (prefs_common.no_recv_err_panel)
+                       break;
+               if (msg)
+                       alertpanel_error(_("Mailbox is locked:\n%s"), msg);
+               else
                        alertpanel_error(_("Mailbox is locked."));
                break;
+       case INC_AUTH_FAILED:
+               if (prefs_common.no_recv_err_panel)
+                       break;
+               if (msg)
+                       alertpanel_error(_("Authentication failed:\n%s"),
+                                        msg);
+               else
+                       alertpanel_error(_("Authentication failed."));
+               break;
        default:
                break;
        }
@@ -923,7 +957,6 @@ static void inc_cancel(IncProgressDialog *dialog)
 
        session = dialog->queue_list->data;
 
-       session->session->state = SESSION_DISCONNECTED;
        session->inc_state = INC_CANCEL;
 
        log_message(_("Incorporation cancelled\n"));