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>
36 // ==== new common headers
37 #include <GlobalContextManager.h>
38 #include <PlatformException.h>
39 #include <JSWebAPIError.h>
40 #include <JSWebAPIException.h>
42 #include <ArgumentValidator.h>
45 #include "MessagingErrorMsg.h"
46 #include "JSMessageAttachment.h"
47 #include "plugin_config.h"
52 using namespace DeviceAPI::Common;
53 using namespace WrtDeviceApis::Commons;
54 using namespace WrtDeviceApis::CommonsJavaScript;
58 JSClassRef JSMessage::m_jsClassRef = NULL;
60 #define MESSAGE_ATTRIBUTE_ID "id"
61 #define MESSAGE_ATTRIBUTE_SERVICE_ID "serviceId"
62 #define MESSAGE_ATTRIBUTE_CONVERSATION_ID "conversationId"
63 #define MESSAGE_ATTRIBUTE_FOLDER_ID "folderId"
64 #define MESSAGE_ATTRIBUTE_TYPE "type"
65 #define MESSAGE_ATTRIBUTE_TIMESTAMP "timestamp"
66 #define MESSAGE_ATTRIBUTE_FROM "from"
67 #define MESSAGE_ATTRIBUTE_TO "to" // used also in dictionary
68 #define MESSAGE_ATTRIBUTE_CC "cc" // used also in dictionary
69 #define MESSAGE_ATTRIBUTE_BCC "bcc" // used also in dictionary
70 #define MESSAGE_ATTRIBUTE_BODY "body"
71 #define MESSAGE_ATTRIBUTE_IS_READ "isRead"
72 #define MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY "isHighPriority" // used also in dictionary
73 #define MESSAGE_ATTRIBUTE_SUBJECT "subject" // used also in dictionary
74 #define MESSAGE_ATTRIBUTE_IN_RESPONSE_TO "inResponseTo"
75 #define MESSAGE_ATTRIBUTE_MESSAGE_STATUS "messageStatus"
76 #define MESSAGE_ATTRIBUTE_ATTACHMENTS "attachments"
77 #define MESSAGE_ATTRIBUTE_HAS_ATTACHMENT "hasAttachment"
79 #define MESSAGE_DICTIONARY_ATTRIBUTE_PLAIN_BODY "plainBody"
80 #define MESSAGE_DICTIONARY_ATTRIBUTE_HTML_BODY "htmlBody"
82 JSClassDefinition JSMessage::m_classInfo = {
84 kJSClassAttributeNone,
87 NULL, // m_property not used here - access properties by setProperty()/getProperty()
92 JSMessage::getProperty, //getProperty,
93 JSMessage::setProperty, //setProperty,
94 NULL, //deleteProperty,
95 JSMessage::getPropertyNames, //getPropertyNames,
96 NULL, //callAsFunction,
97 NULL, //callAsConstructor,
99 NULL, //convertToType,
102 // JSMessage properties - used in: getProperty(), setProperty(), getPropertyNames()
103 JSStaticValue JSMessage::m_property[] = {
104 { MESSAGE_ATTRIBUTE_ID, getMessageId, NULL, kJSPropertyAttributeReadOnly },
105 { MESSAGE_ATTRIBUTE_SERVICE_ID, getAccountID, NULL, kJSPropertyAttributeReadOnly},
106 { MESSAGE_ATTRIBUTE_CONVERSATION_ID, getConversationId, NULL, kJSPropertyAttributeReadOnly },
107 { MESSAGE_ATTRIBUTE_FOLDER_ID, getFolder, NULL, kJSPropertyAttributeReadOnly },
108 { MESSAGE_ATTRIBUTE_TYPE, getMessageType, NULL, kJSPropertyAttributeReadOnly },
109 { MESSAGE_ATTRIBUTE_TIMESTAMP, getTime, NULL, kJSPropertyAttributeReadOnly },
110 { MESSAGE_ATTRIBUTE_FROM, getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
111 { MESSAGE_ATTRIBUTE_TO, getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
112 { MESSAGE_ATTRIBUTE_CC, getCcAddress, setCcAddress, kJSPropertyAttributeNone },
113 { MESSAGE_ATTRIBUTE_BCC, getBccAddress, setBccAddress, kJSPropertyAttributeNone },
114 { MESSAGE_ATTRIBUTE_BODY, getMessageBody, setMessageBody, kJSPropertyAttributeNone },
115 { MESSAGE_ATTRIBUTE_IS_READ, getIsRead, setIsRead, kJSPropertyAttributeNone },
116 { MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY, getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
117 { MESSAGE_ATTRIBUTE_SUBJECT, getSubject, setSubject, kJSPropertyAttributeNone },
118 { MESSAGE_ATTRIBUTE_IN_RESPONSE_TO, getInResponseTo, NULL, kJSPropertyAttributeNone },
119 { MESSAGE_ATTRIBUTE_MESSAGE_STATUS, getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
120 { MESSAGE_ATTRIBUTE_ATTACHMENTS, getAttachments, setAttachments, kJSPropertyAttributeNone },
121 { MESSAGE_ATTRIBUTE_HAS_ATTACHMENT, hasAttachment, NULL, kJSPropertyAttributeReadOnly},
126 JSValueRef JSMessage::createJSObject(JSContextRef context,
127 EmailAccountInfo& account,
129 const std::string& msgId)
132 LoggerD("createJSObject with account ");
136 if (msgType == EMAIL)
138 LoggerD("Account Address:" << &account);
139 LoggerD("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
141 msg = MessageFactory::createMessage(msgType, account, msgId);
143 return JSValueMakeUndefined(context);
147 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
150 Catch(WrtDeviceApis::Commons::UnknownException) {
151 LoggerE("wrong message type, object not created");
152 return JSValueMakeUndefined(context);
155 return createJSObject(context, msg);
158 JSValueRef JSMessage::createJSObject(JSContextRef context,
159 EventUpdateMessageAnswerReceiver* listener,
166 // create message depending on type
167 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
169 msg = MessageFactory::createMessage(msgType, msgId);
171 return JSValueMakeUndefined(context);
175 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
178 Catch(WrtDeviceApis::Commons::UnknownException) {
179 LoggerE("wrong message type, object not created");
180 return JSValueMakeUndefined(context);
182 return createJSObject(context, msg, listener);
185 JSValueRef JSMessage::createJSObject(JSContextRef context,
186 const IMessagePtr& msg,
187 EventUpdateMessageAnswerReceiver* listener)
189 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
190 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
191 priv->setUpdateMsgReceiver(listener);
192 JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
193 JSClassRelease(jsClassRef);
194 if (NULL == jsValueRef) {
195 LoggerE("object creation error");
196 return JSValueMakeUndefined(context);
201 JSValueRef JSMessage::createJSObject(JSContextRef context,
202 const IMessagePtr& msg)
204 LoggerD("createJSObject");
205 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
206 LoggerD("jsClassRef success");
207 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
208 LoggerD("priv success");
210 JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
211 LoggerD("JSObjectMake success");
212 JSClassRelease(jsClassRef);
213 if (NULL == jsValueRef) {
214 LoggerE("object creation error");
215 return JSValueMakeUndefined(context);
220 JSValueRef JSMessage::createJSObject(JSContextRef context,
227 // create message depending on type
228 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
230 msg = MessageFactory::createMessage(msgType, msgId);
234 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
237 Catch(WrtDeviceApis::Commons::UnknownException) {
238 LoggerE("wrong message type, object not created");
239 return JSValueMakeUndefined(context);
241 return createJSObject(context, msg, NULL);
244 JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
248 if (msgType == EMAIL )
250 msg = MessageFactory::createEmailMessage();
254 LoggerE("message type is invalid");
255 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
257 return createJSObject(context, msg);
260 void JSMessage::initialize(JSContextRef context,
265 if (!JSObjectGetPrivate(object))
267 IMessagePtr msg(new Sms());
268 JSMessagePrivateObject *priv = new JSMessagePrivateObject(context, msg);
269 if (!JSObjectSetPrivate(object, priv))
271 LoggerI("set Private Failed...");
277 void JSMessage::finalize(JSObjectRef object)
279 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
281 LoggerD("deleting private object");
283 JSObjectSetPrivate(object, NULL);
287 bool JSMessage::hasProperty(JSContextRef context,
289 JSStringRef propertyName)
294 JSValueRef JSMessage::getProperty(JSContextRef context,
296 JSStringRef propertyName,
297 JSValueRef* exception)
299 LoggerI("Main getProperty()");
301 // for non-NULL property names
302 while(m_property[index].name != NULL) {
303 // if property name matches
304 if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
305 if(m_property[index].getProperty != NULL) {
306 // if getProperty() function exists - call it
307 return m_property[index].getProperty(context, object, propertyName, exception);
309 //otherwise return undefined
310 return JSValueMakeUndefined(context);
318 bool JSMessage::setProperty(JSContextRef context,
320 JSStringRef propertyName,
322 JSValueRef* exception)
324 LoggerI("Main setProperty()");
326 // for non-NULL property names
328 while(m_property[index].name != NULL) {
329 // if property name matches
330 if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
331 if(m_property[index].setProperty != NULL) {
332 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_TO)){
333 if (JSValueIsNull(context, value))
335 throw TypeMismatchException("Value is null");
337 JSUtil::JSArrayToStringVector(context, value);
339 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_CC)){
340 if (JSValueIsNull(context, value))
342 throw TypeMismatchException("Value is null");
344 JSUtil::JSArrayToStringVector(context, value);
346 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_BCC)){
347 if (JSValueIsNull(context, value))
349 throw TypeMismatchException("Value is null");
351 JSUtil::JSArrayToStringVector(context, value);
353 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_BODY)){
354 if (!JSValueIsNull(context, value)) {
355 if (!JSValueIsObject(context, value)) {
356 throw TypeMismatchException("Value is not Object");
358 JSUtil::JSValueToObject(context, value);
361 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_IS_READ)){
362 JSUtil::JSValueToBoolean(context, value);
364 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY)){
365 JSUtil::JSValueToBoolean(context, value);
367 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_SUBJECT)){
368 JSUtil::JSValueToString(context, value);
370 if (JSStringIsEqualToUTF8CString(propertyName, MESSAGE_ATTRIBUTE_ATTACHMENTS)){
371 if (!JSValueIsNull(context, value)) {
372 if (!JSValueIsObject(context, value)) {
373 throw TypeMismatchException("Value is not Object");
375 JSUtil::JSValueToObject(context, value);
378 // if setProperty() function exists - call it
379 return m_property[index].setProperty(context, object, propertyName, value, exception);
381 // otherwise return true (lack of function - readonly attribute)
387 } catch (const BasePlatformException &err) {
388 LoggerW(err.getName() << ": " << err.getMessage());
394 bool JSMessage::deleteProperty(JSContextRef context,
396 JSStringRef propertyName,
397 JSValueRef* exception)
403 void JSMessage::getPropertyNames(JSContextRef context,
405 JSPropertyNameAccumulatorRef propertyNames)
409 JSStringRef propertyName = NULL;
411 // repeat for each declared property - until null on property name
412 while(m_property[index].name != NULL) {
413 LoggerD("Property: " << m_property[index].name);
414 propertyName = JSStringCreateWithUTF8CString(m_property[index].name);
415 JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
416 JSStringRelease(propertyName);
421 JSValueRef JSMessage::callAsFunction(JSContextRef context,
423 JSObjectRef thisObject,
424 size_t argumentCount,
425 const JSValueRef arguments[],
426 JSValueRef* exception)
429 return JSValueMakeUndefined(context);
432 bool JSMessage::hasInstance(JSContextRef context,
433 JSObjectRef constructor,
434 JSValueRef possibleInstance,
435 JSValueRef* exception)
441 JSObjectRef JSMessage::constructor(JSContextRef context,
442 JSObjectRef constructor,
443 size_t argumentCount,
444 const JSValueRef arguments[],
445 JSValueRef* exception)
450 ArgumentValidator validator(context, argumentCount, arguments);
451 std::string msgTypeString = validator.toString(0);
452 MessageType msgType = stringToMessageType(msgTypeString);
453 JSObjectRef dictionary = validator.toObject(1, true);
454 // converter is still used for some parameter
455 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
458 if ( msgType == EMAIL )
460 msg = MessageFactory::createEmailMessage();
462 else if (msgType == MMS || msgType == SMS)
464 msg = MessageFactory::createMessage(msgType); //create message
468 // this should never happen - message type checking done in stringToMessageType()
469 LoggerE("message type is invalid");
470 throw TypeMismatchException("Invalid message type");
474 LoggerD("Message Creation failed");
475 throw DeviceAPI::Common::UnknownException("Message has been not created");
478 if (dictionary != NULL)
480 LoggerD ("##### msg type is " << msgType);
482 JSValueRef subjectData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_SUBJECT);
483 JSValueRef toData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_TO);
484 JSValueRef ccData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_CC);
485 JSValueRef bccData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_BCC);
486 JSValueRef plainBodyData = JSUtil::getProperty(context, dictionary, MESSAGE_DICTIONARY_ATTRIBUTE_PLAIN_BODY);
487 JSValueRef htmlBodyData = JSUtil::getProperty(context, dictionary, MESSAGE_DICTIONARY_ATTRIBUTE_HTML_BODY);
488 JSValueRef priorityData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY);
491 if (!JSValueIsUndefined(context, subjectData) )
493 std::string subject = JSUtil::JSValueToString(context, subjectData);
494 LoggerD (" Subject : " << subject);
499 IMmsPtr mms = MessageFactory::convertToMms(msg);
500 mms->setSubject(subject);
505 IEmailPtr email = MessageFactory::convertToEmail(msg);
506 email->setSubject(subject);
511 LoggerE("message not supported");
512 //Throw(WrtDeviceApis::Commons::UnsupportedException);
518 if (!JSValueIsUndefined(context, toData) )
520 Recipients to = converter->toRecipients(toData);
521 LoggerD("setting to field, size=" << to.getRecipientSize());
522 msg->setToRecipients(to);
525 if (msgType == EMAIL )
527 IEmailPtr email = MessageFactory::convertToEmail(msg);
528 if (!JSValueIsUndefined(context, ccData))
530 Recipients cc = converter->toRecipients(ccData);
531 email->setCcRecipients(cc);
534 if (!JSValueIsUndefined(context, bccData))
536 Recipients bcc = converter->toRecipients(bccData);
537 email->setBccRecipients(bcc);
540 if (!JSValueIsUndefined(context, htmlBodyData))
542 std::string body = JSUtil::JSValueToString(context, htmlBodyData);
543 LoggerD("html body : " << body);
544 email->setHtmlBody(body);
547 if (!JSValueIsUndefined(context, priorityData))
549 email->setPriority(converter->toMessagePriority(priorityData));
552 if (!JSValueIsUndefined(context, plainBodyData) )
554 std::string body = JSUtil::JSValueToString(context, plainBodyData);
555 LoggerD("plain body : " << body);
561 JSClassRef jsClassRef = JSClassCreate(JSMessage::getClassInfo());
562 LoggerD("jsClassRef success");
563 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
564 LoggerD("priv success");
566 JSObjectRef jsObjRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
567 LoggerD("JSObjectMake success");
568 JSClassRelease(jsClassRef);
569 if (NULL == jsObjRef) {
570 LoggerE("JSObject creation error");
571 throw DeviceAPI::Common::UnknownException("JSObject make error");
575 catch(BasePlatformException &bex) {
576 LoggerE("Message creation failed: " << bex.getMessage());
577 JSObjectRef error = JSWebAPIException::makeJSWebAPIException(context, bex);
582 DeviceAPI::Common::UnknownException err("UnknownError in Message constructor.");
583 JSObjectRef error = JSWebAPIException::makeJSWebAPIException(context, err);
590 JSValueRef JSMessage::convertToType(JSContextRef context,
593 JSValueRef* exception)
596 return JSValueMakeUndefined(context);
599 JSValueRef JSMessage::getAttachments(JSContextRef context,
601 JSStringRef propertyName,
602 JSValueRef* exception)
606 GlobalContextManager *gcm = GlobalContextManager::getInstance();
608 LoggerE("Failed to get GlobalContextManager");
609 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
611 JSContextRef globalContext = gcm->getGlobalContext(context);
613 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
614 IMessagePtr msg = converter->toIMessage(object);
615 MessageType msgType = msg->getMessageType();
616 LoggerI("msgType=" << msgType);
617 // prepare common values
618 JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(globalContext, NULL, NULL);
625 std::vector<IAttachmentPtr> attachments;
626 std::vector<IAttachmentPtr>::iterator it;
628 if ( msgType == MMS )
630 AttachmentsPtr mmsAttachments =
631 DPL::StaticPointerCast<Attachments>(MessageFactory::convertToMms(msg));
632 attachments = mmsAttachments->getAttachments();
636 AttachmentsPtr emailAttachments =
637 DPL::StaticPointerCast<Attachments>(MessageFactory::convertToEmail(msg));
638 attachments = emailAttachments->getAttachments();
641 int count = attachments.size();
642 LoggerD( "count : " << count);
644 JSObjectRef jsMessageAttachmentObject[count]; //make
646 for (unsigned int index = 0 ; index < attachments.size(); index++ )
648 LoggerD( "Attachment ID : " << attachments[index]->getAttachmentID());
649 jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(globalContext, attachments[index] );
651 JSObjectRef result = JSObjectMakeArray(globalContext, count, jsMessageAttachmentObject, NULL);
656 JSObjectRef arrayValue = JSObjectMakeArray(globalContext, 0, NULL, NULL);
657 if (NULL == arrayValue)
659 LoggerE("Could not create js array object");
660 return JSValueMakeUndefined(context);
665 LoggerE("Not supported message type");
666 /* unsupported type -> type is integral message attribute
667 * so error at this place means internal api error*/
668 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
672 catch(BasePlatformException &bex) {
673 LoggerE("Attachments getting failure: " << bex.getMessage());
674 return JSValueMakeUndefined(context);
677 LoggerE("UnknownError when getting attachments.");
678 return JSValueMakeUndefined(context);
683 JSValueRef JSMessage::getBccAddress(JSContextRef context,
685 JSStringRef propertyName,
686 JSValueRef* exception)
690 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
691 IMessagePtr msg = converter->toIMessage(object);
692 MessageType msgType = msg->getMessageType();
698 IEmailPtr email = MessageFactory::convertToEmail(msg);
699 RecipientsPtr recipient = email->getBccRecipientsPtr();
700 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
701 if (NULL == arrayValue)
703 LoggerE("Could not create js array object");
704 return JSValueMakeUndefined(context);
707 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
710 JSObjectSetPropertyAtIndex(context, arrayValue, i,
711 converter->toJSValueRef(recipient->getRecipient(i)), &referr);
714 /* previously it was DPL ConversionException converted in
715 * catch into TypeMismatch but it's more an internal error */
716 throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
724 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
725 if (NULL == arrayValue)
727 LoggerE("Could not create js array object");
728 return JSValueMakeUndefined(context);
733 LoggerE("not supported message type");
734 /* unsupported type -> type is integral message attribute
735 * so error at this place means internal api error*/
736 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
740 catch(BasePlatformException &bex) {
741 LoggerE("BCC addressess getting failure: " << bex.getMessage());
742 return JSValueMakeUndefined(context);
745 LoggerE("UnknownError when getting BCC addressess.");
746 return JSValueMakeUndefined(context);
750 JSValueRef JSMessage::getBody(JSContextRef context,
752 JSStringRef propertyName,
753 JSValueRef* exception)
756 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
757 IMessagePtr msg = converter->toIMessage(object);
758 string body = msg->getBody();
759 return converter->toJSValueRef(body);
761 catch(BasePlatformException &bex) {
762 /* Currently this exception will not be caught here as converter
763 * is using od-style, DPL exceptions. This catch sections
764 * is prepared for future converter refactoring */
765 LoggerE("Message body getting failure: " << bex.getMessage());
766 return JSValueMakeUndefined(context);
769 LoggerE("UnknownError when getting Message body.");
770 return JSValueMakeUndefined(context);;
774 JSValueRef JSMessage::getCcAddress(JSContextRef context,
776 JSStringRef propertyName,
777 JSValueRef* exception)
781 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
782 IMessagePtr msg = converter->toIMessage(object);
783 MessageType msgType = msg->getMessageType();
789 IEmailPtr email = MessageFactory::convertToEmail(msg);
790 RecipientsPtr recipient = email->getCcRecipientsPtr();
791 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
792 if (NULL == arrayValue)
794 LoggerE("Could not create js array object");
795 return JSValueMakeUndefined(context);
798 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
801 JSObjectSetPropertyAtIndex(context, arrayValue, i,
802 converter->toJSValueRef(recipient->getRecipient(i)), &referr);
805 /* previously it was DPL ConversionException converted in
806 * catch into TypeMismatch but it's more an internal error */
807 throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
815 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
816 if (NULL == arrayValue)
818 LoggerE("Could not create js array object");
819 return JSValueMakeUndefined(context);
824 LoggerE("not supported message type");
825 /* unsupported type -> type is integral message attribute
826 * so error at this place means internal api error*/
827 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
831 catch(BasePlatformException &bex) {
832 LoggerE("CC addressess getting failure: " << bex.getMessage());
833 return JSValueMakeUndefined(context);
836 LoggerE("UnknownError when getting CC addressess.");
837 return JSValueMakeUndefined(context);
841 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
843 JSStringRef propertyName,
844 JSValueRef* exception)
848 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
849 IMessagePtr msg = converter->toIMessage(object);
850 RecipientsPtr recipient = msg->getToRecipientsPtr();
851 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
852 if (NULL == arrayValue)
854 LoggerE("Could not create js array object");
855 return JSValueMakeUndefined(context);
857 LoggerE("getRecipientSize() : " << recipient->getRecipientSize());
859 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
862 JSObjectSetPropertyAtIndex(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)), &referr);
865 /* previously it was DPL ConversionException converted in
866 * catch into TypeMismatch but it's more an internal error */
867 throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
872 catch(BasePlatformException &bex) {
873 LoggerE("Destination addressess getting failure: " << bex.getMessage());
874 return JSValueMakeUndefined(context);
877 LoggerE("UnknownError when getting destination addressess.");
878 return JSValueMakeUndefined(context);
882 JSValueRef JSMessage::getIsRead(JSContextRef context,
884 JSStringRef propertyName,
885 JSValueRef* exception)
888 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
889 IMessagePtr msg = converter->toIMessage(object);
890 bool isRead = msg->isRead();
891 return converter->toJSValueRef(isRead);
893 catch(BasePlatformException &bex) {
894 /* Currently this exception will not be caught here as converter
895 * is using od-style, DPL exceptions. This catch sections
896 * is prepared for future converter refactoring */
897 LoggerE("Checking if message is read failure: " << bex.getMessage());
898 return JSValueMakeUndefined(context);
901 LoggerE("UnknownError when checking if message is read.");
902 return JSValueMakeUndefined(context);
906 JSValueRef JSMessage::getMessageId(JSContextRef context,
908 JSStringRef propertyName,
909 JSValueRef* exception)
912 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
913 IMessagePtr msg = converter->toIMessage(object);
914 const string& id = msg->getIdRef();
915 LoggerD("msgId=" << id);
916 LoggerD("msg->getMessageStatus()=" << msg->getMessageStatus());
917 if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
919 return JSValueMakeNull(context);
921 return converter->toJSValueRef(id);
923 catch(BasePlatformException &bex) {
924 /* Currently this exception will not be caught here as converter
925 * is using od-style, DPL exceptions. This catch sections
926 * is prepared for future converter refactoring */
927 LoggerE("Getting message id failure: " << bex.getMessage());
928 return JSValueMakeUndefined(context);
931 LoggerE("UnknownError when getting message id.");
932 return JSValueMakeUndefined(context);
936 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
938 JSStringRef propertyName,
939 JSValueRef* exception)
942 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
943 IMessagePtr msg = converter->toIMessage(object);
944 MessageType msgType = msg->getMessageType();
949 LoggerE("priority : false");
950 return converter->toJSValueRef(false);
953 IEmailPtr email = MessageFactory::convertToEmail(msg);
954 int tmpint = email->getPriority();
955 LoggerE("priority : " << tmpint);
956 if(tmpint == MessagePriority::HIGH)
958 return converter->toJSValueRef(true);
960 return converter->toJSValueRef(false);
963 LoggerE("unsupported message type");
964 /* unsupported type -> type is integral message attribute
965 * so error at this place means internal api error*/
966 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
970 catch(BasePlatformException &bex) {
971 LoggerE("Getting message priority failure: " << bex.getMessage());
972 return JSValueMakeUndefined(context);
975 LoggerE("UnknownError when getting message priority.");
976 return JSValueMakeUndefined(context);
980 JSValueRef JSMessage::getMessageType(JSContextRef context,
982 JSStringRef propertyName,
983 JSValueRef* exception)
986 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
987 IMessagePtr msg = converter->toIMessage(object);
988 MessageType msgType = msg->getMessageType();
990 return converter->toJSValueRef(converter->toMessageType(msgType));
992 catch(BasePlatformException &bex) {
993 /* Currently this exception will not be caught here as converter
994 * is using od-style, DPL exceptions. This catch sections
995 * is prepared for future converter refactoring */
996 LoggerE("Getting message type failure: " << bex.getMessage());
997 return JSValueMakeUndefined(context);
1000 LoggerE("UnknownError when getting message type.");
1001 return JSValueMakeUndefined(context);
1005 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
1007 JSStringRef propertyName,
1008 JSValueRef* exception)
1011 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1012 IMessagePtr msg = converter->toIMessage(object);
1013 string from = msg->getSourceAddress();
1014 LoggerD("from =" << from);
1015 if(from.size() == 0)
1017 LoggerD("JSValueMakeNull");
1018 return JSValueMakeNull(context);
1020 return converter->toJSValueRef(from);
1022 catch(BasePlatformException &bex) {
1023 /* Currently this exception will not be caught here as converter
1024 * is using od-style, DPL exceptions. This catch sections
1025 * is prepared for future converter refactoring */
1026 LoggerE("Getting message source address failure: " << bex.getMessage());
1027 return JSValueMakeUndefined(context);
1030 LoggerE("UnknownError when getting message source address.");
1031 return JSValueMakeUndefined(context);
1035 JSValueRef JSMessage::getSubject(JSContextRef context,
1037 JSStringRef propertyName,
1038 JSValueRef* exception)
1041 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1042 IMessagePtr msg = converter->toIMessage(object);
1043 MessageType msgType = msg->getMessageType();
1048 IMmsPtr mms = MessageFactory::convertToMms(msg);
1049 //JSValueMakeUndefined
1050 return converter->toJSValueRef(mms->getSubject());
1054 IEmailPtr email = MessageFactory::convertToEmail(msg);
1055 return converter->toJSValueRef(email->getSubject());
1058 return converter->toJSValueRef("");
1060 LoggerE("message not support subject");
1061 /* unsupported type -> type is integral message attribute
1062 * so error at this place means internal api error*/
1063 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1067 catch(BasePlatformException &bex) {
1068 LoggerE("Getting message subject failure: " << bex.getMessage());
1069 return JSValueMakeUndefined(context);
1072 LoggerE("UnknownError when getting message subject.");
1073 return JSValueMakeUndefined(context);
1077 JSValueRef JSMessage::getTime(JSContextRef context,
1079 JSStringRef propertyName,
1080 JSValueRef* exception)
1083 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1084 IMessagePtr msg = converter->toIMessage(object);
1085 struct tm dateTime = msg->getDateTime();
1086 const string& id = msg->getIdRef();
1087 LoggerD("msg->getMessageStatus()=" << msg->getMessageStatus());
1088 LoggerI("id.size() : " << id.size());
1089 if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
1091 LoggerI("JSValueMakeNull");
1092 return JSValueMakeNull(context);
1094 return converter->toJSValueRef(dateTime);
1096 catch(BasePlatformException &bex) {
1097 /* Currently this exception will not be caught here as converter
1098 * is using od-style, DPL exceptions. This catch sections
1099 * is prepared for future converter refactoring */
1100 LoggerE("Getting message time failure: " << bex.getMessage());
1101 return JSValueMakeUndefined(context);
1104 LoggerE("UnknownError when getting message time.");
1105 return JSValueMakeUndefined(context);
1109 JSValueRef JSMessage::getFolder(JSContextRef context,
1111 JSStringRef propertyName,
1112 JSValueRef* exception)
1115 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1116 IMessagePtr msg = converter->toIMessage(object);
1117 FolderType folder = msg->getCurrentFolder();
1119 int tmpInt = msg->getMessageStatus();
1121 LoggerE("folder : " << folder);
1122 LoggerE("msg->getMessageStatus() : " << tmpInt);
1124 if(tmpInt == MESSAGE_STATUS_CREATED)
1126 return JSValueMakeNull(context);
1129 tmpInt = (int)folder;
1130 return converter->toJSValueRef(converter->convertIntToString(tmpInt));
1132 catch(BasePlatformException &bex) {
1133 /* Currently this exception will not be caught here as converter
1134 * is using od-style, DPL exceptions. This catch sections
1135 * is prepared for future converter refactoring */
1136 LoggerE("Getting message folder failure: " << bex.getMessage());
1137 return JSValueMakeUndefined(context);
1140 LoggerE("UnknownError when getting message folder.");
1141 return JSValueMakeUndefined(context);
1145 JSValueRef JSMessage::getMessageBody(JSContextRef context,
1147 JSStringRef propertyName,
1148 JSValueRef* exception)
1150 LoggerI("getMessageBody");
1153 GlobalContextManager *gcm = GlobalContextManager::getInstance();
1155 LoggerE("Failed to get GlobalContextManager");
1156 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
1158 JSContextRef globalContext = gcm->getGlobalContext(context);
1160 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1161 IMessagePtr msg = converter->toIMessage(object); //get message point
1163 return JSMessageBody::createJS(globalContext, msg);
1165 catch(BasePlatformException &bex) {
1166 LoggerE("Getting message body failure: " << bex.getMessage());
1167 return JSValueMakeUndefined(context);
1170 LoggerE("UnknownError when getting message body.");
1171 return JSValueMakeUndefined(context);
1175 JSValueRef JSMessage::getAccountID(JSContextRef context,
1177 JSStringRef propertyName,
1178 JSValueRef* exception)
1180 LoggerI("getAccountID");
1183 GlobalContextManager *gcm = GlobalContextManager::getInstance();
1185 LoggerE("Failed to get GlobalContextManager");
1186 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
1188 JSContextRef globalContext = gcm->getGlobalContext(context);
1190 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1192 IMessagePtr msg = converter->toIMessage(object); //get message point
1194 LoggerI("create JS");
1196 if (msg->getMessageType() == EMAIL)
1198 IEmailPtr email = MessageFactory::convertToEmail(msg);
1199 if(email->getAccountID() == -1)
1201 return JSValueMakeNull(context);
1203 std::stringstream stream;
1204 stream << email->getAccountID();
1205 if (stream.fail()) {
1206 throw DeviceAPI::Common::UnknownException("Couldn't convert e-mail account id");
1209 return converter->toJSValueRef(stream.str());
1211 else if (msg->getMessageType() == SMS)
1213 std::stringstream stream;
1214 stream << SMS_ACCOUNT_ID;
1215 if (stream.fail()) {
1216 throw DeviceAPI::Common::UnknownException("Couldn't convert sms account id");
1219 return converter->toJSValueRef(stream.str());
1221 else if (msg->getMessageType() == MMS)
1223 std::stringstream stream;
1224 stream << MMS_ACCOUNT_ID;
1225 if (stream.fail()) {
1226 throw DeviceAPI::Common::UnknownException("Couldn't convert mms account id");
1229 return converter->toJSValueRef(stream.str());
1233 return JSValueMakeUndefined(context);
1236 catch(BasePlatformException &bex) {
1237 LoggerE("Getting account id failure: " << bex.getMessage());
1238 return JSValueMakeUndefined(context);
1241 LoggerE("UnknownError when getting account id.");
1242 return JSValueMakeUndefined(context);
1246 JSValueRef JSMessage::getUID(JSContextRef context,
1248 JSStringRef propertyName,
1249 JSValueRef* exception)
1254 GlobalContextManager *gcm = GlobalContextManager::getInstance();
1256 LoggerE("Failed to get GlobalContextManager");
1257 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
1259 JSContextRef globalContext = gcm->getGlobalContext(context);
1261 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1263 IMessagePtr msg = converter->toIMessage(object); //get message point
1265 LoggerI("create JS");
1267 if (msg->getMessageType() == EMAIL)
1269 IEmailPtr email = MessageFactory::convertToEmail(msg);
1270 return converter->toJSValueRef(email->getUID());
1274 return JSValueMakeUndefined(context);
1277 catch(BasePlatformException &bex) {
1278 LoggerE("Getting account id failure: " << bex.getMessage());
1279 return JSValueMakeUndefined(context);
1282 LoggerE("UnknownError when getting account id.");
1283 return JSValueMakeUndefined(context);
1287 bool JSMessage::setAttachments(JSContextRef context,
1289 JSStringRef propertyName,
1291 JSValueRef* exception)
1296 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1298 vector<IAttachmentPtr> attachments;
1299 if (JSIsArrayValue(context, value)) {
1300 JSObjectRef valueObj = converter->toJSObjectRef(value);
1301 unsigned int len = JSGetArrayLength(context, valueObj);
1302 LoggerD("Array Length = " << len);
1303 for (unsigned int i = 0; i < len; ++i)
1305 JSValueRef att = JSObjectGetPropertyAtIndex(context, valueObj, i, NULL);
1306 if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
1307 LoggerW("Invalid array element. Skipping.");
1310 IAttachmentPtr attachment = converter->toIAttachment(att);
1312 if(attachment->getIsValidAttachment() == false)
1314 LoggerD("invalid attachment : " << i);
1315 throw DeviceAPI::Common::InvalidValuesException("Invalid attachment in array");
1318 LoggerD("Adding attachment , shotname: " << attachment->getShortName());
1319 attachments.push_back(attachment);
1324 IAttachmentPtr attachment = converter->toIAttachment(value);
1325 LoggerD("Adding attachment , shotname: " << attachment->getShortName());
1326 if(attachment->getIsValidAttachment() == false)
1328 LoggerD("invalid attachment");
1329 throw DeviceAPI::Common::InvalidValuesException("Invalid attachments array");
1331 attachments.push_back(attachment);
1334 LoggerD("Attachment Size =" << attachments.size());
1335 if ( attachments.size() > 0)
1337 IMessagePtr msg = converter->toIMessage(object);
1340 MessageType msgType = msg->getMessageType();
1344 IMmsPtr mms = MessageFactory::convertToMms(msg);
1345 mms->setAttachments(attachments);
1350 IEmailPtr email = MessageFactory::convertToEmail(msg);
1351 email->setAttachments(attachments);
1355 LoggerE("not supported message type");
1356 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1363 LoggerE("Message converter failed...");
1364 throw DeviceAPI::Common::UnknownException("Message conversion failure");
1368 catch(BasePlatformException &bex) {
1369 LoggerE("Setting attachments failed: " << bex.getMessage());
1373 LoggerE("UnknownError when setting attachments.");
1380 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
1381 bool JSMessage::setAttachments(JSContextRef context,
1383 JSStringRef propertyName,
1385 JSValueRef* exception)
1391 JSMessagePrivateObject* priv =
1392 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1395 return JSTizenExceptionFactory::postException(context, exception,
1396 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1399 Catch(WrtDeviceApis::Commons::NullPointerException) {
1400 LoggerE("Error on pointer, null value");
1401 return JSTizenExceptionFactory::postException(context, exception,
1402 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1405 vector<string> attachments;
1408 ConverterMessageFactory::ConverterType converter =
1409 ConverterMessageFactory::getConverter(context);
1410 if (JSIsArrayValue(context, value)) {
1411 JSObjectRef valueObj = converter->toJSObjectRef(value);
1413 // extract path from each JSFile object
1414 unsigned int len = JSGetArrayLength(context, valueObj);
1415 for (unsigned int i = 0; i < len; ++i) {
1416 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1417 if (JSValueIsUndefined(context,
1418 att) || JSValueIsNull(context, att)) {
1419 LoggerW("Invalid array element. Skipping.");
1422 DeviceAPI::Filesystem::INodePtr node = converter->toFilesystemNode(
1425 LoggerD("Adding attachment: " << node->getPath()->getFullPath());
1426 attachments.push_back(node->getPath()->getFullPath());
1429 LoggerW("Invalid or null element passed as attachment array." <<
1430 "Setting empty vector.");
1433 // set up new attachments list
1434 IMessagePtr msg = converter->toIMessage(object);
1435 MessageType msgType = msg->getMessageType();
1439 IMmsPtr mms = MessageFactory::convertToMms(msg);
1440 mms->setAttachments(attachments, true);
1445 IEmailPtr email = MessageFactory::convertToEmail(msg);
1446 email->setAttachments(attachments, true);
1451 return false; // ignore
1454 LoggerE("not supported message type");
1455 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1459 Catch(WrtDeviceApis::Commons::ConversionException) {
1460 LoggerE("Error on conversion");
1461 return JSTizenExceptionFactory::postException(context, exception,
1462 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1464 Catch(WrtDeviceApis::Commons::NullPointerException) {
1465 LoggerE("Error on pointer, null value");
1466 return JSTizenExceptionFactory::postException(context, exception,
1467 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1469 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1470 LoggerE("Invalid argument");
1471 return JSTizenExceptionFactory::postException(context, exception,
1472 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1478 bool JSMessage::setBccAddress(JSContextRef context,
1480 JSStringRef propertyName,
1482 JSValueRef* exception)
1485 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1486 IMessagePtr msg = converter->toIMessage(object);
1487 Recipients bcc = converter->toRecipients(value);
1488 LoggerD("setting bcc field, size=" << bcc.getRecipientSize());
1490 MessageType msgType = msg->getMessageType();
1494 return false; // ignore
1498 IEmailPtr email = MessageFactory::convertToEmail(msg);
1499 email->setBccRecipients(bcc);
1503 LoggerE("not supported message type");
1504 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1509 catch(BasePlatformException &bex) {
1510 LoggerE("Setting BCC addresses failed: " << bex.getMessage());
1514 LoggerE("UnknownError when setting BCC addresses.");
1520 bool JSMessage::setBody(JSContextRef context,
1522 JSStringRef propertyName,
1524 JSValueRef* exception)
1527 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1528 IMessagePtr msg = converter->toIMessage(object);
1529 string body = converter->toString(value);
1533 catch(BasePlatformException &bex) {
1534 /* Currently this exception will not be caught here as converter
1535 * is using od-style, DPL exceptions. This catch sections
1536 * is prepared for future converter refactoring */
1537 LoggerE("Setting BCC addresses failed: " << bex.getMessage());
1541 LoggerE("UnknownError when setting BCC addresses.");
1547 bool JSMessage::setCcAddress(JSContextRef context,
1549 JSStringRef propertyName,
1551 JSValueRef* exception)
1554 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1555 IMessagePtr msg = converter->toIMessage(object);
1556 Recipients cc = converter->toRecipients(value);
1557 LoggerD("setting cc field, size=" << cc.getRecipientSize());
1559 MessageType msgType = msg->getMessageType();
1563 return true; // ignore
1566 IEmailPtr email = MessageFactory::convertToEmail(msg);
1567 email->setCcRecipients(cc);
1571 LoggerE("unsuported message type");
1572 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1577 catch(BasePlatformException &bex) {
1578 LoggerE("Setting CC addresses failed: " << bex.getMessage());
1582 LoggerE("UnknownError when setting CC addresses.");
1588 bool JSMessage::setDestinationAddress(JSContextRef context,
1590 JSStringRef propertyName,
1592 JSValueRef * exception)
1597 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1598 IMessagePtr msg = converter->toIMessage(object);
1599 Recipients to = converter->toRecipients(value);
1600 LoggerD("setting to field, size=" << to.getRecipientSize());
1601 msg->setToRecipients(to);
1604 catch(BasePlatformException &bex) {
1605 /* Currently this exception will not be caught here as converter
1606 * is using od-style, DPL exceptions. This catch sections
1607 * is prepared for future converter refactoring */
1608 LoggerE("Setting destination addresses failed: " << bex.getMessage());
1612 LoggerE("UnknownError when setting destination addresses.");
1618 bool JSMessage::setIsRead(JSContextRef context,
1620 JSStringRef propertyName,
1622 JSValueRef * exception)
1625 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1626 IMessagePtr msg = converter->toIMessage(object);
1627 msg->setReadStatus(converter->toBool(value));
1628 msg->setisReadChangeStatus(converter->toBool(value));
1631 catch(BasePlatformException &bex) {
1632 /* Currently this exception will not be caught here as converter
1633 * is using od-style, DPL exceptions. This catch sections
1634 * is prepared for future converter refactoring */
1635 LoggerE("Setting destination addresses failed: " << bex.getMessage());
1639 LoggerE("UnknownError when setting destination addresses.");
1645 bool JSMessage::setMessagePriority(JSContextRef context,
1647 JSStringRef propertyName,
1649 JSValueRef * exception)
1653 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1654 IMessagePtr msg = converter->toIMessage(object);
1655 MessageType msgType = msg->getMessageType();
1659 // do not set value but show that this attribute is supported in object
1662 msg->setPriority(converter->toMessagePriority(value));
1666 LoggerE("unsuported message type");
1667 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1672 catch(BasePlatformException &bex) {
1673 LoggerE("Setting message priority failed: " << bex.getMessage());
1677 LoggerE("UnknownError when setting message priority.");
1683 bool JSMessage::setSubject(JSContextRef context,
1685 JSStringRef propertyName,
1687 JSValueRef * exception)
1690 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1691 IMessagePtr msg = converter->toIMessage(object);
1692 MessageType msgType = msg->getMessageType();
1693 string subject = converter->toString(value);
1697 IMmsPtr mms = MessageFactory::convertToMms(msg);
1698 mms->setSubject(subject);
1703 IEmailPtr email = MessageFactory::convertToEmail(msg);
1704 email->setSubject(subject);
1708 return true; // ignore
1711 LoggerE("message not supported");
1712 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1717 catch(BasePlatformException &bex) {
1718 LoggerE("Setting message priority failed: " << bex.getMessage());
1722 LoggerE("UnknownError when setting message priority.");
1728 bool JSMessage::setMessageBody(JSContextRef context,
1730 JSStringRef propertyName,
1732 JSValueRef* exception)
1737 JSValueRef JSMessage::getConversationId(JSContextRef context,
1739 JSStringRef propertyName,
1740 JSValueRef* exception)
1742 LoggerD("getConversationId");
1745 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1747 IMessagePtr msg = converter->toIMessage(object);
1749 LoggerD("msg->getMessageStatus()=" << msg->getMessageStatus());
1750 LoggerD("msg.getConvId()=" << msg->getConvId());
1751 convId = msg->getConvId();
1752 if((msg->getConvId() == -1) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
1754 return JSValueMakeNull(context);
1756 return converter->toJSValueRef(converter->convertIntToString(convId));
1758 catch(BasePlatformException &bex) {
1759 /* Currently this exception will not be caught here as converter
1760 * is using od-style, DPL exceptions. This catch sections
1761 * is prepared for future converter refactoring */
1762 LoggerE("Getting conversation id failure: " << bex.getMessage());
1763 return JSValueMakeUndefined(context);
1766 LoggerE("UnknownError when getting conversation id.");
1767 return JSValueMakeUndefined(context);
1771 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
1773 JSStringRef propertyName,
1774 JSValueRef* exception)
1776 LoggerD("getInResponseTo");
1779 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1782 IMessagePtr msg = converter->toIMessage(object);
1784 if (msg->getMessageType() != EMAIL)
1786 LoggerD("not EMAIL type return empty string");
1787 return JSValueMakeNull(context);
1790 IEmailPtr email = MessageFactory::convertToEmail(msg);
1791 msgId = email->getUID();
1793 LoggerD("msg.getConvId()=" << msg->getConvId());
1794 convId = msg->getConvId();
1796 if (convId == msgId)
1798 LoggerD("Not forwared and replied, return empty string");
1799 return JSValueMakeNull(context);
1802 return converter->toJSValueRef(converter->convertIntToString(convId));
1804 catch(BasePlatformException &bex) {
1805 /* Currently this exception will not be caught here as converter
1806 * is using od-style, DPL exceptions. This catch sections
1807 * is prepared for future converter refactoring */
1808 LoggerE("Getting in response to failure: " << bex.getMessage());
1809 return JSValueMakeUndefined(context);
1812 LoggerE("UnknownError when getting in response to.");
1813 return JSValueMakeUndefined(context);
1817 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
1819 JSStringRef propertyName,
1820 JSValueRef* exception)
1822 LoggerI("getMessageStatus");
1826 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1828 IMessagePtr msg = converter->toIMessage(object); //get message point
1830 LoggerI("create JS");
1831 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1833 catch(BasePlatformException &bex) {
1834 /* Currently this exception will not be caught here as converter
1835 * is using od-style, DPL exceptions. This catch sections
1836 * is prepared for future converter refactoring */
1837 LoggerE("Getting message status failure: " << bex.getMessage());
1838 return JSValueMakeUndefined(context);
1841 LoggerE("UnknownError when getting message status.");
1842 return JSValueMakeUndefined(context);
1847 JSValueRef JSMessage::hasAttachment(JSContextRef context,
1849 JSStringRef propertyName,
1850 JSValueRef* exception)
1852 LoggerI("hasAttachment");
1855 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1857 IMessagePtr msg = converter->toIMessage(object); //get message point
1859 bool hasAttachmentFlag = false;
1861 if ( msg->getMessageType() == EMAIL)
1863 IEmailPtr email = MessageFactory::convertToEmail(msg);
1865 if (email->hasAttachment())
1866 hasAttachmentFlag = true;
1868 else if ( msg->getMessageType() == MMS)
1870 IMmsPtr mms = MessageFactory::convertToMms(msg);
1872 if (mms->hasAttachment())
1873 hasAttachmentFlag = true;
1877 hasAttachmentFlag = false;
1879 return converter->toJSValueRef(hasAttachmentFlag);
1881 catch(BasePlatformException &bex) {
1882 /* Currently this exception will not be caught here as converter
1883 * is using od-style, DPL exceptions. This catch sections
1884 * is prepared for future converter refactoring */
1885 LoggerE("Getting hasAttachment flag failure: " << bex.getMessage());
1886 return JSValueMakeUndefined(context);
1889 LoggerE("UnknownError when getting hasAttachment flag.");
1890 return JSValueMakeUndefined(context);
1894 // Utility functions.
1895 MessageType JSMessage::stringToMessageType(std::string type)
1897 MessageType retval = UNKNOWN;
1898 if (type.compare("messaging.sms") == 0) {
1901 else if (type.compare("messaging.mms") == 0) {
1904 else if (type.compare("messaging.email") == 0) {
1908 throw DeviceAPI::Common::TypeMismatchException("Invalid MessageServiceTag");