Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 53b6121..772b948 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 _0x1705=['destroy','sendStatus','stack','name','send','index','map','MailMessage','rawAttributes','type','key','query','keys','filters','intersection','model','attributes','length','sort','pick','where','merge','VIRTUAL','filter','includeAll','include','findAll','rows','catch','show','params','fields','find','update','body','describe','create','out','secret','MailAccount','CmList','List','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','root','server/files/attachments','basename','List\x20not\x20found','SendMail','sendMail','format','stringify','accept','read','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','MailInteractionId','isNil','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','User','agent','fullname','email','internal','manual','interface','channel','motionChannel','event','EventManager','reject','MailInteraction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','contact','SIP/%s','fromString','rejectmessage','unix','join','server','tmp','files','message-%s.eml','subject','createdAt','Attachment','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','Bcc','existsSync','push','readFileSync','writeFileSync','download','unlinkSync','moment','bluebird','util','path','lodash','ioredis','html-to-text','../../config/logger','api','mail-interactions','redis','defaults','html-entities','client','http','then','info','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','error','code','MailMessage,\x20%s,\x20%s','message','result','status','json','offset','limit','undefined','count','set'];(function(_0x1f80f7,_0x47da0b){var _0x481cf9=function(_0x2e18e0){while(--_0x2e18e0){_0x1f80f7['push'](_0x1f80f7['shift']());}};_0x481cf9(++_0x47da0b);}(_0x1705,0x19d));var _0x5170=function(_0x2a1b33,_0x409f50){_0x2a1b33=_0x2a1b33-0x0;var _0x4c50e7=_0x1705[_0x2a1b33];return _0x4c50e7;};'use strict';var emlformat=require('eml-format');var moment=require(_0x5170('0x0'));var BPromise=require(_0x5170('0x1'));var util=require(_0x5170('0x2'));var path=require(_0x5170('0x3'));var fs=require('fs');var _=require(_0x5170('0x4'));var Redis=require(_0x5170('0x5'));var htmlToText=require(_0x5170('0x6'));var qs=require('../../components/parsers/qs');var logger=require(_0x5170('0x7'))(_0x5170('0x8'));var interaction_log=require(_0x5170('0x7'))(_0x5170('0x9'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config[_0x5170('0xa')]=_[_0x5170('0xb')](config[_0x5170('0xa')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5170('0xa')]));var htmlEntities=require(_0x5170('0xc'));require('./mailMessage.socket')['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x5170('0xd')][_0x5170('0xe')]({'port':0x232c});var client9003=jayson[_0x5170('0xd')][_0x5170('0xe')]({'port':0x232b});var client9002=jayson[_0x5170('0xd')][_0x5170('0xe')]({'port':0x232a});function respondWithRpcPromise(_0x3a7747,_0xf483cf,_0x2496e5,_0x5e3eed){return new BPromise(function(_0x2f5abe,_0x584686){var _0x13a42a=_0x5e3eed||client;return _0x13a42a['request'](_0x3a7747,_0x2496e5)[_0x5170('0xf')](function(_0x4a3721){logger[_0x5170('0x10')]('MailMessage,\x20%s,\x20%s',_0xf483cf,_0x5170('0x11'));logger['debug'](_0x5170('0x12'),_0xf483cf,_0x5170('0x11'),JSON['stringify'](_0x4a3721));if(_0x4a3721['error']){if(_0x4a3721[_0x5170('0x13')][_0x5170('0x14')]===0x1f4){logger['error'](_0x5170('0x15'),_0xf483cf,_0x4a3721['error'][_0x5170('0x16')]);return _0x584686(_0x4a3721[_0x5170('0x13')][_0x5170('0x16')]);}logger[_0x5170('0x13')]('MailMessage,\x20%s,\x20%s',_0xf483cf,_0x4a3721['error'][_0x5170('0x16')]);return _0x2f5abe(_0x4a3721[_0x5170('0x13')][_0x5170('0x16')]);}else{logger[_0x5170('0x10')]('MailMessage,\x20%s,\x20%s',_0xf483cf,_0x5170('0x11'));_0x2f5abe(_0x4a3721[_0x5170('0x17')][_0x5170('0x16')]);}})['catch'](function(_0x11b1d2){logger[_0x5170('0x13')](_0x5170('0x15'),_0xf483cf,_0x11b1d2);_0x584686(_0x11b1d2);});});}function respondWithResult(_0x26a232,_0x2d6b64){_0x2d6b64=_0x2d6b64||0xc8;return function(_0x463a86){if(_0x463a86){return _0x26a232[_0x5170('0x18')](_0x2d6b64)[_0x5170('0x19')](_0x463a86);}};}function respondWithFilteredResult(_0x4b1105,_0xa88532){return function(_0x140225){if(_0x140225){var _0x2f9e56=typeof _0xa88532[_0x5170('0x1a')]==='undefined'&&typeof _0xa88532[_0x5170('0x1b')]===_0x5170('0x1c');var _0x32928d=_0x140225['count'];var _0xbf1c9=_0x2f9e56?0x0:_0xa88532['offset'];var _0x4aa98b=_0x2f9e56?_0x140225[_0x5170('0x1d')]:_0xa88532['offset']+_0xa88532[_0x5170('0x1b')];var _0x2ce3e1;if(_0x4aa98b>=_0x32928d){_0x4aa98b=_0x32928d;_0x2ce3e1=0xc8;}else{_0x2ce3e1=0xce;}_0x4b1105[_0x5170('0x18')](_0x2ce3e1);return _0x4b1105[_0x5170('0x1e')]('Content-Range',_0xbf1c9+'-'+_0x4aa98b+'/'+_0x32928d)[_0x5170('0x19')](_0x140225);}return null;};}function saveUpdates(_0x442827){return function(_0x18f13c){if(_0x18f13c){return _0x18f13c['update'](_0x442827)[_0x5170('0xf')](function(_0xe181a2){return _0xe181a2;});}return null;};}function removeEntity(_0x3ba74e){return function(_0x2a4a96){if(_0x2a4a96){return _0x2a4a96[_0x5170('0x1f')]()[_0x5170('0xf')](function(){_0x3ba74e[_0x5170('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2fc337){return function(_0x3a18c2){if(!_0x3a18c2){_0x2fc337[_0x5170('0x20')](0x194);}return _0x3a18c2;};}function handleError(_0x481004,_0x4fc7af){_0x4fc7af=_0x4fc7af||0x1f4;return function(_0x1cd4b1){logger['error'](_0x1cd4b1[_0x5170('0x21')]);if(_0x1cd4b1[_0x5170('0x22')]){delete _0x1cd4b1[_0x5170('0x22')];}_0x481004[_0x5170('0x18')](_0x4fc7af)[_0x5170('0x23')](_0x1cd4b1);};}exports[_0x5170('0x24')]=function(_0x44bf1d,_0x2b660e){var _0x260abf={},_0x345178={},_0x5bf67e={'count':0x0,'rows':[]};var _0x5a52e1=_[_0x5170('0x25')](db[_0x5170('0x26')][_0x5170('0x27')],function(_0x2a37fb){return{'name':_0x2a37fb['fieldName'],'type':_0x2a37fb[_0x5170('0x28')][_0x5170('0x29')]};});_0x345178['model']=_['map'](_0x5a52e1,_0x5170('0x22'));_0x345178[_0x5170('0x2a')]=_[_0x5170('0x2b')](_0x44bf1d[_0x5170('0x2a')]);_0x345178[_0x5170('0x2c')]=_[_0x5170('0x2d')](_0x345178[_0x5170('0x2e')],_0x345178['query']);_0x260abf[_0x5170('0x2f')]=_[_0x5170('0x2d')](_0x345178['model'],qs['fields'](_0x44bf1d[_0x5170('0x2a')]['fields']));_0x260abf[_0x5170('0x2f')]=_0x260abf['attributes'][_0x5170('0x30')]?_0x260abf[_0x5170('0x2f')]:_0x345178[_0x5170('0x2e')];if(!_0x44bf1d['query']['hasOwnProperty']('nolimit')){_0x260abf[_0x5170('0x1b')]=qs['limit'](_0x44bf1d[_0x5170('0x2a')]['limit']);_0x260abf[_0x5170('0x1a')]=qs[_0x5170('0x1a')](_0x44bf1d[_0x5170('0x2a')]['offset']);}_0x260abf['order']=qs['sort'](_0x44bf1d['query'][_0x5170('0x31')]);_0x260abf['where']=qs[_0x5170('0x2c')](_[_0x5170('0x32')](_0x44bf1d[_0x5170('0x2a')],_0x345178[_0x5170('0x2c')]),_0x5a52e1);if(_0x44bf1d[_0x5170('0x2a')]['filter']){_0x260abf[_0x5170('0x33')]=_[_0x5170('0x34')](_0x260abf['where'],{'$or':_[_0x5170('0x25')](_0x5a52e1,function(_0x59bb16){if(_0x59bb16['type']!==_0x5170('0x35')){var _0x22c047={};_0x22c047[_0x59bb16[_0x5170('0x22')]]={'$like':'%'+_0x44bf1d['query'][_0x5170('0x36')]+'%'};return _0x22c047;}})});}_0x260abf=_['merge']({},_0x260abf,_0x44bf1d['options']);var _0x3f55ba={'where':_0x260abf[_0x5170('0x33')]};return db[_0x5170('0x26')]['count'](_0x3f55ba)[_0x5170('0xf')](function(_0x5e0706){_0x5bf67e[_0x5170('0x1d')]=_0x5e0706;if(_0x44bf1d[_0x5170('0x2a')][_0x5170('0x37')]){_0x260abf[_0x5170('0x38')]=[{'all':!![]}];}return db['MailMessage'][_0x5170('0x39')](_0x260abf);})['then'](function(_0x2592c9){_0x5bf67e[_0x5170('0x3a')]=_0x2592c9;return _0x5bf67e;})['then'](respondWithFilteredResult(_0x2b660e,_0x260abf))[_0x5170('0x3b')](handleError(_0x2b660e,null));};exports[_0x5170('0x3c')]=function(_0x472363,_0xf9e4fc){var _0x2b9580={'raw':!![],'where':{'id':_0x472363[_0x5170('0x3d')]['id']}},_0x27e080={};_0x27e080[_0x5170('0x2e')]=_[_0x5170('0x2b')](db[_0x5170('0x26')][_0x5170('0x27')]);_0x27e080['query']=_[_0x5170('0x2b')](_0x472363[_0x5170('0x2a')]);_0x27e080[_0x5170('0x2c')]=_[_0x5170('0x2d')](_0x27e080[_0x5170('0x2e')],_0x27e080[_0x5170('0x2a')]);_0x2b9580[_0x5170('0x2f')]=_[_0x5170('0x2d')](_0x27e080[_0x5170('0x2e')],qs[_0x5170('0x3e')](_0x472363[_0x5170('0x2a')][_0x5170('0x3e')]));_0x2b9580[_0x5170('0x2f')]=_0x2b9580[_0x5170('0x2f')][_0x5170('0x30')]?_0x2b9580['attributes']:_0x27e080[_0x5170('0x2e')];if(_0x472363[_0x5170('0x2a')][_0x5170('0x37')]){_0x2b9580['include']=[{'all':!![]}];}_0x2b9580=_['merge']({},_0x2b9580,_0x472363['options']);return db[_0x5170('0x26')][_0x5170('0x3f')](_0x2b9580)[_0x5170('0xf')](handleEntityNotFound(_0xf9e4fc,null))[_0x5170('0xf')](respondWithResult(_0xf9e4fc,null))[_0x5170('0x3b')](handleError(_0xf9e4fc,null));};exports[_0x5170('0x40')]=function(_0x31b4a8,_0x22309d){if(_0x31b4a8[_0x5170('0x41')]['id']){delete _0x31b4a8[_0x5170('0x41')]['id'];}return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x31b4a8[_0x5170('0x3d')]['id']}})[_0x5170('0xf')](handleEntityNotFound(_0x22309d,null))['then'](saveUpdates(_0x31b4a8[_0x5170('0x41')],null))[_0x5170('0xf')](respondWithResult(_0x22309d,null))['catch'](handleError(_0x22309d,null));};exports[_0x5170('0x1f')]=function(_0x303daa,_0x21573d){return db['MailMessage'][_0x5170('0x3f')]({'where':{'id':_0x303daa[_0x5170('0x3d')]['id']}})[_0x5170('0xf')](handleEntityNotFound(_0x21573d,null))[_0x5170('0xf')](removeEntity(_0x21573d,null))[_0x5170('0x3b')](handleError(_0x21573d,null));};exports['describe']=function(_0x45731a,_0x304dce){return db[_0x5170('0x26')][_0x5170('0x42')]()[_0x5170('0xf')](respondWithResult(_0x304dce,null))[_0x5170('0x3b')](handleError(_0x304dce,null));};exports[_0x5170('0x43')]=function(_0x34d363,_0x3ef8fd){return db[_0x5170('0x26')][_0x5170('0x43')](_0x34d363[_0x5170('0x41')])[_0x5170('0xf')](function(_0x19d4d0){if(_0x19d4d0){if(_0x19d4d0['direction']===_0x5170('0x44')&&!_0x19d4d0[_0x5170('0x45')]){var _0x388b9f,_0x3d31ee,_0x16b840;if(_0x34d363[_0x5170('0x41')]['to']){_0x3d31ee=_0x34d363[_0x5170('0x41')]['to']['split'](',')[0x0];}return db[_0x5170('0x46')]['findOne']({'where':{'id':_0x19d4d0['MailAccountId']},'include':[{'model':db[_0x5170('0x47')],'as':_0x5170('0x48'),'include':[{'model':db[_0x5170('0x49')],'as':_0x5170('0x4a'),'where':{'email':_0x3d31ee},'limit':0x1,'order':[[_0x5170('0x4b'),_0x5170('0x4c')]]}]},{'model':db[_0x5170('0x4d')],'as':_0x5170('0x4e'),'raw':!![],'include':[{'model':db[_0x5170('0x4f')],'as':'CloudProvider','raw':!![]}]}]})[_0x5170('0xf')](function(_0x5634b5){_0x388b9f=_0x5634b5;if(!_0x388b9f||!_0x388b9f[_0x5170('0x4e')])return;var _0x309961=_0x388b9f[_0x5170('0x50')]();if(_0x34d363['body'][_0x5170('0x51')]&&_0x34d363['body'][_0x5170('0x51')][_0x5170('0x30')]){for(var _0x51c3a3=0x0;_0x51c3a3<_0x34d363[_0x5170('0x41')]['attachments']['length'];_0x51c3a3+=0x1){_0x34d363['body']['attachments'][_0x51c3a3]={'filename':_0x34d363[_0x5170('0x41')][_0x5170('0x51')][_0x51c3a3][_0x5170('0x22')],'path':path['join'](config[_0x5170('0x52')],_0x5170('0x53'),_0x34d363[_0x5170('0x41')][_0x5170('0x51')][_0x51c3a3][_0x5170('0x54')])};}}_0x16b840={'account':_0x309961,'message':_0x34d363[_0x5170('0x41')]};return;})['then'](function(){if(_0x388b9f[_0x5170('0x48')]){if(_0x388b9f[_0x5170('0x48')][_0x5170('0x4a')][_0x5170('0x30')]){return _0x388b9f[_0x5170('0x48')][_0x5170('0x4a')][0x0];}else{return db[_0x5170('0x49')]['create'](_[_0x5170('0xb')](_0x34d363[_0x5170('0x41')],{'firstName':_0x34d363[_0x5170('0x41')]['to'],'email':_0x34d363['body']['to'],'phone':_0x34d363[_0x5170('0x41')]['to'],'ListId':_0x388b9f['ListId']}));}}else{throw new Error(_0x5170('0x55'));}})[_0x5170('0xf')](function(){if(_0x16b840){return respondWithRpcPromise(_0x5170('0x56'),_0x5170('0x57'),_0x16b840,client9003)['then'](function(_0x438e25){return _0x19d4d0[_0x5170('0x40')]({'read':!![],'messageId':_0x438e25['messageId'],'sentAt':moment()[_0x5170('0x58')]('YYYY-MM-DD\x20HH:mm:ss')});})[_0x5170('0x3b')](function(_0x254fc3){logger[_0x5170('0x13')]('%s',JSON[_0x5170('0x59')](_0x254fc3));return _0x19d4d0;});}return _0x19d4d0;});}return _0x19d4d0;}})[_0x5170('0xf')](respondWithResult(_0x3ef8fd,0xc9))[_0x5170('0x3b')](handleError(_0x3ef8fd,null));};exports[_0x5170('0x5a')]=function(_0x2bf714,_0x4fbf4a){var _0x83b293={'agent':{},'channel':'mail'};if(_0x2bf714['body']['id']){delete _0x2bf714[_0x5170('0x41')]['id'];}_0x2bf714[_0x5170('0x41')][_0x5170('0x5b')]=!![];_0x2bf714[_0x5170('0x41')][_0x5170('0x5c')]=moment()['format'](_0x5170('0x5d'));_0x2bf714[_0x5170('0x41')]['UserId']=_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')]||_0x2bf714[_0x5170('0x5f')]['id'];_0x83b293['agent']['id']=_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')];return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x2bf714['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4fbf4a,null))[_0x5170('0xf')](saveUpdates(_0x2bf714[_0x5170('0x41')],null))[_0x5170('0xf')](function(_0xd2b8cc){if(_0xd2b8cc){_0x83b293[_0x5170('0x16')]=_0xd2b8cc['get']({'plain':!![]});return db['MailInteraction'][_0x5170('0x3f')]({'where':{'id':_0xd2b8cc[_0x5170('0x60')]}});}return null;})[_0x5170('0xf')](handleEntityNotFound(_0x4fbf4a,null))['then'](function(_0x3c539f){if(_0x3c539f){return _0x3c539f['update']({'UserId':_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')],'read1stAt':_[_0x5170('0x61')](_0x3c539f['read1stAt'])?moment()[_0x5170('0x58')](_0x5170('0x5d')):undefined});}return null;})[_0x5170('0xf')](function(_0x3df92d){if(_0x3df92d){_0x83b293['interaction']=_0x3df92d[_0x5170('0x62')]({'plain':!![]});interaction_log[_0x5170('0x10')](_0x5170('0x63'),_0x2bf714['user']['id'],_0x2bf714[_0x5170('0x5f')]['name'],_0x2bf714['user']['role'],_0x83b293[_0x5170('0x64')]['id'],_0x2bf714['body']?JSON['stringify'](_0x2bf714[_0x5170('0x41')]):_0x5170('0x65'));return respondWithRpcPromise(_0x5170('0x66'),_0x5170('0x67'),_0x83b293);}return null;})[_0x5170('0xf')](function(_0x898c23){var _0x3f1c1d=_0x5170('0x68')+_0x898c23[_0x5170('0x16')][_0x5170('0x69')];return db['sequelize'][_0x5170('0x2a')](_0x3f1c1d,{'type':db[_0x5170('0x6a')][_0x5170('0x6b')][_0x5170('0x6c')],'raw':!![]})[_0x5170('0xf')](function(_0x5c836c){return _0x5c836c;});})[_0x5170('0xf')](function(_0x5583be){if(_0x5583be){_0x83b293[_0x5170('0x16')]['contact']=_0x5583be[0x0];if(!_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')])return;return db[_0x5170('0x6d')]['find']({'where':{'id':_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')],'role':_0x5170('0x6e')},'attributes':['id',_0x5170('0x22'),_0x5170('0x6f'),_0x5170('0x70'),_0x5170('0x71')],'raw':!![]});}return null;})['then'](function(_0xdf021c){if(!_0xdf021c)return null;_0x83b293[_0x5170('0x16')]['agent']=_0xdf021c;return _0x83b293;})[_0x5170('0xf')](function(_0x2cf3f1){if(_0x2cf3f1){if(_0x2bf714[_0x5170('0x41')][_0x5170('0x72')]){_0x83b293['message'][_0x5170('0x73')]=util['format']('SIP/%s',_0x2bf714[_0x5170('0x5f')][_0x5170('0x22')]);_0x83b293[_0x5170('0x16')][_0x5170('0x74')]=_0x83b293[_0x5170('0x74')];_0x83b293[_0x5170('0x16')][_0x5170('0x75')]=_0x83b293['channel'];_0x83b293[_0x5170('0x16')][_0x5170('0x76')]=_0x5170('0x5a');_0x83b293[_0x5170('0x16')][_0x5170('0x41')]=htmlToText['fromString'](_0x83b293[_0x5170('0x16')]['body']);return respondWithRpcPromise(_0x5170('0x77'),_0x5170('0x77'),{'event':'acceptmessage','message':_0x83b293[_0x5170('0x16')]},client9002)[_0x5170('0xf')](function(){return _0x83b293;});}return _0x83b293;}return null;})[_0x5170('0xf')](respondWithResult(_0x4fbf4a,null))[_0x5170('0x3b')](handleError(_0x4fbf4a,null));};exports[_0x5170('0x78')]=function(_0x512278,_0xbfceb3){var _0xab4abe={'agent':{},'channel':'mail'};if(_0x512278[_0x5170('0x41')]['id']){delete _0x512278[_0x5170('0x41')]['id'];}_0x512278['body'][_0x5170('0x5e')]=_0x512278[_0x5170('0x41')][_0x5170('0x5e')]||_0x512278[_0x5170('0x5f')]['id'];_0xab4abe[_0x5170('0x6e')]['id']=_0x512278[_0x5170('0x41')][_0x5170('0x5e')];return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x512278[_0x5170('0x3d')]['id'],'UserId':null}})[_0x5170('0xf')](handleEntityNotFound(_0xbfceb3,null))[_0x5170('0xf')](function(_0x2e9b5f){if(_0x2e9b5f){_0xab4abe[_0x5170('0x16')]=_0x2e9b5f[_0x5170('0x62')]({'plain':!![]});return db[_0x5170('0x79')]['find']({'where':{'id':_0x2e9b5f['MailInteractionId']}});}return null;})['then'](handleEntityNotFound(_0xbfceb3,null))['then'](function(_0x3a9f39){if(_0x3a9f39){_0xab4abe[_0x5170('0x64')]=_0x3a9f39[_0x5170('0x62')]({'plain':!![]});interaction_log[_0x5170('0x10')](_0x5170('0x7a'),_0x512278[_0x5170('0x5f')]['id'],_0x512278[_0x5170('0x5f')][_0x5170('0x22')],_0x512278[_0x5170('0x5f')][_0x5170('0x7b')],_0xab4abe['interaction']['id'],_0x512278[_0x5170('0x41')]?JSON[_0x5170('0x59')](_0x512278[_0x5170('0x41')]):'null');return respondWithRpcPromise(_0x5170('0x7c'),_0x5170('0x7d'),_0xab4abe);}return null;})[_0x5170('0xf')](function(_0x4b7d12){var _0x319bb5=_0x5170('0x68')+_0x4b7d12[_0x5170('0x16')][_0x5170('0x69')];return db['sequelize']['query'](_0x319bb5,{'type':db['Sequelize'][_0x5170('0x6b')][_0x5170('0x6c')],'raw':!![]})[_0x5170('0xf')](function(_0x536d81){return _0x536d81;});})[_0x5170('0xf')](function(_0x3993d9){if(_0x3993d9){_0xab4abe[_0x5170('0x16')][_0x5170('0x7e')]=_0x3993d9[0x0];if(!_0x512278[_0x5170('0x41')][_0x5170('0x5e')])return;return db[_0x5170('0x6d')]['find']({'where':{'id':_0x512278['body'][_0x5170('0x5e')],'role':_0x5170('0x6e')},'attributes':['id',_0x5170('0x22'),'fullname',_0x5170('0x70'),_0x5170('0x71')],'raw':!![]});}return null;})[_0x5170('0xf')](function(_0x1823ee){if(!_0x1823ee)return null;_0xab4abe[_0x5170('0x16')][_0x5170('0x6e')]=_0x1823ee;return _0xab4abe;})['then'](function(_0x418156){if(_0x418156){_0x418156[_0x5170('0x16')]['interface']=util[_0x5170('0x58')](_0x5170('0x7f'),_0x512278[_0x5170('0x5f')][_0x5170('0x22')]);_0x418156[_0x5170('0x16')]['channel']=_0xab4abe['channel'];_0x418156[_0x5170('0x16')][_0x5170('0x75')]=_0xab4abe[_0x5170('0x74')];_0x418156[_0x5170('0x16')][_0x5170('0x76')]=_0x5170('0x78');_0x418156[_0x5170('0x16')][_0x5170('0x41')]=htmlToText[_0x5170('0x80')](_0xab4abe[_0x5170('0x16')][_0x5170('0x41')]);respondWithRpcPromise(_0x5170('0x77'),'EventManager',{'event':_0x5170('0x81'),'message':_0x418156[_0x5170('0x16')]},client9002);return _0xab4abe;}return null;})['then'](respondWithResult(_0xbfceb3,null))[_0x5170('0x3b')](handleError(_0xbfceb3,null));};exports['download']=function(_0x3ece65,_0x461fdb){var _0x3ace3e=moment()[_0x5170('0x82')]()['toString']();var _0x40d796=path[_0x5170('0x83')](config[_0x5170('0x52')],_0x5170('0x84'),'files',_0x5170('0x85'));var _0xd699d8=path['join'](config[_0x5170('0x52')],'server',_0x5170('0x86'),_0x5170('0x51'));var _0x161185=util[_0x5170('0x58')](_0x5170('0x87'),_0x3ace3e);return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x3ece65[_0x5170('0x3d')]['id']},'attributes':['id',_0x5170('0x41'),'from','to','cc','bcc',_0x5170('0x88'),_0x5170('0x89')],'include':_0x3ece65[_0x5170('0x2a')][_0x5170('0x51')]?[{'model':db[_0x5170('0x8a')],'as':_0x5170('0x8b')}]:undefined})[_0x5170('0xf')](handleEntityNotFound(_0x461fdb,null))[_0x5170('0xf')](function(_0x2dc03e){if(_0x2dc03e){var _0x36fdb1=_0x2dc03e;var _0x195f22={'from':_0x36fdb1['from'],'to':_0x36fdb1['to'],'subject':_0x36fdb1[_0x5170('0x88')],'html':htmlEntities['decode'](_0x36fdb1[_0x5170('0x41')]),'headers':{'Date':moment(_0x36fdb1[_0x5170('0x89')])[_0x5170('0x58')](_0x5170('0x8c'))},'attachments':[]};if(_0x2dc03e['cc']){_0x195f22['headers']['Cc']=_0x2dc03e['cc'];}if(_0x2dc03e['bcc']){_0x195f22['headers'][_0x5170('0x8d')]=_0x2dc03e['bcc'];}return new BPromise(function(_0x23e7ba,_0x51642d){if(_0x2dc03e['Attachments']){for(var _0x2e03f2=0x0;_0x2e03f2<_0x2dc03e[_0x5170('0x8b')][_0x5170('0x30')];_0x2e03f2++){var _0x3e0995=_0x2dc03e['Attachments'][_0x2e03f2];var _0x15d1c8=path['join'](_0xd699d8,_0x3e0995[_0x5170('0x54')]);if(fs[_0x5170('0x8e')](_0x15d1c8)){_0x195f22[_0x5170('0x51')][_0x5170('0x8f')]({'name':_0x3e0995[_0x5170('0x22')],'contentType':_0x3e0995['type'],'data':fs[_0x5170('0x90')](_0x15d1c8)});}}}emlformat['build'](_0x195f22,function(_0xa84862,_0x2b5632){if(_0xa84862)return _0x51642d(_0xa84862);fs[_0x5170('0x91')](path[_0x5170('0x83')](_0x40d796,_0x161185),_0x2b5632);return _0x23e7ba(_0x2b5632);});});}})[_0x5170('0xf')](function(_0x318586){if(_0x318586){return _0x461fdb[_0x5170('0x92')](path[_0x5170('0x83')](_0x40d796,_0x161185),_0x161185,function(_0x58c959){if(!_0x58c959)fs[_0x5170('0x93')](path[_0x5170('0x83')](_0x40d796,_0x161185));});}})[_0x5170('0x3b')](handleError(_0x461fdb,null));};
\ No newline at end of file