Protocol-IMAP

 view release on metacpan or  search on metacpan

lib/Protocol/IMAP/Fetch.pm  view on Meta::CPAN

sub data {
	my $self = shift;
	my $k = shift;
	return $self->{data}{$k} if exists $self->{data}{$k};
	$self->{data}{$k} = my $f = Future->new;
	$self->completion->on_done(sub {
		$f->done(Protocol::IMAP::Envelope->new(
			%{$self->{fetched}{$k}}
		));
	});
	$f
}

=head2 stream

This is what you would normally use for a message, although
at the moment you can't, so don't.

=cut

sub stream { die 'unimplemented' }

1;

__END__

=pod

=over 4

=item * L<Protocol::IMAP::Envelope> - represents the message envelope

=item * L<Protocol::IMAP::Address> - represents an email address as found in the message envelope

=back

my $msg = $imap->fetch(message => 123);
$msg->data('envelope')->on_done(sub {
	my $envelope = shift;
	say "Date: " . $envelope->date;
	say "From: " . join ',', $envelope->from;
	say "To:   " . join ',', $envelope->to;
	say "CC:   " . join ',', $envelope->cc;
	say "BCC:  " . join ',', $envelope->bcc;
});


Implementation:

The untagged FETCH response causes instantiation of this class. We pass
the fetch line as the initial buffer, set up the parser and run the first
parse attempt.

If we already have enough data to parse the FETCH response, then we relinquish
control back to the client.

If there's a {123} string literal, then we need to stream that amount of data:
we request a new sink, primed with the data we have so far, with the byte count
({123} value) as the limit, and allow it to pass us events until completion.

In streaming mode, we'll pass those to event listeners.
Otherwise, we'll store this data internally to the appropriate key.

then switch back to line mode.



( run in 0.807 second using v1.01-cache-2.11-cpan-39bf76dae61 )