Built motion from commit ffdca78c.|2.6.24
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 7a24b8f..14c333a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb1ee=['request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','error','message','result','catch','sendStatus','status','end','json','count','offset','set','Content-Range','save','destroy','stack','name','send','index','map','rawAttributes','type','key','model','query','keys','filters','intersection','attributes','fields','nolimit','limit','order','sort','pick','merge','filter','options','where','MailMessage','includeAll','include','findAll','rows','show','length','update','body','find','describe','create','out','secret','split','MailAccount','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','isNil','service','host','port','secure','authentication','auth','user','pass','attachments','join','root','basename','List','ListId','List\x20not\x20found','sendMail','messageId','format','stringify','mail-interactions','accept','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','params','Contact','MailInteraction','MailInteractionId','read1stAt','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','interaction','null','acceptMessage','interface','channel','event','EventManager','acceptmessage','../../config/logger','reject','mail','agent','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','SIP/%s','rejectmessage','unix','toString','server','files','tmp','message-%s.eml','from','bcc','createdAt','Attachments','subject','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','build','writeFileSync','download','err','unlinkSync','html-pdf','rimraf','zip-dir','fast-json-patch','request-promise','moment','mustache','path','sox','to-csv','ejs','lodash','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/utils','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./mailMessage.socket','register','jayson/promise','client','test','Sequelize','ValidationError','then','info','MailMessage,\x20%s,\x20%s'];(function(_0x401d08,_0x3afbb4){var _0x3a7297=function(_0x2f83a9){while(--_0x2f83a9){_0x401d08['push'](_0x401d08['shift']());}};_0x3a7297(++_0x3afbb4);}(_0xb1ee,0x12a));var _0xeb1e=function(_0x70fd53,_0x2a95a6){_0x70fd53=_0x70fd53-0x0;var _0x4b71c5=_0xb1ee[_0x70fd53];return _0x4b71c5;};'use strict';var pdf=require(_0xeb1e('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xeb1e('0x1'));var zipdir=require(_0xeb1e('0x2'));var jsonpatch=require(_0xeb1e('0x3'));var rp=require(_0xeb1e('0x4'));var moment=require(_0xeb1e('0x5'));var BPromise=require('bluebird');var Mustache=require(_0xeb1e('0x6'));var util=require('util');var path=require(_0xeb1e('0x7'));var sox=require(_0xeb1e('0x8'));var csv=require(_0xeb1e('0x9'));var ejs=require(_0xeb1e('0xa'));var fs=require('fs');var _=require(_0xeb1e('0xb'));var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xeb1e('0xc'));var deskjs=require(_0xeb1e('0xd'));var toCsv=require(_0xeb1e('0x9'));var querystring=require(_0xeb1e('0xe'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0xeb1e('0xf'));var qs=require(_0xeb1e('0x10'));var as=require(_0xeb1e('0x11'));var hardwareService=require(_0xeb1e('0x12'));var logger=require('../../config/logger')(_0xeb1e('0x13'));var utils=require(_0xeb1e('0x14'));var config=require(_0xeb1e('0x15'));var db=require(_0xeb1e('0x16'))['db'];config[_0xeb1e('0x17')]=_[_0xeb1e('0x18')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0xeb1e('0x19'))(new Redis(config[_0xeb1e('0x17')]));require(_0xeb1e('0x1a'))[_0xeb1e('0x1b')](socket);var jayson=require(_0xeb1e('0x1c'));var client=jayson[_0xeb1e('0x1d')]['http']({'port':0x232c});var client9003=jayson[_0xeb1e('0x1d')]['http']({'port':0x232b});var client9002=jayson['client']['http']({'port':0x232a});function checkPasswordPattern(_0x5f0aa0,_0x25f27c,_0x44f466){if(_0x44f466){var _0x27b033=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x27b033[_0xeb1e('0x1e')](_0x25f27c)){return _0x5f0aa0;}else{throw new db[(_0xeb1e('0x1f'))][(_0xeb1e('0x20'))]('The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.');}}else{return _0x5f0aa0;}}function respondWithRpcPromise(_0xffc8d,_0x3ed07f,_0x244f29,_0x261923){return new BPromise(function(_0x482966,_0x54d610){var _0x24291b=_0x261923||client;return _0x24291b['request'](_0xffc8d,_0x244f29)[_0xeb1e('0x21')](function(_0x243819){logger[_0xeb1e('0x22')](_0xeb1e('0x23'),_0x3ed07f,_0xeb1e('0x24'));logger[_0xeb1e('0x25')](_0xeb1e('0x26'),_0x3ed07f,_0xeb1e('0x24'),JSON['stringify'](_0x243819));if(_0x243819[_0xeb1e('0x27')]){if(_0x243819[_0xeb1e('0x27')]['code']===0x1f4){logger['error'](_0xeb1e('0x23'),_0x3ed07f,_0x243819[_0xeb1e('0x27')][_0xeb1e('0x28')]);return _0x54d610(_0x243819['error']['message']);}logger[_0xeb1e('0x27')]('MailMessage,\x20%s,\x20%s',_0x3ed07f,_0x243819[_0xeb1e('0x27')]['message']);return _0x482966(_0x243819[_0xeb1e('0x27')][_0xeb1e('0x28')]);}else{logger['info'](_0xeb1e('0x23'),_0x3ed07f,_0xeb1e('0x24'));_0x482966(_0x243819[_0xeb1e('0x29')]['message']);}})[_0xeb1e('0x2a')](function(_0x262644){logger[_0xeb1e('0x27')]('MailMessage,\x20%s,\x20%s',_0x3ed07f,_0x262644);_0x54d610(_0x262644);});});}function respondWithStatusCode(_0x4a7d5a,_0x1d63d7){_0x1d63d7=_0x1d63d7||0xcc;return function(_0x108c43){if(_0x108c43){return _0x4a7d5a[_0xeb1e('0x2b')](_0x1d63d7);}return _0x4a7d5a[_0xeb1e('0x2c')](_0x1d63d7)[_0xeb1e('0x2d')]();};}function respondWithResult(_0x2df837,_0x3a14e2){_0x3a14e2=_0x3a14e2||0xc8;return function(_0x2fad3b){if(_0x2fad3b){return _0x2df837['status'](_0x3a14e2)[_0xeb1e('0x2e')](_0x2fad3b);}};}function respondWithFilteredResult(_0x58f5bb,_0x18bba7){return function(_0x54fa7c){if(_0x54fa7c){var _0x32cb09=_0x54fa7c[_0xeb1e('0x2f')],_0x380755=_0x18bba7[_0xeb1e('0x30')],_0x3d8318=_0x18bba7[_0xeb1e('0x30')]+_0x18bba7['limit'],_0x339453;if(_0x3d8318>=_0x32cb09){_0x3d8318=_0x32cb09;_0x339453=0xc8;}else{_0x339453=0xce;}_0x58f5bb[_0xeb1e('0x2c')](_0x339453);return _0x58f5bb[_0xeb1e('0x31')](_0xeb1e('0x32'),_0x380755+'-'+_0x3d8318+'/'+_0x32cb09)[_0xeb1e('0x2e')](_0x54fa7c);}return null;};}function patchUpdates(_0x5ae8dd){return function(_0x15f2ee){try{jsonpatch['apply'](_0x15f2ee,_0x5ae8dd,!![]);}catch(_0x4b5cd8){return BPromise['reject'](_0x4b5cd8);}return _0x15f2ee[_0xeb1e('0x33')]();};}function saveUpdates(_0x17ac60,_0x466488){return function(_0x26bbc0){if(_0x26bbc0){return _0x26bbc0['update'](_0x17ac60)[_0xeb1e('0x21')](function(_0xe6cb50){return _0xe6cb50;});}return null;};}function removeEntity(_0x41a207,_0x4bd03f){return function(_0x4f3196){if(_0x4f3196){return _0x4f3196[_0xeb1e('0x34')]()[_0xeb1e('0x21')](function(){_0x41a207[_0xeb1e('0x2c')](0xcc)[_0xeb1e('0x2d')]();});}};}function handleEntityNotFound(_0x4114c7,_0x153299){return function(_0x18ca88){if(!_0x18ca88){_0x4114c7['sendStatus'](0x194);}return _0x18ca88;};}function handleError(_0x39ac99,_0x35db0c){_0x35db0c=_0x35db0c||0x1f4;return function(_0x124229){logger[_0xeb1e('0x27')](_0x124229[_0xeb1e('0x35')]);if(_0x124229[_0xeb1e('0x36')]){delete _0x124229[_0xeb1e('0x36')];}_0x39ac99[_0xeb1e('0x2c')](_0x35db0c)[_0xeb1e('0x37')](_0x124229);};}exports[_0xeb1e('0x38')]=function(_0xed135,_0x4c1c4c){var _0x1ba81c={},_0x56f955={},_0x5a8bf3={'count':0x0,'rows':[]};var _0x56d5e7=_[_0xeb1e('0x39')](db['MailMessage'][_0xeb1e('0x3a')],function(_0x3b0173){return{'name':_0x3b0173['fieldName'],'type':_0x3b0173[_0xeb1e('0x3b')][_0xeb1e('0x3c')]};});_0x56f955[_0xeb1e('0x3d')]=_[_0xeb1e('0x39')](_0x56d5e7,_0xeb1e('0x36'));_0x56f955[_0xeb1e('0x3e')]=_[_0xeb1e('0x3f')](_0xed135[_0xeb1e('0x3e')]);_0x56f955[_0xeb1e('0x40')]=_[_0xeb1e('0x41')](_0x56f955['model'],_0x56f955[_0xeb1e('0x3e')]);_0x1ba81c[_0xeb1e('0x42')]=_[_0xeb1e('0x41')](_0x56f955['model'],qs['fields'](_0xed135['query'][_0xeb1e('0x43')]));_0x1ba81c[_0xeb1e('0x42')]=_0x1ba81c['attributes']['length']?_0x1ba81c[_0xeb1e('0x42')]:_0x56f955['model'];if(!_0xed135[_0xeb1e('0x3e')]['hasOwnProperty'](_0xeb1e('0x44'))){_0x1ba81c['limit']=qs[_0xeb1e('0x45')](_0xed135[_0xeb1e('0x3e')][_0xeb1e('0x45')]);_0x1ba81c['offset']=qs['offset'](_0xed135['query'][_0xeb1e('0x30')]);}_0x1ba81c[_0xeb1e('0x46')]=qs[_0xeb1e('0x47')](_0xed135['query'][_0xeb1e('0x47')]);_0x1ba81c['where']=qs[_0xeb1e('0x40')](_[_0xeb1e('0x48')](_0xed135['query'],_0x56f955[_0xeb1e('0x40')]));if(_0xed135[_0xeb1e('0x3e')]['filter']){_0x1ba81c['where']=_[_0xeb1e('0x49')](_0x1ba81c['where'],{'$or':_[_0xeb1e('0x39')](_0x56d5e7,function(_0xe5b92d){if(_0xe5b92d[_0xeb1e('0x3b')]!=='VIRTUAL'){var _0x35e510={};_0x35e510[_0xe5b92d['name']]={'$like':'%'+_0xed135[_0xeb1e('0x3e')][_0xeb1e('0x4a')]+'%'};return _0x35e510;}})});}_0x1ba81c=_[_0xeb1e('0x49')]({},_0x1ba81c,_0xed135[_0xeb1e('0x4b')]);var _0x26996b={'where':_0x1ba81c[_0xeb1e('0x4c')]};return db[_0xeb1e('0x4d')]['count'](_0x26996b)[_0xeb1e('0x21')](function(_0x5e2a7e){_0x5a8bf3[_0xeb1e('0x2f')]=_0x5e2a7e;if(_0xed135[_0xeb1e('0x3e')][_0xeb1e('0x4e')]){_0x1ba81c[_0xeb1e('0x4f')]=[{'all':!![]}];}return db[_0xeb1e('0x4d')][_0xeb1e('0x50')](_0x1ba81c);})['then'](function(_0x1c6ecb){_0x5a8bf3[_0xeb1e('0x51')]=_0x1c6ecb;return _0x5a8bf3;})[_0xeb1e('0x21')](respondWithFilteredResult(_0x4c1c4c,_0x1ba81c))['catch'](handleError(_0x4c1c4c,null));};exports[_0xeb1e('0x52')]=function(_0x7c7283,_0x15cc33){var _0x3b896a={'raw':!![],'where':{'id':_0x7c7283['params']['id']}},_0x1fab2a={};_0x1fab2a[_0xeb1e('0x3d')]=_[_0xeb1e('0x3f')](db[_0xeb1e('0x4d')][_0xeb1e('0x3a')]);_0x1fab2a[_0xeb1e('0x3e')]=_[_0xeb1e('0x3f')](_0x7c7283[_0xeb1e('0x3e')]);_0x1fab2a[_0xeb1e('0x40')]=_[_0xeb1e('0x41')](_0x1fab2a['model'],_0x1fab2a[_0xeb1e('0x3e')]);_0x3b896a[_0xeb1e('0x42')]=_[_0xeb1e('0x41')](_0x1fab2a[_0xeb1e('0x3d')],qs[_0xeb1e('0x43')](_0x7c7283[_0xeb1e('0x3e')]['fields']));_0x3b896a[_0xeb1e('0x42')]=_0x3b896a[_0xeb1e('0x42')][_0xeb1e('0x53')]?_0x3b896a[_0xeb1e('0x42')]:_0x1fab2a['model'];if(_0x7c7283['query'][_0xeb1e('0x4e')]){_0x3b896a['include']=[{'all':!![]}];}_0x3b896a=_[_0xeb1e('0x49')]({},_0x3b896a,_0x7c7283[_0xeb1e('0x4b')]);return db['MailMessage']['find'](_0x3b896a)[_0xeb1e('0x21')](handleEntityNotFound(_0x15cc33,null))[_0xeb1e('0x21')](respondWithResult(_0x15cc33,null))[_0xeb1e('0x2a')](handleError(_0x15cc33,null));};exports[_0xeb1e('0x54')]=function(_0x46bd93,_0x1799f2){if(_0x46bd93[_0xeb1e('0x55')]['id']){delete _0x46bd93['body']['id'];}return db[_0xeb1e('0x4d')][_0xeb1e('0x56')]({'where':{'id':_0x46bd93['params']['id']}})['then'](handleEntityNotFound(_0x1799f2,null))[_0xeb1e('0x21')](saveUpdates(_0x46bd93[_0xeb1e('0x55')],null))[_0xeb1e('0x21')](respondWithResult(_0x1799f2,null))['catch'](handleError(_0x1799f2,null));};exports[_0xeb1e('0x34')]=function(_0x6468a0,_0x32b849){return db[_0xeb1e('0x4d')][_0xeb1e('0x56')]({'where':{'id':_0x6468a0['params']['id']}})[_0xeb1e('0x21')](handleEntityNotFound(_0x32b849,null))[_0xeb1e('0x21')](removeEntity(_0x32b849,null))['catch'](handleError(_0x32b849,null));};exports[_0xeb1e('0x57')]=function(_0x3ca24a,_0x288e0f){return db[_0xeb1e('0x4d')][_0xeb1e('0x57')]()['then'](respondWithResult(_0x288e0f,null))['catch'](handleError(_0x288e0f,null));};exports[_0xeb1e('0x58')]=function(_0x420310,_0x2e84f0){return db['MailMessage'][_0xeb1e('0x58')](_0x420310['body'])[_0xeb1e('0x21')](function(_0x2d58da){if(_0x2d58da){if(_0x2d58da['direction']===_0xeb1e('0x59')&&!_0x2d58da[_0xeb1e('0x5a')]){var _0x201907,_0x1773e0,_0x174c67;if(_0x420310['body']['to']){_0x1773e0=_0x420310[_0xeb1e('0x55')]['to'][_0xeb1e('0x5b')](',')[0x0];}return db[_0xeb1e('0x5c')]['findOne']({'where':{'id':_0x2d58da[_0xeb1e('0x5d')]},'include':[{'model':db[_0xeb1e('0x5e')],'as':'List','include':[{'model':db[_0xeb1e('0x5f')],'as':_0xeb1e('0x60'),'where':{'email':_0x1773e0},'limit':0x1,'order':[[_0xeb1e('0x61'),_0xeb1e('0x62')]]}]},{'model':db[_0xeb1e('0x63')],'as':_0xeb1e('0x64'),'raw':!![]}]})[_0xeb1e('0x21')](function(_0x46bc93){_0x201907=_0x46bc93;if(_0x201907&&_0x201907[_0xeb1e('0x64')]){var _0x57ab1c={'tls':{'rejectUnauthorized':![]}};if(_[_0xeb1e('0x65')](_0x201907[_0xeb1e('0x64')][_0xeb1e('0x66')])){_0x57ab1c[_0xeb1e('0x67')]=_0x201907[_0xeb1e('0x64')][_0xeb1e('0x67')];_0x57ab1c[_0xeb1e('0x68')]=_0x201907[_0xeb1e('0x64')][_0xeb1e('0x68')];_0x57ab1c[_0xeb1e('0x69')]=_0x201907['Smtp'][_0xeb1e('0x69')];if(_0x201907[_0xeb1e('0x64')][_0xeb1e('0x6a')]){_0x57ab1c[_0xeb1e('0x6b')]={'user':_0x201907[_0xeb1e('0x64')][_0xeb1e('0x6c')],'pass':_0x201907[_0xeb1e('0x64')][_0xeb1e('0x6d')]};}}else{_0x57ab1c[_0xeb1e('0x66')]=_0x201907[_0xeb1e('0x64')]['service'];_0x57ab1c[_0xeb1e('0x6b')]={'user':_0x201907[_0xeb1e('0x64')]['user'],'pass':_0x201907[_0xeb1e('0x64')][_0xeb1e('0x6d')]};_0x57ab1c['secure']=_0x201907[_0xeb1e('0x64')]['secure'];}if(_0x420310[_0xeb1e('0x55')][_0xeb1e('0x6e')]&&_0x420310[_0xeb1e('0x55')]['attachments'][_0xeb1e('0x53')]){for(var _0x6d4b7e=0x0;_0x6d4b7e<_0x420310['body']['attachments'][_0xeb1e('0x53')];_0x6d4b7e+=0x1){_0x420310[_0xeb1e('0x55')][_0xeb1e('0x6e')][_0x6d4b7e]={'filename':_0x420310[_0xeb1e('0x55')][_0xeb1e('0x6e')][_0x6d4b7e]['name'],'path':path[_0xeb1e('0x6f')](config[_0xeb1e('0x70')],'server/files/attachments',_0x420310[_0xeb1e('0x55')][_0xeb1e('0x6e')][_0x6d4b7e][_0xeb1e('0x71')])};}}_0x174c67={'account':_0x57ab1c,'message':_0x420310['body']};return;}})['then'](function(){if(_0x201907[_0xeb1e('0x72')]){if(_0x201907['List'][_0xeb1e('0x60')]['length']){return _0x201907[_0xeb1e('0x72')][_0xeb1e('0x60')][0x0];}else{return db[_0xeb1e('0x5f')][_0xeb1e('0x58')](_[_0xeb1e('0x18')](_0x420310[_0xeb1e('0x55')],{'firstName':_0x420310['body']['to'],'email':_0x420310[_0xeb1e('0x55')]['to'],'phone':_0x420310[_0xeb1e('0x55')]['to'],'ListId':_0x201907[_0xeb1e('0x73')]}));}}else{throw new Error(_0xeb1e('0x74'));}})[_0xeb1e('0x21')](function(){if(_0x174c67){return respondWithRpcPromise('SendMail',_0xeb1e('0x75'),_0x174c67,client9003)['then'](function(_0x50b91b){return _0x2d58da['update']({'read':!![],'messageId':_0x50b91b[_0xeb1e('0x76')],'sentAt':moment()[_0xeb1e('0x77')]('YYYY-MM-DD\x20HH:mm:ss')});})[_0xeb1e('0x2a')](function(_0x1f079f){logger[_0xeb1e('0x27')]('%s',JSON[_0xeb1e('0x78')](_0x1f079f));return _0x2d58da;});}return _0x2d58da;});}return _0x2d58da;}})['then'](respondWithResult(_0x2e84f0,0xc9))[_0xeb1e('0x2a')](handleError(_0x2e84f0,null));};var interaction_log=require('../../config/logger')(_0xeb1e('0x79'));exports[_0xeb1e('0x7a')]=function(_0x59b548,_0x3577e2,_0xeafdbf){var _0x144dfd={'channel':'mail'};if(_0x59b548['body']['id']){delete _0x59b548['body']['id'];}_0x59b548['body']['read']=!![];_0x59b548['body'][_0xeb1e('0x7b')]=moment()[_0xeb1e('0x77')](_0xeb1e('0x7c'));_0x59b548[_0xeb1e('0x55')][_0xeb1e('0x7d')]=_0x59b548['body']['UserId']||_0x59b548[_0xeb1e('0x6c')]['id'];return db[_0xeb1e('0x4d')][_0xeb1e('0x56')]({'where':{'id':_0x59b548[_0xeb1e('0x7e')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0xeb1e('0x7f')}]})[_0xeb1e('0x21')](handleEntityNotFound(_0x3577e2,null))[_0xeb1e('0x21')](saveUpdates(_0x59b548['body'],null))[_0xeb1e('0x21')](function(_0x440f34){if(_0x440f34){_0x144dfd[_0xeb1e('0x28')]=_0x440f34['get']({'plain':!![]});return db[_0xeb1e('0x80')][_0xeb1e('0x56')]({'where':{'id':_0x440f34[_0xeb1e('0x81')]}});}return null;})['then'](handleEntityNotFound(_0x3577e2,null))[_0xeb1e('0x21')](function(_0x3c9e6e){if(_0x3c9e6e){return _0x3c9e6e['update']({'UserId':_0x59b548[_0xeb1e('0x55')][_0xeb1e('0x7d')],'read1stAt':_[_0xeb1e('0x65')](_0x3c9e6e[_0xeb1e('0x82')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0xeb1e('0x21')](function(_0x290574){if(_0x290574){_0x144dfd['interaction']=_0x290574[_0xeb1e('0x83')]({'plain':!![]});interaction_log['info'](_0xeb1e('0x84'),_0x59b548[_0xeb1e('0x6c')]['id'],_0x59b548[_0xeb1e('0x6c')][_0xeb1e('0x36')],_0x59b548[_0xeb1e('0x6c')]['role'],_0x144dfd[_0xeb1e('0x85')]['id'],_0x59b548['body']?JSON['stringify'](_0x59b548[_0xeb1e('0x55')]):_0xeb1e('0x86'));return respondWithRpcPromise('AcceptMessage',_0xeb1e('0x87'),_0x144dfd);}return null;})[_0xeb1e('0x21')](function(_0x178faf){if(_0x178faf){if(_0x59b548[_0xeb1e('0x55')]['manual']){_0x144dfd['message'][_0xeb1e('0x88')]=util[_0xeb1e('0x77')]('SIP/%s',_0x59b548[_0xeb1e('0x6c')][_0xeb1e('0x36')]);_0x144dfd['message']['channel']=_0x144dfd[_0xeb1e('0x89')];_0x144dfd[_0xeb1e('0x28')][_0xeb1e('0x8a')]=_0xeb1e('0x7a');return respondWithRpcPromise(_0xeb1e('0x8b'),'EventManager',{'event':_0xeb1e('0x8c'),'message':_0x144dfd[_0xeb1e('0x28')]},client9002)['then'](function(){return _0x144dfd;});}return _0x144dfd;}return null;})[_0xeb1e('0x21')](respondWithResult(_0x3577e2,null))[_0xeb1e('0x2a')](handleError(_0x3577e2,null));};var interaction_log=require(_0xeb1e('0x8d'))(_0xeb1e('0x79'));exports[_0xeb1e('0x8e')]=function(_0x5269f,_0x329199,_0x5c08f3){var _0xf9e60f={'agent':{},'channel':_0xeb1e('0x8f')};if(_0x5269f[_0xeb1e('0x55')]['id']){delete _0x5269f['body']['id'];}_0x5269f[_0xeb1e('0x55')]['UserId']=_0x5269f[_0xeb1e('0x55')][_0xeb1e('0x7d')]||_0x5269f[_0xeb1e('0x6c')]['id'];_0xf9e60f[_0xeb1e('0x90')]['id']=_0x5269f[_0xeb1e('0x55')][_0xeb1e('0x7d')];return db[_0xeb1e('0x4d')]['find']({'where':{'id':_0x5269f[_0xeb1e('0x7e')]['id'],'UserId':null}})[_0xeb1e('0x21')](handleEntityNotFound(_0x329199,null))[_0xeb1e('0x21')](function(_0xbf3291){if(_0xbf3291){_0xf9e60f['message']=_0xbf3291[_0xeb1e('0x83')]({'plain':!![]});return db[_0xeb1e('0x80')][_0xeb1e('0x56')]({'where':{'id':_0xbf3291[_0xeb1e('0x81')]}});}return null;})[_0xeb1e('0x21')](handleEntityNotFound(_0x329199,null))['then'](function(_0x59519d){if(_0x59519d){_0xf9e60f[_0xeb1e('0x85')]=_0x59519d['get']({'plain':!![]});interaction_log[_0xeb1e('0x22')](_0xeb1e('0x91'),_0x5269f[_0xeb1e('0x6c')]['id'],_0x5269f[_0xeb1e('0x6c')][_0xeb1e('0x36')],_0x5269f[_0xeb1e('0x6c')][_0xeb1e('0x92')],_0xf9e60f[_0xeb1e('0x85')]['id'],_0x5269f[_0xeb1e('0x55')]?JSON[_0xeb1e('0x78')](_0x5269f[_0xeb1e('0x55')]):_0xeb1e('0x86'));return respondWithRpcPromise('RejectMessage','rejectMessage',_0xf9e60f);}return null;})[_0xeb1e('0x21')](function(_0x4b569c){if(_0x4b569c){_0x4b569c[_0xeb1e('0x28')][_0xeb1e('0x88')]=util['format'](_0xeb1e('0x93'),_0x5269f[_0xeb1e('0x6c')][_0xeb1e('0x36')]);_0x4b569c[_0xeb1e('0x28')][_0xeb1e('0x89')]=_0xf9e60f['channel'];_0x4b569c[_0xeb1e('0x28')][_0xeb1e('0x8a')]=_0xeb1e('0x8e');respondWithRpcPromise(_0xeb1e('0x8b'),_0xeb1e('0x8b'),{'event':_0xeb1e('0x94'),'message':_0x4b569c['message']},client9002);return _0xf9e60f;}return null;})[_0xeb1e('0x21')](respondWithResult(_0x329199,null))[_0xeb1e('0x2a')](handleError(_0x329199,null));};exports['download']=function(_0x484fff,_0x86663a){var _0x437eec=moment()[_0xeb1e('0x95')]()[_0xeb1e('0x96')]();var _0x1c5ca4=path[_0xeb1e('0x6f')](config['root'],_0xeb1e('0x97'),_0xeb1e('0x98'),_0xeb1e('0x99'));var _0x3a855c=path[_0xeb1e('0x6f')](config[_0xeb1e('0x70')],_0xeb1e('0x97'),_0xeb1e('0x98'),_0xeb1e('0x6e'));var _0x3cfca6=util[_0xeb1e('0x77')](_0xeb1e('0x9a'),_0x437eec);return db[_0xeb1e('0x4d')]['find']({'where':{'id':_0x484fff[_0xeb1e('0x7e')]['id']},'attributes':['id','body',_0xeb1e('0x9b'),'to','cc',_0xeb1e('0x9c'),'subject',_0xeb1e('0x9d')],'include':_0x484fff[_0xeb1e('0x3e')]['attachments']?[{'model':db['Attachment'],'as':_0xeb1e('0x9e')}]:undefined})['then'](handleEntityNotFound(_0x86663a,null))[_0xeb1e('0x21')](function(_0x38d928){if(_0x38d928){var _0x4483d8=_0x38d928;var _0x129844={'from':_0x4483d8['from'],'to':_0x4483d8['to'],'subject':_0x4483d8[_0xeb1e('0x9f')],'html':_0x4483d8[_0xeb1e('0x55')],'headers':{'Date':moment(_0x4483d8[_0xeb1e('0x9d')])[_0xeb1e('0x77')](_0xeb1e('0xa0'))},'attachments':[]};if(_0x38d928['cc']){_0x129844[_0xeb1e('0xa1')]['Cc']=_0x38d928['cc'];}if(_0x38d928[_0xeb1e('0x9c')]){_0x129844['headers']['Bcc']=_0x38d928[_0xeb1e('0x9c')];}return new BPromise(function(_0x485510,_0xf6ad97){if(_0x38d928[_0xeb1e('0x9e')]){for(var _0x2b3798=0x0;_0x2b3798<_0x38d928[_0xeb1e('0x9e')][_0xeb1e('0x53')];_0x2b3798++){var _0x53a4a4=_0x38d928[_0xeb1e('0x9e')][_0x2b3798];var _0x1e8dac=path[_0xeb1e('0x6f')](_0x3a855c,_0x53a4a4[_0xeb1e('0x71')]);if(fs['existsSync'](_0x1e8dac)){_0x129844['attachments']['push']({'name':_0x53a4a4[_0xeb1e('0x36')],'contentType':_0x53a4a4[_0xeb1e('0x3b')],'data':fs['readFileSync'](_0x1e8dac)});}}}emlformat[_0xeb1e('0xa2')](_0x129844,function(_0x407b04,_0x122b4e){if(_0x407b04)return _0xf6ad97(_0x407b04);fs[_0xeb1e('0xa3')](path[_0xeb1e('0x6f')](_0x1c5ca4,_0x3cfca6),_0x122b4e);return _0x485510(_0x122b4e);});});}})[_0xeb1e('0x21')](function(_0x4f46ae){if(_0x4f46ae){return _0x86663a[_0xeb1e('0xa4')](path[_0xeb1e('0x6f')](_0x1c5ca4,_0x3cfca6),_0x3cfca6,function(_0x7af403){if(_0x7af403){console['log'](_0xeb1e('0xa5'),_0x7af403);}else{fs[_0xeb1e('0xa6')](path[_0xeb1e('0x6f')](_0x1c5ca4,_0x3cfca6));}});}})[_0xeb1e('0x2a')](handleError(_0x86663a,null));};
\ No newline at end of file
+var _0x33fa=['decode','headers','bcc','Bcc','push','readFileSync','writeFileSync','download','unlinkSync','moment','util','path','../../components/parsers/qs','../../config/logger','api','mail-interactions','../../config/environment','redis','defaults','localhost','socket.io-emitter','html-entities','./mailMessage.socket','register','jayson/promise','http','client','request','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','json','offset','undefined','count','limit','set','Content-Range','then','destroy','end','sendStatus','stack','name','status','index','map','MailMessage','rawAttributes','fieldName','type','keys','query','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','pick','filters','filter','merge','VIRTUAL','options','includeAll','include','rows','catch','intersection','find','update','body','params','describe','create','direction','out','split','MailAccount','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','attachments','root','server/files/attachments','basename','List','ListId','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','read','readAt','UserId','user','agent','get','MailInteraction','MailInteractionId','isNil','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','User','email','internal','interface','SIP/%s','channel','motionChannel','event','fromString','EventManager','acceptmessage','reject','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','sequelize','contact','rejectmessage','unix','toString','join','server','files','from','subject','createdAt','Attachment','Attachments'];(function(_0x12dbf6,_0x2c381c){var _0x3adcc6=function(_0x24b23d){while(--_0x24b23d){_0x12dbf6['push'](_0x12dbf6['shift']());}};_0x3adcc6(++_0x2c381c);}(_0x33fa,0x1e9));var _0xa33f=function(_0x412dd8,_0x355780){_0x412dd8=_0x412dd8-0x0;var _0x47b96=_0x33fa[_0x412dd8];return _0x47b96;};'use strict';var emlformat=require('eml-format');var moment=require(_0xa33f('0x0'));var BPromise=require('bluebird');var util=require(_0xa33f('0x1'));var path=require(_0xa33f('0x2'));var fs=require('fs');var _=require('lodash');var Redis=require('ioredis');var htmlToText=require('html-to-text');var qs=require(_0xa33f('0x3'));var logger=require(_0xa33f('0x4'))(_0xa33f('0x5'));var interaction_log=require(_0xa33f('0x4'))(_0xa33f('0x6'));var config=require(_0xa33f('0x7'));var db=require('../../mysqldb')['db'];config[_0xa33f('0x8')]=_[_0xa33f('0x9')](config[_0xa33f('0x8')],{'host':_0xa33f('0xa'),'port':0x18eb});var socket=require(_0xa33f('0xb'))(new Redis(config[_0xa33f('0x8')]));var htmlEntities=require(_0xa33f('0xc'));require(_0xa33f('0xd'))[_0xa33f('0xe')](socket);var jayson=require(_0xa33f('0xf'));var client=jayson['client'][_0xa33f('0x10')]({'port':0x232c});var client9003=jayson[_0xa33f('0x11')]['http']({'port':0x232b});var client9002=jayson[_0xa33f('0x11')][_0xa33f('0x10')]({'port':0x232a});function respondWithRpcPromise(_0x2ba61b,_0x2a21c4,_0x29af5b,_0x3719c2){return new BPromise(function(_0x890766,_0x5bcd37){var _0x67a41a=_0x3719c2||client;return _0x67a41a[_0xa33f('0x12')](_0x2ba61b,_0x29af5b)['then'](function(_0x3d380a){logger[_0xa33f('0x13')](_0xa33f('0x14'),_0x2a21c4,_0xa33f('0x15'));logger[_0xa33f('0x16')](_0xa33f('0x17'),_0x2a21c4,_0xa33f('0x15'),JSON[_0xa33f('0x18')](_0x3d380a));if(_0x3d380a[_0xa33f('0x19')]){if(_0x3d380a[_0xa33f('0x19')][_0xa33f('0x1a')]===0x1f4){logger[_0xa33f('0x19')](_0xa33f('0x14'),_0x2a21c4,_0x3d380a['error']['message']);return _0x5bcd37(_0x3d380a[_0xa33f('0x19')]['message']);}logger[_0xa33f('0x19')]('MailMessage,\x20%s,\x20%s',_0x2a21c4,_0x3d380a[_0xa33f('0x19')][_0xa33f('0x1b')]);return _0x890766(_0x3d380a[_0xa33f('0x19')][_0xa33f('0x1b')]);}else{logger[_0xa33f('0x13')]('MailMessage,\x20%s,\x20%s',_0x2a21c4,'request\x20sent');_0x890766(_0x3d380a[_0xa33f('0x1c')][_0xa33f('0x1b')]);}})['catch'](function(_0x259d86){logger[_0xa33f('0x19')]('MailMessage,\x20%s,\x20%s',_0x2a21c4,_0x259d86);_0x5bcd37(_0x259d86);});});}function respondWithResult(_0x5d11cc,_0x625ce1){_0x625ce1=_0x625ce1||0xc8;return function(_0x233b2f){if(_0x233b2f){return _0x5d11cc['status'](_0x625ce1)[_0xa33f('0x1d')](_0x233b2f);}};}function respondWithFilteredResult(_0x2b08e3,_0x41ce4c){return function(_0x27ab12){if(_0x27ab12){var _0x31727b=typeof _0x41ce4c[_0xa33f('0x1e')]==='undefined'&&typeof _0x41ce4c['limit']===_0xa33f('0x1f');var _0x576f29=_0x27ab12[_0xa33f('0x20')];var _0x4dd6b8=_0x31727b?0x0:_0x41ce4c['offset'];var _0x50773b=_0x31727b?_0x27ab12['count']:_0x41ce4c['offset']+_0x41ce4c[_0xa33f('0x21')];var _0x381c38;if(_0x50773b>=_0x576f29){_0x50773b=_0x576f29;_0x381c38=0xc8;}else{_0x381c38=0xce;}_0x2b08e3['status'](_0x381c38);return _0x2b08e3[_0xa33f('0x22')](_0xa33f('0x23'),_0x4dd6b8+'-'+_0x50773b+'/'+_0x576f29)[_0xa33f('0x1d')](_0x27ab12);}return null;};}function saveUpdates(_0x5d295c){return function(_0x5e1f){if(_0x5e1f){return _0x5e1f['update'](_0x5d295c)[_0xa33f('0x24')](function(_0x1874fd){return _0x1874fd;});}return null;};}function removeEntity(_0x84a167){return function(_0x431e88){if(_0x431e88){return _0x431e88[_0xa33f('0x25')]()[_0xa33f('0x24')](function(){_0x84a167['status'](0xcc)[_0xa33f('0x26')]();});}};}function handleEntityNotFound(_0x2c03d7){return function(_0x172985){if(!_0x172985){_0x2c03d7[_0xa33f('0x27')](0x194);}return _0x172985;};}function handleError(_0x3a0e0a,_0x3606c0){_0x3606c0=_0x3606c0||0x1f4;return function(_0xb1f2db){logger[_0xa33f('0x19')](_0xb1f2db[_0xa33f('0x28')]);if(_0xb1f2db[_0xa33f('0x29')]){delete _0xb1f2db[_0xa33f('0x29')];}_0x3a0e0a[_0xa33f('0x2a')](_0x3606c0)['send'](_0xb1f2db);};}exports[_0xa33f('0x2b')]=function(_0xccb85d,_0x2f5e2e){var _0x38a9c7={},_0x53fcc7={},_0x1c6f2a={'count':0x0,'rows':[]};var _0x136256=_[_0xa33f('0x2c')](db[_0xa33f('0x2d')][_0xa33f('0x2e')],function(_0x1905dd){return{'name':_0x1905dd[_0xa33f('0x2f')],'type':_0x1905dd[_0xa33f('0x30')]['key']};});_0x53fcc7['model']=_[_0xa33f('0x2c')](_0x136256,'name');_0x53fcc7['query']=_[_0xa33f('0x31')](_0xccb85d[_0xa33f('0x32')]);_0x53fcc7['filters']=_['intersection'](_0x53fcc7[_0xa33f('0x33')],_0x53fcc7['query']);_0x38a9c7[_0xa33f('0x34')]=_['intersection'](_0x53fcc7[_0xa33f('0x33')],qs[_0xa33f('0x35')](_0xccb85d['query'][_0xa33f('0x35')]));_0x38a9c7[_0xa33f('0x34')]=_0x38a9c7[_0xa33f('0x34')][_0xa33f('0x36')]?_0x38a9c7[_0xa33f('0x34')]:_0x53fcc7[_0xa33f('0x33')];if(!_0xccb85d[_0xa33f('0x32')][_0xa33f('0x37')](_0xa33f('0x38'))){_0x38a9c7[_0xa33f('0x21')]=qs[_0xa33f('0x21')](_0xccb85d[_0xa33f('0x32')][_0xa33f('0x21')]);_0x38a9c7[_0xa33f('0x1e')]=qs['offset'](_0xccb85d[_0xa33f('0x32')][_0xa33f('0x1e')]);}_0x38a9c7[_0xa33f('0x39')]=qs['sort'](_0xccb85d[_0xa33f('0x32')][_0xa33f('0x3a')]);_0x38a9c7[_0xa33f('0x3b')]=qs['filters'](_[_0xa33f('0x3c')](_0xccb85d[_0xa33f('0x32')],_0x53fcc7[_0xa33f('0x3d')]),_0x136256);if(_0xccb85d[_0xa33f('0x32')][_0xa33f('0x3e')]){_0x38a9c7['where']=_[_0xa33f('0x3f')](_0x38a9c7[_0xa33f('0x3b')],{'$or':_[_0xa33f('0x2c')](_0x136256,function(_0x2d71cd){if(_0x2d71cd['type']!==_0xa33f('0x40')){var _0x37573f={};_0x37573f[_0x2d71cd[_0xa33f('0x29')]]={'$like':'%'+_0xccb85d[_0xa33f('0x32')][_0xa33f('0x3e')]+'%'};return _0x37573f;}})});}_0x38a9c7=_[_0xa33f('0x3f')]({},_0x38a9c7,_0xccb85d[_0xa33f('0x41')]);var _0x5b72f6={'where':_0x38a9c7[_0xa33f('0x3b')]};return db[_0xa33f('0x2d')]['count'](_0x5b72f6)[_0xa33f('0x24')](function(_0x48f090){_0x1c6f2a[_0xa33f('0x20')]=_0x48f090;if(_0xccb85d[_0xa33f('0x32')][_0xa33f('0x42')]){_0x38a9c7[_0xa33f('0x43')]=[{'all':!![]}];}return db['MailMessage']['findAll'](_0x38a9c7);})['then'](function(_0x1b5e7b){_0x1c6f2a[_0xa33f('0x44')]=_0x1b5e7b;return _0x1c6f2a;})['then'](respondWithFilteredResult(_0x2f5e2e,_0x38a9c7))[_0xa33f('0x45')](handleError(_0x2f5e2e,null));};exports['show']=function(_0x1175ae,_0x630dbf){var _0xc9e812={'raw':!![],'where':{'id':_0x1175ae['params']['id']}},_0x1fb8cb={};_0x1fb8cb[_0xa33f('0x33')]=_['keys'](db[_0xa33f('0x2d')][_0xa33f('0x2e')]);_0x1fb8cb[_0xa33f('0x32')]=_[_0xa33f('0x31')](_0x1175ae[_0xa33f('0x32')]);_0x1fb8cb[_0xa33f('0x3d')]=_[_0xa33f('0x46')](_0x1fb8cb['model'],_0x1fb8cb[_0xa33f('0x32')]);_0xc9e812['attributes']=_[_0xa33f('0x46')](_0x1fb8cb[_0xa33f('0x33')],qs[_0xa33f('0x35')](_0x1175ae[_0xa33f('0x32')][_0xa33f('0x35')]));_0xc9e812['attributes']=_0xc9e812[_0xa33f('0x34')][_0xa33f('0x36')]?_0xc9e812['attributes']:_0x1fb8cb[_0xa33f('0x33')];if(_0x1175ae['query']['includeAll']){_0xc9e812[_0xa33f('0x43')]=[{'all':!![]}];}_0xc9e812=_[_0xa33f('0x3f')]({},_0xc9e812,_0x1175ae[_0xa33f('0x41')]);return db['MailMessage'][_0xa33f('0x47')](_0xc9e812)[_0xa33f('0x24')](handleEntityNotFound(_0x630dbf,null))[_0xa33f('0x24')](respondWithResult(_0x630dbf,null))['catch'](handleError(_0x630dbf,null));};exports[_0xa33f('0x48')]=function(_0x450213,_0x258875){if(_0x450213['body']['id']){delete _0x450213[_0xa33f('0x49')]['id'];}return db[_0xa33f('0x2d')]['find']({'where':{'id':_0x450213[_0xa33f('0x4a')]['id']}})['then'](handleEntityNotFound(_0x258875,null))[_0xa33f('0x24')](saveUpdates(_0x450213[_0xa33f('0x49')],null))[_0xa33f('0x24')](respondWithResult(_0x258875,null))[_0xa33f('0x45')](handleError(_0x258875,null));};exports[_0xa33f('0x25')]=function(_0x1307c5,_0x7da055){return db[_0xa33f('0x2d')][_0xa33f('0x47')]({'where':{'id':_0x1307c5['params']['id']}})[_0xa33f('0x24')](handleEntityNotFound(_0x7da055,null))[_0xa33f('0x24')](removeEntity(_0x7da055,null))[_0xa33f('0x45')](handleError(_0x7da055,null));};exports[_0xa33f('0x4b')]=function(_0x40a8bd,_0x540d3e){return db[_0xa33f('0x2d')][_0xa33f('0x4b')]()[_0xa33f('0x24')](respondWithResult(_0x540d3e,null))[_0xa33f('0x45')](handleError(_0x540d3e,null));};exports[_0xa33f('0x4c')]=function(_0x36b1ea,_0x3eb9aa){return db[_0xa33f('0x2d')][_0xa33f('0x4c')](_0x36b1ea['body'])[_0xa33f('0x24')](function(_0x25ffd4){if(_0x25ffd4){if(_0x25ffd4[_0xa33f('0x4d')]===_0xa33f('0x4e')&&!_0x25ffd4['secret']){var _0x6391b6,_0x1d98ed,_0x5543f1;if(_0x36b1ea['body']['to']){_0x1d98ed=_0x36b1ea[_0xa33f('0x49')]['to'][_0xa33f('0x4f')](',')[0x0];}return db[_0xa33f('0x50')]['findOne']({'where':{'id':_0x25ffd4[_0xa33f('0x51')]},'include':[{'model':db[_0xa33f('0x52')],'as':'List','include':[{'model':db[_0xa33f('0x53')],'as':_0xa33f('0x54'),'where':{'email':_0x1d98ed},'limit':0x1,'order':[[_0xa33f('0x55'),_0xa33f('0x56')]]}]},{'model':db[_0xa33f('0x57')],'as':_0xa33f('0x58'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0xa33f('0x59'),'raw':!![]}]}]})[_0xa33f('0x24')](function(_0x4f83f4){_0x6391b6=_0x4f83f4;if(!_0x6391b6||!_0x6391b6['Smtp'])return;var _0x50f37b=_0x6391b6['getSmtpOptions']();if(_0x36b1ea[_0xa33f('0x49')][_0xa33f('0x5a')]&&_0x36b1ea[_0xa33f('0x49')][_0xa33f('0x5a')][_0xa33f('0x36')]){for(var _0xa9b132=0x0;_0xa9b132<_0x36b1ea[_0xa33f('0x49')][_0xa33f('0x5a')][_0xa33f('0x36')];_0xa9b132+=0x1){_0x36b1ea[_0xa33f('0x49')][_0xa33f('0x5a')][_0xa9b132]={'filename':_0x36b1ea[_0xa33f('0x49')]['attachments'][_0xa9b132][_0xa33f('0x29')],'path':path['join'](config[_0xa33f('0x5b')],_0xa33f('0x5c'),_0x36b1ea[_0xa33f('0x49')]['attachments'][_0xa9b132][_0xa33f('0x5d')])};}}_0x5543f1={'account':_0x50f37b,'message':_0x36b1ea[_0xa33f('0x49')]};return;})[_0xa33f('0x24')](function(){if(_0x6391b6['List']){if(_0x6391b6[_0xa33f('0x5e')][_0xa33f('0x54')][_0xa33f('0x36')]){return _0x6391b6[_0xa33f('0x5e')]['Contacts'][0x0];}else{return db[_0xa33f('0x53')][_0xa33f('0x4c')](_[_0xa33f('0x9')](_0x36b1ea[_0xa33f('0x49')],{'firstName':_0x36b1ea[_0xa33f('0x49')]['to'],'email':_0x36b1ea['body']['to'],'phone':_0x36b1ea[_0xa33f('0x49')]['to'],'ListId':_0x6391b6[_0xa33f('0x5f')]}));}}else{throw new Error('List\x20not\x20found');}})[_0xa33f('0x24')](function(){if(_0x5543f1){return respondWithRpcPromise(_0xa33f('0x60'),_0xa33f('0x61'),_0x5543f1,client9003)[_0xa33f('0x24')](function(_0x1c7784){return _0x25ffd4['update']({'read':!![],'messageId':_0x1c7784[_0xa33f('0x62')],'sentAt':moment()[_0xa33f('0x63')](_0xa33f('0x64'))});})['catch'](function(_0x252cef){logger['error']('%s',JSON[_0xa33f('0x18')](_0x252cef));return _0x25ffd4;});}return _0x25ffd4;});}return _0x25ffd4;}})[_0xa33f('0x24')](respondWithResult(_0x3eb9aa,0xc9))[_0xa33f('0x45')](handleError(_0x3eb9aa,null));};exports[_0xa33f('0x65')]=function(_0x16fc5f,_0x1369a8){var _0xf6fedd={'agent':{},'channel':_0xa33f('0x66')};if(_0x16fc5f[_0xa33f('0x49')]['id']){delete _0x16fc5f[_0xa33f('0x49')]['id'];}_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x67')]=!![];_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x68')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x69')]=_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x69')]||_0x16fc5f[_0xa33f('0x6a')]['id'];_0xf6fedd[_0xa33f('0x6b')]['id']=_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x69')];return db[_0xa33f('0x2d')]['find']({'where':{'id':_0x16fc5f[_0xa33f('0x4a')]['id'],'UserId':null}})[_0xa33f('0x24')](handleEntityNotFound(_0x1369a8,null))[_0xa33f('0x24')](saveUpdates(_0x16fc5f[_0xa33f('0x49')],null))[_0xa33f('0x24')](function(_0x4434b8){if(_0x4434b8){_0xf6fedd[_0xa33f('0x1b')]=_0x4434b8[_0xa33f('0x6c')]({'plain':!![]});return db[_0xa33f('0x6d')][_0xa33f('0x47')]({'where':{'id':_0x4434b8[_0xa33f('0x6e')]}});}return null;})[_0xa33f('0x24')](handleEntityNotFound(_0x1369a8,null))[_0xa33f('0x24')](function(_0x3a77c8){if(_0x3a77c8){return _0x3a77c8[_0xa33f('0x48')]({'UserId':_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x69')],'read1stAt':_[_0xa33f('0x6f')](_0x3a77c8['read1stAt'])?moment()[_0xa33f('0x63')](_0xa33f('0x64')):undefined});}return null;})['then'](function(_0x1b23e5){if(_0x1b23e5){_0xf6fedd['interaction']=_0x1b23e5['get']({'plain':!![]});interaction_log[_0xa33f('0x13')](_0xa33f('0x70'),_0x16fc5f['user']['id'],_0x16fc5f[_0xa33f('0x6a')][_0xa33f('0x29')],_0x16fc5f[_0xa33f('0x6a')]['role'],_0xf6fedd[_0xa33f('0x71')]['id'],_0x16fc5f['body']?JSON[_0xa33f('0x18')](_0x16fc5f[_0xa33f('0x49')]):_0xa33f('0x72'));return respondWithRpcPromise(_0xa33f('0x73'),_0xa33f('0x74'),_0xf6fedd);}return null;})[_0xa33f('0x24')](function(_0x4516dd){var _0x179ad2=_0xa33f('0x75')+_0x4516dd['message'][_0xa33f('0x76')];return db['sequelize'][_0xa33f('0x32')](_0x179ad2,{'type':db[_0xa33f('0x77')][_0xa33f('0x78')][_0xa33f('0x79')],'raw':!![]})[_0xa33f('0x24')](function(_0x4a7a42){return _0x4a7a42;});})[_0xa33f('0x24')](function(_0x169efb){if(_0x169efb){_0xf6fedd['message']['contact']=_0x169efb[0x0];if(!_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x69')])return;return db[_0xa33f('0x7a')][_0xa33f('0x47')]({'where':{'id':_0x16fc5f[_0xa33f('0x49')][_0xa33f('0x69')],'role':_0xa33f('0x6b')},'attributes':['id','name','fullname',_0xa33f('0x7b'),_0xa33f('0x7c')],'raw':!![]});}return null;})[_0xa33f('0x24')](function(_0x525cc5){if(!_0x525cc5)return null;_0xf6fedd[_0xa33f('0x1b')][_0xa33f('0x6b')]=_0x525cc5;return _0xf6fedd;})[_0xa33f('0x24')](function(_0x4d8f7b){if(_0x4d8f7b){if(_0x16fc5f['body']['manual']){_0xf6fedd[_0xa33f('0x1b')][_0xa33f('0x7d')]=util['format'](_0xa33f('0x7e'),_0x16fc5f['user'][_0xa33f('0x29')]);_0xf6fedd[_0xa33f('0x1b')][_0xa33f('0x7f')]=_0xf6fedd[_0xa33f('0x7f')];_0xf6fedd[_0xa33f('0x1b')][_0xa33f('0x80')]=_0xf6fedd[_0xa33f('0x7f')];_0xf6fedd['message'][_0xa33f('0x81')]=_0xa33f('0x65');_0xf6fedd[_0xa33f('0x1b')][_0xa33f('0x49')]=htmlToText[_0xa33f('0x82')](_0xf6fedd[_0xa33f('0x1b')][_0xa33f('0x49')]);return respondWithRpcPromise('EventManager',_0xa33f('0x83'),{'event':_0xa33f('0x84'),'message':_0xf6fedd['message']},client9002)[_0xa33f('0x24')](function(){return _0xf6fedd;});}return _0xf6fedd;}return null;})[_0xa33f('0x24')](respondWithResult(_0x1369a8,null))[_0xa33f('0x45')](handleError(_0x1369a8,null));};exports[_0xa33f('0x85')]=function(_0x4288d4,_0x49ca63){var _0x301d9b={'agent':{},'channel':'mail'};if(_0x4288d4[_0xa33f('0x49')]['id']){delete _0x4288d4[_0xa33f('0x49')]['id'];}_0x4288d4['body'][_0xa33f('0x69')]=_0x4288d4[_0xa33f('0x49')][_0xa33f('0x69')]||_0x4288d4[_0xa33f('0x6a')]['id'];_0x301d9b[_0xa33f('0x6b')]['id']=_0x4288d4[_0xa33f('0x49')][_0xa33f('0x69')];return db[_0xa33f('0x2d')][_0xa33f('0x47')]({'where':{'id':_0x4288d4[_0xa33f('0x4a')]['id'],'UserId':null}})[_0xa33f('0x24')](handleEntityNotFound(_0x49ca63,null))[_0xa33f('0x24')](function(_0x41bc91){if(_0x41bc91){_0x301d9b['message']=_0x41bc91[_0xa33f('0x6c')]({'plain':!![]});return db[_0xa33f('0x6d')][_0xa33f('0x47')]({'where':{'id':_0x41bc91[_0xa33f('0x6e')]}});}return null;})[_0xa33f('0x24')](handleEntityNotFound(_0x49ca63,null))[_0xa33f('0x24')](function(_0x27f1b7){if(_0x27f1b7){_0x301d9b[_0xa33f('0x71')]=_0x27f1b7[_0xa33f('0x6c')]({'plain':!![]});interaction_log[_0xa33f('0x13')](_0xa33f('0x86'),_0x4288d4['user']['id'],_0x4288d4['user'][_0xa33f('0x29')],_0x4288d4[_0xa33f('0x6a')][_0xa33f('0x87')],_0x301d9b['interaction']['id'],_0x4288d4[_0xa33f('0x49')]?JSON[_0xa33f('0x18')](_0x4288d4[_0xa33f('0x49')]):_0xa33f('0x72'));return respondWithRpcPromise(_0xa33f('0x88'),_0xa33f('0x89'),_0x301d9b);}return null;})[_0xa33f('0x24')](function(_0x23cb0b){var _0x564768=_0xa33f('0x75')+_0x23cb0b[_0xa33f('0x1b')]['ContactId'];return db[_0xa33f('0x8a')]['query'](_0x564768,{'type':db[_0xa33f('0x77')]['QueryTypes'][_0xa33f('0x79')],'raw':!![]})['then'](function(_0x511219){return _0x511219;});})[_0xa33f('0x24')](function(_0x185e07){if(_0x185e07){_0x301d9b[_0xa33f('0x1b')][_0xa33f('0x8b')]=_0x185e07[0x0];if(!_0x4288d4[_0xa33f('0x49')][_0xa33f('0x69')])return;return db[_0xa33f('0x7a')][_0xa33f('0x47')]({'where':{'id':_0x4288d4['body']['UserId'],'role':'agent'},'attributes':['id',_0xa33f('0x29'),'fullname',_0xa33f('0x7b'),_0xa33f('0x7c')],'raw':!![]});}return null;})[_0xa33f('0x24')](function(_0x465375){if(!_0x465375)return null;_0x301d9b[_0xa33f('0x1b')][_0xa33f('0x6b')]=_0x465375;return _0x301d9b;})[_0xa33f('0x24')](function(_0xe2526c){if(_0xe2526c){_0xe2526c[_0xa33f('0x1b')][_0xa33f('0x7d')]=util[_0xa33f('0x63')]('SIP/%s',_0x4288d4[_0xa33f('0x6a')][_0xa33f('0x29')]);_0xe2526c['message'][_0xa33f('0x7f')]=_0x301d9b[_0xa33f('0x7f')];_0xe2526c[_0xa33f('0x1b')]['motionChannel']=_0x301d9b['channel'];_0xe2526c[_0xa33f('0x1b')][_0xa33f('0x81')]=_0xa33f('0x85');_0xe2526c[_0xa33f('0x1b')][_0xa33f('0x49')]=htmlToText[_0xa33f('0x82')](_0x301d9b[_0xa33f('0x1b')]['body']);respondWithRpcPromise(_0xa33f('0x83'),'EventManager',{'event':_0xa33f('0x8c'),'message':_0xe2526c[_0xa33f('0x1b')]},client9002);return _0x301d9b;}return null;})[_0xa33f('0x24')](respondWithResult(_0x49ca63,null))['catch'](handleError(_0x49ca63,null));};exports['download']=function(_0xb28000,_0x176e0c){var _0x18e7bf=moment()[_0xa33f('0x8d')]()[_0xa33f('0x8e')]();var _0x545493=path[_0xa33f('0x8f')](config[_0xa33f('0x5b')],_0xa33f('0x90'),_0xa33f('0x91'),'tmp');var _0x2ec7f0=path[_0xa33f('0x8f')](config[_0xa33f('0x5b')],_0xa33f('0x90'),_0xa33f('0x91'),_0xa33f('0x5a'));var _0x31d51c=util['format']('message-%s.eml',_0x18e7bf);return db[_0xa33f('0x2d')][_0xa33f('0x47')]({'where':{'id':_0xb28000[_0xa33f('0x4a')]['id']},'attributes':['id','body',_0xa33f('0x92'),'to','cc','bcc',_0xa33f('0x93'),_0xa33f('0x94')],'include':_0xb28000[_0xa33f('0x32')][_0xa33f('0x5a')]?[{'model':db[_0xa33f('0x95')],'as':_0xa33f('0x96')}]:undefined})[_0xa33f('0x24')](handleEntityNotFound(_0x176e0c,null))[_0xa33f('0x24')](function(_0x4f8ad6){if(_0x4f8ad6){var _0x179840=_0x4f8ad6;var _0x1c74b4={'from':_0x179840[_0xa33f('0x92')],'to':_0x179840['to'],'subject':_0x179840['subject'],'html':htmlEntities[_0xa33f('0x97')](_0x179840[_0xa33f('0x49')]),'headers':{'Date':moment(_0x179840[_0xa33f('0x94')])['format']('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x4f8ad6['cc']){_0x1c74b4[_0xa33f('0x98')]['Cc']=_0x4f8ad6['cc'];}if(_0x4f8ad6[_0xa33f('0x99')]){_0x1c74b4[_0xa33f('0x98')][_0xa33f('0x9a')]=_0x4f8ad6[_0xa33f('0x99')];}return new BPromise(function(_0xf35f6a,_0x31eeba){if(_0x4f8ad6[_0xa33f('0x96')]){for(var _0x3d1336=0x0;_0x3d1336<_0x4f8ad6[_0xa33f('0x96')][_0xa33f('0x36')];_0x3d1336++){var _0x48fdf6=_0x4f8ad6['Attachments'][_0x3d1336];var _0xeb70bb=path[_0xa33f('0x8f')](_0x2ec7f0,_0x48fdf6[_0xa33f('0x5d')]);if(fs['existsSync'](_0xeb70bb)){_0x1c74b4['attachments'][_0xa33f('0x9b')]({'name':_0x48fdf6[_0xa33f('0x29')],'contentType':_0x48fdf6[_0xa33f('0x30')],'data':fs[_0xa33f('0x9c')](_0xeb70bb)});}}}emlformat['build'](_0x1c74b4,function(_0x400afa,_0x38b58d){if(_0x400afa)return _0x31eeba(_0x400afa);fs[_0xa33f('0x9d')](path[_0xa33f('0x8f')](_0x545493,_0x31d51c),_0x38b58d);return _0xf35f6a(_0x38b58d);});});}})[_0xa33f('0x24')](function(_0x3b5534){if(_0x3b5534){return _0x176e0c[_0xa33f('0x9e')](path[_0xa33f('0x8f')](_0x545493,_0x31d51c),_0x31d51c,function(_0xeed172){if(!_0xeed172)fs[_0xa33f('0x9f')](path[_0xa33f('0x8f')](_0x545493,_0x31d51c));});}})[_0xa33f('0x45')](handleError(_0x176e0c,null));};
\ No newline at end of file