From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=0.2 required=5.0 tests=DKIM_INVALID,DKIM_SIGNED, FREEMAIL_FROM autolearn=no autolearn_force=no version=3.4.4 Received: (qmail 20213 invoked from network); 9 Oct 2021 10:55:22 -0000 Received: from 4ess.inri.net (216.126.196.42) by inbox.vuxu.org with ESMTPUTF8; 9 Oct 2021 10:55:22 -0000 Received: from mout.gmx.net ([212.227.17.21]) by 4ess; Sat Oct 9 06:49:05 -0400 2021 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=gmx.net; s=badeba3b8450; t=1633776537; bh=515iycSwQyb+SRlykR6kqJbntgksWoO/bMRq3Dwwrow=; h=X-UI-Sender-Class:Date:From:To:Subject; b=TTVOjPCpB4cZxb42v37vdopzjxBF7ULrCDEAJB7x777njXFYvUUxlIzkXTWFHIbZq vKf+CjBtLmT1uAsiu0J47DMSusQME3BEM9iUFaKO0fsKb9B8eLL/F0hXhPuGyTbVS0 A28Oq2JVbBZMr9UFr+em37IQArvKnMG6TAqZ0tbM= X-UI-Sender-Class: 01bb95c1-4bf8-414a-932a-4f6e2808ef9c Received: from purple.silakkatroolari-gw ([82.128.133.160]) by mail.gmx.net (mrgmx104 [212.227.17.174]) with ESMTPSA (Nemesis) id 1Mt79F-1msl252DZh-00tQ64; Sat, 09 Oct 2021 12:36:20 +0200 Message-ID: <405ABA392F41295D7D6361D94B2A8E08@gmx.com> Date: Sat, 09 Oct 2021 12:36:02 +0200 From: risto.salminen@gmx.com To: 9front@9front.org MIME-Version: 1.0 Content-Type: text/plain; charset="US-ASCII" Content-Transfer-Encoding: quoted-printable X-Provags-ID: V03:K1:wFNNOe0ba6ZZSAQv2wGJGCL0ja/KlC66zjYsh3YR8QLlwoud7gg cRt2CNwjezywhvDqyQ224JRUd4QDt++zNmD6GbHTMv2ZoaQTInDB23ViMhQtW+NFlT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oabVnwEksOFUJXVxeaPAPv8IeungfxWgd5d6X9ItCL99c7 VKHT2THAEsn9Sfjvtf1FzJ/tgAQlgQrIP7lL7CFi7qAltcqs1nnYCYVEAhrYT4tn0B3+FUfPN /NrkTkV6WnBWQQ/qXpz26rQOZ7Y4h3I9zLrgQO1rnUzPUxxuyjmA4BtZjXU+y8eVyT8x7Op32 YK8HogXIZ55ydk= List-ID: <9front.9front.org> List-Help: X-Glyph: ➈ X-Bullshit: overflow-preventing basic polling API Subject: [9front] upas/fs: handle outlook's quirks Reply-To: 9front@9front.org Precedence: bulk Hello all, Outlook's IMAP server often tells incorrect message sizes. This patch makes upas/fs handle that at least much better than before. If the length of a message chunk received from the server is less than the requested chunk length, then the whole message has been received, which means that the message was smaller than expected, and upas/fs must adjust its internal notion of the message length accordingly. If this is not done, the message body as presented by upas/fs will contain trailing garbage, that is, previous memory contents. The handling of a message larger than expected works exactly in the same way as the current quirk for Gmail. When requesting the last chunk of a message, upas/fs increases the chunk length, so that hopefully the whole message will be read, and then afterwards also adjusts its internal notion of the message length accordingly. To benefit from this patch, the desired mailbox indices have to be recreated, by manually removing them, so that upas/fs will then create them automatically. Otherwise, things will continue to work as before. Would this be useful for the broader audience? Thanks, Risto diff a8ad3fb3d00551bad97e7b10a9666821fe4b601a uncommitted =2D-- a/sys/src/cmd/upas/fs/cache.c +++ b/sys/src/cmd/upas/fs/cache.c @@ -199,7 +199,7 @@ return -1; } if(m->size - sz0) - l +=3D m->size - sz0; /* awful botch for gmail */ + l +=3D m->size - sz0; /* awful botch for gmail and outlook */ if(expand){ /* grumble. poor planning. */ if(m->badchars > 0) =2D-- a/sys/src/cmd/upas/fs/imap.c +++ b/sys/src/cmd/upas/fs/imap.c @@ -29,6 +29,7 @@ Fssl =3D 1<<0, Fdebug =3D 1<<1, Fgmail =3D 1<<2, + Foutlook=3D 1<<3, }; typedef struct { @@ -331,7 +332,7 @@ } static char* -fetchrsp(Imap *imap, char *p, Mailbox *, Message *m, int idx) +fetchrsp(Imap *imap, char *p, Mailbox *, Message *m, int idx, ulong l0) { char *f[15], *s, *q; int i, n, a; @@ -383,10 +384,12 @@ return confused; l =3D xnum(f[i + 1], '{', '}'); a =3D o + l - m->ibadchars - m->size; - if(a > 0){ - assert(imap->flags & Fgmail); + if(l < l0 || a > 0){ + /* message smaller or larger than expected */ + assert((imap->flags & Fgmail) || (imap->flags & Foutlook)); m->size =3D o + l; msgrealloc(m, m->size); + assert(m->ibadchars < m->size); m->size -=3D m->ibadchars; } if(Bread(&imap->bin, m->start + o, l) !=3D l){ @@ -441,7 +444,7 @@ * data or other informational lines mixed in. */ static char* -imap4resp0(Imap *imap, Mailbox *mb, Message *m) +imap4resp0(Imap *imap, Mailbox *mb, Message *m, ulong l) { char *e, *line, *p, *ep, *op, *q, *verb; int n, idx, unexp; @@ -508,7 +511,7 @@ if(ep[-1] =3D=3D ')') *--ep =3D 0; } - if(e =3D fetchrsp(imap, p, mb, m, n - 1)) + if(e =3D fetchrsp(imap, p, mb, m, n - 1, l)) eprint("imap: fetchrsp: %s\n", e); if(n > 0 && n <=3D imap->muid && n > imap->nuid) imap->nuid =3D n; @@ -553,7 +556,7 @@ static char* imap4resp(Imap *i) { - return imap4resp0(i, 0, 0); + return imap4resp0(i, 0, 0, 0); } static int @@ -590,7 +593,7 @@ if(p > buf){ p[-1] =3D 0; imap4cmd(imap, "uid store %lud flags (%s)", (ulong)m->imapuid, buf); - imap4resp0(imap, mb, m); + imap4resp0(imap, mb, m, 0); } } @@ -861,6 +864,16 @@ return l; } +/* outlook also lies about message sizes */ +static ulong +outlookdiscount(Message *m, uvlong o, ulong l) +{ + if((m->cstate&Cidx) =3D=3D 0) + if(o + l =3D=3D m->size) + return l + 100 + (o + l)/3; + return l; +} + static int imap4fetch(Mailbox *mb, Message *m, uvlong o, ulong l) { @@ -870,9 +883,11 @@ imap =3D mb->aux; if(imap->flags & Fgmail) l =3D gmaildiscount(m, o, l); + if(imap->flags & Foutlook) + l =3D outlookdiscount(m, o, l); idprint(imap, "uid fetch %lud (flags body.peek[]<%llud.%lud>)\n", (ulong= )m->imapuid, o, l); imap4cmd(imap, "uid fetch %lud (flags body.peek[]<%llud.%lud>)", (ulong)= m->imapuid, o, l); - resp =3D imap4resp0(imap, mb, m); + resp =3D imap4resp0(imap, mb, m, (m->cstate&Cidx) ? 0 : l); if(!isokay(resp)){ eprint("imap: imap fetch failed: %s\n", resp); return -1; @@ -1165,6 +1180,8 @@ imap->host =3D f[2]; if(strstr(imap->host, "gmail.com")) imap->flags |=3D Fgmail; + if(strstr(imap->host, "outlook.office365.com")) + imap->flags |=3D Foutlook; imap->refreshtime =3D 60; if(nf < 4) imap->user =3D nil;