Ilja Booij wrote:
Simon Cocking wrote:
Hi Ilja,
Any chance you can produce a patch against 1.2-CVS? I'm not in a
position to test a 2.0 release quite yet..
I'll probably have no time to do this today.. gotta fix some issues
here. I'll try to prepare a patch ASAP.
patch against 1.2-CVS is attached.
Ilja
--
Ilja Booij
IC&S B.V.
Stadhouderslaan 57
3583 JD Utrecht
www.ic-s.nl
T algemeen: 030 6355730
T direct: 030 6355739
F: 030 6355731
E: [EMAIL PROTECTED]
Index: dbmailtypes.h
===================================================================
RCS file: /cvsroot-dbmail/dbmail/dbmailtypes.h,v
retrieving revision 1.13
diff -r1.13 dbmailtypes.h
154a155,159
> /* length of database date string
> YYYY-MM-DD HH:MM:SS
> 1234567890123456789 */
> #define SQL_INTERNALDATE_LEN 19
>
Index: imaputil.c
===================================================================
RCS file: /cvsroot-dbmail/dbmail/imaputil.c,v
retrieving revision 1.65
diff -r1.65 imaputil.c
8a9,14
> /** needed for strptime(). This should be entered in configure.in
> */
> #ifndef _GNU_SOURCE
> #define _GNU_SOURCE
> #endif
>
16a23
> #include <time.h>
48c55,56
< char _imapdate[IMAP_INTERNALDATE_LEN] = "03-Nov-1979 00:00:00";
---
> #define IMAP_STANDARD_DATE "03-Nov-1979 00:00:00 +0000"
> char _imapdate[IMAP_INTERNALDATE_LEN] = IMAP_STANDARD_DATE;
51c59,60
< char _sqldate[] = "1979-11-03 00:00:00";
---
> #define SQL_STANDARD_DATE "1979-11-03 00:00:00"
> char _sqldate[SQL_INTERNALDATE_LEN] = SQL_STANDARD_DATE;
1851,1852c1860
< * NOTE: sqldate is not tested for validity. Behaviour is undefined for
non-sql
< * dates.
---
> * NOTE: if sqldate is not valid IMAP_STANDARD_DATE is returned.
1856,1858c1864,1869
< int mon;
<
< if (strlen(sqldate) != strlen("yyyy-mm-dd hh:mm:ss"))
---
> char *last_char;
> struct tm tm_localtime, tm_sqldate;
> time_t td;
>
> /* we need to get the localtime to get the current timezone */
> if (time(&td) == -1)
1860c1871,1883
< strcpy(_imapdate, "03-Nov-1979 00:00:00");
---
> trace(TRACE_ERROR, "%s,%s: error getting time()",
> __FILE__, __func__);
> return IMAP_STANDARD_DATE;
> }
> tm_localtime = *localtime(&td);
>
> /* parse sqldate */
> last_char = strptime(sqldate, "%Y-%m-%d %T", &tm_sqldate);
> if (*last_char != '\0')
> {
> trace(TRACE_DEBUG, "%s,%s, error parsing date [%s]",
> __FILE__, __func__, sqldate);
> strcpy(_imapdate, IMAP_STANDARD_DATE);
1863,1886c1886,1889
<
< /* copy day */
< _imapdate[0] = sqldate[8];
< _imapdate[1] = sqldate[9];
<
< /* find out which month */
< mon = strtoul(&sqldate[5], NULL, 10) - 1;
< if (mon < 0 || mon > 11)
< mon = 0;
<
< /* copy month */
< _imapdate[3] = month_desc[mon][0];
< _imapdate[4] = month_desc[mon][1];
< _imapdate[5] = month_desc[mon][2];
<
< /* copy year */
< _imapdate[7] = sqldate[0];
< _imapdate[8] = sqldate[1];
< _imapdate[9] = sqldate[2];
< _imapdate[10] = sqldate[3];
<
< /* copy time */
< strcpy(&_imapdate[11], &sqldate[10]);
<
---
> tm_sqldate.tm_gmtoff = tm_localtime.tm_gmtoff;
> (void) strftime(_imapdate, IMAP_INTERNALDATE_LEN,
> "%d-%b-%Y %T %z", &tm_sqldate);
>
1888c1891
< }
---
> }
1899,1901d1901
< *
< * sqldate is slightly tested for validity. NULL is returned in case of an
erroneous date.
< * however, the tests performed are NOT extensive enough.
1905,1925c1905,1909
< int i,j;
< char sub[4];
<
< if (strlen(imapdate) != strlen("dd-mon-yyyy") && strlen(imapdate) !=
strlen("d-mon-yyyy"))
< return NULL;
<
< j = (strlen(imapdate) == strlen("d-mon-yyyy")) ? 1 : 0;
<
< /* copy year */
< _sqldate[0] = imapdate[7-j];
< _sqldate[1] = imapdate[8-j];
< _sqldate[2] = imapdate[9-j];
< _sqldate[3] = imapdate[10-j];
<
< _sqldate[4] = '-';
<
< /* copy month */
< strncpy(sub, &imapdate[3-j], 3);
< sub[3] = 0;
<
< for (i=0; i<12; i++)
---
> struct tm tm;
> char *last_char;
>
> last_char = strptime(imapdate, "%d-%b-%Y", &tm);
> if (*last_char != '\0')
1927,1928c1911,1913
< if (strcasecmp(month_desc[i], sub) == 0)
< break;
---
> trace(TRACE_DEBUG, "%s,%s: error parsing IMAP date %s",
> __FILE__, __func__, imapdate);
> return NULL;
1929a1915,1916
> (void) strftime(_sqldate, SQL_INTERNALDATE_LEN,
> "%Y-%m-%d 00:00:00", &tm);
1931,1945d1917
< if (i>=12)
< return NULL;
<
< i++; /* make i in [1,12] */
< _sqldate[5] = (i<10) ? '0' : '1';
< _sqldate[6] = (i<10) ? (i+'0') : ((i-10) + '0');
<
< _sqldate[7] = '-';
<
< /* copy day */
< _sqldate[8] = j ? '0' : imapdate[0];
< _sqldate[9] = imapdate[1-j];
<
< _sqldate[10] = 0; /* terminate */
<
1947c1919
< }
---
> }