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.
35 #include <lib-lib/lib-lib.h>
37 #include "recvattach.h"
42 /* Reads an arbitrarily long header field, and looks ahead for continuation
43 * lines. ``line'' must point to a dynamically allocated string; it is
44 * increased if more space is required to fit the whole line.
46 ssize_t mutt_read_rfc822_line(FILE *f, char **line, ssize_t *n)
53 /* end of file or end of headers */
54 if (!fgets(p + pos, *n - pos, f) || (ISSPACE(*p) && pos == 0)) {
59 pos += m_strlen(p + pos);
60 if (p[pos - 1] == '\n') {
63 /* remove trailing spaces. safe: p[0] is not a space */
66 } while (ISSPACE(p[pos]));
68 /* check to see if the next line is a continuation line */
70 if (c != ' ' && c != '\t') {
71 /* next line is a separate header field or EOH */
76 /* eat tabs and spaces from the beginning of the continuation line */
79 } while (c == ' ' || c == '\t');
82 /* string is still terminated because we removed at least one
83 whitespace char above */
87 if (*n < pos + STRING) {
95 /* TODO: Make that a string list somehow */
96 string_list_t *mutt_parse_references(char *s, int in_reply_to)
98 string_list_t *lst = NULL;
102 /* some mail clients add other garbage besides message-ids, so do a quick
103 * check to make sure this looks like a valid message-id
104 * some idiotic clients also break their message-ids between lines, deal
105 * with that too (give up if it's more than two lines, though)
108 for (s = strtok(s, " \t;"); s; s = strtok(NULL, " \t;")) {
113 if (s[n - 1] != '>') {
120 ssize_t m = m_strlen(s);
122 if (s[m - 1] != '>') {
125 new = p_new(char, n + m + 1);
131 /* make sure that this really does look like a message-id.
132 * it should have exactly one @, and if we're looking at
133 * an in-reply-to header, make sure that the part before
134 * the @ has more than eight characters or it's probably
138 char *at = strchr(new, '@');
141 if (!at || strchr(at + 1, '@') || (in_reply_to && at - new <= 8)) {
146 tmp = p_new(string_list_t, 1);
156 int mutt_check_encoding(const char *s)
158 int tok = mime_which_token(s, -1);
166 case MIME_QUOTED_PRINTABLE:
167 return ENCQUOTEDPRINTABLE;
170 case MIME_X_UUENCODE:
177 int mutt_check_mime_type(const char *s)
181 if (!m_strcmp(s, "*") || !m_strcmp(s, ".*"))
184 tok = mime_which_token(s, -1);
186 case MIME_TEXT: return TYPETEXT;
187 case MIME_MULTIPART: return TYPEMULTIPART;
188 case MIME_APPLICATION: return TYPEAPPLICATION;
189 case MIME_MESSAGE: return TYPEMESSAGE;
190 case MIME_IMAGE: return TYPEIMAGE;
191 case MIME_AUDIO: return TYPEAUDIO;
192 case MIME_VIDEO: return TYPEVIDEO;
193 case MIME_MODEL: return TYPEMODEL;
194 default: return TYPEOTHER;
198 static parameter_t *parse_parameters(const char *s)
200 parameter_t *res = NULL;
201 parameter_t **list = &res;
209 if (*s == '=') /* parameters are fucked up, go away */
212 p = strpbrk(s, "=;");
217 /* if we hit a ; now the parameter has no value, just skip it */
223 new = parameter_new();
224 new->attribute = p_dupstr(s, i);
226 while (--i >= 0 && ISSPACE(new->attribute[i])) {
227 new->attribute[i] = '\0';
229 s = skipspaces(p + 1); /* skip over the = */
232 char buffer[LONG_STRING];
236 for (i = 0; *s && i < ssizeof(buffer) - 1; i++, s++) {
237 if (!option(OPTSTRICTMIME)) {
238 /* As iso-2022-* has a characer of '"' with non-ascii state,
240 if (*s == 0x1b && i < ssizeof(buffer) - 2) {
241 state_ascii = s[1] == '(' && (s[2] == 'B' || s[2] == 'J');
244 if (state_ascii && *s == '"')
254 new->value = p_dupstr(buffer, i);
256 for (p = s; *p && *p != ' ' && *p != ';'; p++);
257 new->value = p_dupstr(s, p - s);
263 s = strchr(s, ';'); /* Find the next parameter */
265 break; /* no more parameters */
268 rfc2231_decode_parameters(&res);
272 void mutt_parse_content_type(char *s, BODY *ct)
277 p_delete(&ct->subtype);
278 parameter_list_wipe(&ct->parameter);
280 /* First extract any existing parameters */
281 if ((pc = strchr(s, ';')) != NULL) {
283 ct->parameter = parse_parameters(vskipspaces(pc));
285 /* Some pre-RFC1521 gateways still use the "name=filename" convention,
286 * but if a filename has already been set in the content-disposition,
287 * let that take precedence, and don't set it here */
288 pc = parameter_getval(ct->parameter, "name");
289 if (pc && !ct->filename)
290 ct->filename = m_strdup(pc);
293 /* Now get the subtype */
294 if ((subtype = strchr (s, '/'))) {
296 for (pc = subtype; *pc && !ISSPACE(*pc) && *pc != ';'; pc++);
297 ct->subtype = p_dupstr(subtype, pc - subtype);
300 /* Finally, get the major type */
301 ct->type = mutt_check_mime_type(s);
303 if (ct->type == TYPEOTHER) {
304 ct->xtype = m_strdup(s);
308 /* Some older non-MIME mailers (i.e., mailtool, elm) have a content-type
309 * field, so we can attempt to convert the type to BODY here.
312 char buffer[SHORT_STRING];
315 ct->subtype = m_strdup("plain");
319 ct->subtype = m_strdup("basic");
323 ct->subtype = m_strdup("rfc822");
327 ct->type = TYPEAPPLICATION;
328 snprintf(buffer, sizeof(buffer), "x-%s", s);
329 ct->subtype = m_strdup(buffer);
333 ct->subtype = m_strdup("x-unknown");
338 /* Default character set for text types. */
339 if (ct->type == TYPETEXT) {
340 pc = parameter_getval(ct->parameter, "charset");
342 parameter_setval(&ct->parameter, "charset",
343 option(OPTSTRICTMIME)
345 : charset_getfirst(AssumedCharset));
350 static void parse_content_disposition(const char *s, BODY *ct)
352 if (!ascii_strncasecmp(s, "inline", 6)) {
353 ct->disposition = DISPINLINE;
354 } else if (!ascii_strncasecmp(s, "form-data", 9)) {
355 ct->disposition = DISPFORMDATA;
357 ct->disposition = DISPATTACH;
360 /* Check to see if a default filename was given */
361 if ((s = strchr (s, ';'))) {
362 parameter_t *parms = parse_parameters(vskipspaces(s));
364 if ((s = parameter_getval(parms, "filename")))
365 m_strreplace(&ct->filename, s);
366 if ((s = parameter_getval(parms, "name")))
367 ct->form_name = m_strdup(s);
369 parameter_list_wipe(&parms);
374 * fp stream to read from
376 * digest 1 if reading subparts of a multipart/digest, 0
379 BODY *mutt_read_mime_header(FILE *fp, int digest)
381 BODY *body = body_new();
382 char *line = p_new(char, LONG_STRING);
383 ssize_t linelen = LONG_STRING;
386 body->hdr_offset = ftello(fp);
387 body->encoding = ENC7BIT; /* default from RFC1521 */
388 body->disposition = DISPINLINE;
389 body->type = digest ? TYPEMESSAGE : TYPETEXT;
391 while (mutt_read_rfc822_line(fp, &line, &linelen)) {
392 /* Find the value of the current header */
393 if ((p = strchr(line, ':'))) {
402 switch (mime_which_token(line, -1)) {
403 case MIME_CONTENT_TYPE:
404 mutt_parse_content_type (p, body);
407 case MIME_CONTENT_TRANSFER_ENCODING:
408 body->encoding = mutt_check_encoding (p);
411 case MIME_CONTENT_DISPOSITION:
412 parse_content_disposition(p, body);
415 case MIME_CONTENT_DESCRIPTION:
416 m_strreplace(&body->description, p);
417 rfc2047_decode(&body->description);
424 body->offset = ftello(fp); /* Mark the start of the real data */
425 if (!body->subtype) {
426 if (body->type == TYPETEXT)
427 body->subtype = m_strdup("plain");
428 if (body->type == TYPEMESSAGE)
429 body->subtype = m_strdup("rfc822");
436 void mutt_parse_part(FILE *fp, BODY *b)
442 bound = parameter_getval(b->parameter, "boundary");
443 fseeko(fp, b->offset, SEEK_SET);
444 b->parts = mutt_parse_multipart(fp, bound, b->offset + b->length,
445 mime_which_token(b->subtype, -1) == MIME_DIGEST);
450 fseeko(fp, b->offset, SEEK_SET);
452 if (mutt_is_message_type(b->type, b->subtype)) {
453 b->parts = mutt_parse_messageRFC822(fp, b);
455 if (mime_which_token(b->subtype, -1) == MIME_EXTERNAL_BODY) {
456 b->parts = mutt_read_mime_header(fp, 0);
467 /* try to recover from parsing error */
470 m_strreplace(&b->subtype, "plain");
474 /* parse a MESSAGE/RFC822 body
477 * fp stream to read from
479 * parent structure which contains info about the message/rfc822
482 * NOTE: this assumes that `parent->length' has been set!
484 BODY *mutt_parse_messageRFC822(FILE * fp, BODY * parent)
488 parent->hdr = header_new();
489 parent->hdr->offset = ftello(fp);
490 parent->hdr->env = mutt_read_rfc822_header(fp, parent->hdr, 0, 0);
492 msg = parent->hdr->content;
494 /* ignore the length given in the content-length since it could be wrong
495 and we already have the info to calculate the correct length */
496 /* if (msg->length == -1) */
497 /* if body of this message is empty, we can end up with a negative length */
498 msg->length = MAX(0, parent->length - (msg->offset - parent->offset));
500 mutt_parse_part(fp, msg);
505 /* parse a multipart structure
508 * fp stream to read from
510 * bound body separator
512 * end_off length of the multipart body (used when the final
513 * boundary is missing to avoid reading too far)
515 * digest 1 if reading a multipart/digest, 0 otherwise
519 mutt_parse_multipart(FILE *fp, const char *bound, off_t end_off, int digest)
521 char buffer[LONG_STRING];
524 int blen = m_strlen(bound);
525 int final = 0; /* did we see the ending boundary? */
528 mutt_error _("multipart message has no boundary parameter!");
532 while (ftello(fp) < end_off && fgets(buffer, sizeof(buffer), fp)) {
535 len = m_strlen(buffer);
536 crlf = len > 1 && buffer[len - 2] == '\r';
538 if (buffer[0] == '-' && buffer[1] == '-'
539 && !m_strncmp(buffer + 2, bound, blen))
544 /* if the body is empty, we can end up with a -1 length */
545 b->length = MAX(0, ftello(fp) - b->offset - len - 1 - crlf);
546 if (b->parts && b->parts->length == 0) {
547 b->parts->length = ftello(fp) - b->parts->offset
552 /* Remove any trailing whitespace, up to the length of the boundary */
553 for (i = len - 1; ISSPACE(buffer[i]) && i >= blen + 2; i--)
556 /* Check for the end boundary */
557 final = buffer[blen + 3] == '-' && buffer[blen + 4] == '-';
561 if (buffer[2 + blen] == '\0') {
562 BODY *new = mutt_read_mime_header(fp, digest);
565 * Consistency checking - catch
566 * bad attachment end boundaries
569 if (new->offset > end_off) {
570 body_list_wipe(&new);
575 last = &(*last)->next;
581 /* in case of missing end boundary, set the length to something reasonable */
582 if (*last && (*last)->length == 0 && !final)
583 (*last)->length = end_off - (*last)->offset;
585 /* parse recursive MIME parts */
588 for (b = head; b; b = b->next)
589 mutt_parse_part(fp, b);
596 uncomment_timezone(char *buf, size_t buflen, const char *tz)
601 return tz; /* no need to do anything */
603 tz = vskipspaces(tz + 1);
604 p = strpbrk(tz, " )");
608 m_strncpy(buf, buflen, tz, p - tz);
612 /* parses a date string in RFC822 format:
614 * Date: [ weekday , ] day-of-month month year hour:minute:second timezone
616 * This routine assumes that `h' has been initialized to 0. the `timezone'
617 * field is optional, defaulting to +0000 if missing.
619 time_t mutt_parse_date(const char *s, HEADER *h)
621 int zhours = 0, zminutes = 0, zoccident = 0;
622 char scratch[SHORT_STRING];
627 /* Don't modify our argument. Fixed-size buffer is ok here since
628 the date format imposes a natural limit. */
630 m_strcpy(scratch, sizeof(scratch), s);
632 /* kill the day of the week, if it exists. */
633 p = strchr(scratch, ',');
634 p = vskipspaces(p ? p + 1 : scratch);
638 while ((p = strtok (p, " \t")) != NULL) {
639 char tzstr[SHORT_STRING];
643 case 0: /* day of the month */
644 if (!isdigit((unsigned char)*p))
646 tm.tm_mday = atoi(p);
651 case 1: /* month of the year */
652 tm.tm_mon = mutt_check_month(p);
658 tm.tm_year = atoi(p);
661 else if (tm.tm_year >= 1900)
665 case 3: /* time of day */
666 tm.tm_hour = strtol(p, &p, 10);
669 tm.tm_min = strtol(p, &p, 10);
671 tm.tm_sec = strtol(p, &p, 10);
677 case 4: /* timezone */
678 /* sometimes we see things like (MST) or (-0700) so attempt to
679 * compensate by uncommenting the string if non-RFC822 compliant
681 ptz = uncomment_timezone(tzstr, sizeof(tzstr), p);
683 if (*ptz == '+' || *ptz == '-') {
684 if (isdigit((unsigned char)ptz[1])
685 && isdigit((unsigned char)ptz[2])
686 && isdigit((unsigned char)ptz[3])
687 && isdigit((unsigned char)ptz[4]))
689 zoccident = ptz[0] == '-';
690 zhours = (ptz[1] - '0') * 10 + (ptz[2] - '0');
691 zminutes = (ptz[3] - '0') * 10 + (ptz[4] - '0');
700 if (count < 4) { /* don't check for missing timezone */
706 h->zminutes = zminutes;
707 h->zoccident = zoccident;
710 return mutt_mktime(&tm, 0) + (zoccident ? 1 : -1) * (zhours * 3600 + zminutes * 60);
713 string_list_t **mutt_parse_rfc822_line(ENVELOPE *e, HEADER *hdr, char *line, char *p,
714 short weed, short do_2047, string_list_t **user_hdrs)
716 switch (mime_which_token(line, -1)) {
717 case MIME_APPARENTLY_FROM:
718 e->from = rfc822_parse_adrlist (e->from, p);
721 case MIME_APPARENTLY_TO:
722 e->to = rfc822_parse_adrlist (e->to, p);
726 e->bcc = rfc822_parse_adrlist (e->bcc, p);
730 e->cc = rfc822_parse_adrlist (e->cc, p);
733 case MIME_CONTENT_DESCRIPTION:
735 m_strreplace(&hdr->content->description, p);
736 rfc2047_decode(&hdr->content->description);
740 case MIME_CONTENT_DISPOSITION:
742 parse_content_disposition(p, hdr->content);
745 case MIME_CONTENT_LENGTH:
747 if ((hdr->content->length = atoi(p)) < 0)
748 hdr->content->length = -1;
752 case MIME_CONTENT_TRANSFER_ENCODING:
754 hdr->content->encoding = mutt_check_encoding(p);
757 case MIME_CONTENT_TYPE:
759 mutt_parse_content_type (p, hdr->content);
763 m_strreplace(&e->date, p);
765 hdr->date_sent = mutt_parse_date (p, hdr);
769 if (hdr && mutt_parse_date (p, NULL) < time (NULL))
774 case MIME_FOLLOWUP_TO:
775 if (!e->followup_to) {
777 e->followup_to = m_strdup(skipspaces(p));
783 e->from = rfc822_parse_adrlist(e->from, p);
784 /* don't leave from info NULL if there's an invalid address (or
785 * whatever) in From: field; mutt would just display it as empty
786 * and mark mail/(esp.) news article as your own. aaargh! this
787 * bothered me for _years_ */
789 e->from = address_new();
790 e->from->personal = m_strdup(p);
794 case MIME_IN_REPLY_TO:
795 string_list_wipe(&e->in_reply_to);
796 e->in_reply_to = mutt_parse_references(p, 1);
801 /* HACK - mutt has, for a very short time, produced negative
802 Lines header values. Ignore them. */
803 hdr->lines = MAX(0, atoi(p));
808 /* RFC 2369. FIXME: We should ignore whitespace, but don't. */
809 if (strncmp(p, "NO", 2)) {
812 for (beg = strchr (p, '<'); beg; beg = strchr (end, ',')) {
814 if (!(end = strchr (beg, '>')))
817 /* Take the first mailto URL */
818 if (url_check_scheme (beg) == U_MAILTO) {
819 p_delete(&e->list_post);
820 e->list_post = p_dupstr(beg, end - beg);
827 case MIME_MAIL_FOLLOWUP_TO:
828 e->mail_followup_to = rfc822_parse_adrlist(e->mail_followup_to, p);
831 case MIME_MAIL_REPLY_TO:
832 address_list_wipe(&e->reply_to);
833 e->reply_to = rfc822_parse_adrlist(e->reply_to, p);
836 case MIME_MESSAGE_ID:
838 const char *beg, *end;
840 /* We add a new "Message-ID:" when building a message */
841 p_delete(&e->message_id);
843 if ((beg = strchr(p, '<')) && (end = strchr(beg, '>')))
844 e->message_id = p_dupstr(beg, (end - beg) + 1);
848 case MIME_MIME_VERSION:
854 case MIME_NEWSGROUPS:
855 p_delete(&e->newsgroups);
857 e->newsgroups = m_strdup(skipspaces(p));
861 case MIME_ORGANIZATION:
862 if (!e->organization && mime_which_token(p, -1) == MIME_UNKNOWN)
863 e->organization = m_strdup(p);
867 if (hdr && !hdr->received) {
868 char *d = strchr(p, ';');
870 hdr->received = mutt_parse_date(d + 1, NULL);
874 case MIME_REFERENCES:
875 string_list_wipe(&e->references);
876 e->references = mutt_parse_references(p, 0);
880 e->reply_to = rfc822_parse_adrlist(e->reply_to, p);
883 case MIME_RETURN_PATH:
884 e->return_path = rfc822_parse_adrlist(e->return_path, p);
888 e->sender = rfc822_parse_adrlist (e->sender, p);
912 e->subject = m_strdup(p);
915 case MIME_SUPERCEDES:
916 case MIME_SUPERSEDES:
918 e->supersedes = m_strdup(p);
922 e->to = rfc822_parse_adrlist(e->to, p);
926 case MIME_X_COMMENT_TO:
927 if (!e->x_comment_to)
928 e->x_comment_to = m_strdup(p);
933 e->x_label = m_strdup(p);
939 e->xref = m_strdup(p);
968 /* restore the original line */
969 line[m_strlen(line)] = ':';
971 if (weed && option(OPTWEED) && mutt_matches_ignore(line, Ignore)
972 && !mutt_matches_ignore(line, UnIgnore)) {
976 *user_hdrs = string_item_new();
977 (*user_hdrs)->data = m_strdup(line);
979 rfc2047_decode(&(*user_hdrs)->data);
980 return &(*user_hdrs)->next;
986 /* mutt_read_rfc822_header() -- parses a RFC822 header
990 * f stream to read from
992 * hdr header structure of current message (optional).
994 * user_hdrs If set, store user headers. Used for recall-message and
997 * weed If this parameter is set and the user has activated the
998 * $weed option, honor the header weed list for user headers.
999 * Used for recall-message.
1001 * Returns: newly allocated envelope structure. You should free it by
1002 * envelope_delete() when envelope stay unneeded.
1005 mutt_read_rfc822_header(FILE *f, HEADER *hdr, short user_hdrs, short weed)
1007 ENVELOPE *e = envelope_new();
1008 string_list_t **last = user_hdrs ? &e->userhdrs : NULL;
1010 char *line = p_new(char, LONG_STRING);
1011 ssize_t linelen = LONG_STRING;
1014 if (hdr && !hdr->content) {
1015 hdr->content = body_new();
1017 /* set the defaults from RFC1521 */
1018 hdr->content->type = TYPETEXT;
1019 hdr->content->subtype = m_strdup("plain");
1020 hdr->content->encoding = ENC7BIT;
1021 hdr->content->length = -1;
1023 /* RFC 2183 says this is arbitrary */
1024 hdr->content->disposition = DISPINLINE;
1027 while ((loc = ftello(f)),
1028 mutt_read_rfc822_line(f, &line, &linelen))
1030 char buf[LONG_STRING + 1] = "";
1033 p = strpbrk(line, ": \t");
1034 if (!p || *p != ':') {
1035 char return_path[LONG_STRING];
1038 /* some bogus MTAs will quote the original "From " line */
1039 if (!m_strncmp(">From ", line, 6))
1040 continue; /* just ignore */
1042 if (is_from(line, return_path, sizeof(return_path), &t)) {
1043 /* MH somtimes has the From_ line in the middle of the header! */
1044 if (hdr && !hdr->received)
1045 hdr->received = t - mutt_local_tz(t);
1050 break; /* end of header */
1053 if (mutt_match_spam_list(line, SpamList, buf, sizeof(buf))) {
1054 if (!rx_list_match(NoSpamList, line)) {
1055 /* if spam tag already exists, figure out how to amend it */
1056 if (e->spam && *buf) {
1058 /* If SpamSep defined, append with separator */
1059 mutt_buffer_addstr(e->spam, SpamSep);
1060 mutt_buffer_addstr(e->spam, buf);
1062 /* else overwrite */
1063 mutt_buffer_reset(e->spam);
1064 mutt_buffer_addstr(e->spam, buf);
1067 else if (!e->spam && *buf) {
1068 /* spam tag is new, and match expr is non-empty; copy */
1069 e->spam = mutt_buffer_from(NULL, buf);
1071 else if (!e->spam) {
1072 /* match expr is empty; plug in null string if no existing tag */
1073 e->spam = mutt_buffer_from(NULL, "");
1081 continue; /* skip empty header fields */
1083 last = mutt_parse_rfc822_line(e, hdr, line, p, weed, 1, last);
1089 hdr->content->hdr_offset = hdr->offset;
1090 hdr->content->offset = ftello(f);
1091 rfc2047_decode_envelope(e);
1092 /* check for missing or invalid date */
1093 if (hdr->date_sent <= 0) {
1094 hdr->date_sent = hdr->received;
1101 /* Compares mime types to the ok and except lists */
1102 static int count_body_parts_check(string_list_t **checklist, BODY *b)
1104 string_list_t *type;
1106 for (type = *checklist; type; type = type->next) {
1107 ATTACH_MATCH *a = (ATTACH_MATCH *)type->data;
1109 if ((a->major_int == TYPEANY || a->major_int == b->type)
1110 && !regexec(&a->minor_rx, b->subtype, 0, NULL, 0)) {
1118 static int count_body_parts (BODY *body, int flags)
1126 for (bp = body; bp != NULL; bp = bp->next) {
1127 /* Initial disposition is to count and not to recurse this part. */
1128 int shallcount, shallrecurse, iscontainer;
1129 int tok = mime_which_token(bp->subtype, -1);
1131 iscontainer = bp->type == TYPEMESSAGE || bp->type == TYPEMULTIPART;
1133 /* don't recurse in external bodies or multipart/alternatives */
1134 shallrecurse = (bp->type == TYPEMESSAGE && tok != MIME_EXTERNAL_BODY)
1135 || (bp->type == TYPEMULTIPART && tok != MIME_ALTERNATIVE);
1137 /* Don't count top level containers and fundamental inlines */
1138 shallcount = !(iscontainer && (flags & M_PARTS_TOPLEVEL))
1139 && !(!iscontainer && bp->disposition == DISPINLINE && bp == body);
1142 /* Turn off shallcount if message type is not in ok list,
1143 * or if it is in except list. Check is done separately for
1144 * inlines vs. attachments.
1147 if (bp->disposition == DISPATTACH) {
1148 if (!count_body_parts_check(&AttachAllow, bp))
1150 if (count_body_parts_check(&AttachExclude, bp))
1153 if (!count_body_parts_check(&InlineAllow, bp))
1155 if (count_body_parts_check(&InlineExclude, bp))
1160 bp->attach_qualifies = shallcount;
1161 count += shallcount;
1164 bp->attach_count = count_body_parts(bp->parts,
1165 flags & ~M_PARTS_TOPLEVEL);
1166 count += bp->attach_count;
1173 int mutt_count_body_parts(HEADER *hdr, int flags)
1175 if (!option(OPTCOUNTATTACH))
1178 if (hdr->attach_valid && !(flags & M_PARTS_RECOUNT))
1179 return hdr->attach_total;
1181 if (AttachAllow || AttachExclude || InlineAllow || InlineExclude)
1182 hdr->attach_total = count_body_parts(hdr->content,
1183 flags | M_PARTS_TOPLEVEL);
1185 hdr->attach_total = 0;
1187 hdr->attach_valid = 1;
1188 return hdr->attach_total;