vector<IMessagePtr> retVal;
std::string tempString = "";
// MSG_LIST_S message_list = {0, NULL};
- msg_struct_list_s message_list = {0, NULL};
+ msg_struct_list_s message_list = {0,};
Try{
msg_error_t res = MSG_ERR_UNKNOWN;
vector<IMessagePtr> retVal;
// MSG_LIST_S message_list = {0, NULL};
- msg_struct_list_s message_list = {0, NULL};
+ msg_struct_list_s message_list = {0,};
Try{
msg_error_t res = MSG_ERR_UNKNOWN;
void Messaging::OnEventReceived(const DBus::MessageEvent& event)
{
- LogDebug("ENTER");
- EventMessageReceivedPtr jsEvent(new EventMessageReceived());
- DBus::MessagePtr message = event.GetArg0();
+ LogDebug("ENTER");
+ EventMessageReceivedPtr jsEvent(new EventMessageReceived());
+ DBus::MessagePtr message = event.GetArg0();
- if (!message)
- {
- jsEvent->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformException);
- m_onMessageReceived.emit(jsEvent);
- }
- else
- {
- if (message->getInterface() == DBUS_INTERFACE_EMAIL_RECEIVED)
- {
- int account_id = 0, mail_id = 0, thread_id = 0, status = 0;
- std::string name;
- email_mailbox_t m_mailboxes;
- email_mailbox_t* mailboxes = NULL;
-
- DBus::Message::ReadIterator it = message->getReadIterator();
- for (int i = 0; it->isValid(); it->next(), ++i)
- {
- if ((i == 0) && (it->getArgType() == DBUS_TYPE_INT32))
- {
- status = it->getInt();
- LogInfo("status: " << status);
- }
- else if ((i == 1) && (it->getArgType() == DBUS_TYPE_INT32))
- {
- account_id = it->getInt();
- LogInfo("account_id: " << account_id);
- }
- else if ((i == 2) && (it->getArgType() == DBUS_TYPE_INT32))
- {
- mail_id = it->getInt();
- LogInfo("mail_id: " << mail_id);
- }
- else if ((i == 3) && (it->getArgType() == DBUS_TYPE_STRING))
- {
- name = it->getString();
- LogInfo("name: " << name);
- }
- else if ((i == 4) && (it->getArgType() == DBUS_TYPE_INT32))
- {
- thread_id = it->getInt();
- LogInfo("thread_id: " << thread_id);
- }
- }
-
- if ((mail_id > 0) && (NOTI_MAIL_ADD == status))
- { // TODO also RECEIVE_THREAD_ITEM?
- LogInfo("Email received. mail_id: " << mail_id);
+ if (!message)
+ {
+ jsEvent->setExceptionCode(WrtDeviceApis::Commons::ExceptionCodes::PlatformException);
+ m_onMessageReceived.emit(jsEvent);
+ }
+ else
+ {
+ if (message->getInterface() == DBUS_INTERFACE_EMAIL_RECEIVED)
+ {
+ int account_id = 0, mail_id = 0, thread_id = 0, status = 0;
+ std::string name;
+ email_mailbox_t m_mailboxes;
+ email_mailbox_t* mailboxes = NULL;
- IMessagePtr msg = MessageFactory::createMessage(EMAIL, mail_id);
- IConversationPtr conversation(new Conversation(thread_id, EMAIL));
-
- // TODO Temporary fix: ignore messages from OUTBOX, SENTBOX & DRAFTBOX -> most probably we added them
- Api::Messaging::FolderType folder = msg->getCurrentFolder();
- jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
-
- if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
- {
- IEmailPtr email = MessageFactory::convertToEmail(msg);
- jsEvent->setMessage(msg);
- jsEvent->setConversation(conversation);
+ DBus::Message::ReadIterator it = message->getReadIterator();
+ for (int i = 0; it->isValid(); it->next(), ++i)
+ {
+ if ((i == 0) && (it->getArgType() == DBUS_TYPE_INT32))
+ {
+ status = it->getInt();
+ LogInfo("status: " << status);
+ }
+ else if ((i == 1) && (it->getArgType() == DBUS_TYPE_INT32))
+ {
+ account_id = it->getInt();
+ LogInfo("account_id: " << account_id);
+ }
+ else if ((i == 2) && (it->getArgType() == DBUS_TYPE_INT32))
+ {
+ mail_id = it->getInt();
+ LogInfo("mail_id: " << mail_id);
+ }
+ else if ((i == 3) && (it->getArgType() == DBUS_TYPE_STRING))
+ {
+ name = it->getString();
+ LogInfo("name: " << name);
+ }
+ else if ((i == 4) && (it->getArgType() == DBUS_TYPE_INT32))
+ {
+ thread_id = it->getInt();
+ LogInfo("thread_id: " << thread_id);
+ }
+ }
- if(m_onMessageReceived.size() > 0){
- m_onMessageReceived.emit(jsEvent);
- }
+ if ((mail_id > 0) && (NOTI_MAIL_ADD == status))
+ { // TODO also RECEIVE_THREAD_ITEM?
+ LogInfo("Email received. mail_id: " << mail_id);
- if(m_onConversationReceived.size() > 0){
- m_onConversationReceived.emit(jsEvent);
- }
+ IMessagePtr msg = MessageFactory::createMessage(EMAIL, mail_id);
+ IConversationPtr conversation(new Conversation(thread_id, EMAIL));
- } else {
- LogWarning("New email message in ignored folder: " << folder);
- }
- }
- else if ((mail_id > 0) && (NOTI_MAIL_DELETE == status))
- { // TODO also RECEIVE_THREAD_ITEM?
- LogInfo("Email received. delete type: " << mail_id);
+ // TODO Temporary fix: ignore messages from OUTBOX, SENTBOX & DRAFTBOX -> most probably we added them
+ Api::Messaging::FolderType folder = msg->getCurrentFolder();
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
- std::vector<std::string> strIds = String::split(name, ',');
+ if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
+ {
+ jsEvent->setMessage(msg);
+ jsEvent->setConversation(conversation);
- std::stringstream stream;
- for (std::vector<std::string>::iterator it = strIds.begin(); it != strIds.end(); ++it)
- {
- LogDebug("ID is :" << *it);
+ if(m_onMessageReceived.size() > 0){
+ m_onMessageReceived.emit(jsEvent);
+ }
- if ( (*it).length() > 0 ) //vaild id
- {
- stream<< *it;
- int id;
- stream >> id;
-
- IMessagePtr msg = MessageFactory::createMessage(EMAIL, id);
- IConversationPtr conversation(new Conversation(thread_id, EMAIL));
-
- Api::Messaging::FolderType folder = msg->getCurrentFolder();
- jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
-
- if (true) { // if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
- IEmailPtr email = MessageFactory::convertToEmail(msg);
- jsEvent->setMessage(msg);
- jsEvent->setConversation(conversation);
- if(m_onMessageReceived.size() > 0){
- m_onMessageReceived.emit(jsEvent);
- }
- if(m_onConversationReceived.size() > 0){
- m_onConversationReceived.emit(jsEvent);
- }
- }
- else {
- LogWarning("New email message in ignored folder: " << folder);
- }
- }
-
- stream.clear();
- } //for
-
- }
- else if ((mail_id > 0) && (NOTI_MAIL_UPDATE == status))
- { // TODO also RECEIVE_THREAD_ITEM?
- LogInfo("Email received. mail_id: " << mail_id);
+ if(m_onConversationReceived.size() > 0){
+ m_onConversationReceived.emit(jsEvent);
+ }
- IMessagePtr msg = MessageFactory::createMessage(EMAIL, mail_id);
- IConversationPtr conversation(new Conversation(thread_id, EMAIL));
+ } else {
+ LogWarning("New email message in ignored folder: " << folder);
+ }
+ }
+ else if ((mail_id > 0) && (NOTI_MAIL_DELETE == status))
+ { // TODO also RECEIVE_THREAD_ITEM?
+ LogInfo("Email received. delete type: " << mail_id);
- Api::Messaging::FolderType folder = msg->getCurrentFolder();
- jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
-
- if (true) { // if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
- IEmailPtr email = MessageFactory::convertToEmail(msg);
- jsEvent->setMessage(msg);
- jsEvent->setConversation(conversation);
- if(m_onMessageReceived.size() > 0)
- m_onMessageReceived.emit(jsEvent);
- if(m_onConversationReceived.size() > 0)
- m_onConversationReceived.emit(jsEvent);
- } else {
- LogWarning("New email message in ignored folder: " << folder);
- }
- }
- else if (NOTI_MAILBOX_ADD == status)
- {
- LogInfo("Emailbox received. account Id: " << account_id);
- LogInfo("name Id: " << name);
+ std::vector<std::string> strIds = String::split(name, ',');
- email_mail_data_t* mail_data = NULL;
- email_mailbox_t* mail_box = NULL;
-
- if (EMAIL_ERROR_NONE != email_get_mail_data(mail_id, &mail_data)) {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
- if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &mail_box)) {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
-
-// email_get_mailbox_by_name(account_id, name.c_str(), &mail_box);
+ std::stringstream stream;
+ for (std::vector<std::string>::iterator it = strIds.begin(); it != strIds.end(); ++it)
+ {
+ LogDebug("ID is :" << *it);
- m_mailboxes = *mail_box;
+ if ( (*it).length() > 0 ) //vaild id
+ {
+ stream<< *it;
+ int id;
+ stream >> id;
+
+ IMessagePtr msg = MessageFactory::createMessage(EMPTY_MESSAGE, id);
+ IConversationPtr conversation(new Conversation());
+
+ Api::Messaging::FolderType folder = msg->getCurrentFolder();
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+
+ if (true) { // if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
+ jsEvent->setMessage(msg);
+ jsEvent->setConversation(conversation);
+ if(m_onMessageReceived.size() > 0){
+ m_onMessageReceived.emit(jsEvent);
+ }
+ }
+ else {
+ LogWarning("New email message in ignored folder: " << folder);
+ }
+ }
- Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
- jsEvent->setMessageFolder(folderPtr);
- jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
- if(m_onFolderReceived.size() > 0)
- {
- m_onFolderReceived.emit(jsEvent);
- }
+ stream.clear();
+ } //for
- }
- else if (NOTI_MAILBOX_UPDATE == status)
- {
- LogInfo("Emailbox received. account Id: " << account_id);
- LogInfo("name Id: " << name);
+ }
+ else if ((mail_id > 0) && (NOTI_MAIL_UPDATE == status))
+ { // TODO also RECEIVE_THREAD_ITEM?
+ LogInfo("Email received. mail_id: " << mail_id);
+
+ IMessagePtr msg = MessageFactory::createMessage(EMAIL, mail_id);
+ IConversationPtr conversation(new Conversation(thread_id, EMAIL));
+
+ Api::Messaging::FolderType folder = msg->getCurrentFolder();
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
+
+ if (true) { // if (OUTBOX != folder && SENTBOX != folder && DRAFTBOX != folder)
+ jsEvent->setMessage(msg);
+ jsEvent->setConversation(conversation);
+ if(m_onMessageReceived.size() > 0)
+ m_onMessageReceived.emit(jsEvent);
+ if(m_onConversationReceived.size() > 0)
+ m_onConversationReceived.emit(jsEvent);
+ } else {
+ LogWarning("New email message in ignored folder: " << folder);
+ }
+ }
+ else if ((mail_id > 0) && (NOTI_THREAD_DELETE == status))
+ { // TODO also RECEIVE_THREAD_ITEM?
+ LogInfo("Email received. delete thread Id : " << mail_id);
- email_mail_data_t* mail_data = NULL;
- email_mailbox_t* mail_box = NULL;
-
- if (EMAIL_ERROR_NONE != email_get_mail_data(mail_id, &mail_data)) {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
- if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &mail_box)) {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
-
-// email_get_mailbox_by_name(account_id, name.c_str(), &mailboxes);
+ IConversationPtr conversation(new Conversation());
+ conversation->setId((unsigned int)mail_id);
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+ jsEvent->setConversation(conversation);
- m_mailboxes = *mail_box;
+ if(m_onConversationReceived.size() > 0){
+ m_onConversationReceived.emit(jsEvent);
+ }
+ }
+ else if (NOTI_MAILBOX_ADD == status)
+ {
+ LogInfo("Emailbox received. account Id: " << account_id);
+ LogInfo("name Id: " << name);
- Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
- jsEvent->setMessageFolder(folderPtr);
- jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
-
- if(m_onFolderReceived.size() > 0)
- {
- m_onFolderReceived.emit(jsEvent);
- }
- }
- else if (NOTI_MAILBOX_DELETE == status)
- {
- LogInfo("Emailbox received. account Id: " << account_id);
- LogInfo("name Id: " << name);
+ email_mail_data_t* mail_data = NULL;
+ email_mailbox_t* mail_box = NULL;
- email_mail_data_t* mail_data = NULL;
- email_mailbox_t* mail_box = NULL;
+ if (EMAIL_ERROR_NONE != email_get_mail_data(mail_id, &mail_data)) {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
+ if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &mail_box)) {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
- if (EMAIL_ERROR_NONE != email_get_mail_data(mail_id, &mail_data)) {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
- if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &mail_box)) {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
-
-// email_get_mailbox_by_name(account_id, name.c_str(), &mail_box);
+ // email_get_mailbox_by_name(account_id, name.c_str(), &mail_box);
- m_mailboxes = *mail_box;
+ m_mailboxes = *mail_box;
- Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
- jsEvent->setMessageFolder(folderPtr);
- jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
-
- if(m_onFolderReceived.size() > 0)
- {
- m_onFolderReceived.emit(jsEvent);
- }
- }
- else
- {
- LogError("Couldn't retrieve message or it has been malformed.");
- }
- }
- else // DBUS_INTERFACE_EMAIL_RECEIVED
- {
- LogDebug("Wrong DBus interface, skipping it.");
- }
- }
+ Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+ jsEvent->setMessageFolder(folderPtr);
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_ADDED);
+ if(m_onFolderReceived.size() > 0)
+ {
+ m_onFolderReceived.emit(jsEvent);
+ }
+
+ }
+ else if (NOTI_MAILBOX_UPDATE == status)
+ {
+ LogInfo("Emailbox received. account Id: " << account_id);
+ LogInfo("name Id: " << name);
+
+ email_mail_data_t* mail_data = NULL;
+ email_mailbox_t* mail_box = NULL;
+
+ if (EMAIL_ERROR_NONE != email_get_mail_data(mail_id, &mail_data)) {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
+ if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &mail_box)) {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
+
+ // email_get_mailbox_by_name(account_id, name.c_str(), &mailboxes);
+
+ m_mailboxes = *mail_box;
+
+ Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+ jsEvent->setMessageFolder(folderPtr);
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_UPDATED);
+
+ if(m_onFolderReceived.size() > 0)
+ {
+ m_onFolderReceived.emit(jsEvent);
+ }
+ }
+ else if (NOTI_MAILBOX_DELETE == status)
+ {
+ LogInfo("Emailbox received. account Id: " << account_id);
+ LogInfo("name Id: " << name);
+
+ email_mail_data_t* mail_data = NULL;
+ email_mailbox_t* mail_box = NULL;
+
+ if (EMAIL_ERROR_NONE != email_get_mail_data(mail_id, &mail_data)) {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
+ if (EMAIL_ERROR_NONE != email_get_mailbox_by_mailbox_id(mail_data->mailbox_id, &mail_box)) {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
+
+ // email_get_mailbox_by_name(account_id, name.c_str(), &mail_box);
+
+ m_mailboxes = *mail_box;
+
+ Api::Messaging::IMessageFolderPtr folderPtr(new MessageFolder(m_mailboxes));
+ jsEvent->setMessageFolder(folderPtr);
+ jsEvent->setMsg_Event_Type(EventMessageReceived::MSG_DELETED);
+
+ if(m_onFolderReceived.size() > 0)
+ {
+ m_onFolderReceived.emit(jsEvent);
+ }
+ }
+ else
+ {
+ LogError("Couldn't retrieve message or it has been malformed.");
+ }
+ }
+ else // DBUS_INTERFACE_EMAIL_RECEIVED
+ {
+ LogDebug("Wrong DBus interface, skipping it.");
+ }
+ }
}
void Messaging::onMessageStorageChanged(msg_handle_t handle,