apply colin's patch and refactor
authorAlfons Hoogervorst <alfons@proteus.demon.nl>
Wed, 20 Mar 2002 20:40:23 +0000 (20:40 +0000)
committerAlfons Hoogervorst <alfons@proteus.demon.nl>
Wed, 20 Mar 2002 20:40:23 +0000 (20:40 +0000)
ChangeLog.claws
configure.in
src/inc.c

index 8ef55dec8f27ccd441fddbc4313ccbbcf1ac6522..547aa39f2ee036a41f214ef782ad8307eb18a2ac 100644 (file)
@@ -1,3 +1,8 @@
+2002-03-20 [alfons]    0.7.4claws28
+
+       * src/inc.c
+               apply Colin's patch and refactor
+
 2002-03-20 [paul]      0.7.4claws27
 
        * sync with sylpheed 0.7.4cvs9
 2002-03-20 [paul]      0.7.4claws27
 
        * sync with sylpheed 0.7.4cvs9
index 546ad7abe9a0231636373a9f247a3cd7bd1a3419..6319eef25a61efea87063c1756d24a5ed739b691 100644 (file)
@@ -8,7 +8,7 @@ MINOR_VERSION=7
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
 MICRO_VERSION=4
 INTERFACE_AGE=0
 BINARY_AGE=0
-EXTRA_VERSION=claws27
+EXTRA_VERSION=claws28
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
 VERSION=$MAJOR_VERSION.$MINOR_VERSION.$MICRO_VERSION$EXTRA_VERSION
 
 dnl set $target
index 9ef4d97dda207ef1971b9183e3a199c9b3320c89..37c459f075efab97444e1a61ec8bb3215a0420ed 100644 (file)
--- a/src/inc.c
+++ b/src/inc.c
@@ -771,10 +771,13 @@ static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
        gchar *path;
        FILE *fp;
        gchar buf[IDLEN + 3];
        gchar *path;
        FILE *fp;
        gchar buf[IDLEN + 3];
+       GDate curdate;
+       gchar **data;
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl-", ac_prefs->recv_server,
                           "-", ac_prefs->userid, NULL);
 
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl-", ac_prefs->recv_server,
                           "-", ac_prefs->userid, NULL);
+                          
        if ((fp = fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
        if ((fp = fopen(path, "rb")) == NULL) {
                if (ENOENT != errno) FILE_OP_ERROR(path, "fopen");
                g_free(path);
@@ -784,28 +787,37 @@ static GHashTable *inc_get_uidl_table(PrefsAccount *ac_prefs)
 
        table = g_hash_table_new(g_str_hash, g_str_equal);
 
 
        table = g_hash_table_new(g_str_hash, g_str_equal);
 
-       while (fgets(buf, sizeof(buf), fp) != NULL) {
-               gchar **data = NULL;
-               GDate *curdate = g_date_new();
+       g_date_clear(&curdate, 1);
+
+       /*
+        * NOTE: g_date_set_time() has to be called inside this 
+        * loop, because a day change may happen??? That right?
+        */
 
 
-               g_date_set_time(curdate, time(NULL));   
+       while (fgets(buf, sizeof(buf), fp) != NULL) {
                strretchomp(buf);
                
                /* data[0] will contain uidl
                strretchomp(buf);
                
                /* data[0] will contain uidl
-                  data[1] will contain day of retrieval */
-               if( strchr(buf, '\t') ) {
-                       data = g_strsplit(buf,"\t",2);
-                       snprintf(data[1], sizeof(data[1]), "%d", g_date_day_of_year(curdate) );
-               }
-               else {
-                       data[0] = g_strdup(buf);
-                       snprintf(data[1], sizeof(data[1]), "%d", g_date_day_of_year(curdate) );
-               }
-               g_hash_table_insert(table, g_strdup(data[0]), g_strdup(data[1]));
+                * data[1] will contain day of retrieval */
+
+               /* 
+                * FIXME: convoluted implementation. need to find
+                * a better way to split the string.
+                */
+               if (strchr(buf, '\t')) {
+                       data = g_strsplit(buf, "\t", 2);
+                       if (data) {
+                               g_hash_table_insert(table, g_strdup(data[0]), g_strdup(data[1]));
+                               g_strfreev(data);
+                       }       
+               } else {
+                       g_date_set_time(&curdate, time(NULL));  
+                       g_hash_table_insert(table, g_strdup(buf), 
+                                           g_strdup_printf("%d", g_date_day_of_year(&curdate)));
+               }                           
        }
 
        fclose(fp);
        }
 
        fclose(fp);
-
        return table;
 }
 
        return table;
 }
 
@@ -814,10 +826,13 @@ static void inc_write_uidl_list(Pop3State *state)
        gchar *path;
        FILE *fp;
        gint n;
        gchar *path;
        FILE *fp;
        gint n;
-       GDate *curdate = g_date_new();
-       g_date_set_time(curdate, time(NULL));
-       if (!state->uidl_is_valid) return;
+       GDate curdate;
+       const char *sdate;
+       int tdate;
 
 
+       if (!state->uidl_is_valid)
+               return;
+       
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl-", state->ac_prefs->recv_server,
                           "-", state->user, NULL);
        path = g_strconcat(get_rc_dir(), G_DIR_SEPARATOR_S,
                           "uidl-", state->ac_prefs->recv_server,
                           "-", state->user, NULL);
@@ -827,6 +842,8 @@ static void inc_write_uidl_list(Pop3State *state)
                return;
        }
 
                return;
        }
 
+       g_date_clear(&curdate, 1);
+
        for (n = 1; n <= state->count; n++) {
                if (state->msg[n].uidl && state->msg[n].received &&
                    !state->msg[n].deleted) {
        for (n = 1; n <= state->count; n++) {
                if (state->msg[n].uidl && state->msg[n].received &&
                    !state->msg[n].deleted) {
@@ -838,33 +855,34 @@ static void inc_write_uidl_list(Pop3State *state)
                                FILE_OP_ERROR(path, "fputc");
                                break;
                        }
                                FILE_OP_ERROR(path, "fputc");
                                break;
                        }
-                       if(g_hash_table_lookup(state->uidl_table, state->msg[n].uidl ) != NULL) {
-                               const char *sdate = g_hash_table_lookup(state->uidl_table, state->msg[n].uidl);
-                               int tdate = g_date_day_of_year(curdate);
-                               if(sdate != NULL)
-                                       tdate = atoi(sdate);
-
-                               if(fprintf(fp, "%3d", tdate) == EOF) {
+                       
+                       /*
+                        * NOTE: need to set time to watch for day changes??
+                        */
+                       g_date_set_time(&curdate, time(NULL));
+
+                       if (NULL != (sdate = g_hash_table_lookup(state->uidl_table, state->msg[n].uidl))) {
+                               tdate = sdate != NULL ? atoi(sdate) : g_date_day_of_year(&curdate);
+                               if (fprintf(fp, "%3d", tdate) == EOF) {
                                        FILE_OP_ERROR(path, "fprintf");
                                        break;
                                }
                        } else {
                                        FILE_OP_ERROR(path, "fprintf");
                                        break;
                                }
                        } else {
-                               if(fprintf(fp, "%d", g_date_day_of_year(curdate)) == EOF) {
+                               if (fprintf(fp, "%d", g_date_day_of_year(&curdate)) == EOF) {
                                        FILE_OP_ERROR(path, "fputs");
                                        break;
                                }
                                        FILE_OP_ERROR(path, "fputs");
                                        break;
                                }
-
                        }
 
                        if (fputc('\n', fp) == EOF) {
                                FILE_OP_ERROR(path, "fputc");
                                break;
                        }               
                        }
 
                        if (fputc('\n', fp) == EOF) {
                                FILE_OP_ERROR(path, "fputc");
                                break;
                        }               
-                       
                }
        }
 
                }
        }
 
-       if (fclose(fp) == EOF) FILE_OP_ERROR(path, "fclose");
+       if (fclose(fp) == EOF) 
+               FILE_OP_ERROR(path, "fclose");
        g_free(path);
 }
 
        g_free(path);
 }