Commit 2857b8fc authored by Mickaël Turnel's avatar Mickaël Turnel
Browse files

Improved CpimMessage checking when adding a header

parent 95e100ea
......@@ -58,14 +58,20 @@ Cpim::Message::HeaderList Cpim::Message::getMessageHeaders (const string &ns) co
return d->messageHeaders.at(ns);
}
void Cpim::Message::addMessageHeader (const Header &messageHeader, const string &ns) {
bool Cpim::Message::addMessageHeader (const Header &messageHeader, const string &ns) {
L_D();
auto header = Parser::getInstance()->cloneHeader(messageHeader);
if (header == nullptr)
return false;
if (d->messageHeaders.find(ns) == d->messageHeaders.end())
d->messageHeaders[ns] = make_shared<Cpim::MessagePrivate::PrivHeaderList>();
auto list = d->messageHeaders.at(ns);
list->push_back(Parser::getInstance()->cloneHeader(messageHeader));
list->push_back(header);
return true;
}
void Cpim::Message::removeMessageHeader (const Header &messageHeader, const string &ns) {
......@@ -99,9 +105,16 @@ Cpim::Message::HeaderList Cpim::Message::getContentHeaders () const {
return d->contentHeaders;
}
void Cpim::Message::addContentHeader (const Header &contentHeader) {
bool Cpim::Message::addContentHeader (const Header &contentHeader) {
L_D();
d->contentHeaders->push_back(Parser::getInstance()->cloneHeader(contentHeader));
auto header = Parser::getInstance()->cloneHeader(contentHeader);
if (header == nullptr)
return false;
d->contentHeaders->push_back(header);
return true;
}
void Cpim::Message::removeContentHeader (const Header &contentHeader) {
......
......@@ -37,12 +37,12 @@ namespace Cpim {
typedef std::shared_ptr<std::list<std::shared_ptr<const Cpim::Header>>> HeaderList;
HeaderList getMessageHeaders (const std::string &ns = "") const;
void addMessageHeader (const Header &messageHeader, const std::string &ns = "");
bool addMessageHeader (const Header &messageHeader, const std::string &ns = "");
void removeMessageHeader (const Header &messageHeader, const std::string &ns = "");
std::shared_ptr<const Cpim::Header> getMessageHeader (const std::string &name, const std::string &ns = "") const;
HeaderList getContentHeaders () const;
void addContentHeader (const Header &contentHeader);
bool addContentHeader (const Header &contentHeader);
void removeContentHeader (const Header &contentHeader);
std::shared_ptr<const Cpim::Header> getContentHeader (const std::string &name) const;
......
......@@ -175,22 +175,29 @@ static void build_message () {
Cpim::GenericHeader wackyMessageHeader("MyFeatures.WackyMessageOption", "Use-silly-font");
message.addMessageHeader(fromHeader);
message.addMessageHeader(toHeader);
message.addMessageHeader(dateTimeHeader);
message.addMessageHeader(subjectHeader);
message.addMessageHeader(subjectWithLanguageHeader);
message.addMessageHeader(nsHeader);
message.addMessageHeader(requireHeader);
message.addMessageHeader(vitalMessageHeader);
message.addMessageHeader(wackyMessageHeader);
if (!BC_ASSERT_TRUE(message.addMessageHeader(fromHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(toHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(dateTimeHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(subjectHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(subjectWithLanguageHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(nsHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(requireHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(vitalMessageHeader))) return;
if (!BC_ASSERT_TRUE(message.addMessageHeader(wackyMessageHeader))) return;
// Set Content headers.
Cpim::GenericHeader contentTypeHeader("Content-Type", "text/xml; charset=utf-8");
message.addContentHeader(contentTypeHeader);
if (!BC_ASSERT_TRUE(message.addContentHeader(contentTypeHeader))) return;
Cpim::GenericHeader contentIdHeader("Content-ID", "<1234567890@foo.com>");
message.addContentHeader(contentIdHeader);
if (!BC_ASSERT_TRUE(message.addContentHeader(contentIdHeader))) return;
// Add a wrong message header and a wrong content header
Cpim::FromHeader wrongFromHeader("", "");
if (!BC_ASSERT_FALSE(message.addMessageHeader(wrongFromHeader))) return;
Cpim::GenericHeader wrongContentHeader("", "");
if (!BC_ASSERT_FALSE(message.addContentHeader(wrongContentHeader))) return;
const string content = "<body>"
"Here is the text of my message."
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment