Skip Menu |

This queue is for tickets about the Mail-IMAPClient CPAN distribution.

Report information
The Basics
Id: 67263
Status: resolved
Priority: 0/
Queue: Mail-IMAPClient

People
Owner: PLOBBES [...] cpan.org
Requestors: SDIZ [...] cpan.org
Cc:
AdminCc:

Bug Information
Severity: Wishlist
Broken in:
  • 2.2.9
  • 3.00
Fixed in: 3.30



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? } } }
I have changed the error handling a bit, and it works better. But still, it have problem on long session which I have no idea how to debug.
Subject: proof-of-concept2.txt
use Compress::Zlib; sub upgradeCompress { my $imap = shift; if ($imap->_imap_command("COMPRESS DEFLATE")) { my ($d, $status) = deflateInit(-WindowBits => -8, -Level => Compress::Raw::Zlib::Z_BEST_SPEED()); $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_PARTIAL_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, 4*1024*1024, length $inbuf); return undef if (!defined $ret); return $ret if (!$ret && length $outbuf == 0); my ($out, $status) = $imap->{Inflate}->inflate(\$inbuf); $outbuf .= $out; $out = substr($outbuf, 0, $len); substr($outbuf, 0, $len) = ""; substr($$buf, $off) = $out; if (length $out == 0) { return "0 but true" ; } else { return length $out; } } } }
The _read_more() logic seems to prevent it from working well.
On Wed Apr 06 00:50:36 2011, SDIZ wrote: Show quoted text
> The _read_more() logic seems to prevent it from working well.
I am not sure I'll get a chance to look at this soon, but I'm certainly willing to consider adding this to the module. We will have to iron out the issues you are running into so please feel free to add more details if/when you get a chance to dig deeper into the problems.
I have patched the source with a similar implementation to what you provided. This will be included in the next version release (v3.30). Thank you for your contribution! You're welcome to pull the latest code from git if you're interested in seeing what I have checked in: http://sourceforge.net/p/mail-imapclient/git/ Otherwise, hopefully I'll have a full release out soon-ish.
Mail::IMAPClient 3.30 was released today with this enhancement, if you find any problems please open a bug on your findings. Thanks for suggesting this enhancement and providing the patch!