SourcePro® API Reference Guide

 
Loading...
Searching...
No Matches
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 (const RWMimeContentType &type)
 
 RWMimePart (const RWMimePart &second)
 
 RWMimePart (void)
 
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
 

Protected Member Functions

RWMimePartImp & body (void) const
 
- Protected Member Functions inherited from RWHandleBase
 RWHandleBase (const RWHandleBase &second)
 
 RWHandleBase (RWBodyBase *body)
 
 RWHandleBase (RWStaticCtor)
 
 RWHandleBase (void)
 
 ~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:

  • 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.

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);
Represents the Content-Type header of a MIME part.
Definition RWMimeContentTypeHeader.h:71
Represents a MIME part, with methods for manipulating the header list and setting the body of the par...
Definition RWMimePart.h:94
void insertHeader(const RWMimeHeader &header)
void setBody(const RWCString &body)
Represents a Content-Type value with the media type text.
Definition RWMimeTextType.h:37

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() [1/3]

RWMimePart::RWMimePart ( void )

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

◆ RWMimePart() [2/3]

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() [3/3]

RWMimePart::RWMimePart ( const RWMimePart & second)

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

◆ ~RWMimePart()

virtual RWMimePart::~RWMimePart ( void )
virtual

Destructor.

Member Function Documentation

◆ asString()

RWCString RWMimePart::asString ( void ) const

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

◆ body()

RWMimePartImp & RWMimePart::body ( void ) const
protected

Returns a reference to the underlying implementation.

◆ findHeader()

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.

◆ fromString()

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.

◆ getBody()

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.

◆ getHeader()

RWMimeHeader RWMimePart::getHeader ( size_t position) const

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

◆ getHeaderCount()

size_t RWMimePart::getHeaderCount ( void ) const

Returns the number of headers this MIME part contains.

◆ insertHeader()

void RWMimePart::insertHeader ( const RWMimeHeader & header)

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

◆ insertHeaderAt()

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

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

◆ isMultipart()

bool RWMimePart::isMultipart ( void ) const

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

◆ operator=()

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

Assignment operator. Makes self a handle identical to second.

◆ removeHeaderAt()

void RWMimePart::removeHeaderAt ( size_t position)

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

◆ setBody()

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