[Patch] Display time stamps of date-only RFC 5545 iCalendar events

Albrecht Dreß <[email protected]>
Newsgroups gmane.comp.gnome.apps.balsa
Message-ID <[email protected]>
Hi all,

I noticed that “VALUE=DATE” time stamps (date only, without time) in RFC 5545 iCalendar parts (MIME type text/calendar) are not displayed.

The attached trivial patch add parsing, displaying and printing such values.  As to simplify life, the date-only values are printed using the “%x” conversion specification, instead of extracting the date part from balsa_app.date_string.

Opinions?

Cheers,
Albrecht.

_______________________________________________
balsa-list mailing list
[email protected]
https://mail.gnome.org/mailman/listinfo/balsa-list
vcal_fix_all_day_ttimestamp.diff (application/octet-stream, 7.1 KB)
diff --git a/libbalsa/rfc2445.c b/libbalsa/rfc2445.c
index 603cb7a..0a15688 100644
--- a/libbalsa/rfc2445.c
+++ b/libbalsa/rfc2445.c
@@ -66,7 +66,7 @@ static LibBalsaAddress *cal_address_2445_to_lbaddress(const gchar * uri,
 						      is_organizer);
 
 /* conversion helpers */
-static time_t date_time_2445_to_time_t(const gchar * date_time);
+static time_t date_time_2445_to_time_t(const gchar *date_time, const gchar *modifier, gboolean *date_only);
 static gchar *time_t_to_date_time_2445(time_t ttime);
 static gchar *text_2445_unescape(const gchar * text);
 static gchar *text_2445_escape(const gchar * text);
@@ -377,11 +377,11 @@ libbalsa_vcal_new_from_body(LibBalsaMessageBody * body)
                 in_embedded = TRUE;
             else if (!in_embedded) {
                 if (!g_ascii_strcasecmp(entry[0], "DTSTART"))
-                    event->start = date_time_2445_to_time_t(value);
+                    event->start = date_time_2445_to_time_t(value, entry[1], &event->start_date_only);
                 else if (!g_ascii_strcasecmp(entry[0], "DTEND"))
-                    event->end = date_time_2445_to_time_t(value);
+                    event->end = date_time_2445_to_time_t(value, entry[1], &event->end_date_only);
                 else if (!g_ascii_strcasecmp(entry[0], "DTSTAMP"))
-                    event->stamp = date_time_2445_to_time_t(value);
+                    event->stamp = date_time_2445_to_time_t(value, entry[1], NULL);
                 else if (!g_ascii_strcasecmp(entry[0], "UID"))
                     STR_REPL_2445_TXT(event->uid, value);
                 else if (!g_ascii_strcasecmp(entry[0], "SUMMARY"))
@@ -537,10 +537,10 @@ libbalsa_vevent_reply(const LibBalsaVEvent * event, const gchar * sender,
 /* convert a rfc 2445 time string into a time_t value */
 // FIXME - what about entries containing a TZID?
 static time_t
-date_time_2445_to_time_t(const gchar *date_time)
+date_time_2445_to_time_t(const gchar *date_time, const gchar *modifier, gboolean *date_only)
 {
     gint len;
-    time_t the_time = (time_t) (-1);;
+    time_t the_time = (time_t) (-1);
 
     g_return_val_if_fail(date_time != NULL, (time_t) (-1));
     len = strlen(date_time);
@@ -553,7 +553,21 @@ date_time_2445_to_time_t(const gchar *date_time)
         /* the rfc2445 date-time is a special case of an iso8901 date/time value... */
         if (g_time_val_from_iso8601(date_time, &timeval)) {
         	the_time = timeval.tv_sec;
+        	if (date_only != NULL) {
+        		*date_only = FALSE;
+        	}
         }
+    } else if ((modifier!= NULL) && (g_ascii_strcasecmp(modifier, "VALUE=DATE") == 0) && (len == 8)) {
+    	struct tm tm;
+
+    	/* date only (yyyymmdd) */
+    	memset(&tm, 0, sizeof(tm));
+    	if (strptime(date_time, "%Y%m%d", &tm) != NULL) {
+    		the_time = mktime(&tm);
+        	if (date_only != NULL) {
+        		*date_only = TRUE;
+        	}
+    	}
     }
 
     return the_time;
diff --git a/libbalsa/rfc2445.h b/libbalsa/rfc2445.h
index 710c66b..dca5d6c 100644
--- a/libbalsa/rfc2445.h
+++ b/libbalsa/rfc2445.h
@@ -1,7 +1,7 @@
 /* -*-mode:c; c-style:k&r; c-basic-offset:4; -*- */
 /*
  * VCalendar (RFC 2445) stuff
- * Copyright (C) 2009 Albrecht Dreß <[email protected]>
+ * Copyright (C) 2009 Albrecht Dreß <[email protected]>
  *
  * This program is free software; you can redistribute it and/or modify
  * it under the terms of the GNU General Public License as published by
@@ -95,7 +95,9 @@ struct _LibBalsaVEvent {
     GList *attendee;
     time_t stamp;
     time_t start;
+    gboolean start_date_only;
     time_t end;
+    gboolean end_date_only;
     gchar *uid;
     gchar *summary;
     gchar *location;
diff --git a/src/balsa-mime-widget-vcalendar.c b/src/balsa-mime-widget-vcalendar.c
index 34e70cb..6f14747 100644
--- a/src/balsa-mime-widget-vcalendar.c
+++ b/src/balsa-mime-widget-vcalendar.c
@@ -118,11 +118,12 @@ balsa_mime_widget_new_vcalendar(BalsaMessage * bm,
         }                                                               \
     } while (0)
 
-#define GRID_ATTACH_DATE(g,date,label)                                  \
+#define GRID_ATTACH_DATE(g,date,date_only,label)                        \
     do {                                                                \
         if (date != (time_t) -1) {                                      \
             gchar * _dstr =                                             \
-                libbalsa_date_to_utf8(date, balsa_app.date_string);     \
+                libbalsa_date_to_utf8(date, 							\
+                	date_only ? "%x" : balsa_app.date_string);     		\
             GRID_ATTACH(g, _dstr, label);                               \
             g_free(_dstr);                                              \
         }                                                               \
@@ -170,8 +171,8 @@ balsa_vevent_widget(LibBalsaVEvent * event, gboolean may_reply,
     gtk_grid_set_column_spacing(grid, 12);
     GRID_ATTACH(grid, event->summary, _("Summary:"));
     GRID_ATTACH_ADDRESS(grid, event->organizer, _("Organizer:"));
-    GRID_ATTACH_DATE(grid, event->start, _("Start:"));
-    GRID_ATTACH_DATE(grid, event->end, _("End:"));
+    GRID_ATTACH_DATE(grid, event->start, event->start_date_only, _("Start:"));
+    GRID_ATTACH_DATE(grid, event->end, event->end_date_only, _("End:"));
     GRID_ATTACH(grid, event->location, _("Location:"));
     if (event->attendee) {
 	GList *att;
diff --git a/src/balsa-print-object-text.c b/src/balsa-print-object-text.c
index 77e0091..397bc5d 100644
--- a/src/balsa-print-object-text.c
+++ b/src/balsa-print-object-text.c
@@ -555,11 +555,12 @@ balsa_print_object_text_vcard(GList * list,
 	}								\
     } while(0)
 
-#define ADD_VCAL_DATE(buf, labwidth, layout, date, descr)               \
+#define ADD_VCAL_DATE(buf, labwidth, layout, date, date_only, descr)	\
     do {                                                                \
         if (date != (time_t) -1) {                                      \
             gchar * _dstr =                                             \
-                libbalsa_date_to_utf8(date, balsa_app.date_string);     \
+                libbalsa_date_to_utf8(date,								\
+                	date_only ? "%x" : balsa_app.date_string);     		\
             ADD_VCAL_FIELD(buf, labwidth, layout, _dstr, descr);        \
             g_free(_dstr);                                              \
         }                                                               \
@@ -650,9 +651,9 @@ balsa_print_object_text_calendar(GList * list,
         ADD_VCAL_ADDRESS(desc_buf, pod->p_label_width, test_layout,
                          event->organizer, _("Organizer"));
         ADD_VCAL_DATE(desc_buf, pod->p_label_width, test_layout,
-                      event->start, _("Start"));
+                      event->start, event->start_date_only, _("Start"));
         ADD_VCAL_DATE(desc_buf, pod->p_label_width, test_layout,
-                      event->end, _("End"));
+                      event->end, event->end_date_only, _("End"));
         ADD_VCAL_FIELD(desc_buf, pod->p_label_width, test_layout,
                        event->location, _("Location"));
         if (event->attendee) {
signature.asc (application/pgp-signature, 473 B)
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v2

iQEcBAABCAAGBQJa6GVxAAoJEEypbw5n59n4nuwIAKv82KnNXQB1lllJFVijgGOU
3+N+tpQgkuGg/d2VtqwwaAjnbl6yumhhypfHNuGfTfRzmzHiSg+KUvirMZ46k2Ds
vtn97pysq3YMwwOBTUoppEmjcwuL/FYWJGEGYO5EeE4q5O2GpUhqpZc5oe/nRaLz
4Cndp9x7u6nSk4wz6jJtB5peRbos3G2KdoxFvETMzkKoRXzO+cKQkyBahg6/4Xik
6qPTQveCrteu63v4i3rRXWxkG5j91HiX0mX5wrYD/sM+5kz7CK9n8UiKTVH9OFS/
UqnovbMltoHLZgiw91doN9s+yOOPjQxpdlFaIVKYTEpN9Rs/FOx/tBGhwAw2V+g=
=zbiO
-----END PGP SIGNATURE-----
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.