{
    "mode": "perldoc",
    "parameter": "Mail::IMAPClient::BodyStructure",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/perldoc/Mail%3A%3AIMAPClient%3A%3ABodyStructure/json",
    "generated": "2026-06-09T14:12:17Z",
    "synopsis": "use Mail::IMAPClient;\nuse Mail::IMAPClient::BodyStructure;\nmy $imap = Mail::IMAPClient->new(\nServer => $server, User => $login, Password => $pass\n);\n$imap->select(\"INBOX\") or die \"Could not select INBOX: $@\\n\";\nmy @recent = $imap->search(\"recent\") or die \"No recent msgs in INBOX\\n\";\nforeach my $id (@recent) {\nmy $bsdat = $imap->fetch( $id, \"bodystructure\" );\nmy $bso   = Mail::IMAPClient::BodyStructure->new( join(\"\", $imap->History) );\nmy $mime  = $bso->bodytype . \"/\" . $bso->bodysubtype;\nmy $parts = map( \"\\n\\t\" . $, $bso->parts );\nprint \"Msg $id (Content-type: $mime) contains these parts:$parts\\n\";\n}",
    "sections": {
        "NAME": {
            "content": "Mail::IMAPClient::BodyStructure - parse fetched results\n",
            "subsections": []
        },
        "SYNOPSIS": {
            "content": "use Mail::IMAPClient;\nuse Mail::IMAPClient::BodyStructure;\n\nmy $imap = Mail::IMAPClient->new(\nServer => $server, User => $login, Password => $pass\n);\n\n$imap->select(\"INBOX\") or die \"Could not select INBOX: $@\\n\";\n\nmy @recent = $imap->search(\"recent\") or die \"No recent msgs in INBOX\\n\";\n\nforeach my $id (@recent) {\nmy $bsdat = $imap->fetch( $id, \"bodystructure\" );\nmy $bso   = Mail::IMAPClient::BodyStructure->new( join(\"\", $imap->History) );\nmy $mime  = $bso->bodytype . \"/\" . $bso->bodysubtype;\nmy $parts = map( \"\\n\\t\" . $, $bso->parts );\nprint \"Msg $id (Content-type: $mime) contains these parts:$parts\\n\";\n}\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "This extension will parse the result of an IMAP FETCH BODYSTRUCTURE command into a perl data\nstructure. It also provides helper methods to help pull information out of the data structure.\n\nThis module requires Parse::RecDescent.\n",
            "subsections": []
        },
        "Class Methods": {
            "content": "The following class method is available:\n\nnew\nThis class method is the constructor method for instantiating new\nMail::IMAPClient::BodyStructure objects. The new method accepts one argument, a string\ncontaining a server response to a FETCH BODYSTRUCTURE directive.\n\nThe module Mail::IMAPClient provides the getbodystructure convenience method to simplify use of\nthis module when starting with just a messages sequence number or unique ID (UID).\n",
            "subsections": []
        },
        "Object Methods": {
            "content": "The following object methods are available:\n\nbodytype\nThe bodytype object method requires no arguments. It returns the bodytype for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodysubtype\nThe bodysubtype object method requires no arguments. It returns the bodysubtype for the message\nwhose structure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodyparms\nThe bodyparms object method requires no arguments. It returns the bodyparms for the message\nwhose structure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodydisp\nThe bodydisp object method requires no arguments. It returns the bodydisp for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodyid\nThe bodyid object method requires no arguments. It returns the bodyid for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodydesc\nThe bodydesc object method requires no arguments. It returns the bodydesc for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodyenc\nThe bodyenc object method requires no arguments. It returns the bodyenc for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodysize\nThe bodysize object method requires no arguments. It returns the bodysize for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodylang\nThe bodylang object method requires no arguments. It returns the bodylang for the message whose\nstructure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nbodystructure\nThe bodystructure object method requires no arguments. It returns the bodystructure for the\nmessage whose structure is described by the calling Mail::IMAPClient::Bodystructure object.\n\nenvelopestruct\nThe envelopestruct object method requires no arguments. It returns a\nMail::IMAPClient::BodyStructure::Envelope object for the message from the calling\nMail::IMAPClient::Bodystructure object.\n\ntextlines\nThe textlines object method requires no arguments. It returns the textlines for the message\nwhose structure is described by the calling Mail::IMAPClient::Bodystructure object.\n",
            "subsections": []
        },
        "Mail::IMAPClient::BodyStructure::Envelope": {
            "content": "The IMAP standard specifies that output from the IMAP FETCH ENVELOPE command will be an RFC2060\nenvelope structure. It further specifies that output from the FETCH BODYSTRUCTURE command may\nalso contain embedded envelope structures (if, for example, a message's subparts contain one or\nmore included messages). Objects belonging to Mail::IMAPClient::BodyStructure::Envelope are Perl\nrepresentations of these envelope structures, which is to say the nested parenthetical lists of\nRFC2060 translated into a Perl datastructure.\n\nNote that all of the fields relate to the specific part to which they belong. In other words,\noutput from a FETCH nnnn ENVELOPE command (or, in Mail::IMAPClient,\n\"$imap-\"fetch($msgid,\"ENVELOPE\")> or \"my $env = $imap-\"getenvelope($msgid)>) are for the\nmessage, but fields from within a bodystructure relate to the message subpart and not the parent\nmessage.\n\nAn envelope structure's Mail::IMAPClient::BodyStructure::Envelope representation is a hash of\nthingies that looks like this:\n\n{\nsubject   => \"subject\",\ninreplyto => \"referencemessageid\",\nfrom      => [ addressStruct1 ],\nmessageid => \"messageid\",\nbcc       => [ addressStruct1, addressStruct2 ],\ndate      => \"Tue, 09 Jul 2002 14:15:53 -0400\",\nreplyto   => [ adressStruct1, addressStruct2 ],\nto        => [ adressStruct1, addressStruct2 ],\nsender    => [ adressStruct1 ],\ncc        => [ adressStruct1, addressStruct2 ],\n}\n\nThe ...::Envelope object also has methods for accessing data in the structure. They are:\n\ndate\nReturns the date of the message.\n\ninreplyto\nReturns the message id of the message to which this message is a reply.\n\nsubject\nReturns the subject of the message.\n\nmessageid\nReturns the message id of the message.\n\nYou can also use the following methods to get addressing information. Each of these methods\nreturns an array of Mail::IMAPClient::BodyStructure::Address objects, which are perl data\nstructures representing RFC2060 address structures. Some of these arrays would naturally contain\none element (such as from, which normally contains a single \"From:\" address); others will often\ncontain more than one address. However, because RFC2060 defines all of these as \"lists of\naddress structures\", they are all translated into arrays of ...::Address objects.\n\nSee the section on Mail::IMAPClient::BodyStructure::Address, below, for alternate (and\npreferred) ways of accessing these data.\n\nThe methods available are:\n\nbcc Returns an array of blind cc'ed recipients' address structures. (Don't expect much in here\nunless the message was sent from the mailbox you're poking around in, by the way.)\n\ncc  Returns an array of cc'ed recipients' address structures.\n\nfrom\nReturns an array of \"From:\" address structures--usually just one.\n\nreplyto\nReturns an array of \"Reply-to:\" address structures. Once again there is usually just one\naddress in the list.\n\nsender\nReturns an array of senders' address structures--usually just one and usually the same as\nfrom.\n\nto  Returns an array of recipients' address structures.\n\nEach of the methods that returns a list of address structures (i.e. a list of\nMail::IMAPClient::BodyStructure::Address arrays) also has an analogous method that will return a\nlist of E-Mail addresses instead. The addresses are in the format \"personalname\n<mailboxname@hostname>\" (see the section on Mail::IMAPClient::BodyStructure::Address, below)\nHowever, if the personal name is 'NIL' then it is omitted from the address.\n\nThese methods are:\n\nbccaddresses\nReturns a list (or an array reference if called in scalar context) of blind cc'ed\nrecipients' email addresses. (Don't expect much in here unless the message was sent from the\nmailbox you're poking around in, by the way.)\n\nccaddresses\nReturns a list of cc'ed recipients' email addresses. If called in a scalar context it\nreturns a reference to an array of email addresses.\n\nfromaddresses\nReturns a list of \"From:\" email addresses. If called in a scalar context it returns the\nfirst email address in the list. (It's usually a list of just one anyway.)\n\nreplytoaddresses\nReturns a list of \"Reply-to:\" email addresses. If called in a scalar context it returns the\nfirst email address in the list.\n\nsenderaddresses\nReturns a list of senders' email addresses. If called in a scalar context it returns the\nfirst email address in the list.\n\ntoaddresses\nReturns a list of recipients' email addresses. If called in a scalar context it returns a\nreference to an array of email addresses.\n\nNote that context affects the behavior of all of the above methods.\n\nThose fields that will commonly contain multiple entries (i.e. they are recipients) will return\nan array reference when called in scalar context. You can use this behavior to optimize\nperformance.\n\nThose fields that will commonly contain just one address (the sender's) will return the first\n(and usually only) address. You can use this behavior to optimize your development time.\n",
            "subsections": []
        },
        "Addresses and the Mail::IMAPClient::BodyStructure::Address": {
            "content": "Several components of an envelope structure are address structures. They are each parsed into\ntheir own object, Mail::IMAPClient::BodyStructure::Address, which looks like this:\n\n{\nmailboxname  => 'somebody.special',\nhostname     => 'somplace.weird.com'\npersonalname => 'Somebody Special\nsourceroute  => 'NIL'\n}\n\nRFC2060 specifies that each address component of a bodystructure is a list of address\nstructures, so Mail::IMAPClient::BodyStructure parses each of these into an array of\nMail::IMAPClient::BodyStructure::Address objects.\n\nEach of these objects has the following methods available to it:\n\nmailboxname\nReturns the \"mailboxname\" portion of the address, which is the part to the left of the '@'\nsign.\n\nhostname\nReturns the \"hostname\" portion of the address, which is the part to the right of the '@'\nsign.\n\npersonalname\nReturns the \"personalname\" portion of the address, which is the part of the address that's\ntreated like a comment.\n\nsourceroute\nReturns the \"sourceroute\" portion of the address, which is typically \"NIL\".\n\nTaken together, the parts of an address structure form an address that will look something like\nthis:\n\n\"personalname <mailboxname@hostname>\"\n\nNote that because the Mail::IMAPClient::BodyStructure::Address objects come in arrays, it's\ngenerally easier to use the methods available to Mail::IMAPClient::BodyStructure::Envelope to\nobtain all of the addresses in a particular array in one operation. These methods are provided,\nhowever, in case you'd rather do things the hard way. (And also because the aforementioned\nmethods from Mail::IMAPClient::BodyStructure::Envelope need them anyway.)\n",
            "subsections": []
        },
        "AUTHOR": {
            "content": "Original author: David J. Kernen; Reworked by: Mark Overmeer; Maintained by Phil Pearl.\n",
            "subsections": []
        },
        "SEE ALSO": {
            "content": "",
            "subsections": [
                {
                    "name": "perl",
                    "content": ""
                }
            ]
        }
    },
    "summary": "Mail::IMAPClient::BodyStructure - parse fetched results",
    "flags": [],
    "examples": [],
    "see_also": []
}