.\" Automatically generated by Pod::Man 4.14 (Pod::Simple 3.40) .\" .\" Standard preamble: .\" ======================================================================== .de Sp \" Vertical space (when we can't use .PP) .if t .sp .5v .if n .sp .. .de Vb \" Begin verbatim text .ft CW .nf .ne \\$1 .. .de Ve \" End verbatim text .ft R .fi .. .\" Set up some character translations and predefined strings. \*(-- will .\" give an unbreakable dash, \*(PI will give pi, \*(L" will give a left .\" double quote, and \*(R" will give a right double quote. \*(C+ will .\" give a nicer C++. Capital omega is used to do unbreakable dashes and .\" therefore won't be available. \*(C` and \*(C' expand to `' in nroff, .\" nothing in troff, for use with C<>. .tr \(*W- .ds C+ C\v'-.1v'\h'-1p'\s-2+\h'-1p'+\s0\v'.1v'\h'-1p' .ie n \{\ . ds -- \(*W- . ds PI pi . if (\n(.H=4u)&(1m=24u) .ds -- \(*W\h'-12u'\(*W\h'-12u'-\" diablo 10 pitch . if (\n(.H=4u)&(1m=20u) .ds -- \(*W\h'-12u'\(*W\h'-8u'-\" diablo 12 pitch . ds L" "" . ds R" "" . ds C` "" . ds C' "" 'br\} .el\{\ . ds -- \|\(em\| . ds PI \(*p . ds L" `` . ds R" '' . ds C` . ds C' 'br\} .\" .\" Escape single quotes in literal strings from groff's Unicode transform. .ie \n(.g .ds Aq \(aq .el .ds Aq ' .\" .\" If the F register is >0, we'll generate index entries on stderr for .\" titles (.TH), headers (.SH), subsections (.SS), items (.Ip), and index .\" entries marked with X<> in POD. Of course, you'll have to process the .\" output yourself in some meaningful fashion. .\" .\" Avoid warning from groff about undefined register 'F'. .de IX .. .nr rF 0 .if \n(.g .if rF .nr rF 1 .if (\n(rF:(\n(.g==0)) \{\ . if \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . if !\nF==2 \{\ . nr % 0 . nr F 2 . \} . \} .\} .rr rF .\" ======================================================================== .\" .IX Title "Mail::IMAPClient::BodyStructure 3pm" .TH Mail::IMAPClient::BodyStructure 3pm "2021-09-11" "perl v5.32.1" "User Contributed Perl Documentation" .\" For nroff, turn off justification. Always turn off hyphenation; it makes .\" way too many mistakes in technical documents. .if n .ad l .nh .SH "NAME" Mail::IMAPClient::BodyStructure \- parse fetched results .SH "SYNOPSIS" .IX Header "SYNOPSIS" .Vb 2 \& use Mail::IMAPClient; \& use Mail::IMAPClient::BodyStructure; \& \& my $imap = Mail::IMAPClient\->new( \& Server => $server, User => $login, Password => $pass \& ); \& \& $imap\->select("INBOX") or die "Could not select INBOX: $@\en"; \& \& my @recent = $imap\->search("recent") or die "No recent msgs in INBOX\en"; \& \& foreach my $id (@recent) { \& my $bsdat = $imap\->fetch( $id, "bodystructure" ); \& my $bso = Mail::IMAPClient::BodyStructure\->new( join("", $imap\->History) ); \& my $mime = $bso\->bodytype . "/" . $bso\->bodysubtype; \& my $parts = map( "\en\et" . $_, $bso\->parts ); \& print "Msg $id (Content\-type: $mime) contains these parts:$parts\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This extension will parse the result of an \s-1IMAP FETCH BODYSTRUCTURE\s0 command into a perl data structure. It also provides helper methods to help pull information out of the data structure. .PP This module requires Parse::RecDescent. .SH "Class Methods" .IX Header "Class Methods" The following class method is available: .SS "new" .IX Subsection "new" This class method is the constructor method for instantiating new Mail::IMAPClient::BodyStructure objects. The \fBnew\fR method accepts one argument, a string containing a server response to a \s-1FETCH BODYSTRUCTURE\s0 directive. .PP The module \fBMail::IMAPClient\fR provides the \fBget_bodystructure\fR convenience method to simplify use of this module when starting with just a messages sequence number or unique \s-1ID\s0 (\s-1UID\s0). .SH "Object Methods" .IX Header "Object Methods" The following object methods are available: .SS "bodytype" .IX Subsection "bodytype" The \fBbodytype\fR object method requires no arguments. It returns the bodytype for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodysubtype" .IX Subsection "bodysubtype" The \fBbodysubtype\fR object method requires no arguments. It returns the bodysubtype for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodyparms" .IX Subsection "bodyparms" The \fBbodyparms\fR object method requires no arguments. It returns the bodyparms for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodydisp" .IX Subsection "bodydisp" The \fBbodydisp\fR object method requires no arguments. It returns the bodydisp for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodyid" .IX Subsection "bodyid" The \fBbodyid\fR object method requires no arguments. It returns the bodyid for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodydesc" .IX Subsection "bodydesc" The \fBbodydesc\fR object method requires no arguments. It returns the bodydesc for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodyenc" .IX Subsection "bodyenc" The \fBbodyenc\fR object method requires no arguments. It returns the bodyenc for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodysize" .IX Subsection "bodysize" The \fBbodysize\fR object method requires no arguments. It returns the bodysize for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodylang" .IX Subsection "bodylang" The \fBbodylang\fR object method requires no arguments. It returns the bodylang for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SS "bodystructure" .IX Subsection "bodystructure" The \fBbodystructure\fR object method requires no arguments. It returns the bodystructure for the message whose structure is described by the calling \fBMail::IMAPClient::Bodystructure\fR object. .SS "envelopestruct" .IX Subsection "envelopestruct" The \fBenvelopestruct\fR object method requires no arguments. It returns a \fBMail::IMAPClient::BodyStructure::Envelope\fR object for the message from the calling \fBMail::IMAPClient::Bodystructure\fR object. .SS "textlines" .IX Subsection "textlines" The \fBtextlines\fR object method requires no arguments. It returns the textlines for the message whose structure is described by the calling \&\fBMail::IMAPClient::Bodystructure\fR object. .SH "Mail::IMAPClient::BodyStructure::Envelope" .IX Header "Mail::IMAPClient::BodyStructure::Envelope" The \s-1IMAP\s0 standard specifies that output from the \s-1IMAP\s0 \fB\s-1FETCH ENVELOPE\s0\fR command will be an \s-1RFC2060\s0 envelope structure. It further specifies that output from the \fB\s-1FETCH BODYSTRUCTURE\s0\fR command may also contain embedded envelope structures (if, for example, a message's subparts contain one or more included messages). Objects belonging to \&\fBMail::IMAPClient::BodyStructure::Envelope\fR are Perl representations of these envelope structures, which is to say the nested parenthetical lists of \s-1RFC2060\s0 translated into a Perl datastructure. .PP Note that all of the fields relate to the specific part to which they belong. In other words, output from a \s-1FETCH\s0 nnnn \s-1ENVELOPE\s0 command (or, in \fBMail::IMAPClient\fR, \f(CW\*(C`$imap\-\*(C'\fRfetch($msgid,\*(L"\s-1ENVELOPE\*(R"\s0)> or \&\f(CW\*(C`my $env = $imap\-\*(C'\fRget_envelope($msgid)>) are for the message, but fields from within a bodystructure relate to the message subpart and not the parent message. .PP An envelope structure's \fBMail::IMAPClient::BodyStructure::Envelope\fR representation is a hash of thingies that looks like this: .PP .Vb 12 \& { \& subject => "subject", \& inreplyto => "reference_message_id", \& from => [ addressStruct1 ], \& messageid => "message_id", \& bcc => [ addressStruct1, addressStruct2 ], \& date => "Tue, 09 Jul 2002 14:15:53 \-0400", \& replyto => [ adressStruct1, addressStruct2 ], \& to => [ adressStruct1, addressStruct2 ], \& sender => [ adressStruct1 ], \& cc => [ adressStruct1, addressStruct2 ], \& } .Ve .PP The \fB...::Envelope\fR object also has methods for accessing data in the structure. They are: .IP "date" 4 .IX Item "date" Returns the date of the message. .IP "inreplyto" 4 .IX Item "inreplyto" Returns the message id of the message to which this message is a reply. .IP "subject" 4 .IX Item "subject" Returns the subject of the message. .IP "messageid" 4 .IX Item "messageid" Returns the message id of the message. .PP You can also use the following methods to get addressing information. Each of these methods returns an array of \&\fBMail::IMAPClient::BodyStructure::Address\fR objects, which are perl data structures representing \s-1RFC2060\s0 address structures. Some of these arrays would naturally contain one element (such as \fBfrom\fR, which normally contains a single \*(L"From:\*(R" address); others will often contain more than one address. However, because \s-1RFC2060\s0 defines all of these as \*(L"lists of address structures\*(R", they are all translated into arrays of \fB...::Address\fR objects. .PP See the section on \fBMail::IMAPClient::BodyStructure::Address\fR, below, for alternate (and preferred) ways of accessing these data. .PP The methods available are: .IP "bcc" 4 .IX Item "bcc" Returns an array of blind cc'ed recipients' address structures. (Don't expect much in here unless the message was sent from the mailbox you're poking around in, by the way.) .IP "cc" 4 .IX Item "cc" Returns an array of cc'ed recipients' address structures. .IP "from" 4 .IX Item "from" Returns an array of \*(L"From:\*(R" address structures\*(--usually just one. .IP "replyto" 4 .IX Item "replyto" Returns an array of \*(L"Reply-to:\*(R" address structures. Once again there is usually just one address in the list. .IP "sender" 4 .IX Item "sender" Returns an array of senders' address structures\*(--usually just one and usually the same as \fBfrom\fR. .IP "to" 4 .IX Item "to" Returns an array of recipients' address structures. .PP Each of the methods that returns a list of address structures (i.e. a list of \fBMail::IMAPClient::BodyStructure::Address\fR arrays) also has an analogous method that will return a list of E\-Mail addresses instead. The addresses are in the format \f(CW\*(C`personalname \*(C'\fR (see the section on \&\fBMail::IMAPClient::BodyStructure::Address\fR, below) However, if the personal name is '\s-1NIL\s0' then it is omitted from the address. .PP These methods are: .IP "bcc_addresses" 4 .IX Item "bcc_addresses" Returns a list (or an array reference if called in scalar context) of blind cc'ed recipients' email addresses. (Don't expect much in here unless the message was sent from the mailbox you're poking around in, by the way.) .IP "cc_addresses" 4 .IX Item "cc_addresses" Returns a list of cc'ed recipients' email addresses. If called in a scalar context it returns a reference to an array of email addresses. .IP "from_addresses" 4 .IX Item "from_addresses" Returns a list of \*(L"From:\*(R" email addresses. If called in a scalar context it returns the first email address in the list. (It's usually a list of just one anyway.) .IP "replyto_addresses" 4 .IX Item "replyto_addresses" Returns a list of \*(L"Reply-to:\*(R" email addresses. If called in a scalar context it returns the first email address in the list. .IP "sender_addresses" 4 .IX Item "sender_addresses" Returns a list of senders' email addresses. If called in a scalar context it returns the first email address in the list. .IP "to_addresses" 4 .IX Item "to_addresses" Returns a list of recipients' email addresses. If called in a scalar context it returns a reference to an array of email addresses. .PP Note that context affects the behavior of all of the above methods. .PP Those fields that will commonly contain multiple entries (i.e. they are recipients) will return an array reference when called in scalar context. You can use this behavior to optimize performance. .PP Those fields that will commonly contain just one address (the sender's) will return the first (and usually only) address. You can use this behavior to optimize your development time. .SH "Addresses and the Mail::IMAPClient::BodyStructure::Address" .IX Header "Addresses and the Mail::IMAPClient::BodyStructure::Address" Several components of an envelope structure are address structures. They are each parsed into their own object, \&\fBMail::IMAPClient::BodyStructure::Address\fR, which looks like this: .PP .Vb 6 \& { \& mailboxname => \*(Aqsomebody.special\*(Aq, \& hostname => \*(Aqsomplace.weird.com\*(Aq \& personalname => \*(AqSomebody Special \& sourceroute => \*(AqNIL\*(Aq \& } .Ve .PP \&\s-1RFC2060\s0 specifies that each address component of a bodystructure is a list of address structures, so \fBMail::IMAPClient::BodyStructure\fR parses each of these into an array of \&\fBMail::IMAPClient::BodyStructure::Address\fR objects. .PP Each of these objects has the following methods available to it: .IP "mailboxname" 4 .IX Item "mailboxname" Returns the \*(L"mailboxname\*(R" portion of the address, which is the part to the left of the '@' sign. .IP "hostname" 4 .IX Item "hostname" Returns the \*(L"hostname\*(R" portion of the address, which is the part to the right of the '@' sign. .IP "personalname" 4 .IX Item "personalname" Returns the \*(L"personalname\*(R" portion of the address, which is the part of the address that's treated like a comment. .IP "sourceroute" 4 .IX Item "sourceroute" Returns the \*(L"sourceroute\*(R" portion of the address, which is typically \*(L"\s-1NIL\*(R".\s0 .PP Taken together, the parts of an address structure form an address that will look something like this: .PP \&\f(CW\*(C`personalname \*(C'\fR .PP Note that because the \fBMail::IMAPClient::BodyStructure::Address\fR objects come in arrays, it's generally easier to use the methods available to \fBMail::IMAPClient::BodyStructure::Envelope\fR to obtain all of the addresses in a particular array in one operation. These methods are provided, however, in case you'd rather do things the hard way. (And also because the aforementioned methods from \&\fBMail::IMAPClient::BodyStructure::Envelope\fR need them anyway.) .SH "AUTHOR" .IX Header "AUTHOR" Original author: David J. Kernen; Reworked by: Mark Overmeer; Maintained by Phil Pearl. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fBperl\fR\|(1), Mail::IMAPClient, Parse::RecDescent, and \s-1RFC2060.\s0