2004-10-05 10:28:21 +00:00
|
|
|
//
|
2005-03-18 21:33:11 +00:00
|
|
|
// VMime library (http://www.vmime.org)
|
2006-02-05 10:22:59 +00:00
|
|
|
// Copyright (C) 2002-2006 Vincent Richard <vincent@vincent-richard.net>
|
2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
// This program is free software; you can redistribute it and/or
|
|
|
|
// modify it under the terms of the GNU General Public License as
|
|
|
|
// 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.
|
|
|
|
//
|
2005-09-17 10:10:29 +00:00
|
|
|
// You should have received a copy of the GNU General Public License along
|
|
|
|
// with this program; if not, write to the Free Software Foundation, Inc.,
|
|
|
|
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
//
|
|
|
|
// Linking this library statically or dynamically with other modules is making
|
|
|
|
// a combined work based on this library. Thus, the terms and conditions of
|
|
|
|
// the GNU General Public License cover the whole combination.
|
2004-10-05 10:28:21 +00:00
|
|
|
//
|
|
|
|
|
2004-12-26 20:23:29 +00:00
|
|
|
#include "vmime/plainTextPart.hpp"
|
|
|
|
#include "vmime/header.hpp"
|
|
|
|
#include "vmime/exception.hpp"
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2005-11-04 23:21:22 +00:00
|
|
|
#include "vmime/contentTypeField.hpp"
|
|
|
|
|
2005-01-28 17:50:53 +00:00
|
|
|
#include "vmime/emptyContentHandler.hpp"
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
namespace vmime
|
|
|
|
{
|
|
|
|
|
|
|
|
|
2005-01-28 17:50:53 +00:00
|
|
|
plainTextPart::plainTextPart()
|
2005-07-12 22:28:02 +00:00
|
|
|
: m_text(vmime::create <emptyContentHandler>())
|
2005-01-28 17:50:53 +00:00
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
plainTextPart::~plainTextPart()
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const mediaType plainTextPart::getType() const
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
|
|
|
return (mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const int plainTextPart::getPartCount() const
|
|
|
|
{
|
|
|
|
return (1);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plainTextPart::generateIn(bodyPart& /* message */, bodyPart& parent) const
|
|
|
|
{
|
|
|
|
// Create a new part
|
2005-07-12 22:28:02 +00:00
|
|
|
ref <bodyPart> part = vmime::create <bodyPart>();
|
2004-10-21 15:05:47 +00:00
|
|
|
parent.getBody()->appendPart(part);
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
// Set header fields
|
2005-07-12 22:28:02 +00:00
|
|
|
part->getHeader()->ContentType()->setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
|
2005-11-04 23:21:22 +00:00
|
|
|
part->getHeader()->ContentType().dynamicCast <contentTypeField>()->setCharset(m_charset);
|
2005-07-12 22:28:02 +00:00
|
|
|
part->getHeader()->ContentTransferEncoding()->setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
// Set contents
|
2005-07-12 22:28:02 +00:00
|
|
|
part->getBody()->setContents(m_text);
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plainTextPart::parse(const bodyPart& /* message */,
|
|
|
|
const bodyPart& /* parent */, const bodyPart& textPart)
|
|
|
|
{
|
2005-07-12 22:28:02 +00:00
|
|
|
m_text = textPart.getBody()->getContents()->clone().dynamicCast <contentHandler>();
|
2004-10-05 10:28:21 +00:00
|
|
|
|
|
|
|
try
|
|
|
|
{
|
|
|
|
const contentTypeField& ctf = dynamic_cast<contentTypeField&>
|
2004-10-21 15:05:47 +00:00
|
|
|
(*textPart.getHeader()->findField(fields::CONTENT_TYPE));
|
2004-10-05 10:28:21 +00:00
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
m_charset = ctf.getCharset();
|
2004-10-05 10:28:21 +00:00
|
|
|
}
|
2005-11-04 23:21:22 +00:00
|
|
|
catch (exceptions::no_such_field&)
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
|
|
|
// No "Content-type" field.
|
|
|
|
}
|
2005-11-04 23:21:22 +00:00
|
|
|
catch (exceptions::no_such_parameter&)
|
2004-10-05 10:28:21 +00:00
|
|
|
{
|
|
|
|
// No "charset" parameter.
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-21 15:05:47 +00:00
|
|
|
const charset& plainTextPart::getCharset() const
|
|
|
|
{
|
|
|
|
return (m_charset);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void plainTextPart::setCharset(const charset& ch)
|
|
|
|
{
|
|
|
|
m_charset = ch;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-12 22:28:02 +00:00
|
|
|
const ref <const contentHandler> plainTextPart::getText() const
|
2004-10-21 15:05:47 +00:00
|
|
|
{
|
2005-07-12 22:28:02 +00:00
|
|
|
return (m_text);
|
2004-10-21 15:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2005-07-12 22:28:02 +00:00
|
|
|
void plainTextPart::setText(ref <contentHandler> text)
|
2004-10-21 15:05:47 +00:00
|
|
|
{
|
2005-07-12 22:28:02 +00:00
|
|
|
m_text = text->clone().dynamicCast <contentHandler>();
|
2004-10-21 15:05:47 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
2004-10-05 10:28:21 +00:00
|
|
|
} // vmime
|