Hello,
today I noticed that when I rename mail folders (through IMAP) not every
sub-folder is also moved to the new location. I traced this down to a bug in
the PostgreSQL version of db_listmailboxchildren() :
The attached patch shows the relevant code (which is removed): 'row' contains
the first result returned by the query asking PostgreSQL for the sub-folders
and 'PQcounter' is initialized to 0, so the first result tuple is fetched
again. The first and second entry in the 'children' list returned by
db_listmailboxchildren() are then the same and therefore the last result
value from the query is never returned. The "first" sub-folder is renamed
twice and the "last" sub-folder is not renamed.
The patch replaces the do/while-loop with an IMHO easier to read and
understand for-loop (the "big fatal" error can not occur since *nchildren is
initialized to PQntuples(res) ).
Please apply this to CVS.
Regards,
Armin
Index: pgsql/dbpgsql.c
===================================================================
RCS file: /cvsroot-dbmail/dbmail/pgsql/dbpgsql.c,v
retrieving revision 1.99
diff -u -r1.99 dbpgsql.c
--- pgsql/dbpgsql.c 2003/03/21 13:02:22 1.99
+++ pgsql/dbpgsql.c 2003/05/20 15:31:31
@@ -2808,31 +2809,12 @@
return -1;
}
-
- i = 0;
- PQcounter = 0;
- do
- {
- if (i == *nchildren)
- {
- /* big fatal */
- my_free(*children);
- *children = NULL;
- *nchildren = 0;
- PQclear(res);
- trace(TRACE_ERROR, "db_listmailboxchildren(): data when none expected.\n");
-
- return -1;
- }
- (*children)[i++] = strtoull(row, NULL, 10);
- row = PQgetvalue (res, PQcounter, 0);
- PQcounter ++;
- }
- while (PQcounter < PQntuples (res));
+ (*children)[0] = strtoull(row, NULL, 10);
+ for (i=1; i<*nchildren; i++)
+ (*children)[i] = strtoull(PQgetvalue (res, i, 0), NULL, 10);
PQclear(res);
-
return 0; /* success */
}