NeoMutt  2024-03-23-147-g885fbc
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
email.c File Reference

Representation of an email. More...

#include "config.h"
#include <stdbool.h>
#include <string.h>
#include "mutt/lib.h"
#include "email.h"
#include "body.h"
#include "envelope.h"
#include "tags.h"
+ Include dependency graph for email.c:

Go to the source code of this file.

Functions

void nm_edata_free (void **ptr)
 Free data attached to an Email.
 
void email_free (struct Email **ptr)
 Free an Email.
 
struct Emailemail_new (void)
 Create a new Email.
 
bool email_cmp_strict (const struct Email *e1, const struct Email *e2)
 Strictly compare message emails.
 
size_t email_size (const struct Email *e)
 Compute the size of an email.
 
struct ListNodeheader_find (const struct ListHead *hdrlist, const char *header)
 Find a header, matching on its field, in a list of headers.
 
struct ListNodeheader_add (struct ListHead *hdrlist, const char *header)
 Add a header to a list.
 
struct ListNodeheader_update (struct ListNode *hdr, const char *header)
 Update an existing header.
 
struct ListNodeheader_set (struct ListHead *hdrlist, const char *header)
 Set a header value in a list.
 
void header_free (struct ListHead *hdrlist, struct ListNode *target)
 Free and remove a header from a header list.
 

Detailed Description

Representation of an email.

Authors
  • Richard Russon
  • Pietro Cerutti
  • Matthew Hughes

This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.

You should have received a copy of the GNU General Public License along with this program. If not, see http://www.gnu.org/licenses/.

Definition in file email.c.

Function Documentation

◆ nm_edata_free()

void nm_edata_free ( void **  ptr)

Free data attached to an Email.

Parameters
[out]ptrEmail data

Each email has an attached NmEmailData, which contains things like the tags (labels).

Definition at line 42 of file edata.c.

43{
44 if (!ptr || !*ptr)
45 return;
46
47 struct NmEmailData *edata = *ptr;
48
49 mutt_debug(LL_DEBUG2, "nm: freeing email %p\n", (void *) edata);
50 FREE(&edata->folder);
51 FREE(&edata->oldpath);
52 FREE(&edata->virtual_id);
53
54 FREE(ptr);
55}
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_DEBUG2
Log at debug level 2.
Definition: logging2.h:44
#define FREE(x)
Definition: memory.h:45
void * edata
Driver-specific data.
Definition: email.h:74
Notmuch-specific Email data -.
Definition: edata.h:34
+ Here is the caller graph for this function:

◆ email_free()

void email_free ( struct Email **  ptr)

Free an Email.

Parameters
[out]ptrEmail to free

Definition at line 46 of file email.c.

47{
48 if (!ptr || !*ptr)
49 return;
50
51 struct Email *e = *ptr;
52
53 mutt_debug(LL_NOTIFY, "NT_EMAIL_DELETE: %p\n", (void *) e);
54 struct EventEmail ev_e = { 1, &e };
56
57 if (e->edata_free && e->edata)
58 e->edata_free(&e->edata);
59
60 mutt_env_free(&e->env);
62 FREE(&e->tree);
63 FREE(&e->path);
64#ifdef MIXMASTER
66#endif
67#ifdef USE_NOTMUCH
69#endif
72
73 FREE(ptr);
74}
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:58
void nm_edata_free(void **ptr)
Free data attached to an Email.
Definition: edata.c:42
@ NT_EMAIL_DELETE
Email is about to be deleted.
Definition: email.h:187
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
void mutt_list_free(struct ListHead *h)
Free a List AND its strings.
Definition: list.c:122
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:173
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:75
@ NT_EMAIL
Email has changed, NotifyEmail, EventEmail.
Definition: notify_type.h:44
The envelope/body of an email.
Definition: email.h:39
struct Envelope * env
Envelope information.
Definition: email.h:68
struct Body * body
List of MIME parts.
Definition: email.h:69
void * nm_edata
Notmuch private data.
Definition: email.h:96
char * tree
Character string to print thread tree.
Definition: email.h:128
void(* edata_free)(void **ptr)
Definition: email.h:90
struct ListHead chain
Mixmaster chain.
Definition: email.h:93
struct TagList tags
For drivers that support server tagging.
Definition: email.h:72
struct Notify * notify
Notifications: NotifyEmail, EventEmail.
Definition: email.h:73
char * path
Path of Email (for local Mailboxes)
Definition: email.h:70
An Event that happened to an Email.
Definition: email.h:199
void driver_tags_free(struct TagList *tl)
Free tags from a header.
Definition: tags.c:131
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ email_new()

struct Email * email_new ( void  )

Create a new Email.

Return values
ptrNewly created Email

Definition at line 80 of file email.c.

81{
82 static size_t sequence = 0;
83
84 struct Email *e = mutt_mem_calloc(1, sizeof(struct Email));
85#ifdef MIXMASTER
86 STAILQ_INIT(&e->chain);
87#endif
88 STAILQ_INIT(&e->tags);
89 e->visible = true;
90 e->sequence = sequence++;
91 e->notify = notify_new();
92
93 return e;
94}
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:62
#define STAILQ_INIT(head)
Definition: queue.h:372
bool visible
Is this message part of the view?
Definition: email.h:124
size_t sequence
Sequence number assigned on creation.
Definition: email.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ email_cmp_strict()

bool email_cmp_strict ( const struct Email e1,
const struct Email e2 
)

Strictly compare message emails.

Parameters
e1First Email
e2Second Email
Return values
trueEmails are strictly identical

Definition at line 102 of file email.c.

103{
104 if (e1 && e2)
105 {
106 if ((e1->received != e2->received) || (e1->date_sent != e2->date_sent) ||
107 (e1->body->length != e2->body->length) || (e1->lines != e2->lines) ||
108 (e1->zhours != e2->zhours) || (e1->zminutes != e2->zminutes) ||
109 (e1->zoccident != e2->zoccident) || (e1->mime != e2->mime) ||
110 !mutt_env_cmp_strict(e1->env, e2->env) || !mutt_body_cmp_strict(e1->body, e2->body))
111 {
112 return false;
113 }
114 return true;
115 }
116 else
117 {
118 return (!e1 && !e2);
119 }
120}
bool mutt_body_cmp_strict(const struct Body *b1, const struct Body *b2)
Strictly compare two email Body's.
Definition: body.c:109
bool mutt_env_cmp_strict(const struct Envelope *e1, const struct Envelope *e2)
Strictly compare two Envelopes.
Definition: envelope.c:285
LOFF_T length
length (in bytes) of attachment
Definition: body.h:53
unsigned int zminutes
Minutes away from UTC.
Definition: email.h:57
bool mime
Has a MIME-Version header?
Definition: email.h:48
int lines
How many lines in the body of this message?
Definition: email.h:62
bool zoccident
True, if west of UTC, False if east.
Definition: email.h:58
unsigned int zhours
Hours away from UTC.
Definition: email.h:56
time_t date_sent
Time when the message was sent (UTC)
Definition: email.h:60
time_t received
Time when the message was placed in the mailbox.
Definition: email.h:61
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ email_size()

size_t email_size ( const struct Email e)

Compute the size of an email.

Parameters
eEmail
Return values
numSize of the email, in bytes

Definition at line 127 of file email.c.

128{
129 if (!e || !e->body)
130 return 0;
131 return e->body->length + e->body->offset - e->body->hdr_offset;
132}
LOFF_T offset
offset where the actual data begins
Definition: body.h:52
long hdr_offset
Offset in stream where the headers begin.
Definition: body.h:80
+ Here is the caller graph for this function:

◆ header_find()

struct ListNode * header_find ( const struct ListHead *  hdrlist,
const char *  header 
)

Find a header, matching on its field, in a list of headers.

Parameters
hdrlistList of headers to search
headerThe header to search for
Return values
ptrThe node in the list matching the header
NULLNo matching header is found

The header should either of the form "X-Header:" or "X-Header: value"

Definition at line 143 of file email.c.

144{
145 const char *key_end = strchr(header, ':');
146 if (!key_end)
147 return NULL;
148
149 const int keylen = key_end - header + 1;
150
151 struct ListNode *n = NULL;
152 STAILQ_FOREACH(n, hdrlist, entries)
153 {
154 if (mutt_istrn_equal(n->data, header, keylen))
155 return n;
156 }
157 return n;
158}
bool mutt_istrn_equal(const char *a, const char *b, size_t num)
Check for equality of two strings ignoring case (to a maximum), safely.
Definition: string.c:502
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
A List node for strings.
Definition: list.h:35
char * data
String.
Definition: list.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ header_add()

struct ListNode * header_add ( struct ListHead *  hdrlist,
const char *  header 
)

Add a header to a list.

Parameters
hdrlistList of headers to search
headerString to set as the header
Return values
ptrThe created header

Definition at line 166 of file email.c.

167{
168 struct ListNode *n = mutt_list_insert_tail(hdrlist, NULL);
169 n->data = mutt_str_dup(header);
170
171 return n;
172}
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ header_update()

struct ListNode * header_update ( struct ListNode hdr,
const char *  header 
)

Update an existing header.

Parameters
hdrThe header to update
headerString to update the header with
Return values
ptrThe updated header

Definition at line 180 of file email.c.

181{
182 FREE(&hdr->data);
183 hdr->data = mutt_str_dup(header);
184
185 return hdr;
186}
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ header_set()

struct ListNode * header_set ( struct ListHead *  hdrlist,
const char *  header 
)

Set a header value in a list.

Parameters
hdrlistList of headers to search
headerString to set the value of the header to
Return values
ptrThe updated or created header

If a header exists with the same field, update it, otherwise add a new header.

Definition at line 196 of file email.c.

197{
198 struct ListNode *n = header_find(hdrlist, header);
199
200 return n ? header_update(n, header) : header_add(hdrlist, header);
201}
struct ListNode * header_add(struct ListHead *hdrlist, const char *header)
Add a header to a list.
Definition: email.c:166
struct ListNode * header_update(struct ListNode *hdr, const char *header)
Update an existing header.
Definition: email.c:180
struct ListNode * header_find(const struct ListHead *hdrlist, const char *header)
Find a header, matching on its field, in a list of headers.
Definition: email.c:143
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ header_free()

void header_free ( struct ListHead *  hdrlist,
struct ListNode target 
)

Free and remove a header from a header list.

Parameters
hdrlistList to free the header from
targetThe header to free

Definition at line 208 of file email.c.

209{
210 STAILQ_REMOVE(hdrlist, target, ListNode, entries);
211 FREE(&target->data);
212 FREE(&target);
213}
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
+ Here is the caller graph for this function: