#endif
/* Global includes */
+#include <errno.h>
#include <glib.h>
#include <glib/gi18n.h>
#include <string.h>
static gint rssyl_cb_feed_compare(const FeedItem *a, const FeedItem *b)
{
gboolean date_eq = FALSE, url_eq = FALSE, title_eq = FALSE;
+ gboolean pubdate_eq = FALSE, moddate_eq = FALSE;
gboolean no_url = FALSE, no_date = FALSE, no_title = FALSE;
+ gboolean no_pubdate = FALSE, no_moddate = FALSE;
gchar *atit = NULL, *btit = NULL;
g_return_val_if_fail(a != NULL && b != NULL, 1);
} else
no_url = TRUE;
+ /* Now we prepare some boolean flags to help us express comparing choices
+ * later on. */
+
+ /* Title */
if( (a->title != NULL) && (b->title != NULL) ) {
atit = conv_unmime_header(a->title, CS_UTF_8, FALSE);
btit = conv_unmime_header(b->title, CS_UTF_8, FALSE);
} else
no_title = TRUE;
- /* If there's no 'published' timestamp for the item, we can only judge
- * by item url - 'modified' timestamp can have changed if the item was
- * updated recently. */
- if( b->date_published <= 0 ) {
- if( b->date_modified > 0 ) {
- /* If the item has 'modified' timestamp, we can only rely on url
- * and title at this point. */
- if( (url_eq || no_url) && title_eq
- && (a->date_modified >= b->date_modified) )
- return 0;
- else
- return 1;
- } else {
- /* No timestamp of any kind, we'll just assume if both title and url
- * match, we found the right item. Items in such feeds rarely change,
- * and if they do, there's no way we can really */
- if( (url_eq || no_url) && title_eq )
- return 0;
- else
- return 1;
- }
+ /* Published date */
+ if (b->date_published <= 0) {
+ no_pubdate = TRUE;
+ } else {
+ if (a->date_published == b->date_published)
+ pubdate_eq = TRUE;
}
- /* Check if 'published' or at least 'modified' timestamps match */
- if( ((a->date_published > 0) && (b->date_published > 0) &&
- (a->date_published == b->date_published))
- || ((a->date_modified > 0) && (b->date_modified > 0) &&
- (a->date_modified == b->date_modified))) {
- date_eq = TRUE;
- } else
+ /* Modified date */
+ if (b->date_modified <= 0) {
+ no_moddate = TRUE;
+ } else {
+ if (a->date_modified == b->date_modified)
+ moddate_eq = TRUE;
+ }
+
+ if (no_pubdate && no_moddate)
no_date = TRUE;
- /* If 'published' time and item url match, it is reasonable to assume
+ if (pubdate_eq || (no_pubdate && moddate_eq))
+ date_eq = TRUE;
+
+ /* If timestamp and url match, it is reasonable to assume
* we found our item. */
- if( (no_url || url_eq) && date_eq )
+ if (url_eq && date_eq)
+ return 0;
+
+ /* Likewise if timestamp and title match. */
+ if (title_eq && date_eq)
return 0;
/* There is no timestamp and the url matches (or there is none),
return 0;
else
return 1;
+ }
- /* ... and as a last resort, if there is no title, item texts. */
- if( no_title && a->text && b->text ) {
- if( !strcmp(a->text, b->text) )
- return 0;
- else
- return 1;
- }
+ /* ... and as a last resort, if there is no title, item texts. */
+ if( no_title && a->text && b->text ) {
+ if( !strcmp(a->text, b->text) )
+ return 0;
+ else
+ return 1;
}
/* We don't know this item. */
gchar *dirname = NULL;
gchar *text = NULL;
gchar *heading = NULL;
+ gchar *pathbasename = NULL;
gchar hdr[1024];
FeedItemEnclosure *enc = NULL;
RFeedCtx *ctx;
g_return_if_fail(ritem != NULL);
/* If item title is empty, try to fill it from source title (Atom only). */
- debug_print(",%s,\n", (feed_item->title ? feed_item->title : "<null>"));
- debug_print(",%s,\n", (feed_item->sourcetitle ? feed_item->sourcetitle : "<null>"));
tmp = feed_item_get_sourcetitle(feed_item);
if( feed_item_get_title(feed_item) == NULL ||
strlen(feed_item->title) == 0 ) {
/* Fix up subject, url and ID (rssyl_format_string()) so that
* comparing doesn't break. */
debug_print("RSSyl: fixing up subject '%s'\n", feed_item_get_title(feed_item));
- feed_item_set_title(feed_item, rssyl_format_string(feed_item_get_title(feed_item), TRUE, TRUE));
+ tmp = rssyl_format_string(feed_item_get_title(feed_item), TRUE, TRUE);
+ feed_item_set_title(feed_item, tmp);
+ g_free(tmp);
debug_print("RSSyl: fixing up URL\n");
- feed_item_set_url(feed_item, rssyl_format_string(feed_item_get_url(feed_item),
- TRUE, TRUE));
+ tmp = rssyl_format_string(feed_item_get_url(feed_item), FALSE, TRUE);
+ feed_item_set_url(feed_item, tmp);
+ g_free(tmp);
if( feed_item_get_id(feed_item) != NULL ) {
debug_print("RSSyl: fixing up ID\n");
- feed_item_set_id(feed_item, rssyl_format_string(feed_item_get_id(feed_item),
- TRUE, TRUE));
+ tmp = rssyl_format_string(feed_item_get_id(feed_item), FALSE, TRUE);
+ feed_item_set_id(feed_item, tmp);
+ g_free(tmp);
}
/* If there's a summary, but no text, use summary as text. */
/* Store permflags of the old item. */
ctx = (RFeedCtx *)old_item->data;
+ pathbasename = g_path_get_basename(ctx->path);
msginfo = folder_item_get_msginfo((FolderItem *)ritem,
- atoi(g_path_get_basename(ctx->path)));
+ atoi(pathbasename));
+ g_free(pathbasename);
oldperm_flags = msginfo->flags.perm_flags;
ritem->items = g_slist_remove(ritem->items, old_item);
- g_remove(ctx->path);
+ if (g_unlink(ctx->path) != 0) {
+ debug_print("RSSyl: Error, could not delete file '%s': %s\n",
+ ctx->path, g_strerror(errno));
+ }
g_free(ctx->path);
feed_item_free(old_item);
dirname = folder_item_get_path(&ritem->item);
template = g_strconcat(dirname, G_DIR_SEPARATOR_S,
RSSYL_TMP_TEMPLATE, NULL);
- fd = mkstemp(template);
+ if ((fd = g_mkstemp(template)) < 0) {
+ g_warning("Couldn't g_mkstemp('%s'), not adding message!\n", template);
+ g_free(dirname);
+ g_free(template);
+ return;
+ }
f = fdopen(fd, "w");
- if(f == NULL) {
- g_warning("Couldn't open file '%s', not adding msg!\n", template);
+ if (f == NULL) {
+ g_warning("Couldn't open file '%s', not adding message!\n", template);
+ g_free(dirname);
g_free(template);
return;
}
d = folder_item_add_msg(&ritem->item, template, flags, TRUE);
g_free(template);
+ g_free(flags);
ctx = g_new0(RFeedCtx, 1);
ctx->path = (gpointer)g_strdup_printf("%s%c%d", dirname,
ctx->last_seen = ritem->last_update;
((FeedItem *)ritem->items->data)->data = (gpointer)ctx;
+ g_free(dirname);
+
/* Unset unread+new if the changed item wasn't set unread and user
* doesn't want to see it unread because of the change. */
- if (!(oldperm_flags & MSG_UNREAD) && (ritem->silent_update == 2
- || (ritem->silent_update == 1 && dif == EXISTS_CHANGED_TEXTONLY)))
- procmsg_msginfo_unset_flags(
- folder_item_get_msginfo((FolderItem *)ritem, d), MSG_NEW | MSG_UNREAD, 0);
+ if (dif != EXISTS_NEW) {
+ if (!(oldperm_flags & MSG_UNREAD) && (ritem->silent_update == 2
+ || (ritem->silent_update == 1 && dif == EXISTS_CHANGED_TEXTONLY)))
+ procmsg_msginfo_unset_flags(
+ folder_item_get_msginfo((FolderItem *)ritem, d), MSG_NEW | MSG_UNREAD, 0);
+ }
debug_print("RSSyl: folder_item_add_msg(): %d\n", d);
}