#include "rfc2231.h"
#include "url.h"
-/**
- * mutt_matches_ignore - Does the string match the ignore list
- * @param s String to check
- * @retval true If string matches
- *
- * Checks Ignore and UnIgnore using mutt_list_match
- */
-bool mutt_matches_ignore(const char *s)
-{
- return mutt_list_match(s, &Ignore) && !mutt_list_match(s, &UnIgnore);
-}
-
-/**
- * mutt_check_mime_type - Check a MIME type string
- * @param s String to check
- * @retval num MIME type, e.g. #TYPE_TEXT
- */
-int mutt_check_mime_type(const char *s)
-{
- if (mutt_str_strcasecmp("text", s) == 0)
- return TYPE_TEXT;
- else if (mutt_str_strcasecmp("multipart", s) == 0)
- return TYPE_MULTIPART;
-#ifdef SUN_ATTACHMENT
- else if (mutt_str_strcasecmp("x-sun-attachment", s) == 0)
- return TYPE_MULTIPART;
-#endif
- else if (mutt_str_strcasecmp("application", s) == 0)
- return TYPE_APPLICATION;
- else if (mutt_str_strcasecmp("message", s) == 0)
- return TYPE_MESSAGE;
- else if (mutt_str_strcasecmp("image", s) == 0)
- return TYPE_IMAGE;
- else if (mutt_str_strcasecmp("audio", s) == 0)
- return TYPE_AUDIO;
- else if (mutt_str_strcasecmp("video", s) == 0)
- return TYPE_VIDEO;
- else if (mutt_str_strcasecmp("model", s) == 0)
- return TYPE_MODEL;
- else if (mutt_str_strcasecmp("*", s) == 0)
- return TYPE_ANY;
- else if (mutt_str_strcasecmp(".*", s) == 0)
- return TYPE_ANY;
- else
- return TYPE_OTHER;
-}
-
-/**
- * mutt_extract_message_id - Find a message-id
- * @param s String to parse
- * @param saveptr Save result here
- * @retval ptr First character after message-id
- * @retval NULL No more message ids
- *
- * Extract the first substring that looks like a message-id.
- * Call back with NULL for more (like strtok).
- */
-char *mutt_extract_message_id(const char *s, const char **saveptr)
-{
- const char *o = NULL, *onull = NULL, *p = NULL;
- char *ret = NULL;
-
- if (s)
- p = s;
- else if (saveptr)
- p = *saveptr;
- else
- return NULL;
-
- for (s = NULL, o = NULL, onull = NULL; (p = strpbrk(p, "<> \t;")) != NULL; ++p)
- {
- if (*p == '<')
- {
- s = p;
- o = onull = NULL;
- continue;
- }
-
- if (!s)
- continue;
-
- if (*p == '>')
- {
- size_t olen = onull - o, slen = p - s + 1;
- ret = mutt_mem_malloc(olen + slen + 1);
- if (o)
- memcpy(ret, o, olen);
- memcpy(ret + olen, s, slen);
- ret[olen + slen] = '\0';
- if (saveptr)
- *saveptr = p + 1; /* next call starts after '>' */
- return ret;
- }
-
- /* some idiotic clients break their message-ids between lines */
- if (s == p)
- {
- /* step past another whitespace */
- s = p + 1;
- }
- else if (o)
- {
- /* more than two lines, give up */
- s = o = onull = NULL;
- }
- else
- {
- /* remember the first line, start looking for the second */
- o = s;
- onull = p;
- s = p + 1;
- }
- }
-
- return NULL;
-}
-
-/**
- * mutt_check_encoding - Check the encoding type
- * @param c String to check
- * @retval num Encoding type, e.g. #ENC_QUOTED_PRINTABLE
- */
-int mutt_check_encoding(const char *c)
-{
- if (mutt_str_strncasecmp("7bit", c, sizeof("7bit") - 1) == 0)
- return ENC_7BIT;
- else if (mutt_str_strncasecmp("8bit", c, sizeof("8bit") - 1) == 0)
- return ENC_8BIT;
- else if (mutt_str_strncasecmp("binary", c, sizeof("binary") - 1) == 0)
- return ENC_BINARY;
- else if (mutt_str_strncasecmp("quoted-printable", c, sizeof("quoted-printable") - 1) == 0)
- {
- return ENC_QUOTED_PRINTABLE;
- }
- else if (mutt_str_strncasecmp("base64", c, sizeof("base64") - 1) == 0)
- return ENC_BASE64;
- else if (mutt_str_strncasecmp("x-uuencode", c, sizeof("x-uuencode") - 1) == 0)
- return ENC_UUENCODED;
-#ifdef SUN_ATTACHMENT
- else if (mutt_str_strncasecmp("uuencode", c, sizeof("uuencode") - 1) == 0)
- return ENC_UUENCODED;
-#endif
- else
- return ENC_OTHER;
-}
-
/**
* parse_parameters - Parse a list of Parameters
* @param param Parameter list for the results
{
bool state_ascii = true;
s++;
- for (i = 0; *s && i < sizeof(buffer) - 1; i++, s++)
+ for (i = 0; *s && (i < (sizeof(buffer) - 1)); i++, s++)
{
if (AssumedCharset && *AssumedCharset)
{
/* As iso-2022-* has a character of '"' with non-ascii state,
* ignore it. */
- if (*s == 0x1b && i < sizeof(buffer) - 2)
+ if ((*s == 0x1b) && (i < (sizeof(buffer) - 2)))
{
- if (s[1] == '(' && (s[2] == 'B' || s[2] == 'J'))
+ if ((s[1] == '(') && ((s[2] == 'B') || (s[2] == 'J')))
state_ascii = true;
else
state_ascii = false;
}
}
- if (state_ascii && *s == '"')
+ if (state_ascii && (*s == '"'))
break;
if (*s == '\\')
{
}
else
{
- for (i = 0; *s && *s != ' ' && *s != ';' && i < sizeof(buffer) - 1; i++, s++)
+ for (i = 0; *s && (*s != ' ') && (*s != ';') && (i < (sizeof(buffer) - 1)); i++, s++)
buffer[i] = *s;
buffer[i] = 0;
}
}
/* Find the next parameter */
- if (*s != ';' && (s = strchr(s, ';')) == NULL)
+ if ((*s != ';') && (s = strchr(s, ';')) == NULL)
break; /* no more parameters */
do
}
/**
- * mutt_parse_content_language - Read the content's language
+ * parse_content_language - Read the content's language
* @param s Language string
* @param ct Body of the email
*/
-static void mutt_parse_content_language(char *s, struct Body *ct)
+static void parse_content_language(char *s, struct Body *ct)
{
if (!s || !ct)
return;
ct->language = mutt_str_strdup(s);
}
+/**
+ * mutt_matches_ignore - Does the string match the ignore list
+ * @param s String to check
+ * @retval true If string matches
+ *
+ * Checks Ignore and UnIgnore using mutt_list_match
+ */
+bool mutt_matches_ignore(const char *s)
+{
+ return mutt_list_match(s, &Ignore) && !mutt_list_match(s, &UnIgnore);
+}
+
+/**
+ * mutt_check_mime_type - Check a MIME type string
+ * @param s String to check
+ * @retval num MIME type, e.g. #TYPE_TEXT
+ */
+int mutt_check_mime_type(const char *s)
+{
+ if (mutt_str_strcasecmp("text", s) == 0)
+ return TYPE_TEXT;
+ else if (mutt_str_strcasecmp("multipart", s) == 0)
+ return TYPE_MULTIPART;
+#ifdef SUN_ATTACHMENT
+ else if (mutt_str_strcasecmp("x-sun-attachment", s) == 0)
+ return TYPE_MULTIPART;
+#endif
+ else if (mutt_str_strcasecmp("application", s) == 0)
+ return TYPE_APPLICATION;
+ else if (mutt_str_strcasecmp("message", s) == 0)
+ return TYPE_MESSAGE;
+ else if (mutt_str_strcasecmp("image", s) == 0)
+ return TYPE_IMAGE;
+ else if (mutt_str_strcasecmp("audio", s) == 0)
+ return TYPE_AUDIO;
+ else if (mutt_str_strcasecmp("video", s) == 0)
+ return TYPE_VIDEO;
+ else if (mutt_str_strcasecmp("model", s) == 0)
+ return TYPE_MODEL;
+ else if (mutt_str_strcasecmp("*", s) == 0)
+ return TYPE_ANY;
+ else if (mutt_str_strcasecmp(".*", s) == 0)
+ return TYPE_ANY;
+ else
+ return TYPE_OTHER;
+}
+
+/**
+ * mutt_extract_message_id - Find a message-id
+ * @param s String to parse
+ * @param saveptr Save result here
+ * @retval ptr First character after message-id
+ * @retval NULL No more message ids
+ *
+ * Extract the first substring that looks like a message-id.
+ * Call back with NULL for more (like strtok).
+ */
+char *mutt_extract_message_id(const char *s, const char **saveptr)
+{
+ const char *o = NULL, *onull = NULL, *p = NULL;
+ char *ret = NULL;
+
+ if (s)
+ p = s;
+ else if (saveptr)
+ p = *saveptr;
+ else
+ return NULL;
+
+ for (s = NULL, o = NULL, onull = NULL; (p = strpbrk(p, "<> \t;")) != NULL; ++p)
+ {
+ if (*p == '<')
+ {
+ s = p;
+ o = onull = NULL;
+ continue;
+ }
+
+ if (!s)
+ continue;
+
+ if (*p == '>')
+ {
+ size_t olen = onull - o;
+ size_t slen = p - s + 1;
+ ret = mutt_mem_malloc(olen + slen + 1);
+ if (o)
+ memcpy(ret, o, olen);
+ memcpy(ret + olen, s, slen);
+ ret[olen + slen] = '\0';
+ if (saveptr)
+ *saveptr = p + 1; /* next call starts after '>' */
+ return ret;
+ }
+
+ /* some idiotic clients break their message-ids between lines */
+ if (s == p)
+ {
+ /* step past another whitespace */
+ s = p + 1;
+ }
+ else if (o)
+ {
+ /* more than two lines, give up */
+ s = o = onull = NULL;
+ }
+ else
+ {
+ /* remember the first line, start looking for the second */
+ o = s;
+ onull = p;
+ s = p + 1;
+ }
+ }
+
+ return NULL;
+}
+
+/**
+ * mutt_check_encoding - Check the encoding type
+ * @param c String to check
+ * @retval num Encoding type, e.g. #ENC_QUOTED_PRINTABLE
+ */
+int mutt_check_encoding(const char *c)
+{
+ if (mutt_str_strncasecmp("7bit", c, sizeof("7bit") - 1) == 0)
+ return ENC_7BIT;
+ else if (mutt_str_strncasecmp("8bit", c, sizeof("8bit") - 1) == 0)
+ return ENC_8BIT;
+ else if (mutt_str_strncasecmp("binary", c, sizeof("binary") - 1) == 0)
+ return ENC_BINARY;
+ else if (mutt_str_strncasecmp("quoted-printable", c, sizeof("quoted-printable") - 1) == 0)
+ return ENC_QUOTED_PRINTABLE;
+ else if (mutt_str_strncasecmp("base64", c, sizeof("base64") - 1) == 0)
+ return ENC_BASE64;
+ else if (mutt_str_strncasecmp("x-uuencode", c, sizeof("x-uuencode") - 1) == 0)
+ return ENC_UUENCODED;
+#ifdef SUN_ATTACHMENT
+ else if (mutt_str_strncasecmp("uuencode", c, sizeof("uuencode") - 1) == 0)
+ return ENC_UUENCODED;
+#endif
+ else
+ return ENC_OTHER;
+}
+
/**
* mutt_parse_content_type - Parse a content type
* @param s String to parse
if (subtype)
{
*subtype++ = '\0';
- for (pc = subtype; *pc && !ISSPACE(*pc) && *pc != ';'; pc++)
+ for (pc = subtype; *pc && !ISSPACE(*pc) && (*pc != ';'); pc++)
;
*pc = '\0';
ct->subtype = mutt_str_strdup(subtype);
else if (mutt_str_strcasecmp(line + 8, "language") == 0)
{
if (hdr)
- mutt_parse_content_language(p, hdr->content);
+ parse_content_language(p, hdr->content);
matched = 1;
}
else if (mutt_str_strcasecmp(line + 8, "transfer-encoding") == 0)
/* HACK - neomutt has, for a very short time, produced negative
* Lines header values. Ignore them.
*/
- if (mutt_str_atoi(p, &hdr->lines) < 0 || hdr->lines < 0)
+ if (mutt_str_atoi(p, &hdr->lines) < 0 || (hdr->lines < 0))
hdr->lines = 0;
}
while (true)
{
- if (fgets(buf, *linelen - offset, f) == NULL || /* end of file or */
- (ISSPACE(*line) && !offset)) /* end of headers */
+ if (!fgets(buf, *linelen - offset, f) || /* end of file or */
+ (ISSPACE(*line) && !offset)) /* end of headers */
{
*line = 0;
return line;
}
/* eat tabs and spaces from the beginning of the continuation line */
- while ((ch = fgetc(f)) == ' ' || ch == '\t')
+ while (((ch = fgetc(f)) == ' ') || (ch == '\t'))
;
ungetc(ch, f);
*++buf = ' '; /* string is still terminated because we removed
buf++;
offset = buf - line;
- if (*linelen < offset + STRING)
+ if (*linelen < (offset + STRING))
{
/* grow the buffer */
*linelen += STRING;
if (mutt_str_strcasecmp("type", line + 8) == 0)
mutt_parse_content_type(c, p);
else if (mutt_str_strcasecmp("language", line + 8) == 0)
- mutt_parse_content_language(c, p);
+ parse_content_language(c, p);
else if (mutt_str_strcasecmp("transfer-encoding", line + 8) == 0)
p->encoding = mutt_check_encoding(c);
else if (mutt_str_strcasecmp("disposition", line + 8) == 0)
}
const size_t blen = mutt_str_strlen(boundary);
- while (ftello(fp) < end_off && fgets(buffer, LONG_STRING, fp) != NULL)
+ while ((ftello(fp) < end_off) && fgets(buffer, LONG_STRING, fp))
{
const size_t len = mutt_str_strlen(buffer);
- const size_t crlf = (len > 1 && buffer[len - 2] == '\r') ? 1 : 0;
+ const size_t crlf = ((len > 1) && (buffer[len - 2] == '\r')) ? 1 : 0;
- if (buffer[0] == '-' && buffer[1] == '-' &&
+ if ((buffer[0] == '-') && (buffer[1] == '-') &&
(mutt_str_strncmp(buffer + 2, boundary, blen) == 0))
{
if (last)
if (len > 0)
{
/* Remove any trailing whitespace, up to the length of the boundary */
- for (size_t i = len - 1; ISSPACE(buffer[i]) && i >= blen + 2; i--)
+ for (size_t i = len - 1; ISSPACE(buffer[i]) && (i >= (blen + 2)); i--)
buffer[i] = 0;
}
if (mutt_str_atoi(mutt_param_get(&new->parameter, "content-lines"), &lines) < 0)
lines = 0;
for (; lines; lines--)
- if (ftello(fp) >= end_off || fgets(buffer, LONG_STRING, fp) == NULL)
+ if ((ftello(fp) >= end_off) || !fgets(buffer, LONG_STRING, fp))
break;
}
#endif
}
/* in case of missing end boundary, set the length to something reasonable */
- if (last && last->length == 0 && !final)
+ if (last && (last->length == 0) && !final)
last->length = end_off - last->offset;
/* parse recursive MIME parts */