2 * This program is free software; you can redistribute it and/or modify
3 * it under the terms of the GNU General Public License as published by
4 * the Free Software Foundation; either version 2 of the License, or (at
5 * your option) any later version.
7 * This program is distributed in the hope that it will be useful, but
8 * WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
10 * General Public License for more details.
12 * You should have received a copy of the GNU General Public License
13 * along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 * Copyright © 2006 Pierre Habouzit
21 * Copyright notice from original mutt:
22 * Copyright (C) 1996-2000 Michael R. Elkins <me@mutt.org>
24 * This file is part of mutt-ng, see http://www.muttng.org/.
25 * It's licensed under the GNU General Public License,
26 * please see the file GPL in the top level source directory.
29 #include <lib-lib/lib-lib.h>
31 #include "recvattach.h"
36 /* Reads an arbitrarily long header field, and looks ahead for continuation
37 * lines. ``line'' must point to a dynamically allocated string; it is
38 * increased if more space is required to fit the whole line.
40 ssize_t mutt_read_rfc822_line(FILE *f, char **line, ssize_t *n)
47 /* end of file or end of headers */
48 if (!fgets(p + pos, *n - pos, f) || (ISSPACE(*p) && pos == 0)) {
53 pos += m_strlen(p + pos);
54 if (p[pos - 1] == '\n') {
57 /* remove trailing spaces. safe: p[0] is not a space */
60 } while (ISSPACE(p[pos]));
62 /* check to see if the next line is a continuation line */
64 if (c != ' ' && c != '\t') {
65 /* next line is a separate header field or EOH */
70 /* eat tabs and spaces from the beginning of the continuation line */
73 } while (c == ' ' || c == '\t');
76 /* string is still terminated because we removed at least one
77 whitespace char above */
81 if (*n < pos + STRING) {
89 /* TODO: Make that a string list somehow */
90 string_list_t *mutt_parse_references(char *s, int in_reply_to)
92 string_list_t *lst = NULL;
96 /* some mail clients add other garbage besides message-ids, so do a quick
97 * check to make sure this looks like a valid message-id
98 * some idiotic clients also break their message-ids between lines, deal
99 * with that too (give up if it's more than two lines, though)
102 for (s = strtok(s, " \t;"); s; s = strtok(NULL, " \t;")) {
107 if (s[n - 1] != '>') {
114 ssize_t m = m_strlen(s);
116 if (s[m - 1] != '>') {
119 new = p_new(char, n + m + 1);
125 /* make sure that this really does look like a message-id.
126 * it should have exactly one @, and if we're looking at
127 * an in-reply-to header, make sure that the part before
128 * the @ has more than eight characters or it's probably
132 char *at = strchr(new, '@');
135 if (!at || strchr(at + 1, '@') || (in_reply_to && at - new <= 8)) {
140 tmp = p_new(string_list_t, 1);
150 int mutt_check_encoding(const char *s)
152 int tok = mime_which_token(s, -1);
160 case MIME_QUOTED_PRINTABLE:
161 return ENCQUOTEDPRINTABLE;
164 case MIME_X_UUENCODE:
171 int mutt_check_mime_type(const char *s)
175 if (!m_strcmp(s, "*") || !m_strcmp(s, ".*"))
178 tok = mime_which_token(s, -1);
180 case MIME_TEXT: return TYPETEXT;
181 case MIME_MULTIPART: return TYPEMULTIPART;
182 case MIME_APPLICATION: return TYPEAPPLICATION;
183 case MIME_MESSAGE: return TYPEMESSAGE;
184 case MIME_IMAGE: return TYPEIMAGE;
185 case MIME_AUDIO: return TYPEAUDIO;
186 case MIME_VIDEO: return TYPEVIDEO;
187 case MIME_MODEL: return TYPEMODEL;
188 default: return TYPEOTHER;
192 static parameter_t *parse_parameters(const char *s)
194 parameter_t *res = NULL;
195 parameter_t **list = &res;
203 if (*s == '=') /* parameters are fucked up, go away */
206 p = strpbrk(s, "=;");
211 /* if we hit a ; now the parameter has no value, just skip it */
217 new = parameter_new();
218 new->attribute = p_dupstr(s, i);
220 while (--i >= 0 && ISSPACE(new->attribute[i])) {
221 new->attribute[i] = '\0';
223 s = skipspaces(p + 1); /* skip over the = */
226 char buffer[LONG_STRING];
230 for (i = 0; *s && i < ssizeof(buffer) - 1; i++, s++) {
231 if (!option(OPTSTRICTMIME)) {
232 /* As iso-2022-* has a characer of '"' with non-ascii state,
234 if (*s == 0x1b && i < ssizeof(buffer) - 2) {
235 state_ascii = s[1] == '(' && (s[2] == 'B' || s[2] == 'J');
238 if (state_ascii && *s == '"')
248 new->value = p_dupstr(buffer, i);
250 for (p = s; *p && *p != ' ' && *p != ';'; p++);
251 new->value = p_dupstr(s, p - s);
257 s = strchr(s, ';'); /* Find the next parameter */
259 break; /* no more parameters */
262 rfc2231_decode_parameters(&res);
266 void mutt_parse_content_type(char *s, BODY *ct)
271 p_delete(&ct->subtype);
272 parameter_list_wipe(&ct->parameter);
274 /* First extract any existing parameters */
275 if ((pc = strchr(s, ';')) != NULL) {
277 ct->parameter = parse_parameters(vskipspaces(pc));
279 /* Some pre-RFC1521 gateways still use the "name=filename" convention,
280 * but if a filename has already been set in the content-disposition,
281 * let that take precedence, and don't set it here */
282 pc = parameter_getval(ct->parameter, "name");
283 if (pc && !ct->filename)
284 ct->filename = m_strdup(pc);
287 /* Now get the subtype */
288 if ((subtype = strchr (s, '/'))) {
290 for (pc = subtype; *pc && !ISSPACE(*pc) && *pc != ';'; pc++);
291 ct->subtype = p_dupstr(subtype, pc - subtype);
294 /* Finally, get the major type */
295 ct->type = mutt_check_mime_type(s);
297 if (ct->type == TYPEOTHER) {
298 ct->xtype = m_strdup(s);
302 /* Some older non-MIME mailers (i.e., mailtool, elm) have a content-type
303 * field, so we can attempt to convert the type to BODY here.
306 char buffer[SHORT_STRING];
309 ct->subtype = m_strdup("plain");
313 ct->subtype = m_strdup("basic");
317 ct->subtype = m_strdup("rfc822");
321 ct->type = TYPEAPPLICATION;
322 snprintf(buffer, sizeof(buffer), "x-%s", s);
323 ct->subtype = m_strdup(buffer);
327 ct->subtype = m_strdup("x-unknown");
332 /* Default character set for text types. */
333 if (ct->type == TYPETEXT) {
334 pc = parameter_getval(ct->parameter, "charset");
336 parameter_setval(&ct->parameter, "charset",
337 option(OPTSTRICTMIME)
339 : charset_getfirst(AssumedCharset));
344 static void parse_content_disposition(const char *s, BODY *ct)
346 if (!ascii_strncasecmp(s, "inline", 6)) {
347 ct->disposition = DISPINLINE;
348 } else if (!ascii_strncasecmp(s, "form-data", 9)) {
349 ct->disposition = DISPFORMDATA;
351 ct->disposition = DISPATTACH;
354 /* Check to see if a default filename was given */
355 if ((s = strchr (s, ';'))) {
356 parameter_t *parms = parse_parameters(vskipspaces(s));
358 if ((s = parameter_getval(parms, "filename")))
359 m_strreplace(&ct->filename, s);
360 if ((s = parameter_getval(parms, "name")))
361 ct->form_name = m_strdup(s);
363 parameter_list_wipe(&parms);
368 * fp stream to read from
370 * digest 1 if reading subparts of a multipart/digest, 0
373 BODY *mutt_read_mime_header(FILE *fp, int digest)
375 BODY *body = body_new();
376 char *line = p_new(char, LONG_STRING);
377 ssize_t linelen = LONG_STRING;
380 body->hdr_offset = ftello(fp);
381 body->encoding = ENC7BIT; /* default from RFC1521 */
382 body->disposition = DISPINLINE;
383 body->type = digest ? TYPEMESSAGE : TYPETEXT;
385 while (mutt_read_rfc822_line(fp, &line, &linelen)) {
386 /* Find the value of the current header */
387 if ((p = strchr(line, ':'))) {
396 switch (mime_which_token(line, -1)) {
397 case MIME_CONTENT_TYPE:
398 mutt_parse_content_type (p, body);
401 case MIME_CONTENT_TRANSFER_ENCODING:
402 body->encoding = mutt_check_encoding (p);
405 case MIME_CONTENT_DISPOSITION:
406 parse_content_disposition(p, body);
409 case MIME_CONTENT_DESCRIPTION:
410 m_strreplace(&body->description, p);
411 rfc2047_decode(&body->description);
418 body->offset = ftello(fp); /* Mark the start of the real data */
419 if (!body->subtype) {
420 if (body->type == TYPETEXT)
421 body->subtype = m_strdup("plain");
422 if (body->type == TYPEMESSAGE)
423 body->subtype = m_strdup("rfc822");
430 void mutt_parse_part(FILE *fp, BODY *b)
436 bound = parameter_getval(b->parameter, "boundary");
437 fseeko(fp, b->offset, SEEK_SET);
438 b->parts = mutt_parse_multipart(fp, bound, b->offset + b->length,
439 mime_which_token(b->subtype, -1) == MIME_DIGEST);
444 fseeko(fp, b->offset, SEEK_SET);
446 if (mutt_is_message_type(b->type, b->subtype)) {
447 b->parts = mutt_parse_messageRFC822(fp, b);
449 if (mime_which_token(b->subtype, -1) == MIME_EXTERNAL_BODY) {
450 b->parts = mutt_read_mime_header(fp, 0);
461 /* try to recover from parsing error */
464 m_strreplace(&b->subtype, "plain");
468 /* parse a MESSAGE/RFC822 body
471 * fp stream to read from
473 * parent structure which contains info about the message/rfc822
476 * NOTE: this assumes that `parent->length' has been set!
478 BODY *mutt_parse_messageRFC822(FILE * fp, BODY * parent)
482 parent->hdr = header_new();
483 parent->hdr->offset = ftello(fp);
484 parent->hdr->env = mutt_read_rfc822_header(fp, parent->hdr, 0, 0);
486 msg = parent->hdr->content;
488 /* ignore the length given in the content-length since it could be wrong
489 and we already have the info to calculate the correct length */
490 /* if (msg->length == -1) */
491 /* if body of this message is empty, we can end up with a negative length */
492 msg->length = MAX(0, parent->length - (msg->offset - parent->offset));
494 mutt_parse_part(fp, msg);
499 /* parse a multipart structure
502 * fp stream to read from
504 * bound body separator
506 * end_off length of the multipart body (used when the final
507 * boundary is missing to avoid reading too far)
509 * digest 1 if reading a multipart/digest, 0 otherwise
513 mutt_parse_multipart(FILE *fp, const char *bound, off_t end_off, int digest)
515 char buffer[LONG_STRING];
518 int blen = m_strlen(bound);
519 int final = 0; /* did we see the ending boundary? */
522 mutt_error _("multipart message has no boundary parameter!");
526 while (ftello(fp) < end_off && fgets(buffer, sizeof(buffer), fp)) {
529 len = m_strlen(buffer);
530 crlf = len > 1 && buffer[len - 2] == '\r';
532 if (buffer[0] == '-' && buffer[1] == '-'
533 && !m_strncmp(buffer + 2, bound, blen))
538 /* if the body is empty, we can end up with a -1 length */
539 b->length = MAX(0, ftello(fp) - b->offset - len - 1 - crlf);
540 if (b->parts && b->parts->length == 0) {
541 b->parts->length = ftello(fp) - b->parts->offset
546 /* Remove any trailing whitespace, up to the length of the boundary */
547 for (i = len - 1; ISSPACE(buffer[i]) && i >= blen + 2; i--)
550 /* Check for the end boundary */
551 final = buffer[blen + 3] == '-' && buffer[blen + 4] == '-';
555 if (buffer[2 + blen] == '\0') {
556 BODY *new = mutt_read_mime_header(fp, digest);
559 * Consistency checking - catch
560 * bad attachment end boundaries
563 if (new->offset > end_off) {
564 body_list_wipe(&new);
569 last = &(*last)->next;
575 /* in case of missing end boundary, set the length to something reasonable */
576 if (*last && (*last)->length == 0 && !final)
577 (*last)->length = end_off - (*last)->offset;
579 /* parse recursive MIME parts */
582 for (b = head; b; b = b->next)
583 mutt_parse_part(fp, b);
590 uncomment_timezone(char *buf, size_t buflen, const char *tz)
595 return tz; /* no need to do anything */
597 tz = vskipspaces(tz + 1);
598 p = strpbrk(tz, " )");
602 m_strncpy(buf, buflen, tz, p - tz);
606 /* parses a date string in RFC822 format:
608 * Date: [ weekday , ] day-of-month month year hour:minute:second timezone
610 * This routine assumes that `h' has been initialized to 0. the `timezone'
611 * field is optional, defaulting to +0000 if missing.
613 time_t mutt_parse_date(const char *s, HEADER *h)
615 int zhours = 0, zminutes = 0, zoccident = 0;
616 char scratch[SHORT_STRING];
621 /* Don't modify our argument. Fixed-size buffer is ok here since
622 the date format imposes a natural limit. */
624 m_strcpy(scratch, sizeof(scratch), s);
626 /* kill the day of the week, if it exists. */
627 p = strchr(scratch, ',');
628 p = vskipspaces(p ? p + 1 : scratch);
632 while ((p = strtok (p, " \t")) != NULL) {
633 char tzstr[SHORT_STRING];
637 case 0: /* day of the month */
638 if (!isdigit((unsigned char)*p))
640 tm.tm_mday = atoi(p);
645 case 1: /* month of the year */
646 tm.tm_mon = mutt_check_month(p);
652 tm.tm_year = atoi(p);
655 else if (tm.tm_year >= 1900)
659 case 3: /* time of day */
660 tm.tm_hour = strtol(p, &p, 10);
663 tm.tm_min = strtol(p, &p, 10);
665 tm.tm_sec = strtol(p, &p, 10);
671 case 4: /* timezone */
672 /* sometimes we see things like (MST) or (-0700) so attempt to
673 * compensate by uncommenting the string if non-RFC822 compliant
675 ptz = uncomment_timezone(tzstr, sizeof(tzstr), p);
677 if (*ptz == '+' || *ptz == '-') {
678 if (isdigit((unsigned char)ptz[1])
679 && isdigit((unsigned char)ptz[2])
680 && isdigit((unsigned char)ptz[3])
681 && isdigit((unsigned char)ptz[4]))
683 zoccident = ptz[0] == '-';
684 zhours = (ptz[1] - '0') * 10 + (ptz[2] - '0');
685 zminutes = (ptz[3] - '0') * 10 + (ptz[4] - '0');
694 if (count < 4) { /* don't check for missing timezone */
700 h->zminutes = zminutes;
701 h->zoccident = zoccident;
704 return mutt_mktime(&tm, 0) + (zoccident ? 1 : -1) * (zhours * 3600 + zminutes * 60);
707 string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p,
708 short weed, short do_2047, string_list_t **user_hdrs)
710 switch (mime_which_token(line, -1)) {
711 case MIME_APPARENTLY_FROM:
712 e->from = rfc822_parse_adrlist (e->from, p);
715 case MIME_APPARENTLY_TO:
716 e->to = rfc822_parse_adrlist (e->to, p);
720 e->bcc = rfc822_parse_adrlist (e->bcc, p);
724 e->cc = rfc822_parse_adrlist (e->cc, p);
727 case MIME_CONTENT_DESCRIPTION:
729 m_strreplace(&hdr->content->description, p);
730 rfc2047_decode(&hdr->content->description);
734 case MIME_CONTENT_DISPOSITION:
736 parse_content_disposition(p, hdr->content);
739 case MIME_CONTENT_LENGTH:
741 if ((hdr->content->length = atoi(p)) < 0)
742 hdr->content->length = -1;
746 case MIME_CONTENT_TRANSFER_ENCODING:
748 hdr->content->encoding = mutt_check_encoding(p);
751 case MIME_CONTENT_TYPE:
753 mutt_parse_content_type (p, hdr->content);
757 m_strreplace(&e->date, p);
759 hdr->date_sent = mutt_parse_date (p, hdr);
763 if (hdr && mutt_parse_date (p, NULL) < time (NULL))
768 case MIME_FOLLOWUP_TO:
769 if (!e->followup_to) {
771 e->followup_to = m_strdup(skipspaces(p));
777 e->from = rfc822_parse_adrlist(e->from, p);
778 /* don't leave from info NULL if there's an invalid address (or
779 * whatever) in From: field; mutt would just display it as empty
780 * and mark mail/(esp.) news article as your own. aaargh! this
781 * bothered me for _years_ */
783 e->from = address_new();
784 e->from->personal = m_strdup(p);
788 case MIME_IN_REPLY_TO:
789 string_list_wipe(&e->in_reply_to);
790 e->in_reply_to = mutt_parse_references(p, 1);
795 /* HACK - mutt has, for a very short time, produced negative
796 Lines header values. Ignore them. */
797 hdr->lines = MAX(0, atoi(p));
802 /* RFC 2369. FIXME: We should ignore whitespace, but don't. */
803 if (strncmp(p, "NO", 2)) {
806 for (beg = strchr (p, '<'); beg; beg = strchr (end, ',')) {
808 if (!(end = strchr (beg, '>')))
811 /* Take the first mailto URL */
812 if (url_check_scheme (beg) == U_MAILTO) {
813 p_delete(&e->list_post);
814 e->list_post = p_dupstr(beg, end - beg);
821 case MIME_MAIL_FOLLOWUP_TO:
822 e->mail_followup_to = rfc822_parse_adrlist(e->mail_followup_to, p);
825 case MIME_MAIL_REPLY_TO:
826 address_list_wipe(&e->reply_to);
827 e->reply_to = rfc822_parse_adrlist(e->reply_to, p);
830 case MIME_MESSAGE_ID:
832 const char *beg, *end;
834 /* We add a new "Message-ID:" when building a message */
835 p_delete(&e->message_id);
837 if ((beg = strchr(p, '<')) && (end = strchr(beg, '>')))
838 e->message_id = p_dupstr(beg, (end - beg) + 1);
842 case MIME_MIME_VERSION:
848 case MIME_NEWSGROUPS:
849 p_delete(&e->newsgroups);
851 e->newsgroups = m_strdup(skipspaces(p));
855 case MIME_ORGANIZATION:
856 if (!e->organization && mime_which_token(p, -1) == MIME_UNKNOWN)
857 e->organization = m_strdup(p);
861 if (hdr && !hdr->received) {
862 char *d = strchr(p, ';');
864 hdr->received = mutt_parse_date(d + 1, NULL);
868 case MIME_REFERENCES:
869 string_list_wipe(&e->references);
870 e->references = mutt_parse_references(p, 0);
874 e->reply_to = rfc822_parse_adrlist(e->reply_to, p);
877 case MIME_RETURN_PATH:
878 e->return_path = rfc822_parse_adrlist(e->return_path, p);
882 e->sender = rfc822_parse_adrlist (e->sender, p);
906 e->subject = m_strdup(p);
909 case MIME_SUPERCEDES:
910 case MIME_SUPERSEDES:
912 e->supersedes = m_strdup(p);
916 e->to = rfc822_parse_adrlist(e->to, p);
920 case MIME_X_COMMENT_TO:
921 if (!e->x_comment_to)
922 e->x_comment_to = m_strdup(p);
927 e->x_label = m_strdup(p);
933 e->xref = m_strdup(p);
962 /* restore the original line */
963 line[m_strlen(line)] = ':';
965 if (weed && option(OPTWEED) && mutt_matches_ignore(line, Ignore)
966 && !mutt_matches_ignore(line, UnIgnore)) {
970 *user_hdrs = string_item_new();
971 (*user_hdrs)->data = m_strdup(line);
973 rfc2047_decode(&(*user_hdrs)->data);
974 return &(*user_hdrs)->next;
980 /* mutt_read_rfc822_header() -- parses a RFC822 header
984 * f stream to read from
986 * hdr header structure of current message (optional).
988 * user_hdrs If set, store user headers. Used for recall-message and
991 * weed If this parameter is set and the user has activated the
992 * $weed option, honor the header weed list for user headers.
993 * Used for recall-message.
995 * Returns: newly allocated envelope structure. You should free it by
996 * envelope_delete() when envelope stay unneeded.
999 mutt_read_rfc822_header(FILE *f, HEADER *hdr, short user_hdrs, short weed)
1001 ENVELOPE *e = envelope_new();
1002 string_list_t **last = user_hdrs ? &e->userhdrs : NULL;
1004 char *line = p_new(char, LONG_STRING);
1005 ssize_t linelen = LONG_STRING;
1008 if (hdr && !hdr->content) {
1009 hdr->content = body_new();
1011 /* set the defaults from RFC1521 */
1012 hdr->content->type = TYPETEXT;
1013 hdr->content->subtype = m_strdup("plain");
1014 hdr->content->encoding = ENC7BIT;
1015 hdr->content->length = -1;
1017 /* RFC 2183 says this is arbitrary */
1018 hdr->content->disposition = DISPINLINE;
1021 while ((loc = ftello(f)),
1022 mutt_read_rfc822_line(f, &line, &linelen))
1024 char buf[LONG_STRING + 1] = "";
1027 p = strpbrk(line, ": \t");
1028 if (!p || *p != ':') {
1029 char return_path[LONG_STRING];
1032 /* some bogus MTAs will quote the original "From " line */
1033 if (!m_strncmp(">From ", line, 6))
1034 continue; /* just ignore */
1036 if (is_from(line, return_path, sizeof(return_path), &t)) {
1037 /* MH somtimes has the From_ line in the middle of the header! */
1038 if (hdr && !hdr->received)
1039 hdr->received = t - mutt_local_tz(t);
1044 break; /* end of header */
1047 if (mutt_match_spam_list(line, SpamList, buf, sizeof(buf))) {
1048 if (!rx_list_match(NoSpamList, line)) {
1049 /* if spam tag already exists, figure out how to amend it */
1050 if (e->spam && *buf) {
1052 /* If SpamSep defined, append with separator */
1053 mutt_buffer_addstr(e->spam, SpamSep);
1054 mutt_buffer_addstr(e->spam, buf);
1056 /* else overwrite */
1057 mutt_buffer_reset(e->spam);
1058 mutt_buffer_addstr(e->spam, buf);
1061 else if (!e->spam && *buf) {
1062 /* spam tag is new, and match expr is non-empty; copy */
1063 e->spam = mutt_buffer_from(NULL, buf);
1065 else if (!e->spam) {
1066 /* match expr is empty; plug in null string if no existing tag */
1067 e->spam = mutt_buffer_from(NULL, "");
1075 continue; /* skip empty header fields */
1077 last = mutt_parse_rfc822_line(e, hdr, line, p, weed, 1, last);
1083 hdr->content->hdr_offset = hdr->offset;
1084 hdr->content->offset = ftello(f);
1085 rfc2047_decode_envelope(e);
1086 /* check for missing or invalid date */
1087 if (hdr->date_sent <= 0) {
1088 hdr->date_sent = hdr->received;
1095 /* Compares mime types to the ok and except lists */
1096 static int count_body_parts_check(string_list_t **checklist, BODY *b)
1098 string_list_t *type;
1100 for (type = *checklist; type; type = type->next) {
1101 ATTACH_MATCH *a = (ATTACH_MATCH *)type->data;
1103 if ((a->major_int == TYPEANY || a->major_int == b->type)
1104 && !regexec(&a->minor_rx, b->subtype, 0, NULL, 0)) {
1112 static int count_body_parts (BODY *body, int flags)
1120 for (bp = body; bp != NULL; bp = bp->next) {
1121 /* Initial disposition is to count and not to recurse this part. */
1122 int shallcount, shallrecurse, iscontainer;
1123 int tok = mime_which_token(bp->subtype, -1);
1125 iscontainer = bp->type == TYPEMESSAGE || bp->type == TYPEMULTIPART;
1127 /* don't recurse in external bodies or multipart/alternatives */
1128 shallrecurse = (bp->type == TYPEMESSAGE && tok != MIME_EXTERNAL_BODY)
1129 || (bp->type == TYPEMULTIPART && tok != MIME_ALTERNATIVE);
1131 /* Don't count top level containers and fundamental inlines */
1132 shallcount = !(iscontainer && (flags & M_PARTS_TOPLEVEL))
1133 && !(!iscontainer && bp->disposition == DISPINLINE && bp == body);
1136 /* Turn off shallcount if message type is not in ok list,
1137 * or if it is in except list. Check is done separately for
1138 * inlines vs. attachments.
1141 if (bp->disposition == DISPATTACH) {
1142 if (!count_body_parts_check(&AttachAllow, bp))
1144 if (count_body_parts_check(&AttachExclude, bp))
1147 if (!count_body_parts_check(&InlineAllow, bp))
1149 if (count_body_parts_check(&InlineExclude, bp))
1154 bp->attach_qualifies = shallcount;
1155 count += shallcount;
1158 bp->attach_count = count_body_parts(bp->parts,
1159 flags & ~M_PARTS_TOPLEVEL);
1160 count += bp->attach_count;
1167 int mutt_count_body_parts(HEADER *hdr, int flags)
1169 if (!option(OPTCOUNTATTACH))
1172 if (hdr->attach_valid && !(flags & M_PARTS_RECOUNT))
1173 return hdr->attach_total;
1175 if (AttachAllow || AttachExclude || InlineAllow || InlineExclude)
1176 hdr->attach_total = count_body_parts(hdr->content,
1177 flags | M_PARTS_TOPLEVEL);
1179 hdr->attach_total = 0;
1181 hdr->attach_valid = 1;
1182 return hdr->attach_total;