2004-10-05 10:28:21 +00:00
|
|
|
//
|
2005-03-18 21:33:11 +00:00
|
|
|
// VMime library (http://www.vmime.org)
|
2013-01-10 16:30:31 +00:00
|
|
|
// Copyright (C) 2002-2013 Vincent Richard <vincent@vmime.org>
|
2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
2009-09-06 12:02:10 +00:00
|
|
|
// published by the Free Software Foundation; either version 3 of
|
2004-10-05 10:28:21 +00:00
|
|
|
// the License, or (at your option) any later version.
|
|
|
|
//
|
|
|
|
// This program is distributed in the hope that it will be useful,
|
|
|
|
// but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
// General Public License for more details.
|
|
|
|
//
|
2005-09-17 10:10:29 +00:00
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// Linking this library statically or dynamically with other modules is making
|
|
|
|
// a combined work based on this library. Thus, the terms and conditions of
|
|
|
|
// the GNU General Public License cover the whole combination.
|
2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef VMIME_COMPONENT_HPP_INCLUDED
|
|
|
|
#define VMIME_COMPONENT_HPP_INCLUDED
|
|
|
|
|
|
|
|
|
2004-12-26 20:23:29 +00:00
|
|
|
#include "vmime/base.hpp"
|
2012-04-14 11:46:05 +00:00
|
|
|
#include "vmime/utility/inputStream.hpp"
|
2012-04-16 20:32:33 +00:00
|
|
|
#include "vmime/utility/seekableInputStream.hpp"
|
|
|
|
#include "vmime/utility/parserInputStreamAdapter.hpp"
|
2012-04-14 11:46:05 +00:00
|
|
|
#include "vmime/utility/outputStream.hpp"
|
2013-02-24 15:28:13 +00:00
|
|
|
#include "vmime/generationContext.hpp"
|
|
|
|
#include "vmime/parsingContext.hpp"
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
|
|
|
|
namespace vmime
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2010-05-21 09:32:42 +00:00
|
|
|
/** This abstract class is the base class for all the components of a message.
|
|
|
|
* It defines methods for parsing and generating a component.
|
2004-10-05 10:28:21 +00:00
|
|
|
*/
|
|
|
|
|
2013-05-12 14:51:40 +00:00
|
|
|
class VMIME_EXPORT component : public object
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
2004-10-21 15:05:47 +00:00
|
|
|
public:
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-12-15 20:28:09 +00:00
|
|
|
component();
|
2004-10-21 15:05:47 +00:00
|
|
|
virtual ~component();
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component, using the default
|
|
|
|
* parsing context.
|
2004-10-05 10:28:21 +00:00
|
|
|
*
|
|
|
|
* @param buffer input buffer
|
|
|
|
*/
|
|
|
|
void parse(const string& buffer);
|
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component.
|
|
|
|
*
|
|
|
|
* @param ctx parsing context
|
|
|
|
* @param buffer input buffer
|
|
|
|
*/
|
|
|
|
void parse(const parsingContext& ctx, const string& buffer);
|
|
|
|
|
2012-04-16 20:32:33 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component. If stream is not seekable,
|
|
|
|
* or if length is not specified, entire contents of the stream will
|
|
|
|
* be loaded into memory before parsing.
|
2013-02-24 15:28:13 +00:00
|
|
|
*
|
|
|
|
* @param inputStream stream from which to read data
|
|
|
|
* @param length data length, in bytes (0 = unknown/not specified)
|
2012-04-16 20:32:33 +00:00
|
|
|
*/
|
|
|
|
void parse(ref <utility::inputStream> inputStream, const utility::stream::size_type length);
|
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component, using the default
|
|
|
|
* parsing context.
|
2004-10-05 10:28:21 +00:00
|
|
|
*
|
|
|
|
* @param buffer input buffer
|
|
|
|
* @param position current position in the input buffer
|
|
|
|
* @param end end position in the input buffer
|
|
|
|
* @param newPosition will receive the new position in the input buffer
|
|
|
|
*/
|
2012-04-16 20:32:33 +00:00
|
|
|
void parse
|
|
|
|
(const string& buffer,
|
|
|
|
const string::size_type position,
|
|
|
|
const string::size_type end,
|
|
|
|
string::size_type* newPosition = NULL);
|
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component.
|
|
|
|
*
|
|
|
|
* @param ctx parsing context
|
|
|
|
* @param buffer input buffer
|
|
|
|
* @param position current position in the input buffer
|
|
|
|
* @param end end position in the input buffer
|
|
|
|
* @param newPosition will receive the new position in the input buffer
|
|
|
|
*/
|
|
|
|
void parse
|
|
|
|
(const parsingContext& ctx,
|
|
|
|
const string& buffer,
|
|
|
|
const string::size_type position,
|
|
|
|
const string::size_type end,
|
|
|
|
string::size_type* newPosition = NULL);
|
|
|
|
|
2012-04-16 20:32:33 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component. If stream is not seekable,
|
|
|
|
* or if end position is not specified, entire contents of the stream will
|
2013-02-24 15:28:13 +00:00
|
|
|
* be loaded into memory before parsing. The default parsing context
|
|
|
|
* will be used.
|
2012-04-16 20:32:33 +00:00
|
|
|
*
|
|
|
|
* @param inputStream stream from which to read data
|
|
|
|
* @param position current position in the input stream
|
|
|
|
* @param end end position in the input stream
|
|
|
|
* @param newPosition will receive the new position in the input stream
|
|
|
|
*/
|
|
|
|
void parse
|
|
|
|
(ref <utility::inputStream> inputStream,
|
|
|
|
const utility::stream::size_type position,
|
|
|
|
const utility::stream::size_type end,
|
|
|
|
utility::stream::size_type* newPosition = NULL);
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Parse RFC-822/MIME data for this component. If stream is not seekable,
|
|
|
|
* or if end position is not specified, entire contents of the stream will
|
|
|
|
* be loaded into memory before parsing.
|
|
|
|
*
|
|
|
|
* @param ctx parsing context
|
|
|
|
* @param inputStream stream from which to read data
|
|
|
|
* @param position current position in the input stream
|
|
|
|
* @param end end position in the input stream
|
|
|
|
* @param newPosition will receive the new position in the input stream
|
|
|
|
*/
|
|
|
|
void parse
|
|
|
|
(const parsingContext& ctx,
|
|
|
|
ref <utility::inputStream> inputStream,
|
|
|
|
const utility::stream::size_type position,
|
|
|
|
const utility::stream::size_type end,
|
|
|
|
utility::stream::size_type* newPosition = NULL);
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
/** Generate RFC-2822/MIME data for this component.
|
|
|
|
*
|
|
|
|
* \deprecated Use the new generate() method, which takes an outputStream parameter.
|
|
|
|
*
|
|
|
|
* @param maxLineLength maximum line length for output
|
|
|
|
* @param curLinePos length of the current line in the output buffer
|
|
|
|
* @return generated data
|
|
|
|
*/
|
2012-04-16 20:32:33 +00:00
|
|
|
virtual const string generate
|
|
|
|
(const string::size_type maxLineLength = lineLengthLimits::infinite,
|
|
|
|
const string::size_type curLinePos = 0) const;
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Generate RFC-2822/MIME data for this component, using the default generation context.
|
2004-10-05 10:28:21 +00:00
|
|
|
*
|
2012-04-16 20:32:33 +00:00
|
|
|
* @param outputStream output stream
|
2004-10-05 10:28:21 +00:00
|
|
|
* @param maxLineLength maximum line length for output
|
|
|
|
* @param curLinePos length of the current line in the output buffer
|
|
|
|
* @param newLinePos will receive the new line position (length of the last line written)
|
|
|
|
*/
|
2012-04-16 20:32:33 +00:00
|
|
|
virtual void generate
|
|
|
|
(utility::outputStream& outputStream,
|
|
|
|
const string::size_type curLinePos = 0,
|
|
|
|
string::size_type* newLinePos = NULL) const;
|
|
|
|
|
2013-02-24 15:28:13 +00:00
|
|
|
/** Generate RFC-2822/MIME data for this component, using the default generation context.
|
2012-04-16 20:32:33 +00:00
|
|
|
*
|
2013-02-24 15:28:13 +00:00
|
|
|
* @param ctx generation context
|
2012-04-16 20:32:33 +00:00
|
|
|
* @param outputStream output stream
|
|
|
|
* @param maxLineLength maximum line length for output
|
|
|
|
* @param curLinePos length of the current line in the output buffer
|
|
|
|
* @param newLinePos will receive the new line position (length of the last line written)
|
|
|
|
*/
|
|
|
|
virtual void generate
|
2013-02-24 15:28:13 +00:00
|
|
|
(const generationContext& ctx,
|
|
|
|
utility::outputStream& outputStream,
|
2012-04-16 20:32:33 +00:00
|
|
|
const string::size_type curLinePos = 0,
|
|
|
|
string::size_type* newLinePos = NULL) const;
|
2004-10-21 15:05:47 +00:00
|
|
|
|
|
|
|
/** Clone this component.
|
|
|
|
*
|
|
|
|
* @return a copy of this component
|
|
|
|
*/
|
2005-07-12 22:28:02 +00:00
|
|
|
virtual ref <component> clone() const = 0;
|
2004-10-21 15:05:47 +00:00
|
|
|
|
|
|
|
/** Replace data in this component by data in other component.
|
|
|
|
* Both components must be of the same type.
|
|
|
|
*
|
|
|
|
* @throw std::bad_cast_exception if the components are not
|
|
|
|
* of the same (dynamic) type
|
|
|
|
* @param other other component to copy data from
|
|
|
|
*/
|
|
|
|
virtual void copyFrom(const component& other) = 0;
|
2004-12-15 20:28:09 +00:00
|
|
|
|
|
|
|
/** Return the start position of this component in the
|
2012-04-16 20:32:33 +00:00
|
|
|
* parsed message contents. Use for debugging only.
|
2004-12-15 20:28:09 +00:00
|
|
|
*
|
|
|
|
* @return start position in parsed buffer
|
|
|
|
* or 0 if this component has not been parsed
|
|
|
|
*/
|
2012-04-16 20:32:33 +00:00
|
|
|
utility::stream::size_type getParsedOffset() const;
|
2004-12-15 20:28:09 +00:00
|
|
|
|
|
|
|
/** Return the length of this component in the
|
2012-04-16 20:32:33 +00:00
|
|
|
* parsed message contents. Use for debugging only.
|
2004-12-15 20:28:09 +00:00
|
|
|
*
|
|
|
|
* @return length of the component in parsed buffer
|
|
|
|
* or 0 if this component has not been parsed
|
|
|
|
*/
|
2012-04-16 20:32:33 +00:00
|
|
|
utility::stream::size_type getParsedLength() const;
|
2004-12-15 20:28:09 +00:00
|
|
|
|
2004-12-20 12:33:55 +00:00
|
|
|
/** Return the list of children of this component.
|
|
|
|
*
|
|
|
|
* @return list of child components
|
|
|
|
*/
|
2012-04-16 20:32:33 +00:00
|
|
|
virtual const std::vector <ref <component> > getChildComponents() = 0;
|
2004-12-20 12:33:55 +00:00
|
|
|
|
2013-06-24 13:32:40 +00:00
|
|
|
/** Get the number of bytes that will be used by this component when
|
|
|
|
* it is generated. This may be a heuristically-derived estimate,
|
|
|
|
* but such an estimated size should always be larger than the actual
|
|
|
|
* generated size.
|
|
|
|
*
|
|
|
|
* @param ctx generation context
|
|
|
|
* @return component size when generated
|
|
|
|
*/
|
|
|
|
virtual utility::stream::size_type getGeneratedSize(const generationContext& ctx);
|
|
|
|
|
2004-12-15 20:28:09 +00:00
|
|
|
protected:
|
|
|
|
|
2012-04-16 20:32:33 +00:00
|
|
|
void setParsedBounds(const utility::stream::size_type start, const utility::stream::size_type end);
|
|
|
|
|
|
|
|
// AT LEAST ONE of these parseImpl() functions MUST be implemented in derived class
|
|
|
|
virtual void parseImpl
|
2013-02-24 15:28:13 +00:00
|
|
|
(const parsingContext& ctx,
|
|
|
|
ref <utility::parserInputStreamAdapter> parser,
|
2012-04-16 20:32:33 +00:00
|
|
|
const utility::stream::size_type position,
|
|
|
|
const utility::stream::size_type end,
|
|
|
|
utility::stream::size_type* newPosition = NULL);
|
|
|
|
|
|
|
|
virtual void parseImpl
|
2013-02-24 15:28:13 +00:00
|
|
|
(const parsingContext& ctx,
|
|
|
|
const string& buffer,
|
2012-04-16 20:32:33 +00:00
|
|
|
const string::size_type position,
|
|
|
|
const string::size_type end,
|
|
|
|
string::size_type* newPosition = NULL);
|
|
|
|
|
|
|
|
virtual void generateImpl
|
2013-02-24 15:28:13 +00:00
|
|
|
(const generationContext& ctx,
|
|
|
|
utility::outputStream& os,
|
2012-04-16 20:32:33 +00:00
|
|
|
const string::size_type curLinePos = 0,
|
|
|
|
string::size_type* newLinePos = NULL) const = 0;
|
2004-12-15 20:28:09 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
|
2012-04-16 20:32:33 +00:00
|
|
|
void offsetParsedBounds(const utility::stream::size_type offset);
|
|
|
|
|
|
|
|
utility::stream::size_type m_parsedOffset;
|
|
|
|
utility::stream::size_type m_parsedLength;
|
2004-10-05 10:28:21 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
} // vmime
|
|
|
|
|
|
|
|
|
|
|
|
#endif // VMIME_COMPONENT_HPP_INCLUDED
|