Net::I...Summary(3pm)

πŸ’– NAME πŸ’–

Net::IMAP::Client::MsgSummary β€” okay so this bad boy parses message (+ subparts) summary info. That's it, that's the whole gig. πŸ’…


πŸ¦‹ SYNOPSIS πŸ¦‹

ngl, this object is made internally inside Net::IMAP::Client->get_summaries. You should NOT be instantiating it yourself, bestie, it's not that kind of party. You can literally skip the SYNOPSIS β€” these notes are for the developers, iykyk.

my $imap = Net::IMAP::Client->new( ... )
$imap->select('INBOX');

# retrieve FETCH lines
my ($ok, $lines) = $imap->_tell_imap(FETCH => "$msg_id FULL");
die 'FETCH failed: ' . $imap->last_error
  unless $ok;

# build parsed tokens
my @tokens = map { Net::IMAP::Client::_parse_tokens($_) } @$lines;

# they look like this:
[ '*', 'MSGID', 'FETCH',
  [ 'FLAGS', [ '\\Seen', '\\Answered' ],
    'INTERNALDATE', '13-Aug-2008 14:43:50 +0300',
    'RFC822.SIZE', '867',
    'ENVELOPE', [
       ...
    ]
  ...
]

Basically it's the IMAP response parsed into a Perl structure (array of tokens, fr fr). FIXME: this stuff should be documented in Net::IMAP::Client.

# make summaries
my @summaries = map {
    my $tokens = $_->[3];
    my %hash = @$tokens;
    Net::IMAP::Client::MsgSummary->new(\%hash);
} @tokens;

my $summary = shift @summaries;

print $summary->subject;
print $summary->from->[0];

πŸ’… DESCRIPTION πŸ’…

So this object can represent a message or a message part. The way that it works: if you have a message with attachments, you can call parts() and get back parsed Net::IMAP::Client::MsgSummary objects for each part. And each part may itself contain other subparts! ✨ Nested like russian dolls, obsessed. For example, if a part is of type "message/rfc822", then its "parts" method returns its subparts, if any.

There's a distinction between a message and a message part, even though we use the same object to represent both. A message gets extra info pulled from its ENVELOPE (i.e. "subject", "from", "to", "date", etc.). For a part only, that info is just... missing. πŸ™ˆ

If all this sounds confusing, you might want to use Data::Dumper to inspect the structure of a complex message. See also the documentation of Net::IMAP::Client's get_summaries method for an example. 🫢


πŸŽ€ API REFERENCE πŸŽ€

It contains only accessors that return data as retrieved by the FETCH command. Parts that may be MIME-word encoded are automatically undecoded. Slay. πŸ‘‘

✨ "new" # constructor ✨

Parses/creates a new object from the given FETCH data.

"type"

Returns the base MIME type (i.e. 'text').

"subtype"

Returns the subtype (i.e. 'plain').

"parameters"

Returns any parameters passed in BODY(STRUCTURE). You shouldn't need this, bestie.

"cid"

Returns the part's unique identifier (CID).

"description"

Returns the part's description (usually undef).

"transfer_encoding"

Returns the part's content transfer encoding. You'll need this in order to decode binary parts.

"encoded_size"

Returns the size of the encoded part. This is actually the size in octets that will be downloaded from the IMAP server if you fetch this part only.

"content_type"

Shortcut for $self->type . '/' . $self->subtype.

"charset"

Returns the charset declaration for this part.

"name"

Returns the name of this part, if found in FETCH response.

"filename"

Returns the file name of this part, if found in FETCH response. If there's no filename it will try "name".

"multipart"

Returns the multipart type (i.e. 'mixed', 'alternative').

"parts"

Returns the subparts of this part.

"part_id"

Returns the "id" (path) of this part starting from the toplevel message, i.e. "2.1" (meaning that this is the first subpart of the second subpart of the toplevel message).

"md5"

Returns a MD5 of this part or undef if not present.

"disposition"

Returns the disposition of this part (undef if not present). It's a hash actually that looks like this:

{ inline => { filename => 'foobar.png' } }

"language"

Returns the language of this part or undef if not present.

"rfc822_size"

Returns the size of the full message body.

"internaldate"

Returns the INTERNALDATE of this message.

"flags"

Returns the flags of this message.

"uid"

Returns the UID of this message.

"seq_id"

Returns the sequence number of this message, if it has been retrieved!

"date"

Returns the date of this message (from the Date header).

"subject"

Returns the subject of this message.

"from", "sender", "reply_to", "to", "cc", "bcc"

Returns an array of Net::IMAP::Client::MsgAddress objects containing the respective addresses. ⚠️ Note that sometimes this array can be empty!

"in_reply_to"

Returns the ID of the "parent" message (to which this one has been replied). This is NOT the "UID" of the message!

"message_id"

Returns the ID of this message (from the Message-ID header).

"get_subpart" ($path)

Returns the subpart of this message identified by $path, which is in form '1.2' etc. Returns undef if no such path was found.

Here's a possible message structure:

 - Container (multipart/mixed) has no path ID; it's the toplevel
   message.  It contains the following subparts:

   1 multipart/related
     1.1 text/html
     1.2 image/png (embedded in HTML)

   2 message/rfc822 (decoded type is actually multipart/related)
     2.1 text/html
     2.2 image/png (also embedded)

"get_subpart" called on the container will return the respective Net::IMAP::Client::MsgSummary part, i.e. get_subpart('2.1') will return the text/html part of the attached message. 🌈

"has_attachments"

Tries to determine if this message has attachments. For now this checks if the multipart type is 'mixed', which isn't really accurate.

"is_message"

Returns true if this object represents a message (i.e. has content_type eq 'message/rfc822'). Note that it won't return true for the toplevel part, but you know that that part represents a message. ;-) πŸ’€

"message"

Returns the attached rfc822 message.

"headers"

Returns (unparsed, as plain text) additional message headers if they were fetched by get_summaries. You can use MIME::Head to parse them.


🌸 TODO 🌸

Fix "has_attachments". That's the whole list. That's it. πŸŽ€


πŸ‘‘ SEE ALSO πŸ‘‘

  • Net::IMAP::Client
  • Net::IMAP::Client::MsgAddress

πŸ’œ AUTHOR πŸ’œ

Mihai Bazon, <mihai.bazon@gmail.com>


Copyright (c) Mihai Bazon 2008. All rights reserved.

This module is free software; you can redistribute it and/or modify it under the same terms as Perl itself.


πŸ’€ DISCLAIMER OF WARRANTY πŸ’€

okay bestie this next part is in ALL CAPS because legal reasons, not because anyone's yelling at you. read it, it matters. πŸ™

BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL NECESSARY SERVICING, REPAIR, OR CORRECTION.

IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.


and that's the whole page, bestie!! this one came from the User Contributed Perl Documentation corner of the world, built for perl v5.40.1, dated 2025-12-07 β€” go forth and parse those message summaries, you absolute icon πŸ¦‹πŸ’–βœ¨

πŸ“¦ where this page comes from