Skip to content

Commit

Permalink
Truncate large UIDVALIDITYs to support non-conforming IMAP servers
Browse files Browse the repository at this point in the history
Fixes #3830
  • Loading branch information
gahr committed Jun 14, 2023
1 parent 2b5e793 commit a8b8221
Showing 1 changed file with 26 additions and 14 deletions.
40 changes: 26 additions & 14 deletions imap/command.c
Original file line number Diff line number Diff line change
Expand Up @@ -864,23 +864,35 @@ static void cmd_parse_status(struct ImapAccountData *adata, char *s)

errno = 0;
const unsigned long ulcount = strtoul(value, &value, 10);
if (((errno == ERANGE) && (ulcount == ULONG_MAX)) || ((unsigned int) ulcount != ulcount))
{
mutt_debug(LL_DEBUG1, "Error parsing STATUS number\n");
return;
}
const bool truncated = ((errno == ERANGE) && (ulcount == ULONG_MAX)) || ((unsigned int) ulcount != ulcount);
const unsigned int count = (unsigned int) ulcount;

if (mutt_str_startswith(s, "MESSAGES"))
mdata->messages = count;
else if (mutt_str_startswith(s, "RECENT"))
mdata->recent = count;
else if (mutt_str_startswith(s, "UIDNEXT"))
mdata->uid_next = count;
else if (mutt_str_startswith(s, "UIDVALIDITY"))
// we accept to truncate a larger value only for UIDVALIDITY, to accomodate
// for IMAP servers that use 64-bits for it. This seems to be what also
// Thunderbird is doing, see #3830
if (mutt_str_startswith(s, "UIDVALIDITY"))
{
mdata->uidvalidity = count;
else if (mutt_str_startswith(s, "UNSEEN"))
mdata->unseen = count;
}
else
{
if (truncated)
{
mutt_debug(LL_DEBUG1, "Error parsing STATUS number\n");
return;
}
else
{
if (mutt_str_startswith(s, "MESSAGES"))
mdata->messages = count;
else if (mutt_str_startswith(s, "RECENT"))
mdata->recent = count;
else if (mutt_str_startswith(s, "UIDNEXT"))
mdata->uid_next = count;
else if (mutt_str_startswith(s, "UNSEEN"))
mdata->unseen = count;
}
}

s = value;
if ((s[0] != '\0') && (*s != ')'))
Expand Down

0 comments on commit a8b8221

Please sign in to comment.