NeoMutt  2025-12-11-435-g4ac674
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
recvattach.h File Reference

Routines for managing attachments. More...

#include <stdbool.h>
#include <stdio.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.
 
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
  • Richard Russon

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 1187 of file recvattach.c.

1188{
1189 /* Collapse the attachments if '$digest_collapse' is set AND if...
1190 * the outer container is of type 'multipart/digest' */
1191 bool digest = mutt_istr_equal(actx->email->body->subtype, "digest");
1192
1193 const bool c_digest_collapse = cs_subset_bool(NeoMutt->sub, "digest_collapse");
1194 for (int i = 0; i < actx->idxlen; i++)
1195 {
1196 actx->idx[i]->body->tagged = false;
1197
1198 /* OR an inner container is of type 'multipart/digest' */
1199 actx->idx[i]->collapsed = (c_digest_collapse &&
1200 (digest ||
1201 ((actx->idx[i]->body->type == TYPE_MULTIPART) &&
1202 mutt_istr_equal(actx->idx[i]->body->subtype, "digest"))));
1203 }
1204}
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition helpers.c:47
@ 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:674
struct Email * email
Used by recvattach for updating.
Definition attach.h:64
struct AttachPtr ** idx
Array of attachments.
Definition attach.h:67
short idxlen
Number of attachmentes.
Definition attach.h:68
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:90
char * subtype
content-type subtype
Definition body.h:61
unsigned int type
content-type primary type, ContentType
Definition body.h:40
struct Body * body
List of MIME parts.
Definition email.h:69
Container for Accounts, Notifications.
Definition neomutt.h:41
struct ConfigSubset * sub
Inherited config items.
Definition neomutt.h:49
+ 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) ? MUTT_TREE_VLINE : MUTT_TREE_SPACE;
158 *s++ = MUTT_TREE_SPACE;
159 }
160 }
161}
@ MUTT_TREE_LLCORNER
Lower left corner.
Definition thread.h:57
@ MUTT_TREE_RARROW
Right arrow.
Definition thread.h:63
@ MUTT_TREE_LTEE
Left T-piece.
Definition thread.h:59
@ MUTT_TREE_VLINE
Vertical line.
Definition thread.h:61
@ MUTT_TREE_HLINE
Horizontal line.
Definition thread.h:60
@ MUTT_TREE_SPACE
Blank space.
Definition thread.h:62
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition string.c:257
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition string.c:662
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition string.c:284
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:72
short * v2r
Mapping from virtual to real attachment.
Definition attach.h:71
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:72
+ 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 * b,
FILE * fp,
int parent_type,
int level,
bool decrypted )

Create a list of attachments.

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

Definition at line 1089 of file recvattach.c.

1092{
1093 struct Body *bp = NULL;
1094 struct Body *new_body = NULL;
1095 FILE *fp_new = NULL;
1097
1098 for (bp = b; bp; bp = bp->next)
1099 {
1100 bool need_secured = false;
1101 bool secured = false;
1102
1104 {
1105 need_secured = true;
1106
1107 if (type & SEC_ENCRYPT)
1108 {
1110 goto decrypt_failed;
1111
1112 if (e->env)
1114 }
1115
1116 secured = (crypt_smime_decrypt_mime(fp, &fp_new, bp, &new_body) == 0);
1117 /* If the decrypt/verify-opaque doesn't generate mime output, an empty
1118 * text/plain type will still be returned by mutt_read_mime_header().
1119 * We can't distinguish an actual part from a failure, so only use a
1120 * text/plain that results from a single top-level part. */
1121 if (secured && (new_body->type == TYPE_TEXT) &&
1122 mutt_istr_equal("plain", new_body->subtype) && ((b != bp) || bp->next))
1123 {
1124 mutt_body_free(&new_body);
1125 mutt_file_fclose(&fp_new);
1126 goto decrypt_failed;
1127 }
1128
1129 if (secured && (type & SEC_ENCRYPT))
1130 e->security |= SMIME_ENCRYPT;
1131 }
1132
1133 if (((WithCrypto & APPLICATION_PGP) != 0) &&
1135 {
1136 need_secured = true;
1137
1139 goto decrypt_failed;
1140
1141 secured = (crypt_pgp_decrypt_mime(fp, &fp_new, bp, &new_body) == 0);
1142
1143 if (secured)
1144 e->security |= PGP_ENCRYPT;
1145 }
1146
1147 if (need_secured && secured)
1148 {
1149 mutt_actx_add_fp(actx, fp_new);
1150 mutt_actx_add_body(actx, new_body);
1151 mutt_generate_recvattach_list(actx, e, new_body, fp_new, parent_type, level, 1);
1152 continue;
1153 }
1154
1155 decrypt_failed:
1156 /* Fall through and show the original parts if decryption fails */
1157 if (need_secured && !secured)
1158 mutt_error(_("Can't decrypt encrypted message"));
1159
1160 struct AttachPtr *ap = mutt_aptr_new();
1161 mutt_actx_add_attach(actx, ap);
1162
1163 ap->body = bp;
1164 ap->fp = fp;
1165 bp->aptr = ap;
1167 ap->level = level;
1168 ap->decrypted = decrypted;
1169
1170 if (mutt_is_message_type(bp->type, bp->subtype))
1171 {
1172 mutt_generate_recvattach_list(actx, bp->email, bp->parts, fp, bp->type,
1173 level + 1, decrypted);
1174 e->security |= bp->email->security;
1175 }
1176 else
1177 {
1178 mutt_generate_recvattach_list(actx, e, bp->parts, fp, bp->type, level + 1, decrypted);
1179 }
1180 }
1181}
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
void mutt_actx_add_body(struct AttachCtx *actx, struct Body *b)
Add an email body to an Attachment Context.
Definition attach.c:142
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition crypt.c:609
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition crypt.c:131
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition crypt.c:443
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition crypt.c:504
int crypt_pgp_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition cryptglue.c:210
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition cryptglue.c:454
int crypt_smime_decrypt_mime(FILE *fp_in, FILE **fp_out, struct Body *b, struct Body **b_dec)
Wrapper for CryptModuleSpecs::decrypt_mime()
Definition cryptglue.c:432
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition body.c:58
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
Definition parse.c:1506
#define mutt_file_fclose(FP)
Definition file.h:139
#define mutt_error(...)
Definition logging2.h:94
@ 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:84
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition lib.h:98
#define PGP_ENCRYPT
Email is PGP encrypted.
Definition lib.h:104
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition lib.h:99
#define SEC_ENCRYPT
Email is encrypted.
Definition lib.h:86
#define SMIME_ENCRYPT
Email is S/MIME encrypted.
Definition lib.h:110
#define WithCrypto
Definition lib.h:124
void mutt_generate_recvattach_list(struct AttachCtx *actx, struct Email *e, struct Body *b, FILE *fp, int parent_type, int level, bool decrypted)
Create a list of attachments.
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:73
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition body.h:75
struct Email * email
header information for message/rfc822
Definition body.h:74
struct Envelope * env
Envelope information.
Definition email.h:68
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib....
Definition email.h:43
+ 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:164
+ 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 1212 of file recvattach.c.

1213{
1214 if (init)
1215 {
1216 mutt_generate_recvattach_list(actx, actx->email, actx->email->body,
1217 actx->fp_root, -1, 0, 0);
1218 mutt_attach_init(actx);
1219 }
1220
1221 mutt_update_tree(actx);
1222
1223 menu->max = actx->vcount;
1224
1225 const int index = menu_get_index(menu);
1226 if (index >= menu->max)
1227 menu_set_index(menu, menu->max - 1);
1229}
#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:188
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition menu.c:178
void mutt_attach_init(struct AttachCtx *actx)
Create a new Attachment context.
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:65
int max
Number of entries in the menu.
Definition lib.h:82
+ 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 929 of file recvattach.c.

930{
931 struct AttachPtr *cur_att = current_attachment(actx, menu);
932 if (!mutt_edit_content_type(e, cur_att->body, cur_att->fp))
933 return;
934
935 /* The mutt_update_recvattach_menu() will overwrite any changes
936 * made to a decrypted cur_att->body, so warn the user. */
937 if (cur_att->decrypted)
938 {
939 mutt_message(_("Structural changes to decrypted attachments are not supported"));
940 mutt_sleep(1);
941 }
942 /* Editing the content type can rewrite the body structure. */
943 for (int i = 0; i < actx->idxlen; i++)
944 actx->idx[i]->body = NULL;
946 mutt_update_recvattach_menu(actx, menu, true);
947}
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:1072
#define mutt_message(...)
Definition logging2.h:93
void mutt_sleep(short s)
Sleep for a while.
Definition muttlib.c:786
void mutt_update_recvattach_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Update the Attachment Menu.
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 1239 of file recvattach.c.

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