NeoMutt
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
recvattach.h File Reference

Routines for managing attachments. More...

#include <stddef.h>
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include "format_flags.h"
+ Include dependency graph for recvattach.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void mutt_attach_init (struct AttachCtx *actx)
 Create a new Attachment context.
 
void mutt_update_tree (struct AttachCtx *actx)
 Refresh the list of attachments.
 
const char * attach_format_str (char *buf, size_t buflen, size_t col, int cols, char op, const char *src, const char *prec, const char *if_str, const char *else_str, intptr_t data, MuttFormatFlags flags)
 Format a string for the attachment menu - Implements format_t -.
 
void dlg_attachment (struct ConfigSubset *sub, struct MailboxView *mv, struct Email *e, FILE *fp, bool attach_msg)
 Show the attachments in a Menu -.
 
void mutt_generate_recvattach_list (struct AttachCtx *actx, struct Email *e, struct Body *parts, FILE *fp, int parent_type, int level, bool decrypted)
 Create a list of attachments.
 
struct AttachPtrcurrent_attachment (struct AttachCtx *actx, struct Menu *menu)
 Get the current attachment.
 
void mutt_update_recvattach_menu (struct AttachCtx *actx, struct Menu *menu, bool init)
 Update the Attachment Menu.
 
void recvattach_edit_content_type (struct AttachCtx *actx, struct Menu *menu, struct Email *e)
 Edit the content type of an attachment.
 
int ba_add_tagged (struct BodyArray *ba, struct AttachCtx *actx, struct Menu *menu)
 Get an array of tagged Attachments.
 

Detailed Description

Routines for managing attachments.

Authors
  • Michael R. Elkins
  • Thomas Roessler

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

Function Documentation

◆ mutt_attach_init()

void mutt_attach_init ( struct AttachCtx actx)

Create a new Attachment context.

Parameters
actxAttachment context

Definition at line 1183 of file recvattach.c.

1184{
1185 /* Collapse the attachments if '$digest_collapse' is set AND if...
1186 * the outer container is of type 'multipart/digest' */
1187 bool digest = mutt_istr_equal(actx->email->body->subtype, "digest");
1188
1189 const bool c_digest_collapse = cs_subset_bool(NeoMutt->sub, "digest_collapse");
1190 for (int i = 0; i < actx->idxlen; i++)
1191 {
1192 actx->idx[i]->body->tagged = false;
1193
1194 /* OR an inner container is of type 'multipart/digest' */
1195 actx->idx[i]->collapsed = (c_digest_collapse &&
1196 (digest ||
1197 ((actx->idx[i]->body->type == TYPE_MULTIPART) &&
1198 mutt_istr_equal(actx->idx[i]->body->subtype, "digest"))));
1199 }
1200}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:48
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:810
struct Email * email
Used by recvattach for updating.
Definition: attach.h:52
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:55
short idxlen
Number of attachmentes.
Definition: attach.h:56
struct Body * body
Attachment.
Definition: attach.h:36
bool collapsed
Group is collapsed.
Definition: attach.h:44
bool tagged
This attachment is tagged.
Definition: body.h:89
char * subtype
content-type subtype
Definition: body.h:60
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
struct Body * body
List of MIME parts.
Definition: email.h:67
Container for Accounts, Notifications.
Definition: neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_update_tree()

void mutt_update_tree ( struct AttachCtx actx)

Refresh the list of attachments.

Parameters
actxAttachment context

Definition at line 116 of file recvattach.c.

117{
118 char buf[256] = { 0 };
119 char *s = NULL;
120
121 mutt_update_v2r(actx);
122
123 for (int vindex = 0; vindex < actx->vcount; vindex++)
124 {
125 const int rindex = actx->v2r[vindex];
126 actx->idx[rindex]->num = vindex;
127 if ((2 * (actx->idx[rindex]->level + 2)) < sizeof(buf))
128 {
129 if (actx->idx[rindex]->level)
130 {
131 s = buf + 2 * (actx->idx[rindex]->level - 1);
132 *s++ = (actx->idx[rindex]->body->next) ? MUTT_TREE_LTEE : MUTT_TREE_LLCORNER;
133 *s++ = MUTT_TREE_HLINE;
134 *s++ = MUTT_TREE_RARROW;
135 }
136 else
137 {
138 s = buf;
139 }
140 *s = '\0';
141 }
142
143 if (actx->idx[rindex]->tree)
144 {
145 if (!mutt_str_equal(actx->idx[rindex]->tree, buf))
146 mutt_str_replace(&actx->idx[rindex]->tree, buf);
147 }
148 else
149 {
150 actx->idx[rindex]->tree = mutt_str_dup(buf);
151 }
152
153 if (((2 * (actx->idx[rindex]->level + 2)) < sizeof(buf)) &&
154 actx->idx[rindex]->level)
155 {
156 s = buf + 2 * (actx->idx[rindex]->level - 1);
157 *s++ = (actx->idx[rindex]->body->next) ? '\005' : '\006';
158 *s++ = '\006';
159 }
160 }
161}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:798
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:327
@ MUTT_TREE_LLCORNER
Lower left corner.
Definition: mutt_thread.h:56
@ MUTT_TREE_RARROW
Right arrow.
Definition: mutt_thread.h:62
@ MUTT_TREE_LTEE
Left T-piece.
Definition: mutt_thread.h:58
@ MUTT_TREE_HLINE
Horizontal line.
Definition: mutt_thread.h:59
static void mutt_update_v2r(struct AttachCtx *actx)
Update the virtual list of attachments.
Definition: recvattach.c:85
short vcount
The number of virtual attachments.
Definition: attach.h:60
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:59
char * tree
Tree characters to display.
Definition: attach.h:39
int num
Attachment index number.
Definition: attach.h:41
int level
Nesting depth of attachment.
Definition: attach.h:40
struct Body * next
next attachment in the list
Definition: body.h:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_generate_recvattach_list()

void mutt_generate_recvattach_list ( struct AttachCtx actx,
struct Email e,
struct Body parts,
FILE *  fp,
int  parent_type,
int  level,
bool  decrypted 
)

Create a list of attachments.

Parameters
actxAttachment context
eEmail
partsBody of email
fpFile to read from
parent_typeType, e.g. TYPE_MULTIPART
levelAttachment depth
decryptedTrue if attachment has been decrypted

Definition at line 1085 of file recvattach.c.

1088{
1089 struct Body *m = NULL;
1090 struct Body *new_body = NULL;
1091 FILE *fp_new = NULL;
1093
1094 for (m = parts; m; m = m->next)
1095 {
1096 bool need_secured = false;
1097 bool secured = false;
1098
1100 {
1101 need_secured = true;
1102
1103 if (type & SEC_ENCRYPT)
1104 {
1106 goto decrypt_failed;
1107
1108 if (e->env)
1110 }
1111
1112 secured = (crypt_smime_decrypt_mime(fp, &fp_new, m, &new_body) == 0);
1113 /* If the decrypt/verify-opaque doesn't generate mime output, an empty
1114 * text/plain type will still be returned by mutt_read_mime_header().
1115 * We can't distinguish an actual part from a failure, so only use a
1116 * text/plain that results from a single top-level part. */
1117 if (secured && (new_body->type == TYPE_TEXT) &&
1118 mutt_istr_equal("plain", new_body->subtype) && ((parts != m) || m->next))
1119 {
1120 mutt_body_free(&new_body);
1121 mutt_file_fclose(&fp_new);
1122 goto decrypt_failed;
1123 }
1124
1125 if (secured && (type & SEC_ENCRYPT))
1126 e->security |= SMIME_ENCRYPT;
1127 }
1128
1129 if (((WithCrypto & APPLICATION_PGP) != 0) &&
1131 {
1132 need_secured = true;
1133
1135 goto decrypt_failed;
1136
1137 secured = (crypt_pgp_decrypt_mime(fp, &fp_new, m, &new_body) == 0);
1138
1139 if (secured)
1140 e->security |= PGP_ENCRYPT;
1141 }
1142
1143 if (need_secured && secured)
1144 {
1145 mutt_actx_add_fp(actx, fp_new);
1146 mutt_actx_add_body(actx, new_body);
1147 mutt_generate_recvattach_list(actx, e, new_body, fp_new, parent_type, level, 1);
1148 continue;
1149 }
1150
1151 decrypt_failed:
1152 /* Fall through and show the original parts if decryption fails */
1153 if (need_secured && !secured)
1154 mutt_error(_("Can't decrypt encrypted message"));
1155
1156 struct AttachPtr *ap = mutt_aptr_new();
1157 mutt_actx_add_attach(actx, ap);
1158
1159 ap->body = m;
1160 ap->fp = fp;
1161 m->aptr = ap;
1163 ap->level = level;
1164 ap->decrypted = decrypted;
1165
1166 if (mutt_is_message_type(m->type, m->subtype))
1167 {
1169 level + 1, decrypted);
1170 e->security |= m->email->security;
1171 }
1172 else
1173 {
1174 mutt_generate_recvattach_list(actx, e, m->parts, fp, m->type, level + 1, decrypted);
1175 }
1176 }
1177}
void mutt_actx_add_body(struct AttachCtx *actx, struct Body *new_body)
Add an email body to an Attachment Context.
Definition: attach.c:142
void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
Add an Attachment to an Attachment Context.
Definition: attach.c:65
void mutt_actx_add_fp(struct AttachCtx *actx, FILE *fp_new)
Save a File handle to the Attachment Context.
Definition: attach.c:121
struct AttachPtr * mutt_aptr_new(void)
Create a new Attachment Pointer.
Definition: attach.c:40
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:598
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:135
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:432
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:493
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:433
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:455
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **cur)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition: cryptglue.c:211
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
Definition: parse.c:1482
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:152
#define mutt_error(...)
Definition: logging2.h:92
@ TYPE_TEXT
Type: 'text/*'.
Definition: mime.h:38
#define _(a)
Definition: message.h:28
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:77
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:91
#define PGP_ENCRYPT
Definition: lib.h:97
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:92
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:79
#define SMIME_ENCRYPT
Definition: lib.h:103
#define WithCrypto
Definition: lib.h:117
void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *e, struct Body *parts, FILE *fp, int parent_type, int level, bool decrypted)
Create a list of attachments.
Definition: recvattach.c:1085
An email to which things will be attached.
Definition: attach.h:35
FILE * fp
Used in the recvattach menu.
Definition: attach.h:37
bool decrypted
Not part of message as stored in the email->body.
Definition: attach.h:43
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:38
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:74
struct Email * email
header information for message/rfc822
Definition: body.h:73
struct Envelope * env
Envelope information.
Definition: email.h:66
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition: email.h:41
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ current_attachment()

struct AttachPtr * current_attachment ( struct AttachCtx actx,
struct Menu menu 
)

Get the current attachment.

Parameters
actxAttachment context
menuMenu
Return values
ptrCurrent Attachment

Definition at line 71 of file recvattach.c.

72{
73 const int virt = menu_get_index(menu);
74 const int index = actx->v2r[virt];
75
76 return actx->idx[index];
77}
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:156
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_update_recvattach_menu()

void mutt_update_recvattach_menu ( struct AttachCtx actx,
struct Menu menu,
bool  init 
)

Update the Attachment Menu.

Parameters
actxAttachment context
menuMenu listing Attachments
initIf true, create a new Attachments context

Definition at line 1208 of file recvattach.c.

1209{
1210 if (init)
1211 {
1212 mutt_generate_recvattach_list(actx, actx->email, actx->email->body,
1213 actx->fp_root, -1, 0, 0);
1214 mutt_attach_init(actx);
1215 }
1216
1217 mutt_update_tree(actx);
1218
1219 menu->max = actx->vcount;
1220
1221 const int index = menu_get_index(menu);
1222 if (index >= menu->max)
1223 menu_set_index(menu, menu->max - 1);
1225}
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:57
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:180
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:170
void mutt_attach_init(struct AttachCtx *actx)
Create a new Attachment context.
Definition: recvattach.c:1183
void mutt_update_tree(struct AttachCtx *actx)
Refresh the list of attachments.
Definition: recvattach.c:116
FILE * fp_root
Used by recvattach for updating.
Definition: attach.h:53
int max
Number of entries in the menu.
Definition: lib.h:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ recvattach_edit_content_type()

void recvattach_edit_content_type ( struct AttachCtx actx,
struct Menu menu,
struct Email e 
)

Edit the content type of an attachment.

Parameters
actxAttachment context
menuMenu listing Attachments
eEmail

Definition at line 928 of file recvattach.c.

929{
930 struct AttachPtr *cur_att = current_attachment(actx, menu);
931 if (!mutt_edit_content_type(e, cur_att->body, cur_att->fp))
932 return;
933
934 /* The mutt_update_recvattach_menu() will overwrite any changes
935 * made to a decrypted cur_att->body, so warn the user. */
936 if (cur_att->decrypted)
937 {
938 mutt_message(_("Structural changes to decrypted attachments are not supported"));
939 mutt_sleep(1);
940 }
941 /* Editing the content type can rewrite the body structure. */
942 for (int i = 0; i < actx->idxlen; i++)
943 actx->idx[i]->body = NULL;
945 mutt_update_recvattach_menu(actx, menu, true);
946}
void mutt_actx_entries_free(struct AttachCtx *actx)
Free entries in an Attachment Context.
Definition: attach.c:162
bool mutt_edit_content_type(struct Email *e, struct Body *b, FILE *fp)
Edit the content type of an attachment.
Definition: external.c:1078
#define mutt_message(...)
Definition: logging2.h:91
void mutt_sleep(short s)
Sleep for a while.
Definition: muttlib.c:1428
void mutt_update_recvattach_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Update the Attachment Menu.
Definition: recvattach.c:1208
struct AttachPtr * current_attachment(struct AttachCtx *actx, struct Menu *menu)
Get the current attachment.
Definition: recvattach.c:71
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ ba_add_tagged()

int ba_add_tagged ( struct BodyArray *  ba,
struct AttachCtx actx,
struct Menu menu 
)

Get an array of tagged Attachments.

Parameters
baEmpty BodyArray to populate
actxList of Attachments
menuMenu
Return values
numNumber of selected Attachments
-1Error

Definition at line 1235 of file recvattach.c.

1236{
1237 if (!ba || !actx || !menu)
1238 return -1;
1239
1240 if (menu->tag_prefix)
1241 {
1242 for (int i = 0; i < actx->idxlen; i++)
1243 {
1244 struct Body *b = actx->idx[i]->body;
1245 if (b->tagged)
1246 {
1247 ARRAY_ADD(ba, b);
1248 }
1249 }
1250 }
1251 else
1252 {
1253 struct AttachPtr *cur = current_attachment(actx, menu);
1254 if (!cur)
1255 return -1;
1256
1257 ARRAY_ADD(ba, cur->body);
1258 }
1259
1260 return ARRAY_SIZE(ba);
1261}
#define ARRAY_ADD(head, elem)
Add an element at the end of the array.
Definition: array.h:155
#define ARRAY_SIZE(head)
The number of elements stored.
Definition: array.h:86
bool tag_prefix
User has pressed <tag-prefix>
Definition: lib.h:76
+ Here is the call graph for this function:
+ Here is the caller graph for this function: