summaryrefslogtreecommitdiff
path: root/src/Messaging/IMessage.cpp
blob: d989c56c4207eaa1fa6f9dfca837161838fed947 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
//
// Tizen Web Device API
// Copyright (c) 2012 Samsung Electronics Co., Ltd.
//
// Licensed under the Apache License, Version 2.0 (the License);
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.
//

#include <pcrecpp.h>
#include <Commons/Exception.h>
#include "IMessage.h"
#include "EventSendMessage.h"
#include "EventMessagingService.h"
#include <Logger.h>

using namespace std;

namespace DeviceAPI {
namespace Messaging {

IMessage::IMessage(const MessageType msgType,
        const string& id) :
    m_id(id),
    m_convId(-1),
    m_msgType(msgType),
    m_readStatus(false),
    m_validReadStatus(false),
    m_isReadChangeStatus(false),
    m_validisReadChangeStatus(true),
    m_folder(DRAFTBOX),
    m_folderId(-1),
    m_requestReceiver(NULL),
    m_sendMessageEvent(NULL)
{
    LoggerD("message creation, msgId=" << m_id << ", msgType=" << m_msgType);

    //initialize dateTime of message
    time_t rawtime;
    time(&rawtime);
    tm* local = localtime(&rawtime);
    if (local) {
        m_dateTime = *local;
    } else {
        LoggerE("Failed to initialize message dateTime");
    }
}

IMessage::~IMessage()
{
    LoggerD("destroying message, msgId=" << m_id << ", msgType=" << m_msgType);
}

string IMessage::getId() const
{
    return m_id;
}

int IMessage::getConvId() const
{
    return m_convId;
}

const string& IMessage::getIdRef() const
{
    return m_id;
}

MessageType IMessage::getMessageType() const
{
    return m_msgType;
}

struct tm IMessage::getDateTime() const
{
    return m_dateTime;
}

string IMessage::convertId(int arg) const
{
    ostringstream stream;
    stream << arg;
    return stream.str();
}

int IMessage::convertId(const string& arg) const
{
    int retVal = 0;
    istringstream(arg) >> retVal;
    return retVal;
}

void IMessage::setId(const string& value)
{
    m_id = value;
}

void IMessage::setConvId(int value)
{
    m_convId = value;
}

void IMessage::setDateTime(const tm dateTime)
{
    m_dateTime = dateTime;
}

void IMessage::setReadStatus(bool state)
{
    m_validReadStatus = false;
    m_readStatus = state;
}

void IMessage::setSize(int size)
{
    m_size = size;
}

int IMessage::getSize() const
{
    return m_size;
}

bool IMessage::isRead() const
{
    return m_readStatus;
}

bool IMessage::isReadStatusValid() const
{
    return m_validReadStatus;
}

void IMessage::setReadStatusValidity(bool valid)
{
    m_validReadStatus = valid;
}

bool IMessage::isReadChangeStatus() const
{
    return m_isReadChangeStatus;
}

void IMessage::setisReadChangeStatus(bool state)
{
    m_validisReadChangeStatus = false;
    m_isReadChangeStatus = state;
}

bool IMessage::isReadChangeStatusValid() const
{
    return m_validisReadChangeStatus;
}

void IMessage::setisReadChangeStatusValidity(bool valid)
{
    m_validisReadChangeStatus = valid;
}

FolderType IMessage::getCurrentFolder() const
{
    return m_folder;
}

void IMessage::setFolderType(FolderType folder)
{
    m_folder = folder;
}

string IMessage::getCurrentUserFolder() const
{
    if (m_folder != USERDEFINED_FOLDER) {
        LoggerE("folder is not user folder type");
        Throw(WrtDeviceApis::Commons::UnknownException);
    }
    return m_userFolderName;
}

void IMessage::setCurrentUserFolder(const std::string& arg)
{
    m_userFolderName = arg;
}

int IMessage::getCurrentFolderId() const
{
    return m_folderId;
}

void IMessage::setCurrentFolderId(int folderId)
{
    m_folderId = folderId;
}


bool IMessage::validatePhoneNumber(std::string& number)
{
    LoggerD("testing number=" << number);
    return true;
/*
    pcrecpp::RE re("[^0-9#\\+\\*]?");
    re.GlobalReplace("", &number);	//remove invailde phone number. phone Number were composed only number.
    
    if (number.empty()) {
        LoggerE("wrong phoneNumber=" << number);
        return false;
    }
    LoggerD("phoneNumber=" << number);

    pcrecpp::RE re2("^[+#]?[0-9]{1,22}$");
    if (re2.FullMatch(number)) {
        LoggerD("vaildate Number=" << number);
        return true;
    }
    else
    {
        LoggerD("invaildate Number=" << number);
    	  return false;
    }
*/
}

bool IMessage::validateEmailAddr(const Recipients& addr)
{
    for (size_t i = 0; i < addr.getRecipientSize(); i++) {
        if (false == validateEmailAddr(addr.getRecipient(i))) {
            LoggerE("wrong email address");
            return false;
        }
    }
    return true;
}

bool IMessage::validateEmailAddr(const std::string& email)
{
    if (email.empty()) {
        return false;
    }
    pcrecpp::RE re(
        "^([a-zA-Z0-9_\\-\\.]+)@((\\[[0-9]{1,3}"
        "\\.[0-9]{1,3}\\.[0-9]{1,3}\\.)|(([a-zA-Z0-9\\-]+\\"
        ".)+))([a-zA-Z]{2,4}|[0-9]{1,3})(\\]?)$"
        );
    if (re.FullMatch(email)) {
        LoggerD("emailAddress=" << email);
        return true;
    }
    LoggerE("wrong emailAddress=" << email);
    return false;
}

void IMessage::setEmitter(const EventOnSendingFailedEmitterPtr& emitter)
{
    m_emitter = emitter;
}

EventOnSendingFailedEmitterPtr IMessage::getEmitter() const
{
    return m_emitter;
}

void IMessage::setSendMessageEvent(const EventSendMessagePtr &event)
{
    m_sendMessageEvent = event;
}

EventSendMessagePtr IMessage::getSendMessageEvent() const
{
    return m_sendMessageEvent;
}

void IMessage::setMessagingServiceEvent(const EventMessagingServicePtr & event)
{
	m_messagingServiceEvent = event;
}

EventMessagingServicePtr IMessage::getMessagingServiceEvent() const
{
	return m_messagingServiceEvent;
}

void IMessage::setRequestReceiver(ReqReceiverMessage* reqReceiver)
{
    m_requestReceiver = reqReceiver;
}

ReqReceiverMessage* IMessage::getRequestReceiver() const
{
    return m_requestReceiver;
}

void IMessage::setMessageStatus( MessageStatus status)
{
	LoggerD("setMessageStatus : " << status);
	m_msgStatus = status;
}

MessageStatus IMessage::getMessageStatus() const
{
	return m_msgStatus;
}

}
}