Pike v8.1 release 6

Class MIME.Message

Description

This class is used to hold a decoded MIME message.


Variable body_parts

array(object) MIME.Message.body_parts

Description

If the message is of type multipart, this is an array containing one Message object for each part of the message. If the message is not a multipart, this field is 0 (zero).

See also

type, boundary


Variable boundary

string MIME.Message.boundary

Description

For multipart messages, this Content-Type parameter gives a delimiter string for separating the individual messages. As multiparts are handled internally by the module, you should not need to access this field.

See also

setboundary()


Variable charset

string MIME.Message.charset

Description

One of the possible parameters of the Content-Type header is the charset attribute. It determines the character encoding used in bodies of type text.

If there is no Content-Type header, the value of this field is "us-ascii".

See also

type


Variable data

string MIME.Message.data

Description

This variable contains the raw data of the message body entity.

The type and subtype attributes indicate how this data should be interpreted.

Note

In Pike 7.6 and earlier you had to use getdata() and setdata() to access this value.

See also

getdata(), setdata()


Variable disp_params

mapping(string:string) MIME.Message.disp_params

Description

A mapping containing all the additional parameters to the Content-Disposition header.

See also

setdisp_param(), get_filename()


Variable disposition

string MIME.Message.disposition

Description

The first part of the Content-Disposition header, hinting on how this part of a multipart message should be presented in an interactive application.

If there is no Content-Disposition header, this field is 0.


Variable headers

mapping(string:string) MIME.Message.headers

Description

This mapping contains all the headers of the message.

The key is the header name (in lower case) and the value is the header value.

Although the mapping contains all headers, some particular headers get special treatment by the module and should not be accessed through this mapping. These fields are currently:

"content-type"
"content-disposition"
"content-length"
"content-transfer-encoding"

The contents of these fields can be accessed and/or modified through a set of variables and methods available for this purpose.

See also

type, subtype, charset, boundary, transfer_encoding, params, disposition, disp_params, setencoding(), setparam(), setdisp_param(), setcharset(), setboundary()

Note

Some headers (eg Subject) may include RFC 1522/RFC 2047 encoded words. To decode these, see decode_words_text and decode_words_tokenized and their friends.


Variable params

mapping(string:string) MIME.Message.params

Description

A mapping containing all the additional parameters to the Content-Type header.

Some of these parameters have fields of their own, which should be accessed instead of this mapping wherever applicable.

See also

charset, boundary, setparam()


Variable subtype

string MIME.Message.subtype

Description

The Content-Type header contains a type, a subtype, and optionally some parameters. This field contains the subtype attribute extracted from the header.

If there is no Content-Type header, the value of this field is "plain".

See also

type, params


Variable transfer_encoding

string MIME.Message.transfer_encoding

Description

The contents of the Content-Transfer-Encoding header.

If no Content-Transfer-Encoding header is given, this field is 0 (zero).

Transfer encoding and decoding is done transparently by the module, so this field should be interesting only to applications wishing to do auto conversion of certain transfer encodings.

See also

setencoding()


Variable type

string MIME.Message.type

Description

The Content-Type header contains a type, a subtype, and optionally some parameters. This field contains the type attribute extracted from the header.

If there is no Content-Type header, the value of this field is "text".

See also

subtype, params


Method create

MIME.Message MIME.Message()
MIME.Message MIME.Message(string message)
MIME.Message MIME.Message(string message, mapping(string:string|array(string)) headers, array(object)|void parts)
MIME.Message MIME.Message(string message, mapping(string:string|array(string)) headers, array(object)|void parts, bool guess)

Description

There are several ways to call the constructor of the Message class:

  • With zero arguments, you will get a dummy message with neither headers nor body. Not very useful.

  • With one argument, the argument is taken to be a byte stream containing a message in encoded form. The constructor will analyze the string and extract headers and body.

  • With two or three arguments, the first argument is taken to be the raw body data, and the second argument a desired set of headers. The keys of this mapping are not case-sensitive. If the given headers indicate that the message should be of type multipart, an array of Message objects constituting the subparts should be given as a third argument.

  • With the guess argument set to 1 (headers and parts may be 0 if you don't want to give any), you get a more forgiving MIME Message that will do its best to guess what broken input data really meant. It won't always guess right, but for applications like mail archives and similar where you can't get away with throwing an error at the user, this comes in handy. Only use the guess mode only for situations where you need to process broken MIME messages silently; the abuse of overly lax tools is what poisons standards.

See also

cast()