Qore Mime Module Reference: Mime::MultiPartMessage Class Reference

Qore Mime Module Reference 1.3.4

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes

- Class List
- Class Index
- Class Hierarchy
- Class Members

All Classes Namespaces Functions Variables Groups Pages
Public Member Functions | Static Public Member Functions | List of all members
Mime::MultiPartMessage Class Referenceabstract

MultiPartMessage class implementation. More...

Inheritance diagram for Mime::MultiPartMessage:
[legend]

## Public Member Functions
| constructor (string mptype, string boundary=MultiPartMessage::getBoundary())
| creates the object More...
abstract hash | getMsgAndHeaders ()
| returns a hash of the message More...
binary | serialize ()
| serializes the message and returns a binary object ready to send over a socket

## Static Public Member Functions
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 More...
static hash | parseBody (string boundary, string body, bool decode=True)
| returns a hash representing a parsed multipart message body from a boundary string and body arguments More...
static binary | serializeHeaders (hash hdr)
| serializes a header hash to a binary object More...

## Detailed Description

MultiPartMessage class implementation.

## Member Function Documentation

Mime::MultiPartMessage::constructor | ( | string | mptype,
|  | string | boundary = `MultiPartMessage::getBoundary()`
| ) |  |

creates the object

Parameters

  mptype | the type of multi-part message: see MultiPartMessage Constants for possible values
  boundary | the boundary to use between parts

abstract hash Mime::MultiPartMessage::getMsgAndHeaders | ( |  | ) |
| pure virtual

returns a hash of the message

Returns
  a hash of the message with the following keys:
  - `hdr:` a hash of header information
  - `msg:` a binary object of serialized message parts

Implemented in Mime::MultiPartMixedMessage, and Mime::MultiPartRelatedMessage.

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()

static hash Mime::MultiPartMessage::parseBody | ( | string | boundary,
|  | string | 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:
  my 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\r
  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 or binary object; this can only be a binary object if the decode argumnent 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

static binary Mime::MultiPartMessage::serializeHeaders | ( | hash | hdr | ) |
| static

serializes a header hash to a binary object

Parameters

  hdr | the hash to serialize

Returns
  the binary object representing the hash with each header separated by `"\r\n"`