Built motion from commit 1fa89557.|2.6.10
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index ddd701f..48c2add 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5f66=['key','model','map','query','keys','filters','attributes','intersection','fields','length','nolimit','limit','order','sort','where','pick','filter','VIRTUAL','merge','includeAll','include','rows','show','options','find','body','params','describe','direction','secret','split','findOne','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','isNil','service','host','port','secure','authentication','auth','user','pass','attachments','join','root','basename','List','create','List\x20not\x20found','SendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','../../config/logger','accept','mail','UserId','agent','Contact','MailInteraction','interaction','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','interface','SIP/%s','channel','event','EventManager','acceptmessage','MailInteractionId','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','rejectmessage','download','unix','server','files','tmp','from','createdAt','Attachment','Attachments','subject','headers','Bcc','bcc','existsSync','push','readFileSync','build','err','unlinkSync','eml-format','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','sox','to-csv','squel','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','api','../../config/license/util','redis','localhost','socket.io-emitter','./mailMessage.socket','register','jayson/promise','client','http','request','then','MailMessage,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','info','catch','status','end','count','offset','set','apply','reject','save','update','destroy','name','MailMessage','fieldName','type'];(function(_0x4685f0,_0xe9b1bb){var _0x1a98ca=function(_0x145638){while(--_0x145638){_0x4685f0['push'](_0x4685f0['shift']());}};_0x1a98ca(++_0xe9b1bb);}(_0x5f66,0x1a0));var _0x65f6=function(_0x164eca,_0x555e28){_0x164eca=_0x164eca-0x0;var _0x2ce562=_0x5f66[_0x164eca];return _0x2ce562;};'use strict';var pdf=require('html-pdf');var emlformat=require(_0x65f6('0x0'));var rimraf=require('rimraf');var zipdir=require(_0x65f6('0x1'));var jsonpatch=require(_0x65f6('0x2'));var rp=require(_0x65f6('0x3'));var moment=require(_0x65f6('0x4'));var BPromise=require(_0x65f6('0x5'));var Mustache=require('mustache');var util=require(_0x65f6('0x6'));var path=require('path');var sox=require(_0x65f6('0x7'));var csv=require(_0x65f6('0x8'));var ejs=require('ejs');var fs=require('fs');var _=require('lodash');var squel=require(_0x65f6('0x9'));var crypto=require(_0x65f6('0xa'));var jsforce=require(_0x65f6('0xb'));var deskjs=require(_0x65f6('0xc'));var toCsv=require(_0x65f6('0x8'));var querystring=require(_0x65f6('0xd'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x65f6('0xe'));var qs=require(_0x65f6('0xf'));var as=require(_0x65f6('0x10'));var hardwareService=require(_0x65f6('0x11'));var logger=require('../../config/logger')(_0x65f6('0x12'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x65f6('0x13'));var db=require('../../mysqldb')['db'];config[_0x65f6('0x14')]=_['defaults'](config[_0x65f6('0x14')],{'host':_0x65f6('0x15'),'port':0x18eb});var socket=require(_0x65f6('0x16'))(new Redis(config[_0x65f6('0x14')]));require(_0x65f6('0x17'))[_0x65f6('0x18')](socket);var jayson=require(_0x65f6('0x19'));var client=jayson[_0x65f6('0x1a')][_0x65f6('0x1b')]({'port':0x232c});var client9003=jayson[_0x65f6('0x1a')]['http']({'port':0x232b});var client9002=jayson[_0x65f6('0x1a')]['http']({'port':0x232a});function respondWithRpcPromise(_0x5dd324,_0x1693e6,_0x5c69f8,_0x37330d){return new BPromise(function(_0x1c955c,_0x1b1cbb){var _0x1f974c=_0x37330d||client;return _0x1f974c[_0x65f6('0x1c')](_0x5dd324,_0x5c69f8)[_0x65f6('0x1d')](function(_0x495dd6){logger['info'](_0x65f6('0x1e'),_0x1693e6,'request\x20sent');logger['debug']('MailMessage,\x20%s,\x20%s,\x20%s',_0x1693e6,_0x65f6('0x1f'),JSON[_0x65f6('0x20')](_0x495dd6));if(_0x495dd6['error']){if(_0x495dd6[_0x65f6('0x21')][_0x65f6('0x22')]===0x1f4){logger[_0x65f6('0x21')](_0x65f6('0x1e'),_0x1693e6,_0x495dd6[_0x65f6('0x21')][_0x65f6('0x23')]);return _0x1b1cbb(_0x495dd6['error'][_0x65f6('0x23')]);}logger['error']('MailMessage,\x20%s,\x20%s',_0x1693e6,_0x495dd6[_0x65f6('0x21')][_0x65f6('0x23')]);return _0x1c955c(_0x495dd6['error'][_0x65f6('0x23')]);}else{logger[_0x65f6('0x24')](_0x65f6('0x1e'),_0x1693e6,_0x65f6('0x1f'));_0x1c955c(_0x495dd6['result'][_0x65f6('0x23')]);}})[_0x65f6('0x25')](function(_0x20a161){logger['error']('MailMessage,\x20%s,\x20%s',_0x1693e6,_0x20a161);_0x1b1cbb(_0x20a161);});});}function respondWithStatusCode(_0x4fde2f,_0x29abdb){_0x29abdb=_0x29abdb||0xcc;return function(_0x16cde8){if(_0x16cde8){return _0x4fde2f['sendStatus'](_0x29abdb);}return _0x4fde2f[_0x65f6('0x26')](_0x29abdb)[_0x65f6('0x27')]();};}function respondWithResult(_0x52277c,_0x325cb4){_0x325cb4=_0x325cb4||0xc8;return function(_0x2bff2b){if(_0x2bff2b){return _0x52277c[_0x65f6('0x26')](_0x325cb4)['json'](_0x2bff2b);}};}function respondWithFilteredResult(_0x4ac04b,_0x488d36){return function(_0x266cfe){if(_0x266cfe){var _0x3c032f=_0x266cfe[_0x65f6('0x28')],_0x4344b3=_0x488d36[_0x65f6('0x29')],_0x408ccc=_0x488d36['offset']+_0x488d36['limit'],_0x518cac;if(_0x408ccc>=_0x3c032f){_0x408ccc=_0x3c032f;_0x518cac=0xc8;}else{_0x518cac=0xce;}_0x4ac04b[_0x65f6('0x26')](_0x518cac);return _0x4ac04b[_0x65f6('0x2a')]('Content-Range',_0x4344b3+'-'+_0x408ccc+'/'+_0x3c032f)['json'](_0x266cfe);}return null;};}function patchUpdates(_0x10b368){return function(_0x1ce43c){try{jsonpatch[_0x65f6('0x2b')](_0x1ce43c,_0x10b368,!![]);}catch(_0xc53cb7){return BPromise[_0x65f6('0x2c')](_0xc53cb7);}return _0x1ce43c[_0x65f6('0x2d')]();};}function saveUpdates(_0x5792a0,_0x103265){return function(_0x38f3c6){if(_0x38f3c6){return _0x38f3c6[_0x65f6('0x2e')](_0x5792a0)['then'](function(_0x217f35){return _0x217f35;});}return null;};}function removeEntity(_0x2a7aa8,_0xbaed3c){return function(_0x45510a){if(_0x45510a){return _0x45510a[_0x65f6('0x2f')]()[_0x65f6('0x1d')](function(){_0x2a7aa8['status'](0xcc)[_0x65f6('0x27')]();});}};}function handleEntityNotFound(_0x1b24ea,_0x4f3e22){return function(_0x36dbf4){if(!_0x36dbf4){_0x1b24ea['sendStatus'](0x194);}return _0x36dbf4;};}function handleError(_0x2b403b,_0x50494b){_0x50494b=_0x50494b||0x1f4;return function(_0x2b9fb6){logger[_0x65f6('0x21')](_0x2b9fb6['stack']);if(_0x2b9fb6[_0x65f6('0x30')]){delete _0x2b9fb6[_0x65f6('0x30')];}_0x2b403b[_0x65f6('0x26')](_0x50494b)['send'](_0x2b9fb6);};}exports['index']=function(_0x30109d,_0x4c0df4){var _0x26de30={},_0x4e6653={},_0x22d760={'count':0x0,'rows':[]};var _0x2b9675=_['map'](db[_0x65f6('0x31')]['rawAttributes'],function(_0x5edd04){return{'name':_0x5edd04[_0x65f6('0x32')],'type':_0x5edd04[_0x65f6('0x33')][_0x65f6('0x34')]};});_0x4e6653[_0x65f6('0x35')]=_[_0x65f6('0x36')](_0x2b9675,_0x65f6('0x30'));_0x4e6653[_0x65f6('0x37')]=_[_0x65f6('0x38')](_0x30109d['query']);_0x4e6653[_0x65f6('0x39')]=_['intersection'](_0x4e6653[_0x65f6('0x35')],_0x4e6653[_0x65f6('0x37')]);_0x26de30[_0x65f6('0x3a')]=_[_0x65f6('0x3b')](_0x4e6653['model'],qs[_0x65f6('0x3c')](_0x30109d[_0x65f6('0x37')][_0x65f6('0x3c')]));_0x26de30[_0x65f6('0x3a')]=_0x26de30[_0x65f6('0x3a')][_0x65f6('0x3d')]?_0x26de30[_0x65f6('0x3a')]:_0x4e6653[_0x65f6('0x35')];if(!_0x30109d[_0x65f6('0x37')]['hasOwnProperty'](_0x65f6('0x3e'))){_0x26de30[_0x65f6('0x3f')]=qs[_0x65f6('0x3f')](_0x30109d[_0x65f6('0x37')][_0x65f6('0x3f')]);_0x26de30[_0x65f6('0x29')]=qs[_0x65f6('0x29')](_0x30109d[_0x65f6('0x37')][_0x65f6('0x29')]);}_0x26de30[_0x65f6('0x40')]=qs[_0x65f6('0x41')](_0x30109d[_0x65f6('0x37')][_0x65f6('0x41')]);_0x26de30[_0x65f6('0x42')]=qs[_0x65f6('0x39')](_[_0x65f6('0x43')](_0x30109d['query'],_0x4e6653[_0x65f6('0x39')]),_0x2b9675);if(_0x30109d[_0x65f6('0x37')][_0x65f6('0x44')]){_0x26de30[_0x65f6('0x42')]=_['merge'](_0x26de30[_0x65f6('0x42')],{'$or':_[_0x65f6('0x36')](_0x2b9675,function(_0x2b01eb){if(_0x2b01eb['type']!==_0x65f6('0x45')){var _0x3386a2={};_0x3386a2[_0x2b01eb[_0x65f6('0x30')]]={'$like':'%'+_0x30109d[_0x65f6('0x37')]['filter']+'%'};return _0x3386a2;}})});}_0x26de30=_[_0x65f6('0x46')]({},_0x26de30,_0x30109d['options']);var _0x3f1baa={'where':_0x26de30[_0x65f6('0x42')]};return db['MailMessage'][_0x65f6('0x28')](_0x3f1baa)['then'](function(_0x30812d){_0x22d760[_0x65f6('0x28')]=_0x30812d;if(_0x30109d[_0x65f6('0x37')][_0x65f6('0x47')]){_0x26de30[_0x65f6('0x48')]=[{'all':!![]}];}return db[_0x65f6('0x31')]['findAll'](_0x26de30);})['then'](function(_0x198e2f){_0x22d760[_0x65f6('0x49')]=_0x198e2f;return _0x22d760;})[_0x65f6('0x1d')](respondWithFilteredResult(_0x4c0df4,_0x26de30))[_0x65f6('0x25')](handleError(_0x4c0df4,null));};exports[_0x65f6('0x4a')]=function(_0x2d6ab9,_0x149c28){var _0x41690c={'raw':!![],'where':{'id':_0x2d6ab9['params']['id']}},_0x414f49={};_0x414f49[_0x65f6('0x35')]=_[_0x65f6('0x38')](db[_0x65f6('0x31')]['rawAttributes']);_0x414f49[_0x65f6('0x37')]=_[_0x65f6('0x38')](_0x2d6ab9['query']);_0x414f49[_0x65f6('0x39')]=_[_0x65f6('0x3b')](_0x414f49['model'],_0x414f49[_0x65f6('0x37')]);_0x41690c['attributes']=_[_0x65f6('0x3b')](_0x414f49[_0x65f6('0x35')],qs[_0x65f6('0x3c')](_0x2d6ab9['query'][_0x65f6('0x3c')]));_0x41690c[_0x65f6('0x3a')]=_0x41690c['attributes'][_0x65f6('0x3d')]?_0x41690c[_0x65f6('0x3a')]:_0x414f49['model'];if(_0x2d6ab9[_0x65f6('0x37')][_0x65f6('0x47')]){_0x41690c[_0x65f6('0x48')]=[{'all':!![]}];}_0x41690c=_[_0x65f6('0x46')]({},_0x41690c,_0x2d6ab9[_0x65f6('0x4b')]);return db[_0x65f6('0x31')][_0x65f6('0x4c')](_0x41690c)[_0x65f6('0x1d')](handleEntityNotFound(_0x149c28,null))['then'](respondWithResult(_0x149c28,null))['catch'](handleError(_0x149c28,null));};exports['update']=function(_0x19f40c,_0x2091f1){if(_0x19f40c[_0x65f6('0x4d')]['id']){delete _0x19f40c[_0x65f6('0x4d')]['id'];}return db['MailMessage'][_0x65f6('0x4c')]({'where':{'id':_0x19f40c[_0x65f6('0x4e')]['id']}})[_0x65f6('0x1d')](handleEntityNotFound(_0x2091f1,null))['then'](saveUpdates(_0x19f40c[_0x65f6('0x4d')],null))[_0x65f6('0x1d')](respondWithResult(_0x2091f1,null))[_0x65f6('0x25')](handleError(_0x2091f1,null));};exports['destroy']=function(_0x551fe3,_0x1d337d){return db[_0x65f6('0x31')][_0x65f6('0x4c')]({'where':{'id':_0x551fe3[_0x65f6('0x4e')]['id']}})[_0x65f6('0x1d')](handleEntityNotFound(_0x1d337d,null))[_0x65f6('0x1d')](removeEntity(_0x1d337d,null))[_0x65f6('0x25')](handleError(_0x1d337d,null));};exports[_0x65f6('0x4f')]=function(_0x2d8b5b,_0xddbd90){return db[_0x65f6('0x31')][_0x65f6('0x4f')]()[_0x65f6('0x1d')](respondWithResult(_0xddbd90,null))[_0x65f6('0x25')](handleError(_0xddbd90,null));};exports['create']=function(_0x47610a,_0x37d527){return db[_0x65f6('0x31')]['create'](_0x47610a[_0x65f6('0x4d')])[_0x65f6('0x1d')](function(_0x4638c9){if(_0x4638c9){if(_0x4638c9[_0x65f6('0x50')]==='out'&&!_0x4638c9[_0x65f6('0x51')]){var _0x4227f5,_0xe5fc65,_0x3e0d8b;if(_0x47610a['body']['to']){_0xe5fc65=_0x47610a[_0x65f6('0x4d')]['to'][_0x65f6('0x52')](',')[0x0];}return db['MailAccount'][_0x65f6('0x53')]({'where':{'id':_0x4638c9[_0x65f6('0x54')]},'include':[{'model':db[_0x65f6('0x55')],'as':'List','include':[{'model':db[_0x65f6('0x56')],'as':_0x65f6('0x57'),'where':{'email':_0xe5fc65},'limit':0x1,'order':[[_0x65f6('0x58'),_0x65f6('0x59')]]}]},{'model':db[_0x65f6('0x5a')],'as':_0x65f6('0x5b'),'raw':!![]}]})['then'](function(_0x4ee8bd){_0x4227f5=_0x4ee8bd;if(_0x4227f5&&_0x4227f5['Smtp']){var _0x336a7d={'tls':{'rejectUnauthorized':![]}};if(_[_0x65f6('0x5c')](_0x4227f5[_0x65f6('0x5b')][_0x65f6('0x5d')])){_0x336a7d[_0x65f6('0x5e')]=_0x4227f5[_0x65f6('0x5b')]['host'];_0x336a7d[_0x65f6('0x5f')]=_0x4227f5[_0x65f6('0x5b')]['port'];_0x336a7d[_0x65f6('0x60')]=_0x4227f5[_0x65f6('0x5b')][_0x65f6('0x60')];if(_0x4227f5['Smtp'][_0x65f6('0x61')]){_0x336a7d[_0x65f6('0x62')]={'user':_0x4227f5['Smtp'][_0x65f6('0x63')],'pass':_0x4227f5[_0x65f6('0x5b')][_0x65f6('0x64')]};}}else{_0x336a7d[_0x65f6('0x5d')]=_0x4227f5[_0x65f6('0x5b')][_0x65f6('0x5d')];_0x336a7d[_0x65f6('0x62')]={'user':_0x4227f5['Smtp']['user'],'pass':_0x4227f5[_0x65f6('0x5b')][_0x65f6('0x64')]};_0x336a7d['secure']=_0x4227f5[_0x65f6('0x5b')]['secure'];}if(_0x47610a[_0x65f6('0x4d')]['attachments']&&_0x47610a[_0x65f6('0x4d')][_0x65f6('0x65')][_0x65f6('0x3d')]){for(var _0x2beeb7=0x0;_0x2beeb7<_0x47610a[_0x65f6('0x4d')][_0x65f6('0x65')][_0x65f6('0x3d')];_0x2beeb7+=0x1){_0x47610a[_0x65f6('0x4d')][_0x65f6('0x65')][_0x2beeb7]={'filename':_0x47610a['body']['attachments'][_0x2beeb7][_0x65f6('0x30')],'path':path[_0x65f6('0x66')](config[_0x65f6('0x67')],'server/files/attachments',_0x47610a['body'][_0x65f6('0x65')][_0x2beeb7][_0x65f6('0x68')])};}}_0x3e0d8b={'account':_0x336a7d,'message':_0x47610a[_0x65f6('0x4d')]};return;}})[_0x65f6('0x1d')](function(){if(_0x4227f5[_0x65f6('0x69')]){if(_0x4227f5[_0x65f6('0x69')]['Contacts']['length']){return _0x4227f5[_0x65f6('0x69')][_0x65f6('0x57')][0x0];}else{return db['CmContact'][_0x65f6('0x6a')](_['defaults'](_0x47610a[_0x65f6('0x4d')],{'firstName':_0x47610a[_0x65f6('0x4d')]['to'],'email':_0x47610a[_0x65f6('0x4d')]['to'],'phone':_0x47610a[_0x65f6('0x4d')]['to'],'ListId':_0x4227f5['ListId']}));}}else{throw new Error(_0x65f6('0x6b'));}})[_0x65f6('0x1d')](function(){if(_0x3e0d8b){return respondWithRpcPromise(_0x65f6('0x6c'),'sendMail',_0x3e0d8b,client9003)['then'](function(_0x469550){return _0x4638c9['update']({'read':!![],'messageId':_0x469550[_0x65f6('0x6d')],'sentAt':moment()[_0x65f6('0x6e')](_0x65f6('0x6f'))});})[_0x65f6('0x25')](function(_0x512776){logger['error']('%s',JSON['stringify'](_0x512776));return _0x4638c9;});}return _0x4638c9;});}return _0x4638c9;}})[_0x65f6('0x1d')](respondWithResult(_0x37d527,0xc9))[_0x65f6('0x25')](handleError(_0x37d527,null));};var interaction_log=require(_0x65f6('0x70'))('mail-interactions');exports[_0x65f6('0x71')]=function(_0x44a2b8,_0x2a7c90,_0x49cee2){var _0x40d0f7={'agent':{},'channel':_0x65f6('0x72')};if(_0x44a2b8['body']['id']){delete _0x44a2b8[_0x65f6('0x4d')]['id'];}_0x44a2b8[_0x65f6('0x4d')]['read']=!![];_0x44a2b8[_0x65f6('0x4d')]['readAt']=moment()[_0x65f6('0x6e')]('YYYY-MM-DD\x20HH:mm:ss');_0x44a2b8[_0x65f6('0x4d')][_0x65f6('0x73')]=_0x44a2b8['body'][_0x65f6('0x73')]||_0x44a2b8[_0x65f6('0x63')]['id'];_0x40d0f7[_0x65f6('0x74')]['id']=_0x44a2b8[_0x65f6('0x4d')][_0x65f6('0x73')];return db[_0x65f6('0x31')][_0x65f6('0x4c')]({'where':{'id':_0x44a2b8[_0x65f6('0x4e')]['id'],'UserId':null},'include':[{'model':db[_0x65f6('0x56')],'as':_0x65f6('0x75')}]})[_0x65f6('0x1d')](handleEntityNotFound(_0x2a7c90,null))['then'](saveUpdates(_0x44a2b8[_0x65f6('0x4d')],null))[_0x65f6('0x1d')](function(_0x15c8b7){if(_0x15c8b7){_0x40d0f7[_0x65f6('0x23')]=_0x15c8b7['get']({'plain':!![]});return db[_0x65f6('0x76')][_0x65f6('0x4c')]({'where':{'id':_0x15c8b7['MailInteractionId']}});}return null;})[_0x65f6('0x1d')](handleEntityNotFound(_0x2a7c90,null))['then'](function(_0x10d98f){if(_0x10d98f){return _0x10d98f['update']({'UserId':_0x44a2b8[_0x65f6('0x4d')][_0x65f6('0x73')],'read1stAt':_['isNil'](_0x10d98f['read1stAt'])?moment()[_0x65f6('0x6e')](_0x65f6('0x6f')):undefined});}return null;})['then'](function(_0x2d86c8){if(_0x2d86c8){_0x40d0f7[_0x65f6('0x77')]=_0x2d86c8[_0x65f6('0x78')]({'plain':!![]});interaction_log['info'](_0x65f6('0x79'),_0x44a2b8[_0x65f6('0x63')]['id'],_0x44a2b8['user'][_0x65f6('0x30')],_0x44a2b8['user'][_0x65f6('0x7a')],_0x40d0f7['interaction']['id'],_0x44a2b8['body']?JSON[_0x65f6('0x20')](_0x44a2b8[_0x65f6('0x4d')]):_0x65f6('0x7b'));return respondWithRpcPromise(_0x65f6('0x7c'),_0x65f6('0x7d'),_0x40d0f7);}return null;})[_0x65f6('0x1d')](function(_0x1ac46f){if(_0x1ac46f){if(_0x44a2b8[_0x65f6('0x4d')]['manual']){_0x40d0f7['message'][_0x65f6('0x7e')]=util['format'](_0x65f6('0x7f'),_0x44a2b8[_0x65f6('0x63')][_0x65f6('0x30')]);_0x40d0f7[_0x65f6('0x23')][_0x65f6('0x80')]=_0x40d0f7['channel'];_0x40d0f7[_0x65f6('0x23')][_0x65f6('0x81')]=_0x65f6('0x71');return respondWithRpcPromise('EventManager',_0x65f6('0x82'),{'event':_0x65f6('0x83'),'message':_0x40d0f7[_0x65f6('0x23')]},client9002)[_0x65f6('0x1d')](function(){return _0x40d0f7;});}return _0x40d0f7;}return null;})[_0x65f6('0x1d')](respondWithResult(_0x2a7c90,null))[_0x65f6('0x25')](handleError(_0x2a7c90,null));};var interaction_log=require('../../config/logger')('mail-interactions');exports[_0x65f6('0x2c')]=function(_0x10d744,_0x10c916,_0x4113e3){var _0x490c29={'agent':{},'channel':'mail'};if(_0x10d744[_0x65f6('0x4d')]['id']){delete _0x10d744[_0x65f6('0x4d')]['id'];}_0x10d744[_0x65f6('0x4d')][_0x65f6('0x73')]=_0x10d744[_0x65f6('0x4d')][_0x65f6('0x73')]||_0x10d744['user']['id'];_0x490c29['agent']['id']=_0x10d744['body'][_0x65f6('0x73')];return db[_0x65f6('0x31')][_0x65f6('0x4c')]({'where':{'id':_0x10d744[_0x65f6('0x4e')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x10c916,null))['then'](function(_0x217e3d){if(_0x217e3d){_0x490c29[_0x65f6('0x23')]=_0x217e3d['get']({'plain':!![]});return db[_0x65f6('0x76')]['find']({'where':{'id':_0x217e3d[_0x65f6('0x84')]}});}return null;})['then'](handleEntityNotFound(_0x10c916,null))[_0x65f6('0x1d')](function(_0x208fee){if(_0x208fee){_0x490c29['interaction']=_0x208fee[_0x65f6('0x78')]({'plain':!![]});interaction_log[_0x65f6('0x24')](_0x65f6('0x85'),_0x10d744[_0x65f6('0x63')]['id'],_0x10d744[_0x65f6('0x63')][_0x65f6('0x30')],_0x10d744['user'][_0x65f6('0x7a')],_0x490c29['interaction']['id'],_0x10d744[_0x65f6('0x4d')]?JSON['stringify'](_0x10d744[_0x65f6('0x4d')]):_0x65f6('0x7b'));return respondWithRpcPromise(_0x65f6('0x86'),_0x65f6('0x87'),_0x490c29);}return null;})['then'](function(_0x2b6f98){if(_0x2b6f98){_0x2b6f98[_0x65f6('0x23')][_0x65f6('0x7e')]=util['format']('SIP/%s',_0x10d744[_0x65f6('0x63')][_0x65f6('0x30')]);_0x2b6f98['message'][_0x65f6('0x80')]=_0x490c29[_0x65f6('0x80')];_0x2b6f98[_0x65f6('0x23')]['event']=_0x65f6('0x2c');respondWithRpcPromise(_0x65f6('0x82'),'EventManager',{'event':_0x65f6('0x88'),'message':_0x2b6f98[_0x65f6('0x23')]},client9002);return _0x490c29;}return null;})[_0x65f6('0x1d')](respondWithResult(_0x10c916,null))['catch'](handleError(_0x10c916,null));};exports[_0x65f6('0x89')]=function(_0x2287fc,_0x150b5b){var _0x5acd25=moment()[_0x65f6('0x8a')]()['toString']();var _0x1beaa7=path[_0x65f6('0x66')](config[_0x65f6('0x67')],_0x65f6('0x8b'),_0x65f6('0x8c'),_0x65f6('0x8d'));var _0x5d6540=path[_0x65f6('0x66')](config[_0x65f6('0x67')],_0x65f6('0x8b'),_0x65f6('0x8c'),_0x65f6('0x65'));var _0x59407d=util['format']('message-%s.eml',_0x5acd25);return db[_0x65f6('0x31')][_0x65f6('0x4c')]({'where':{'id':_0x2287fc[_0x65f6('0x4e')]['id']},'attributes':['id','body',_0x65f6('0x8e'),'to','cc','bcc','subject',_0x65f6('0x8f')],'include':_0x2287fc[_0x65f6('0x37')]['attachments']?[{'model':db[_0x65f6('0x90')],'as':_0x65f6('0x91')}]:undefined})[_0x65f6('0x1d')](handleEntityNotFound(_0x150b5b,null))[_0x65f6('0x1d')](function(_0x10520e){if(_0x10520e){var _0x1bd68f=_0x10520e;var _0x2b541b={'from':_0x1bd68f[_0x65f6('0x8e')],'to':_0x1bd68f['to'],'subject':_0x1bd68f[_0x65f6('0x92')],'html':_0x1bd68f[_0x65f6('0x4d')],'headers':{'Date':moment(_0x1bd68f[_0x65f6('0x8f')])[_0x65f6('0x6e')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x10520e['cc']){_0x2b541b[_0x65f6('0x93')]['Cc']=_0x10520e['cc'];}if(_0x10520e['bcc']){_0x2b541b['headers'][_0x65f6('0x94')]=_0x10520e[_0x65f6('0x95')];}return new BPromise(function(_0xdcfe8,_0x3727f9){if(_0x10520e['Attachments']){for(var _0x136e74=0x0;_0x136e74<_0x10520e['Attachments']['length'];_0x136e74++){var _0x416ed4=_0x10520e[_0x65f6('0x91')][_0x136e74];var _0x1a7e52=path[_0x65f6('0x66')](_0x5d6540,_0x416ed4[_0x65f6('0x68')]);if(fs[_0x65f6('0x96')](_0x1a7e52)){_0x2b541b['attachments'][_0x65f6('0x97')]({'name':_0x416ed4['name'],'contentType':_0x416ed4[_0x65f6('0x33')],'data':fs[_0x65f6('0x98')](_0x1a7e52)});}}}emlformat[_0x65f6('0x99')](_0x2b541b,function(_0x5094ba,_0x29396f){if(_0x5094ba)return _0x3727f9(_0x5094ba);fs['writeFileSync'](path['join'](_0x1beaa7,_0x59407d),_0x29396f);return _0xdcfe8(_0x29396f);});});}})[_0x65f6('0x1d')](function(_0xc40329){if(_0xc40329){return _0x150b5b[_0x65f6('0x89')](path[_0x65f6('0x66')](_0x1beaa7,_0x59407d),_0x59407d,function(_0x3b8dd5){if(_0x3b8dd5){console['log'](_0x65f6('0x9a'),_0x3b8dd5);}else{fs[_0x65f6('0x9b')](path[_0x65f6('0x66')](_0x1beaa7,_0x59407d));}});}})[_0x65f6('0x25')](handleError(_0x150b5b,null));};
\ No newline at end of file
+var _0xa335=['[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','null','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','email','interface','channel','event','fromString','EventManager','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','fullname','internal','SIP/%s','motionChannel','reject','rejectmessage','download','unix','server','files','from','bcc','subject','Attachment','Attachments','decode','createdAt','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','build','writeFileSync','unlinkSync','eml-format','moment','bluebird','util','path','lodash','ioredis','../../components/parsers/qs','../../config/logger','api','mail-interactions','../../config/environment','../../mysqldb','defaults','redis','html-entities','./mailMessage.socket','register','client','http','request','then','info','MailMessage,\x20%s,\x20%s','debug','request\x20sent','stringify','error','code','message','result','catch','status','json','offset','undefined','count','limit','set','Content-Range','update','destroy','end','sendStatus','name','send','index','map','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','filters','pick','filter','VIRTUAL','merge','options','MailMessage','includeAll','include','findAll','params','find','body','describe','direction','out','split','findOne','MailAccountId','List','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','attachments','join','root','server/files/attachments','basename','create','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','read','readAt','agent','UserId','get','MailInteraction','MailInteractionId','isNil','read1stAt','interaction'];(function(_0x475048,_0x11e175){var _0x4fbcb1=function(_0x40f68f){while(--_0x40f68f){_0x475048['push'](_0x475048['shift']());}};_0x4fbcb1(++_0x11e175);}(_0xa335,0xca));var _0x5a33=function(_0x3dd15e,_0x1f0015){_0x3dd15e=_0x3dd15e-0x0;var _0x231fd0=_0xa335[_0x3dd15e];return _0x231fd0;};'use strict';var emlformat=require(_0x5a33('0x0'));var moment=require(_0x5a33('0x1'));var BPromise=require(_0x5a33('0x2'));var util=require(_0x5a33('0x3'));var path=require(_0x5a33('0x4'));var fs=require('fs');var _=require(_0x5a33('0x5'));var Redis=require(_0x5a33('0x6'));var htmlToText=require('html-to-text');var qs=require(_0x5a33('0x7'));var logger=require(_0x5a33('0x8'))(_0x5a33('0x9'));var interaction_log=require('../../config/logger')(_0x5a33('0xa'));var config=require(_0x5a33('0xb'));var db=require(_0x5a33('0xc'))['db'];config['redis']=_[_0x5a33('0xd')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5a33('0xe')]));var htmlEntities=require(_0x5a33('0xf'));require(_0x5a33('0x10'))[_0x5a33('0x11')](socket);var jayson=require('jayson/promise');var client=jayson[_0x5a33('0x12')][_0x5a33('0x13')]({'port':0x232c});var client9003=jayson[_0x5a33('0x12')][_0x5a33('0x13')]({'port':0x232b});var client9002=jayson[_0x5a33('0x12')]['http']({'port':0x232a});function respondWithRpcPromise(_0x5e6579,_0x273798,_0xc8a484,_0x3000a7){return new BPromise(function(_0x3afd07,_0xc38323){var _0x243d93=_0x3000a7||client;return _0x243d93[_0x5a33('0x14')](_0x5e6579,_0xc8a484)[_0x5a33('0x15')](function(_0x3dc2af){logger[_0x5a33('0x16')](_0x5a33('0x17'),_0x273798,'request\x20sent');logger[_0x5a33('0x18')]('MailMessage,\x20%s,\x20%s,\x20%s',_0x273798,_0x5a33('0x19'),JSON[_0x5a33('0x1a')](_0x3dc2af));if(_0x3dc2af[_0x5a33('0x1b')]){if(_0x3dc2af['error'][_0x5a33('0x1c')]===0x1f4){logger[_0x5a33('0x1b')]('MailMessage,\x20%s,\x20%s',_0x273798,_0x3dc2af[_0x5a33('0x1b')]['message']);return _0xc38323(_0x3dc2af[_0x5a33('0x1b')][_0x5a33('0x1d')]);}logger[_0x5a33('0x1b')](_0x5a33('0x17'),_0x273798,_0x3dc2af[_0x5a33('0x1b')]['message']);return _0x3afd07(_0x3dc2af['error'][_0x5a33('0x1d')]);}else{logger[_0x5a33('0x16')](_0x5a33('0x17'),_0x273798,_0x5a33('0x19'));_0x3afd07(_0x3dc2af[_0x5a33('0x1e')][_0x5a33('0x1d')]);}})[_0x5a33('0x1f')](function(_0x6ced4){logger[_0x5a33('0x1b')](_0x5a33('0x17'),_0x273798,_0x6ced4);_0xc38323(_0x6ced4);});});}function respondWithResult(_0x28ee08,_0xa86f8){_0xa86f8=_0xa86f8||0xc8;return function(_0x27a443){if(_0x27a443){return _0x28ee08[_0x5a33('0x20')](_0xa86f8)[_0x5a33('0x21')](_0x27a443);}};}function respondWithFilteredResult(_0x48635e,_0x478aff){return function(_0x21d5fc){if(_0x21d5fc){var _0x2a051c=typeof _0x478aff[_0x5a33('0x22')]===_0x5a33('0x23')&&typeof _0x478aff['limit']==='undefined';var _0x45f5fd=_0x21d5fc[_0x5a33('0x24')];var _0x2d42a1=_0x2a051c?0x0:_0x478aff[_0x5a33('0x22')];var _0x109fe7=_0x2a051c?_0x21d5fc[_0x5a33('0x24')]:_0x478aff[_0x5a33('0x22')]+_0x478aff[_0x5a33('0x25')];var _0x56c65a;if(_0x109fe7>=_0x45f5fd){_0x109fe7=_0x45f5fd;_0x56c65a=0xc8;}else{_0x56c65a=0xce;}_0x48635e[_0x5a33('0x20')](_0x56c65a);return _0x48635e[_0x5a33('0x26')](_0x5a33('0x27'),_0x2d42a1+'-'+_0x109fe7+'/'+_0x45f5fd)[_0x5a33('0x21')](_0x21d5fc);}return null;};}function saveUpdates(_0x1d8fb3){return function(_0x2d7d88){if(_0x2d7d88){return _0x2d7d88[_0x5a33('0x28')](_0x1d8fb3)['then'](function(_0x45be00){return _0x45be00;});}return null;};}function removeEntity(_0xa2a02e){return function(_0x567858){if(_0x567858){return _0x567858[_0x5a33('0x29')]()['then'](function(){_0xa2a02e[_0x5a33('0x20')](0xcc)[_0x5a33('0x2a')]();});}};}function handleEntityNotFound(_0x42e5ea){return function(_0x2d48a1){if(!_0x2d48a1){_0x42e5ea[_0x5a33('0x2b')](0x194);}return _0x2d48a1;};}function handleError(_0x1a1bcf,_0x5cd134){_0x5cd134=_0x5cd134||0x1f4;return function(_0x48a8db){logger[_0x5a33('0x1b')](_0x48a8db['stack']);if(_0x48a8db[_0x5a33('0x2c')]){delete _0x48a8db[_0x5a33('0x2c')];}_0x1a1bcf['status'](_0x5cd134)[_0x5a33('0x2d')](_0x48a8db);};}exports[_0x5a33('0x2e')]=function(_0x5a0e6b,_0x29a486){var _0x377efe={},_0x1c4c37={},_0x368fc9={'count':0x0,'rows':[]};var _0x3cbab8=_[_0x5a33('0x2f')](db['MailMessage'][_0x5a33('0x30')],function(_0x23c66e){return{'name':_0x23c66e[_0x5a33('0x31')],'type':_0x23c66e[_0x5a33('0x32')][_0x5a33('0x33')]};});_0x1c4c37[_0x5a33('0x34')]=_[_0x5a33('0x2f')](_0x3cbab8,_0x5a33('0x2c'));_0x1c4c37[_0x5a33('0x35')]=_[_0x5a33('0x36')](_0x5a0e6b['query']);_0x1c4c37['filters']=_[_0x5a33('0x37')](_0x1c4c37['model'],_0x1c4c37[_0x5a33('0x35')]);_0x377efe[_0x5a33('0x38')]=_[_0x5a33('0x37')](_0x1c4c37[_0x5a33('0x34')],qs['fields'](_0x5a0e6b['query'][_0x5a33('0x39')]));_0x377efe['attributes']=_0x377efe[_0x5a33('0x38')][_0x5a33('0x3a')]?_0x377efe[_0x5a33('0x38')]:_0x1c4c37[_0x5a33('0x34')];if(!_0x5a0e6b[_0x5a33('0x35')][_0x5a33('0x3b')]('nolimit')){_0x377efe[_0x5a33('0x25')]=qs[_0x5a33('0x25')](_0x5a0e6b[_0x5a33('0x35')][_0x5a33('0x25')]);_0x377efe[_0x5a33('0x22')]=qs[_0x5a33('0x22')](_0x5a0e6b[_0x5a33('0x35')]['offset']);}_0x377efe[_0x5a33('0x3c')]=qs[_0x5a33('0x3d')](_0x5a0e6b[_0x5a33('0x35')][_0x5a33('0x3d')]);_0x377efe[_0x5a33('0x3e')]=qs[_0x5a33('0x3f')](_[_0x5a33('0x40')](_0x5a0e6b[_0x5a33('0x35')],_0x1c4c37[_0x5a33('0x3f')]),_0x3cbab8);if(_0x5a0e6b[_0x5a33('0x35')][_0x5a33('0x41')]){_0x377efe[_0x5a33('0x3e')]=_['merge'](_0x377efe[_0x5a33('0x3e')],{'$or':_[_0x5a33('0x2f')](_0x3cbab8,function(_0x1e7b52){if(_0x1e7b52[_0x5a33('0x32')]!==_0x5a33('0x42')){var _0x347128={};_0x347128[_0x1e7b52[_0x5a33('0x2c')]]={'$like':'%'+_0x5a0e6b['query'][_0x5a33('0x41')]+'%'};return _0x347128;}})});}_0x377efe=_[_0x5a33('0x43')]({},_0x377efe,_0x5a0e6b[_0x5a33('0x44')]);var _0x2837d1={'where':_0x377efe['where']};return db[_0x5a33('0x45')][_0x5a33('0x24')](_0x2837d1)[_0x5a33('0x15')](function(_0x3d73e9){_0x368fc9[_0x5a33('0x24')]=_0x3d73e9;if(_0x5a0e6b[_0x5a33('0x35')][_0x5a33('0x46')]){_0x377efe[_0x5a33('0x47')]=[{'all':!![]}];}return db[_0x5a33('0x45')][_0x5a33('0x48')](_0x377efe);})[_0x5a33('0x15')](function(_0x179215){_0x368fc9['rows']=_0x179215;return _0x368fc9;})[_0x5a33('0x15')](respondWithFilteredResult(_0x29a486,_0x377efe))[_0x5a33('0x1f')](handleError(_0x29a486,null));};exports['show']=function(_0x3e3a7f,_0x1d174d){var _0x5c8033={'raw':!![],'where':{'id':_0x3e3a7f[_0x5a33('0x49')]['id']}},_0x143edd={};_0x143edd['model']=_[_0x5a33('0x36')](db['MailMessage']['rawAttributes']);_0x143edd['query']=_[_0x5a33('0x36')](_0x3e3a7f['query']);_0x143edd['filters']=_[_0x5a33('0x37')](_0x143edd['model'],_0x143edd[_0x5a33('0x35')]);_0x5c8033[_0x5a33('0x38')]=_[_0x5a33('0x37')](_0x143edd[_0x5a33('0x34')],qs['fields'](_0x3e3a7f[_0x5a33('0x35')][_0x5a33('0x39')]));_0x5c8033[_0x5a33('0x38')]=_0x5c8033[_0x5a33('0x38')][_0x5a33('0x3a')]?_0x5c8033['attributes']:_0x143edd[_0x5a33('0x34')];if(_0x3e3a7f[_0x5a33('0x35')]['includeAll']){_0x5c8033[_0x5a33('0x47')]=[{'all':!![]}];}_0x5c8033=_[_0x5a33('0x43')]({},_0x5c8033,_0x3e3a7f[_0x5a33('0x44')]);return db['MailMessage'][_0x5a33('0x4a')](_0x5c8033)['then'](handleEntityNotFound(_0x1d174d,null))['then'](respondWithResult(_0x1d174d,null))['catch'](handleError(_0x1d174d,null));};exports[_0x5a33('0x28')]=function(_0x3c6b92,_0x25a894){if(_0x3c6b92['body']['id']){delete _0x3c6b92['body']['id'];}return db['MailMessage'][_0x5a33('0x4a')]({'where':{'id':_0x3c6b92['params']['id']}})['then'](handleEntityNotFound(_0x25a894,null))[_0x5a33('0x15')](saveUpdates(_0x3c6b92[_0x5a33('0x4b')],null))[_0x5a33('0x15')](respondWithResult(_0x25a894,null))[_0x5a33('0x1f')](handleError(_0x25a894,null));};exports[_0x5a33('0x29')]=function(_0x88a906,_0x32dfd9){return db[_0x5a33('0x45')][_0x5a33('0x4a')]({'where':{'id':_0x88a906[_0x5a33('0x49')]['id']}})[_0x5a33('0x15')](handleEntityNotFound(_0x32dfd9,null))['then'](removeEntity(_0x32dfd9,null))[_0x5a33('0x1f')](handleError(_0x32dfd9,null));};exports[_0x5a33('0x4c')]=function(_0x19f660,_0x4958d1){return db[_0x5a33('0x45')][_0x5a33('0x4c')]()[_0x5a33('0x15')](respondWithResult(_0x4958d1,null))[_0x5a33('0x1f')](handleError(_0x4958d1,null));};exports['create']=function(_0x1c7ecb,_0x111271){return db[_0x5a33('0x45')]['create'](_0x1c7ecb[_0x5a33('0x4b')])['then'](function(_0x2d4aa3){if(_0x2d4aa3){if(_0x2d4aa3[_0x5a33('0x4d')]===_0x5a33('0x4e')&&!_0x2d4aa3['secret']){var _0x4211d0,_0x56f456,_0x40438d;if(_0x1c7ecb[_0x5a33('0x4b')]['to']){_0x56f456=_0x1c7ecb['body']['to'][_0x5a33('0x4f')](',')[0x0];}return db['MailAccount'][_0x5a33('0x50')]({'where':{'id':_0x2d4aa3[_0x5a33('0x51')]},'include':[{'model':db['CmList'],'as':_0x5a33('0x52'),'include':[{'model':db[_0x5a33('0x53')],'as':_0x5a33('0x54'),'where':{'email':_0x56f456},'limit':0x1,'order':[[_0x5a33('0x55'),_0x5a33('0x56')]]}]},{'model':db[_0x5a33('0x57')],'as':'Smtp','raw':!![],'include':[{'model':db['CloudProvider'],'as':'CloudProvider','raw':!![]}]}]})[_0x5a33('0x15')](function(_0x3a914f){_0x4211d0=_0x3a914f;if(!_0x4211d0||!_0x4211d0[_0x5a33('0x58')])return;var _0x1ad0c1=_0x4211d0['getSmtpOptions']();if(_0x1c7ecb[_0x5a33('0x4b')][_0x5a33('0x59')]&&_0x1c7ecb[_0x5a33('0x4b')][_0x5a33('0x59')][_0x5a33('0x3a')]){for(var _0x240114=0x0;_0x240114<_0x1c7ecb[_0x5a33('0x4b')][_0x5a33('0x59')]['length'];_0x240114+=0x1){_0x1c7ecb[_0x5a33('0x4b')][_0x5a33('0x59')][_0x240114]={'filename':_0x1c7ecb[_0x5a33('0x4b')]['attachments'][_0x240114][_0x5a33('0x2c')],'path':path[_0x5a33('0x5a')](config[_0x5a33('0x5b')],_0x5a33('0x5c'),_0x1c7ecb[_0x5a33('0x4b')]['attachments'][_0x240114][_0x5a33('0x5d')])};}}_0x40438d={'account':_0x1ad0c1,'message':_0x1c7ecb['body']};return;})['then'](function(){if(_0x4211d0[_0x5a33('0x52')]){if(_0x4211d0['List'][_0x5a33('0x54')]['length']){return _0x4211d0[_0x5a33('0x52')][_0x5a33('0x54')][0x0];}else{return db[_0x5a33('0x53')][_0x5a33('0x5e')](_[_0x5a33('0xd')](_0x1c7ecb[_0x5a33('0x4b')],{'firstName':_0x1c7ecb[_0x5a33('0x4b')]['to'],'email':_0x1c7ecb['body']['to'],'phone':_0x1c7ecb[_0x5a33('0x4b')]['to'],'ListId':_0x4211d0[_0x5a33('0x5f')]}));}}else{throw new Error(_0x5a33('0x60'));}})['then'](function(){if(_0x40438d){return respondWithRpcPromise(_0x5a33('0x61'),_0x5a33('0x62'),_0x40438d,client9003)[_0x5a33('0x15')](function(_0x3b73ac){return _0x2d4aa3['update']({'read':!![],'messageId':_0x3b73ac[_0x5a33('0x63')],'sentAt':moment()[_0x5a33('0x64')](_0x5a33('0x65'))});})[_0x5a33('0x1f')](function(_0x5767de){logger[_0x5a33('0x1b')]('%s',JSON[_0x5a33('0x1a')](_0x5767de));return _0x2d4aa3;});}return _0x2d4aa3;});}return _0x2d4aa3;}})[_0x5a33('0x15')](respondWithResult(_0x111271,0xc9))[_0x5a33('0x1f')](handleError(_0x111271,null));};exports[_0x5a33('0x66')]=function(_0x181f6d,_0x2ac05a){var _0x253570={'agent':{},'channel':_0x5a33('0x67')};if(_0x181f6d['body']['id']){delete _0x181f6d['body']['id'];}_0x181f6d[_0x5a33('0x4b')][_0x5a33('0x68')]=!![];_0x181f6d[_0x5a33('0x4b')][_0x5a33('0x69')]=moment()[_0x5a33('0x64')](_0x5a33('0x65'));_0x181f6d[_0x5a33('0x4b')]['UserId']=_0x181f6d['body']['UserId']||_0x181f6d['user']['id'];_0x253570[_0x5a33('0x6a')]['id']=_0x181f6d[_0x5a33('0x4b')][_0x5a33('0x6b')];return db[_0x5a33('0x45')][_0x5a33('0x4a')]({'where':{'id':_0x181f6d[_0x5a33('0x49')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x2ac05a,null))['then'](saveUpdates(_0x181f6d[_0x5a33('0x4b')],null))[_0x5a33('0x15')](function(_0x49a549){if(_0x49a549){_0x253570[_0x5a33('0x1d')]=_0x49a549[_0x5a33('0x6c')]({'plain':!![]});return db[_0x5a33('0x6d')][_0x5a33('0x4a')]({'where':{'id':_0x49a549[_0x5a33('0x6e')]}});}return null;})[_0x5a33('0x15')](handleEntityNotFound(_0x2ac05a,null))[_0x5a33('0x15')](function(_0x56039a){if(_0x56039a){return _0x56039a[_0x5a33('0x28')]({'UserId':_0x181f6d['body'][_0x5a33('0x6b')],'read1stAt':_[_0x5a33('0x6f')](_0x56039a[_0x5a33('0x70')])?moment()[_0x5a33('0x64')](_0x5a33('0x65')):undefined});}return null;})[_0x5a33('0x15')](function(_0x480dc4){if(_0x480dc4){_0x253570[_0x5a33('0x71')]=_0x480dc4[_0x5a33('0x6c')]({'plain':!![]});interaction_log[_0x5a33('0x16')](_0x5a33('0x72'),_0x181f6d[_0x5a33('0x73')]['id'],_0x181f6d['user'][_0x5a33('0x2c')],_0x181f6d[_0x5a33('0x73')][_0x5a33('0x74')],_0x253570[_0x5a33('0x71')]['id'],_0x181f6d[_0x5a33('0x4b')]?JSON[_0x5a33('0x1a')](_0x181f6d[_0x5a33('0x4b')]):_0x5a33('0x75'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x253570);}return null;})[_0x5a33('0x15')](function(_0x3b1bdb){var _0xdf286b=_0x5a33('0x76')+_0x3b1bdb[_0x5a33('0x1d')][_0x5a33('0x77')];return db[_0x5a33('0x78')]['query'](_0xdf286b,{'type':db[_0x5a33('0x79')][_0x5a33('0x7a')][_0x5a33('0x7b')],'raw':!![]})[_0x5a33('0x15')](function(_0x5d192a){return _0x5d192a;});})[_0x5a33('0x15')](function(_0x5aecb5){if(_0x5aecb5){_0x253570['message'][_0x5a33('0x7c')]=_0x5aecb5[0x0];if(!_0x181f6d['body'][_0x5a33('0x6b')])return;return db['User'][_0x5a33('0x4a')]({'where':{'id':_0x181f6d[_0x5a33('0x4b')]['UserId'],'role':_0x5a33('0x6a')},'attributes':['id',_0x5a33('0x2c'),'fullname',_0x5a33('0x7d'),'internal'],'raw':!![]});}return null;})[_0x5a33('0x15')](function(_0x237b6f){if(!_0x237b6f)return null;_0x253570[_0x5a33('0x1d')][_0x5a33('0x6a')]=_0x237b6f;return _0x253570;})[_0x5a33('0x15')](function(_0x4aacc9){if(_0x4aacc9){if(_0x181f6d[_0x5a33('0x4b')]['manual']){_0x253570[_0x5a33('0x1d')][_0x5a33('0x7e')]=util[_0x5a33('0x64')]('SIP/%s',_0x181f6d[_0x5a33('0x73')]['name']);_0x253570[_0x5a33('0x1d')][_0x5a33('0x7f')]=_0x253570[_0x5a33('0x7f')];_0x253570['message']['motionChannel']=_0x253570[_0x5a33('0x7f')];_0x253570[_0x5a33('0x1d')][_0x5a33('0x80')]=_0x5a33('0x66');_0x253570[_0x5a33('0x1d')][_0x5a33('0x4b')]=htmlToText[_0x5a33('0x81')](_0x253570['message'][_0x5a33('0x4b')]);return respondWithRpcPromise(_0x5a33('0x82'),'EventManager',{'event':'acceptmessage','message':_0x253570['message']},client9002)[_0x5a33('0x15')](function(){return _0x253570;});}return _0x253570;}return null;})[_0x5a33('0x15')](respondWithResult(_0x2ac05a,null))[_0x5a33('0x1f')](handleError(_0x2ac05a,null));};exports['reject']=function(_0x1159df,_0x4e7d8d){var _0xa8edc1={'agent':{},'channel':_0x5a33('0x67')};if(_0x1159df[_0x5a33('0x4b')]['id']){delete _0x1159df[_0x5a33('0x4b')]['id'];}_0x1159df[_0x5a33('0x4b')]['UserId']=_0x1159df['body'][_0x5a33('0x6b')]||_0x1159df['user']['id'];_0xa8edc1[_0x5a33('0x6a')]['id']=_0x1159df['body'][_0x5a33('0x6b')];return db[_0x5a33('0x45')][_0x5a33('0x4a')]({'where':{'id':_0x1159df[_0x5a33('0x49')]['id'],'UserId':null}})[_0x5a33('0x15')](handleEntityNotFound(_0x4e7d8d,null))['then'](function(_0x4602f3){if(_0x4602f3){_0xa8edc1[_0x5a33('0x1d')]=_0x4602f3[_0x5a33('0x6c')]({'plain':!![]});return db[_0x5a33('0x6d')]['find']({'where':{'id':_0x4602f3['MailInteractionId']}});}return null;})[_0x5a33('0x15')](handleEntityNotFound(_0x4e7d8d,null))[_0x5a33('0x15')](function(_0x3eb01f){if(_0x3eb01f){_0xa8edc1[_0x5a33('0x71')]=_0x3eb01f[_0x5a33('0x6c')]({'plain':!![]});interaction_log[_0x5a33('0x16')](_0x5a33('0x83'),_0x1159df[_0x5a33('0x73')]['id'],_0x1159df[_0x5a33('0x73')][_0x5a33('0x2c')],_0x1159df[_0x5a33('0x73')][_0x5a33('0x74')],_0xa8edc1['interaction']['id'],_0x1159df[_0x5a33('0x4b')]?JSON['stringify'](_0x1159df['body']):_0x5a33('0x75'));return respondWithRpcPromise(_0x5a33('0x84'),'rejectMessage',_0xa8edc1);}return null;})[_0x5a33('0x15')](function(_0x14fd9b){var _0x354e5b=_0x5a33('0x76')+_0x14fd9b[_0x5a33('0x1d')]['ContactId'];return db[_0x5a33('0x78')][_0x5a33('0x35')](_0x354e5b,{'type':db[_0x5a33('0x79')][_0x5a33('0x7a')][_0x5a33('0x7b')],'raw':!![]})[_0x5a33('0x15')](function(_0x428516){return _0x428516;});})[_0x5a33('0x15')](function(_0x393c2c){if(_0x393c2c){_0xa8edc1[_0x5a33('0x1d')][_0x5a33('0x7c')]=_0x393c2c[0x0];if(!_0x1159df[_0x5a33('0x4b')][_0x5a33('0x6b')])return;return db['User'][_0x5a33('0x4a')]({'where':{'id':_0x1159df[_0x5a33('0x4b')][_0x5a33('0x6b')],'role':_0x5a33('0x6a')},'attributes':['id',_0x5a33('0x2c'),_0x5a33('0x85'),_0x5a33('0x7d'),_0x5a33('0x86')],'raw':!![]});}return null;})[_0x5a33('0x15')](function(_0x38ea89){if(!_0x38ea89)return null;_0xa8edc1[_0x5a33('0x1d')][_0x5a33('0x6a')]=_0x38ea89;return _0xa8edc1;})[_0x5a33('0x15')](function(_0x1ed043){if(_0x1ed043){_0x1ed043[_0x5a33('0x1d')][_0x5a33('0x7e')]=util['format'](_0x5a33('0x87'),_0x1159df[_0x5a33('0x73')]['name']);_0x1ed043['message'][_0x5a33('0x7f')]=_0xa8edc1[_0x5a33('0x7f')];_0x1ed043[_0x5a33('0x1d')][_0x5a33('0x88')]=_0xa8edc1[_0x5a33('0x7f')];_0x1ed043[_0x5a33('0x1d')]['event']=_0x5a33('0x89');_0x1ed043['message'][_0x5a33('0x4b')]=htmlToText[_0x5a33('0x81')](_0xa8edc1[_0x5a33('0x1d')]['body']);respondWithRpcPromise(_0x5a33('0x82'),_0x5a33('0x82'),{'event':_0x5a33('0x8a'),'message':_0x1ed043[_0x5a33('0x1d')]},client9002);return _0xa8edc1;}return null;})['then'](respondWithResult(_0x4e7d8d,null))[_0x5a33('0x1f')](handleError(_0x4e7d8d,null));};exports[_0x5a33('0x8b')]=function(_0x587690,_0xeb9b5b){var _0x20d97d=moment()[_0x5a33('0x8c')]()['toString']();var _0x49a3cd=path['join'](config['root'],_0x5a33('0x8d'),_0x5a33('0x8e'),'tmp');var _0x19be08=path[_0x5a33('0x5a')](config[_0x5a33('0x5b')],_0x5a33('0x8d'),'files',_0x5a33('0x59'));var _0x3b60d7=util['format']('message-%s.eml',_0x20d97d);return db[_0x5a33('0x45')][_0x5a33('0x4a')]({'where':{'id':_0x587690[_0x5a33('0x49')]['id']},'attributes':['id',_0x5a33('0x4b'),_0x5a33('0x8f'),'to','cc',_0x5a33('0x90'),_0x5a33('0x91'),'createdAt'],'include':_0x587690['query'][_0x5a33('0x59')]?[{'model':db[_0x5a33('0x92')],'as':_0x5a33('0x93')}]:undefined})['then'](handleEntityNotFound(_0xeb9b5b,null))[_0x5a33('0x15')](function(_0x48d339){if(_0x48d339){var _0x5e6ff8=_0x48d339;var _0x52820d={'from':_0x5e6ff8[_0x5a33('0x8f')],'to':_0x5e6ff8['to'],'subject':_0x5e6ff8['subject'],'html':htmlEntities[_0x5a33('0x94')](_0x5e6ff8[_0x5a33('0x4b')]),'headers':{'Date':moment(_0x5e6ff8[_0x5a33('0x95')])['format'](_0x5a33('0x96'))},'attachments':[]};if(_0x48d339['cc']){_0x52820d[_0x5a33('0x97')]['Cc']=_0x48d339['cc'];}if(_0x48d339[_0x5a33('0x90')]){_0x52820d[_0x5a33('0x97')][_0x5a33('0x98')]=_0x48d339[_0x5a33('0x90')];}return new BPromise(function(_0x1c9476,_0xe081e0){if(_0x48d339[_0x5a33('0x93')]){for(var _0x2dd463=0x0;_0x2dd463<_0x48d339[_0x5a33('0x93')][_0x5a33('0x3a')];_0x2dd463++){var _0x426a9a=_0x48d339['Attachments'][_0x2dd463];var _0x382a30=path[_0x5a33('0x5a')](_0x19be08,_0x426a9a[_0x5a33('0x5d')]);if(fs[_0x5a33('0x99')](_0x382a30)){_0x52820d['attachments'][_0x5a33('0x9a')]({'name':_0x426a9a[_0x5a33('0x2c')],'contentType':_0x426a9a[_0x5a33('0x32')],'data':fs['readFileSync'](_0x382a30)});}}}emlformat[_0x5a33('0x9b')](_0x52820d,function(_0x2f526d,_0x358a11){if(_0x2f526d)return _0xe081e0(_0x2f526d);fs[_0x5a33('0x9c')](path[_0x5a33('0x5a')](_0x49a3cd,_0x3b60d7),_0x358a11);return _0x1c9476(_0x358a11);});});}})[_0x5a33('0x15')](function(_0x398d22){if(_0x398d22){return _0xeb9b5b['download'](path['join'](_0x49a3cd,_0x3b60d7),_0x3b60d7,function(_0x25b571){if(!_0x25b571)fs[_0x5a33('0x9d')](path['join'](_0x49a3cd,_0x3b60d7));});}})[_0x5a33('0x1f')](handleError(_0xeb9b5b,null));};
\ No newline at end of file