1 /** 2 * @file 3 * Representation of an email 4 * 5 * @authors 6 * Copyright (C) 2017 Richard Russon <rich@flatcap.org> 7 * 8 * @copyright 9 * This program is free software: you can redistribute it and/or modify it under 10 * the terms of the GNU General Public License as published by the Free Software 11 * Foundation, either version 2 of the License, or (at your option) any later 12 * version. 13 * 14 * This program is distributed in the hope that it will be useful, but WITHOUT 15 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS 16 * FOR A PARTICULAR PURPOSE. See the GNU General Public License for more 17 * details. 18 * 19 * You should have received a copy of the GNU General Public License along with 20 * this program. If not, see <http://www.gnu.org/licenses/>. 21 */ 22 23 #ifndef MUTT_EMAIL_EMAIL_H 24 #define MUTT_EMAIL_EMAIL_H 25 26 #include "config.h" 27 #include <stdbool.h> 28 #include <time.h> 29 #include "mutt/lib.h" 30 #include "ncrypt/lib.h" 31 #include "tags.h" 32 33 /** 34 * struct Email - The envelope/body of an email 35 */ 36 struct Email 37 { 38 // --------------------------------------------------------------------------- 39 // Data that gets stored in the Header Cache 40 41 SecurityFlags security; ///< bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp 42 ///< See: ncrypt/lib.h pgplib.h, smime.h 43 44 bool expired : 1; ///< Already expired? 45 bool flagged : 1; ///< Marked important? 46 bool mime : 1; ///< Has a MIME-Version header? 47 bool old : 1; ///< Email is seen, but unread 48 bool read : 1; ///< Email is read 49 bool replied : 1; ///< Email has been replied to 50 bool superseded : 1; ///< Got superseded? 51 bool trash : 1; ///< Message is marked as trashed on disk (used by the maildir_trash option) 52 53 // Timezone of the sender of this message 54 unsigned int zhours : 5; ///< Hours away from UTC 55 unsigned int zminutes : 6; ///< Minutes away from UTC 56 bool zoccident : 1; ///< True, if west of UTC, False if east 57 58 time_t date_sent; ///< Time when the message was sent (UTC) 59 time_t received; ///< Time when the message was placed in the mailbox 60 int lines; ///< How many lines in the body of this message? 61 62 // --------------------------------------------------------------------------- 63 // Management data - Runtime info and glue to hold the objects together 64 65 size_t sequence; ///< Sequence number assigned on creation 66 struct Envelope *env; ///< Envelope information 67 struct Body *body; ///< List of MIME parts 68 char *path; ///< Path of Email (for local Mailboxes) 69 LOFF_T offset; ///< Where in the stream does this message begin? 70 struct TagList tags; ///< For drivers that support server tagging 71 struct Notify *notify; ///< Notifications: #NotifyEmail, #EventEmail 72 void *edata; ///< Driver-specific data 73 74 bool active : 1; ///< Message is not to be removed 75 bool changed : 1; ///< Email has been edited 76 bool deleted : 1; ///< Email is deleted 77 bool purge : 1; ///< Skip trash folder when deleting 78 79 /** 80 * edata_free - Free the private data attached to the Email 81 * @param ptr Private data to be freed 82 * 83 * **Contract** 84 * - @a ptr is not NULL 85 * - @a *ptr is not NULL 86 */ 87 void (*edata_free)(void **ptr); 88 89 #ifdef MIXMASTER 90 struct ListHead chain; ///< Mixmaster chain 91 #endif 92 #ifdef USE_NOTMUCH 93 void *nm_edata; ///< Notmuch private data 94 #endif 95 96 // --------------------------------------------------------------------------- 97 // View data - Used by the GUI 98 99 bool attach_del : 1; ///< Has an attachment marked for deletion 100 bool attach_valid : 1; ///< true when the attachment count is valid 101 bool display_subject : 1; ///< Used for threading 102 bool matched : 1; ///< Search matches this Email 103 bool quasi_deleted : 1; ///< Deleted from neomutt, but not modified on disk 104 bool recip_valid : 1; ///< Is_recipient is valid 105 bool searched : 1; ///< Email has been searched 106 bool subject_changed : 1; ///< Used for threading 107 bool tagged : 1; ///< Email is tagged 108 bool threaded : 1; ///< Used for threading 109 110 int index; ///< The absolute (unsorted) message number 111 int msgno; ///< Number displayed to the user 112 int pair; ///< Color-pair to use when displaying in the index 113 int score; ///< Message score 114 int vnum; ///< Virtual message number 115 short attach_total; ///< Number of qualifying attachments in message, if attach_valid 116 short recipient; ///< User_is_recipient()'s return value, cached 117 118 // The following are used to support collapsing threads 119 struct MuttThread *thread; ///< Thread of Emails 120 bool collapsed : 1; ///< Is this message part of a collapsed thread? 121 bool visible : 1; ///< Is this message part of the view? 122 size_t num_hidden; ///< Number of hidden messages in this view 123 ///< (only valid when collapsed is set) 124 char *tree; ///< Character string to print thread tree 125 }; 126 127 /** 128 * struct EmailNode - List of Emails 129 */ 130 struct EmailNode 131 { 132 struct Email *email; ///< Email in the list 133 STAILQ_ENTRY(EmailNode) entries; ///< Linked list 134 }; 135 STAILQ_HEAD(EmailList, EmailNode); 136 137 /** 138 * enum NotifyEmail - Types of Email Event 139 * 140 * Observers of #NT_EMAIL will be passed an #EventEmail. 141 * 142 * @note Delete notifications are sent **before** the object is deleted. 143 * @note Other notifications are sent **after** the event. 144 */ 145 enum NotifyEmail 146 { 147 NT_EMAIL_ADD = 1, ///< Email has been added 148 NT_EMAIL_DELETE, ///< Email is about to be deleted 149 NT_EMAIL_DELETE_ALL, ///< All the Emails are about to be deleted 150 NT_EMAIL_CHANGE, ///< Email has changed 151 }; 152 153 /** 154 * struct EventEmail - An Event that happened to an Email 155 */ 156 struct EventEmail 157 { 158 int num_emails; ///< Number of Emails the event applies to 159 struct Email **emails; ///< Emails affected by the event 160 }; 161 162 /** 163 * enum NotifyHeader - Types of Header Event 164 * 165 * Observers on #NT_HEADER will be passed an #EventHeader 166 */ 167 enum NotifyHeader 168 { 169 NT_HEADER_ADD = 1, ///< Header has been added 170 NT_HEADER_DELETE, ///< Header has been removed 171 NT_HEADER_CHANGE, ///< An existing header has been changed 172 }; 173 174 /** 175 * struct EventHeader - An event that happened to a header 176 */ 177 struct EventHeader 178 { 179 char *header; ///< The contents of the header 180 }; 181 182 bool email_cmp_strict(const struct Email *e1, const struct Email *e2); 183 void email_free (struct Email **ptr); 184 struct Email *email_new (void); 185 size_t email_size (const struct Email *e); 186 187 int emaillist_add_email(struct EmailList *el, struct Email *e); 188 void emaillist_clear (struct EmailList *el); 189 190 struct ListNode *header_add (struct ListHead *hdrlist, const char *header); 191 struct ListNode *header_find (const struct ListHead *hdrlist, const char *header); 192 void header_free (struct ListHead *hdrlist, struct ListNode *target); 193 struct ListNode *header_set (struct ListHead *hdrlist, const char *header); 194 struct ListNode *header_update(struct ListNode *hdrnode, const char *header); 195 196 #endif /* MUTT_EMAIL_EMAIL_H */ 197