vmime/src/plainTextPart.cpp

121 lines
2.6 KiB
C++
Raw Normal View History

2004-10-05 10:28:21 +00:00
//
// VMime library (http://vmime.sourceforge.net)
// Copyright (C) 2002-2005 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.
//
// 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., 675 Mass Ave, Cambridge, MA 02139, USA.
//
#include "vmime/plainTextPart.hpp"
#include "vmime/header.hpp"
#include "vmime/exception.hpp"
2004-10-05 10:28:21 +00:00
#include "vmime/emptyContentHandler.hpp"
2004-10-05 10:28:21 +00:00
namespace vmime
{
plainTextPart::plainTextPart()
: m_text(new emptyContentHandler)
{
}
plainTextPart::~plainTextPart()
{
delete (m_text);
}
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
bodyPart* part = new bodyPart();
2004-10-21 15:05:47 +00:00
parent.getBody()->appendPart(part);
2004-10-05 10:28:21 +00:00
// Set header fields
2004-10-21 15:05:47 +00:00
part->getHeader()->ContentType().setValue(mediaType(mediaTypes::TEXT, mediaTypes::TEXT_PLAIN));
part->getHeader()->ContentType().setCharset(m_charset);
part->getHeader()->ContentTransferEncoding().setValue(encoding(encodingTypes::QUOTED_PRINTABLE));
2004-10-05 10:28:21 +00:00
// Set contents
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)
{
delete (m_text);
m_text = textPart.getBody()->getContents().clone();
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
}
catch (exceptions::no_such_field)
{
// No "Content-type" field.
}
catch (exceptions::no_such_parameter)
{
// 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;
}
const contentHandler& plainTextPart::getText() const
{
return (*m_text);
2004-10-21 15:05:47 +00:00
}
void plainTextPart::setText(const contentHandler& text)
{
delete (m_text);
m_text = text.clone();
2004-10-21 15:05:47 +00:00
}
2004-10-05 10:28:21 +00:00
} // vmime