// // VMime library (http://www.vmime.org) // Copyright (C) 2002 Vincent Richard // // 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 3 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/headerFieldFactory.hpp" #include "vmime/exception.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/contentTypeField.hpp" #include "vmime/contentDispositionField.hpp" #include "vmime/mailboxField.hpp" namespace vmime { headerFieldFactory::headerFieldFactory() { // Register parameterized fields registerField (vmime::fields::CONTENT_TYPE); registerField (vmime::fields::CONTENT_TRANSFER_ENCODING); registerField (vmime::fields::CONTENT_DISPOSITION); registerField (vmime::fields::FROM); registerField (vmime::fields::SENDER); registerField (vmime::fields::REPLY_TO); registerField (vmime::fields::DELIVERED_TO); // Register standard field values registerFieldValue (vmime::fields::FROM); registerFieldValue (vmime::fields::TO); registerFieldValue (vmime::fields::CC); registerFieldValue (vmime::fields::BCC); registerFieldValue (vmime::fields::SENDER); registerFieldValue (vmime::fields::DATE); registerFieldValue (vmime::fields::RECEIVED); registerFieldValue (vmime::fields::SUBJECT); registerFieldValue (vmime::fields::REPLY_TO); registerFieldValue (vmime::fields::DELIVERED_TO); registerFieldValue (vmime::fields::ORGANIZATION); registerFieldValue (vmime::fields::USER_AGENT); registerFieldValue (vmime::fields::RETURN_PATH); registerFieldValue (vmime::fields::CONTENT_TYPE); registerFieldValue (vmime::fields::CONTENT_TRANSFER_ENCODING); registerFieldValue (vmime::fields::CONTENT_DESCRIPTION); registerFieldValue (vmime::fields::MIME_VERSION); registerFieldValue (vmime::fields::CONTENT_DISPOSITION); registerFieldValue (vmime::fields::CONTENT_ID); registerFieldValue (vmime::fields::MESSAGE_ID); registerFieldValue (vmime::fields::CONTENT_LOCATION); registerFieldValue (vmime::fields::IN_REPLY_TO); registerFieldValue (vmime::fields::REFERENCES); registerFieldValue (vmime::fields::ORIGINAL_MESSAGE_ID); registerFieldValue (vmime::fields::DISPOSITION); registerFieldValue (vmime::fields::DISPOSITION_NOTIFICATION_TO); } headerFieldFactory::~headerFieldFactory() { } shared_ptr headerFieldFactory::getInstance() { static headerFieldFactory instance; return shared_ptr (&instance, noop_shared_ptr_deleter ()); } shared_ptr headerFieldFactory::create( const string& name, const string& body ) { NameMap::const_iterator pos = m_nameMap.find(utility::stringUtils::toLower(name)); shared_ptr field; if (pos != m_nameMap.end()) { field = ((*pos).second)(); } else { field = registerer ::creator(); } field->setName(name); field->setValue(createValue(name)); if (body != NULL_STRING) { field->parse(body); } return field; } shared_ptr headerFieldFactory::createValue(const string& fieldName) { ValueMap::const_iterator pos = m_valueMap.find( utility::stringUtils::toLower(fieldName) ); shared_ptr value; if (pos != m_valueMap.end()) { value = ((*pos).second.allocFunc)(); } else { value = registerer ::creator(); } return value; } bool headerFieldFactory::isValueTypeValid( const headerField& field, const headerFieldValue& value ) const { ValueMap::const_iterator pos = m_valueMap.find (utility::stringUtils::toLower(field.getName())); if (pos != m_valueMap.end()) { return ((*pos).second.checkTypeFunc)(value); } return true; // No info on this field } } // vmime