2 * Copyright 2012-2013 Samsung Electronics Co., Ltd
4 * Licensed under the Flora License, Version 1.1 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
8 * http://floralicense.org/license/
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
24 #include "MsgCppTypes.h"
25 #include "MsgStorageTypes.h"
26 #include "MsgSettingTypes.h"
27 #include "MsgUtilFile.h"
28 #include "MsgGconfWrapper.h"
29 #include "MsgMmsMessage.h"
30 #include "MmsPluginTypes.h"
31 #include "MmsPluginDebug.h"
32 #include "MmsPluginMessage.h"
33 #include "MmsPluginMIME.h"
34 #include "MmsPluginAvCodec.h"
35 #include "MmsPluginStorage.h"
36 #include "MmsPluginSMILValidate.h"
37 #include "MmsPluginSmil.h"
38 #include "MmsPluginUtil.h"
40 #define PRINT_KEY_VAL_STR(key, val)\
42 MSG_DEBUG("%-20s: %s", key, val);\
45 #define PRINT_KEY_VAL_INT(key, val)\
47 MSG_DEBUG("%-20s: %d", key, val);\
50 static MsgMultipart *MmsGetNthMultipart(MmsMsg *pMsg, int index);
51 static bool MmsSetMsgAddressList(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S *pMsgInfo);
52 static char *MmsComposeAddress(const MSG_MESSAGE_INFO_S *pMsgInfo, int recipientType);
53 static bool MmsGetSmilRawData(MMS_MESSAGE_DATA_S *pMsgBody, char *pRawData, int *nSize);
54 static bool MmsInsertPresentation(MmsMsg *pMsg, MimeType mimeType, const char *content_id, char *pData, int size);
55 static bool MmsInsertPartFromFile(MmsMsg *pMsg, char *szTitleName, char *szOrgFilePath, char *szContentID);
56 static bool MmsInsertPartFromMultipart(MmsMsg *pMsg, MMS_MULTIPART_DATA_S *pNewMultipart);
57 static bool MmsGetTypeByFileName(int *type, char *szFileName);
58 static bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart);
60 bool MmsSetMsgAddressList(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S * pMsgInfo)
62 MSG_DEBUG("MmsSetMsgAddressList");
63 pAttrib->szTo = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_TO);
64 MSG_DEBUG("To address: %s", pAttrib->szTo);
65 pAttrib->szCc = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_CC);
66 MSG_DEBUG("Cc address: %s", pAttrib->szCc);
67 pAttrib->szBcc = MmsComposeAddress(pMsgInfo, MSG_RECIPIENTS_TYPE_BCC);
68 MSG_DEBUG("Bcc address: %s", pAttrib->szBcc);
73 void MmsSetMsgMultiStatus(MmsAttrib *pAttrib, const MSG_MESSAGE_INFO_S *pMsgInfo)
77 nAddressCnt = pMsgInfo->nAddressCnt;
79 for (int i = 0; i < nAddressCnt; ++i) {
80 pAttrib->pMultiStatus = (MmsMsgMultiStatus *)malloc(sizeof(MmsMsgMultiStatus));
82 memset(pAttrib->pMultiStatus->szTo, 0, MAX_ADDRESS_VAL_LEN + 1);
83 strncpy(pAttrib->pMultiStatus->szTo, pMsgInfo->addressList[i].addressVal, MAX_ADDRESS_VAL_LEN);
85 MSG_DEBUG("### pMultistatus->szTo = %s ####", pAttrib->pMultiStatus->szTo);
86 pAttrib->pMultiStatus->bDeliveryReportIsRead = false;
87 pAttrib->pMultiStatus->bDeliveyrReportIsLast = false;
88 pAttrib->pMultiStatus->msgStatus = MMS_MSGSTATUS_NONE;
89 pAttrib->pMultiStatus->handledTime = 0;
90 pAttrib->pMultiStatus->bReadReplyIsRead = false;
91 pAttrib->pMultiStatus->bReadReplyIsLast = false;
92 pAttrib->pMultiStatus->readStatus = MMS_READSTATUS_NONE;
93 pAttrib->pMultiStatus->readTime = 0;
95 pAttrib->pMultiStatus = pAttrib->pMultiStatus->pNext;
99 char *MmsComposeAddress(const MSG_MESSAGE_INFO_S *pMsgInfo, int recipientType)
101 MSG_DEBUG("MmsComposeAddress");
105 char pString[MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3] = {0, };
108 nAddressCnt = pMsgInfo->nAddressCnt;
110 // Calculate allocated buffer size
111 for (int i = 0; i < nAddressCnt; ++i) {
112 MSG_DEBUG("recipientType: %d, address value: %s", pMsgInfo->addressList[i].recipientType, pMsgInfo->addressList[i].addressVal);
113 if (pMsgInfo->addressList[i].recipientType == recipientType) {
114 if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_PLMN) {
115 addrLen += strlen(MsgGetString(MSG_ADDR_TYPE, MSG_ADDR_TYPE_PHONE));
116 addrLen += strlen(pMsgInfo->addressList[i].addressVal);
117 } else if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_EMAIL) {
118 addrLen += strlen(pMsgInfo->addressList[i].addressVal);
120 ; // Need to consider IPV4, IPV6, and Alias formatted address
127 addrLen = addrLen + nRecpCnt - 1;
128 szCompose = (char *)calloc(addrLen + 1, 1);
130 // Address String copy
131 for (int i = 0; i < nAddressCnt; ++i) {
132 if (pMsgInfo->addressList[i].recipientType == recipientType) {
133 if (strlen(szCompose) > 0)
134 strcat(szCompose, MSG_STR_ADDR_DELIMETER);
136 memset(pString, 0x00, (MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3) * sizeof(char));
137 if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_PLMN) {
138 snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s%s", pMsgInfo->addressList[i].addressVal, MsgGetString(MSG_ADDR_TYPE, MSG_ADDR_TYPE_PHONE));
139 MSG_DEBUG("%s", pString);
140 } else if (pMsgInfo->addressList[i].addressType == MSG_ADDRESS_TYPE_EMAIL) {
141 snprintf(pString, MSG_LOCALE_NAME_LEN + MSG_ADDR_LEN + 3, "%s", pMsgInfo->addressList[i].addressVal);
143 ; // Need to consider IPV4, IPV6, and Alias formatted address
145 strcat(szCompose, pString);
153 bool MmsGetMsgBodyfromMsgInfo(const MSG_MESSAGE_INFO_S *pMsgInfo, MMS_MESSAGE_DATA_S *pMsgBody, char *pFileData)
155 MSG_DEBUG("MmsGetMsgBodyfromMsgInfo");
156 memset(pMsgBody, 0, sizeof(MMS_MESSAGE_DATA_S));
158 if (pMsgInfo->bTextSms == false) { //if the message body was stored in file.
159 _MsgMmsDeserializeMessageData(pMsgBody, pFileData);
165 bool MmsGetSmilRawData(MMS_MESSAGE_DATA_S *pMsgBody, char **pRawdata)
169 if (MsgReadSmilFile(pMsgBody->szSmilFilePath, pRawdata) < 0)
172 MsgDeleteSmilFile(pMsgBody->szSmilFilePath);
179 bool MmsInsertPresentation(MmsMsg *pMsg, MimeType mimeType, const char *content_id, char *pData, int size)
184 MSG_DEBUG("pMsg is NULL");
188 if (pMsg->msgBody.pPresentationBody != NULL)
191 memset(&pMsg->msgBody.presentationType, 0, sizeof(MsgType));
192 pMsg->msgBody.pPresentationBody = (MsgBody *)malloc(sizeof(MsgBody));
193 if (pMsg->msgBody.pPresentationBody == NULL)
196 MmsInitMsgBody(pMsg->msgBody.pPresentationBody);
198 pMsg->msgBody.pPresentationBody->body.pText = (char *)malloc(size + 1);
199 if (pMsg->msgBody.pPresentationBody->body.pText == NULL)
202 pMsg->msgBody.pPresentationBody->size = size;
203 pMsg->msgBody.presentationType.type = mimeType;
204 pMsg->msgBody.presentationType.param.charset = MSG_CHARSET_UTF8;
206 if (content_id && strlen(content_id) > 0) {
207 snprintf(pMsg->msgBody.presentationType.szContentID, MSG_MSG_ID_LEN + 1, "%s", content_id);
209 snprintf(pMsg->msgBody.presentationType.szContentID, MSG_MSG_ID_LEN + 1, "<_S_>");//default
212 snprintf(pMsg->msgType.param.szStart, MSG_MSG_ID_LEN + 1, "%s", pMsg->msgBody.presentationType.szContentID);
214 pMsg->msgType.param.type = mimeType;
216 memset(pMsg->msgBody.pPresentationBody->body.pText, 0, size + 1);
217 strncpy(pMsg->msgBody.pPresentationBody->body.pText, pData, size);
224 if (pMsg->msgBody.pPresentationBody != NULL) {
225 if (pMsg->msgBody.pPresentationBody->body.pText != NULL) {
226 free(pMsg->msgBody.pPresentationBody->body.pText);
227 pMsg->msgBody.pPresentationBody->body.pText = NULL;
230 free(pMsg->msgBody.pPresentationBody);
231 pMsg->msgBody.pPresentationBody = NULL;
237 bool MmsInsertPartFromFile(MmsMsg *pMsg, char *szTitleName, char *szOrgFilePath, char *szContentID)
239 MSG_DEBUG("MmsInsertPartFromFile");
241 MsgMultipart *pMultipart = NULL;
242 MsgMultipart *pLastPart = NULL;
244 MimeType mimeType = MIME_UNKNOWN;
247 pExt = strrchr(szOrgFilePath, '.');
249 if (pExt == NULL || pExt[0] == '\0' || strrchr(pExt, '/'))
250 mimeType = MIME_UNKNOWN;
252 if (strcasecmp(pExt, ".dcf") == 0)
253 mimeType = MIME_APPLICATION_VND_OMA_DRM_CONTENT;
255 if (MmsGetTypeByFileName((int *)&mimeType, szOrgFilePath) == false)
260 MSG_DEBUG("MmsInsertPartFromFile: type = %d, name = %s, filepath = %s, cid = %s", mimeType, szTitleName, szOrgFilePath, szContentID);
262 if (mimeType == MIME_UNKNOWN)
263 mimeType = MIME_APPLICATION_OCTET_STREAM;
265 if (MmsIsMultipart(pMsg->msgType.type) == true) {
266 /* Insert as a multipart */
267 if (MsgGetFileSize(szOrgFilePath, &nFileSize) == false) {
268 MSG_DEBUG("MsgGetFileSize: failed");
272 pMultipart = MmsMakeMultipart(mimeType, szTitleName, szOrgFilePath, szContentID, NULL);
273 if (pMultipart == NULL)
276 if (pMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
277 pMsg->mmsAttrib.contentType == MIME_MULTIPART_MIXED)
278 pMultipart->type.disposition = MSG_DISPOSITION_ATTACHMENT;
280 if (pMsg->msgBody.body.pMultipart == NULL) {
281 pMsg->msgBody.body.pMultipart = pMultipart;
283 pLastPart = pMsg->msgBody.body.pMultipart;
284 while (pLastPart->pNext) {
285 pLastPart = pLastPart->pNext;
288 pLastPart->pNext = pMultipart;
291 pMsg->msgBody.size += pMultipart->pBody->size;
292 pMsg->msgType.contentSize += pMultipart->pBody->size;
294 /* Single part - Insert as a message body */
295 if (pMsg->mmsAttrib.contentType != mimeType || pMsg->msgType.type != mimeType)
298 strncpy(pMsg->msgType.param.szName, szTitleName, MSG_LOCALE_FILENAME_LEN_MAX);
300 if (MmsIsText(pMsg->msgType.type) == true) {
301 pMsg->msgType.param.charset = MSG_CHARSET_UTF8;
304 strncpy(pMsg->msgBody.szOrgFilePath, szOrgFilePath, MSG_FILEPATH_LEN_MAX - 1);
305 if (MsgGetFileSize(szOrgFilePath, &nFileSize) == false) {
306 MSG_DEBUG("MsgGetFileSize: failed");
310 pMsg->msgBody.offset = 0;
311 pMsg->msgBody.size = nFileSize;
312 pMsg->msgType.contentSize = nFileSize;
324 bool MmsIsMultipart(int type)
326 MSG_DEBUG("MmsIsMultipart");
327 if (type == MIME_MULTIPART_RELATED ||
328 type == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
329 type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED ||
330 type == MIME_APPLICATION_VND_WAP_MULTIPART_ASTERIC ||
331 type == MIME_MULTIPART_MIXED ||
332 type == MIME_MULTIPART_REPORT) {
339 bool MmsIsText(int type)
341 if (type == MIME_TEXT_PLAIN ||
342 type == MIME_TEXT_HTML ||
343 type == MIME_TEXT_VND_WAP_WML ||
344 type == MIME_TEXT_X_VCARD ||
345 type == MIME_TEXT_X_VCALENDAR ||
346 type == MIME_TEXT_X_VNOTE ||
347 type == MIME_APPLICATION_SMIL ||
348 type == MIME_TEXT_X_IMELODY) {
349 MSG_DEBUG("MmsIsText true.");
352 MSG_DEBUG("MmsIsText false.");
357 bool MmsIsVitemContent (int type, char *pszName)
362 * To make Encoding information right.
363 * case MIME_TEXT_X_VCARD :
364 * case MIME_TEXT_X_VCALENDAR :
365 * case MIME_TEXT_X_VNOTE : // vnt
367 * MSG_DEBUG("MmsIsVitemContent true.");
372 case MIME_TEXT_X_VCARD:
373 case MIME_TEXT_X_VCALENDAR:
374 case MIME_TEXT_X_VNOTE: // vnt
375 case MIME_TEXT_PLAIN: // vbm - It SHOULD be distinguished from a normal text file.
382 // search file extension.
383 if ((pszExt = strrchr(pszName, '.')) == NULL)
386 if (!strcasecmp(pszExt, ".vbm")) {
387 MSG_DEBUG("MmsIsVitemContent true.");
397 MSG_DEBUG("MmsIsVitemContent false.");
403 MsgMultipart *MmsAllocMultipart(void)
405 MsgMultipart *pMultipart = NULL;
407 pMultipart = (MsgMultipart *)malloc(sizeof(MsgMultipart));
409 if (pMultipart == NULL)
412 pMultipart->pBody = (MsgBody *)malloc(sizeof(MsgBody));
414 if (pMultipart->pBody == NULL)
417 MmsInitMsgType(&pMultipart->type);
418 MmsInitMsgBody(pMultipart->pBody);
420 pMultipart->pNext = NULL;
427 if (pMultipart->pBody) {
428 free(pMultipart->pBody);
429 pMultipart->pBody = NULL;
439 MsgMultipart *MmsMakeMultipart(MimeType mimeType, char *szTitleName, char *szOrgFilePath, char *szContentID, char *szContentLocation)
441 MsgMultipart *pMultipart = NULL;
443 if ((pMultipart = MmsAllocMultipart()) == NULL)
446 pMultipart->type.type = mimeType;
448 if (szTitleName && szTitleName[0]) {
449 memset(pMultipart->type.param.szName, 0, MSG_LOCALE_FILENAME_LEN_MAX + 1);
450 strncpy(pMultipart->type.param.szName, szTitleName, MSG_LOCALE_FILENAME_LEN_MAX);
453 if (szContentID && szContentID[0]) {
454 memset(pMultipart->type.szContentID, 0, MSG_MSG_ID_LEN + 1);
455 snprintf(pMultipart->type.szContentID, MSG_MSG_ID_LEN + 1, "<%s>", szContentID);
458 if (szContentLocation && szContentLocation[0]) {
459 memset(pMultipart->type.szContentLocation, 0, MSG_MSG_ID_LEN + 1);
460 snprintf(pMultipart->type.szContentLocation, MSG_MSG_ID_LEN + 1, "%s", szContentLocation);
463 if (MmsIsText(mimeType) == true) {
464 if (!MmsIsVitemContent (mimeType, pMultipart->type.param.szName)) {
465 pMultipart->type.param.charset = MSG_CHARSET_UTF8;
467 pMultipart->type.encoding = MSG_ENCODING_8BIT;
469 pMultipart->type.encoding = MSG_ENCODING_BINARY;
473 strncpy(pMultipart->pBody->szOrgFilePath, szOrgFilePath, MSG_FILEPATH_LEN_MAX - 1);
474 pMultipart->pBody->offset = 0;
475 pMultipart->pBody->size = MsgGetFileSize(szOrgFilePath);
480 bool MmsGetTypeByFileName(int *type, char *szFileName)
483 AvCodecType AvType = AV_CODEC_NONE;
485 /* AVMS unknown or text/image file format identify type from file extention */
487 pExt = strrchr(szFileName, '.');
488 if (pExt == NULL || pExt[0] == '\0')
493 if (strcasecmp(pExt, "mp4") == 0 || strcasecmp(pExt, "mpeg4") == 0 ||
494 strcasecmp(pExt, "3gp") == 0 || strcasecmp(pExt, "3gpp") == 0) {
495 /* Audio / Video format. If file exists already, AvGetFileCodecType() can identify the format */
496 if (szFileName[0] != '/')
499 AvType = AvGetFileCodecType(szFileName);
502 case AV_DEC_AUDIO_MPEG4:
503 *type = MIME_AUDIO_MP4;//*type = MIME_AUDIO_3GPP;
506 case AV_DEC_VIDEO_MPEG4:
507 *type = MIME_VIDEO_MP4;
511 *type = MIME_VIDEO_3GPP;
517 if (strcasecmp(pExt, "amr") == 0) {
518 *type = MIME_AUDIO_AMR;
520 } else if ((strcasecmp(pExt, "mid") == 0) || (strcasecmp(pExt, "midi") == 0)) {
521 *type = MIME_AUDIO_MIDI;
523 } else if (strcasecmp(pExt, "imy") == 0) {
524 *type = MIME_TEXT_X_IMELODY;
528 *type = MimeGetMimeFromExtInt((const char *)pExt);
534 *type = MIME_UNKNOWN;
539 bool MmsComposeMessage(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMsgData, char *pFileData)
543 char *pRawData = NULL;
544 AutoPtr<char> buf(&pRawData);
546 struct tm *timeInfo = NULL;
548 time_t nTimeInSecs = 0;
550 msg_error_t err = MSG_SUCCESS;
552 // Initialize mmsMsg structure
553 MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
554 MmsInitMsgType(&pMmsMsg->msgType);
555 MmsInitMsgBody(&pMmsMsg->msgBody);
557 // setting mmsMsg structure
558 pMmsMsg->mailbox = pMsgInfo->folderId;
559 pMmsMsg->msgID = pMsgInfo->msgId;
561 memset(pMmsMsg->szTrID, 0, MMS_TR_ID_LEN + 1);
562 memset(pMmsMsg->szContentLocation, 0, MMS_LOCATION_LEN + 1);
563 memset(pMmsMsg->szMsgID, 0, MMS_MSG_ID_LEN + 1);
564 memset(pMmsMsg->szForwardMsgID, 0, MMS_MSG_ID_LEN + 1);
566 pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_DRAFT;
568 MSG_DEBUG("## delivery = %d ##", pSendOptInfo->bDeliverReq);
569 MSG_DEBUG("## read = %d ##", pSendOptInfo->option.mmsSendOptInfo.bReadReq);
570 MSG_DEBUG("## priority = %d ##", pSendOptInfo->option.mmsSendOptInfo.priority);
571 MSG_DEBUG("## expiryTime = %d ##", pSendOptInfo->option.mmsSendOptInfo.expiryTime.time);
573 if (pSendOptInfo->bSetting == false) {
574 unsigned int expiryTime;
575 MSG_MMS_DELIVERY_TIME_T deliveryTime;
577 pMmsMsg->mmsAttrib.priority = (MmsPriority)MsgSettingGetInt(MMS_SEND_PRIORITY);
579 MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pMmsMsg->mmsAttrib.bAskDeliveryReport);
580 MsgSettingGetBool(MMS_SEND_READ_REPLY, &pMmsMsg->mmsAttrib.bAskReadReply);
581 MsgSettingGetBool(MSG_KEEP_COPY, &pMmsMsg->mmsAttrib.bLeaveCopy);
583 expiryTime = (unsigned int)MsgSettingGetInt(MMS_SEND_EXPIRY_TIME);
586 pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_NONE;
588 pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_RELATIVE;
589 pMmsMsg->mmsAttrib.expiryTime.time = expiryTime;
592 deliveryTime = (MSG_MMS_DELIVERY_TIME_T)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
594 if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
595 pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = true;
597 pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
598 pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY);
600 pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = false;
602 pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
603 pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)deliveryTime;
606 pMmsMsg->mmsAttrib.priority = (MmsPriority)pSendOptInfo->option.mmsSendOptInfo.priority;
607 pMmsMsg->mmsAttrib.bAskDeliveryReport = pSendOptInfo->bDeliverReq;
608 pMmsMsg->mmsAttrib.bAskReadReply = pSendOptInfo->option.mmsSendOptInfo.bReadReq;
609 pMmsMsg->mmsAttrib.expiryTime.type = pSendOptInfo->option.mmsSendOptInfo.expiryTime.type;
610 pMmsMsg->mmsAttrib.bLeaveCopy = pSendOptInfo->bKeepCopy;
612 if (pMmsMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE)
613 pMmsMsg->mmsAttrib.expiryTime.time = pSendOptInfo->option.mmsSendOptInfo.expiryTime.time;
615 pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime;
616 pMmsMsg->mmsAttrib.deliveryTime.type = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.type;
617 pMmsMsg->mmsAttrib.deliveryTime.time = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time;
620 MSG_DEBUG("pSendOptInfo->bSetting = %d", pSendOptInfo->bSetting);
621 MSG_DEBUG("pMmsMsg->mmsAttrib.bLeaveCopy = %d", pMmsMsg->mmsAttrib.bLeaveCopy);
622 MSG_DEBUG("pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = %d", pMmsMsg->mmsAttrib.bUseDeliveryCustomTime);
623 MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.type = %d", pMmsMsg->mmsAttrib.deliveryTime.type);
624 MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.time = %d", pMmsMsg->mmsAttrib.deliveryTime.time);
626 /* MMS-1.3-con-739 */
627 pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)MsgSettingGetInt(MMS_SEND_MSG_CLASS);
628 /* MMS-1.3-con-739 */
629 #ifdef MMS_13_CON_742_ENABLED
630 /* MMS-1.3-con-742 */
631 pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
632 /* MMS-1.3-con-742 */
635 MSG_DEBUG("@@@ pMmsMsg->mmsAttrib.bAskDeliveryReport = %d @@@", pMmsMsg->mmsAttrib.bAskDeliveryReport);
636 MSG_DEBUG("@@@ pMmsMsg->mmsAttrib.bAskReadReply = %d @@@", pMmsMsg->mmsAttrib.bAskReadReply);
637 MSG_DEBUG("@@@ pMmsMsg->mmsAttrib.priority = %d @@@", pMmsMsg->mmsAttrib.priority);
641 timeInfo = localtime(&RawTime);
642 nTimeInSecs = mktime(timeInfo);
643 pMmsMsg->mmsAttrib.date = nTimeInSecs; // todo: need to subtract timeline value to make GMT+0 time
646 strcpy(pMmsMsg->mmsAttrib.szSubject, pMsgInfo->subject);
649 MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
650 //MmsGetMsgBodyfromMsgInfo(pMsgInfo, pMsgData, pFileData);
652 int pageCnt = _MsgMmsGetPageCount(pMsgData);
654 if (pageCnt == 0) { // Multipart mixed
655 pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
656 pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
657 MmsMakePreviewInfo(pMsgInfo->msgId, pMsgData);
658 } else { // Multipart related
664 snprintf(pMsgData->szSmilFilePath, MSG_FILEPATH_LEN_MAX, "%lu", RawTime);
666 MsgMMSCreateSMIL(pMsgData);
668 RawDataSize = MmsGetSmilRawData(pMsgData, &pRawData);
669 if (RawDataSize < 0) {
670 MSG_DEBUG("Smil file size is less than 0");
673 MSG_DEBUG("%s", pRawData);
675 MmsInsertPresentation(pMmsMsg, MIME_APPLICATION_SMIL, NULL, pRawData, strlen(pRawData));
677 pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
678 pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
680 for (int i = 0; i < pageCnt; ++i) {
681 MMS_PAGE_S *pPage = _MsgMmsGetPage(pMsgData, i);
682 int mediaCnt = pPage->mediaCnt;
683 MSG_DEBUG("PAGE %d's media Cnt: %d", i+1, mediaCnt);
685 for (int j = 0; j < mediaCnt; ++j) {
686 MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
688 switch (pMedia->mediatype) {
689 case MMS_SMIL_MEDIA_IMG:
690 case MMS_SMIL_MEDIA_VIDEO:
691 case MMS_SMIL_MEDIA_AUDIO:
692 case MMS_SMIL_MEDIA_TEXT:
693 if (pMedia->szFilePath[0] != 0) {
694 if (!MmsInsertPartFromFile(pMmsMsg, pMedia->szFileName, pMedia->szFilePath, pMedia->szContentID))
705 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };;
706 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms", pMsgInfo->msgId);
708 MmsPluginStorage *pStorage = MmsPluginStorage::instance();
709 err = pStorage->getMsgText(pMsgData, pMsgInfo->msgText);
710 MmsMakePreviewInfo(pMsgInfo->msgId, pMsgData);
713 #ifdef FEATURE_JAVA_MMS
714 MSG_DEBUG("msgAppId: valid:%d appId:%s replyToAppId:%s", pMsgData->msgAppId.valid, pMsgData->msgAppId.appId, pMsgData->msgAppId.replyToAppId);
715 if (pMsgData->msgAppId.valid) { // check if msgAppId.valid is true, both appId and replytoappId must have a meaning data
716 if (pMsgData->msgAppId.appId[0] != 0) {
717 pMmsMsg->msgType.param.szApplicationID = (char *)malloc(strlen(pMsgData->msgAppId.appId) + 1);
718 if (pMmsMsg->msgType.param.szApplicationID == NULL) {
719 MSG_DEBUG("Error: out of Memory");
722 memset(pMmsMsg->msgType.param.szApplicationID, 0, strlen(pMsgData->msgAppId.appId) + 1);
724 strcpy(pMmsMsg->msgType.param.szApplicationID, pMsgData->msgAppId.appId);
727 if (pMsgData->msgAppId.replyToAppId[0] != 0) {
728 pMmsMsg->msgType.param.szReplyToApplicationID = (char *)malloc(strlen(pMsgData->msgAppId.replyToAppId) + 1);
729 if (pMmsMsg->msgType.param.szReplyToApplicationID == NULL) {
730 MSG_DEBUG("Error: out of Memory");
733 memset(pMmsMsg->msgType.param.szReplyToApplicationID, 0, strlen(pMsgData->msgAppId.replyToAppId) + 1);
735 strcpy(pMmsMsg->msgType.param.szReplyToApplicationID, pMsgData->msgAppId.replyToAppId);
740 //Processing Attachment List
741 for (int i = 0; i < _MsgMmsGetAttachCount(pMsgData); ++i) {
742 MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pMsgData, i);
743 if (pMedia->szFilePath[0] != 0) {
744 if (!MmsInsertPartFromFile(pMmsMsg, pMedia->szFileName, pMedia->szFilePath, NULL)) {
754 void MmsComposeNotiMessage(MmsMsg *pMmsMsg, msg_message_id_t msgID)
758 struct tm *timeInfo = NULL;
760 time_t nTimeInSecs = 0;
762 MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
763 MmsInitMsgType(&pMmsMsg->msgType);
764 MmsInitMsgBody(&pMmsMsg->msgBody);
766 pMmsMsg->msgID = msgID;
768 pMmsMsg->mmsAttrib.version = mmsHeader.version;
772 timeInfo = localtime(&RawTime);
773 nTimeInSecs = mktime(timeInfo);
774 pMmsMsg->mmsAttrib.date = nTimeInSecs;
776 pMmsMsg->mmsAttrib.bReportAllowed = mmsHeader.reportAllowed;
777 pMmsMsg->mmsAttrib.bAskDeliveryReport = mmsHeader.deliveryReport;
779 MSG_DEBUG("######## Version = %d ########", pMmsMsg->mmsAttrib.version);
781 strncpy(pMmsMsg->szTrID, mmsHeader.szTrID, MMS_TR_ID_LEN);
782 strncpy(pMmsMsg->szMsgID, mmsHeader.szMsgID, MMS_MSG_ID_LEN);
783 pMmsMsg->szForwardMsgID[0] = '\0';
785 if (mmsHeader.pFrom) {
786 MmsAddrUtilRemovePlmnString(mmsHeader.pFrom->szAddr );
787 strncpy(pMmsMsg->mmsAttrib.szFrom, mmsHeader.pFrom->szAddr, MSG_LOCALE_ADDR_LEN + 9);
790 strncpy(pMmsMsg->mmsAttrib.szSubject, mmsHeader.szSubject, MSG_LOCALE_SUBJ_LEN);
791 strncpy(pMmsMsg->szContentLocation, mmsHeader.szContentLocation, MMS_LOCATION_LEN);
793 pMmsMsg->mmsAttrib.msgClass = mmsHeader.msgClass;
794 pMmsMsg->mmsAttrib.msgSize = mmsHeader.msgSize;
795 pMmsMsg->mmsAttrib.expiryTime.type = mmsHeader.expiryTime.type;
796 pMmsMsg->mmsAttrib.expiryTime.time = mmsHeader.expiryTime.time;
797 pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_NOTIFY;
798 pMmsMsg->mmsAttrib.bRead = false;
799 pMmsMsg->mailbox = MSG_INBOX_ID;
801 pMmsMsg->mmsAttrib.replyCharge.chargeType = mmsHeader.replyCharge.chargeType;
802 pMmsMsg->mmsAttrib.replyCharge.deadLine.type = mmsHeader.replyCharge.deadLine.type;
803 pMmsMsg->mmsAttrib.replyCharge.deadLine.time = mmsHeader.replyCharge.deadLine.time;
804 pMmsMsg->mmsAttrib.replyCharge.chargeSize = mmsHeader.replyCharge.chargeSize;
806 strncpy(pMmsMsg->mmsAttrib.replyCharge.szChargeID, mmsHeader.replyCharge.szChargeID, MMS_MSG_ID_LEN);
811 void MmsComposeReadReportMessage(MmsMsg *pMmsMsg, const MSG_MESSAGE_INFO_S *pMsgInfo, msg_message_id_t selectedMsgId)
813 struct tm *timeInfo = NULL;
815 time_t nTimeInSecs = 0;
817 MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
818 MmsInitMsgType(&pMmsMsg->msgType);
819 MmsInitMsgBody(&pMmsMsg->msgBody);
821 // setting mmsMsg structure
822 pMmsMsg->mailbox = pMsgInfo->folderId;
823 pMmsMsg->msgID = pMsgInfo->msgId;
825 memset(pMmsMsg->szTrID, 0, MMS_TR_ID_LEN + 1);
826 memset(pMmsMsg->szContentLocation, 0, MMS_LOCATION_LEN + 1);
827 memset(pMmsMsg->szForwardMsgID, 0, MMS_MSG_ID_LEN + 1);
829 pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_DRAFT;
833 timeInfo = localtime(&RawTime);
834 nTimeInSecs = mktime(timeInfo);
835 pMmsMsg->mmsAttrib.date = nTimeInSecs;
838 MmsPluginStorage::instance()->getMmsMessageId(selectedMsgId, pMmsMsg);
841 strcpy(pMmsMsg->mmsAttrib.szSubject, pMsgInfo->subject);
844 MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
846 if (pMmsMsg->mmsAttrib.szTo)
847 strncpy(pMmsMsg->mmsAttrib.szFrom, pMmsMsg->mmsAttrib.szTo, strlen(pMmsMsg->mmsAttrib.szTo));
850 bool MmsFindMatchedMedia(MMS_MESSAGE_DATA_S *pMsgData, char *pszFilePath)
852 if (pMsgData == NULL || pszFilePath == NULL)
855 if (pMsgData->pagelist) {
856 for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
857 MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
859 if (page && page->medialist) {
860 for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
861 MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
863 if (strcmp(pszFilePath, media->szFilePath) == 0)
874 bool MmsCheckAdditionalMedia(MMS_MESSAGE_DATA_S *pMsgData, MsgType *partHeader)
876 if (MmsFindMatchedMedia(pMsgData, partHeader->param.szFileName))
882 /*PIM objects SHALL be supported as attachments to an MM*/
883 bool MmsRemovePims(MMS_MESSAGE_DATA_S *pMsgData)
885 GList *cur_page = NULL;
886 GList *cur_media = NULL;
888 if (pMsgData == NULL)
891 cur_page = pMsgData->pagelist;
894 MMS_PAGE_S *page = (MMS_PAGE_S *)cur_page->data;
896 cur_media = page->medialist;
899 MMS_MEDIA_S *pMedia = (MMS_MEDIA_S *)cur_media->data;
902 MsgGetTypeByFileName(&tempType, pMedia->szFilePath);
903 if (tempType == MIME_TEXT_X_VCALENDAR || tempType == MIME_TEXT_X_VCARD) {
904 page->medialist = g_list_remove_all(page->medialist, pMedia);
905 page->mediaCnt = g_list_length(page->medialist);
906 cur_media = page->medialist;
909 cur_media = g_list_next(cur_media);
912 cur_media = g_list_next(cur_media);
914 } //cur_media while for remove pims file in list
916 if (page->medialist == NULL) {//remove empty page
917 pMsgData->pagelist = g_list_remove_all(pMsgData->pagelist, page);
918 pMsgData->pageCnt = g_list_length(pMsgData->pagelist);
919 cur_page = pMsgData->pagelist;
922 cur_page = g_list_next(cur_page);
931 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg)
933 MMS_PAGE_S *pPage = NULL;
934 MMS_MEDIA_S *pMedia = NULL;
937 return MSG_ERR_NULL_POINTER;
939 MmsPluginStorage::instance()->removePreviewInfo(msgId); //remove exist previnfo
941 if (pMmsMsg->pageCnt > 0) {
943 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
945 pPage = _MsgMmsGetPage(pMmsMsg, 0);
946 for (int j = 0; j < pPage->mediaCnt; j++) {
948 pMedia = _MsgMmsGetMedia(pPage, j);
949 MSG_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
951 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
952 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
953 char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
956 memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
957 memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
959 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
961 if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
962 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s/%s.png", MSG_THUMBNAIL_PATH, szFileName);
964 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s/%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
967 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
968 if (makeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
969 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
971 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
974 if (makeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
975 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
977 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
981 } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
982 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
986 MSG_DEBUG("There is no page");
989 int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
991 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
992 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
994 MSG_DEBUG("There is no attachment");
1000 void MmsPrintFileInfoForVLD(MMS_MESSAGE_DATA_S *pMmsMsg)
1002 MMS_PAGE_S *pPage = NULL;
1003 MMS_MEDIA_S *pMedia = NULL;
1005 if (pMmsMsg == NULL)
1008 if (pMmsMsg->pageCnt > 0) {
1009 for (int i = 0; i < pMmsMsg->pageCnt; i++) {
1011 pPage = _MsgMmsGetPage(pMmsMsg, i);
1016 for (int j = 0; j < pPage->mediaCnt; j++) {
1018 pMedia = _MsgMmsGetMedia(pPage, j);
1022 MSG_MMS_VLD_FILE("[%s], %d", pMedia->szFilePath, MsgGetFileSize(pMedia->szFilePath));
1027 int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
1028 if (attachCnt > 0) {
1029 for (int i = 0; i < pMmsMsg->attachCnt; i++) {
1030 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, i);
1031 MSG_MMS_VLD_FILE("[%s], %d", pAttach->szFilePath, MsgGetFileSize(pAttach->szFilePath));
1036 MMS_MEDIA_S *MmsFindMediaWithCID(MMS_MESSAGE_DATA_S *pMsgData, const char *szContentID)
1039 if (pMsgData == NULL || szContentID == NULL || strlen(szContentID) == 0) {
1040 MSG_DEBUG("Invalid Parameter pMsgData = %p, szContentID = %p", pMsgData, szContentID);
1044 if (pMsgData->pagelist) {
1045 for (int pageIdx = 0; pageIdx < pMsgData->pageCnt; pageIdx++) {
1047 MMS_PAGE_S *page = (MMS_PAGE_S *)g_list_nth_data(pMsgData->pagelist, pageIdx);
1049 if (page && page->medialist) {
1051 for (int mediaIdx = 0; mediaIdx < page->mediaCnt; mediaIdx++) {
1053 MMS_MEDIA_S *media = (MMS_MEDIA_S *)g_list_nth_data(page->medialist, mediaIdx);
1056 if (strcmp(media->szContentID, szContentID) == 0) {
1057 MSG_DEBUG("Find media with Content ID [%s] from pMsgData", szContentID);
1062 MSG_DEBUG("Error media NULL");
1065 } //end for media list
1067 } //end for page list
1070 MSG_DEBUG("Not exist Matched media with [%s]", szContentID);
1074 MsgMultipart *MmsGetNthMultipart(MmsMsg *pMsg, int index)
1076 MsgMultipart *pPart = NULL;
1078 if (MsgIsMultipart(pMsg->msgType.type) == true) {
1080 pPart = pMsg->msgBody.body.pMultipart;
1082 while (pPart && index--) {
1083 pPart = pPart->pNext;
1086 if (pPart == NULL) {
1087 MSG_DEBUG("There is no such Multipart [index = %d].", index);
1093 MSG_DEBUG("This Msg is not Multipart");
1099 bool MmsInsertPartToMmsData(MMS_MESSAGE_DATA_S *pMsgData, MMS_MULTIPART_DATA_S *pMultipart)
1101 MMS_MEDIA_S * match_media = NULL;
1102 bool isPimsFile = false;
1103 int tempType;//MimeType
1105 if (pMsgData == NULL || pMultipart == NULL) {
1109 //for pims file add to attach
1110 MsgGetTypeByFileName(&tempType, pMultipart->szFilePath);
1111 if (tempType == MIME_TEXT_X_VCALENDAR || tempType == MIME_TEXT_X_VCARD) {
1112 MSG_DEBUG("Pims File");
1116 if (strlen(pMultipart->szContentID) > 0) {
1117 char szTempContentID[MSG_MSG_ID_LEN + 1] = {0,};
1118 removeLessGreaterMark(pMultipart->szContentID, szTempContentID, sizeof(szTempContentID));
1119 match_media = MmsFindMediaWithCID(pMsgData, szTempContentID);
1121 if (match_media == NULL && strlen(pMultipart->szContentLocation) > 0 ) {
1122 match_media = MmsFindMediaWithCID(pMsgData, pMultipart->szContentLocation);
1126 MSG_DEBUG("ContentID is NULL");
1132 if (match_media && isPimsFile == false) { // set file path
1133 snprintf(match_media->szFilePath, sizeof(match_media->szFilePath), "%s", pMultipart->szFilePath);
1134 snprintf(match_media->szFileName, sizeof(match_media->szFileName), "%s", pMultipart->szFileName);
1135 snprintf(match_media->szContentID, sizeof(match_media->szContentID), "%s", pMultipart->szContentID);
1136 snprintf(match_media->szContentLocation, sizeof(match_media->szContentLocation), "%s", pMultipart->szContentLocation);
1137 snprintf(match_media->szContentType, sizeof(match_media->szContentType), "%s", pMultipart->szContentType);
1138 } else { // add attach
1140 MMS_ATTACH_S *attachment = NULL;
1141 attachment = (MMS_ATTACH_S *)calloc(sizeof(MMS_ATTACH_S), 1);
1143 attachment->mediatype = (MimeType)tempType;
1144 snprintf(attachment->szContentType, sizeof(attachment->szContentType), "%s", pMultipart->szContentType);
1145 snprintf(attachment->szFilePath, sizeof(attachment->szFilePath), "%s", pMultipart->szFilePath);
1146 snprintf(attachment->szFileName, sizeof(attachment->szFileName), "%s", pMultipart->szFileName);
1147 attachment->fileSize = MsgGetFileSize(attachment->szFilePath);
1149 if (_MsgMmsAddAttachment(pMsgData, attachment) != MSG_SUCCESS) {
1158 bool MmsEncodeMmsMessage(MmsMsg *pMmsMsg, const char *raw_filepath)
1160 bool encode_ret = false;
1161 mode_t file_mode = (S_IRUSR | S_IWUSR);
1163 if (pMmsMsg == NULL || raw_filepath == NULL) {
1164 MSG_DEBUG("Invalid Parameter pMmsMsg = %p , raw_filepath = %p", pMmsMsg, raw_filepath);
1168 FILE *pFile = MsgOpenFile(raw_filepath, "wb+");
1170 if (pFile == NULL) {
1171 MSG_FATAL("File Open Error: %s", strerror(errno));
1175 if (MsgFseek(pFile, 0L, SEEK_CUR) < 0) {
1176 MSG_DEBUG("File Fseek Error: %s", strerror(errno));
1180 if (fchmod(fileno(pFile), file_mode) < 0) {
1181 MSG_DEBUG("File chmod Error: %s", strerror(errno));
1185 switch(pMmsMsg->mmsAttrib.msgType)
1187 case MMS_MSGTYPE_SEND_REQ:
1188 case MMS_MSGTYPE_SEND_CONF:
1189 encode_ret = MmsEncodeSendReq(pFile, pMmsMsg);
1190 if (encode_ret == false) {
1191 MSG_DEBUG("Fail to MmsEncodeSendReq");
1196 MSG_DEBUG("Not Support msg type : %d", pMmsMsg->mmsAttrib.msgType);
1201 MsgFsync(pFile); //file is written to device immediately, it prevents missing file data from unexpected power off
1202 MsgCloseFile(pFile);
1208 MsgCloseFile(pFile);
1214 bool MmsInsertPartFromMultipart(MmsMsg *pMsg, MMS_MULTIPART_DATA_S *pNewMultipart)
1216 MsgMultipart *pMultipart = NULL;
1217 MsgMultipart *pLastPart = NULL;
1219 MimeType mimeType = MIME_UNKNOWN;
1222 pExt = strrchr(pNewMultipart->szFilePath, '.');
1224 if (pExt == NULL || pExt[0] == '\0' || strrchr(pExt, '/')) {
1225 //mimeType = MIME_UNKNOWN;
1226 mimeType = MimeGetMimeIntFromMimeString(pNewMultipart->szContentType);
1228 if (strcasecmp(pExt, ".dcf") == 0)
1229 mimeType = MIME_APPLICATION_VND_OMA_DRM_CONTENT;
1231 if (MmsGetTypeByFileName((int *)&mimeType, pNewMultipart->szFilePath) == false)
1236 MSG_DEBUG("type = %d, name = %s, filepath = %s, cid = %s, cl = %s", mimeType, pNewMultipart->szFileName, pNewMultipart->szFilePath, pNewMultipart->szContentID, pNewMultipart->szContentLocation);
1238 if (mimeType == MIME_UNKNOWN)
1239 mimeType = MIME_APPLICATION_OCTET_STREAM;
1241 if (MmsIsMultipart(pMsg->msgType.type) == true) {
1242 /* Insert as a multipart */
1243 pMultipart = MmsMakeMultipart(mimeType, pNewMultipart->szFileName, pNewMultipart->szFilePath, pNewMultipart->szContentID, pNewMultipart->szContentLocation);
1245 if (pMultipart == NULL)
1248 if (pMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_MIXED ||
1249 pMsg->mmsAttrib.contentType == MIME_MULTIPART_MIXED)
1250 pMultipart->type.disposition = MSG_DISPOSITION_ATTACHMENT;
1252 if (pMsg->msgBody.body.pMultipart == NULL) {
1253 pMsg->msgBody.body.pMultipart = pMultipart;
1255 pLastPart = pMsg->msgBody.body.pMultipart;
1256 while (pLastPart->pNext) {
1257 pLastPart = pLastPart->pNext;
1260 pLastPart->pNext = pMultipart;
1263 pMsg->msgBody.size += pMultipart->pBody->size;
1264 pMsg->msgType.contentSize += pMultipart->pBody->size;
1266 /* Single part - Insert as a message body */
1267 if (pMsg->mmsAttrib.contentType != mimeType || pMsg->msgType.type != mimeType)
1270 strncpy(pMsg->msgType.param.szName, pNewMultipart->szFileName, MSG_LOCALE_FILENAME_LEN_MAX);
1272 if (MmsIsText(pMsg->msgType.type) == true) {
1273 pMsg->msgType.param.charset = MSG_CHARSET_UTF8;
1276 strncpy(pMsg->msgBody.szOrgFilePath, pNewMultipart->szFilePath, MSG_FILEPATH_LEN_MAX - 1);
1277 pMsg->msgBody.offset = 0;
1278 pMsg->msgBody.size = MsgGetFileSize(pNewMultipart->szFilePath);
1279 pMsg->msgType.contentSize = MsgGetFileSize(pNewMultipart->szFilePath);
1291 bool MmsMakeMmsData(MmsMsg *pMsg, MMS_MESSAGE_DATA_S *pMmsMsg)
1295 bzero(pMmsMsg, sizeof(MMS_MESSAGE_DATA_S));
1296 pMmsMsg->regionCnt = 0;
1297 pMmsMsg->pageCnt = 0;
1298 pMmsMsg->attachCnt = 0;
1299 pMmsMsg->transitionCnt = 0;
1300 pMmsMsg->metaCnt = 0;
1301 memset(pMmsMsg->szSmilFilePath, 0, MSG_FILEPATH_LEN_MAX);
1303 if (pMsg->mmsAttrib.contentType == MIME_MULTIPART_RELATED || pMsg->mmsAttrib.contentType == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
1304 char *pSmilDoc = NULL;
1306 if (pMsg->msgBody.pPresentationBody) {
1307 if (pMsg->msgBody.pPresentationBody->body.pText) {
1308 pSmilDoc = pMsg->msgBody.pPresentationBody->body.pText;
1310 MmsSmilParseSmilDocOnlyLayout(pMmsMsg, pSmilDoc);
1313 pMmsMsg->smil.type = MIME_APPLICATION_SMIL;
1314 snprintf(pMmsMsg->smil.szContentType, MSG_MSG_ID_LEN, "%s", MimeGetMimeStringFromMimeInt(pMsg->msgBody.presentationType.type));
1315 snprintf(pMmsMsg->smil.szContentID, MSG_MSG_ID_LEN, "%s", pMsg->msgBody.presentationType.szContentID);
1316 snprintf(pMmsMsg->smil.szContentLocation, MSG_MSG_ID_LEN, "%s", pMsg->msgBody.presentationType.szContentLocation);
1317 snprintf(pMmsMsg->smil.szFileName, MSG_FILENAME_LEN_MAX, "%s", pMsg->msgBody.presentationType.param.szName);
1318 snprintf(pMmsMsg->smil.szFilePath, MSG_FILEPATH_LEN_MAX, "%s/%s", MSG_DATA_PATH, pMsg->msgBody.presentationType.param.szFileName);
1321 MSG_DEBUG("Not Exist pPresentationBody");
1325 int partCnt = pMsg->nPartCount;
1327 for (int i = 0; i < partCnt; ++i) {
1329 MsgMultipart *multipart = MmsGetNthMultipart(pMsg, i);
1330 MMS_MULTIPART_DATA_S pMultipart;
1332 if (multipart == NULL) {
1333 MSG_DEBUG("multipart is NULL [%d]", i);
1337 bzero(&pMultipart, sizeof(MMS_MULTIPART_DATA_S));
1338 snprintf(pMultipart.szContentID, sizeof(pMultipart.szContentID), "%s", multipart->type.szContentID);
1339 snprintf(pMultipart.szContentLocation, sizeof(pMultipart.szContentLocation), "%s", multipart->type.szContentLocation);
1340 snprintf(pMultipart.szFileName, sizeof(pMultipart.szFileName), "%s", multipart->type.param.szName);
1341 snprintf(pMultipart.szFilePath, sizeof(pMultipart.szFilePath), "%s", multipart->pBody->szOrgFilePath);
1342 snprintf(pMultipart.szContentType, sizeof(pMultipart.szContentType), "%s",MimeGetMimeStringFromMimeInt(multipart->type.type));
1344 if (MmsInsertPartToMmsData(pMmsMsg, &pMultipart) == false) {
1345 MSG_DEBUG("Fail to MmsSetMultipartToMmsData");
1355 void MmsPrintMmsMsg(const MmsMsg *pMmsMsg)
1357 MmsMsgType msgType = pMmsMsg->mmsAttrib.msgType;
1358 if (msgType == MMS_MSGTYPE_SEND_REQ) {
1359 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_SEND_REQ");
1360 } else if (msgType == MMS_MSGTYPE_SEND_CONF) {
1361 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_SEND_CONF");
1362 } else if (msgType == MMS_MSGTYPE_NOTIFICATION_IND) {
1363 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_NOTIFICATION_IND");
1364 } else if (msgType == MMS_MSGTYPE_NOTIFYRESP_IND) {
1365 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_NOTIFYRESP_IND");
1366 } else if (msgType == MMS_MSGTYPE_RETRIEVE_CONF) {
1367 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_RETRIEVE_CONF");
1368 } else if (msgType == MMS_MSGTYPE_ACKNOWLEDGE_IND) {
1369 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_ACKNOWLEDGE_IND");
1370 } else if (msgType == MMS_MSGTYPE_DELIVERY_IND) {
1371 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_DELIVERY_IND");
1372 } else if (msgType == MMS_MSGTYPE_READREC_IND) {
1373 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_READREC_IND");
1374 } else if (msgType == MMS_MSGTYPE_READORG_IND) {
1375 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_READORG_IND");
1376 } else if (msgType == MMS_MSGTYPE_FORWARD_REQ) {
1377 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_FORWARD_REQ");
1378 } else if (msgType == MMS_MSGTYPE_FORWARD_CONF) {
1379 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_FORWARD_CONF");
1380 } else if (msgType == MMS_MSGTYPE_READ_REPLY) {
1381 PRINT_KEY_VAL_STR("mms type", "MMS_MSGTYPE_READ_REPLY");
1383 PRINT_KEY_VAL_STR("mms type", "Unknown");
1386 PRINT_KEY_VAL_STR("mms ver", pMmsMsg->mmsAttrib.version);
1390 bool MmsComposeSendReq(MmsMsg *pMmsMsg, MSG_MESSAGE_INFO_S *pMsgInfo, MSG_SENDINGOPT_INFO_S *pSendOptInfo, MMS_MESSAGE_DATA_S *pMsgData)
1394 char *pRawData = NULL;
1395 AutoPtr<char> buf(&pRawData);
1396 struct tm *timeInfo = NULL;
1398 time_t nTimeInSecs = 0;
1400 // Initialize mmsMsg structure
1401 MmsInitMsgAttrib(&pMmsMsg->mmsAttrib);
1402 MmsInitMsgType(&pMmsMsg->msgType);
1403 MmsInitMsgBody(&pMmsMsg->msgBody);
1405 // setting mmsMsg structure
1406 pMmsMsg->mailbox = pMsgInfo->folderId;
1407 pMmsMsg->msgID = pMsgInfo->msgId;
1409 memset(pMmsMsg->szTrID, 0, MMS_TR_ID_LEN + 1);
1410 memset(pMmsMsg->szContentLocation, 0, MMS_LOCATION_LEN + 1);
1411 memset(pMmsMsg->szMsgID, 0, MMS_MSG_ID_LEN + 1);
1412 memset(pMmsMsg->szForwardMsgID, 0, MMS_MSG_ID_LEN + 1);
1414 pMmsMsg->mmsAttrib.dataType = MMS_DATATYPE_DRAFT;
1415 pMmsMsg->mmsAttrib.msgType = MMS_MSGTYPE_SEND_REQ;
1417 if (pSendOptInfo->bSetting == false) {
1418 unsigned int expiryTime;
1419 MSG_MMS_DELIVERY_TIME_T deliveryTime;
1421 pMmsMsg->mmsAttrib.priority = (MmsPriority)MsgSettingGetInt(MMS_SEND_PRIORITY);
1423 MsgSettingGetBool(MMS_SEND_DELIVERY_REPORT, &pMmsMsg->mmsAttrib.bAskDeliveryReport);
1424 MsgSettingGetBool(MMS_SEND_READ_REPLY, &pMmsMsg->mmsAttrib.bAskReadReply);
1425 MsgSettingGetBool(MSG_KEEP_COPY, &pMmsMsg->mmsAttrib.bLeaveCopy);
1427 expiryTime = (unsigned int)MsgSettingGetInt(MMS_SEND_EXPIRY_TIME);
1429 if (expiryTime == 0)
1430 pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_NONE;
1432 pMmsMsg->mmsAttrib.expiryTime.type = MMS_TIMETYPE_RELATIVE;
1433 pMmsMsg->mmsAttrib.expiryTime.time = expiryTime;
1436 deliveryTime = (MSG_MMS_DELIVERY_TIME_T)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
1438 if (deliveryTime == MSG_DELIVERY_TIME_CUSTOM) {
1439 pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = true;
1441 pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
1442 pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_CUSTOM_DELIVERY);
1444 pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = false;
1446 pMmsMsg->mmsAttrib.deliveryTime.type = MMS_TIMETYPE_RELATIVE;
1447 pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)deliveryTime;
1450 pMmsMsg->mmsAttrib.priority = (MmsPriority)pSendOptInfo->option.mmsSendOptInfo.priority;
1451 pMmsMsg->mmsAttrib.bAskDeliveryReport = pSendOptInfo->bDeliverReq;
1452 pMmsMsg->mmsAttrib.bAskReadReply = pSendOptInfo->option.mmsSendOptInfo.bReadReq;
1453 pMmsMsg->mmsAttrib.expiryTime.type = pSendOptInfo->option.mmsSendOptInfo.expiryTime.type;
1454 pMmsMsg->mmsAttrib.bLeaveCopy = pSendOptInfo->bKeepCopy;
1456 if (pMmsMsg->mmsAttrib.expiryTime.type != MMS_TIMETYPE_NONE)
1457 pMmsMsg->mmsAttrib.expiryTime.time = pSendOptInfo->option.mmsSendOptInfo.expiryTime.time;
1459 pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = pSendOptInfo->option.mmsSendOptInfo.bUseDeliveryCustomTime;
1460 pMmsMsg->mmsAttrib.deliveryTime.type = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.type;
1461 pMmsMsg->mmsAttrib.deliveryTime.time = pSendOptInfo->option.mmsSendOptInfo.deliveryTime.time;
1464 MSG_DEBUG("pSendOptInfo->bSetting = %d", pSendOptInfo->bSetting);
1465 MSG_DEBUG("pMmsMsg->mmsAttrib.bLeaveCopy = %d", pMmsMsg->mmsAttrib.bLeaveCopy);
1467 MSG_DEBUG("pMmsMsg->mmsAttrib.bUseDeliveryCustomTime = %d", pMmsMsg->mmsAttrib.bUseDeliveryCustomTime);
1468 MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.type = %d", pMmsMsg->mmsAttrib.deliveryTime.type);
1469 MSG_DEBUG("pMmsMsg->mmsAttrib.deliveryTime.time = %d", pMmsMsg->mmsAttrib.deliveryTime.time);
1471 MSG_DEBUG("pMmsMsg->mmsAttrib.priority = %d", pMmsMsg->mmsAttrib.priority);
1473 MSG_DEBUG("pMmsMsg->mmsAttrib.bAskDeliveryReport = %d", pMmsMsg->mmsAttrib.bAskDeliveryReport);
1474 MSG_DEBUG("pMmsMsg->mmsAttrib.bAskReadReply = %d", pMmsMsg->mmsAttrib.bAskReadReply);
1476 MSG_DEBUG("pMmsMsg->mmsAttrib.expiryTime.type = %d", pMmsMsg->mmsAttrib.expiryTime.type);
1477 MSG_DEBUG("pMmsMsg->mmsAttrib.expiryTime.time = %d", pMmsMsg->mmsAttrib.expiryTime.time);
1479 /* MMS-1.3-con-739 */
1480 pMmsMsg->mmsAttrib.msgClass = (MmsMsgClass)MsgSettingGetInt(MMS_SEND_MSG_CLASS);
1481 /* MMS-1.3-con-739 */
1482 #ifdef MMS_13_CON_742_ENABLED
1483 /* MMS-1.3-con-742 */
1484 pMmsMsg->mmsAttrib.deliveryTime.time = (unsigned int)MsgSettingGetInt(MMS_SEND_DELIVERY_TIME);
1485 /* MMS-1.3-con-742 */
1490 timeInfo = localtime(&RawTime);
1491 nTimeInSecs = mktime(timeInfo);
1492 pMmsMsg->mmsAttrib.date = nTimeInSecs; // todo: need to subtract timeline value to make GMT+0 time
1495 strcpy(pMmsMsg->mmsAttrib.szSubject, pMsgInfo->subject);
1498 MmsSetMsgAddressList(&pMmsMsg->mmsAttrib, pMsgInfo);
1500 //default type mixed
1501 pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
1502 pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_MIXED;
1504 int pageCnt = _MsgMmsGetPageCount(pMsgData);
1506 if (pageCnt > 0) { // Multipart related
1508 int RawDataSize = 0;
1512 snprintf(pMsgData->szSmilFilePath, MSG_FILEPATH_LEN_MAX, "%lu", RawTime);
1514 MsgMMSCreateSMIL(pMsgData);
1516 RawDataSize = MmsGetSmilRawData(pMsgData, &pRawData);
1517 if (RawDataSize < 0) {
1518 MSG_DEBUG("Smil file size is less than 0");
1521 MSG_DEBUG("%s", pRawData);
1523 MmsInsertPresentation(pMmsMsg, MIME_APPLICATION_SMIL, NULL, pRawData, strlen(pRawData));
1525 pMmsMsg->mmsAttrib.contentType = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
1526 pMmsMsg->msgType.type = MIME_APPLICATION_VND_WAP_MULTIPART_RELATED;
1530 if (pMmsMsg->msgType.type == MIME_APPLICATION_VND_WAP_MULTIPART_RELATED) {
1532 int pageCnt = _MsgMmsGetPageCount(pMsgData);
1534 for (int i = 0; i < pageCnt; ++i) {
1535 MMS_PAGE_S *pPage = _MsgMmsGetPage(pMsgData, i);
1536 int mediaCnt = pPage->mediaCnt;
1537 MSG_DEBUG("PAGE %d's media Cnt: %d", i+1, mediaCnt);
1539 for (int j = 0; j < mediaCnt; ++j) {
1540 MMS_MEDIA_S *pMedia = _MsgMmsGetMedia(pPage, j);
1541 if (pMedia->szFilePath[0] != 0) {
1542 MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
1544 snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szContentID);
1545 snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szContentLocation);
1546 snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
1547 snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
1548 snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
1550 if (!MmsInsertPartFromMultipart(pMmsMsg, pMultipart)) {
1564 //Processing Attachment List
1565 for (int i = 0; i < _MsgMmsGetAttachCount(pMsgData); ++i) {
1566 MMS_ATTACH_S *pMedia = _MsgMmsGetAttachment(pMsgData, i);
1567 if (pMedia->szFilePath[0] != 0) {
1568 MMS_MULTIPART_DATA_S *pMultipart = (MMS_MULTIPART_DATA_S *)calloc(1, sizeof(MMS_MULTIPART_DATA_S));
1570 snprintf(pMultipart->szContentID, sizeof(pMultipart->szContentID), "%s", pMedia->szFileName);
1571 snprintf(pMultipart->szContentLocation, sizeof(pMultipart->szContentLocation), "%s", pMedia->szFileName);
1572 snprintf(pMultipart->szFileName, sizeof(pMultipart->szFileName), "%s", pMedia->szFileName);
1573 snprintf(pMultipart->szFilePath, sizeof(pMultipart->szFilePath), "%s", pMedia->szFilePath);
1574 snprintf(pMultipart->szContentType, sizeof(pMultipart->szContentType), "%s", pMedia->szContentType);
1576 if (!MmsInsertPartFromMultipart(pMmsMsg, pMultipart)) {
1591 int MmsUpdatePreviewData(MSG_MESSAGE_INFO_S *pMsgInfo)
1595 MMS_MESSAGE_DATA_S msgData = {0,};
1597 MmsPluginStorage::instance()->getMmsMessage(&pMmsMsg);
1599 MmsReleaseMmsMsg(pMmsMsg);
1601 if (MmsReadMsgBody(pMsgInfo->msgId, true, false, NULL) == false) {
1602 MSG_DEBUG("Fail to MmsReadMsgBody");
1606 if (MmsMakeMmsData(pMmsMsg, &msgData) == false) {
1607 MSG_DEBUG("Fail to makeMmsMessageData");
1611 MmsMakePreviewInfo(pMsgInfo->msgId, &msgData);
1613 MmsPluginStorage::instance()->getMsgText(&msgData, pMsgInfo->msgText);
1615 MmsReleaseMmsMsg(pMmsMsg);
1616 MsgMmsReleaseMmsLists(&msgData);
1622 MmsReleaseMmsMsg(pMmsMsg);
1623 MsgMmsReleaseMmsLists(&msgData);