MultiPartMessage class implementation.
More...
#include <Mime.qm.dox.h>
|
| constructor (string mptype, string boundary=MultiPartMessage::getBoundary()) |
| creates the object
|
|
string | getBoundary () |
| returns the message boundary string used
|
|
abstract hash< MessageInfo > | getMsgAndHeaders () |
| returns a hash of the message
|
|
binary | serialize () |
| serializes the message with the Content-Type header first and returns a binary object ready to send over a socket
|
|
binary | serializeBody () |
| serializes the message body only and returns a binary object ready to send over a socket
|
|
int | size () |
| returns the number of parts in the message
|
|
|
static string | getBoundary () |
| returns a string embedded with the current timestamp designed to be used as MultiPart boundary string
|
|
static string | getRandomString (int len) |
| returns a string of random characters
|
|
static hash< MessageInfo > | parseBody (string boundary, data body, bool decode=True) |
| returns a hash representing a parsed multipart message body from a boundary string and body arguments
|
|
static binary | serializeHeaders (hash hdr) |
| serializes a header hash to a binary object
|
|
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()
abstract hash< MessageInfo > Mime::MultiPartMessage::getMsgAndHeaders |
( |
| ) |
|
returns a hash of the message
- Returns
- a hash of the message with the following keys:
hdr:
a hash of header information
body:
a binary object of serialized message parts
◆ 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()
static hash< MessageInfo > Mime::MultiPartMessage::parseBody |
( |
string |
boundary, |
|
|
data |
body, |
|
|
bool |
decode = True |
|
) |
| |
|
static |
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));
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