Built motion from commit 10af8726.|2.6.34
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 53b6121..313e7b8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xbf89=['bluebird','util','path','ioredis','html-to-text','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','./mailMessage.socket','jayson/promise','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','error','message','result','catch','json','offset','undefined','limit','count','status','set','Content-Range','update','destroy','name','send','index','map','MailMessage','rawAttributes','fieldName','type','key','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','filters','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','find','body','params','create','out','MailAccount','findOne','CmList','List','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','server/files/attachments','basename','CmContact','ListId','SendMail','sendMail','format','YYYY-MM-DD\x20HH:mm:ss','stringify','accept','read','readAt','UserId','agent','get','MailInteraction','MailInteractionId','isNil','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','user','role','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','contact','User','email','internal','manual','interface','SIP/%s','motionChannel','channel','event','EventManager','acceptmessage','reject','mail','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','fullname','rejectmessage','download','toString','files','tmp','server','message-%s.eml','from','subject','createdAt','Attachment','decode','bcc','headers','Attachments','push','readFileSync','build','writeFileSync','eml-format'];(function(_0x160817,_0x3a7d36){var _0x260566=function(_0x1c337e){while(--_0x1c337e){_0x160817['push'](_0x160817['shift']());}};_0x260566(++_0x3a7d36);}(_0xbf89,0x131));var _0x9bf8=function(_0x4a00d0,_0x56d533){_0x4a00d0=_0x4a00d0-0x0;var _0x6e25bf=_0xbf89[_0x4a00d0];return _0x6e25bf;};'use strict';var emlformat=require(_0x9bf8('0x0'));var moment=require('moment');var BPromise=require(_0x9bf8('0x1'));var util=require(_0x9bf8('0x2'));var path=require(_0x9bf8('0x3'));var fs=require('fs');var _=require('lodash');var Redis=require(_0x9bf8('0x4'));var htmlToText=require(_0x9bf8('0x5'));var qs=require('../../components/parsers/qs');var logger=require(_0x9bf8('0x6'))('api');var interaction_log=require('../../config/logger')('mail-interactions');var config=require(_0x9bf8('0x7'));var db=require(_0x9bf8('0x8'))['db'];config[_0x9bf8('0x9')]=_[_0x9bf8('0xa')](config[_0x9bf8('0x9')],{'host':'localhost','port':0x18eb});var socket=require(_0x9bf8('0xb'))(new Redis(config[_0x9bf8('0x9')]));var htmlEntities=require('html-entities');require(_0x9bf8('0xc'))['register'](socket);var jayson=require(_0x9bf8('0xd'));var client=jayson[_0x9bf8('0xe')][_0x9bf8('0xf')]({'port':0x232c});var client9003=jayson[_0x9bf8('0xe')][_0x9bf8('0xf')]({'port':0x232b});var client9002=jayson[_0x9bf8('0xe')][_0x9bf8('0xf')]({'port':0x232a});function respondWithRpcPromise(_0x4df685,_0x3243a9,_0x129f96,_0x4334ac){return new BPromise(function(_0x208bc0,_0xeb042){var _0x7697f3=_0x4334ac||client;return _0x7697f3[_0x9bf8('0x10')](_0x4df685,_0x129f96)[_0x9bf8('0x11')](function(_0x5d94c0){logger[_0x9bf8('0x12')](_0x9bf8('0x13'),_0x3243a9,_0x9bf8('0x14'));logger[_0x9bf8('0x15')](_0x9bf8('0x16'),_0x3243a9,_0x9bf8('0x14'),JSON['stringify'](_0x5d94c0));if(_0x5d94c0[_0x9bf8('0x17')]){if(_0x5d94c0[_0x9bf8('0x17')]['code']===0x1f4){logger[_0x9bf8('0x17')](_0x9bf8('0x13'),_0x3243a9,_0x5d94c0['error'][_0x9bf8('0x18')]);return _0xeb042(_0x5d94c0[_0x9bf8('0x17')][_0x9bf8('0x18')]);}logger[_0x9bf8('0x17')]('MailMessage,\x20%s,\x20%s',_0x3243a9,_0x5d94c0[_0x9bf8('0x17')][_0x9bf8('0x18')]);return _0x208bc0(_0x5d94c0[_0x9bf8('0x17')][_0x9bf8('0x18')]);}else{logger['info'](_0x9bf8('0x13'),_0x3243a9,_0x9bf8('0x14'));_0x208bc0(_0x5d94c0[_0x9bf8('0x19')]['message']);}})[_0x9bf8('0x1a')](function(_0x55300e){logger[_0x9bf8('0x17')](_0x9bf8('0x13'),_0x3243a9,_0x55300e);_0xeb042(_0x55300e);});});}function respondWithResult(_0x1d6618,_0x145262){_0x145262=_0x145262||0xc8;return function(_0x41040f){if(_0x41040f){return _0x1d6618['status'](_0x145262)[_0x9bf8('0x1b')](_0x41040f);}};}function respondWithFilteredResult(_0x308aa2,_0x3cb69b){return function(_0x5561a7){if(_0x5561a7){var _0x43245a=typeof _0x3cb69b[_0x9bf8('0x1c')]===_0x9bf8('0x1d')&&typeof _0x3cb69b[_0x9bf8('0x1e')]===_0x9bf8('0x1d');var _0x5bd2f7=_0x5561a7[_0x9bf8('0x1f')];var _0x5c8fe7=_0x43245a?0x0:_0x3cb69b['offset'];var _0x5488b4=_0x43245a?_0x5561a7['count']:_0x3cb69b[_0x9bf8('0x1c')]+_0x3cb69b[_0x9bf8('0x1e')];var _0x42744f;if(_0x5488b4>=_0x5bd2f7){_0x5488b4=_0x5bd2f7;_0x42744f=0xc8;}else{_0x42744f=0xce;}_0x308aa2[_0x9bf8('0x20')](_0x42744f);return _0x308aa2[_0x9bf8('0x21')](_0x9bf8('0x22'),_0x5c8fe7+'-'+_0x5488b4+'/'+_0x5bd2f7)['json'](_0x5561a7);}return null;};}function saveUpdates(_0x3de61f){return function(_0x1958c6){if(_0x1958c6){return _0x1958c6[_0x9bf8('0x23')](_0x3de61f)[_0x9bf8('0x11')](function(_0x470736){return _0x470736;});}return null;};}function removeEntity(_0x4f7edd){return function(_0x504562){if(_0x504562){return _0x504562[_0x9bf8('0x24')]()[_0x9bf8('0x11')](function(){_0x4f7edd[_0x9bf8('0x20')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3c9c1f){return function(_0x1087da){if(!_0x1087da){_0x3c9c1f['sendStatus'](0x194);}return _0x1087da;};}function handleError(_0x2db039,_0x215d0b){_0x215d0b=_0x215d0b||0x1f4;return function(_0x58fede){logger[_0x9bf8('0x17')](_0x58fede['stack']);if(_0x58fede['name']){delete _0x58fede[_0x9bf8('0x25')];}_0x2db039[_0x9bf8('0x20')](_0x215d0b)[_0x9bf8('0x26')](_0x58fede);};}exports[_0x9bf8('0x27')]=function(_0x598980,_0x4e7330){var _0x3a6779={},_0x46bd00={},_0x524e85={'count':0x0,'rows':[]};var _0x46c36d=_[_0x9bf8('0x28')](db[_0x9bf8('0x29')][_0x9bf8('0x2a')],function(_0x471320){return{'name':_0x471320[_0x9bf8('0x2b')],'type':_0x471320[_0x9bf8('0x2c')][_0x9bf8('0x2d')]};});_0x46bd00[_0x9bf8('0x2e')]=_[_0x9bf8('0x28')](_0x46c36d,_0x9bf8('0x25'));_0x46bd00[_0x9bf8('0x2f')]=_[_0x9bf8('0x30')](_0x598980[_0x9bf8('0x2f')]);_0x46bd00['filters']=_[_0x9bf8('0x31')](_0x46bd00[_0x9bf8('0x2e')],_0x46bd00[_0x9bf8('0x2f')]);_0x3a6779[_0x9bf8('0x32')]=_[_0x9bf8('0x31')](_0x46bd00[_0x9bf8('0x2e')],qs['fields'](_0x598980[_0x9bf8('0x2f')][_0x9bf8('0x33')]));_0x3a6779[_0x9bf8('0x32')]=_0x3a6779[_0x9bf8('0x32')][_0x9bf8('0x34')]?_0x3a6779[_0x9bf8('0x32')]:_0x46bd00[_0x9bf8('0x2e')];if(!_0x598980[_0x9bf8('0x2f')][_0x9bf8('0x35')](_0x9bf8('0x36'))){_0x3a6779[_0x9bf8('0x1e')]=qs['limit'](_0x598980['query'][_0x9bf8('0x1e')]);_0x3a6779['offset']=qs[_0x9bf8('0x1c')](_0x598980[_0x9bf8('0x2f')][_0x9bf8('0x1c')]);}_0x3a6779[_0x9bf8('0x37')]=qs[_0x9bf8('0x38')](_0x598980[_0x9bf8('0x2f')][_0x9bf8('0x38')]);_0x3a6779[_0x9bf8('0x39')]=qs[_0x9bf8('0x3a')](_[_0x9bf8('0x3b')](_0x598980[_0x9bf8('0x2f')],_0x46bd00['filters']),_0x46c36d);if(_0x598980[_0x9bf8('0x2f')][_0x9bf8('0x3c')]){_0x3a6779['where']=_[_0x9bf8('0x3d')](_0x3a6779[_0x9bf8('0x39')],{'$or':_[_0x9bf8('0x28')](_0x46c36d,function(_0x5003c8){if(_0x5003c8[_0x9bf8('0x2c')]!==_0x9bf8('0x3e')){var _0x2baee8={};_0x2baee8[_0x5003c8[_0x9bf8('0x25')]]={'$like':'%'+_0x598980[_0x9bf8('0x2f')]['filter']+'%'};return _0x2baee8;}})});}_0x3a6779=_[_0x9bf8('0x3d')]({},_0x3a6779,_0x598980[_0x9bf8('0x3f')]);var _0x37201d={'where':_0x3a6779[_0x9bf8('0x39')]};return db[_0x9bf8('0x29')][_0x9bf8('0x1f')](_0x37201d)[_0x9bf8('0x11')](function(_0x2fa444){_0x524e85[_0x9bf8('0x1f')]=_0x2fa444;if(_0x598980[_0x9bf8('0x2f')][_0x9bf8('0x40')]){_0x3a6779[_0x9bf8('0x41')]=[{'all':!![]}];}return db[_0x9bf8('0x29')][_0x9bf8('0x42')](_0x3a6779);})[_0x9bf8('0x11')](function(_0x1f4f0b){_0x524e85[_0x9bf8('0x43')]=_0x1f4f0b;return _0x524e85;})[_0x9bf8('0x11')](respondWithFilteredResult(_0x4e7330,_0x3a6779))[_0x9bf8('0x1a')](handleError(_0x4e7330,null));};exports['show']=function(_0x30ae19,_0xcba73a){var _0x4ce1f5={'raw':!![],'where':{'id':_0x30ae19['params']['id']}},_0x57e02c={};_0x57e02c['model']=_['keys'](db[_0x9bf8('0x29')][_0x9bf8('0x2a')]);_0x57e02c[_0x9bf8('0x2f')]=_[_0x9bf8('0x30')](_0x30ae19['query']);_0x57e02c['filters']=_[_0x9bf8('0x31')](_0x57e02c['model'],_0x57e02c[_0x9bf8('0x2f')]);_0x4ce1f5[_0x9bf8('0x32')]=_[_0x9bf8('0x31')](_0x57e02c[_0x9bf8('0x2e')],qs[_0x9bf8('0x33')](_0x30ae19[_0x9bf8('0x2f')][_0x9bf8('0x33')]));_0x4ce1f5[_0x9bf8('0x32')]=_0x4ce1f5['attributes']['length']?_0x4ce1f5[_0x9bf8('0x32')]:_0x57e02c[_0x9bf8('0x2e')];if(_0x30ae19['query'][_0x9bf8('0x40')]){_0x4ce1f5['include']=[{'all':!![]}];}_0x4ce1f5=_[_0x9bf8('0x3d')]({},_0x4ce1f5,_0x30ae19[_0x9bf8('0x3f')]);return db['MailMessage'][_0x9bf8('0x44')](_0x4ce1f5)[_0x9bf8('0x11')](handleEntityNotFound(_0xcba73a,null))[_0x9bf8('0x11')](respondWithResult(_0xcba73a,null))[_0x9bf8('0x1a')](handleError(_0xcba73a,null));};exports['update']=function(_0x4e2f95,_0x4c3729){if(_0x4e2f95[_0x9bf8('0x45')]['id']){delete _0x4e2f95[_0x9bf8('0x45')]['id'];}return db[_0x9bf8('0x29')][_0x9bf8('0x44')]({'where':{'id':_0x4e2f95[_0x9bf8('0x46')]['id']}})[_0x9bf8('0x11')](handleEntityNotFound(_0x4c3729,null))[_0x9bf8('0x11')](saveUpdates(_0x4e2f95[_0x9bf8('0x45')],null))['then'](respondWithResult(_0x4c3729,null))[_0x9bf8('0x1a')](handleError(_0x4c3729,null));};exports[_0x9bf8('0x24')]=function(_0x3232c8,_0xd31325){return db['MailMessage'][_0x9bf8('0x44')]({'where':{'id':_0x3232c8[_0x9bf8('0x46')]['id']}})['then'](handleEntityNotFound(_0xd31325,null))[_0x9bf8('0x11')](removeEntity(_0xd31325,null))[_0x9bf8('0x1a')](handleError(_0xd31325,null));};exports['describe']=function(_0x22a20b,_0x4ed0e9){return db['MailMessage']['describe']()[_0x9bf8('0x11')](respondWithResult(_0x4ed0e9,null))[_0x9bf8('0x1a')](handleError(_0x4ed0e9,null));};exports[_0x9bf8('0x47')]=function(_0x1907f9,_0x2d7bf9){return db['MailMessage'][_0x9bf8('0x47')](_0x1907f9[_0x9bf8('0x45')])[_0x9bf8('0x11')](function(_0x21aad3){if(_0x21aad3){if(_0x21aad3['direction']===_0x9bf8('0x48')&&!_0x21aad3['secret']){var _0x1a5a93,_0x23d669,_0x514748;if(_0x1907f9['body']['to']){_0x23d669=_0x1907f9[_0x9bf8('0x45')]['to']['split'](',')[0x0];}return db[_0x9bf8('0x49')][_0x9bf8('0x4a')]({'where':{'id':_0x21aad3['MailAccountId']},'include':[{'model':db[_0x9bf8('0x4b')],'as':_0x9bf8('0x4c'),'include':[{'model':db['CmContact'],'as':_0x9bf8('0x4d'),'where':{'email':_0x23d669},'limit':0x1,'order':[[_0x9bf8('0x4e'),_0x9bf8('0x4f')]]}]},{'model':db[_0x9bf8('0x50')],'as':_0x9bf8('0x51'),'raw':!![],'include':[{'model':db[_0x9bf8('0x52')],'as':_0x9bf8('0x52'),'raw':!![]}]}]})[_0x9bf8('0x11')](function(_0x425250){_0x1a5a93=_0x425250;if(!_0x1a5a93||!_0x1a5a93[_0x9bf8('0x51')])return;var _0x1e7d70=_0x1a5a93[_0x9bf8('0x53')]();if(_0x1907f9[_0x9bf8('0x45')][_0x9bf8('0x54')]&&_0x1907f9['body'][_0x9bf8('0x54')][_0x9bf8('0x34')]){for(var _0x5513d7=0x0;_0x5513d7<_0x1907f9[_0x9bf8('0x45')][_0x9bf8('0x54')][_0x9bf8('0x34')];_0x5513d7+=0x1){_0x1907f9[_0x9bf8('0x45')][_0x9bf8('0x54')][_0x5513d7]={'filename':_0x1907f9['body'][_0x9bf8('0x54')][_0x5513d7]['name'],'path':path[_0x9bf8('0x55')](config[_0x9bf8('0x56')],_0x9bf8('0x57'),_0x1907f9[_0x9bf8('0x45')]['attachments'][_0x5513d7][_0x9bf8('0x58')])};}}_0x514748={'account':_0x1e7d70,'message':_0x1907f9[_0x9bf8('0x45')]};return;})[_0x9bf8('0x11')](function(){if(_0x1a5a93[_0x9bf8('0x4c')]){if(_0x1a5a93[_0x9bf8('0x4c')][_0x9bf8('0x4d')]['length']){return _0x1a5a93[_0x9bf8('0x4c')]['Contacts'][0x0];}else{return db[_0x9bf8('0x59')][_0x9bf8('0x47')](_[_0x9bf8('0xa')](_0x1907f9['body'],{'firstName':_0x1907f9['body']['to'],'email':_0x1907f9['body']['to'],'phone':_0x1907f9[_0x9bf8('0x45')]['to'],'ListId':_0x1a5a93[_0x9bf8('0x5a')]}));}}else{throw new Error('List\x20not\x20found');}})['then'](function(){if(_0x514748){return respondWithRpcPromise(_0x9bf8('0x5b'),_0x9bf8('0x5c'),_0x514748,client9003)[_0x9bf8('0x11')](function(_0x52c921){return _0x21aad3[_0x9bf8('0x23')]({'read':!![],'messageId':_0x52c921['messageId'],'sentAt':moment()[_0x9bf8('0x5d')](_0x9bf8('0x5e'))});})[_0x9bf8('0x1a')](function(_0x49836f){logger[_0x9bf8('0x17')]('%s',JSON[_0x9bf8('0x5f')](_0x49836f));return _0x21aad3;});}return _0x21aad3;});}return _0x21aad3;}})[_0x9bf8('0x11')](respondWithResult(_0x2d7bf9,0xc9))['catch'](handleError(_0x2d7bf9,null));};exports[_0x9bf8('0x60')]=function(_0x25f636,_0x3a3213){var _0xee886c={'agent':{},'channel':'mail'};if(_0x25f636[_0x9bf8('0x45')]['id']){delete _0x25f636[_0x9bf8('0x45')]['id'];}_0x25f636[_0x9bf8('0x45')][_0x9bf8('0x61')]=!![];_0x25f636['body'][_0x9bf8('0x62')]=moment()['format'](_0x9bf8('0x5e'));_0x25f636[_0x9bf8('0x45')][_0x9bf8('0x63')]=_0x25f636['body'][_0x9bf8('0x63')]||_0x25f636['user']['id'];_0xee886c[_0x9bf8('0x64')]['id']=_0x25f636[_0x9bf8('0x45')][_0x9bf8('0x63')];return db['MailMessage'][_0x9bf8('0x44')]({'where':{'id':_0x25f636[_0x9bf8('0x46')]['id'],'UserId':null}})[_0x9bf8('0x11')](handleEntityNotFound(_0x3a3213,null))[_0x9bf8('0x11')](saveUpdates(_0x25f636[_0x9bf8('0x45')],null))[_0x9bf8('0x11')](function(_0x34d896){if(_0x34d896){_0xee886c[_0x9bf8('0x18')]=_0x34d896[_0x9bf8('0x65')]({'plain':!![]});return db[_0x9bf8('0x66')][_0x9bf8('0x44')]({'where':{'id':_0x34d896[_0x9bf8('0x67')]}});}return null;})[_0x9bf8('0x11')](handleEntityNotFound(_0x3a3213,null))[_0x9bf8('0x11')](function(_0x5650cb){if(_0x5650cb){return _0x5650cb[_0x9bf8('0x23')]({'UserId':_0x25f636[_0x9bf8('0x45')][_0x9bf8('0x63')],'read1stAt':_[_0x9bf8('0x68')](_0x5650cb['read1stAt'])?moment()[_0x9bf8('0x5d')](_0x9bf8('0x5e')):undefined});}return null;})[_0x9bf8('0x11')](function(_0x2c1545){if(_0x2c1545){_0xee886c[_0x9bf8('0x69')]=_0x2c1545['get']({'plain':!![]});interaction_log[_0x9bf8('0x12')](_0x9bf8('0x6a'),_0x25f636[_0x9bf8('0x6b')]['id'],_0x25f636['user'][_0x9bf8('0x25')],_0x25f636[_0x9bf8('0x6b')][_0x9bf8('0x6c')],_0xee886c[_0x9bf8('0x69')]['id'],_0x25f636['body']?JSON[_0x9bf8('0x5f')](_0x25f636[_0x9bf8('0x45')]):'null');return respondWithRpcPromise('AcceptMessage',_0x9bf8('0x6d'),_0xee886c);}return null;})[_0x9bf8('0x11')](function(_0xc754ad){var _0x124e6a=_0x9bf8('0x6e')+_0xc754ad[_0x9bf8('0x18')][_0x9bf8('0x6f')];return db[_0x9bf8('0x70')][_0x9bf8('0x2f')](_0x124e6a,{'type':db[_0x9bf8('0x71')][_0x9bf8('0x72')][_0x9bf8('0x73')],'raw':!![]})[_0x9bf8('0x11')](function(_0x33e926){return _0x33e926;});})[_0x9bf8('0x11')](function(_0xf7de12){if(_0xf7de12){_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x74')]=_0xf7de12[0x0];if(!_0x25f636[_0x9bf8('0x45')]['UserId'])return;return db[_0x9bf8('0x75')][_0x9bf8('0x44')]({'where':{'id':_0x25f636[_0x9bf8('0x45')][_0x9bf8('0x63')],'role':_0x9bf8('0x64')},'attributes':['id',_0x9bf8('0x25'),'fullname',_0x9bf8('0x76'),_0x9bf8('0x77')],'raw':!![]});}return null;})[_0x9bf8('0x11')](function(_0x54f3e6){if(!_0x54f3e6)return null;_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x64')]=_0x54f3e6;return _0xee886c;})['then'](function(_0x15e322){if(_0x15e322){if(_0x25f636[_0x9bf8('0x45')][_0x9bf8('0x78')]){_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x79')]=util[_0x9bf8('0x5d')](_0x9bf8('0x7a'),_0x25f636[_0x9bf8('0x6b')][_0x9bf8('0x25')]);_0xee886c['message']['channel']=_0xee886c['channel'];_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x7b')]=_0xee886c[_0x9bf8('0x7c')];_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x7d')]=_0x9bf8('0x60');_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x45')]=htmlToText['fromString'](_0xee886c[_0x9bf8('0x18')][_0x9bf8('0x45')]);return respondWithRpcPromise(_0x9bf8('0x7e'),_0x9bf8('0x7e'),{'event':_0x9bf8('0x7f'),'message':_0xee886c['message']},client9002)['then'](function(){return _0xee886c;});}return _0xee886c;}return null;})['then'](respondWithResult(_0x3a3213,null))[_0x9bf8('0x1a')](handleError(_0x3a3213,null));};exports[_0x9bf8('0x80')]=function(_0x4a52c6,_0x21aed7){var _0x1499ef={'agent':{},'channel':_0x9bf8('0x81')};if(_0x4a52c6[_0x9bf8('0x45')]['id']){delete _0x4a52c6[_0x9bf8('0x45')]['id'];}_0x4a52c6[_0x9bf8('0x45')][_0x9bf8('0x63')]=_0x4a52c6['body'][_0x9bf8('0x63')]||_0x4a52c6[_0x9bf8('0x6b')]['id'];_0x1499ef[_0x9bf8('0x64')]['id']=_0x4a52c6[_0x9bf8('0x45')][_0x9bf8('0x63')];return db[_0x9bf8('0x29')][_0x9bf8('0x44')]({'where':{'id':_0x4a52c6[_0x9bf8('0x46')]['id'],'UserId':null}})[_0x9bf8('0x11')](handleEntityNotFound(_0x21aed7,null))[_0x9bf8('0x11')](function(_0x3bd88f){if(_0x3bd88f){_0x1499ef['message']=_0x3bd88f[_0x9bf8('0x65')]({'plain':!![]});return db['MailInteraction'][_0x9bf8('0x44')]({'where':{'id':_0x3bd88f[_0x9bf8('0x67')]}});}return null;})[_0x9bf8('0x11')](handleEntityNotFound(_0x21aed7,null))[_0x9bf8('0x11')](function(_0x3b4d09){if(_0x3b4d09){_0x1499ef[_0x9bf8('0x69')]=_0x3b4d09[_0x9bf8('0x65')]({'plain':!![]});interaction_log[_0x9bf8('0x12')](_0x9bf8('0x82'),_0x4a52c6[_0x9bf8('0x6b')]['id'],_0x4a52c6[_0x9bf8('0x6b')]['name'],_0x4a52c6[_0x9bf8('0x6b')]['role'],_0x1499ef['interaction']['id'],_0x4a52c6[_0x9bf8('0x45')]?JSON[_0x9bf8('0x5f')](_0x4a52c6[_0x9bf8('0x45')]):'null');return respondWithRpcPromise(_0x9bf8('0x83'),_0x9bf8('0x84'),_0x1499ef);}return null;})['then'](function(_0x400f15){var _0x34fa35=_0x9bf8('0x6e')+_0x400f15[_0x9bf8('0x18')]['ContactId'];return db['sequelize'][_0x9bf8('0x2f')](_0x34fa35,{'type':db[_0x9bf8('0x71')][_0x9bf8('0x72')]['SELECT'],'raw':!![]})[_0x9bf8('0x11')](function(_0xd30698){return _0xd30698;});})[_0x9bf8('0x11')](function(_0x2407a7){if(_0x2407a7){_0x1499ef[_0x9bf8('0x18')][_0x9bf8('0x74')]=_0x2407a7[0x0];if(!_0x4a52c6[_0x9bf8('0x45')]['UserId'])return;return db[_0x9bf8('0x75')][_0x9bf8('0x44')]({'where':{'id':_0x4a52c6[_0x9bf8('0x45')][_0x9bf8('0x63')],'role':_0x9bf8('0x64')},'attributes':['id',_0x9bf8('0x25'),_0x9bf8('0x85'),_0x9bf8('0x76'),'internal'],'raw':!![]});}return null;})['then'](function(_0x44e329){if(!_0x44e329)return null;_0x1499ef[_0x9bf8('0x18')]['agent']=_0x44e329;return _0x1499ef;})[_0x9bf8('0x11')](function(_0x3e4cba){if(_0x3e4cba){_0x3e4cba['message']['interface']=util[_0x9bf8('0x5d')](_0x9bf8('0x7a'),_0x4a52c6[_0x9bf8('0x6b')][_0x9bf8('0x25')]);_0x3e4cba['message'][_0x9bf8('0x7c')]=_0x1499ef['channel'];_0x3e4cba[_0x9bf8('0x18')][_0x9bf8('0x7b')]=_0x1499ef['channel'];_0x3e4cba['message'][_0x9bf8('0x7d')]=_0x9bf8('0x80');_0x3e4cba['message'][_0x9bf8('0x45')]=htmlToText['fromString'](_0x1499ef[_0x9bf8('0x18')][_0x9bf8('0x45')]);respondWithRpcPromise(_0x9bf8('0x7e'),_0x9bf8('0x7e'),{'event':_0x9bf8('0x86'),'message':_0x3e4cba[_0x9bf8('0x18')]},client9002);return _0x1499ef;}return null;})[_0x9bf8('0x11')](respondWithResult(_0x21aed7,null))['catch'](handleError(_0x21aed7,null));};exports[_0x9bf8('0x87')]=function(_0x45ac1b,_0x141993){var _0x49e128=moment()['unix']()[_0x9bf8('0x88')]();var _0x3e05f7=path[_0x9bf8('0x55')](config[_0x9bf8('0x56')],'server',_0x9bf8('0x89'),_0x9bf8('0x8a'));var _0x5f20a0=path['join'](config['root'],_0x9bf8('0x8b'),'files','attachments');var _0x53767a=util[_0x9bf8('0x5d')](_0x9bf8('0x8c'),_0x49e128);return db[_0x9bf8('0x29')]['find']({'where':{'id':_0x45ac1b[_0x9bf8('0x46')]['id']},'attributes':['id','body',_0x9bf8('0x8d'),'to','cc','bcc',_0x9bf8('0x8e'),_0x9bf8('0x8f')],'include':_0x45ac1b[_0x9bf8('0x2f')][_0x9bf8('0x54')]?[{'model':db[_0x9bf8('0x90')],'as':'Attachments'}]:undefined})['then'](handleEntityNotFound(_0x141993,null))[_0x9bf8('0x11')](function(_0x34d497){if(_0x34d497){var _0x140da7=_0x34d497;var _0x36cdb2={'from':_0x140da7[_0x9bf8('0x8d')],'to':_0x140da7['to'],'subject':_0x140da7[_0x9bf8('0x8e')],'html':htmlEntities[_0x9bf8('0x91')](_0x140da7[_0x9bf8('0x45')]),'headers':{'Date':moment(_0x140da7['createdAt'])['format']('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x34d497['cc']){_0x36cdb2['headers']['Cc']=_0x34d497['cc'];}if(_0x34d497[_0x9bf8('0x92')]){_0x36cdb2[_0x9bf8('0x93')]['Bcc']=_0x34d497[_0x9bf8('0x92')];}return new BPromise(function(_0x1a1115,_0x42c7c7){if(_0x34d497[_0x9bf8('0x94')]){for(var _0x529fa0=0x0;_0x529fa0<_0x34d497['Attachments'][_0x9bf8('0x34')];_0x529fa0++){var _0x1744ea=_0x34d497[_0x9bf8('0x94')][_0x529fa0];var _0x2c7ab9=path['join'](_0x5f20a0,_0x1744ea[_0x9bf8('0x58')]);if(fs['existsSync'](_0x2c7ab9)){_0x36cdb2[_0x9bf8('0x54')][_0x9bf8('0x95')]({'name':_0x1744ea[_0x9bf8('0x25')],'contentType':_0x1744ea[_0x9bf8('0x2c')],'data':fs[_0x9bf8('0x96')](_0x2c7ab9)});}}}emlformat[_0x9bf8('0x97')](_0x36cdb2,function(_0x163fb0,_0x328f36){if(_0x163fb0)return _0x42c7c7(_0x163fb0);fs[_0x9bf8('0x98')](path[_0x9bf8('0x55')](_0x3e05f7,_0x53767a),_0x328f36);return _0x1a1115(_0x328f36);});});}})['then'](function(_0x486a1b){if(_0x486a1b){return _0x141993[_0x9bf8('0x87')](path['join'](_0x3e05f7,_0x53767a),_0x53767a,function(_0x1a2f93){if(!_0x1a2f93)fs['unlinkSync'](path[_0x9bf8('0x55')](_0x3e05f7,_0x53767a));});}})[_0x9bf8('0x1a')](handleError(_0x141993,null));};
\ No newline at end of file
+var _0x1da8=['email','internal','interface','SIP/%s','channel','motionChannel','reject','fromString','EventManager','rejectmessage','unix','toString','join','server','files','message-%s.eml','from','createdAt','Attachment','Attachments','subject','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','bcc','Bcc','existsSync','push','build','download','util','path','lodash','ioredis','html-to-text','../../components/interaction/service','../../components/parsers/qs','api','../../config/logger','../../config/environment','../../mysqldb','localhost','socket.io-emitter','redis','client','http','request','then','info','MailMessage,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','MailMessage,\x20%s,\x20%s','catch','status','json','offset','undefined','limit','count','update','end','sendStatus','stack','name','index','map','MailMessage','rawAttributes','fieldName','type','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','params','fields','options','find','body','destroy','describe','create','direction','split','findOne','CmList','List','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','root','server/files/attachments','basename','Contacts','defaults','List\x20not\x20found','SendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','UserId','user','agent','get','MailInteractionId','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','QueryTypes','contact','User'];(function(_0x5ab7ec,_0x57a517){var _0x29b724=function(_0x2ac13e){while(--_0x2ac13e){_0x5ab7ec['push'](_0x5ab7ec['shift']());}};_0x29b724(++_0x57a517);}(_0x1da8,0x1c2));var _0x81da=function(_0x2e2d8d,_0x407eb5){_0x2e2d8d=_0x2e2d8d-0x0;var _0x31645c=_0x1da8[_0x2e2d8d];return _0x31645c;};'use strict';var emlformat=require('eml-format');var moment=require('moment');var util=require(_0x81da('0x0'));var path=require(_0x81da('0x1'));var fs=require('fs');var _=require(_0x81da('0x2'));var Redis=require(_0x81da('0x3'));var htmlToText=require(_0x81da('0x4'));var interactionService=require(_0x81da('0x5'));var qs=require(_0x81da('0x6'));var logger=require('../../config/logger')(_0x81da('0x7'));var interaction_log=require(_0x81da('0x8'))('mail-interactions');var config=require(_0x81da('0x9'));var db=require(_0x81da('0xa'))['db'];config['redis']=_['defaults'](config['redis'],{'host':_0x81da('0xb'),'port':0x18eb});var socket=require(_0x81da('0xc'))(new Redis(config[_0x81da('0xd')]));var htmlEntities=require('html-entities');require('./mailMessage.socket')['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x81da('0xe')]['http']({'port':0x232c});var client9003=jayson[_0x81da('0xe')][_0x81da('0xf')]({'port':0x232b});var client9002=jayson[_0x81da('0xe')]['http']({'port':0x232a});function respondWithRpcPromise(_0x3d5a75,_0x54bfd3,_0x49174f,_0x25120f){return new Promise(function(_0x2f560c,_0x4d90ac){var _0x35c2d8=_0x25120f||client;return _0x35c2d8[_0x81da('0x10')](_0x3d5a75,_0x49174f)[_0x81da('0x11')](function(_0x132ea0){logger[_0x81da('0x12')]('MailMessage,\x20%s,\x20%s',_0x54bfd3,'request\x20sent');logger['debug'](_0x81da('0x13'),_0x54bfd3,_0x81da('0x14'),JSON[_0x81da('0x15')](_0x132ea0));if(_0x132ea0[_0x81da('0x16')]){if(_0x132ea0['error'][_0x81da('0x17')]===0x1f4){logger['error']('MailMessage,\x20%s,\x20%s',_0x54bfd3,_0x132ea0[_0x81da('0x16')]['message']);return _0x4d90ac(_0x132ea0[_0x81da('0x16')][_0x81da('0x18')]);}logger['error'](_0x81da('0x19'),_0x54bfd3,_0x132ea0[_0x81da('0x16')][_0x81da('0x18')]);return _0x2f560c(_0x132ea0[_0x81da('0x16')][_0x81da('0x18')]);}else{logger[_0x81da('0x12')](_0x81da('0x19'),_0x54bfd3,_0x81da('0x14'));_0x2f560c(_0x132ea0['result'][_0x81da('0x18')]);}})[_0x81da('0x1a')](function(_0xe804f3){logger[_0x81da('0x16')](_0x81da('0x19'),_0x54bfd3,_0xe804f3);_0x4d90ac(_0xe804f3);});});}function respondWithResult(_0x357f85,_0x553230){_0x553230=_0x553230||0xc8;return function(_0x4f6285){if(_0x4f6285){return _0x357f85[_0x81da('0x1b')](_0x553230)[_0x81da('0x1c')](_0x4f6285);}};}function respondWithFilteredResult(_0x84118c,_0x162a95){return function(_0x17a952){if(_0x17a952){var _0x20089e=typeof _0x162a95[_0x81da('0x1d')]===_0x81da('0x1e')&&typeof _0x162a95[_0x81da('0x1f')]===_0x81da('0x1e');var _0x534f71=_0x17a952[_0x81da('0x20')];var _0x469439=_0x20089e?0x0:_0x162a95[_0x81da('0x1d')];var _0x5aedc6=_0x20089e?_0x17a952['count']:_0x162a95[_0x81da('0x1d')]+_0x162a95[_0x81da('0x1f')];var _0x222d3a;if(_0x5aedc6>=_0x534f71){_0x5aedc6=_0x534f71;_0x222d3a=0xc8;}else{_0x222d3a=0xce;}_0x84118c['status'](_0x222d3a);return _0x84118c['set']('Content-Range',_0x469439+'-'+_0x5aedc6+'/'+_0x534f71)[_0x81da('0x1c')](_0x17a952);}return null;};}function saveUpdates(_0x1dcefe){return function(_0x3e9615){if(_0x3e9615){return _0x3e9615[_0x81da('0x21')](_0x1dcefe)[_0x81da('0x11')](function(_0x1b064b){return _0x1b064b;});}return null;};}function removeEntity(_0x14970f){return function(_0x4ebda1){if(_0x4ebda1){return _0x4ebda1['destroy']()[_0x81da('0x11')](function(){_0x14970f[_0x81da('0x1b')](0xcc)[_0x81da('0x22')]();});}};}function handleEntityNotFound(_0xfc65aa){return function(_0x5f1ec1){if(!_0x5f1ec1){_0xfc65aa[_0x81da('0x23')](0x194);}return _0x5f1ec1;};}function handleError(_0x300c89,_0x138677){_0x138677=_0x138677||0x1f4;return function(_0xd63409){logger['error'](_0xd63409[_0x81da('0x24')]);if(_0xd63409[_0x81da('0x25')]){delete _0xd63409[_0x81da('0x25')];}_0x300c89[_0x81da('0x1b')](_0x138677)['send'](_0xd63409);};}exports[_0x81da('0x26')]=function(_0x52a44e,_0x1d59f0){var _0x3acbbf={},_0xb6c577={},_0x1d3167={'count':0x0,'rows':[]};var _0x27789d=_[_0x81da('0x27')](db[_0x81da('0x28')][_0x81da('0x29')],function(_0x534c58){return{'name':_0x534c58[_0x81da('0x2a')],'type':_0x534c58[_0x81da('0x2b')][_0x81da('0x2c')]};});_0xb6c577[_0x81da('0x2d')]=_[_0x81da('0x27')](_0x27789d,_0x81da('0x25'));_0xb6c577[_0x81da('0x2e')]=_[_0x81da('0x2f')](_0x52a44e['query']);_0xb6c577[_0x81da('0x30')]=_[_0x81da('0x31')](_0xb6c577[_0x81da('0x2d')],_0xb6c577[_0x81da('0x2e')]);_0x3acbbf[_0x81da('0x32')]=_['intersection'](_0xb6c577['model'],qs['fields'](_0x52a44e[_0x81da('0x2e')]['fields']));_0x3acbbf[_0x81da('0x32')]=_0x3acbbf[_0x81da('0x32')][_0x81da('0x33')]?_0x3acbbf[_0x81da('0x32')]:_0xb6c577[_0x81da('0x2d')];if(!_0x52a44e[_0x81da('0x2e')][_0x81da('0x34')](_0x81da('0x35'))){_0x3acbbf[_0x81da('0x1f')]=qs['limit'](_0x52a44e[_0x81da('0x2e')][_0x81da('0x1f')]);_0x3acbbf[_0x81da('0x1d')]=qs['offset'](_0x52a44e[_0x81da('0x2e')][_0x81da('0x1d')]);}_0x3acbbf[_0x81da('0x36')]=qs[_0x81da('0x37')](_0x52a44e[_0x81da('0x2e')][_0x81da('0x37')]);_0x3acbbf[_0x81da('0x38')]=qs[_0x81da('0x30')](_[_0x81da('0x39')](_0x52a44e['query'],_0xb6c577['filters']),_0x27789d);if(_0x52a44e[_0x81da('0x2e')][_0x81da('0x3a')]){_0x3acbbf[_0x81da('0x38')]=_[_0x81da('0x3b')](_0x3acbbf[_0x81da('0x38')],{'$or':_['map'](_0x27789d,function(_0x1a31f7){if(_0x1a31f7['type']!==_0x81da('0x3c')){var _0x521494={};_0x521494[_0x1a31f7[_0x81da('0x25')]]={'$like':'%'+_0x52a44e[_0x81da('0x2e')]['filter']+'%'};return _0x521494;}})});}_0x3acbbf=_[_0x81da('0x3b')]({},_0x3acbbf,_0x52a44e['options']);var _0x22f666={'where':_0x3acbbf[_0x81da('0x38')]};return db['MailMessage'][_0x81da('0x20')](_0x22f666)[_0x81da('0x11')](function(_0x32753c){_0x1d3167['count']=_0x32753c;if(_0x52a44e[_0x81da('0x2e')][_0x81da('0x3d')]){_0x3acbbf[_0x81da('0x3e')]=[{'all':!![]}];}return db[_0x81da('0x28')][_0x81da('0x3f')](_0x3acbbf);})[_0x81da('0x11')](function(_0x5c41ac){_0x1d3167[_0x81da('0x40')]=_0x5c41ac;return _0x1d3167;})[_0x81da('0x11')](respondWithFilteredResult(_0x1d59f0,_0x3acbbf))[_0x81da('0x1a')](handleError(_0x1d59f0,null));};exports['show']=function(_0x518d1e,_0x166cbd){var _0x11b9e3={'raw':!![],'where':{'id':_0x518d1e[_0x81da('0x41')]['id']}},_0x18c519={};_0x18c519[_0x81da('0x2d')]=_[_0x81da('0x2f')](db[_0x81da('0x28')][_0x81da('0x29')]);_0x18c519[_0x81da('0x2e')]=_[_0x81da('0x2f')](_0x518d1e[_0x81da('0x2e')]);_0x18c519['filters']=_['intersection'](_0x18c519[_0x81da('0x2d')],_0x18c519[_0x81da('0x2e')]);_0x11b9e3['attributes']=_['intersection'](_0x18c519[_0x81da('0x2d')],qs[_0x81da('0x42')](_0x518d1e[_0x81da('0x2e')][_0x81da('0x42')]));_0x11b9e3[_0x81da('0x32')]=_0x11b9e3[_0x81da('0x32')]['length']?_0x11b9e3['attributes']:_0x18c519[_0x81da('0x2d')];if(_0x518d1e['query'][_0x81da('0x3d')]){_0x11b9e3[_0x81da('0x3e')]=[{'all':!![]}];}_0x11b9e3=_['merge']({},_0x11b9e3,_0x518d1e[_0x81da('0x43')]);return db[_0x81da('0x28')][_0x81da('0x44')](_0x11b9e3)['then'](handleEntityNotFound(_0x166cbd,null))['then'](respondWithResult(_0x166cbd,null))['catch'](handleError(_0x166cbd,null));};exports[_0x81da('0x21')]=function(_0x290614,_0x1785e3){if(_0x290614[_0x81da('0x45')]['id']){delete _0x290614[_0x81da('0x45')]['id'];}return db[_0x81da('0x28')]['find']({'where':{'id':_0x290614[_0x81da('0x41')]['id']}})['then'](handleEntityNotFound(_0x1785e3,null))[_0x81da('0x11')](saveUpdates(_0x290614[_0x81da('0x45')],null))[_0x81da('0x11')](respondWithResult(_0x1785e3,null))[_0x81da('0x1a')](handleError(_0x1785e3,null));};exports[_0x81da('0x46')]=function(_0x1ab797,_0x38057f){return db['MailMessage'][_0x81da('0x44')]({'where':{'id':_0x1ab797[_0x81da('0x41')]['id']}})['then'](handleEntityNotFound(_0x38057f,null))['then'](removeEntity(_0x38057f,null))[_0x81da('0x1a')](handleError(_0x38057f,null));};exports[_0x81da('0x47')]=function(_0x5954fa,_0x54311b){return db[_0x81da('0x28')]['describe']()['then'](respondWithResult(_0x54311b,null))[_0x81da('0x1a')](handleError(_0x54311b,null));};exports[_0x81da('0x48')]=function(_0x40f5a0,_0x3a940b){return db['MailMessage']['create'](_0x40f5a0['body'])[_0x81da('0x11')](function(_0x5e9360){if(_0x5e9360){if(_0x5e9360[_0x81da('0x49')]==='out'&&!_0x5e9360['secret']){var _0x51a25f,_0x122447,_0x4db720;if(_0x40f5a0[_0x81da('0x45')]['to']){_0x122447=_0x40f5a0[_0x81da('0x45')]['to'][_0x81da('0x4a')](',')[0x0];}return db['MailAccount'][_0x81da('0x4b')]({'where':{'id':_0x5e9360['MailAccountId']},'include':[{'model':db[_0x81da('0x4c')],'as':_0x81da('0x4d'),'include':[{'model':db['CmContact'],'as':'Contacts','where':{'email':_0x122447},'limit':0x1,'order':[[_0x81da('0x4e'),_0x81da('0x4f')]]}]},{'model':db[_0x81da('0x50')],'as':_0x81da('0x51'),'raw':!![],'include':[{'model':db[_0x81da('0x52')],'as':_0x81da('0x52'),'raw':!![]}]}]})[_0x81da('0x11')](function(_0x3ad2bb){_0x51a25f=_0x3ad2bb;if(!_0x51a25f||!_0x51a25f['Smtp'])return;var _0x4ad320=_0x51a25f[_0x81da('0x53')]();if(_0x40f5a0[_0x81da('0x45')][_0x81da('0x54')]&&_0x40f5a0[_0x81da('0x45')][_0x81da('0x54')][_0x81da('0x33')]){for(var _0xe29e78=0x0;_0xe29e78<_0x40f5a0[_0x81da('0x45')][_0x81da('0x54')][_0x81da('0x33')];_0xe29e78+=0x1){_0x40f5a0[_0x81da('0x45')]['attachments'][_0xe29e78]={'filename':_0x40f5a0['body'][_0x81da('0x54')][_0xe29e78][_0x81da('0x25')],'path':path['join'](config[_0x81da('0x55')],_0x81da('0x56'),_0x40f5a0['body'][_0x81da('0x54')][_0xe29e78][_0x81da('0x57')])};}}_0x4db720={'account':_0x4ad320,'message':_0x40f5a0['body']};return;})[_0x81da('0x11')](function(){if(_0x51a25f[_0x81da('0x4d')]){if(_0x51a25f[_0x81da('0x4d')]['Contacts'][_0x81da('0x33')]){return _0x51a25f[_0x81da('0x4d')][_0x81da('0x58')][0x0];}else{return db['CmContact'][_0x81da('0x48')](_[_0x81da('0x59')](_0x40f5a0['body'],{'firstName':_0x40f5a0[_0x81da('0x45')]['to'],'email':_0x40f5a0[_0x81da('0x45')]['to'],'phone':_0x40f5a0[_0x81da('0x45')]['to'],'ListId':_0x51a25f['ListId']}));}}else{throw new Error(_0x81da('0x5a'));}})['then'](function(){if(_0x4db720){return respondWithRpcPromise(_0x81da('0x5b'),'sendMail',_0x4db720,client9003)[_0x81da('0x11')](function(_0x2d31bb){return _0x5e9360[_0x81da('0x21')]({'read':!![],'messageId':_0x2d31bb[_0x81da('0x5c')],'sentAt':moment()[_0x81da('0x5d')](_0x81da('0x5e'))});})[_0x81da('0x1a')](function(_0x27827d){logger[_0x81da('0x16')]('%s',JSON[_0x81da('0x15')](_0x27827d));return _0x5e9360;});}return _0x5e9360;});}return _0x5e9360;}})[_0x81da('0x11')](respondWithResult(_0x3a940b,0xc9))[_0x81da('0x1a')](handleError(_0x3a940b,null));};exports[_0x81da('0x5f')]=function(_0x4458f0,_0x46cc53){var _0x28416e=_0x81da('0x60');return interactionService['acceptMessage'](_0x4458f0,_0x28416e)['then'](respondWithResult(_0x46cc53,null))[_0x81da('0x1a')](handleError(_0x46cc53,null));};exports['reject']=function(_0x1354d2,_0x4f88fb){var _0x24e000={'agent':{},'channel':_0x81da('0x60')};if(_0x1354d2[_0x81da('0x45')]['id']){delete _0x1354d2[_0x81da('0x45')]['id'];}_0x1354d2[_0x81da('0x45')]['UserId']=_0x1354d2[_0x81da('0x45')][_0x81da('0x61')]||_0x1354d2[_0x81da('0x62')]['id'];_0x24e000[_0x81da('0x63')]['id']=_0x1354d2['body'][_0x81da('0x61')];return db['MailMessage'][_0x81da('0x44')]({'where':{'id':_0x1354d2[_0x81da('0x41')]['id'],'UserId':null}})[_0x81da('0x11')](handleEntityNotFound(_0x4f88fb,null))[_0x81da('0x11')](function(_0x295791){if(_0x295791){_0x24e000[_0x81da('0x18')]=_0x295791[_0x81da('0x64')]({'plain':!![]});return db['MailInteraction'][_0x81da('0x44')]({'where':{'id':_0x295791[_0x81da('0x65')]}});}return null;})['then'](handleEntityNotFound(_0x4f88fb,null))['then'](function(_0x2a6706){if(_0x2a6706){_0x24e000['interaction']=_0x2a6706[_0x81da('0x64')]({'plain':!![]});interaction_log[_0x81da('0x12')](_0x81da('0x66'),_0x1354d2[_0x81da('0x62')]['id'],_0x1354d2['user'][_0x81da('0x25')],_0x1354d2[_0x81da('0x62')][_0x81da('0x67')],_0x24e000['interaction']['id'],_0x1354d2[_0x81da('0x45')]?JSON[_0x81da('0x15')](_0x1354d2[_0x81da('0x45')]):'null');return respondWithRpcPromise('RejectMessage',_0x81da('0x68'),_0x24e000);}return null;})[_0x81da('0x11')](function(_0x583002){var _0x44fac3=_0x81da('0x69')+_0x583002[_0x81da('0x18')]['ContactId'];return db[_0x81da('0x6a')][_0x81da('0x2e')](_0x44fac3,{'type':db['Sequelize'][_0x81da('0x6b')]['SELECT'],'raw':!![]})['then'](function(_0x3dd52f){return _0x3dd52f;});})[_0x81da('0x11')](function(_0x4c6c63){if(_0x4c6c63){_0x24e000[_0x81da('0x18')][_0x81da('0x6c')]=_0x4c6c63[0x0];if(!_0x1354d2['body']['UserId'])return;return db[_0x81da('0x6d')][_0x81da('0x44')]({'where':{'id':_0x1354d2[_0x81da('0x45')]['UserId'],'role':_0x81da('0x63')},'attributes':['id',_0x81da('0x25'),'fullname',_0x81da('0x6e'),_0x81da('0x6f')],'raw':!![]});}return null;})[_0x81da('0x11')](function(_0x46a81c){if(!_0x46a81c)return null;_0x24e000[_0x81da('0x18')]['agent']=_0x46a81c;return _0x24e000;})['then'](function(_0x5003fa){if(_0x5003fa){_0x5003fa[_0x81da('0x18')][_0x81da('0x70')]=util[_0x81da('0x5d')](_0x81da('0x71'),_0x1354d2[_0x81da('0x62')][_0x81da('0x25')]);_0x5003fa['message'][_0x81da('0x72')]=_0x24e000[_0x81da('0x72')];_0x5003fa['message'][_0x81da('0x73')]=_0x24e000[_0x81da('0x72')];_0x5003fa[_0x81da('0x18')]['event']=_0x81da('0x74');_0x5003fa[_0x81da('0x18')][_0x81da('0x45')]=htmlToText[_0x81da('0x75')](_0x24e000[_0x81da('0x18')][_0x81da('0x45')]);respondWithRpcPromise(_0x81da('0x76'),_0x81da('0x76'),{'event':_0x81da('0x77'),'message':_0x5003fa['message']},client9002);return _0x24e000;}return null;})[_0x81da('0x11')](respondWithResult(_0x4f88fb,null))['catch'](handleError(_0x4f88fb,null));};exports['download']=function(_0x2b8ae8,_0x225c24){var _0x37ac71=moment()[_0x81da('0x78')]()[_0x81da('0x79')]();var _0x2c27f9=path[_0x81da('0x7a')](config['root'],_0x81da('0x7b'),_0x81da('0x7c'),'tmp');var _0x158667=path['join'](config[_0x81da('0x55')],_0x81da('0x7b'),_0x81da('0x7c'),_0x81da('0x54'));var _0x3f89a5=util[_0x81da('0x5d')](_0x81da('0x7d'),_0x37ac71);return db[_0x81da('0x28')][_0x81da('0x44')]({'where':{'id':_0x2b8ae8[_0x81da('0x41')]['id']},'attributes':['id','body',_0x81da('0x7e'),'to','cc','bcc','subject',_0x81da('0x7f')],'include':_0x2b8ae8[_0x81da('0x2e')][_0x81da('0x54')]?[{'model':db[_0x81da('0x80')],'as':_0x81da('0x81')}]:undefined})[_0x81da('0x11')](handleEntityNotFound(_0x225c24,null))[_0x81da('0x11')](function(_0x3a1acd){if(_0x3a1acd){var _0x99b3a=_0x3a1acd;var _0x46b8fc={'from':_0x99b3a[_0x81da('0x7e')],'to':_0x99b3a['to'],'subject':_0x99b3a[_0x81da('0x82')],'html':htmlEntities[_0x81da('0x83')](_0x99b3a[_0x81da('0x45')]),'headers':{'Date':moment(_0x99b3a[_0x81da('0x7f')])[_0x81da('0x5d')](_0x81da('0x84'))},'attachments':[]};if(_0x3a1acd['cc']){_0x46b8fc[_0x81da('0x85')]['Cc']=_0x3a1acd['cc'];}if(_0x3a1acd[_0x81da('0x86')]){_0x46b8fc[_0x81da('0x85')][_0x81da('0x87')]=_0x3a1acd[_0x81da('0x86')];}return new Promise(function(_0x682f69,_0x5c061a){if(_0x3a1acd[_0x81da('0x81')]){for(var _0x2fc4fd=0x0;_0x2fc4fd<_0x3a1acd[_0x81da('0x81')]['length'];_0x2fc4fd++){var _0xc19f39=_0x3a1acd[_0x81da('0x81')][_0x2fc4fd];var _0xf490bf=path[_0x81da('0x7a')](_0x158667,_0xc19f39[_0x81da('0x57')]);if(fs[_0x81da('0x88')](_0xf490bf)){_0x46b8fc[_0x81da('0x54')][_0x81da('0x89')]({'name':_0xc19f39[_0x81da('0x25')],'contentType':_0xc19f39[_0x81da('0x2b')],'data':fs['readFileSync'](_0xf490bf)});}}}emlformat[_0x81da('0x8a')](_0x46b8fc,function(_0x1a6716,_0x13d451){if(_0x1a6716)return _0x5c061a(_0x1a6716);fs['writeFileSync'](path[_0x81da('0x7a')](_0x2c27f9,_0x3f89a5),_0x13d451);return _0x682f69(_0x13d451);});});}})[_0x81da('0x11')](function(_0x43ee81){if(_0x43ee81){return _0x225c24[_0x81da('0x8b')](path[_0x81da('0x7a')](_0x2c27f9,_0x3f89a5),_0x3f89a5,function(_0x1d8d0c){if(!_0x1d8d0c)fs['unlinkSync'](path['join'](_0x2c27f9,_0x3f89a5));});}})[_0x81da('0x1a')](handleError(_0x225c24,null));};
\ No newline at end of file