Set missing pubdate/moddate in RSSyl items to the other one, if available.
authorAndrej Kacian <ticho@claws-mail.org>
Tue, 18 Sep 2018 17:29:12 +0000 (19:29 +0200)
committerAndrej Kacian <ticho@claws-mail.org>
Tue, 18 Sep 2018 17:29:12 +0000 (19:29 +0200)
src/plugins/rssyl/parse822.c
src/plugins/rssyl/rssyl_add_item.c

index b153936..3f12414 100644 (file)
@@ -103,10 +103,12 @@ FeedItem *rssyl_parse_folder_item_file(gchar *path)
                                        started_author = TRUE;
                                }
 
-                               /* Date */
+                               /* Date (set both FeedItem timestamps) */
                                if( !strcmp(line[0], "Date") ) {
                                        feed_item_set_date_modified(item,
                                                        procheader_date_parse(NULL, line[1], 0));
+                                       feed_item_set_date_published(item,
+                                                       feed_item_get_date_modified(item));
                                        debug_print("RSSyl: got date \n" );
                                }
 
index 25ce836..685d75b 100644 (file)
@@ -303,11 +303,30 @@ void rssyl_add_item(RFolderItem *ritem, FeedItem *feed_item)
        }
 */
 
-       /* If neither item date is set, use date from source (Atom only). */
+       /* If one of the timestamps is empty, set it to value of the other one. */
        if( feed_item_get_date_modified(feed_item) == -1 &&
-                       feed_item_get_date_published(feed_item) == -1 )
+                       feed_item_get_date_published(feed_item) >= 0 ) {
+               debug_print("RSSyl: setting missing moddate to pubdate %ld\n",
+                               feed_item_get_date_published(feed_item));
+               feed_item_set_date_modified(feed_item,
+                               feed_item_get_date_published(feed_item));
+       } else if( feed_item_get_date_published(feed_item) == -1 &&
+                       feed_item_get_date_modified(feed_item) >= 0 ) {
+               debug_print("RSSyl: setting missing pubdate to modddate %ld\n",
+                               feed_item_get_date_modified(feed_item));
                feed_item_set_date_published(feed_item,
+                               feed_item_get_date_modified(feed_item));
+       } else if( feed_item_get_date_modified(feed_item) == -1 &&
+                       feed_item_get_date_published(feed_item) == -1 &&
+                       feed_item_get_sourcedate(feed_item) >= 0 ) {
+               /* If neither item date is set, use date from source (Atom only). */
+               debug_print("RSSyl: setting missing pubdate and moddate to feed source date %ld\n",
                                feed_item_get_sourcedate(feed_item));
+               feed_item_set_date_modified(feed_item,
+                               feed_item_get_sourcedate(feed_item));
+               feed_item_set_date_published(feed_item,
+                               feed_item_get_sourcedate(feed_item));
+       }
 
        /* Fix up subject, url and ID (rssyl_format_string()) so that
         * comparing doesn't break. */