{
    "content": [
        {
            "type": "text",
            "text": "# Mail::Message (perldoc)\n\n**Summary:** Mail::Message - general message object\n\n**Synopsis:** use Mail::Box::Manager;\nmy $mgr    = Mail::Box::Manager->new;\nmy $folder = $mgr->open(folder => 'InBox');\nmy $msg    = $folder->message(2);    # $msg is a Mail::Message now\nmy $subject = $msg->subject;         # The message's subject\nmy @cc      = $msg->cc;              # List of Mail::Address'es\nmy Mail::Message::Head $head = $msg->head;\nmy Mail::Message::Body $body = $msg->decoded;\n$msg->decoded->print($outfile);\n# Send a simple email\nMail::Message->build\n( To             => 'you@example.com'\n, From           => 'me@example.com'\n, Subject        => \"My subject\"\n, data           => \"Some plain text content\"\n)->send(via => 'postfix');\nmy $replymsg = Mail::Message->reply(...);\nmy $frwdmsg  = Mail::Message->forward(...);\n\n## Section Outline\n\n- **NAME** (2 lines)\n- **INHERITANCE** (19 lines)\n- **SYNOPSIS** (23 lines)\n- **DESCRIPTION** (17 lines)\n- **METHODS** (2 lines) — 10 subsections\n  - Constructors (107 lines)\n  - Constructing a message (65 lines)\n  - The message (118 lines)\n  - The header (152 lines)\n  - The body (85 lines)\n  - Flags (98 lines)\n  - The whole message as text (16 lines)\n  - Internals (91 lines)\n  - Error handling (55 lines)\n  - Cleanup (22 lines)\n- **DETAILS** (1 lines) — 4 subsections\n  - Structure of a Message (25 lines)\n  - Message object implementation (30 lines)\n  - Message class implementation (41 lines)\n  - Labels (92 lines)\n- **DIAGNOSTICS** (45 lines)\n- **SEE ALSO** (3 lines)\n- **LICENSE** (6 lines)\n\n## Full Content\n\n### NAME\n\nMail::Message - general message object\n\n### INHERITANCE\n\nMail::Message has extra code in\nMail::Message::Construct\nMail::Message::Construct::Bounce\nMail::Message::Construct::Build\nMail::Message::Construct::Forward\nMail::Message::Construct::Read\nMail::Message::Construct::Rebuild\nMail::Message::Construct::Reply\nMail::Message::Construct::Text\n\nMail::Message\nis a Mail::Reporter\n\nMail::Message is extended by\nMail::Box::Message\nMail::Message::Dummy\nMail::Message::Part\nMail::Message::Replace::MailInternet\n\n### SYNOPSIS\n\nuse Mail::Box::Manager;\nmy $mgr    = Mail::Box::Manager->new;\nmy $folder = $mgr->open(folder => 'InBox');\nmy $msg    = $folder->message(2);    # $msg is a Mail::Message now\n\nmy $subject = $msg->subject;         # The message's subject\nmy @cc      = $msg->cc;              # List of Mail::Address'es\n\nmy Mail::Message::Head $head = $msg->head;\nmy Mail::Message::Body $body = $msg->decoded;\n$msg->decoded->print($outfile);\n\n# Send a simple email\nMail::Message->build\n( To             => 'you@example.com'\n, From           => 'me@example.com'\n, Subject        => \"My subject\"\n, data           => \"Some plain text content\"\n)->send(via => 'postfix');\n\nmy $replymsg = Mail::Message->reply(...);\nmy $frwdmsg  = Mail::Message->forward(...);\n\n### DESCRIPTION\n\nA \"Mail::Message\" object is a container for MIME-encoded message\ninformation, as defined by RFC2822. Everything what is not specificaly\nrelated to storing the messages in mailboxes (folders) is implemented in\nthis class. Methods which are related to folders is implemented in the\nMail::Box::Message extension.\n\nThe main methods are get(), to get information from a message header\nfield, and decoded() to get the intended content of a message. But there\nare many more which can assist your program.\n\nComplex message handling, like construction of replies and forwards, are\nimplemented in separate packages which are autoloaded into this class.\nThis means you can simply use these methods as if they are part of this\nclass. Those package add functionality to all kinds of message objects.\n\nExtends \"DESCRIPTION\" in Mail::Reporter.\n\n### METHODS\n\nExtends \"METHODS\" in Mail::Reporter.\n\n#### Constructors\n\nExtends \"Constructors\" in Mail::Reporter.\n\n$obj->clone(%options)\nCreate a copy of this message. Returned is a \"Mail::Message\" object.\nThe head and body, the log and trace levels are taken. Labels are\ncopied with the message, but the delete and modified flags are not.\n\nBE WARNED: the clone of any kind of message (or a message part) will\nalways be a \"Mail::Message\" object. For example, a\nMail::Box::Message's clone is detached from the folder of its\noriginal. When you use Mail::Box::addMessage() with the cloned\nmessage at hand, then the clone will automatically be coerced into\nthe right message type to be added.\n\nSee also Mail::Box::Message::copyTo() and\nMail::Box::Message::moveTo().\n\n-Option      --Default\nshallow       <false>\nshallowbody  <false>\nshallowhead  <false>\n\nshallow => BOOLEAN\nWhen a shallow clone is made, the header and body of the message\nwill not be cloned, but shared. This is quite dangerous: for\ninstance in some folder types, the header fields are used to store\nfolder flags. When one of both shallow clones change the flags,\nthat will update the header and thereby be visible in both.\n\nThere are situations where a shallow clone can be used safely. For\ninstance, when Mail::Box::Message::moveTo() is used and you are\nsure that the original message cannot get undeleted after the\nmove.\n\nshallowbody => BOOLEAN\nA rather safe bet, because you are not allowed to modify the body\nof a message: you may only set a new body with body().\n\nshallowhead => BOOLEAN\nOnly the head uses is reused, not the body. This is probably a bad\nchoice, because the header fields can be updated, for instance\nwhen labels change.\n\nexample:\n\n$copy = $msg->clone;\n\nMail::Message->new(%options)\n-Option    --Defined in     --Default\nbody                         undef\nbodytype                    Mail::Message::Body::Lines\ndeleted                      <false>\nfieldtype                   undef\nhead                         undef\nheadtype                    Mail::Message::Head::Complete\nlabels                       {}\nlog         Mail::Reporter   'WARNINGS'\nmessageId                    undef\nmodified                     <false>\ntrace       Mail::Reporter   'WARNINGS'\ntrusted                      <false>\n\nbody => OBJECT\nInstantiate the message with a body which has been created\nsomewhere before the message is constructed. The OBJECT must be a\nsub-class of Mail::Message::Body. See also body() and storeBody().\n\nbodytype => CLASS\nDefault type of body to be created for readBody().\n\ndeleted => BOOLEAN\nIs the file deleted from the start?\n\nfieldtype => CLASS\nhead => OBJECT\nInstantiate the message with a head which has been created\nsomewhere before the message is constructed. The OBJECT must be a\n(sub-)class of Mail::Message::Head. See also head().\n\nheadtype => CLASS\nDefault type of head to be created for readHead().\n\nlabels => ARRAY|HASH\nInitial values of the labels. In case of Mail::Box::Message's,\nthis shall reflect the state the message is in. For newly\nconstructed Mail::Message's, this may be anything you want,\nbecause coerce() will take care of the folder specifics once the\nmessage is added to one.\n\nlog => LEVEL\nmessageId => STRING\nThe id on which this message can be recognized. If none specified\nand not defined in the header --but one is needed-- there will be\none assigned to the message to be able to pass unique message-ids\nbetween objects.\n\nmodified => BOOLEAN\nFlags this message as being modified from the beginning on.\nUsually, modification is auto-detected, but there may be reasons\nto be extra explicit.\n\ntrace => LEVEL\ntrusted => BOOLEAN\nIs this message from a trusted source? If not, the content must be\nchecked before use. This checking will be performed when the body\ndata is decoded or used for transmission.\n\n#### Constructing a message\n\n$obj->bounce( [<$rgobject|%options>] )\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Bounce\n\nMail::Message->build( [$message|$part|$body], $content )\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Build\n\nMail::Message->buildFromBody($body, [$head], $headers)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Build\n\n$obj->forward(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardAttach(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardEncapsulate(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardInline(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardNo(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardPostlude()\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardPrelude()\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\n$obj->forwardSubject(STRING)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Forward\n\nMail::Message->read($fh|STRING|SCALAR|ARRAY, %options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Read\n\n$obj->rebuild(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Rebuild\n\n$obj->reply(%options)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Reply\n\n$obj->replyPrelude( [STRING|$field|$address|ARRAY-$of-$things] )\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Reply\n\n$obj->replySubject(STRING)\nMail::Message->replySubject(STRING)\nInherited, see \"Constructing a message\" in\nMail::Message::Construct::Reply\n\n#### The message\n\n$obj->container()\nIf the message is a part of another message, \"container\" returns the\nreference to the containing body.\n\nexample:\n\nmy Mail::Message $msg = ...\nreturn unless $msg->body->isMultipart;\nmy $part   = $msg->body->part(2);\n\nreturn unless $part->body->isMultipart;\nmy $nested = $part->body->part(3);\n\n$nested->container;  # returns $msg->body\n$nested->toplevel;   # returns $msg\n$msg->container;     # returns undef\n$msg->toplevel;      # returns $msg\n$msg->isPart;        # returns false\n$part->isPart;       # returns true\n\n$obj->isDummy()\nDummy messages are used to fill holes in linked-list and such, where\nonly a message-id is known, but not the place of the header of body\ndata.\n\nThis method is also available for Mail::Message::Dummy objects,\nwhere this will return \"true\". On any extension of \"Mail::Message\",\nthis will return \"false\".\n\n$obj->isPart()\nReturns true if the message is a part of another message. This is\nthe case for Mail::Message::Part extensions of \"Mail::Message\".\n\n$obj->messageId()\nRetrieve the message's id. Every message has a unique message-id.\nThis id is used mainly for recognizing discussion threads.\n\n$obj->partNumber()\nReturns a string representing the location of this part. In case the\ntop message is a single message, 'undef' is returned. When it is a\nmultipart, '1' up to the number of multiparts is returned. A\nmulti-level nested part may for instance return '2.5.1'.\n\nUsually, this string is very short. Numbering follows the IMAP4\ndesign, see RFC2060 section 6.4.5.\n\n$obj->print( [$fh] )\nPrint the message to the FILE-HANDLE, which defaults to the selected\nfilehandle, without the encapsulation sometimes required by a folder\ntype, like write() does.\n\nexample:\n\n$message->print(\\*STDERR);  # to the error output\n$message->print;            # to the selected file\n\nmy $out = IO::File->new('out', 'w');\n$message->print($out);      # no encapsulation: no folder\n$message->write($out);      # with encapsulation: is folder.\n\n$obj->send( [$mailer], %options )\nTransmit the message to anything outside this Perl program. Returns\nfalse when sending failed even after retries.\n\nThe optional $mailer is a Mail::Transport::Send object. When the\n$mailer is not specified, one will be created and kept as default\nfor the next messages as well.\n\nThe %options are mailer specific, and a mixture of what is usable\nfor the creation of the mailer object and the sending itself.\nTherefore, see for possible options Mail::Transport::Send::new() and\nMail::Transport::Send::send(). That object also provides a\n\"trySend()\" method which gives more low-level control.\n\nexample:\n\n$message->send;\n\nis short (but little less flexibile) for\n\nmy $mailer = Mail::Transport::SMTP->new(@smtpopts);\n$mailer->send($message, @sendopts);\n\nSee examples/send.pl in the distribution of Mail::Box.\n\nexample:\n\n$message->send(via => 'sendmail')\n\n$obj->size()\nReturns an estimated size of the whole message in bytes. In many\noccasions, the functions which process the message further, for\ninstance send() or print() will need to add/change header lines or\nadd CR characters, so the size is only an estimate with a few\npercent margin of the real result.\n\nThe computation assumes that each line ending is represented by one\ncharacter (like UNIX, MacOS, and sometimes Cygwin), and not two\ncharacters (like Windows and sometimes Cygwin). If you write the\nmessage to file on a system which uses CR and LF to end a single\nline (all Windows versions), the result in that file will be at\nleast nrLines() larger than this method returns.\n\n$obj->toplevel()\nReturns a reference to the main message, which will be the current\nmessage if the message is not part of another message.\n\n$obj->write( [$fh] )\nWrite the message to the FILE-HANDLE, which defaults to the selected\n$fh, with all surrounding information which is needed to put it\ncorrectly in a folder file.\n\nIn most cases, the result of \"write\" will be the same as with\nprint(). The main exception is for Mbox folder messages, which will\nget printed with their leading 'From ' line and a trailing blank.\nEach line of their body which starts with 'From ' will have an '>'\nadded in front.\n\n#### The header\n\n$obj->bcc()\nReturns the addresses which are specified on the \"Bcc\" header line\n(or lines) A list of Mail::Address objects is returned. \"Bcc\" stands\nfor *Blind Carbon Copy*: destinations of the message which are not\nlisted in the messages actually sent. So, this field will be empty\nfor received messages, but may be present in messages you construct\nyourself.\n\n$obj->cc()\nReturns the addresses which are specified on the \"Cc\" header line\n(or lines) A list of Mail::Address objects is returned. \"Cc\" stands\nfor *Carbon Copy*; the people addressed on this line receive the\nmessage informational, and are usually not expected to reply on its\ncontent.\n\n$obj->date()\nMethod has been removed for reasons of consistency. Use timestamp()\nor \"$msg->head->get('Date')\".\n\n$obj->destinations()\nReturns a list of Mail::Address objects which contains the combined\ninfo of active \"To\", \"Cc\", and \"Bcc\" addresses. Double addresses are\nremoved if detectable.\n\n$obj->from()\nReturns the addresses from the senders. It is possible to have more\nthan one address specified in the \"From\" field of the message,\naccording to the specification. Therefore a list of Mail::Address\nobjects is returned, which usually has length 1.\n\nIf you need only one address from a sender, for instance to create a\n\"original message by\" line in constructed forwarded message body,\nthen use sender().\n\nexample: using from() to get all sender addresses\n\nmy @from = $message->from;\n\n$obj->get($fieldname)\nReturns the value which is stored in the header field with the\nspecified name. The $fieldname is case insensitive. The *unfolded\nbody* of the field is returned, stripped from any attributes. See\nMail::Message::Field::body().\n\nIf the field has multiple appearances in the header, only the last\ninstance is returned. If you need more complex handing of fields,\nthen call Mail::Message::Head::get() yourself. See study() when you\nwant to be smart, doing the better (but slower) job.\n\nexample: the get() short-cut for header fields\n\nprint $msg->get('Content-Type'), \"\\n\";\n\nIs equivalent to:\n\nprint $msg->head->get('Content-Type')->body, \"\\n\";\n\n$obj->guessTimestamp()\nReturn an estimate on the time this message was sent. The data is\nderived from the header, where it can be derived from the \"date\" and\n\"received\" lines. For MBox-like folders you may get the date from\nthe from-line as well.\n\nThis method may return \"undef\" if the header is not parsed or only\npartially known. If you require a time, then use the timestamp()\nmethod, described below.\n\nexample: using guessTimestamp() to get a transmission date\n\nprint \"Receipt \", ($message->timestamp || 'unknown'), \"\\n\";\n\n$obj->head( [$head] )\nReturn (optionally after setting) the $head of this message. The\nhead must be an (sub-)class of Mail::Message::Head. When the head is\nadded, status information is taken from it and transformed into\nlabels. More labels can be added by the LABELS hash. They are added\nlater.\n\nexample:\n\nmy $header = Mail::Message::Head->new;\n$msg->head($header);    # set\nmy $head = $msg->head;  # get\n\n$obj->nrLines()\nReturns the number of lines used for the whole message.\n\n$obj->sender()\nReturns exactly one address, which is the originator of this\nmessage. The returned Mail::Address object is taken from the\n\"Sender\" header field, unless that field does not exists, in which\ncase the first address from the \"From\" field is taken. If none of\nboth provide an address, \"undef\" is returned.\n\nexample: using sender() to get exactly one sender address\n\nmy $sender = $message->sender;\nprint \"Reply to: \", $sender->format, \"\\n\" if defined $sender;\n\n$obj->study($fieldname)\nStudy the content of a field, like get() does, with as main\ndifference that a Mail::Message::Field::Full object is returned.\nThese objects stringify to an utf8 decoded representation of the\ndata contained in the field, where get() does not decode. When the\nfield does not exist, then \"undef\" is returned. See\nMail::Message::Field::study().\n\nexample: the study() short-cut for header fields\n\nprint $msg->study('to'), \"\\n\";\n\nIs equivalent to:\n\nprint $msg->head->study('to'), \"\\n\";       # and\nprint $msg->head->get('to')->study, \"\\n\";\n\nor better: if(my $to = $msg->study('to')) { print \"$to\\n\" } if(my\n$to = $msg->get('to')) { print $to->study, \"\\n\" }\n\n$obj->subject()\nReturns the message's subject, or the empty string. The subject may\nhave encoded characters in it; use study() to get rit of that.\n\nexample: using subject() to get the message's subject\n\nprint $msg->subject;\nprint $msg->study('subject');\n\n$obj->timestamp()\nGet a good timestamp for the message, doesn't matter how much work\nit is. The value returned is compatible with the platform dependent\nresult of function time().\n\nIn these days, the timestamp as supplied by the message (in the\n\"Date\" field) is not trustable at all: many spammers produce illegal\nor unreal dates to influence their location in the displayed folder.\n\nTo start, the received headers are tried for a date (see\nMail::Message::Head::Complete::recvstamp()) and only then the \"Date\"\nfield. In very rare cases, only with some locally produced messages,\nno stamp can be found.\n\n$obj->to()\nReturns the addresses which are specified on the \"To\" header line\n(or lines). A list of Mail::Address objects is returned. The people\naddressed here are the targets of the content, and should read it\ncontents carefully.\n\nexample: using to() to get all primar destination addresses\n\nmy @to = $message->to;\n\n#### The body\n\n$obj->body( [$body] )\nReturn the body of this message. BE WARNED that this returns you an\nobject which may be encoded: use decoded() to get a body with usable\ndata.\n\nWith options, a new $body is set for this message. This is not for\nnormal use unless you understand the consequences: you change the\nmessage content without changing the message-ID. The right way to go\nis via\n\n$message = Mail::Message->buildFromBody($body);  # or\n$message = Mail::Message->build($body);          # or\n$message = $origmsg->forward(body => $body);\n\nThe $body must be an (sub-)class of Mail::Message::Body. In this\ncase, information from the specified body will be copied into the\nheader. The body object will be encoded if needed, because messages\nwritten to file or transmitted shall not contain binary data. The\nconverted body is returned.\n\nWhen $body is \"undef\", the current message body will be dissected\nfrom the message. All relation will be cut. The body is returned,\nand can be connected to a different message.\n\nexample:\n\nmy $body      = $msg->body;\nmy @encoded   = $msg->body->lines;\n\nmy $new       = Mail::Message::Body->new(mimetype => 'text/html');\nmy $converted = $msg->body($new);\n\n$obj->contentType()\nReturns the content type header line, or \"text/plain\" if it is not\ndefined. The parameters will be stripped off.\n\n$obj->decoded(%options)\nDecodes the body of this message, and returns it as a body object.\nShort for \"$msg->body->decoded\" All %options are passed-on.\n\n$obj->encode(%options)\nEncode the message to a certain format. Read the details in the\ndedicated manual page Mail::Message::Body::Encode. The %options\nwhich can be specified here are those of the\nMail::Message::Body::encode() method.\n\n$obj->isMultipart()\nCheck whether this message is a multipart message (has attachments).\nTo find this out, we need at least the header of the message; there\nis no need to read the body of the message to detect this.\n\n$obj->isNested()\nReturns \"true\" for \"message/rfc822\" messages and message parts.\n\n$obj->parts( [<'ALL'|'ACTIVE'|'DELETED'|'RECURSE'|$filter>] )\nReturns the *parts* of this message. Maybe a bit inconvenient: it\nreturns the message itself when it is not a multipart.\n\nUsually, the term *part* is used with *multipart* messages: messages\nwhich are encapsulated in the body of a message. To abstract this\nconcept: this method will return you all header-body combinations\nwhich are stored within this message except the multipart and\nmessage/rfc822 wrappers. Objects returned are \"Mail::Message\"'s and\nMail::Message::Part's.\n\nThe option default to 'ALL', which will return the message itself\nfor single-parts, the nested content of a message/rfc822 object,\nrespectively the parts of a multipart without recursion. In case of\n'RECURSE', the parts of multiparts will be collected recursively.\nThis option cannot be combined with the other options, which you may\nwant: it that case you have to test yourself.\n\n'ACTIVE' and 'DELETED' check for the deleted flag on messages and\nmessage parts. The $filter is a code reference, which is called for\neach part of the message; each part as \"RECURSE\" would return.\n\nexample:\n\nmy @parts = $msg->parts;           # $msg not multipart: returns ($msg)\nmy $parts = $msg->parts('ACTIVE'); # returns ($msg)\n\n$msg->delete;\nmy @parts = $msg->parts;           # returns ($msg)\nmy $parts = $msg->parts('ACTIVE'); # returns ()\n\n#### Flags\n\n$obj->delete()\nFlag the message to be deleted, which is a shortcut for\n$msg->label(deleted => time); The real deletion only takes place on\na synchronization of the folder. See deleted() as well.\n\nThe time stamp of the moment of deletion is stored as value, but\nthat is not always preserved in the folder (depends on the\nimplementation). When the same message is deleted more than once,\nthe first time stamp will stay.\n\nexample:\n\n$message->delete;\n$message->deleted(1);  # exactly the same\n$message->label(deleted => 1);\ndelete $message;\n\n$obj->deleted( [BOOLEAN] )\nSet the delete flag for this message. Without argument, the method\nreturns the same as isDeleted(), which is preferred. When a true\nvalue is given, delete() is called.\n\nexample:\n\n$message->deleted(1);          # delete\n$message->delete;              # delete (preferred)\n\n$message->deleted(0);          # undelete\n\nif($message->deleted) {...}    # check\nif($message->isDeleted) {...}  # check (preferred)\n\n$obj->isDeleted()\nShort-cut for $msg->label('deleted')\n\nFor some folder types, you will get the time of deletion in return.\nThis depends on the implementation.\n\nexample:\n\nnext if $message->isDeleted;\n\nif(my $when = $message->isDeleted) {\nprint scalar localtime $when;\n}\n\n$obj->isModified()\nReturns whether this message is flagged as being modified.\nModifications are changes in header lines, when a new body is set to\nthe message (dangerous), or when labels change.\n\n$obj->label($label|PAIRS)\nReturn the value of the $label, optionally after setting some\nvalues. In case of setting values, you specify key-value PAIRS.\n\nLabels are used to store knowledge about handling of the message\nwithin the folder. Flags about whether a message was read, replied\nto, or scheduled for deletion.\n\nSome labels are taken from the header's \"Status\" and \"X-Status\"\nlines. Folder types like MH define a separate label file, and\nMaildir adds letters to the message filename. But the MailBox labels\nare always the same.\n\nexample:\n\nprint $message->label('seen');\nif($message->label('seen')) {...};\n$message->label(seen => 1);\n\n$message->label(deleted => 1);  # same as $message->delete\n\n$obj->labels()\nReturns all known labels. In SCALAR context, it returns the\nknowledge as reference to a hash. This is a reference to the\noriginal data, but you shall *not* change that data directly: call\n\"label\" for changes!\n\nIn LIST context, you get a list of names which are defined. Be\nwarned that they will not all evaluate to true, although most of\nthem will.\n\n$obj->labelsToStatus()\nWhen the labels were changed, that may effect the \"Status\" and/or\n\"X-Status\" header lines of mbox messages. Read about the relation\nbetween these fields and the labels in the DETAILS chapter.\n\nThe method will carefully only affect the result of modified() when\nthere is a real change of flags, so not for each call to label().\n\n$obj->modified( [BOOLEAN] )\nReturns (optionally after setting) whether this message is flagged\nas being modified. See isModified().\n\n$obj->statusToLabels()\nUpdate the labels according the status lines in the header. See the\ndescription in the DETAILS chapter.\n\n#### The whole message as text\n\n$obj->file()\nInherited, see \"The whole message as text\" in\nMail::Message::Construct::Text\n\n$obj->lines()\nInherited, see \"The whole message as text\" in\nMail::Message::Construct::Text\n\n$obj->printStructure( [$fh|undef],[$indent] )\nInherited, see \"The whole message as text\" in\nMail::Message::Construct::Text\n\n$obj->string()\nInherited, see \"The whole message as text\" in\nMail::Message::Construct::Text\n\n#### Internals\n\n$obj->clonedFrom()\nReturns the $message which is the source of this message, which was\ncreated by a clone() operation.\n\nMail::Message->coerce($message, %options)\nCoerce a $message into a Mail::Message. In some occasions, for\ninstance where you add a message to a folder, this coercion is\nautomatically called to ensure that the correct message type is\nstored.\n\nThe coerced message is returned on success, otherwise \"undef\". The\ncoerced message may be a reblessed version of the original message\nor a new object. In case the message has to be specialized, for\ninstance from a general Mail::Message into a\nMail::Box::Mbox::Message, no copy is needed. However, to coerce a\nMail::Internet object into a Mail::Message, a lot of copying and\nconverting will take place.\n\nValid MESSAGEs which can be coerced into Mail::Message objects are\nof type\n\n*   Any type of Mail::Box::Message\n\n*   MIME::Entity objects, using Mail::Message::Convert::MimeEntity\n\n*   Mail::Internet objects, using\nMail::Message::Convert::MailInternet\n\n*   Email::Simple objects, using Mail::Message::Convert::EmailSimple\n\n*   Email::Abstract objects\n\nMail::Message::Part's, which are extensions of \"Mail::Message\"'s,\ncan also be coerced directly from a Mail::Message::Body.\n\nexample:\n\nmy $folder  = Mail::Box::Mbox->new;\nmy $message = Mail::Message->build(...);\n\nmy $coerced = Mail::Box::Mbox::Message->coerce($message);\n$folder->addMessage($coerced);\n\nSimpler replacement for the previous two lines:\n\nmy $coerced = $folder->addMessage($message);\n\n$obj->isDelayed()\nCheck whether the message is delayed (not yet read from file).\nReturns true or false, dependent on the body type.\n\n$obj->readBody( $parser, $head, [$bodytype] )\nRead a body of a message. The $parser is the access to the folder's\nfile, and the $head is already read. Information from the $head is\nused to create expectations about the message's length, but also to\ndetermine the mime-type and encodings of the body data.\n\nThe $bodytype determines which kind of body will be made and\ndefaults to the value specified by new(bodytype). $bodytype may be\nthe name of a body class, or a reference to a routine which returns\nthe body's class when passed the $head as only argument.\n\n$obj->readFromParser( $parser, [$bodytype] )\nRead one message from file. The $parser is opened on the file. First\nreadHead() is called, and the head is stored in the message. Then\nreadBody() is called, to produce a body. Also the body is added to\nthe message without decodings being done.\n\nThe optional $bodytype may be a body class or a reference to a code\nwhich returns a body-class based on the header.\n\n$obj->readHead( $parser, [$class] )\nRead a head into an object of the specified $class. The $class\ndefaults to new(headtype). The $parser is the access to the\nfolder's file.\n\n$obj->recursiveRebuildPart($part, %options)\nInherited, see \"Internals\" in Mail::Message::Construct::Rebuild\n\n$obj->storeBody($body)\nWhere the body() method can be used to set and get a body, with all\nthe necessary checks, this method is bluntly adding the specified\nbody to the message. No conversions, not checking.\n\n$obj->takeMessageId( [STRING] )\nTake the message-id from the STRING, or create one when the \"undef\"\nis specified. If not STRING nor \"undef\" is given, the current header\nof the message is requested for the value of the 'Message-ID' field.\n\nAngles (if present) are removed from the id.\n\n#### Error handling\n\nExtends \"Error handling\" in Mail::Reporter.\n\n$obj->AUTOLOAD()\nInherited, see \"METHODS\" in Mail::Message::Construct\n\n$obj->addReport($object)\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level,\n$callback] )\nMail::Message->defaultTrace( [$level]|[$loglevel, $tracelevel]|[$level,\n$callback] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->errors()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->log( [$level, [$strings]] )\nMail::Message->log( [$level, [$strings]] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->logPriority($level)\nMail::Message->logPriority($level)\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->logSettings()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->notImplemented()\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->report( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->reportAll( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->shortSize( [$value] )\nMail::Message->shortSize( [$value] )\nRepresent an integer $value representing the size of file or memory,\n(which can be large) into a short string using M and K (Megabytes\nand Kilobytes). Without $value, the size of the message head is\nused.\n\n$obj->shortString()\nConvert the message header to a short string (without trailing\nnewline), representing the most important facts (for debugging\npurposes only). For now, it only reports size and subject.\n\n$obj->trace( [$level] )\nInherited, see \"Error handling\" in Mail::Reporter\n\n$obj->warnings()\nInherited, see \"Error handling\" in Mail::Reporter\n\n#### Cleanup\n\nExtends \"Cleanup\" in Mail::Reporter.\n\n$obj->DESTROY()\nInherited, see \"Cleanup\" in Mail::Reporter\n\n$obj->destruct()\nRemove the information contained in the message object. This will be\nignored when more than one reference to the same message object\nexists, because the method has the same effect as assigning \"undef\"\nto the variable which contains the reference. Normal garbage\ncollection will call \"DESTROY()\" when possible.\n\nThis method is only provided to hide differences with messages which\nare located in folders: their Mail::Box::Message::destruct() works\nquite differently.\n\nexample: of Mail::Message destruct\n\nmy $msg = Mail::Message->read;\n$msg->destruct;\n$msg = undef;    # same\n\n### DETAILS\n\n#### Structure of a Message\n\nA MIME-compliant message is build upon two parts: the *header* and the\n*body*.\n\nThe header\nThe header is a list of fields, some spanning more than one line\n(*folded*) each telling something about the message. Information stored\nin here are for instance the sender of the message, the receivers of the\nmessage, when it was transported, how it was transported, etc. Headers\ncan grow quite large.\n\nIn MailBox, each message object manages exactly one header object (a\nMail::Message::Head) and one body object (a Mail::Message::Body). The\nheader contains a list of header fields, which are represented by\nMail::Message::Field objects.\n\nThe body\nThe body contains the \"payload\": the data to be transferred. The data\ncan be encoded, only accessible with a specific application, and may use\nsome weird character-set, like Vietnamese; the MailBox distribution\ntries to assist you with handling these e-mails without the need to know\nall the details. This additional information (\"meta-information\") about\nthe body data is stored in the header. The header contains more\ninformation, for instance about the message transport and relations to\nother messages.\n\n#### Message object implementation\n\nThe general idea about the structure of a message is\n\nMail::Message\n|  |\n|  `-has-one--Mail::Message::Body\n|\n`----has-one--Mail::Message::Head\n|\n`-has-many--Mail::Message::Field\n\nHowever: there are about 7 kinds of body objects, 3 kinds of headers and\n3 kinds of fields. You will usually not see too much of these kinds,\nbecause they are merely created for performance reasons and can be used\nall the same, with the exception of the multipart bodies.\n\nA multipart body is either a Mail::Message::Body::Multipart (mime type\n\"multipart/*\") or a Mail::Message::Body::Nested (mime type\n\"message/rfc822\"). These bodies are more complex:\n\nMail::Message::Body::Multipart\n|\n`-has-many--Mail::Message::Part\n|  |\n|  `-has-one--Mail::Message::Body\n|\n`----has-one--Mail::Message::Head\n\nBefore you try to reconstruct multiparts or nested messages yourself,\nyou can better take a look at Mail::Message::Construct::Rebuild.\n\n#### Message class implementation\n\nThe class structure of messages is very close to that of folders. For\ninstance, a Mail::Box::File::Message relates to a Mail::Box::File\nfolder.\n\nAs extra level of inheritance, it has a Mail::Message, which is a\nmessage without location. And there is a special case of message:\nMail::Message::Part is a message encapsulated in a multipart body.\n\nThe message types are:\n\nMail::Box::Mbox::Message            Mail::Box::POP3::Message\n|  Mail::Box::Dbx::Message      Mail::Box::IMAP4::Message  |\n|  |                                                    |  |\nMail::Box::File::Message             Mail::Box::Net::Message\n|                                      |\n|       Mail::Box::Maildir::Message    |\n|       |   Mail::Box::MH::Message     |\n|       |   |                          |\n|       Mail::Box::Dir::Message        |\n|                |                     |\n`------------.   |   .-----------------'\n|   |   |\nMail::Box::Message    Mail::Message::Part\n|                     |\n|       .-------------'\n|       |\nMail::Message\n|\n|\nMail::Reporter (general base class)\n\nBy far most folder features are implemented in Mail::Box, so available\nto all folder types. Sometimes, features which appear in only some of\nthe folder types are simulated for folders that miss them, like\nsub-folder support for MBOX.\n\nTwo strange other message types are defined: the Mail::Message::Dummy,\nwhich fills holes in Mail::Box::Thread::Node lists, and a\nMail::Box::Message::Destructed, this is an on purpose demolished message\nto reduce memory consumption.\n\n#### Labels\n\nLabels (also named \"Flags\") are used to indicate some special condition\non the message, primary targeted on organizational issues: which\nmessages are already read or should be deleted. There is a very strong\nuser relation to labels.\n\nThe main complication is that each folder type has its own way of\nstoring labels. To give an indication: MBOX folders use \"Status\" and\n\"X-Status\" header fields, MH uses a \".mh-sequences\" file, MAILDIR\nencodes the flags in the message's filename, and IMAP has flags as part\nof the protocol.\n\nBesides, some folder types can store labels with user defined names,\nwhere other lack that feature. Some folders have case-insensitive\nlabels, other don't. Read all about the specifics in the manual page of\nthe message type you actually have.\n\nPredefined labels\nTo standardize the folder types, MailBox has defined the following\nlabels, which can be used with the label() and labels() methods on all\nkinds of messages:\n\n*   deleted\n\nThis message is flagged to be deleted once the folder closes. Be\nvery careful about the concept of 'delete' in a folder context : it\nis only a flag, and does not involve immediate action! This means,\nfor instance, that the memory which is used by Perl to store the\nmessage is not released immediately (see destruct() if you need to).\n\nThe methods delete(), deleted(), and isDeleted() are only short-cuts\nfor managing the \"delete\" label (as of MailBox 2.052).\n\n*   draft\n\nThe user has prepared this message, but is has not been send (yet).\nThis flag is not automatically added to a message by MailBox, and\nhas only a meaning in user applications.\n\n*   flagged\n\nMessages can be *flagged* for some purpose, for instance as result\nof a search for spam in a folder. The Mail::Box::messages() method\ncan be used to collect all these flagged messages from the folder.\n\nProbably it is more useful to use an understandable name (like\n\"spam\") for these selections, however these self-defined labels can\nnot stored in all folder types.\n\n*   old\n\nThe message was already in the folder when it was opened the last\ntime, so was not recently added to the folder. This flag will never\nautomatically be set by MailBox, because it would probably conflict\nwith the user's idea of what is old.\n\n*   passed\n\nNot often used or kept, this flag indicates that the message was\nbounced or forwarded to someone else.\n\n*   replied\n\nThe user (or application) has sent a message back to the sender of\nthe message, as response of this one. This flag is automatically set\nif you use reply(), but not with forward() or bounce().\n\n*   seen\n\nWhen this flag is set, the receiver of the message has consumed the\nmessage. A mail user agent (MUA) will set this flag when the user\nhas opened the message once.\n\nStatus and X-Status fields\nMbox folders have no special means of storing information about messages\n(except the message separator line), and therefore have to revert to\nadding fields to the message header when something special comes up.\nThis feature is also enabled for POP3, although whether that works\ndepends on the POP server.\n\nAll applications which can handle mbox folders support the \"Status\" and\n\"X-Status\" field convensions. The following encoding is used:\n\nFlag   Field       Label\nR      Status   => seen    (Read)\nO      Status   => old     (not recent)\nA      X-Status => replied (Answered)\nF      X-Status => flagged\n\nThere is no special flag for \"deleted\", which most other folders\nsupport: messages flagged to be deleted will never be written to a\nfolder file when it is closed.\n\n### DIAGNOSTICS\n\nError: Cannot coerce a $class object into a $class object\nError: Cannot include forward source as $include.\nUnknown alternative for the forward(include). Valid choices are\n\"NO\", \"INLINE\", \"ATTACH\", and \"ENCAPSULATE\".\n\nError: Cannot include reply source as $include.\nUnknown alternative for the \"include\" option of reply(). Valid\nchoices are \"NO\", \"INLINE\", and \"ATTACH\".\n\nError: Method bounce requires To, Cc, or Bcc\nThe message bounce() method forwards a received message off to\nsomeone else without modification; you must specified it's new\ndestination. If you have the urge not to specify any destination,\nyou probably are looking for reply(). When you wish to modify the\ncontent, use forward().\n\nError: Method forwardAttach requires a preamble\nError: Method forwardEncapsulate requires a preamble\nError: No address to create forwarded to.\nIf a forward message is created, a destination address must be\nspecified.\n\nError: No default mailer found to send message.\nThe message send() mechanism had not enough information to\nautomatically find a mail transfer agent to sent this message.\nSpecify a mailer explicitly using the \"via\" options.\n\nError: No rebuild rule $name defined.\nError: Only build() Mail::Message's; they are not in a folder yet\nYou may wish to construct a message to be stored in a some kind of\nfolder, but you need to do that in two steps. First, create a normal\nMail::Message, and then add it to the folder. During this\nMail::Box::addMessage() process, the message will get coerce()-d\ninto the right message type, adding storage information and the\nlike.\n\nError: Package $package does not implement $method.\nFatal error: the specific package (or one of its superclasses) does\nnot implement this method where it should. This message means that\nsome other related classes do implement this method however the\nclass at hand does not. Probably you should investigate this and\nprobably inform the author of the package.\n\nError: coercion starts with some object\n\n### SEE ALSO\n\nThis module is part of Mail-Message distribution version 3.012, built on\nFebruary 11, 2022. Website: http://perl.overmeer.net/CPAN/\n\n### LICENSE\n\nCopyrights 2001-2022 by [Mark Overmeer <markov@cpan.org>]. For other\ncontributors see ChangeLog.\n\nThis program is free software; you can redistribute it and/or modify it\nunder the same terms as Perl itself. See http://dev.perl.org/licenses/\n\n"
        }
    ],
    "structuredContent": {
        "command": "Mail::Message",
        "section": "",
        "mode": "perldoc",
        "summary": "Mail::Message - general message object",
        "synopsis": "use Mail::Box::Manager;\nmy $mgr    = Mail::Box::Manager->new;\nmy $folder = $mgr->open(folder => 'InBox');\nmy $msg    = $folder->message(2);    # $msg is a Mail::Message now\nmy $subject = $msg->subject;         # The message's subject\nmy @cc      = $msg->cc;              # List of Mail::Address'es\nmy Mail::Message::Head $head = $msg->head;\nmy Mail::Message::Body $body = $msg->decoded;\n$msg->decoded->print($outfile);\n# Send a simple email\nMail::Message->build\n( To             => 'you@example.com'\n, From           => 'me@example.com'\n, Subject        => \"My subject\"\n, data           => \"Some plain text content\"\n)->send(via => 'postfix');\nmy $replymsg = Mail::Message->reply(...);\nmy $frwdmsg  = Mail::Message->forward(...);",
        "flags": [],
        "examples": [],
        "see_also": [],
        "section_outline": [
            {
                "name": "NAME",
                "lines": 2,
                "subsections": []
            },
            {
                "name": "INHERITANCE",
                "lines": 19,
                "subsections": []
            },
            {
                "name": "SYNOPSIS",
                "lines": 23,
                "subsections": []
            },
            {
                "name": "DESCRIPTION",
                "lines": 17,
                "subsections": []
            },
            {
                "name": "METHODS",
                "lines": 2,
                "subsections": [
                    {
                        "name": "Constructors",
                        "lines": 107
                    },
                    {
                        "name": "Constructing a message",
                        "lines": 65
                    },
                    {
                        "name": "The message",
                        "lines": 118
                    },
                    {
                        "name": "The header",
                        "lines": 152
                    },
                    {
                        "name": "The body",
                        "lines": 85
                    },
                    {
                        "name": "Flags",
                        "lines": 98
                    },
                    {
                        "name": "The whole message as text",
                        "lines": 16
                    },
                    {
                        "name": "Internals",
                        "lines": 91
                    },
                    {
                        "name": "Error handling",
                        "lines": 55
                    },
                    {
                        "name": "Cleanup",
                        "lines": 22
                    }
                ]
            },
            {
                "name": "DETAILS",
                "lines": 1,
                "subsections": [
                    {
                        "name": "Structure of a Message",
                        "lines": 25
                    },
                    {
                        "name": "Message object implementation",
                        "lines": 30
                    },
                    {
                        "name": "Message class implementation",
                        "lines": 41
                    },
                    {
                        "name": "Labels",
                        "lines": 92
                    }
                ]
            },
            {
                "name": "DIAGNOSTICS",
                "lines": 45,
                "subsections": []
            },
            {
                "name": "SEE ALSO",
                "lines": 3,
                "subsections": []
            },
            {
                "name": "LICENSE",
                "lines": 6,
                "subsections": []
            }
        ]
    }
}