}
}
-MessageFolderType stringToMessageFolderType(const std::string& type) {
- ScopeLogger();
- if (FOLDER_TYPE_INBOX == type) {
- return MessageFolderType::MESSAGE_FOLDER_TYPE_INBOX;
- }
- if (FOLDER_TYPE_OUTBOX == type) {
- return MessageFolderType::MESSAGE_FOLDER_TYPE_OUTBOX;
- }
- if (FOLDER_TYPE_DRAFTS == type) {
- return MessageFolderType::MESSAGE_FOLDER_TYPE_DRAFTS;
- }
- if (FOLDER_TYPE_SENTBOX == type) {
- return MessageFolderType::MESSAGE_FOLDER_TYPE_SENTBOX;
- }
- return MessageFolderType::MESSAGE_FOLDER_TYPE_NOTSTANDARD;
-}
-
MessageFolder::MessageFolder(const std::string& id, const std::string& parent_id,
const std::string& service_id, const std::string& content_type,
const std::string& name, const std::string& path,
MessageFolderType type, bool synchronizable) {
ScopeLogger();
- attributes["id"] = picojson::value(id);
- attributes["parentId"] = picojson::value(parent_id);
- attributes["serviceId"] = picojson::value(service_id);
- attributes["contentType"] = picojson::value(content_type);
- attributes["name"] = picojson::value(name);
- attributes["path"] = picojson::value(path);
- attributes["type"] = picojson::value(static_cast<double>(type));
- attributes["synchronizable"] = picojson::value(synchronizable);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_ID] = picojson::value(id);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID] = picojson::value(parent_id);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID] = picojson::value(service_id);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE] = picojson::value(content_type);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_NAME] = picojson::value(name);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_PATH] = picojson::value(path);
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_TYPE] = picojson::value(static_cast<double>(type));
+ attributes[MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE] = picojson::value(synchronizable);
}
MessageFolder::MessageFolder(email_mailbox_t mailbox)
}
std::string MessageFolder::getId() const {
- return attributes.at("id").get<std::string>();
-}
-
-std::string MessageFolder::getParentId() const {
- return attributes.at("parentId").get<std::string>();
-}
-
-bool MessageFolder::isParentIdSet() const {
- return attributes.at("parentId").is<std::string>() &&
- not attributes.at("parentId").get<std::string>().empty();
-}
-
-void MessageFolder::setParentId(const std::string& parentId) {
- attributes["parentId"] = picojson::value(parentId);
-}
-
-std::string MessageFolder::getServiceId() const {
- return attributes.at("serviceId").get<std::string>();
-}
-
-std::string MessageFolder::getContentType() const {
- return attributes.at("contentType").get<std::string>();
-}
-
-std::string MessageFolder::getName() const {
- return attributes.at("name").get<std::string>();
-}
-
-void MessageFolder::setName(const std::string& value) {
- attributes["name"] = picojson::value(value);
-}
-
-std::string MessageFolder::getPath() const {
- return attributes.at("path").get<std::string>();
+ return attributes.at(MESSAGE_FOLDER_ATTRIBUTE_ID).get<std::string>();
}
MessageFolderType MessageFolder::getType() const {
- return static_cast<MessageFolderType>(static_cast<int>(attributes.at("type").get<double>()));
-}
-
-bool MessageFolder::getSynchronizable() const {
- return attributes.at("synchronizable").get<bool>();
-}
-
-void MessageFolder::setSynchronizable(const bool& value) {
- attributes.at("synchronizable") = picojson::value(value);
+ return static_cast<MessageFolderType>(
+ static_cast<int>(attributes.at(MESSAGE_FOLDER_ATTRIBUTE_TYPE).get<double>()));
}
picojson::value MessageFolder::toJSON() const {
picojson::value json(attributes);
- json.get<picojson::object>()["type"] = picojson::value(messageFolderTypeToString(getType()));
+ json.get<picojson::object>()[MESSAGE_FOLDER_ATTRIBUTE_TYPE] =
+ picojson::value(messageFolderTypeToString(getType()));
return json;
}
LoggerD("attribute_name: (%s), match_flag: (%s), match_value: (%s)", attribute_name.c_str(),
common::AttributeMatchFlagToString(match_flag).c_str(), match_value->toString().c_str());
+ const auto attr = attributes.find(attribute_name);
+ if (attr == attributes.end()) {
+ LoggerD("attribute: %s is NOT SUPPORTED", attribute_name.c_str());
+ return false;
+ }
+
if (common::AttributeMatchFlag::kExists == match_flag) {
- return attributes.find(attribute_name) != attributes.end();
+ return true;
}
- if (MESSAGE_FOLDER_ATTRIBUTE_ID == attribute_name) {
- return FilterUtils::isMatching(*match_value, getId(), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_PARENT_ID == attribute_name) {
- return FilterUtils::isMatching(*match_value, getParentId(), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_SERVICE_ID == attribute_name) {
- return FilterUtils::isMatching(*match_value, getServiceId(), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_CONTENT_TYPE == attribute_name) {
- return FilterUtils::isMatching(*match_value, getContentType(), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_NAME == attribute_name) {
- return FilterUtils::isMatching(*match_value, getName(), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_PATH == attribute_name) {
- return FilterUtils::isMatching(*match_value, getPath(), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_TYPE == attribute_name) {
+ if (MESSAGE_FOLDER_ATTRIBUTE_TYPE == attribute_name) {
return FilterUtils::isMatching(*match_value, messageFolderTypeToString(getType()), match_flag);
- } else if (MESSAGE_FOLDER_ATTRIBUTE_SYNCHRONIZABLE == attribute_name) {
- return FilterUtils::isMatching(*match_value, getSynchronizable(), match_flag);
}
- LoggerD("attribute: %s is NOT SUPPORTED", attribute_name.c_str());
- return false;
+ return FilterUtils::isMatching(*match_value, attr->second, match_flag);
}
bool MessageFolder::isMatchingAttributeRange(const std::string& attribute_name,
for (const auto& fp : source_folders) {
if (filter->isMatching(fp.get())) {
LoggerD("folder id:%s, folder name: %s, match: %s", fp->getId().c_str(),
- fp->getName().c_str(), "true");
+ fp->attributes.at(MESSAGE_FOLDER_ATTRIBUTE_NAME).get<std::string>().c_str(), "true");
filtered_folders.push_back(fp);
} else {
LoggerD("folder id:%s, folder name: %s, match: %s", fp->getId().c_str(),
- fp->getName().c_str(), "false");
+ fp->attributes.at(MESSAGE_FOLDER_ATTRIBUTE_NAME).get<std::string>().c_str(), "false");
}
}