RSSyl: Free GError from memory where necessary.
[claws.git] / src / plugins / rssyl / parse822.c
index 846fb6d..5eadc4a 100644 (file)
@@ -50,7 +50,7 @@
  */
 FeedItem *rssyl_parse_folder_item_file(gchar *path)
 {
-       gchar *contents, **lines, **line, **splid;
+       gchar *contents, **lines, **line, **splid, *tmp, *tmp2;
        GError *error = NULL;
        FeedItem *item;
        RFeedCtx *ctx;
@@ -63,8 +63,10 @@ FeedItem *rssyl_parse_folder_item_file(gchar *path)
 
        g_file_get_contents(path, &contents, NULL, &error);
 
-       if( error )
+       if( error ) {
                g_warning("GError: '%s'\n", error->message);
+               g_error_free(error);
+       }
 
        if( contents != NULL ) {
                lines = strsplit_no_copy(contents, '\n');
@@ -138,10 +140,15 @@ FeedItem *rssyl_parse_folder_item_file(gchar *path)
 
                                /* ID */
                                if( !strcmp(line[0], "Message-ID") ) {
-                                       splid = g_strsplit_set(line[1], "<>", 3);
-                                       if( strlen(splid[1]) != 0 )
-                                               feed_item_set_id(item, splid[1]);
-                                       g_strfreev(splid);
+                                       if (line[1][0] != '<' || line[1][strlen(line[1])-1] != '>') {
+                                               debug_print("RSSyl: malformed Message-ID, ignoring...\n");
+                                       } else {
+                                               /* Get the ID from within < and >. */
+                                               tmp = line[1] + 1;
+                                               tmp2 = g_strndup(tmp, strlen(tmp) - 1);
+                                               feed_item_set_id(item, tmp2);
+                                               g_free(tmp2);
+                                       }
                                }
 
                                /* Feed comments */
@@ -236,9 +243,9 @@ static void rssyl_flush_folder_func(gpointer data, gpointer user_data)
 static void rssyl_folder_read_existing_real(RFolderItem *ritem)
 {
        gchar *path = NULL, *fname = NULL;
-       DIR *dp;
-       struct dirent *d;
-       struct stat st;
+       GDir *dp;
+       const gchar *d;
+       GError *error;
        gint num;
        FeedItem *item = NULL;
        RFeedCtx *ctx;
@@ -258,34 +265,31 @@ static void rssyl_folder_read_existing_real(RFolderItem *ritem)
        ritem->items = NULL;
        ritem->last_update = 0;
 
-       if( (dp = opendir(path)) == NULL ) {
-               FILE_OP_ERROR(path, "opendir");
+       if( (dp = g_dir_open(path, 0, &error)) == NULL ) {
+               FILE_OP_ERROR(path, "g_dir_open");
+               debug_print("g_dir_open on \"%s\" failed with error %d (%s)\n",
+                               path, error->code, error->message);
+               g_error_free(error);
                g_free(path);
                return;
        }
 
-       while( (d = readdir(dp)) != NULL ) {
+       while( (d = g_dir_read_name(dp)) != NULL ) {
                if( claws_is_exiting() ) {
-                       closedir(dp);
+                       g_dir_close(dp);
                        g_free(path);
                        return;
                }
 
-               if( d->d_name[0] != '.' && (num = to_number(d->d_name)) > 0 ) {
-                       fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d->d_name);
-                       if( g_stat(fname, &st) < 0 ) {
-                               debug_print("RSSyl: couldn't stat() file '%s', ignoring it\n", fname);
-                               g_free(fname);
-                               continue;
-                       }
-
-                       if( !S_ISREG(st.st_mode)) {
+               if( d[0] != '.' && (num = to_number(d)) > 0 ) {
+                       fname = g_strdup_printf("%s%c%s", path, G_DIR_SEPARATOR, d);
+                       if (!g_file_test(fname, G_FILE_TEST_IS_REGULAR)) {
                                debug_print("RSSyl: not a regular file: '%s', ignoring it\n", fname);
                                g_free(fname);
                                continue;
                        }
 
-                       debug_print("RSSyl: starting to parse '%s'\n", d->d_name);
+                       debug_print("RSSyl: starting to parse '%s'\n", d);
                        if( (item = rssyl_parse_folder_item_file(fname)) != NULL ) {
                                /* Find latest timestamp */
                                ctx = (RFeedCtx *)item->data;
@@ -298,7 +302,7 @@ static void rssyl_folder_read_existing_real(RFolderItem *ritem)
                }
        }
 
-       closedir(dp);
+       g_dir_close(dp);
        g_free(path);
 
        ritem->items = g_slist_reverse(ritem->items);