NeoMutt  2024-04-16-36-g75b6fb
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 1189 of file recvattach.c.

1190{
1191 /* Collapse the attachments if '$digest_collapse' is set AND if...
1192 * the outer container is of type 'multipart/digest' */
1193 bool digest = mutt_istr_equal(actx->email->body->subtype, "digest");
1194
1195 const bool c_digest_collapse = cs_subset_bool(NeoMutt->sub, "digest_collapse");
1196 for (int i = 0; i < actx->idxlen; i++)
1197 {
1198 actx->idx[i]->body->tagged = false;
1199
1200 /* OR an inner container is of type 'multipart/digest' */
1201 actx->idx[i]->collapsed = (c_digest_collapse &&
1202 (digest ||
1203 ((actx->idx[i]->body->type == TYPE_MULTIPART) &&
1204 mutt_istr_equal(actx->idx[i]->body->subtype, "digest"))));
1205 }
1206}
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:666
struct Email * email
Used by recvattach for updating.
Definition: attach.h:66
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:69
short idxlen
Number of attachmentes.
Definition: attach.h:70
struct Body * body
Attachment.
Definition: attach.h:38
bool collapsed
Group is collapsed.
Definition: attach.h:46
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:69
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 122 of file recvattach.c.

123{
124 char buf[256] = { 0 };
125 char *s = NULL;
126
127 mutt_update_v2r(actx);
128
129 for (int vindex = 0; vindex < actx->vcount; vindex++)
130 {
131 const int rindex = actx->v2r[vindex];
132 actx->idx[rindex]->num = vindex;
133 if ((2 * (actx->idx[rindex]->level + 2)) < sizeof(buf))
134 {
135 if (actx->idx[rindex]->level)
136 {
137 s = buf + 2 * (actx->idx[rindex]->level - 1);
138 *s++ = (actx->idx[rindex]->body->next) ? MUTT_TREE_LTEE : MUTT_TREE_LLCORNER;
139 *s++ = MUTT_TREE_HLINE;
140 *s++ = MUTT_TREE_RARROW;
141 }
142 else
143 {
144 s = buf;
145 }
146 *s = '\0';
147 }
148
149 if (actx->idx[rindex]->tree)
150 {
151 if (!mutt_str_equal(actx->idx[rindex]->tree, buf))
152 mutt_str_replace(&actx->idx[rindex]->tree, buf);
153 }
154 else
155 {
156 actx->idx[rindex]->tree = mutt_str_dup(buf);
157 }
158
159 if (((2 * (actx->idx[rindex]->level + 2)) < sizeof(buf)) &&
160 actx->idx[rindex]->level)
161 {
162 s = buf + 2 * (actx->idx[rindex]->level - 1);
163 *s++ = (actx->idx[rindex]->body->next) ? MUTT_TREE_VLINE : MUTT_TREE_SPACE;
164 *s++ = MUTT_TREE_SPACE;
165 }
166 }
167}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:253
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:654
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:274
@ MUTT_TREE_LLCORNER
Lower left corner.
Definition: mutt_thread.h:58
@ MUTT_TREE_RARROW
Right arrow.
Definition: mutt_thread.h:64
@ MUTT_TREE_LTEE
Left T-piece.
Definition: mutt_thread.h:60
@ MUTT_TREE_VLINE
Vertical line.
Definition: mutt_thread.h:62
@ MUTT_TREE_HLINE
Horizontal line.
Definition: mutt_thread.h:61
@ MUTT_TREE_SPACE
Blank space.
Definition: mutt_thread.h:63
static void mutt_update_v2r(struct AttachCtx *actx)
Update the virtual list of attachments.
Definition: recvattach.c:91
short vcount
The number of virtual attachments.
Definition: attach.h:74
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:73
char * tree
Tree characters to display.
Definition: attach.h:41
int num
Attachment index number.
Definition: attach.h:43
int level
Nesting depth of attachment.
Definition: attach.h:42
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 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 1091 of file recvattach.c.

1094{
1095 struct Body *bp = NULL;
1096 struct Body *new_body = NULL;
1097 FILE *fp_new = NULL;
1099
1100 for (bp = b; bp; bp = bp->next)
1101 {
1102 bool need_secured = false;
1103 bool secured = false;
1104
1106 {
1107 need_secured = true;
1108
1109 if (type & SEC_ENCRYPT)
1110 {
1112 goto decrypt_failed;
1113
1114 if (e->env)
1116 }
1117
1118 secured = (crypt_smime_decrypt_mime(fp, &fp_new, bp, &new_body) == 0);
1119 /* If the decrypt/verify-opaque doesn't generate mime output, an empty
1120 * text/plain type will still be returned by mutt_read_mime_header().
1121 * We can't distinguish an actual part from a failure, so only use a
1122 * text/plain that results from a single top-level part. */
1123 if (secured && (new_body->type == TYPE_TEXT) &&
1124 mutt_istr_equal("plain", new_body->subtype) && ((b != bp) || bp->next))
1125 {
1126 mutt_body_free(&new_body);
1127 mutt_file_fclose(&fp_new);
1128 goto decrypt_failed;
1129 }
1130
1131 if (secured && (type & SEC_ENCRYPT))
1132 e->security |= SMIME_ENCRYPT;
1133 }
1134
1135 if (((WithCrypto & APPLICATION_PGP) != 0) &&
1137 {
1138 need_secured = true;
1139
1141 goto decrypt_failed;
1142
1143 secured = (crypt_pgp_decrypt_mime(fp, &fp_new, bp, &new_body) == 0);
1144
1145 if (secured)
1146 e->security |= PGP_ENCRYPT;
1147 }
1148
1149 if (need_secured && secured)
1150 {
1151 mutt_actx_add_fp(actx, fp_new);
1152 mutt_actx_add_body(actx, new_body);
1153 mutt_generate_recvattach_list(actx, e, new_body, fp_new, parent_type, level, 1);
1154 continue;
1155 }
1156
1157 decrypt_failed:
1158 /* Fall through and show the original parts if decryption fails */
1159 if (need_secured && !secured)
1160 mutt_error(_("Can't decrypt encrypted message"));
1161
1162 struct AttachPtr *ap = mutt_aptr_new();
1163 mutt_actx_add_attach(actx, ap);
1164
1165 ap->body = bp;
1166 ap->fp = fp;
1167 bp->aptr = ap;
1169 ap->level = level;
1170 ap->decrypted = decrypted;
1171
1172 if (mutt_is_message_type(bp->type, bp->subtype))
1173 {
1174 mutt_generate_recvattach_list(actx, bp->email, bp->parts, fp, bp->type,
1175 level + 1, decrypted);
1176 e->security |= bp->email->security;
1177 }
1178 else
1179 {
1180 mutt_generate_recvattach_list(actx, e, bp->parts, fp, bp->type, level + 1, decrypted);
1181 }
1182 }
1183}
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:595
bool crypt_valid_passphrase(SecurityFlags flags)
Check that we have a usable passphrase, ask if not.
Definition: crypt.c:132
SecurityFlags mutt_is_multipart_encrypted(struct Body *b)
Does the message have encrypted parts?
Definition: crypt.c:429
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:490
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:1493
#define mutt_file_fclose(FP)
Definition: file.h:147
#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:76
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:90
#define PGP_ENCRYPT
Definition: lib.h:96
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:91
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:78
#define SMIME_ENCRYPT
Definition: lib.h:102
#define WithCrypto
Definition: lib.h:116
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.
Definition: recvattach.c:1091
An email to which things will be attached.
Definition: attach.h:37
FILE * fp
Used in the recvattach menu.
Definition: attach.h:39
bool decrypted
Not part of message as stored in the email->body.
Definition: attach.h:45
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:40
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: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 77 of file recvattach.c.

78{
79 const int virt = menu_get_index(menu);
80 const int index = actx->v2r[virt];
81
82 return actx->idx[index];
83}
int menu_get_index(struct Menu *menu)
Get the current selection in the Menu.
Definition: menu.c:160
+ 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 1214 of file recvattach.c.

1215{
1216 if (init)
1217 {
1218 mutt_generate_recvattach_list(actx, actx->email, actx->email->body,
1219 actx->fp_root, -1, 0, 0);
1220 mutt_attach_init(actx);
1221 }
1222
1223 mutt_update_tree(actx);
1224
1225 menu->max = actx->vcount;
1226
1227 const int index = menu_get_index(menu);
1228 if (index >= menu->max)
1229 menu_set_index(menu, menu->max - 1);
1231}
#define MENU_REDRAW_INDEX
Redraw the index.
Definition: lib.h:56
void menu_queue_redraw(struct Menu *menu, MenuRedrawFlags redraw)
Queue a request for a redraw.
Definition: menu.c:184
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:174
void mutt_attach_init(struct AttachCtx *actx)
Create a new Attachment context.
Definition: recvattach.c:1189
void mutt_update_tree(struct AttachCtx *actx)
Refresh the list of attachments.
Definition: recvattach.c:122
FILE * fp_root
Used by recvattach for updating.
Definition: attach.h:67
int max
Number of entries in the menu.
Definition: lib.h:81
+ 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 932 of file recvattach.c.

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

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