refactor should_delete() a little bit
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 19 Mar 2002 19:39:16 +0000 (19:39 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Tue, 19 Mar 2002 19:39:16 +0000 (19:39 +0000)
ChangeLog.claws
configure.in
src/pop.c

index a058a97eb6e2906895dd77e093a39bea3e23557a..acde0b49afdb67f26263e1b3430591392a4f04d5 100644 (file)
@@ -1,3 +1,8 @@
+2002-03-20 [alfons]    0.7.4claws25
+
+       * src/pop.c
+               refactor should_delete() a little bit 
+
 2002-03-19 [paul]      0.7.4claws24
 
        * src/inc.[ch]
index 8b888ae1c416c64dcc1ff0198e694e848186ef31..3a4bcf681913b3bb2510352a3b22d61db9c0fc66 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws24
+EXTRA_VERSION=claws25
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index c74573f1376ea9d13fcd476db04ee1e05e21b80e..0a9ee1289131149571d3486fb32662279e0890d0 100644 (file)
--- a/src/pop.c
+++ b/src/pop.c
@@ -66,6 +66,7 @@ static gint pop3_ok(SockInfo *sock, gchar *argbuf);
 static void pop3_gen_send(SockInfo *sock, const gchar *format, ...);
 static gint pop3_gen_recv(SockInfo *sock, gchar *buf, gint size);
 static gboolean pop3_delete_header (Pop3State *state);
+static gboolean should_delete (const char *uidl, gpointer data); 
 
 gint pop3_greeting_recv(SockInfo *sock, gpointer data)
 {
@@ -313,7 +314,7 @@ gint pop3_getrange_uidl_recv(SockInfo *sock, gpointer data)
                        }
                }
 
-               if(should_delete(buf, (Pop3State *)state))
+               if (should_delete(buf, (Pop3State *) state))
                        state->uidl_todelete_list = g_slist_append
                                        (state->uidl_todelete_list, g_strdup(buf));             
                
@@ -326,31 +327,47 @@ gint pop3_getrange_uidl_recv(SockInfo *sock, gpointer data)
        else
                return POP3_LOGOUT_SEND;
 }
-gboolean should_delete(char * uidl, gpointer data) {
-       Pop3State *state = (Pop3State *)data;
+
+static gboolean should_delete(const char *uidl, gpointer data) 
+{
        /* answer[0] will contain id
-          answer[0] will contain uidl */
+        * answer[0] will contain uidl */
+       Pop3State *state = (Pop3State *) data;
        gchar **answer;
-       GDate *curdate = g_date_new();
-       int id = 0;
+       GDate *curdate;
+       int  id = 0;
+       const gchar *sdate;
+       gboolean result;
+
+       if (!state->ac_prefs->rmmail || !strchr(uidl, ' '))
+               return FALSE;
+
+       curdate = g_date_new(); 
+       g_return_val_if_fail(curdate, FALSE);   
+       
        g_date_set_time(curdate, time(NULL));
-       if( state->ac_prefs->rmmail && strchr(uidl,' ') ) {
-               /* remove \r\n */
-               uidl = g_strndup(uidl, strlen(uidl)-2);
-               answer = g_strsplit(uidl, " ", 2);
-               id = atoi(answer[0]);
-               if( g_hash_table_lookup(state->uidl_table, answer[1]) != NULL ) {
-                       gchar *sdate = g_hash_table_lookup(state->uidl_table, answer[1]);
-                       int tdate = atoi(sdate);
-                       int keep_for = atoi(state->ac_prefs->leave_time);
-                       int today = g_date_day_of_year(curdate);
-                       int nb_days = 365;
-                       if ( g_date_is_leap_year (g_date_year(curdate)) ) 
-                               nb_days = 366;
-                       return ( (tdate + keep_for)%nb_days <= today );
-               }
-       }
-       return FALSE;
+       
+       /* remove \r\n */
+       uidl   = g_strndup(uidl, strlen(uidl) - 2);
+       answer = g_strsplit(uidl, " ", 2);
+       id     = atoi(answer[0]);
+
+       if (NULL != (sdate = g_hash_table_lookup(state->uidl_table, answer[1]))) {
+               int tdate    = atoi(sdate);
+               int keep_for = atoi(state->ac_prefs->leave_time); /* FIXME: leave time should be an int */
+               int today    = g_date_day_of_year(curdate);
+               int nb_days  = 365;
+
+               nb_days = g_date_is_leap_year(g_date_year(curdate)) ? 366 : 365;
+               result = ( (tdate + keep_for)%nb_days <= today );
+       } else
+               result = FALSE;
+
+       g_date_free(curdate);
+       g_free(uidl);
+       g_strfreev(answer);
+       
+       return result;
 }
 
 gint pop3_getsize_list_send(SockInfo *sock, gpointer data)
@@ -541,10 +558,11 @@ gint pop3_logout_send(SockInfo *sock, gpointer data)
        while (state->uidl_todelete_list != NULL) {
                gchar **parts;
                gint ok;
-               parts=g_strsplit((gchar *)state->uidl_todelete_list->data," ",2);
-               state->uidl_todelete_list = g_slist_remove(
-                                       state->uidl_todelete_list, state->uidl_todelete_list->data);
-               pop3_gen_send(sock, "DELE %s",parts[0]);
+               
+               parts = g_strsplit((gchar *) state->uidl_todelete_list->data, " ", 2);
+               state->uidl_todelete_list = g_slist_remove
+                       (state->uidl_todelete_list, state->uidl_todelete_list->data);
+               pop3_gen_send(sock, "DELE %s", parts[0]);
                if ((ok = pop3_ok(sock, NULL)) != PS_SUCCESS)
                        log_warning(_("error occurred on DELE\n"));
        }