e66fcee5b3c5acd7d7dcbcdf0b01f138b1784644
[framework/web/wrt-plugins-tizen.git] / src / Messaging / Attachment.cpp
1 //
2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
4 //
5 // Licensed under the Apache License, Version 2.0 (the License);
6 // you may not use this file except in compliance with the License.
7 // You may obtain a copy of the License at
8 //
9 // http://www.apache.org/licenses/LICENSE-2.0
10 //
11 // Unless required by applicable law or agreed to in writing, software
12 // distributed under the License is distributed on an "AS IS" BASIS,
13 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14 // See the License for the specific language governing permissions and
15 // limitations under the License.
16 //
17
18 #include <algorithm>
19 #include <Commons/Exception.h>
20 #include "Attachment.h"
21
22 #include <Manager.h>
23 #include <INode.h>
24 #include <IManager.h>
25 #include <EventGetNodeData.h>
26
27 extern "C" {
28 #include <sys/stat.h>
29 #include <stdlib.h>
30 }
31
32 #include <Logger.h>
33
34 using namespace WrtDeviceApis::Commons;
35 using namespace std;
36
37 //--------------------------------------------------------------------------
38 namespace DeviceAPI {
39 namespace Messaging {
40
41 Attachment::Attachment()
42 {
43     LoggerD("entered");
44 }
45
46 Attachment::Attachment(const string& fullPath,
47         bool isVirtualPath)
48 {
49     LoggerD("entered");
50     init(fullPath, isVirtualPath);
51 }
52
53 /*
54 Attachment::Attachment(email_attachment_info_t* att)
55 {
56     LoggerD("entered");
57
58     m_attachShortName = std::string(att->name); //set shot Name
59     m_isDownloaded = att->downloaded;
60     m_attachmentID = att->attachment_id;
61         
62     LoggerD(" showname = " << m_attachShortName << " isDownloaded = " << m_isDownloaded << " attachmentID = " << m_attachmentID);
63     LoggerD("save name is = " << att->savename);
64     if ( att->savename )
65     {
66         init( att->savename, false);
67     }
68 }
69 */
70 Attachment::Attachment(email_attachment_data_t* att)
71 {
72         LoggerD("entered");
73
74         m_attachShortName = std::string(att->attachment_name);
75         m_isDownloaded = att->save_status;
76         m_attachmentID = att->attachment_id;    
77         m_isInlineAttachment =  att->inline_content_status;
78         //m_mimeType = std::string(att->attachment_mime_type);
79         LoggerD(" showname = " << m_attachShortName << " isDownloaded = " << m_isDownloaded << " attachmentID = " << m_attachmentID << "Mime= " << m_mimeType);
80         LoggerD("save name is = " << att->attachment_path << "isInlineAttachment = " << m_isInlineAttachment);
81
82         if ( att->attachment_path)
83         {
84                 init( att->attachment_path, false);
85         }
86 }
87
88 /*
89 Attachment::Attachment(const std::string& fullPath, bool isVirtualPath, 
90         const DeviceAPI::Filesystem::INode& inode):
91         DeviceAPI::Filesystem::INode(inode)
92 {
93         LoggerD("entered , inode");
94         init(fullPath, isVirtualPath);  
95 }
96 */
97
98 #if 0
99 Attachment::Attachment(const std::string& fullPath, bool isVirtualPath, const DeviceAPI::Filesystem::INode& inode):
100         IAttachment(inode)
101 {
102         LoggerD("entered , inode");
103         init(fullPath, isVirtualPath);  
104 }
105 #endif 
106
107 std::string Attachment::getRealPath(const std::string &path) const
108 {
109
110 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
111     Try
112     {
113         DeviceAPI::Filesystem::IPathPtr currentPath = DeviceAPI::Filesystem::IPath::create(
114                 path);
115         return currentPath->getFullPath();
116     }
117
118     Catch(WrtDeviceApis::Commons::Exception) {
119         LoggerE("invalid path");
120         ReThrow(WrtDeviceApis::Commons::InvalidArgumentException);
121     }
122 #endif
123
124         LoggerD(" path = " << path);
125
126         return path;
127
128 }
129
130 }
131 }
132