{
    "content": [
        {
            "type": "text",
            "text": "# MIME::Tools (perldoc)\n\n## NAME\n\nMIME-tools - modules for parsing (and creating!) MIME entities\n\n## SYNOPSIS\n\nHere's some pretty basic code for parsing a MIME message, and outputting its decoded components\nto a given directory:\nuse MIME::Parser;\n### Create parser, and set some parsing options:\nmy $parser = new MIME::Parser;\n$parser->outputunder(\"$ENV{HOME}/mimemail\");\n### Parse input:\n$entity = $parser->parse(\\*STDIN) or die \"parse failed\\n\";\n### Take a look at the top-level entity (and any parts it has):\n$entity->dumpskeleton;\nHere's some code which composes and sends a MIME message containing three parts: a text file, an\nattached GIF, and some more text:\nuse MIME::Entity;\n### Create the top-level, and set up the mail headers:\n$top = MIME::Entity->build(Type    =>\"multipart/mixed\",\nFrom    => \"me\\@myhost.com\",\nTo      => \"you\\@yourhost.com\",\nSubject => \"Hello, nurse!\");\n### Part #1: a simple text document:\n$top->attach(Path=>\"./testin/short.txt\");\n### Part #2: a GIF file:\n$top->attach(Path        => \"./docs/mime-sm.gif\",\nType        => \"image/gif\",\nEncoding    => \"base64\");\n### Part #3: some literal text:\n$top->attach(Data=>$message);\n### Send it:\nopen MAIL, \"| /usr/lib/sendmail -t -oi -oem\" or die \"open: $!\";\n$top->print(\\*MAIL);\nclose MAIL;\nFor more examples, look at the scripts in the examples directory of the MIME-tools distribution.\n\n## DESCRIPTION\n\nMIME-tools is a collection of Perl5 MIME:: modules for parsing, decoding, *and generating*\nsingle- or multipart (even nested multipart) MIME messages. (Yes, kids, that means you can send\nmessages with attached GIF files).\n\n## Sections\n\n- **NAME**\n- **SYNOPSIS**\n- **DESCRIPTION**\n- **REQUIREMENTS**\n- **A QUICK TOUR** (6 subsections)\n- **THINGS YOU SHOULD DO** (5 subsections)\n- **THINGS I DO THAT YOU SHOULD KNOW ABOUT** (6 subsections)\n- **A MIME PRIMER** (3 subsections)\n- **SEE ALSO**\n- **SUPPORT**\n- **CHANGE LOG**\n- **AUTHOR**\n- **ACKNOWLEDGMENTS**\n- **LICENSE**\n\nUse structuredContent.sections for detailed options, examples, and full documentation.\n"
        }
    ],
    "structuredContent": {
        "command": "MIME::Tools",
        "section": "",
        "mode": "perldoc",
        "summary": "MIME-tools - modules for parsing (and creating!) MIME entities",
        "synopsis": "Here's some pretty basic code for parsing a MIME message, and outputting its decoded components\nto a given directory:\nuse MIME::Parser;\n### Create parser, and set some parsing options:\nmy $parser = new MIME::Parser;\n$parser->outputunder(\"$ENV{HOME}/mimemail\");\n### Parse input:\n$entity = $parser->parse(\\*STDIN) or die \"parse failed\\n\";\n### Take a look at the top-level entity (and any parts it has):\n$entity->dumpskeleton;\nHere's some code which composes and sends a MIME message containing three parts: a text file, an\nattached GIF, and some more text:\nuse MIME::Entity;\n### Create the top-level, and set up the mail headers:\n$top = MIME::Entity->build(Type    =>\"multipart/mixed\",\nFrom    => \"me\\@myhost.com\",\nTo      => \"you\\@yourhost.com\",\nSubject => \"Hello, nurse!\");\n### Part #1: a simple text document:\n$top->attach(Path=>\"./testin/short.txt\");\n### Part #2: a GIF file:\n$top->attach(Path        => \"./docs/mime-sm.gif\",\nType        => \"image/gif\",\nEncoding    => \"base64\");\n### Part #3: some literal text:\n$top->attach(Data=>$message);\n### Send it:\nopen MAIL, \"| /usr/lib/sendmail -t -oi -oem\" or die \"open: $!\";\n$top->print(\\*MAIL);\nclose MAIL;\nFor more examples, look at the scripts in the examples directory of the MIME-tools distribution.",
        "tldr_summary": null,
        "tldr_examples": [],
        "tldr_source": null,
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 44,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 4,
                "subsections": []
            },
            {
                "name": "REQUIREMENTS",
                "lines": 13,
                "subsections": []
            },
            {
                "name": "A QUICK TOUR",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Overview of the classes",
                        "lines": 75
                    },
                    {
                        "name": "Parsing messages",
                        "lines": 22
                    },
                    {
                        "name": "Composing messages",
                        "lines": 17
                    },
                    {
                        "name": "Sending email",
                        "lines": 29
                    },
                    {
                        "name": "Message-logging",
                        "lines": 36
                    },
                    {
                        "name": "Configuring the toolkit",
                        "lines": 19
                    }
                ]
            },
            {
                "name": "THINGS YOU SHOULD DO",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Take a look at the examples",
                        "lines": 3
                    },
                    {
                        "name": "Run with warnings enabled",
                        "lines": 3
                    },
                    {
                        "name": "Avoid non-standard encodings",
                        "lines": 3
                    },
                    {
                        "name": "Plan for thrown exceptions",
                        "lines": 27
                    },
                    {
                        "name": "Understand how international characters are represented",
                        "lines": 29
                    }
                ]
            },
            {
                "name": "THINGS I DO THAT YOU SHOULD KNOW ABOUT",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Fuzzing of CRLF and newline on input",
                        "lines": 6
                    },
                    {
                        "name": "Fuzzing of CRLF and newline when decoding",
                        "lines": 12
                    },
                    {
                        "name": "Inability to handle multipart boundaries with embedded newlines",
                        "lines": 4
                    },
                    {
                        "name": "Ignoring non-header headers",
                        "lines": 11
                    },
                    {
                        "name": "Fuzzing of empty multipart preambles",
                        "lines": 28
                    },
                    {
                        "name": "Use of a temp file during parsing",
                        "lines": 22
                    }
                ]
            },
            {
                "name": "A MIME PRIMER",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Glossary",
                        "lines": 46
                    },
                    {
                        "name": "Content types",
                        "lines": 26
                    },
                    {
                        "name": "Content transfer encodings",
                        "lines": 26
                    }
                ]
            },
            {
                "name": "SEE ALSO",
                "lines": 9,
                "subsections": []
            },
            {
                "name": "SUPPORT",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "CHANGE LOG",
                "lines": 5,
                "subsections": []
            },
            {
                "name": "AUTHOR",
                "lines": 11,
                "subsections": []
            },
            {
                "name": "ACKNOWLEDGMENTS",
                "lines": 34,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 5,
                "subsections": []
            }
        ],
        "sections": {
            "NAME": {
                "content": "MIME-tools - modules for parsing (and creating!) MIME entities\n",
                "subsections": []
            },
            "SYNOPSIS": {
                "content": "Here's some pretty basic code for parsing a MIME message, and outputting its decoded components\nto a given directory:\n\nuse MIME::Parser;\n\n### Create parser, and set some parsing options:\nmy $parser = new MIME::Parser;\n$parser->outputunder(\"$ENV{HOME}/mimemail\");\n\n### Parse input:\n$entity = $parser->parse(\\*STDIN) or die \"parse failed\\n\";\n\n### Take a look at the top-level entity (and any parts it has):\n$entity->dumpskeleton;\n\nHere's some code which composes and sends a MIME message containing three parts: a text file, an\nattached GIF, and some more text:\n\nuse MIME::Entity;\n\n### Create the top-level, and set up the mail headers:\n$top = MIME::Entity->build(Type    =>\"multipart/mixed\",\nFrom    => \"me\\@myhost.com\",\nTo      => \"you\\@yourhost.com\",\nSubject => \"Hello, nurse!\");\n\n### Part #1: a simple text document:\n$top->attach(Path=>\"./testin/short.txt\");\n\n### Part #2: a GIF file:\n$top->attach(Path        => \"./docs/mime-sm.gif\",\nType        => \"image/gif\",\nEncoding    => \"base64\");\n\n### Part #3: some literal text:\n$top->attach(Data=>$message);\n\n### Send it:\nopen MAIL, \"| /usr/lib/sendmail -t -oi -oem\" or die \"open: $!\";\n$top->print(\\*MAIL);\nclose MAIL;\n\nFor more examples, look at the scripts in the examples directory of the MIME-tools distribution.\n",
                "subsections": []
            },
            "DESCRIPTION": {
                "content": "MIME-tools is a collection of Perl5 MIME:: modules for parsing, decoding, *and generating*\nsingle- or multipart (even nested multipart) MIME messages. (Yes, kids, that means you can send\nmessages with attached GIF files).\n",
                "subsections": []
            },
            "REQUIREMENTS": {
                "content": "You will need the following installed on your system:\n\nFile::Path\nFile::Spec\nIPC::Open2              (optional)\nMIME::Base64\nMIME::QuotedPrint\nNet::SMTP\nMail::Internet, ...     from the MailTools distribution.\n\nSee the Makefile.PL in your distribution for the most-comprehensive list of prerequisite modules\nand their version numbers.\n",
                "subsections": []
            },
            "A QUICK TOUR": {
                "content": "",
                "subsections": [
                    {
                        "name": "Overview of the classes",
                        "content": "Here are the classes you'll generally be dealing with directly:\n\n(START HERE)            results() .-----------------.\n\\                 .-------->| MIME::          |\n.-----------.   /          | Parser::Results |\n| MIME::    |--'           `-----------------'\n| Parser    |--.           .-----------------.\n`-----------'   \\ filer()  | MIME::          |\n| parse()     `-------->| Parser::Filer   |\n| gives you             `-----------------'\n| a...                                  | outputpath()\n|                                       | determines\n|                                       | path() of...\n|    head()       .--------.            |\n|    returns...   | MIME:: | get()      |\nV       .-------->| Head   | etc...     |\n.--------./          `--------'            |\n.---> | MIME:: |                                 |\n`-----| Entity |           .--------.            |\nparts() `--------'\\          | MIME:: |           /\nreturns            `-------->| Body   |<---------'\nsub-entities    bodyhandle() `--------'\n(if any)        returns...       | open()\n| returns...\n|\nV\n.--------. read()\n| IO::   | getline()\n| Handle | print()\n`--------' etc...\n\nTo illustrate, parsing works this way:\n\n*   The \"parser\" parses the MIME stream. A parser is an instance of \"MIME::Parser\". You hand it\nan input stream (like a filehandle) to parse a message from: if the parse is successful, the\nresult is an \"entity\".\n\n*   A parsed message is represented by an \"entity\". An entity is an instance of \"MIME::Entity\"\n(a subclass of \"Mail::Internet\"). If the message had \"parts\" (e.g., attachments), then those\nparts are \"entities\" as well, contained inside the top-level entity. Each entity has a\n\"head\" and a \"body\".\n\n*   The entity's \"head\" contains information about the message. A \"head\" is an instance of\n\"MIME::Head\" (a subclass of \"Mail::Header\"). It contains information from the message\nheader: content type, sender, subject line, etc.\n\n*   The entity's \"body\" knows where the message data is. You can ask to \"open\" this data source\nfor *reading* or *writing*, and you will get back an \"I/O handle\".\n\n*   You can open() a \"body\" and get an \"I/O handle\" to read/write message data. This handle is\nan object that is basically like an IO::Handle... it can be any class, so long as it\nsupports a small, standard set of methods for reading from or writing to the underlying data\nsource.\n\nA typical multipart message containing two parts -- a textual greeting and an \"attached\" GIF\nfile -- would be a tree of MIME::Entity objects, each of which would have its own MIME::Head.\nLike this:\n\n.--------.\n| MIME:: | Content-type: multipart/mixed\n| Entity | Subject: Happy Samhaine!\n`--------'\n|\n`----.\nparts |\n|   .--------.\n|---| MIME:: | Content-type: text/plain; charset=us-ascii\n|   | Entity | Content-transfer-encoding: 7bit\n|   `--------'\n|   .--------.\n|---| MIME:: | Content-type: image/gif\n| Entity | Content-transfer-encoding: base64\n`--------' Content-disposition: inline;\nfilename=\"hs.gif\"\n"
                    },
                    {
                        "name": "Parsing messages",
                        "content": "You usually start by creating an instance of MIME::Parser and setting up certain parsing\nparameters: what directory to save extracted files to, how to name the files, etc.\n\nYou then give that instance a readable filehandle on which waits a MIME message. If all goes\nwell, you will get back a MIME::Entity object (a subclass of Mail::Internet), which consists\nof...\n\n*   A MIME::Head (a subclass of Mail::Header) which holds the MIME header data.\n\n*   A MIME::Body, which is a object that knows where the body data is. You ask this object to\n\"open\" itself for reading, and it will hand you back an \"I/O handle\" for reading the data:\nthis could be of any class, so long as it conforms to a subset of the IO::Handle interface.\n\nIf the original message was a multipart document, the MIME::Entity object will have a non-empty\nlist of \"parts\", each of which is in turn a MIME::Entity (which might also be a multipart\nentity, etc, etc...).\n\nInternally, the parser (in MIME::Parser) asks for instances of MIME::Decoder whenever it needs\nto decode an encoded file. MIME::Decoder has a mapping from supported encodings (e.g., 'base64')\nto classes whose instances can decode them. You can add to this mapping to try out\nnew/experiment encodings. You can also use MIME::Decoder by itself.\n"
                    },
                    {
                        "name": "Composing messages",
                        "content": "All message composition is done via the MIME::Entity class. For single-part messages, you can\nuse the MIME::Entity/build constructor to create MIME entities very easily.\n\nFor multipart messages, you can start by creating a top-level \"multipart\" entity with\nMIME::Entity::build(), and then use the similar MIME::Entity::attach() method to attach parts to\nthat message. *Please note:* what most people think of as \"a text message with an attached GIF\nfile\" is *really* a multipart message with 2 parts: the first being the text message, and the\nsecond being the GIF file.\n\nWhen building MIME a entity, you'll have to provide two very important pieces of information:\nthe *content type* and the *content transfer encoding*. The type is usually easy, as it is\ndirectly determined by the file format; e.g., an HTML file is \"text/html\". The encoding,\nhowever, is trickier... for example, some HTML files are \"7bit\"-compliant, but others might have\nvery long lines and would need to be sent \"quoted-printable\" for reliability.\n\nSee the section on encoding/decoding for more details, as well as \"A MIME PRIMER\" below.\n"
                    },
                    {
                        "name": "Sending email",
                        "content": "Since MIME::Entity inherits directly from Mail::Internet, you can use the normal Mail::Internet\nmechanisms to send email. For example,\n\n$entity->smtpsend;\n\nEncoding/decoding support\nThe MIME::Decoder class can be used to *encode* as well; this is done when printing MIME\nentities. All the standard encodings are supported (see \"A MIME PRIMER\" below for details):\n\nEncoding:        | Normally used when message contents are:\n-------------------------------------------------------------------\n7bit             | 7-bit data with under 1000 chars/line, or multipart.\n8bit             | 8-bit data with under 1000 chars/line.\nbinary           | 8-bit data with some long lines (or no line breaks).\nquoted-printable | Text files with some 8-bit chars (e.g., Latin-1 text).\nbase64           | Binary files.\n\nWhich encoding you choose for a given document depends largely on (1) what you know about the\ndocument's contents (text vs binary), and (2) whether you need the resulting message to have a\nreliable encoding for 7-bit Internet email transport.\n\nIn general, only \"quoted-printable\" and \"base64\" guarantee reliable transport of all data; the\nother three \"no-encoding\" encodings simply pass the data through, and are only reliable if that\ndata is 7bit ASCII with under 1000 characters per line, and has no conflicts with the multipart\nboundaries.\n\nI've considered making it so that the content-type and encoding can be automatically inferred\nfrom the file's path, but that seems to be asking for trouble... or at least, for Mail::Cap...\n"
                    },
                    {
                        "name": "Message-logging",
                        "content": "MIME-tools is a large and complex toolkit which tries to deal with a wide variety of external\ninput. It's sometimes helpful to see what's really going on behind the scenes. There are several\nkinds of messages logged by the toolkit itself:\n\nDebug messages\nThese are printed directly to the STDERR, with a prefix of \"MIME-tools: debug\".\n\nDebug message are only logged if you have turned \"debugging\" on in the MIME::Tools\nconfiguration.\n\nWarning messages\nThese are logged by the standard Perl warn() mechanism to indicate an unusual situation.\nThey all have a prefix of \"MIME-tools: warning\".\n\nWarning messages are only logged if $^W is set true and MIME::Tools is not configured to be\n\"quiet\".\n\nError messages\nThese are logged by the standard Perl warn() mechanism to indicate that something actually\nfailed. They all have a prefix of \"MIME-tools: error\".\n\nError messages are only logged if $^W is set true and MIME::Tools is not configured to be\n\"quiet\".\n\nUsage messages\nUnlike \"typical\" warnings above, which warn about problems processing data, usage-warnings\nare for alerting developers of deprecated methods and suspicious invocations.\n\nUsage messages are currently only logged if $^W is set true and MIME::Tools is not\nconfigured to be \"quiet\".\n\nWhen a MIME::Parser (or one of its internal helper classes) wants to report a message, it\ngenerally does so by recording the message to the MIME::Parser::Results object immediately\nbefore invoking the appropriate function above. That means each parsing run has its own\ntrace-log which can be examined for problems.\n"
                    },
                    {
                        "name": "Configuring the toolkit",
                        "content": "If you want to tweak the way this toolkit works (for example, to turn on debugging), use the\nroutines in the MIME::Tools module.\n\ndebugging\nTurn debugging on or off. Default is false (off).\n\nMIME::Tools->debugging(1);\n\nquiet\nTurn the reporting of warning/error messages on or off. Default is true, meaning that these\nmessage are silenced.\n\nMIME::Tools->quiet(1);\n\nversion\nReturn the toolkit version.\n\nprint MIME::Tools->version, \"\\n\";\n"
                    }
                ]
            },
            "THINGS YOU SHOULD DO": {
                "content": "",
                "subsections": [
                    {
                        "name": "Take a look at the examples",
                        "content": "The MIME-Tools distribution comes with an \"examples\" directory. The scripts in there are\nbasically just tossed-together, but they'll give you some ideas of how to use the parser.\n"
                    },
                    {
                        "name": "Run with warnings enabled",
                        "content": "*Always* run your Perl script with \"-w\". If you see a warning about a deprecated method, change\nyour code ASAP. This will ease upgrades tremendously.\n"
                    },
                    {
                        "name": "Avoid non-standard encodings",
                        "content": "Don't try to MIME-encode using the non-standard MIME encodings. It's just not a good practice if\nyou want people to be able to read your messages.\n"
                    },
                    {
                        "name": "Plan for thrown exceptions",
                        "content": "For example, if your mail-handling code absolutely must not die, then perform mail parsing like\nthis:\n\n$entity = eval { $parser->parse(\\*INPUT) };\n\nParsing is a complex process, and some components may throw exceptions if seriously-bad things\nhappen. Since \"seriously-bad\" is in the eye of the beholder, you're better off *catching*\npossible exceptions instead of asking me to propagate \"undef\" up the stack. Use of exceptions in\nreusable modules is one of those religious issues we're never all going to agree upon;\nthankfully, that's what \"eval{}\" is good for.\n\nCheck the parser results for warnings/errors\nAs of 5.3xx, the parser tries extremely hard to give you a MIME::Entity. If there were any\nproblems, it logs warnings/errors to the underlying \"results\" object (see\nMIME::Parser::Results). Look at that object after each parse. Print out the warnings and errors,\n*especially* if messages don't parse the way you thought they would.\n\nDon't plan on printing exactly what you parsed!\n*Parsing is a (slightly) lossy operation.* Because of things like ambiguities in\nbase64-encoding, the following is *not* going to spit out its input unchanged in all cases:\n\n$entity = $parser->parse(\\*STDIN);\n$entity->print(\\*STDOUT);\n\nIf you're using MIME::Tools to process email, remember to save the data you parse if you want to\nsend it on unchanged. This is vital for things like PGP-signed email.\n"
                    },
                    {
                        "name": "Understand how international characters are represented",
                        "content": "The MIME standard allows for text strings in headers to contain characters from any character\nset, by using special sequences which look like this:\n\n=?ISO-8859-1?Q?KeldJ=F8rnSimonsen?=\n\nTo be consistent with the existing Mail::Field classes, MIME::Tools does *not* automatically\nunencode these strings, since doing so would lose the character-set information and interfere\nwith the parsing of fields (see \"decodeheaders\" in MIME::Parser for a full explanation). That\nmeans you should be prepared to deal with these encoded strings.\n\nThe most common question then is, how do I decode these encoded strings? The answer depends on\nwhat you want to decode them *to*: ASCII, Latin1, UTF-8, etc. Be aware that your \"target\"\nrepresentation may not support all possible character sets you might encounter; for example,\nLatin1 (ISO-8859-1) has no way of representing Big5 (Chinese) characters. A common practice is\nto represent \"untranslateable\" characters as \"?\"s, or to ignore them completely.\n\nTo unencode the strings into some of the more-popular Western byte representations (e.g.,\nLatin1, Latin2, etc.), you can use the decoders in MIME::WordDecoder (see MIME::WordDecoder).\nThe simplest way is by using \"unmime()\", a function wrapped around your \"default\" decoder, as\nfollows:\n\nuse MIME::WordDecoder;\n...\n$subject = unmime $entity->head->get('subject');\n\nOne place this *is* done automatically is in extracting the recommended filename for a part\nwhile parsing. That's why you should start by setting up the best \"default\" decoder if the\ndefault target of Latin1 isn't to your liking.\n"
                    }
                ]
            },
            "THINGS I DO THAT YOU SHOULD KNOW ABOUT": {
                "content": "",
                "subsections": [
                    {
                        "name": "Fuzzing of CRLF and newline on input",
                        "content": "RFC 2045 dictates that MIME streams have lines terminated by CRLF (\"\\r\\n\"). However, it is\nextremely likely that folks will want to parse MIME streams where each line ends in the local\nnewline character \"\\n\" instead.\n\nAn attempt has been made to allow the parser to handle both CRLF and newline-terminated input.\n"
                    },
                    {
                        "name": "Fuzzing of CRLF and newline when decoding",
                        "content": "The \"7bit\" and \"8bit\" decoders will decode both a \"\\n\" and a \"\\r\\n\" end-of-line sequence into a\n\"\\n\".\n\nThe \"binary\" decoder (default if no encoding specified) still outputs stuff verbatim... so a\nMIME message with CRLFs and no explicit encoding will be output as a text file that, on many\nsystems, will have an annoying ^M at the end of each line... *but this is as it should be*.\n\nFuzzing of CRLF and newline when encoding/composing\nTODO FIXME All encoders currently output the end-of-line sequence as a \"\\n\", with the assumption\nthat the local mail agent will perform the conversion from newline to CRLF when sending the\nmail. However, there probably should be an option to output CRLF as per RFC 2045\n"
                    },
                    {
                        "name": "Inability to handle multipart boundaries with embedded newlines",
                        "content": "Let's get something straight: this is an evil, EVIL practice. If your mailer creates multipart\nboundary strings that contain newlines, give it two weeks notice and find another one. If your\nmail robot receives MIME mail like this, regard it as syntactically incorrect, which it is.\n"
                    },
                    {
                        "name": "Ignoring non-header headers",
                        "content": "People like to hand the parser raw messages straight from POP3 or from a mailbox. There is often\npredictable non-header information in front of the real headers; e.g., the initial \"From\" line\nin the following message:\n\nFrom - Wed Mar 22 02:13:18 2000\nReturn-Path: <eryq@zeegee.com>\nSubject: Hello\n\nThe parser simply ignores such stuff quietly. Perhaps it shouldn't, but most people seem to want\nthat behavior.\n"
                    },
                    {
                        "name": "Fuzzing of empty multipart preambles",
                        "content": "Please note that there is currently an ambiguity in the way preambles are parsed in. The\nfollowing message fragments *both* are regarded as having an empty preamble (where \"\\n\"\nindicates a newline character):\n\nContent-type: multipart/mixed; boundary=\"xyz\"\\n\nSubject: This message (#1) has an empty preamble\\n\n\\n\n--xyz\\n\n...\n\nContent-type: multipart/mixed; boundary=\"xyz\"\\n\nSubject: This message (#2) also has an empty preamble\\n\n\\n\n\\n\n--xyz\\n\n...\n\nIn both cases, the *first* completely-empty line (after the \"Subject\") marks the end of the\nheader.\n\nBut we should clearly ignore the *second* empty line in message #2, since it fills the role of\n*\"the newline which is only there to make sure that the boundary is at the beginning of a\nline\"*. Such newlines are *never* part of the content preceding the boundary; thus, there is no\npreamble \"content\" in message #2.\n\nHowever, it seems clear that message #1 *also* has no preamble \"content\", and is in fact merely\na compact representation of an empty preamble.\n"
                    },
                    {
                        "name": "Use of a temp file during parsing",
                        "content": "*Why not do everything in core?* Although the amount of core available on even a modest home\nsystem continues to grow, the size of attachments continues to grow with it. I wanted to make\nsure that even users with small systems could deal with decoding multi-megabyte sounds and movie\nfiles. That means not being core-bound.\n\nAs of the released 5.3xx, MIME::Parser gets by with only one temp file open per parser. This\ntemp file provides a sort of infinite scratch space for dealing with the current message part.\nIt's fast and lightweight, but you should know about it anyway.\n\nWhy do I assume that MIME objects are email objects?\nAchim Bohnet once pointed out that MIME headers do nothing more than store a collection of\nattributes, and thus could be represented as objects which don't inherit from Mail::Header.\n\nI agree in principle, but RFC 2045 says otherwise. RFC 2045 [MIME] headers are a syntactic\nsubset of RFC-822 [email] headers. Perhaps a better name for these modules would have been\nRFC1521:: instead of MIME::, but we're a little beyond that stage now.\n\nWhen I originally wrote these modules for the CPAN, I agonized for a long time about whether or\nnot they really should subclass from Mail::Internet (then at version 1.17). Thanks to Graham\nBarr, who graciously evolved MailTools 1.06 to be more MIME-friendly, unification was achieved\nat MIME-tools release 2.0. The benefits in reuse alone have been substantial.\n"
                    }
                ]
            },
            "A MIME PRIMER": {
                "content": "So you need to parse (or create) MIME, but you're not quite up on the specifics? No problem...\n",
                "subsections": [
                    {
                        "name": "Glossary",
                        "content": "Here are some definitions adapted from RFC 1521 (predecessor of the current RFC 204[56789]\ndefining MIME) explaining the terminology we use; each is accompanied by the equivalent in\nMIME:: module terms...\n\nattachment\nAn \"attachment\" is common slang for any part of a multipart message -- except, perhaps, for\nthe first part, which normally carries a user message describing the attachments that follow\n(e.g.: \"Hey dude, here's that GIF file I promised you.\").\n\nIn our system, an attachment is just a MIME::Entity under the top-level entity, probably one\nof its parts.\n\nbody\nThe \"body\" of an entity is that portion of the entity which follows the header and which\ncontains the real message content. For example, if your MIME message has a GIF file\nattachment, then the body of that attachment is the base64-encoded GIF file itself.\n\nA body is represented by an instance of MIME::Body. You get the body of an entity by sending\nit a bodyhandle() message.\n\nbody part\nOne of the parts of the body of a multipart /entity. A body part has a /header and a /body,\nso it makes sense to speak about the body of a body part.\n\nSince a body part is just a kind of entity, it's represented by an instance of MIME::Entity.\n\nentity\nAn \"entity\" means either a /message or a /body part. All entities have a /header and a\n/body.\n\nAn entity is represented by an instance of MIME::Entity. There are instance methods for\nrecovering the header (a MIME::Head) and the body (a MIME::Body).\n\nheader\nThis is the top portion of the MIME message, which contains the \"Content-type\",\n\"Content-transfer-encoding\", etc. Every MIME entity has a header, represented by an instance\nof MIME::Head. You get the header of an entity by sending it a head() message.\n\nmessage\nA \"message\" generally means the complete (or \"top-level\") message being transferred on a\nnetwork.\n\nThere currently is no explicit package for \"messages\"; under MIME::, messages are streams of\ndata which may be read in from files or filehandles. You can think of the MIME::Entity\nreturned by the MIME::Parser as representing the full message.\n"
                    },
                    {
                        "name": "Content types",
                        "content": "This indicates what kind of data is in the MIME message, usually as *majortype/minortype*. The\nstandard major types are shown below. A more-comprehensive listing may be found in RFC-2046.\n\napplication\nData which does not fit in any of the other categories, particularly data to be processed by\nsome type of application program. \"application/octet-stream\", \"application/gzip\",\n\"application/postscript\"...\n\naudio\nAudio data. \"audio/basic\"...\n\nimage\nGraphics data. \"image/gif\", \"image/jpeg\"...\n\nmessage\nA message, usually another mail or MIME message. \"message/rfc822\"...\n\nmultipart\nA message containing other messages. \"multipart/mixed\", \"multipart/alternative\"...\n\ntext\nTextual data, meant for humans to read. \"text/plain\", \"text/html\"...\n\nvideo\nVideo or video+audio data. \"video/mpeg\"...\n"
                    },
                    {
                        "name": "Content transfer encodings",
                        "content": "This is how the message body is packaged up for safe transit. There are the 5 major MIME\nencodings. A more-comprehensive listing may be found in RFC-2045.\n\n7bit\nNo encoding is done at all. This label simply asserts that no 8-bit characters are present,\nand that lines do not exceed 1000 characters in length (including the CRLF).\n\n8bit\nNo encoding is done at all. This label simply asserts that the message might contain 8-bit\ncharacters, and that lines do not exceed 1000 characters in length (including the CRLF).\n\nbinary\nNo encoding is done at all. This label simply asserts that the message might contain 8-bit\ncharacters, and that lines may exceed 1000 characters in length. Such messages are the\n*least* likely to get through mail gateways.\n\nbase64\nA standard encoding, which maps arbitrary binary data to the 7bit domain. Like \"uuencode\",\nbut very well-defined. This is how you should send essentially binary information (tar\nfiles, GIFs, JPEGs, etc.).\n\nquoted-printable\nA standard encoding, which maps arbitrary line-oriented data to the 7bit domain. Useful for\nencoding messages which are textual in nature, yet which contain non-ASCII characters (e.g.,\nLatin-1, Latin-2, or any other 8-bit alphabet).\n"
                    }
                ]
            },
            "SEE ALSO": {
                "content": "MIME::Parser, MIME::Head, MIME::Body, MIME::Entity, MIME::Decoder, Mail::Header, Mail::Internet\n\nAt the time of this writing, the MIME-tools homepage was\nhttp://www.mimedefang.org/static/mime-tools.php. Check there for updates and support.\n\nThe MIME format is documented in RFCs 1521-1522, and more recently in RFCs 2045-2049.\n\nThe MIME header format is an outgrowth of the mail header format documented in RFC 822.\n",
                "subsections": []
            },
            "SUPPORT": {
                "content": "Please file support requests via rt.cpan.org.\n",
                "subsections": []
            },
            "CHANGE LOG": {
                "content": "Released as MIME-parser (1.0): 28 April 1996. Released as MIME-tools (2.0): Halloween 1996.\nReleased as MIME-tools (4.0): Christmas 1997. Released as MIME-tools (5.0): Mother's Day 2000.\n\nSee ChangeLog file for full details.\n",
                "subsections": []
            },
            "AUTHOR": {
                "content": "Eryq (eryq@zeegee.com), ZeeGee Software Inc (http://www.zeegee.com). Dianne Skoll\n(dfs@roaringpenguin.com) http://www.roaringpenguin.com.\n\nCopyright (c) 1998, 1999 by ZeeGee Software Inc (www.zeegee.com). Copyright (c) 2004 by Roaring\nPenguin Software Inc (www.roaringpenguin.com)\n\nThis program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee the COPYING file in the distribution for details.\n",
                "subsections": []
            },
            "ACKNOWLEDGMENTS": {
                "content": "This kit would not have been possible but for the direct contributions of the following:\n\nGisle Aas             The MIME encoding/decoding modules.\nLaurent Amon          Bug reports and suggestions.\nGraham Barr           The new MailTools.\nAchim Bohnet          Numerous good suggestions, including the I/O model.\nKent Boortz           Initial code for RFC-1522-decoding of MIME headers.\nAndreas Koenig        Numerous good ideas, tons of beta testing,\nand help with CPAN-friendly packaging.\nIgor Starovoitov      Bug reports and suggestions.\nJason L Tibbitts III  Bug reports, suggestions, patches.\n\nNot to mention the Accidental Beta Test Team, whose bug reports (and comments) have been\ninvaluable in improving the whole:\n\nPhil Abercrombie\nMike Blazer\nBrandon Browning\nKurt Freytag\nSteve Kilbane\nJake Morrison\nRolf Nelson\nJoel Noble\nMichael W. Normandin\nTim Pierce\nAndrew Pimlott\nDragomir R. Radev\nNickolay Saukh\nRussell Sutherland\nLarry Virden\nZyx\n\nPlease forgive me if I've accidentally left you out. Better yet, email me, and I'll put you in.\n",
                "subsections": []
            },
            "LICENSE": {
                "content": "This program is free software; you can redistribute it and/or modify it under the same terms as\nPerl itself.\n\nSee the COPYING file for more details.\n",
                "subsections": []
            }
        }
    }
}