a346ac
From 27998dc1340a2879a619225bbe43e952c858ef7e Mon Sep 17 00:00:00 2001
a346ac
From: Bastien Nocera <hadess@hadess.net>
a346ac
Date: Mon, 4 Jun 2018 14:25:29 +0200
a346ac
Subject: [PATCH] Remove gmime dependency
a346ac
a346ac
---
a346ac
 meson.build                           |  21 +-
a346ac
 plparse/meson.build                   |   1 +
a346ac
 plparse/totem-pl-parser-decode-date.c | 608 ++++++++++++++++++++++++++
a346ac
 plparse/totem-pl-parser-decode-date.h |  25 ++
a346ac
 plparse/totem-pl-parser.c             |   5 +-
a346ac
 5 files changed, 641 insertions(+), 19 deletions(-)
a346ac
 create mode 100644 plparse/totem-pl-parser-decode-date.c
a346ac
 create mode 100644 plparse/totem-pl-parser-decode-date.h
a346ac
a346ac
diff --git a/meson.build b/meson.build
a346ac
index 1c126c5..bad7351 100644
a346ac
--- a/meson.build
a346ac
+++ b/meson.build
a346ac
@@ -137,25 +137,16 @@ foreach cflag: test_cflags
a346ac
 endforeach
a346ac
 
a346ac
 # gmime dependency
a346ac
-enable_gmime = not get_option('disable-gmime-i-know-what-im-doing')
a346ac
+enable_gmime = true
a346ac
 if enable_gmime
a346ac
-   have_gmime3 = false
a346ac
-   gmime_dep = dependency('gmime-3.0', required : false)
a346ac
-   if gmime_dep.found()
a346ac
-     cdata.set('HAVE_GMIME3', true,
a346ac
-       description: 'GMime 3.0 available in the system')
a346ac
-     pkgconf.set('GMIME', 'gmime-3.0')
a346ac
-   else
a346ac
-     gmime_dep = dependency('gmime-2.6', required : false)
a346ac
-     if not gmime_dep.found()
a346ac
-       error('libgmime is required to compile totem-pl-parser.')
a346ac
-     endif
a346ac
-     pkgconf.set('GMIME', 'gmime-2.6')
a346ac
-   endif
a346ac
    pkgconf.set('USEGMIME', 'yes')
a346ac
    cdata.set('HAVE_GMIME', true,
a346ac
      description: 'GMime available in the system')
a346ac
-   totem_pl_parser_deps += [gmime_dep]
a346ac
+   pkgconf.set('GMIME', '')
a346ac
+   cdata.set('HAVE_TM_GMTOFF', true,
a346ac
+     description: 'Whether struct tm has a tm_gmtoff member')
a346ac
+   cdata.set('HAVE_TIMEZONE', true,
a346ac
+     description: 'Whether libc defines a timezone variable')
a346ac
 else
a346ac
   message('''
a346ac
 **************************************************************
a346ac
diff --git a/plparse/meson.build b/plparse/meson.build
a346ac
index bbc3757..48b0556 100644
a346ac
--- a/plparse/meson.build
a346ac
+++ b/plparse/meson.build
a346ac
@@ -34,6 +34,7 @@ plparser_sources = [
a346ac
   'totem-disc.c',
a346ac
   'totem-pl-parser.c',
a346ac
   'totem-pl-parser-amz.c',
a346ac
+  'totem-pl-parser-decode-date.c',
a346ac
   'totem-pl-parser-lines.c',
a346ac
   'totem-pl-parser-media.c',
a346ac
   'totem-pl-parser-misc.c',
a346ac
diff --git a/plparse/totem-pl-parser-decode-date.c b/plparse/totem-pl-parser-decode-date.c
a346ac
new file mode 100644
a346ac
index 0000000..aefefd1
a346ac
--- /dev/null
a346ac
+++ b/plparse/totem-pl-parser-decode-date.c
a346ac
@@ -0,0 +1,608 @@
a346ac
+/*  GMime
a346ac
+ *  Copyright (C) 2000-2009 Jeffrey Stedfast
a346ac
+ *
a346ac
+ *  This library is free software; you can redistribute it and/or
a346ac
+ *  modify it under the terms of the GNU Lesser General Public License
a346ac
+ *  as published by the Free Software Foundation; either version 2.1
a346ac
+ *  of the License, or (at your option) any later version.
a346ac
+ *
a346ac
+ *  This library is distributed in the hope that it will be useful,
a346ac
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a346ac
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a346ac
+ *  Lesser General Public License for more details.
a346ac
+ *
a346ac
+ *  You should have received a copy of the GNU Lesser General Public
a346ac
+ *  License along with this library; if not, write to the Free
a346ac
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
a346ac
+ *  02110-1301, USA.
a346ac
+ */
a346ac
+
a346ac
+#include "config.h"
a346ac
+
a346ac
+#include <glib.h>
a346ac
+
a346ac
+#include <stdio.h>
a346ac
+#include <stdlib.h>
a346ac
+#include <string.h>
a346ac
+
a346ac
+#include "totem-pl-parser-decode-date.h"
a346ac
+
a346ac
+#define d(x)
a346ac
+
a346ac
+#define DATE_TOKEN_NON_NUMERIC          (1 << 0)
a346ac
+#define DATE_TOKEN_NON_WEEKDAY          (1 << 1)
a346ac
+#define DATE_TOKEN_NON_MONTH            (1 << 2)
a346ac
+#define DATE_TOKEN_NON_TIME             (1 << 3)
a346ac
+#define DATE_TOKEN_HAS_COLON            (1 << 4)
a346ac
+#define DATE_TOKEN_NON_TIMEZONE_ALPHA   (1 << 5)
a346ac
+#define DATE_TOKEN_NON_TIMEZONE_NUMERIC (1 << 6)
a346ac
+#define DATE_TOKEN_HAS_SIGN             (1 << 7)
a346ac
+
a346ac
+static unsigned char gmime_datetok_table[256] = {
a346ac
+	128,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111, 79, 79,111,175,111,175,111,111,
a346ac
+	 38, 38, 38, 38, 38, 38, 38, 38, 38, 38,119,111,111,111,111,111,
a346ac
+	111, 75,111, 79, 75, 79,105, 79,111,111,107,111,111, 73, 75,107,
a346ac
+	 79,111,111, 73, 77, 79,111,109,111, 79, 79,111,111,111,111,111,
a346ac
+	111,105,107,107,109,105,111,107,105,105,111,111,107,107,105,105,
a346ac
+	107,111,105,105,105,105,107,111,111,105,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+	111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,111,
a346ac
+};
a346ac
+
a346ac
+/* hrm, is there a library for this shit? */
a346ac
+static struct {
a346ac
+	char *name;
a346ac
+	int offset;
a346ac
+} tz_offsets [] = {
a346ac
+	{ "UT", 0 },
a346ac
+	{ "GMT", 0 },
a346ac
+	{ "EST", -500 },	/* these are all US timezones.  bloody yanks */
a346ac
+	{ "EDT", -400 },
a346ac
+	{ "CST", -600 },
a346ac
+	{ "CDT", -500 },
a346ac
+	{ "MST", -700 },
a346ac
+	{ "MDT", -600 },
a346ac
+	{ "PST", -800 },
a346ac
+	{ "PDT", -700 },
a346ac
+	{ "Z", 0 },
a346ac
+	{ "A", -100 },
a346ac
+	{ "M", -1200 },
a346ac
+	{ "N", 100 },
a346ac
+	{ "Y", 1200 },
a346ac
+};
a346ac
+
a346ac
+static char *tm_months[] = {
a346ac
+	"Jan", "Feb", "Mar", "Apr", "May", "Jun",
a346ac
+	"Jul", "Aug", "Sep", "Oct", "Nov", "Dec"
a346ac
+};
a346ac
+
a346ac
+static char *tm_days[] = {
a346ac
+	"Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"
a346ac
+};
a346ac
+
a346ac
+/* This is where it gets ugly... */
a346ac
+
a346ac
+typedef struct _date_token {
a346ac
+	struct _date_token *next;
a346ac
+	unsigned char mask;
a346ac
+	const char *start;
a346ac
+	size_t len;
a346ac
+} date_token;
a346ac
+
a346ac
+#define date_token_free(tok) g_slice_free (date_token, tok)
a346ac
+#define date_token_new() g_slice_new (date_token)
a346ac
+
a346ac
+static date_token *
a346ac
+datetok (const char *date)
a346ac
+{
a346ac
+	date_token *tokens = NULL, *token, *tail = (date_token *) &tokens;
a346ac
+	const char *start, *end;
a346ac
+        unsigned char mask;
a346ac
+	
a346ac
+	start = date;
a346ac
+	while (*start) {
a346ac
+		/* kill leading whitespace */
a346ac
+		while (*start == ' ' || *start == '\t')
a346ac
+			start++;
a346ac
+		
a346ac
+		if (*start == '\0')
a346ac
+			break;
a346ac
+		
a346ac
+		mask = gmime_datetok_table[(unsigned char) *start];
a346ac
+		
a346ac
+		/* find the end of this token */
a346ac
+		end = start + 1;
a346ac
+		while (*end && !strchr ("-/,\t\r\n ", *end))
a346ac
+			mask |= gmime_datetok_table[(unsigned char) *end++];
a346ac
+		
a346ac
+		if (end != start) {
a346ac
+			token = date_token_new ();
a346ac
+			token->next = NULL;
a346ac
+			token->start = start;
a346ac
+			token->len = end - start;
a346ac
+			token->mask = mask;
a346ac
+			
a346ac
+			tail->next = token;
a346ac
+			tail = token;
a346ac
+		}
a346ac
+		
a346ac
+		if (*end)
a346ac
+			start = end + 1;
a346ac
+		else
a346ac
+			break;
a346ac
+	}
a346ac
+	
a346ac
+	return tokens;
a346ac
+}
a346ac
+
a346ac
+static int
a346ac
+decode_int (const char *in, size_t inlen)
a346ac
+{
a346ac
+	register const char *inptr;
a346ac
+	int sign = 1, val = 0;
a346ac
+	const char *inend;
a346ac
+	
a346ac
+	inptr = in;
a346ac
+	inend = in + inlen;
a346ac
+	
a346ac
+	if (*inptr == '-') {
a346ac
+		sign = -1;
a346ac
+		inptr++;
a346ac
+	} else if (*inptr == '+')
a346ac
+		inptr++;
a346ac
+	
a346ac
+	for ( ; inptr < inend; inptr++) {
a346ac
+		if (!(*inptr >= '0' && *inptr <= '9'))
a346ac
+			return -1;
a346ac
+		else
a346ac
+			val = (val * 10) + (*inptr - '0');
a346ac
+	}
a346ac
+	
a346ac
+	val *= sign;
a346ac
+	
a346ac
+	return val;
a346ac
+}
a346ac
+
a346ac
+#if 0
a346ac
+static int
a346ac
+get_days_in_month (int month, int year)
a346ac
+{
a346ac
+        switch (month) {
a346ac
+	case 1:
a346ac
+	case 3:
a346ac
+	case 5:
a346ac
+	case 7:
a346ac
+	case 8:
a346ac
+	case 10:
a346ac
+	case 12:
a346ac
+	        return 31;
a346ac
+	case 4:
a346ac
+	case 6:
a346ac
+	case 9:
a346ac
+	case 11:
a346ac
+	        return 30;
a346ac
+	case 2:
a346ac
+	        if (g_date_is_leap_year (year))
a346ac
+		        return 29;
a346ac
+		else
a346ac
+		        return 28;
a346ac
+	default:
a346ac
+	        return 0;
a346ac
+	}
a346ac
+}
a346ac
+#endif
a346ac
+
a346ac
+static int
a346ac
+get_wday (const char *in, size_t inlen)
a346ac
+{
a346ac
+	int wday;
a346ac
+	
a346ac
+	g_return_val_if_fail (in != NULL, -1);
a346ac
+	
a346ac
+	if (inlen < 3)
a346ac
+		return -1;
a346ac
+	
a346ac
+	for (wday = 0; wday < 7; wday++) {
a346ac
+		if (!g_ascii_strncasecmp (in, tm_days[wday], 3))
a346ac
+			return wday;
a346ac
+	}
a346ac
+	
a346ac
+	return -1;  /* unknown week day */
a346ac
+}
a346ac
+
a346ac
+static int
a346ac
+get_mday (const char *in, size_t inlen)
a346ac
+{
a346ac
+	int mday;
a346ac
+	
a346ac
+	g_return_val_if_fail (in != NULL, -1);
a346ac
+	
a346ac
+	mday = decode_int (in, inlen);
a346ac
+	
a346ac
+	if (mday < 0 || mday > 31)
a346ac
+		mday = -1;
a346ac
+	
a346ac
+	return mday;
a346ac
+}
a346ac
+
a346ac
+static int
a346ac
+get_month (const char *in, size_t inlen)
a346ac
+{
a346ac
+	int i;
a346ac
+	
a346ac
+	g_return_val_if_fail (in != NULL, -1);
a346ac
+	
a346ac
+	if (inlen < 3)
a346ac
+		return -1;
a346ac
+	
a346ac
+	for (i = 0; i < 12; i++) {
a346ac
+		if (!g_ascii_strncasecmp (in, tm_months[i], 3))
a346ac
+			return i;
a346ac
+	}
a346ac
+	
a346ac
+	return -1;  /* unknown month */
a346ac
+}
a346ac
+
a346ac
+static int
a346ac
+get_year (const char *in, size_t inlen)
a346ac
+{
a346ac
+	int year;
a346ac
+	
a346ac
+	g_return_val_if_fail (in != NULL, -1);
a346ac
+	
a346ac
+	if ((year = decode_int (in, inlen)) == -1)
a346ac
+		return -1;
a346ac
+	
a346ac
+	if (year < 100)
a346ac
+		year += (year < 70) ? 2000 : 1900;
a346ac
+	
a346ac
+	if (year < 1969)
a346ac
+		return -1;
a346ac
+	
a346ac
+	return year;
a346ac
+}
a346ac
+
a346ac
+static gboolean
a346ac
+get_time (const char *in, size_t inlen, int *hour, int *min, int *sec)
a346ac
+{
a346ac
+	register const char *inptr;
a346ac
+	int *val, colons = 0;
a346ac
+	const char *inend;
a346ac
+	
a346ac
+	*hour = *min = *sec = 0;
a346ac
+	
a346ac
+	inend = in + inlen;
a346ac
+	val = hour;
a346ac
+	for (inptr = in; inptr < inend; inptr++) {
a346ac
+		if (*inptr == ':') {
a346ac
+			colons++;
a346ac
+			switch (colons) {
a346ac
+			case 1:
a346ac
+				val = min;
a346ac
+				break;
a346ac
+			case 2:
a346ac
+				val = sec;
a346ac
+				break;
a346ac
+			default:
a346ac
+				return FALSE;
a346ac
+			}
a346ac
+		} else if (!(*inptr >= '0' && *inptr <= '9'))
a346ac
+			return FALSE;
a346ac
+		else
a346ac
+			*val = (*val * 10) + (*inptr - '0');
a346ac
+	}
a346ac
+	
a346ac
+	return TRUE;
a346ac
+}
a346ac
+
a346ac
+static int
a346ac
+get_tzone (date_token **token)
a346ac
+{
a346ac
+	const char *inptr, *inend;
a346ac
+	size_t inlen;
a346ac
+	int i, t;
a346ac
+	
a346ac
+	for (i = 0; *token && i < 2; *token = (*token)->next, i++) {
a346ac
+		inptr = (*token)->start;
a346ac
+		inlen = (*token)->len;
a346ac
+		inend = inptr + inlen;
a346ac
+		
a346ac
+		if (*inptr == '+' || *inptr == '-') {
a346ac
+			return decode_int (inptr, inlen);
a346ac
+		} else {
a346ac
+			if (*inptr == '(') {
a346ac
+				inptr++;
a346ac
+				if (*(inend - 1) == ')')
a346ac
+					inlen -= 2;
a346ac
+				else
a346ac
+					inlen--;
a346ac
+			}
a346ac
+			
a346ac
+			for (t = 0; t < 15; t++) {
a346ac
+				size_t len = strlen (tz_offsets[t].name);
a346ac
+				
a346ac
+				if (len != inlen)
a346ac
+					continue;
a346ac
+				
a346ac
+				if (!strncmp (inptr, tz_offsets[t].name, len))
a346ac
+					return tz_offsets[t].offset;
a346ac
+			}
a346ac
+		}
a346ac
+	}
a346ac
+	
a346ac
+	return -1;
a346ac
+}
a346ac
+
a346ac
+static time_t
a346ac
+mktime_utc (struct tm *tm)
a346ac
+{
a346ac
+	time_t tt;
a346ac
+	long tz;
a346ac
+	
a346ac
+	tm->tm_isdst = -1;
a346ac
+	tt = mktime (tm);
a346ac
+	
a346ac
+#if defined (G_OS_WIN32)
a346ac
+	_get_timezone (&tz;;
a346ac
+	if (tm->tm_isdst > 0) {
a346ac
+		int dst;
a346ac
+		
a346ac
+		_get_dstbias (&dst);
a346ac
+		tz += dst;
a346ac
+	}
a346ac
+#elif defined (HAVE_TM_GMTOFF)
a346ac
+	tz = -tm->tm_gmtoff;
a346ac
+#elif defined (HAVE_TIMEZONE)
a346ac
+	if (tm->tm_isdst > 0) {
a346ac
+#if defined (HAVE_ALTZONE)
a346ac
+		tz = altzone;
a346ac
+#else /* !defined (HAVE_ALTZONE) */
a346ac
+		tz = (timezone - 3600);
a346ac
+#endif
a346ac
+	} else {
a346ac
+		tz = timezone;
a346ac
+	}
a346ac
+#elif defined (HAVE__TIMEZONE)
a346ac
+	tz = _timezone;
a346ac
+#else
a346ac
+#error Neither HAVE_TIMEZONE nor HAVE_TM_GMTOFF defined. Rerun meson.
a346ac
+#endif
a346ac
+	
a346ac
+	return tt - tz;
a346ac
+}
a346ac
+
a346ac
+static time_t
a346ac
+parse_rfc822_date (date_token *tokens, int *tzone)
a346ac
+{
a346ac
+	int hour, min, sec, offset, n;
a346ac
+	date_token *token;
a346ac
+	struct tm tm;
a346ac
+	time_t t;
a346ac
+	
a346ac
+	g_return_val_if_fail (tokens != NULL, (time_t) 0);
a346ac
+	
a346ac
+	token = tokens;
a346ac
+	
a346ac
+	memset ((void *) &tm, 0, sizeof (struct tm));
a346ac
+	
a346ac
+	if ((n = get_wday (token->start, token->len)) != -1) {
a346ac
+		/* not all dates may have this... */
a346ac
+		tm.tm_wday = n;
a346ac
+		token = token->next;
a346ac
+	}
a346ac
+	
a346ac
+	/* get the mday */
a346ac
+	if (!token || (n = get_mday (token->start, token->len)) == -1)
a346ac
+		return (time_t) 0;
a346ac
+	
a346ac
+	tm.tm_mday = n;
a346ac
+	token = token->next;
a346ac
+	
a346ac
+	/* get the month */
a346ac
+	if (!token || (n = get_month (token->start, token->len)) == -1)
a346ac
+		return (time_t) 0;
a346ac
+	
a346ac
+	tm.tm_mon = n;
a346ac
+	token = token->next;
a346ac
+	
a346ac
+	/* get the year */
a346ac
+	if (!token || (n = get_year (token->start, token->len)) == -1)
a346ac
+		return (time_t) 0;
a346ac
+	
a346ac
+	tm.tm_year = n - 1900;
a346ac
+	token = token->next;
a346ac
+	
a346ac
+	/* get the hour/min/sec */
a346ac
+	if (!token || !get_time (token->start, token->len, &hour, &min, &sec))
a346ac
+		return (time_t) 0;
a346ac
+	
a346ac
+	tm.tm_hour = hour;
a346ac
+	tm.tm_min = min;
a346ac
+	tm.tm_sec = sec;
a346ac
+	token = token->next;
a346ac
+	
a346ac
+	/* get the timezone */
a346ac
+	if (!token || (n = get_tzone (&token)) == -1) {
a346ac
+		/* I guess we assume tz is GMT? */
a346ac
+		offset = 0;
a346ac
+	} else {
a346ac
+		offset = n;
a346ac
+	}
a346ac
+	
a346ac
+	t = mktime_utc (&tm;;
a346ac
+	
a346ac
+	/* t is now GMT of the time we want, but not offset by the timezone ... */
a346ac
+	
a346ac
+	/* this should convert the time to the GMT equiv time */
a346ac
+	t -= ((offset / 100) * 60 * 60) + (offset % 100) * 60;
a346ac
+	
a346ac
+	if (tzone)
a346ac
+		*tzone = offset;
a346ac
+	
a346ac
+	return t;
a346ac
+}
a346ac
+
a346ac
+
a346ac
+#define date_token_mask(t)  (((date_token *) t)->mask)
a346ac
+#define is_numeric(t)       ((date_token_mask (t) & DATE_TOKEN_NON_NUMERIC) == 0)
a346ac
+#define is_weekday(t)       ((date_token_mask (t) & DATE_TOKEN_NON_WEEKDAY) == 0)
a346ac
+#define is_month(t)         ((date_token_mask (t) & DATE_TOKEN_NON_MONTH) == 0)
a346ac
+#define is_time(t)          (((date_token_mask (t) & DATE_TOKEN_NON_TIME) == 0) && (date_token_mask (t) & DATE_TOKEN_HAS_COLON))
a346ac
+#define is_tzone_alpha(t)   ((date_token_mask (t) & DATE_TOKEN_NON_TIMEZONE_ALPHA) == 0)
a346ac
+#define is_tzone_numeric(t) (((date_token_mask (t) & DATE_TOKEN_NON_TIMEZONE_NUMERIC) == 0) && (date_token_mask (t) & DATE_TOKEN_HAS_SIGN))
a346ac
+#define is_tzone(t)         (is_tzone_alpha (t) || is_tzone_numeric (t))
a346ac
+
a346ac
+static time_t
a346ac
+parse_broken_date (date_token *tokens, int *tzone)
a346ac
+{
a346ac
+	gboolean got_wday, got_month, got_tzone;
a346ac
+	int hour, min, sec, offset, n;
a346ac
+	date_token *token;
a346ac
+	struct tm tm;
a346ac
+	time_t t;
a346ac
+	
a346ac
+	memset ((void *) &tm, 0, sizeof (struct tm));
a346ac
+	got_wday = got_month = got_tzone = FALSE;
a346ac
+	offset = 0;
a346ac
+	
a346ac
+	token = tokens;
a346ac
+	while (token) {
a346ac
+		if (is_weekday (token) && !got_wday) {
a346ac
+			if ((n = get_wday (token->start, token->len)) != -1) {
a346ac
+				d(printf ("weekday; "));
a346ac
+				got_wday = TRUE;
a346ac
+				tm.tm_wday = n;
a346ac
+				goto next;
a346ac
+			}
a346ac
+		}
a346ac
+		
a346ac
+		if (is_month (token) && !got_month) {
a346ac
+			if ((n = get_month (token->start, token->len)) != -1) {
a346ac
+				d(printf ("month; "));
a346ac
+				got_month = TRUE;
a346ac
+				tm.tm_mon = n;
a346ac
+				goto next;
a346ac
+			}
a346ac
+		}
a346ac
+		
a346ac
+		if (is_time (token) && !tm.tm_hour && !tm.tm_min && !tm.tm_sec) {
a346ac
+			if (get_time (token->start, token->len, &hour, &min, &sec)) {
a346ac
+				d(printf ("time; "));
a346ac
+				tm.tm_hour = hour;
a346ac
+				tm.tm_min = min;
a346ac
+				tm.tm_sec = sec;
a346ac
+				goto next;
a346ac
+			}
a346ac
+		}
a346ac
+		
a346ac
+		if (is_tzone (token) && !got_tzone) {
a346ac
+			date_token *t = token;
a346ac
+			
a346ac
+			if ((n = get_tzone (&t)) != -1) {
a346ac
+				d(printf ("tzone; "));
a346ac
+				got_tzone = TRUE;
a346ac
+				offset = n;
a346ac
+				goto next;
a346ac
+			}
a346ac
+		}
a346ac
+		
a346ac
+		if (is_numeric (token)) {
a346ac
+			if (token->len == 4 && !tm.tm_year) {
a346ac
+				if ((n = get_year (token->start, token->len)) != -1) {
a346ac
+					d(printf ("year; "));
a346ac
+					tm.tm_year = n - 1900;
a346ac
+					goto next;
a346ac
+				}
a346ac
+			} else {
a346ac
+				/* Note: assumes MM-DD-YY ordering if '0 < MM < 12' holds true */
a346ac
+				if (!got_month && token->next && is_numeric (token->next)) {
a346ac
+					if ((n = decode_int (token->start, token->len)) > 12) {
a346ac
+						goto mday;
a346ac
+					} else if (n > 0) {
a346ac
+						d(printf ("mon; "));
a346ac
+						got_month = TRUE;
a346ac
+						tm.tm_mon = n - 1;
a346ac
+					}
a346ac
+					goto next;
a346ac
+				} else if (!tm.tm_mday && (n = get_mday (token->start, token->len)) != -1) {
a346ac
+				mday:
a346ac
+					d(printf ("mday; "));
a346ac
+					tm.tm_mday = n;
a346ac
+					goto next;
a346ac
+				} else if (!tm.tm_year) {
a346ac
+					if ((n = get_year (token->start, token->len)) != -1) {
a346ac
+						d(printf ("2-digit year; "));
a346ac
+						tm.tm_year = n - 1900;
a346ac
+					}
a346ac
+					goto next;
a346ac
+				}
a346ac
+			}
a346ac
+		}
a346ac
+		
a346ac
+		d(printf ("???; "));
a346ac
+		
a346ac
+	next:
a346ac
+		
a346ac
+		token = token->next;
a346ac
+	}
a346ac
+	
a346ac
+	d(printf ("\n"));
a346ac
+	
a346ac
+	t = mktime_utc (&tm;;
a346ac
+	
a346ac
+	/* t is now GMT of the time we want, but not offset by the timezone ... */
a346ac
+	
a346ac
+	/* this should convert the time to the GMT equiv time */
a346ac
+	t -= ((offset / 100) * 60 * 60) + (offset % 100) * 60;
a346ac
+	
a346ac
+	if (tzone)
a346ac
+		*tzone = offset;
a346ac
+	
a346ac
+	return t;
a346ac
+}
a346ac
+
a346ac
+/**
a346ac
+ * g_mime_utils_header_decode_date:
a346ac
+ * @str: input date string
a346ac
+ * @tz_offset: timezone offset
a346ac
+ *
a346ac
+ * Decodes the rfc822 date string and saves the GMT offset into
a346ac
+ * @tz_offset if non-NULL.
a346ac
+ *
a346ac
+ * Returns: the time_t representation of the date string specified by
a346ac
+ * @str or (time_t) %0 on error. If @tz_offset is non-NULL, the value
a346ac
+ * of the timezone offset will be stored.
a346ac
+ **/
a346ac
+time_t
a346ac
+g_mime_utils_header_decode_date (const char *str, int *tz_offset)
a346ac
+{
a346ac
+	date_token *token, *tokens;
a346ac
+	time_t date;
a346ac
+	
a346ac
+	if (!(tokens = datetok (str))) {
a346ac
+		if (tz_offset)
a346ac
+			*tz_offset = 0;
a346ac
+		
a346ac
+		return (time_t) 0;
a346ac
+	}
a346ac
+	
a346ac
+	if (!(date = parse_rfc822_date (tokens, tz_offset)))
a346ac
+		date = parse_broken_date (tokens, tz_offset);
a346ac
+	
a346ac
+	/* cleanup */
a346ac
+	while (tokens) {
a346ac
+		token = tokens;
a346ac
+		tokens = tokens->next;
a346ac
+		date_token_free (token);
a346ac
+	}
a346ac
+	
a346ac
+	return date;
a346ac
+}
a346ac
diff --git a/plparse/totem-pl-parser-decode-date.h b/plparse/totem-pl-parser-decode-date.h
a346ac
new file mode 100644
a346ac
index 0000000..f1a7725
a346ac
--- /dev/null
a346ac
+++ b/plparse/totem-pl-parser-decode-date.h
a346ac
@@ -0,0 +1,25 @@
a346ac
+/*  GMime
a346ac
+ *  Copyright (C) 2000-2009 Jeffrey Stedfast
a346ac
+ *
a346ac
+ *  This library is free software; you can redistribute it and/or
a346ac
+ *  modify it under the terms of the GNU Lesser General Public License
a346ac
+ *  as published by the Free Software Foundation; either version 2.1
a346ac
+ *  of the License, or (at your option) any later version.
a346ac
+ *
a346ac
+ *  This library is distributed in the hope that it will be useful,
a346ac
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
a346ac
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
a346ac
+ *  Lesser General Public License for more details.
a346ac
+ *
a346ac
+ *  You should have received a copy of the GNU Lesser General Public
a346ac
+ *  License along with this library; if not, write to the Free
a346ac
+ *  Software Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
a346ac
+ *  02110-1301, USA.
a346ac
+ */
a346ac
+
a346ac
+#include <glib.h>
a346ac
+
a346ac
+#include <stdio.h>
a346ac
+
a346ac
+time_t g_mime_utils_header_decode_date (const char *str, int *tz_offset);
a346ac
+
a346ac
diff --git a/plparse/totem-pl-parser.c b/plparse/totem-pl-parser.c
a346ac
index 505957a..83fafa1 100644
a346ac
--- a/plparse/totem-pl-parser.c
a346ac
+++ b/plparse/totem-pl-parser.c
a346ac
@@ -132,16 +132,13 @@
a346ac
 #ifndef TOTEM_PL_PARSER_MINI
a346ac
 #include <gobject/gvaluecollector.h>
a346ac
 
a346ac
-#ifdef HAVE_GMIME
a346ac
-#include <gmime/gmime-utils.h>
a346ac
-#endif
a346ac
-
a346ac
 #include "totem-pl-parser.h"
a346ac
 #include "totemplparser-marshal.h"
a346ac
 #include "totem-disc.h"
a346ac
 #endif /* !TOTEM_PL_PARSER_MINI */
a346ac
 
a346ac
 #include "totem-pl-parser-mini.h"
a346ac
+#include "totem-pl-parser-decode-date.h"
a346ac
 #include "totem-pl-parser-wm.h"
a346ac
 #include "totem-pl-parser-qt.h"
a346ac
 #include "totem-pl-parser-pls.h"
a346ac
-- 
a346ac
2.17.0
a346ac