SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Protected Member Functions
RWMimePart Class Reference

Represents a MIME part, with methods for manipulating the header list and setting the body of the part. More...

#include <rw/mime/RWMimePart.h>

Inheritance diagram for RWMimePart:
RWHandleBase RWMimeMultipart

Public Member Functions

 RWMimePart (void)
 
 RWMimePart (const RWMimeContentType &type)
 
 RWMimePart (const RWMimePart &second)
 
virtual ~RWMimePart (void)
 
RWCString asString (void) const
 
size_t findHeader (const RWCString &label, size_t start=0) const
 
void fromString (const RWCString &partString)
 
RWCString getBody (void) const
 
RWMimeHeader getHeader (size_t position) const
 
size_t getHeaderCount (void) const
 
void insertHeader (const RWMimeHeader &header)
 
void insertHeaderAt (size_t position, const RWMimeHeader &header)
 
bool isMultipart (void) const
 
RWMimePartoperator= (const RWMimePart &second)
 
void removeHeaderAt (size_t position)
 
void setBody (const RWCString &body)
 
- Public Member Functions inherited from RWHandleBase
bool isValid (void) const
 
bool operator!= (const RWHandleBase &second) const
 
bool operator< (const RWHandleBase &second) const
 
bool operator== (const RWHandleBase &second) const
 

Protected Member Functions

RWMimePartImp & body (void) const
 
- Protected Member Functions inherited from RWHandleBase
 RWHandleBase (void)
 
 RWHandleBase (RWStaticCtor)
 
 RWHandleBase (RWBodyBase *body)
 
 RWHandleBase (const RWHandleBase &second)
 
 ~RWHandleBase (void)
 
RWBodyBasebody (void) const
 
RWHandleBaseoperator= (const RWHandleBase &second)
 

Detailed Description

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:

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.

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.

Reference
RWMimePart provides an encapsulation of the Multipurpose Internet Mail Extensions (MIME) as described in RFC 2045 - 2049.

Constructor & Destructor Documentation

RWMimePart::RWMimePart ( void  )

Default constructor. Constructs a MIME part with no headers and an empty body.

RWMimePart::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::RWMimePart ( const RWMimePart second)

Copy constructor. Constructs a new handle to the body second refers to.

virtual RWMimePart::~RWMimePart ( void  )
virtual

Destructor.

Member Function Documentation

RWCString RWMimePart::asString ( void  ) const

Returns a string representation of self. Throws RWMimeError if the function cannot create a MIME part with valid structure.

RWMimePartImp& RWMimePart::body ( void  ) const
protected

Returns a reference to the underlying implementation.

size_t RWMimePart::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 greater than or equal to getHeaderCount(). The RWCString should contain 7-bit US-ASCII data.

void RWMimePart::fromString ( const RWCString partString)

Populates self with the contents of partString. Throws RWMimeParseError if the function cannot parse partString as a MIME part.

RWCString RWMimePart::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 RWMimePart::getHeader ( size_t  position) const

Returns the header at position. Throws RWBoundsErr if position is greater than or equal to getHeaderCount().

size_t RWMimePart::getHeaderCount ( void  ) const

Returns the number of headers this MIME part contains.

void RWMimePart::insertHeader ( const RWMimeHeader header)

Inserts header at the end of self's header list.

void RWMimePart::insertHeaderAt ( size_t  position,
const RWMimeHeader header 
)

Inserts header at position. Throws RWBoundsErr if position is greater than getHeaderCount().

bool RWMimePart::isMultipart ( void  ) const

Returns true if the underlying implementation is multipart, false otherwise.

RWMimePart& RWMimePart::operator= ( const RWMimePart second)

Assignment operator. Makes self a handle identical to second.

void RWMimePart::removeHeaderAt ( size_t  position)

Removes the header at position. Throws RWBoundsErr if position is greater than or equal to getHeaderCount().

void RWMimePart::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 © 2022 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.