NeoMutt  2021-02-05-666-ge300cd
Teaching an old dog new tricks
DOXYGEN
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. More...
 
void mutt_update_tree (struct AttachCtx *actx)
 Refresh the list of attachments. More...
 
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 -
Expando Description
%C Character set
%c Character set: convert?
%D Deleted flag
%d Description
%e MIME content-transfer-encoding
%f Filename
%F Filename for content-disposition header
%I Content-disposition, either I (inline) or A (attachment)
%m Major MIME type
%M MIME subtype
%n Attachment number
%Q 'Q', if MIME part qualifies for attachment counting
%s Size
%t Tagged flag
%T Tree chars
%u Unlink
%X Number of qualifying MIME parts in this part and its children
More...
 
void dlg_select_attachment (struct ConfigSubset *sub, struct Mailbox *m, struct Email *e, FILE *fp)
 Show the attachments in a Menu. More...
 
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. More...
 

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

1572 {
1573  /* Collapse the attachments if '$digest_collapse' is set AND if...
1574  * the outer container is of type 'multipart/digest' */
1575  bool digest = mutt_istr_equal(actx->email->body->subtype, "digest");
1576 
1577  const bool c_digest_collapse =
1578  cs_subset_bool(NeoMutt->sub, "digest_collapse");
1579  for (int i = 0; i < actx->idxlen; i++)
1580  {
1581  actx->idx[i]->body->tagged = false;
1582 
1583  /* OR an inner container is of type 'multipart/digest' */
1584  actx->idx[i]->body->collapsed =
1585  (c_digest_collapse &&
1586  (digest || ((actx->idx[i]->body->type == TYPE_MULTIPART) &&
1587  mutt_istr_equal(actx->idx[i]->body->subtype, "digest"))));
1588  }
1589 }
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
struct Body * body
List of MIME parts.
Definition: email.h:91
struct Email * email
Used by recvattach for updating.
Definition: attach.h:51
short idxlen
Number of attachmentes.
Definition: attach.h:55
Container for Accounts, Notifications.
Definition: neomutt.h:36
bool tagged
This attachment is tagged.
Definition: body.h:70
bool collapsed
Used by recvattach.
Definition: body.h:83
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
struct Body * body
Attachment.
Definition: attach.h:36
+ 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 204 of file recvattach.c.

205 {
206  char buf[256];
207  char *s = NULL;
208 
209  mutt_update_v2r(actx);
210 
211  for (int vindex = 0; vindex < actx->vcount; vindex++)
212  {
213  const int rindex = actx->v2r[vindex];
214  actx->idx[rindex]->num = vindex;
215  if ((2 * (actx->idx[rindex]->level + 2)) < sizeof(buf))
216  {
217  if (actx->idx[rindex]->level)
218  {
219  s = buf + 2 * (actx->idx[rindex]->level - 1);
220  *s++ = (actx->idx[rindex]->body->next) ? MUTT_TREE_LTEE : MUTT_TREE_LLCORNER;
221  *s++ = MUTT_TREE_HLINE;
222  *s++ = MUTT_TREE_RARROW;
223  }
224  else
225  s = buf;
226  *s = '\0';
227  }
228 
229  if (actx->idx[rindex]->tree)
230  {
231  if (!mutt_str_equal(actx->idx[rindex]->tree, buf))
232  mutt_str_replace(&actx->idx[rindex]->tree, buf);
233  }
234  else
235  actx->idx[rindex]->tree = mutt_str_dup(buf);
236 
237  if (((2 * (actx->idx[rindex]->level + 2)) < sizeof(buf)) &&
238  actx->idx[rindex]->level)
239  {
240  s = buf + 2 * (actx->idx[rindex]->level - 1);
241  *s++ = (actx->idx[rindex]->body->next) ? '\005' : '\006';
242  *s++ = '\006';
243  }
244  }
245 }
bool mutt_str_equal(const char *a, const char *b)
Compare two strings.
Definition: string.c:904
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
struct Body * next
next attachment in the list
Definition: body.h:53
Lower left corner.
Definition: mutt_thread.h:42
char * tree
Tree characters to display.
Definition: attach.h:39
static void mutt_update_v2r(struct AttachCtx *actx)
Update the virtual list of attachments.
Definition: recvattach.c:175
Right arrow.
Definition: mutt_thread.h:48
int num
Attachment index number.
Definition: attach.h:41
Left T-piece.
Definition: mutt_thread.h:44
Horizontal line.
Definition: mutt_thread.h:45
short * v2r
Mapping from virtual to real attachment.
Definition: attach.h:58
char * mutt_str_replace(char **p, const char *s)
Replace one string with another.
Definition: string.c:446
int level
Nesting depth of attachment.
Definition: attach.h:40
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
short vcount
The number of virtual attachments.
Definition: attach.h:59
struct Body * body
Attachment.
Definition: attach.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ dlg_select_attachment()

void dlg_select_attachment ( struct ConfigSubset sub,
struct Mailbox m,
struct Email e,
FILE *  fp 
)

Show the attachments in a Menu.

Parameters
subConfig Subset
mMailbox
eEmail
fpFile with the content of the email, or NULL

Definition at line 1713 of file recvattach.c.

1715 {
1716  if (!m || !e || !fp)
1717  {
1718  return;
1719  }
1720 
1721  int op = OP_NULL;
1722 
1723  /* make sure we have parsed this message */
1724  mutt_parse_mime_message(m, e, fp);
1726 
1728 
1729  struct Menu *menu = dlg->wdata;
1730  menu->make_entry = attach_make_entry;
1731  menu->tag = attach_tag;
1732 
1733  struct MuttWindow *win_menu = menu->win;
1734 
1735  // NT_COLOR is handled by the SimpleDialog
1738 
1739  struct MuttWindow *sbar = window_find_child(dlg, WT_STATUS_BAR);
1740  sbar_set_title(sbar, _("Attachments"));
1741 
1742  struct AttachCtx *actx = mutt_actx_new();
1743  actx->email = e;
1744  actx->fp_root = fp;
1745  mutt_update_recvattach_menu(sub, actx, menu, true);
1746 
1747  while (true)
1748  {
1749  if (op == OP_NULL)
1750  op = menu_loop(menu);
1751  window_redraw(dlg);
1752  if (!m)
1753  return;
1754  switch (op)
1755  {
1756  case OP_ATTACH_VIEW_MAILCAP:
1757  {
1758  struct AttachPtr *cur_att = current_attachment(actx, menu);
1759  mutt_view_attachment(cur_att->fp, cur_att->body, MUTT_VA_MAILCAP, e,
1760  actx, menu->win);
1762  break;
1763  }
1764 
1765  case OP_ATTACH_VIEW_TEXT:
1766  {
1767  struct AttachPtr *cur_att = current_attachment(actx, menu);
1768  mutt_view_attachment(cur_att->fp, cur_att->body, MUTT_VA_AS_TEXT, e,
1769  actx, menu->win);
1771  break;
1772  }
1773 
1774  case OP_ATTACH_VIEW_PAGER:
1775  {
1776  struct AttachPtr *cur_att = current_attachment(actx, menu);
1777  mutt_view_attachment(cur_att->fp, cur_att->body, MUTT_VA_PAGER, e, actx, menu->win);
1779  break;
1780  }
1781 
1782  case OP_DISPLAY_HEADERS:
1783  case OP_VIEW_ATTACH:
1784  op = mutt_attach_display_loop(sub, menu, op, e, actx, true);
1786  continue;
1787 
1788  case OP_ATTACH_COLLAPSE:
1789  {
1790  struct AttachPtr *cur_att = current_attachment(actx, menu);
1791  if (!cur_att->body->parts)
1792  {
1793  mutt_error(_("There are no subparts to show"));
1794  break;
1795  }
1796  attach_collapse(actx, menu);
1797  mutt_update_recvattach_menu(sub, actx, menu, false);
1798  break;
1799  }
1800 
1801  case OP_FORGET_PASSPHRASE:
1803  break;
1804 
1805  case OP_EXTRACT_KEYS:
1807  {
1808  recvattach_extract_pgp_keys(actx, menu);
1810  }
1811  break;
1812 
1813  case OP_CHECK_TRADITIONAL:
1814  if (((WithCrypto & APPLICATION_PGP) != 0) &&
1816  {
1817  e->security = crypt_query(NULL);
1819  }
1820  break;
1821 
1822  case OP_PRINT:
1823  {
1824  struct AttachPtr *cur_att = current_attachment(actx, menu);
1825  mutt_print_attachment_list(actx, cur_att->fp, menu->tagprefix, cur_att->body);
1826  break;
1827  }
1828 
1829  case OP_PIPE:
1830  {
1831  struct AttachPtr *cur_att = current_attachment(actx, menu);
1832  mutt_pipe_attachment_list(actx, cur_att->fp, menu->tagprefix, cur_att->body, false);
1833  break;
1834  }
1835 
1836  case OP_SAVE:
1837  {
1838  struct AttachPtr *cur_att = current_attachment(actx, menu);
1839  mutt_save_attachment_list(actx, cur_att->fp, menu->tagprefix,
1840  cur_att->body, e, menu);
1841 
1842  const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
1843  const int index = menu_get_index(menu) + 1;
1844  if (!menu->tagprefix && c_resolve && (index < menu->max))
1845  menu_set_index(menu, index);
1846  break;
1847  }
1848 
1849  case OP_DELETE:
1850  if (check_readonly(m))
1851  break;
1852 
1853 #ifdef USE_POP
1854  if (m->type == MUTT_POP)
1855  {
1856  mutt_flushinp();
1857  mutt_error(_("Can't delete attachment from POP server"));
1858  break;
1859  }
1860 #endif
1861 
1862 #ifdef USE_NNTP
1863  if (m->type == MUTT_NNTP)
1864  {
1865  mutt_flushinp();
1866  mutt_error(_("Can't delete attachment from news server"));
1867  break;
1868  }
1869 #endif
1870 
1871  if ((WithCrypto != 0) && (e->security & SEC_ENCRYPT))
1872  {
1873  mutt_message(_("Deletion of attachments from encrypted messages is "
1874  "unsupported"));
1875  break;
1876  }
1877  if ((WithCrypto != 0) && (e->security & (SEC_SIGN | SEC_PARTSIGN)))
1878  {
1879  mutt_message(_("Deletion of attachments from signed messages may "
1880  "invalidate the signature"));
1881  }
1882  if (!menu->tagprefix)
1883  {
1884  struct AttachPtr *cur_att = current_attachment(actx, menu);
1885  if (cur_att->parent_type == TYPE_MULTIPART)
1886  {
1887  cur_att->body->deleted = true;
1888  const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
1889  const int index = menu_get_index(menu) + 1;
1890  if (c_resolve && (index < menu->max))
1891  {
1892  menu_set_index(menu, index);
1893  }
1894  else
1896  }
1897  else
1898  {
1899  mutt_message(
1900  _("Only deletion of multipart attachments is supported"));
1901  }
1902  }
1903  else
1904  {
1905  for (int i = 0; i < menu->max; i++)
1906  {
1907  if (actx->idx[i]->body->tagged)
1908  {
1909  if (actx->idx[i]->parent_type == TYPE_MULTIPART)
1910  {
1911  actx->idx[i]->body->deleted = true;
1913  }
1914  else
1915  {
1916  mutt_message(
1917  _("Only deletion of multipart attachments is supported"));
1918  }
1919  }
1920  }
1921  }
1922  break;
1923 
1924  case OP_UNDELETE:
1925  if (check_readonly(m))
1926  break;
1927  if (!menu->tagprefix)
1928  {
1929  struct AttachPtr *cur_att = current_attachment(actx, menu);
1930  cur_att->body->deleted = false;
1931  const bool c_resolve = cs_subset_bool(NeoMutt->sub, "resolve");
1932  const int index = menu_get_index(menu) + 1;
1933  if (c_resolve && (index < menu->max))
1934  {
1935  menu_set_index(menu, index);
1936  }
1937  else
1939  }
1940  else
1941  {
1942  for (int i = 0; i < menu->max; i++)
1943  {
1944  if (actx->idx[i]->body->tagged)
1945  {
1946  actx->idx[i]->body->deleted = false;
1948  }
1949  }
1950  }
1951  break;
1952 
1953  case OP_RESEND:
1954  {
1955  if (check_attach())
1956  break;
1957  struct AttachPtr *cur_att = current_attachment(actx, menu);
1958  mutt_attach_resend(cur_att->fp, m, actx,
1959  menu->tagprefix ? NULL : cur_att->body);
1961  break;
1962  }
1963 
1964  case OP_BOUNCE_MESSAGE:
1965  {
1966  if (check_attach())
1967  break;
1968  struct AttachPtr *cur_att = current_attachment(actx, menu);
1969  mutt_attach_bounce(m, cur_att->fp, actx,
1970  menu->tagprefix ? NULL : cur_att->body);
1972  break;
1973  }
1974 
1975  case OP_FORWARD_MESSAGE:
1976  {
1977  if (check_attach())
1978  break;
1979  struct AttachPtr *cur_att = current_attachment(actx, menu);
1980  mutt_attach_forward(cur_att->fp, e, actx,
1981  menu->tagprefix ? NULL : cur_att->body, SEND_NO_FLAGS);
1983  break;
1984  }
1985 
1986 #ifdef USE_NNTP
1987  case OP_FORWARD_TO_GROUP:
1988  {
1989  if (check_attach())
1990  break;
1991  struct AttachPtr *cur_att = current_attachment(actx, menu);
1992  mutt_attach_forward(cur_att->fp, e, actx,
1993  menu->tagprefix ? NULL : cur_att->body, SEND_NEWS);
1995  break;
1996  }
1997 
1998  case OP_FOLLOWUP:
1999  {
2000  if (check_attach())
2001  break;
2002 
2003  const enum QuadOption c_followup_to_poster =
2004  cs_subset_quad(NeoMutt->sub, "followup_to_poster");
2005  struct AttachPtr *cur_att = current_attachment(actx, menu);
2006  if (!cur_att->body->email->env->followup_to ||
2007  !mutt_istr_equal(cur_att->body->email->env->followup_to,
2008  "poster") ||
2009  (query_quadoption(c_followup_to_poster,
2010  _("Reply by mail as poster prefers?")) != MUTT_YES))
2011  {
2012  mutt_attach_reply(cur_att->fp, m, e, actx,
2013  menu->tagprefix ? NULL : cur_att->body, SEND_NEWS | SEND_REPLY);
2015  break;
2016  }
2017  }
2018 #endif
2019  /* fallthrough */
2020  case OP_REPLY:
2021  case OP_GROUP_REPLY:
2022  case OP_GROUP_CHAT_REPLY:
2023  case OP_LIST_REPLY:
2024  {
2025  if (check_attach())
2026  break;
2027 
2028  SendFlags flags = SEND_REPLY;
2029  if (op == OP_GROUP_REPLY)
2030  flags |= SEND_GROUP_REPLY;
2031  else if (op == OP_GROUP_CHAT_REPLY)
2032  flags |= SEND_GROUP_CHAT_REPLY;
2033  else if (op == OP_LIST_REPLY)
2034  flags |= SEND_LIST_REPLY;
2035 
2036  struct AttachPtr *cur_att = current_attachment(actx, menu);
2037  mutt_attach_reply(cur_att->fp, m, e, actx,
2038  menu->tagprefix ? NULL : cur_att->body, flags);
2040  break;
2041  }
2042 
2043  case OP_COMPOSE_TO_SENDER:
2044  {
2045  if (check_attach())
2046  break;
2047  struct AttachPtr *cur_att = current_attachment(actx, menu);
2048  mutt_attach_mail_sender(cur_att->fp, e, actx,
2049  menu->tagprefix ? NULL : cur_att->body);
2051  break;
2052  }
2053 
2054  case OP_EDIT_TYPE:
2055  recvattach_edit_content_type(sub, actx, menu, e);
2057  break;
2058 
2059  case OP_EXIT:
2060  e->attach_del = false;
2061  for (int i = 0; i < actx->idxlen; i++)
2062  {
2063  if (actx->idx[i]->body && actx->idx[i]->body->deleted)
2064  {
2065  e->attach_del = true;
2066  break;
2067  }
2068  }
2069  if (e->attach_del)
2070  e->changed = true;
2071 
2072  mutt_actx_free(&actx);
2073 
2074  simple_dialog_free(&dlg);
2075  return;
2076  }
2077 
2078  op = OP_NULL;
2079  }
2080 
2081  /* not reached */
2082 }
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e, FILE *fp)
Parse a MIME email.
Definition: attachments.c:591
struct MuttWindow * window_find_child(struct MuttWindow *win, enum WindowType type)
Recursively find a child Window of a given type.
Definition: mutt_window.c:550
enum MailboxType type
Mailbox type.
Definition: mailbox.h:105
An email to which things will be attached.
Definition: attach.h:34
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:73
#define WithCrypto
Definition: lib.h:113
void simple_dialog_free(struct MuttWindow **ptr)
Destroy a simple index Dialog.
Definition: simple.c:165
static const struct Mapping AttachHelp[]
Help Bar for the Attachment selection dialog.
Definition: recvattach.c:111
Definition: lib.h:67
&#39;NNTP&#39; (Usenet) Mailbox type
Definition: mailbox.h:52
#define mutt_error(...)
Definition: logging.h:88
Attach Dialog, dlg_select_attachment()
Definition: mutt_window.h:78
struct Email * email
Used by recvattach for updating.
Definition: attach.h:51
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
void mutt_flushinp(void)
Empty all the keyboard buffers.
Definition: curs_lib.c:668
static void attach_make_entry(struct Menu *menu, char *buf, size_t buflen, int line)
Format a menu item for the attachment list - Implements Menu::make_entry() -.
Definition: recvattach.c:505
bool attach_del
Has an attachment marked for deletion.
Definition: email.h:49
void crypt_forget_passphrase(void)
Forget a passphrase and display a message.
Definition: crypt.c:93
FILE * fp_root
Used by recvattach for updating.
Definition: attach.h:52
#define _(a)
Definition: message.h:28
bool changed
Email has been edited.
Definition: email.h:48
static bool check_readonly(struct Mailbox *m)
Check if the Mailbox is readonly.
Definition: recvattach.c:157
short idxlen
Number of attachmentes.
Definition: attach.h:55
void window_redraw(struct MuttWindow *win)
Reflow, recalc and repaint a tree of Windows.
Definition: mutt_window.c:632
Force viewing as text.
Definition: mutt_attach.h:45
#define MUTT_MESSAGE_HOOK
message-hook: run before displaying a message
Definition: hook.h:46
uint16_t SendFlags
Flags for mutt_send_message(), e.g. SEND_REPLY.
Definition: send.h:36
static void mutt_update_recvattach_menu(struct ConfigSubset *sub, struct AttachCtx *actx, struct Menu *menu, bool init)
Update the Attachment Menu.
Definition: recvattach.c:1598
Container for Accounts, Notifications.
Definition: neomutt.h:36
static int attach_window_observer(struct NotifyCallback *nc)
Notification that a Window has changed - Implements observer_t.
Definition: recvattach.c:1684
MuttWindow has changed, NotifyWindow, EventWindow.
Definition: notify_type.h:53
Status Bar containing extra info about the Index/Pager/etc.
Definition: mutt_window.h:102
QuadOption
Possible values for a quad-option.
Definition: quad.h:35
void(* make_entry)(struct Menu *menu, char *buf, size_t buflen, int line)
Definition: lib.h:105
#define SEND_NO_FLAGS
No flags are set.
Definition: send.h:39
struct Notify * notify
Notifications: NotifyWindow, EventWindow.
Definition: mutt_window.h:138
struct MuttWindow * win
Window holding the Menu.
Definition: lib.h:76
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:38
struct Envelope * env
Envelope information.
Definition: email.h:90
enum QuadOption query_quadoption(enum QuadOption opt, const char *prompt)
Ask the user a quad-question.
Definition: question.c:347
#define SEND_LIST_REPLY
Reply to mailing list.
Definition: send.h:42
Select an attachment.
Definition: type.h:38
bool tagged
This attachment is tagged.
Definition: body.h:70
bool notify_observer_add(struct Notify *notify, enum NotifyType type, observer_t callback, void *global_data)
Add an observer to an object.
Definition: notify.c:189
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
int mutt_attach_display_loop(struct ConfigSubset *sub, struct Menu *menu, int op, struct Email *e, struct AttachCtx *actx, bool recv)
Event loop for the Attachment menu.
Definition: recvattach.c:1373
void mutt_attach_bounce(struct Mailbox *m, FILE *fp, struct AttachCtx *actx, struct Body *cur)
Bounce function, from the attachment menu.
Definition: recvcmd.c:161
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
&#39;POP3&#39; Mailbox type
Definition: mailbox.h:55
void mutt_attach_reply(FILE *fp, struct Mailbox *m, struct Email *e, struct AttachCtx *actx, struct Body *e_cur, SendFlags flags)
Attach a reply.
Definition: recvcmd.c:938
static struct AttachPtr * current_attachment(struct AttachCtx *actx, struct Menu *menu)
Get the current attachment.
Definition: recvattach.c:128
static int attach_config_observer(struct NotifyCallback *nc)
Notification that a Config Variable has changed - Implements observer_t.
Definition: recvattach.c:1660
static void recvattach_edit_content_type(struct ConfigSubset *sub, struct AttachCtx *actx, struct Menu *menu, struct Email *e)
Edit the content type of an attachment.
Definition: recvattach.c:1341
bool tagprefix
User has pressed <tag-prefix>
Definition: lib.h:75
static void recvattach_extract_pgp_keys(struct AttachCtx *actx, struct Menu *menu)
Extract PGP keys from attachments.
Definition: recvattach.c:1288
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
FILE * fp
Used in the recvattach menu.
Definition: attach.h:37
#define SEND_NEWS
Reply to a news article.
Definition: send.h:53
void sbar_set_title(struct MuttWindow *win, const char *title)
Set the title for the Simple Bar.
Definition: sbar.c:221
int(* tag)(struct Menu *menu, int sel, int act)
Definition: lib.h:130
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
static int recvattach_pgp_check_traditional(struct AttachCtx *actx, struct Menu *menu)
Is the Attachment inline PGP?
Definition: recvattach.c:1315
View attachment in pager using copiousoutput mailcap.
Definition: mutt_attach.h:46
Force viewing using mailcap entry.
Definition: mutt_attach.h:44
#define SEND_REPLY
Reply to sender.
Definition: send.h:40
enum QuadOption cs_subset_quad(const struct ConfigSubset *sub, const char *name)
Get a quad-value config item by name.
Definition: helpers.c:218
int max
Number of entries in the menu.
Definition: lib.h:71
void mutt_attach_resend(FILE *fp, struct Mailbox *m, struct AttachCtx *actx, struct Body *cur)
resend-message, from the attachment menu
Definition: recvcmd.c:294
void mutt_print_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, struct Body *top)
Print a list of Attachments.
Definition: recvattach.c:1240
void mutt_attach_forward(FILE *fp, struct Email *e, struct AttachCtx *actx, struct Body *cur, SendFlags flags)
Forward an Attachment.
Definition: recvcmd.c:784
Config has changed, NotifyConfig, EventConfig.
Definition: notify_type.h:42
#define SEC_SIGN
Email is signed.
Definition: lib.h:76
bool deleted
Attachment marked for deletion.
Definition: body.h:71
static void attach_collapse(struct AttachCtx *actx, struct Menu *menu)
Close the tree of the current attachment.
Definition: recvattach.c:1624
static bool check_attach(void)
Check if in attach-message mode.
Definition: recvattach.c:140
#define SEND_GROUP_REPLY
Reply to all.
Definition: send.h:41
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
struct AttachCtx * mutt_actx_new(void)
Create a new Attachment Context.
Definition: attach.c:131
char * followup_to
List of &#39;followup-to&#39; fields.
Definition: envelope.h:77
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition: crypt.c:698
#define mutt_message(...)
Definition: logging.h:87
void mutt_save_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, struct Body *top, struct Email *e, struct Menu *menu)
Save a list of attachments.
Definition: recvattach.c:788
void mutt_attach_mail_sender(FILE *fp, struct Email *e, struct AttachCtx *actx, struct Body *cur)
Compose an email to the sender in the email attachment.
Definition: recvcmd.c:1115
struct MuttWindow * simple_dialog_new(enum MenuType mtype, enum WindowType wtype, const struct Mapping *help_data)
Create a simple index Dialog.
Definition: simple.c:128
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
void mutt_message_hook(struct Mailbox *m, struct Email *e, HookFlags type)
Perform a message hook.
Definition: hook.c:598
#define SEND_GROUP_CHAT_REPLY
Reply to all recipients preserving To/Cc.
Definition: send.h:52
int attach_tag(struct Menu *menu, int sel, int act)
Tag an attachment - Implements Menu::tag() -.
Definition: recvattach.c:519
void * wdata
Private data.
Definition: mutt_window.h:145
struct Email * email
header information for message/rfc822
Definition: body.h:55
A set of attachments.
Definition: attach.h:49
struct AttachPtr ** idx
Array of attachments.
Definition: attach.h:54
#define SEC_PARTSIGN
Not all parts of the email is signed.
Definition: lib.h:79
void mutt_pipe_attachment_list(struct AttachCtx *actx, FILE *fp, bool tag, struct Body *top, bool filter)
Pipe a list of attachments to a command.
Definition: recvattach.c:1081
User answered &#39;Yes&#39;, or assume &#39;Yes&#39;.
Definition: quad.h:39
int mutt_view_attachment(FILE *fp, struct Body *a, enum ViewAttachMode mode, struct Email *e, struct AttachCtx *actx, struct MuttWindow *win)
View an attachment.
Definition: mutt_attach.c:415
void mutt_actx_free(struct AttachCtx **ptr)
Free an Attachment Context.
Definition: attach.c:140
struct Body * body
Attachment.
Definition: attach.h:36
+ 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 1465 of file recvattach.c.

1468 {
1469  struct Body *m = NULL;
1470  struct Body *new_body = NULL;
1471  FILE *fp_new = NULL;
1473  int need_secured, secured;
1474 
1475  for (m = parts; m; m = m->next)
1476  {
1477  need_secured = 0;
1478  secured = 0;
1479 
1480  if (((WithCrypto & APPLICATION_SMIME) != 0) && (type = mutt_is_application_smime(m)))
1481  {
1482  need_secured = 1;
1483 
1484  if (type & SEC_ENCRYPT)
1485  {
1486  if (!crypt_valid_passphrase(APPLICATION_SMIME))
1487  goto decrypt_failed;
1488 
1489  if (e->env)
1491  }
1492 
1493  secured = !crypt_smime_decrypt_mime(fp, &fp_new, m, &new_body);
1494  /* If the decrypt/verify-opaque doesn't generate mime output, an empty
1495  * text/plain type will still be returned by mutt_read_mime_header().
1496  * We can't distinguish an actual part from a failure, so only use a
1497  * text/plain that results from a single top-level part. */
1498  if (secured && (new_body->type == TYPE_TEXT) &&
1499  mutt_istr_equal("plain", new_body->subtype) && ((parts != m) || m->next))
1500  {
1501  mutt_body_free(&new_body);
1502  mutt_file_fclose(&fp_new);
1503  goto decrypt_failed;
1504  }
1505 
1506  if (secured && (type & SEC_ENCRYPT))
1507  e->security |= SMIME_ENCRYPT;
1508  }
1509 
1510  if (((WithCrypto & APPLICATION_PGP) != 0) &&
1512  {
1513  need_secured = 1;
1514 
1515  if (!crypt_valid_passphrase(APPLICATION_PGP))
1516  goto decrypt_failed;
1517 
1518  secured = !crypt_pgp_decrypt_mime(fp, &fp_new, m, &new_body);
1519 
1520  if (secured)
1521  e->security |= PGP_ENCRYPT;
1522  }
1523 
1524  if (need_secured && secured)
1525  {
1526  mutt_actx_add_fp(actx, fp_new);
1527  mutt_actx_add_body(actx, new_body);
1528  mutt_generate_recvattach_list(actx, e, new_body, fp_new, parent_type, level, 1);
1529  continue;
1530  }
1531 
1532  decrypt_failed:
1533  /* Fall through and show the original parts if decryption fails */
1534  if (need_secured && !secured)
1535  mutt_error(_("Can't decrypt encrypted message"));
1536 
1537  /* Strip out the top level multipart */
1538  if ((m->type == TYPE_MULTIPART) && m->parts && !need_secured &&
1539  ((parent_type == -1) && !mutt_istr_equal("alternative", m->subtype)))
1540  {
1541  mutt_generate_recvattach_list(actx, e, m->parts, fp, m->type, level, decrypted);
1542  }
1543  else
1544  {
1545  struct AttachPtr *ap = mutt_mem_calloc(1, sizeof(struct AttachPtr));
1546  mutt_actx_add_attach(actx, ap);
1547 
1548  ap->body = m;
1549  ap->fp = fp;
1550  m->aptr = ap;
1551  ap->parent_type = parent_type;
1552  ap->level = level;
1553  ap->decrypted = decrypted;
1554 
1555  if (m->type == TYPE_MULTIPART)
1556  mutt_generate_recvattach_list(actx, e, m->parts, fp, m->type, level + 1, decrypted);
1557  else if (mutt_is_message_type(m->type, m->subtype))
1558  {
1559  mutt_generate_recvattach_list(actx, m->email, m->parts, fp, m->type,
1560  level + 1, decrypted);
1561  e->security |= m->email->security;
1562  }
1563  }
1564  }
1565 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
An email to which things will be attached.
Definition: attach.h:34
#define WithCrypto
Definition: lib.h:113
bool mutt_is_message_type(int type, const char *subtype)
Determine if a mime type matches a message or not.
Definition: parse.c:1385
#define mutt_error(...)
Definition: logging.h:88
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:1465
#define SMIME_ENCRYPT
Definition: lib.h:99
#define SEC_ENCRYPT
Email is encrypted.
Definition: lib.h:75
SecurityFlags mutt_is_application_smime(struct Body *b)
Does the message use S/MIME?
Definition: crypt.c:623
#define PGP_ENCRYPT
Definition: lib.h:93
#define _(a)
Definition: message.h:28
struct Body * next
next attachment in the list
Definition: body.h:53
uint16_t SecurityFlags
Flags, e.g. SEC_ENCRYPT.
Definition: lib.h:71
The body of an email.
Definition: body.h:34
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:460
int mutt_file_fclose(FILE **fp)
Close a FILE handle (and NULL the pointer)
Definition: file.c:153
int parent_type
Type of parent attachment, e.g. TYPE_MULTIPART.
Definition: attach.h:38
void mutt_actx_add_body(struct AttachCtx *actx, struct Body *new_body)
Add an email box to an Attachment Context.
Definition: attach.c:83
struct Envelope * env
Envelope information.
Definition: email.h:90
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:916
char * subtype
content-type subtype
Definition: body.h:37
#define APPLICATION_SMIME
Use SMIME to encrypt/sign.
Definition: lib.h:88
bool decrypted
Not part of message as stored in the email->body.
Definition: attach.h:43
#define APPLICATION_PGP
Use PGP to encrypt/sign.
Definition: lib.h:87
struct AttachPtr * aptr
Menu information, used in recvattach.c.
Definition: body.h:57
Type: &#39;text/*&#39;.
Definition: mime.h:38
void crypt_smime_getkeys(struct Envelope *env)
Wrapper for CryptModuleSpecs::smime_getkeys()
Definition: cryptglue.c:463
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
FILE * fp
Used in the recvattach menu.
Definition: attach.h:37
SecurityFlags mutt_is_malformed_multipart_pgp_encrypted(struct Body *b)
Check for malformed layout.
Definition: crypt.c:521
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:439
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
void mutt_actx_add_attach(struct AttachCtx *actx, struct AttachPtr *attach)
Add an Attachment to an Attachment Context.
Definition: attach.c:40
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
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:212
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
void mutt_actx_add_fp(struct AttachCtx *actx, FILE *fp_new)
Save a File handle to the Attachment Context.
Definition: attach.c:62
struct Email * email
header information for message/rfc822
Definition: body.h:55
int level
Nesting depth of attachment.
Definition: attach.h:40
struct Body * body
Attachment.
Definition: attach.h:36
+ Here is the call graph for this function:
+ Here is the caller graph for this function: