SourcePro® API Reference Guide

 
List of all members | Public Member Functions | Protected Member Functions | Friends
RWMimeHeader Class Reference

Base class for classes that represent message headers as defined in the Internet Message format specification (RFC 2822). More...

#include <rw/mime/RWMimeHeader.h>

Inheritance diagram for RWMimeHeader:
RWHandleBase RWMimeContentDescriptionHeader RWMimeContentDispositionHeader RWMimeContentIdHeader RWMimeContentLocationHeader RWMimeContentTransferEncodingHeader RWMimeContentTypeHeader RWMimeGenericHeader RWMimeVersionHeader

Public Member Functions

 RWMimeHeader (void)
 
 RWMimeHeader (const RWCString &label)
 
 RWMimeHeader (const RWMimeHeader &second)
 
virtual ~RWMimeHeader (void)
 
RWCString asString (void) const
 
void fromString (const RWCString &headerString)
 
RWCString getLabel (void) const
 
RWMimeHeaderoperator= (const RWMimeHeader &second)
 
- 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

RWMimeHeaderImp & body (void) const
 
virtual bool checkLabel (const RWCString &label) 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)
 

Friends

bool operator!= (const RWMimeHeader &first, const RWMimeHeader &second)
 
bool operator== (const RWMimeHeader &first, const RWMimeHeader &second)
 

Detailed Description

RWMimeHeader is a base class for classes that represent message headers as defined in the Internet Message format specification (RFC 2822). A header consists of a label and a value. MIME requires that both the label and value contain only printable characters in the US-ASCII character set. The name may not contain a colon. To create a header value in another character set, encode the value according to the guidelines in RFC 2047.

The label appears first in the header, and is separated from the value by a colon. So, the header line

From: Rudi Marquez <rudi_marquez@roguewave.com>

contains the label From, a colon as a separator, and the value

Rudi Marquez <rudi_marquez@roguewave.com>

The Internet Message Format does not define the structure or meaning of a value. Therefore, RWMimeHeader does not define an interface for working with a header value. Just as each individual header in the specification defines the structure and semantics of its value, each derived class implements its own interface for working with the header value.

An instance of RWMimeHeader is a handle to a private, reference-counted body. Note that the body is always a specific header implementation.

Classes that contain MIME headers collect the headers as instances of RWMimeHeader. Each derived class contains a conversion constructor which creates a new derived-class handle to the implementation of the RWMimeHeader. Conversion happens automatically when an RWMimeHeader is assigned to a handle of the appropriate type. For example,

// RWMimePart part contains a MIME-Version header.
size_t index = part.findHeader(RWMimeVersionHeader::Label);
if (index != RW_NPOS)
{
RWMimeVersionHeader versionHdr = part.getHeader(index);
// ...
}

In the code above, the RWMimePart::getHeader() function returns an RWMimeHeader. Because RWMimeVersionHeader provides a conversion constructor from RWMimeHeader, the compiler automatically invokes that conversion constructor. The result is a completely typesafe assignment; no downcast is required. The conversion is also efficient, since the conversion constructor simply creates a new handle to the existing implementation.

Reference
RWMimeHeader conforms to the header requirements specified in Section 2.2 (p. 7) of RFC 2822, the Internet Message Format specification. RFC 2822 is an update of RFC 822, which originally defined the format for Internet message headers.

Constructor & Destructor Documentation

RWMimeHeader::RWMimeHeader ( void  )

Default constructor. Constructs a header with an empty label and an empty value.

Note
A header with an empty label and an empty value does not meet the requirements of an Internet Message Format header.
RWMimeHeader::RWMimeHeader ( const RWCString label)

Constructs a header with the given label and an empty value. Does not verify that the string provided meets the requirements for an Internet Message Format header. The RWCString should contain 7-bit US-ASCII data.

Note
A header with an empty value does not meet the requirements of an Internet Message Format header.
RWMimeHeader::RWMimeHeader ( const RWMimeHeader second)

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

virtual RWMimeHeader::~RWMimeHeader ( void  )
virtual

Destructor.

Member Function Documentation

RWCString RWMimeHeader::asString ( void  ) const

Returns this header as a string. Throws RWMimeError if self cannot be represented as a valid header. The RWCString should contain 7-bit US-ASCII data.

RWMimeHeaderImp& RWMimeHeader::body ( void  ) const
protected

Returns a reference to the underlying implementation.

virtual bool RWMimeHeader::checkLabel ( const RWCString label) const
protectedvirtual

Returns true. Since RWMimeHeader does not represent any specific header, this class imposes no special requirements on a label. In RWMimeHeader this function returns true without examining label. Derived classes that represent specific headers may require specific values for a label.

Reimplemented in RWMimeContentTypeHeader, RWMimeGenericHeader, RWMimeContentLocationHeader, RWMimeContentIdHeader, RWMimeContentTransferEncodingHeader, RWMimeVersionHeader, RWMimeContentDispositionHeader, and RWMimeContentDescriptionHeader.

void RWMimeHeader::fromString ( const RWCString headerString)

Populates self with the contents of headerString. Throws RWMimeParseError if the function cannot parse headerString as a valid header. In derived classes, throws RWMimeError if the label in headerString is not a valid label for the header that the class represents. The RWCString should contain 7-bit US-ASCII data.

RWCString RWMimeHeader::getLabel ( void  ) const

Returns the label of this header. The RWCString should contain 7-bit US-ASCII data.

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

Assignment operator. Makes self a handle identical to second.

Friends And Related Function Documentation

bool operator!= ( const RWMimeHeader first,
const RWMimeHeader second 
)
friend

Inequality operator. Returns true if first is not equal to second, false otherwise. Uses a case-insensitive comparison for labels. If the labels match, compares the values as appropriate for the specific header type.

bool operator== ( const RWMimeHeader first,
const RWMimeHeader second 
)
friend

Equality operator. Returns true if first is equal to second, false otherwise. Uses a case-insensitive comparison for labels. If the labels match, compares the values as appropriate for the specific header type.

Copyright © 2023 Rogue Wave Software, Inc., a Perforce company. All Rights Reserved.