2 // Open Service Platform
3 // Copyright (c) 2012-2013 Samsung Electronics Co., Ltd.
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
9 // http://www.apache.org/licenses/LICENSE-2.0
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
18 * @file FMsg_MsgUtil.cpp
19 * @brief This is the implementation file for the %_MsgUtil class.
21 * This file contains the implementation of the %_MsgUtil class.
27 #include <FBaseUtilStringUtil.h>
29 #include <FMsgMmsMessage.h>
30 #include <FMsgSmsMessage.h>
31 #include <FMsgEmailMessage.h>
32 #include <FBaseSysLog.h>
33 #include <FBase_StringConverter.h>
34 #include "FMsg_SmsMessageImpl.h"
35 #include "FMsg_MsgUtil.h"
37 using namespace Tizen::Base;
38 using namespace Tizen::Base::Collection;
39 using namespace Tizen::Base::Utility;
40 using namespace Tizen::Io;
42 namespace Tizen { namespace Messaging
46 _MsgUtil::CheckAddressValidity(const Tizen::Base::String& address, _MessageType type)
57 addressLen = address.GetLength();
58 if (address[0] == L'+')
63 if (addressLen < MIN_LENGTH_PHONE || addressLen > MAX_LENGTH_PHONE)
65 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The Address length (%d) is too short or too long.", addressLen);
66 r = E_INVALID_ADDRESS;
70 for (int index = 0; index < addressLen; index++)
72 if (address[0] == L'+')
74 if (!Character::IsDigit(address[index + 1]))
76 r = E_INVALID_ADDRESS;
77 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The phone number contains a non-digit string.");
83 if (!Character::IsDigit(address[index]))
85 r = E_INVALID_ADDRESS;
86 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The phone number contains a non-digit string.");
97 addressLen = address.GetLength();
100 if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a"
102 r = E_INVALID_ADDRESS;
103 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen);
107 // check number of '@' char and '@' position
111 r = address.IndexOf(L'@', 0, pos);
112 r = address.LastIndexOf(L'@', addressLen - 1, posByLast);
114 if (pos <= 0 || pos != posByLast)
116 r = E_INVALID_ADDRESS;
117 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters.");
126 SysLogException(NID_MSG, r, "[E_INVALID_ARG] There is not a such type of address (%d).", type);
137 _MsgUtil::CheckEmailAddressValidity(const RecipientList& recipientList)
139 result r = E_SUCCESS;
140 RecipientList* pRecipientList = null;
141 IList* pToList = null;
142 IList* pCcList = null;
143 IList* pBccList = null;
146 String* pItem = null;
148 pRecipientList = const_cast< RecipientList* >(&recipientList);
151 count = 0; // initialize the count value
152 pToList = pRecipientList->GetListN(RECIPIENT_TYPE_TO);
158 SysLogException(NID_MSG, r, "[%s] Failed to get TO list.", GetErrorMessage(r));
163 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in TO list is not valid.");
166 "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_TO) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS.");
167 r = E_INVALID_ADDRESS;
173 count = pToList->GetCount();
178 for (index = 0; index < count; index++)
180 pItem = dynamic_cast< String* >(pToList->GetAt(index));
183 r = CheckAddressValidity(*pItem, _MSG_EMAIL);
187 r = E_INVALID_ADDRESS;
192 SysLogException(NID_MSG, r, "[%s] There is invalid email address in TO list. Please check the RecipientList first.",
201 count = 0; // initialize the count value
202 pCcList = pRecipientList->GetListN(RECIPIENT_TYPE_CC);
208 SysLogException(NID_MSG, r, "[%s] Failed to get CC list.", GetErrorMessage(r));
213 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in CC list is not valid.");
216 "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_CC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS.");
217 r = E_INVALID_ADDRESS;
223 count = pCcList->GetCount();
228 for (index = 0; index < count; index++)
230 pItem = dynamic_cast< String* >(pCcList->GetAt(index));
233 r = CheckAddressValidity(*pItem, _MSG_EMAIL);
237 r = E_INVALID_ADDRESS;
243 SysLogException(NID_MSG, r, "[%s] There is invalid email address in CC list. Please check the RecipientList first.",
252 count = 0; // initialize the count value
253 pBccList = pRecipientList->GetListN(RECIPIENT_TYPE_BCC);
259 SysLogException(NID_MSG, r, "[%s] Failed to get BCC list.", GetErrorMessage(r));
264 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in BCC list is not valid.");
267 "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_BCC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS.");
268 r = E_INVALID_ADDRESS;
274 count = pBccList->GetCount();
279 for (index = 0; index < count; index++)
281 pItem = dynamic_cast< String* >(pBccList->GetAt(index));
284 r = CheckAddressValidity(*pItem, _MSG_EMAIL);
288 r = E_INVALID_ADDRESS;
294 SysLogException(NID_MSG, r, "[%s] There is invalid email address in BCC list. Please check the RecipientList first.",
305 if (pToList->GetCount() > 0)
307 pToList->RemoveAll(true);
314 if (pCcList->GetCount() > 0)
316 pCcList->RemoveAll(true);
323 if (pBccList->GetCount() > 0)
325 pBccList->RemoveAll(true);
336 if (pToList->GetCount() > 0)
338 pToList->RemoveAll(true);
345 if (pCcList->GetCount() > 0)
347 pCcList->RemoveAll(true);
354 if (pBccList->GetCount() > 0)
356 pBccList->RemoveAll(true);
366 _MsgUtil::CheckPhoneNumberValidity(_MessageType type, const RecipientList& recipientList)
368 result r = E_SUCCESS;
369 RecipientList* pRecipientList = null;
370 IList* pToList = null;
371 IList* pCcList = null;
372 IList* pBccList = null;
375 String* pItem = null;
378 pRecipientList = const_cast< RecipientList* >(&recipientList);
381 count = 0; // initialize the count value
382 pToList = pRecipientList->GetListN(RECIPIENT_TYPE_TO);
388 SysLogException(NID_MSG, r, "[%s] Failed to get TO list.", GetErrorMessage(r));
393 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in TO list is not valid.");
396 "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_TO) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS.");
397 r = E_INVALID_ADDRESS;
403 count = pToList->GetCount();
408 for (index = 0; index < count; index++)
410 pItem = dynamic_cast< String* >(pToList->GetAt(index));
411 SysTryCatch(NID_MSG, pItem != null, r = E_INVALID_ADDRESS, r, "To List Null");
412 r = CheckAddressValidity(*pItem, type);
414 if (type == _MSG_MMS && r != E_SUCCESS) //Check If MMS might have email address
416 addressLen = pItem->GetLength();
419 if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a"
421 r = E_INVALID_ADDRESS;
422 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen);
426 // check number of '@' char and '@' position
430 r = pItem->IndexOf(L'@', 0, pos);
431 r = pItem->LastIndexOf(L'@', addressLen - 1, posByLast);
433 if (pos <= 0 || pos != posByLast)
435 r = E_INVALID_ADDRESS;
436 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters.");
443 SysLogException(NID_MSG, r, "[%s] There is invalid phone number in TO list. Please check the RecipientList first.",
452 count = 0; // initialize the count value
453 pCcList = pRecipientList->GetListN(RECIPIENT_TYPE_CC);
459 SysLogException(NID_MSG, r, "[%s] Failed to get CC list.", GetErrorMessage(r));
464 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in CC list is not valid.");
467 "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_CC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS.");
468 r = E_INVALID_ADDRESS;
474 count = pCcList->GetCount();
479 for (index = 0; index < count; index++)
481 pItem = dynamic_cast< String* >(pCcList->GetAt(index));
482 SysTryCatch(NID_MSG, pItem != null, r = E_INVALID_ADDRESS, r, "To List Null");
483 r = CheckAddressValidity(*pItem, type);
486 if (type == _MSG_MMS && r != E_SUCCESS) //Check If MMS might have email address
488 addressLen = pItem->GetLength();
491 if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a"
493 r = E_INVALID_ADDRESS;
494 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen);
498 // check number of '@' char and '@' position
502 r = pItem->IndexOf(L'@', 0, pos);
503 r = pItem->LastIndexOf(L'@', addressLen - 1, posByLast);
505 if (pos <= 0 || pos != posByLast)
507 r = E_INVALID_ADDRESS;
508 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters.");
515 SysLogException(NID_MSG, r, "[%s] There is invalid phone number in CC list. Please check the RecipientList first.",
524 count = 0; // initialize the count value
525 pBccList = pRecipientList->GetListN(RECIPIENT_TYPE_BCC);
531 SysLogException(NID_MSG, r, "[%s] Failed to get BCC list.", GetErrorMessage(r));
536 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] One of the address in BCC list is not valid.");
539 "Strange!! RecipientList::GetListN(RECIPIENT_TYPE_BCC) returns null. But the last result (by GetLastResult) is E_SUCCESS. So just return E_INVALID_ADDRESS.");
540 r = E_INVALID_ADDRESS;
546 count = pBccList->GetCount();
551 for (index = 0; index < count; index++)
553 pItem = dynamic_cast< String* >(pBccList->GetAt(index));
554 SysTryCatch(NID_MSG, pItem != null, r = E_INVALID_ADDRESS, r, "To List Null");
555 r = CheckAddressValidity(*pItem, type);
558 if (type == _MSG_MMS && r != E_SUCCESS) //Check If MMS might have email address
560 addressLen = pItem->GetLength();
563 if (addressLen < 5 || addressLen > MAX_LENGTH_EMAIL) // "a@a.a"
565 r = E_INVALID_ADDRESS;
566 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] The length (%d) of email address is too short or too long.", addressLen);
570 // check number of '@' char and '@' position
574 r = pItem->IndexOf(L'@', 0, pos);
575 r = pItem->LastIndexOf(L'@', addressLen - 1, posByLast);
577 if (pos <= 0 || pos != posByLast)
579 r = E_INVALID_ADDRESS;
580 SysLogException(NID_MSG, r, "[E_INVALID_ADDRESS] There is not a @ character or there are multiple @ characters.");
587 SysLogException(NID_MSG, r, "[%s] There is invalid phone number in BCC list. Please check the RecipientList first.",
598 if (pToList->GetCount() > 0)
600 pToList->RemoveAll(true);
607 if (pCcList->GetCount() > 0)
609 pCcList->RemoveAll(true);
616 if (pBccList->GetCount() > 0)
618 pBccList->RemoveAll(true);
629 if (pToList->GetCount() > 0)
631 pToList->RemoveAll(true);
638 if (pCcList->GetCount() > 0)
640 pCcList->RemoveAll(true);
647 if (pBccList->GetCount() > 0)
649 pBccList->RemoveAll(true);
659 _MsgUtil::IsValidImageFile(const String& filePath)
661 bool isValid = false;
663 String delimiter(L";");
664 String fileExtensionTable(L"jpg;jpeg;gif;png;bmp;wbmp;tif;tiff;swf;svg;svgz");
665 String fileExtension = Tizen::Io::File::GetFileExtension(filePath);
666 Tizen::Base::Utility::StringTokenizer strTok(fileExtensionTable, delimiter);
669 while (strTok.HasMoreTokens())
671 strTok.GetNextToken(token);
672 if (token.Equals(fileExtension, false))
683 _MsgUtil::IsValidAudioFile(const String& filePath)
685 bool isValid = false;
687 String delimiter(L";");
688 String fileExtensionTable(L"mid;midi;spm;imy;amr;mmf;xmf;mxmf;3gp;3gpp;mp4;asf;ra;ram;rv;rm;mp3;aac;wav;3ga;m4a;wma");
689 String fileExtension = Tizen::Io::File::GetFileExtension(filePath);
690 Tizen::Base::Utility::StringTokenizer strTok(fileExtensionTable, delimiter);
693 while (strTok.HasMoreTokens())
695 strTok.GetNextToken(token);
696 if (token.Equals(fileExtension, false))
707 _MsgUtil::IsValidVideoFile(const String& filePath)
710 bool isValid = false;
712 String delimiter(L";");
713 String fileExtensionTable(L"3gp;3gpp;mp4;asf;wmv;ra;ram;rv;rm");
714 String fileExtension = Tizen::Io::File::GetFileExtension(filePath);
715 Tizen::Base::Utility::StringTokenizer strTok(fileExtensionTable, delimiter);
718 while (strTok.HasMoreTokens())
720 strTok.GetNextToken(token);
721 if (token.Equals(fileExtension, false))
733 _MsgUtil::IsValidVcardFile(const String& filePath)
735 bool isValid = false;
736 String fileExtension = Tizen::Io::File::GetFileExtension(filePath);
738 if (fileExtension.Equals(L"vcf", false))
747 _MsgUtil::IsValidVcalendarFile(const String& filePath)
749 bool isValid = false;
750 String fileExtension = Tizen::Io::File::GetFileExtension(filePath);
752 if (fileExtension.Equals(L"vcs", false))
761 _MsgUtil::CheckMediaFormat(const MmsAttachmentFormat format, const String& filePath)
763 bool isValid = false;
767 isValid = IsValidImageFile(filePath);
771 isValid = IsValidAudioFile(filePath);
775 isValid = IsValidVideoFile(filePath);
779 isValid = IsValidVcardFile(filePath);
783 isValid = IsValidVcalendarFile(filePath);
793 _MsgUtil::IsValidPhoneNumber(const Tizen::Base::String& phoneNumber)
797 length = phoneNumber.GetLength();
798 if (phoneNumber[0] == L'+')
803 if (length < MIN_LENGTH_PHONE || length > MAX_LENGTH_PHONE)
805 SysLog(NID_MSG, "The length of the phone number (%d) is too short or too long.", length);
809 for (int index = 0; index < length; index++)
811 if (phoneNumber[0] == L'+')
813 if (!Character::IsDigit(phoneNumber[index + 1]))
815 SysLog(NID_MSG, "The phone number contains a non-digit string.");
821 if (!Character::IsDigit(phoneNumber[index]))
823 SysLog(NID_MSG, "The phone number contains a non-digit string.");
833 _MsgUtil::GetSmsMessageBoxType(messages_message_box_e folderId)
835 SmsMessageBoxType type = SMS_MESSAGE_BOX_TYPE_NONE;
838 case MESSAGES_MBOX_INBOX:
839 type = SMS_MESSAGE_BOX_TYPE_INBOX;
842 case MESSAGES_MBOX_OUTBOX:
843 type = SMS_MESSAGE_BOX_TYPE_OUTBOX;
846 case MESSAGES_MBOX_SENTBOX:
847 type = SMS_MESSAGE_BOX_TYPE_SENTBOX;
850 // case MESSAGES_MBOX_ALL:
851 // type = SMS_MESSAGE_BOX_TYPE_ALL;
855 type = SMS_MESSAGE_BOX_TYPE_NONE;
862 messages_message_box_e
863 _MsgUtil::GetMsgFolderId(const SmsMessageBoxType& type)
865 messages_message_box_e folderId;
869 case SMS_MESSAGE_BOX_TYPE_INBOX:
870 folderId = MESSAGES_MBOX_INBOX;
873 case SMS_MESSAGE_BOX_TYPE_OUTBOX:
874 folderId = MESSAGES_MBOX_OUTBOX;
877 case SMS_MESSAGE_BOX_TYPE_SENTBOX:
878 folderId = MESSAGES_MBOX_SENTBOX;
881 case SMS_MESSAGE_BOX_TYPE_ALL:
882 folderId = MESSAGES_MBOX_ALL;
886 folderId = (messages_message_box_e) -1;
894 _MsgUtil::GetMsgBoxType(const messages_message_box_e& folderId)
896 SmsMessageBoxType type;
900 case MESSAGES_MBOX_INBOX:
901 type = SMS_MESSAGE_BOX_TYPE_INBOX;
904 case MESSAGES_MBOX_OUTBOX:
905 type = SMS_MESSAGE_BOX_TYPE_OUTBOX;
908 case MESSAGES_MBOX_SENTBOX:
909 type = SMS_MESSAGE_BOX_TYPE_SENTBOX;
912 case MESSAGES_MBOX_ALL:
913 type = SMS_MESSAGE_BOX_TYPE_ALL;
917 type = SMS_MESSAGE_BOX_TYPE_NONE;
925 _MsgUtil::GetSmsMessage(const SmsMessage& message, const RecipientList& recipientList, messages_message_h& smsMsg)
927 int err = MESSAGES_ERROR_NONE;
928 const char* pMsgBody = null;
929 result r = E_SUCCESS;
932 err = messages_create_message(MESSAGES_TYPE_SMS, &smsMsg);
933 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to create message object");
935 if (message.GetText().GetLength() == 0)
937 Tizen::Base::String emptyText(L" ");
938 pMsgBody = _StringConverter::CopyToCharArrayN(emptyText);
942 pMsgBody = _StringConverter::CopyToCharArrayN(message.GetText());
945 SysTryCatch(NID_MSG, pMsgBody != null, r = E_OUT_OF_MEMORY, E_OUT_OF_MEMORY, "memory allocation failed.");
947 err = messages_set_text(smsMsg, pMsgBody);
948 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to set message text");
950 err = AddMessageAddress(recipientList, RECIPIENT_TYPE_TO, smsMsg, MESSAGES_RECIPIENT_TO);
951 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to set message To address");
973 _MsgUtil::GetEmailMessage(const EmailMessage& message, const RecipientList& recipientList, email_h& emailMsg)
975 int err = EMAIL_ERROR_NONE;
976 result r = E_SUCCESS;
978 const char* pSubject = null;
979 const char* pMsgBody = null;
980 Tizen::Base::Collection::IList* pAttachmentList = null;
982 pSubject = _StringConverter::CopyToCharArrayN(message.GetSubject());
983 pMsgBody = _StringConverter::CopyToCharArrayN(message.GetText());
985 err = email_set_subject(emailMsg, pSubject);
986 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add subject failed");
987 err = email_set_body(emailMsg, pMsgBody);
988 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add body failed");
990 err = AddEmailMessageAddress(recipientList, RECIPIENT_TYPE_TO, emailMsg, EMAIL_RECIPIENT_TYPE_TO);
991 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add recipient failed");
992 err = AddEmailMessageAddress(recipientList, RECIPIENT_TYPE_CC, emailMsg, EMAIL_RECIPIENT_TYPE_CC);
993 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add recipient failed");
994 err = AddEmailMessageAddress(recipientList, RECIPIENT_TYPE_BCC, emailMsg, EMAIL_RECIPIENT_TYPE_BCC);
995 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add recipient failed");
997 pAttachmentList = message.GetAttachmentListN();
1001 attachNum = pAttachmentList->GetCount();
1006 String* pAttachPath = null;
1007 char* pTempAttachPath = null;
1009 for (int index = 0; index < attachNum; index++)
1011 pAttachPath = dynamic_cast< String* >(pAttachmentList->GetAt(index));
1012 SysTryCatch(NID_MSG, pAttachPath != null, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add attachment failed");
1013 pTempAttachPath = _StringConverter::CopyToCharArrayN(*pAttachPath);
1014 err = email_add_attach(emailMsg, pTempAttachPath);
1015 if (pTempAttachPath)
1017 delete[] pTempAttachPath;
1018 pTempAttachPath = null;
1020 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "[E_SYSTEM] email add attachment failed");
1024 if (pAttachmentList)
1026 if (pAttachmentList->GetCount() > 0)
1028 pAttachmentList->RemoveAll(true);
1030 delete pAttachmentList;
1031 pAttachmentList = null;
1061 if (pAttachmentList)
1063 if (pAttachmentList->GetCount() > 0)
1065 pAttachmentList->RemoveAll(true);
1067 delete pAttachmentList;
1068 pAttachmentList = null;
1075 _MsgUtil::AddEmailMessageAddress(const RecipientList& recipientList, RecipientType type, email_h& emailMsg, email_recipient_type_e recipientType)
1077 String* pTempRecipient = null;
1078 IList* pRecipientList = null;
1079 char* pEmailAddr = null;
1081 int err = EMAIL_ERROR_NONE;
1082 result r = E_SUCCESS;
1084 pRecipientList = (const_cast< RecipientList& >(recipientList)).GetListN(type);
1085 if (!pRecipientList)
1087 r = GetLastResult();
1088 SysLogException(NID_MSG, r, "[%s] Failed to get recipient list", GetErrorMessage(r));
1092 count = pRecipientList->GetCount();
1093 for (int index = 0; index < count; index++)
1095 pTempRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index));
1096 if (!pTempRecipient)
1098 r = GetLastResult();
1099 err = EMAIL_ERROR_OPERATION_FAILED;
1100 SysLogException(NID_MSG, r, "[%s] Failed to get a recipient", GetErrorMessage(r));
1104 pEmailAddr = _StringConverter::CopyToCharArrayN(*pTempRecipient);
1105 err = email_add_recipient(emailMsg, recipientType, pEmailAddr);
1109 delete[] pEmailAddr;
1112 SysTryCatch(NID_MSG, err == EMAIL_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to set message address");
1117 if (pRecipientList->GetCount() > 0)
1119 pRecipientList->RemoveAll(true);
1121 delete pRecipientList;
1122 pRecipientList = null;
1130 if (pRecipientList->GetCount() > 0)
1132 pRecipientList->RemoveAll(true);
1134 delete pRecipientList;
1135 pRecipientList = null;
1142 _MsgUtil::AddMessageAddress(const RecipientList& recipientList, RecipientType type, messages_message_h& messageMsg, messages_recipient_type_e recipientType)
1144 String* pTempRecipient = null;
1145 IList* pRecipientList = null;
1146 char* pPhoneNum = null;
1148 int err = MESSAGES_ERROR_NONE;
1149 result r = E_SUCCESS;
1151 pRecipientList = (const_cast< RecipientList& >(recipientList)).GetListN(type);
1152 if (!pRecipientList)
1154 r = GetLastResult();
1155 SysLogException(NID_MSG, r, "[%s] Failed to get recipient list", GetErrorMessage(r));
1159 count = pRecipientList->GetCount();
1160 for (int index = 0; index < count; index++)
1162 pTempRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index));
1163 if (!pTempRecipient)
1165 r = GetLastResult();
1166 err = MESSAGES_ERROR_OPERATION_FAILED;
1167 SysLogException(NID_MSG, r, "[%s] Failed to get a recipient", GetErrorMessage(r));
1171 pPhoneNum = _StringConverter::CopyToCharArrayN(*pTempRecipient);
1172 err = messages_add_address(messageMsg, pPhoneNum, recipientType);
1179 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to set message address");
1184 if (pRecipientList->GetCount() > 0)
1186 pRecipientList->RemoveAll(true);
1188 delete pRecipientList;
1189 pRecipientList = null;
1197 if (pRecipientList->GetCount() > 0)
1199 pRecipientList->RemoveAll(true);
1201 delete pRecipientList;
1202 pRecipientList = null;
1209 _MsgUtil::GetConcatenatedRecipientListString(const RecipientList& recipientList, RecipientType type,
1210 const Tizen::Base::String& delim)
1212 String concatenatedString;
1213 String* pTempRecipient = null;
1214 IList* pRecipientList = null;
1216 result r = E_SUCCESS;
1220 pRecipientList = (const_cast< RecipientList& >(recipientList)).GetListN(type);
1221 if (!pRecipientList)
1223 r = GetLastResult();
1224 SysLogException(NID_MSG, r, "[%s] Failed to get recipient list", GetErrorMessage(r));
1228 concatenatedString.Clear();
1230 count = pRecipientList->GetCount();
1231 for (int index = 0; index < count; index++)
1233 pTempRecipient = dynamic_cast< String* >(pRecipientList->GetAt(index));
1234 if (!pTempRecipient)
1236 r = GetLastResult();
1237 SysLogException(NID_MSG, r, "[%s] Failed to get a recipient", GetErrorMessage(r));
1241 concatenatedString.Append(*pTempRecipient);
1242 if (index < count - 1)
1244 concatenatedString.Append(delim);
1249 if (pRecipientList->GetCount() > 0)
1251 pRecipientList->RemoveAll(true);
1253 delete pRecipientList;
1254 pRecipientList = null;
1256 return concatenatedString;
1263 if (pRecipientList->GetCount() > 0)
1265 pRecipientList->RemoveAll(true);
1267 delete pRecipientList;
1268 pRecipientList = null;
1271 return concatenatedString;
1275 _MsgUtil::GetMmsMessage(const MmsMessage& message, const RecipientList& recipientList, messages_message_h& mmsMsg)
1277 int err = MESSAGES_ERROR_NONE;
1278 result r = E_SUCCESS;
1279 const char* pSubject = null;
1280 const char* pMsgBody = null;
1281 const char* pFilePath = null;
1284 pSubject = _StringConverter::CopyToCharArrayN(message.GetSubject());
1285 pMsgBody = _StringConverter::CopyToCharArrayN(message.GetText());
1287 //create new message
1288 err = messages_create_message(MESSAGES_TYPE_MMS, &mmsMsg);
1289 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "Insufficient memory");
1291 err = messages_set_text(mmsMsg, pMsgBody);
1292 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to set mms text");
1294 err = messages_mms_set_subject(mmsMsg, pSubject);
1295 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to set mms body");
1297 err = AddMessageAddress(recipientList, RECIPIENT_TYPE_TO, mmsMsg, MESSAGES_RECIPIENT_TO);
1298 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to add To address");
1300 err = AddMessageAddress(recipientList, RECIPIENT_TYPE_CC, mmsMsg, MESSAGES_RECIPIENT_CC);
1301 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to add Cc address");
1303 err = AddMessageAddress(recipientList, RECIPIENT_TYPE_BCC, mmsMsg, MESSAGES_RECIPIENT_BCC);
1304 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "failed to add Bcc address");
1306 // populate attachments
1307 filePath = message.GetAttachment(MMS_IMAGE);
1308 if (filePath.GetLength())
1310 pFilePath = _StringConverter::CopyToCharArrayN(filePath);
1311 err = messages_mms_add_attachment(mmsMsg, MESSAGES_MEDIA_IMAGE, pFilePath);
1314 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "mms add attachment failed");
1318 filePath = message.GetAttachment(MMS_VIDEO);
1319 if (filePath.GetLength())
1321 pFilePath = _StringConverter::CopyToCharArrayN(filePath);
1322 err = messages_mms_add_attachment(mmsMsg, MESSAGES_MEDIA_VIDEO, pFilePath);
1325 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "mms add attachment failed");
1329 filePath = message.GetAttachment(MMS_AUDIO);
1330 if (filePath.GetLength())
1332 pFilePath = _StringConverter::CopyToCharArrayN(filePath);
1333 err = messages_mms_add_attachment(mmsMsg, MESSAGES_MEDIA_AUDIO, pFilePath);
1336 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "mms add attachment failed");
1340 filePath = message.GetAttachment(MMS_VCARD);
1341 if (filePath.GetLength())
1343 pFilePath = _StringConverter::CopyToCharArrayN(filePath);
1344 err = messages_mms_add_attachment(mmsMsg, MESSAGES_MEDIA_UNKNOWN, pFilePath); // Not Suppourted Yet
1347 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "mms add attachment failed");
1350 //calander attachment
1351 filePath = message.GetAttachment(MMS_VCALENDAR);
1352 if (filePath.GetLength())
1354 pFilePath = _StringConverter::CopyToCharArrayN(filePath);
1355 err = messages_mms_add_attachment(mmsMsg, MESSAGES_MEDIA_UNKNOWN, pFilePath); // Not Suppourted Yet
1358 SysTryCatch(NID_MSG, err == MESSAGES_ERROR_NONE, r = E_SYSTEM, E_SYSTEM, "mms add attachment failed");
1392 Tizen::Base::DateTime
1393 _MsgUtil::ConvertTime(time_t* pTime)
1396 struct tm* pTempTime = null;
1398 pTempTime = gmtime(pTime);
1401 dateTime.SetValue(pTempTime->tm_year + 1900, pTempTime->tm_mon + 1, pTempTime->tm_mday, pTempTime->tm_hour, pTempTime->tm_min, pTempTime->tm_sec);
1407 _MsgUtil::ConvertSmsMessageN(const SmsMessageBoxType& type, messages_message_h msg)
1409 result r = E_SUCCESS;
1410 SmsMessage* pSmsMessage = null;
1411 char* pOriginalText = null;
1412 char* pBodyText = null;
1413 char* pMsgAddress = null;
1415 time_t tempTime = 0;
1416 bool hasMoreText = false;
1419 messages_recipient_type_e recipientType = MESSAGES_RECIPIENT_TO;
1420 const int msgBodyLength = 160;
1421 int originalTextLength = 0;
1423 pSmsMessage = new (std::nothrow) SmsMessage();
1424 SysTryCatch(NID_MSG, pSmsMessage != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
1427 messages_get_message_id(msg, &messageId);
1429 messages_get_text(msg, &pOriginalText);
1430 SysTryCatch(NID_MSG, pOriginalText != null, r = E_SYSTEM, r, "sms get message body failed");
1432 originalTextLength = strlen(pOriginalText);
1433 if (originalTextLength > msgBodyLength)
1435 pBodyText = (char*) calloc(msgBodyLength + 1, sizeof(char)); // include NULL character
1436 SysTryCatch(NID_MSG, pBodyText != null, r = E_OUT_OF_MEMORY, r, "memory allocation failed");
1437 strncpy(pBodyText, pOriginalText, msgBodyLength);
1438 pBodyText[msgBodyLength] = '\0'; // add NULL character
1439 free(const_cast< char* >(pOriginalText));
1440 pOriginalText = null;
1446 pBodyText = const_cast< char* >(pOriginalText);
1447 pOriginalText = null;
1452 // received/sent time
1453 messages_get_time(msg, &tempTime);
1454 time = _MsgUtil::ConvertTime(&tempTime);
1458 case SMS_MESSAGE_BOX_TYPE_INBOX:
1461 messages_get_address(msg, 0, &pMsgAddress, &recipientType);
1462 SysTryCatch(NID_MSG, pMsgAddress != null, r = E_SYSTEM, r, "sms get message address failed");
1463 String senderAddress(pMsgAddress);
1466 _SmsMessageImpl::GetInstance(*pSmsMessage)->SetInboxMessage(messageId, body, hasMoreText, senderAddress, time);
1470 case SMS_MESSAGE_BOX_TYPE_SENTBOX:
1473 int recipient_count = 0;
1474 messages_get_address_count(msg, &recipient_count);
1475 RecipientList recipients;
1477 for (int index = 0; index < recipient_count; index++)
1479 messages_get_address(msg, index, &pMsgAddress, &recipientType);
1480 SysTryCatch(NID_MSG, pMsgAddress != null, r = E_SYSTEM, r, "sms get message address failed");
1481 String senderAddress(pMsgAddress);
1484 r = recipients.Add(RECIPIENT_TYPE_TO, senderAddress);
1486 _SmsMessageImpl::GetInstance(*pSmsMessage)->SetSentboxMessage(messageId, body, hasMoreText, recipients, time);
1490 case SMS_MESSAGE_BOX_TYPE_OUTBOX:
1493 int recipient_count = 0;
1494 messages_get_address_count(msg, &recipient_count);
1495 RecipientList recipients;
1497 for (int index = 0; index < recipient_count; index++)
1499 messages_get_address(msg, index, &pMsgAddress, &recipientType);
1500 SysTryCatch(NID_MSG, pMsgAddress != null, r = E_SYSTEM, r, "sms get message address failed");
1501 String senderAddress(pMsgAddress);
1504 r = recipients.Add(RECIPIENT_TYPE_TO, senderAddress);
1506 _SmsMessageImpl::GetInstance(*pSmsMessage)->SetOutboxMessage(messageId, body, hasMoreText, recipients, time);
1538 } } // Tizen::Messaging