NeoMutt  2018-07-16 +2481-68dcde
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/mutt.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->free_edata)
49  e->free_edata(&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  else
98  return true;
99  }
100  else
101  {
102  if (!e1 && !e2)
103  return true;
104  else
105  return false;
106  }
107 }
108 
114 size_t email_size(const struct Email *e)
115 {
116  if (!e || !e->content)
117  return 0;
118  return e->content->length + e->content->offset - e->content->hdr_offset;
119 }
120 
127 void emaillist_clear(struct EmailList *el)
128 {
129  if (!el)
130  return;
131 
132  struct EmailNode *en = NULL, *tmp = NULL;
133  STAILQ_FOREACH_SAFE(en, el, entries, tmp)
134  {
135  STAILQ_REMOVE(el, en, EmailNode, entries);
136  FREE(&en);
137  }
138  STAILQ_INIT(el);
139 }
void(* free_edata)(void **)
Driver-specific data free function.
Definition: email.h:113
int lines
How many lines in the body of this message?
Definition: email.h:86
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:400
The envelope/body of an email.
Definition: email.h:39
Representation of the body of an email.
struct Body * content
List of MIME parts.
Definition: email.h:92
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
bool zoccident
True, if west of UTC, False if east.
Definition: email.h:67
void driver_tags_free(struct TagList *list)
Free tags from a header.
Definition: tags.c:103
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:123
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:370
bool mime
Has a MIME-Version header?
Definition: email.h:44
struct Envelope * env
Envelope information.
Definition: email.h:91
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:360
struct TagList tags
For drivers that support server tagging.
Definition: email.h:108
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:83
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
unsigned int zhours
Hours away from UTC.
Definition: email.h:65
char * tree
Character string to print thread tree.
Definition: email.h:95
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:127
void * edata
Driver-specific data.
Definition: email.h:112
char * maildir_flags
Unknown maildir flags.
Definition: email.h:110
char * path
Path of Email (for local Mailboxes)
Definition: email.h:93
#define FREE(x)
Definition: memory.h:40
Driver based email tags.
List of Emails.
Definition: email.h:120
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
void email_free(struct Email **ptr)
Free an Email.
Definition: email.c:41
unsigned int zminutes
Minutes away from UTC.
Definition: email.h:66
size_t email_size(const struct Email *e)
compute the size of an email
Definition: email.c:114
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:84