#include "common/platform_result.h"
#include "common/scope_exit.h"
#include "message_folder.h"
+#include "messaging_util.h"
#include <email-api-mailbox.h>
+#include <string>
#include <vector>
using extension::messaging::MessageFolder;
+using extension::messaging::MessagingUtil;
+using extension::messaging::MESSAGE_FOLDER_TYPE_INBOX;
+using extension::messaging::MESSAGE_FOLDER_TYPE_SENTBOX;
+using extension::messaging::MESSAGE_FOLDER_TYPE_DRAFTS;
+using extension::messaging::MESSAGE_FOLDER_TYPE_OUTBOX;
+using extension::messaging::EMAIL;
+using extension::messaging::MessageFolderTypeStr;
using common::PlatformResult;
using common::ErrorCode;
+namespace {
+
+std::string convertPlatformFolderType(email_mailbox_type_e folderType) {
+ ScopeLogger();
+ switch (folderType) {
+ case EMAIL_MAILBOX_TYPE_INBOX:
+ return MessageFolderTypeStr[MESSAGE_FOLDER_TYPE_INBOX];
+ case EMAIL_MAILBOX_TYPE_SENTBOX:
+ return MessageFolderTypeStr[MESSAGE_FOLDER_TYPE_SENTBOX];
+ case EMAIL_MAILBOX_TYPE_DRAFT:
+ return MessageFolderTypeStr[MESSAGE_FOLDER_TYPE_DRAFTS];
+ case EMAIL_MAILBOX_TYPE_OUTBOX:
+ return MessageFolderTypeStr[MESSAGE_FOLDER_TYPE_OUTBOX];
+ default:
+ return "";
+ }
+}
+
+MessageFolder createMessageFolderFromMailbox(email_mailbox_t mailbox) {
+ ScopeLogger();
+ return MessageFolder(std::to_string(mailbox.mailbox_id), "", std::to_string(mailbox.account_id),
+ MessagingUtil::messageTypeToString(EMAIL), mailbox.alias,
+ mailbox.mailbox_name, convertPlatformFolderType(mailbox.mailbox_type),
+ mailbox.local == 0);
+}
+
+} // namespace
+
namespace native {
PlatformResult EmailGetMailboxList(int account_id, email_mailbox_t** mailboxes, int* count) {
}
for (int i = 0; i < count; ++i) {
- folders.push_back(MessageFolder(mailboxes[i]));
+ folders.push_back(createMessageFolderFromMailbox(mailboxes[i]));
+ }
+
+ return PlatformResult();
+}
+
+PlatformResult EmailGetMailboxById(int mailbox_id, MessageFolder& folder) {
+ email_mailbox_t* mailbox = nullptr;
+ int ret = email_get_mailbox_by_mailbox_id(mailbox_id, &mailbox);
+ if (EMAIL_ERROR_NONE != ret) {
+ LoggerE("Failed to load mailbox with id: %d. Error: %s (%d)", mailbox_id,
+ get_error_message(ret), ret);
+ return PlatformResult(ErrorCode::UNKNOWN_ERR, "email_get_mailbox_by_mailbox_id() failed.");
+ }
+
+ folder = createMessageFolderFromMailbox(*mailbox);
+ if (EMAIL_ERROR_NONE != email_free_mailbox(&mailbox, 1)) {
+ LoggerW("Calling email_free_mailbox() failed.");
}
return PlatformResult();