aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2013-02-15 04:34:14 +0000
committerhiro <hiro@ee746299-78ed-0310-b773-934348b2243d>2013-02-15 04:34:14 +0000
commit906bd4558c72374d7c09daf291bec8c1897f2b46 (patch)
tree730c13f3f4272996b02398d8f5634ae689e6f82e
parent19177b744c0b5944be35350dfba9fbd61027cac1 (diff)
modified Date header parser.
git-svn-id: svn://sylpheed.sraoss.jp/sylpheed/trunk@3227 ee746299-78ed-0310-b773-934348b2243d
-rw-r--r--ChangeLog6
-rw-r--r--libsylph/procheader.c36
2 files changed, 32 insertions, 10 deletions
diff --git a/ChangeLog b/ChangeLog
index 91aaad9c..e0637c99 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
2013-02-15
+ * libsylph/procheader.cprocheader_date_parse(): support ISO-type date
+ (YYYY-MM-DD HH:MM:SS).
+ Added workaround for time_t limit.
+
+2013-02-15
+
* src/notificationwindow.c: notification_window_set_message():
check if the window exists.
diff --git a/libsylph/procheader.c b/libsylph/procheader.c
index 0c803baa..bd635363 100644
--- a/libsylph/procheader.c
+++ b/libsylph/procheader.c
@@ -840,6 +840,10 @@ static gint procheader_scan_date_string(const gchar *str,
if (result == 6) return 0;
*zone = '\0';
+ result = sscanf(str, "%d-%2s-%2d %2d:%2d:%2d",
+ year, month, day, hh, mm, ss);
+ if (result == 6) return 0;
+
result = sscanf(str, "%10s %d %9s %d %2d:%2d",
weekday, day, month, year, hh, mm);
if (result == 6) return 0;
@@ -882,10 +886,14 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
}
month[3] = '\0';
- for (p = monthstr; *p != '\0'; p += 3) {
- if (!g_ascii_strncasecmp(p, month, 3)) {
- dmonth = (gint)(p - monthstr) / 3 + 1;
- break;
+ if (g_ascii_isdigit(month[0])) {
+ dmonth = atoi(month);
+ } else {
+ for (p = monthstr; *p != '\0'; p += 3) {
+ if (!g_ascii_strncasecmp(p, month, 3)) {
+ dmonth = (gint)(p - monthstr) / 3 + 1;
+ break;
+ }
}
}
@@ -901,14 +909,22 @@ time_t procheader_date_parse(gchar *dest, const gchar *src, gint len)
timer = mktime(&t);
if (timer == -1) {
- if (dest)
- dest[0] = '\0';
- return 0;
+ if (year >= 2038) {
+ g_warning("mktime: date overflow: %s", src);
+ timer = G_MAXINT - 12 * 3600;
+ } else {
+ g_warning("mktime: can't convert date: %s", src);
+ if (dest)
+ dest[0] = '\0';
+ return 0;
+ }
}
- tz_offset = remote_tzoffset_sec(zone);
- if (tz_offset != -1)
- timer += tzoffset_sec(&timer) - tz_offset;
+ if (timer < G_MAXINT - 12 * 3600) {
+ tz_offset = remote_tzoffset_sec(zone);
+ if (tz_offset != -1)
+ timer += tzoffset_sec(&timer) - tz_offset;
+ }
if (dest)
procheader_date_get_localtime(dest, len, timer);