# Poco::Net

# class MultipartReader

Library: Net
Package: Messages
Header: Poco/Net/MultipartReader.h

## Description

This class is used to split a MIME multipart message into its single parts.

The format of multipart messages is described in section 5.1 of RFC 2046.

To split a multipart message into its parts, do the following:

- Create a MultipartReader object, passing it an input stream and optionally a boundary string.
- while hasNextPart() returns true, call nextPart() and read the part from stream().

Always ensure that you read all data from the part stream, otherwise the MultipartReader will fail to find the next part.

## Member Summary

Member Functions: boundary, findFirstBoundary, guessBoundary, hasNextPart, nextPart, parseHeader, readLine, stream

## Constructors

### MultipartReader

explicit MultipartReader(
std::istream & istr
);

Creates the MultipartReader and attaches it to the given input stream.

The boundary string is determined from the input stream. The message must not contain a preamble preceding the first encapsulation boundary.

### MultipartReader

MultipartReader(
std::istream & istr,
const std::string & boundary
);

Creates the MultipartReader and attaches it to the given input stream. The given boundary string is used to find message boundaries.

## Destructor

### ~MultipartReader

~MultipartReader();

Destroys the MultipartReader.

## Member Functions

### boundary

const std::string & boundary() const;

Returns the multipart boundary used by this reader.

### hasNextPart

bool hasNextPart();

Returns true iff more parts are available.

Before the first call to nextPart(), returns always true.

### nextPart

void nextPart(
MessageHeader & messageHeader
);

Moves to the next part in the message and stores the part's header fields in messageHeader.

Throws an MultipartException if there are no more parts available, or if no boundary line can be found in the input stream.

### stream

std::istream & stream() const;

Returns a reference to the reader's stream that can be used to read the current part.

The returned reference will be valid until nextPart() is called or the MultipartReader object is destroyed.

### findFirstBoundary

void findFirstBoundary();

### guessBoundary

void guessBoundary();

### parseHeader

void parseHeader(
MessageHeader & messageHeader
);

### readLine

bool readLine(
std::string & line,
std::string::size_type n
);