NeoMutt  2023-11-03-107-g582dc1
Teaching an old dog new tricks
DOXYGEN
Loading...
Searching...
No Matches
functions.c File Reference

Compose functions. More...

#include "config.h"
#include <errno.h>
#include <limits.h>
#include <stdbool.h>
#include <stdio.h>
#include <string.h>
#include <sys/stat.h>
#include <unistd.h>
#include "private.h"
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "conn/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "lib.h"
#include "attach/lib.h"
#include "browser/lib.h"
#include "editor/lib.h"
#include "history/lib.h"
#include "imap/lib.h"
#include "index/lib.h"
#include "key/lib.h"
#include "menu/lib.h"
#include "ncrypt/lib.h"
#include "nntp/lib.h"
#include "pop/lib.h"
#include "question/lib.h"
#include "send/lib.h"
#include "attach_data.h"
#include "external.h"
#include "functions.h"
#include "globals.h"
#include "hook.h"
#include "mutt_header.h"
#include "mutt_logging.h"
#include "muttlib.h"
#include "mview.h"
#include "mx.h"
#include "nntp/adata.h"
#include "protos.h"
#include "rfc3676.h"
#include "shared_data.h"
#include <libintl.h>
#include "mixmaster/lib.h"
+ Include dependency graph for functions.c:

Go to the source code of this file.

Functions

static bool check_count (struct AttachCtx *actx)
 Check if there are any attachments.
 
static char * gen_cid (void)
 Generate a random Content ID.
 
static bool check_cid (const char *cid)
 Check if a Content-ID is valid.
 
static int check_attachments (struct AttachCtx *actx, struct ConfigSubset *sub)
 Check if any attachments have changed or been deleted.
 
static int delete_attachment (struct AttachCtx *actx, int aidx)
 Delete an attachment.
 
static void update_idx (struct Menu *menu, struct AttachCtx *actx, struct AttachPtr *ap)
 Add a new attachment to the message.
 
static void compose_attach_swap (struct Email *e, struct AttachCtx *actx, int first, int second)
 Swap two adjacent entries in the attachment list.
 
static int group_attachments (struct ComposeSharedData *shared, char *subtype)
 Group tagged attachments into a multipart group.
 
static int op_attachment_attach_file (struct ComposeSharedData *shared, int op)
 Attach files to this message - Implements compose_function_t -.
 
static int op_attachment_attach_key (struct ComposeSharedData *shared, int op)
 Attach a PGP public key - Implements compose_function_t -.
 
static int op_attachment_attach_message (struct ComposeSharedData *shared, int op)
 Attach messages to this message - Implements compose_function_t -.
 
static int op_attachment_detach (struct ComposeSharedData *shared, int op)
 Delete the current entry - Implements compose_function_t -.
 
static int op_attachment_edit_content_id (struct ComposeSharedData *shared, int op)
 Edit the 'Content-ID' of the attachment - Implements compose_function_t -.
 
static int op_attachment_edit_description (struct ComposeSharedData *shared, int op)
 Edit attachment description - Implements compose_function_t -.
 
static int op_attachment_edit_encoding (struct ComposeSharedData *shared, int op)
 Edit attachment transfer-encoding - Implements compose_function_t -.
 
static int op_attachment_edit_language (struct ComposeSharedData *shared, int op)
 Edit the 'Content-Language' of the attachment - Implements compose_function_t -.
 
static int op_attachment_edit_mime (struct ComposeSharedData *shared, int op)
 Edit attachment using mailcap entry - Implements compose_function_t -.
 
static int op_attachment_edit_type (struct ComposeSharedData *shared, int op)
 Edit attachment content type - Implements compose_function_t -.
 
static int op_attachment_filter (struct ComposeSharedData *shared, int op)
 Filter attachment through a shell command - Implements compose_function_t -.
 
static int op_attachment_get_attachment (struct ComposeSharedData *shared, int op)
 Get a temporary copy of an attachment - Implements compose_function_t -.
 
static int op_attachment_group_alts (struct ComposeSharedData *shared, int op)
 Group tagged attachments as 'multipart/alternative' - Implements compose_function_t -.
 
static int op_attachment_group_lingual (struct ComposeSharedData *shared, int op)
 Group tagged attachments as 'multipart/multilingual' - Implements compose_function_t -.
 
static int op_attachment_group_related (struct ComposeSharedData *shared, int op)
 Group tagged attachments as 'multipart/related' - Implements compose_function_t -.
 
static int op_attachment_move_down (struct ComposeSharedData *shared, int op)
 Move an attachment down in the attachment list - Implements compose_function_t -.
 
static int op_attachment_move_up (struct ComposeSharedData *shared, int op)
 Move an attachment up in the attachment list - Implements compose_function_t -.
 
static int op_attachment_new_mime (struct ComposeSharedData *shared, int op)
 Compose new attachment using mailcap entry - Implements compose_function_t -.
 
static int op_attachment_print (struct ComposeSharedData *shared, int op)
 Print the current entry - Implements compose_function_t -.
 
static int op_attachment_rename_attachment (struct ComposeSharedData *shared, int op)
 Send attachment with a different name - Implements compose_function_t -.
 
static int op_attachment_save (struct ComposeSharedData *shared, int op)
 Save message/attachment to a mailbox/file - Implements compose_function_t -.
 
static int op_attachment_toggle_disposition (struct ComposeSharedData *shared, int op)
 Toggle disposition between inline/attachment - Implements compose_function_t -.
 
static int op_attachment_toggle_recode (struct ComposeSharedData *shared, int op)
 Toggle recoding of this attachment - Implements compose_function_t -.
 
static int op_attachment_toggle_unlink (struct ComposeSharedData *shared, int op)
 Toggle whether to delete file after sending it - Implements compose_function_t -.
 
static int op_attachment_ungroup (struct ComposeSharedData *shared, int op)
 Ungroup a 'multipart' attachment - Implements compose_function_t -.
 
static int op_attachment_update_encoding (struct ComposeSharedData *shared, int op)
 Update an attachment's encoding info - Implements compose_function_t -.
 
static int op_envelope_edit_headers (struct ComposeSharedData *shared, int op)
 Edit the message with headers - Implements compose_function_t -.
 
static int op_compose_edit_file (struct ComposeSharedData *shared, int op)
 Edit the file to be attached - Implements compose_function_t -.
 
static int op_compose_edit_message (struct ComposeSharedData *shared, int op)
 Edit the message - Implements compose_function_t -.
 
static int op_compose_ispell (struct ComposeSharedData *shared, int op)
 Run ispell on the message - Implements compose_function_t -.
 
static int op_compose_postpone_message (struct ComposeSharedData *shared, int op)
 Save this message to send later - Implements compose_function_t -.
 
static int op_compose_rename_file (struct ComposeSharedData *shared, int op)
 Rename/move an attached file - Implements compose_function_t -.
 
static int op_compose_send_message (struct ComposeSharedData *shared, int op)
 Send the message - Implements compose_function_t -.
 
static int op_compose_write_message (struct ComposeSharedData *shared, int op)
 Write the message to a folder - Implements compose_function_t -.
 
static int op_display_headers (struct ComposeSharedData *shared, int op)
 Display message and toggle header weeding - Implements compose_function_t -.
 
static int op_exit (struct ComposeSharedData *shared, int op)
 Exit this menu - Implements compose_function_t -.
 
static int op_forget_passphrase (struct ComposeSharedData *shared, int op)
 Wipe passphrases from memory - Implements compose_function_t -.
 
int compose_function_dispatcher (struct MuttWindow *win, int op)
 Perform a Compose function - Implements function_dispatcher_t -.
 

Variables

const struct MenuFuncOp OpCompose []
 Functions for the Compose Menu.
 
const struct MenuOpSeq ComposeDefaultBindings []
 Key bindings for the Compose Menu.
 
static const struct ComposeFunction ComposeFunctions []
 All the NeoMutt functions that the Compose supports.
 

Detailed Description

Compose functions.

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 functions.c.

Function Documentation

◆ check_count()

static bool check_count ( struct AttachCtx actx)
static

Check if there are any attachments.

Parameters
actxAttachment context
Return values
trueThere are attachments

Definition at line 223 of file functions.c.

224{
225 if (actx->idxlen == 0)
226 {
227 mutt_error(_("There are no attachments"));
228 return false;
229 }
230
231 return true;
232}
#define mutt_error(...)
Definition: logging2.h:92
#define _(a)
Definition: message.h:28
short idxlen
Number of attachmentes.
Definition: attach.h:56
+ Here is the caller graph for this function:

◆ gen_cid()

static char * gen_cid ( void  )
static

Generate a random Content ID.

Return values
ptrContent ID
Note
The caller should free the string

Definition at line 240 of file functions.c.

241{
242 char rndid[MUTT_RANDTAG_LEN + 1];
243
244 mutt_rand_base32(rndid, sizeof(rndid) - 1);
245 rndid[MUTT_RANDTAG_LEN] = 0;
246
247 return mutt_str_dup(rndid);
248}
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:251
void mutt_rand_base32(char *buf, size_t buflen)
Fill a buffer with a base32-encoded random string.
Definition: random.c:104
#define MUTT_RANDTAG_LEN
Definition: sendlib.h:35
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_cid()

static bool check_cid ( const char *  cid)
static

Check if a Content-ID is valid.

Parameters
cidContent-ID to check
Return values
trueContent-ID is valid
falseContent-ID is not valid

Definition at line 256 of file functions.c.

257{
258 static const char *check = "^[-\\.0-9@A-Z_a-z]+$";
259
260 struct Regex *check_cid_regex = mutt_regex_new(check, 0, NULL);
261
262 const bool valid = mutt_regex_match(check_cid_regex, cid);
263
264 mutt_regex_free(&check_cid_regex);
265
266 return valid;
267}
struct Regex * mutt_regex_new(const char *str, uint32_t flags, struct Buffer *err)
Create an Regex from a string.
Definition: regex.c:76
void mutt_regex_free(struct Regex **ptr)
Free a Regex object.
Definition: regex.c:114
bool mutt_regex_match(const struct Regex *regex, const char *str)
Shorthand to mutt_regex_capture()
Definition: regex.c:636
Cached regular expression.
Definition: regex3.h:89
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ check_attachments()

static int check_attachments ( struct AttachCtx actx,
struct ConfigSubset sub 
)
static

Check if any attachments have changed or been deleted.

Parameters
actxAttachment context
subConfigSubset
Return values
0Success
-1Error

Definition at line 276 of file functions.c.

277{
278 int rc = -1;
279 struct stat st = { 0 };
280 struct Buffer *pretty = NULL, *msg = NULL;
281
282 for (int i = 0; i < actx->idxlen; i++)
283 {
284 if (actx->idx[i]->body->type == TYPE_MULTIPART)
285 continue;
286 if (stat(actx->idx[i]->body->filename, &st) != 0)
287 {
288 if (!pretty)
289 pretty = buf_pool_get();
290 buf_strcpy(pretty, actx->idx[i]->body->filename);
291 buf_pretty_mailbox(pretty);
292 /* L10N: This message is displayed in the compose menu when an attachment
293 doesn't stat. %d is the attachment number and %s is the attachment
294 filename. The filename is located last to avoid a long path hiding
295 the error message. */
296 mutt_error(_("Attachment #%d no longer exists: %s"), i + 1, buf_string(pretty));
297 goto cleanup;
298 }
299
300 if (actx->idx[i]->body->stamp < st.st_mtime)
301 {
302 if (!pretty)
303 pretty = buf_pool_get();
304 buf_strcpy(pretty, actx->idx[i]->body->filename);
305 buf_pretty_mailbox(pretty);
306
307 if (!msg)
308 msg = buf_pool_get();
309 /* L10N: This message is displayed in the compose menu when an attachment
310 is modified behind the scenes. %d is the attachment number and %s is
311 the attachment filename. The filename is located last to avoid a long
312 path hiding the prompt question. */
313 buf_printf(msg, _("Attachment #%d modified. Update encoding for %s?"),
314 i + 1, buf_string(pretty));
315
317 if (ans == MUTT_YES)
318 mutt_update_encoding(actx->idx[i]->body, sub);
319 else if (ans == MUTT_ABORT)
320 goto cleanup;
321 }
322 }
323
324 rc = 0;
325
326cleanup:
327 buf_pool_release(&pretty);
328 buf_pool_release(&msg);
329 return rc;
330}
int buf_printf(struct Buffer *buf, const char *fmt,...)
Format a string overwriting a Buffer.
Definition: buffer.c:173
size_t buf_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:407
static const char * buf_string(const struct Buffer *buf)
Convert a buffer to a const char * "string".
Definition: buffer.h:93
@ TYPE_MULTIPART
Type: 'multipart/*'.
Definition: mime.h:37
void buf_pretty_mailbox(struct Buffer *buf)
Shorten a mailbox path using '~' or '='.
Definition: muttlib.c:556
struct Buffer * buf_pool_get(void)
Get a Buffer from the pool.
Definition: pool.c:81
void buf_pool_release(struct Buffer **ptr)
Return a Buffer to the pool.
Definition: pool.c:94
QuadOption
Possible values for a quad-option.
Definition: quad.h:36
@ MUTT_ABORT
User aborted the question (with Ctrl-G)
Definition: quad.h:37
@ MUTT_YES
User answered 'Yes', or assume 'Yes'.
Definition: quad.h:39
enum QuadOption query_yesorno(const char *prompt, enum QuadOption def)
Ask the user a Yes/No question.
Definition: question.c:330
void mutt_update_encoding(struct Body *b, struct ConfigSubset *sub)
Update the encoding type.
Definition: sendlib.c:420
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:55
struct Body * body
Attachment.
Definition: attach.h:36
time_t stamp
Time stamp of last encoding update.
Definition: body.h:76
unsigned int type
content-type primary type, ContentType
Definition: body.h:40
char * filename
When sending a message, this is the file to which this structure refers.
Definition: body.h:58
String manipulation buffer.
Definition: buffer.h:34
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ delete_attachment()

static int delete_attachment ( struct AttachCtx actx,
int  aidx 
)
static

Delete an attachment.

Parameters
actxAttachment context
aidxIndex number of attachment to delete
Return values
0Success
-1Error

Definition at line 339 of file functions.c.

340{
341 if (!actx || (aidx < 0) || (aidx >= actx->idxlen))
342 return -1;
343
344 struct AttachPtr **idx = actx->idx;
345 struct Body *b_previous = NULL;
346 struct Body *b_parent = NULL;
347
348 if (aidx == 0)
349 {
350 struct Body *b = actx->idx[0]->body;
351 if (!b->next) // There's only one attachment left
352 {
353 mutt_error(_("You may not delete the only attachment"));
354 return -1;
355 }
356 }
357
358 if (idx[aidx]->level > 0)
359 {
360 if (attach_body_parent(idx[0]->body, NULL, idx[aidx]->body, &b_parent))
361 {
362 if (attach_body_count(b_parent->parts, false) < 3)
363 {
364 mutt_error(_("Can't leave group with only one attachment"));
365 return -1;
366 }
367 }
368 }
369
370 // reorder body pointers
371 if (aidx > 0)
372 {
373 if (attach_body_previous(idx[0]->body, idx[aidx]->body, &b_previous))
374 b_previous->next = idx[aidx]->body->next;
375 else if (attach_body_parent(idx[0]->body, NULL, idx[aidx]->body, &b_parent))
376 b_parent->parts = idx[aidx]->body->next;
377 }
378
379 // free memory
380 int part_count = 1;
381 if (aidx < (actx->idxlen - 1))
382 {
383 if ((idx[aidx]->body->type == TYPE_MULTIPART) &&
384 (idx[aidx + 1]->level > idx[aidx]->level))
385 {
386 part_count += attach_body_count(idx[aidx]->body->parts, true);
387 }
388 }
389 idx[aidx]->body->next = NULL;
390 mutt_body_free(&(idx[aidx]->body));
391 for (int i = 0; i < part_count; i++)
392 {
393 FREE(&idx[aidx + i]->tree);
394 FREE(&idx[aidx + i]);
395 }
396
397 // reorder attachment list
398 for (int i = aidx; i < (actx->idxlen - part_count); i++)
399 idx[i] = idx[i + part_count];
400 for (int i = 0; i < part_count; i++)
401 idx[actx->idxlen - i - 1] = NULL;
402 actx->idxlen -= part_count;
403
404 return 0;
405}
bool attach_body_parent(struct Body *start, struct Body *start_parent, struct Body *body, struct Body **body_parent)
Find the parent of a body.
Definition: lib.c:71
int attach_body_count(struct Body *body, bool recurse)
Count bodies.
Definition: lib.c:42
bool attach_body_previous(struct Body *start, struct Body *body, struct Body **previous)
Find the previous body of a body.
Definition: lib.c:142
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
#define FREE(x)
Definition: memory.h:45
An email to which things will be attached.
Definition: attach.h:35
The body of an email.
Definition: body.h:36
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:72
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:

◆ update_idx()

static void update_idx ( struct Menu menu,
struct AttachCtx actx,
struct AttachPtr ap 
)
static

Add a new attachment to the message.

Parameters
menuCurrent menu
actxAttachment context
apAttachment to add

Definition at line 413 of file functions.c.

414{
415 ap->level = 0;
416 for (int i = actx->idxlen; i > 0; i--)
417 {
418 if (ap->level == actx->idx[i - 1]->level)
419 {
420 actx->idx[i - 1]->body->next = ap->body;
421 break;
422 }
423 }
424
425 ap->body->aptr = ap;
426 mutt_actx_add_attach(actx, ap);
427 update_menu(actx, menu, false);
428 menu_set_index(menu, actx->vcount - 1);
429}
void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
Add an Attachment to an Attachment Context.
Definition: attach.c:65
void update_menu(struct AttachCtx *actx, struct Menu *menu, bool init)
Redraw the compose window.
Definition: dlg_compose.c:219
MenuRedrawFlags menu_set_index(struct Menu *menu, int index)
Set the current selection in the Menu.
Definition: menu.c:170
short vcount
The number of virtual attachments.
Definition: attach.h:60
int level
Nesting depth of attachment.
Definition: attach.h:40
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:74
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ compose_attach_swap()

static void compose_attach_swap ( struct Email e,
struct AttachCtx actx,
int  first,
int  second 
)
static

Swap two adjacent entries in the attachment list.

Parameters
eEmail
actxAttachment information
firstIndex of first attachment to swap
secondIndex of second attachment to swap

Definition at line 438 of file functions.c.

439{
440 struct AttachPtr **idx = actx->idx;
441
442 // check that attachments really are adjacent
443 if (idx[first]->body->next != idx[second]->body)
444 return;
445
446 // reorder Body pointers
447 if (first == 0)
448 {
449 // first attachment is the fundamental part
450 idx[first]->body->next = idx[second]->body->next;
451 idx[second]->body->next = idx[first]->body;
452 e->body = idx[second]->body;
453 }
454 else
455 {
456 // find previous attachment
457 struct Body *b_previous = NULL;
458 struct Body *b_parent = NULL;
459 if (attach_body_previous(e->body, idx[first]->body, &b_previous))
460 {
461 idx[first]->body->next = idx[second]->body->next;
462 idx[second]->body->next = idx[first]->body;
463 b_previous->next = idx[second]->body;
464 }
465 else if (attach_body_parent(e->body, NULL, idx[first]->body, &b_parent))
466 {
467 idx[first]->body->next = idx[second]->body->next;
468 idx[second]->body->next = idx[first]->body;
469 b_parent->parts = idx[second]->body;
470 }
471 }
472
473 // reorder attachment list
474 struct AttachPtr *saved = idx[second];
475 for (int i = second; i > first; i--)
476 idx[i] = idx[i - 1];
477 idx[first] = saved;
478
479 // if moved attachment is a group then move subparts too
480 if ((idx[first]->body->type == TYPE_MULTIPART) && (second < actx->idxlen - 1))
481 {
482 int i = second + 1;
483 while (idx[i]->level > idx[first]->level)
484 {
485 saved = idx[i];
486 int destidx = i - second + first;
487 for (int j = i; j > destidx; j--)
488 idx[j] = idx[j - 1];
489 idx[destidx] = saved;
490 i++;
491 if (i >= actx->idxlen)
492 break;
493 }
494 }
495}
struct Body * body
List of MIME parts.
Definition: email.h:67
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ group_attachments()

static int group_attachments ( struct ComposeSharedData shared,
char *  subtype 
)
static

Group tagged attachments into a multipart group.

Parameters
sharedShared compose data
subtypeMIME subtype
Return values
FR_SUCCESSSuccess
FR_ERRORFailure

Definition at line 504 of file functions.c.

505{
506 struct AttachCtx *actx = shared->adata->actx;
507 int group_level = -1;
508 struct Body *bptr_parent = NULL;
509
510 // Attachments to be grouped must have the same parent
511 for (int i = 0; i < actx->idxlen; i++)
512 {
513 // check if all tagged attachments are at same level
514 if (actx->idx[i]->body->tagged)
515 {
516 if (group_level == -1)
517 {
518 group_level = actx->idx[i]->level;
519 }
520 else
521 {
522 if (group_level != actx->idx[i]->level)
523 {
524 mutt_error(_("Attachments to be grouped must have the same parent"));
525 return FR_ERROR;
526 }
527 }
528 // if not at top level check if all tagged attachments have same parent
529 if (group_level > 0)
530 {
531 if (bptr_parent)
532 {
533 struct Body *bptr_test = NULL;
534 if (!attach_body_parent(actx->idx[0]->body, NULL, actx->idx[i]->body, &bptr_test))
535 mutt_debug(LL_DEBUG5, "can't find parent\n");
536 if (bptr_test != bptr_parent)
537 {
538 mutt_error(_("Attachments to be grouped must have the same parent"));
539 return FR_ERROR;
540 }
541 }
542 else
543 {
544 if (!attach_body_parent(actx->idx[0]->body, NULL, actx->idx[i]->body, &bptr_parent))
545 mutt_debug(LL_DEBUG5, "can't find parent\n");
546 }
547 }
548 }
549 }
550
551 // Can't group all attachments unless at top level
552 if (bptr_parent)
553 {
554 if (shared->adata->menu->num_tagged == attach_body_count(bptr_parent->parts, false))
555 {
556 mutt_error(_("Can't leave group with only one attachment"));
557 return FR_ERROR;
558 }
559 }
560
561 struct Body *group = mutt_body_new();
562 group->type = TYPE_MULTIPART;
563 group->subtype = mutt_str_dup(subtype);
564 group->encoding = ENC_7BIT;
565
566 struct Body *bptr_first = NULL; // first tagged attachment
567 struct Body *bptr = NULL; // current tagged attachment
568 struct Body *group_parent = NULL; // parent of group
569 struct Body *group_previous = NULL; // previous body to group
570 struct Body *group_part = NULL; // current attachment in group
571 int group_idx = 0; // index in attachment list where group will be inserted
572 int group_last_idx = 0; // index of last part of previous found group
573 int group_parent_type = TYPE_OTHER;
574
575 for (int i = 0; i < actx->idxlen; i++)
576 {
577 bptr = actx->idx[i]->body;
578 if (bptr->tagged)
579 {
580 // set group properties based on first tagged attachment
581 if (!bptr_first)
582 {
583 group->disposition = bptr->disposition;
584 if (bptr->language && !mutt_str_equal(subtype, "multilingual"))
585 group->language = mutt_str_dup(bptr->language);
586 group_parent_type = bptr->aptr->parent_type;
587 bptr_first = bptr;
588 if (i > 0)
589 {
590 if (!attach_body_previous(shared->email->body, bptr, &group_previous))
591 {
592 mutt_debug(LL_DEBUG5, "couldn't find previous\n");
593 }
594 if (!attach_body_parent(shared->email->body, NULL, bptr, &group_parent))
595 {
596 mutt_debug(LL_DEBUG5, "couldn't find parent\n");
597 }
598 }
599 }
600
601 shared->adata->menu->num_tagged--;
602 bptr->tagged = false;
603 bptr->aptr->level++;
605
606 // append bptr to the group parts list and remove from email body list
607 struct Body *bptr_previous = NULL;
608 if (attach_body_previous(shared->email->body, bptr, &bptr_previous))
609 bptr_previous->next = bptr->next;
610 else if (attach_body_parent(shared->email->body, NULL, bptr, &bptr_parent))
611 bptr_parent->parts = bptr->next;
612 else
613 shared->email->body = bptr->next;
614
615 if (group_part)
616 {
617 // add bptr to group parts list
618 group_part->next = bptr;
619 group_part = group_part->next;
620 group_part->next = NULL;
621
622 // reorder attachments and set levels
623 int bptr_attachments = attach_body_count(bptr, true);
624 for (int j = i + 1; j < (i + bptr_attachments); j++)
625 actx->idx[j]->level++;
626 if (i > (group_last_idx + 1))
627 {
628 for (int j = 0; j < bptr_attachments; j++)
629 {
630 struct AttachPtr *saved = actx->idx[i + bptr_attachments - 1];
631 for (int k = i + bptr_attachments - 1; k > (group_last_idx + 1); k--)
632 actx->idx[k] = actx->idx[k - 1];
633 actx->idx[group_last_idx + 1] = saved;
634 }
635 }
636 i += bptr_attachments - 1;
637 group_last_idx += bptr_attachments;
638 }
639 else
640 {
641 group_idx = i;
642 group->parts = bptr;
643 group_part = bptr;
644 group_part->next = NULL;
645 int bptr_attachments = attach_body_count(bptr, true);
646 for (int j = i + 1; j < (i + bptr_attachments); j++)
647 actx->idx[j]->level++;
648 i += bptr_attachments - 1;
649 group_last_idx = i;
650 }
651 }
652 }
653
654 if (!bptr_first)
655 {
656 mutt_body_free(&group);
657 return FR_ERROR;
658 }
659
660 // set group->next
661 int next_aidx = group_idx + attach_body_count(group->parts, true);
662 if (group_parent)
663 {
664 // find next attachment with the same parent as the group
665 struct Body *b = NULL;
666 struct Body *b_parent = NULL;
667 while (next_aidx < actx->idxlen)
668 {
669 b = actx->idx[next_aidx]->body;
670 b_parent = NULL;
671 if (attach_body_parent(shared->email->body, NULL, b, &b_parent))
672 {
673 if (group_parent == b_parent)
674 {
675 group->next = b;
676 break;
677 }
678 }
679 next_aidx++;
680 }
681 }
682 else if (next_aidx < actx->idxlen)
683 {
684 // group is at top level
685 group->next = actx->idx[next_aidx]->body;
686 }
687
688 // set previous or parent for group
689 if (group_previous)
690 group_previous->next = group;
691 else if (group_parent)
692 group_parent->parts = group;
693
695
696 struct AttachPtr *group_ap = mutt_aptr_new();
697 group_ap->body = group;
698 group_ap->body->aptr = group_ap;
699 group_ap->level = group_level;
700 group_ap->parent_type = group_parent_type;
701
702 // insert group into attachment list
703 mutt_actx_ins_attach(actx, group_ap, group_idx);
704
705 // update email body and last attachment pointers
706 shared->email->body = actx->idx[0]->body;
707 actx->idx[actx->idxlen - 1]->body->next = NULL;
708
709 update_menu(actx, shared->adata->menu, false);
710 shared->adata->menu->current = group_idx;
712
714 return FR_SUCCESS;
715}
void mutt_actx_ins_attach(struct AttachCtx *actx, struct AttachPtr *attach, int aidx)
Insert an Attachment into an Attachment Context at Specified Index.
Definition: attach.c:91
struct AttachPtr * mutt_aptr_new(void)
Create a new Attachment Pointer.
Definition: attach.c:40
@ FR_SUCCESS
Valid function - successfully performed.
Definition: dispatcher.h:39
@ FR_ERROR
Valid function - error occurred.
Definition: dispatcher.h:38
struct Body * mutt_body_new(void)
Create a new Body.
Definition: body.c:43
#define mutt_debug(LEVEL,...)
Definition: logging2.h:89
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:666
#define MUTT_SEND2_HOOK
send2-hook: when changing fields in the compose menu
Definition: hook.h:48
@ LL_DEBUG5
Log at debug level 5.
Definition: logging2.h:47
#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
@ ENC_7BIT
7-bit text
Definition: mime.h:49
@ TYPE_OTHER
Unknown Content-Type.
Definition: mime.h:31
void mutt_generate_boundary(struct ParameterList *pl)
Create a unique boundary id for a MIME part.
Definition: multipart.c:86
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:763
A set of attachments.
Definition: attach.h:51
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:38
char * language
content-language (RFC8255)
Definition: body.h:77
struct ParameterList parameter
Parameters of the content-type.
Definition: body.h:62
unsigned int disposition
content-disposition, ContentDisposition
Definition: body.h:42
bool tagged
This attachment is tagged.
Definition: body.h:89
char * subtype
content-type subtype
Definition: body.h:60
unsigned int encoding
content-transfer-encoding, ContentEncoding
Definition: body.h:41
struct Menu * menu
Menu displaying the attachments.
Definition: attach_data.h:35
struct AttachCtx * actx
Set of attachments.
Definition: attach_data.h:34
struct ComposeAttachData * adata
Attachments.
Definition: shared_data.h:39
struct Email * email
Email being composed.
Definition: shared_data.h:38
int current
Current entry.
Definition: lib.h:71
int num_tagged
Number of tagged entries.
Definition: lib.h:84
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ OpCompose

const struct MenuFuncOp OpCompose[]

Functions for the Compose Menu.

Definition at line 88 of file functions.c.

◆ ComposeDefaultBindings

const struct MenuOpSeq ComposeDefaultBindings[]

Key bindings for the Compose Menu.

Definition at line 157 of file functions.c.

◆ ComposeFunctions

const struct ComposeFunction ComposeFunctions[]
static

All the NeoMutt functions that the Compose supports.

Definition at line 2050 of file functions.c.