* A valid message separator looks like:
* `From [ <return-path> ] <weekday> <month> <day> <time> [ <timezone> ] <year>`
*/
-int is_from(const char *s, char *path, size_t pathlen, time_t *tp)
+bool is_from(const char *s, char *path, size_t pathlen, time_t *tp)
{
struct tm tm;
int yr;
*path = '\0';
if (mutt_str_strncmp("From ", s, 5) != 0)
- return 0;
+ return false;
s = mutt_str_next_word(s); /* skip over the From part. */
if (!*s)
- return 0;
+ return false;
mutt_debug(3, "\nis_from(): parsing: %s\n", s);
if (*p == '\\')
{
if (*++p == '\0')
- return 0;
+ return false;
}
else if (*p == '"')
{
}
if (q || !*p)
- return 0;
+ return false;
/* pipermail archives have the return_path obscured such as "me at neomutt.org" */
if (mutt_str_strncasecmp(p, " at ", 4) == 0)
"error parsing what appears to be a pipermail-style "
"obscured return_path: %s\n",
s);
- return 0;
+ return false;
}
}
if (path)
{
size_t len = (size_t)(p - s);
- if (len + 1 > pathlen)
+ if ((len + 1) > pathlen)
len = pathlen - 1;
memcpy(path, s, len);
path[len] = '\0';
s = p + 1;
SKIPWS(s);
if (!*s)
- return 0;
+ return false;
if (!mutt_date_is_day_name(s))
{
mutt_debug(1, " expected weekday, got: %s\n", s);
- return 0;
+ return false;
}
}
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
/* do a quick check to make sure that this isn't really the day of the week.
* this could happen when receiving mail from a local user whose login name
{
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
}
/* now we should be on the month. */
tm.tm_mon = mutt_date_check_month(s);
if (tm.tm_mon < 0)
- return 0;
+ return false;
/* day */
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
if (sscanf(s, "%d", &tm.tm_mday) != 1)
- return 0;
+ return false;
if ((tm.tm_mday < 1) || (tm.tm_mday > 31))
- return 0;
+ return false;
/* time */
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
/* Accept either HH:MM or HH:MM:SS */
if (sscanf(s, "%d:%d:%d", &tm.tm_hour, &tm.tm_min, &tm.tm_sec) == 3)
else if (sscanf(s, "%d:%d", &tm.tm_hour, &tm.tm_min) == 2)
tm.tm_sec = 0;
else
- return 0;
+ return false;
if ((tm.tm_hour < 0) || (tm.tm_hour > 23) || (tm.tm_min < 0) ||
(tm.tm_min > 59) || (tm.tm_sec < 0) || (tm.tm_sec > 60))
{
- return 0;
+ return false;
}
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
/* timezone? */
- if (isalpha((unsigned char) *s) || *s == '+' || *s == '-')
+ if (isalpha((unsigned char) *s) || (*s == '+') || (*s == '-'))
{
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
/*
* some places have two timezone fields after the time, e.g.
{
s = mutt_str_next_word(s);
if (!*s)
- return 0;
+ return false;
}
}
/* year */
if (sscanf(s, "%d", &yr) != 1)
- return 0;
+ return false;
if ((yr < 0) || (yr > 9999))
- return 0;
- tm.tm_year = yr > 1900 ? yr - 1900 : (yr < 70 ? yr + 100 : yr);
+ return false;
+ tm.tm_year = (yr > 1900) ? (yr - 1900) : ((yr < 70) ? (yr + 100) : yr);
mutt_debug(3, "month=%d, day=%d, hr=%d, min=%d, sec=%d, yr=%d.\n", tm.tm_mon,
tm.tm_mday, tm.tm_hour, tm.tm_min, tm.tm_sec, tm.tm_year);
if (tp)
*tp = mutt_date_make_time(&tm, 0);
- return 1;
+ return true;
}