]> granicus.if.org Git - neomutt/commitdiff
nntp: use Mailbox, not Context
authorRichard Russon <rich@flatcap.org>
Thu, 6 Sep 2018 11:20:42 +0000 (12:20 +0100)
committerRichard Russon <rich@flatcap.org>
Sun, 9 Sep 2018 15:10:35 +0000 (16:10 +0100)
curs_main.c
nntp/newsrc.c
nntp/nntp.c
nntp/nntp.h
nntp/nntp_private.h
sendlib.c

index a1026176e7ab6f0b1c3abf7230d6a7e544e7da0f..a8cb492cd6d4a0f924875745536213d38e4ca825 100644 (file)
@@ -2217,7 +2217,7 @@ int mutt_index_menu(void)
               cp = _("Open newsgroup in read-only mode");
             else
               cp = _("Open newsgroup");
-            nntp_mailbox(buf, sizeof(buf));
+            nntp_mailbox(Context->mailbox, buf, sizeof(buf));
           }
           else
 #endif
index 26c6a014b823d4a906e60dd203ea207e41d6a16c..324b81df5310971a8c63028cf5ced88894873cb9 100644 (file)
@@ -1072,7 +1072,7 @@ struct NntpServer *nntp_select_server(char *server, bool leave_lock)
       return NULL;
 
     /* check for new newsgroups */
-    if (!leave_lock && nntp_check_new_groups(nserv) < 0)
+    if (!leave_lock && nntp_check_new_groups(Context->mailbox, nserv) < 0)
       rc = -1;
 
     /* .newsrc has been externally modified */
@@ -1118,7 +1118,7 @@ struct NntpServer *nntp_select_server(char *server, bool leave_lock)
   {
     /* try to load list of newsgroups from cache */
     if (nserv->cacheable && active_get_cache(nserv) == 0)
-      rc = nntp_check_new_groups(nserv);
+      rc = nntp_check_new_groups(Context->mailbox, nserv);
 
     /* load list of newsgroups from server */
     else
@@ -1204,19 +1204,19 @@ struct NntpServer *nntp_select_server(char *server, bool leave_lock)
 
 /**
  * nntp_article_status - Get status of articles from .newsrc
- * @param ctx   Mailbox
- * @param hdr   Email Header
- * @param group Newsgroup
- * @param anum  Article number
+ * @param mailbox Mailbox
+ * @param hdr     Email Header
+ * @param group   Newsgroup
+ * @param anum    Article number
  *
  * Full status flags are not supported by nntp, but we can fake some of them:
  * Read = a read message number is in the .newsrc
  * New = not read and not cached
  * Old = not read but cached
  */
-void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, anum_t anum)
+void nntp_article_status(struct Mailbox *mailbox, struct Header *hdr, char *group, anum_t anum)
 {
-  struct NntpData *nntp_data = ctx->mailbox->data;
+  struct NntpData *nntp_data = mailbox->data;
 
   if (group)
     nntp_data = mutt_hash_find(nntp_data->nserv->groups_hash, group);
@@ -1230,7 +1230,7 @@ void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, a
         (anum <= nntp_data->newsrc_ent[i].last))
     {
       /* can't use mutt_set_flag() because mx_update_context()
-         didn't called yet */
+         didn't get called yet */
       hdr->read = true;
       return;
     }
@@ -1374,11 +1374,15 @@ struct NntpData *mutt_newsgroup_uncatchup(struct NntpServer *nserv, char *group)
 
 /**
  * nntp_mailbox - Get first newsgroup with new messages
- * @param buf Buffer for result
- * @param buflen Length of buffer
+ * @param mailbox Mailbox
+ * @param buf     Buffer for result
+ * @param buflen  Length of buffer
  */
-void nntp_mailbox(char *buf, size_t buflen)
+void nntp_mailbox(struct Mailbox *mailbox, char *buf, size_t buflen)
 {
+  if (!mailbox)
+    return;
+
   for (unsigned int i = 0; i < CurrentNewsSrv->groups_num; i++)
   {
     struct NntpData *nntp_data = CurrentNewsSrv->groups_list[i];
@@ -1386,14 +1390,13 @@ void nntp_mailbox(char *buf, size_t buflen)
     if (!nntp_data || !nntp_data->subscribed || !nntp_data->unread)
       continue;
 
-    if (Context && Context->mailbox->magic == MUTT_NNTP &&
-        (mutt_str_strcmp(nntp_data->group,
-                         ((struct NntpData *) Context->mailbox->data)->group) == 0))
+    if ((mailbox->magic == MUTT_NNTP) &&
+        (mutt_str_strcmp(nntp_data->group, ((struct NntpData *) mailbox->data)->group) == 0))
     {
       unsigned int unread = 0;
 
-      for (unsigned int j = 0; j < Context->mailbox->msg_count; j++)
-        if (!Context->mailbox->hdrs[j]->read && !Context->mailbox->hdrs[j]->deleted)
+      for (unsigned int j = 0; j < mailbox->msg_count; j++)
+        if (!mailbox->hdrs[j]->read && !mailbox->hdrs[j]->deleted)
           unread++;
       if (!unread)
         continue;
index 725e65e652763566e9ce93278e1f2b61f03817e7..bc6d9105e6b4478c989394df20132e0c414bd1bf 100644 (file)
@@ -1018,14 +1018,14 @@ static int get_description(struct NntpData *nntp_data, const char *wildmat, cons
 
 /**
  * nntp_parse_xref - Parse cross-reference
- * @param ctx Mailbox
- * @param hdr Email header
+ * @param mailbox Mailbox
+ * @param hdr     Email header
  *
  * Update read flag and set article number if empty
  */
-static void nntp_parse_xref(struct Context *ctx, struct Header *hdr)
+static void nntp_parse_xref(struct Mailbox *mailbox, struct Header *hdr)
 {
-  struct NntpData *nntp_data = ctx->mailbox->data;
+  struct NntpData *nntp_data = mailbox->data;
 
   char *buf = mutt_str_strdup(hdr->env->xref);
   char *p = buf;
@@ -1050,7 +1050,7 @@ static void nntp_parse_xref(struct Context *ctx, struct Header *hdr)
     if (sscanf(colon, ANUM, &anum) != 1)
       continue;
 
-    nntp_article_status(ctx, hdr, grp, anum);
+    nntp_article_status(mailbox, hdr, grp, anum);
     if (!NHDR(hdr)->article_num && (mutt_str_strcmp(nntp_data->group, grp) == 0))
       NHDR(hdr)->article_num = anum;
   }
@@ -1248,9 +1248,9 @@ static int parse_overview_line(char *line, void *data)
       hdr->changed = true;
     else
     {
-      nntp_article_status(ctx, hdr, NULL, anum);
+      nntp_article_status(ctx->mailbox, hdr, NULL, anum);
       if (!hdr->read)
-        nntp_parse_xref(ctx, hdr);
+        nntp_parse_xref(ctx->mailbox, hdr);
     }
     if (anum > nntp_data->last_loaded)
       nntp_data->last_loaded = anum;
@@ -1470,9 +1470,9 @@ static int nntp_fetch_headers(struct Context *ctx, void *hc, anum_t first,
       hdr->changed = true;
     else
     {
-      nntp_article_status(ctx, hdr, NULL, NHDR(hdr)->article_num);
+      nntp_article_status(ctx->mailbox, hdr, NULL, NHDR(hdr)->article_num);
       if (!hdr->read)
-        nntp_parse_xref(ctx, hdr);
+        nntp_parse_xref(ctx->mailbox, hdr);
     }
     if (current > nntp_data->last_loaded)
       nntp_data->last_loaded = current;
@@ -1775,17 +1775,19 @@ static int nntp_msg_close(struct Context *ctx, struct Message *msg)
 
 /**
  * nntp_post - Post article
- * @param msg Message to post
+ * @param mailbox Mailbox
+ * @param msg     Message to post
  * @retval  0 Success
  * @retval -1 Failure
  */
-int nntp_post(const char *msg)
+int nntp_post(struct Mailbox *mailbox, const char *msg)
 {
-  struct NntpData *nntp_data, nntp_tmp;
+  struct NntpData *nntp_data = NULL;
+  struct NntpData nntp_tmp = { 0 };
   char buf[LONG_STRING];
 
-  if (Context && Context->mailbox->magic == MUTT_NNTP)
-    nntp_data = Context->mailbox->data;
+  if (mailbox && (mailbox->magic == MUTT_NNTP))
+    nntp_data = mailbox->data;
   else
   {
     CurrentNewsSrv = nntp_select_server(NewsServer, false);
@@ -2013,9 +2015,9 @@ static int check_mailbox(struct Context *ctx)
         ctx->mailbox->hdrs[i]->flagged = flagged;
         ctx->mailbox->hdrs[i]->read = false;
         ctx->mailbox->hdrs[i]->old = false;
-        nntp_article_status(ctx, ctx->mailbox->hdrs[i], NULL, anum);
+        nntp_article_status(ctx->mailbox, ctx->mailbox->hdrs[i], NULL, anum);
         if (!ctx->mailbox->hdrs[i]->read)
-          nntp_parse_xref(ctx, ctx->mailbox->hdrs[i]);
+          nntp_parse_xref(ctx->mailbox, ctx->mailbox->hdrs[i]);
       }
       ctx->mailbox->hdrs[j++] = ctx->mailbox->hdrs[i];
     }
@@ -2057,9 +2059,9 @@ static int check_mailbox(struct Context *ctx)
         hdr->old = false;
         hdr->data = mutt_mem_calloc(1, sizeof(struct NntpHeaderData));
         NHDR(hdr)->article_num = anum;
-        nntp_article_status(ctx, hdr, NULL, anum);
+        nntp_article_status(ctx->mailbox, hdr, NULL, anum);
         if (!hdr->read)
-          nntp_parse_xref(ctx, hdr);
+          nntp_parse_xref(ctx->mailbox, hdr);
       }
     }
     FREE(&messages);
@@ -2332,12 +2334,13 @@ int nntp_active_fetch(struct NntpServer *nserv, bool new)
 
 /**
  * nntp_check_new_groups - Check for new groups/articles in subscribed groups
- * @param nserv NNTP server
+ * @param mailbox Mailbox
+ * @param nserv   NNTP server
  * @retval  1 New groups found
  * @retval  0 No new groups
  * @retval -1 Error
  */
-int nntp_check_new_groups(struct NntpServer *nserv)
+int nntp_check_new_groups(struct Mailbox *mailbox, struct NntpServer *nserv)
 {
   struct NntpData nntp_data;
   time_t now;
@@ -2368,10 +2371,10 @@ int nntp_check_new_groups(struct NntpServer *nserv)
       }
     }
     /* select current newsgroup */
-    if (Context && Context->mailbox->magic == MUTT_NNTP)
+    if (mailbox && (mailbox->magic == MUTT_NNTP))
     {
       buf[0] = '\0';
-      if (nntp_query(Context->mailbox->data, buf, sizeof(buf)) < 0)
+      if (nntp_query(mailbox->data, buf, sizeof(buf)) < 0)
         return -1;
     }
   }
@@ -2383,8 +2386,8 @@ int nntp_check_new_groups(struct NntpServer *nserv)
   if (nntp_date(nserv, &now) < 0)
     return -1;
   nntp_data.nserv = nserv;
-  if (Context && Context->mailbox->magic == MUTT_NNTP)
-    nntp_data.group = ((struct NntpData *) Context->mailbox->data)->group;
+  if (mailbox && (mailbox->magic == MUTT_NNTP))
+    nntp_data.group = ((struct NntpData *) mailbox->data)->group;
   else
     nntp_data.group = NULL;
   i = nserv->groups_num;
@@ -2485,7 +2488,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid)
 
   /* get article number */
   if (hdr->env->xref)
-    nntp_parse_xref(ctx, hdr);
+    nntp_parse_xref(ctx->mailbox, hdr);
   else
   {
     snprintf(buf, sizeof(buf), "STAT %s\r\n", msgid);
@@ -2513,7 +2516,7 @@ int nntp_check_msgid(struct Context *ctx, const char *msgid)
  */
 struct ChildCtx
 {
-  struct Context *ctx;
+  struct Mailbox *mailbox;
   unsigned int num;
   unsigned int max;
   anum_t *child;
@@ -2532,8 +2535,8 @@ static int fetch_children(char *line, void *data)
 
   if (!line || sscanf(line, ANUM, &anum) != 1)
     return 0;
-  for (unsigned int i = 0; i < cc->ctx->mailbox->msg_count; i++)
-    if (NHDR(cc->ctx->mailbox->hdrs[i])->article_num == anum)
+  for (unsigned int i = 0; i < cc->mailbox->msg_count; i++)
+    if (NHDR(cc->mailbox->hdrs[i])->article_num == anum)
       return 0;
   if (cc->num >= cc->max)
   {
@@ -2566,7 +2569,7 @@ int nntp_check_children(struct Context *ctx, const char *msgid)
     return 0;
 
   /* init context */
-  cc.ctx = ctx;
+  cc.mailbox = ctx->mailbox;
   cc.num = 0;
   cc.max = 10;
   cc.child = mutt_mem_malloc(sizeof(anum_t) * cc.max);
index 7a902914630fbf9628a0540226fa5f8737a08437..cedee4fe346bea6629d4acbc98a9ab9bf137ffb0 100644 (file)
@@ -157,19 +157,19 @@ struct NntpData *mutt_newsgroup_catchup(struct NntpServer *nserv, char *group);
 struct NntpData *mutt_newsgroup_uncatchup(struct NntpServer *nserv, char *group);
 int nntp_active_fetch(struct NntpServer *nserv, bool new);
 int nntp_newsrc_update(struct NntpServer *nserv);
-int nntp_post(const char *msg);
+int nntp_post(struct Mailbox *mailbox, const char *msg);
 int nntp_check_msgid(struct Context *ctx, const char *msgid);
 int nntp_check_children(struct Context *ctx, const char *msgid);
 int nntp_newsrc_parse(struct NntpServer *nserv);
 void nntp_newsrc_close(struct NntpServer *nserv);
-void nntp_mailbox(char *buf, size_t buflen);
+void nntp_mailbox(struct Mailbox *mailbox, char *buf, size_t buflen);
 void nntp_expand_path(char *buf, size_t buflen, struct Account *acct);
 void nntp_clear_cache(struct NntpServer *nserv);
 const char *nntp_format_str(char *buf, size_t buflen, size_t col, int cols, char op,
                             const char *src, const char *prec, const char *if_str,
                             const char *else_str, unsigned long data, enum FormatFlag flags);
 
-void nntp_article_status(struct Context *ctx, struct Header *hdr, char *group, anum_t anum);
+void nntp_article_status(struct Mailbox *mailbox, struct Header *hdr, char *group, anum_t anum);
 
 extern struct NntpServer *CurrentNewsSrv;
 
index 75cdf52a2e58a9dc96ed411b3cd71cf80ab5b47e..c9a6be48e4df4ce2679b015993ac06a2fadf9ce6 100644 (file)
@@ -28,6 +28,7 @@
 #endif
 
 struct Context;
+struct Mailbox;
 struct NntpData;
 struct NntpServer;
 
@@ -50,7 +51,7 @@ void nntp_acache_free(struct NntpData *nntp_data);
 int  nntp_active_save_cache(struct NntpServer *nserv);
 int  nntp_add_group(char *line, void *data);
 void nntp_bcache_update(struct NntpData *nntp_data);
-int  nntp_check_new_groups(struct NntpServer *nserv);
+int  nntp_check_new_groups(struct Mailbox *mailbox, struct NntpServer *nserv);
 void nntp_data_free(void *data);
 void nntp_delete_group_cache(struct NntpData *nntp_data);
 void nntp_group_unread_stat(struct NntpData *nntp_data);
index fe198d38b86b55878702f85421bfaa1c1ac4a1d7..fb3769c4978e7559cde35763eb81628d9530c3fe 100644 (file)
--- a/sendlib.c
+++ b/sendlib.c
@@ -2716,7 +2716,7 @@ int mutt_invoke_sendmail(struct Address *from, struct Address *to, struct Addres
                         NONULL(Inews), nntp_format_str, 0, 0);
     if (!*cmd)
     {
-      i = nntp_post(msg);
+      i = nntp_post(Context->mailbox, msg);
       unlink(msg);
       return i;
     }