pop: use Mailbox, not Context
authorRichard Russon <rich@flatcap.org>
Thu, 6 Sep 2018 11:33:26 +0000 (12:33 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 9 Sep 2018 15:10:39 +0000 (16:10 +0100)
pop/pop.c
pop/pop_lib.c
pop/pop_private.h

index f59e95278ee8d44c634af9e3e371e836106f4bde..23e277fc90f969404f03e3c8a3bda0411d8c91a4 100644 (file)
--- a/pop/pop.c
+++ b/pop/pop.c
@@ -247,10 +247,10 @@ static int fetch_uidl(char *line, void *data)
  */
 static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data)
 {
-  struct Context *ctx = data;
-  if (!ctx)
+  struct Mailbox *mailbox = data;
+  if (!mailbox)
     return -1;
-  struct PopData *pop_data = ctx->mailbox->data;
+  struct PopData *pop_data = mailbox->data;
   if (!pop_data)
     return -1;
 
@@ -260,11 +260,10 @@ static int msg_cache_check(const char *id, struct BodyCache *bcache, void *data)
     return 0;
 #endif
 
-  for (int i = 0; i < ctx->mailbox->msg_count; i++)
+  for (int i = 0; i < mailbox->msg_count; i++)
   {
     /* if the id we get is known for a header: done (i.e. keep in cache) */
-    if (ctx->mailbox->hdrs[i]->data &&
-        (mutt_str_strcmp(ctx->mailbox->hdrs[i]->data, id) == 0))
+    if (mailbox->hdrs[i]->data && (mutt_str_strcmp(mailbox->hdrs[i]->data, id) == 0))
       return 0;
   }
 
@@ -470,7 +469,7 @@ static int pop_fetch_headers(struct Context *ctx)
    * the availability of our cache
    */
   if (MessageCacheClean)
-    mutt_bcache_list(pop_data->bcache, msg_cache_check, (void *) ctx);
+    mutt_bcache_list(pop_data->bcache, msg_cache_check, ctx->mailbox);
 
   mutt_clear_error();
   return new_count - old_count;
@@ -529,7 +528,7 @@ static int pop_mbox_open(struct Context *ctx)
 
   while (true)
   {
-    if (pop_reconnect(ctx) < 0)
+    if (pop_reconnect(ctx->mailbox) < 0)
       return -1;
 
     ctx->mailbox->size = pop_data->size;
@@ -582,7 +581,7 @@ static int pop_mbox_close(struct Context *ctx)
   if (!pop_data)
     return 0;
 
-  pop_logout(ctx);
+  pop_logout(ctx->mailbox);
 
   if (pop_data->status != POP_NONE)
     mutt_socket_close(pop_data->conn);
@@ -651,7 +650,7 @@ static int pop_msg_open(struct Context *ctx, struct Message *msg, int msgno)
 
   while (true)
   {
-    if (pop_reconnect(ctx) < 0)
+    if (pop_reconnect(ctx->mailbox) < 0)
       return -1;
 
     /* verify that massage index is correct */
@@ -784,7 +783,7 @@ static int pop_mbox_sync(struct Context *ctx, int *index_hint)
 
   while (true)
   {
-    if (pop_reconnect(ctx) < 0)
+    if (pop_reconnect(ctx->mailbox) < 0)
       return -1;
 
     mutt_progress_init(&progress, _("Marking messages deleted..."),
@@ -863,7 +862,7 @@ static int pop_mbox_check(struct Context *ctx, int *index_hint)
   if ((pop_data->check_time + PopCheckinterval) > time(NULL))
     return 0;
 
-  pop_logout(ctx);
+  pop_logout(ctx->mailbox);
 
   mutt_socket_close(pop_data->conn);
 
index 3dc040325d109efd86a1d6e34a4a7bcb048cbfb5..ac20f07bfb9c6f173e291bf56e35c10b439f87ec 100644 (file)
@@ -417,11 +417,11 @@ err_conn:
 
 /**
  * pop_logout - logout from a POP server
- * @param ctx Context
+ * @param mailbox Mailbox
  */
-void pop_logout(struct Context *ctx)
+void pop_logout(struct Mailbox *mailbox)
 {
-  struct PopData *pop_data = ctx->mailbox->data;
+  struct PopData *pop_data = mailbox->data;
 
   if (pop_data->status == POP_CONNECTED)
   {
@@ -429,7 +429,7 @@ void pop_logout(struct Context *ctx)
     char buf[LONG_STRING];
     mutt_message(_("Closing connection to POP server..."));
 
-    if (ctx->mailbox->readonly)
+    if (mailbox->readonly)
     {
       mutt_str_strfcpy(buf, "RSET\r\n", sizeof(buf));
       ret = pop_query(pop_data, buf, sizeof(buf));
@@ -575,23 +575,25 @@ int pop_fetch_data(struct PopData *pop_data, const char *query,
  */
 static int check_uidl(char *line, void *data)
 {
-  unsigned int index;
-  struct Context *ctx = data;
+  if (!line || !data)
+    return -1;
+
   char *endp = NULL;
 
   errno = 0;
-  index = strtoul(line, &endp, 10);
-  if (errno)
+  unsigned int index = strtoul(line, &endp, 10);
+  if (errno != 0)
     return -1;
   while (*endp == ' ')
     endp++;
   memmove(line, endp, strlen(endp) + 1);
 
-  for (int i = 0; i < ctx->mailbox->msg_count; i++)
+  struct Mailbox *mailbox = data;
+  for (int i = 0; i < mailbox->msg_count; i++)
   {
-    if (mutt_str_strcmp(ctx->mailbox->hdrs[i]->data, line) == 0)
+    if (mutt_str_strcmp(mailbox->hdrs[i]->data, line) == 0)
     {
-      ctx->mailbox->hdrs[i]->refno = index;
+      mailbox->hdrs[i]->refno = index;
       break;
     }
   }
@@ -601,13 +603,13 @@ static int check_uidl(char *line, void *data)
 
 /**
  * pop_reconnect - reconnect and verify indexes if connection was lost
- * @param ctx Context
+ * @param mailbox Mailbox
  * @retval  0 Success
  * @retval -1 Error
  */
-int pop_reconnect(struct Context *ctx)
+int pop_reconnect(struct Mailbox *mailbox)
 {
-  struct PopData *pop_data = ctx->mailbox->data;
+  struct PopData *pop_data = mailbox->data;
 
   if (pop_data->status == POP_CONNECTED)
     return 0;
@@ -625,10 +627,10 @@ int pop_reconnect(struct Context *ctx)
       mutt_progress_init(&progressbar, _("Verifying message indexes..."),
                          MUTT_PROGRESS_SIZE, NetInc, 0);
 
-      for (int i = 0; i < ctx->mailbox->msg_count; i++)
-        ctx->mailbox->hdrs[i]->refno = -1;
+      for (int i = 0; i < mailbox->msg_count; i++)
+        mailbox->hdrs[i]->refno = -1;
 
-      ret = pop_fetch_data(pop_data, "UIDL\r\n", &progressbar, check_uidl, ctx);
+      ret = pop_fetch_data(pop_data, "UIDL\r\n", &progressbar, check_uidl, mailbox);
       if (ret == -2)
       {
         mutt_error("%s", pop_data->err_msg);
@@ -637,7 +639,7 @@ int pop_reconnect(struct Context *ctx)
     if (ret == 0)
       return 0;
 
-    pop_logout(ctx);
+    pop_logout(mailbox);
 
     if (ret < -1)
       return -1;
index ade12f1efdc3981150c0096652ed79d15deb5f07..84fda7bf01efe2b84b84dae7e589b5b87d766902 100644 (file)
@@ -28,6 +28,7 @@
 
 struct Account;
 struct Context;
+struct Mailbox;
 struct Progress;
 
 #define POP_PORT 110
@@ -121,7 +122,7 @@ int pop_open_connection(struct PopData *pop_data);
 int pop_query_d(struct PopData *pop_data, char *buf, size_t buflen, char *msg);
 int pop_fetch_data(struct PopData *pop_data, const char *query, struct Progress *progressbar,
                    int (*func)(char *, void *), void *data);
-int pop_reconnect(struct Context *ctx);
-void pop_logout(struct Context *ctx);
+int pop_reconnect(struct Mailbox *mailbox);
+void pop_logout(struct Mailbox *mailbox);
 
 #endif /* MUTT_POP_POP_PRIVATE_H */