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>
41 #include <ArgumentValidator.h>
44 #include "MessagingErrorMsg.h"
45 #include "JSMessageAttachment.h"
46 #include "plugin_config.h"
51 using namespace DeviceAPI::Common;
52 using namespace WrtDeviceApis::Commons;
53 using namespace WrtDeviceApis::CommonsJavaScript;
57 JSClassRef JSMessage::m_jsClassRef = NULL;
59 #define MESSAGE_ATTRIBUTE_ID "id"
60 #define MESSAGE_ATTRIBUTE_SERVICE_ID "serviceId"
61 #define MESSAGE_ATTRIBUTE_CONVERSATION_ID "conversationId"
62 #define MESSAGE_ATTRIBUTE_FOLDER_ID "folderId"
63 #define MESSAGE_ATTRIBUTE_TYPE "type"
64 #define MESSAGE_ATTRIBUTE_TIMESTAMP "timestamp"
65 #define MESSAGE_ATTRIBUTE_FROM "from"
66 #define MESSAGE_ATTRIBUTE_TO "to" // used also in dictionary
67 #define MESSAGE_ATTRIBUTE_CC "cc" // used also in dictionary
68 #define MESSAGE_ATTRIBUTE_BCC "bcc" // used also in dictionary
69 #define MESSAGE_ATTRIBUTE_BODY "body"
70 #define MESSAGE_ATTRIBUTE_IS_READ "isRead"
71 #define MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY "isHighPriority" // used also in dictionary
72 #define MESSAGE_ATTRIBUTE_SUBJECT "subject" // used also in dictionary
73 #define MESSAGE_ATTRIBUTE_IN_RESPONSE_TO "inResponseTo"
74 #define MESSAGE_ATTRIBUTE_MESSAGE_STATUS "messageStatus"
75 #define MESSAGE_ATTRIBUTE_ATTACHMENTS "attachments"
76 #define MESSAGE_ATTRIBUTE_HAS_ATTACHMENT "hasAttachment"
78 #define MESSAGE_DICTIONARY_ATTRIBUTE_PLAIN_BODY "plainBody"
79 #define MESSAGE_DICTIONARY_ATTRIBUTE_HTML_BODY "htmlBody"
81 JSClassDefinition JSMessage::m_classInfo = {
83 kJSClassAttributeNone,
86 NULL, // m_property not used here - access properties by setProperty()/getProperty()
91 JSMessage::getProperty, //getProperty,
92 JSMessage::setProperty, //setProperty,
93 NULL, //deleteProperty,
94 JSMessage::getPropertyNames, //getPropertyNames,
95 NULL, //callAsFunction,
96 NULL, //callAsConstructor,
98 NULL, //convertToType,
101 // JSMessage properties - used in: getProperty(), setProperty(), getPropertyNames()
102 JSStaticValue JSMessage::m_property[] = {
103 { MESSAGE_ATTRIBUTE_ID, getMessageId, NULL, kJSPropertyAttributeReadOnly },
104 { MESSAGE_ATTRIBUTE_SERVICE_ID, getAccountID, NULL, kJSPropertyAttributeReadOnly},
105 { MESSAGE_ATTRIBUTE_CONVERSATION_ID, getConversationId, NULL, kJSPropertyAttributeReadOnly },
106 { MESSAGE_ATTRIBUTE_FOLDER_ID, getFolder, NULL, kJSPropertyAttributeReadOnly },
107 { MESSAGE_ATTRIBUTE_TYPE, getMessageType, NULL, kJSPropertyAttributeReadOnly },
108 { MESSAGE_ATTRIBUTE_TIMESTAMP, getTime, NULL, kJSPropertyAttributeReadOnly },
109 { MESSAGE_ATTRIBUTE_FROM, getSourceAddress, NULL, kJSPropertyAttributeReadOnly },
110 { MESSAGE_ATTRIBUTE_TO, getDestinationAddress, setDestinationAddress, kJSPropertyAttributeNone },
111 { MESSAGE_ATTRIBUTE_CC, getCcAddress, setCcAddress, kJSPropertyAttributeNone },
112 { MESSAGE_ATTRIBUTE_BCC, getBccAddress, setBccAddress, kJSPropertyAttributeNone },
113 { MESSAGE_ATTRIBUTE_BODY, getMessageBody, setMessageBody, kJSPropertyAttributeNone },
114 { MESSAGE_ATTRIBUTE_IS_READ, getIsRead, setIsRead, kJSPropertyAttributeNone },
115 { MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY, getMessagePriority, setMessagePriority, kJSPropertyAttributeNone },
116 { MESSAGE_ATTRIBUTE_SUBJECT, getSubject, setSubject, kJSPropertyAttributeNone },
117 { MESSAGE_ATTRIBUTE_IN_RESPONSE_TO, getInResponseTo, NULL, kJSPropertyAttributeNone },
118 { MESSAGE_ATTRIBUTE_MESSAGE_STATUS, getMessageStatus, NULL, kJSPropertyAttributeReadOnly},
119 { MESSAGE_ATTRIBUTE_ATTACHMENTS, getAttachments, setAttachments, kJSPropertyAttributeNone },
120 { MESSAGE_ATTRIBUTE_HAS_ATTACHMENT, hasAttachment, NULL, kJSPropertyAttributeReadOnly},
125 JSValueRef JSMessage::createJSObject(JSContextRef context,
126 EmailAccountInfo& account,
128 const std::string& msgId)
131 LoggerD("createJSObject with account ");
135 if (msgType == EMAIL)
137 LoggerD("Account Address:" << &account);
138 LoggerD("Account Data ,ID" << account.getId() << "name:" << account.getName() << " Account:" << account.getAddress());
140 msg = MessageFactory::createMessage(msgType, account, msgId);
142 return JSValueMakeUndefined(context);
146 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
149 Catch(WrtDeviceApis::Commons::UnknownException) {
150 LoggerE("wrong message type, object not created");
151 return JSValueMakeUndefined(context);
154 return createJSObject(context, msg);
157 JSValueRef JSMessage::createJSObject(JSContextRef context,
158 EventUpdateMessageAnswerReceiver* listener,
165 // create message depending on type
166 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
168 msg = MessageFactory::createMessage(msgType, msgId);
170 return JSValueMakeUndefined(context);
174 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
177 Catch(WrtDeviceApis::Commons::UnknownException) {
178 LoggerE("wrong message type, object not created");
179 return JSValueMakeUndefined(context);
181 return createJSObject(context, msg, listener);
184 JSValueRef JSMessage::createJSObject(JSContextRef context,
185 const IMessagePtr& msg,
186 EventUpdateMessageAnswerReceiver* listener)
188 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
189 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
190 priv->setUpdateMsgReceiver(listener);
191 JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
192 JSClassRelease(jsClassRef);
193 if (NULL == jsValueRef) {
194 LoggerE("object creation error");
195 return JSValueMakeUndefined(context);
200 JSValueRef JSMessage::createJSObject(JSContextRef context,
201 const IMessagePtr& msg)
203 LoggerD("createJSObject");
204 JSClassRef jsClassRef = JSClassCreate(getClassInfo());
205 LoggerD("jsClassRef success");
206 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
207 LoggerD("priv success");
209 JSObjectRef jsValueRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
210 LoggerD("JSObjectMake success");
211 JSClassRelease(jsClassRef);
212 if (NULL == jsValueRef) {
213 LoggerE("object creation error");
214 return JSValueMakeUndefined(context);
219 JSValueRef JSMessage::createJSObject(JSContextRef context,
226 // create message depending on type
227 if (msgType == SMS || msgType == MMS || msgType == EMAIL)
229 msg = MessageFactory::createMessage(msgType, msgId);
233 Throw(WrtDeviceApis::Commons::UnknownException); // unsupported type
236 Catch(WrtDeviceApis::Commons::UnknownException) {
237 LoggerE("wrong message type, object not created");
238 return JSValueMakeUndefined(context);
240 return createJSObject(context, msg, NULL);
243 JSValueRef JSMessage::createDummyMessageJSObject(JSContextRef context,
247 if (msgType == EMAIL )
249 msg = MessageFactory::createEmailMessage();
253 LoggerE("message type is invalid");
254 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
256 return createJSObject(context, msg);
259 void JSMessage::initialize(JSContextRef context,
264 if (!JSObjectGetPrivate(object))
266 IMessagePtr msg(new Sms());
267 JSMessagePrivateObject *priv = new JSMessagePrivateObject(context, msg);
268 if (!JSObjectSetPrivate(object, priv))
270 LoggerI("set Private Failed...");
276 void JSMessage::finalize(JSObjectRef object)
278 JSMessagePrivateObject* priv = static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
280 LoggerD("deleting private object");
282 JSObjectSetPrivate(object, NULL);
286 bool JSMessage::hasProperty(JSContextRef context,
288 JSStringRef propertyName)
293 JSValueRef JSMessage::getProperty(JSContextRef context,
295 JSStringRef propertyName,
296 JSValueRef* exception)
298 LoggerI("Main getProperty()");
300 // for non-NULL property names
301 while(m_property[index].name != NULL) {
302 // if property name matches
303 if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
304 if(m_property[index].getProperty != NULL) {
305 // if getProperty() function exists - call it
306 return m_property[index].getProperty(context, object, propertyName, exception);
308 //otherwise return undefined
309 return JSValueMakeUndefined(context);
317 bool JSMessage::setProperty(JSContextRef context,
319 JSStringRef propertyName,
321 JSValueRef* exception)
323 LoggerI("Main setProperty()");
325 // for non-NULL property names
326 while(m_property[index].name != NULL) {
327 // if property name matches
328 if(JSStringIsEqualToUTF8CString(propertyName,m_property[index].name)) {
329 if(m_property[index].setProperty != NULL) {
330 // if setProperty() function exists - call it
331 return m_property[index].setProperty(context, object, propertyName, value, exception);
333 // otherwise return true (lack of function - readonly attribute)
342 bool JSMessage::deleteProperty(JSContextRef context,
344 JSStringRef propertyName,
345 JSValueRef* exception)
351 void JSMessage::getPropertyNames(JSContextRef context,
353 JSPropertyNameAccumulatorRef propertyNames)
357 JSStringRef propertyName = NULL;
359 // repeat for each declared property - until null on property name
360 while(m_property[index].name != NULL) {
361 LoggerD("Property: " << m_property[index].name);
362 propertyName = JSStringCreateWithUTF8CString(m_property[index].name);
363 JSPropertyNameAccumulatorAddName(propertyNames, propertyName);
364 JSStringRelease(propertyName);
369 JSValueRef JSMessage::callAsFunction(JSContextRef context,
371 JSObjectRef thisObject,
372 size_t argumentCount,
373 const JSValueRef arguments[],
374 JSValueRef* exception)
377 return JSValueMakeUndefined(context);
380 bool JSMessage::hasInstance(JSContextRef context,
381 JSObjectRef constructor,
382 JSValueRef possibleInstance,
383 JSValueRef* exception)
389 JSObjectRef JSMessage::constructor(JSContextRef context,
390 JSObjectRef constructor,
391 size_t argumentCount,
392 const JSValueRef arguments[],
393 JSValueRef* exception)
398 ArgumentValidator validator(context, argumentCount, arguments);
399 std::string msgTypeString = validator.toString(0);
400 MessageType msgType = stringToMessageType(msgTypeString);
401 JSObjectRef dictionary = validator.toObject(1, true);
402 // converter is still used for some parameter
403 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
406 if ( msgType == EMAIL )
408 msg = MessageFactory::createEmailMessage();
410 else if (msgType == MMS || msgType == SMS)
412 msg = MessageFactory::createMessage(msgType); //create message
416 // this should never happen - message type checking done in stringToMessageType()
417 LoggerE("message type is invalid");
418 throw TypeMismatchException("Invalid message type");
422 LoggerD("Message Creation failed");
423 throw DeviceAPI::Common::UnknownException("Message has been not created");
426 if (dictionary != NULL)
428 LoggerD ("##### msg type is " << msgType);
430 JSValueRef subjectData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_SUBJECT);
431 JSValueRef toData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_TO);
432 JSValueRef ccData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_CC);
433 JSValueRef bccData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_BCC);
434 JSValueRef plainBodyData = JSUtil::getProperty(context, dictionary, MESSAGE_DICTIONARY_ATTRIBUTE_PLAIN_BODY);
435 JSValueRef htmlBodyData = JSUtil::getProperty(context, dictionary, MESSAGE_DICTIONARY_ATTRIBUTE_HTML_BODY);
436 JSValueRef priorityData = JSUtil::getProperty(context, dictionary, MESSAGE_ATTRIBUTE_IS_HIGH_PRIORITY);
439 if (!JSValueIsUndefined(context, subjectData) )
441 std::string subject = JSUtil::JSValueToString(context, subjectData);
442 LoggerD (" Subject : " << subject);
447 IMmsPtr mms = MessageFactory::convertToMms(msg);
448 mms->setSubject(subject);
453 IEmailPtr email = MessageFactory::convertToEmail(msg);
454 email->setSubject(subject);
459 LoggerE("message not supported");
460 //Throw(WrtDeviceApis::Commons::UnsupportedException);
466 if (!JSValueIsUndefined(context, toData) )
468 Recipients to = converter->toRecipients(toData);
469 LoggerD("setting to field, size=" << to.getRecipientSize());
470 msg->setToRecipients(to);
473 if (msgType == EMAIL )
475 IEmailPtr email = MessageFactory::convertToEmail(msg);
476 if (!JSValueIsUndefined(context, ccData))
478 Recipients cc = converter->toRecipients(ccData);
479 email->setCcRecipients(cc);
482 if (!JSValueIsUndefined(context, bccData))
484 Recipients bcc = converter->toRecipients(bccData);
485 email->setBccRecipients(bcc);
488 if (!JSValueIsUndefined(context, htmlBodyData))
490 std::string body = JSUtil::JSValueToString(context, htmlBodyData);
491 LoggerD("html body : " << body);
492 email->setHtmlBody(body);
495 if (!JSValueIsUndefined(context, priorityData))
497 email->setPriority(converter->toMessagePriority(priorityData));
500 if (!JSValueIsUndefined(context, plainBodyData) )
502 std::string body = JSUtil::JSValueToString(context, plainBodyData);
503 LoggerD("plain body : " << body);
509 JSClassRef jsClassRef = JSClassCreate(JSMessage::getClassInfo());
510 LoggerD("jsClassRef success");
511 JSMessagePrivateObject* priv = new JSMessagePrivateObject(context, msg);
512 LoggerD("priv success");
514 JSObjectRef jsObjRef = JSObjectMake(context, jsClassRef, static_cast<void*>(priv));
515 LoggerD("JSObjectMake success");
516 JSClassRelease(jsClassRef);
517 if (NULL == jsObjRef) {
518 LoggerE("JSObject creation error");
519 throw DeviceAPI::Common::UnknownException("JSObject make error");
523 catch(BasePlatformException &bex) {
524 LoggerE("Message creation failed: " << bex.getMessage());
525 JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, bex);
530 DeviceAPI::Common::UnknownException err("UnknownError in Message constructor.");
531 JSObjectRef error = JSWebAPIError::makeJSWebAPIError(context, err);
538 JSValueRef JSMessage::convertToType(JSContextRef context,
541 JSValueRef* exception)
544 return JSValueMakeUndefined(context);
547 JSValueRef JSMessage::getAttachments(JSContextRef context,
549 JSStringRef propertyName,
550 JSValueRef* exception)
554 GlobalContextManager *gcm = GlobalContextManager::getInstance();
556 LoggerE("Failed to get GlobalContextManager");
557 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
559 JSContextRef globalContext = gcm->getGlobalContext(context);
561 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
562 IMessagePtr msg = converter->toIMessage(object);
563 MessageType msgType = msg->getMessageType();
564 LoggerI("msgType=" << msgType);
565 // prepare common values
566 JSCallbackManagerPtr emptyCallbackMgr = JSCallbackManager::createObject(globalContext, NULL, NULL);
573 std::vector<IAttachmentPtr> attachments;
574 std::vector<IAttachmentPtr>::iterator it;
576 if ( msgType == MMS )
578 AttachmentsPtr mmsAttachments =
579 DPL::StaticPointerCast<Attachments>(MessageFactory::convertToMms(msg));
580 attachments = mmsAttachments->getAttachments();
584 AttachmentsPtr emailAttachments =
585 DPL::StaticPointerCast<Attachments>(MessageFactory::convertToEmail(msg));
586 attachments = emailAttachments->getAttachments();
589 int count = attachments.size();
590 LoggerD( "count : " << count);
592 JSObjectRef jsMessageAttachmentObject[count]; //make
594 for (unsigned int index = 0 ; index < attachments.size(); index++ )
596 LoggerD( "Attachment ID : " << attachments[index]->getAttachmentID());
597 jsMessageAttachmentObject[index] = JSMessageAttachment::createJS(globalContext, attachments[index] );
599 JSObjectRef result = JSObjectMakeArray(globalContext, count, jsMessageAttachmentObject, NULL);
604 JSObjectRef arrayValue = JSObjectMakeArray(globalContext, 0, NULL, NULL);
605 if (NULL == arrayValue)
607 LoggerE("Could not create js array object");
608 return JSValueMakeUndefined(context);
613 LoggerE("Not supported message type");
614 /* unsupported type -> type is integral message attribute
615 * so error at this place means internal api error*/
616 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
620 catch(BasePlatformException &bex) {
621 LoggerE("Attachments getting failure: " << bex.getMessage());
622 return JSValueMakeUndefined(context);
625 LoggerE("UnknownError when getting attachments.");
626 return JSValueMakeUndefined(context);
631 JSValueRef JSMessage::getBccAddress(JSContextRef context,
633 JSStringRef propertyName,
634 JSValueRef* exception)
638 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
639 IMessagePtr msg = converter->toIMessage(object);
640 MessageType msgType = msg->getMessageType();
646 IEmailPtr email = MessageFactory::convertToEmail(msg);
647 RecipientsPtr recipient = email->getBccRecipientsPtr();
648 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
649 if (NULL == arrayValue)
651 LoggerE("Could not create js array object");
652 return JSValueMakeUndefined(context);
655 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
658 JSObjectSetPropertyAtIndex(context, arrayValue, i,
659 converter->toJSValueRef(recipient->getRecipient(i)), &referr);
662 /* previously it was DPL ConversionException converted in
663 * catch into TypeMismatch but it's more an internal error */
664 throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
672 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
673 if (NULL == arrayValue)
675 LoggerE("Could not create js array object");
676 return JSValueMakeUndefined(context);
681 LoggerE("not supported message type");
682 /* unsupported type -> type is integral message attribute
683 * so error at this place means internal api error*/
684 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
688 catch(BasePlatformException &bex) {
689 LoggerE("BCC addressess getting failure: " << bex.getMessage());
690 return JSValueMakeUndefined(context);
693 LoggerE("UnknownError when getting BCC addressess.");
694 return JSValueMakeUndefined(context);
698 JSValueRef JSMessage::getBody(JSContextRef context,
700 JSStringRef propertyName,
701 JSValueRef* exception)
704 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
705 IMessagePtr msg = converter->toIMessage(object);
706 string body = msg->getBody();
707 return converter->toJSValueRef(body);
709 catch(BasePlatformException &bex) {
710 /* Currently this exception will not be caught here as converter
711 * is using od-style, DPL exceptions. This catch sections
712 * is prepared for future converter refactoring */
713 LoggerE("Message body getting failure: " << bex.getMessage());
714 return JSValueMakeUndefined(context);
717 LoggerE("UnknownError when getting Message body.");
718 return JSValueMakeUndefined(context);;
722 JSValueRef JSMessage::getCcAddress(JSContextRef context,
724 JSStringRef propertyName,
725 JSValueRef* exception)
729 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
730 IMessagePtr msg = converter->toIMessage(object);
731 MessageType msgType = msg->getMessageType();
737 IEmailPtr email = MessageFactory::convertToEmail(msg);
738 RecipientsPtr recipient = email->getCcRecipientsPtr();
739 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
740 if (NULL == arrayValue)
742 LoggerE("Could not create js array object");
743 return JSValueMakeUndefined(context);
746 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
749 JSObjectSetPropertyAtIndex(context, arrayValue, i,
750 converter->toJSValueRef(recipient->getRecipient(i)), &referr);
753 /* previously it was DPL ConversionException converted in
754 * catch into TypeMismatch but it's more an internal error */
755 throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
763 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
764 if (NULL == arrayValue)
766 LoggerE("Could not create js array object");
767 return JSValueMakeUndefined(context);
772 LoggerE("not supported message type");
773 /* unsupported type -> type is integral message attribute
774 * so error at this place means internal api error*/
775 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
779 catch(BasePlatformException &bex) {
780 LoggerE("CC addressess getting failure: " << bex.getMessage());
781 return JSValueMakeUndefined(context);
784 LoggerE("UnknownError when getting CC addressess.");
785 return JSValueMakeUndefined(context);
789 JSValueRef JSMessage::getDestinationAddress(JSContextRef context,
791 JSStringRef propertyName,
792 JSValueRef* exception)
796 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
797 IMessagePtr msg = converter->toIMessage(object);
798 RecipientsPtr recipient = msg->getToRecipientsPtr();
799 JSObjectRef arrayValue = JSObjectMakeArray(context, 0, NULL, NULL);
800 if (NULL == arrayValue)
802 LoggerE("Could not create js array object");
803 return JSValueMakeUndefined(context);
805 LoggerE("getRecipientSize() : " << recipient->getRecipientSize());
807 for(size_t i = 0; i < recipient->getRecipientSize(); i++)
810 JSObjectSetPropertyAtIndex(context, arrayValue, i, converter->toJSValueRef(recipient->getRecipient(i)), &referr);
813 /* previously it was DPL ConversionException converted in
814 * catch into TypeMismatch but it's more an internal error */
815 throw DeviceAPI::Common::UnknownException("Could not insert value into js array");
820 catch(BasePlatformException &bex) {
821 LoggerE("Destination addressess getting failure: " << bex.getMessage());
822 return JSValueMakeUndefined(context);
825 LoggerE("UnknownError when getting destination addressess.");
826 return JSValueMakeUndefined(context);
830 JSValueRef JSMessage::getIsRead(JSContextRef context,
832 JSStringRef propertyName,
833 JSValueRef* exception)
836 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
837 IMessagePtr msg = converter->toIMessage(object);
838 bool isRead = msg->isRead();
839 return converter->toJSValueRef(isRead);
841 catch(BasePlatformException &bex) {
842 /* Currently this exception will not be caught here as converter
843 * is using od-style, DPL exceptions. This catch sections
844 * is prepared for future converter refactoring */
845 LoggerE("Checking if message is read failure: " << bex.getMessage());
846 return JSValueMakeUndefined(context);
849 LoggerE("UnknownError when checking if message is read.");
850 return JSValueMakeUndefined(context);
854 JSValueRef JSMessage::getMessageId(JSContextRef context,
856 JSStringRef propertyName,
857 JSValueRef* exception)
860 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
861 IMessagePtr msg = converter->toIMessage(object);
862 const string& id = msg->getIdRef();
863 LoggerD("msgId=" << id);
864 LoggerD("msg->getMessageStatus()=" << msg->getMessageStatus());
865 if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
867 return JSValueMakeNull(context);
869 return converter->toJSValueRef(id);
871 catch(BasePlatformException &bex) {
872 /* Currently this exception will not be caught here as converter
873 * is using od-style, DPL exceptions. This catch sections
874 * is prepared for future converter refactoring */
875 LoggerE("Getting message id failure: " << bex.getMessage());
876 return JSValueMakeUndefined(context);
879 LoggerE("UnknownError when getting message id.");
880 return JSValueMakeUndefined(context);
884 JSValueRef JSMessage::getMessagePriority(JSContextRef context,
886 JSStringRef propertyName,
887 JSValueRef* exception)
890 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
891 IMessagePtr msg = converter->toIMessage(object);
892 MessageType msgType = msg->getMessageType();
897 LoggerE("priority : false");
898 return converter->toJSValueRef(false);
901 IEmailPtr email = MessageFactory::convertToEmail(msg);
902 int tmpint = email->getPriority();
903 LoggerE("priority : " << tmpint);
904 if(tmpint == MessagePriority::HIGH)
906 return converter->toJSValueRef(true);
908 return converter->toJSValueRef(false);
911 LoggerE("unsupported message type");
912 /* unsupported type -> type is integral message attribute
913 * so error at this place means internal api error*/
914 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
918 catch(BasePlatformException &bex) {
919 LoggerE("Getting message priority failure: " << bex.getMessage());
920 return JSValueMakeUndefined(context);
923 LoggerE("UnknownError when getting message priority.");
924 return JSValueMakeUndefined(context);
928 JSValueRef JSMessage::getMessageType(JSContextRef context,
930 JSStringRef propertyName,
931 JSValueRef* exception)
934 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
935 IMessagePtr msg = converter->toIMessage(object);
936 MessageType msgType = msg->getMessageType();
938 return converter->toJSValueRef(converter->toMessageType(msgType));
940 catch(BasePlatformException &bex) {
941 /* Currently this exception will not be caught here as converter
942 * is using od-style, DPL exceptions. This catch sections
943 * is prepared for future converter refactoring */
944 LoggerE("Getting message type failure: " << bex.getMessage());
945 return JSValueMakeUndefined(context);
948 LoggerE("UnknownError when getting message type.");
949 return JSValueMakeUndefined(context);
953 JSValueRef JSMessage::getSourceAddress(JSContextRef context,
955 JSStringRef propertyName,
956 JSValueRef* exception)
959 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
960 IMessagePtr msg = converter->toIMessage(object);
961 string from = msg->getSourceAddress();
962 LoggerD("from =" << from);
965 LoggerD("JSValueMakeNull");
966 return JSValueMakeNull(context);
968 return converter->toJSValueRef(from);
970 catch(BasePlatformException &bex) {
971 /* Currently this exception will not be caught here as converter
972 * is using od-style, DPL exceptions. This catch sections
973 * is prepared for future converter refactoring */
974 LoggerE("Getting message source address failure: " << bex.getMessage());
975 return JSValueMakeUndefined(context);
978 LoggerE("UnknownError when getting message source address.");
979 return JSValueMakeUndefined(context);
983 JSValueRef JSMessage::getSubject(JSContextRef context,
985 JSStringRef propertyName,
986 JSValueRef* exception)
989 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
990 IMessagePtr msg = converter->toIMessage(object);
991 MessageType msgType = msg->getMessageType();
996 IMmsPtr mms = MessageFactory::convertToMms(msg);
997 //JSValueMakeUndefined
998 return converter->toJSValueRef(mms->getSubject());
1002 IEmailPtr email = MessageFactory::convertToEmail(msg);
1003 return converter->toJSValueRef(email->getSubject());
1006 return converter->toJSValueRef("");
1008 LoggerE("message not support subject");
1009 /* unsupported type -> type is integral message attribute
1010 * so error at this place means internal api error*/
1011 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1015 catch(BasePlatformException &bex) {
1016 LoggerE("Getting message subject failure: " << bex.getMessage());
1017 return JSValueMakeUndefined(context);
1020 LoggerE("UnknownError when getting message subject.");
1021 return JSValueMakeUndefined(context);
1025 JSValueRef JSMessage::getTime(JSContextRef context,
1027 JSStringRef propertyName,
1028 JSValueRef* exception)
1031 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1032 IMessagePtr msg = converter->toIMessage(object);
1033 struct tm dateTime = msg->getDateTime();
1034 const string& id = msg->getIdRef();
1035 LoggerD("msg->getMessageStatus()=" << msg->getMessageStatus());
1036 LoggerI("id.size() : " << id.size());
1037 if((id.size() == 0) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
1039 LoggerI("JSValueMakeNull");
1040 return JSValueMakeNull(context);
1042 return converter->toJSValueRef(dateTime);
1044 catch(BasePlatformException &bex) {
1045 /* Currently this exception will not be caught here as converter
1046 * is using od-style, DPL exceptions. This catch sections
1047 * is prepared for future converter refactoring */
1048 LoggerE("Getting message time failure: " << bex.getMessage());
1049 return JSValueMakeUndefined(context);
1052 LoggerE("UnknownError when getting message time.");
1053 return JSValueMakeUndefined(context);
1057 JSValueRef JSMessage::getFolder(JSContextRef context,
1059 JSStringRef propertyName,
1060 JSValueRef* exception)
1063 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1064 IMessagePtr msg = converter->toIMessage(object);
1065 FolderType folder = msg->getCurrentFolder();
1067 int tmpInt = msg->getMessageStatus();
1069 LoggerE("folder : " << folder);
1070 LoggerE("msg->getMessageStatus() : " << tmpInt);
1072 if(tmpInt == MESSAGE_STATUS_CREATED)
1074 return JSValueMakeNull(context);
1077 tmpInt = (int)folder;
1078 return converter->toJSValueRef(converter->convertIntToString(tmpInt));
1080 catch(BasePlatformException &bex) {
1081 /* Currently this exception will not be caught here as converter
1082 * is using od-style, DPL exceptions. This catch sections
1083 * is prepared for future converter refactoring */
1084 LoggerE("Getting message folder failure: " << bex.getMessage());
1085 return JSValueMakeUndefined(context);
1088 LoggerE("UnknownError when getting message folder.");
1089 return JSValueMakeUndefined(context);
1093 JSValueRef JSMessage::getMessageBody(JSContextRef context,
1095 JSStringRef propertyName,
1096 JSValueRef* exception)
1098 LoggerI("getMessageBody");
1101 GlobalContextManager *gcm = GlobalContextManager::getInstance();
1103 LoggerE("Failed to get GlobalContextManager");
1104 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
1106 JSContextRef globalContext = gcm->getGlobalContext(context);
1108 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1109 IMessagePtr msg = converter->toIMessage(object); //get message point
1111 return JSMessageBody::createJS(globalContext, msg);
1113 catch(BasePlatformException &bex) {
1114 LoggerE("Getting message body failure: " << bex.getMessage());
1115 return JSValueMakeUndefined(context);
1118 LoggerE("UnknownError when getting message body.");
1119 return JSValueMakeUndefined(context);
1123 JSValueRef JSMessage::getAccountID(JSContextRef context,
1125 JSStringRef propertyName,
1126 JSValueRef* exception)
1128 LoggerI("getAccountID");
1131 GlobalContextManager *gcm = GlobalContextManager::getInstance();
1133 LoggerE("Failed to get GlobalContextManager");
1134 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
1136 JSContextRef globalContext = gcm->getGlobalContext(context);
1138 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1140 IMessagePtr msg = converter->toIMessage(object); //get message point
1142 LoggerI("create JS");
1144 if (msg->getMessageType() == EMAIL)
1146 IEmailPtr email = MessageFactory::convertToEmail(msg);
1147 if(email->getAccountID() == -1)
1149 return JSValueMakeNull(context);
1151 std::stringstream stream;
1152 stream << email->getAccountID();
1153 if (stream.fail()) {
1154 throw DeviceAPI::Common::UnknownException("Couldn't convert e-mail account id");
1157 return converter->toJSValueRef(stream.str());
1159 else if (msg->getMessageType() == SMS)
1161 std::stringstream stream;
1162 stream << SMS_ACCOUNT_ID;
1163 if (stream.fail()) {
1164 throw DeviceAPI::Common::UnknownException("Couldn't convert sms account id");
1167 return converter->toJSValueRef(stream.str());
1169 else if (msg->getMessageType() == MMS)
1171 std::stringstream stream;
1172 stream << MMS_ACCOUNT_ID;
1173 if (stream.fail()) {
1174 throw DeviceAPI::Common::UnknownException("Couldn't convert mms account id");
1177 return converter->toJSValueRef(stream.str());
1181 return JSValueMakeUndefined(context);
1184 catch(BasePlatformException &bex) {
1185 LoggerE("Getting account id failure: " << bex.getMessage());
1186 return JSValueMakeUndefined(context);
1189 LoggerE("UnknownError when getting account id.");
1190 return JSValueMakeUndefined(context);
1194 JSValueRef JSMessage::getUID(JSContextRef context,
1196 JSStringRef propertyName,
1197 JSValueRef* exception)
1202 GlobalContextManager *gcm = GlobalContextManager::getInstance();
1204 LoggerE("Failed to get GlobalContextManager");
1205 throw DeviceAPI::Common::UnknownException("Unable to receive global context");
1207 JSContextRef globalContext = gcm->getGlobalContext(context);
1209 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(globalContext);
1211 IMessagePtr msg = converter->toIMessage(object); //get message point
1213 LoggerI("create JS");
1215 if (msg->getMessageType() == EMAIL)
1217 IEmailPtr email = MessageFactory::convertToEmail(msg);
1218 return converter->toJSValueRef(email->getUID());
1222 return JSValueMakeUndefined(context);
1225 catch(BasePlatformException &bex) {
1226 LoggerE("Getting account id failure: " << bex.getMessage());
1227 return JSValueMakeUndefined(context);
1230 LoggerE("UnknownError when getting account id.");
1231 return JSValueMakeUndefined(context);
1235 bool JSMessage::setAttachments(JSContextRef context,
1237 JSStringRef propertyName,
1239 JSValueRef* exception)
1244 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1246 vector<IAttachmentPtr> attachments;
1247 if (JSIsArrayValue(context, value)) {
1248 JSObjectRef valueObj = converter->toJSObjectRef(value);
1249 unsigned int len = JSGetArrayLength(context, valueObj);
1250 LoggerD("Array Length = " << len);
1251 for (unsigned int i = 0; i < len; ++i)
1253 JSValueRef att = JSObjectGetPropertyAtIndex(context, valueObj, i, NULL);
1254 if (JSValueIsUndefined(context, att) || JSValueIsNull(context, att)) {
1255 LoggerW("Invalid array element. Skipping.");
1258 IAttachmentPtr attachment = converter->toIAttachment(att);
1260 if(attachment->getIsValidAttachment() == false)
1262 LoggerD("invalid attachment : " << i);
1263 throw DeviceAPI::Common::InvalidValuesException("Invalid attachment in array");
1266 LoggerD("Adding attachment , shotname: " << attachment->getShortName());
1267 attachments.push_back(attachment);
1272 IAttachmentPtr attachment = converter->toIAttachment(value);
1273 LoggerD("Adding attachment , shotname: " << attachment->getShortName());
1274 if(attachment->getIsValidAttachment() == false)
1276 LoggerD("invalid attachment");
1277 throw DeviceAPI::Common::InvalidValuesException("Invalid attachments array");
1279 attachments.push_back(attachment);
1282 LoggerD("Attachment Size =" << attachments.size());
1283 if ( attachments.size() > 0)
1285 IMessagePtr msg = converter->toIMessage(object);
1288 MessageType msgType = msg->getMessageType();
1292 IMmsPtr mms = MessageFactory::convertToMms(msg);
1293 mms->setAttachments(attachments);
1298 IEmailPtr email = MessageFactory::convertToEmail(msg);
1299 email->setAttachments(attachments);
1303 LoggerE("not supported message type");
1304 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1311 LoggerE("Message converter failed...");
1312 throw DeviceAPI::Common::UnknownException("Message conversion failure");
1316 catch(BasePlatformException &bex) {
1317 LoggerE("Setting attachments failed: " << bex.getMessage());
1321 LoggerE("UnknownError when setting attachments.");
1328 #if 0 // MESSAGING ATTACHMENT IS BLOCKED
1329 bool JSMessage::setAttachments(JSContextRef context,
1331 JSStringRef propertyName,
1333 JSValueRef* exception)
1339 JSMessagePrivateObject* priv =
1340 static_cast<JSMessagePrivateObject*>(JSObjectGetPrivate(object));
1343 return JSTizenExceptionFactory::postException(context, exception,
1344 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1347 Catch(WrtDeviceApis::Commons::NullPointerException) {
1348 LoggerE("Error on pointer, null value");
1349 return JSTizenExceptionFactory::postException(context, exception,
1350 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1353 vector<string> attachments;
1356 ConverterMessageFactory::ConverterType converter =
1357 ConverterMessageFactory::getConverter(context);
1358 if (JSIsArrayValue(context, value)) {
1359 JSObjectRef valueObj = converter->toJSObjectRef(value);
1361 // extract path from each JSFile object
1362 unsigned int len = JSGetArrayLength(context, valueObj);
1363 for (unsigned int i = 0; i < len; ++i) {
1364 JSValueRef att = JSGetArrayElement(context, valueObj, i);
1365 if (JSValueIsUndefined(context,
1366 att) || JSValueIsNull(context, att)) {
1367 LoggerW("Invalid array element. Skipping.");
1370 DeviceAPI::Filesystem::INodePtr node = converter->toFilesystemNode(
1373 LoggerD("Adding attachment: " << node->getPath()->getFullPath());
1374 attachments.push_back(node->getPath()->getFullPath());
1377 LoggerW("Invalid or null element passed as attachment array." <<
1378 "Setting empty vector.");
1381 // set up new attachments list
1382 IMessagePtr msg = converter->toIMessage(object);
1383 MessageType msgType = msg->getMessageType();
1387 IMmsPtr mms = MessageFactory::convertToMms(msg);
1388 mms->setAttachments(attachments, true);
1393 IEmailPtr email = MessageFactory::convertToEmail(msg);
1394 email->setAttachments(attachments, true);
1399 return false; // ignore
1402 LoggerE("not supported message type");
1403 Throw(WrtDeviceApis::Commons::InvalidArgumentException);
1407 Catch(WrtDeviceApis::Commons::ConversionException) {
1408 LoggerE("Error on conversion");
1409 return JSTizenExceptionFactory::postException(context, exception,
1410 JSTizenException::TYPE_MISMATCH_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1412 Catch(WrtDeviceApis::Commons::NullPointerException) {
1413 LoggerE("Error on pointer, null value");
1414 return JSTizenExceptionFactory::postException(context, exception,
1415 JSTizenException::UNKNOWN_ERROR, JSMESSAGING_EXCEPTION_MSG_UNKNOWN);
1417 Catch(WrtDeviceApis::Commons::InvalidArgumentException) {
1418 LoggerE("Invalid argument");
1419 return JSTizenExceptionFactory::postException(context, exception,
1420 JSTizenException::INVALID_VALUES_ERROR, JSMESSAGING_EXCEPTION_MSG_INVALID_ARGUMENT);
1426 bool JSMessage::setBccAddress(JSContextRef context,
1428 JSStringRef propertyName,
1430 JSValueRef* exception)
1433 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1434 IMessagePtr msg = converter->toIMessage(object);
1435 Recipients bcc = converter->toRecipients(value);
1436 LoggerD("setting bcc field, size=" << bcc.getRecipientSize());
1438 MessageType msgType = msg->getMessageType();
1442 return false; // ignore
1446 IEmailPtr email = MessageFactory::convertToEmail(msg);
1447 email->setBccRecipients(bcc);
1451 LoggerE("not supported message type");
1452 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1457 catch(BasePlatformException &bex) {
1458 LoggerE("Setting BCC addresses failed: " << bex.getMessage());
1462 LoggerE("UnknownError when setting BCC addresses.");
1468 bool JSMessage::setBody(JSContextRef context,
1470 JSStringRef propertyName,
1472 JSValueRef* exception)
1475 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1476 IMessagePtr msg = converter->toIMessage(object);
1477 string body = converter->toString(value);
1481 catch(BasePlatformException &bex) {
1482 /* Currently this exception will not be caught here as converter
1483 * is using od-style, DPL exceptions. This catch sections
1484 * is prepared for future converter refactoring */
1485 LoggerE("Setting BCC addresses failed: " << bex.getMessage());
1489 LoggerE("UnknownError when setting BCC addresses.");
1495 bool JSMessage::setCcAddress(JSContextRef context,
1497 JSStringRef propertyName,
1499 JSValueRef* exception)
1502 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1503 IMessagePtr msg = converter->toIMessage(object);
1504 Recipients cc = converter->toRecipients(value);
1505 LoggerD("setting cc field, size=" << cc.getRecipientSize());
1507 MessageType msgType = msg->getMessageType();
1511 return true; // ignore
1514 IEmailPtr email = MessageFactory::convertToEmail(msg);
1515 email->setCcRecipients(cc);
1519 LoggerE("unsuported message type");
1520 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1525 catch(BasePlatformException &bex) {
1526 LoggerE("Setting CC addresses failed: " << bex.getMessage());
1530 LoggerE("UnknownError when setting CC addresses.");
1536 bool JSMessage::setDestinationAddress(JSContextRef context,
1538 JSStringRef propertyName,
1540 JSValueRef * exception)
1545 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1546 IMessagePtr msg = converter->toIMessage(object);
1547 Recipients to = converter->toRecipients(value);
1548 LoggerD("setting to field, size=" << to.getRecipientSize());
1549 msg->setToRecipients(to);
1552 catch(BasePlatformException &bex) {
1553 /* Currently this exception will not be caught here as converter
1554 * is using od-style, DPL exceptions. This catch sections
1555 * is prepared for future converter refactoring */
1556 LoggerE("Setting destination addresses failed: " << bex.getMessage());
1560 LoggerE("UnknownError when setting destination addresses.");
1566 bool JSMessage::setIsRead(JSContextRef context,
1568 JSStringRef propertyName,
1570 JSValueRef * exception)
1573 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1574 IMessagePtr msg = converter->toIMessage(object);
1575 msg->setReadStatus(converter->toBool(value));
1576 msg->setisReadChangeStatus(converter->toBool(value));
1579 catch(BasePlatformException &bex) {
1580 /* Currently this exception will not be caught here as converter
1581 * is using od-style, DPL exceptions. This catch sections
1582 * is prepared for future converter refactoring */
1583 LoggerE("Setting destination addresses failed: " << bex.getMessage());
1587 LoggerE("UnknownError when setting destination addresses.");
1593 bool JSMessage::setMessagePriority(JSContextRef context,
1595 JSStringRef propertyName,
1597 JSValueRef * exception)
1601 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1602 IMessagePtr msg = converter->toIMessage(object);
1603 MessageType msgType = msg->getMessageType();
1607 // do not set value but show that this attribute is supported in object
1610 msg->setPriority(converter->toMessagePriority(value));
1614 LoggerE("unsuported message type");
1615 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1620 catch(BasePlatformException &bex) {
1621 LoggerE("Setting message priority failed: " << bex.getMessage());
1625 LoggerE("UnknownError when setting message priority.");
1631 bool JSMessage::setSubject(JSContextRef context,
1633 JSStringRef propertyName,
1635 JSValueRef * exception)
1638 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1639 IMessagePtr msg = converter->toIMessage(object);
1640 MessageType msgType = msg->getMessageType();
1641 string subject = converter->toString(value);
1645 IMmsPtr mms = MessageFactory::convertToMms(msg);
1646 mms->setSubject(subject);
1651 IEmailPtr email = MessageFactory::convertToEmail(msg);
1652 email->setSubject(subject);
1656 return true; // ignore
1659 LoggerE("message not supported");
1660 throw DeviceAPI::Common::NotSupportedException("Unsupported message type");
1665 catch(BasePlatformException &bex) {
1666 LoggerE("Setting message priority failed: " << bex.getMessage());
1670 LoggerE("UnknownError when setting message priority.");
1676 bool JSMessage::setMessageBody(JSContextRef context,
1678 JSStringRef propertyName,
1680 JSValueRef* exception)
1685 JSValueRef JSMessage::getConversationId(JSContextRef context,
1687 JSStringRef propertyName,
1688 JSValueRef* exception)
1690 LoggerD("getConversationId");
1693 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1695 IMessagePtr msg = converter->toIMessage(object);
1697 LoggerD("msg->getMessageStatus()=" << msg->getMessageStatus());
1698 LoggerD("msg.getConvId()=" << msg->getConvId());
1699 convId = msg->getConvId();
1700 if((msg->getConvId() == -1) && msg->getMessageStatus() == MESSAGE_STATUS_CREATED)
1702 return JSValueMakeNull(context);
1704 return converter->toJSValueRef(converter->convertIntToString(convId));
1706 catch(BasePlatformException &bex) {
1707 /* Currently this exception will not be caught here as converter
1708 * is using od-style, DPL exceptions. This catch sections
1709 * is prepared for future converter refactoring */
1710 LoggerE("Getting conversation id failure: " << bex.getMessage());
1711 return JSValueMakeUndefined(context);
1714 LoggerE("UnknownError when getting conversation id.");
1715 return JSValueMakeUndefined(context);
1719 JSValueRef JSMessage::getInResponseTo(JSContextRef context,
1721 JSStringRef propertyName,
1722 JSValueRef* exception)
1724 LoggerD("getInResponseTo");
1727 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1730 IMessagePtr msg = converter->toIMessage(object);
1732 if (msg->getMessageType() != EMAIL)
1734 LoggerD("not EMAIL type return empty string");
1735 return converter->toJSValueRef("");
1738 IEmailPtr email = MessageFactory::convertToEmail(msg);
1739 msgId = email->getUID();
1741 LoggerD("msg.getConvId()=" << msg->getConvId());
1742 convId = msg->getConvId();
1744 if (convId == msgId)
1746 LoggerD("Not forwared and replied, return empty string");
1747 return converter->toJSValueRef("");
1750 return converter->toJSValueRef(converter->convertIntToString(convId));
1752 catch(BasePlatformException &bex) {
1753 /* Currently this exception will not be caught here as converter
1754 * is using od-style, DPL exceptions. This catch sections
1755 * is prepared for future converter refactoring */
1756 LoggerE("Getting in response to failure: " << bex.getMessage());
1757 return JSValueMakeUndefined(context);
1760 LoggerE("UnknownError when getting in response to.");
1761 return JSValueMakeUndefined(context);
1765 JSValueRef JSMessage::getMessageStatus(JSContextRef context,
1767 JSStringRef propertyName,
1768 JSValueRef* exception)
1770 LoggerI("getMessageStatus");
1774 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1776 IMessagePtr msg = converter->toIMessage(object); //get message point
1778 LoggerI("create JS");
1779 return converter->toJSValueRef(converter->toMessageStatusType(msg->getMessageStatus()));
1781 catch(BasePlatformException &bex) {
1782 /* Currently this exception will not be caught here as converter
1783 * is using od-style, DPL exceptions. This catch sections
1784 * is prepared for future converter refactoring */
1785 LoggerE("Getting message status failure: " << bex.getMessage());
1786 return JSValueMakeUndefined(context);
1789 LoggerE("UnknownError when getting message status.");
1790 return JSValueMakeUndefined(context);
1795 JSValueRef JSMessage::hasAttachment(JSContextRef context,
1797 JSStringRef propertyName,
1798 JSValueRef* exception)
1800 LoggerI("hasAttachment");
1803 ConverterMessageFactory::ConverterType converter = ConverterMessageFactory::getConverter(context);
1805 IMessagePtr msg = converter->toIMessage(object); //get message point
1807 bool hasAttachmentFlag = false;
1809 if ( msg->getMessageType() == EMAIL)
1811 IEmailPtr email = MessageFactory::convertToEmail(msg);
1813 if (email->hasAttachment())
1814 hasAttachmentFlag = true;
1816 else if ( msg->getMessageType() == MMS)
1818 IMmsPtr mms = MessageFactory::convertToMms(msg);
1820 if (mms->hasAttachment())
1821 hasAttachmentFlag = true;
1825 hasAttachmentFlag = false;
1827 return converter->toJSValueRef(hasAttachmentFlag);
1829 catch(BasePlatformException &bex) {
1830 /* Currently this exception will not be caught here as converter
1831 * is using od-style, DPL exceptions. This catch sections
1832 * is prepared for future converter refactoring */
1833 LoggerE("Getting hasAttachment flag failure: " << bex.getMessage());
1834 return JSValueMakeUndefined(context);
1837 LoggerE("UnknownError when getting hasAttachment flag.");
1838 return JSValueMakeUndefined(context);
1842 // Utility functions.
1843 MessageType JSMessage::stringToMessageType(std::string type)
1845 MessageType retval = UNKNOWN;
1846 if (type.compare("messaging.sms") == 0) {
1849 else if (type.compare("messaging.mms") == 0) {
1852 else if (type.compare("messaging.email") == 0) {
1856 throw DeviceAPI::Common::TypeMismatchException("Invalid MessageServiceTag");