2 // Tizen Web Device API
3 // Copyright (c) 2012 Samsung Electronics Co., Ltd.
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
9 // http://www.apache.org/licenses/LICENSE-2.0
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.
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"
31 #include <JSTizenExceptionFactory.h>
32 #include <JSTizenException.h>
33 #include <SecurityExceptions.h>
35 #include <CommonsJavaScript/ScopedJSStringRef.h>
37 #include "MessagingErrorMsg.h"
38 #include "JSMessageAttachment.h"
39 #include "plugin_config.h"
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;
53 JSClassRef JSMessage::m_jsClassRef = NULL;
55 JSClassDefinition JSMessage::m_classInfo = {
57 kJSClassAttributeNone,
67 NULL, //deleteProperty,
68 NULL, //getPropertyNames,
69 NULL, //callAsFunction,
70 constructor, //callAsConstructor,
72 NULL, //convertToType,
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},
100 JSValueRef JSMessage::createJSObject(JSContextRef context,
101 EmailAccountInfo& account,
103 const std::string& msgId)
106 LogDebug("createJSObject with account ");
110 if (msgType == EMAIL)
112 LogDebug("Account Address:" << &account);
113 LogDebug("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
115 msg = MessageFactory::createMessage(msgType, account, msgId);
117 return JSValueMakeUndefined(context);
121 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
124 Catch(WrtDeviceApis::Commons::UnknownException) {
125 LogError("wrong message type, object not created");
126 return JSValueMakeUndefined(context);
129 return createJSObject(context, msg);
132 JSValueRef JSMessage::createJSObject(JSContextRef context,
133 EventUpdateMessageAnswerReceiver* listener,
140 // create message depending on type
141 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
143 msg = MessageFactory::createMessage(msgType, msgId);
145 return JSValueMakeUndefined(context);
149 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
152 Catch(WrtDeviceApis::Commons::UnknownException) {
153 LogError("wrong message type, object not created");
154 return JSValueMakeUndefined(context);
156 return createJSObject(context, msg, listener);
159 JSValueRef JSMessage::createJSObject(JSContextRef context,
160 const IMessagePtr& msg,
161 EventUpdateMessageAnswerReceiver* listener)
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);
175 JSValueRef JSMessage::createJSObject(JSContextRef context,
176 const IMessagePtr& msg)
178 LogDebug("createJSObject");
179 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
180 LogDebug("jsClassRef success");
181 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
182 LogDebug("priv success");
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);
194 JSValueRef JSMessage::createJSObject(JSContextRef context,
201 // create message depending on type
202 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
204 msg = MessageFactory::createMessage(msgType, msgId);
208 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
211 Catch(WrtDeviceApis::Commons::UnknownException) {
212 LogError("wrong message type, object not created");
213 return JSValueMakeUndefined(context);
215 return createJSObject(context, msg, NULL);
218 JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
222 if (msgType == EMAIL )
224 msg = MessageFactory::createEmailMessage();
228 LogError("message type is invalid");
229 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
231 return createJSObject(context, msg);
234 void JSMessage::initialize(JSContextRef context,
239 if (!JSObjectGetPrivate(object))
241 IMessagePtr msg(new Sms());
242 JSMessagePrivateObject *priv = new JSMessagePrivateObject(context, msg);
243 if (!JSObjectSetPrivate(object, priv))
245 LogInfo("set Private Failed...");
251 void JSMessage::finalize(JSObjectRef object)
253 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
255 LogDebug("deleting private object");
257 JSObjectSetPrivate(object, NULL);
261 bool JSMessage::hasProperty(JSContextRef context,
263 JSStringRef propertyName)
268 JSValueRef JSMessage::getProperty(JSContextRef context,
270 JSStringRef propertyName,
271 JSValueRef* exception)
273 LogError("should not enter");
274 return JSValueMakeUndefined(context);
277 bool JSMessage::setProperty(JSContextRef context,
279 JSStringRef propertyName,
281 JSValueRef* exception)
283 LogError("should not enter");
287 bool JSMessage::deleteProperty(JSContextRef context,
289 JSStringRef propertyName,
290 JSValueRef* exception)
296 void JSMessage::getPropertyNames(JSContextRef context,
298 JSPropertyNameAccumulatorRef propertyNames)
303 JSValueRef JSMessage::callAsFunction(JSContextRef context,
305 JSObjectRef thisObject,
306 size_t argumentCount,
307 const JSValueRef arguments[],
308 JSValueRef* exception)
311 return JSValueMakeUndefined(context);
314 bool JSMessage::hasInstance(JSContextRef context,
315 JSObjectRef constructor,
316 JSValueRef possibleInstance,
317 JSValueRef* exception)
323 JSObjectRef JSMessage::constructor(JSContextRef context,
324 JSObjectRef constructor,
325 size_t argumentCount,
326 const JSValueRef arguments[],
327 JSValueRef* exception)
331 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(constructor));
332 JSContextRef globalContext = priv ? priv->getContext() : context;
336 LogDebug(" globalContext is NULL ");
337 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
343 if ( argumentCount < 1 ) {
344 LogError("Wrong argument count");
345 ThrowMsg(WrtDeviceApis::Commons::InvalidArgumentException, "Wrong Message argumentCount");
348 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
349 MessageType msgType = converter->toMessageType(arguments[0]);
350 //objMsg = JSMessage::createDummyMessageJSObject(globalContext, msgType); //make message JSValueRef.
353 if ( msgType == EMAIL )
355 msg = MessageFactory::createEmailMessage();
357 else if (msgType == MMS || msgType == SMS)
359 msg = MessageFactory::createMessage(msgType); //create message
363 LogError("message type is invalid");
364 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
369 if ( argumentCount == 2 )
371 LogDebug ("##### msg type is " << msgType);
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"));
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);
391 if (!JSValueIsUndefined(globalContext, subjectData) )
393 LogDebug ( " Subject : " << converter->toString(subjectData) );
394 std::string subject = converter->toString(subjectData);
399 IMmsPtr mms = MessageFactory::convertToMms(msg);
400 mms->setSubject(subject);
405 IEmailPtr email = MessageFactory::convertToEmail(msg);
406 email->setSubject(subject);
411 LogError("message not supported");
412 //Throw(WrtDeviceApis::Commons::UnsupportedException);
418 if (!JSValueIsUndefined(globalContext, toData) )
420 Recipients to = converter->toRecipients(toData);
421 LogDebug("setting to field, size=" << to.getRecipientSize());
422 msg->setToRecipients(to);
425 if (msgType == EMAIL )
427 IEmailPtr email = MessageFactory::convertToEmail(msg);
428 if (!JSValueIsUndefined(globalContext, ccData))
430 Recipients cc = converter->toRecipients(ccData);
431 email->setCcRecipients(cc);
434 if (!JSValueIsUndefined(globalContext, bccData))
436 Recipients bcc = converter->toRecipients(bccData);
437 email->setBccRecipients(bcc);
440 if (!JSValueIsUndefined(globalContext, htmlBodyData))
442 std::string body = converter->toString(htmlBodyData);
443 LogDebug("html body : " << body);
444 email->setHtmlBody(body);
447 if (!JSValueIsUndefined(globalContext, priorityData))
449 email->setPriority(converter->toMessagePriority(priorityData));
452 if (!JSValueIsUndefined(globalContext, plainBodyData) )
454 std::string body = converter->toString(plainBodyData);
455 LogDebug("plain body : " << body);
462 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
463 LogDebug("jsClassRef success");
464 JSMessagePrivateObject* priv = new JSMessagePrivateObject(globalContext, msg);
465 LogDebug("priv success");
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");
479 LogDebug("Message Creation failed");
480 ThrowMsg(WrtDeviceApis::Commons::PlatformException, "message has been not created");
483 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
484 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
487 Catch(WrtDeviceApis::Commons::ConversionException) {
488 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_TYPE_MISMATCH);
491 Catch(WrtDeviceApis::Commons::PlatformException) {
492 *exception = JSTizenExceptionFactory::makeErrorObject(context, JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
498 JSValueRef JSMessage::convertToType(JSContextRef context,
501 JSValueRef* exception)
504 return JSValueMakeUndefined(context);
507 JSValueRef JSMessage::getAttachments(JSContextRef context,
509 JSStringRef propertyName,
510 JSValueRef* exception)
515 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
517 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
519 JSContextRef globalContext = priv->getContext();
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);
533 std::vector<IAttachmentPtr> attachments;
534 std::vector<IAttachmentPtr>::iterator it;
536 if ( msgType == MMS )
538 AttachmentsPtr mmsAttachments =
539 DPL::StaticPointerCast<Attachments>(MessageFactory::convertToMms(msg));
540 attachments = mmsAttachments->getAttachments();
544 AttachmentsPtr emailAttachments =
545 DPL::StaticPointerCast<Attachments>(MessageFactory::convertToEmail(msg));
546 attachments = emailAttachments->getAttachments();
549 int count = attachments.size();
550 LogDebug( "count : " << count);
552 JSObjectRef jsMessageAttachmentObject[count]; //make
554 for (unsigned int index = 0 ; index < attachments.size(); index++ )
556 LogDebug( "Attachment ID : " << attachments[index]->getAttachmentID());
557 jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(globalContext, attachments[index] );
559 JSObjectRef result = JSObjectMakeArray(globalContext, count, jsMessageAttachmentObject, NULL);
563 return JSValueMakeNull(context);
565 LogError("not supported message type");
566 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
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);
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);
582 JSValueRef JSMessage::getBccAddress(JSContextRef context,
584 JSStringRef propertyName,
585 JSValueRef* exception)
590 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
591 IMessagePtr msg = converter->toIMessage(object);
592 MessageType msgType = msg->getMessageType();
598 IEmailPtr email = MessageFactory::convertToEmail(msg);
599 RecipientsPtr recipient = email->getBccRecipientsPtr();
600 JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
601 if (NULL == arrayValue)
603 LogError("Could not create js array object");
604 return JSValueMakeUndefined(context);
606 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
608 JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)));
614 return JSValueMakeNull(context);
617 LogError("not supported message type");
618 return JSTizenExceptionFactory::postException(context, exception,
619 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
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);
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);
635 JSValueRef JSMessage::getBody(JSContextRef context,
637 JSStringRef propertyName,
638 JSValueRef* exception)
642 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
643 IMessagePtr msg = converter->toIMessage(object);
644 string body = msg->getBody();
645 return converter->toJSValueRef(body);
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);
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);
659 JSValueRef JSMessage::getCcAddress(JSContextRef context,
661 JSStringRef propertyName,
662 JSValueRef* exception)
667 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
668 IMessagePtr msg = converter->toIMessage(object);
669 MessageType msgType = msg->getMessageType();
675 IEmailPtr email = MessageFactory::convertToEmail(msg);
676 RecipientsPtr recipient = email->getCcRecipientsPtr();
677 JSObjectRef arrayValue = JSCreateArrayObject(context, 0, NULL);
678 if (NULL == arrayValue)
680 LogError("Could not create js array object");
681 return JSValueMakeUndefined(context);
683 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
685 JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)));
691 return JSValueMakeNull(context);
694 LogError("not supported message type");
695 return JSTizenExceptionFactory::postException(context, exception,
696 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
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);
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);
713 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
715 JSStringRef propertyName,
716 JSValueRef* exception)
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)
727 LogError("Could not create js array object");
728 return JSValueMakeUndefined(context);
730 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
732 JSSetArrayElement(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)));
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);
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);
748 JSValueRef JSMessage::getIsRead(JSContextRef context,
750 JSStringRef propertyName,
751 JSValueRef* exception)
755 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
756 IMessagePtr msg = converter->toIMessage(object);
757 bool isRead = msg->isRead();
758 return converter->toJSValueRef(isRead);
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);
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);
772 JSValueRef JSMessage::getMessageId(JSContextRef context,
774 JSStringRef propertyName,
775 JSValueRef* exception)
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)
786 return JSValueMakeNull(context);
788 return converter->toJSValueRef(id);
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);
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);
802 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
804 JSStringRef propertyName,
805 JSValueRef* exception)
809 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
810 IMessagePtr msg = converter->toIMessage(object);
811 MessageType msgType = msg->getMessageType();
816 return JSValueMakeNull(context);
819 IEmailPtr email = MessageFactory::convertToEmail(msg);
820 int tmpint = email->getPriority();
821 LogError("priority : " << tmpint);
822 if(tmpint == MessagePriority::HIGH)
824 return converter->toJSValueRef(true);
826 return converter->toJSValueRef(false);
829 LogError("unsupported message type");
830 return JSTizenExceptionFactory::postException(context, exception,
831 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
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);
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);
847 JSValueRef JSMessage::getMessageType(JSContextRef context,
849 JSStringRef propertyName,
850 JSValueRef* exception)
854 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
855 IMessagePtr msg = converter->toIMessage(object);
856 MessageType msgType = msg->getMessageType();
858 return converter->toJSValueRef(converter->toMessageType(msgType));
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);
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);
872 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
874 JSStringRef propertyName,
875 JSValueRef* exception)
879 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
880 IMessagePtr msg = converter->toIMessage(object);
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);
888 return converter->toJSValueRef(msg->getSourceAddress());
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);
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);
902 JSValueRef JSMessage::getSubject(JSContextRef context,
904 JSStringRef propertyName,
905 JSValueRef* exception)
909 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
910 IMessagePtr msg = converter->toIMessage(object);
911 MessageType msgType = msg->getMessageType();
916 IMmsPtr mms = MessageFactory::convertToMms(msg);
917 return converter->toJSValueRef(mms->getSubject());
921 IEmailPtr email = MessageFactory::convertToEmail(msg);
922 return converter->toJSValueRef(email->getSubject());
925 return JSValueMakeNull(context);
927 LogError("message not support subject");
928 return JSTizenExceptionFactory::postException(context, exception,
929 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
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);
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);
943 Catch(WrtDeviceApis::Commons::UnsupportedException) {
944 return JSTizenExceptionFactory::postException(context, exception,
945 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
949 JSValueRef JSMessage::getTime(JSContextRef context,
951 JSStringRef propertyName,
952 JSValueRef* exception)
956 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
957 IMessagePtr msg = converter->toIMessage(object);
958 struct tm dateTime = msg->getDateTime();
959 return converter->toJSValueRef(dateTime);
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);
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);
973 JSValueRef JSMessage::getFolder(JSContextRef context,
975 JSStringRef propertyName,
976 JSValueRef* exception)
980 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
981 IMessagePtr msg = converter->toIMessage(object);
982 FolderType folder = msg->getCurrentFolder();
984 int tmpInt = msg->getMessageStatus();
986 LogError("folder : " << folder);
987 LogError("msg->getMessageStatus() : " << tmpInt);
989 if(tmpInt == MESSAGE_STATUS_CREATED)
991 return JSValueMakeNull(context);
994 tmpInt = (int)folder;
995 return converter->toJSValueRef(converter->convertIntToString(tmpInt));
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);
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);
1009 JSValueRef JSMessage::getMessageBody(JSContextRef context,
1011 JSStringRef propertyName,
1012 JSValueRef* exception)
1014 LogInfo("getMessageBody");
1018 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1020 ThrowMsg(WrtDeviceApis::Commons::NullPointerException, "Couldn't get Messaage Private Object");
1022 JSContextRef globalContext = priv->getContext();
1024 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1025 IMessagePtr msg = converter->toIMessage(object); //get message point
1027 return JSMessageBody::createJS(globalContext, msg);
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);
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);
1041 JSValueRef JSMessage::getAccountID(JSContextRef context,
1043 JSStringRef propertyName,
1044 JSValueRef* exception)
1046 LogInfo("getAccountID");
1050 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1052 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1054 JSContextRef globalContext = priv->getContext();
1056 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1058 IMessagePtr msg = converter->toIMessage(object); //get message point
1060 LogInfo("create JS");
1062 if (msg->getMessageType() == EMAIL)
1064 IEmailPtr email = MessageFactory::convertToEmail(msg);
1065 if(email->getAccountID() == -1)
1067 return JSValueMakeNull(context);
1069 std::stringstream stream;
1070 stream << email->getAccountID();
1071 if (stream.fail()) {
1072 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert e-mail account id");
1075 return converter->toJSValueRef(stream.str());
1077 else if (msg->getMessageType() == SMS)
1079 std::stringstream stream;
1080 stream << SMS_ACCOUNT_ID;
1081 if (stream.fail()) {
1082 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert sms account id");
1085 return converter->toJSValueRef(stream.str());
1087 else if (msg->getMessageType() == MMS)
1089 std::stringstream stream;
1090 stream << MMS_ACCOUNT_ID;
1091 if (stream.fail()) {
1092 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't convert mms account id");
1095 return converter->toJSValueRef(stream.str());
1099 return JSValueMakeUndefined(context);
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);
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);
1114 JSValueRef JSMessage::getUID(JSContextRef context,
1116 JSStringRef propertyName,
1117 JSValueRef* exception)
1123 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1125 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1127 JSContextRef globalContext = priv->getContext();
1129 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1131 IMessagePtr msg = converter->toIMessage(object); //get message point
1133 LogInfo("create JS");
1135 if (msg->getMessageType() == EMAIL)
1137 IEmailPtr email = MessageFactory::convertToEmail(msg);
1138 return converter->toJSValueRef(email->getUID());
1142 return JSValueMakeUndefined(context);
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);
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);
1157 bool JSMessage::setAttachments(JSContextRef context,
1159 JSStringRef propertyName,
1161 JSValueRef* exception)
1167 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1170 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1172 JSContextRef globalContext = priv->getContext();
1175 LogDebug("globalContext is NULL");
1176 globalContext = context;
1178 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
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)
1187 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1188 if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
1189 LogWarning("Invalid array element. Skipping.");
1192 IAttachmentPtr attachment = converter->toIAttachment(att);
1194 if(attachment->getIsValidAttachment() == false)
1196 LogDebug("invalid attachment : " << i);
1197 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1200 LogDebug("Adding attachment , shotname: " << attachment->getShortName());
1201 attachments.push_back(attachment);
1206 IAttachmentPtr attachment = converter->toIAttachment(value);
1207 LogDebug("Adding attachment , shotname: " << attachment->getShortName());
1208 if(attachment->getIsValidAttachment() == false)
1210 LogDebug("invalid attachment");
1211 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1213 attachments.push_back(attachment);
1216 LogDebug("Attachment Size =" << attachments.size());
1217 if ( attachments.size() > 0)
1219 IMessagePtr msg = converter->toIMessage(object);
1222 MessageType msgType = msg->getMessageType();
1226 IMmsPtr mms = MessageFactory::convertToMms(msg);
1227 mms->setAttachments(attachments);
1232 IEmailPtr email = MessageFactory::convertToEmail(msg);
1233 email->setAttachments(attachments);
1237 LogError("not supported message type");
1238 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1244 LogError("Message converter failed...");
1245 Throw(WrtDeviceApis::Commons::NullPointerException);
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);
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);
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);
1264 Catch(WrtDeviceApis::Commons::UnsupportedException) {
1265 return JSTizenExceptionFactory::postException(context, exception,
1266 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1272 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
1273 bool JSMessage::setAttachments(JSContextRef context,
1275 JSStringRef propertyName,
1277 JSValueRef* exception)
1283 JSMessagePrivateObject* priv =
1284 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1287 return JSTizenExceptionFactory::postException(context, exception,
1288 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
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);
1297 vector<string> attachments;
1300 ConverterMessageFactory::ConverterType converter =
1301 ConverterMessageFactory::getConverter(context);
1302 if (JSIsArrayValue(context, value)) {
1303 JSObjectRef valueObj = converter->toJSObjectRef(value);
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.");
1314 DeviceAPI::Filesystem::INodePtr node = converter->toFilesystemNode(
1317 LogDebug("Adding attachment: " << node->getPath()->getFullPath());
1318 attachments.push_back(node->getPath()->getFullPath());
1321 LogWarning("Invalid or null element passed as attachment array." <<
1322 "Setting empty vector.");
1325 // set up new attachments list
1326 IMessagePtr msg = converter->toIMessage(object);
1327 MessageType msgType = msg->getMessageType();
1331 IMmsPtr mms = MessageFactory::convertToMms(msg);
1332 mms->setAttachments(attachments, true);
1337 IEmailPtr email = MessageFactory::convertToEmail(msg);
1338 email->setAttachments(attachments, true);
1343 return false; // ignore
1346 LogError("not supported message type");
1347 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
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);
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);
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);
1370 bool JSMessage::setBccAddress(JSContextRef context,
1372 JSStringRef propertyName,
1374 JSValueRef* exception)
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());
1383 MessageType msgType = msg->getMessageType();
1387 return false; // ignore
1391 IEmailPtr email = MessageFactory::convertToEmail(msg);
1392 email->setBccRecipients(bcc);
1396 LogError("unsupported message type");
1397 return JSTizenExceptionFactory::postException(context, exception,
1398 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
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);
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);
1412 Catch(WrtDeviceApis::Commons::PlatformException) {
1413 LogError("Platform execution");
1414 return JSTizenExceptionFactory::postException(context, exception,
1415 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1420 bool JSMessage::setBody(JSContextRef context,
1422 JSStringRef propertyName,
1424 JSValueRef* exception)
1428 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1429 IMessagePtr msg = converter->toIMessage(object);
1430 string body = converter->toString(value);
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);
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);
1444 Catch(WrtDeviceApis::Commons::PlatformException) {
1445 LogError("Platform execution");
1446 return JSTizenExceptionFactory::postException(context, exception,
1447 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1452 bool JSMessage::setCcAddress(JSContextRef context,
1454 JSStringRef propertyName,
1456 JSValueRef* exception)
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());
1465 MessageType msgType = msg->getMessageType();
1469 return false; // ignore
1473 IEmailPtr email = MessageFactory::convertToEmail(msg);
1474 email->setCcRecipients(cc);
1478 LogError("unsuported message type");
1479 return JSTizenExceptionFactory::postException(context, exception,
1480 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED); // unsupported type
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);
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);
1495 Catch(WrtDeviceApis::Commons::PlatformException) {
1496 LogError("Platform execution");
1497 return JSTizenExceptionFactory::postException(context, exception,
1498 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1503 bool JSMessage::setDestinationAddress(JSContextRef context,
1505 JSStringRef propertyName,
1507 JSValueRef * exception)
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);
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);
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);
1529 Catch(WrtDeviceApis::Commons::PlatformException) {
1530 LogError("Platform execution");
1531 return JSTizenExceptionFactory::postException(context, exception,
1532 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1537 bool JSMessage::setIsRead(JSContextRef context,
1539 JSStringRef propertyName,
1541 JSValueRef * exception)
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));
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);
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);
1564 bool JSMessage::setMessagePriority(JSContextRef context,
1566 JSStringRef propertyName,
1568 JSValueRef * exception)
1572 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1573 IMessagePtr msg = converter->toIMessage(object);
1574 MessageType msgType = msg->getMessageType();
1578 return false; // ignore
1581 msg->setPriority(converter->toMessagePriority(value));
1585 LogError("unsuported message type");
1586 Throw(WrtDeviceApis::Commons::ConversionException);
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);
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);
1601 Catch(WrtDeviceApis::Commons::PlatformException) {
1602 LogError("Platform execution");
1603 return JSTizenExceptionFactory::postException(context, exception,
1604 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1609 bool JSMessage::setSubject(JSContextRef context,
1611 JSStringRef propertyName,
1613 JSValueRef * exception)
1617 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1618 IMessagePtr msg = converter->toIMessage(object);
1619 MessageType msgType = msg->getMessageType();
1620 string subject = converter->toString(value);
1624 IMmsPtr mms = MessageFactory::convertToMms(msg);
1625 mms->setSubject(subject);
1630 IEmailPtr email = MessageFactory::convertToEmail(msg);
1631 email->setSubject(subject);
1635 return false; // ignore
1638 LogError("message not supported");
1639 Throw(WrtDeviceApis::Commons::UnsupportedException);
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);
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);
1654 Catch(WrtDeviceApis::Commons::PlatformException) {
1655 LogError("Platform execution");
1656 return JSTizenExceptionFactory::postException(context, exception,
1657 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1659 Catch(WrtDeviceApis::Commons::UnsupportedException) {
1660 return JSTizenExceptionFactory::postException(context, exception,
1661 JSTizenException::NOT_SUPPORTED_ERROR, JSMESSAGING_EXCEPTION_MSG_NOT_SUPPORTED);
1666 bool JSMessage::setMessageBody(JSContextRef context,
1668 JSStringRef propertyName,
1670 JSValueRef* exception)
1674 LogDebug("Set Message Body.");
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);
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);
1687 Catch(WrtDeviceApis::Commons::PlatformException) {
1688 LogError("Platform execution");
1689 return JSTizenExceptionFactory::postException(context, exception,
1690 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1695 JSValueRef JSMessage::getConversationId(JSContextRef context,
1697 JSStringRef propertyName,
1698 JSValueRef* exception)
1700 LogDebug("getConversationId");
1704 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1706 IMessagePtr msg = converter->toIMessage(object);
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)
1713 return JSValueMakeNull(context);
1715 return converter->toJSValueRef(converter->convertIntToString(convId));
1717 EventGetConversationIdPtr event(new EventGetConversationId());
1718 event->setConversationMsgPtr(msg);
1719 event->setForSynchronousCall();
1720 ReqReceiverMessageSingleton::Instance().getConversationId(event);
1722 convId = event->getConversationId();
1723 // TODO messageIDref string size 0 => return NULL
1724 return converter->toJSValueRef(convId);
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);
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);
1737 Catch(WrtDeviceApis::Commons::PlatformException) {
1738 LogError("Platform execution");
1739 return JSTizenExceptionFactory::postException(context, exception,
1740 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1744 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
1746 JSStringRef propertyName,
1747 JSValueRef* exception)
1749 LogDebug("getInResponseTo");
1753 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1756 IMessagePtr msg = converter->toIMessage(object);
1758 if (msg->getMessageType() != EMAIL)
1760 LogDebug("not EMAIL type");
1761 return JSValueMakeNull(context);
1764 IEmailPtr email = MessageFactory::convertToEmail(msg);
1765 msgId = email->getUID();
1767 LogDebug("msg.getConvId()=" << msg->getConvId());
1768 convId = msg->getConvId();
1770 EventGetConversationIdPtr event(new EventGetConversationId());
1771 event->setConversationMsgPtr(msg);
1772 event->setForSynchronousCall();
1773 ReqReceiverMessageSingleton::Instance().getConversationId(event);
1774 convId = event->getConversationId();
1776 if (convId == msgId)
1778 LogDebug("Not forwared and replied, return NULL");
1779 return JSValueMakeNull(context);
1782 return converter->toJSValueRef(converter->convertIntToString(convId));
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);
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);
1794 Catch(WrtDeviceApis::Commons::PlatformException) {
1795 LogError("Platform execution");
1796 return JSTizenExceptionFactory::postException(context, exception,
1797 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1801 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
1803 JSStringRef propertyName,
1804 JSValueRef* exception)
1806 LogInfo("getMessageStatus");
1810 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1812 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1814 JSContextRef globalContext = priv->getContext();
1816 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1818 IMessagePtr msg = converter->toIMessage(object); //get message point
1820 LogInfo("create JS");
1821 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
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);
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);
1836 JSValueRef JSMessage::hasAttachment(JSContextRef context,
1838 JSStringRef propertyName,
1839 JSValueRef* exception)
1841 LogInfo("hasAttachment");
1845 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1847 ThrowMsg(WrtDeviceApis::Commons::UnknownException, "Couldn't get Messaage Private Object");
1849 JSContextRef globalContext = priv->getContext();
1851 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1853 IMessagePtr msg = converter->toIMessage(object); //get message point
1855 bool hasAttachmentFlag = false;
1857 if ( msg->getMessageType() == EMAIL)
1859 IEmailPtr email = MessageFactory::convertToEmail(msg);
1861 if (email->hasAttachment())
1862 hasAttachmentFlag = true;
1864 else if ( msg->getMessageType() == MMS)
1866 IMmsPtr mms = MessageFactory::convertToMms(msg);
1868 if (mms->hasAttachment())
1869 hasAttachmentFlag = true;
1873 return JSValueMakeNull(context);
1875 return converter->toJSValueRef(hasAttachmentFlag);
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);
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);
1891 JSValueRef JSMessage::getAttachmentExistence(JSContextRef context,
1893 JSStringRef propertyName,
1894 JSValueRef* exception)
1896 LogInfo("getAttachmentExistence");
1900 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1901 Assert(priv && "Private object is NULL.");
1903 JSContextRef globalContext = priv->getContext();
1905 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1907 IMessagePtr msg = converter->toIMessage(object); //get message point
1909 LogInfo("create JS");
1910 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
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);
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);
1924 return JSValueMakeUndefined(context);