]> granicus.if.org Git - neomutt/commitdiff
add EmailList for tagged Emails
authorRichard Russon <rich@flatcap.org>
Mon, 31 Dec 2018 16:21:20 +0000 (16:21 +0000)
committerRichard Russon <rich@flatcap.org>
Fri, 8 Feb 2019 14:34:07 +0000 (14:34 +0000)
context.c
context.h
email/email.h

index aac8435dd3efe739c5c51b88868b0ef44d544040..789c7c8ac64e4a4ed314f50cb82664e59d599ee8 100644 (file)
--- 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;
+}
index e71ed1ad532ac060098ec0237735675b9d0b7ad4..1974fb48c83f1026bc4e3dfe603febfa506c8dc1 100644 (file)
--- a/context.h
+++ b/context.h
@@ -29,6 +29,8 @@
 #include <time.h>
 #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 */
index cb12856f8b93ab7d1e3d73b223fddb00f8c3d388..62de7c6e25567a9513e7a08da60632992fa98c6a 100644 (file)
@@ -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);