Built motion from commit 97153652.|2.6.26
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index c895df8..b100912 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xf734=['fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','fromString','acceptmessage','mail','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','contact','EventManager','download','unix','toString','files','tmp','server','message-%s.eml','bcc','subject','createdAt','Attachment','Attachments','from','decode','headers','Bcc','existsSync','readFileSync','writeFileSync','unlinkSync','eml-format','moment','bluebird','util','path','ioredis','../../components/parsers/qs','api','../../config/logger','mail-interactions','../../config/environment','../../mysqldb','redis','defaults','localhost','./mailMessage.socket','register','client','http','request','info','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','error','code','MailMessage,\x20%s,\x20%s','message','result','status','offset','undefined','limit','count','set','Content-Range','json','update','then','destroy','end','name','send','index','map','MailMessage','rawAttributes','fieldName','type','key','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','keys','find','body','describe','create','direction','out','secret','split','findOne','MailAccountId','CmList','List','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','basename','ListId','List\x20not\x20found','SendMail','format','accept','read','UserId','agent','get','MailInteraction','MailInteractionId','isNil','read1stAt','YYYY-MM-DD\x20HH:mm:ss','interaction','user','role','stringify','null','acceptMessage','ContactId','Sequelize','QueryTypes','SELECT','User'];(function(_0xfa44b8,_0x3e6c66){var _0x20dcad=function(_0x19c420){while(--_0x19c420){_0xfa44b8['push'](_0xfa44b8['shift']());}};_0x20dcad(++_0x3e6c66);}(_0xf734,0x16a));var _0x4f73=function(_0x132979,_0x49d6ae){_0x132979=_0x132979-0x0;var _0xf97fa0=_0xf734[_0x132979];return _0xf97fa0;};'use strict';var emlformat=require(_0x4f73('0x0'));var moment=require(_0x4f73('0x1'));var BPromise=require(_0x4f73('0x2'));var util=require(_0x4f73('0x3'));var path=require(_0x4f73('0x4'));var fs=require('fs');var _=require('lodash');var Redis=require(_0x4f73('0x5'));var htmlToText=require('html-to-text');var qs=require(_0x4f73('0x6'));var logger=require('../../config/logger')(_0x4f73('0x7'));var interaction_log=require(_0x4f73('0x8'))(_0x4f73('0x9'));var config=require(_0x4f73('0xa'));var db=require(_0x4f73('0xb'))['db'];config[_0x4f73('0xc')]=_[_0x4f73('0xd')](config[_0x4f73('0xc')],{'host':_0x4f73('0xe'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x4f73('0xc')]));var htmlEntities=require('html-entities');require(_0x4f73('0xf'))[_0x4f73('0x10')](socket);var jayson=require('jayson/promise');var client=jayson[_0x4f73('0x11')]['http']({'port':0x232c});var client9003=jayson[_0x4f73('0x11')][_0x4f73('0x12')]({'port':0x232b});var client9002=jayson['client'][_0x4f73('0x12')]({'port':0x232a});function respondWithRpcPromise(_0x2f6a85,_0xc15b46,_0x15c3b7,_0x238843){return new BPromise(function(_0x3bba77,_0x1f7dbe){var _0x29e71e=_0x238843||client;return _0x29e71e[_0x4f73('0x13')](_0x2f6a85,_0x15c3b7)['then'](function(_0x34a3ca){logger[_0x4f73('0x14')]('MailMessage,\x20%s,\x20%s',_0xc15b46,_0x4f73('0x15'));logger[_0x4f73('0x16')](_0x4f73('0x17'),_0xc15b46,'request\x20sent',JSON['stringify'](_0x34a3ca));if(_0x34a3ca[_0x4f73('0x18')]){if(_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x19')]===0x1f4){logger[_0x4f73('0x18')](_0x4f73('0x1a'),_0xc15b46,_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x1b')]);return _0x1f7dbe(_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x1b')]);}logger['error']('MailMessage,\x20%s,\x20%s',_0xc15b46,_0x34a3ca[_0x4f73('0x18')]['message']);return _0x3bba77(_0x34a3ca[_0x4f73('0x18')][_0x4f73('0x1b')]);}else{logger['info'](_0x4f73('0x1a'),_0xc15b46,_0x4f73('0x15'));_0x3bba77(_0x34a3ca[_0x4f73('0x1c')][_0x4f73('0x1b')]);}})['catch'](function(_0xe28367){logger[_0x4f73('0x18')](_0x4f73('0x1a'),_0xc15b46,_0xe28367);_0x1f7dbe(_0xe28367);});});}function respondWithResult(_0x44615c,_0x165d14){_0x165d14=_0x165d14||0xc8;return function(_0x42213a){if(_0x42213a){return _0x44615c[_0x4f73('0x1d')](_0x165d14)['json'](_0x42213a);}};}function respondWithFilteredResult(_0x40303d,_0xa0b221){return function(_0x1058ef){if(_0x1058ef){var _0x3f6c97=typeof _0xa0b221[_0x4f73('0x1e')]===_0x4f73('0x1f')&&typeof _0xa0b221[_0x4f73('0x20')]===_0x4f73('0x1f');var _0x3dd9b1=_0x1058ef[_0x4f73('0x21')];var _0xaf6864=_0x3f6c97?0x0:_0xa0b221['offset'];var _0xee5cd2=_0x3f6c97?_0x1058ef['count']:_0xa0b221[_0x4f73('0x1e')]+_0xa0b221[_0x4f73('0x20')];var _0x1ef623;if(_0xee5cd2>=_0x3dd9b1){_0xee5cd2=_0x3dd9b1;_0x1ef623=0xc8;}else{_0x1ef623=0xce;}_0x40303d['status'](_0x1ef623);return _0x40303d[_0x4f73('0x22')](_0x4f73('0x23'),_0xaf6864+'-'+_0xee5cd2+'/'+_0x3dd9b1)[_0x4f73('0x24')](_0x1058ef);}return null;};}function saveUpdates(_0x72771d){return function(_0x3fac0c){if(_0x3fac0c){return _0x3fac0c[_0x4f73('0x25')](_0x72771d)[_0x4f73('0x26')](function(_0x2f3c84){return _0x2f3c84;});}return null;};}function removeEntity(_0x4ced5e){return function(_0x420ff5){if(_0x420ff5){return _0x420ff5[_0x4f73('0x27')]()[_0x4f73('0x26')](function(){_0x4ced5e[_0x4f73('0x1d')](0xcc)[_0x4f73('0x28')]();});}};}function handleEntityNotFound(_0x9b37e1){return function(_0x26a2da){if(!_0x26a2da){_0x9b37e1['sendStatus'](0x194);}return _0x26a2da;};}function handleError(_0x37cc50,_0x33e5e5){_0x33e5e5=_0x33e5e5||0x1f4;return function(_0xc54ec5){logger[_0x4f73('0x18')](_0xc54ec5['stack']);if(_0xc54ec5[_0x4f73('0x29')]){delete _0xc54ec5[_0x4f73('0x29')];}_0x37cc50[_0x4f73('0x1d')](_0x33e5e5)[_0x4f73('0x2a')](_0xc54ec5);};}exports[_0x4f73('0x2b')]=function(_0x53176c,_0xbd66a7){var _0x220f82={},_0xacb95f={},_0x3ba980={'count':0x0,'rows':[]};var _0x30d312=_[_0x4f73('0x2c')](db[_0x4f73('0x2d')][_0x4f73('0x2e')],function(_0x3b7c5e){return{'name':_0x3b7c5e[_0x4f73('0x2f')],'type':_0x3b7c5e[_0x4f73('0x30')][_0x4f73('0x31')]};});_0xacb95f['model']=_[_0x4f73('0x2c')](_0x30d312,'name');_0xacb95f[_0x4f73('0x32')]=_['keys'](_0x53176c['query']);_0xacb95f[_0x4f73('0x33')]=_[_0x4f73('0x34')](_0xacb95f[_0x4f73('0x35')],_0xacb95f[_0x4f73('0x32')]);_0x220f82[_0x4f73('0x36')]=_[_0x4f73('0x34')](_0xacb95f[_0x4f73('0x35')],qs[_0x4f73('0x37')](_0x53176c[_0x4f73('0x32')]['fields']));_0x220f82['attributes']=_0x220f82[_0x4f73('0x36')][_0x4f73('0x38')]?_0x220f82[_0x4f73('0x36')]:_0xacb95f[_0x4f73('0x35')];if(!_0x53176c[_0x4f73('0x32')][_0x4f73('0x39')](_0x4f73('0x3a'))){_0x220f82[_0x4f73('0x20')]=qs['limit'](_0x53176c['query'][_0x4f73('0x20')]);_0x220f82[_0x4f73('0x1e')]=qs[_0x4f73('0x1e')](_0x53176c['query'][_0x4f73('0x1e')]);}_0x220f82[_0x4f73('0x3b')]=qs['sort'](_0x53176c[_0x4f73('0x32')][_0x4f73('0x3c')]);_0x220f82[_0x4f73('0x3d')]=qs[_0x4f73('0x33')](_[_0x4f73('0x3e')](_0x53176c[_0x4f73('0x32')],_0xacb95f[_0x4f73('0x33')]),_0x30d312);if(_0x53176c['query'][_0x4f73('0x3f')]){_0x220f82[_0x4f73('0x3d')]=_[_0x4f73('0x40')](_0x220f82[_0x4f73('0x3d')],{'$or':_['map'](_0x30d312,function(_0x330b68){if(_0x330b68[_0x4f73('0x30')]!==_0x4f73('0x41')){var _0x23ba31={};_0x23ba31[_0x330b68[_0x4f73('0x29')]]={'$like':'%'+_0x53176c['query'][_0x4f73('0x3f')]+'%'};return _0x23ba31;}})});}_0x220f82=_['merge']({},_0x220f82,_0x53176c[_0x4f73('0x42')]);var _0x4b60f3={'where':_0x220f82[_0x4f73('0x3d')]};return db[_0x4f73('0x2d')]['count'](_0x4b60f3)[_0x4f73('0x26')](function(_0x53d3d5){_0x3ba980[_0x4f73('0x21')]=_0x53d3d5;if(_0x53176c[_0x4f73('0x32')][_0x4f73('0x43')]){_0x220f82[_0x4f73('0x44')]=[{'all':!![]}];}return db[_0x4f73('0x2d')][_0x4f73('0x45')](_0x220f82);})[_0x4f73('0x26')](function(_0x583527){_0x3ba980[_0x4f73('0x46')]=_0x583527;return _0x3ba980;})[_0x4f73('0x26')](respondWithFilteredResult(_0xbd66a7,_0x220f82))[_0x4f73('0x47')](handleError(_0xbd66a7,null));};exports[_0x4f73('0x48')]=function(_0x35b319,_0x1c1897){var _0x2810bf={'raw':!![],'where':{'id':_0x35b319[_0x4f73('0x49')]['id']}},_0x2a44e7={};_0x2a44e7[_0x4f73('0x35')]=_[_0x4f73('0x4a')](db[_0x4f73('0x2d')]['rawAttributes']);_0x2a44e7[_0x4f73('0x32')]=_[_0x4f73('0x4a')](_0x35b319[_0x4f73('0x32')]);_0x2a44e7['filters']=_[_0x4f73('0x34')](_0x2a44e7['model'],_0x2a44e7['query']);_0x2810bf[_0x4f73('0x36')]=_[_0x4f73('0x34')](_0x2a44e7[_0x4f73('0x35')],qs[_0x4f73('0x37')](_0x35b319[_0x4f73('0x32')][_0x4f73('0x37')]));_0x2810bf['attributes']=_0x2810bf[_0x4f73('0x36')][_0x4f73('0x38')]?_0x2810bf[_0x4f73('0x36')]:_0x2a44e7[_0x4f73('0x35')];if(_0x35b319[_0x4f73('0x32')][_0x4f73('0x43')]){_0x2810bf[_0x4f73('0x44')]=[{'all':!![]}];}_0x2810bf=_[_0x4f73('0x40')]({},_0x2810bf,_0x35b319['options']);return db[_0x4f73('0x2d')][_0x4f73('0x4b')](_0x2810bf)['then'](handleEntityNotFound(_0x1c1897,null))['then'](respondWithResult(_0x1c1897,null))[_0x4f73('0x47')](handleError(_0x1c1897,null));};exports[_0x4f73('0x25')]=function(_0x29b527,_0x2804fa){if(_0x29b527['body']['id']){delete _0x29b527['body']['id'];}return db['MailMessage'][_0x4f73('0x4b')]({'where':{'id':_0x29b527[_0x4f73('0x49')]['id']}})[_0x4f73('0x26')](handleEntityNotFound(_0x2804fa,null))[_0x4f73('0x26')](saveUpdates(_0x29b527[_0x4f73('0x4c')],null))[_0x4f73('0x26')](respondWithResult(_0x2804fa,null))[_0x4f73('0x47')](handleError(_0x2804fa,null));};exports[_0x4f73('0x27')]=function(_0x42b0e9,_0x3bd9ec){return db[_0x4f73('0x2d')][_0x4f73('0x4b')]({'where':{'id':_0x42b0e9[_0x4f73('0x49')]['id']}})['then'](handleEntityNotFound(_0x3bd9ec,null))[_0x4f73('0x26')](removeEntity(_0x3bd9ec,null))[_0x4f73('0x47')](handleError(_0x3bd9ec,null));};exports[_0x4f73('0x4d')]=function(_0x4822b4,_0x485935){return db[_0x4f73('0x2d')][_0x4f73('0x4d')]()[_0x4f73('0x26')](respondWithResult(_0x485935,null))[_0x4f73('0x47')](handleError(_0x485935,null));};exports[_0x4f73('0x4e')]=function(_0x5ee115,_0x2d954b){return db[_0x4f73('0x2d')][_0x4f73('0x4e')](_0x5ee115['body'])[_0x4f73('0x26')](function(_0x5d0288){if(_0x5d0288){if(_0x5d0288[_0x4f73('0x4f')]===_0x4f73('0x50')&&!_0x5d0288[_0x4f73('0x51')]){var _0x11475f,_0x425af4,_0x24503a;if(_0x5ee115[_0x4f73('0x4c')]['to']){_0x425af4=_0x5ee115[_0x4f73('0x4c')]['to'][_0x4f73('0x52')](',')[0x0];}return db['MailAccount'][_0x4f73('0x53')]({'where':{'id':_0x5d0288[_0x4f73('0x54')]},'include':[{'model':db[_0x4f73('0x55')],'as':_0x4f73('0x56'),'include':[{'model':db[_0x4f73('0x57')],'as':_0x4f73('0x58'),'where':{'email':_0x425af4},'limit':0x1,'order':[[_0x4f73('0x59'),_0x4f73('0x5a')]]}]},{'model':db[_0x4f73('0x5b')],'as':_0x4f73('0x5c'),'raw':!![],'include':[{'model':db[_0x4f73('0x5d')],'as':_0x4f73('0x5d'),'raw':!![]}]}]})['then'](function(_0x5add97){_0x11475f=_0x5add97;if(!_0x11475f||!_0x11475f[_0x4f73('0x5c')])return;var _0x256294=_0x11475f[_0x4f73('0x5e')]();if(_0x5ee115[_0x4f73('0x4c')][_0x4f73('0x5f')]&&_0x5ee115[_0x4f73('0x4c')][_0x4f73('0x5f')][_0x4f73('0x38')]){for(var _0x24a8f9=0x0;_0x24a8f9<_0x5ee115[_0x4f73('0x4c')]['attachments'][_0x4f73('0x38')];_0x24a8f9+=0x1){_0x5ee115['body'][_0x4f73('0x5f')][_0x24a8f9]={'filename':_0x5ee115[_0x4f73('0x4c')][_0x4f73('0x5f')][_0x24a8f9][_0x4f73('0x29')],'path':path[_0x4f73('0x60')](config[_0x4f73('0x61')],'server/files/attachments',_0x5ee115[_0x4f73('0x4c')]['attachments'][_0x24a8f9][_0x4f73('0x62')])};}}_0x24503a={'account':_0x256294,'message':_0x5ee115[_0x4f73('0x4c')]};return;})[_0x4f73('0x26')](function(){if(_0x11475f['List']){if(_0x11475f[_0x4f73('0x56')][_0x4f73('0x58')][_0x4f73('0x38')]){return _0x11475f['List'][_0x4f73('0x58')][0x0];}else{return db[_0x4f73('0x57')][_0x4f73('0x4e')](_[_0x4f73('0xd')](_0x5ee115[_0x4f73('0x4c')],{'firstName':_0x5ee115[_0x4f73('0x4c')]['to'],'email':_0x5ee115[_0x4f73('0x4c')]['to'],'phone':_0x5ee115['body']['to'],'ListId':_0x11475f[_0x4f73('0x63')]}));}}else{throw new Error(_0x4f73('0x64'));}})[_0x4f73('0x26')](function(){if(_0x24503a){return respondWithRpcPromise(_0x4f73('0x65'),'sendMail',_0x24503a,client9003)[_0x4f73('0x26')](function(_0x543957){return _0x5d0288[_0x4f73('0x25')]({'read':!![],'messageId':_0x543957['messageId'],'sentAt':moment()[_0x4f73('0x66')]('YYYY-MM-DD\x20HH:mm:ss')});})['catch'](function(_0x596ebc){logger[_0x4f73('0x18')]('%s',JSON['stringify'](_0x596ebc));return _0x5d0288;});}return _0x5d0288;});}return _0x5d0288;}})[_0x4f73('0x26')](respondWithResult(_0x2d954b,0xc9))[_0x4f73('0x47')](handleError(_0x2d954b,null));};exports[_0x4f73('0x67')]=function(_0x31bd3d,_0xc55ca9){var _0x17a4c8={'agent':{},'channel':'mail'};if(_0x31bd3d[_0x4f73('0x4c')]['id']){delete _0x31bd3d[_0x4f73('0x4c')]['id'];}_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x68')]=!![];_0x31bd3d[_0x4f73('0x4c')]['readAt']=moment()[_0x4f73('0x66')]('YYYY-MM-DD\x20HH:mm:ss');_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x69')]=_0x31bd3d['body'][_0x4f73('0x69')]||_0x31bd3d['user']['id'];_0x17a4c8[_0x4f73('0x6a')]['id']=_0x31bd3d[_0x4f73('0x4c')]['UserId'];return db[_0x4f73('0x2d')][_0x4f73('0x4b')]({'where':{'id':_0x31bd3d[_0x4f73('0x49')]['id'],'UserId':null}})[_0x4f73('0x26')](handleEntityNotFound(_0xc55ca9,null))[_0x4f73('0x26')](saveUpdates(_0x31bd3d['body'],null))[_0x4f73('0x26')](function(_0x3db287){if(_0x3db287){_0x17a4c8[_0x4f73('0x1b')]=_0x3db287[_0x4f73('0x6b')]({'plain':!![]});return db[_0x4f73('0x6c')][_0x4f73('0x4b')]({'where':{'id':_0x3db287[_0x4f73('0x6d')]}});}return null;})[_0x4f73('0x26')](handleEntityNotFound(_0xc55ca9,null))['then'](function(_0x541e31){if(_0x541e31){return _0x541e31[_0x4f73('0x25')]({'UserId':_0x31bd3d['body'][_0x4f73('0x69')],'read1stAt':_[_0x4f73('0x6e')](_0x541e31[_0x4f73('0x6f')])?moment()[_0x4f73('0x66')](_0x4f73('0x70')):undefined});}return null;})['then'](function(_0x283d62){if(_0x283d62){_0x17a4c8[_0x4f73('0x71')]=_0x283d62['get']({'plain':!![]});interaction_log[_0x4f73('0x14')]('[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x31bd3d[_0x4f73('0x72')]['id'],_0x31bd3d[_0x4f73('0x72')][_0x4f73('0x29')],_0x31bd3d[_0x4f73('0x72')][_0x4f73('0x73')],_0x17a4c8[_0x4f73('0x71')]['id'],_0x31bd3d[_0x4f73('0x4c')]?JSON[_0x4f73('0x74')](_0x31bd3d[_0x4f73('0x4c')]):_0x4f73('0x75'));return respondWithRpcPromise('AcceptMessage',_0x4f73('0x76'),_0x17a4c8);}return null;})[_0x4f73('0x26')](function(_0x4b1978){var _0x4c31f8='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x4b1978[_0x4f73('0x1b')][_0x4f73('0x77')];return db['sequelize'][_0x4f73('0x32')](_0x4c31f8,{'type':db[_0x4f73('0x78')][_0x4f73('0x79')][_0x4f73('0x7a')],'raw':!![]})[_0x4f73('0x26')](function(_0x51258d){return _0x51258d;});})[_0x4f73('0x26')](function(_0x592dc8){if(_0x592dc8){_0x17a4c8[_0x4f73('0x1b')]['contact']=_0x592dc8[0x0];if(!_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x69')])return;return db[_0x4f73('0x7b')][_0x4f73('0x4b')]({'where':{'id':_0x31bd3d[_0x4f73('0x4c')]['UserId'],'role':_0x4f73('0x6a')},'attributes':['id','name',_0x4f73('0x7c'),_0x4f73('0x7d'),_0x4f73('0x7e')],'raw':!![]});}return null;})[_0x4f73('0x26')](function(_0x54169f){if(!_0x54169f)return null;_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x6a')]=_0x54169f;return _0x17a4c8;})[_0x4f73('0x26')](function(_0xd0ed57){if(_0xd0ed57){if(_0x31bd3d[_0x4f73('0x4c')][_0x4f73('0x7f')]){_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x80')]=util[_0x4f73('0x66')](_0x4f73('0x81'),_0x31bd3d[_0x4f73('0x72')][_0x4f73('0x29')]);_0x17a4c8['message'][_0x4f73('0x82')]=_0x17a4c8[_0x4f73('0x82')];_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x83')]=_0x17a4c8[_0x4f73('0x82')];_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x84')]='accept';_0x17a4c8[_0x4f73('0x1b')]['body']=htmlToText[_0x4f73('0x85')](_0x17a4c8[_0x4f73('0x1b')][_0x4f73('0x4c')]);return respondWithRpcPromise('EventManager','EventManager',{'event':_0x4f73('0x86'),'message':_0x17a4c8[_0x4f73('0x1b')]},client9002)[_0x4f73('0x26')](function(){return _0x17a4c8;});}return _0x17a4c8;}return null;})['then'](respondWithResult(_0xc55ca9,null))[_0x4f73('0x47')](handleError(_0xc55ca9,null));};exports['reject']=function(_0x1af4d8,_0x4fb0a7){var _0x105e00={'agent':{},'channel':_0x4f73('0x87')};if(_0x1af4d8[_0x4f73('0x4c')]['id']){delete _0x1af4d8[_0x4f73('0x4c')]['id'];}_0x1af4d8['body'][_0x4f73('0x69')]=_0x1af4d8[_0x4f73('0x4c')][_0x4f73('0x69')]||_0x1af4d8[_0x4f73('0x72')]['id'];_0x105e00[_0x4f73('0x6a')]['id']=_0x1af4d8[_0x4f73('0x4c')]['UserId'];return db['MailMessage'][_0x4f73('0x4b')]({'where':{'id':_0x1af4d8[_0x4f73('0x49')]['id'],'UserId':null}})[_0x4f73('0x26')](handleEntityNotFound(_0x4fb0a7,null))[_0x4f73('0x26')](function(_0xc12767){if(_0xc12767){_0x105e00[_0x4f73('0x1b')]=_0xc12767[_0x4f73('0x6b')]({'plain':!![]});return db[_0x4f73('0x6c')]['find']({'where':{'id':_0xc12767[_0x4f73('0x6d')]}});}return null;})['then'](handleEntityNotFound(_0x4fb0a7,null))[_0x4f73('0x26')](function(_0x52865a){if(_0x52865a){_0x105e00[_0x4f73('0x71')]=_0x52865a[_0x4f73('0x6b')]({'plain':!![]});interaction_log['info'](_0x4f73('0x88'),_0x1af4d8[_0x4f73('0x72')]['id'],_0x1af4d8[_0x4f73('0x72')][_0x4f73('0x29')],_0x1af4d8['user'][_0x4f73('0x73')],_0x105e00[_0x4f73('0x71')]['id'],_0x1af4d8[_0x4f73('0x4c')]?JSON[_0x4f73('0x74')](_0x1af4d8['body']):'null');return respondWithRpcPromise(_0x4f73('0x89'),_0x4f73('0x8a'),_0x105e00);}return null;})[_0x4f73('0x26')](function(_0x97bf66){var _0x47769c=_0x4f73('0x8b')+_0x97bf66['message'][_0x4f73('0x77')];return db['sequelize']['query'](_0x47769c,{'type':db[_0x4f73('0x78')][_0x4f73('0x79')][_0x4f73('0x7a')],'raw':!![]})[_0x4f73('0x26')](function(_0x4c5228){return _0x4c5228;});})[_0x4f73('0x26')](function(_0x2837ff){if(_0x2837ff){_0x105e00['message'][_0x4f73('0x8c')]=_0x2837ff[0x0];if(!_0x1af4d8[_0x4f73('0x4c')][_0x4f73('0x69')])return;return db['User'][_0x4f73('0x4b')]({'where':{'id':_0x1af4d8[_0x4f73('0x4c')][_0x4f73('0x69')],'role':_0x4f73('0x6a')},'attributes':['id','name','fullname',_0x4f73('0x7d'),_0x4f73('0x7e')],'raw':!![]});}return null;})[_0x4f73('0x26')](function(_0x5646d9){if(!_0x5646d9)return null;_0x105e00['message'][_0x4f73('0x6a')]=_0x5646d9;return _0x105e00;})[_0x4f73('0x26')](function(_0x5c0fbe){if(_0x5c0fbe){_0x5c0fbe[_0x4f73('0x1b')][_0x4f73('0x80')]=util[_0x4f73('0x66')](_0x4f73('0x81'),_0x1af4d8[_0x4f73('0x72')]['name']);_0x5c0fbe[_0x4f73('0x1b')]['channel']=_0x105e00[_0x4f73('0x82')];_0x5c0fbe[_0x4f73('0x1b')][_0x4f73('0x83')]=_0x105e00[_0x4f73('0x82')];_0x5c0fbe['message'][_0x4f73('0x84')]='reject';_0x5c0fbe[_0x4f73('0x1b')][_0x4f73('0x4c')]=htmlToText[_0x4f73('0x85')](_0x105e00[_0x4f73('0x1b')][_0x4f73('0x4c')]);respondWithRpcPromise(_0x4f73('0x8d'),_0x4f73('0x8d'),{'event':'rejectmessage','message':_0x5c0fbe[_0x4f73('0x1b')]},client9002);return _0x105e00;}return null;})[_0x4f73('0x26')](respondWithResult(_0x4fb0a7,null))[_0x4f73('0x47')](handleError(_0x4fb0a7,null));};exports[_0x4f73('0x8e')]=function(_0x7e93d2,_0x27ad05){var _0xfa3bfc=moment()[_0x4f73('0x8f')]()[_0x4f73('0x90')]();var _0x19e036=path['join'](config[_0x4f73('0x61')],'server',_0x4f73('0x91'),_0x4f73('0x92'));var _0x2b94ee=path[_0x4f73('0x60')](config['root'],_0x4f73('0x93'),_0x4f73('0x91'),_0x4f73('0x5f'));var _0x4c0201=util['format'](_0x4f73('0x94'),_0xfa3bfc);return db['MailMessage'][_0x4f73('0x4b')]({'where':{'id':_0x7e93d2[_0x4f73('0x49')]['id']},'attributes':['id',_0x4f73('0x4c'),'from','to','cc',_0x4f73('0x95'),_0x4f73('0x96'),_0x4f73('0x97')],'include':_0x7e93d2[_0x4f73('0x32')][_0x4f73('0x5f')]?[{'model':db[_0x4f73('0x98')],'as':_0x4f73('0x99')}]:undefined})[_0x4f73('0x26')](handleEntityNotFound(_0x27ad05,null))[_0x4f73('0x26')](function(_0x557efd){if(_0x557efd){var _0x150bc4=_0x557efd;var _0x2deac0={'from':_0x150bc4[_0x4f73('0x9a')],'to':_0x150bc4['to'],'subject':_0x150bc4[_0x4f73('0x96')],'html':htmlEntities[_0x4f73('0x9b')](_0x150bc4[_0x4f73('0x4c')]),'headers':{'Date':moment(_0x150bc4[_0x4f73('0x97')])[_0x4f73('0x66')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x557efd['cc']){_0x2deac0[_0x4f73('0x9c')]['Cc']=_0x557efd['cc'];}if(_0x557efd['bcc']){_0x2deac0['headers'][_0x4f73('0x9d')]=_0x557efd[_0x4f73('0x95')];}return new BPromise(function(_0x2ef825,_0x16918a){if(_0x557efd[_0x4f73('0x99')]){for(var _0xa028cb=0x0;_0xa028cb<_0x557efd[_0x4f73('0x99')][_0x4f73('0x38')];_0xa028cb++){var _0x299642=_0x557efd[_0x4f73('0x99')][_0xa028cb];var _0x4e0810=path['join'](_0x2b94ee,_0x299642[_0x4f73('0x62')]);if(fs[_0x4f73('0x9e')](_0x4e0810)){_0x2deac0[_0x4f73('0x5f')]['push']({'name':_0x299642['name'],'contentType':_0x299642[_0x4f73('0x30')],'data':fs[_0x4f73('0x9f')](_0x4e0810)});}}}emlformat['build'](_0x2deac0,function(_0x12ba41,_0x2f575a){if(_0x12ba41)return _0x16918a(_0x12ba41);fs[_0x4f73('0xa0')](path[_0x4f73('0x60')](_0x19e036,_0x4c0201),_0x2f575a);return _0x2ef825(_0x2f575a);});});}})['then'](function(_0x35f456){if(_0x35f456){return _0x27ad05[_0x4f73('0x8e')](path['join'](_0x19e036,_0x4c0201),_0x4c0201,function(_0x399be6){if(!_0x399be6)fs[_0x4f73('0xa1')](path[_0x4f73('0x60')](_0x19e036,_0x4c0201));});}})[_0x4f73('0x47')](handleError(_0x27ad05,null));};
\ No newline at end of file
+var _0x6f5f=['SendMail','sendMail','messageId','YYYY-MM-DD\x20HH:mm:ss','accept','mail','readAt','format','UserId','agent','isNil','read1stAt','interaction','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','AcceptMessage','acceptMessage','ContactId','Sequelize','SELECT','User','fullname','email','internal','manual','interface','channel','motionChannel','event','fromString','EventManager','acceptmessage','MailInteraction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','QueryTypes','contact','SIP/%s','reject','rejectmessage','download','unix','toString','server','files','tmp','message-%s.eml','from','bcc','subject','createdAt','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','readFileSync','build','writeFileSync','eml-format','moment','bluebird','util','lodash','ioredis','html-to-text','../../components/parsers/qs','../../config/logger','api','../../mysqldb','redis','defaults','localhost','socket.io-emitter','html-entities','./mailMessage.socket','register','jayson/promise','client','http','then','info','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','MailMessage,\x20%s,\x20%s','message','result','catch','status','offset','undefined','limit','count','set','Content-Range','json','update','destroy','end','sendStatus','name','send','index','map','MailMessage','fieldName','type','key','model','query','keys','filters','intersection','attributes','fields','length','hasOwnProperty','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','findAll','rows','show','params','rawAttributes','include','find','body','describe','create','direction','secret','split','findOne','MailAccountId','CmList','CmContact','updatedAt','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','server/files/attachments','basename','List','Contacts','ListId','List\x20not\x20found'];(function(_0x1e2080,_0x53283b){var _0x260111=function(_0x15da5e){while(--_0x15da5e){_0x1e2080['push'](_0x1e2080['shift']());}};_0x260111(++_0x53283b);}(_0x6f5f,0xe7));var _0xf6f5=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0x6f5f[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0xf6f5('0x0'));var moment=require(_0xf6f5('0x1'));var BPromise=require(_0xf6f5('0x2'));var util=require(_0xf6f5('0x3'));var path=require('path');var fs=require('fs');var _=require(_0xf6f5('0x4'));var Redis=require(_0xf6f5('0x5'));var htmlToText=require(_0xf6f5('0x6'));var qs=require(_0xf6f5('0x7'));var logger=require(_0xf6f5('0x8'))(_0xf6f5('0x9'));var interaction_log=require(_0xf6f5('0x8'))('mail-interactions');var config=require('../../config/environment');var db=require(_0xf6f5('0xa'))['db'];config[_0xf6f5('0xb')]=_[_0xf6f5('0xc')](config[_0xf6f5('0xb')],{'host':_0xf6f5('0xd'),'port':0x18eb});var socket=require(_0xf6f5('0xe'))(new Redis(config[_0xf6f5('0xb')]));var htmlEntities=require(_0xf6f5('0xf'));require(_0xf6f5('0x10'))[_0xf6f5('0x11')](socket);var jayson=require(_0xf6f5('0x12'));var client=jayson[_0xf6f5('0x13')][_0xf6f5('0x14')]({'port':0x232c});var client9003=jayson[_0xf6f5('0x13')][_0xf6f5('0x14')]({'port':0x232b});var client9002=jayson[_0xf6f5('0x13')][_0xf6f5('0x14')]({'port':0x232a});function respondWithRpcPromise(_0x44290c,_0x425822,_0x8d6f6,_0x125677){return new BPromise(function(_0x52c6e3,_0x244499){var _0x3afb95=_0x125677||client;return _0x3afb95['request'](_0x44290c,_0x8d6f6)[_0xf6f5('0x15')](function(_0x116a35){logger[_0xf6f5('0x16')]('MailMessage,\x20%s,\x20%s',_0x425822,_0xf6f5('0x17'));logger['debug'](_0xf6f5('0x18'),_0x425822,_0xf6f5('0x17'),JSON[_0xf6f5('0x19')](_0x116a35));if(_0x116a35[_0xf6f5('0x1a')]){if(_0x116a35[_0xf6f5('0x1a')]['code']===0x1f4){logger['error'](_0xf6f5('0x1b'),_0x425822,_0x116a35[_0xf6f5('0x1a')][_0xf6f5('0x1c')]);return _0x244499(_0x116a35[_0xf6f5('0x1a')][_0xf6f5('0x1c')]);}logger[_0xf6f5('0x1a')](_0xf6f5('0x1b'),_0x425822,_0x116a35['error'][_0xf6f5('0x1c')]);return _0x52c6e3(_0x116a35[_0xf6f5('0x1a')][_0xf6f5('0x1c')]);}else{logger['info'](_0xf6f5('0x1b'),_0x425822,_0xf6f5('0x17'));_0x52c6e3(_0x116a35[_0xf6f5('0x1d')][_0xf6f5('0x1c')]);}})[_0xf6f5('0x1e')](function(_0x667aad){logger[_0xf6f5('0x1a')](_0xf6f5('0x1b'),_0x425822,_0x667aad);_0x244499(_0x667aad);});});}function respondWithResult(_0x110a70,_0x3ff047){_0x3ff047=_0x3ff047||0xc8;return function(_0x5a3f42){if(_0x5a3f42){return _0x110a70[_0xf6f5('0x1f')](_0x3ff047)['json'](_0x5a3f42);}};}function respondWithFilteredResult(_0x3ebc64,_0x23ce20){return function(_0x457ffa){if(_0x457ffa){var _0x267a8d=typeof _0x23ce20[_0xf6f5('0x20')]===_0xf6f5('0x21')&&typeof _0x23ce20[_0xf6f5('0x22')]===_0xf6f5('0x21');var _0x23ff20=_0x457ffa[_0xf6f5('0x23')];var _0xb9cdfc=_0x267a8d?0x0:_0x23ce20[_0xf6f5('0x20')];var _0x25581b=_0x267a8d?_0x457ffa[_0xf6f5('0x23')]:_0x23ce20['offset']+_0x23ce20[_0xf6f5('0x22')];var _0x214a54;if(_0x25581b>=_0x23ff20){_0x25581b=_0x23ff20;_0x214a54=0xc8;}else{_0x214a54=0xce;}_0x3ebc64[_0xf6f5('0x1f')](_0x214a54);return _0x3ebc64[_0xf6f5('0x24')](_0xf6f5('0x25'),_0xb9cdfc+'-'+_0x25581b+'/'+_0x23ff20)[_0xf6f5('0x26')](_0x457ffa);}return null;};}function saveUpdates(_0x3eff6c){return function(_0x2b967c){if(_0x2b967c){return _0x2b967c[_0xf6f5('0x27')](_0x3eff6c)[_0xf6f5('0x15')](function(_0x58d4c2){return _0x58d4c2;});}return null;};}function removeEntity(_0x453d16){return function(_0x1b4a81){if(_0x1b4a81){return _0x1b4a81[_0xf6f5('0x28')]()['then'](function(){_0x453d16[_0xf6f5('0x1f')](0xcc)[_0xf6f5('0x29')]();});}};}function handleEntityNotFound(_0x3c39cb){return function(_0x55f938){if(!_0x55f938){_0x3c39cb[_0xf6f5('0x2a')](0x194);}return _0x55f938;};}function handleError(_0x4d79b5,_0x6caf31){_0x6caf31=_0x6caf31||0x1f4;return function(_0x366f6d){logger[_0xf6f5('0x1a')](_0x366f6d['stack']);if(_0x366f6d[_0xf6f5('0x2b')]){delete _0x366f6d['name'];}_0x4d79b5['status'](_0x6caf31)[_0xf6f5('0x2c')](_0x366f6d);};}exports[_0xf6f5('0x2d')]=function(_0x1282ec,_0x20bd23){var _0x532851={},_0x1eeb1={},_0x12bdf6={'count':0x0,'rows':[]};var _0x2fb31a=_[_0xf6f5('0x2e')](db[_0xf6f5('0x2f')]['rawAttributes'],function(_0x2f3c43){return{'name':_0x2f3c43[_0xf6f5('0x30')],'type':_0x2f3c43[_0xf6f5('0x31')][_0xf6f5('0x32')]};});_0x1eeb1[_0xf6f5('0x33')]=_[_0xf6f5('0x2e')](_0x2fb31a,_0xf6f5('0x2b'));_0x1eeb1[_0xf6f5('0x34')]=_[_0xf6f5('0x35')](_0x1282ec[_0xf6f5('0x34')]);_0x1eeb1[_0xf6f5('0x36')]=_[_0xf6f5('0x37')](_0x1eeb1['model'],_0x1eeb1['query']);_0x532851[_0xf6f5('0x38')]=_['intersection'](_0x1eeb1['model'],qs[_0xf6f5('0x39')](_0x1282ec[_0xf6f5('0x34')][_0xf6f5('0x39')]));_0x532851[_0xf6f5('0x38')]=_0x532851['attributes'][_0xf6f5('0x3a')]?_0x532851['attributes']:_0x1eeb1[_0xf6f5('0x33')];if(!_0x1282ec[_0xf6f5('0x34')][_0xf6f5('0x3b')]('nolimit')){_0x532851['limit']=qs[_0xf6f5('0x22')](_0x1282ec[_0xf6f5('0x34')][_0xf6f5('0x22')]);_0x532851['offset']=qs[_0xf6f5('0x20')](_0x1282ec[_0xf6f5('0x34')][_0xf6f5('0x20')]);}_0x532851['order']=qs[_0xf6f5('0x3c')](_0x1282ec['query'][_0xf6f5('0x3c')]);_0x532851[_0xf6f5('0x3d')]=qs[_0xf6f5('0x36')](_[_0xf6f5('0x3e')](_0x1282ec['query'],_0x1eeb1[_0xf6f5('0x36')]),_0x2fb31a);if(_0x1282ec['query'][_0xf6f5('0x3f')]){_0x532851[_0xf6f5('0x3d')]=_[_0xf6f5('0x40')](_0x532851[_0xf6f5('0x3d')],{'$or':_[_0xf6f5('0x2e')](_0x2fb31a,function(_0x2012d1){if(_0x2012d1[_0xf6f5('0x31')]!==_0xf6f5('0x41')){var _0x4381a5={};_0x4381a5[_0x2012d1[_0xf6f5('0x2b')]]={'$like':'%'+_0x1282ec[_0xf6f5('0x34')][_0xf6f5('0x3f')]+'%'};return _0x4381a5;}})});}_0x532851=_[_0xf6f5('0x40')]({},_0x532851,_0x1282ec[_0xf6f5('0x42')]);var _0x2a323a={'where':_0x532851[_0xf6f5('0x3d')]};return db[_0xf6f5('0x2f')][_0xf6f5('0x23')](_0x2a323a)[_0xf6f5('0x15')](function(_0x292934){_0x12bdf6['count']=_0x292934;if(_0x1282ec[_0xf6f5('0x34')][_0xf6f5('0x43')]){_0x532851['include']=[{'all':!![]}];}return db[_0xf6f5('0x2f')][_0xf6f5('0x44')](_0x532851);})[_0xf6f5('0x15')](function(_0x4c5036){_0x12bdf6[_0xf6f5('0x45')]=_0x4c5036;return _0x12bdf6;})['then'](respondWithFilteredResult(_0x20bd23,_0x532851))[_0xf6f5('0x1e')](handleError(_0x20bd23,null));};exports[_0xf6f5('0x46')]=function(_0x3a806a,_0x578c5d){var _0x41e7ba={'raw':!![],'where':{'id':_0x3a806a[_0xf6f5('0x47')]['id']}},_0x5845c7={};_0x5845c7[_0xf6f5('0x33')]=_[_0xf6f5('0x35')](db[_0xf6f5('0x2f')][_0xf6f5('0x48')]);_0x5845c7[_0xf6f5('0x34')]=_['keys'](_0x3a806a[_0xf6f5('0x34')]);_0x5845c7['filters']=_[_0xf6f5('0x37')](_0x5845c7[_0xf6f5('0x33')],_0x5845c7[_0xf6f5('0x34')]);_0x41e7ba[_0xf6f5('0x38')]=_[_0xf6f5('0x37')](_0x5845c7[_0xf6f5('0x33')],qs[_0xf6f5('0x39')](_0x3a806a['query'][_0xf6f5('0x39')]));_0x41e7ba[_0xf6f5('0x38')]=_0x41e7ba['attributes'][_0xf6f5('0x3a')]?_0x41e7ba['attributes']:_0x5845c7[_0xf6f5('0x33')];if(_0x3a806a[_0xf6f5('0x34')]['includeAll']){_0x41e7ba[_0xf6f5('0x49')]=[{'all':!![]}];}_0x41e7ba=_[_0xf6f5('0x40')]({},_0x41e7ba,_0x3a806a[_0xf6f5('0x42')]);return db[_0xf6f5('0x2f')][_0xf6f5('0x4a')](_0x41e7ba)[_0xf6f5('0x15')](handleEntityNotFound(_0x578c5d,null))[_0xf6f5('0x15')](respondWithResult(_0x578c5d,null))[_0xf6f5('0x1e')](handleError(_0x578c5d,null));};exports[_0xf6f5('0x27')]=function(_0x51e7f2,_0x288eb4){if(_0x51e7f2['body']['id']){delete _0x51e7f2['body']['id'];}return db[_0xf6f5('0x2f')]['find']({'where':{'id':_0x51e7f2[_0xf6f5('0x47')]['id']}})['then'](handleEntityNotFound(_0x288eb4,null))['then'](saveUpdates(_0x51e7f2[_0xf6f5('0x4b')],null))[_0xf6f5('0x15')](respondWithResult(_0x288eb4,null))[_0xf6f5('0x1e')](handleError(_0x288eb4,null));};exports[_0xf6f5('0x28')]=function(_0x19da56,_0x46621b){return db[_0xf6f5('0x2f')][_0xf6f5('0x4a')]({'where':{'id':_0x19da56[_0xf6f5('0x47')]['id']}})[_0xf6f5('0x15')](handleEntityNotFound(_0x46621b,null))[_0xf6f5('0x15')](removeEntity(_0x46621b,null))[_0xf6f5('0x1e')](handleError(_0x46621b,null));};exports[_0xf6f5('0x4c')]=function(_0x1b59dd,_0x49cb6f){return db[_0xf6f5('0x2f')]['describe']()['then'](respondWithResult(_0x49cb6f,null))[_0xf6f5('0x1e')](handleError(_0x49cb6f,null));};exports[_0xf6f5('0x4d')]=function(_0x282165,_0x1f110a){return db[_0xf6f5('0x2f')][_0xf6f5('0x4d')](_0x282165[_0xf6f5('0x4b')])[_0xf6f5('0x15')](function(_0x5eaad1){if(_0x5eaad1){if(_0x5eaad1[_0xf6f5('0x4e')]==='out'&&!_0x5eaad1[_0xf6f5('0x4f')]){var _0x3a49e4,_0x51a1ba,_0x8c9356;if(_0x282165[_0xf6f5('0x4b')]['to']){_0x51a1ba=_0x282165[_0xf6f5('0x4b')]['to'][_0xf6f5('0x50')](',')[0x0];}return db['MailAccount'][_0xf6f5('0x51')]({'where':{'id':_0x5eaad1[_0xf6f5('0x52')]},'include':[{'model':db[_0xf6f5('0x53')],'as':'List','include':[{'model':db[_0xf6f5('0x54')],'as':'Contacts','where':{'email':_0x51a1ba},'limit':0x1,'order':[[_0xf6f5('0x55'),'DESC']]}]},{'model':db[_0xf6f5('0x56')],'as':_0xf6f5('0x57'),'raw':!![],'include':[{'model':db[_0xf6f5('0x58')],'as':_0xf6f5('0x58'),'raw':!![]}]}]})[_0xf6f5('0x15')](function(_0x16731b){_0x3a49e4=_0x16731b;if(!_0x3a49e4||!_0x3a49e4['Smtp'])return;var _0x187961=_0x3a49e4[_0xf6f5('0x59')]();if(_0x282165['body'][_0xf6f5('0x5a')]&&_0x282165[_0xf6f5('0x4b')]['attachments']['length']){for(var _0x4853b4=0x0;_0x4853b4<_0x282165[_0xf6f5('0x4b')]['attachments']['length'];_0x4853b4+=0x1){_0x282165[_0xf6f5('0x4b')][_0xf6f5('0x5a')][_0x4853b4]={'filename':_0x282165[_0xf6f5('0x4b')]['attachments'][_0x4853b4]['name'],'path':path[_0xf6f5('0x5b')](config[_0xf6f5('0x5c')],_0xf6f5('0x5d'),_0x282165[_0xf6f5('0x4b')][_0xf6f5('0x5a')][_0x4853b4][_0xf6f5('0x5e')])};}}_0x8c9356={'account':_0x187961,'message':_0x282165[_0xf6f5('0x4b')]};return;})[_0xf6f5('0x15')](function(){if(_0x3a49e4[_0xf6f5('0x5f')]){if(_0x3a49e4[_0xf6f5('0x5f')]['Contacts'][_0xf6f5('0x3a')]){return _0x3a49e4['List'][_0xf6f5('0x60')][0x0];}else{return db[_0xf6f5('0x54')]['create'](_['defaults'](_0x282165[_0xf6f5('0x4b')],{'firstName':_0x282165['body']['to'],'email':_0x282165[_0xf6f5('0x4b')]['to'],'phone':_0x282165['body']['to'],'ListId':_0x3a49e4[_0xf6f5('0x61')]}));}}else{throw new Error(_0xf6f5('0x62'));}})[_0xf6f5('0x15')](function(){if(_0x8c9356){return respondWithRpcPromise(_0xf6f5('0x63'),_0xf6f5('0x64'),_0x8c9356,client9003)['then'](function(_0x3cf39c){return _0x5eaad1['update']({'read':!![],'messageId':_0x3cf39c[_0xf6f5('0x65')],'sentAt':moment()['format'](_0xf6f5('0x66'))});})[_0xf6f5('0x1e')](function(_0x5e9791){logger[_0xf6f5('0x1a')]('%s',JSON[_0xf6f5('0x19')](_0x5e9791));return _0x5eaad1;});}return _0x5eaad1;});}return _0x5eaad1;}})['then'](respondWithResult(_0x1f110a,0xc9))[_0xf6f5('0x1e')](handleError(_0x1f110a,null));};exports[_0xf6f5('0x67')]=function(_0x5e9743,_0x2fa2b8){var _0x377c13={'agent':{},'channel':_0xf6f5('0x68')};if(_0x5e9743[_0xf6f5('0x4b')]['id']){delete _0x5e9743[_0xf6f5('0x4b')]['id'];}_0x5e9743[_0xf6f5('0x4b')]['read']=!![];_0x5e9743[_0xf6f5('0x4b')][_0xf6f5('0x69')]=moment()[_0xf6f5('0x6a')](_0xf6f5('0x66'));_0x5e9743['body']['UserId']=_0x5e9743[_0xf6f5('0x4b')][_0xf6f5('0x6b')]||_0x5e9743['user']['id'];_0x377c13[_0xf6f5('0x6c')]['id']=_0x5e9743[_0xf6f5('0x4b')][_0xf6f5('0x6b')];return db[_0xf6f5('0x2f')][_0xf6f5('0x4a')]({'where':{'id':_0x5e9743[_0xf6f5('0x47')]['id'],'UserId':null}})[_0xf6f5('0x15')](handleEntityNotFound(_0x2fa2b8,null))[_0xf6f5('0x15')](saveUpdates(_0x5e9743[_0xf6f5('0x4b')],null))['then'](function(_0x4f0513){if(_0x4f0513){_0x377c13['message']=_0x4f0513['get']({'plain':!![]});return db['MailInteraction'][_0xf6f5('0x4a')]({'where':{'id':_0x4f0513['MailInteractionId']}});}return null;})[_0xf6f5('0x15')](handleEntityNotFound(_0x2fa2b8,null))[_0xf6f5('0x15')](function(_0x2999d2){if(_0x2999d2){return _0x2999d2[_0xf6f5('0x27')]({'UserId':_0x5e9743['body'][_0xf6f5('0x6b')],'read1stAt':_[_0xf6f5('0x6d')](_0x2999d2[_0xf6f5('0x6e')])?moment()[_0xf6f5('0x6a')](_0xf6f5('0x66')):undefined});}return null;})[_0xf6f5('0x15')](function(_0x5da973){if(_0x5da973){_0x377c13[_0xf6f5('0x6f')]=_0x5da973[_0xf6f5('0x70')]({'plain':!![]});interaction_log[_0xf6f5('0x16')](_0xf6f5('0x71'),_0x5e9743[_0xf6f5('0x72')]['id'],_0x5e9743[_0xf6f5('0x72')]['name'],_0x5e9743[_0xf6f5('0x72')][_0xf6f5('0x73')],_0x377c13[_0xf6f5('0x6f')]['id'],_0x5e9743[_0xf6f5('0x4b')]?JSON['stringify'](_0x5e9743[_0xf6f5('0x4b')]):_0xf6f5('0x74'));return respondWithRpcPromise(_0xf6f5('0x75'),_0xf6f5('0x76'),_0x377c13);}return null;})[_0xf6f5('0x15')](function(_0x3c42ba){var _0x4a77af='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x3c42ba[_0xf6f5('0x1c')][_0xf6f5('0x77')];return db['sequelize']['query'](_0x4a77af,{'type':db[_0xf6f5('0x78')]['QueryTypes'][_0xf6f5('0x79')],'raw':!![]})[_0xf6f5('0x15')](function(_0x405c85){return _0x405c85;});})[_0xf6f5('0x15')](function(_0x308364){if(_0x308364){_0x377c13[_0xf6f5('0x1c')]['contact']=_0x308364[0x0];if(!_0x5e9743[_0xf6f5('0x4b')][_0xf6f5('0x6b')])return;return db[_0xf6f5('0x7a')]['find']({'where':{'id':_0x5e9743[_0xf6f5('0x4b')][_0xf6f5('0x6b')],'role':_0xf6f5('0x6c')},'attributes':['id',_0xf6f5('0x2b'),_0xf6f5('0x7b'),_0xf6f5('0x7c'),_0xf6f5('0x7d')],'raw':!![]});}return null;})[_0xf6f5('0x15')](function(_0x5b898c){if(!_0x5b898c)return null;_0x377c13[_0xf6f5('0x1c')]['agent']=_0x5b898c;return _0x377c13;})[_0xf6f5('0x15')](function(_0x1ed6ca){if(_0x1ed6ca){if(_0x5e9743[_0xf6f5('0x4b')][_0xf6f5('0x7e')]){_0x377c13[_0xf6f5('0x1c')][_0xf6f5('0x7f')]=util[_0xf6f5('0x6a')]('SIP/%s',_0x5e9743[_0xf6f5('0x72')]['name']);_0x377c13[_0xf6f5('0x1c')]['channel']=_0x377c13[_0xf6f5('0x80')];_0x377c13[_0xf6f5('0x1c')][_0xf6f5('0x81')]=_0x377c13['channel'];_0x377c13['message'][_0xf6f5('0x82')]=_0xf6f5('0x67');_0x377c13[_0xf6f5('0x1c')][_0xf6f5('0x4b')]=htmlToText[_0xf6f5('0x83')](_0x377c13[_0xf6f5('0x1c')][_0xf6f5('0x4b')]);return respondWithRpcPromise('EventManager',_0xf6f5('0x84'),{'event':_0xf6f5('0x85'),'message':_0x377c13[_0xf6f5('0x1c')]},client9002)[_0xf6f5('0x15')](function(){return _0x377c13;});}return _0x377c13;}return null;})[_0xf6f5('0x15')](respondWithResult(_0x2fa2b8,null))[_0xf6f5('0x1e')](handleError(_0x2fa2b8,null));};exports['reject']=function(_0x1bbb98,_0x12acc4){var _0x512c5b={'agent':{},'channel':'mail'};if(_0x1bbb98[_0xf6f5('0x4b')]['id']){delete _0x1bbb98['body']['id'];}_0x1bbb98[_0xf6f5('0x4b')]['UserId']=_0x1bbb98[_0xf6f5('0x4b')]['UserId']||_0x1bbb98['user']['id'];_0x512c5b[_0xf6f5('0x6c')]['id']=_0x1bbb98['body'][_0xf6f5('0x6b')];return db[_0xf6f5('0x2f')]['find']({'where':{'id':_0x1bbb98['params']['id'],'UserId':null}})[_0xf6f5('0x15')](handleEntityNotFound(_0x12acc4,null))[_0xf6f5('0x15')](function(_0x4673fc){if(_0x4673fc){_0x512c5b[_0xf6f5('0x1c')]=_0x4673fc[_0xf6f5('0x70')]({'plain':!![]});return db[_0xf6f5('0x86')][_0xf6f5('0x4a')]({'where':{'id':_0x4673fc['MailInteractionId']}});}return null;})[_0xf6f5('0x15')](handleEntityNotFound(_0x12acc4,null))[_0xf6f5('0x15')](function(_0x4a8c4b){if(_0x4a8c4b){_0x512c5b[_0xf6f5('0x6f')]=_0x4a8c4b['get']({'plain':!![]});interaction_log[_0xf6f5('0x16')](_0xf6f5('0x87'),_0x1bbb98[_0xf6f5('0x72')]['id'],_0x1bbb98[_0xf6f5('0x72')][_0xf6f5('0x2b')],_0x1bbb98[_0xf6f5('0x72')][_0xf6f5('0x73')],_0x512c5b['interaction']['id'],_0x1bbb98[_0xf6f5('0x4b')]?JSON[_0xf6f5('0x19')](_0x1bbb98[_0xf6f5('0x4b')]):'null');return respondWithRpcPromise(_0xf6f5('0x88'),_0xf6f5('0x89'),_0x512c5b);}return null;})['then'](function(_0x227a6f){var _0x3218c2=_0xf6f5('0x8a')+_0x227a6f[_0xf6f5('0x1c')][_0xf6f5('0x77')];return db[_0xf6f5('0x8b')][_0xf6f5('0x34')](_0x3218c2,{'type':db['Sequelize'][_0xf6f5('0x8c')][_0xf6f5('0x79')],'raw':!![]})[_0xf6f5('0x15')](function(_0x474dcb){return _0x474dcb;});})['then'](function(_0x551c42){if(_0x551c42){_0x512c5b['message'][_0xf6f5('0x8d')]=_0x551c42[0x0];if(!_0x1bbb98['body'][_0xf6f5('0x6b')])return;return db[_0xf6f5('0x7a')][_0xf6f5('0x4a')]({'where':{'id':_0x1bbb98[_0xf6f5('0x4b')][_0xf6f5('0x6b')],'role':_0xf6f5('0x6c')},'attributes':['id',_0xf6f5('0x2b'),'fullname',_0xf6f5('0x7c'),_0xf6f5('0x7d')],'raw':!![]});}return null;})[_0xf6f5('0x15')](function(_0x47b628){if(!_0x47b628)return null;_0x512c5b[_0xf6f5('0x1c')][_0xf6f5('0x6c')]=_0x47b628;return _0x512c5b;})['then'](function(_0x171b11){if(_0x171b11){_0x171b11[_0xf6f5('0x1c')][_0xf6f5('0x7f')]=util[_0xf6f5('0x6a')](_0xf6f5('0x8e'),_0x1bbb98[_0xf6f5('0x72')]['name']);_0x171b11[_0xf6f5('0x1c')][_0xf6f5('0x80')]=_0x512c5b[_0xf6f5('0x80')];_0x171b11[_0xf6f5('0x1c')][_0xf6f5('0x81')]=_0x512c5b['channel'];_0x171b11['message'][_0xf6f5('0x82')]=_0xf6f5('0x8f');_0x171b11[_0xf6f5('0x1c')][_0xf6f5('0x4b')]=htmlToText['fromString'](_0x512c5b['message']['body']);respondWithRpcPromise(_0xf6f5('0x84'),_0xf6f5('0x84'),{'event':_0xf6f5('0x90'),'message':_0x171b11[_0xf6f5('0x1c')]},client9002);return _0x512c5b;}return null;})['then'](respondWithResult(_0x12acc4,null))[_0xf6f5('0x1e')](handleError(_0x12acc4,null));};exports[_0xf6f5('0x91')]=function(_0x55654b,_0x1131ff){var _0x819147=moment()[_0xf6f5('0x92')]()[_0xf6f5('0x93')]();var _0x5ca623=path[_0xf6f5('0x5b')](config[_0xf6f5('0x5c')],_0xf6f5('0x94'),_0xf6f5('0x95'),_0xf6f5('0x96'));var _0x40d344=path['join'](config[_0xf6f5('0x5c')],_0xf6f5('0x94'),_0xf6f5('0x95'),_0xf6f5('0x5a'));var _0x1c197d=util[_0xf6f5('0x6a')](_0xf6f5('0x97'),_0x819147);return db['MailMessage'][_0xf6f5('0x4a')]({'where':{'id':_0x55654b[_0xf6f5('0x47')]['id']},'attributes':['id','body',_0xf6f5('0x98'),'to','cc',_0xf6f5('0x99'),_0xf6f5('0x9a'),_0xf6f5('0x9b')],'include':_0x55654b[_0xf6f5('0x34')][_0xf6f5('0x5a')]?[{'model':db['Attachment'],'as':_0xf6f5('0x9c')}]:undefined})['then'](handleEntityNotFound(_0x1131ff,null))['then'](function(_0x3cd256){if(_0x3cd256){var _0x552b97=_0x3cd256;var _0x306bab={'from':_0x552b97[_0xf6f5('0x98')],'to':_0x552b97['to'],'subject':_0x552b97[_0xf6f5('0x9a')],'html':htmlEntities['decode'](_0x552b97[_0xf6f5('0x4b')]),'headers':{'Date':moment(_0x552b97[_0xf6f5('0x9b')])['format'](_0xf6f5('0x9d'))},'attachments':[]};if(_0x3cd256['cc']){_0x306bab[_0xf6f5('0x9e')]['Cc']=_0x3cd256['cc'];}if(_0x3cd256['bcc']){_0x306bab[_0xf6f5('0x9e')][_0xf6f5('0x9f')]=_0x3cd256[_0xf6f5('0x99')];}return new BPromise(function(_0x5ef2d1,_0x366949){if(_0x3cd256[_0xf6f5('0x9c')]){for(var _0x2d1088=0x0;_0x2d1088<_0x3cd256[_0xf6f5('0x9c')]['length'];_0x2d1088++){var _0x48b63e=_0x3cd256[_0xf6f5('0x9c')][_0x2d1088];var _0xb59982=path['join'](_0x40d344,_0x48b63e[_0xf6f5('0x5e')]);if(fs[_0xf6f5('0xa0')](_0xb59982)){_0x306bab[_0xf6f5('0x5a')][_0xf6f5('0xa1')]({'name':_0x48b63e[_0xf6f5('0x2b')],'contentType':_0x48b63e[_0xf6f5('0x31')],'data':fs[_0xf6f5('0xa2')](_0xb59982)});}}}emlformat[_0xf6f5('0xa3')](_0x306bab,function(_0x436e35,_0x34fafb){if(_0x436e35)return _0x366949(_0x436e35);fs[_0xf6f5('0xa4')](path[_0xf6f5('0x5b')](_0x5ca623,_0x1c197d),_0x34fafb);return _0x5ef2d1(_0x34fafb);});});}})['then'](function(_0x4fd545){if(_0x4fd545){return _0x1131ff[_0xf6f5('0x91')](path[_0xf6f5('0x5b')](_0x5ca623,_0x1c197d),_0x1c197d,function(_0x55b36e){if(!_0x55b36e)fs['unlinkSync'](path[_0xf6f5('0x5b')](_0x5ca623,_0x1c197d));});}})[_0xf6f5('0x1e')](handleError(_0x1131ff,null));};
\ No newline at end of file