Subject: | COMPRESS Extension (RFC4978) |
I think it is nice to have compression (RFC2978) support. I have written
some PoC code, but there are some problem with error handling.
May you include this in the example/ , or advice the proper way to get it
in the main module?
Subject: | proof-of-concept.txt |
use Compress::Zlib;
sub upgradeCompress {
my $imap = shift;
if ($imap->_imap_command("COMPRESS DEFLATE")) {
my ($d, $status) = deflateInit(-WindowBits => -8);
$imap->{Deflate} = $d;
$imap->{Prewritemethod} = sub {
my ($imap, $string) = @_;
my ($out, $status) = $imap->{Deflate}->deflate($string);
my ($out2, $status2) = $imap->{Deflate}->flush(Compress::Raw::Zlib::Z_SYNC_FLUSH());
return $out . $out2;
};
my ($inbuf, $outbuf);
my ($i, $status2) = inflateInit(-WindowBits => -Compress::Raw::Zlib::MAX_WBITS());
$imap->{Inflate} = $i;
$imap->{Readmethod} = sub {
my ( $imap, $fh, $buf, $len, $off ) = @_;
my $ret = sysread($fh, $inbuf, 32768, length $inbuf);
return undef if (!defined $ret);
my ($out, $status) = $imap->{Inflate}->inflate(\$inbuf);
$outbuf .= $out;
$out = substr($outbuf, 0, $len);
substr($outbuf, 0, $len) = "";
substr($$buf, $off) = $out;
return 1; # BUG: why not return "length $out;" ? how to handle EOF?
}
}
}