always use LISTGROUP if available.
[apps/madmutt.git] / nntp / nntp.c
index bd1fcf0..5e76fdd 100644 (file)
@@ -22,8 +22,6 @@
 #include "buffy.h"
 #include "crypt.h"
 
-#define WANT_LISTGROUP_COMMAND          0
-
 static unsigned int _checked = 0;
 
 void nntp_sync_sidebar (NNTP_DATA* data) {
@@ -40,13 +38,13 @@ void nntp_sync_sidebar (NNTP_DATA* data) {
    * mailboxes command ;-((( FIXME
    */
   buf[0] = '\0';
-  snprintf (buf, sizeof (buf), "nntp%s://%s%s%s%s/%s",
-            (data->nserv->conn->account.flags & M_ACCT_SSL) ? "s" : "",
-            NONULL (data->nserv->conn->account.user),
-            *data->nserv->conn->account.pass ? ":" : "",
-            *data->nserv->conn->account.pass ? data->nserv->conn->account.pass : "",
-            data->nserv->conn->account.host,
-            data->group);
+  snprintf(buf, sizeof (buf), "nntp%s://%s%s%s%s/%s",
+           data->nserv->conn->account.has_ssl ? "s" : "",
+           NONULL(data->nserv->conn->account.user),
+           *data->nserv->conn->account.pass ? ":" : "",
+           *data->nserv->conn->account.pass ? data->nserv->conn->account.pass : "",
+           data->nserv->conn->account.host,
+           data->group);
 
   /* bail out if group not found via mailboxes */
   if ((i = buffy_lookup (buf)) < 0)
@@ -71,8 +69,8 @@ static int nntp_auth (NNTP_SERVER * serv)
   char buf[STRING];
   unsigned char flags = conn->account.flags;
 
-  if (mutt_account_getuser (&conn->account) || !conn->account.user[0] ||
-      mutt_account_getpass (&conn->account) || !conn->account.pass[0]) {
+  if (mutt_account_getuser(&conn->account) || !conn->account.user[0] ||
+      mutt_account_getpass(&conn->account) || !conn->account.pass[0]) {
     conn->account.flags = flags;
     return -2;
   }
@@ -140,8 +138,6 @@ static int nntp_connect_and_auth (NNTP_SERVER * serv)
     return -1;
   }
 
-  sleep (1);
-
   /* Tell INN to switch to mode reader if it isn't so. Ignore all
      returned codes and messages. */
   mutt_socket_write (conn, "MODE READER\r\n");
@@ -152,7 +148,7 @@ static int nntp_connect_and_auth (NNTP_SERVER * serv)
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
     return nntp_connect_error (serv);
 
-  if (!(conn->account.flags & M_ACCT_USER) && m_strncmp("480", buf, 3)) {
+  if (!conn->account.has_user && m_strncmp("480", buf, 3)) {
     serv->status = NNTP_OK;
     return 0;
   }
@@ -193,13 +189,11 @@ static int nntp_attempt_features (NNTP_SERVER * serv)
   if (m_strncmp("500", buf, 3))
     serv->hasXPAT = 1;
 
-#if WANT_LISTGROUP_COMMAND
   mutt_socket_write (conn, "LISTGROUP\r\n");
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
     return (nntp_connect_error (serv));
   if (m_strncmp("500", buf, 3))
     serv->hasLISTGROUP = 1;
-#endif
 
   mutt_socket_write (conn, "XGTITLE +\r\n");
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
@@ -299,8 +293,9 @@ static int mutt_nntp_query (NNTP_DATA * data, char *line, size_t linelen)
  * -2 - invalid command or execution error,
  * -3 - error in funct(*line, *data).
  */
-static int mutt_nntp_fetch (NNTP_DATA * nntp_data, const char *query, char *msg,
-                            progress_t* bar, int (*funct) (char *, void *),
+static int mutt_nntp_fetch (NNTP_DATA * nntp_data, const char *query,
+                            const char *msg, progress_t* bar,
+                            int (*funct) (char *, void *),
                             void *data, int tagged)
 {
   char buf[LONG_STRING];
@@ -436,7 +431,7 @@ static int nntp_read_header (CONTEXT * ctx, const char *msgid,
   int ret;
   HEADER *h = ctx->hdrs[ctx->msgcount];
 
-  f = m_tempfile(tempfile, sizeof(tempfile), NONULL(MCore.tmpdir), NULL);
+  f = m_tempfile(tempfile, sizeof(tempfile), NONULL(mod_core.tmpdir), NULL);
   if (!f)
     return -1;
 
@@ -604,27 +599,26 @@ typedef struct {
   char *msg;
 } FETCH_CONTEXT;
 
-#define fc ((FETCH_CONTEXT *) c)
-
-#if WANT_LISTGROUP_COMMAND
-static int _nntp_fetch_numbers (unsigned int num, void *c)
+static int nntp_fetch_numbers (char *line, void *c)
 {
+  unsigned int num;
+  FETCH_CONTEXT *fc = c;
+
+  if (!line)
+    return 0;
+
+  num = atoi(line);
   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));
-}
-#endif
 
 static int add_xover_line (char *line, void *c)
 {
   unsigned int num, total;
+  FETCH_CONTEXT *fc = c;
   CONTEXT *ctx = fc->ctx;
   NNTP_DATA *data = (NNTP_DATA *) ctx->data;
 
@@ -660,8 +654,8 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
                                unsigned int last)
 {
   char buf[HUGE_STRING];
-  char *msg = _("Fetching message headers...");
-  char *msg2 = _("Fetching headers from cache...");
+  const char *msg = _("Fetching message headers...");
+  const char *msg2 = _("Fetching headers from cache...");
   NNTP_DATA *nntp_data = ((NNTP_DATA *) ctx->data);
   int ret;
   int num;
@@ -681,7 +675,7 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
   fc.base = first;
   fc.last = last;
   fc.messages = p_new(unsigned short, last - first + 1);
-#if WANT_LISTGROUP_COMMAND
+
   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) !=
@@ -691,14 +685,10 @@ static int nntp_fetch_headers (CONTEXT * ctx, unsigned int first,
       p_delete(&fc.messages);
       return -1;
     }
-  }
-  else {
-#endif
+  } else {
     for (num = 0; num < last - first + 1; num++)
       fc.messages[num] = 1;
-#if WANT_LISTGROUP_COMMAND
   }
-#endif
 
   /* CACHE: must be loaded xover cache here */
   num = nntp_data->lastCached - first + 1;
@@ -914,7 +904,7 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
   p_delete(&cache->path);
 
   cache->index = ctx->hdrs[msgno]->index;
-  msg->fp = m_tempfile(path, sizeof(path), NONULL(MCore.tmpdir), NULL);
+  msg->fp = m_tempfile(path, sizeof(path), NONULL(mod_core.tmpdir), NULL);
   if (!msg->fp) {
     return -1;
   }