NeoMutt  2024-11-14-34-g5aaf0d
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
email.h File Reference

Representation of an email. More...

#include "config.h"
#include <stdbool.h>
#include <time.h>
#include "mutt/lib.h"
#include "ncrypt/lib.h"
#include "tags.h"
+ Include dependency graph for email.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Data Structures

struct  Email
 The envelope/body of an email. More...
 
struct  EmailNode
 List of Emails. More...
 
struct  EventEmail
 An Event that happened to an Email. More...
 
struct  EventHeader
 An event that happened to a header. More...
 

Enumerations

enum  ExpandoDataEmail {
  ED_EMA_ATTACHMENT_COUNT = 1 , ED_EMA_BODY_CHARACTERS , ED_EMA_COMBINED_FLAGS , ED_EMA_CRYPTO_FLAGS ,
  ED_EMA_DATE_FORMAT , ED_EMA_DATE_FORMAT_LOCAL , ED_EMA_FLAG_CHARS , ED_EMA_FROM_LIST ,
  ED_EMA_INDEX_HOOK , ED_EMA_LINES , ED_EMA_LIST_OR_SAVE_FOLDER , ED_EMA_MESSAGE_FLAGS ,
  ED_EMA_NUMBER , ED_EMA_SCORE , ED_EMA_SIZE , ED_EMA_STATUS_FLAGS ,
  ED_EMA_STRF , ED_EMA_STRF_LOCAL , ED_EMA_STRF_RECV_LOCAL , ED_EMA_TAGS ,
  ED_EMA_TAGS_TRANSFORMED , ED_EMA_THREAD_COUNT , ED_EMA_THREAD_HIDDEN_COUNT , ED_EMA_THREAD_NUMBER ,
  ED_EMA_THREAD_TAGS , ED_EMA_TO_CHARS
}
 Expando UIDs for Emails. More...
 
enum  NotifyEmail {
  NT_EMAIL_ADD = 1 , NT_EMAIL_DELETE , NT_EMAIL_DELETE_ALL , NT_EMAIL_CHANGE ,
  NT_EMAIL_CHANGE_ENVELOPE , NT_EMAIL_CHANGE_ATTACH , NT_EMAIL_CHANGE_SECURITY
}
 Types of Email Event. More...
 
enum  NotifyHeader { NT_HEADER_ADD = 1 , NT_HEADER_DELETE , NT_HEADER_CHANGE }
 Types of Header Event. More...
 

Functions

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

Detailed Description

Representation of an email.

Authors
  • Richard Russon
  • Matthew Hughes
  • Pietro Cerutti

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.h.

Enumeration Type Documentation

◆ ExpandoDataEmail

Expando UIDs for Emails.

See also
ED_EMAIL, ExpandoDomain
Enumerator
ED_EMA_ATTACHMENT_COUNT 

Email, mutt_count_body_parts()

ED_EMA_BODY_CHARACTERS 

Body.length.

ED_EMA_COMBINED_FLAGS 

Email.read, Email.old, thread_is_new(), ...

ED_EMA_CRYPTO_FLAGS 

Email.security, SecurityFlags.

ED_EMA_DATE_FORMAT 

Email.date_sent.

ED_EMA_DATE_FORMAT_LOCAL 

Email.date_sent.

ED_EMA_FLAG_CHARS 

Email.deleted, Email.attach_del, ...

ED_EMA_FROM_LIST 

Envelope.to, Envelope.cc.

ED_EMA_INDEX_HOOK 

Mailbox, Email, mutt_idxfmt_hook()

ED_EMA_LINES 

Email.lines.

ED_EMA_LIST_OR_SAVE_FOLDER 

Envelope.to, Envelope.cc, check_for_mailing_list()

ED_EMA_MESSAGE_FLAGS 

Email.tagged, Email.flagged.

ED_EMA_NUMBER 

Email.msgno.

ED_EMA_SCORE 

Email.score.

ED_EMA_SIZE 

Body.length.

ED_EMA_STATUS_FLAGS 

Email.deleted, Email.attach_del, ...

ED_EMA_STRF 

Email.date_sent, Email.zhours, Email.zminutes, Email.zoccident.

ED_EMA_STRF_LOCAL 

Email.date_sent.

ED_EMA_STRF_RECV_LOCAL 

Email.received.

ED_EMA_TAGS 

Email.tags.

ED_EMA_TAGS_TRANSFORMED 

Email.tags, driver_tags_get_transformed()

ED_EMA_THREAD_COUNT 

Email, mutt_messages_in_thread()

ED_EMA_THREAD_HIDDEN_COUNT 

Email.collapsed, Email.num_hidden, ...

ED_EMA_THREAD_NUMBER 

Email, mutt_messages_in_thread()

ED_EMA_THREAD_TAGS 

Email.tags.

ED_EMA_TO_CHARS 

Email, User_is_recipient()

Definition at line 134 of file email.h.

135{
162};
@ ED_EMA_ATTACHMENT_COUNT
Email, mutt_count_body_parts()
Definition: email.h:136
@ ED_EMA_DATE_FORMAT_LOCAL
Email.date_sent.
Definition: email.h:141
@ ED_EMA_TAGS_TRANSFORMED
Email.tags, driver_tags_get_transformed()
Definition: email.h:156
@ ED_EMA_THREAD_HIDDEN_COUNT
Email.collapsed, Email.num_hidden, ...
Definition: email.h:158
@ ED_EMA_DATE_FORMAT
Email.date_sent.
Definition: email.h:140
@ ED_EMA_THREAD_TAGS
Email.tags.
Definition: email.h:160
@ ED_EMA_TAGS
Email.tags.
Definition: email.h:155
@ ED_EMA_SIZE
Body.length.
Definition: email.h:150
@ ED_EMA_FLAG_CHARS
Email.deleted, Email.attach_del, ...
Definition: email.h:142
@ ED_EMA_THREAD_NUMBER
Email, mutt_messages_in_thread()
Definition: email.h:159
@ ED_EMA_TO_CHARS
Email, User_is_recipient()
Definition: email.h:161
@ ED_EMA_BODY_CHARACTERS
Body.length.
Definition: email.h:137
@ ED_EMA_STRF
Email.date_sent, Email.zhours, Email.zminutes, Email.zoccident.
Definition: email.h:152
@ ED_EMA_COMBINED_FLAGS
Email.read, Email.old, thread_is_new(), ...
Definition: email.h:138
@ ED_EMA_THREAD_COUNT
Email, mutt_messages_in_thread()
Definition: email.h:157
@ ED_EMA_STATUS_FLAGS
Email.deleted, Email.attach_del, ...
Definition: email.h:151
@ ED_EMA_NUMBER
Email.msgno.
Definition: email.h:148
@ ED_EMA_FROM_LIST
Envelope.to, Envelope.cc.
Definition: email.h:143
@ ED_EMA_SCORE
Email.score.
Definition: email.h:149
@ ED_EMA_CRYPTO_FLAGS
Email.security, SecurityFlags.
Definition: email.h:139
@ ED_EMA_STRF_RECV_LOCAL
Email.received.
Definition: email.h:154
@ ED_EMA_STRF_LOCAL
Email.date_sent.
Definition: email.h:153
@ ED_EMA_LIST_OR_SAVE_FOLDER
Envelope.to, Envelope.cc, check_for_mailing_list()
Definition: email.h:146
@ ED_EMA_INDEX_HOOK
Mailbox, Email, mutt_idxfmt_hook()
Definition: email.h:144
@ ED_EMA_LINES
Email.lines.
Definition: email.h:145
@ ED_EMA_MESSAGE_FLAGS
Email.tagged, Email.flagged.
Definition: email.h:147

◆ NotifyEmail

Types of Email Event.

Observers of NT_EMAIL will be passed an EventEmail.

Note
Delete notifications are sent before the object is deleted.
Other notifications are sent after the event.
Enumerator
NT_EMAIL_ADD 

Email has been added.

NT_EMAIL_DELETE 

Email is about to be deleted.

NT_EMAIL_DELETE_ALL 

All the Emails are about to be deleted.

NT_EMAIL_CHANGE 

Email has changed.

NT_EMAIL_CHANGE_ENVELOPE 

Email's Envelope has changed.

NT_EMAIL_CHANGE_ATTACH 

Email's Attachments have changed.

NT_EMAIL_CHANGE_SECURITY 

Email's security settings have changed.

Definition at line 181 of file email.h.

182{
183 NT_EMAIL_ADD = 1,
190};
@ NT_EMAIL_ADD
Email has been added.
Definition: email.h:183
@ NT_EMAIL_DELETE
Email is about to be deleted.
Definition: email.h:184
@ NT_EMAIL_CHANGE_SECURITY
Email's security settings have changed.
Definition: email.h:189
@ NT_EMAIL_DELETE_ALL
All the Emails are about to be deleted.
Definition: email.h:185
@ NT_EMAIL_CHANGE
Email has changed.
Definition: email.h:186
@ NT_EMAIL_CHANGE_ATTACH
Email's Attachments have changed.
Definition: email.h:188
@ NT_EMAIL_CHANGE_ENVELOPE
Email's Envelope has changed.
Definition: email.h:187

◆ NotifyHeader

Types of Header Event.

Observers of NT_HEADER will be passed an EventHeader.

Enumerator
NT_HEADER_ADD 

Header has been added.

NT_HEADER_DELETE 

Header has been removed.

NT_HEADER_CHANGE 

An existing header has been changed.

Definition at line 206 of file email.h.

207{
208 NT_HEADER_ADD = 1,
211};
@ NT_HEADER_CHANGE
An existing header has been changed.
Definition: email.h:210
@ NT_HEADER_ADD
Header has been added.
Definition: email.h:208
@ NT_HEADER_DELETE
Header has been removed.
Definition: email.h:209

Function Documentation

◆ ARRAY_HEAD()

ARRAY_HEAD ( EmailArray  ,
struct Email  
)

◆ 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 96 of file email.c.

97{
98 if (e1 && e2)
99 {
100 if ((e1->received != e2->received) || (e1->date_sent != e2->date_sent) ||
101 (e1->body->length != e2->body->length) || (e1->lines != e2->lines) ||
102 (e1->zhours != e2->zhours) || (e1->zminutes != e2->zminutes) ||
103 (e1->zoccident != e2->zoccident) || (e1->mime != e2->mime) ||
104 !mutt_env_cmp_strict(e1->env, e2->env) || !mutt_body_cmp_strict(e1->body, e2->body))
105 {
106 return false;
107 }
108 return true;
109 }
110 else
111 {
112 return (!e1 && !e2);
113 }
114}
bool mutt_body_cmp_strict(const struct Body *b1, const struct Body *b2)
Strictly compare two email Body's.
Definition: body.c:110
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
struct Envelope * env
Envelope information.
Definition: email.h:68
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
struct Body * body
List of MIME parts.
Definition: email.h:69
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_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 USE_NOTMUCH
66#endif
69
70 FREE(ptr);
71}
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
void mutt_env_free(struct Envelope **ptr)
Free an Envelope.
Definition: envelope.c:126
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
@ LL_NOTIFY
Log of notifications.
Definition: logging2.h:48
#define FREE(x)
Definition: memory.h:55
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
void * edata
Driver-specific data.
Definition: email.h:74
void * nm_edata
Notmuch private data.
Definition: email.h:93
char * tree
Character string to print thread tree.
Definition: email.h:125
void(* edata_free)(void **ptr)
Definition: email.h:90
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:196
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 77 of file email.c.

78{
79 static size_t sequence = 0;
80
81 struct Email *e = MUTT_MEM_CALLOC(1, struct Email);
82 STAILQ_INIT(&e->tags);
83 e->visible = true;
84 e->sequence = sequence++;
85 e->notify = notify_new();
86
87 return e;
88}
#define MUTT_MEM_CALLOC(n, type)
Definition: memory.h:40
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:121
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_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 121 of file email.c.

122{
123 if (!e || !e->body)
124 return 0;
125 return e->body->length + e->body->offset - e->body->hdr_offset;
126}
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:81
+ 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 160 of file email.c.

161{
162 struct ListNode *n = mutt_list_insert_tail(hdrlist, NULL);
163 n->data = mutt_str_dup(header);
164
165 return n;
166}
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:65
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
A List node for strings.
Definition: list.h:37
char * data
String.
Definition: list.h:38
+ Here is the call graph for this function:
+ 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 137 of file email.c.

138{
139 const char *key_end = strchr(header, ':');
140 if (!key_end)
141 return NULL;
142
143 const int keylen = key_end - header + 1;
144
145 struct ListNode *n = NULL;
146 STAILQ_FOREACH(n, hdrlist, entries)
147 {
148 if (mutt_istrn_equal(n->data, header, keylen))
149 return n;
150 }
151 return n;
152}
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:453
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:352
+ 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 202 of file email.c.

203{
204 STAILQ_REMOVE(hdrlist, target, ListNode, entries);
205 FREE(&target->data);
206 FREE(&target);
207}
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:402
+ 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 190 of file email.c.

191{
192 struct ListNode *n = header_find(hdrlist, header);
193
194 return n ? header_update(n, header) : header_add(hdrlist, header);
195}
struct ListNode * header_add(struct ListHead *hdrlist, const char *header)
Add a header to a list.
Definition: email.c:160
struct ListNode * header_update(struct ListNode *hdr, const char *header)
Update an existing header.
Definition: email.c:174
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:137
+ 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 174 of file email.c.

175{
176 FREE(&hdr->data);
177 hdr->data = mutt_str_dup(header);
178
179 return hdr;
180}
+ Here is the call graph for this function:
+ Here is the caller graph for this function: