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)
66 MMS_PAGE_S *pPage = NULL;
67 MMS_MEDIA_S *pMedia = NULL;
69 MMS_MESSAGE_DATA_S *pMmsMsgData = &mmsMsgData;
71 if (pMmsMsgData == NULL)
74 /* Get the text data from the 1st slide. */
75 if (pMmsMsgData->pageCnt > 0) {
77 pPage = _MsgMmsGetPage(pMmsMsgData, 0);
81 for (int j = 0; j < pPage->mediaCnt; ++j) {
83 pMedia = _MsgMmsGetMedia(pPage, j);
85 if (pMedia && pMedia->mediatype == MMS_SMIL_MEDIA_TEXT) {
87 MimeType mimeType = MIME_UNKNOWN;
89 MsgGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
91 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD || mimeType == MIME_TEXT_X_VTODO || mimeType == MIME_TEXT_X_VNOTE) {
92 MSG_SEC_DEBUG("Media Type is Text, but Vobject file [%s]", pMedia->szFilePath);
94 MSG_SEC_DEBUG("Text path : [%s]", pMedia->szFilePath);
95 snprintf(textBuf, textBufSize, "%s", pMedia->szFilePath); /* Set Text Filepath of First Pages */
103 * Set filepath of the first text/plain attachment to display preview text on notification */
104 if (pMmsMsgData->attachlist) {
105 GList *l = pMmsMsgData->attachlist;
107 MMS_ATTACH_S *attach = (MMS_ATTACH_S *)l->data;
108 if (g_strcmp0(attach->szContentType, "text/plain") == 0) {
109 MSG_SEC_DEBUG("The first text filepath for multipart: (%s)", attach->szFilePath);
110 snprintf(textBuf, textBufSize, "%s", attach->szFilePath);
123 /* FIXME::need to move AppBase */
124 msg_error_t MmsMakePreviewInfo(int msgId, MMS_MESSAGE_DATA_S *pMmsMsg, bool allow_malware, const char *raw_filepath)
126 MMS_PAGE_S *pPage = NULL;
127 MMS_MEDIA_S *pMedia = NULL;
130 int ref_attach_count = 0;
131 const char * attachment_name = NULL;
134 return MSG_ERR_NULL_POINTER;
136 MmsPluginStorage::instance()->removePreviewInfo(msgId); /* remove exist previnfo */
138 /* scan malware in raw file */
139 if (raw_filepath && strlen(raw_filepath) > 0 && MsgAccessFile(raw_filepath, F_OK) == true) {
140 int tcs_ret = 0; // MmsPluginTcsScanFile(raw_filepath, &bc_level);
143 MSG_DEBUG("malware exist, level = %d", bc_level);
144 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_MALWARE, "malware", bc_level);
149 /* check ref type and increase attach count */
150 if (pMmsMsg->pageCnt > 0) {
151 for (int i = 0; i < pMmsMsg->pageCnt; i++) {
152 pPage = _MsgMmsGetPage(pMmsMsg, i);
154 for (int j = 0; j < pPage->mediaCnt; j++) {
155 pMedia = _MsgMmsGetMedia(pPage, j);
156 if (pMedia) { /* IF Vobject type add to Attach in Preview data */
158 MimeType mimeType = MIME_UNKNOWN;
159 MsgGetMimeTypeFromFileName(MIME_MAINTYPE_UNKNOWN, pMedia->szFilePath, &mimeType, NULL);
160 if (mimeType == MIME_TEXT_X_VCALENDAR || mimeType == MIME_TEXT_X_VCARD) {
162 MSG_DEBUG("Unsupported File [%s] It will be add to attach list", pMedia->szFilePath);
166 if (attachment_name == NULL) {
167 attachment_name = pMedia->szFileName;
178 if (pMmsMsg->pageCnt > 0) {
180 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_PAGE, (char *)"pagecount", pMmsMsg->pageCnt);
182 pPage = _MsgMmsGetPage(pMmsMsg, 0);
185 for (int j = 0; j < pPage->mediaCnt; j++) {
187 pMedia = _MsgMmsGetMedia(pPage, j);
189 if (pMedia == NULL) {
190 MSG_ERR("[%d]th pMedia is NULL", j);
194 MSG_SEC_DEBUG("pMedia's Name: %s", pMedia->szFilePath);
196 if (allow_malware == false && bc_level > -1) {
197 if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
198 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
202 if (j == 0) { /* First Page, First Media */
203 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_1ST_MEDIA, pMedia->szFilePath);
206 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG || pMedia->mediatype == MMS_SMIL_MEDIA_VIDEO) {
207 char szFileName[MSG_FILENAME_LEN_MAX+1] = {0, };
208 char thumbPath[MSG_FILEPATH_LEN_MAX+1] = {0, };
211 memset(szFileName, 0x00, MSG_FILENAME_LEN_MAX+1);
212 memset(thumbPath, 0x00, MSG_FILEPATH_LEN_MAX);
214 MSG_SEC_DEBUG("drm type = %d, %s", pMedia->drmType, pMedia->szFilePath);
216 if (pMedia->drmType == MSG_DRM_TYPE_NONE) {
218 snprintf(szFileName, MSG_FILENAME_LEN_MAX+1, "%d.mms",msgId);
220 if ((pszExt = strrchr(pMedia->szFilePath, '.')) != NULL && !strcasecmp(pszExt, ".png")) {
221 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.png", MSG_THUMBNAIL_PATH, szFileName);
223 snprintf(thumbPath, MSG_FILEPATH_LEN_MAX, "%s%s.jpg", MSG_THUMBNAIL_PATH, szFileName);
226 if (MakeThumbnail(pMedia->szFilePath, thumbPath) == true) {
227 if (pMedia->mediatype == MMS_SMIL_MEDIA_IMG) {
228 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_IMG, thumbPath);
230 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_VIDEO, thumbPath);
233 MSG_DEBUG("Fail of generating thumbnail: %s to %s", pMedia->szFilePath, thumbPath);
236 } else if (pMedia->mediatype == MMS_SMIL_MEDIA_AUDIO) {
237 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_AUDIO, pMedia->szFileName);
243 MSG_DEBUG("There is no page");
246 int attachCnt = _MsgMmsGetAttachCount(pMmsMsg);
249 MMS_ATTACH_S *pAttach = _MsgMmsGetAttachment(pMmsMsg, 0);
251 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, pAttach->szFileName, attachCnt);
252 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt); /* for Get Message */
254 if (attachment_name == NULL) {
255 attachment_name = pAttach->szFileName;
259 MSG_DEBUG("There is no attachment");
262 if (attachCnt + ref_attach_count > 0 && attachment_name) {
264 MmsPluginStorage::instance()->insertPreviewInfo(msgId, MSG_MMS_ITEM_TYPE_ATTACH, attachment_name, attachCnt + ref_attach_count);
265 MmsPluginStorage::instance()->updateMmsAttachCount(msgId, attachCnt + ref_attach_count);