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 MmsPluginAppBase::MmsPluginAppBase(MMS_DATA_S *pMmsData)
36 MmsPluginAppBase::MmsPluginAppBase(MmsMsg *pMmsMsg)
41 MmsPluginAppBase::~MmsPluginAppBase()
43 MsgMmsReleaseMmsLists(&mmsMsgData);
46 void MmsPluginAppBase::setMmsData(MmsMsg *pMmsMsg)
48 MmsConvertMsgData(pMmsMsg, &mmsMsgData);
51 void MmsPluginAppBase::setMmsData(MMS_DATA_S *pMmsData)
53 MsgMmsConvertMmsDataToMmsMessageData(pMmsData, &mmsMsgData);
56 void MmsPluginAppBase::makePreviewInfo(msg_message_id_t msgId, bool allow_malware, const char *raw_filepath)
58 MmsMakePreviewInfo(msgId, &mmsMsgData, allow_malware, raw_filepath);
61 void MmsPluginAppBase::getFirstPageTextFilePath(char *textBuf, int textBufSize)
64 MMS_PAGE_S *pPage = NULL;
65 MMS_MEDIA_S *pMedia = NULL;
67 MMS_MESSAGE_DATA_S *pMmsMsgData = &mmsMsgData;
69 if (pMmsMsgData == NULL)
72 // Get the text data from the 1st slide.
73 if (pMmsMsgData->pageCnt > 0) {
75 pPage = _MsgMmsGetPage(pMmsMsgData, 0);
79 for (int j = 0; j < pPage->mediaCnt; ++j) {
81 pMedia = _MsgMmsGetMedia(pPage, j);
83 if (pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
85 MimeType mimeType = MIME_UNKNOWN;
87 MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
89 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
90 MSG_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
92 MSG_DEBUG("Text path : [%s]", pMedia->szFilePath);
93 snprintf(textBuf, textBufSize, "%s", pMedia->szFilePath);//Set Text Filepath of First Pages
105 //FIXME::need to move AppBase
106 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath)
108 MMS_PAGE_S *pPage = NULL;
109 MMS_MEDIA_S *pMedia = NULL;
112 int ref_attach_count = 0;
113 const char * attachment_name = NULL;
116 return MSG_ERR_NULL_POINTER;
118 MmsPluginStorage::instance()->removePreviewInfo(msgId); //remove exist previnfo
120 //scan malware in raw file
121 if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
122 int tcs_ret = 0; // MmsPluginTcsScanFile(raw_filepath, &bc_level);
125 MSG_DEBUG("malware exist, level = %d", bc_level);
126 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_MALWARE, "malware", bc_level);
131 //check ref type and increase attach count
132 if (pMmsMsg->pageCnt > 0) {
133 for (int i = 0; i < pMmsMsg->pageCnt; i++) {
134 pPage = _MsgMmsGetPage(pMmsMsg, i);
136 for (int j = 0; j < pPage->mediaCnt; j++) {
137 pMedia = _MsgMmsGetMedia(pPage, j);
138 if (pMedia) { //IF Vobject type add to Attach in Preview data
140 MimeType mimeType = MIME_UNKNOWN;
141 MmsGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
142 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD) {
144 MSG_DEBUG("Unsupported File [%s] It will be add to attach list", pMedia->szFilePath);
148 if (attachment_name == NULL) {
149 attachment_name = pMedia->szFileName;
160 if (pMmsMsg->pageCnt > 0) {
162 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
164 pPage = _MsgMmsGetPage(pMmsMsg, 0);
167 for (int j = 0; j < pPage->mediaCnt; j++) {
169 pMedia = _MsgMmsGetMedia(pPage, j);
171 if (pMedia == NULL) {
172 MSG_ERR("[%d]th pMedia is NULL", j);
176 MSG_SEC_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
178 if (allow_malware == false && bc_level > -1) {
179 if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
180 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
184 if (j == 0) { //First Page, First Media
185 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_1ST_MEDIA, pMedia->szFilePath);
188 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
189 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
190 char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
193 memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
194 memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
196 MSG_DEBUG("drm type = %d, %s", pMedia->drmType, pMedia->szFilePath);
198 if (pMedia->drmType == MSG_DRM_TYPE_NONE) {
200 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
202 if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
203 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.png", MSG_THUMBNAIL_PATH, szFileName);
205 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
208 if (MmsMakeImageThumbnail(pMedia->szFilePath, thumbPath) == true) {
209 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
210 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
212 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
215 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
218 } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
219 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
225 MSG_DEBUG("There is no page");
228 int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
231 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
233 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
234 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt); // for Get Message
236 if (attachment_name == NULL) {
237 attachment_name = pAttach->szFileName;
241 MSG_DEBUG("There is no attachment");
244 if (attachCnt + ref_attach_count > 0 && attachment_name) {
246 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, attachment_name, attachCnt + ref_attach_count);
247 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt + ref_attach_count);