Previous section To contents

14.11.2.2 Public methods

METHOD
MIME.Message.cast - Encode message into byte stream

SYNTAX
string (string )MIME.Message;

DESCRIPTION
Casting the message object to a string will yield a byte stream suitable for transmitting the message over protocols such as ESMTP and NNTP. The body will be encoded using the current transfer encoding, and subparts of a multipart will be collected recursively. If the message is a multipart and no boundary string has been set, one is generated using generate_boundary.

EXAMPLE
> object msg = MIME.Message( "Hello, world!",
                ([ "MIME-Version" : "1.0",
                     "Content-Type":"text/plain",
                     "Content-Transfer-Encoding":"base64" ]) );
Result: object
> (string )msg;
Result: Content-Type: text/plain
Content-Length: 20
Content-Transfer-Encoding: base64
MIME-Version: 1.0

SGVsbG8sIHdvcmxkIQ==

SEE ALSO
MIME.Message->create

METHOD
MIME.Message.create - Create a Message object

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

DESCRIPTION
There are several ways to call the constructor of the Message class;
  • With zero arguments, you will get a dummy message without either headers or 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.

EXAMPLE
> object msg = MIME.Message( "Hello, world!", ([ "MIME-Version" : "1.0", "Content-Type" : "text/plain; charset=iso-8859-1" ]) ); Result: object > msg->charset; Result: iso-8859-1

SEE ALSO
MIME.Message->cast

METHOD
MIME.Message.getdata - Obtain raw body data

SYNTAX
string getdata();

DESCRIPTION
This method returns the raw data of the message body entity. The type and subtype attributes indicate how this data should be interpreted.

SEE ALSO
MIME.Message->getencoded

METHOD
MIME.Message.getencoded - Obtain encoded body data

SYNTAX
string getencoded();

DESCRIPTION
This method returns the data of the message body entity, encoded using the current transfer encoding. You should never have to call this function.

SEE ALSO
MIME.Message->getdata

METHOD
MIME.Message.get_filename - Get supplied filename for body data

SYNTAX
string get_filename();

DESCRIPTION
This method tries to find a suitable filename should you want to save the body data to disk. It will examine the filename attribute of the Content-Disposition header, and failing that the name attribute of the Content-Type header. If neither attribute is set, the method returns 0.

NOTE
An interactive application should always query the user for the actual filename to use. This method may provide a reasonable default though.

METHOD
MIME.Message.is_partial - Identify <tt>message/partial</tt> message

SYNTAX
array(string|int) is_partial();

DESCRIPTION
If this message is a part of a fragmented message (i.e. has a Content-Type of message/partial), an array with three elements is returned. The first element is an identifier string. This string should be used to group this message with the other fragments of the message (which will have the same id string). The second element is the sequence number of this fragment. The first part will have number 1, the next number 2 etc. The third element of the array is either the total number of fragments that the original message has been split into, or 0 of this information was not available. If this method is called in a message that is not a part of a fragmented message, it will return 0.

SEE ALSO
MIME.reconstruct_partial

METHOD
MIME.Message.setboundary - Set boundary parameter

SYNTAX
void setboundary(string boundary);

DESCRIPTION
Sets the boundary parameter of the Content-Type header. This is equivalent of calling msg->setparam("boundary", boundary).

SEE ALSO
MIME.Message->setparam

METHOD
MIME.Message.setcharset - Set charset parameter

SYNTAX
void setcharset(string charset);

DESCRIPTION
Sets the charset parameter of the Content-Type header. This is equivalent of calling msg->setparam("charset", charset).

SEE ALSO
MIME.Message->setparam

METHOD
MIME.Message.setdata - Replace body data

SYNTAX
void setdata(string data);

DESCRIPTION
Replaces the body entity of the data with a new piece of raw data. The new data should comply to the format indicated by the type and subtype attributes. Do not use this method unless you know what you are doing.

SEE ALSO
MIME.Message->getdata

METHOD
MIME.Message.setdisp_param - Set Content-Disposition parameters

SYNTAX
void setdisp_param(string param, string value);

DESCRIPTION
Set or modify the named parameter of the Content-Disposition header. A common parameters is e.g. filename. It is not allowed to modify the Content-Disposition header directly, please use this function instead.

SEE ALSO
MIME.Message->setparam and MIME.Message->get_filename

METHOD
MIME.Message.setencoding - Set transfer encoding for message body

SYNTAX
void setencoding(string encoding);

DESCRIPTION
Select a new transfer encoding for this message. The Content-Transfer-Encoding header will be modified accordingly, and subsequent calls to getencoded will produce data encoded using the new encoding. See encode for a list of valid encodings.

SEE ALSO
MIME.Message->getencoded

METHOD
MIME.Message.setparam - Set Content-Type parameters

SYNTAX
void setparam(string param, string value);

DESCRIPTION
Set or modify the named parameter of the Content-Type header. Common parameters include charset for text messages, and boundary for multipart messages. It is not allowed to modify the Content-Type header directly, please use this function instead.

SEE ALSO
MIME.Message->setcharset, MIME.Message->setboundary and MIME.Message->setdisp_param

Previous section To contents