[evolution-rss] fix deleton for articles no longer present in the feed
- From: Lucian Langa <lucilanga src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [evolution-rss] fix deleton for articles no longer present in the feed
- Date: Sun, 2 May 2010 14:28:36 +0000 (UTC)
commit c6ea0960e24f1fa787f7c562984fe887fe5497c7
Author: Lucian Langa <lucilanga gnome org>
Date: Sun May 2 17:27:33 2010 +0300
fix deleton for articles no longer present in the feed
src/misc.c | 46 ++++++++++++++++++++++++++++++++++++++++++++++
src/misc.h | 9 ++++++---
src/parser.c | 18 +++++++++++-------
src/parser.h | 5 ++++-
src/rss.c | 14 ++++++++++++--
5 files changed, 79 insertions(+), 13 deletions(-)
---
diff --git a/src/misc.c b/src/misc.c
index 6c97e03..74d1d44 100644
--- a/src/misc.c
+++ b/src/misc.c
@@ -23,11 +23,13 @@
#include <stdint.h>
#include <string.h>
#include <glib.h>
+#include <glib/gstdio.h>
#if (DATASERVER_VERSION >= 2031001)
#include <camel/camel.h>
#else
#include <camel/camel-mime-utils.h>
#endif
+#include <e-util/e-mktemp.h>
extern int rss_verbose_debug;
@@ -530,6 +532,50 @@ encode_rfc2047(gchar *str)
return (gchar *)rfctmp;
}
+/* this whole process is not optimal
+ * but for the time being it will have to do
+ */
+void
+feed_remove_status_line(gchar *file_name, gchar *needle)
+{
+ gchar rfeed[513];
+ FILE *fr, *fw;
+ int occ = 0;
+ gchar *tmpneedle, *port, *tp;
+ gchar *tmp = e_mktemp("evo-rss-XXXXXX");
+ if (tmp) {
+ fw = fopen(tmp, "wb");
+ if (!fw)
+ return;
+ }
+
+ memset(rfeed, 0, 512);
+ fr = fopen(file_name, "r");
+ tmpneedle = NULL;
+ port = get_port_from_uri(needle);
+ if (port && atoi(port) == 80) {
+ tp = g_strconcat(":", port, NULL);
+ g_free(port);
+ tmpneedle = strextr(needle, tp);
+ g_free(tp);
+ } else
+ tmpneedle = g_strdup(needle);
+
+ if (fr) {
+ while (fgets(rfeed, 511, fr) != NULL) {
+ if (!g_strstr_len(rfeed, -1, tmpneedle)) {
+ fputs(rfeed, fw);
+ }
+ }
+ fclose(fr);
+ fclose(fw);
+ g_unlink(file_name);
+ g_rename(tmp, file_name);
+ }
+ g_free(tmpneedle);
+ return occ;
+}
+
//check if feed already exists in feed file
//and if not add it to the feed file
gboolean
diff --git a/src/misc.h b/src/misc.h
index 4aa1b99..721dfa3 100644
--- a/src/misc.h
+++ b/src/misc.h
@@ -25,9 +25,11 @@ gchar *gen_md5(gchar *buffer);
gchar *strplchr(gchar *source);
gchar *markup_decode (gchar *str);
gboolean check_key_match (gpointer key,
- gpointer value,
- gpointer user_data);
-gboolean check_if_match (gpointer key, gpointer value, gpointer user_data);
+ gpointer value,
+ gpointer user_data);
+gboolean check_if_match (gpointer key,
+ gpointer value,
+ gpointer user_data);
gchar *get_server_from_uri(gchar *uri);
gchar *get_port_from_uri(gchar *uri);
gchar *get_url_basename(gchar *url);
@@ -43,6 +45,7 @@ void print_list(gpointer data, gpointer user_data);
void print_hash(gpointer key, gpointer value, gpointer user_data);
void print_hash_int(gpointer key, gpointer value, gpointer user_data);
gboolean feed_is_new(gchar *file_name, gchar *needle);
+void feed_remove_status_line(gchar *file_name, gchar *needle);
void write_feed_status_line(gchar *file, gchar *needle);
#endif
diff --git a/src/parser.c b/src/parser.c
index 10f6543..ba103d7 100644
--- a/src/parser.c
+++ b/src/parser.c
@@ -856,7 +856,7 @@ tree_walk (xmlNodePtr root, RDF *r)
}
create_feed *
-parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date)
+parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date, gchar **article_uid)
{
char *q = NULL;
char *b = NULL;
@@ -884,7 +884,11 @@ parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date)
id = (gchar *)layer_find (top, (gchar *)"id", //ATOM
layer_find (top, (gchar *)"guid", NULL)); //RSS 2.0
feed = g_strdup_printf("%s\n", id ? id : link);
- if (feed) g_strstrip(feed);
+ if (feed) {
+ g_strstrip(feed);
+ if (article_uid != NULL)
+ *article_uid = g_strdup(feed);
+ }
//not very nice but allows shortcutting
if (feed_is_new(feed_name, feed)) {
g_free(link);
@@ -1094,6 +1098,7 @@ update_channel(RDF *r)
gchar *uid, *msg;
gboolean freeze = FALSE;
CamelFolder *mail_folder = NULL;
+ gchar *article_uid = NULL;
safes = encode_rfc2047(chn_name);
sender = g_strdup_printf("%s <%s>", safes, chn_name);
@@ -1126,14 +1131,13 @@ update_channel(RDF *r)
msg);
g_free(msg);
}
-
- CF = parse_channel_line(el->children, feed_name, main_date);
- if (!CF) continue;
if (!r->uids) {
r->uids = g_array_new(TRUE, TRUE, sizeof(gpointer));
}
- uid = g_strdup(CF->feed_uri);
- g_array_append_val(r->uids, uid);
+
+ CF = parse_channel_line(el->children, feed_name, main_date, &article_uid);
+ g_array_append_val(r->uids, article_uid);
+ if (!CF) continue;
CF->feedid = g_strdup(buf);
CF->sender = g_strdup(sender);
if (r->prefix)
diff --git a/src/parser.h b/src/parser.h
index a62cd08..0d6d947 100644
--- a/src/parser.h
+++ b/src/parser.h
@@ -43,7 +43,10 @@ GList *layer_find_all (xmlNodePtr node, const char *match, const char *fail);
xmlDoc *parse_html(char *url, const char *html, int len);
xmlDoc *parse_html_sux (const char *buf, guint len);
xmlDoc *xml_parse_sux (const char *buf, int len);
-create_feed *parse_channel_line(xmlNode *top, gchar *feed_name, char *main_date);
+create_feed *parse_channel_line(xmlNode *top,
+ gchar *feed_name,
+ char *main_date,
+ gchar **article_uid);
gchar *tree_walk (xmlNodePtr root, RDF *r);
xmlNode *html_find (xmlNode *node, gchar *match);
void html_set_base(xmlNode *doc, char *base, const char *tag, const char *prop, char *basehref);
diff --git a/src/rss.c b/src/rss.c
index e5e14ae..5d7148d 100644
--- a/src/rss.c
+++ b/src/rss.c
@@ -6744,7 +6744,7 @@ update_comments(RDF *r)
gchar *scomments;
GString *comments = g_string_new(NULL);
for (i=0; NULL != (el = g_array_index(r->item, xmlNodePtr, i)); i++) {
- CF = parse_channel_line(el->children, NULL, NULL);
+ CF = parse_channel_line(el->children, NULL, NULL, NULL);
g_string_append_printf (comments,
"<div style=\"border: solid #%06x 1px; background-color: #%06x; padding: 0px; color: #%06x;\">",
frame_colour & 0xffffff,
@@ -6932,14 +6932,24 @@ get_feed_age(RDF *r, gpointer name)
break;
for (j=0; NULL != (el = g_array_index(r->uids, gpointer, j)); j++) {
- if (!g_ascii_strcasecmp(g_strstrip(feedid), g_strstrip(el)))
+ if (!g_ascii_strcasecmp(g_strstrip(feedid), g_strstrip(el))) {
match = TRUE;
+ break;
+ }
}
if (!match) {
info = camel_folder_get_message_info(folder, uids->pdata[i]);
flags = camel_message_info_flags(info);
if ((del_unread) && !(flags & CAMEL_MESSAGE_FLAGGED)) {
+ gchar *feed_dir, *feed_name;
camel_folder_delete_message(folder, uids->pdata[i]);
+ feed_dir = rss_component_peek_base_directory();
+ feed_name = g_build_path(G_DIR_SEPARATOR_S, feed_dir, key, NULL);
+ g_free(feed_dir);
+ feed_remove_status_line(
+ feed_name,
+ g_hash_table_lookup(rf->hr, key));
+ g_free(feed_name);
}
camel_folder_free_message_info(folder, info);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]