From: Richard Russon Date: Mon, 31 Dec 2018 16:21:20 +0000 (+0000) Subject: add EmailList for tagged Emails X-Git-Tag: 2019-10-25~373^2~22 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=b1318b3571e06d3d0283d941d4fde7f17b581958;p=neomutt add EmailList for tagged Emails --- diff --git a/context.c b/context.c index aac8435dd..789c7c8ac 100644 --- a/context.c +++ b/context.c @@ -309,3 +309,85 @@ bool message_is_tagged(struct Context *ctx, int index) { return message_is_visible(ctx, index) && ctx->mailbox->emails[index]->tagged; } + +/** + * el_free - Drop a private list of Emails + * @param el EmailList to empty + * + * The Emails are not freed. + */ +void el_free(struct EmailList *el) +{ + if (!el) + return; + + struct EmailNode *en = NULL, *tmp = NULL; + STAILQ_FOREACH_SAFE(en, el, entries, tmp) + { + STAILQ_REMOVE(el, en, EmailNode, entries); + FREE(&en); + } + STAILQ_INIT(el); +} + +/** + * el_add_tagged - Get a list of the tagged Emails + * @param el Empty EmailList to populate + * @param ctx Current Mailbox + * @param e Current Email + * @param use_tagged Use tagged Emails + * @retval num Number of selected emails + * @retval -1 Error + */ +int el_add_tagged(struct EmailList *el, struct Context *ctx, struct Email *e, bool use_tagged) +{ + int count = 0; + + if (use_tagged) + { + if (!ctx || !ctx->mailbox || !ctx->mailbox->emails) + return -1; + + for (size_t i = 0; i < ctx->mailbox->msg_count; i++) + { + if (!message_is_tagged(ctx, i)) + continue; + + struct EmailNode *en = mutt_mem_calloc(1, sizeof(*en)); + en->email = ctx->mailbox->emails[i]; + STAILQ_INSERT_TAIL(el, en, entries); + count++; + } + } + else + { + if (!e) + return -1; + + struct EmailNode *en = mutt_mem_calloc(1, sizeof(*en)); + en->email = e; + STAILQ_INSERT_TAIL(el, en, entries); + count = 1; + } + + return count; +} + +/** + * el_add_email - Get a list of the selected Emails + * @param e Current Email + * @param el EmailList to add to + * @retval 0 Success + * @retval -1 Error + */ +int el_add_email(struct EmailList *el, struct Email *e) +{ + if (!el || !e) + return -1; + + struct EmailNode *en = mutt_mem_calloc(1, sizeof(*en)); + en->email = e; + STAILQ_INSERT_TAIL(el, en, entries); + + return 0; +} diff --git a/context.h b/context.h index e71ed1ad5..1974fb48c 100644 --- a/context.h +++ b/context.h @@ -29,6 +29,8 @@ #include #include "mailbox.h" +struct EmailList; + /** * struct Context - The "current" mailbox */ @@ -57,4 +59,8 @@ void ctx_update_tables(struct Context *ctx, bool committing); bool message_is_tagged(struct Context *ctx, int index); bool message_is_visible(struct Context *ctx, int index); +int el_add_email(struct EmailList *el, struct Email *e); +int el_add_tagged(struct EmailList *el, struct Context *ctx, struct Email *e, bool use_tagged); +void el_free(struct EmailList *el); + #endif /* MUTT_CONTEXT_H */ diff --git a/email/email.h b/email/email.h index cb12856f8..62de7c6e2 100644 --- a/email/email.h +++ b/email/email.h @@ -113,6 +113,17 @@ struct Email void (*free_edata)(void **); /**< driver-specific data free function */ }; +/** + * struct EmailNode - List of Emails + */ +struct EmailNode +{ + struct Email *email; + STAILQ_ENTRY(EmailNode) entries; +}; + +STAILQ_HEAD(EmailList, EmailNode); + bool mutt_email_cmp_strict(const struct Email *e1, const struct Email *e2); void mutt_email_free(struct Email **e); struct Email *mutt_email_new(void);