1Net::IMAP::SimpleX(3) User Contributed Perl DocumentationNet::IMAP::SimpleX(3)
2
3
4
6 Net::IMAP::SimpleX - Addons for Net::IMAP::Simple
7
9 use strict;
10 use warnings;
11 use Net::IMAP::SimpleX;
12
13 Net::IMAP::SimpleX uses Net::IMAP::Simple as a base so the object
14 creation is the same as it is for the ancestor:
15
16 my $imap = Net::IMAP::SimpleX->new('imap.example.com') ||
17 die "Unable to connect to IMAP: $Net::IMAP::Simple::errstr\n";
18
19 $imap->select("INBOX");
20
21 Net::IMAP::SimpleX is a collection of handy methods that are not
22 simple, require Parse::RecDescent, or are experimental.
23
25 This module adds some useful, yet not so simple, extensions on top of
26 Net::IMAP::Simple.
27
29 new For details on the invocation, read Net::IMAP::Simple.
30
31 body_summary
32 Typical invocations will take this overall shape.
33
34 # get an object representation of the message body
35 my $summary = $imap->body_summary($message_number);
36
37 # multipart message
38 if ($summary->has_parts) {
39 for my $subpart ($summary->parts) {
40 if ($subpart->has_parts) { ... }
41 # examine the message part
42 my @attr = map { $subpart->$_ } qw/content_type encoding encoded_size/;
43 # fetch the raw message part
44 my $subpart_body = $imap->get($message_number, $subpart->part_number);
45 }
46 } else {
47 my $body = $summary->body;
48 my @attr = map { $body->$_ } qw/content_type encoding encoded_size/
49 }
50
51 This method returns a simple object that contains a representation
52 of the body of a message. The object is built by a
53 Parse::RecDescent parser using the output of an IMAP fetch body
54 command. The parser uses the formal syntax as defined by RFC3501
55 <http://tools.ietf.org/html/rfc3501#section-9>.
56
57 my $body = $summary->body;
58 my @attr = map { $body->$_ } qw/
59 content_description
60 encoded_size
61 charset
62 content_type
63 part_number
64 format
65 id
66 encoding
67 /;
68
69 For multipart messages, the object contains sub-objects for each
70 message part, accessible via the parts() method and inspected via
71 the has_parts() method. The type method describes the type of
72 multipart (such as mixed or alternative). The parts method returns
73 a list of sub parts, which themselves may have subparts, and so on.
74
75 An example of a multipart, alternative message with a text body and
76 an html version of the body would looke something like:
77
78 if ($summary->has_parts) {
79 if ($summary->type eq 'alternative') {
80 my ($html) = grep { $_->content_type eq 'text/html' } $summary->parts;
81 }
82 }
83
84 A really complex, multipart message could look something like this:
85
86 if ($summary->has_parts && $summary->type eq 'mixed') {
87
88 for my $part ($summary->parts) {
89 if ($part->has_parts && $part->type eq 'mixed') { ... }
90 ...
91 }
92
93 }
94
95 fetch
96 The fetch command returns the various parts of messages that users
97 request. It is fairly complicated (following RFC3501 using a
98 grammar/parser), but there are some basic patterns that it follows.
99
100 my $res =$imap->fetch('30:32' => 'UID BODY.PEEK[HEADER.FIELDS (DATE)] FLAGS')
101 # $res = {
102 # 30 => {
103 # "BODY[HEADER.FIELDS (DATE)]" => "Date: Sun, 18 Jul 2010 20:54:48 -0400\r\n\r\n",
104 # "FLAGS" => ["\\Flagged", "\\Seen"],
105 # "UID" => 58890,
106 # },
107 # 31 => {
108 # "BODY[HEADER.FIELDS (DATE)]" => "Date: Wed, 21 Jul 2010 09:09:04 -0400\r\n\r\n",
109 # "FLAGS" => ["\\Seen"],
110 # "UID" => 58891,
111 # },
112 # 32 => {
113 # "BODY[HEADER.FIELDS (DATE)]" => "Date: Sat, 24 Jul 2010 05:12:06 -0700\r\n\r\n",
114 # "FLAGS" => ["\\Seen"],
115 # "UID" => 58892,
116 # },
117 # }
118
119 So-called "parenthized" lists will be returned as an array (see
120 "FLAGS") but nearly everything else will come back as strings.
121 This includes parenthized queries. Take "BODY.PEAK[HEADER.FIELDS
122 (DATE FROM SUBJECT)]"), for example. The result would come back as
123 the RFC822 header lines (as the above "Date: Sun, ..." has done).
124
125 For more information about the different types of queries, see
126 RFC3501. There's a surprising number of things that can be
127 queried.
128
129 uidfetch
130 This is roughly the same thing as the fetch() method above, but the
131 query runs on UIDs instead of sequence numbers. The keys of the
132 $res are still the sequence numbers though.
133
134 my $res =$imap->fetch('58890' => 'UID BODY.PEEK[HEADER.FIELDS (DATE)] FLAGS')
135 # $res = {
136 # 30 => {
137 # "BODY[HEADER.FIELDS (DATE)]" => "Date: Sun, 18 Jul 2010 20:54:48 -0400\r\n\r\n",
138 # "FLAGS" => ["\\Flagged", "\\Seen"],
139 # "UID" => 58890,
140 # },
141 # ...
142
144 INITIAL AUTHOR
145 Jason Woodward "<woodwardj@jaos.org>"
146
147 ADDITIONAL CONTRIBUTIONS
148 Paul Miller "<jettero@cpan.org>" [fetch()]
149
151 Copyright (c) 2010 Jason Woodward
152
153 All rights reserved. This program is free software; you can
154 redistribute it and/or modify it under the same terms as Perl itself.
155
157 This module is free software. You can redistribute it and/or modify it
158 under the terms of the Artistic License 2.0.
159
160 This program is distributed in the hope that it will be useful, but
161 without any warranty; without even the implied warranty of
162 merchantability or fitness for a particular purpose.
163
165 <https://rt.cpan.org/Dist/Display.html?Queue=Net-IMAP-Simple>
166
168 perl, Net::IMAP::Simple, Parse::RecDescent
169
170
171
172perl v5.36.0 2023-01-20 Net::IMAP::SimpleX(3)