rationalize list handling in mutt a bit.
[apps/madmutt.git] / pop / pop.c
index c24ac1c..a8c2616 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
 # include "config.h"
 #endif
 
+#include <string.h>
+#include <unistd.h>
+
 #include <lib-lib/mem.h>
+#include <lib-lib/file.h>
+#include <lib-lib/str.h>
 #include <lib-lib/macros.h>
+#include <lib-lib/debug.h>
+
+#include <lib-ui/curses.h>
 
 #include "mutt.h"
 #include "mx.h"
 #include "pop.h"
-#include "mutt_crypt.h"
-#include "mutt_curses.h"
-
-#include "lib/str.h"
-#include "lib/debug.h"
-
-#include <string.h>
-#include <unistd.h>
+#include <lib-crypt/crypt.h>
 
 /* write line to file */
 static int fetch_message (char *line, void *file)
@@ -61,7 +62,7 @@ static pop_query_status pop_read_header (POP_DATA * pop_data, HEADER * h)
     return PFD_FUNCT_ERROR;
   }
 
-  snprintf (buf, sizeof (buf), "LIST %d\r\n", h->refno);
+  snprintf (buf, sizeof (buf), "string_list_t %d\r\n", h->refno);
   ret = pop_query (pop_data, buf, sizeof (buf));
   if (ret == PQ_OK) {
     sscanf (buf, "+OK %d %ld", &index, &length);
@@ -131,7 +132,7 @@ static int fetch_uidl (char *line, void *data)
 
   sscanf (line, "%d %s", &index, line);
   for (i = 0; i < ctx->msgcount; i++)
-    if (!str_cmp (line, ctx->hdrs[i]->data))
+    if (!m_strcmp(line, ctx->hdrs[i]->data))
       break;
 
   if (i == ctx->msgcount) {
@@ -141,8 +142,8 @@ static int fetch_uidl (char *line, void *data)
       mx_alloc_memory (ctx);
 
     ctx->msgcount++;
-    ctx->hdrs[i] = mutt_new_header ();
-    ctx->hdrs[i]->data = str_dup (line);
+    ctx->hdrs[i] = header_new();
+    ctx->hdrs[i]->data = m_strdup(line);
   }
   else if (ctx->hdrs[i]->index != index - 1)
     pop_data->clear_cache = 1;
@@ -216,7 +217,7 @@ static int pop_fetch_headers (CONTEXT * ctx)
 
   if (ret != PQ_OK) {
     for (i = ctx->msgcount; i < new_count; i++)
-      mutt_free_header (&ctx->hdrs[i]);
+      header_delete(&ctx->hdrs[i]);
     return ret;
   }
 
@@ -248,7 +249,7 @@ int pop_open_mailbox (CONTEXT * ctx)
     return -1;
 
   p_delete(&ctx->path);
-  ctx->path = str_dup (buf);
+  ctx->path = m_strdup(buf);
 
   pop_data = p_new(POP_DATA, 1);
   pop_data->conn = conn;
@@ -259,7 +260,7 @@ int pop_open_mailbox (CONTEXT * ctx)
 
   conn->data = pop_data;
 
-  FOREVER {
+  for (;;) {
     if (pop_reconnect (ctx) != PQ_OK)
       return -1;
 
@@ -354,7 +355,7 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
     }
   }
 
-  FOREVER {
+  for (;;) {
     if (pop_reconnect (ctx) != PQ_OK)
       return -1;
 
@@ -405,10 +406,10 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
    * portion of the headers, those required for the main display.
    */
   cache->index = h->index;
-  cache->path = str_dup (path);
+  cache->path = m_strdup(path);
   rewind (msg->fp);
   uidl = h->data;
-  mutt_free_envelope (&h->env);
+  envelope_delete(&h->env);
   h->env = mutt_read_rfc822_header (msg->fp, h, 0, 0);
   h->data = uidl;
   h->lines = 0;
@@ -421,8 +422,7 @@ int pop_fetch_message (MESSAGE * msg, CONTEXT * ctx, int msgno)
   h->content->length = ftello (msg->fp) - h->content->offset;
 
   /* This needs to be done in case this is a multipart message */
-  if (!WithCrypto)
-    h->security = crypt_query (h->content);
+  h->security = crypt_query (h->content);
 
   mutt_clear_error ();
   rewind (msg->fp);
@@ -440,7 +440,7 @@ pop_query_status pop_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
 
   pop_data->check_time = 0;
 
-  FOREVER {
+  for (;;) {
     if (pop_reconnect (ctx) != PQ_OK)
       return PQ_NOT_CONNECTED;
 
@@ -454,7 +454,7 @@ pop_query_status pop_sync_mailbox (CONTEXT * ctx, int unused, int *index_hint)
     }
 
     if (ret == PQ_OK) {
-      strfcpy (buf, "QUIT\r\n", sizeof (buf));
+      m_strcpy(buf, sizeof(buf), "QUIT\r\n");
       ret = pop_query (pop_data, buf, sizeof (buf));
     }
 
@@ -557,7 +557,7 @@ void pop_fetch_mail (void)
   mutt_message _("Checking for new messages...");
 
   /* find out how many messages are in the mailbox. */
-  strfcpy (buffer, "STAT\r\n", sizeof (buffer));
+  m_strcpy(buffer, sizeof(buffer), "STAT\r\n");
   ret = pop_query (pop_data, buffer, sizeof (buffer));
   if (ret == PQ_NOT_CONNECTED)
     goto fail;
@@ -570,7 +570,7 @@ void pop_fetch_mail (void)
 
   /* only get unread messages */
   if (msgs > 0 && option (OPTPOPLAST)) {
-    strfcpy (buffer, "LAST\r\n", sizeof (buffer));
+    m_strcpy(buffer, sizeof(buffer), "LAST\r\n");
     ret = pop_query (pop_data, buffer, sizeof (buffer));
     if (ret == PQ_NOT_CONNECTED)
       goto fail;
@@ -639,14 +639,14 @@ void pop_fetch_mail (void)
 
   if (rset) {
     /* make sure no messages get deleted */
-    strfcpy (buffer, "RSET\r\n", sizeof (buffer));
+    m_strcpy(buffer, sizeof(buffer), "RSET\r\n");
     if (pop_query (pop_data, buffer, sizeof (buffer)) == PQ_NOT_CONNECTED)
       goto fail;
   }
 
 finish:
   /* exit gracefully */
-  strfcpy (buffer, "QUIT\r\n", sizeof (buffer));
+  m_strcpy(buffer, sizeof(buffer), "QUIT\r\n");
   if (pop_query (pop_data, buffer, sizeof (buffer)) == PQ_NOT_CONNECTED)
     goto fail;
   mutt_socket_close (conn);