package POE::Filter::IMAP; use strict; use warnings; our $VERSION = '0.01'; use Encode::IMAPUTF7; use base qw(POE::Filter::Line); sub new { my $class = shift; my $self = $class->SUPER::new(Literal => "\x0D\x0A"); return $self; } sub get_one { my $self = shift; my $lines = $self->SUPER::get_one(@_); foreach my $line (@$lines) { my ($seq, $cmd, $data) = split(/\s+/, $line, 3); my @args; if ($data) { $data =~ s/\s+$//; Encode::IMAPUTF7::decode('IMAP-UTF-7',$data); # my @args = map { $_ =~ s/^"(.+)"$/$1/; $_ } split(/\s+/, $data); @args = split(/\s+/, $data); } $line = { seq => $seq, cmd => lc($cmd), args => \@args }; } return $lines; } sub put { my ($self, $lines) = @_; $lines = [ map { ref $_ eq 'ARRAY' ? @$_ : $_ } @$lines ]; foreach my $line (@$lines) { my @tmp; if ($line->{seq}) { push(@tmp,$line->{seq}); } else { push(@tmp,'*'); } if ($line->{cmd}) { push(@tmp,$line->{cmd}); } if ($line->{args}) { # odd...This works without encoding... # Encode::IMAPUTF7::encode('IMAP-UTF-7',$_) push(@tmp, map { $_ } @{$line->{args}} ); } $line = join(' ',@tmp); print STDERR "put [$line]\n"; } $self->SUPER::put($lines); } 1; __END__ =head1 NAME POE::Filter::IMAP - POE Filter for IMAP =head1 SYNOPSIS use POE qw(Filter::IMAP); my $filter = POE::Filter::IMAP->new(); =head1 DESCRIPTION =head1 SEE ALSO =head1 AUTHOR David Davis, Exantus@cpan.orgE =head1 COPYRIGHT AND LICENSE Copyright (c) 2004-2007 by David Davis This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut