Fixed a bug when no article can be fetched after server timeout if the
authorSergey Vlasov <vsu@users.sourceforge.net>
Thu, 3 May 2001 18:11:22 +0000 (18:11 +0000)
committerSergey Vlasov <vsu@users.sourceforge.net>
Thu, 3 May 2001 18:11:22 +0000 (18:11 +0000)
connection was restored by news_post().

ChangeLog.claws
src/news.c

index 3779941..4ccc8a2 100644 (file)
@@ -1,3 +1,13 @@
+2001-05-03 [sergey]
+
+       * src/news.c: fixed a bug when no article can be fetched after
+       server timeout if the connection was restored by news_post():
+       (news_select_group): new function.
+       (news_fetch_msg): call news_select_group() before fetching
+       article.
+       (news_get_uncached_articles): set session->group after successful
+       GROUP command.
+
 2001-05-03 [hoa]
 
        * src/defs.h
index 473d733..fcf7c95 100644 (file)
@@ -57,6 +57,8 @@ static gint news_get_header            (NNTPSession   *session,
                                          gint           num,
                                          gchar         *filename);
 
+static gint news_select_group           (NNTPSession   *session,
+                                         const char    *group);
 static GSList *news_get_uncached_articles(NNTPSession  *session,
                                          FolderItem    *item,
                                          gint           cache_last,
@@ -243,6 +245,14 @@ gchar *news_fetch_msg(Folder *folder, FolderItem *item, gint num)
                return NULL;
        }
 
+       ok = news_select_group(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
+                              item->path);
+       if (ok != NN_SUCCESS) {
+               g_warning(_("can't select group %s\n"), item->path);
+               g_free(filename);
+               return NULL;
+       }
+
        debug_print(_("getting article %d...\n"), num);
        ok = news_get_article(NNTP_SESSION(REMOTE_FOLDER(folder)->session),
                              num, filename);
@@ -321,6 +331,36 @@ static gint news_get_header(NNTPSession *session, gint num, gchar *filename)
        return news_get_article_cmd(session, "HEAD", num, filename);
 }
 
+/**
+ * news_select_group:
+ * @session: Active NNTP session.
+ * @group: Newsgroup name.
+ * 
+ * Select newsgroup @group with the GROUP command if it is not already
+ * selected in @session.
+ * 
+ * Return value: NNTP result code.
+ **/
+static gint news_select_group(NNTPSession *session,
+                             const char *group)
+{
+       gint ok;
+       gint num, first, last;
+
+       if (g_strcasecmp(session->group, group) == 0)
+               return NN_SUCCESS;
+
+       g_free(session->group);
+       session->group = NULL;
+
+       ok = nntp_group(session->nntp_sock, group, &num, &first, &last);
+
+       if (ok == NN_SUCCESS)
+               session->group = g_strdup(group);
+
+       return ok;
+}
+
 static GSList *news_get_uncached_articles(NNTPSession *session,
                                          FolderItem *item, gint cache_last,
                                          gint *rfirst, gint *rlast)
@@ -340,6 +380,9 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
        g_return_val_if_fail(item->folder != NULL, NULL);
        g_return_val_if_fail(item->folder->type == F_NEWS, NULL);
 
+       g_free(session->group);
+       session->group = NULL;
+
        ok = nntp_group(session->nntp_sock, item->path,
                        &num, &first, &last);
        if (ok != NN_SUCCESS) {
@@ -347,6 +390,8 @@ static GSList *news_get_uncached_articles(NNTPSession *session,
                return NULL;
        }
 
+       session->group = g_strdup(item->path);
+
        /* calculate getting overview range */
        if (first > last) {
                log_warning(_("invalid article range: %d - %d\n"),