From edc44d613bdc57566a48ea855af86a9df0b3d13d Mon Sep 17 00:00:00 2001
From: Lukas Fleischer <lfleischer@calcurse.org>
Date: Fri, 17 Nov 2017 06:24:49 +0100
Subject: calcurse-caldav: Avoid corrupting the sync DB

When importing an iCal event via calcurse fails (i.e. does not return a
single object hash), do not write anything to the synchronization
database instead of blindly appending the entry, thereby potentially
corrupting the database.

Signed-off-by: Lukas Fleischer <lfleischer@calcurse.org>
---
 contrib/caldav/calcurse-caldav.py | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

(limited to 'contrib')

diff --git a/contrib/caldav/calcurse-caldav.py b/contrib/caldav/calcurse-caldav.py
index 4d5e471..997a5f6 100755
--- a/contrib/caldav/calcurse-caldav.py
+++ b/contrib/caldav/calcurse-caldav.py
@@ -431,8 +431,15 @@ def pull_objects(hrefs_missing, hrefs_modified, conn, syncdb, etagdict):
                 continue
 
         objhash = calcurse_import(cdata)
-        syncdb_add(syncdb, href, etag, objhash)
-        added += 1
+
+        # TODO: Add support for importing multiple events at once, see GitHub
+        # issue #20 for details.
+        if re.match(r'[0-ga-f]+$', objhash):
+            syncdb_add(syncdb, href, etag, objhash)
+            added += 1
+        else:
+            print("Failed to import object: {} ({})".format(etag, href),
+                  file=sys.stderr)
 
     return added
 
-- 
cgit v1.2.3-70-g09d2