diff options
author | Eric Wong <e@80x24.org> | 2021-01-18 04:30:32 -0600 |
---|---|---|
committer | Eric Wong <e@80x24.org> | 2021-01-18 21:20:32 +0000 |
commit | 935f837e759f03ed48d369ab97517b8b03662ba3 (patch) | |
tree | 861a7c99e9d436c551ccd2bebb5ceee2e3b9c5c8 /lib/PublicInbox | |
parent | 51191d611e918ff3ef6e9ce8ee52ba7b2cd2144c (diff) | |
download | public-inbox-935f837e759f03ed48d369ab97517b8b03662ba3.tar.gz |
Instead of optimizing our own performance, this optimizes our data to reduce work done by the MUA consumer. Maildir and mbox destinations no longer support any notion of the IMAP \Recent flag. JMAP has no functioning \Recent equivalent, and neither do we. In practice, having MUAs (e.g. mutt) clear the \Recent flag when committing changes to the mbox is expensive: it creates a rename(2) storm with Maildir and overwrites the entire mbox. For mboxcl2 (and mboxcl), we'll further optimize mutt behavior by setting the Lines: header in addition to Content-Length. With these changes, mutt exits instantaneously on mboxcl2, mboxcl, and Maildirs generated by "lei q".
Diffstat (limited to 'lib/PublicInbox')
-rw-r--r-- | lib/PublicInbox/LeiToMail.pm | 30 |
1 files changed, 22 insertions, 8 deletions
diff --git a/lib/PublicInbox/LeiToMail.pm b/lib/PublicInbox/LeiToMail.pm index 8d030227..dcf6d8a3 100644 --- a/lib/PublicInbox/LeiToMail.pm +++ b/lib/PublicInbox/LeiToMail.pm @@ -34,7 +34,11 @@ my %kw2status = ( sub _mbox_hdr_buf ($$$) { my ($eml, $type, $kw) = @_; $eml->header_set($_) for (qw(Lines Bytes Content-Length)); - my %hdr; # set Status, X-Status + + # Messages are always 'O' (non-\Recent in IMAP), it saves + # MUAs the trouble of rewriting the mbox if no other + # changes are made + my %hdr = (Status => [ 'O' ]); # set Status, X-Status for my $k (@$kw) { if (my $ent = $kw2status{$k}) { push @{$hdr{$ent->[0]}}, $ent->[1]; @@ -92,6 +96,16 @@ sub eml2mboxo { $buf; } +sub _mboxcl_common ($$$) { + my ($buf, $bdy, $crlf) = @_; + # add Lines: so mutt won't have to add it on MUA close + my $lines = $$bdy =~ tr!\n!\n!; + $$buf .= 'Content-Length: '.length($$bdy).$crlf. + 'Lines: '.$lines.$crlf.$crlf; + substr($$bdy, 0, 0, $$buf); # prepend header + $_[0] = $bdy; +} + # mboxcl still escapes "From " lines sub eml2mboxcl { my ($eml, $kw) = @_; @@ -99,9 +113,7 @@ sub eml2mboxcl { my $crlf = $eml->{crlf}; if (my $bdy = delete $eml->{bdy}) { $$bdy =~ s/^From />From /gm; - $$buf .= 'Content-Length: '.length($$bdy).$crlf.$crlf; - substr($$bdy, 0, 0, $$buf); # prepend header - $buf = $bdy; + _mboxcl_common($buf, $bdy, $crlf); } $$buf .= $crlf; $buf; @@ -113,9 +125,7 @@ sub eml2mboxcl2 { my $buf = _mbox_hdr_buf($eml, 'mboxcl2', $kw); my $crlf = $eml->{crlf}; if (my $bdy = delete $eml->{bdy}) { - $$buf .= 'Content-Length: '.length($$bdy).$crlf.$crlf; - substr($$bdy, 0, 0, $$buf); # prepend header - $buf = $bdy; + _mboxcl_common($buf, $bdy, $crlf); } $$buf .= $crlf; $buf; @@ -276,7 +286,11 @@ sub _buf2maildir { } while (!sysopen($fh, $tmp, O_CREAT|O_EXCL|O_WRONLY) && $! == EEXIST && ($rand = int(rand 0x7fffffff).',')); if (print $fh $$buf and close($fh)) { - $dst .= $sfx eq '' ? 'new/' : 'cur/'; + # ignore new/ and write only to cur/, otherwise MUAs + # with R/W access to the Maildir will end up doing + # a mass rename which can take a while with thousands + # of messages. + $dst .= 'cur/'; $rand = ''; do { $final = $dst.$rand."oid=$oid:2,$sfx"; |