.\" Automatically generated by Pod::Man 2.25 (Pod::Simple 3.16) .\" .\" 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" '' '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 turned on, 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. .ie \nF \{\ . de IX . tm Index:\\$1\t\\n%\t"\\$2" .. . nr % 0 . rr F .\} .el \{\ . de IX .. .\} .\" .\" Accent mark definitions (@(#)ms.acc 1.5 88/02/08 SMI; from UCB 4.2). .\" Fear. Run. Save yourself. No user-serviceable parts. . \" fudge factors for nroff and troff .if n \{\ . ds #H 0 . ds #V .8m . ds #F .3m . ds #[ \f1 . ds #] \fP .\} .if t \{\ . ds #H ((1u-(\\\\n(.fu%2u))*.13m) . ds #V .6m . ds #F 0 . ds #[ \& . ds #] \& .\} . \" simple accents for nroff and troff .if n \{\ . ds ' \& . ds ` \& . ds ^ \& . ds , \& . ds ~ ~ . ds / .\} .if t \{\ . ds ' \\k:\h'-(\\n(.wu*8/10-\*(#H)'\'\h"|\\n:u" . ds ` \\k:\h'-(\\n(.wu*8/10-\*(#H)'\`\h'|\\n:u' . ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'^\h'|\\n:u' . ds , \\k:\h'-(\\n(.wu*8/10)',\h'|\\n:u' . ds ~ \\k:\h'-(\\n(.wu-\*(#H-.1m)'~\h'|\\n:u' . ds / \\k:\h'-(\\n(.wu*8/10-\*(#H)'\z\(sl\h'|\\n:u' .\} . \" troff and (daisy-wheel) nroff accents .ds : \\k:\h'-(\\n(.wu*8/10-\*(#H+.1m+\*(#F)'\v'-\*(#V'\z.\h'.2m+\*(#F'.\h'|\\n:u'\v'\*(#V' .ds 8 \h'\*(#H'\(*b\h'-\*(#H' .ds o \\k:\h'-(\\n(.wu+\w'\(de'u-\*(#H)/2u'\v'-.3n'\*(#[\z\(de\v'.3n'\h'|\\n:u'\*(#] .ds d- \h'\*(#H'\(pd\h'-\w'~'u'\v'-.25m'\f2\(hy\fP\v'.25m'\h'-\*(#H' .ds D- D\\k:\h'-\w'D'u'\v'-.11m'\z\(hy\v'.11m'\h'|\\n:u' .ds th \*(#[\v'.3m'\s+1I\s-1\v'-.3m'\h'-(\w'I'u*2/3)'\s-1o\s+1\*(#] .ds Th \*(#[\s+2I\s-2\h'-\w'I'u*3/5'\v'-.3m'o\v'.3m'\*(#] .ds ae a\h'-(\w'a'u*4/10)'e .ds Ae A\h'-(\w'A'u*4/10)'E . \" corrections for vroff .if v .ds ~ \\k:\h'-(\\n(.wu*9/10-\*(#H)'\s-2\u~\d\s+2\h'|\\n:u' .if v .ds ^ \\k:\h'-(\\n(.wu*10/11-\*(#H)'\v'-.4m'^\v'.4m'\h'|\\n:u' . \" for low resolution devices (crt and lpr) .if \n(.H>23 .if \n(.V>19 \ \{\ . ds : e . ds 8 ss . ds o a . ds d- d\h'-1'\(ga . ds D- D\h'-1'\(hy . ds th \o'bp' . ds Th \o'LP' . ds ae ae . ds Ae AE .\} .rm #[ #] #H #V #F C .\" ======================================================================== .\" .IX Title "Mail::IMAPClient::BodyStructure 3pm" .TH Mail::IMAPClient::BodyStructure 3pm "2011-08-09" "perl v5.14.2" "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::BodyStructure; \& use Mail::IMAPClient; \& \& my $imap = Mail::IMAPClient\->new(Server=>$serv,User=>$usr,Password=>$pwd); \& $imap\->select("INBOX") or die "cannot select the inbox for $usr: $@\en"; \& \& my @recent = $imap\->search("recent"); \& \& foreach my $id (@recent) \& { my $fetched = $imap\->fetch($id, "bodystructure"); \& my $struct = Mail::IMAPClient::BodyStructure\->new($fetched); \& \& my $mime = $struct\->bodytype."/".$struct\->bodysubtype; \& my $parts =join "\en\et", $struct\->parts; \& print "Msg $id (Content\-type: $mime) contains these parts:\en\et$parts\en"; \& } .Ve .SH "DESCRIPTION" .IX Header "DESCRIPTION" This extension will parse the result of an \s-1IMAP\s0 \s-1FETCH\s0 \s-1BODYSTRUCTURE\s0 command into a perl data structure. It also provides helper methods that will help you pull information out of the data structure. .PP Use of this extension requires Parse::RecDescent. If you don't have Parse::RecDescent then you must either get it or refrain from using this module. .SS "\s-1EXPORT\s0" .IX Subsection "EXPORT" Nothing is exported by default. \f(CW$parser\fR is exported upon request. \f(CW$parser\fR is the BodyStucture object's Parse::RecDescent object, which you'll probably only need for debugging purposes. .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\s0 \s-1BODYSTRUCTURE\s0 directive. Only one message's body structure should be described in this string, although that message may contain an arbitrary number of parts. .PP If you know the messages sequence number or unique \s-1ID\s0 (\s-1UID\s0) but haven't got its body structure, and you want to get the body structure and parse it into a \fBMail::IMAPClient::BodyStructure\fR object, then you might as well save yourself some work and use \&\fBMail::IMAPClient\fR's \fBget_bodystructure\fR method, which accepts a message sequence number (or \s-1UID\s0 if \fIUid\fR is true) and returns a \&\fBMail::IMAPClient::BodyStructure\fR object. It's functionally equivalent to issuing the \s-1FETCH\s0 \s-1BODYSTRUCTURE\s0 \s-1IMAP\s0 client command and then passing the results to \fBMail::IMAPClient::BodyStructure\fR's \fBnew\fR method but it does those things in one simple method call. .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 the envelopestruct for the message whose structure is described by the calling \fBMail::IMAPClient::Bodystructure\fR object. This envelope structure is blessed into the \fBMail::IMAPClient::BodyStructure::Envelope\fR subclass, which is explained more fully below. .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 "Envelopes and the Mail::IMAPClient::BodyStructure::Envelope Subclass" .IX Header "Envelopes and the Mail::IMAPClient::BodyStructure::Envelope Subclass" The \s-1IMAP\s0 standard specifies that output from the \s-1IMAP\s0 \fB\s-1FETCH\s0 \&\s-1ENVELOPE\s0\fR command will be an \s-1RFC2060\s0 envelope structure. It further specifies that output from the \fB\s-1FETCH\s0 \s-1BODYSTRUCTURE\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\s0\*(R")> 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 analagous 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 5 \& { 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\s0\*(R". .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" David J. Kernen .PP Reworked and maintained by Mark Overmeer. .SH "SEE ALSO" .IX Header "SEE ALSO" \&\fIperl\fR\|(1), Mail::IMAPClient, and \s-1RFC2060\s0. See also Parse::RecDescent if you want to understand the internals of this module.