2005-10-03 [colin] 1.9.15cvs4
[claws.git] / src / inc.c
index d4b5de3b58b82fafed42a767bfddca1c4035258c..186d289c302d8188b3fc51eb59b70c084839217e 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -14,7 +14,7 @@
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  */
 
 #ifdef HAVE_CONFIG_H
 #include <stdio.h>
 #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>
-#include <signal.h>
-#include <errno.h>
 
 #include "main.h"
 #include "inc.h"
@@ -173,10 +166,7 @@ void inc_mail(MainWindow *mainwin, gboolean notify)
 
        if (inc_lock_count) return;
 
-       if (prefs_common.work_offline)
-               if (alertpanel(_("Offline warning"), 
-                              _("You're working offline. Override?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+       if (prefs_common.work_offline && !inc_offline_should_override())
                return;
 
        inc_lock();
@@ -278,11 +268,8 @@ gint inc_account_mail(MainWindow *mainwin, PrefsAccount *account)
 
        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 0;
+       if (prefs_common.work_offline && !inc_offline_should_override())
+               return 0;
 
        inc_autocheck_timer_remove();
        main_window_lock(mainwin);
@@ -304,10 +291,7 @@ void inc_all_account_mail(MainWindow *mainwin, gboolean autocheck,
        gint new_msgs = 0;
        gint account_new_msgs = 0;
        
-       if (prefs_common.work_offline)
-               if (alertpanel(_("Offline warning"), 
-                              _("You're working offline. Override?"),
-                              _("Yes"), _("No"), NULL) != G_ALERTDEFAULT)
+       if (prefs_common.work_offline && !inc_offline_should_override())
                return;
 
        if (inc_lock_count) return;
@@ -385,11 +369,11 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
 
        progress_dialog_get_fraction(progress);
 
-       stock_pixbuf_gdk(progress->list_view, STOCK_PIXMAP_COMPLETE,
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_COMPLETE,
                         &okpix);
-       stock_pixbuf_gdk(progress->list_view, STOCK_PIXMAP_CONTINUE,
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_CONTINUE,
                         &currentpix);
-       stock_pixbuf_gdk(progress->list_view, STOCK_PIXMAP_ERROR,
+       stock_pixbuf_gdk(progress->treeview, STOCK_PIXMAP_ERROR,
                         &errorpix);
 
        if (prefs_common.recv_dialog_mode == RECV_DIALOG_ALWAYS ||
@@ -400,8 +384,8 @@ static IncProgressDialog *inc_progress_dialog_create(gboolean autocheck)
        }
 
        dialog->dialog = progress;
-       gettimeofday(&dialog->progress_tv, NULL);
-       gettimeofday(&dialog->folder_tv, NULL);
+       g_get_current_time(&dialog->progress_tv);
+       g_get_current_time(&dialog->folder_tv);
        dialog->queue_list = NULL;
        dialog->cur_row = 0;
 
@@ -548,6 +532,7 @@ 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);
 
@@ -560,8 +545,8 @@ static gint inc_start(IncProgressDialog *inc_dialog)
                }
 
                inc_progress_dialog_clear(inc_dialog);
-               progress_dialog_list_select_row(inc_dialog->dialog,
-                                               inc_dialog->cur_row);
+               progress_dialog_scroll_to_row(inc_dialog->dialog,
+                                             inc_dialog->cur_row);
 
                SET_PIXMAP_AND_TEXT(currentpix, _("Retrieving"));
 
@@ -635,17 +620,30 @@ static gint inc_start(IncProgressDialog *inc_dialog)
 
                /* process messages */
                folder_item_update_freeze();
-               for(msglist_element = msglist; msglist_element != NULL; msglist_element = msglist_element->next) {
+               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);
+
+                       if (pop3_session->ac_prefs->filter_on_recv)
+                               statusbar_progress_all(cur++,total, prefs_common.statusbar_update_step);
+
                        if (!pop3_session->ac_prefs->filter_on_recv || 
                            !procmsg_msginfo_filter(msginfo))
                                folder_item_move_msg(inbox, msginfo);
                        procmsg_msginfo_free(msginfo);
                }
                folder_item_update_thaw();
+               
+               statusbar_progress_all(0,0,0);
+               statusbar_pop_all();
+
                g_slist_free(msglist);
 
                statusbar_pop_all();
@@ -753,6 +751,20 @@ static IncState inc_pop3_session_do(IncSession *session)
                SESSION(pop3_session)->nonblocking =
                        pop3_session->ac_prefs->use_nonblocking_ssl;
 #else
+       if (pop3_session->ac_prefs->ssl_pop != SSL_NONE) {
+               if (alertpanel_full(_("Insecure connection"),
+                       _("This connection is configured to be secured "
+                         "using SSL, but SSL is not available in this "
+                         "build of Sylpheed-Claws. \n\n"
+                         "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)
+                       return INC_CONNECT_ERROR;
+       }
        port = pop3_session->ac_prefs->set_popport ?
                pop3_session->ac_prefs->popport : 110;
 #endif
@@ -950,17 +962,17 @@ static void inc_progress_dialog_set_progress(IncProgressDialog *inc_dialog,
 static void inc_progress_dialog_update_periodic(IncProgressDialog *inc_dialog,
                                                IncSession *inc_session)
 {
-       struct timeval tv_cur;
-       struct timeval tv_result;
+       GTimeVal tv_cur;
+       GTimeVal tv_result;
        gint msec;
 
-       gettimeofday(&tv_cur, NULL);
+       g_get_current_time(&tv_cur);
 
        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;
+               tv_result.tv_usec += G_USEC_PER_SEC;
        }
 
        msec = tv_result.tv_sec * 1000 + tv_result.tv_usec / 1000;
@@ -1066,7 +1078,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        } else
                inbox = folder_get_default_inbox();
        if (!inbox) {
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -1076,7 +1088,7 @@ static gint inc_drop_message(Pop3Session *session, const gchar *file)
        /* add msg file to drop folder */
        if ((msgnum = folder_item_add_msg(
                        dropfolder, file, NULL, TRUE)) < 0) {
-               unlink(file);
+               g_unlink(file);
                return -1;
        }
 
@@ -1312,7 +1324,7 @@ static gint get_spool(FolderItem *dest, const gchar *mbox)
 
        msgs = proc_mbox(dest, tmp_mbox, TRUE);
 
-       unlink(tmp_mbox);
+       g_unlink(tmp_mbox);
        if (msgs >= 0) empty_mbox(mbox);
        unlock_mbox(mbox, lockfd, LOCK_FLOCK);
 
@@ -1411,3 +1423,41 @@ static gint inc_autocheck_func(gpointer data)
 
        return FALSE;
 }
+
+gboolean inc_offline_should_override(void)
+{
+       static time_t overridden_yes = 0;
+       static time_t overridden_no  = 0;
+       int length = 600;
+       gint answer = G_ALERTDEFAULT;
+       
+       if (prefs_common.autochk_newmail)
+               length = prefs_common.autochk_itv;
+
+       if (prefs_common.work_offline) {
+               gchar *tmp = g_strdup_printf(
+                               _("You're working offline. Override for %d minutes?"),
+                               length);
+               if (time(NULL) - overridden_yes < length * 10)
+                        return TRUE;
+               else if (time(NULL) - overridden_no < length * 10)
+                        return FALSE;
+               
+               answer = alertpanel(_("Offline warning"), 
+                              tmp,
+                              GTK_STOCK_YES, GTK_STOCK_NO, _("On_ly once"));
+               g_free(tmp);
+               if (answer == G_ALERTDEFAULT) {
+                       overridden_yes = time(NULL);
+                       return TRUE;
+               } else if (answer == G_ALERTALTERNATE) {
+                       overridden_no  = time(NULL);
+                       return FALSE;
+               } else {
+                       overridden_yes = (time_t)0;
+                       overridden_no  = (time_t)0;
+                       return TRUE;
+               }
+       }
+       return TRUE;
+}