Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index ddd701f..70048c7 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 _0xa0e1=['err','rimraf','zip-dir','request-promise','moment','bluebird','util','path','sox','ejs','fs-extra','lodash','squel','jsforce','querystring','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','./mailMessage.socket','register','client','http','request','then','info','MailMessage,\x20%s,\x20%s','debug','stringify','error','code','message','request\x20sent','result','catch','sendStatus','status','offset','undefined','limit','count','set','Content-Range','json','apply','reject','destroy','send','index','map','MailMessage','rawAttributes','fieldName','type','key','model','name','keys','query','filters','intersection','fields','attributes','length','hasOwnProperty','sort','where','pick','filter','VIRTUAL','merge','findAll','rows','show','params','include','options','find','body','out','secret','split','MailAccount','findOne','MailAccountId','CmList','List','CmContact','Contacts','DESC','MailServerOut','Smtp','isNil','service','host','port','secure','auth','user','attachments','root','server/files/attachments','basename','create','ListId','SendMail','sendMail','update','messageId','format','YYYY-MM-DD\x20HH:mm:ss','../../config/logger','accept','read','readAt','UserId','agent','Contact','MailInteraction','MailInteractionId','interaction','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','AcceptMessage','acceptMessage','manual','interface','channel','event','EventManager','acceptmessage','mail-interactions','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','rejectmessage','download','unix','toString','join','tmp','server','message-%s.eml','from','subject','createdAt','Attachment','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','bcc','readFileSync','writeFileSync','log'];(function(_0xcf351e,_0x4037d2){var _0x29e9c4=function(_0xdba9a){while(--_0xdba9a){_0xcf351e['push'](_0xcf351e['shift']());}};_0x29e9c4(++_0x4037d2);}(_0xa0e1,0x14d));var _0x1a0e=function(_0x291d28,_0x4f0710){_0x291d28=_0x291d28-0x0;var _0x2cf6a5=_0xa0e1[_0x291d28];return _0x2cf6a5;};'use strict';var emlformat=require('eml-format');var rimraf=require(_0x1a0e('0x0'));var zipdir=require(_0x1a0e('0x1'));var jsonpatch=require('fast-json-patch');var rp=require(_0x1a0e('0x2'));var moment=require(_0x1a0e('0x3'));var BPromise=require(_0x1a0e('0x4'));var Mustache=require('mustache');var util=require(_0x1a0e('0x5'));var path=require(_0x1a0e('0x6'));var sox=require(_0x1a0e('0x7'));var csv=require('to-csv');var ejs=require(_0x1a0e('0x8'));var fs=require('fs');var fs_extra=require(_0x1a0e('0x9'));var _=require(_0x1a0e('0xa'));var squel=require(_0x1a0e('0xb'));var crypto=require('crypto');var jsforce=require(_0x1a0e('0xc'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require(_0x1a0e('0xd'));var Papa=require(_0x1a0e('0xe'));var Redis=require(_0x1a0e('0xf'));var authService=require(_0x1a0e('0x10'));var qs=require(_0x1a0e('0x11'));var as=require(_0x1a0e('0x12'));var hardwareService=require(_0x1a0e('0x13'));var logger=require('../../config/logger')('api');var utils=require(_0x1a0e('0x14'));var config=require(_0x1a0e('0x15'));var licenseUtil=require(_0x1a0e('0x16'));var db=require(_0x1a0e('0x17'))['db'];config['redis']=_[_0x1a0e('0x18')](config[_0x1a0e('0x19')],{'host':_0x1a0e('0x1a'),'port':0x18eb});var socket=require(_0x1a0e('0x1b'))(new Redis(config[_0x1a0e('0x19')]));require(_0x1a0e('0x1c'))[_0x1a0e('0x1d')](socket);var jayson=require('jayson/promise');var client=jayson[_0x1a0e('0x1e')][_0x1a0e('0x1f')]({'port':0x232c});var client9003=jayson[_0x1a0e('0x1e')]['http']({'port':0x232b});var client9002=jayson[_0x1a0e('0x1e')][_0x1a0e('0x1f')]({'port':0x232a});function respondWithRpcPromise(_0x216edc,_0x39ff66,_0x81d448,_0x201f89){return new BPromise(function(_0x413aea,_0x1f4173){var _0x1bfd09=_0x201f89||client;return _0x1bfd09[_0x1a0e('0x20')](_0x216edc,_0x81d448)[_0x1a0e('0x21')](function(_0x309e3e){logger[_0x1a0e('0x22')](_0x1a0e('0x23'),_0x39ff66,'request\x20sent');logger[_0x1a0e('0x24')]('MailMessage,\x20%s,\x20%s,\x20%s',_0x39ff66,'request\x20sent',JSON[_0x1a0e('0x25')](_0x309e3e));if(_0x309e3e['error']){if(_0x309e3e[_0x1a0e('0x26')][_0x1a0e('0x27')]===0x1f4){logger[_0x1a0e('0x26')](_0x1a0e('0x23'),_0x39ff66,_0x309e3e['error'][_0x1a0e('0x28')]);return _0x1f4173(_0x309e3e[_0x1a0e('0x26')][_0x1a0e('0x28')]);}logger['error'](_0x1a0e('0x23'),_0x39ff66,_0x309e3e['error'][_0x1a0e('0x28')]);return _0x413aea(_0x309e3e[_0x1a0e('0x26')]['message']);}else{logger[_0x1a0e('0x22')](_0x1a0e('0x23'),_0x39ff66,_0x1a0e('0x29'));_0x413aea(_0x309e3e[_0x1a0e('0x2a')][_0x1a0e('0x28')]);}})[_0x1a0e('0x2b')](function(_0x1ff36b){logger[_0x1a0e('0x26')]('MailMessage,\x20%s,\x20%s',_0x39ff66,_0x1ff36b);_0x1f4173(_0x1ff36b);});});}function respondWithStatusCode(_0x28a641,_0x21353b){_0x21353b=_0x21353b||0xcc;return function(_0xe57a83){if(_0xe57a83){return _0x28a641[_0x1a0e('0x2c')](_0x21353b);}return _0x28a641[_0x1a0e('0x2d')](_0x21353b)['end']();};}function respondWithResult(_0x3dffa9,_0x6d331a){_0x6d331a=_0x6d331a||0xc8;return function(_0x406b1c){if(_0x406b1c){return _0x3dffa9[_0x1a0e('0x2d')](_0x6d331a)['json'](_0x406b1c);}};}function respondWithFilteredResult(_0x43867c,_0x478b4d){return function(_0x954613){if(_0x954613){var _0x4e5932=typeof _0x478b4d[_0x1a0e('0x2e')]===_0x1a0e('0x2f')&&typeof _0x478b4d[_0x1a0e('0x30')]===_0x1a0e('0x2f');var _0x53fac5=_0x954613[_0x1a0e('0x31')];var _0x312a6e=_0x4e5932?0x0:_0x478b4d[_0x1a0e('0x2e')];var _0x5df909=_0x4e5932?_0x954613['count']:_0x478b4d[_0x1a0e('0x2e')]+_0x478b4d[_0x1a0e('0x30')];var _0x335c55;if(_0x5df909>=_0x53fac5){_0x5df909=_0x53fac5;_0x335c55=0xc8;}else{_0x335c55=0xce;}_0x43867c[_0x1a0e('0x2d')](_0x335c55);return _0x43867c[_0x1a0e('0x32')](_0x1a0e('0x33'),_0x312a6e+'-'+_0x5df909+'/'+_0x53fac5)[_0x1a0e('0x34')](_0x954613);}return null;};}function patchUpdates(_0x5f3b22){return function(_0x40b94d){try{jsonpatch[_0x1a0e('0x35')](_0x40b94d,_0x5f3b22,!![]);}catch(_0x3a7952){return BPromise[_0x1a0e('0x36')](_0x3a7952);}return _0x40b94d['save']();};}function saveUpdates(_0x104a7c,_0x1b977e){return function(_0x21b206){if(_0x21b206){return _0x21b206['update'](_0x104a7c)[_0x1a0e('0x21')](function(_0x235e1b){return _0x235e1b;});}return null;};}function removeEntity(_0x5517be,_0x2d8c43){return function(_0x15b9fa){if(_0x15b9fa){return _0x15b9fa[_0x1a0e('0x37')]()[_0x1a0e('0x21')](function(){_0x5517be[_0x1a0e('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x229c04,_0xc0bfe0){return function(_0x139b2b){if(!_0x139b2b){_0x229c04[_0x1a0e('0x2c')](0x194);}return _0x139b2b;};}function handleError(_0x3ca1ec,_0xaa8e86){_0xaa8e86=_0xaa8e86||0x1f4;return function(_0x59da35){logger['error'](_0x59da35['stack']);if(_0x59da35['name']){delete _0x59da35['name'];}_0x3ca1ec['status'](_0xaa8e86)[_0x1a0e('0x38')](_0x59da35);};}exports[_0x1a0e('0x39')]=function(_0x299790,_0x569a1b){var _0x5d51f2={},_0x2fd6a0={},_0x5040af={'count':0x0,'rows':[]};var _0x11137e=_[_0x1a0e('0x3a')](db[_0x1a0e('0x3b')][_0x1a0e('0x3c')],function(_0x581f25){return{'name':_0x581f25[_0x1a0e('0x3d')],'type':_0x581f25[_0x1a0e('0x3e')][_0x1a0e('0x3f')]};});_0x2fd6a0[_0x1a0e('0x40')]=_[_0x1a0e('0x3a')](_0x11137e,_0x1a0e('0x41'));_0x2fd6a0['query']=_[_0x1a0e('0x42')](_0x299790[_0x1a0e('0x43')]);_0x2fd6a0[_0x1a0e('0x44')]=_[_0x1a0e('0x45')](_0x2fd6a0[_0x1a0e('0x40')],_0x2fd6a0[_0x1a0e('0x43')]);_0x5d51f2['attributes']=_[_0x1a0e('0x45')](_0x2fd6a0['model'],qs[_0x1a0e('0x46')](_0x299790[_0x1a0e('0x43')][_0x1a0e('0x46')]));_0x5d51f2[_0x1a0e('0x47')]=_0x5d51f2[_0x1a0e('0x47')][_0x1a0e('0x48')]?_0x5d51f2['attributes']:_0x2fd6a0[_0x1a0e('0x40')];if(!_0x299790[_0x1a0e('0x43')][_0x1a0e('0x49')]('nolimit')){_0x5d51f2[_0x1a0e('0x30')]=qs[_0x1a0e('0x30')](_0x299790['query'][_0x1a0e('0x30')]);_0x5d51f2[_0x1a0e('0x2e')]=qs['offset'](_0x299790['query'][_0x1a0e('0x2e')]);}_0x5d51f2['order']=qs[_0x1a0e('0x4a')](_0x299790[_0x1a0e('0x43')][_0x1a0e('0x4a')]);_0x5d51f2[_0x1a0e('0x4b')]=qs[_0x1a0e('0x44')](_[_0x1a0e('0x4c')](_0x299790[_0x1a0e('0x43')],_0x2fd6a0[_0x1a0e('0x44')]),_0x11137e);if(_0x299790['query'][_0x1a0e('0x4d')]){_0x5d51f2['where']=_['merge'](_0x5d51f2[_0x1a0e('0x4b')],{'$or':_[_0x1a0e('0x3a')](_0x11137e,function(_0x268e01){if(_0x268e01[_0x1a0e('0x3e')]!==_0x1a0e('0x4e')){var _0x3b66a8={};_0x3b66a8[_0x268e01[_0x1a0e('0x41')]]={'$like':'%'+_0x299790[_0x1a0e('0x43')][_0x1a0e('0x4d')]+'%'};return _0x3b66a8;}})});}_0x5d51f2=_[_0x1a0e('0x4f')]({},_0x5d51f2,_0x299790['options']);var _0x17a4bc={'where':_0x5d51f2['where']};return db[_0x1a0e('0x3b')][_0x1a0e('0x31')](_0x17a4bc)[_0x1a0e('0x21')](function(_0x42cd50){_0x5040af[_0x1a0e('0x31')]=_0x42cd50;if(_0x299790['query']['includeAll']){_0x5d51f2['include']=[{'all':!![]}];}return db[_0x1a0e('0x3b')][_0x1a0e('0x50')](_0x5d51f2);})[_0x1a0e('0x21')](function(_0x2a1e41){_0x5040af[_0x1a0e('0x51')]=_0x2a1e41;return _0x5040af;})['then'](respondWithFilteredResult(_0x569a1b,_0x5d51f2))[_0x1a0e('0x2b')](handleError(_0x569a1b,null));};exports[_0x1a0e('0x52')]=function(_0x58bd85,_0x1faf8a){var _0x13f2e3={'raw':!![],'where':{'id':_0x58bd85[_0x1a0e('0x53')]['id']}},_0x5b2daa={};_0x5b2daa[_0x1a0e('0x40')]=_[_0x1a0e('0x42')](db[_0x1a0e('0x3b')][_0x1a0e('0x3c')]);_0x5b2daa[_0x1a0e('0x43')]=_['keys'](_0x58bd85[_0x1a0e('0x43')]);_0x5b2daa[_0x1a0e('0x44')]=_[_0x1a0e('0x45')](_0x5b2daa[_0x1a0e('0x40')],_0x5b2daa[_0x1a0e('0x43')]);_0x13f2e3[_0x1a0e('0x47')]=_['intersection'](_0x5b2daa[_0x1a0e('0x40')],qs[_0x1a0e('0x46')](_0x58bd85[_0x1a0e('0x43')][_0x1a0e('0x46')]));_0x13f2e3[_0x1a0e('0x47')]=_0x13f2e3[_0x1a0e('0x47')][_0x1a0e('0x48')]?_0x13f2e3['attributes']:_0x5b2daa[_0x1a0e('0x40')];if(_0x58bd85['query']['includeAll']){_0x13f2e3[_0x1a0e('0x54')]=[{'all':!![]}];}_0x13f2e3=_[_0x1a0e('0x4f')]({},_0x13f2e3,_0x58bd85[_0x1a0e('0x55')]);return db['MailMessage'][_0x1a0e('0x56')](_0x13f2e3)[_0x1a0e('0x21')](handleEntityNotFound(_0x1faf8a,null))[_0x1a0e('0x21')](respondWithResult(_0x1faf8a,null))[_0x1a0e('0x2b')](handleError(_0x1faf8a,null));};exports['update']=function(_0x3e4260,_0x2a7c7b){if(_0x3e4260[_0x1a0e('0x57')]['id']){delete _0x3e4260[_0x1a0e('0x57')]['id'];}return db[_0x1a0e('0x3b')][_0x1a0e('0x56')]({'where':{'id':_0x3e4260[_0x1a0e('0x53')]['id']}})[_0x1a0e('0x21')](handleEntityNotFound(_0x2a7c7b,null))[_0x1a0e('0x21')](saveUpdates(_0x3e4260[_0x1a0e('0x57')],null))[_0x1a0e('0x21')](respondWithResult(_0x2a7c7b,null))[_0x1a0e('0x2b')](handleError(_0x2a7c7b,null));};exports[_0x1a0e('0x37')]=function(_0x584a6a,_0x130374){return db[_0x1a0e('0x3b')][_0x1a0e('0x56')]({'where':{'id':_0x584a6a[_0x1a0e('0x53')]['id']}})[_0x1a0e('0x21')](handleEntityNotFound(_0x130374,null))[_0x1a0e('0x21')](removeEntity(_0x130374,null))['catch'](handleError(_0x130374,null));};exports['describe']=function(_0x281c03,_0x151671){return db['MailMessage']['describe']()[_0x1a0e('0x21')](respondWithResult(_0x151671,null))[_0x1a0e('0x2b')](handleError(_0x151671,null));};exports['create']=function(_0xebe19d,_0x205d09){return db[_0x1a0e('0x3b')]['create'](_0xebe19d[_0x1a0e('0x57')])[_0x1a0e('0x21')](function(_0x165c99){if(_0x165c99){if(_0x165c99['direction']===_0x1a0e('0x58')&&!_0x165c99[_0x1a0e('0x59')]){var _0x4721c1,_0x3b8265,_0x36e67d;if(_0xebe19d['body']['to']){_0x3b8265=_0xebe19d[_0x1a0e('0x57')]['to'][_0x1a0e('0x5a')](',')[0x0];}return db[_0x1a0e('0x5b')][_0x1a0e('0x5c')]({'where':{'id':_0x165c99[_0x1a0e('0x5d')]},'include':[{'model':db[_0x1a0e('0x5e')],'as':_0x1a0e('0x5f'),'include':[{'model':db[_0x1a0e('0x60')],'as':_0x1a0e('0x61'),'where':{'email':_0x3b8265},'limit':0x1,'order':[['updatedAt',_0x1a0e('0x62')]]}]},{'model':db[_0x1a0e('0x63')],'as':_0x1a0e('0x64'),'raw':!![]}]})[_0x1a0e('0x21')](function(_0x2679ed){_0x4721c1=_0x2679ed;if(_0x4721c1&&_0x4721c1[_0x1a0e('0x64')]){var _0x19f25a={'tls':{'rejectUnauthorized':![]}};if(_[_0x1a0e('0x65')](_0x4721c1[_0x1a0e('0x64')][_0x1a0e('0x66')])){_0x19f25a[_0x1a0e('0x67')]=_0x4721c1[_0x1a0e('0x64')]['host'];_0x19f25a[_0x1a0e('0x68')]=_0x4721c1[_0x1a0e('0x64')][_0x1a0e('0x68')];_0x19f25a[_0x1a0e('0x69')]=_0x4721c1[_0x1a0e('0x64')][_0x1a0e('0x69')];if(_0x4721c1['Smtp']['authentication']){_0x19f25a[_0x1a0e('0x6a')]={'user':_0x4721c1[_0x1a0e('0x64')][_0x1a0e('0x6b')],'pass':_0x4721c1[_0x1a0e('0x64')]['pass']};}}else{_0x19f25a[_0x1a0e('0x66')]=_0x4721c1['Smtp'][_0x1a0e('0x66')];_0x19f25a['auth']={'user':_0x4721c1[_0x1a0e('0x64')][_0x1a0e('0x6b')],'pass':_0x4721c1[_0x1a0e('0x64')]['pass']};_0x19f25a[_0x1a0e('0x69')]=_0x4721c1[_0x1a0e('0x64')]['secure'];}if(_0xebe19d[_0x1a0e('0x57')]['attachments']&&_0xebe19d[_0x1a0e('0x57')][_0x1a0e('0x6c')]['length']){for(var _0x35855c=0x0;_0x35855c<_0xebe19d[_0x1a0e('0x57')]['attachments'][_0x1a0e('0x48')];_0x35855c+=0x1){_0xebe19d[_0x1a0e('0x57')][_0x1a0e('0x6c')][_0x35855c]={'filename':_0xebe19d[_0x1a0e('0x57')][_0x1a0e('0x6c')][_0x35855c]['name'],'path':path['join'](config[_0x1a0e('0x6d')],_0x1a0e('0x6e'),_0xebe19d[_0x1a0e('0x57')][_0x1a0e('0x6c')][_0x35855c][_0x1a0e('0x6f')])};}}_0x36e67d={'account':_0x19f25a,'message':_0xebe19d[_0x1a0e('0x57')]};return;}})[_0x1a0e('0x21')](function(){if(_0x4721c1['List']){if(_0x4721c1['List'][_0x1a0e('0x61')][_0x1a0e('0x48')]){return _0x4721c1[_0x1a0e('0x5f')][_0x1a0e('0x61')][0x0];}else{return db[_0x1a0e('0x60')][_0x1a0e('0x70')](_['defaults'](_0xebe19d[_0x1a0e('0x57')],{'firstName':_0xebe19d['body']['to'],'email':_0xebe19d[_0x1a0e('0x57')]['to'],'phone':_0xebe19d['body']['to'],'ListId':_0x4721c1[_0x1a0e('0x71')]}));}}else{throw new Error('List\x20not\x20found');}})[_0x1a0e('0x21')](function(){if(_0x36e67d){return respondWithRpcPromise(_0x1a0e('0x72'),_0x1a0e('0x73'),_0x36e67d,client9003)[_0x1a0e('0x21')](function(_0xe0f2c8){return _0x165c99[_0x1a0e('0x74')]({'read':!![],'messageId':_0xe0f2c8[_0x1a0e('0x75')],'sentAt':moment()[_0x1a0e('0x76')](_0x1a0e('0x77'))});})[_0x1a0e('0x2b')](function(_0xd4773f){logger[_0x1a0e('0x26')]('%s',JSON[_0x1a0e('0x25')](_0xd4773f));return _0x165c99;});}return _0x165c99;});}return _0x165c99;}})[_0x1a0e('0x21')](respondWithResult(_0x205d09,0xc9))[_0x1a0e('0x2b')](handleError(_0x205d09,null));};var interaction_log=require(_0x1a0e('0x78'))('mail-interactions');exports[_0x1a0e('0x79')]=function(_0x2a5ab0,_0x5b7453,_0x469cc2){var _0x297b60={'agent':{},'channel':'mail'};if(_0x2a5ab0['body']['id']){delete _0x2a5ab0[_0x1a0e('0x57')]['id'];}_0x2a5ab0[_0x1a0e('0x57')][_0x1a0e('0x7a')]=!![];_0x2a5ab0[_0x1a0e('0x57')][_0x1a0e('0x7b')]=moment()[_0x1a0e('0x76')](_0x1a0e('0x77'));_0x2a5ab0[_0x1a0e('0x57')][_0x1a0e('0x7c')]=_0x2a5ab0[_0x1a0e('0x57')]['UserId']||_0x2a5ab0['user']['id'];_0x297b60[_0x1a0e('0x7d')]['id']=_0x2a5ab0[_0x1a0e('0x57')][_0x1a0e('0x7c')];return db[_0x1a0e('0x3b')][_0x1a0e('0x56')]({'where':{'id':_0x2a5ab0['params']['id'],'UserId':null},'include':[{'model':db[_0x1a0e('0x60')],'as':_0x1a0e('0x7e')}]})['then'](handleEntityNotFound(_0x5b7453,null))[_0x1a0e('0x21')](saveUpdates(_0x2a5ab0['body'],null))[_0x1a0e('0x21')](function(_0x7e83e2){if(_0x7e83e2){_0x297b60[_0x1a0e('0x28')]=_0x7e83e2['get']({'plain':!![]});return db[_0x1a0e('0x7f')]['find']({'where':{'id':_0x7e83e2[_0x1a0e('0x80')]}});}return null;})[_0x1a0e('0x21')](handleEntityNotFound(_0x5b7453,null))[_0x1a0e('0x21')](function(_0x1358ef){if(_0x1358ef){return _0x1358ef[_0x1a0e('0x74')]({'UserId':_0x2a5ab0['body'][_0x1a0e('0x7c')],'read1stAt':_[_0x1a0e('0x65')](_0x1358ef['read1stAt'])?moment()[_0x1a0e('0x76')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x1a0e('0x21')](function(_0x297531){if(_0x297531){_0x297b60[_0x1a0e('0x81')]=_0x297531[_0x1a0e('0x82')]({'plain':!![]});interaction_log[_0x1a0e('0x22')](_0x1a0e('0x83'),_0x2a5ab0[_0x1a0e('0x6b')]['id'],_0x2a5ab0[_0x1a0e('0x6b')][_0x1a0e('0x41')],_0x2a5ab0[_0x1a0e('0x6b')]['role'],_0x297b60[_0x1a0e('0x81')]['id'],_0x2a5ab0[_0x1a0e('0x57')]?JSON[_0x1a0e('0x25')](_0x2a5ab0[_0x1a0e('0x57')]):_0x1a0e('0x84'));return respondWithRpcPromise(_0x1a0e('0x85'),_0x1a0e('0x86'),_0x297b60);}return null;})['then'](function(_0x539380){if(_0x539380){if(_0x2a5ab0[_0x1a0e('0x57')][_0x1a0e('0x87')]){_0x297b60[_0x1a0e('0x28')][_0x1a0e('0x88')]=util['format']('SIP/%s',_0x2a5ab0['user']['name']);_0x297b60[_0x1a0e('0x28')][_0x1a0e('0x89')]=_0x297b60[_0x1a0e('0x89')];_0x297b60[_0x1a0e('0x28')][_0x1a0e('0x8a')]=_0x1a0e('0x79');return respondWithRpcPromise(_0x1a0e('0x8b'),'EventManager',{'event':_0x1a0e('0x8c'),'message':_0x297b60[_0x1a0e('0x28')]},client9002)[_0x1a0e('0x21')](function(){return _0x297b60;});}return _0x297b60;}return null;})['then'](respondWithResult(_0x5b7453,null))[_0x1a0e('0x2b')](handleError(_0x5b7453,null));};var interaction_log=require(_0x1a0e('0x78'))(_0x1a0e('0x8d'));exports[_0x1a0e('0x36')]=function(_0x2b4adc,_0x13f7e5,_0x2b8542){var _0x391d2c={'agent':{},'channel':'mail'};if(_0x2b4adc[_0x1a0e('0x57')]['id']){delete _0x2b4adc[_0x1a0e('0x57')]['id'];}_0x2b4adc[_0x1a0e('0x57')][_0x1a0e('0x7c')]=_0x2b4adc[_0x1a0e('0x57')][_0x1a0e('0x7c')]||_0x2b4adc[_0x1a0e('0x6b')]['id'];_0x391d2c[_0x1a0e('0x7d')]['id']=_0x2b4adc[_0x1a0e('0x57')][_0x1a0e('0x7c')];return db[_0x1a0e('0x3b')]['find']({'where':{'id':_0x2b4adc[_0x1a0e('0x53')]['id'],'UserId':null}})[_0x1a0e('0x21')](handleEntityNotFound(_0x13f7e5,null))[_0x1a0e('0x21')](function(_0x395da7){if(_0x395da7){_0x391d2c[_0x1a0e('0x28')]=_0x395da7[_0x1a0e('0x82')]({'plain':!![]});return db[_0x1a0e('0x7f')]['find']({'where':{'id':_0x395da7[_0x1a0e('0x80')]}});}return null;})[_0x1a0e('0x21')](handleEntityNotFound(_0x13f7e5,null))['then'](function(_0x3f2841){if(_0x3f2841){_0x391d2c[_0x1a0e('0x81')]=_0x3f2841[_0x1a0e('0x82')]({'plain':!![]});interaction_log[_0x1a0e('0x22')](_0x1a0e('0x8e'),_0x2b4adc[_0x1a0e('0x6b')]['id'],_0x2b4adc['user']['name'],_0x2b4adc[_0x1a0e('0x6b')]['role'],_0x391d2c['interaction']['id'],_0x2b4adc[_0x1a0e('0x57')]?JSON[_0x1a0e('0x25')](_0x2b4adc['body']):_0x1a0e('0x84'));return respondWithRpcPromise(_0x1a0e('0x8f'),_0x1a0e('0x90'),_0x391d2c);}return null;})[_0x1a0e('0x21')](function(_0x476598){if(_0x476598){_0x476598['message'][_0x1a0e('0x88')]=util[_0x1a0e('0x76')]('SIP/%s',_0x2b4adc['user'][_0x1a0e('0x41')]);_0x476598[_0x1a0e('0x28')][_0x1a0e('0x89')]=_0x391d2c[_0x1a0e('0x89')];_0x476598[_0x1a0e('0x28')][_0x1a0e('0x8a')]=_0x1a0e('0x36');respondWithRpcPromise('EventManager',_0x1a0e('0x8b'),{'event':_0x1a0e('0x91'),'message':_0x476598['message']},client9002);return _0x391d2c;}return null;})[_0x1a0e('0x21')](respondWithResult(_0x13f7e5,null))['catch'](handleError(_0x13f7e5,null));};exports[_0x1a0e('0x92')]=function(_0x235391,_0x331c3b){var _0x1dda55=moment()[_0x1a0e('0x93')]()[_0x1a0e('0x94')]();var _0x3f4969=path[_0x1a0e('0x95')](config[_0x1a0e('0x6d')],'server','files',_0x1a0e('0x96'));var _0x128e2c=path[_0x1a0e('0x95')](config[_0x1a0e('0x6d')],_0x1a0e('0x97'),'files',_0x1a0e('0x6c'));var _0x866a3c=util[_0x1a0e('0x76')](_0x1a0e('0x98'),_0x1dda55);return db[_0x1a0e('0x3b')][_0x1a0e('0x56')]({'where':{'id':_0x235391[_0x1a0e('0x53')]['id']},'attributes':['id',_0x1a0e('0x57'),_0x1a0e('0x99'),'to','cc','bcc',_0x1a0e('0x9a'),_0x1a0e('0x9b')],'include':_0x235391[_0x1a0e('0x43')][_0x1a0e('0x6c')]?[{'model':db[_0x1a0e('0x9c')],'as':_0x1a0e('0x9d')}]:undefined})[_0x1a0e('0x21')](handleEntityNotFound(_0x331c3b,null))[_0x1a0e('0x21')](function(_0x2fe01d){if(_0x2fe01d){var _0x3a72ee=_0x2fe01d;var _0x232124={'from':_0x3a72ee[_0x1a0e('0x99')],'to':_0x3a72ee['to'],'subject':_0x3a72ee[_0x1a0e('0x9a')],'html':_0x3a72ee[_0x1a0e('0x57')],'headers':{'Date':moment(_0x3a72ee['createdAt'])[_0x1a0e('0x76')](_0x1a0e('0x9e'))},'attachments':[]};if(_0x2fe01d['cc']){_0x232124[_0x1a0e('0x9f')]['Cc']=_0x2fe01d['cc'];}if(_0x2fe01d['bcc']){_0x232124[_0x1a0e('0x9f')][_0x1a0e('0xa0')]=_0x2fe01d[_0x1a0e('0xa1')];}return new BPromise(function(_0x5a1f36,_0x5185b1){if(_0x2fe01d[_0x1a0e('0x9d')]){for(var _0x525ee7=0x0;_0x525ee7<_0x2fe01d['Attachments'][_0x1a0e('0x48')];_0x525ee7++){var _0x290c8c=_0x2fe01d[_0x1a0e('0x9d')][_0x525ee7];var _0x1036e5=path[_0x1a0e('0x95')](_0x128e2c,_0x290c8c[_0x1a0e('0x6f')]);if(fs['existsSync'](_0x1036e5)){_0x232124[_0x1a0e('0x6c')]['push']({'name':_0x290c8c[_0x1a0e('0x41')],'contentType':_0x290c8c[_0x1a0e('0x3e')],'data':fs[_0x1a0e('0xa2')](_0x1036e5)});}}}emlformat['build'](_0x232124,function(_0x38f9c5,_0x39e922){if(_0x38f9c5)return _0x5185b1(_0x38f9c5);fs[_0x1a0e('0xa3')](path['join'](_0x3f4969,_0x866a3c),_0x39e922);return _0x5a1f36(_0x39e922);});});}})['then'](function(_0x5393c2){if(_0x5393c2){return _0x331c3b[_0x1a0e('0x92')](path[_0x1a0e('0x95')](_0x3f4969,_0x866a3c),_0x866a3c,function(_0x478363){if(_0x478363){console[_0x1a0e('0xa4')](_0x1a0e('0xa5'),_0x478363);}else{fs['unlinkSync'](path['join'](_0x3f4969,_0x866a3c));}});}})[_0x1a0e('0x2b')](handleError(_0x331c3b,null));};
\ No newline at end of file