Rocco Rutte:
authorpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Wed, 2 Mar 2005 20:35:00 +0000 (20:35 +0000)
committerpdmef <pdmef@e385b8ad-14ed-0310-8656-cc95a2468c6d>
Wed, 2 Mar 2005 20:35:00 +0000 (20:35 +0000)
support for news servers without LISTGROUP (fixes bug #3483)

git-svn-id: svn://svn.berlios.de/mutt-ng/trunk@136 e385b8ad-14ed-0310-8656-cc95a2468c6d

ChangeLog.mutt-ng
UPGRADING
nntp.c
nntp.h

index c4d4cff..7f6ef9e 100644 (file)
@@ -1,5 +1,8 @@
 Changes specific to mutt-ng:
 
+2005-03-02:
+  * support for news servers without LISTGROUP (fixes bug #3483)
+
 2005-03-01:
   * made internal buffy list sorted (-> sorted in sidebar, too)
   * somewhat bigger documentation update; introduce UPGRADING document
index 67f8648..5a802f4 100644 (file)
--- a/UPGRADING
+++ b/UPGRADING
@@ -37,7 +37,7 @@ rev123, please put it "into" init and removes this comment when done!
     assumed_charset, strict_mime, file_charset 
 
     Header Caching:
-    maildir_header_cache_verify, maildir_cache 
+    maildir_header_cache_verify, header_cache 
 
     Sidebar:
     sidebar_delim, sidebar_visible, sidebar_width, shorten_hierarchy
diff --git a/nntp.c b/nntp.c
index f838921..4f03046 100644 (file)
--- a/nntp.c
+++ b/nntp.c
@@ -180,6 +180,12 @@ static int nntp_attempt_features (NNTP_SERVER *serv)
   char buf[LONG_STRING];
   CONNECTION *conn = serv->conn;
 
+  mutt_socket_write (conn, "LISTGROUP\r\n");
+  if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
+    return (nntp_connect_error (serv));
+  if (mutt_strncmp ("500", buf, 3))
+    serv->hasLISTGROUP = 1;
+
   mutt_socket_write (conn, "XOVER\r\n");
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
     return nntp_connect_error (serv);
@@ -621,18 +627,18 @@ typedef struct
 } FETCH_CONTEXT;
 
 #define fc ((FETCH_CONTEXT *) c)
-static int nntp_fetch_numbers (char *line, void *c)
-{
-  unsigned int num;
-
-  if (!line)
-    return 0;
-  num = atoi (line);
+static int _nntp_fetch_numbers (unsigned int num ,void* c) {
   if (num < fc->base || num > fc->last)
     return 0;
   fc->messages[num - fc->base] = 1;
   return 0;
 }
+static int nntp_fetch_numbers (char *line, void *c)
+{
+  if (!line)
+    return 0;
+  return (_nntp_fetch_numbers ((unsigned int) atoi (line), c));
+}
 
 static int add_xover_line (char *line, void *c)
 {
@@ -691,15 +697,31 @@ static int nntp_fetch_headers (CONTEXT *ctx, unsigned int first,
   fc.base = first;
   fc.last = last;
   fc.messages = safe_calloc (last - first + 1, sizeof (unsigned short));
-  snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
-  if (mutt_nntp_fetch (nntp_data, buf, NULL, nntp_fetch_numbers, &fc, 0) != 0)
-  {
-    mutt_error (_("LISTGROUP command failed: %s"), buf);
+  if (nntp_data->nserv->hasLISTGROUP) {
+    snprintf (buf, sizeof (buf), "LISTGROUP %s\r\n", nntp_data->group);
+    if (mutt_nntp_fetch (nntp_data, buf, NULL, nntp_fetch_numbers, &fc, 0) != 0)
+    {
+      mutt_error (_("LISTGROUP command failed: %s"), buf);
+      sleep (2);
 #ifdef DEBUG
-    nntp_error ("nntp_fetch_headers()", buf);
+      nntp_error ("nntp_fetch_headers()", buf);
 #endif
-    FREE (&fc.messages);
-    return -1;
+      FREE (&fc.messages);
+      return -1;
+    }
+  } else {
+    /* mutt_nntp_query() issues a 'GROUP nntp_data->group' 
+     * command on its own if !*buf */
+    buf[0] = '\0';
+    mutt_nntp_query (nntp_data, buf, sizeof (buf));
+    if (sscanf (buf + 4, "%d %d %d %s", &num, &fc.first, &fc.last, buf) != 4) {
+      mutt_error (_("GROUP command failed: %s"), buf);
+      FREE (&fc.messages);
+      return (-1);
+    } else {
+      for (num = fc.first; num < fc.last; num++)
+        _nntp_fetch_numbers (num, &fc);
+    }
   }
 
   /* CACHE: must be loaded xover cache here */
diff --git a/nntp.h b/nntp.h
index 3ad0a18..335f094 100644 (file)
--- a/nntp.h
+++ b/nntp.h
@@ -50,6 +50,7 @@ typedef struct
   unsigned int hasXPAT : 1;
   unsigned int hasXGTITLE : 1;
   unsigned int hasXOVER : 1;
+  unsigned int hasLISTGROUP : 1;
   unsigned int status : 3;
   char *newsrc;
   char *cache;