Module: Internet Protocols Module Package: MIME
RWMimePartRWHandleBase
asString() findHeader() fromString() getBody() |
getHeader() getHeaderCount() insertHeader() insertHeaderAt() |
isMultipart() operator=() removeHeaderAt() RWMimePart() |
setBody() ~RWMimePart() |
#include <rw/mime/RWMimePart.h>
RWMimePart represents a MIME part. Each part has a body, the actual content of the part, and a list of headers that describe the body. The body may contain either a single document or a collection of other MIME parts.
RWMimePart provides functions for manipulating the header list and setting the body of the part. The derived class RWMimeMultipart represents parts with multipart bodies and provides functions for working with multipart bodies.
The MIME specification requires a top-level MIME message to contain a MIME-Version header. This header is optional for parts within a multipart message. No headers are required for every MIME part, but the MIME specification defines the following default values:
When a part does not contain a Content-Type header, the content type of the part is text-plain;charset=us-ascii.
When a part does not contain a Content-Transfer-Encoding header, the transfer encoding of the part is 7bit.
The example below is a complete MIME part. The part has the transfer encoding 7bit, even though the part does not contain a Content-Transfer-Encoding header. The body of the part is a simple HTML document.
Content-Type: text/html;charset=iso-8859-1 <HTML> <HEAD> <TITLE>Sample document</TITLE> </HEAD> <BODY> <H1>Sample Document</H1> <P>This is a sample document.</P> </BODY> </HTML>
This code snippet constructs an equivalent MIME part.
RWMimePart part; part.setBody( "<HTML>\r\n" " <HEAD>\r\n" " <TITLE>Sample document</TITLE>\r\n" " </HEAD>\r\n" " <BODY>\r\n" " <H1>Sample Document</H1>\r\n" " <P>This is a sample document.</P>\r\n" " </BODY>\r\n" "</HTML>\r\n"); RWMimeTextType htmlType("html", "iso-8859-1"); RWMimeContentTypeHeader htmlTypeHeader(htmlType); part.insertHeader(htmlTypeHeader);
An instance of this class is a handle to a private, reference-counted implementation.
RWMimePart provides an encapsulation of the Multipurpose Internet Mail Extensions (MIME) as described in RFC 2045 - 2049.
RWMimePart(void);
Default constructor. Constructs a MIME part with no headers and an empty body.
RWMimePart(const RWMimeContentType& type);
Content-Type constructor. Constructs a MIME part that contains a Content-Type header with the value type. The new part contains an empty part body.
RWMimePart(const RWMimePart& second);
Copy constructor. Constructs a new handle to the implementation second refers to.
virtual ~RWMimePart(void);
Destructor.
RWMimePart& operator=(const RWMimePart& second);
Makes self a handle identical to second.
RWCString asString(void) const;
Returns a string representation of self. Throws RWMimeError if the function cannot create a MIME part with valid structure.
size_t findHeader(const RWCString& label, size_t start = 0) const;
Returns the position of the first header in the header list with a label matching label. Begins searching at start. Returns RW_NPOS if no such header is present or if start is less than 0 or greater than getHeaderCount() - 1. The RWCString should contain 7-bit US-ASCII data.
void fromString(const RWCString& partString);
Populates self with the contents of partString. Throws RWMimeParseError if the function cannot parse partString as a MIME part.
RWCString getBody(void) const;
Returns self's body as a string. If the underlying implementation is multipart, throws RWMimeError if the function cannot create a valid MIME part body.
RWMimeHeader getHeader(size_t position) const;
Returns the header at position. Throws RWBoundsErr if position is less than 0 or greater than getHeaderCount() - 1.
size_t getHeaderCount(void) const;
Returns the number of headers this MIME part contains.
void insertHeader(const RWMimeHeader& header);
Inserts header at the end of self's header list.
void insertHeaderAt(size_t position, const RWMimeHeader& header);
Inserts header at position. Throws RWBoundsErr if position is less than 0 or greater than getHeaderCount().
bool isMultipart(void) const;
Returns true if the underlying implementation is multipart, false otherwise.
void removeHeaderAt(size_t position);
Removes the header at position. Throws RWBoundsErr if position is less than 0 or greater than getHeaderCount() - 1.
void setBody(const RWCString& body);
Sets self's body to body. Does not validate body if the underlying implementation is a single part. If the underlying implementation is multipart, throws RWMimeParseError if the function cannot parse body.
© Copyright Rogue Wave Software, Inc. All Rights Reserved.
Rogue Wave and SourcePro are registered trademarks of Rogue Wave Software, Inc. in the United States and other countries. All other trademarks are the property of their respective owners.
Contact Rogue Wave about documentation or support issues.