talons

Fork of Claws Mail https://www.claws-mail
Log | Files | Refs | README | LICENSE

commit b9565000500c1d669b8ffd6c77c5edc850ac7220
parent 5b65a79cf66fdd70709a56751ab971ad772ad51c
Author: Andrej Kacian <ticho@claws-mail.org>
Date:   Sun, 15 Jul 2018 00:31:18 +0200

RSSyl: rework matching deleted items to better handle feeds without id

Fixes bug #3971 again.

Diffstat:
Msrc/plugins/rssyl/rssyl_deleted.c | 92++++++++++++++++++++++++++++++++++++++++++++++++++-----------------------------
1 file changed, 58 insertions(+), 34 deletions(-)

diff --git a/src/plugins/rssyl/rssyl_deleted.c b/src/plugins/rssyl/rssyl_deleted.c @@ -245,34 +245,53 @@ static gint _rssyl_deleted_check_func(gconstpointer a, gconstpointer b) { RDeletedItem *ditem = (RDeletedItem *)a; FeedItem *fitem = (FeedItem *)b; + gchar *id; + gboolean id_match = FALSE; + gboolean title_match = FALSE; + gboolean pubdate_match = FALSE; + gboolean moddate_newer = FALSE; g_return_val_if_fail(ditem != NULL, -10); g_return_val_if_fail(fitem != NULL, -20); /* Following must match: - * ID, ... */ - if (!ditem->id || !feed_item_get_id(fitem) || - strcmp(ditem->id, feed_item_get_id(fitem))) - return -1; + * ID, or if there is no ID, the URL, since that's + * what would have been stored in .deleted instead + * of ID... */ + if ((id = feed_item_get_id(fitem)) == NULL) + id = feed_item_get_url(fitem); + + if (ditem->id && id && + !strcmp(ditem->id, id)) + id_match = TRUE; /* title, ... */ - if (!ditem->title || !feed_item_get_title(fitem) || - strcmp(ditem->title, feed_item_get_title(fitem))) - return -2; + if (ditem->title && feed_item_get_title(fitem) && + !strcmp(ditem->title, feed_item_get_title(fitem))) + title_match = TRUE; - /* time of publishing, ... */ - if (ditem->date_published != -1 && - ditem->date_published != feed_item_get_date_published(fitem)) - return -3; + /* time of publishing, if set... */ + if (ditem->date_published == -1 || + ditem->date_published == feed_item_get_date_published(fitem)) + pubdate_match = TRUE; /* and the time of last modification must be greater * (this means that the item was updated since deletion, and possibly * contains new data, so we add it again) */ if (ditem->date_modified != -1 && ditem->date_modified < feed_item_get_date_modified(fitem)) - return -4; + moddate_newer = TRUE; + + if (id_match && title_match && pubdate_match) { + /* we have our item */ + if (moddate_newer) + return -1; /* it's been updated, add it */ + else + return 0; /* not updated, keep ignoring */ + } - return 0; + /* not our item */ + return -1; } /* Returns TRUE if fitem is found among the deleted stuff. */ @@ -297,31 +316,36 @@ static void _rssyl_deleted_expire_func_f(gpointer data, gpointer user_data) { FeedItem *fitem = (FeedItem *)data; RDelExpireCtx *ctx = (RDelExpireCtx *)user_data; + gchar *id; + gboolean id_match = FALSE; + gboolean title_match = FALSE; + gboolean pubdate_match = FALSE; /* Following must match: - * ID, ... */ - if (!ctx->ditem->id || !feed_item_get_id(fitem) || - strcmp(ctx->ditem->id, feed_item_get_id(fitem))) - return; + * ID, or if there is no ID, the URL, since that's + * what would have been stored in .deleted instead + * of ID... */ + if ((id = feed_item_get_id(fitem)) == NULL) + id = feed_item_get_url(fitem); - /* title, ... */ - if (!ctx->ditem->title || !feed_item_get_title(fitem) || - strcmp(ctx->ditem->title, feed_item_get_title(fitem))) - return; - - /* time of publishing, ... */ - if (ctx->ditem->date_published != -1 && - ctx->ditem->date_published != feed_item_get_date_published(fitem)) - return; + if (ctx->ditem->id && id && + !strcmp(ctx->ditem->id, id)) + id_match = TRUE; - /* and the time of last modification must be greater - * (this means that the item was updated since deletion, and possibly - * contains new data, so we add it again) */ - if (ctx->ditem->date_modified != -1 && - ctx->ditem->date_modified != feed_item_get_date_modified(fitem)) - return; - - ctx->delete = FALSE; + /* title, ... */ + if (ctx->ditem->title && feed_item_get_title(fitem) && + !strcmp(ctx->ditem->title, feed_item_get_title(fitem))) + title_match = TRUE; + + /* time of publishing, if set... */ + if (ctx->ditem->date_published == -1 || + ctx->ditem->date_published == feed_item_get_date_published(fitem)) + pubdate_match = TRUE; + + /* if it's our item, set to NOT delete, since it's obviously + * still in the feed */ + if (id_match && title_match && pubdate_match) + ctx->delete = FALSE; } /* Checks each item in deleted items list against feed and removes it if