Rocco Rutte:
[apps/madmutt.git] / nntp / nntp.c
index efd887f..a0fd012 100644 (file)
 #include "mutt_curses.h"
 #include "sort.h"
 #include "mx.h"
+#include "mx_nntp.h"
 #include "mime.h"
 #include "rfc1524.h"
 #include "rfc2047.h"
-#include "mailbox.h"
 #include "nntp.h"
 
-#ifdef HAVE_PGP
-#include "pgp.h"
-#endif
+#include "mutt_crypt.h"
 
-#ifdef HAVE_SMIME
-#include "smime.h"
-#endif
+#include "lib/mem.h"
+#include "lib/str.h"
+#include "lib/intl.h"
+#include "lib/debug.h"
 
 #include <unistd.h>
 #include <string.h>
 
 static unsigned int _checked = 0;
 
-#ifdef DEBUG
-static void nntp_error (const char *where, const char *msg)
-{
-  dprint (1,
-          (debugfile, "nntp_error(): unexpected response in %s: %s\n", where,
-           msg));
+static void nntp_error (const char *where, const char *msg) {
+  debug_print (1, ("unexpected response in %s: %s\n", where, msg));
 }
-#endif /* DEBUG */
 
 static int nntp_auth (NNTP_SERVER * serv)
 {
@@ -70,8 +64,8 @@ static int nntp_auth (NNTP_SERVER * serv)
 
 #ifdef DEBUG
   /* don't print the password unless we're at the ungodly debugging level */
-  if (debuglevel < M_SOCK_LOG_FULL)
-    dprint (M_SOCK_LOG_CMD, (debugfile, "> AUTHINFO PASS *\n"));
+  if (DebugLevel < M_SOCK_LOG_FULL)
+    debug_print (M_SOCK_LOG_CMD, ("> AUTHINFO PASS *\n"));
 #endif
   snprintf (buf, sizeof (buf), "AUTHINFO PASS %s\r\n", conn->account.pass);
   mutt_socket_write_d (conn, buf, M_SOCK_LOG_FULL);
@@ -80,7 +74,7 @@ static int nntp_auth (NNTP_SERVER * serv)
     return -1;
   }
 
-  if (mutt_strncmp ("281", buf, 3)) {
+  if (safe_strncmp ("281", buf, 3)) {
     conn->account.flags = flags;
     mutt_error _("Login failed.");
 
@@ -115,13 +109,13 @@ static int nntp_connect_and_auth (NNTP_SERVER * serv)
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
     return nntp_connect_error (serv);
 
-  if (!mutt_strncmp ("200", buf, 3))
+  if (!safe_strncmp ("200", buf, 3))
     mutt_message (_("Connected to %s. Posting ok."), conn->account.host);
-  else if (!mutt_strncmp ("201", buf, 3))
+  else if (!safe_strncmp ("201", buf, 3))
     mutt_message (_("Connected to %s. Posting NOT ok."), conn->account.host);
   else {
     mutt_socket_close (conn);
-    mutt_remove_trailing_ws (buf);
+    str_skip_trailws (buf);
     mutt_error ("%s", buf);
     sleep (2);
     return -1;
@@ -139,7 +133,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) && mutt_strncmp ("480", buf, 3)) {
+  if (!(conn->account.flags & M_ACCT_USER) && safe_strncmp ("480", buf, 3)) {
     serv->status = NNTP_OK;
     return 0;
   }
@@ -171,28 +165,28 @@ static int nntp_attempt_features (NNTP_SERVER * serv)
   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))
+  if (safe_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);
-  if (mutt_strncmp ("500", buf, 3))
+  if (safe_strncmp ("500", buf, 3))
     serv->hasXOVER = 1;
 
   mutt_socket_write (conn, "XPAT\r\n");
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
     return nntp_connect_error (serv);
-  if (mutt_strncmp ("500", buf, 3))
+  if (safe_strncmp ("500", buf, 3))
     serv->hasXPAT = 1;
 
   mutt_socket_write (conn, "XGTITLE +\r\n");
   if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
     return nntp_connect_error (serv);
-  if (mutt_strncmp ("500", buf, 3))
+  if (safe_strncmp ("500", buf, 3))
     serv->hasXGTITLE = 1;
 
-  if (!mutt_strncmp ("282", buf, 3)) {
+  if (!safe_strncmp ("282", buf, 3)) {
     do {
       if (mutt_socket_readln (buf, sizeof (buf), conn) < 0)
         return nntp_connect_error (serv);
@@ -266,7 +260,7 @@ static int mutt_nntp_query (NNTP_DATA * data, char *line, size_t linelen)
       if (*line)
         done = FALSE;
     }
-    else if ((!mutt_strncmp ("480", buf, 3)) && nntp_auth (data->nserv) < 0)
+    else if ((!safe_strncmp ("480", buf, 3)) && nntp_auth (data->nserv) < 0)
       return -1;
   } while (!done);
 
@@ -427,10 +421,8 @@ static int nntp_read_header (CONTEXT * ctx, const char *msgid,
 
   ret = mutt_nntp_fetch (nntp_data, buf, NULL, nntp_read_tempfile, f, 0);
   if (ret) {
-#ifdef DEBUG
     if (ret != -1)
-      dprint (1, (debugfile, "nntp_read_header: %s\n", buf));
-#endif
+      debug_print (1, ("%s\n", buf));
     fclose (f);
     unlink (tempfile);
     return (ret == -1 ? -1 : 1);
@@ -466,7 +458,7 @@ static int parse_description (char *line, void *n)
   d++;
   while (*d && (*d == '\t' || *d == ' '))
     d++;
-  dprint (2, (debugfile, "group: %s, desc: %s\n", line, d));
+  debug_print (2, ("group: %s, desc: %s\n", line, d));
   if ((data = (NNTP_DATA *) hash_find (news->newsgroups, line)) != NULL &&
       mutt_strcmp (d, data->desc)) {
     FREE (&data->desc);
@@ -847,11 +839,11 @@ int nntp_open_mailbox (CONTEXT * ctx)
     return -1;
   }
 
-  if (mutt_strncmp ("211", buf, 3)) {
+  if (safe_strncmp ("211", buf, 3)) {
     LIST *l = serv->list;
 
     /* GROUP command failed */
-    if (!mutt_strncmp ("411", buf, 3)) {
+    if (!safe_strncmp ("411", buf, 3)) {
       mutt_error (_("Newsgroup %s not found on server %s"),
                   nntp_data->group, serv->conn->account.host);
 
@@ -933,7 +925,7 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
   if (ret == 1) {
     mutt_error (_("Article %d not found on server"),
                 ctx->hdrs[msgno]->article_num);
-    dprint (1, (debugfile, "nntp_fetch_message: %s\n", buf));
+    debug_print (1, ("%s\n", buf));
   }
 
   if (ret) {
@@ -961,9 +953,7 @@ int nntp_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
    * full headers aren't parsed with XOVER, so the information wasn't
    * available then.
    */
-#if defined(HAVE_PGP) || defined(HAVE_SMIME)
   ctx->hdrs[msgno]->security = crypt_query (ctx->hdrs[msgno]->content);
-#endif /* HAVE_PGP || HAVE_SMIME */
 
   mutt_clear_error ();
   rewind (msg->fp);
@@ -1090,7 +1080,7 @@ void nntp_delete_data (void *p)
   FREE (p);
 }
 
-int nntp_sync_mailbox (CONTEXT * ctx)
+int nntp_sync_mailbox (CONTEXT * ctx, int unused1, int* unused2)
 {
   NNTP_DATA *data = ctx->data;
 
@@ -1137,7 +1127,7 @@ int nntp_close_mailbox (CONTEXT * ctx)
         return -1;
     }
   }
-  nntp_sync_mailbox (ctx);
+  nntp_sync_mailbox (ctx, 0, NULL);
   if (ctx->data && ((NNTP_DATA *) ctx->data)->nserv) {
     NNTP_SERVER *news;
 
@@ -1166,7 +1156,7 @@ static int _nntp_check_mailbox (CONTEXT * ctx, NNTP_DATA * nntp_data)
 #endif
     return -1;
   }
-  if (mutt_strncmp ("211", buf, 3)) {
+  if (safe_strncmp ("211", buf, 3)) {
     buf[0] = 0;
     if (mutt_nntp_query (nntp_data, buf, sizeof (buf)) < 0) {
 #ifdef DEBUG
@@ -1175,7 +1165,7 @@ static int _nntp_check_mailbox (CONTEXT * ctx, NNTP_DATA * nntp_data)
       return -1;
     }
   }
-  if (!mutt_strncmp ("211", buf, 3)) {
+  if (!safe_strncmp ("211", buf, 3)) {
     int first;
     int last;
 
@@ -1208,7 +1198,7 @@ static int _nntp_check_mailbox (CONTEXT * ctx, NNTP_DATA * nntp_data)
   return 0;
 }
 
-int nntp_check_mailbox (CONTEXT * ctx)
+int nntp_check_mailbox (CONTEXT * ctx, int* unused1, int unused2)
 {
   return _nntp_check_mailbox (ctx, (NNTP_DATA *) ctx->data);
 }