NeoMutt  2021-02-05-329-g9e03b7
Teaching an old dog new tricks
DOXYGEN
attachments.c File Reference

Handle the attachments commmand. More...

#include "config.h"
#include <stdbool.h>
#include <stdint.h>
#include <stdio.h>
#include <string.h>
#include "mutt/lib.h"
#include "config/lib.h"
#include "email/lib.h"
#include "core/lib.h"
#include "gui/lib.h"
#include "mutt.h"
#include "attachments.h"
#include "ncrypt/lib.h"
#include "init.h"
#include "mutt_commands.h"
+ Include dependency graph for attachments.c:

Go to the source code of this file.

Data Structures

struct  AttachMatch
 An attachment matching a regex for attachment counter. More...
 

Functions

static void attachmatch_free (struct AttachMatch **ptr)
 Free an AttachMatch - Implements list_free_t. More...
 
static struct AttachMatchattachmatch_new (void)
 Create a new AttachMatch. More...
 
void attach_free (void)
 Free the attachments lists. More...
 
void attach_init (void)
 Set up the attachments lists. More...
 
static bool count_body_parts_check (struct ListHead *checklist, struct Body *b, bool dflt)
 Compares mime types to the ok and except lists. More...
 
static int count_body_parts (struct Body *body)
 Count the MIME Body parts. More...
 
int mutt_count_body_parts (struct Mailbox *m, struct Email *e, FILE *fp)
 Count the MIME Body parts. More...
 
void mutt_attachments_reset (struct Mailbox *m)
 Reset the attachment count for all Emails. More...
 
static enum CommandResult parse_attach_list (struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
 Parse the "attachments" command. More...
 
static enum CommandResult parse_unattach_list (struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
 Parse the "unattachments" command. More...
 
static int print_attach_list (struct ListHead *h, const char op, const char *name)
 Print a list of attachments. More...
 
enum CommandResult parse_attachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'attachments' command - Implements Command::parse() More...
 
enum CommandResult parse_unattachments (struct Buffer *buf, struct Buffer *s, intptr_t data, struct Buffer *err)
 Parse the 'unattachments' command - Implements Command::parse() More...
 
void mutt_parse_mime_message (struct Mailbox *m, struct Email *e, FILE *fp)
 Parse a MIME email. More...
 

Variables

struct ListHead AttachAllow = STAILQ_HEAD_INITIALIZER(AttachAllow)
 List of attachment types to be counted. More...
 
struct ListHead AttachExclude = STAILQ_HEAD_INITIALIZER(AttachExclude)
 List of attachment types to be ignored. More...
 
struct ListHead InlineAllow = STAILQ_HEAD_INITIALIZER(InlineAllow)
 List of inline types to counted. More...
 
struct ListHead InlineExclude = STAILQ_HEAD_INITIALIZER(InlineExclude)
 List of inline types to ignore. More...
 
static struct NotifyAttachmentsNotify = NULL
 

Detailed Description

Handle the attachments commmand.

Authors
  • Michael R. Elkins

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

Function Documentation

◆ attachmatch_free()

static void attachmatch_free ( struct AttachMatch **  ptr)
static

Free an AttachMatch - Implements list_free_t.

Parameters
ptrAttachMatch to free
Note
We don't free minor because it is either a pointer into major, or a static string.

Definition at line 69 of file attachments.c.

70 {
71  if (!ptr || !*ptr)
72  return;
73 
74  struct AttachMatch *am = *ptr;
75  regfree(&am->minor_regex);
76  FREE(&am->major);
77  FREE(ptr);
78 }
const char * major
Major mime type, e.g. "text".
Definition: attachments.c:50
regex_t minor_regex
Minor mime type regex.
Definition: attachments.c:53
#define FREE(x)
Definition: memory.h:40
An attachment matching a regex for attachment counter.
Definition: attachments.c:48
+ Here is the caller graph for this function:

◆ attachmatch_new()

static struct AttachMatch* attachmatch_new ( void  )
static

Create a new AttachMatch.

Return values
ptrNew AttachMatch

Definition at line 84 of file attachments.c.

85 {
86  return mutt_mem_calloc(1, sizeof(struct AttachMatch));
87 }
void * mutt_mem_calloc(size_t nmemb, size_t size)
Allocate zeroed memory on the heap.
Definition: memory.c:50
An attachment matching a regex for attachment counter.
Definition: attachments.c:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_free()

void attach_free ( void  )

Free the attachments lists.

Definition at line 92 of file attachments.c.

93 {
95 
96  /* Lists of AttachMatch */
101 }
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
static void attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: attachments.c:69
void notify_free(struct Notify **ptr)
Free a notification handler.
Definition: notify.c:62
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:144
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:59
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:57
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
void(* list_free_t)(void **ptr)
Prototype for a function to free List data.
Definition: list.h:45
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ attach_init()

void attach_init ( void  )

Set up the attachments lists.

Definition at line 106 of file attachments.c.

107 {
108  if (AttachmentsNotify)
109  return;
110 
113 }
Container for Accounts, Notifications.
Definition: neomutt.h:36
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
struct Notify * notify_new(void)
Create a new notifications handler.
Definition: notify.c:49
struct Notify * notify
Notifications handler.
Definition: neomutt.h:38
void notify_set_parent(struct Notify *notify, struct Notify *parent)
Set the parent notification handler.
Definition: notify.c:82
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ count_body_parts_check()

static bool count_body_parts_check ( struct ListHead *  checklist,
struct Body b,
bool  dflt 
)
static

Compares mime types to the ok and except lists.

Parameters
checklistList of AttachMatch
bEmail Body
dfltLog whether the matches are OK, or Excluded
Return values
trueAttachment should be counted

Definition at line 122 of file attachments.c.

123 {
124  /* If list is null, use default behavior. */
125  if (!checklist || STAILQ_EMPTY(checklist))
126  {
127  return false;
128  }
129 
130  struct AttachMatch *a = NULL;
131  struct ListNode *np = NULL;
132  STAILQ_FOREACH(np, checklist, entries)
133  {
134  a = (struct AttachMatch *) np->data;
135  mutt_debug(LL_DEBUG3, "%s %d/%s ?? %s/%s [%d]... ", dflt ? "[OK] " : "[EXCL] ",
136  b->type, b->subtype ? b->subtype : "*", a->major, a->minor, a->major_int);
137  if (((a->major_int == TYPE_ANY) || (a->major_int == b->type)) &&
138  (!b->subtype || (regexec(&a->minor_regex, b->subtype, 0, NULL, 0) == 0)))
139  {
140  mutt_debug(LL_DEBUG3, "yes\n");
141  return true;
142  }
143  else
144  {
145  mutt_debug(LL_DEBUG3, "no\n");
146  }
147  }
148 
149  return false;
150 }
enum ContentType major_int
Major mime type, e.g. TYPE_TEXT.
Definition: attachments.c:51
Type: &#39;*&#39; or &#39;.*&#39;.
Definition: mime.h:40
const char * major
Major mime type, e.g. "text".
Definition: attachments.c:50
char * subtype
content-type subtype
Definition: body.h:37
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
char * data
String.
Definition: list.h:36
regex_t minor_regex
Minor mime type regex.
Definition: attachments.c:53
#define STAILQ_EMPTY(head)
Definition: queue.h:345
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
An attachment matching a regex for attachment counter.
Definition: attachments.c:48
A List node for strings.
Definition: list.h:34
const char * minor
Minor mime type, e.g. "html".
Definition: attachments.c:52
Log at debug level 3.
Definition: logging.h:42
+ Here is the caller graph for this function:

◆ count_body_parts()

static int count_body_parts ( struct Body body)
static

Count the MIME Body parts.

Parameters
bodyBody of email
Return values
numNumber of MIME Body parts

Definition at line 157 of file attachments.c.

158 {
159  if (!body)
160  return 0;
161 
162  int count = 0;
163 
164  for (struct Body *bp = body; bp; bp = bp->next)
165  {
166  /* Initial disposition is to count and not to recurse this part. */
167  bool shallcount = true; /* default */
168  bool shallrecurse = false;
169 
170  mutt_debug(LL_DEBUG5, "desc=\"%s\"; fn=\"%s\", type=\"%d/%s\"\n",
171  bp->description ? bp->description : ("none"),
172  bp->filename ? bp->filename :
173  bp->d_filename ? bp->d_filename :
174  "(none)",
175  bp->type, bp->subtype ? bp->subtype : "*");
176 
177  if (bp->type == TYPE_MESSAGE)
178  {
179  shallrecurse = true;
180 
181  /* If it's an external body pointer, don't recurse it. */
182  if (mutt_istr_equal(bp->subtype, "external-body"))
183  shallrecurse = false;
184  }
185  else if (bp->type == TYPE_MULTIPART)
186  {
187  /* Always recurse multiparts, except multipart/alternative. */
188  shallrecurse = true;
189  if (mutt_istr_equal(bp->subtype, "alternative"))
190  {
191  const bool c_count_alternatives =
192  cs_subset_bool(NeoMutt->sub, "count_alternatives");
193  shallrecurse = c_count_alternatives;
194  }
195  }
196 
197  if ((bp->disposition == DISP_INLINE) && (bp->type != TYPE_MULTIPART) &&
198  (bp->type != TYPE_MESSAGE) && (bp == body))
199  {
200  shallcount = false; /* ignore fundamental inlines */
201  }
202 
203  /* If this body isn't scheduled for enumeration already, don't bother
204  * profiling it further. */
205  if (shallcount)
206  {
207  /* Turn off shallcount if message type is not in ok list,
208  * or if it is in except list. Check is done separately for
209  * inlines vs. attachments. */
210 
211  if (bp->disposition == DISP_ATTACH)
212  {
213  if (!count_body_parts_check(&AttachAllow, bp, true))
214  shallcount = false; /* attach not allowed */
215  if (count_body_parts_check(&AttachExclude, bp, false))
216  shallcount = false; /* attach excluded */
217  }
218  else
219  {
220  if (!count_body_parts_check(&InlineAllow, bp, true))
221  shallcount = false; /* inline not allowed */
222  if (count_body_parts_check(&InlineExclude, bp, false))
223  shallcount = false; /* excluded */
224  }
225  }
226 
227  if (shallcount)
228  count++;
229  bp->attach_qualifies = shallcount;
230 
231  mutt_debug(LL_DEBUG3, "%p shallcount = %d\n", (void *) bp, shallcount);
232 
233  if (shallrecurse)
234  {
235  mutt_debug(LL_DEBUG3, "%p pre count = %d\n", (void *) bp, count);
236  bp->attach_count = count_body_parts(bp->parts);
237  count += bp->attach_count;
238  mutt_debug(LL_DEBUG3, "%p post count = %d\n", (void *) bp, count);
239  }
240  }
241 
242  mutt_debug(LL_DEBUG3, "return %d\n", (count < 0) ? 0 : count);
243  return (count < 0) ? 0 : count;
244 }
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
bool cs_subset_bool(const struct ConfigSubset *sub, const char *name)
Get a boolean config item by name.
Definition: helpers.c:71
struct Body * next
next attachment in the list
Definition: body.h:53
static bool count_body_parts_check(struct ListHead *checklist, struct Body *b, bool dflt)
Compares mime types to the ok and except lists.
Definition: attachments.c:122
Container for Accounts, Notifications.
Definition: neomutt.h:36
The body of an email.
Definition: body.h:34
static int count_body_parts(struct Body *body)
Count the MIME Body parts.
Definition: attachments.c:157
Content is attached.
Definition: mime.h:63
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
Type: &#39;message/*&#39;.
Definition: mime.h:35
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:59
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
struct ConfigSubset * sub
Inherited config items.
Definition: neomutt.h:39
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:57
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
Log at debug level 5.
Definition: logging.h:44
Content is inline.
Definition: mime.h:62
Log at debug level 3.
Definition: logging.h:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_count_body_parts()

int mutt_count_body_parts ( struct Mailbox m,
struct Email e,
FILE *  fp 
)

Count the MIME Body parts.

Parameters
mMailbox
eEmail
fpFile to parse
Return values
numNumber of MIME Body parts

Definition at line 253 of file attachments.c.

254 {
255  if (!m || !e)
256  return 0;
257 
258  bool keep_parts = false;
259 
260  if (e->attach_valid)
261  return e->attach_total;
262 
263  if (e->body->parts)
264  keep_parts = true;
265  else
266  mutt_parse_mime_message(m, e, fp);
267 
270  {
272  }
273  else
274  e->attach_total = 0;
275 
276  e->attach_valid = true;
277 
278  if (!keep_parts)
279  mutt_body_free(&e->body->parts);
280 
281  return e->attach_total;
282 }
void mutt_parse_mime_message(struct Mailbox *m, struct Email *e, FILE *fp)
Parse a MIME email.
Definition: attachments.c:587
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
struct Body * body
List of MIME parts.
Definition: email.h:91
static int count_body_parts(struct Body *body)
Count the MIME Body parts.
Definition: attachments.c:157
short attach_total
Number of qualifying attachments in message, if attach_valid.
Definition: email.h:97
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
bool attach_valid
true when the attachment count is valid
Definition: email.h:70
void mutt_body_free(struct Body **ptr)
Free a Body.
Definition: body.c:57
struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:59
#define STAILQ_EMPTY(head)
Definition: queue.h:345
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:57
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ mutt_attachments_reset()

void mutt_attachments_reset ( struct Mailbox m)

Reset the attachment count for all Emails.

Definition at line 287 of file attachments.c.

288 {
289  if (!m)
290  return;
291 
292  for (int i = 0; i < m->msg_count; i++)
293  {
294  struct Email *e = m->emails[i];
295  if (!e)
296  break;
297  e->attach_valid = false;
298  e->attach_total = 0;
299  }
300 }
struct Email ** emails
Array of Emails.
Definition: mailbox.h:99
int msg_count
Total number of messages.
Definition: mailbox.h:91
The envelope/body of an email.
Definition: email.h:37
short attach_total
Number of qualifying attachments in message, if attach_valid.
Definition: email.h:97
bool attach_valid
true when the attachment count is valid
Definition: email.h:70
+ Here is the caller graph for this function:

◆ parse_attach_list()

static enum CommandResult parse_attach_list ( struct Buffer buf,
struct Buffer s,
struct ListHead *  head,
struct Buffer err 
)
static

Parse the "attachments" command.

Parameters
bufBuffer for temporary storage
sBuffer containing the attachments command
headList of AttachMatch to add to
errBuffer for error messages
Return values
CommandResultResult e.g. MUTT_CMD_SUCCESS

Definition at line 310 of file attachments.c.

312 {
313  struct AttachMatch *a = NULL;
314  char *p = NULL;
315  char *tmpminor = NULL;
316  size_t len;
317  int ret;
318 
319  do
320  {
322 
323  if (!buf->data || (*buf->data == '\0'))
324  continue;
325 
326  a = attachmatch_new();
327 
328  /* some cheap hacks that I expect to remove */
329  if (mutt_istr_equal(buf->data, "any"))
330  a->major = mutt_str_dup("*/.*");
331  else if (mutt_istr_equal(buf->data, "none"))
332  a->major = mutt_str_dup("cheap_hack/this_should_never_match");
333  else
334  a->major = mutt_str_dup(buf->data);
335 
336  p = strchr(a->major, '/');
337  if (p)
338  {
339  *p = '\0';
340  p++;
341  a->minor = p;
342  }
343  else
344  {
345  a->minor = "unknown";
346  }
347 
348  len = strlen(a->minor);
349  tmpminor = mutt_mem_malloc(len + 3);
350  strcpy(&tmpminor[1], a->minor);
351  tmpminor[0] = '^';
352  tmpminor[len + 1] = '$';
353  tmpminor[len + 2] = '\0';
354 
356  ret = REG_COMP(&a->minor_regex, tmpminor, REG_ICASE);
357 
358  FREE(&tmpminor);
359 
360  if (ret != 0)
361  {
362  regerror(ret, &a->minor_regex, err->data, err->dsize);
363  FREE(&a->major);
364  FREE(&a);
365  return MUTT_CMD_ERROR;
366  }
367 
368  mutt_debug(LL_DEBUG3, "added %s/%s [%d]\n", a->major, a->minor, a->major_int);
369 
370  mutt_list_insert_tail(head, (char *) a);
371  } while (MoreArgs(s));
372 
374 
375  return MUTT_CMD_SUCCESS;
376 }
static struct AttachMatch * attachmatch_new(void)
Create a new AttachMatch.
Definition: attachments.c:84
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
Attachment command changed, NotifyAttach.
Definition: notify_type.h:37
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
enum ContentType major_int
Major mime type, e.g. TYPE_TEXT.
Definition: attachments.c:51
#define REG_COMP(preg, regex, cflags)
Compile a regular expression.
Definition: regex3.h:54
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
size_t dsize
Length of data.
Definition: buffer.h:37
#define MoreArgs(buf)
Definition: buffer.h:40
enum ContentType mutt_check_mime_type(const char *s)
Check a MIME type string.
Definition: parse.c:326
const char * major
Major mime type, e.g. "text".
Definition: attachments.c:50
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
struct ListNode * mutt_list_insert_tail(struct ListHead *h, char *s)
Append a string to the end of a List.
Definition: list.c:64
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
void * mutt_mem_malloc(size_t size)
Allocate memory on the heap.
Definition: memory.c:90
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
regex_t minor_regex
Minor mime type regex.
Definition: attachments.c:53
Attachment regex has been added.
Definition: attachments.h:36
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
An attachment matching a regex for attachment counter.
Definition: attachments.c:48
const char * minor
Minor mime type, e.g. "html".
Definition: attachments.c:52
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ parse_unattach_list()

static enum CommandResult parse_unattach_list ( struct Buffer buf,
struct Buffer s,
struct ListHead *  head,
struct Buffer err 
)
static

Parse the "unattachments" command.

Parameters
bufBuffer for temporary storage
sBuffer containing the unattachments command
headList of AttachMatch to remove from
errBuffer for error messages
Return values
MUTT_CMD_SUCCESSAlways

Definition at line 386 of file attachments.c.

388 {
389  struct AttachMatch *a = NULL;
390  char *tmp = NULL;
391  char *minor = NULL;
392 
393  do
394  {
396  FREE(&tmp);
397 
398  if (mutt_istr_equal(buf->data, "any"))
399  tmp = mutt_str_dup("*/.*");
400  else if (mutt_istr_equal(buf->data, "none"))
401  tmp = mutt_str_dup("cheap_hack/this_should_never_match");
402  else
403  tmp = mutt_str_dup(buf->data);
404 
405  minor = strchr(tmp, '/');
406  if (minor)
407  {
408  *minor = '\0';
409  minor++;
410  }
411  else
412  {
413  minor = "unknown";
414  }
415  const enum ContentType major = mutt_check_mime_type(tmp);
416 
417  struct ListNode *np = NULL, *tmp2 = NULL;
418  STAILQ_FOREACH_SAFE(np, head, entries, tmp2)
419  {
420  a = (struct AttachMatch *) np->data;
421  mutt_debug(LL_DEBUG3, "check %s/%s [%d] : %s/%s [%d]\n", a->major,
422  a->minor, a->major_int, tmp, minor, major);
423  if ((a->major_int == major) && mutt_istr_equal(minor, a->minor))
424  {
425  mutt_debug(LL_DEBUG3, "removed %s/%s [%d]\n", a->major, a->minor, a->major_int);
426  regfree(&a->minor_regex);
427  FREE(&a->major);
428  STAILQ_REMOVE(head, np, ListNode, entries);
429  FREE(&np->data);
430  FREE(&np);
431  }
432  }
433 
434  } while (MoreArgs(s));
435 
436  FREE(&tmp);
437 
439 
440  return MUTT_CMD_SUCCESS;
441 }
#define STAILQ_REMOVE(head, elm, type, field)
Definition: queue.h:399
Attachment command changed, NotifyAttach.
Definition: notify_type.h:37
char * mutt_str_dup(const char *str)
Copy a string, safely.
Definition: string.c:370
enum ContentType major_int
Major mime type, e.g. TYPE_TEXT.
Definition: attachments.c:51
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
#define MoreArgs(buf)
Definition: buffer.h:40
enum ContentType mutt_check_mime_type(const char *s)
Check a MIME type string.
Definition: parse.c:326
const char * major
Major mime type, e.g. "text".
Definition: attachments.c:50
#define STAILQ_FOREACH_SAFE(var, head, field, tvar)
Definition: queue.h:359
bool mutt_istr_equal(const char *a, const char *b)
Compare two strings, ignoring case.
Definition: string.c:883
Attachment regex has been deleted.
Definition: attachments.h:37
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
Success: Command worked.
Definition: mutt_commands.h:38
char * data
String.
Definition: list.h:36
regex_t minor_regex
Minor mime type regex.
Definition: attachments.c:53
#define FREE(x)
Definition: memory.h:40
#define mutt_debug(LEVEL,...)
Definition: logging.h:81
An attachment matching a regex for attachment counter.
Definition: attachments.c:48
A List node for strings.
Definition: list.h:34
const char * minor
Minor mime type, e.g. "html".
Definition: attachments.c:52
Log at debug level 3.
Definition: logging.h:42
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
ContentType
Content-Type.
Definition: mime.h:29
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ print_attach_list()

static int print_attach_list ( struct ListHead *  h,
const char  op,
const char *  name 
)
static

Print a list of attachments.

Parameters
hList of attachments
opOperation, e.g. '+', '-'
nameAttached/Inline, 'A', 'I'
Return values
0Always

Definition at line 450 of file attachments.c.

451 {
452  struct ListNode *np = NULL;
453  STAILQ_FOREACH(np, h, entries)
454  {
455  printf("attachments %c%s %s/%s\n", op, name,
456  ((struct AttachMatch *) np->data)->major,
457  ((struct AttachMatch *) np->data)->minor);
458  }
459 
460  return 0;
461 }
#define STAILQ_FOREACH(var, head, field)
Definition: queue.h:349
char * data
String.
Definition: list.h:36
An attachment matching a regex for attachment counter.
Definition: attachments.c:48
A List node for strings.
Definition: list.h:34
+ Here is the caller graph for this function:

◆ parse_attachments()

enum CommandResult parse_attachments ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'attachments' command - Implements Command::parse()

Definition at line 466 of file attachments.c.

468 {
470  if (!buf->data || (*buf->data == '\0'))
471  {
472  mutt_buffer_strcpy(err, _("attachments: no disposition"));
473  return MUTT_CMD_WARNING;
474  }
475 
476  char *category = buf->data;
477  char op = *category++;
478 
479  if (op == '?')
480  {
481  mutt_endwin();
482  fflush(stdout);
483  printf("\n%s\n\n", _("Current attachments settings:"));
484  print_attach_list(&AttachAllow, '+', "A");
485  print_attach_list(&AttachExclude, '-', "A");
486  print_attach_list(&InlineAllow, '+', "I");
487  print_attach_list(&InlineExclude, '-', "I");
489  return MUTT_CMD_SUCCESS;
490  }
491 
492  if ((op != '+') && (op != '-'))
493  {
494  op = '+';
495  category--;
496  }
497 
498  struct ListHead *head = NULL;
499  if (mutt_istr_startswith("attachment", category))
500  {
501  if (op == '+')
502  head = &AttachAllow;
503  else
504  head = &AttachExclude;
505  }
506  else if (mutt_istr_startswith("inline", category))
507  {
508  if (op == '+')
509  head = &InlineAllow;
510  else
511  head = &InlineExclude;
512  }
513  else
514  {
515  mutt_buffer_strcpy(err, _("attachments: invalid disposition"));
516  return MUTT_CMD_ERROR;
517  }
518 
519  return parse_attach_list(buf, s, head, err);
520 }
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
#define _(a)
Definition: message.h:28
void mutt_endwin(void)
Shutdown curses/slang.
Definition: curs_lib.c:568
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
static enum CommandResult parse_attach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "attachments" command.
Definition: attachments.c:310
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
int mutt_any_key_to_continue(const char *s)
Prompt the user to &#39;press any key&#39; and wait.
Definition: curs_lib.c:601
static int print_attach_list(struct ListHead *h, const char op, const char *name)
Print a list of attachments.
Definition: attachments.c:450
Success: Command worked.
Definition: mutt_commands.h:38
Warning: Help given to the user.
Definition: mutt_commands.h:37
struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:59
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:57
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
+ Here is the call graph for this function:

◆ parse_unattachments()

enum CommandResult parse_unattachments ( struct Buffer buf,
struct Buffer s,
intptr_t  data,
struct Buffer err 
)

Parse the 'unattachments' command - Implements Command::parse()

Definition at line 525 of file attachments.c.

527 {
528  char op;
529  char *p = NULL;
530  struct ListHead *head = NULL;
531 
533  if (!buf->data || (*buf->data == '\0'))
534  {
535  mutt_buffer_strcpy(err, _("unattachments: no disposition"));
536  return MUTT_CMD_WARNING;
537  }
538 
539  p = buf->data;
540  op = *p++;
541 
542  if (op == '*')
543  {
548 
550  return 0;
551  }
552 
553  if ((op != '+') && (op != '-'))
554  {
555  op = '+';
556  p--;
557  }
558  if (mutt_istr_startswith("attachment", p))
559  {
560  if (op == '+')
561  head = &AttachAllow;
562  else
563  head = &AttachExclude;
564  }
565  else if (mutt_istr_startswith("inline", p))
566  {
567  if (op == '+')
568  head = &InlineAllow;
569  else
570  head = &InlineExclude;
571  }
572  else
573  {
574  mutt_buffer_strcpy(err, _("unattachments: invalid disposition"));
575  return MUTT_CMD_ERROR;
576  }
577 
578  return parse_unattach_list(buf, s, head, err);
579 }
struct ListHead InlineAllow
List of inline types to counted.
Definition: attachments.c:58
Error: Can&#39;t help the user.
Definition: mutt_commands.h:36
static void attachmatch_free(struct AttachMatch **ptr)
Free an AttachMatch - Implements list_free_t.
Definition: attachments.c:69
static enum CommandResult parse_unattach_list(struct Buffer *buf, struct Buffer *s, struct ListHead *head, struct Buffer *err)
Parse the "unattachments" command.
Definition: attachments.c:386
Attachment command changed, NotifyAttach.
Definition: notify_type.h:37
void mutt_list_free_type(struct ListHead *h, list_free_t fn)
Free a List of type.
Definition: list.c:144
#define _(a)
Definition: message.h:28
static struct Notify * AttachmentsNotify
Definition: attachments.c:60
Attachment regex has been deleted.
Definition: attachments.h:37
int mutt_extract_token(struct Buffer *dest, struct Buffer *tok, TokenFlags flags)
Extract one token from a string.
Definition: init.c:395
char * data
Pointer to data.
Definition: buffer.h:35
size_t mutt_istr_startswith(const char *str, const char *prefix)
Check whether a string starts with a prefix, ignoring case.
Definition: string.c:172
size_t mutt_buffer_strcpy(struct Buffer *buf, const char *s)
Copy a string into a Buffer.
Definition: buffer.c:312
Warning: Help given to the user.
Definition: mutt_commands.h:37
struct ListHead InlineExclude
List of inline types to ignore.
Definition: attachments.c:59
struct ListHead AttachExclude
List of attachment types to be ignored.
Definition: attachments.c:57
struct ListHead AttachAllow
List of attachment types to be counted.
Definition: attachments.c:56
#define MUTT_TOKEN_NO_FLAGS
No flags are set.
Definition: mutt.h:66
void(* list_free_t)(void **ptr)
Prototype for a function to free List data.
Definition: list.h:45
bool notify_send(struct Notify *notify, enum NotifyType event_type, int event_subtype, void *event_data)
Send out a notification message.
Definition: notify.c:156
+ Here is the call graph for this function:

◆ mutt_parse_mime_message()

void mutt_parse_mime_message ( struct Mailbox m,
struct Email e,
FILE *  fp 
)

Parse a MIME email.

Parameters
mMailbox
eEmail
fpFile to parse

Definition at line 587 of file attachments.c.

588 {
589  const bool right_type =
590  (e->body->type == TYPE_MESSAGE) || (e->body->type == TYPE_MULTIPART);
591  const bool not_parsed = (e->body->parts == NULL);
592 
593  if (right_type && fp && not_parsed)
594  {
595  mutt_parse_part(fp, e->body);
596  if (WithCrypto)
597  {
598  e->security = crypt_query(e->body);
599  }
600  }
601 
602  e->attach_valid = false;
603 }
#define WithCrypto
Definition: lib.h:113
struct Body * body
List of MIME parts.
Definition: email.h:91
struct Body * parts
parts of a multipart or message/rfc822
Definition: body.h:54
bool attach_valid
true when the attachment count is valid
Definition: email.h:70
SecurityFlags security
bit 0-10: flags, bit 11,12: application, bit 13: traditional pgp See: ncrypt/lib.h pgplib...
Definition: email.h:39
unsigned int type
content-type primary type, ContentType
Definition: body.h:65
Type: &#39;message/*&#39;.
Definition: mime.h:35
void mutt_parse_part(FILE *fp, struct Body *b)
Parse a MIME part.
Definition: parse.c:1676
Type: &#39;multipart/*&#39;.
Definition: mime.h:37
SecurityFlags crypt_query(struct Body *b)
Check out the type of encryption used.
Definition: crypt.c:697
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ AttachAllow

struct ListHead AttachAllow = STAILQ_HEAD_INITIALIZER(AttachAllow)

List of attachment types to be counted.

Definition at line 56 of file attachments.c.

◆ AttachExclude

struct ListHead AttachExclude = STAILQ_HEAD_INITIALIZER(AttachExclude)

List of attachment types to be ignored.

Definition at line 57 of file attachments.c.

◆ InlineAllow

struct ListHead InlineAllow = STAILQ_HEAD_INITIALIZER(InlineAllow)

List of inline types to counted.

Definition at line 58 of file attachments.c.

◆ InlineExclude

struct ListHead InlineExclude = STAILQ_HEAD_INITIALIZER(InlineExclude)

List of inline types to ignore.

Definition at line 59 of file attachments.c.

◆ AttachmentsNotify

struct Notify* AttachmentsNotify = NULL
static

Definition at line 60 of file attachments.c.