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 "MmsPluginAppBase.h"
22 #include "MmsPluginUtil.h"
23 #include "MsgUtilFile.h"
24 #include "MsgUtilMime.h"
26 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath);
28 MmsPluginAppBase::MmsPluginAppBase()
30 memset(&mmsMsgData, 0x00, sizeof(mmsMsgData));
33 MmsPluginAppBase::MmsPluginAppBase(MMS_DATA_S *pMmsData)
38 MmsPluginAppBase::MmsPluginAppBase(MmsMsg *pMmsMsg)
43 MmsPluginAppBase::~MmsPluginAppBase()
45 MsgMmsReleaseMmsLists(&mmsMsgData);
48 void MmsPluginAppBase::setMmsData(MmsMsg *pMmsMsg)
50 MmsConvertMsgData(pMmsMsg, &mmsMsgData);
53 void MmsPluginAppBase::setMmsData(MMS_DATA_S *pMmsData)
55 MsgMmsConvertMmsDataToMmsMessageData(pMmsData, &mmsMsgData);
58 void MmsPluginAppBase::makePreviewInfo(msg_message_id_t msgId, bool allow_malware, const char *raw_filepath)
60 MmsMakePreviewInfo(msgId, &mmsMsgData, allow_malware, raw_filepath);
63 void MmsPluginAppBase::getFirstPageTextFilePath(char *textBuf, int textBufSize)
65 MMS_PAGE_S *pPage = NULL;
66 MMS_MEDIA_S *pMedia = NULL;
68 MMS_MESSAGE_DATA_S *pMmsMsgData = &mmsMsgData;
70 if (pMmsMsgData == NULL)
73 /* Get the text data from the 1st slide. */
74 if (pMmsMsgData->pageCnt > 0) {
75 pPage = _MsgMmsGetPage(pMmsMsgData, 0);
78 for (int j = 0; j < pPage->mediaCnt; ++j) {
79 pMedia = _MsgMmsGetMedia(pPage, j);
81 if (pMedia && pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
82 MimeType mimeType = MIME_UNKNOWN;
84 MsgGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
86 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
87 MSG_SEC_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
89 MSG_SEC_DEBUG("Text path : [%s]", pMedia->szFilePath);
90 snprintf(textBuf, textBufSize, "%s", pMedia->szFilePath); /* Set Text Filepath of First Pages */
97 /* Set filepath of the first text/plain attachment to display preview text on notification */
98 if (pMmsMsgData->attachlist) {
99 GList *l = pMmsMsgData->attachlist;
101 MMS_ATTACH_S *attach = (MMS_ATTACH_S *)l->data;
102 if (g_strcmp0(attach->szContentType, "text/plain") == 0) {
103 MSG_SEC_DEBUG("The first text filepath for multipart: (%s)", attach->szFilePath);
104 snprintf(textBuf, textBufSize, "%s", attach->szFilePath);
117 /* FIXME::need to move AppBase */
118 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath)
120 MMS_PAGE_S *pPage = NULL;
121 MMS_MEDIA_S *pMedia = NULL;
124 int ref_attach_count = 0;
125 const char * attachment_name = NULL;
128 return MSG_ERR_NULL_POINTER;
130 MmsPluginStorage::instance()->removePreviewInfo(msgId); /* remove exist previnfo */
132 /* scan malware in raw file */
133 if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
134 int tcs_ret = MsgTcsScanFile(raw_filepath, &bc_level);
137 MSG_DEBUG("malware exist, level = %d", bc_level);
138 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_MALWARE, "malware", bc_level);
143 /* check ref type and increase attach count */
144 if (pMmsMsg->pageCnt > 0) {
145 for (int i = 0; i < pMmsMsg->pageCnt; i++) {
146 pPage = _MsgMmsGetPage(pMmsMsg, i);
148 for (int j = 0; j < pPage->mediaCnt; j++) {
149 pMedia = _MsgMmsGetMedia(pPage, j);
150 if (pMedia) { /* IF Vobject type add to Attach in Preview data */
151 MimeType mimeType = MIME_UNKNOWN;
152 MsgGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
153 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD) {
154 MSG_DEBUG("Unsupported File [%s] It will be add to attach list", pMedia->szFilePath);
158 if (attachment_name == NULL) {
159 attachment_name = pMedia->szFileName;
169 if (pMmsMsg->pageCnt > 0) {
170 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
172 pPage = _MsgMmsGetPage(pMmsMsg, 0);
175 for (int j = 0; j < pPage->mediaCnt; j++) {
176 pMedia = _MsgMmsGetMedia(pPage, j);
178 if (pMedia == NULL) {
179 MSG_ERR("[%d]th pMedia is NULL", j);
183 MSG_SEC_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
185 if (allow_malware == false && bc_level > -1) {
186 if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
187 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
190 if (j == 0) { /* First Page, First Media */
191 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_1ST_MEDIA, pMedia->szFilePath);
194 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
195 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
196 char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
199 memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
200 memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
202 MSG_SEC_DEBUG("drm type = %d, %s", pMedia->drmType, pMedia->szFilePath);
204 if (pMedia->drmType == MSG_DRM_TYPE_NONE) {
205 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms", msgId);
207 if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
208 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.png", MSG_THUMBNAIL_PATH, szFileName);
210 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
213 if (MakeThumbnail(pMedia->szFilePath, thumbPath) == true) {
214 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
215 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
217 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
220 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
223 } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
224 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
230 MSG_DEBUG("There is no page");
233 int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
235 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
237 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
238 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt); /* for Get Message */
240 if (attachment_name == NULL) {
241 attachment_name = pAttach->szFileName;
244 MSG_DEBUG("There is no attachment");
247 if (attachCnt + ref_attach_count > 0 && attachment_name) {
248 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, attachment_name, attachCnt + ref_attach_count);
249 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt + ref_attach_count);