dovecot-2.2: lib-imap: Added imap_to_date()

dovecot at dovecot.org dovecot at dovecot.org
Thu Apr 23 16:21:35 UTC 2015


details:   http://hg.dovecot.org/dovecot-2.2/rev/274b42b7d0de
changeset: 18454:274b42b7d0de
user:      Timo Sirainen <tss at iki.fi>
date:      Thu Apr 23 19:19:10 2015 +0300
description:
lib-imap: Added imap_to_date()

diffstat:

 src/lib-imap/imap-date.c |  30 ++++++++++++++++++++++++------
 src/lib-imap/imap-date.h |   5 +++++
 2 files changed, 29 insertions(+), 6 deletions(-)

diffs (67 lines):

diff -r b4a81e123f1a -r 274b42b7d0de src/lib-imap/imap-date.c
--- a/src/lib-imap/imap-date.c	Thu Apr 23 16:33:19 2015 +0300
+++ b/src/lib-imap/imap-date.c	Thu Apr 23 19:19:10 2015 +0300
@@ -158,15 +158,10 @@
 	return TRUE;
 }
 
-static const char *
-imap_to_datetime_tm(const struct tm *tm, int timezone_offset)
+static void imap_to_date_tm(char buf[11], const struct tm *tm)
 {
-	char *buf;
 	int year;
 
-	/* @UNSAFE: but faster than t_strdup_printf() call.. */
-	buf = t_malloc(27);
-
 	/* dd-mon- */
 	buf[0] = (tm->tm_mday / 10) + '0';
 	buf[1] = (tm->tm_mday % 10) + '0';
@@ -180,6 +175,16 @@
 	buf[8] = ((year / 100) % 10) + '0';
 	buf[9] = ((year / 10) % 10) + '0';
 	buf[10] = (year % 10) + '0';
+}
+
+static const char *
+imap_to_datetime_tm(const struct tm *tm, int timezone_offset)
+{
+	char *buf;
+
+	/* @UNSAFE: but faster than t_strdup_printf() call.. */
+	buf = t_malloc(27);
+	imap_to_date_tm(buf, tm);
 	buf[11] = ' ';
 
 	/* hh:mi:ss */
@@ -227,3 +232,16 @@
 	tm = gmtime(&adjusted);
 	return imap_to_datetime_tm(tm, timezone_offset);
 }
+
+bool imap_to_date(time_t timestamp, const char **str_r)
+{
+	const struct tm *tm;
+	char *buf;
+
+	tm = localtime(&timestamp);
+
+	buf = t_malloc0(12);
+	imap_to_date_tm(buf, tm);
+	*str_r = buf;
+	return tm->tm_hour == 0 && tm->tm_min == 0 && tm->tm_sec == 0;
+}
diff -r b4a81e123f1a -r 274b42b7d0de src/lib-imap/imap-date.h
--- a/src/lib-imap/imap-date.h	Thu Apr 23 16:33:19 2015 +0300
+++ b/src/lib-imap/imap-date.h	Thu Apr 23 19:19:10 2015 +0300
@@ -17,4 +17,9 @@
 /* Returns given UTC timestamp as IMAP date-time string in given timezone. */
 const char *imap_to_datetime_tz(time_t timestamp, int timezone_offset);
 
+/* Returns TRUE if timestamp was successfully converted to a date,
+   FALSE if time would have been required as well (but the string is still
+   returned). */
+bool imap_to_date(time_t timestamp, const char **str_r);
+
 #endif


More information about the dovecot-cvs mailing list