isync

mailbox synchronization program
git clone https://git.code.sf.net/p/isync/isync
Log | Files | Refs | README | LICENSE

commit 507203293931aed82a14c59ba1c07b7c4601594d
parent 0a5a84793283bae245d64fbf634f651b433afe0d
Author: Oswald Buddenhagen <ossi@users.sf.net>
Date:   Sun,  8 Apr 2018 18:10:21 +0200

fix uidvalidity recovery with really long message-id headers

re-using the file name buffer for the headers wasn't such a great idea,
as _POSIX_PATH_MAX is only 256, while RFC2822 permits lines up to 1000
chars. and sure enough, i have a message with a whopping 470-char
message-id header ...

Diffstat:
Msrc/drv_maildir.c | 21+++++++++++----------
1 file changed, 11 insertions(+), 10 deletions(-)

diff --git a/src/drv_maildir.c b/src/drv_maildir.c @@ -1153,28 +1153,29 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) goto retry; } int off, in_msgid = 0; - while ((want_tuid || want_msgid) && fgets( nbuf, sizeof(nbuf), f )) { - int bufl = strlen( nbuf ); - if (bufl && nbuf[bufl - 1] == '\n') + char lnbuf[1000]; // Says RFC2822 + while ((want_tuid || want_msgid) && fgets( lnbuf, sizeof(lnbuf), f )) { + int bufl = strlen( lnbuf ); + if (bufl && lnbuf[bufl - 1] == '\n') --bufl; - if (bufl && nbuf[bufl - 1] == '\r') + if (bufl && lnbuf[bufl - 1] == '\r') --bufl; if (!bufl) break; - if (want_tuid && starts_with( nbuf, bufl, "X-TUID: ", 8 )) { + if (want_tuid && starts_with( lnbuf, bufl, "X-TUID: ", 8 )) { if (bufl < 8 + TUIDL) { error( "Maildir error: malformed X-TUID header (UID %u)\n", uid ); continue; } - memcpy( entry->tuid, nbuf + 8, TUIDL ); + memcpy( entry->tuid, lnbuf + 8, TUIDL ); want_tuid = 0; in_msgid = 0; continue; } - if (want_msgid && starts_with_upper( nbuf, bufl, "MESSAGE-ID:", 11 )) { + if (want_msgid && starts_with_upper( lnbuf, bufl, "MESSAGE-ID:", 11 )) { off = 11; } else if (in_msgid) { - if (!isspace( nbuf[0] )) { + if (!isspace( lnbuf[0] )) { in_msgid = 0; continue; } @@ -1182,13 +1183,13 @@ maildir_scan( maildir_store_t *ctx, msg_t_array_alloc_t *msglist ) } else { continue; } - while (off < bufl && isspace( nbuf[off] )) + while (off < bufl && isspace( lnbuf[off] )) off++; if (off == bufl) { in_msgid = 1; continue; } - entry->msgid = nfstrndup( nbuf + off, bufl - off ); + entry->msgid = nfstrndup( lnbuf + off, bufl - off ); want_msgid = 0; in_msgid = 0; }