mbox-from.c revision 87b426af6a2365c6840b14281a98c23e903bf28e
/* Copyright (C) 2002 Timo Sirainen */
#include "lib.h"
#include "str.h"
#include "utc-mktime.h"
#include "mbox-from.h"
#include <time.h>
#include <ctype.h>
static const char *weekdays[] = {
"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
};
static const char *months[] = {
"Jan", "Feb", "Mar", "Apr", "May", "Jun",
"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
};
{
int i;
for (i = 0; i < 12; i++) {
break;
}
}
/* just a hack to parse one special mbox I have :) */
i = 0;
}
return -1;
return 0;
}
{
return -1;
return 0;
}
{
time_t t;
/* <sender> <date> <moreinfo> */
/* get sender */
/* "x y z"@domain - skip the quoted part */
msg++;
return -1;
msg++;
}
msg++;
}
return -1;
msg++;
}
sender_end = msg;
/* next 24 chars should be in the date in asctime() format, eg.
"Thu Nov 9 22:33:52 2001 +0300"
- Some put the timezone before the year
- Some use a named timezone before or after year, which we ignore
- Some don't include seconds
*/
return -1;
/* skip weekday */
msg += 4;
/* month */
/* Try alternate timestamp: "Thu, 9 Nov 2002 22:33:52" */
msg++;
return -1;
msg++;
msg++;
}
if (msg[0] != ' ')
return -1;
msg++;
return -1;
msg += 4;
return -1;
msg += 5;
} else {
msg += 4;
/* day. single digit is usually preceded by extra space */
if (msg[0] == ' ')
msg++;
return -1;
msg += 2;
} else {
return -1;
msg += 3;
}
}
/* hour */
return -1;
msg += 3;
/* minute */
return -1;
msg += 2;
/* optional second */
if (msg[0] == ':') {
msg++;
return -1;
msg += 2;
if (msg[0] == ' ')
msg++;
else if (!alt_stamp)
return -1;
} else {
if (msg[0] != ' ')
return -1;
msg++;
}
/* optional named timezone */
if (alt_stamp)
;
/* skip to next space */
return -1;
msg++;
}
return -1;
msg++;
/* numeric timezone, use it */
msg += 6;
}
if (!alt_stamp) {
/* year */
return -1;
msg += 4;
}
if (!seen_timezone &&
}
if (seen_timezone) {
t = utc_mktime(&tm);
if (t == (time_t)-1)
return -1;
t -= timezone;
*time_r = t;
} else {
/* assume local timezone */
}
return 0;
}
{
int year;
/* we could use simply asctime(), but i18n etc. may break it.
Example: "Thu Nov 29 22:33:52 2001" */
/* week day */
/* month */
/* day */
/* hour */
/* minute */
/* second */
/* year */
}