Net::IMAP::SimpleX - Addons for Net::IMAP::Simple
use strict; use warnings; use Net::IMAP::SimpleX;
Net::IMAP::SimpleX uses Net::IMAP::Simple as a base so the object creation is the same as it is for the ancestor:
my $imap = Net::IMAP::SimpleX->new('imap.example.com') || die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n"; $imap->select("INBOX");
So far Net::IMAP::SimpleX only provides one extension.
# get an object representation of the message body my $summary = $imap->body_summary($message_number); # multipart message if ($summary->has_parts) { for my $subpart ($summary->parts) { if ($subpart->has_parts) { ... } # examine the message part my @attr = map { $subpart->$_ } qw/content_type encoding encoded_size/; # fetch the raw message part my $subpart_body = $imap->get($message_number, $subpart->part_number); } } else { my $body = $summary->body; my @attr = map { $body->$_ } qw/content_type encoding encoded_size/ }
This module adds some useful, yet not so simple, extensions on top of Net::IMAP::Simple.
my $summary = $imap->body_summary($message_number);
This method returns a simple object that contains a representation of the body of a message. The object is built by a Parse::RecDescent parser using the output of an IMAP fetch body command. The parser uses the formal syntax as defined by RFC3501 http://tools.ietf.org/html/rfc3501#section-9.
my $body = $summary->body; my @attr = map { $body->$_ } qw/ content_description encoded_size charset content_type part_number format id encoding /;
For multipart messages, the object contains sub-objects for each message part, accessable via the parts() method and inspected via the has_parts() method. The type method describes the type of multipart (such as mixed or alternative). The parts method returns a list of sub parts, which themselves may have subparts, and so on.
An example of a multipart, alternative message with a text body and an html version of the body would looke something like:
if ($summary->has_parts) { if ($summary->type eq 'alternative') { my ($html) = grep { $_->content_type eq 'text/html' } $summary->parts; } }
A really complex, multipart message could look something like this:
if ($summary->has_parts && $summary->type eq 'mixed') { for my $part ($summary->parts) { if ($part->has_parts && $part->type eq 'mixed') { ... } ... } }
For details on the invocation, read Net::IMAP::Simple.
Jason Woodward <woodwardj@jaos.org>
<woodwardj@jaos.org>
Copyright (c) 2010 Jason Woodward
All rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0.
This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose.
https://rt.cpan.org/Dist/Display.html?Queue=Net-IMAP-Simple
perl, Net::IMAP::Simple, Parse::RecDescent
To install Net::IMAP::Simple, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Net::IMAP::Simple
CPAN shell
perl -MCPAN -e shell install Net::IMAP::Simple
For more information on module installation, please visit the detailed CPAN module installation guide.