MultiPartMessage class implementation.
More...
MultiPartMessage class implementation.
◆ constructor()
creates the object
- Parameters
-
mptype | the type of multi-part message: see MultiPartMessage Constants for possible values |
boundary | the boundary to use between parts |
◆ getBoundary()
string Mime::MultiPartMessage::getBoundary |
( |
| ) |
|
returns the message boundary string used
- Returns
- the message boundary string used
- Since
- Mime 1.4
◆ getMsgAndHeaders()
◆ getRandomString()
static string Mime::MultiPartMessage::getRandomString |
( |
int |
len | ) |
|
|
static |
returns a string of random characters
- Parameters
-
len | the length of the string to return |
- Since
- Mime 1.3.4 implemented by Util::get_random_string()
◆ parseBody()
returns a hash representing a parsed multipart message body from a boundary string and body arguments
Also parses long headers as per RFC 2822 section 2.2.3
- Example:
- For example, given the following code:
string body = "This is a message with multiple parts in MIME format.\r
--frontier\r
Content-Type: text/plain\r
\r
This is the body of the message.\r
--frontier\r
Content-Type: text/html\r
Content-Transfer-Encoding: base64\r
\r
PGh0bWw+CiAgPGhlYWQ+CiAgPC9oZWFkPgogIDxib2R5PgogICAgPHA+VGhpcyBpcyB0aGUg\rMultiPartFormDataMessage
Ym9keSBvZiB0aGUgbWVzc2FnZS48L3A+CiAgPC9ib2R5Pgo8L2h0bWw+Cg=\r
--frontier--\r
";
printf("%N\n", MultiPartMessage::parseBody(
"frontier", body,
True));
string printf(string fmt,...)
The above code will output the following: hash: (2 members)
body : "This is a message with multiple parts in MIME format."
part : list: (2 elements)
[0]=hash: (2 members)
hdr : hash: (1 member)
content-type : "text/plain"
body : "This is the body of the message."
[1]=hash: (2 members)
hdr : hash: (2 members)
content-type : "text/html"
content-transfer-encoding : "base64"
body : "<html>
<head>
</head>
<body>
<p>This is the body of the message.</p>
</body>
</html>
"
- Parameters
-
boundary | the boundary string |
body | the message body to parse; parsing only works if the line termination characters are "\r\n" |
decode | decode the parts (in this case a part may itself have parts recursively) |
- Returns
- a hash representing a parsed multipart message body with the following keys:
body:
any non-part message body left after parsing the parts; will be an empty string if the entiore body is made up of the parts
part:
a list of the parts; each list element is a hash representing a part of the message with the following keys:
hdr:
a hash of part headers, where each header value is converted to lower case and used as a hash key
body:
the body of the part as a string; this can only be a binary object if the decode argument is True, the part's content-encoding is base64 and the part's content type does not contain the word "text"
[part]: if the decode parameter is True then any content-encoding for parts is decoded automatically; also parts that have parts themselves are processed recursively if this argument is set
- Exceptions
-
MULTIPART-PARSEBODY-ERROR | no boundary found in body; no closing boundary; malformatted part or part header, etc |
- Note
- multipart message parsing only works if the line termination characters are
"\r\n"
; make sure and convert the end of line characters before passing to this method if necessary
◆ serializeBody()
binary Mime::MultiPartMessage::serializeBody |
( |
| ) |
|
serializes the message body only and returns a binary object ready to send over a socket
- Since
- Mime 1.4
◆ serializeHeaders()
static binary Mime::MultiPartMessage::serializeHeaders |
( |
hash |
hdr | ) |
|
|
static |
serializes a header hash to a binary object
- Parameters
-
- Returns
- the binary object representing the hash with each header separated by
"\r\n"
◆ size()
int Mime::MultiPartMessage::size |
( |
| ) |
|
returns the number of parts in the message
- Returns
- the number of parts in the message
- Since
- Mime 1.4