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 */
{
/* 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
/**
* 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);
(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;
}
/**
* 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];
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;
/**
* 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;
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;
}
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;
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;
/**
* 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);
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];
}
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);
/**
* 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;
}
}
/* 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;
}
}
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;
/* 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);
*/
struct ChildCtx
{
- struct Context *ctx;
+ struct Mailbox *mailbox;
unsigned int num;
unsigned int max;
anum_t *child;
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)
{
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);
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;