LISTGROUP isn't as efficient as XOVER. Only use it if needed.
[apps/madmutt.git] / nntp / nntp.c
index 6b1888e..aad5bb2 100644 (file)
@@ -627,7 +627,7 @@ static int add_xover_line (char *line, void *c)
   nntp_parse_xover (ctx, line, ctx->hdrs[ctx->msgcount]);
   num = ctx->hdrs[ctx->msgcount]->article_num;
 
-  if (bit_isset(&fc->messages, num)) {
+  if (num >= fc->first && num <= fc->last) {
     ctx->msgcount++;
     if (num > data->lastLoaded)
       data->lastLoaded = num;
@@ -635,9 +635,9 @@ static int add_xover_line (char *line, void *c)
     total = fc->last - fc->first + 1;
     if (!ctx->quiet && fc->msg && ReadInc && (num % ReadInc == 0))
       mutt_message ("%s %d/%d", fc->msg, num, total);
-  }
-  else
+  } else {
     header_delete(&ctx->hdrs[ctx->msgcount]);       /* skip it */
+  }
 
   return 0;
 }
@@ -663,22 +663,6 @@ static int nntp_fetch_headers(CONTEXT * ctx, int first, int last)
   fc.ctx   = ctx;
   fc.first = first;
   fc.last  = last;
-  bits_init(&fc.messages);
-
-  if (nntp_data->nserv->hasLISTGROUP) {
-    snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
-    if (mutt_nntp_fetch(nntp_data, buf, NULL, NULL,
-                        nntp_fetch_numbers, &fc, 0))
-    {
-      mutt_error (_("LISTGROUP command failed: %s"), buf);
-      sleep (2);
-      bits_wipe(&fc.messages);
-      return -1;
-    }
-  } else {
-    for (num = first; num <= last; num++)
-      bit_set(&fc.messages, num);
-  }
 
   /* CACHE: must be loaded xover cache here */
   num = nntp_data->lastCached - first + 1;
@@ -715,7 +699,6 @@ static int nntp_fetch_headers(CONTEXT * ctx, int first, int last)
   }
   num = last - first + 1;
   if (num <= 0) {
-    bits_wipe(&fc.messages);
     return 0;
   }
 
@@ -735,11 +718,26 @@ static int nntp_fetch_headers(CONTEXT * ctx, int first, int last)
       mx_update_context (ctx, ctx->msgcount - oldmsgcount);
     if (ret != 0) {
       mutt_error (_("XOVER command failed: %s"), buf);
-      bits_wipe(&fc.messages);
       return -1;
     }
-  /* fetched OK */
   } else {
+    bits_init(&fc.messages);
+
+    if (nntp_data->nserv->hasLISTGROUP) {
+      snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
+      if (mutt_nntp_fetch(nntp_data, buf, NULL, NULL,
+                          nntp_fetch_numbers, &fc, 0))
+      {
+        mutt_error (_("LISTGROUP command failed: %s"), buf);
+        sleep (2);
+        bits_wipe(&fc.messages);
+        return -1;
+      }
+    } else {
+      for (num = first; num <= last; num++)
+        bit_set(&fc.messages, num);
+    }
+
     for (current = first; current <= last; current++) {
       HEADER *h;
 
@@ -770,14 +768,15 @@ static int nntp_fetch_headers(CONTEXT * ctx, int first, int last)
       if (current > nntp_data->lastLoaded)
         nntp_data->lastLoaded = current;
     }
+    bits_wipe(&fc.messages);
   }
-  bits_wipe(&fc.messages);
+
   nntp_data->lastLoaded = last;
   mutt_clear_error ();
   return 0;
 }
 
-/* 
+/*
  * currently, nntp "mailbox" is "newsgroup"
  */
 static int nntp_open_mailbox (CONTEXT * ctx)