Refactored header field values and parameters.

This commit is contained in:
Vincent Richard 2005-11-04 23:21:22 +00:00
parent 14e4d1f06d
commit acfa9ffc64
74 changed files with 1058 additions and 1279 deletions

View File

@ -2,6 +2,10 @@
VERSION 0.7.2cvs VERSION 0.7.2cvs
================ ================
2005-11-05 Vincent Richard <vincent@vincent-richard.net>
* Refactored header field values and parameters.
2005-10-19 Vincent Richard <vincent@vincent-richard.net> 2005-10-19 Vincent Richard <vincent@vincent-richard.net>
* charsetConverter.{hpp|cpp}: new object 'charsetConverter' for converting * charsetConverter.{hpp|cpp}: new object 'charsetConverter' for converting

View File

@ -91,7 +91,6 @@ libvmime_sources = [
'contentTypeField.cpp', 'contentTypeField.hpp', 'contentTypeField.cpp', 'contentTypeField.hpp',
'dateTime.cpp', 'dateTime.hpp', 'dateTime.cpp', 'dateTime.hpp',
'defaultAttachment.cpp', 'defaultAttachment.hpp', 'defaultAttachment.cpp', 'defaultAttachment.hpp',
'defaultParameter.cpp', 'defaultParameter.hpp',
'disposition.cpp', 'disposition.hpp', 'disposition.cpp', 'disposition.hpp',
'emptyContentHandler.cpp', 'emptyContentHandler.hpp', 'emptyContentHandler.cpp', 'emptyContentHandler.hpp',
'encoder.cpp', 'encoder.hpp', 'encoder.cpp', 'encoder.hpp',
@ -126,7 +125,6 @@ libvmime_sources = [
'options.cpp', 'options.hpp', 'options.cpp', 'options.hpp',
'path.cpp', 'path.hpp', 'path.cpp', 'path.hpp',
'parameter.cpp', 'parameter.hpp', 'parameter.cpp', 'parameter.hpp',
'parameterFactory.cpp', 'parameterFactory.hpp',
'parameterizedHeaderField.cpp', 'parameterizedHeaderField.hpp', 'parameterizedHeaderField.cpp', 'parameterizedHeaderField.hpp',
'parserHelpers.hpp', 'parserHelpers.hpp',
'plainTextPart.cpp', 'plainTextPart.hpp', 'plainTextPart.cpp', 'plainTextPart.hpp',
@ -140,7 +138,6 @@ libvmime_sources = [
'text.cpp', 'text.hpp', 'text.cpp', 'text.hpp',
'textPartFactory.cpp', 'textPartFactory.hpp', 'textPartFactory.cpp', 'textPartFactory.hpp',
'textPart.hpp', 'textPart.hpp',
'typeAdapter.cpp', 'typeAdapter.hpp',
'types.hpp', 'types.hpp',
'word.cpp', 'word.hpp', 'word.cpp', 'word.hpp',
'vmime.hpp', 'vmime.hpp',

View File

@ -37,7 +37,7 @@ addressList::addressList()
addressList::addressList(const addressList& addrList) addressList::addressList(const addressList& addrList)
: component() : headerFieldValue()
{ {
copyFrom(addrList); copyFrom(addrList);
} }

View File

@ -24,6 +24,7 @@
#include "vmime/attachmentHelper.hpp" #include "vmime/attachmentHelper.hpp"
#include "vmime/bodyPartAttachment.hpp" #include "vmime/bodyPartAttachment.hpp"
#include "vmime/disposition.hpp"
namespace vmime namespace vmime
@ -38,10 +39,13 @@ const bool attachmentHelper::isBodyPartAnAttachment(ref <const bodyPart> part)
const contentDispositionField& cdf = dynamic_cast<contentDispositionField&> const contentDispositionField& cdf = dynamic_cast<contentDispositionField&>
(*part->getHeader()->findField(fields::CONTENT_DISPOSITION)); (*part->getHeader()->findField(fields::CONTENT_DISPOSITION));
if (cdf.getValue().getName() != contentDispositionTypes::INLINE) const contentDisposition disp = *cdf.getValue()
.dynamicCast <const contentDisposition>();
if (disp.getName() != contentDispositionTypes::INLINE)
return true; return true;
} }
catch (exceptions::no_such_field) catch (exceptions::no_such_field&)
{ {
// No "Content-disposition" field: assume "attachment" if // No "Content-disposition" field: assume "attachment" if
// type is not "text/..." or "multipart/...". // type is not "text/..." or "multipart/...".
@ -52,9 +56,9 @@ const bool attachmentHelper::isBodyPartAnAttachment(ref <const bodyPart> part)
const contentTypeField& ctf = dynamic_cast<contentTypeField&> const contentTypeField& ctf = dynamic_cast<contentTypeField&>
(*part->getHeader()->findField(fields::CONTENT_TYPE)); (*part->getHeader()->findField(fields::CONTENT_TYPE));
type = ctf.getValue(); type = *ctf.getValue().dynamicCast <const mediaType>();
} }
catch (exceptions::no_such_field) catch (exceptions::no_such_field&)
{ {
// No "Content-type" field: assume "application/octet-stream". // No "Content-type" field: assume "application/octet-stream".
type = mediaType(mediaTypes::APPLICATION, type = mediaType(mediaTypes::APPLICATION,

View File

@ -39,7 +39,6 @@
// For initializing // For initializing
#include "vmime/encoderFactory.hpp" #include "vmime/encoderFactory.hpp"
#include "vmime/headerFieldFactory.hpp" #include "vmime/headerFieldFactory.hpp"
#include "vmime/parameterFactory.hpp"
#include "vmime/textPartFactory.hpp" #include "vmime/textPartFactory.hpp"
#include "vmime/options.hpp" #include "vmime/options.hpp"
@ -143,7 +142,6 @@ public:
encoderFactory::getInstance(); encoderFactory::getInstance();
headerFieldFactory::getInstance(); headerFieldFactory::getInstance();
parameterFactory::getInstance();
textPartFactory::getInstance(); textPartFactory::getInstance();
#if VMIME_HAVE_MESSAGING_FEATURES #if VMIME_HAVE_MESSAGING_FEATURES

View File

@ -27,6 +27,7 @@
#include "vmime/options.hpp" #include "vmime/options.hpp"
#include "vmime/contentTypeField.hpp" #include "vmime/contentTypeField.hpp"
#include "vmime/text.hpp"
#include "vmime/utility/random.hpp" #include "vmime/utility/random.hpp"
@ -65,7 +66,9 @@ void body::parse(const string& buffer, const string::size_type position,
const ref <const contentTypeField> ctf = const ref <const contentTypeField> ctf =
m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>(); m_header->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>();
if (ctf->getValue().getType() == mediaTypes::MULTIPART) const mediaType type = *ctf->getValue().dynamicCast <const mediaType>();
if (type.getType() == mediaTypes::MULTIPART)
{ {
isMultipart = true; isMultipart = true;
@ -388,7 +391,7 @@ const mediaType body::getContentType() const
ref <const contentTypeField> ctf = ref <const contentTypeField> ctf =
m_header->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>(); m_header->findField(fields::CONTENT_TYPE).dynamicCast <const contentTypeField>();
return (ctf->getValue()); return (*ctf->getValue().dynamicCast <const mediaType>());
} }
catch (exceptions::no_such_field&) catch (exceptions::no_such_field&)
{ {
@ -424,10 +427,10 @@ const encoding body::getEncoding() const
{ {
try try
{ {
const ref <const contentEncodingField> cef = const ref <const headerField> cef =
m_header->findField(fields::CONTENT_TRANSFER_ENCODING).dynamicCast <contentEncodingField>(); m_header->findField(fields::CONTENT_TRANSFER_ENCODING);
return (cef->getValue()); return (*cef->getValue().dynamicCast <const encoding>());
} }
catch (exceptions::no_such_field&) catch (exceptions::no_such_field&)
{ {
@ -550,7 +553,7 @@ void body::initNewPart(ref <bodyPart> part)
ctf->setBoundary(generateRandomBoundaryString()); ctf->setBoundary(generateRandomBoundaryString());
} }
if (ctf->getValue().getType() != mediaTypes::MULTIPART) if (ctf->getValue().dynamicCast <const mediaType>()->getType() != mediaTypes::MULTIPART)
{ {
// Warning: multi-part body but the Content-Type is // Warning: multi-part body but the Content-Type is
// not specified as "multipart/..." // not specified as "multipart/..."

View File

@ -40,7 +40,7 @@ const mediaType bodyPartAttachment::getType() const
try try
{ {
type = getContentType()->getValue(); type = *getContentType()->getValue().dynamicCast <const mediaType>();
} }
catch (exceptions::no_such_field&) catch (exceptions::no_such_field&)
{ {
@ -76,8 +76,7 @@ const word bodyPartAttachment::getName() const
{ {
try try
{ {
ref <defaultParameter> prm = getContentType()-> ref <parameter> prm = getContentType()->findParameter("name");
findParameter("name").dynamicCast <defaultParameter>();
if (prm != NULL) if (prm != NULL)
name = prm->getValue(); name = prm->getValue();
@ -102,10 +101,10 @@ const text bodyPartAttachment::getDescription() const
try try
{ {
const textField& cd = dynamic_cast <textField&> ref <const headerField> cd =
(*getHeader()->findField(fields::CONTENT_DESCRIPTION)); getHeader()->findField(fields::CONTENT_DESCRIPTION);
description = cd.getValue(); description = *cd->getValue().dynamicCast <const text>();
} }
catch (exceptions::no_such_field&) catch (exceptions::no_such_field&)
{ {

View File

@ -42,7 +42,7 @@ contentDisposition::contentDisposition(const string& name)
contentDisposition::contentDisposition(const contentDisposition& type) contentDisposition::contentDisposition(const contentDisposition& type)
: component(), m_name(type.m_name) : headerFieldValue(), m_name(type.m_name)
{ {
} }

View File

@ -24,8 +24,6 @@
#include "vmime/contentDispositionField.hpp" #include "vmime/contentDispositionField.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/standardParams.hpp"
namespace vmime namespace vmime
{ {
@ -37,68 +35,68 @@ contentDispositionField::contentDispositionField()
contentDispositionField::contentDispositionField(contentDispositionField&) contentDispositionField::contentDispositionField(contentDispositionField&)
: headerField(), parameterizedHeaderField(), genericField <contentDisposition>() : headerField(), parameterizedHeaderField()
{ {
} }
const datetime& contentDispositionField::getCreationDate() const const datetime contentDispositionField::getCreationDate() const
{ {
return (dynamic_cast <const dateParameter&>(*findParameter("creation-date")).getValue()); return findParameter("creation-date")->getValueAs <datetime>();
} }
void contentDispositionField::setCreationDate(const datetime& creationDate) void contentDispositionField::setCreationDate(const datetime& creationDate)
{ {
dynamic_cast <dateParameter&>(*getParameter("creation-date")).setValue(creationDate); getParameter("creation-date")->setValue(creationDate);
} }
const datetime& contentDispositionField::getModificationDate() const const datetime contentDispositionField::getModificationDate() const
{ {
return (dynamic_cast <const dateParameter&>(*findParameter("modification-date")).getValue()); return findParameter("modification-date")->getValueAs <datetime>();
} }
void contentDispositionField::setModificationDate(const datetime& modificationDate) void contentDispositionField::setModificationDate(const datetime& modificationDate)
{ {
dynamic_cast <dateParameter&>(*getParameter("modification-date")).setValue(modificationDate); getParameter("modification-date")->setValue(modificationDate);
} }
const datetime& contentDispositionField::getReadDate() const const datetime contentDispositionField::getReadDate() const
{ {
return (dynamic_cast <const dateParameter&>(*findParameter("read-date")).getValue()); return findParameter("read-date")->getValueAs <datetime>();
} }
void contentDispositionField::setReadDate(const datetime& readDate) void contentDispositionField::setReadDate(const datetime& readDate)
{ {
dynamic_cast <dateParameter&>(*getParameter("read-date")).setValue(readDate); getParameter("read-date")->setValue(readDate);
} }
const word contentDispositionField::getFilename() const const word contentDispositionField::getFilename() const
{ {
return (dynamic_cast <const defaultParameter&>(*findParameter("filename")).getValue()); return findParameter("filename")->getValue();
} }
void contentDispositionField::setFilename(const word& filename) void contentDispositionField::setFilename(const word& filename)
{ {
dynamic_cast <defaultParameter&>(*getParameter("filename")).setValue(filename); getParameter("filename")->setValue(filename);
} }
const string contentDispositionField::getSize() const const string contentDispositionField::getSize() const
{ {
return (dynamic_cast <const defaultParameter&>(*findParameter("size")).getValue().getBuffer()); return findParameter("size")->getValue().getBuffer();
} }
void contentDispositionField::setSize(const string& size) void contentDispositionField::setSize(const string& size)
{ {
dynamic_cast <defaultParameter&>(*getParameter("size")).setValue(word(size)); getParameter("size")->setValue(word(size, vmime::charsets::US_ASCII));
} }

View File

@ -24,8 +24,6 @@
#include "vmime/contentTypeField.hpp" #include "vmime/contentTypeField.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/standardParams.hpp"
namespace vmime namespace vmime
{ {
@ -37,45 +35,46 @@ contentTypeField::contentTypeField()
contentTypeField::contentTypeField(contentTypeField&) contentTypeField::contentTypeField(contentTypeField&)
: headerField(), parameterizedHeaderField(), genericField <mediaType>() : headerField(), parameterizedHeaderField()
{ {
} }
const string contentTypeField::getBoundary() const const string contentTypeField::getBoundary() const
{ {
return (dynamic_cast <const defaultParameter&>(*findParameter("boundary")).getValue().getBuffer()); return findParameter("boundary")->getValue().getBuffer();
} }
void contentTypeField::setBoundary(const string& boundary) void contentTypeField::setBoundary(const string& boundary)
{ {
dynamic_cast <defaultParameter&>(*getParameter("boundary")).setValue(word(boundary)); getParameter("boundary")->setValue(word(boundary, vmime::charsets::US_ASCII));
} }
const charset& contentTypeField::getCharset() const const charset contentTypeField::getCharset() const
{ {
return (dynamic_cast <const charsetParameter&>(*findParameter("charset")).getValue()); return findParameter("charset")->getValueAs <charset>();
} }
void contentTypeField::setCharset(const charset& ch) void contentTypeField::setCharset(const charset& ch)
{ {
dynamic_cast <charsetParameter&>(*getParameter("charset")).setValue(ch); getParameter("charset")->setValue(ch);
} }
const string contentTypeField::getReportType() const const string contentTypeField::getReportType() const
{ {
return (dynamic_cast <const defaultParameter&>(*findParameter("report-type")).getValue().getBuffer()); return findParameter("report-type")->getValue().getBuffer();
} }
void contentTypeField::setReportType(const string& reportType) void contentTypeField::setReportType(const string& reportType)
{ {
dynamic_cast <defaultParameter&>(*getParameter("report-type")).setValue(word(reportType)); getParameter("report-type")->setValue(word(reportType, vmime::charsets::US_ASCII));
} }
} // vmime } // vmime

View File

@ -640,7 +640,7 @@ datetime::datetime(const int year, const int month, const int day,
datetime::datetime(const datetime& d) datetime::datetime(const datetime& d)
: component(), m_year(d.m_year), m_month(d.m_month), m_day(d.m_day), : headerFieldValue(), m_year(d.m_year), m_month(d.m_month), m_day(d.m_day),
m_hour(d.m_hour), m_minute(d.m_minute), m_second(d.m_second), m_zone(d.m_zone) m_hour(d.m_hour), m_minute(d.m_minute), m_second(d.m_second), m_zone(d.m_zone)
{ {
} }

View File

@ -22,6 +22,8 @@
// //
#include "vmime/defaultAttachment.hpp" #include "vmime/defaultAttachment.hpp"
#include "vmime/contentDisposition.hpp"
#include "vmime/encoding.hpp" #include "vmime/encoding.hpp"

View File

@ -1,437 +0,0 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// 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.
//
// 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.
//
#include "vmime/defaultParameter.hpp"
#include "vmime/parserHelpers.hpp"
namespace vmime
{
defaultParameter::defaultParameter()
: m_value(vmime::create <word>())
{
}
defaultParameter& defaultParameter::operator=(const defaultParameter& other)
{
copyFrom(other);
return (*this);
}
const ref <const component> defaultParameter::getValueImp() const
{
return (m_value);
}
const ref <component> defaultParameter::getValueImp()
{
return (m_value);
}
const word& defaultParameter::getValue() const
{
return (*m_value);
}
word& defaultParameter::getValue()
{
return (*m_value);
}
void defaultParameter::setValue(const word& value)
{
*m_value = value;
}
void defaultParameter::setValue(const component& value)
{
const word& v = dynamic_cast <const word&>(value);
*m_value = v;
}
void defaultParameter::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
m_value = vmime::create <word>
(string(buffer.begin() + position, buffer.begin() + end),
charset(charsets::US_ASCII));
if (newPosition)
*newPosition = end;
}
void defaultParameter::parse(const std::vector <valueChunk>& chunks)
{
bool foundCharsetChunk = false;
charset ch(charsets::US_ASCII);
std::ostringstream value;
for (std::vector <valueChunk>::size_type i = 0 ; i < chunks.size() ; ++i)
{
const valueChunk& chunk = chunks[i];
// Decode following data
if (chunk.encoded)
{
const string::size_type len = chunk.data.length();
string::size_type pos = 0;
// If this is the first encoded chunk, extract charset
// and language information
if (!foundCharsetChunk)
{
// Eg. "us-ascii'en'This%20is%20even%20more%20"
string::size_type q = chunk.data.find_first_of('\'');
if (q != string::npos)
{
const string chs = chunk.data.substr(0, q);
if (!chs.empty())
ch = charset(chs);
++q;
pos = q;
}
q = chunk.data.find_first_of('\'', pos);
if (q != string::npos)
{
// Ignore language
++q;
pos = q;
}
foundCharsetChunk = true;
}
for (string::size_type i = pos ; i < len ; ++i)
{
const string::value_type c = chunk.data[i];
if (c == '%' && i + 2 < len)
{
string::value_type v = 0;
// First char
switch (chunk.data[i + 1])
{
case 'a': case 'A': v += 10; break;
case 'b': case 'B': v += 11; break;
case 'c': case 'C': v += 12; break;
case 'd': case 'D': v += 13; break;
case 'e': case 'E': v += 14; break;
case 'f': case 'F': v += 15; break;
default: // assume 0-9
v += (chunk.data[i + 1] - '0');
break;
}
v *= 16;
// Second char
switch (chunk.data[i + 2])
{
case 'a': case 'A': v += 10; break;
case 'b': case 'B': v += 11; break;
case 'c': case 'C': v += 12; break;
case 'd': case 'D': v += 13; break;
case 'e': case 'E': v += 14; break;
case 'f': case 'F': v += 15; break;
default: // assume 0-9
v += (chunk.data[i + 2] - '0');
break;
}
value << v;
i += 2; // skip next 2 chars
}
else
{
value << c;
}
}
}
// Simply copy data, as it is not encoded
else
{
value << chunk.data;
}
}
m_value = vmime::create <word>(value.str(), ch);
}
void defaultParameter::generate(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
const string& name = getName();
const string& value = m_value->getBuffer();
// For compatibility with implementations that do not understand RFC-2231,
// also generate a normal "7bit/us-ascii" parameter
string::size_type pos = curLinePos;
if (pos + name.length() + 10 + value.length() > maxLineLength)
{
os << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
bool needQuoting = false;
string::size_type valueLength = 0;
for (string::size_type i = 0 ; (i < value.length()) && (pos + valueLength < maxLineLength - 4) ; ++i, ++valueLength)
{
switch (value[i])
{
// Characters that need to be quoted _and_ escaped
case '"':
case '\\':
// Other characters that need quoting
case ' ':
case '\t':
case '(':
case ')':
case '<':
case '>':
case '@':
case ',':
case ';':
case ':':
case '/':
case '[':
case ']':
case '?':
case '=':
needQuoting = true;
break;
}
}
const bool cutValue = (valueLength != value.length()); // has the value been cut?
if (needQuoting)
{
os << name << "=\"";
pos += name.length() + 2;
}
else
{
os << name << "=";
pos += name.length() + 1;
}
bool extended = false;
for (string::size_type i = 0 ; (i < value.length()) && (pos < maxLineLength - 4) ; ++i)
{
const char_t c = value[i];
if (/* needQuoting && */ (c == '"' || c == '\\')) // 'needQuoting' is implicit
{
os << '\\' << value[i]; // escape 'x' with '\x'
pos += 2;
}
else if (parserHelpers::isAscii(c))
{
os << value[i];
++pos;
}
else
{
extended = true;
}
}
if (needQuoting)
{
os << '"';
++pos;
}
// Also generate an extended parameter if the value contains 8-bit characters
// or is too long for a single line
if (extended || cutValue)
{
os << ';';
++pos;
/* RFC-2231
* ========
*
* Content-Type: message/external-body; access-type=URL;
* URL*0="ftp://";
* URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
*
* Content-Type: application/x-stuff;
* title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A
*
* Content-Type: application/x-stuff;
* title*0*=us-ascii'en'This%20is%20even%20more%20
* title*1*=%2A%2A%2Afun%2A%2A%2A%20
* title*2="isn't it!"
*/
// Check whether there is enough space for the first section:
// parameter name, section identifier, charset and separators
// + at least 5 characters for the value
const string::size_type firstSectionLength =
name.length() + 4 /* *0*= */ + 2 /* '' */
+ m_value->getCharset().getName().length();
if (pos + firstSectionLength + 5 >= maxLineLength)
{
os << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
// Split text into multiple sections that fit on one line
int sectionCount = 0;
std::vector <string> sectionText;
string currentSection;
string::size_type currentSectionLength = firstSectionLength;
for (string::size_type i = 0 ; i < value.length() ; ++i)
{
// Check whether we should start a new line (taking into
// account the next character will be encoded = worst case)
if (currentSectionLength + 3 >= maxLineLength)
{
sectionText.push_back(currentSection);
sectionCount++;
currentSection.clear();
currentSectionLength = NEW_LINE_SEQUENCE_LENGTH
+ name.length() + 6;
}
// Output next character
const char_t c = value[i];
bool encode = false;
switch (c)
{
// special characters
case ' ':
case '\t':
case '\r':
case '\n':
case '"':
case ';':
case ',':
encode = true;
break;
default:
encode = (!parserHelpers::isPrint(c) ||
!parserHelpers::isAscii(c));
break;
}
if (encode) // need encoding
{
const int h1 = static_cast <unsigned char>(c) / 16;
const int h2 = static_cast <unsigned char>(c) % 16;
currentSection += '%';
currentSection += "0123456789ABCDEF"[h1];
currentSection += "0123456789ABCDEF"[h2];
pos += 3;
currentSectionLength += 3;
}
else
{
currentSection += value[i];
++pos;
++currentSectionLength;
}
}
if (!currentSection.empty())
{
sectionText.push_back(currentSection);
sectionCount++;
}
// Output sections
for (int sectionNumber = 0 ; sectionNumber < sectionCount ; ++sectionNumber)
{
os << name;
if (sectionCount != 1) // no section specifier when only a single one
{
os << '*';
os << sectionNumber;
}
os << "*=";
if (sectionNumber == 0)
{
os << m_value->getCharset().getName();
os << '\'' << /* No language */ '\'';
}
os << sectionText[sectionNumber];
if (sectionNumber + 1 < sectionCount)
{
os << ';';
os << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
}
}
if (newLinePos)
*newLinePos = pos;
}
} // vmime

View File

@ -45,7 +45,7 @@ encoding::encoding(const string& name)
encoding::encoding(const encoding& enc) encoding::encoding(const encoding& enc)
: component(), m_name(enc.m_name) : headerFieldValue(), m_name(enc.m_name)
{ {
} }

View File

@ -29,6 +29,8 @@
#include "vmime/streamContentHandler.hpp" #include "vmime/streamContentHandler.hpp"
#include "vmime/contentDispositionField.hpp"
namespace vmime namespace vmime
{ {
@ -78,7 +80,8 @@ void fileAttachment::generatePart(bodyPart& part) const
{ {
defaultAttachment::generatePart(part); defaultAttachment::generatePart(part);
ref <contentDispositionField> cdf = part.getHeader()->ContentDisposition(); ref <contentDispositionField> cdf = part.getHeader()->ContentDisposition().
dynamicCast <contentDispositionField>();
if (m_fileInfo.hasSize()) cdf->setSize(utility::stringUtils::toString(m_fileInfo.getSize())); if (m_fileInfo.hasSize()) cdf->setSize(utility::stringUtils::toString(m_fileInfo.getSize()));
if (m_fileInfo.hasFilename()) cdf->setFilename(m_fileInfo.getFilename()); if (m_fileInfo.hasFilename()) cdf->setFilename(m_fileInfo.getFilename());

View File

@ -62,7 +62,7 @@ void headerField::copyFrom(const component& other)
{ {
const headerField& hf = dynamic_cast <const headerField&>(other); const headerField& hf = dynamic_cast <const headerField&>(other);
getValue().copyFrom(hf.getValue()); m_value->copyFrom(*hf.m_value);
} }
@ -227,7 +227,7 @@ ref <headerField> headerField::parseNext(const string& buffer, const string::siz
void headerField::parse(const string& buffer, const string::size_type position, const string::size_type end, void headerField::parse(const string& buffer, const string::size_type position, const string::size_type end,
string::size_type* newPosition) string::size_type* newPosition)
{ {
getValue().parse(buffer, position, end, newPosition); m_value->parse(buffer, position, end, newPosition);
} }
@ -236,13 +236,19 @@ void headerField::generate(utility::outputStream& os, const string::size_type ma
{ {
os << m_name + ": "; os << m_name + ": ";
getValue().generate(os, maxLineLength, curLinePos + m_name.length() + 2, newLinePos); m_value->generate(os, maxLineLength, curLinePos + m_name.length() + 2, newLinePos);
} }
const string headerField::getName() const const string headerField::getName() const
{ {
return (m_name); return m_name;
}
void headerField::setName(const string& name)
{
m_name = name;
} }
@ -256,12 +262,43 @@ const std::vector <ref <const component> > headerField::getChildComponents() con
{ {
std::vector <ref <const component> > list; std::vector <ref <const component> > list;
list.push_back(getValueImp()); list.push_back(m_value);
return (list); return (list);
} }
ref <const headerFieldValue> headerField::getValue() const
{
return m_value;
}
ref <headerFieldValue> headerField::getValue()
{
return m_value;
}
void headerField::setValue(ref <headerFieldValue> value)
{
if (value != NULL)
m_value = value;
}
void headerField::setValueConst(ref <const headerFieldValue> value)
{
m_value = value->clone().dynamicCast <headerFieldValue>();
}
void headerField::setValue(const headerFieldValue& value)
{
m_value = value.clone().dynamicCast <headerFieldValue>();
}
void headerField::setValue(const string& value) void headerField::setValue(const string& value)
{ {
parse(value); parse(value);

View File

@ -24,11 +24,18 @@
#include "vmime/headerFieldFactory.hpp" #include "vmime/headerFieldFactory.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/standardFields.hpp" #include "vmime/mailboxList.hpp"
#include "vmime/dateTime.hpp"
#include "vmime/text.hpp"
#include "vmime/path.hpp"
#include "vmime/relay.hpp"
#include "vmime/encoding.hpp"
#include "vmime/disposition.hpp"
#include "vmime/messageIdSequence.hpp"
#include "vmime/mailboxField.hpp"
#include "vmime/contentTypeField.hpp" #include "vmime/contentTypeField.hpp"
#include "vmime/contentDispositionField.hpp" #include "vmime/contentDispositionField.hpp"
#include "vmime/mailboxField.hpp"
namespace vmime namespace vmime
@ -37,34 +44,44 @@ namespace vmime
headerFieldFactory::headerFieldFactory() headerFieldFactory::headerFieldFactory()
{ {
// Register some default fields // Register parameterized fields
registerName <mailboxField>(vmime::fields::FROM); registerField <contentTypeField>(vmime::fields::CONTENT_TYPE);
registerName <addressListField>(vmime::fields::TO); registerField <parameterizedHeaderField>(vmime::fields::CONTENT_TRANSFER_ENCODING);
registerName <addressListField>(vmime::fields::CC); registerField <contentDispositionField>(vmime::fields::CONTENT_DISPOSITION);
registerName <addressListField>(vmime::fields::BCC);
registerName <mailboxField>(vmime::fields::SENDER);
registerName <dateField>(vmime::fields::DATE);
registerName <relayField>(vmime::fields::RECEIVED);
registerName <textField>(vmime::fields::SUBJECT);
registerName <mailboxField>(vmime::fields::REPLY_TO);
registerName <mailboxField>(vmime::fields::DELIVERED_TO);
registerName <textField>(vmime::fields::ORGANIZATION);
registerName <textField>(vmime::fields::USER_AGENT);
registerName <pathField>(vmime::fields::RETURN_PATH);
registerName <contentTypeField>(vmime::fields::CONTENT_TYPE);
registerName <contentEncodingField>(vmime::fields::CONTENT_TRANSFER_ENCODING);
registerName <textField>(vmime::fields::CONTENT_DESCRIPTION);
registerName <defaultField>(vmime::fields::MIME_VERSION);
registerName <contentDispositionField>(vmime::fields::CONTENT_DISPOSITION);
registerName <messageIdField>(vmime::fields::CONTENT_ID);
registerName <messageIdField>(vmime::fields::MESSAGE_ID);
registerName <defaultField>(vmime::fields::CONTENT_LOCATION);
registerName <messageIdSequenceField>(vmime::fields::IN_REPLY_TO);
registerName <messageIdSequenceField>(vmime::fields::REFERENCES);
registerName <messageIdField>(vmime::fields::ORIGINAL_MESSAGE_ID); registerField <mailboxField>(vmime::fields::FROM);
registerName <dispositionField>(vmime::fields::DISPOSITION); registerField <mailboxField>(vmime::fields::SENDER);
registerName <mailboxListField>(vmime::fields::DISPOSITION_NOTIFICATION_TO); registerField <mailboxField>(vmime::fields::REPLY_TO);
registerField <mailboxField>(vmime::fields::DELIVERED_TO);
// Register standard field values
registerFieldValue <mailbox>(vmime::fields::FROM);
registerFieldValue <addressList>(vmime::fields::TO);
registerFieldValue <addressList>(vmime::fields::CC);
registerFieldValue <addressList>(vmime::fields::BCC);
registerFieldValue <mailbox>(vmime::fields::SENDER);
registerFieldValue <datetime>(vmime::fields::DATE);
registerFieldValue <relay>(vmime::fields::RECEIVED);
registerFieldValue <text>(vmime::fields::SUBJECT);
registerFieldValue <mailbox>(vmime::fields::REPLY_TO);
registerFieldValue <mailbox>(vmime::fields::DELIVERED_TO);
registerFieldValue <text>(vmime::fields::ORGANIZATION);
registerFieldValue <text>(vmime::fields::USER_AGENT);
registerFieldValue <path>(vmime::fields::RETURN_PATH);
registerFieldValue <mediaType>(vmime::fields::CONTENT_TYPE);
registerFieldValue <encoding>(vmime::fields::CONTENT_TRANSFER_ENCODING);
registerFieldValue <text>(vmime::fields::CONTENT_DESCRIPTION);
registerFieldValue <text>(vmime::fields::MIME_VERSION);
registerFieldValue <contentDisposition>(vmime::fields::CONTENT_DISPOSITION);
registerFieldValue <messageId>(vmime::fields::CONTENT_ID);
registerFieldValue <messageId>(vmime::fields::MESSAGE_ID);
registerFieldValue <text>(vmime::fields::CONTENT_LOCATION);
registerFieldValue <messageIdSequence>(vmime::fields::IN_REPLY_TO);
registerFieldValue <messageIdSequence>(vmime::fields::REFERENCES);
registerFieldValue <messageId>(vmime::fields::ORIGINAL_MESSAGE_ID);
registerFieldValue <disposition>(vmime::fields::DISPOSITION);
registerFieldValue <mailboxList>(vmime::fields::DISPOSITION_NOTIFICATION_TO);
} }
@ -87,21 +104,35 @@ ref <headerField> headerFieldFactory::create
ref <headerField> field = NULL; ref <headerField> field = NULL;
if (pos != m_nameMap.end()) if (pos != m_nameMap.end())
{
field = ((*pos).second)(); field = ((*pos).second)();
}
else else
{ field = registerer <headerField, headerField>::creator();
field = registerer <defaultField>::creator();
}
field->m_name = name; field->setName(name);
field->setValue(createValue(name));
if (body != NULL_STRING) if (body != NULL_STRING)
field->parse(body); field->parse(body);
return (field); return field;
}
ref <headerFieldValue> headerFieldFactory::createValue(const string& fieldName)
{
ValueMap::const_iterator pos = m_valueMap.find
(utility::stringUtils::toLower(fieldName));
ref <headerFieldValue> value = NULL;
if (pos != m_valueMap.end())
value = ((*pos).second)();
else
value = registerer <headerFieldValue, text>::creator();
return value;
} }
} // vmime } // vmime

View File

@ -24,6 +24,10 @@
#include "vmime/htmlTextPart.hpp" #include "vmime/htmlTextPart.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/contentTypeField.hpp"
#include "vmime/contentDisposition.hpp"
#include "vmime/text.hpp"
#include "vmime/emptyContentHandler.hpp" #include "vmime/emptyContentHandler.hpp"
#include "vmime/stringContentHandler.hpp" #include "vmime/stringContentHandler.hpp"
@ -66,8 +70,9 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
parent.getBody()->appendPart(part); parent.getBody()->appendPart(part);
// -- Set header fields // -- Set header fields
part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN)); part->getHeader()->ContentType()->setValue
part->getHeader()->ContentType()->setCharset(m_charset); (mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
part->getHeader()->ContentType().dynamicCast <contentTypeField>()->setCharset(m_charset);
part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE)); part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// -- Set contents // -- Set contents
@ -80,7 +85,7 @@ void htmlTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
// -- Set header fields // -- Set header fields
htmlPart->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML)); htmlPart->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_HTML));
htmlPart->getHeader()->ContentType()->setCharset(m_charset); htmlPart->getHeader()->ContentType().dynamicCast <contentTypeField>()->setCharset(m_charset);
htmlPart->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE)); htmlPart->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// -- Set contents // -- Set contents
@ -167,8 +172,8 @@ void htmlTextPart::addEmbeddedObject(const bodyPart& part, const string& id)
try try
{ {
const ref <const contentTypeField> ctf = part.getHeader()->ContentType(); const ref <const headerField> ctf = part.getHeader()->ContentType();
type = ctf->getValue(); type = *ctf->getValue().dynamicCast <const mediaType>();
} }
catch (exceptions::no_such_field) catch (exceptions::no_such_field)
{ {
@ -219,29 +224,34 @@ void htmlTextPart::parse(const bodyPart& message, const bodyPart& parent, const
// found inline part, we check if its CID/Location is contained in the HTML text. // found inline part, we check if its CID/Location is contained in the HTML text.
for (std::vector <ref <const bodyPart> >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p) for (std::vector <ref <const bodyPart> >::const_iterator p = cidParts.begin() ; p != cidParts.end() ; ++p)
{ {
const ref <const messageIdField> midField = const ref <const headerField> midField =
(*p)->getHeader()->findField(fields::CONTENT_ID).dynamicCast <messageIdField>(); (*p)->getHeader()->findField(fields::CONTENT_ID);
const string searchFor("CID:" + midField->getValue().getId()); const messageId mid = *midField->getValue().dynamicCast <const messageId>();
const string searchFor("CID:" + mid.getId());
if (data.find(searchFor) != string::npos) if (data.find(searchFor) != string::npos)
{ {
// This part is referenced in the HTML text. // This part is referenced in the HTML text.
// Add it to the embedded object list. // Add it to the embedded object list.
addEmbeddedObject(**p, "CID:" + midField->getValue().getId()); addEmbeddedObject(**p, "CID:" + mid.getId());
} }
} }
for (std::vector <ref <const bodyPart> >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p) for (std::vector <ref <const bodyPart> >::const_iterator p = locParts.begin() ; p != locParts.end() ; ++p)
{ {
const ref <const defaultField> locField = const ref <const headerField> locField =
(*p)->getHeader()->findField(fields::CONTENT_LOCATION).dynamicCast <defaultField>(); (*p)->getHeader()->findField(fields::CONTENT_LOCATION);
if (data.find(locField->getValue()) != string::npos) const text loc = *locField->getValue().dynamicCast <const text>();
const string locStr = loc.getWholeBuffer();
if (data.find(locStr) != string::npos)
{ {
// This part is referenced in the HTML text. // This part is referenced in the HTML text.
// Add it to the embedded object list. // Add it to the embedded object list.
addEmbeddedObject(**p, locField->getValue()); addEmbeddedObject(**p, locStr);
} }
} }
@ -258,11 +268,13 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren
// We search for the nearest "multipart/alternative" part. // We search for the nearest "multipart/alternative" part.
try try
{ {
const ref <const contentTypeField> ctf = const ref <const headerField> ctf =
part.getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>(); part.getHeader()->findField(fields::CONTENT_TYPE);
if (ctf->getValue().getType() == mediaTypes::MULTIPART && const mediaType type = *ctf->getValue().dynamicCast <const mediaType>();
ctf->getValue().getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
if (type.getType() == mediaTypes::MULTIPART &&
type.getSubType() == mediaTypes::MULTIPART_ALTERNATIVE)
{ {
ref <const bodyPart> foundPart = NULL; ref <const bodyPart> foundPart = NULL;
@ -288,11 +300,13 @@ bool htmlTextPart::findPlainTextPart(const bodyPart& part, const bodyPart& paren
try try
{ {
const ref <const contentTypeField> ctf = const ref <const headerField> ctf =
p->getHeader()->findField(fields::CONTENT_TYPE).dynamicCast <contentTypeField>(); p->getHeader()->findField(fields::CONTENT_TYPE);
if (ctf->getValue().getType() == mediaTypes::TEXT && const mediaType type = *ctf->getValue().dynamicCast <const mediaType>();
ctf->getValue().getSubType() == mediaTypes::TEXT_PLAIN)
if (type.getType() == mediaTypes::TEXT &&
type.getSubType() == mediaTypes::TEXT_PLAIN)
{ {
m_plainText = p->getBody()->getContents()->clone(); m_plainText = p->getBody()->getContents()->clone();
found = true; found = true;

View File

@ -25,6 +25,9 @@
#include "vmime/mailboxGroup.hpp" #include "vmime/mailboxGroup.hpp"
#ifndef VMIME_BUILDING_DOC
namespace vmime namespace vmime
{ {
@ -35,7 +38,7 @@ mailboxField::mailboxField()
mailboxField::mailboxField(const mailboxField&) mailboxField::mailboxField(const mailboxField&)
: headerField(), genericField <mailbox>() : headerField()
{ {
} }
@ -43,7 +46,7 @@ mailboxField::mailboxField(const mailboxField&)
void mailboxField::parse(const string& buffer, const string::size_type position, void mailboxField::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition) const string::size_type end, string::size_type* newPosition)
{ {
getValue().clear(); ref <mailbox> mbox = vmime::create <mailbox>();
// Here, we cannot simply call "m_mailbox.parse()" because it // Here, we cannot simply call "m_mailbox.parse()" because it
// may have more than one address specified (even if this field // may have more than one address specified (even if this field
@ -59,16 +62,18 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
ref <mailboxGroup> group = parsedAddress.staticCast <mailboxGroup>(); ref <mailboxGroup> group = parsedAddress.staticCast <mailboxGroup>();
if (!group->isEmpty()) if (!group->isEmpty())
getValue() = *(group->getMailboxAt(0)); mbox = group->getMailboxAt(0);
} }
else else
{ {
// Parse only if it is a mailbox // Parse only if it is a mailbox
getValue() = *parsedAddress.staticCast <mailbox>(); mbox = parsedAddress.staticCast <mailbox>();
} }
} }
getValue().setParsedBounds(position, end); mbox->setParsedBounds(position, end);
setValue(mbox);
setParsedBounds(position, end); setParsedBounds(position, end);
@ -78,3 +83,7 @@ void mailboxField::parse(const string& buffer, const string::size_type position,
} // vmime } // vmime
#endif // VMIME_BUILDING_DOC

View File

@ -35,7 +35,7 @@ mailboxList::mailboxList()
mailboxList::mailboxList(const mailboxList& mboxList) mailboxList::mailboxList(const mailboxList& mboxList)
: component(), m_list(mboxList.m_list) : headerFieldValue(), m_list(mboxList.m_list)
{ {
} }

View File

@ -22,6 +22,11 @@
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/stringContentHandler.hpp" #include "vmime/stringContentHandler.hpp"
#include "vmime/contentTypeField.hpp"
#include "vmime/path.hpp"
#include "vmime/dateTime.hpp"
namespace vmime { namespace vmime {
namespace mdn { namespace mdn {
@ -52,7 +57,8 @@ const std::vector <sendableMDNInfos> MDNHelper::getPossibleMDNs(const ref <const
if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO)) if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
{ {
const mailboxList& dnto = hdr->DispositionNotificationTo()->getValue(); const mailboxList& dnto = *hdr->DispositionNotificationTo()->getValue()
.dynamicCast <const mailboxList>();
for (int i = 0 ; i < dnto.getMailboxCount() ; ++i) for (int i = 0 ; i < dnto.getMailboxCount() ; ++i)
result.push_back(sendableMDNInfos(msg, *dnto.getMailboxAt(i))); result.push_back(sendableMDNInfos(msg, *dnto.getMailboxAt(i)));
@ -72,10 +78,13 @@ const bool MDNHelper::isMDN(const ref <const message> msg)
// and its value is "disposition-notification" // and its value is "disposition-notification"
if (hdr->hasField(fields::CONTENT_TYPE)) if (hdr->hasField(fields::CONTENT_TYPE))
{ {
const contentTypeField& ctf = *(hdr->ContentType()); const contentTypeField& ctf = *(hdr->ContentType()
.dynamicCast <const contentTypeField>());
if (ctf.getValue().getType() == vmime::mediaTypes::MULTIPART && const mediaType type = *ctf.getValue().dynamicCast <const mediaType>();
ctf.getValue().getSubType() == vmime::mediaTypes::MULTIPART_REPORT)
if (type.getType() == vmime::mediaTypes::MULTIPART &&
type.getSubType() == vmime::mediaTypes::MULTIPART_REPORT)
{ {
if (ctf.hasParameter("report-type") && if (ctf.hasParameter("report-type") &&
ctf.getReportType() == "disposition-notification") ctf.getReportType() == "disposition-notification")
@ -104,26 +113,29 @@ const bool MDNHelper::needConfirmation(const ref <const message> msg)
// No "Return-Path" field // No "Return-Path" field
if (!hdr->hasField(fields::RETURN_PATH)) if (!hdr->hasField(fields::RETURN_PATH))
return (true); return true;
// More than one address in Disposition-Notification-To // More than one address in Disposition-Notification-To
if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO)) if (hdr->hasField(fields::DISPOSITION_NOTIFICATION_TO))
{ {
const mailboxList& dnto = hdr->DispositionNotificationTo()->getValue(); const mailboxList& dnto = *hdr->DispositionNotificationTo()->getValue()
.dynamicCast <const mailboxList>();
if (dnto.getMailboxCount() > 1) if (dnto.getMailboxCount() > 1)
return (true); return true;
else if (dnto.getMailboxCount() == 0)
return false;
// Return-Path != Disposition-Notification-To // Return-Path != Disposition-Notification-To
const mailbox& mbox = *dnto.getMailboxAt(0); const mailbox& mbox = *dnto.getMailboxAt(0);
const path& rp = hdr->ReturnPath()->getValue(); const path& rp = *hdr->ReturnPath()->getValue().dynamicCast <const path>();
if (mbox.getEmail() != rp.getLocalPart() + "@" + rp.getDomain()) if (mbox.getEmail() != rp.getLocalPart() + "@" + rp.getDomain())
return (true); return true;
} }
// User confirmation not needed // User confirmation not needed
return (false); return false;
} }
@ -143,13 +155,17 @@ ref <message> MDNHelper::buildMDN(const sendableMDNInfos& mdnInfos,
hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MULTIPART, hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::MULTIPART,
vmime::mediaTypes::MULTIPART_REPORT)); vmime::mediaTypes::MULTIPART_REPORT));
hdr->ContentType()->setReportType("disosition-notification"); hdr->ContentType().dynamicCast <contentTypeField>()->setReportType("disposition-notification");
hdr->Disposition()->setValue(dispo); hdr->Disposition()->setValue(dispo);
hdr->To()->getValue().appendAddress(vmime::create <mailbox>(mdnInfos.getRecipient())); addressList to;
hdr->From()->getValue() = expeditor; to.appendAddress(vmime::create <mailbox>(mdnInfos.getRecipient()));
hdr->Subject()->getValue().appendWord(vmime::create <word>("Disposition notification")); hdr->To()->setValue(to);
hdr->From()->setValue(expeditor);
hdr->Subject()->setValue(vmime::text(word("Disposition notification")));
hdr->Date()->setValue(datetime::now()); hdr->Date()->setValue(datetime::now());
hdr->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION)); hdr->MimeVersion()->setValue(string(SUPPORTED_MIME_VERSION));
@ -174,7 +190,7 @@ ref <bodyPart> MDNHelper::createFirstMDNPart(const sendableMDNInfos& /* mdnInfos
hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT, hdr->ContentType()->setValue(mediaType(vmime::mediaTypes::TEXT,
vmime::mediaTypes::TEXT_PLAIN)); vmime::mediaTypes::TEXT_PLAIN));
hdr->ContentType()->setCharset(ch); hdr->ContentType().dynamicCast <contentTypeField>()->setCharset(ch);
// Body // Body
part->getBody()->setContents(vmime::create <stringContentHandler>(text)); part->getBody()->setContents(vmime::create <stringContentHandler>(text));
@ -233,9 +249,8 @@ ref <bodyPart> MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
ruaText += reportingUAProducts[i]; ruaText += reportingUAProducts[i];
} }
ref <defaultField> rua = ref <headerField> rua = headerFieldFactory::getInstance()->
(headerFieldFactory::getInstance()->create create(vmime::fields::REPORTING_UA);
(vmime::fields::REPORTING_UA)).dynamicCast <defaultField>();
rua->setValue(ruaText); rua->setValue(ruaText);
@ -243,16 +258,15 @@ ref <bodyPart> MDNHelper::createSecondMDNPart(const sendableMDNInfos& mdnInfos,
} }
// -- Final-Recipient // -- Final-Recipient
ref <defaultField> fr = ref <headerField> fr = headerFieldFactory::getInstance()->
(headerFieldFactory::getInstance()-> create(vmime::fields::FINAL_RECIPIENT);
create(vmime::fields::FINAL_RECIPIENT)).dynamicCast <defaultField>();
fr->setValue("rfc822; " + mdnInfos.getRecipient().getEmail()); fr->setValue("rfc822; " + mdnInfos.getRecipient().getEmail());
// -- Original-Message-ID // -- Original-Message-ID
if (mdnInfos.getMessage()->getHeader()->hasField(vmime::fields::MESSAGE_ID)) if (mdnInfos.getMessage()->getHeader()->hasField(vmime::fields::MESSAGE_ID))
{ {
fields.OriginalMessageId()->setValue fields.OriginalMessageId()->setValueConst
(mdnInfos.getMessage()->getHeader()->MessageId()->getValue()); (mdnInfos.getMessage()->getHeader()->MessageId()->getValue());
} }

View File

@ -82,7 +82,8 @@ void receivedMDNInfos::extract()
if (!part->getHeader()->hasField(fields::CONTENT_TYPE)) if (!part->getHeader()->hasField(fields::CONTENT_TYPE))
continue; continue;
const mediaType& type = part->getHeader()->ContentType()->getValue(); const mediaType& type = *part->getHeader()->ContentType()->
getValue().dynamicCast <const mediaType>();
// Extract from second part (message/disposition-notification) // Extract from second part (message/disposition-notification)
if (type.getType() == vmime::mediaTypes::MESSAGE && if (type.getType() == vmime::mediaTypes::MESSAGE &&
@ -97,10 +98,10 @@ void receivedMDNInfos::extract()
header fields; header fields;
fields.parse(oss.str()); fields.parse(oss.str());
try { m_omid = fields.OriginalMessageId()->getValue(); } try { m_omid = *fields.OriginalMessageId()->getValue().dynamicCast <const messageId>(); }
catch (exceptions::no_such_field&) { /* Ignore */ } catch (exceptions::no_such_field&) { /* Ignore */ }
try { m_disp = fields.Disposition()->getValue(); } try { m_disp = *fields.Disposition()->getValue().dynamicCast <const disposition>(); }
catch (exceptions::no_such_field&) { /* Ignore */ } catch (exceptions::no_such_field&) { /* Ignore */ }
} }
} }

View File

@ -23,6 +23,7 @@
#include "vmime/messageBuilder.hpp" #include "vmime/messageBuilder.hpp"
#include "vmime/dateTime.hpp"
#include "vmime/textPartFactory.hpp" #include "vmime/textPartFactory.hpp"

View File

@ -43,7 +43,7 @@ messageId::messageId(const string& id)
messageId::messageId(const messageId& mid) messageId::messageId(const messageId& mid)
: component(), m_left(mid.m_left), m_right(mid.m_right) : headerFieldValue(), m_left(mid.m_left), m_right(mid.m_right)
{ {
} }

View File

@ -44,7 +44,7 @@ messageIdSequence::~messageIdSequence()
messageIdSequence::messageIdSequence(const messageIdSequence& midSeq) messageIdSequence::messageIdSequence(const messageIdSequence& midSeq)
: component() : headerFieldValue()
{ {
copyFrom(midSeq); copyFrom(midSeq);
} }

View File

@ -28,6 +28,9 @@
#include "vmime/defaultAttachment.hpp" #include "vmime/defaultAttachment.hpp"
#include "vmime/textPartFactory.hpp" #include "vmime/textPartFactory.hpp"
#include "vmime/relay.hpp"
#include "vmime/contentTypeField.hpp"
namespace vmime namespace vmime
{ {
@ -59,16 +62,16 @@ void messageParser::parse(ref <const message> msg)
#ifndef VMIME_BUILDING_DOC #ifndef VMIME_BUILDING_DOC
#define TRY_FIELD(var, type, name) \ #define TRY_FIELD(var, type, name) \
try { var = dynamic_cast<type&>(*msg->getHeader()->findField(name)).getValue(); } \ try { var = *msg->getHeader()->findField(name)->getValue().dynamicCast <type>(); } \
catch (exceptions::no_such_field) { } catch (exceptions::no_such_field) { }
TRY_FIELD(m_from, mailboxField, fields::FROM); TRY_FIELD(m_from, mailbox, fields::FROM);
TRY_FIELD(m_to, addressListField, fields::TO); TRY_FIELD(m_to, addressList, fields::TO);
TRY_FIELD(m_cc, addressListField, fields::CC); TRY_FIELD(m_cc, addressList, fields::CC);
TRY_FIELD(m_bcc, addressListField, fields::BCC); TRY_FIELD(m_bcc, addressList, fields::BCC);
TRY_FIELD(m_subject, textField, fields::SUBJECT); TRY_FIELD(m_subject, text, fields::SUBJECT);
#undef TRY_FIELD #undef TRY_FIELD
@ -77,19 +80,15 @@ void messageParser::parse(ref <const message> msg)
// Date // Date
try try
{ {
vmime::relayField& recv = dynamic_cast <vmime::relayField&> const headerField& recv = *msg->getHeader()->findField(fields::RECEIVED);
(*msg->getHeader()->findField(fields::RECEIVED)); m_date = recv.getValue().dynamicCast <const relay>()->getDate();
m_date = recv.getValue().getDate();
} }
catch (vmime::exceptions::no_such_field&) catch (vmime::exceptions::no_such_field&)
{ {
try try
{ {
vmime::dateField& date = dynamic_cast <vmime::dateField&> const headerField& date = *msg->getHeader()->findField(fields::DATE);
(*msg->getHeader()->findField(fields::DATE)); m_date = *date.getValue().dynamicCast <const datetime>();
m_date = date.getValue();
} }
catch (vmime::exceptions::no_such_field&) catch (vmime::exceptions::no_such_field&)
{ {
@ -125,13 +124,16 @@ void messageParser::findTextParts(const bodyPart& msg, const bodyPart& part)
const contentTypeField& ctf = dynamic_cast<contentTypeField&> const contentTypeField& ctf = dynamic_cast<contentTypeField&>
(*msg.getHeader()->findField(fields::CONTENT_TYPE)); (*msg.getHeader()->findField(fields::CONTENT_TYPE));
if (ctf.getValue().getType() == mediaTypes::TEXT) const mediaType ctfType =
*ctf.getValue().dynamicCast <const mediaType>();
if (ctfType.getType() == mediaTypes::TEXT)
{ {
type = ctf.getValue(); type = ctfType;
accept = true; accept = true;
} }
} }
catch (exceptions::no_such_field) catch (exceptions::no_such_field&)
{ {
// No "Content-type" field: assume "text/plain". // No "Content-type" field: assume "text/plain".
accept = true; accept = true;
@ -171,12 +173,14 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
const contentTypeField& ctf = dynamic_cast <const contentTypeField&> const contentTypeField& ctf = dynamic_cast <const contentTypeField&>
(*(p->getHeader()->findField(fields::CONTENT_TYPE))); (*(p->getHeader()->findField(fields::CONTENT_TYPE)));
if (ctf.getValue().getType() == mediaTypes::TEXT) const mediaType type = *ctf.getValue().dynamicCast <const mediaType>();
if (type.getType() == mediaTypes::TEXT)
{ {
textParts.push_back(p); textParts.push_back(p);
} }
} }
catch (exceptions::no_such_field) catch (exceptions::no_such_field&)
{ {
// No "Content-type" field. // No "Content-type" field.
} }
@ -191,9 +195,11 @@ bool messageParser::findSubTextParts(const bodyPart& msg, const bodyPart& part)
const contentTypeField& ctf = dynamic_cast <const contentTypeField&> const contentTypeField& ctf = dynamic_cast <const contentTypeField&>
(*((*p)->getHeader()->findField(fields::CONTENT_TYPE))); (*((*p)->getHeader()->findField(fields::CONTENT_TYPE)));
const mediaType type = *ctf.getValue().dynamicCast <const mediaType>();
try try
{ {
ref <textPart> txtPart = textPartFactory::getInstance()->create(ctf.getValue()); ref <textPart> txtPart = textPartFactory::getInstance()->create(type);
txtPart->parse(msg, part, **p); txtPart->parse(msg, part, **p);
m_textParts.push_back(txtPart); m_textParts.push_back(txtPart);

View File

@ -20,6 +20,8 @@
#include "vmime/misc/importanceHelper.hpp" #include "vmime/misc/importanceHelper.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/text.hpp"
namespace vmime { namespace vmime {
namespace misc { namespace misc {
@ -66,8 +68,8 @@ const importanceHelper::Importance importanceHelper::getImportanceHeader(ref <co
// Try "X-Priority" field // Try "X-Priority" field
try try
{ {
const ref <const defaultField> fld = hdr->findField("X-Priority").dynamicCast <const defaultField>(); const ref <const headerField> fld = hdr->findField("X-Priority");
const string value = fld->getValue(); const string value = fld->getValue().dynamicCast <const text>()->getWholeBuffer();
int n = IMPORTANCE_NORMAL; int n = IMPORTANCE_NORMAL;
@ -92,8 +94,9 @@ const importanceHelper::Importance importanceHelper::getImportanceHeader(ref <co
// Try "Importance" field // Try "Importance" field
try try
{ {
const ref <const defaultField> fld = hdr->findField("Importance").dynamicCast <const defaultField>(); const ref <const headerField> fld = hdr->findField("Importance");
const string value = utility::stringUtils::toLower(utility::stringUtils::trim(fld->getValue())); const string value = utility::stringUtils::toLower(utility::stringUtils::trim
(fld->getValue().dynamicCast <const text>()->getWholeBuffer()));
if (value == "low") if (value == "low")
return (IMPORTANCE_LOWEST); return (IMPORTANCE_LOWEST);
@ -123,7 +126,7 @@ void importanceHelper::setImportance(ref <message> msg, const Importance i)
void importanceHelper::setImportanceHeader(ref <header> hdr, const Importance i) void importanceHelper::setImportanceHeader(ref <header> hdr, const Importance i)
{ {
// "X-Priority:" Field // "X-Priority:" Field
ref <defaultField> fld = hdr->getField("X-Priority").dynamicCast <defaultField>(); ref <headerField> fld = hdr->getField("X-Priority");
switch (i) switch (i)
{ {
@ -136,7 +139,7 @@ void importanceHelper::setImportanceHeader(ref <header> hdr, const Importance i)
} }
// "Importance:" Field // "Importance:" Field
fld = hdr->getField("Importance").dynamicCast <defaultField>(); fld = hdr->getField("Importance");
switch (i) switch (i)
{ {

View File

@ -54,9 +54,10 @@ void transport::send(ref <vmime::message> msg, utility::progressListener* progre
try try
{ {
const mailboxField& from = dynamic_cast <const mailboxField&> const mailbox& mbox = *msg->getHeader()->findField(fields::FROM)->
(*msg->getHeader()->findField(fields::FROM)); getValue().dynamicCast <const mailbox>();
expeditor = from.getValue();
expeditor = mbox;
} }
catch (exceptions::no_such_field&) catch (exceptions::no_such_field&)
{ {
@ -68,25 +69,28 @@ void transport::send(ref <vmime::message> msg, utility::progressListener* progre
try try
{ {
const addressListField& to = dynamic_cast <const addressListField&> const addressList& to = *msg->getHeader()->findField(fields::TO)->
(*msg->getHeader()->findField(fields::TO)); getValue().dynamicCast <const addressList>();
extractMailboxes(recipients, to.getValue());
extractMailboxes(recipients, to);
} }
catch (exceptions::no_such_field&) { } catch (exceptions::no_such_field&) { }
try try
{ {
const addressListField& cc = dynamic_cast <const addressListField&> const addressList& cc = *msg->getHeader()->findField(fields::CC)->
(*msg->getHeader()->findField(fields::CC)); getValue().dynamicCast <const addressList>();
extractMailboxes(recipients, cc.getValue());
extractMailboxes(recipients, cc);
} }
catch (exceptions::no_such_field&) { } catch (exceptions::no_such_field&) { }
try try
{ {
const addressListField& bcc = dynamic_cast <const addressListField&> const addressList& bcc = *msg->getHeader()->findField(fields::BCC)->
(*msg->getHeader()->findField(fields::BCC)); getValue().dynamicCast <const addressList>();
extractMailboxes(recipients, bcc.getValue());
extractMailboxes(recipients, bcc);
} }
catch (exceptions::no_such_field&) { } catch (exceptions::no_such_field&) { }

View File

@ -22,16 +22,42 @@
// //
#include "vmime/parameter.hpp" #include "vmime/parameter.hpp"
#include "vmime/parameterFactory.hpp" #include "vmime/parserHelpers.hpp"
#include "vmime/text.hpp"
namespace vmime namespace vmime
{ {
parameter::parameter(const string& name)
: m_name(name)
{
}
parameter::parameter(const string& name, const word& value)
: m_name(name), m_value(value)
{
}
parameter::parameter(const string& name, const string& value)
: m_name(name), m_value(value)
{
}
parameter::parameter(const parameter&)
: component()
{
}
ref <component> parameter::clone() const ref <component> parameter::clone() const
{ {
ref <parameter> p = parameterFactory::getInstance()->create(m_name); ref <parameter> p = vmime::create <parameter>(m_name);
p->copyFrom(*this); p->copyFrom(*this);
return (p); return (p);
@ -43,8 +69,7 @@ void parameter::copyFrom(const component& other)
const parameter& param = dynamic_cast <const parameter&>(other); const parameter& param = dynamic_cast <const parameter&>(other);
m_name = param.m_name; m_name = param.m_name;
m_value.copyFrom(param.m_value);
getValue().copyFrom(param.getValue());
} }
@ -57,16 +82,38 @@ parameter& parameter::operator=(const parameter& other)
const string& parameter::getName() const const string& parameter::getName() const
{ {
return (m_name); return m_name;
}
const word& parameter::getValue() const
{
return m_value;
}
void parameter::setValue(const component& value)
{
std::ostringstream oss;
utility::outputStreamAdapter vos(oss);
value.generate(vos);
setValue(word(oss.str(), vmime::charsets::US_ASCII));
}
void parameter::setValue(const word& value)
{
m_value = value;
} }
void parameter::parse(const string& buffer, const string::size_type position, void parameter::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition) const string::size_type end, string::size_type* newPosition)
{ {
getValue().parse(buffer, position, end, newPosition); m_value.setBuffer(string(buffer.begin() + position, buffer.begin() + end));
m_value.setCharset(charset(charsets::US_ASCII));
setParsedBounds(position, end);
if (newPosition) if (newPosition)
*newPosition = end; *newPosition = end;
@ -75,69 +122,157 @@ void parameter::parse(const string& buffer, const string::size_type position,
void parameter::parse(const std::vector <valueChunk>& chunks) void parameter::parse(const std::vector <valueChunk>& chunks)
{ {
string value; bool foundCharsetChunk = false;
for (std::vector <valueChunk>::const_iterator it = chunks.begin() ; charset ch(charsets::US_ASCII);
it != chunks.end() ; ++it) std::ostringstream value;
for (std::vector <valueChunk>::size_type i = 0 ; i < chunks.size() ; ++i)
{ {
value += (*it).data; const valueChunk& chunk = chunks[i];
// Decode following data
if (chunk.encoded)
{
const string::size_type len = chunk.data.length();
string::size_type pos = 0;
// If this is the first encoded chunk, extract charset
// and language information
if (!foundCharsetChunk)
{
// Eg. "us-ascii'en'This%20is%20even%20more%20"
string::size_type q = chunk.data.find_first_of('\'');
if (q != string::npos)
{
const string chs = chunk.data.substr(0, q);
if (!chs.empty())
ch = charset(chs);
++q;
pos = q;
}
q = chunk.data.find_first_of('\'', pos);
if (q != string::npos)
{
// Ignore language
++q;
pos = q;
}
foundCharsetChunk = true;
}
for (string::size_type i = pos ; i < len ; ++i)
{
const string::value_type c = chunk.data[i];
if (c == '%' && i + 2 < len)
{
string::value_type v = 0;
// First char
switch (chunk.data[i + 1])
{
case 'a': case 'A': v += 10; break;
case 'b': case 'B': v += 11; break;
case 'c': case 'C': v += 12; break;
case 'd': case 'D': v += 13; break;
case 'e': case 'E': v += 14; break;
case 'f': case 'F': v += 15; break;
default: // assume 0-9
v += (chunk.data[i + 1] - '0');
break;
}
v *= 16;
// Second char
switch (chunk.data[i + 2])
{
case 'a': case 'A': v += 10; break;
case 'b': case 'B': v += 11; break;
case 'c': case 'C': v += 12; break;
case 'd': case 'D': v += 13; break;
case 'e': case 'E': v += 14; break;
case 'f': case 'F': v += 15; break;
default: // assume 0-9
v += (chunk.data[i + 2] - '0');
break;
}
value << v;
i += 2; // skip next 2 chars
}
else
{
value << c;
}
}
}
// Simply copy data, as it is not encoded
else
{
// This syntax is non-standard (expressly prohibited
// by RFC-2047), but is used by Mozilla:
//
// Content-Type: image/png;
// name="=?us-ascii?Q?Logo_VMime=2Epng?="
// Using 'vmime::text' to parse the data is safe even
// if the data is not encoded, because it can recover
// from parsing errors.
vmime::text t;
t.parse(chunk.data);
if (t.getWordCount() != 0)
{
value << t.getWholeBuffer();
if (!foundCharsetChunk)
ch = t.getWordAt(0)->getCharset();
}
}
} }
getValue().parse(value, 0, value.length(), NULL); m_value.setBuffer(value.str());
m_value.setCharset(ch);
} }
void parameter::generate(utility::outputStream& os, const string::size_type maxLineLength, void parameter::generate(utility::outputStream& os, const string::size_type maxLineLength,
const string::size_type curLinePos, string::size_type* newLinePos) const const string::size_type curLinePos, string::size_type* newLinePos) const
{ {
const string& name = m_name;
const string& value = m_value.getBuffer();
// For compatibility with implementations that do not understand RFC-2231,
// also generate a normal "7bit/us-ascii" parameter
string::size_type pos = curLinePos; string::size_type pos = curLinePos;
if (pos + m_name.length() + 10 > maxLineLength) if (pos + name.length() + 10 + value.length() > maxLineLength)
{ {
os << NEW_LINE_SEQUENCE; os << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH; pos = NEW_LINE_SEQUENCE_LENGTH;
} }
os << m_name << "="; bool needQuoting = false;
pos += m_name.length() + 1; string::size_type valueLength = 0;
generateValue(os, maxLineLength, pos, newLinePos); for (string::size_type i = 0 ; (i < value.length()) && (pos + valueLength < maxLineLength - 4) ; ++i, ++valueLength)
}
void parameter::generateValue(utility::outputStream& os, const string::size_type /* maxLineLength */,
const string::size_type curLinePos, string::size_type* newLinePos) const
{
// NOTE: This default implementation does not support parameter
// values that span on several lines ('defaultParameter' can do
// that, following rules specified in RFC-2231).
std::ostringstream valueStream;
utility::outputStreamAdapter valueStreamV(valueStream);
getValue().generate(valueStreamV, lineLengthLimits::infinite, 0, NULL);
const string value(valueStream.str());
std::ostringstream ss;
string::const_iterator start = value.begin();
bool quoted = false;
for (string::const_iterator i = value.begin() ; i != value.end() ; ++i)
{ {
switch (*i) switch (value[i])
{ {
// Characters that need to be quoted _and_ escaped // Characters that need to be quoted _and_ escaped
case '"': case '"':
case '\\': case '\\':
ss << string(start, i) << "\\" << *i;
start = i + 1;
quoted = true;
break;
// Other characters that need quoting // Other characters that need quoting
case ' ': case ' ':
case '\t': case '\t':
@ -155,21 +290,194 @@ void parameter::generateValue(utility::outputStream& os, const string::size_type
case '?': case '?':
case '=': case '=':
quoted = true; needQuoting = true;
break; break;
} }
} }
if (start != value.end()) const bool cutValue = (valueLength != value.length()); // has the value been cut?
ss << string(start, value.end());
if (quoted) if (needQuoting)
os << "\"" << ss.str() << "\""; {
os << name << "=\"";
pos += name.length() + 2;
}
else else
os << ss.str(); {
os << name << "=";
pos += name.length() + 1;
}
bool extended = false;
for (string::size_type i = 0 ; (i < value.length()) && (pos < maxLineLength - 4) ; ++i)
{
const char_t c = value[i];
if (/* needQuoting && */ (c == '"' || c == '\\')) // 'needQuoting' is implicit
{
os << '\\' << value[i]; // escape 'x' with '\x'
pos += 2;
}
else if (parserHelpers::isAscii(c))
{
os << value[i];
++pos;
}
else
{
extended = true;
}
}
if (needQuoting)
{
os << '"';
++pos;
}
// Also generate an extended parameter if the value contains 8-bit characters
// or is too long for a single line
if (extended || cutValue)
{
os << ';';
++pos;
/* RFC-2231
* ========
*
* Content-Type: message/external-body; access-type=URL;
* URL*0="ftp://";
* URL*1="cs.utk.edu/pub/moore/bulk-mailer/bulk-mailer.tar"
*
* Content-Type: application/x-stuff;
* title*=us-ascii'en-us'This%20is%20%2A%2A%2Afun%2A%2A%2A
*
* Content-Type: application/x-stuff;
* title*0*=us-ascii'en'This%20is%20even%20more%20
* title*1*=%2A%2A%2Afun%2A%2A%2A%20
* title*2="isn't it!"
*/
// Check whether there is enough space for the first section:
// parameter name, section identifier, charset and separators
// + at least 5 characters for the value
const string::size_type firstSectionLength =
name.length() + 4 /* *0*= */ + 2 /* '' */
+ m_value.getCharset().getName().length();
if (pos + firstSectionLength + 5 >= maxLineLength)
{
os << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
// Split text into multiple sections that fit on one line
int sectionCount = 0;
std::vector <string> sectionText;
string currentSection;
string::size_type currentSectionLength = firstSectionLength;
for (string::size_type i = 0 ; i < value.length() ; ++i)
{
// Check whether we should start a new line (taking into
// account the next character will be encoded = worst case)
if (currentSectionLength + 3 >= maxLineLength)
{
sectionText.push_back(currentSection);
sectionCount++;
currentSection.clear();
currentSectionLength = NEW_LINE_SEQUENCE_LENGTH
+ name.length() + 6;
}
// Output next character
const char_t c = value[i];
bool encode = false;
switch (c)
{
// special characters
case ' ':
case '\t':
case '\r':
case '\n':
case '"':
case ';':
case ',':
encode = true;
break;
default:
encode = (!parserHelpers::isPrint(c) ||
!parserHelpers::isAscii(c));
break;
}
if (encode) // need encoding
{
const int h1 = static_cast <unsigned char>(c) / 16;
const int h2 = static_cast <unsigned char>(c) % 16;
currentSection += '%';
currentSection += "0123456789ABCDEF"[h1];
currentSection += "0123456789ABCDEF"[h2];
pos += 3;
currentSectionLength += 3;
}
else
{
currentSection += value[i];
++pos;
++currentSectionLength;
}
}
if (!currentSection.empty())
{
sectionText.push_back(currentSection);
sectionCount++;
}
// Output sections
for (int sectionNumber = 0 ; sectionNumber < sectionCount ; ++sectionNumber)
{
os << name;
if (sectionCount != 1) // no section specifier when only a single one
{
os << '*';
os << sectionNumber;
}
os << "*=";
if (sectionNumber == 0)
{
os << m_value.getCharset().getName();
os << '\'' << /* No language */ '\'';
}
os << sectionText[sectionNumber];
if (sectionNumber + 1 < sectionCount)
{
os << ';';
os << NEW_LINE_SEQUENCE;
pos = NEW_LINE_SEQUENCE_LENGTH;
}
}
}
if (newLinePos) if (newLinePos)
*newLinePos = curLinePos + ss.str().length() + 2; *newLinePos = pos;
} }
@ -177,10 +485,11 @@ const std::vector <ref <const component> > parameter::getChildComponents() const
{ {
std::vector <ref <const component> > list; std::vector <ref <const component> > list;
list.push_back(getValueImp()); list.push_back(ref <const component>::fromPtr(&m_value));
return (list); return list;
} }
} // vmime } // vmime

View File

@ -1,103 +0,0 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// 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.
//
// 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.
//
#include "vmime/parameterFactory.hpp"
#include "vmime/exception.hpp"
#include "vmime/standardParams.hpp"
namespace vmime
{
parameterFactory::parameterFactory()
{
// Register some default names
registerName <charsetParameter>("charset");
registerName <dateParameter>("creation-date");
registerName <dateParameter>("modification-date");
registerName <dateParameter>("read-date");
}
parameterFactory::~parameterFactory()
{
}
parameterFactory* parameterFactory::getInstance()
{
static parameterFactory instance;
return (&instance);
}
ref <parameter> parameterFactory::create
(const string& name, const string& value)
{
const string lcName = utility::stringUtils::toLower(name);
NameMap::const_iterator pos = m_nameMap.find(lcName);
ref <parameter> param;
if (pos != m_nameMap.end())
{
param = ((*pos).second)();
}
else
{
param = registerer <defaultParameter>::creator();
}
param->m_name = name;
if (value != NULL_STRING) param->parse(value);
return (param);
}
ref <parameter> parameterFactory::create(const string& name, const component& value)
{
const string lcName = utility::stringUtils::toLower(name);
NameMap::const_iterator pos = m_nameMap.find(lcName);
ref <parameter> param;
if (pos != m_nameMap.end())
{
param = ((*pos).second)();
}
else
{
param = registerer <defaultParameter>::creator();
}
param->m_name = name;
param->setValue(value);
return (param);
}
} // vmime

View File

@ -22,7 +22,6 @@
// //
#include "vmime/parameterizedHeaderField.hpp" #include "vmime/parameterizedHeaderField.hpp"
#include "vmime/parameterFactory.hpp"
#include "vmime/text.hpp" #include "vmime/text.hpp"
#include "vmime/parserHelpers.hpp" #include "vmime/parserHelpers.hpp"
@ -90,7 +89,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty
while (p < pend && *p != ';') ++p; while (p < pend && *p != ';') ++p;
getValue().parse(buffer, start, position + (p - pstart)); getValue()->parse(buffer, start, position + (p - pstart));
removeAllParameters(); removeAllParameters();
@ -295,7 +294,7 @@ void parameterizedHeaderField::parse(const string& buffer, const string::size_ty
const paramInfo& info = (*it).second; const paramInfo& info = (*it).second;
// Append this parameter to the list // Append this parameter to the list
ref <parameter> param = parameterFactory::getInstance()->create((*it).first); ref <parameter> param = vmime::create <parameter>((*it).first);
param->parse(info.value); param->parse(info.value);
param->setParsedBounds(info.start, info.end); param->setParsedBounds(info.start, info.end);
@ -404,7 +403,7 @@ ref <parameter> parameterizedHeaderField::getParameter(const string& paramName)
// If no parameter with this name can be found, create a new one // If no parameter with this name can be found, create a new one
if (pos == end) if (pos == end)
{ {
ref <parameter> param = parameterFactory::getInstance()->create(paramName); ref <parameter> param = vmime::create <parameter>(paramName);
appendParameter(param); appendParameter(param);

View File

@ -41,7 +41,7 @@ path::path(const string& localPart, const string& domain)
path::path(const path& p) path::path(const path& p)
: component(), m_localPart(p.m_localPart), m_domain(p.m_domain) : headerFieldValue(), m_localPart(p.m_localPart), m_domain(p.m_domain)
{ {
} }

View File

@ -25,6 +25,8 @@
#include "vmime/header.hpp" #include "vmime/header.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/contentTypeField.hpp"
#include "vmime/emptyContentHandler.hpp" #include "vmime/emptyContentHandler.hpp"
@ -63,7 +65,7 @@ void plainTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
// Set header fields // Set header fields
part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN)); part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
part->getHeader()->ContentType()->setCharset(m_charset); part->getHeader()->ContentType().dynamicCast <contentTypeField>()->setCharset(m_charset);
part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE)); part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
// Set contents // Set contents
@ -83,11 +85,11 @@ void plainTextPart::parse(const bodyPart& /* message */,
m_charset = ctf.getCharset(); m_charset = ctf.getCharset();
} }
catch (exceptions::no_such_field) catch (exceptions::no_such_field&)
{ {
// No "Content-type" field. // No "Content-type" field.
} }
catch (exceptions::no_such_parameter) catch (exceptions::no_such_parameter&)
{ {
// No "charset" parameter. // No "charset" parameter.
} }

View File

@ -38,7 +38,7 @@ relay::relay()
relay::relay(const relay& r) relay::relay(const relay& r)
: component() : headerFieldValue()
{ {
copyFrom(r); copyFrom(r);
} }

View File

@ -36,7 +36,7 @@ text::text()
text::text(const text& t) text::text(const text& t)
: component() : headerFieldValue()
{ {
copyFrom(t); copyFrom(t);
} }
@ -383,4 +383,18 @@ const std::vector <ref <const component> > text::getChildComponents() const
} }
const string text::getWholeBuffer() const
{
string res;
for (std::vector <ref <word> >::const_iterator it = m_words.begin() ;
it != m_words.end() ; ++it)
{
res += (*it)->getBuffer();
}
return res;
}
} // vmime } // vmime

View File

@ -44,7 +44,7 @@ word::word()
word::word(const word& w) word::word(const word& w)
: component(), m_buffer(w.m_buffer), m_charset(w.m_charset) : headerFieldValue(), m_buffer(w.m_buffer), m_charset(w.m_charset)
{ {
} }

View File

@ -78,10 +78,10 @@ VMIME_TEST_SUITE_BEGIN
vmime::misc::importanceHelper::setImportanceHeader(hdr, i); vmime::misc::importanceHelper::setImportanceHeader(hdr, i);
VASSERT_NO_THROW("1", hdr->findField("Importance")); VASSERT_NO_THROW("1", hdr->findField("Importance"));
VASSERT_EQ("2", ImportanceValue, hdr->findField("Importance")->getValue().generate()); VASSERT_EQ("2", ImportanceValue, hdr->findField("Importance")->getValue()->generate());
VASSERT_NO_THROW("3", hdr->findField("X-Priority")); VASSERT_NO_THROW("3", hdr->findField("X-Priority"));
VASSERT_EQ("4", XPriorityValue, hdr->findField("X-Priority")->getValue().generate()); VASSERT_EQ("4", XPriorityValue, hdr->findField("X-Priority")->getValue()->generate());
} }
void testSetImportance1() void testSetImportance1()

View File

@ -33,40 +33,30 @@ VMIME_TEST_SUITE_BEGIN
VMIME_TEST_LIST_BEGIN VMIME_TEST_LIST_BEGIN
VMIME_TEST(testParse) VMIME_TEST(testParse)
VMIME_TEST(testGenerate) VMIME_TEST(testGenerate)
VMIME_TEST(testNonStandardEncodedParam)
VMIME_TEST_LIST_END VMIME_TEST_LIST_END
// HACK: parameterizedHeaderField constructor is private // HACK: parameterizedHeaderField constructor is private
class parameterizedHeaderField : public vmime::parameterizedHeaderField class parameterizedHeaderField : public vmime::parameterizedHeaderField
{ {
private:
vmime::ref <vmime::typeAdapter <vmime::string> > m_value;
public: public:
parameterizedHeaderField() parameterizedHeaderField()
: headerField("F"), : headerField("F")
m_value(vmime::create <vmime::typeAdapter <vmime::string> >("X"))
{ {
setValue(vmime::headerFieldFactory::getInstance()->createValue(getName()));
setValue(vmime::word("X"));
} }
const vmime::component& getValue() const { return *m_value; }
vmime::component& getValue() { return *m_value; }
void setValue(const vmime::component&) { /* Do nothing */ }
const vmime::ref <const vmime::component> getValueImp() const { return m_value; }
vmime::ref <vmime::component> getValueImp() { return m_value; }
}; };
#define PARAM_VALUE(p, n) (p.getParameterAt(n)->getValue().generate()) #define PARAM_VALUE(p, n) (p.getParameterAt(n)->getValue().generate())
#define PARAM_NAME(p, n) (p.getParameterAt(n)->getName()) #define PARAM_NAME(p, n) (p.getParameterAt(n)->getName())
#define PARAM_CHARSET(p, n) ( \ #define PARAM_CHARSET(p, n) \
(p.getParameterAt(n).staticCast <vmime::defaultParameter>())->getValue().getCharset().generate()) (p.getParameterAt(n)->getValue().getCharset().generate())
#define PARAM_BUFFER(p, n) ( \ #define PARAM_BUFFER(p, n) \
(p.getParameterAt(n).staticCast <vmime::defaultParameter>())->getValue().getBuffer()) (p.getParameterAt(n)->getValue().getBuffer())
void testParse() void testParse()
@ -201,32 +191,32 @@ VMIME_TEST_SUITE_BEGIN
{ {
// Simple parameter/value // Simple parameter/value
parameterizedHeaderField p1; parameterizedHeaderField p1;
p1.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "value1")); p1.appendParameter(vmime::create <vmime::parameter>("param1", "value1"));
VASSERT_EQ("1", "F: X; param1=value1", p1.generate()); VASSERT_EQ("1", "F: X; param1=value1", p1.generate());
// Value that needs quoting (1/2) // Value that needs quoting (1/2)
parameterizedHeaderField p2a; parameterizedHeaderField p2a;
p2a.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "value1a;value1b")); p2a.appendParameter(vmime::create <vmime::parameter>("param1", "value1a;value1b"));
VASSERT_EQ("2a", "F: X; param1=\"value1a;value1b\"", p2a.generate()); VASSERT_EQ("2a", "F: X; param1=\"value1a;value1b\"", p2a.generate());
// Value that needs quoting (2/2) // Value that needs quoting (2/2)
parameterizedHeaderField p2b; parameterizedHeaderField p2b;
p2b.appendParameter(vmime::parameterFactory::getInstance()->create("param1", "va\\lue\"1")); p2b.appendParameter(vmime::create <vmime::parameter>("param1", "va\\lue\"1"));
VASSERT_EQ("2b", "F: X; param1=\"va\\\\lue\\\"1\"", p2b.generate()); VASSERT_EQ("2b", "F: X; param1=\"va\\\\lue\\\"1\"", p2b.generate());
// Extended parameter with charset specifier // Extended parameter with charset specifier
parameterizedHeaderField p3; parameterizedHeaderField p3;
p3.appendParameter(vmime::parameterFactory::getInstance()->create("param1", p3.appendParameter(vmime::create <vmime::parameter>("param1",
vmime::word("value 1\xe9", vmime::charset("charset")))); vmime::word("value 1\xe9", vmime::charset("charset"))));
VASSERT_EQ("3", "F: X; param1=\"value 1\";param1*=charset''value%201%E9", p3.generate()); VASSERT_EQ("3", "F: X; param1=\"value 1\";param1*=charset''value%201%E9", p3.generate());
// Value that spans on multiple lines // Value that spans on multiple lines
parameterizedHeaderField p4; parameterizedHeaderField p4;
p4.appendParameter(vmime::parameterFactory::getInstance()->create("param1", p4.appendParameter(vmime::create <vmime::parameter>("param1",
vmime::word("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ", vmime::word("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ",
vmime::charset("charset")))); vmime::charset("charset"))));
@ -241,5 +231,28 @@ VMIME_TEST_SUITE_BEGIN
"param1*6*=WXYZ", p4.generate(25)); // max line length = 25 "param1*6*=WXYZ", p4.generate(25)); // max line length = 25
} }
void testNonStandardEncodedParam()
{
// This syntax is non-standard (expressly prohibited
// by RFC-2047), but is used by Mozilla:
//
// Content-Type: image/png;
// name="=?us-ascii?Q?Logo_VMime=2Epng?="
parameterizedHeaderField p1;
p1.parse("image/png; name=\"=?us-ascii?Q?Logo_VMime=2Epng?=\"");
VASSERT_EQ("1.1", 1, p1.getParameterCount());
VASSERT_EQ("1.2", "name", PARAM_NAME(p1, 0));
VASSERT_EQ("1.3", "Logo VMime.png", PARAM_VALUE(p1, 0));
parameterizedHeaderField p2;
p2.parse("image/png; name=\"Logo =?us-ascii?Q?VMime=2Epng?=\"");
VASSERT_EQ("2.1", 1, p2.getParameterCount());
VASSERT_EQ("2.2", "name", PARAM_NAME(p2, 0));
VASSERT_EQ("2.3", "Logo VMime.png", PARAM_VALUE(p2, 0));
}
VMIME_TEST_SUITE_END VMIME_TEST_SUITE_END

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
namespace vmime namespace vmime
@ -39,7 +39,7 @@ namespace vmime
* and mailboxGroup classes. * and mailboxGroup classes.
*/ */
class address : public component class address : public headerFieldValue
{ {
friend class addressList; friend class addressList;

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
#include "vmime/address.hpp" #include "vmime/address.hpp"
@ -41,7 +41,7 @@ class mailboxList;
/** A list of addresses. /** A list of addresses.
*/ */
class addressList : public component class addressList : public headerFieldValue
{ {
public: public:

View File

@ -27,6 +27,9 @@
#include "vmime/attachment.hpp" #include "vmime/attachment.hpp"
#include "vmime/contentDispositionField.hpp"
#include "vmime/contentTypeField.hpp"
namespace vmime namespace vmime
{ {

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
namespace vmime namespace vmime
@ -36,7 +36,7 @@ namespace vmime
/** Content disposition (basic type). /** Content disposition (basic type).
*/ */
class contentDisposition : public component class contentDisposition : public headerFieldValue
{ {
public: public:

View File

@ -26,7 +26,6 @@
#include "vmime/parameterizedHeaderField.hpp" #include "vmime/parameterizedHeaderField.hpp"
#include "vmime/genericField.hpp"
#include "vmime/contentDisposition.hpp" #include "vmime/contentDisposition.hpp"
#include "vmime/dateTime.hpp" #include "vmime/dateTime.hpp"
@ -37,7 +36,7 @@ namespace vmime
{ {
class contentDispositionField : public parameterizedHeaderField, public genericField <contentDisposition> class contentDispositionField : public parameterizedHeaderField
{ {
friend class vmime::creator; // create ref friend class vmime::creator; // create ref
@ -48,19 +47,69 @@ protected:
public: public:
const datetime& getCreationDate() const; /** Return the value of the "creation-date" parameter.
*
* @return value of the "creation-date" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/
const datetime getCreationDate() const;
/** Set the value of the "creation-date" parameter.
*
* @param creationDate new value for the "creation-date" parameter
*/
void setCreationDate(const datetime& creationDate); void setCreationDate(const datetime& creationDate);
const datetime& getModificationDate() const; /** Return the value of the "modification-date" parameter.
*
* @return value of the "modification-date" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/
const datetime getModificationDate() const;
/** Set the value of the "modification-date" parameter.
*
* @param modificationDate new value for the "modification-date" parameter
*/
void setModificationDate(const datetime& modificationDate); void setModificationDate(const datetime& modificationDate);
const datetime& getReadDate() const; /** Return the value of the "read-date" parameter.
*
* @return value of the "read-date" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/
const datetime getReadDate() const;
/** Set the value of the "read-date" parameter.
*
* @param readDate new value for the "read-date" parameter
*/
void setReadDate(const datetime& readDate); void setReadDate(const datetime& readDate);
/** Return the value of the "filename" parameter.
*
* @return value of the "filename" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/
const word getFilename() const; const word getFilename() const;
/** Set the value of the "filename" parameter.
*
* @param filename new value for the "filename" parameter
*/
void setFilename(const word& filename); void setFilename(const word& filename);
/** Return the value of the "size" parameter.
*
* @return value of the "size" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/
const string getSize() const; const string getSize() const;
/** Set the value of the "size" parameter.
*
* @param size new value for the "size" parameter
*/
void setSize(const string& size); void setSize(const string& size);
}; };

View File

@ -26,7 +26,6 @@
#include "vmime/parameterizedHeaderField.hpp" #include "vmime/parameterizedHeaderField.hpp"
#include "vmime/genericField.hpp"
#include "vmime/mediaType.hpp" #include "vmime/mediaType.hpp"
#include "vmime/charset.hpp" #include "vmime/charset.hpp"
@ -36,7 +35,7 @@ namespace vmime
{ {
class contentTypeField : public parameterizedHeaderField, public genericField <mediaType> class contentTypeField : public parameterizedHeaderField
{ {
friend class vmime::creator; // create ref friend class vmime::creator; // create ref
@ -47,25 +46,33 @@ protected:
public: public:
/** Return the value of the "boundary" parameter. /** Return the value of the "boundary" parameter. Boundary is a
* random string used to separate body parts.
* *
* @return value of the "boundary" parameter * @return value of the "boundary" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/ */
const string getBoundary() const; const string getBoundary() const;
/** Set the value of the "boundary" parameter. /** Set the value of the "boundary" parameter. Boundary is a
* random string used to separate body parts. Normally, the
* boundary is generated automatically by VMime, you should
* not need to call this.
* *
* @param boundary new value for the "boundary" parameter * @param boundary new value for the "boundary" parameter
*/ */
void setBoundary(const string& boundary); void setBoundary(const string& boundary);
/** Return the value of the "charset" parameter. /** Return the value of the "charset" parameter. It specifies the
* charset used in the body part contents.
* *
* @return value of the "charset" parameter * @return value of the "charset" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/ */
const charset& getCharset() const; const charset getCharset() const;
/** Set the value of the "charset" parameter. /** Set the value of the "charset" parameter. It specifies the
* charset used in the body part contents.
* *
* @param ch new value for the "charset" parameter * @param ch new value for the "charset" parameter
*/ */
@ -74,6 +81,7 @@ public:
/** Return the value of the "report-type" parameter (RFC-1892). /** Return the value of the "report-type" parameter (RFC-1892).
* *
* @return value of the "report-type" parameter * @return value of the "report-type" parameter
* @throw exceptions::no_such_parameter if the parameter does not exist
*/ */
const string getReportType() const; const string getReportType() const;

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
#include <ctime> #include <ctime>
@ -38,7 +38,7 @@ namespace vmime
/** Date and time (basic type). /** Date and time (basic type).
*/ */
class datetime : public component class datetime : public headerFieldValue
{ {
public: public:

View File

@ -1,77 +0,0 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// 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.
//
// 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.
//
#ifndef VMIME_DEFAULTPARAMETER_HPP_INCLUDED
#define VMIME_DEFAULTPARAMETER_HPP_INCLUDED
#include "vmime/parameter.hpp"
#include "vmime/parameterFactory.hpp"
#include "vmime/word.hpp"
namespace vmime
{
/** Default parameter implementation (with support for RFC-2231).
*/
class defaultParameter : public parameter
{
friend class vmime::creator; // create ref
protected:
defaultParameter();
public:
defaultParameter& operator=(const defaultParameter& other);
const word& getValue() const;
word& getValue();
void setValue(const word& value);
void setValue(const component& value);
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
private:
void parse(const std::vector <valueChunk>& chunks);
const ref <const component> getValueImp() const;
const ref <component> getValueImp();
ref <word> m_value;
};
} // vmime
#endif // VMIME_DEFAULTPARAMETER_HPP_INCLUDED

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
#include <vector> #include <vector>
@ -38,7 +38,7 @@ namespace vmime
/** Disposition - from RFC-3798 (basic type). /** Disposition - from RFC-3798 (basic type).
*/ */
class disposition : public component class disposition : public headerFieldValue
{ {
public: public:

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
#include "vmime/encoder.hpp" #include "vmime/encoder.hpp"
@ -40,7 +40,7 @@ class contentHandler;
/** Content encoding (basic type). /** Content encoding (basic type).
*/ */
class encoding : public component class encoding : public headerFieldValue
{ {
public: public:

View File

@ -27,6 +27,8 @@
#include "vmime/defaultAttachment.hpp" #include "vmime/defaultAttachment.hpp"
#include "vmime/dateTime.hpp"
namespace vmime namespace vmime
{ {

View File

@ -32,13 +32,6 @@
#include "vmime/headerField.hpp" #include "vmime/headerField.hpp"
#include "vmime/headerFieldFactory.hpp" #include "vmime/headerFieldFactory.hpp"
#include "vmime/mailboxField.hpp"
#include "vmime/contentTypeField.hpp"
#include "vmime/contentDispositionField.hpp"
#include "vmime/standardFields.hpp"
#include "vmime/standardParams.hpp"
namespace vmime namespace vmime
{ {
@ -61,38 +54,38 @@ public:
header(); header();
~header(); ~header();
#define FIELD_ACCESS(methodName, fieldName, type) \ #define FIELD_ACCESS(methodName, fieldName) \
ref <type> methodName() { return getField(fields::fieldName).dynamicCast <type>(); } \ ref <headerField> methodName() { return getField(fields::fieldName); } \
ref <const type> methodName() const { return findField(fields::fieldName).dynamicCast <const type>(); } ref <const headerField> methodName() const { return findField(fields::fieldName); }
FIELD_ACCESS(From, FROM, mailboxField) FIELD_ACCESS(From, FROM)
FIELD_ACCESS(Sender, SENDER, mailboxField) FIELD_ACCESS(Sender, SENDER)
FIELD_ACCESS(ReplyTo, REPLY_TO, mailboxField) FIELD_ACCESS(ReplyTo, REPLY_TO)
FIELD_ACCESS(DeliveredTo, DELIVERED_TO, mailboxField) FIELD_ACCESS(DeliveredTo, DELIVERED_TO)
FIELD_ACCESS(InReplyTo, IN_REPLY_TO, messageIdSequenceField) FIELD_ACCESS(InReplyTo, IN_REPLY_TO)
FIELD_ACCESS(ReturnPath, RETURN_PATH, pathField) FIELD_ACCESS(ReturnPath, RETURN_PATH)
FIELD_ACCESS(References, REFERENCES, messageIdSequenceField) FIELD_ACCESS(References, REFERENCES)
FIELD_ACCESS(To, TO, addressListField) FIELD_ACCESS(To, TO)
FIELD_ACCESS(Cc, CC, addressListField) FIELD_ACCESS(Cc, CC)
FIELD_ACCESS(Bcc, BCC, addressListField) FIELD_ACCESS(Bcc, BCC)
FIELD_ACCESS(Date, DATE, dateField) FIELD_ACCESS(Date, DATE)
FIELD_ACCESS(Subject, SUBJECT, textField) FIELD_ACCESS(Subject, SUBJECT)
FIELD_ACCESS(Organization, ORGANIZATION, textField) FIELD_ACCESS(Organization, ORGANIZATION)
FIELD_ACCESS(UserAgent, USER_AGENT, textField) FIELD_ACCESS(UserAgent, USER_AGENT)
FIELD_ACCESS(ContentType, CONTENT_TYPE, contentTypeField) FIELD_ACCESS(ContentType, CONTENT_TYPE)
FIELD_ACCESS(ContentDescription, CONTENT_DESCRIPTION, textField) FIELD_ACCESS(ContentDescription, CONTENT_DESCRIPTION)
FIELD_ACCESS(ContentTransferEncoding, CONTENT_TRANSFER_ENCODING, contentEncodingField) FIELD_ACCESS(ContentTransferEncoding, CONTENT_TRANSFER_ENCODING)
FIELD_ACCESS(MimeVersion, MIME_VERSION, defaultField) FIELD_ACCESS(MimeVersion, MIME_VERSION)
FIELD_ACCESS(ContentDisposition, CONTENT_DISPOSITION, contentDispositionField) FIELD_ACCESS(ContentDisposition, CONTENT_DISPOSITION)
FIELD_ACCESS(ContentId, CONTENT_ID, messageIdField) FIELD_ACCESS(ContentId, CONTENT_ID)
FIELD_ACCESS(MessageId, MESSAGE_ID, messageIdField) FIELD_ACCESS(MessageId, MESSAGE_ID)
FIELD_ACCESS(ContentLocation, CONTENT_LOCATION, defaultField) FIELD_ACCESS(ContentLocation, CONTENT_LOCATION)
FIELD_ACCESS(OriginalMessageId, ORIGINAL_MESSAGE_ID, messageIdField) FIELD_ACCESS(OriginalMessageId, ORIGINAL_MESSAGE_ID)
FIELD_ACCESS(Disposition, DISPOSITION, dispositionField) FIELD_ACCESS(Disposition, DISPOSITION)
FIELD_ACCESS(DispositionNotificationTo, DISPOSITION_NOTIFICATION_TO, mailboxListField) FIELD_ACCESS(DispositionNotificationTo, DISPOSITION_NOTIFICATION_TO)
#undef FIELD_ACCESS #undef FIELD_ACCESS

View File

@ -27,6 +27,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/component.hpp"
#include "vmime/headerFieldValue.hpp"
namespace vmime namespace vmime
@ -41,8 +42,12 @@ class headerField : public component
friend class headerFieldFactory; friend class headerFieldFactory;
friend class header; friend class header;
friend class vmime::creator; // create ref
protected: protected:
// Protected constructor to prevent the user from creating
// new objects without using 'headerFieldFactory'
headerField(); headerField();
headerField(const string& fieldName); headerField(const string& fieldName);
@ -56,6 +61,12 @@ public:
const std::vector <ref <const component> > getChildComponents() const; const std::vector <ref <const component> > getChildComponents() const;
/** Sets the name of this field.
*
* @param name field name (eg: "From" or "X-MyField").
*/
void setName(const string& name);
/** Return the name of this field. /** Return the name of this field.
* *
* @return field name * @return field name
@ -73,21 +84,32 @@ public:
* *
* @return read-only value object * @return read-only value object
*/ */
virtual const component& getValue() const = 0; virtual ref <const headerFieldValue> getValue() const;
/** Return the value object attached to this field. /** Return the value object attached to this field.
* *
* @return value object * @return value object
*/ */
virtual component& getValue() = 0; virtual ref <headerFieldValue> getValue();
/** Set the value of this field. /** Set the value of this field.
* *
* @throw std::bad_cast_exception if the value type is * @param value new value
* incompatible with the header field type
* @param value value object
*/ */
virtual void setValue(const component& value) = 0; virtual void setValue(ref <headerFieldValue> value);
/** Set the value of this field by cloning the specified value.
*
* @param value new value
*/
virtual void setValueConst(ref <const headerFieldValue> value);
/** Set the value of this field (reference version).
* The value will be cloned.
*
* @param value new value
*/
virtual void setValue(const headerFieldValue& value);
/** Set the value of this field given a character string. /** Set the value of this field given a character string.
* *
@ -104,15 +126,11 @@ public:
protected: protected:
virtual const ref <const component> getValueImp() const = 0;
virtual ref <component> getValueImp() = 0;
private:
static ref <headerField> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL); static ref <headerField> parseNext(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
string m_name; string m_name;
ref <headerFieldValue> m_value;
}; };

View File

@ -33,6 +33,9 @@ namespace vmime
{ {
/** Creates header field and header field value objects.
*/
class headerFieldFactory class headerFieldFactory
{ {
protected: protected:
@ -45,17 +48,23 @@ protected:
NameMap m_nameMap; NameMap m_nameMap;
typedef ref <headerFieldValue> (*ValueAllocFunc)(void);
typedef std::map <string, ValueAllocFunc> ValueMap;
ValueMap m_valueMap;
public: public:
static headerFieldFactory* getInstance(); static headerFieldFactory* getInstance();
#ifndef VMIME_BUILDING_DOC #ifndef VMIME_BUILDING_DOC
template <class TYPE> // TYPE must inherit from BASE_TYPE
template <class BASE_TYPE, class TYPE>
class registerer class registerer
{ {
public: public:
static ref <headerField> creator() static ref <BASE_TYPE> creator()
{ {
// Allocate a new object // Allocate a new object
return vmime::create <TYPE>(); return vmime::create <TYPE>();
@ -64,14 +73,49 @@ public:
#endif // VMIME_BUILDING_DOC #endif // VMIME_BUILDING_DOC
/** Register a field type.
*
* @param T field class (must inherit from 'headerField')
* @param name field name (eg. "X-MyField")
*/
template <class T> template <class T>
void registerName(const string& name) void registerField(const string& name)
{ {
m_nameMap.insert(NameMap::value_type m_nameMap.insert(NameMap::value_type
(utility::stringUtils::toLower(name), &registerer<T>::creator)); (utility::stringUtils::toLower(name),
&registerer <headerField, T>::creator));
} }
/** Register a field value type.
*
* @param T value class (must inherit from 'headerFieldValue')
* @param name field name
*/
template <class T>
void registerFieldValue(const string& name)
{
m_valueMap.insert(ValueMap::value_type
(utility::stringUtils::toLower(name),
&registerer <headerFieldValue, T>::creator));
}
/** Create a new field object for the specified field name.
* If the field name has not been registered, a default type
* is used.
*
* @param name field name
* @param body string that will be parsed to initialize
* the value of the field
* @return a new field object
*/
ref <headerField> create(const string& name, const string& body = NULL_STRING); ref <headerField> create(const string& name, const string& body = NULL_STRING);
/** Create a new field value for the specified field.
*
* @param fieldName name of the field for which to create value
* @return a new value object for the field
*/
ref <headerFieldValue> createValue(const string& fieldName);
}; };

View File

@ -21,29 +21,31 @@
// the GNU General Public License cover the whole combination. // the GNU General Public License cover the whole combination.
// //
#ifndef VMIME_HEADERFIELDVALUE_HPP_INCLUDED
#define VMIME_HEADERFIELDVALUE_HPP_INCLUDED
#include "vmime/typeAdapter.hpp"
#include "vmime/base.hpp"
#include "vmime/component.hpp"
namespace vmime namespace vmime
{ {
#if (!defined(__GNUC__) || ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 3))) && !defined(_MSC_VER) /** Base class for all classes that can be used as a value
* for a header field.
*/
template <> class headerFieldValue : public component
void typeAdapter <string>::parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{ {
m_value = string(buffer.begin() + position, buffer.begin() + end); public:
setParsedBounds(position, end); };
if (newPosition)
*newPosition = end;
}
#endif // (!defined(__GNUC__) || ((__GNUC__ >= 3) && (__GNUC_MINOR__ >= 3))) && !defined(_MSC_VER)
} // vmime } // vmime
#endif // VMIME_HEADERFIELDVALUE_HPP_INCLUDED

View File

@ -25,15 +25,23 @@
#define VMIME_MAILBOXFIELD_HPP_INCLUDED #define VMIME_MAILBOXFIELD_HPP_INCLUDED
#include "vmime/genericField.hpp" #include "vmime/headerField.hpp"
#include "vmime/mailbox.hpp" #include "vmime/mailbox.hpp"
// Hide implementation details from user
#ifndef VMIME_BUILDING_DOC
namespace vmime namespace vmime
{ {
class mailboxField : public genericField <mailbox> /** Work-around for malformed header fields that are of type 'mailbox'
* and contains multiple addresses.
*/
class mailboxField : public headerField
{ {
friend class vmime::creator; // create ref friend class vmime::creator; // create ref
@ -48,7 +56,11 @@ public:
}; };
#endif // VMIME_BUILDING_DOC
} // vmime } // vmime
#endif // VMIME_MAILBOXFIELD_HPP_INCLUDED #endif // VMIME_MAILBOXFIELD_HPP_INCLUDED

View File

@ -39,7 +39,7 @@ namespace vmime
* from inserting mailbox groups where it is not allowed by the RFC. * from inserting mailbox groups where it is not allowed by the RFC.
*/ */
class mailboxList : public component class mailboxList : public headerFieldValue
{ {
public: public:

View File

@ -28,6 +28,8 @@
#include "vmime/mdn/receivedMDNInfos.hpp" #include "vmime/mdn/receivedMDNInfos.hpp"
#include "vmime/mdn/sendableMDNInfos.hpp" #include "vmime/mdn/sendableMDNInfos.hpp"
#include "vmime/mailboxList.hpp"
namespace vmime { namespace vmime {
namespace mdn { namespace mdn {

View File

@ -26,7 +26,10 @@
#include "vmime/mdn/MDNInfos.hpp" #include "vmime/mdn/MDNInfos.hpp"
#include "vmime/disposition.hpp" #include "vmime/disposition.hpp"
#include "vmime/messageId.hpp"
#include "vmime/mailbox.hpp"
namespace vmime { namespace vmime {

View File

@ -27,6 +27,8 @@
#include "vmime/mdn/MDNInfos.hpp" #include "vmime/mdn/MDNInfos.hpp"
#include "vmime/mailbox.hpp"
namespace vmime { namespace vmime {
namespace mdn { namespace mdn {

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
namespace vmime namespace vmime
@ -36,7 +36,7 @@ namespace vmime
/** Content media type (basic type). /** Content media type (basic type).
*/ */
class mediaType : public component class mediaType : public headerFieldValue
{ {
public: public:

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
namespace vmime namespace vmime
@ -36,7 +36,7 @@ namespace vmime
/** Message identifier (basic type). /** Message identifier (basic type).
*/ */
class messageId : public component class messageId : public headerFieldValue
{ {
friend class messageIdSequence; friend class messageIdSequence;

View File

@ -35,7 +35,7 @@ namespace vmime
/** A list of message identifiers (basic type). /** A list of message identifiers (basic type).
*/ */
class messageIdSequence : public component class messageIdSequence : public headerFieldValue
{ {
public: public:

View File

@ -30,6 +30,10 @@
#include "vmime/message.hpp" #include "vmime/message.hpp"
#include "vmime/attachment.hpp" #include "vmime/attachment.hpp"
#include "vmime/mailbox.hpp"
#include "vmime/addressList.hpp"
#include "vmime/dateTime.hpp"
#include "vmime/textPart.hpp" #include "vmime/textPart.hpp"

View File

@ -26,6 +26,7 @@
#include "vmime/header.hpp" #include "vmime/header.hpp"
#include "vmime/mediaType.hpp"
#include "vmime/utility/progressListener.hpp" #include "vmime/utility/progressListener.hpp"
#include "vmime/utility/stream.hpp" #include "vmime/utility/stream.hpp"

View File

@ -26,6 +26,7 @@
#include "vmime/config.hpp" #include "vmime/config.hpp"
#include "vmime/messageId.hpp"
#include "vmime/net/store.hpp" #include "vmime/net/store.hpp"
#include "vmime/net/socket.hpp" #include "vmime/net/socket.hpp"

View File

@ -28,6 +28,8 @@
#include "vmime/net/service.hpp" #include "vmime/net/service.hpp"
#include "vmime/utility/stream.hpp" #include "vmime/utility/stream.hpp"
#include "vmime/mailboxList.hpp"
namespace vmime { namespace vmime {

View File

@ -27,6 +27,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/component.hpp"
#include "vmime/word.hpp"
namespace vmime namespace vmime
@ -35,11 +36,19 @@ namespace vmime
class parameter : public component class parameter : public component
{ {
friend class parameterFactory;
friend class parameterizedHeaderField; friend class parameterizedHeaderField;
private:
parameter(const parameter&);
public: public:
parameter(const string& name);
parameter(const string& name, const word& value);
parameter(const string& name, const string& value);
#ifndef VMIME_BUILDING_DOC #ifndef VMIME_BUILDING_DOC
/** A single section of a multi-section parameter, /** A single section of a multi-section parameter,
@ -60,31 +69,58 @@ public:
const std::vector <ref <const component> > getChildComponents() const; const std::vector <ref <const component> > getChildComponents() const;
/** Return the name of the parameter. /** Return the name of this parameter.
* *
* @return name of the parameter * @return name of this parameter
*/ */
const string& getName() const; const string& getName() const;
/** Return the read-only value object attached to this field. /** Return the raw value of this parameter.
* *
* @return read-only value object * @return read-only value
*/ */
virtual const component& getValue() const = 0; const word& getValue() const;
/** Return the value object attached to this field. /** Return the value of this object in the specified type.
* For example, the following code:
* *
* @return value object * <pre>
* getParameter("creation-date")->getValueAs <vmime::dateTime>()</pre>
* </pre>
*
* is equivalent to:
*
* <pre>
* ref <vmime::word> rawValue = getParameter("creation-date");
*
* vmime::dateTime theDate;
* theDate.parse(rawValue->getBuffer());
* </pre>
*
* @param T type to which convert the value
* @return value
*/ */
virtual component& getValue() = 0; template <typename T>
const T getValueAs() const
{
T ret;
ret.parse(m_value.getBuffer());
/** Set the value of the parameter. return ret;
}
/** Set the value of this parameter.
* *
* @throw std::bad_cast_exception if the value type is * @param value new value
* incompatible with the parameter type
* @param value value object
*/ */
virtual void setValue(const component& value) = 0; void setValue(const component& value);
/** Set the raw value of this parameter.
*
* @param value new value
*/
void setValue(const word& value);
using component::parse; using component::parse;
using component::generate; using component::generate;
@ -92,18 +128,13 @@ public:
void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL); void parse(const string& buffer, const string::size_type position, const string::size_type end, string::size_type* newPosition = NULL);
void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const; void generate(utility::outputStream& os, const string::size_type maxLineLength = lineLengthLimits::infinite, const string::size_type curLinePos = 0, string::size_type* newLinePos = NULL) const;
protected:
virtual const ref <const component> getValueImp() const = 0;
virtual const ref <component> getValueImp() = 0;
private: private:
void parse(const std::vector <valueChunk>& chunks);
string m_name; string m_name;
word m_value;
void generateValue(utility::outputStream& os, const string::size_type maxLineLength, const string::size_type curLinePos, string::size_type* newLinePos) const;
virtual void parse(const std::vector <valueChunk>& chunks);
}; };

View File

@ -1,97 +0,0 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// 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.
//
// 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.
//
#ifndef VMIME_PARAMETERFACTORY_HPP_INCLUDED
#define VMIME_PARAMETERFACTORY_HPP_INCLUDED
#include "vmime/parameter.hpp"
#include "vmime/utility/stringUtils.hpp"
namespace vmime
{
class parameterFactory
{
protected:
parameterFactory();
~parameterFactory();
typedef ref <parameter> (*AllocFunc)(void);
typedef std::map <string, AllocFunc> NameMap;
NameMap m_nameMap;
public:
static parameterFactory* getInstance();
#ifndef VMIME_BUILDING_DOC
template <class TYPE>
class registerer
{
public:
static ref <parameter> creator()
{
// Allocate a new object
return vmime::create <TYPE>();
}
};
#endif // VMIME_BUILDING_DOC
template <class T>
void registerName(const string& name)
{
m_nameMap.insert(NameMap::value_type
(utility::stringUtils::toLower(name), &registerer<T>::creator));
}
/** Create a new parameter and parse its value. The returned parameter
* can then be added in a vmime::parameterizedHeaderField object.
*
* @param name parameter name (ASCII characters only)
* @param value value to be parsed
* @return created parameter
*/
ref <parameter> create(const string& name, const string& value = NULL_STRING);
/** Create a new parameter and set its value. The returned parameter
* can then be added in a vmime::parameterizedHeaderField object.
*
* @param name parameter name (ASCII characters only)
* @param value value to be set
* @return created parameter
*/
ref <parameter> create(const string& name, const component& value);
};
} // vmime
#endif // VMIME_PARAMETERFACTORY_HPP_INCLUDED

View File

@ -29,7 +29,6 @@
#include "vmime/headerFieldFactory.hpp" #include "vmime/headerFieldFactory.hpp"
#include "vmime/parameter.hpp" #include "vmime/parameter.hpp"
#include "vmime/exception.hpp" #include "vmime/exception.hpp"
#include "vmime/parameterFactory.hpp"
namespace vmime namespace vmime
@ -42,10 +41,12 @@ namespace vmime
class parameterizedHeaderField : virtual public headerField class parameterizedHeaderField : virtual public headerField
{ {
friend class headerFieldFactory::registerer <parameterizedHeaderField>; friend class vmime::creator; // create ref
protected: protected:
// Protected constructor to prevent the user from creating
// new objects without using 'headerFieldFactory'
parameterizedHeaderField(); parameterizedHeaderField();
public: public:

View File

@ -25,7 +25,7 @@
#define VMIME_PATH_HPP_INCLUDED #define VMIME_PATH_HPP_INCLUDED
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
namespace vmime namespace vmime
@ -35,7 +35,7 @@ namespace vmime
/** A path: a local part + '@' + a domain. /** A path: a local part + '@' + a domain.
*/ */
class path : public component class path : public headerFieldValue
{ {
public: public:

View File

@ -26,7 +26,7 @@
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
#include "vmime/dateTime.hpp" #include "vmime/dateTime.hpp"
@ -38,7 +38,7 @@ namespace vmime
/** Trace information about a relay (basic type). /** Trace information about a relay (basic type).
*/ */
class relay : public component class relay : public headerFieldValue
{ {
public: public:

View File

@ -25,6 +25,7 @@
#define VMIME_TEXT_HPP_INCLUDED #define VMIME_TEXT_HPP_INCLUDED
#include "vmime/headerFieldValue.hpp"
#include "vmime/base.hpp" #include "vmime/base.hpp"
#include "vmime/word.hpp" #include "vmime/word.hpp"
@ -36,7 +37,7 @@ namespace vmime
/** List of encoded-words, as defined in RFC-2047 (basic type). /** List of encoded-words, as defined in RFC-2047 (basic type).
*/ */
class text : public component class text : public headerFieldValue
{ {
public: public:
@ -142,6 +143,14 @@ public:
*/ */
const string getConvertedText(const charset& dest) const; const string getConvertedText(const charset& dest) const;
/** Return the unconverted (raw) data of all words. This is the
* concatenation of the results returned by getBuffer() on
* the contained words.
*
* @return raw data
*/
const string getWholeBuffer() const;
/** This function can be used to make several encoded words from a text. /** This function can be used to make several encoded words from a text.
* All the characters in the text must be in the same specified charset. * All the characters in the text must be in the same specified charset.
* *

View File

@ -1,159 +0,0 @@
//
// VMime library (http://www.vmime.org)
// Copyright (C) 2002-2005 Vincent Richard <vincent@vincent-richard.net>
//
// This program is free software; you can redistribute it and/or
// modify it under the terms of the GNU General Public License as
// published by the Free Software Foundation; either version 2 of
// 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.
//
// 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.
//
#ifndef VMIME_TYPEADAPTER_HPP_INCLUDED
#define VMIME_TYPEADAPTER_HPP_INCLUDED
#include <sstream>
#include "vmime/component.hpp"
namespace vmime
{
/** An adapter to allow any type to act as a 'component'.
*/
template <class TYPE>
class typeAdapter : public component
{
public:
typeAdapter()
{
}
typeAdapter(typeAdapter& a)
: component(), m_value(a.m_value)
{
}
typeAdapter(const TYPE& v)
: m_value(v)
{
}
ref <component> clone() const
{
return create <typeAdapter>(*this);
}
void copyFrom(const component& other)
{
m_value = dynamic_cast <const typeAdapter <TYPE>&>(other).m_value;
}
typeAdapter& operator=(const TYPE& v)
{
m_value = v;
return (*this);
}
typeAdapter& operator=(const component& other)
{
copyFrom(other);
return (*this);
}
operator TYPE() const
{
return (m_value);
}
void parse(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition = NULL)
{
std::istringstream iss(string(buffer.begin() + position, buffer.begin() + end));
iss >> m_value;
setParsedBounds(position, end);
if (newPosition)
*newPosition = end;
}
void generate(utility::outputStream& os,
const string::size_type /* maxLineLength */ = lineLengthLimits::infinite,
const string::size_type curLinePos = 0,
string::size_type* newLinePos = NULL) const
{
std::ostringstream oss;
oss << m_value;
os << oss.str();
if (newLinePos)
*newLinePos = curLinePos + oss.str().length();
}
const std::vector <ref <const component> > getChildComponents() const
{
return std::vector <ref <const component> >();
}
private:
TYPE m_value;
};
#if (defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ <= 2)) || defined(_MSC_VER)
// Because of a bug with g++ <= 3.2, we have to put the implementation
// of the function inline.
template <>
inline void typeAdapter <string>::parse
(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition)
{
m_value = string(buffer.begin() + position, buffer.begin() + end);
if (newPosition)
*newPosition = end;
}
#else
template <>
void typeAdapter <string>::parse
(const string& buffer, const string::size_type position,
const string::size_type end, string::size_type* newPosition);
#endif // (defined(__GNUC__) && (__GNUC__ >= 3) && (__GNUC_MINOR__ <= 2)) || defined(_MSC_VER)
} // vmime
#endif // VMIME_TYPEADAPTE_HPP_INCLUDED

View File

@ -48,8 +48,10 @@
#include "vmime/addressList.hpp" #include "vmime/addressList.hpp"
#include "vmime/mediaType.hpp" #include "vmime/mediaType.hpp"
#include "vmime/messageId.hpp" #include "vmime/messageId.hpp"
#include "vmime/messageIdSequence.hpp"
#include "vmime/relay.hpp" #include "vmime/relay.hpp"
#include "vmime/disposition.hpp" #include "vmime/disposition.hpp"
#include "vmime/path.hpp"
#include "vmime/emptyContentHandler.hpp" #include "vmime/emptyContentHandler.hpp"
#include "vmime/stringContentHandler.hpp" #include "vmime/stringContentHandler.hpp"
@ -62,7 +64,6 @@
#include "vmime/headerFieldFactory.hpp" #include "vmime/headerFieldFactory.hpp"
#include "vmime/mailboxField.hpp" #include "vmime/mailboxField.hpp"
#include "vmime/parameterizedHeaderField.hpp" #include "vmime/parameterizedHeaderField.hpp"
#include "vmime/standardFields.hpp"
// Encoders // Encoders
#include "vmime/encoderFactory.hpp" #include "vmime/encoderFactory.hpp"

View File

@ -25,7 +25,7 @@
#define VMIME_WORD_HPP_INCLUDED #define VMIME_WORD_HPP_INCLUDED
#include "vmime/component.hpp" #include "vmime/headerFieldValue.hpp"
#include "vmime/charset.hpp" #include "vmime/charset.hpp"
@ -37,7 +37,7 @@ namespace vmime
* some text encoded into one specified charset. * some text encoded into one specified charset.
*/ */
class word : public component class word : public headerFieldValue
{ {
friend class text; friend class text;