Update change log and spec for wrt-plugins-tizen_0.4.12
[framework/web/wrt-plugins-tizen.git] / src / Messaging / JSMessage.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 <dpl/assert.h>
19 #include "MessageFactory.h"
20 #include "MessagePriority.h"
21 #include <CommonsJavaScript/JSCallbackManager.h>
22 #include <CommonsJavaScript/JSUtils.h>
23 #include <CommonsJavaScript/Utils.h>
24 #include "ConverterMessage.h"
25 #include "JSMessage.h"
26 #include "JSRecipientArray.h"
27 #include "JSMessagePrivateObject.h"
28 #include "MessagingListener.h"
29 #include "ReqReceiverMessage.h"
30
31 #include <JSTizenExceptionFactory.h>
32 #include <JSTizenException.h>
33 #include <SecurityExceptions.h>
34
35 #include <CommonsJavaScript/ScopedJSStringRef.h>
36
37 #include "MessagingErrorMsg.h"
38 #include "JSMessageAttachment.h"
39 #include "plugin_config.h"
40
41 #include "Sms.h"
42
43
44 using namespace std;
45 using namespace DeviceAPI::Messaging;
46 using namespace DeviceAPI::Common;
47 using namespace WrtDeviceApis::Commons;
48 using namespace DeviceAPI::Messaging;
49 using namespace WrtDeviceApis::CommonsJavaScript;
50
51 namespace DeviceAPI {
52 namespace Messaging {
53 JSClassRef JSMessage::m_jsClassRef = NULL;
54
55 JSClassDefinition JSMessage::m_classInfo = {
56         0,
57         kJSClassAttributeNone,
58         "Message",
59         0,
60         m_property,
61         NULL,           //m_function
62         initialize,
63         finalize,
64         NULL, //hasProperty,
65         NULL, //getProperty,
66         NULL, //setProperty,
67         NULL, //deleteProperty,
68         NULL, //getPropertyNames,
69         NULL, //callAsFunction,
70         constructor, //callAsConstructor,
71         NULL, //hasInstance,
72         NULL, //convertToType,
73 };
74
75 // JSMessage properties
76 JSStaticValue JSMessage::m_property[] = {
77         { "id", getMessageId, NULL, kJSPropertyAttributeReadOnly },
78         { "serviceId", getAccountID, NULL, kJSPropertyAttributeReadOnly},
79         { "conversationId", getConversationId, NULL, kJSPropertyAttributeReadOnly },
80         { "folderId", getFolder, NULL, kJSPropertyAttributeReadOnly },
81         { "type", getMessageType, NULL, kJSPropertyAttributeReadOnly },
82         { "timestamp", getTime, NULL, kJSPropertyAttributeReadOnly },
83         { "from", getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
84         { "to", getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
85         { "cc", getCcAddress, setCcAddress, kJSPropertyAttributeNone },
86         { "bcc", getBccAddress, setBccAddress, kJSPropertyAttributeNone },
87         { "body", getMessageBody, setMessageBody, kJSPropertyAttributeNone },
88         { "isRead", getIsRead, setIsRead, kJSPropertyAttributeNone },
89         //{ "hasAttachment", getAttachmentExistence, NULL, kJSPropertyAttributeReadOnly },
90         { "isHighPriority", getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
91         { "subject", getSubject, setSubject, kJSPropertyAttributeNone },
92         { "inResponseTo", getInResponseTo, NULL, kJSPropertyAttributeNone },
93         { "messageStatus", getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
94         { "attachments", getAttachments, setAttachments, kJSPropertyAttributeNone },
95         { "hasAttachment", hasAttachment, NULL, kJSPropertyAttributeReadOnly},
96         //{ "uid", getUID, NULL, kJSPropertyAttributeReadOnly},
97         { 0, 0, 0, 0 }
98 };
99
100 JSValueRef JSMessage::createJSObject(JSContextRef context,
101                 EmailAccountInfo& account,
102                 MessageType msgType,
103                 const std::string& msgId)
104 {
105         IMessagePtr msg;
106         LogDebug("createJSObject with account ");
107
108         Try
109         {
110                 if (msgType == EMAIL)
111                 {
112                         LogDebug("Account Address:" << &account);
113                         LogDebug("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
114
115                         msg = MessageFactory::createMessage(msgType, account, msgId);
116                         if (!msg)
117                                 return JSValueMakeUndefined(context);
118                 }
119                 else
120                 {
121                         Throw(WrtDeviceApis::Commons::UnknownException);   // unsupported type
122                 }
123         }
124         Catch(WrtDeviceApis::Commons::UnknownException) {
125                 LogError("wrong message type, object not created");
126                 return JSValueMakeUndefined(context);
127         }
128
129         return createJSObject(context, msg);
130 }
131
132 JSValueRef JSMessage::createJSObject(JSContextRef context,
133         EventUpdateMessageAnswerReceiver* listener,
134         MessageType msgType,
135         const string& msgId)
136 {
137         IMessagePtr msg;
138         Try
139         {
140                 // create message depending on type
141                 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
142                 {
143                         msg = MessageFactory::createMessage(msgType, msgId);
144                         if (!msg)
145                                 return JSValueMakeUndefined(context);
146                 }
147                 else
148                 {
149                         Throw(WrtDeviceApis::Commons::UnknownException);   // unsupported type
150                 }
151         }
152         Catch(WrtDeviceApis::Commons::UnknownException) {
153                 LogError("wrong message type, object not created");
154                 return JSValueMakeUndefined(context);
155         }
156         return createJSObject(context, msg, listener);
157 }
158
159 JSValueRef JSMessage::createJSObject(JSContextRef context,
160         const IMessagePtr& msg,
161         EventUpdateMessageAnswerReceiver* listener)
162 {
163         JSClassRef jsClassRef = JSClassCreate(getClassInfo());
164         JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
165         priv->setUpdateMsgReceiver(listener);
166         JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
167         JSClassRelease(jsClassRef);
168         if (NULL == jsValueRef) {
169                 LogError("object creation error");
170                 return JSValueMakeUndefined(context);
171         }
172         return jsValueRef;
173 }
174
175 JSValueRef JSMessage::createJSObject(JSContextRef context,
176         const IMessagePtr& msg)
177 {
178         LogDebug("createJSObject");
179         JSClassRef jsClassRef = JSClassCreate(getClassInfo());
180         LogDebug("jsClassRef success");
181         JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
182         LogDebug("priv success");
183
184         JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
185         LogDebug("JSObjectMake success");
186         JSClassRelease(jsClassRef);
187         if (NULL == jsValueRef) {
188                 LogError("object creation error");
189                 return JSValueMakeUndefined(context);
190         }
191         return jsValueRef;
192 }
193
194 JSValueRef JSMessage::createJSObject(JSContextRef context,
195         MessageType msgType,
196         const string& msgId)
197 {
198         IMessagePtr msg;
199         Try
200         {
201                 // create message depending on type
202                 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
203                 {
204                         msg = MessageFactory::createMessage(msgType, msgId);
205                 }
206                 else
207                 {
208                         Throw(WrtDeviceApis::Commons::UnknownException);   // unsupported type
209                 }
210         }
211         Catch(WrtDeviceApis::Commons::UnknownException) {
212                 LogError("wrong message type, object not created");
213                 return JSValueMakeUndefined(context);
214         }
215         return createJSObject(context, msg, NULL);
216 }
217
218 JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
219                 MessageType msgType)
220 {
221         IMessagePtr msg;
222         if (msgType == EMAIL )
223         {
224                 msg = MessageFactory::createEmailMessage();
225         }
226         else
227         {
228                 LogError("message type is invalid");
229                 Throw(WrtDeviceApis::Commons::InvalidArgumentException); 
230         }
231         return createJSObject(context, msg);
232 }
233
234 void JSMessage::initialize(JSContextRef context,
235         JSObjectRef object)
236 {
237         LogInfo("enter");
238
239         if (!JSObjectGetPrivate(object))
240         {
241                 IMessagePtr msg(new Sms());
242                 JSMessagePrivateObject *priv = new JSMessagePrivateObject(context, msg);
243                 if (!JSObjectSetPrivate(object, priv))
244                 {
245                         LogInfo("set Private Failed...");
246                         delete priv;
247                 }
248         }
249 }
250
251 void JSMessage::finalize(JSObjectRef object)
252 {
253         JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
254         if (priv) {
255                 LogDebug("deleting private object");
256                 delete priv;
257                 JSObjectSetPrivate(object, NULL);
258         }
259 }
260
261 bool JSMessage::hasProperty(JSContextRef context,
262         JSObjectRef object,
263         JSStringRef propertyName)
264 {
265         return false;
266 }
267
268 JSValueRef JSMessage::getProperty(JSContextRef context,
269         JSObjectRef object,
270         JSStringRef propertyName,
271         JSValueRef* exception)
272 {
273         LogError("should not enter");
274         return JSValueMakeUndefined(context);
275 }
276
277 bool JSMessage::setProperty(JSContextRef context,
278         JSObjectRef object,
279         JSStringRef propertyName,
280         JSValueRef value,
281         JSValueRef* exception)
282 {
283         LogError("should not enter");
284         return false;
285 }
286
287 bool JSMessage::deleteProperty(JSContextRef context,
288         JSObjectRef object,
289         JSStringRef propertyName,
290         JSValueRef* exception)
291 {
292         LogInfo("enter");
293         return true;
294 }
295
296 void JSMessage::getPropertyNames(JSContextRef context,
297         JSObjectRef object,
298         JSPropertyNameAccumulatorRef propertyNames)
299 {
300         LogInfo("enter");
301 }
302
303 JSValueRef JSMessage::callAsFunction(JSContextRef context,
304         JSObjectRef object,
305         JSObjectRef thisObject,
306         size_t argumentCount,
307         const JSValueRef arguments[],
308         JSValueRef* exception)
309 {
310         LogInfo("enter");
311         return JSValueMakeUndefined(context);
312 }
313
314 bool JSMessage::hasInstance(JSContextRef context,
315         JSObjectRef constructor,
316         JSValueRef possibleInstance,
317         JSValueRef* exception)
318 {
319         LogInfo("enter");
320         return true;
321 }
322
323 JSObjectRef JSMessage::constructor(JSContextRef context, 
324                 JSObjectRef constructor, 
325                 size_t argumentCount, 
326                 const JSValueRef arguments[], 
327                 JSValueRef* exception)
328 {
329         LogDebug("entered");
330
331         JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(constructor));
332         JSContextRef globalContext = priv ? priv->getContext() : context;
333
334         if (!globalContext)
335         {
336                 LogDebug(" globalContext is NULL ");
337                 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);     
338                 return NULL;
339         }
340
341         try
342         {
343                 if ( argumentCount < 1 ) {
344                         LogError("Wrong argument count");
345                         ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong Message argumentCount");
346                 }
347
348                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
349                 MessageType msgType = converter->toMessageType(arguments[0]);
350                 //objMsg = JSMessage::createDummyMessageJSObject(globalContext, msgType);               //make message JSValueRef.
351
352                 IMessagePtr msg;
353                 if ( msgType == EMAIL )
354                 {
355                         msg = MessageFactory::createEmailMessage();
356                 }
357                 else if (msgType == MMS || msgType == SMS)
358                 {
359                         msg = MessageFactory::createMessage(msgType);   //create message
360                 }
361                 else
362                 {
363                         LogError("message type is invalid");
364                         Throw(WrtDeviceApis::Commons::InvalidArgumentException); 
365                 }
366
367                 if (msg)
368                 {
369                         if ( argumentCount == 2 )
370                         {
371                                 LogDebug ("##### msg type is " << msgType);
372
373                                 const ScopedJSStringRef subjectStr(JSStringCreateWithUTF8CString("subject"));
374                                 const ScopedJSStringRef toStr(JSStringCreateWithUTF8CString("to"));
375                                 const ScopedJSStringRef ccStr(JSStringCreateWithUTF8CString("cc"));
376                                 const ScopedJSStringRef bccStr(JSStringCreateWithUTF8CString("bcc"));
377                                 const ScopedJSStringRef plainBodyStr(JSStringCreateWithUTF8CString("plainBody"));
378                                 const ScopedJSStringRef htmlBodyStr(JSStringCreateWithUTF8CString("htmlBody"));
379                                 const ScopedJSStringRef priorityStr(JSStringCreateWithUTF8CString("isHighPriority"));
380
381                                 JSObjectRef arg = converter->toJSObjectRef(arguments[1]);       //get dictionary
382                                 JSValueRef subjectData = JSObjectGetProperty(globalContext, arg, subjectStr.get(), NULL);
383                                 JSValueRef toData = JSObjectGetProperty(globalContext, arg, toStr.get(), NULL);
384                                 JSValueRef ccData = JSObjectGetProperty(globalContext, arg, ccStr.get(), NULL);
385                                 JSValueRef bccData = JSObjectGetProperty(globalContext, arg, bccStr.get(), NULL);
386                                 JSValueRef plainBodyData = JSObjectGetProperty(globalContext, arg, plainBodyStr.get(), NULL);
387                                 JSValueRef htmlBodyData = JSObjectGetProperty(globalContext, arg, htmlBodyStr.get(), NULL);
388                                 JSValueRef priorityData = JSObjectGetProperty(globalContext, arg, priorityStr.get(), NULL);
389
390                                 //subject
391                                 if (!JSValueIsUndefined(globalContext, subjectData) )
392                                 {
393                                         LogDebug ( " Subject : " << converter->toString(subjectData) );
394                                         std::string subject = converter->toString(subjectData);
395                                         switch (msgType)
396                                         {
397                                                 case MMS:
398                                                 {
399                                                         IMmsPtr mms = MessageFactory::convertToMms(msg);
400                                                         mms->setSubject(subject);
401                                                         break;
402                                                 }
403                                                 case EMAIL:
404                                                 {
405                                                         IEmailPtr email = MessageFactory::convertToEmail(msg);
406                                                         email->setSubject(subject);
407                                                         break;
408                                                 }
409                                                 default:
410                                                 {
411                                                         LogError("message not supported");
412                                                         //Throw(WrtDeviceApis::Commons::UnsupportedException);
413                                                         //break;
414                                                 }
415                                         }
416                                 }
417                                 //to
418                                 if (!JSValueIsUndefined(globalContext, toData) )
419                                 {
420                                         Recipients to = converter->toRecipients(toData);
421                                         LogDebug("setting to field, size=" << to.getRecipientSize());
422                                         msg->setToRecipients(to);
423                                 }
424                                 //cc
425                                 if (msgType == EMAIL )
426                                 {
427                                         IEmailPtr email = MessageFactory::convertToEmail(msg);
428                                         if (!JSValueIsUndefined(globalContext, ccData))
429                                         {
430                                                 Recipients cc = converter->toRecipients(ccData);
431                                                 email->setCcRecipients(cc);
432                                         }
433
434                                         if (!JSValueIsUndefined(globalContext, bccData))
435                                         {
436                                                 Recipients bcc = converter->toRecipients(bccData);
437                                                 email->setBccRecipients(bcc);
438                                         }
439
440                                         if (!JSValueIsUndefined(globalContext, htmlBodyData))
441                                         {
442                                                 std::string body = converter->toString(htmlBodyData);
443                                                 LogDebug("html body : " << body);
444                                                 email->setHtmlBody(body);
445                                         }
446
447                                         if (!JSValueIsUndefined(globalContext, priorityData))
448                                         {
449                                                 email->setPriority(converter->toMessagePriority(priorityData));
450                                         }
451                                 }
452                                 if (!JSValueIsUndefined(globalContext, plainBodyData) )
453                                 {
454                                         std::string body = converter->toString(plainBodyData);
455                                         LogDebug("plain body  : " << body);
456                                         msg->setBody(body);
457                                 }
458
459                         }
460
461                         //return
462                         JSClassRef jsClassRef = JSClassCreate(getClassInfo());
463                         LogDebug("jsClassRef success");
464                         JSMessagePrivateObject* priv = new JSMessagePrivateObject(globalContext, msg);
465                         LogDebug("priv success");
466
467                         JSObjectRef jsObjRef = JSObjectMake(globalContext, jsClassRef, static_cast<void*>(priv));
468                         LogDebug("JSObjectMake success");
469                         JSClassRelease(jsClassRef);
470                         if (NULL == jsObjRef) {
471                                 LogError("object creation error");
472                                 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "JSObject make error"); 
473                         }
474                         return jsObjRef;
475
476                 }
477                 else
478                 {
479                         LogDebug("Message Creation failed");
480                         ThrowMsg(WrtDeviceApis::Commons::PlatformException, "message has been not created"); 
481                 }
482         }
483         Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
484                 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
485                 return NULL;
486         }
487         Catch(WrtDeviceApis::Commons::ConversionException) {
488                 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
489                 return NULL;
490         }
491         Catch(WrtDeviceApis::Commons::PlatformException) {
492                 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
493                 return NULL;
494         }
495         return NULL;
496 }
497
498 JSValueRef JSMessage::convertToType(JSContextRef context,
499         JSObjectRef object,
500         JSType type,
501         JSValueRef* exception)
502 {
503     LogInfo("enter");
504     return JSValueMakeUndefined(context);
505 }
506
507 JSValueRef JSMessage::getAttachments(JSContextRef context,
508         JSObjectRef object,
509         JSStringRef propertyName,
510         JSValueRef* exception)
511 {
512         LogInfo("enter");
513         Try
514         {
515                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
516                 if (!priv)
517                         Throw(WrtDeviceApis::Commons::InvalidArgumentException);
518
519                 JSContextRef globalContext = priv->getContext();
520
521                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
522                 IMessagePtr msg = converter->toIMessage(object);
523                 MessageType msgType = msg->getMessageType();
524                 LogInfo("msgType=" << msgType);
525                 // prepare common values
526                 JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(converter->toJSGlobalContext(object), NULL, NULL);
527
528                 switch (msgType) {
529                         case MMS:
530                         case EMAIL:
531                         {
532
533                                 std::vector<IAttachmentPtr> attachments;
534                                 std::vector<IAttachmentPtr>::iterator it;
535
536                                 if ( msgType == MMS )
537                                 {
538                                         AttachmentsPtr mmsAttachments =
539                                         DPL::StaticPointerCast<Attachments>(MessageFactory::convertToMms(msg));
540                                         attachments = mmsAttachments->getAttachments();
541                                 }
542                                 else
543                                 {
544                                         AttachmentsPtr emailAttachments =
545                                         DPL::StaticPointerCast<Attachments>(MessageFactory::convertToEmail(msg));
546                                         attachments = emailAttachments->getAttachments();
547                                 }
548
549                                 int count = attachments.size();
550                                 LogDebug( "count : " << count);
551
552                                 JSObjectRef jsMessageAttachmentObject[count];   //make
553
554                                 for (unsigned int index = 0 ; index < attachments.size(); index++ )
555                                 {
556                                         LogDebug( "Attachment ID : " << attachments[index]->getAttachmentID());
557                                         jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(globalContext, attachments[index] );
558                                 }
559                                 JSObjectRef result = JSObjectMakeArray(globalContext, count, jsMessageAttachmentObject, NULL);
560                                 return result;
561                         }
562                         case SMS:
563                                 return JSValueMakeNull(context);
564                         default:
565                                 LogError("not supported message type");
566                                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
567                 }
568         }
569         Catch(WrtDeviceApis::Commons::ConversionException) {
570                 LogError("Error on conversion");
571                 return JSTizenExceptionFactory::postException(context, exception,
572                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
573         }
574         Catch(WrtDeviceApis::Commons::NullPointerException) {
575                 LogError("Error on pointer, null value");
576                 return JSTizenExceptionFactory::postException(context, exception,
577                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
578         }
579 }
580
581
582 JSValueRef JSMessage::getBccAddress(JSContextRef context,
583         JSObjectRef object,
584         JSStringRef propertyName,
585         JSValueRef* exception)
586 {
587         LogDebug("enter");
588         Try
589         {
590                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
591                 IMessagePtr msg = converter->toIMessage(object);
592                 MessageType msgType = msg->getMessageType();
593
594                 switch (msgType)
595                 {
596                         case EMAIL:
597                         {
598                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
599                                 RecipientsPtr recipient = email->getBccRecipientsPtr();
600                                 JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
601                                 if (NULL == arrayValue)
602                                 {
603                                         LogError("Could not create js array object");
604                                         return JSValueMakeUndefined(context);
605                                 }
606                                 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
607                                 {
608                                         JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)));
609                                 }
610                                 return arrayValue;
611                         }
612                         case SMS:
613                         case MMS:
614                                 return JSValueMakeNull(context);
615
616                         default:
617                                 LogError("not supported message type");
618                                 return JSTizenExceptionFactory::postException(context, exception,
619                                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);        // unsupported type
620                         break;
621                 }
622         }
623         Catch(WrtDeviceApis::Commons::ConversionException) {
624                 LogError("Error on conversion");
625                 return JSTizenExceptionFactory::postException(context, exception,
626                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
627         }
628         Catch(WrtDeviceApis::Commons::NullPointerException) {
629                 LogError("Error on pointer, null value");
630                 return JSTizenExceptionFactory::postException(context, exception,
631                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
632         }
633 }
634
635 JSValueRef JSMessage::getBody(JSContextRef context,
636         JSObjectRef object,
637         JSStringRef propertyName,
638         JSValueRef* exception)
639 {
640         Try
641         {
642                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
643                 IMessagePtr msg = converter->toIMessage(object);
644                 string body = msg->getBody();
645                 return converter->toJSValueRef(body);
646         }
647         Catch(WrtDeviceApis::Commons::ConversionException) {
648                 LogError("Error on conversion");
649                 return JSTizenExceptionFactory::postException(context, exception,
650                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
651         }
652         Catch(WrtDeviceApis::Commons::NullPointerException) {
653                 LogError("Error on pointer, null value");
654                 return JSTizenExceptionFactory::postException(context, exception,
655                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
656         }
657 }
658
659 JSValueRef JSMessage::getCcAddress(JSContextRef context,
660         JSObjectRef object,
661         JSStringRef propertyName,
662         JSValueRef* exception)
663 {
664         LogDebug("enter");
665         Try
666         {
667                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
668                 IMessagePtr msg = converter->toIMessage(object);
669                 MessageType msgType = msg->getMessageType();
670
671                 switch (msgType)
672                 {
673                         case EMAIL:
674                         {
675                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
676                                 RecipientsPtr recipient = email->getCcRecipientsPtr();
677                                 JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
678                                 if (NULL == arrayValue)
679                                 {
680                                         LogError("Could not create js array object");
681                                         return JSValueMakeUndefined(context);
682                                 }
683                                 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
684                                 {
685                                         JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)));
686                                 }
687                                 return arrayValue;
688                         }
689                         case MMS:
690                         case SMS:
691                                 return JSValueMakeNull(context);
692
693                         default:
694                                 LogError("not supported message type");
695                                 return JSTizenExceptionFactory::postException(context, exception, 
696                                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);    // unsupported type
697
698                         break;
699                 }
700         }
701         Catch(WrtDeviceApis::Commons::ConversionException) {
702                 LogError("Error on conversion");
703                 return JSTizenExceptionFactory::postException(context, exception,
704                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
705         }
706         Catch(WrtDeviceApis::Commons::NullPointerException) {
707                 LogError("Error on pointer, null value");
708                 return JSTizenExceptionFactory::postException(context, exception,
709                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
710         }
711 }
712
713 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
714         JSObjectRef object,
715         JSStringRef propertyName,
716         JSValueRef* exception)
717 {
718         LogInfo("enter");
719         Try
720         {
721                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
722                 IMessagePtr msg = converter->toIMessage(object);
723                 RecipientsPtr recipient = msg->getToRecipientsPtr();
724                 JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
725                 if (NULL == arrayValue)
726                 {
727                         LogError("Could not create js array object");
728                         return JSValueMakeUndefined(context);
729                 }
730                 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
731                 {
732                         JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)));
733                 }
734                 return arrayValue;
735         }
736         Catch(WrtDeviceApis::Commons::ConversionException) {
737                 LogError("Error on conversion");
738                 return JSTizenExceptionFactory::postException(context, exception,
739                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
740         }
741         Catch(WrtDeviceApis::Commons::NullPointerException) {
742                 LogError("Error on pointer, null value");
743                 return JSTizenExceptionFactory::postException(context, exception,
744                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
745         }
746 }
747
748 JSValueRef JSMessage::getIsRead(JSContextRef context,
749         JSObjectRef object,
750         JSStringRef propertyName,
751         JSValueRef* exception)
752 {
753         Try
754                 {
755                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
756                 IMessagePtr msg = converter->toIMessage(object);
757                 bool isRead = msg->isRead();
758                 return converter->toJSValueRef(isRead);
759         }
760         Catch(WrtDeviceApis::Commons::ConversionException) {
761                 LogError("Error on conversion");
762                 return JSTizenExceptionFactory::postException(context, exception,
763                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
764         }
765         Catch(WrtDeviceApis::Commons::NullPointerException) {
766                 LogError("Error on pointer, null value");
767                 return JSTizenExceptionFactory::postException(context, exception,
768                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
769         }
770 }
771
772 JSValueRef JSMessage::getMessageId(JSContextRef context,
773         JSObjectRef object,
774         JSStringRef propertyName,
775         JSValueRef* exception)
776 {
777         Try
778         {
779                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
780                 IMessagePtr msg = converter->toIMessage(object);
781                 const string& id = msg->getIdRef();
782                 LogDebug("msgId=" << id);
783                 LogDebug("msg->getMessageStatus()=" << msg->getMessageStatus());
784                 if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
785                 {
786                         return JSValueMakeNull(context);
787                 }
788                 return converter->toJSValueRef(id);
789         }
790         Catch(WrtDeviceApis::Commons::ConversionException) {
791                 LogError("Error on conversion");
792                 return JSTizenExceptionFactory::postException(context, exception,
793                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
794         }
795         Catch(WrtDeviceApis::Commons::NullPointerException) {
796                 LogError("Error on pointer, null value");
797                 return JSTizenExceptionFactory::postException(context, exception,
798                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
799         }
800 }
801
802 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
803         JSObjectRef object,
804         JSStringRef propertyName,
805         JSValueRef* exception)
806 {
807         Try
808         {
809                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
810                 IMessagePtr msg = converter->toIMessage(object);
811                 MessageType msgType = msg->getMessageType();
812
813                 switch (msgType) {
814                         case SMS:
815                         case MMS:
816                                 return JSValueMakeNull(context);
817                         case EMAIL:
818                         {
819                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
820                                 int tmpint = email->getPriority();
821                                 LogError("priority : " << tmpint);
822                                 if(tmpint == MessagePriority::HIGH)
823                                 {
824                                         return converter->toJSValueRef(true);
825                                 }
826                                 return converter->toJSValueRef(false);
827                         }
828                         default:
829                                 LogError("unsupported message type");
830                                 return JSTizenExceptionFactory::postException(context, exception,
831                                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
832                         break;
833                 }
834         }
835         Catch(WrtDeviceApis::Commons::ConversionException) {
836                 LogError("Error on conversion");
837                 return JSTizenExceptionFactory::postException(context, exception,
838                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
839         }
840         Catch(WrtDeviceApis::Commons::NullPointerException) {
841                 LogError("Error on pointer, null value");
842                 return JSTizenExceptionFactory::postException(context, exception,
843                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
844         }
845 }
846
847 JSValueRef JSMessage::getMessageType(JSContextRef context,
848         JSObjectRef object,
849         JSStringRef propertyName,
850         JSValueRef* exception)
851 {
852         Try
853         {
854                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
855                 IMessagePtr msg = converter->toIMessage(object);
856                 MessageType msgType = msg->getMessageType();
857
858                 return converter->toJSValueRef(converter->toMessageType(msgType));
859         }
860         Catch(WrtDeviceApis::Commons::ConversionException) {
861                 LogError("Error on conversion");
862                 return JSTizenExceptionFactory::postException(context, exception,
863                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
864         }
865         Catch(WrtDeviceApis::Commons::NullPointerException) {
866                 LogError("Error on pointer, null value");
867                 return JSTizenExceptionFactory::postException(context, exception,
868                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
869         }
870 }
871
872 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
873         JSObjectRef object,
874         JSStringRef propertyName,
875         JSValueRef* exception)
876 {
877         Try
878         {
879                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
880                 IMessagePtr msg = converter->toIMessage(object);
881
882                 //This property is set up by the device or the web runtime environment.
883                 //This property should only be taken into account for Email.
884                 // TODO Verify with Tizen.
885                 //        if (msg->getMessageType() != EMAIL && msg->getMessageType() != Api::VIRTUAL_MESSAGE) {
886                 //            return JSValueMakeUndefined(context);
887                 //        }
888                 return converter->toJSValueRef(msg->getSourceAddress());
889         }
890         Catch(WrtDeviceApis::Commons::ConversionException) {
891                 LogError("Error on conversion");
892                 return JSTizenExceptionFactory::postException(context, exception,
893                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
894         }
895         Catch(WrtDeviceApis::Commons::NullPointerException) {
896                 LogError("Error on pointer, null value");
897                 return JSTizenExceptionFactory::postException(context, exception,
898                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
899         }
900 }
901
902 JSValueRef JSMessage::getSubject(JSContextRef context,
903         JSObjectRef object,
904         JSStringRef propertyName,
905         JSValueRef* exception)
906 {
907         Try
908         {
909                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
910                 IMessagePtr msg = converter->toIMessage(object);
911                 MessageType msgType = msg->getMessageType();
912
913                 switch (msgType) {
914                         case MMS:
915                         {
916                                 IMmsPtr mms = MessageFactory::convertToMms(msg);
917                                 return converter->toJSValueRef(mms->getSubject());
918                         }
919                         case EMAIL:
920                         {
921                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
922                                 return converter->toJSValueRef(email->getSubject());
923                         }
924                         case SMS:
925                                 return JSValueMakeNull(context);
926                         default:
927                                 LogError("message not support subject");
928                                 return JSTizenExceptionFactory::postException(context, exception,
929                                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
930                         break;
931                 }
932         }
933         Catch(WrtDeviceApis::Commons::ConversionException) {
934                 LogError("Error on conversion");
935                 return JSTizenExceptionFactory::postException(context, exception,
936                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
937         }
938         Catch(WrtDeviceApis::Commons::NullPointerException) {
939                 LogError("Error on pointer, null value");
940                 return JSTizenExceptionFactory::postException(context, exception,
941                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
942         }
943         Catch(WrtDeviceApis::Commons::UnsupportedException) {
944                 return JSTizenExceptionFactory::postException(context, exception,
945                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
946         }
947 }
948
949 JSValueRef JSMessage::getTime(JSContextRef context,
950         JSObjectRef object,
951         JSStringRef propertyName,
952         JSValueRef* exception)
953 {
954         Try
955         {
956                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
957                 IMessagePtr msg = converter->toIMessage(object);
958                 struct tm dateTime = msg->getDateTime();
959                 return converter->toJSValueRef(dateTime);
960         }
961         Catch(WrtDeviceApis::Commons::ConversionException) {
962                 LogError("Error on conversion");
963                 return JSTizenExceptionFactory::postException(context, exception, 
964                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
965         }
966         Catch(WrtDeviceApis::Commons::NullPointerException) {
967                 LogError("Error on pointer, null value");
968                 return JSTizenExceptionFactory::postException(context, exception, 
969                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
970         }
971 }
972
973 JSValueRef JSMessage::getFolder(JSContextRef context,
974         JSObjectRef object,
975         JSStringRef propertyName,
976         JSValueRef* exception)
977 {
978         Try
979         {
980                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
981                 IMessagePtr msg = converter->toIMessage(object);
982                 FolderType folder = msg->getCurrentFolder();
983
984                 int tmpInt = msg->getMessageStatus();
985
986                 LogError("folder : " << folder);
987                 LogError("msg->getMessageStatus() : " << tmpInt);
988
989                 if(tmpInt == MESSAGE_STATUS_CREATED)
990                 {
991                         return JSValueMakeNull(context);
992                 }
993
994                 tmpInt = (int)folder;
995                 return converter->toJSValueRef(converter->convertIntToString(tmpInt));
996         }
997         Catch(WrtDeviceApis::Commons::ConversionException) {
998                 LogError("Error on conversion");
999                 return JSTizenExceptionFactory::postException(context, exception,
1000                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1001         }
1002         Catch(WrtDeviceApis::Commons::NullPointerException) {
1003                 LogError("Error on pointer, null value");
1004                 return JSTizenExceptionFactory::postException(context, exception,
1005                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1006         }
1007 }
1008
1009 JSValueRef JSMessage::getMessageBody(JSContextRef context,
1010         JSObjectRef object,
1011         JSStringRef propertyName,
1012         JSValueRef* exception)
1013 {
1014         LogInfo("getMessageBody");
1015
1016         Try
1017         {
1018                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1019                 if (!priv)
1020                         ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Couldn't get Messaage Private Object");
1021
1022                 JSContextRef globalContext = priv->getContext();
1023
1024                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1025                 IMessagePtr msg = converter->toIMessage(object);        //get message point
1026
1027                 return JSMessageBody::createJS(globalContext, msg);
1028         }
1029         Catch(WrtDeviceApis::Commons::ConversionException) {
1030                 LogError("Error on conversion");
1031                 return JSTizenExceptionFactory::postException(context, exception,
1032                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1033         }
1034         Catch(WrtDeviceApis::Commons::NullPointerException) {
1035                 LogError("Error on pointer, null value");
1036                 return JSTizenExceptionFactory::postException(context, exception,
1037                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1038         }
1039 }
1040
1041 JSValueRef JSMessage::getAccountID(JSContextRef context,
1042         JSObjectRef object,
1043         JSStringRef propertyName,
1044         JSValueRef* exception)
1045 {
1046         LogInfo("getAccountID");
1047
1048         Try
1049         {
1050                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1051                 if (!priv)
1052                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1053
1054                 JSContextRef globalContext = priv->getContext();
1055
1056                 ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
1057
1058                 IMessagePtr msg = converter->toIMessage(object);        //get message point
1059
1060                 LogInfo("create JS");
1061                 //getAccountID
1062                 if (msg->getMessageType() == EMAIL)
1063                 {
1064                         IEmailPtr email = MessageFactory::convertToEmail(msg);
1065                         if(email->getAccountID() == -1)
1066                         {
1067                                 return JSValueMakeNull(context);
1068                         }
1069                         std::stringstream stream;
1070                         stream << email->getAccountID();
1071                         if (stream.fail()) {
1072                                 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert e-mail account id");
1073                         }
1074
1075                         return converter->toJSValueRef(stream.str());
1076                 }
1077                 else if (msg->getMessageType() == SMS)
1078                 {
1079                         std::stringstream stream;
1080                         stream << SMS_ACCOUNT_ID;
1081                         if (stream.fail()) {
1082                                 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert sms account id");
1083                         }
1084
1085                         return converter->toJSValueRef(stream.str());
1086                 }
1087                 else if (msg->getMessageType() == MMS)
1088                 {
1089                         std::stringstream stream;
1090                         stream << MMS_ACCOUNT_ID;
1091                         if (stream.fail()) {
1092                                 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert mms account id");
1093                         }
1094
1095                         return converter->toJSValueRef(stream.str());
1096                 }
1097                 else
1098                 {
1099                         return JSValueMakeUndefined(context);
1100                 }
1101         }
1102         Catch(WrtDeviceApis::Commons::ConversionException) {
1103                 LogError("Error on conversion");
1104                 return JSTizenExceptionFactory::postException(context, exception,
1105                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1106         }
1107         Catch(WrtDeviceApis::Commons::NullPointerException) {
1108                 LogError("Error on pointer, null value");
1109                 return JSTizenExceptionFactory::postException(context, exception,
1110                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1111         }
1112 }
1113
1114 JSValueRef JSMessage::getUID(JSContextRef context,
1115                         JSObjectRef object,
1116                         JSStringRef propertyName,
1117                         JSValueRef* exception)
1118 {
1119         LogInfo("getUID");
1120
1121         Try
1122         {
1123                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1124                 if (!priv)
1125                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1126
1127                 JSContextRef globalContext = priv->getContext();
1128
1129                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1130
1131                 IMessagePtr msg = converter->toIMessage(object); //get message point
1132
1133                 LogInfo("create JS");
1134                 //getAccountID
1135                 if (msg->getMessageType() == EMAIL)
1136                 {
1137                         IEmailPtr email = MessageFactory::convertToEmail(msg);
1138                         return converter->toJSValueRef(email->getUID());
1139                 }
1140                 else
1141                 {
1142                         return JSValueMakeUndefined(context);
1143                 }
1144         }
1145         Catch(WrtDeviceApis::Commons::ConversionException) {
1146                 LogError("Error on conversion");
1147                 return JSTizenExceptionFactory::postException(context, exception,
1148                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1149         }
1150         Catch(WrtDeviceApis::Commons::NullPointerException) {
1151                 LogError("Error on pointer, null value");
1152                 return JSTizenExceptionFactory::postException(context, exception,
1153                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1154         }
1155 }
1156
1157 bool JSMessage::setAttachments(JSContextRef context,
1158         JSObjectRef object,
1159         JSStringRef propertyName,
1160         JSValueRef value,
1161         JSValueRef* exception)
1162 {
1163         LogInfo("enter");
1164
1165         Try
1166         {
1167                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1168                 
1169                 if (!priv)
1170                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1171
1172                 JSContextRef globalContext = priv->getContext();
1173                 if (!globalContext)
1174                 {
1175                         LogDebug("globalContext is NULL");
1176                         globalContext = context;
1177                 }
1178                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1179
1180                 vector<IAttachmentPtr> attachments;
1181                 if (JSIsArrayValue(context, value)) {
1182                         JSObjectRef valueObj = converter->toJSObjectRef(value);
1183                         unsigned int len = JSGetArrayLength(context, valueObj);
1184                         LogDebug("Array Length = " << len);
1185                         for (unsigned int i = 0; i < len; ++i)
1186                         {
1187                                 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1188                                 if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
1189                                         LogWarning("Invalid array element. Skipping.");
1190                                         continue;
1191                                 }
1192                                 IAttachmentPtr attachment = converter->toIAttachment(att);
1193
1194                                 if(attachment->getIsValidAttachment() == false)
1195                                 {
1196                                         LogDebug("invalid attachment : " << i);
1197                                         Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1198                                 }
1199
1200                                 LogDebug("Adding attachment , shotname: " << attachment->getShortName());
1201                                 attachments.push_back(attachment);
1202                         }
1203                 }
1204                 else
1205                 {
1206                         IAttachmentPtr attachment = converter->toIAttachment(value);
1207                         LogDebug("Adding attachment , shotname: " << attachment->getShortName());
1208                         if(attachment->getIsValidAttachment() == false)
1209                         {
1210                                 LogDebug("invalid attachment");
1211                                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1212                         }
1213                         attachments.push_back(attachment);
1214                 }
1215
1216                 LogDebug("Attachment Size =" << attachments.size());
1217                 if ( attachments.size() > 0)
1218                 {
1219                         IMessagePtr msg = converter->toIMessage(object);
1220                         if (msg)
1221                         {
1222                                 MessageType msgType = msg->getMessageType();
1223                                 switch (msgType) {
1224                                         case MMS:
1225                                         {
1226                                                 IMmsPtr mms = MessageFactory::convertToMms(msg);
1227                                                 mms->setAttachments(attachments);
1228                                                 break;
1229                                         }
1230                                         case EMAIL:
1231                                         {
1232                                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
1233                                                 email->setAttachments(attachments);
1234                                                 break;
1235                                         }
1236                                         default:
1237                                                 LogError("not supported message type");
1238                                                 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1239                                 }
1240                                 return true;
1241                         }
1242                         else
1243                         {
1244                                 LogError("Message converter failed...");
1245                                 Throw(WrtDeviceApis::Commons::NullPointerException);
1246                         }
1247                 }
1248         }
1249         Catch(WrtDeviceApis::Commons::ConversionException) {
1250                 LogError("Error on conversion");
1251                 return JSTizenExceptionFactory::postException(context, exception, 
1252                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1253         }
1254         Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1255                 LogError("Invalid argument exception");
1256                 return JSTizenExceptionFactory::postException(context, exception, 
1257                                 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1258         }
1259         Catch(WrtDeviceApis::Commons::NullPointerException) {
1260                 LogError("Error on pointer, null value");
1261                 return JSTizenExceptionFactory::postException(context, exception, 
1262                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1263         }
1264         Catch(WrtDeviceApis::Commons::UnsupportedException) {
1265                 return JSTizenExceptionFactory::postException(context, exception, 
1266                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1267         }
1268         return false;   
1269 }
1270
1271
1272 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
1273 bool JSMessage::setAttachments(JSContextRef context,
1274         JSObjectRef object,
1275         JSStringRef propertyName,
1276         JSValueRef value,
1277         JSValueRef* exception)
1278 {
1279     LogInfo("enter");
1280
1281     Try
1282     {
1283         JSMessagePrivateObject* priv =
1284             static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1285
1286         if (!priv) {
1287             return JSTizenExceptionFactory::postException(context, exception, 
1288                            JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1289         }
1290     }
1291     Catch(WrtDeviceApis::Commons::NullPointerException) {
1292         LogError("Error on pointer, null value");
1293            return JSTizenExceptionFactory::postException(context, exception, 
1294                            JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1295     }
1296
1297     vector<string> attachments;
1298     Try
1299     {
1300         ConverterMessageFactory::ConverterType converter =
1301             ConverterMessageFactory::getConverter(context);
1302         if (JSIsArrayValue(context, value)) {
1303             JSObjectRef valueObj = converter->toJSObjectRef(value);
1304
1305             // extract path from each JSFile object
1306             unsigned int len = JSGetArrayLength(context, valueObj);
1307             for (unsigned int i = 0; i < len; ++i) {
1308                 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1309                 if (JSValueIsUndefined(context,
1310                                        att) || JSValueIsNull(context, att)) {
1311                     LogWarning("Invalid array element. Skipping.");
1312                     continue;
1313                 }
1314                 DeviceAPI::Filesystem::INodePtr node = converter->toFilesystemNode(
1315                         att);
1316
1317                 LogDebug("Adding attachment: " << node->getPath()->getFullPath());
1318                 attachments.push_back(node->getPath()->getFullPath());
1319             }
1320         } else {
1321             LogWarning("Invalid or null element passed as attachment array." <<
1322                        "Setting empty vector.");
1323         }
1324
1325         // set up new attachments list
1326         IMessagePtr msg = converter->toIMessage(object);
1327         MessageType msgType = msg->getMessageType();
1328         switch (msgType) {
1329         case MMS:
1330         {
1331             IMmsPtr mms = MessageFactory::convertToMms(msg);
1332             mms->setAttachments(attachments, true);
1333             break;
1334         }
1335         case EMAIL:
1336         {
1337             IEmailPtr email = MessageFactory::convertToEmail(msg);
1338             email->setAttachments(attachments, true);
1339             break;
1340         }
1341         case SMS:
1342
1343             return false; // ignore
1344
1345         default:
1346             LogError("not supported message type");
1347             Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1348         }
1349         return true;
1350     }
1351     Catch(WrtDeviceApis::Commons::ConversionException) {
1352         LogError("Error on conversion");
1353           return JSTizenExceptionFactory::postException(context, exception, 
1354                    JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1355     }
1356     Catch(WrtDeviceApis::Commons::NullPointerException) {
1357         LogError("Error on pointer, null value");
1358           return JSTizenExceptionFactory::postException(context, exception, 
1359                          JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1360     }
1361     Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1362         LogError("Invalid argument");
1363            return JSTizenExceptionFactory::postException(context, exception, 
1364                            JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1365     }
1366     return false;
1367 }
1368 #endif
1369
1370 bool JSMessage::setBccAddress(JSContextRef context,
1371         JSObjectRef object,
1372         JSStringRef propertyName,
1373         JSValueRef value,
1374         JSValueRef* exception)
1375 {
1376         Try
1377         {
1378                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1379                 IMessagePtr msg = converter->toIMessage(object);
1380                 Recipients bcc = converter->toRecipients(value);
1381                 LogDebug("setting bcc field, size=" << bcc.getRecipientSize());
1382
1383                 MessageType msgType = msg->getMessageType();
1384                 switch (msgType) {
1385                         case SMS:
1386                         case MMS:
1387                                 return false;   // ignore
1388
1389                         case EMAIL:
1390                         {
1391                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
1392                                 email->setBccRecipients(bcc);
1393                                 break;
1394                         }
1395                         default:
1396                                 LogError("unsupported message type");
1397                                 return JSTizenExceptionFactory::postException(context, exception,
1398                                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
1399                 }
1400                 return true;
1401         }
1402         Catch(WrtDeviceApis::Commons::ConversionException) {
1403                 LogError("Error on conversion");
1404                 return JSTizenExceptionFactory::postException(context, exception,
1405                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1406         }
1407         Catch(WrtDeviceApis::Commons::NullPointerException) {
1408                 LogError("Error on pointer, null value");
1409                 return JSTizenExceptionFactory::postException(context, exception,
1410                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1411         }
1412         Catch(WrtDeviceApis::Commons::PlatformException) {
1413                 LogError("Platform execution");
1414                 return JSTizenExceptionFactory::postException(context, exception,
1415                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1416         }
1417     return false;
1418 }
1419
1420 bool JSMessage::setBody(JSContextRef context,
1421         JSObjectRef object,
1422         JSStringRef propertyName,
1423         JSValueRef value,
1424         JSValueRef* exception)
1425 {
1426         Try
1427         {
1428                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1429                 IMessagePtr msg = converter->toIMessage(object);
1430                 string body = converter->toString(value);
1431                 msg->setBody(body);
1432                 return true;
1433         }
1434         Catch(WrtDeviceApis::Commons::ConversionException) {
1435                 LogError("Error on conversion");
1436                 return JSTizenExceptionFactory::postException(context, exception,
1437                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1438         }
1439         Catch(WrtDeviceApis::Commons::NullPointerException) {
1440                 LogError("Error on pointer, null value");
1441                 return JSTizenExceptionFactory::postException(context, exception,
1442                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1443         }
1444         Catch(WrtDeviceApis::Commons::PlatformException) {
1445                 LogError("Platform execution");
1446                 return JSTizenExceptionFactory::postException(context, exception,
1447                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1448         }
1449         return false;
1450 }
1451
1452 bool JSMessage::setCcAddress(JSContextRef context,
1453         JSObjectRef object,
1454         JSStringRef propertyName,
1455         JSValueRef value,
1456         JSValueRef* exception)
1457 {
1458         Try
1459         {
1460                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1461                 IMessagePtr msg = converter->toIMessage(object);
1462                 Recipients cc = converter->toRecipients(value);
1463                 LogDebug("setting cc field, size=" << cc.getRecipientSize());
1464
1465                 MessageType msgType = msg->getMessageType();
1466                 switch (msgType) {
1467                         case SMS:
1468                         case MMS:
1469                                 return false;   // ignore
1470
1471                         case EMAIL:
1472                         {
1473                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
1474                                 email->setCcRecipients(cc);
1475                                 break;
1476                         }
1477                         default:
1478                                 LogError("unsuported message type");
1479                                 return JSTizenExceptionFactory::postException(context, exception,
1480                                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);          // unsupported type
1481                         break;
1482                 }
1483                         return true;
1484         }
1485         Catch(WrtDeviceApis::Commons::ConversionException) {
1486                 LogError("Error on conversion");
1487                 return JSTizenExceptionFactory::postException(context, exception,
1488                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1489         }
1490         Catch(WrtDeviceApis::Commons::NullPointerException) {
1491                 LogError("Error on pointer, null value");
1492                 return JSTizenExceptionFactory::postException(context, exception,
1493                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1494         }
1495         Catch(WrtDeviceApis::Commons::PlatformException) {
1496                 LogError("Platform execution");
1497                 return JSTizenExceptionFactory::postException(context, exception,
1498                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1499         }
1500     return false;
1501 }
1502
1503 bool JSMessage::setDestinationAddress(JSContextRef context,
1504         JSObjectRef object,
1505         JSStringRef propertyName,
1506         JSValueRef value,
1507         JSValueRef * exception)
1508 {
1509         LogInfo("enter");
1510         Try
1511         {
1512                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1513                 IMessagePtr msg = converter->toIMessage(object);
1514                 Recipients to = converter->toRecipients(value);
1515                 LogDebug("setting to field, size=" << to.getRecipientSize());
1516                 msg->setToRecipients(to);
1517                 return true;
1518         }
1519         Catch(WrtDeviceApis::Commons::ConversionException) {
1520                 LogError("Error on conversion");
1521                 return JSTizenExceptionFactory::postException(context, exception,
1522                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1523         }
1524         Catch(WrtDeviceApis::Commons::NullPointerException) {
1525                 LogError("Error on pointer, null value");
1526                 return JSTizenExceptionFactory::postException(context, exception,
1527                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1528         }
1529         Catch(WrtDeviceApis::Commons::PlatformException) {
1530                 LogError("Platform execution");
1531                 return JSTizenExceptionFactory::postException(context, exception,
1532                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1533         }
1534         return false;
1535 }
1536
1537 bool JSMessage::setIsRead(JSContextRef context,
1538         JSObjectRef object,
1539         JSStringRef propertyName,
1540         JSValueRef value,
1541         JSValueRef * exception)
1542 {
1543         Try
1544         {
1545                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1546                 IMessagePtr msg = converter->toIMessage(object);
1547                 msg->setReadStatus(converter->toBool(value));
1548                 msg->setisReadChangeStatus(converter->toBool(value));
1549                 return true;
1550         }
1551         Catch(WrtDeviceApis::Commons::ConversionException) {
1552                 LogError("Error on conversion");
1553                 return JSTizenExceptionFactory::postException(context, exception,
1554                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1555         }
1556         Catch(WrtDeviceApis::Commons::NullPointerException) {
1557                 LogError("Error on pointer, null value");
1558                 return JSTizenExceptionFactory::postException(context, exception,
1559                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1560         }
1561         return false;
1562 }
1563
1564 bool JSMessage::setMessagePriority(JSContextRef context,
1565         JSObjectRef object,
1566         JSStringRef propertyName,
1567         JSValueRef value,
1568         JSValueRef * exception)
1569 {
1570         Try
1571         {
1572                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1573                 IMessagePtr msg = converter->toIMessage(object);
1574                 MessageType msgType = msg->getMessageType();
1575                 switch (msgType) {
1576                         case MMS:
1577                         case SMS:
1578                                 return false;   // ignore
1579
1580                         case EMAIL:
1581                                 msg->setPriority(converter->toMessagePriority(value));
1582                         break;
1583
1584                         default:
1585                                 LogError("unsuported message type");
1586                                 Throw(WrtDeviceApis::Commons::ConversionException);
1587                         break;
1588                 }
1589                 return true;
1590         }
1591         Catch(WrtDeviceApis::Commons::ConversionException) {
1592                 LogError("Error on conversion");
1593                 return JSTizenExceptionFactory::postException(context, exception,
1594                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1595         }
1596         Catch(WrtDeviceApis::Commons::NullPointerException) {
1597                 LogError("Error on pointer, null value");
1598                 return JSTizenExceptionFactory::postException(context, exception,
1599                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1600         }
1601         Catch(WrtDeviceApis::Commons::PlatformException) {
1602                 LogError("Platform execution");
1603                 return JSTizenExceptionFactory::postException(context, exception,
1604                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1605         }
1606         return false;
1607 }
1608
1609 bool JSMessage::setSubject(JSContextRef context,
1610         JSObjectRef object,
1611         JSStringRef propertyName,
1612         JSValueRef value,
1613         JSValueRef * exception)
1614 {
1615         Try
1616         {
1617                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1618                 IMessagePtr msg = converter->toIMessage(object);
1619                 MessageType msgType = msg->getMessageType();
1620                 string subject = converter->toString(value);
1621                 switch (msgType) {
1622                         case MMS:
1623                         {
1624                                 IMmsPtr mms = MessageFactory::convertToMms(msg);
1625                                 mms->setSubject(subject);
1626                                 break;
1627                         }
1628                         case EMAIL:
1629                         {
1630                                 IEmailPtr email = MessageFactory::convertToEmail(msg);
1631                                 email->setSubject(subject);
1632                                 break;
1633                         }
1634                         case SMS:
1635                                 return false;   // ignore
1636
1637                         default:
1638                                 LogError("message not supported");
1639                                 Throw(WrtDeviceApis::Commons::UnsupportedException);
1640                         break;
1641                 }
1642                 return true;
1643         }
1644         Catch(WrtDeviceApis::Commons::ConversionException) {
1645                 LogError("Error on conversion");
1646                 return JSTizenExceptionFactory::postException(context, exception,
1647                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1648         }
1649         Catch(WrtDeviceApis::Commons::NullPointerException) {
1650                 LogError("Error on pointer, null value");
1651                 return JSTizenExceptionFactory::postException(context, exception,
1652                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1653         }
1654         Catch(WrtDeviceApis::Commons::PlatformException) {
1655                 LogError("Platform execution");
1656                 return JSTizenExceptionFactory::postException(context, exception,
1657                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1658         }
1659         Catch(WrtDeviceApis::Commons::UnsupportedException) {
1660                 return JSTizenExceptionFactory::postException(context, exception,
1661                                 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1662         }
1663         return false;
1664 }
1665
1666 bool JSMessage::setMessageBody(JSContextRef context,
1667         JSObjectRef object,
1668         JSStringRef propertyName,
1669         JSValueRef value,
1670         JSValueRef* exception)
1671 {
1672         Try
1673         {
1674                 LogDebug("Set Message Body.");
1675                 return true;
1676         }
1677         Catch(WrtDeviceApis::Commons::ConversionException) {
1678                 LogError("Error on conversion");
1679                 return JSTizenExceptionFactory::postException(context, exception,
1680                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1681         }
1682         Catch(WrtDeviceApis::Commons::NullPointerException) {
1683                 LogError("Error on pointer, null value");
1684                 return JSTizenExceptionFactory::postException(context, exception,
1685                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1686         }
1687         Catch(WrtDeviceApis::Commons::PlatformException) {
1688                 LogError("Platform execution");
1689                 return JSTizenExceptionFactory::postException(context, exception,
1690                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1691         }
1692         return false;
1693 }
1694
1695 JSValueRef JSMessage::getConversationId(JSContextRef context,
1696         JSObjectRef object,
1697         JSStringRef propertyName,
1698         JSValueRef* exception)
1699 {
1700         LogDebug("getConversationId");
1701
1702         Try
1703         {
1704                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1705                 int convId = 0;
1706                 IMessagePtr msg = converter->toIMessage(object);
1707
1708                 LogDebug("msg->getMessageStatus()=" << msg->getMessageStatus());
1709                 LogDebug("msg.getConvId()=" << msg->getConvId());
1710                 convId = msg->getConvId();
1711                 if((msg->getConvId() == -1) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
1712                 {
1713                         return JSValueMakeNull(context);
1714                 }
1715                 return converter->toJSValueRef(converter->convertIntToString(convId));
1716                 /*
1717                 EventGetConversationIdPtr event(new EventGetConversationId());
1718                 event->setConversationMsgPtr(msg);
1719                 event->setForSynchronousCall();
1720                 ReqReceiverMessageSingleton::Instance().getConversationId(event);
1721
1722                 convId = event->getConversationId();
1723                 // TODO messageIDref string size 0 => return NULL
1724                 return converter->toJSValueRef(convId);
1725                 */
1726         }
1727         Catch(WrtDeviceApis::Commons::ConversionException) {
1728                 LogError("Error on conversion");
1729                 return JSTizenExceptionFactory::postException(context, exception,
1730                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1731         }
1732         Catch(WrtDeviceApis::Commons::NullPointerException) {
1733                 LogError("Error on pointer, null value");
1734                 return JSTizenExceptionFactory::postException(context, exception,
1735                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1736         }
1737         Catch(WrtDeviceApis::Commons::PlatformException) {
1738                 LogError("Platform execution");
1739                 return JSTizenExceptionFactory::postException(context, exception,
1740                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1741         }
1742 }
1743
1744 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
1745                 JSObjectRef object,
1746                 JSStringRef propertyName,
1747                 JSValueRef* exception)
1748 {
1749         LogDebug("getInResponseTo");
1750
1751         Try
1752         {
1753                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1754                 int convId = -1;
1755                 int msgId = 0;
1756                 IMessagePtr msg = converter->toIMessage(object);
1757
1758                 if (msg->getMessageType() != EMAIL)
1759                 {
1760                         LogDebug("not EMAIL type");
1761                         return JSValueMakeNull(context);
1762                 }
1763
1764                 IEmailPtr email = MessageFactory::convertToEmail(msg);
1765                 msgId = email->getUID();
1766
1767                 LogDebug("msg.getConvId()=" << msg->getConvId());
1768                 convId = msg->getConvId();
1769                 /*
1770                 EventGetConversationIdPtr event(new EventGetConversationId());
1771                 event->setConversationMsgPtr(msg);
1772                 event->setForSynchronousCall();
1773                 ReqReceiverMessageSingleton::Instance().getConversationId(event);
1774                 convId = event->getConversationId();
1775                 */
1776                 if (convId == msgId)
1777                 {
1778                         LogDebug("Not forwared and replied, return NULL");
1779                         return JSValueMakeNull(context);
1780                 }
1781
1782                 return converter->toJSValueRef(converter->convertIntToString(convId));
1783         }
1784         Catch(WrtDeviceApis::Commons::ConversionException) {
1785                 LogError("Error on conversion");
1786                 return JSTizenExceptionFactory::postException(context, exception,
1787                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1788         }
1789         Catch(WrtDeviceApis::Commons::NullPointerException) {
1790                 LogError("Error on pointer, null value");
1791                 return JSTizenExceptionFactory::postException(context, exception,
1792                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1793         }
1794         Catch(WrtDeviceApis::Commons::PlatformException) {
1795                 LogError("Platform execution");
1796                 return JSTizenExceptionFactory::postException(context, exception,
1797                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1798         }
1799 }
1800
1801 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
1802                         JSObjectRef object,
1803                         JSStringRef propertyName,
1804                         JSValueRef* exception)
1805 {
1806         LogInfo("getMessageStatus");
1807
1808         Try
1809         {
1810                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1811                 if (!priv)
1812                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1813
1814                 JSContextRef globalContext = priv->getContext();
1815
1816                 ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
1817
1818                 IMessagePtr msg = converter->toIMessage(object); //get message point
1819
1820                 LogInfo("create JS");
1821                 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1822         }
1823         Catch(WrtDeviceApis::Commons::ConversionException) {
1824                 LogError("Error on conversion");
1825                 return JSTizenExceptionFactory::postException(context, exception,
1826                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1827         }
1828         Catch(WrtDeviceApis::Commons::NullPointerException) {
1829                 LogError("Error on pointer, null value");
1830                 return JSTizenExceptionFactory::postException(context, exception,
1831                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1832         }
1833 }
1834
1835
1836 JSValueRef JSMessage::hasAttachment(JSContextRef context,
1837                         JSObjectRef object,
1838                         JSStringRef propertyName,
1839                         JSValueRef* exception)
1840 {
1841         LogInfo("hasAttachment");
1842
1843         Try
1844                 {
1845                 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1846                 if (!priv)
1847                         ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1848
1849                 JSContextRef globalContext = priv->getContext();
1850
1851                 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1852
1853                 IMessagePtr msg = converter->toIMessage(object); //get message point
1854
1855                 bool hasAttachmentFlag = false;
1856
1857                 if ( msg->getMessageType() == EMAIL)
1858                 {
1859                         IEmailPtr email = MessageFactory::convertToEmail(msg);
1860
1861                         if (email->hasAttachment())
1862                                 hasAttachmentFlag = true;
1863                 }
1864                 else if  ( msg->getMessageType() == MMS)
1865                 {
1866                         IMmsPtr mms = MessageFactory::convertToMms(msg);
1867
1868                         if (mms->hasAttachment())
1869                                 hasAttachmentFlag = true;
1870                 }
1871                 else
1872                 {
1873                         return JSValueMakeNull(context);
1874                 }
1875                 return converter->toJSValueRef(hasAttachmentFlag);
1876
1877         }
1878         Catch(WrtDeviceApis::Commons::ConversionException) {
1879                 LogError("Error on conversion");
1880                 return JSTizenExceptionFactory::postException(context, exception,
1881                                 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
1882         }
1883         Catch(WrtDeviceApis::Commons::NullPointerException) {
1884                 LogError("Error on pointer, null value");
1885                 return JSTizenExceptionFactory::postException(context, exception,
1886                                 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1887         }
1888 }
1889
1890 #if 0
1891 JSValueRef JSMessage::getAttachmentExistence(JSContextRef context,
1892                         JSObjectRef object,
1893                         JSStringRef propertyName,
1894                         JSValueRef* exception)
1895 {
1896         LogInfo("getAttachmentExistence");
1897
1898         Try
1899         {
1900           JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1901           Assert(priv && "Private object is NULL.");
1902
1903           JSContextRef globalContext = priv->getContext();
1904
1905           ConverterMessageFactory::ConverterType converter =  ConverterMessageFactory::getConverter(globalContext);
1906
1907           IMessagePtr msg = converter->toIMessage(object); //get message point
1908
1909           LogInfo("create JS");
1910           return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1911
1912         }
1913         Catch(WrtDeviceApis::Commons::ConversionException) {
1914                 LogError("Error on conversion");
1915           return JSTizenExceptionFactory::postException(context, exception, 
1916                    JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1917         }
1918         Catch(WrtDeviceApis::Commons::NullPointerException) {
1919                 LogError("Error on pointer, null value");
1920           return JSTizenExceptionFactory::postException(context, exception, 
1921                  JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1922         }
1923         
1924         return JSValueMakeUndefined(context);
1925 }
1926 #endif
1927
1928 }
1929 }