Blame SOURCES/0001-Remove-gmime-dependency.patch

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