Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index bc3440c..70048c7 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x8f17=['length','includeAll','find','body','describe','create','direction','secret','split','MailAccount','findOne','CmList','List','CmContact','MailServerOut','Smtp','isNil','host','port','secure','authentication','service','auth','pass','attachments','root','server/files/attachments','basename','Contacts','ListId','List\x20not\x20found','SendMail','messageId','YYYY-MM-DD\x20HH:mm:ss','mail-interactions','accept','mail','read','readAt','format','UserId','user','agent','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','acceptMessage','manual','channel','event','EventManager','acceptmessage','MailInteractionId','interaction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','SIP/%s','rejectmessage','unix','toString','join','files','tmp','server','message-%s.eml','from','bcc','subject','createdAt','Attachments','headers','Bcc','existsSync','push','readFileSync','build','writeFileSync','log','err','unlinkSync','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','bluebird','mustache','util','path','sox','to-csv','ejs','fs-extra','lodash','crypto','jsforce','desk.js','querystring','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','redis','socket.io-emitter','./mailMessage.socket','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','end','status','count','offset','limit','set','Content-Range','json','apply','reject','save','update','destroy','stack','send','map','MailMessage','rawAttributes','fieldName','type','key','model','name','query','keys','filters','intersection','attributes','fields','hasOwnProperty','order','sort','where','pick','merge','VIRTUAL','options','findAll','rows','show','params'];(function(_0x39443c,_0x25bf1f){var _0x39a016=function(_0x352fc3){while(--_0x352fc3){_0x39443c['push'](_0x39443c['shift']());}};_0x39a016(++_0x25bf1f);}(_0x8f17,0xfb));var _0x78f1=function(_0x24d06a,_0x59c850){_0x24d06a=_0x24d06a-0x0;var _0x4a987d=_0x8f17[_0x24d06a];return _0x4a987d;};'use strict';var emlformat=require(_0x78f1('0x0'));var rimraf=require(_0x78f1('0x1'));var zipdir=require(_0x78f1('0x2'));var jsonpatch=require(_0x78f1('0x3'));var rp=require(_0x78f1('0x4'));var moment=require('moment');var BPromise=require(_0x78f1('0x5'));var Mustache=require(_0x78f1('0x6'));var util=require(_0x78f1('0x7'));var path=require(_0x78f1('0x8'));var sox=require(_0x78f1('0x9'));var csv=require(_0x78f1('0xa'));var ejs=require(_0x78f1('0xb'));var fs=require('fs');var fs_extra=require(_0x78f1('0xc'));var _=require(_0x78f1('0xd'));var squel=require('squel');var crypto=require(_0x78f1('0xe'));var jsforce=require(_0x78f1('0xf'));var deskjs=require(_0x78f1('0x10'));var toCsv=require('to-csv');var querystring=require(_0x78f1('0x11'));var Papa=require('papaparse');var Redis=require('ioredis');var authService=require(_0x78f1('0x12'));var qs=require(_0x78f1('0x13'));var as=require(_0x78f1('0x14'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x78f1('0x15'))(_0x78f1('0x16'));var utils=require(_0x78f1('0x17'));var config=require('../../config/environment');var licenseUtil=require(_0x78f1('0x18'));var db=require(_0x78f1('0x19'))['db'];config['redis']=_[_0x78f1('0x1a')](config[_0x78f1('0x1b')],{'host':'localhost','port':0x18eb});var socket=require(_0x78f1('0x1c'))(new Redis(config[_0x78f1('0x1b')]));require(_0x78f1('0x1d'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x78f1('0x1e')][_0x78f1('0x1f')]({'port':0x232c});var client9003=jayson['client']['http']({'port':0x232b});var client9002=jayson[_0x78f1('0x1e')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3807e9,_0x5108b6,_0x59f315,_0x5f7fc7){return new BPromise(function(_0x4b0492,_0x469759){var _0x550993=_0x5f7fc7||client;return _0x550993[_0x78f1('0x20')](_0x3807e9,_0x59f315)[_0x78f1('0x21')](function(_0x17c4f5){logger[_0x78f1('0x22')](_0x78f1('0x23'),_0x5108b6,_0x78f1('0x24'));logger[_0x78f1('0x25')](_0x78f1('0x26'),_0x5108b6,_0x78f1('0x24'),JSON[_0x78f1('0x27')](_0x17c4f5));if(_0x17c4f5[_0x78f1('0x28')]){if(_0x17c4f5['error'][_0x78f1('0x29')]===0x1f4){logger[_0x78f1('0x28')](_0x78f1('0x23'),_0x5108b6,_0x17c4f5[_0x78f1('0x28')][_0x78f1('0x2a')]);return _0x469759(_0x17c4f5[_0x78f1('0x28')][_0x78f1('0x2a')]);}logger[_0x78f1('0x28')](_0x78f1('0x23'),_0x5108b6,_0x17c4f5[_0x78f1('0x28')]['message']);return _0x4b0492(_0x17c4f5[_0x78f1('0x28')][_0x78f1('0x2a')]);}else{logger[_0x78f1('0x22')](_0x78f1('0x23'),_0x5108b6,_0x78f1('0x24'));_0x4b0492(_0x17c4f5[_0x78f1('0x2b')][_0x78f1('0x2a')]);}})[_0x78f1('0x2c')](function(_0x1261bb){logger[_0x78f1('0x28')](_0x78f1('0x23'),_0x5108b6,_0x1261bb);_0x469759(_0x1261bb);});});}function respondWithStatusCode(_0x5e8cc3,_0x4c59ca){_0x4c59ca=_0x4c59ca||0xcc;return function(_0x5f04e9){if(_0x5f04e9){return _0x5e8cc3[_0x78f1('0x2d')](_0x4c59ca);}return _0x5e8cc3['status'](_0x4c59ca)[_0x78f1('0x2e')]();};}function respondWithResult(_0x368de1,_0x306063){_0x306063=_0x306063||0xc8;return function(_0x44ad8c){if(_0x44ad8c){return _0x368de1[_0x78f1('0x2f')](_0x306063)['json'](_0x44ad8c);}};}function respondWithFilteredResult(_0x47f798,_0x59efcd){return function(_0x281573){if(_0x281573){var _0x20734c=_0x281573[_0x78f1('0x30')],_0x5cc0e1=_0x59efcd[_0x78f1('0x31')],_0x3de6b3=_0x59efcd[_0x78f1('0x31')]+_0x59efcd[_0x78f1('0x32')],_0x50fc6d;if(_0x3de6b3>=_0x20734c){_0x3de6b3=_0x20734c;_0x50fc6d=0xc8;}else{_0x50fc6d=0xce;}_0x47f798[_0x78f1('0x2f')](_0x50fc6d);return _0x47f798[_0x78f1('0x33')](_0x78f1('0x34'),_0x5cc0e1+'-'+_0x3de6b3+'/'+_0x20734c)[_0x78f1('0x35')](_0x281573);}return null;};}function patchUpdates(_0x501d17){return function(_0x4e34c2){try{jsonpatch[_0x78f1('0x36')](_0x4e34c2,_0x501d17,!![]);}catch(_0x2f43e){return BPromise[_0x78f1('0x37')](_0x2f43e);}return _0x4e34c2[_0x78f1('0x38')]();};}function saveUpdates(_0x3451e7,_0x3ebc17){return function(_0x182e7d){if(_0x182e7d){return _0x182e7d[_0x78f1('0x39')](_0x3451e7)[_0x78f1('0x21')](function(_0x3f34c3){return _0x3f34c3;});}return null;};}function removeEntity(_0x43a942,_0x17d6c3){return function(_0x47e757){if(_0x47e757){return _0x47e757[_0x78f1('0x3a')]()[_0x78f1('0x21')](function(){_0x43a942['status'](0xcc)[_0x78f1('0x2e')]();});}};}function handleEntityNotFound(_0x4911a6,_0x247762){return function(_0x4f2d17){if(!_0x4f2d17){_0x4911a6[_0x78f1('0x2d')](0x194);}return _0x4f2d17;};}function handleError(_0x3ebc5c,_0x366c2f){_0x366c2f=_0x366c2f||0x1f4;return function(_0x2cfdf3){logger[_0x78f1('0x28')](_0x2cfdf3[_0x78f1('0x3b')]);if(_0x2cfdf3['name']){delete _0x2cfdf3['name'];}_0x3ebc5c[_0x78f1('0x2f')](_0x366c2f)[_0x78f1('0x3c')](_0x2cfdf3);};}exports['index']=function(_0x484769,_0x34debb){var _0x3fb010={},_0x52bccd={},_0xe804d4={'count':0x0,'rows':[]};var _0x475f54=_[_0x78f1('0x3d')](db[_0x78f1('0x3e')][_0x78f1('0x3f')],function(_0x215198){return{'name':_0x215198[_0x78f1('0x40')],'type':_0x215198[_0x78f1('0x41')][_0x78f1('0x42')]};});_0x52bccd[_0x78f1('0x43')]=_['map'](_0x475f54,_0x78f1('0x44'));_0x52bccd[_0x78f1('0x45')]=_[_0x78f1('0x46')](_0x484769['query']);_0x52bccd[_0x78f1('0x47')]=_[_0x78f1('0x48')](_0x52bccd[_0x78f1('0x43')],_0x52bccd[_0x78f1('0x45')]);_0x3fb010[_0x78f1('0x49')]=_[_0x78f1('0x48')](_0x52bccd['model'],qs[_0x78f1('0x4a')](_0x484769[_0x78f1('0x45')][_0x78f1('0x4a')]));_0x3fb010['attributes']=_0x3fb010[_0x78f1('0x49')]['length']?_0x3fb010[_0x78f1('0x49')]:_0x52bccd['model'];if(!_0x484769['query'][_0x78f1('0x4b')]('nolimit')){_0x3fb010[_0x78f1('0x32')]=qs[_0x78f1('0x32')](_0x484769[_0x78f1('0x45')][_0x78f1('0x32')]);_0x3fb010['offset']=qs[_0x78f1('0x31')](_0x484769['query'][_0x78f1('0x31')]);}_0x3fb010[_0x78f1('0x4c')]=qs['sort'](_0x484769[_0x78f1('0x45')][_0x78f1('0x4d')]);_0x3fb010[_0x78f1('0x4e')]=qs[_0x78f1('0x47')](_[_0x78f1('0x4f')](_0x484769[_0x78f1('0x45')],_0x52bccd[_0x78f1('0x47')]),_0x475f54);if(_0x484769[_0x78f1('0x45')]['filter']){_0x3fb010['where']=_[_0x78f1('0x50')](_0x3fb010[_0x78f1('0x4e')],{'$or':_[_0x78f1('0x3d')](_0x475f54,function(_0x321340){if(_0x321340[_0x78f1('0x41')]!==_0x78f1('0x51')){var _0x3255ad={};_0x3255ad[_0x321340[_0x78f1('0x44')]]={'$like':'%'+_0x484769[_0x78f1('0x45')]['filter']+'%'};return _0x3255ad;}})});}_0x3fb010=_[_0x78f1('0x50')]({},_0x3fb010,_0x484769[_0x78f1('0x52')]);var _0x4b91c0={'where':_0x3fb010[_0x78f1('0x4e')]};return db['MailMessage']['count'](_0x4b91c0)['then'](function(_0x19b23e){_0xe804d4[_0x78f1('0x30')]=_0x19b23e;if(_0x484769['query']['includeAll']){_0x3fb010['include']=[{'all':!![]}];}return db[_0x78f1('0x3e')][_0x78f1('0x53')](_0x3fb010);})['then'](function(_0x86d9b){_0xe804d4[_0x78f1('0x54')]=_0x86d9b;return _0xe804d4;})[_0x78f1('0x21')](respondWithFilteredResult(_0x34debb,_0x3fb010))[_0x78f1('0x2c')](handleError(_0x34debb,null));};exports[_0x78f1('0x55')]=function(_0x5cfbda,_0x1b0d38){var _0x143b6e={'raw':!![],'where':{'id':_0x5cfbda[_0x78f1('0x56')]['id']}},_0x586c2c={};_0x586c2c['model']=_[_0x78f1('0x46')](db[_0x78f1('0x3e')][_0x78f1('0x3f')]);_0x586c2c[_0x78f1('0x45')]=_[_0x78f1('0x46')](_0x5cfbda[_0x78f1('0x45')]);_0x586c2c[_0x78f1('0x47')]=_[_0x78f1('0x48')](_0x586c2c[_0x78f1('0x43')],_0x586c2c['query']);_0x143b6e[_0x78f1('0x49')]=_[_0x78f1('0x48')](_0x586c2c[_0x78f1('0x43')],qs[_0x78f1('0x4a')](_0x5cfbda[_0x78f1('0x45')][_0x78f1('0x4a')]));_0x143b6e[_0x78f1('0x49')]=_0x143b6e['attributes'][_0x78f1('0x57')]?_0x143b6e[_0x78f1('0x49')]:_0x586c2c[_0x78f1('0x43')];if(_0x5cfbda['query'][_0x78f1('0x58')]){_0x143b6e['include']=[{'all':!![]}];}_0x143b6e=_[_0x78f1('0x50')]({},_0x143b6e,_0x5cfbda['options']);return db['MailMessage'][_0x78f1('0x59')](_0x143b6e)[_0x78f1('0x21')](handleEntityNotFound(_0x1b0d38,null))[_0x78f1('0x21')](respondWithResult(_0x1b0d38,null))['catch'](handleError(_0x1b0d38,null));};exports[_0x78f1('0x39')]=function(_0x229736,_0xc5328){if(_0x229736[_0x78f1('0x5a')]['id']){delete _0x229736[_0x78f1('0x5a')]['id'];}return db['MailMessage'][_0x78f1('0x59')]({'where':{'id':_0x229736['params']['id']}})[_0x78f1('0x21')](handleEntityNotFound(_0xc5328,null))['then'](saveUpdates(_0x229736[_0x78f1('0x5a')],null))[_0x78f1('0x21')](respondWithResult(_0xc5328,null))[_0x78f1('0x2c')](handleError(_0xc5328,null));};exports[_0x78f1('0x3a')]=function(_0x153991,_0x39840d){return db[_0x78f1('0x3e')][_0x78f1('0x59')]({'where':{'id':_0x153991[_0x78f1('0x56')]['id']}})['then'](handleEntityNotFound(_0x39840d,null))[_0x78f1('0x21')](removeEntity(_0x39840d,null))[_0x78f1('0x2c')](handleError(_0x39840d,null));};exports[_0x78f1('0x5b')]=function(_0x3f6f48,_0x538253){return db[_0x78f1('0x3e')][_0x78f1('0x5b')]()[_0x78f1('0x21')](respondWithResult(_0x538253,null))[_0x78f1('0x2c')](handleError(_0x538253,null));};exports[_0x78f1('0x5c')]=function(_0x3c2cd6,_0x450289){return db[_0x78f1('0x3e')][_0x78f1('0x5c')](_0x3c2cd6[_0x78f1('0x5a')])[_0x78f1('0x21')](function(_0x36b020){if(_0x36b020){if(_0x36b020[_0x78f1('0x5d')]==='out'&&!_0x36b020[_0x78f1('0x5e')]){var _0x1390ee,_0x2797b1,_0xa6fde6;if(_0x3c2cd6[_0x78f1('0x5a')]['to']){_0x2797b1=_0x3c2cd6[_0x78f1('0x5a')]['to'][_0x78f1('0x5f')](',')[0x0];}return db[_0x78f1('0x60')][_0x78f1('0x61')]({'where':{'id':_0x36b020['MailAccountId']},'include':[{'model':db[_0x78f1('0x62')],'as':_0x78f1('0x63'),'include':[{'model':db[_0x78f1('0x64')],'as':'Contacts','where':{'email':_0x2797b1},'limit':0x1,'order':[['updatedAt','DESC']]}]},{'model':db[_0x78f1('0x65')],'as':_0x78f1('0x66'),'raw':!![]}]})[_0x78f1('0x21')](function(_0xd5d344){_0x1390ee=_0xd5d344;if(_0x1390ee&&_0x1390ee[_0x78f1('0x66')]){var _0x148ba5={'tls':{'rejectUnauthorized':![]}};if(_[_0x78f1('0x67')](_0x1390ee[_0x78f1('0x66')]['service'])){_0x148ba5['host']=_0x1390ee[_0x78f1('0x66')][_0x78f1('0x68')];_0x148ba5[_0x78f1('0x69')]=_0x1390ee[_0x78f1('0x66')][_0x78f1('0x69')];_0x148ba5[_0x78f1('0x6a')]=_0x1390ee['Smtp'][_0x78f1('0x6a')];if(_0x1390ee[_0x78f1('0x66')][_0x78f1('0x6b')]){_0x148ba5['auth']={'user':_0x1390ee[_0x78f1('0x66')]['user'],'pass':_0x1390ee[_0x78f1('0x66')]['pass']};}}else{_0x148ba5[_0x78f1('0x6c')]=_0x1390ee['Smtp']['service'];_0x148ba5[_0x78f1('0x6d')]={'user':_0x1390ee[_0x78f1('0x66')]['user'],'pass':_0x1390ee['Smtp'][_0x78f1('0x6e')]};_0x148ba5['secure']=_0x1390ee[_0x78f1('0x66')]['secure'];}if(_0x3c2cd6['body'][_0x78f1('0x6f')]&&_0x3c2cd6[_0x78f1('0x5a')][_0x78f1('0x6f')][_0x78f1('0x57')]){for(var _0x1d0da6=0x0;_0x1d0da6<_0x3c2cd6[_0x78f1('0x5a')]['attachments']['length'];_0x1d0da6+=0x1){_0x3c2cd6[_0x78f1('0x5a')][_0x78f1('0x6f')][_0x1d0da6]={'filename':_0x3c2cd6['body'][_0x78f1('0x6f')][_0x1d0da6][_0x78f1('0x44')],'path':path['join'](config[_0x78f1('0x70')],_0x78f1('0x71'),_0x3c2cd6[_0x78f1('0x5a')][_0x78f1('0x6f')][_0x1d0da6][_0x78f1('0x72')])};}}_0xa6fde6={'account':_0x148ba5,'message':_0x3c2cd6[_0x78f1('0x5a')]};return;}})[_0x78f1('0x21')](function(){if(_0x1390ee['List']){if(_0x1390ee['List'][_0x78f1('0x73')][_0x78f1('0x57')]){return _0x1390ee[_0x78f1('0x63')][_0x78f1('0x73')][0x0];}else{return db[_0x78f1('0x64')][_0x78f1('0x5c')](_[_0x78f1('0x1a')](_0x3c2cd6[_0x78f1('0x5a')],{'firstName':_0x3c2cd6[_0x78f1('0x5a')]['to'],'email':_0x3c2cd6[_0x78f1('0x5a')]['to'],'phone':_0x3c2cd6['body']['to'],'ListId':_0x1390ee[_0x78f1('0x74')]}));}}else{throw new Error(_0x78f1('0x75'));}})[_0x78f1('0x21')](function(){if(_0xa6fde6){return respondWithRpcPromise(_0x78f1('0x76'),'sendMail',_0xa6fde6,client9003)[_0x78f1('0x21')](function(_0x9733d2){return _0x36b020[_0x78f1('0x39')]({'read':!![],'messageId':_0x9733d2[_0x78f1('0x77')],'sentAt':moment()['format'](_0x78f1('0x78'))});})[_0x78f1('0x2c')](function(_0x52b10f){logger[_0x78f1('0x28')]('%s',JSON['stringify'](_0x52b10f));return _0x36b020;});}return _0x36b020;});}return _0x36b020;}})[_0x78f1('0x21')](respondWithResult(_0x450289,0xc9))[_0x78f1('0x2c')](handleError(_0x450289,null));};var interaction_log=require(_0x78f1('0x15'))(_0x78f1('0x79'));exports[_0x78f1('0x7a')]=function(_0x5891e6,_0xfe441c,_0x11b00f){var _0x5ed60a={'agent':{},'channel':_0x78f1('0x7b')};if(_0x5891e6[_0x78f1('0x5a')]['id']){delete _0x5891e6[_0x78f1('0x5a')]['id'];}_0x5891e6['body'][_0x78f1('0x7c')]=!![];_0x5891e6[_0x78f1('0x5a')][_0x78f1('0x7d')]=moment()[_0x78f1('0x7e')](_0x78f1('0x78'));_0x5891e6[_0x78f1('0x5a')][_0x78f1('0x7f')]=_0x5891e6['body']['UserId']||_0x5891e6[_0x78f1('0x80')]['id'];_0x5ed60a[_0x78f1('0x81')]['id']=_0x5891e6[_0x78f1('0x5a')]['UserId'];return db[_0x78f1('0x3e')][_0x78f1('0x59')]({'where':{'id':_0x5891e6[_0x78f1('0x56')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':'Contact'}]})[_0x78f1('0x21')](handleEntityNotFound(_0xfe441c,null))[_0x78f1('0x21')](saveUpdates(_0x5891e6[_0x78f1('0x5a')],null))[_0x78f1('0x21')](function(_0x3901b1){if(_0x3901b1){_0x5ed60a[_0x78f1('0x2a')]=_0x3901b1[_0x78f1('0x82')]({'plain':!![]});return db['MailInteraction'][_0x78f1('0x59')]({'where':{'id':_0x3901b1['MailInteractionId']}});}return null;})[_0x78f1('0x21')](handleEntityNotFound(_0xfe441c,null))[_0x78f1('0x21')](function(_0x117899){if(_0x117899){return _0x117899['update']({'UserId':_0x5891e6[_0x78f1('0x5a')][_0x78f1('0x7f')],'read1stAt':_['isNil'](_0x117899['read1stAt'])?moment()[_0x78f1('0x7e')](_0x78f1('0x78')):undefined});}return null;})[_0x78f1('0x21')](function(_0x118d4f){if(_0x118d4f){_0x5ed60a['interaction']=_0x118d4f[_0x78f1('0x82')]({'plain':!![]});interaction_log[_0x78f1('0x22')](_0x78f1('0x83'),_0x5891e6[_0x78f1('0x80')]['id'],_0x5891e6[_0x78f1('0x80')]['name'],_0x5891e6[_0x78f1('0x80')][_0x78f1('0x84')],_0x5ed60a['interaction']['id'],_0x5891e6['body']?JSON['stringify'](_0x5891e6[_0x78f1('0x5a')]):_0x78f1('0x85'));return respondWithRpcPromise('AcceptMessage',_0x78f1('0x86'),_0x5ed60a);}return null;})[_0x78f1('0x21')](function(_0x383cc1){if(_0x383cc1){if(_0x5891e6['body'][_0x78f1('0x87')]){_0x5ed60a[_0x78f1('0x2a')]['interface']=util['format']('SIP/%s',_0x5891e6['user'][_0x78f1('0x44')]);_0x5ed60a['message'][_0x78f1('0x88')]=_0x5ed60a[_0x78f1('0x88')];_0x5ed60a[_0x78f1('0x2a')][_0x78f1('0x89')]='accept';return respondWithRpcPromise(_0x78f1('0x8a'),_0x78f1('0x8a'),{'event':_0x78f1('0x8b'),'message':_0x5ed60a[_0x78f1('0x2a')]},client9002)[_0x78f1('0x21')](function(){return _0x5ed60a;});}return _0x5ed60a;}return null;})[_0x78f1('0x21')](respondWithResult(_0xfe441c,null))['catch'](handleError(_0xfe441c,null));};var interaction_log=require(_0x78f1('0x15'))(_0x78f1('0x79'));exports[_0x78f1('0x37')]=function(_0x3f2e1b,_0x46585a,_0x5cc573){var _0xbd7c63={'agent':{},'channel':_0x78f1('0x7b')};if(_0x3f2e1b['body']['id']){delete _0x3f2e1b[_0x78f1('0x5a')]['id'];}_0x3f2e1b['body'][_0x78f1('0x7f')]=_0x3f2e1b[_0x78f1('0x5a')][_0x78f1('0x7f')]||_0x3f2e1b['user']['id'];_0xbd7c63[_0x78f1('0x81')]['id']=_0x3f2e1b[_0x78f1('0x5a')][_0x78f1('0x7f')];return db[_0x78f1('0x3e')][_0x78f1('0x59')]({'where':{'id':_0x3f2e1b[_0x78f1('0x56')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x46585a,null))[_0x78f1('0x21')](function(_0x1a59d1){if(_0x1a59d1){_0xbd7c63['message']=_0x1a59d1['get']({'plain':!![]});return db['MailInteraction'][_0x78f1('0x59')]({'where':{'id':_0x1a59d1[_0x78f1('0x8c')]}});}return null;})[_0x78f1('0x21')](handleEntityNotFound(_0x46585a,null))[_0x78f1('0x21')](function(_0x201c72){if(_0x201c72){_0xbd7c63[_0x78f1('0x8d')]=_0x201c72[_0x78f1('0x82')]({'plain':!![]});interaction_log['info'](_0x78f1('0x8e'),_0x3f2e1b[_0x78f1('0x80')]['id'],_0x3f2e1b[_0x78f1('0x80')][_0x78f1('0x44')],_0x3f2e1b[_0x78f1('0x80')][_0x78f1('0x84')],_0xbd7c63[_0x78f1('0x8d')]['id'],_0x3f2e1b[_0x78f1('0x5a')]?JSON['stringify'](_0x3f2e1b[_0x78f1('0x5a')]):_0x78f1('0x85'));return respondWithRpcPromise(_0x78f1('0x8f'),_0x78f1('0x90'),_0xbd7c63);}return null;})[_0x78f1('0x21')](function(_0x2a1350){if(_0x2a1350){_0x2a1350[_0x78f1('0x2a')]['interface']=util[_0x78f1('0x7e')](_0x78f1('0x91'),_0x3f2e1b[_0x78f1('0x80')][_0x78f1('0x44')]);_0x2a1350[_0x78f1('0x2a')]['channel']=_0xbd7c63[_0x78f1('0x88')];_0x2a1350['message'][_0x78f1('0x89')]='reject';respondWithRpcPromise(_0x78f1('0x8a'),_0x78f1('0x8a'),{'event':_0x78f1('0x92'),'message':_0x2a1350[_0x78f1('0x2a')]},client9002);return _0xbd7c63;}return null;})['then'](respondWithResult(_0x46585a,null))['catch'](handleError(_0x46585a,null));};exports['download']=function(_0x179d9c,_0x4bab29){var _0x4208ca=moment()[_0x78f1('0x93')]()[_0x78f1('0x94')]();var _0xa4190e=path[_0x78f1('0x95')](config[_0x78f1('0x70')],'server',_0x78f1('0x96'),_0x78f1('0x97'));var _0x26df7e=path[_0x78f1('0x95')](config[_0x78f1('0x70')],_0x78f1('0x98'),_0x78f1('0x96'),_0x78f1('0x6f'));var _0x16ba87=util[_0x78f1('0x7e')](_0x78f1('0x99'),_0x4208ca);return db['MailMessage'][_0x78f1('0x59')]({'where':{'id':_0x179d9c[_0x78f1('0x56')]['id']},'attributes':['id',_0x78f1('0x5a'),_0x78f1('0x9a'),'to','cc',_0x78f1('0x9b'),_0x78f1('0x9c'),_0x78f1('0x9d')],'include':_0x179d9c['query']['attachments']?[{'model':db['Attachment'],'as':_0x78f1('0x9e')}]:undefined})[_0x78f1('0x21')](handleEntityNotFound(_0x4bab29,null))[_0x78f1('0x21')](function(_0x97b722){if(_0x97b722){var _0x15efe4=_0x97b722;var _0x3d1151={'from':_0x15efe4[_0x78f1('0x9a')],'to':_0x15efe4['to'],'subject':_0x15efe4[_0x78f1('0x9c')],'html':_0x15efe4[_0x78f1('0x5a')],'headers':{'Date':moment(_0x15efe4[_0x78f1('0x9d')])[_0x78f1('0x7e')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x97b722['cc']){_0x3d1151[_0x78f1('0x9f')]['Cc']=_0x97b722['cc'];}if(_0x97b722[_0x78f1('0x9b')]){_0x3d1151[_0x78f1('0x9f')][_0x78f1('0xa0')]=_0x97b722[_0x78f1('0x9b')];}return new BPromise(function(_0x46bf5d,_0x59b726){if(_0x97b722['Attachments']){for(var _0x3979d2=0x0;_0x3979d2<_0x97b722[_0x78f1('0x9e')][_0x78f1('0x57')];_0x3979d2++){var _0x515782=_0x97b722[_0x78f1('0x9e')][_0x3979d2];var _0xeb2560=path[_0x78f1('0x95')](_0x26df7e,_0x515782[_0x78f1('0x72')]);if(fs[_0x78f1('0xa1')](_0xeb2560)){_0x3d1151['attachments'][_0x78f1('0xa2')]({'name':_0x515782[_0x78f1('0x44')],'contentType':_0x515782[_0x78f1('0x41')],'data':fs[_0x78f1('0xa3')](_0xeb2560)});}}}emlformat[_0x78f1('0xa4')](_0x3d1151,function(_0x1eef70,_0x1536a7){if(_0x1eef70)return _0x59b726(_0x1eef70);fs[_0x78f1('0xa5')](path['join'](_0xa4190e,_0x16ba87),_0x1536a7);return _0x46bf5d(_0x1536a7);});});}})[_0x78f1('0x21')](function(_0x1885c4){if(_0x1885c4){return _0x4bab29['download'](path[_0x78f1('0x95')](_0xa4190e,_0x16ba87),_0x16ba87,function(_0xf663e6){if(_0xf663e6){console[_0x78f1('0xa6')](_0x78f1('0xa7'),_0xf663e6);}else{fs[_0x78f1('0xa8')](path[_0x78f1('0x95')](_0xa4190e,_0x16ba87));}});}})[_0x78f1('0x2c')](handleError(_0x4bab29,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