NeoMutt  2020-06-26-30-g76c339
Teaching an old dog new tricks
DOXYGEN
email.c
Go to the documentation of this file.
1 
29 #include "config.h"
30 #include <stdbool.h>
31 #include "mutt/lib.h"
32 #include "email.h"
33 #include "body.h"
34 #include "envelope.h"
35 #include "tags.h"
36 
41 void email_free(struct Email **ptr)
42 {
43  if (!ptr || !*ptr)
44  return;
45 
46  struct Email *e = *ptr;
47 
48  if (e->edata && e->edata_free)
49  e->edata_free(&e->edata);
50 
51  mutt_env_free(&e->env);
53  FREE(&e->maildir_flags);
54  FREE(&e->tree);
55  FREE(&e->path);
56 #ifdef MIXMASTER
57  mutt_list_free(&e->chain);
58 #endif
60 
61  FREE(ptr);
62 }
63 
68 struct Email *email_new(void)
69 {
70  struct Email *e = mutt_mem_calloc(1, sizeof(struct Email));
71 #ifdef MIXMASTER
72  STAILQ_INIT(&e->chain);
73 #endif
74  STAILQ_INIT(&e->tags);
75  return e;
76 }
77 
84 bool email_cmp_strict(const struct Email *e1, const struct Email *e2)
85 {
86  if (e1 && e2)
87  {
88  if ((e1->received != e2->received) || (e1->date_sent != e2->date_sent) ||
89  (e1->content->length != e2->content->length) ||
90  (e1->lines != e2->lines) || (e1->zhours != e2->zhours) ||
91  (e1->zminutes != e2->zminutes) || (e1->zoccident != e2->zoccident) ||
92  (e1->mime != e2->mime) || !mutt_env_cmp_strict(e1->env, e2->env) ||
94  {
95  return false;
96  }
97  return true;
98  }
99  else
100  {
101  return (!e1 && !e2);
102  }
103 }
104 
110 size_t email_size(const struct Email *e)
111 {
112  if (!e || !e->content)
113  return 0;
114  return e->content->length + e->content->offset - e->content->hdr_offset;
115 }
116 
123 void emaillist_clear(struct EmailList *el)
124 {
125  if (!el)
126  return;
127 
128  struct EmailNode *en = NULL, *tmp = NULL;
129  STAILQ_FOREACH_SAFE(en, el, entries, tmp)
130  {
131  STAILQ_REMOVE(el, en, EmailNode, entries);
132  FREE(&en);
133  }
134  STAILQ_INIT(el);
135 }
136 
144 int emaillist_add_email(struct EmailList *el, struct Email *e)
145 {
146  if (!el || !e)
147  return -1;
148 
149  struct EmailNode *en = mutt_mem_calloc(1, sizeof(*en));
150  en->email = e;
151  STAILQ_INSERT_TAIL(el, en, entries);
152 
153  return 0;
154 }
int lines
How many lines in the body of this message?
Definition: email.h:84
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
The envelope/body of an email.
Definition: email.h:37
Representation of the body of an email.
int emaillist_add_email(struct EmailList *el, struct Email *e)
Add an Email to a list.
Definition: email.c:144
struct Body * content
List of MIME parts.
Definition: email.h:90
LOFF_T offset
offset where the actual data begins
Definition: body.h:44
bool mutt_env_cmp_strict(const struct Envelope *e1, const struct Envelope *e2)
Strictly compare two Envelopes.
Definition: envelope.c:241
#define STAILQ_INSERT_TAIL(head, elm, field)
Definition: queue.h:386
bool zoccident
True, if west of UTC, False if east.
Definition: email.h:65
void driver_tags_free(struct TagList *list)
Free tags from a header.
Definition: tags.c:104
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
bool mutt_body_cmp_strict(const struct Body *b1, const struct Body *b2)
Strictly compare two email Body&#39;s.
Definition: body.c:108
Representation of an email.
#define STAILQ_INIT(head)
Definition: queue.h:369
bool mime
Has a MIME-Version header?
Definition: email.h:42
struct Envelope * env
Envelope information.
Definition: email.h:89
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
struct TagList tags
For drivers that support server tagging.
Definition: email.h:102
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:81
struct ListHead chain
Mixmaster chain.
Definition: email.h:99
LOFF_T length
length (in bytes) of attachment
Definition: body.h:45
Representation of an email header (envelope)
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:96
void(* edata_free)(void **ptr)
Driver-specific data free function.
Definition: email.h:107
unsigned int zhours
Hours away from UTC.
Definition: email.h:63
char * tree
Character string to print thread tree.
Definition: email.h:93
bool email_cmp_strict(const struct Email *e1, const struct Email *e2)
Strictly compare message emails.
Definition: email.c:84
void emaillist_clear(struct EmailList *el)
Drop a private list of Emails.
Definition: email.c:123
void * edata
Driver-specific data.
Definition: email.h:106
struct Email * email
Email in the list.
Definition: email.h:116
char * maildir_flags
Unknown maildir flags.
Definition: email.h:104
char * path
Path of Email (for local Mailboxes)
Definition: email.h:91
#define FREE(x)
Definition: memory.h:40
Driver based email tags.
List of Emails.
Definition: email.h:114
struct Email * email_new(void)
Create a new Email.
Definition: email.c:68
long hdr_offset
Offset in stream where the headers begin.
Definition: body.h:42
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
Convenience wrapper for the library headers.
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
unsigned int zminutes
Minutes away from UTC.
Definition: email.h:64
size_t email_size(const struct Email *e)
compute the size of an email
Definition: email.c:110
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:82