2 * Copyright (c) 2014 Samsung Electronics Co., Ltd. All rights reserved
4 * Licensed under the Apache License, Version 2.0 (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://www.apache.org/licenses/LICENSE-2.0
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.
17 #include "MsgMmsMessage.h"
18 #include "MmsPluginDebug.h"
19 #include "MmsPluginStorage.h"
20 #include "MmsPluginMessage.h"
21 #include "MmsPluginMIME.h"
22 #include "MmsPluginAppBase.h"
23 #include "MmsPluginUtil.h"
24 #include "MmsPluginTcs.h"
25 #include "MsgUtilFile.h"
27 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath);
29 MmsPluginAppBase::MmsPluginAppBase()
31 memset(&mmsMsgData, 0x00, sizeof(mmsMsgData));
34 MmsPluginAppBase::MmsPluginAppBase(MMS_DATA_S *pMmsData)
39 MmsPluginAppBase::MmsPluginAppBase(MmsMsg *pMmsMsg)
44 MmsPluginAppBase::~MmsPluginAppBase()
46 MsgMmsReleaseMmsLists(&mmsMsgData);
49 void MmsPluginAppBase::setMmsData(MmsMsg *pMmsMsg)
51 MmsConvertMsgData(pMmsMsg, &mmsMsgData);
54 void MmsPluginAppBase::setMmsData(MMS_DATA_S *pMmsData)
56 MsgMmsConvertMmsDataToMmsMessageData(pMmsData, &mmsMsgData);
59 void MmsPluginAppBase::makePreviewInfo(msg_message_id_t msgId, bool allow_malware, const char *raw_filepath)
61 MmsMakePreviewInfo(msgId, &mmsMsgData, allow_malware, raw_filepath);
64 void MmsPluginAppBase::getFirstPageTextFilePath(char *textBuf, int textBufSize)
67 MMS_PAGE_S *pPage = NULL;
68 MMS_MEDIA_S *pMedia = NULL;
70 MMS_MESSAGE_DATA_S *pMmsMsgData = &mmsMsgData;
72 if (pMmsMsgData == NULL)
75 // Get the text data from the 1st slide.
76 if (pMmsMsgData->pageCnt > 0) {
78 pPage = _MsgMmsGetPage(pMmsMsgData, 0);
82 for (int j = 0; j < pPage->mediaCnt; ++j) {
84 pMedia = _MsgMmsGetMedia(pPage, j);
86 if (pMedia && pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
88 MimeType mimeType = MIME_UNKNOWN;
90 MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
92 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
93 MSG_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
95 MSG_DEBUG("Text path : [%s]", pMedia->szFilePath);
96 snprintf(textBuf, textBufSize, "%s", pMedia->szFilePath);//Set Text Filepath of First Pages
108 //FIXME::need to move AppBase
109 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath)
111 MMS_PAGE_S *pPage = NULL;
112 MMS_MEDIA_S *pMedia = NULL;
115 int ref_attach_count = 0;
116 const char * attachment_name = NULL;
119 return MSG_ERR_NULL_POINTER;
121 MmsPluginStorage::instance()->removePreviewInfo(msgId); //remove exist previnfo
123 //scan malware in raw file
124 if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
125 int tcs_ret = 0; // MmsPluginTcsScanFile(raw_filepath, &bc_level);
128 MSG_DEBUG("malware exist, level = %d", bc_level);
129 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_MALWARE, "malware", bc_level);
134 //check ref type and increase attach count
135 if (pMmsMsg->pageCnt > 0) {
136 for (int i = 0; i < pMmsMsg->pageCnt; i++) {
137 pPage = _MsgMmsGetPage(pMmsMsg, i);
139 for (int j = 0; j < pPage->mediaCnt; j++) {
140 pMedia = _MsgMmsGetMedia(pPage, j);
141 if (pMedia) { //IF Vobject type add to Attach in Preview data
143 MimeType mimeType = MIME_UNKNOWN;
144 MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
145 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD) {
147 MSG_DEBUG("Unsupported File [%s] It will be add to attach list", pMedia->szFilePath);
151 if (attachment_name == NULL) {
152 attachment_name = pMedia->szFileName;
163 if (pMmsMsg->pageCnt > 0) {
165 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
167 pPage = _MsgMmsGetPage(pMmsMsg, 0);
170 for (int j = 0; j < pPage->mediaCnt; j++) {
172 pMedia = _MsgMmsGetMedia(pPage, j);
174 if (pMedia == NULL) {
175 MSG_ERR("[%d]th pMedia is NULL", j);
179 MSG_SEC_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
181 if (allow_malware == false && bc_level > -1) {
182 if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
183 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
187 if (j == 0) { //First Page, First Media
188 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_1ST_MEDIA, pMedia->szFilePath);
191 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
192 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
193 char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
196 memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
197 memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
199 MSG_DEBUG("drm type = %d, %s", pMedia->drmType, pMedia->szFilePath);
201 if (pMedia->drmType == MSG_DRM_TYPE_NONE) {
203 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
205 if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
206 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.png", MSG_THUMBNAIL_PATH, szFileName);
208 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
211 if (MmsMakeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
212 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
213 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
215 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
218 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
221 } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
222 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
228 MSG_DEBUG("There is no page");
231 int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
234 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
236 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
237 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt); // for Get Message
239 if (attachment_name == NULL) {
240 attachment_name = pAttach->szFileName;
244 MSG_DEBUG("There is no attachment");
247 if (attachCnt + ref_attach_count > 0 && attachment_name) {
249 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, attachment_name, attachCnt + ref_attach_count);
250 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt + ref_attach_count);