Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 50d4762..0103475 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0baf=['authentication','auth','user','service','pass','attachments','root','server/files/attachments','CmContact','defaults','ListId','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','mail','read','UserId','agent','get','MailInteraction','read1stAt','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','QueryTypes','SELECT','User','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','event','fromString','EventManager','acceptmessage','reject','MailInteractionId','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','contact','rejectmessage','download','unix','toString','server','files','tmp','join','message-%s.eml','from','createdAt','Attachments','subject','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','bcc','Bcc','existsSync','push','readFileSync','build','writeFileSync','unlinkSync','eml-format','moment','bluebird','util','path','lodash','ioredis','html-to-text','../../components/parsers/qs','../../config/logger','api','mail-interactions','../../config/environment','../../mysqldb','localhost','socket.io-emitter','redis','./mailMessage.socket','register','jayson/promise','client','http','then','info','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','MailMessage,\x20%s,\x20%s','message','result','catch','status','json','offset','undefined','limit','count','set','Content-Range','update','destroy','end','sendStatus','stack','name','index','map','MailMessage','fieldName','type','model','query','keys','filters','intersection','fields','attributes','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','VIRTUAL','options','includeAll','include','findAll','params','merge','find','body','describe','create','out','secret','MailAccount','findOne','MailAccountId','CmList','List','Contacts','updatedAt','DESC','Smtp','isNil','host','port','secure'];(function(_0x478874,_0x36d2a5){var _0x53e9d9=function(_0x32f00e){while(--_0x32f00e){_0x478874['push'](_0x478874['shift']());}};_0x53e9d9(++_0x36d2a5);}(_0x0baf,0xf3));var _0xf0ba=function(_0x55c979,_0x36c5f0){_0x55c979=_0x55c979-0x0;var _0x690107=_0x0baf[_0x55c979];return _0x690107;};'use strict';var emlformat=require(_0xf0ba('0x0'));var moment=require(_0xf0ba('0x1'));var BPromise=require(_0xf0ba('0x2'));var util=require(_0xf0ba('0x3'));var path=require(_0xf0ba('0x4'));var fs=require('fs');var _=require(_0xf0ba('0x5'));var Redis=require(_0xf0ba('0x6'));var htmlToText=require(_0xf0ba('0x7'));var qs=require(_0xf0ba('0x8'));var logger=require(_0xf0ba('0x9'))(_0xf0ba('0xa'));var interaction_log=require('../../config/logger')(_0xf0ba('0xb'));var config=require(_0xf0ba('0xc'));var db=require(_0xf0ba('0xd'))['db'];config['redis']=_['defaults'](config['redis'],{'host':_0xf0ba('0xe'),'port':0x18eb});var socket=require(_0xf0ba('0xf'))(new Redis(config[_0xf0ba('0x10')]));var htmlEntities=require('html-entities');require(_0xf0ba('0x11'))[_0xf0ba('0x12')](socket);var jayson=require(_0xf0ba('0x13'));var client=jayson[_0xf0ba('0x14')]['http']({'port':0x232c});var client9003=jayson[_0xf0ba('0x14')][_0xf0ba('0x15')]({'port':0x232b});var client9002=jayson[_0xf0ba('0x14')][_0xf0ba('0x15')]({'port':0x232a});function respondWithRpcPromise(_0x3832a9,_0x5b3d13,_0x15936c,_0x47d8c7){return new BPromise(function(_0x39fbe0,_0x191f41){var _0x49bb2c=_0x47d8c7||client;return _0x49bb2c['request'](_0x3832a9,_0x15936c)[_0xf0ba('0x16')](function(_0x52a8bc){logger[_0xf0ba('0x17')]('MailMessage,\x20%s,\x20%s',_0x5b3d13,_0xf0ba('0x18'));logger['debug'](_0xf0ba('0x19'),_0x5b3d13,_0xf0ba('0x18'),JSON[_0xf0ba('0x1a')](_0x52a8bc));if(_0x52a8bc[_0xf0ba('0x1b')]){if(_0x52a8bc[_0xf0ba('0x1b')][_0xf0ba('0x1c')]===0x1f4){logger[_0xf0ba('0x1b')](_0xf0ba('0x1d'),_0x5b3d13,_0x52a8bc[_0xf0ba('0x1b')][_0xf0ba('0x1e')]);return _0x191f41(_0x52a8bc[_0xf0ba('0x1b')][_0xf0ba('0x1e')]);}logger[_0xf0ba('0x1b')](_0xf0ba('0x1d'),_0x5b3d13,_0x52a8bc[_0xf0ba('0x1b')][_0xf0ba('0x1e')]);return _0x39fbe0(_0x52a8bc[_0xf0ba('0x1b')]['message']);}else{logger[_0xf0ba('0x17')](_0xf0ba('0x1d'),_0x5b3d13,_0xf0ba('0x18'));_0x39fbe0(_0x52a8bc[_0xf0ba('0x1f')]['message']);}})[_0xf0ba('0x20')](function(_0x18a5a3){logger['error']('MailMessage,\x20%s,\x20%s',_0x5b3d13,_0x18a5a3);_0x191f41(_0x18a5a3);});});}function respondWithResult(_0x20a98e,_0x28e6cd){_0x28e6cd=_0x28e6cd||0xc8;return function(_0x27f04a){if(_0x27f04a){return _0x20a98e[_0xf0ba('0x21')](_0x28e6cd)[_0xf0ba('0x22')](_0x27f04a);}};}function respondWithFilteredResult(_0xeb2f8f,_0x3875ec){return function(_0x65a7c6){if(_0x65a7c6){var _0x543c2a=typeof _0x3875ec[_0xf0ba('0x23')]===_0xf0ba('0x24')&&typeof _0x3875ec[_0xf0ba('0x25')]==='undefined';var _0x5851cc=_0x65a7c6[_0xf0ba('0x26')];var _0x32b139=_0x543c2a?0x0:_0x3875ec[_0xf0ba('0x23')];var _0x2d21bf=_0x543c2a?_0x65a7c6[_0xf0ba('0x26')]:_0x3875ec[_0xf0ba('0x23')]+_0x3875ec[_0xf0ba('0x25')];var _0x44e9ac;if(_0x2d21bf>=_0x5851cc){_0x2d21bf=_0x5851cc;_0x44e9ac=0xc8;}else{_0x44e9ac=0xce;}_0xeb2f8f[_0xf0ba('0x21')](_0x44e9ac);return _0xeb2f8f[_0xf0ba('0x27')](_0xf0ba('0x28'),_0x32b139+'-'+_0x2d21bf+'/'+_0x5851cc)[_0xf0ba('0x22')](_0x65a7c6);}return null;};}function saveUpdates(_0x4c8b12){return function(_0x397306){if(_0x397306){return _0x397306[_0xf0ba('0x29')](_0x4c8b12)[_0xf0ba('0x16')](function(_0x397e17){return _0x397e17;});}return null;};}function removeEntity(_0x69fc25){return function(_0x31b3b6){if(_0x31b3b6){return _0x31b3b6[_0xf0ba('0x2a')]()[_0xf0ba('0x16')](function(){_0x69fc25[_0xf0ba('0x21')](0xcc)[_0xf0ba('0x2b')]();});}};}function handleEntityNotFound(_0x1b3225){return function(_0x5c468d){if(!_0x5c468d){_0x1b3225[_0xf0ba('0x2c')](0x194);}return _0x5c468d;};}function handleError(_0x809db3,_0x490e4a){_0x490e4a=_0x490e4a||0x1f4;return function(_0xecd299){logger['error'](_0xecd299[_0xf0ba('0x2d')]);if(_0xecd299[_0xf0ba('0x2e')]){delete _0xecd299[_0xf0ba('0x2e')];}_0x809db3['status'](_0x490e4a)['send'](_0xecd299);};}exports[_0xf0ba('0x2f')]=function(_0x3e9287,_0x314bc8){var _0x5a5d71={},_0x4b9afe={},_0x3c5180={'count':0x0,'rows':[]};var _0x34d2e7=_[_0xf0ba('0x30')](db[_0xf0ba('0x31')]['rawAttributes'],function(_0x56c814){return{'name':_0x56c814[_0xf0ba('0x32')],'type':_0x56c814[_0xf0ba('0x33')]['key']};});_0x4b9afe[_0xf0ba('0x34')]=_[_0xf0ba('0x30')](_0x34d2e7,_0xf0ba('0x2e'));_0x4b9afe[_0xf0ba('0x35')]=_[_0xf0ba('0x36')](_0x3e9287[_0xf0ba('0x35')]);_0x4b9afe[_0xf0ba('0x37')]=_[_0xf0ba('0x38')](_0x4b9afe['model'],_0x4b9afe[_0xf0ba('0x35')]);_0x5a5d71['attributes']=_[_0xf0ba('0x38')](_0x4b9afe[_0xf0ba('0x34')],qs[_0xf0ba('0x39')](_0x3e9287[_0xf0ba('0x35')]['fields']));_0x5a5d71['attributes']=_0x5a5d71[_0xf0ba('0x3a')][_0xf0ba('0x3b')]?_0x5a5d71[_0xf0ba('0x3a')]:_0x4b9afe[_0xf0ba('0x34')];if(!_0x3e9287[_0xf0ba('0x35')][_0xf0ba('0x3c')](_0xf0ba('0x3d'))){_0x5a5d71[_0xf0ba('0x25')]=qs[_0xf0ba('0x25')](_0x3e9287['query'][_0xf0ba('0x25')]);_0x5a5d71[_0xf0ba('0x23')]=qs['offset'](_0x3e9287[_0xf0ba('0x35')]['offset']);}_0x5a5d71[_0xf0ba('0x3e')]=qs['sort'](_0x3e9287[_0xf0ba('0x35')][_0xf0ba('0x3f')]);_0x5a5d71['where']=qs[_0xf0ba('0x37')](_[_0xf0ba('0x40')](_0x3e9287[_0xf0ba('0x35')],_0x4b9afe[_0xf0ba('0x37')]),_0x34d2e7);if(_0x3e9287[_0xf0ba('0x35')][_0xf0ba('0x41')]){_0x5a5d71[_0xf0ba('0x42')]=_['merge'](_0x5a5d71['where'],{'$or':_[_0xf0ba('0x30')](_0x34d2e7,function(_0x56a25e){if(_0x56a25e[_0xf0ba('0x33')]!==_0xf0ba('0x43')){var _0x5b5c4a={};_0x5b5c4a[_0x56a25e['name']]={'$like':'%'+_0x3e9287[_0xf0ba('0x35')][_0xf0ba('0x41')]+'%'};return _0x5b5c4a;}})});}_0x5a5d71=_['merge']({},_0x5a5d71,_0x3e9287[_0xf0ba('0x44')]);var _0x5d83f6={'where':_0x5a5d71[_0xf0ba('0x42')]};return db['MailMessage'][_0xf0ba('0x26')](_0x5d83f6)[_0xf0ba('0x16')](function(_0x1a9f5e){_0x3c5180[_0xf0ba('0x26')]=_0x1a9f5e;if(_0x3e9287[_0xf0ba('0x35')][_0xf0ba('0x45')]){_0x5a5d71[_0xf0ba('0x46')]=[{'all':!![]}];}return db[_0xf0ba('0x31')][_0xf0ba('0x47')](_0x5a5d71);})[_0xf0ba('0x16')](function(_0x36323e){_0x3c5180['rows']=_0x36323e;return _0x3c5180;})['then'](respondWithFilteredResult(_0x314bc8,_0x5a5d71))[_0xf0ba('0x20')](handleError(_0x314bc8,null));};exports['show']=function(_0x50b7f4,_0x494b15){var _0x3f1547={'raw':!![],'where':{'id':_0x50b7f4[_0xf0ba('0x48')]['id']}},_0x37f004={};_0x37f004[_0xf0ba('0x34')]=_['keys'](db[_0xf0ba('0x31')]['rawAttributes']);_0x37f004[_0xf0ba('0x35')]=_[_0xf0ba('0x36')](_0x50b7f4[_0xf0ba('0x35')]);_0x37f004[_0xf0ba('0x37')]=_[_0xf0ba('0x38')](_0x37f004[_0xf0ba('0x34')],_0x37f004[_0xf0ba('0x35')]);_0x3f1547['attributes']=_[_0xf0ba('0x38')](_0x37f004[_0xf0ba('0x34')],qs['fields'](_0x50b7f4[_0xf0ba('0x35')][_0xf0ba('0x39')]));_0x3f1547[_0xf0ba('0x3a')]=_0x3f1547['attributes'][_0xf0ba('0x3b')]?_0x3f1547[_0xf0ba('0x3a')]:_0x37f004['model'];if(_0x50b7f4['query'][_0xf0ba('0x45')]){_0x3f1547['include']=[{'all':!![]}];}_0x3f1547=_[_0xf0ba('0x49')]({},_0x3f1547,_0x50b7f4[_0xf0ba('0x44')]);return db['MailMessage'][_0xf0ba('0x4a')](_0x3f1547)['then'](handleEntityNotFound(_0x494b15,null))[_0xf0ba('0x16')](respondWithResult(_0x494b15,null))[_0xf0ba('0x20')](handleError(_0x494b15,null));};exports['update']=function(_0x18a39c,_0x3852e7){if(_0x18a39c['body']['id']){delete _0x18a39c[_0xf0ba('0x4b')]['id'];}return db['MailMessage'][_0xf0ba('0x4a')]({'where':{'id':_0x18a39c[_0xf0ba('0x48')]['id']}})[_0xf0ba('0x16')](handleEntityNotFound(_0x3852e7,null))[_0xf0ba('0x16')](saveUpdates(_0x18a39c['body'],null))[_0xf0ba('0x16')](respondWithResult(_0x3852e7,null))[_0xf0ba('0x20')](handleError(_0x3852e7,null));};exports[_0xf0ba('0x2a')]=function(_0x4bd601,_0x5b57f8){return db[_0xf0ba('0x31')][_0xf0ba('0x4a')]({'where':{'id':_0x4bd601['params']['id']}})[_0xf0ba('0x16')](handleEntityNotFound(_0x5b57f8,null))[_0xf0ba('0x16')](removeEntity(_0x5b57f8,null))['catch'](handleError(_0x5b57f8,null));};exports[_0xf0ba('0x4c')]=function(_0x126dbb,_0x2b7e5b){return db['MailMessage'][_0xf0ba('0x4c')]()['then'](respondWithResult(_0x2b7e5b,null))[_0xf0ba('0x20')](handleError(_0x2b7e5b,null));};exports['create']=function(_0x55065c,_0x146629){return db[_0xf0ba('0x31')][_0xf0ba('0x4d')](_0x55065c[_0xf0ba('0x4b')])[_0xf0ba('0x16')](function(_0x5290b1){if(_0x5290b1){if(_0x5290b1['direction']===_0xf0ba('0x4e')&&!_0x5290b1[_0xf0ba('0x4f')]){var _0x2c1f79,_0x2d4cbc,_0x3b9ee0;if(_0x55065c[_0xf0ba('0x4b')]['to']){_0x2d4cbc=_0x55065c[_0xf0ba('0x4b')]['to']['split'](',')[0x0];}return db[_0xf0ba('0x50')][_0xf0ba('0x51')]({'where':{'id':_0x5290b1[_0xf0ba('0x52')]},'include':[{'model':db[_0xf0ba('0x53')],'as':_0xf0ba('0x54'),'include':[{'model':db['CmContact'],'as':_0xf0ba('0x55'),'where':{'email':_0x2d4cbc},'limit':0x1,'order':[[_0xf0ba('0x56'),_0xf0ba('0x57')]]}]},{'model':db['MailServerOut'],'as':_0xf0ba('0x58'),'raw':!![]}]})[_0xf0ba('0x16')](function(_0x3582be){_0x2c1f79=_0x3582be;if(_0x2c1f79&&_0x2c1f79[_0xf0ba('0x58')]){var _0xa14c80={'tls':{'rejectUnauthorized':![]}};if(_[_0xf0ba('0x59')](_0x2c1f79[_0xf0ba('0x58')]['service'])){_0xa14c80[_0xf0ba('0x5a')]=_0x2c1f79['Smtp'][_0xf0ba('0x5a')];_0xa14c80[_0xf0ba('0x5b')]=_0x2c1f79['Smtp'][_0xf0ba('0x5b')];_0xa14c80[_0xf0ba('0x5c')]=_0x2c1f79[_0xf0ba('0x58')][_0xf0ba('0x5c')];if(_0x2c1f79['Smtp'][_0xf0ba('0x5d')]){_0xa14c80[_0xf0ba('0x5e')]={'user':_0x2c1f79['Smtp'][_0xf0ba('0x5f')],'pass':_0x2c1f79[_0xf0ba('0x58')]['pass']};}}else{_0xa14c80[_0xf0ba('0x60')]=_0x2c1f79[_0xf0ba('0x58')][_0xf0ba('0x60')];_0xa14c80[_0xf0ba('0x5e')]={'user':_0x2c1f79[_0xf0ba('0x58')]['user'],'pass':_0x2c1f79['Smtp'][_0xf0ba('0x61')]};_0xa14c80['secure']=_0x2c1f79[_0xf0ba('0x58')]['secure'];}if(_0x55065c[_0xf0ba('0x4b')][_0xf0ba('0x62')]&&_0x55065c['body'][_0xf0ba('0x62')][_0xf0ba('0x3b')]){for(var _0x3cb42f=0x0;_0x3cb42f<_0x55065c[_0xf0ba('0x4b')][_0xf0ba('0x62')][_0xf0ba('0x3b')];_0x3cb42f+=0x1){_0x55065c[_0xf0ba('0x4b')]['attachments'][_0x3cb42f]={'filename':_0x55065c[_0xf0ba('0x4b')][_0xf0ba('0x62')][_0x3cb42f][_0xf0ba('0x2e')],'path':path['join'](config[_0xf0ba('0x63')],_0xf0ba('0x64'),_0x55065c['body'][_0xf0ba('0x62')][_0x3cb42f]['basename'])};}}_0x3b9ee0={'account':_0xa14c80,'message':_0x55065c[_0xf0ba('0x4b')]};return;}})[_0xf0ba('0x16')](function(){if(_0x2c1f79[_0xf0ba('0x54')]){if(_0x2c1f79['List'][_0xf0ba('0x55')]['length']){return _0x2c1f79[_0xf0ba('0x54')][_0xf0ba('0x55')][0x0];}else{return db[_0xf0ba('0x65')][_0xf0ba('0x4d')](_[_0xf0ba('0x66')](_0x55065c[_0xf0ba('0x4b')],{'firstName':_0x55065c[_0xf0ba('0x4b')]['to'],'email':_0x55065c[_0xf0ba('0x4b')]['to'],'phone':_0x55065c[_0xf0ba('0x4b')]['to'],'ListId':_0x2c1f79[_0xf0ba('0x67')]}));}}else{throw new Error('List\x20not\x20found');}})['then'](function(){if(_0x3b9ee0){return respondWithRpcPromise('SendMail',_0xf0ba('0x68'),_0x3b9ee0,client9003)['then'](function(_0x4268bc){return _0x5290b1[_0xf0ba('0x29')]({'read':!![],'messageId':_0x4268bc[_0xf0ba('0x69')],'sentAt':moment()[_0xf0ba('0x6a')](_0xf0ba('0x6b'))});})[_0xf0ba('0x20')](function(_0x3518fa){logger[_0xf0ba('0x1b')]('%s',JSON[_0xf0ba('0x1a')](_0x3518fa));return _0x5290b1;});}return _0x5290b1;});}return _0x5290b1;}})[_0xf0ba('0x16')](respondWithResult(_0x146629,0xc9))['catch'](handleError(_0x146629,null));};exports['accept']=function(_0xc84012,_0xd33726){var _0x9f0620={'agent':{},'channel':_0xf0ba('0x6c')};if(_0xc84012[_0xf0ba('0x4b')]['id']){delete _0xc84012['body']['id'];}_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x6d')]=!![];_0xc84012[_0xf0ba('0x4b')]['readAt']=moment()[_0xf0ba('0x6a')](_0xf0ba('0x6b'));_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x6e')]=_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x6e')]||_0xc84012['user']['id'];_0x9f0620[_0xf0ba('0x6f')]['id']=_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x6e')];return db[_0xf0ba('0x31')][_0xf0ba('0x4a')]({'where':{'id':_0xc84012[_0xf0ba('0x48')]['id'],'UserId':null}})[_0xf0ba('0x16')](handleEntityNotFound(_0xd33726,null))['then'](saveUpdates(_0xc84012['body'],null))[_0xf0ba('0x16')](function(_0x301d2d){if(_0x301d2d){_0x9f0620['message']=_0x301d2d[_0xf0ba('0x70')]({'plain':!![]});return db[_0xf0ba('0x71')]['find']({'where':{'id':_0x301d2d['MailInteractionId']}});}return null;})[_0xf0ba('0x16')](handleEntityNotFound(_0xd33726,null))[_0xf0ba('0x16')](function(_0x3a250){if(_0x3a250){return _0x3a250[_0xf0ba('0x29')]({'UserId':_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x6e')],'read1stAt':_[_0xf0ba('0x59')](_0x3a250[_0xf0ba('0x72')])?moment()[_0xf0ba('0x6a')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})['then'](function(_0x1a3398){if(_0x1a3398){_0x9f0620['interaction']=_0x1a3398[_0xf0ba('0x70')]({'plain':!![]});interaction_log[_0xf0ba('0x17')](_0xf0ba('0x73'),_0xc84012[_0xf0ba('0x5f')]['id'],_0xc84012[_0xf0ba('0x5f')][_0xf0ba('0x2e')],_0xc84012[_0xf0ba('0x5f')][_0xf0ba('0x74')],_0x9f0620[_0xf0ba('0x75')]['id'],_0xc84012[_0xf0ba('0x4b')]?JSON[_0xf0ba('0x1a')](_0xc84012['body']):_0xf0ba('0x76'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x9f0620);}return null;})[_0xf0ba('0x16')](function(_0x1720ed){var _0x60ca0b=_0xf0ba('0x77')+_0x1720ed[_0xf0ba('0x1e')][_0xf0ba('0x78')];return db[_0xf0ba('0x79')][_0xf0ba('0x35')](_0x60ca0b,{'type':db[_0xf0ba('0x7a')][_0xf0ba('0x7b')][_0xf0ba('0x7c')],'raw':!![]})['then'](function(_0xa5fc1a){return _0xa5fc1a;});})[_0xf0ba('0x16')](function(_0x2400c9){if(_0x2400c9){_0x9f0620['message']['contact']=_0x2400c9[0x0];if(!_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x6e')])return;return db[_0xf0ba('0x7d')][_0xf0ba('0x4a')]({'where':{'id':_0xc84012['body'][_0xf0ba('0x6e')],'role':'agent'},'attributes':['id',_0xf0ba('0x2e'),_0xf0ba('0x7e'),_0xf0ba('0x7f'),_0xf0ba('0x80')],'raw':!![]});}return null;})[_0xf0ba('0x16')](function(_0x232db6){if(!_0x232db6)return null;_0x9f0620[_0xf0ba('0x1e')][_0xf0ba('0x6f')]=_0x232db6;return _0x9f0620;})[_0xf0ba('0x16')](function(_0x518dcb){if(_0x518dcb){if(_0xc84012[_0xf0ba('0x4b')][_0xf0ba('0x81')]){_0x9f0620[_0xf0ba('0x1e')][_0xf0ba('0x82')]=util[_0xf0ba('0x6a')](_0xf0ba('0x83'),_0xc84012['user'][_0xf0ba('0x2e')]);_0x9f0620['message'][_0xf0ba('0x84')]=_0x9f0620[_0xf0ba('0x84')];_0x9f0620[_0xf0ba('0x1e')][_0xf0ba('0x85')]=_0x9f0620['channel'];_0x9f0620[_0xf0ba('0x1e')][_0xf0ba('0x86')]='accept';_0x9f0620['message'][_0xf0ba('0x4b')]=htmlToText[_0xf0ba('0x87')](_0x9f0620[_0xf0ba('0x1e')]['body']);return respondWithRpcPromise(_0xf0ba('0x88'),'EventManager',{'event':_0xf0ba('0x89'),'message':_0x9f0620[_0xf0ba('0x1e')]},client9002)[_0xf0ba('0x16')](function(){return _0x9f0620;});}return _0x9f0620;}return null;})[_0xf0ba('0x16')](respondWithResult(_0xd33726,null))['catch'](handleError(_0xd33726,null));};exports[_0xf0ba('0x8a')]=function(_0x52b8fe,_0x20a5c8){var _0x8211f0={'agent':{},'channel':'mail'};if(_0x52b8fe[_0xf0ba('0x4b')]['id']){delete _0x52b8fe[_0xf0ba('0x4b')]['id'];}_0x52b8fe[_0xf0ba('0x4b')][_0xf0ba('0x6e')]=_0x52b8fe[_0xf0ba('0x4b')][_0xf0ba('0x6e')]||_0x52b8fe[_0xf0ba('0x5f')]['id'];_0x8211f0[_0xf0ba('0x6f')]['id']=_0x52b8fe[_0xf0ba('0x4b')][_0xf0ba('0x6e')];return db[_0xf0ba('0x31')][_0xf0ba('0x4a')]({'where':{'id':_0x52b8fe[_0xf0ba('0x48')]['id'],'UserId':null}})[_0xf0ba('0x16')](handleEntityNotFound(_0x20a5c8,null))[_0xf0ba('0x16')](function(_0x25aa2a){if(_0x25aa2a){_0x8211f0['message']=_0x25aa2a['get']({'plain':!![]});return db[_0xf0ba('0x71')][_0xf0ba('0x4a')]({'where':{'id':_0x25aa2a[_0xf0ba('0x8b')]}});}return null;})['then'](handleEntityNotFound(_0x20a5c8,null))[_0xf0ba('0x16')](function(_0x47e04e){if(_0x47e04e){_0x8211f0[_0xf0ba('0x75')]=_0x47e04e[_0xf0ba('0x70')]({'plain':!![]});interaction_log[_0xf0ba('0x17')](_0xf0ba('0x8c'),_0x52b8fe[_0xf0ba('0x5f')]['id'],_0x52b8fe[_0xf0ba('0x5f')][_0xf0ba('0x2e')],_0x52b8fe[_0xf0ba('0x5f')][_0xf0ba('0x74')],_0x8211f0[_0xf0ba('0x75')]['id'],_0x52b8fe[_0xf0ba('0x4b')]?JSON[_0xf0ba('0x1a')](_0x52b8fe['body']):_0xf0ba('0x76'));return respondWithRpcPromise(_0xf0ba('0x8d'),_0xf0ba('0x8e'),_0x8211f0);}return null;})['then'](function(_0x253bc3){var _0x14842a='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x253bc3[_0xf0ba('0x1e')][_0xf0ba('0x78')];return db['sequelize'][_0xf0ba('0x35')](_0x14842a,{'type':db[_0xf0ba('0x7a')][_0xf0ba('0x7b')][_0xf0ba('0x7c')],'raw':!![]})[_0xf0ba('0x16')](function(_0x435cf9){return _0x435cf9;});})[_0xf0ba('0x16')](function(_0x3ea486){if(_0x3ea486){_0x8211f0[_0xf0ba('0x1e')][_0xf0ba('0x8f')]=_0x3ea486[0x0];if(!_0x52b8fe[_0xf0ba('0x4b')]['UserId'])return;return db[_0xf0ba('0x7d')][_0xf0ba('0x4a')]({'where':{'id':_0x52b8fe[_0xf0ba('0x4b')]['UserId'],'role':'agent'},'attributes':['id',_0xf0ba('0x2e'),_0xf0ba('0x7e'),'email',_0xf0ba('0x80')],'raw':!![]});}return null;})[_0xf0ba('0x16')](function(_0x29153d){if(!_0x29153d)return null;_0x8211f0[_0xf0ba('0x1e')]['agent']=_0x29153d;return _0x8211f0;})[_0xf0ba('0x16')](function(_0x459347){if(_0x459347){_0x459347[_0xf0ba('0x1e')][_0xf0ba('0x82')]=util['format'](_0xf0ba('0x83'),_0x52b8fe['user']['name']);_0x459347[_0xf0ba('0x1e')][_0xf0ba('0x84')]=_0x8211f0[_0xf0ba('0x84')];_0x459347['message'][_0xf0ba('0x85')]=_0x8211f0['channel'];_0x459347[_0xf0ba('0x1e')][_0xf0ba('0x86')]='reject';_0x459347[_0xf0ba('0x1e')][_0xf0ba('0x4b')]=htmlToText[_0xf0ba('0x87')](_0x8211f0[_0xf0ba('0x1e')][_0xf0ba('0x4b')]);respondWithRpcPromise(_0xf0ba('0x88'),'EventManager',{'event':_0xf0ba('0x90'),'message':_0x459347['message']},client9002);return _0x8211f0;}return null;})[_0xf0ba('0x16')](respondWithResult(_0x20a5c8,null))['catch'](handleError(_0x20a5c8,null));};exports[_0xf0ba('0x91')]=function(_0x16f6ea,_0x33f033){var _0x3140d0=moment()[_0xf0ba('0x92')]()[_0xf0ba('0x93')]();var _0x1ea6f8=path['join'](config['root'],_0xf0ba('0x94'),_0xf0ba('0x95'),_0xf0ba('0x96'));var _0xdff4d6=path[_0xf0ba('0x97')](config[_0xf0ba('0x63')],_0xf0ba('0x94'),_0xf0ba('0x95'),_0xf0ba('0x62'));var _0x31081b=util[_0xf0ba('0x6a')](_0xf0ba('0x98'),_0x3140d0);return db[_0xf0ba('0x31')][_0xf0ba('0x4a')]({'where':{'id':_0x16f6ea[_0xf0ba('0x48')]['id']},'attributes':['id',_0xf0ba('0x4b'),_0xf0ba('0x99'),'to','cc','bcc','subject',_0xf0ba('0x9a')],'include':_0x16f6ea['query'][_0xf0ba('0x62')]?[{'model':db['Attachment'],'as':_0xf0ba('0x9b')}]:undefined})[_0xf0ba('0x16')](handleEntityNotFound(_0x33f033,null))[_0xf0ba('0x16')](function(_0x599efd){if(_0x599efd){var _0x363724=_0x599efd;var _0x18ca2e={'from':_0x363724[_0xf0ba('0x99')],'to':_0x363724['to'],'subject':_0x363724[_0xf0ba('0x9c')],'html':htmlEntities[_0xf0ba('0x9d')](_0x363724[_0xf0ba('0x4b')]),'headers':{'Date':moment(_0x363724[_0xf0ba('0x9a')])[_0xf0ba('0x6a')](_0xf0ba('0x9e'))},'attachments':[]};if(_0x599efd['cc']){_0x18ca2e[_0xf0ba('0x9f')]['Cc']=_0x599efd['cc'];}if(_0x599efd[_0xf0ba('0xa0')]){_0x18ca2e[_0xf0ba('0x9f')][_0xf0ba('0xa1')]=_0x599efd[_0xf0ba('0xa0')];}return new BPromise(function(_0xa474ac,_0x3f7626){if(_0x599efd[_0xf0ba('0x9b')]){for(var _0xd521b1=0x0;_0xd521b1<_0x599efd[_0xf0ba('0x9b')][_0xf0ba('0x3b')];_0xd521b1++){var _0x169b23=_0x599efd['Attachments'][_0xd521b1];var _0x5015b1=path[_0xf0ba('0x97')](_0xdff4d6,_0x169b23['basename']);if(fs[_0xf0ba('0xa2')](_0x5015b1)){_0x18ca2e[_0xf0ba('0x62')][_0xf0ba('0xa3')]({'name':_0x169b23[_0xf0ba('0x2e')],'contentType':_0x169b23[_0xf0ba('0x33')],'data':fs[_0xf0ba('0xa4')](_0x5015b1)});}}}emlformat[_0xf0ba('0xa5')](_0x18ca2e,function(_0x14a6e6,_0x154c4e){if(_0x14a6e6)return _0x3f7626(_0x14a6e6);fs[_0xf0ba('0xa6')](path[_0xf0ba('0x97')](_0x1ea6f8,_0x31081b),_0x154c4e);return _0xa474ac(_0x154c4e);});});}})[_0xf0ba('0x16')](function(_0x4e5709){if(_0x4e5709){return _0x33f033[_0xf0ba('0x91')](path[_0xf0ba('0x97')](_0x1ea6f8,_0x31081b),_0x31081b,function(_0x3bea55){if(!_0x3bea55)fs[_0xf0ba('0xa7')](path[_0xf0ba('0x97')](_0x1ea6f8,_0x31081b));});}})[_0xf0ba('0x20')](handleError(_0x33f033,null));};
\ No newline at end of file
+var _0x591b=['end','sendStatus','stack','name','send','index','MailMessage','fieldName','key','map','query','keys','filters','intersection','model','fields','attributes','length','order','sort','where','pick','filter','merge','VIRTUAL','options','includeAll','include','findAll','rows','catch','show','params','rawAttributes','find','body','describe','create','direction','out','secret','split','MailAccount','findOne','MailAccountId','CmList','Contacts','updatedAt','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','server/files/attachments','List','CmContact','ListId','SendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','read','readAt','UserId','user','agent','get','MailInteraction','MailInteractionId','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','QueryTypes','SELECT','contact','User','email','interface','SIP/%s','channel','fromString','EventManager','acceptmessage','reject','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','internal','motionChannel','event','rejectmessage','download','server','tmp','files','message-%s.eml','subject','createdAt','Attachments','decode','headers','bcc','Bcc','basename','push','type','build','writeFileSync','unlinkSync','eml-format','moment','util','path','lodash','ioredis','html-to-text','../../components/parsers/qs','api','../../config/logger','../../config/environment','defaults','localhost','socket.io-emitter','redis','html-entities','./mailMessage.socket','register','jayson/promise','http','client','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','MailMessage,\x20%s,\x20%s','message','info','result','status','json','offset','limit','undefined','count','set','Content-Range','update','then','destroy'];(function(_0x3f6426,_0x12cbf9){var _0x25d790=function(_0x3c6756){while(--_0x3c6756){_0x3f6426['push'](_0x3f6426['shift']());}};_0x25d790(++_0x12cbf9);}(_0x591b,0x77));var _0xb591=function(_0x1a7352,_0x1b50c2){_0x1a7352=_0x1a7352-0x0;var _0x533af4=_0x591b[_0x1a7352];return _0x533af4;};'use strict';var emlformat=require(_0xb591('0x0'));var moment=require(_0xb591('0x1'));var BPromise=require('bluebird');var util=require(_0xb591('0x2'));var path=require(_0xb591('0x3'));var fs=require('fs');var _=require(_0xb591('0x4'));var Redis=require(_0xb591('0x5'));var htmlToText=require(_0xb591('0x6'));var qs=require(_0xb591('0x7'));var logger=require('../../config/logger')(_0xb591('0x8'));var interaction_log=require(_0xb591('0x9'))('mail-interactions');var config=require(_0xb591('0xa'));var db=require('../../mysqldb')['db'];config['redis']=_[_0xb591('0xb')](config['redis'],{'host':_0xb591('0xc'),'port':0x18eb});var socket=require(_0xb591('0xd'))(new Redis(config[_0xb591('0xe')]));var htmlEntities=require(_0xb591('0xf'));require(_0xb591('0x10'))[_0xb591('0x11')](socket);var jayson=require(_0xb591('0x12'));var client=jayson['client'][_0xb591('0x13')]({'port':0x232c});var client9003=jayson[_0xb591('0x14')][_0xb591('0x13')]({'port':0x232b});var client9002=jayson[_0xb591('0x14')][_0xb591('0x13')]({'port':0x232a});function respondWithRpcPromise(_0x52b404,_0x41cea2,_0x4b42c9,_0x58b4ed){return new BPromise(function(_0x25d347,_0x3d1f7c){var _0x566cf5=_0x58b4ed||client;return _0x566cf5['request'](_0x52b404,_0x4b42c9)['then'](function(_0x5b6043){logger['info']('MailMessage,\x20%s,\x20%s',_0x41cea2,_0xb591('0x15'));logger['debug'](_0xb591('0x16'),_0x41cea2,_0xb591('0x15'),JSON[_0xb591('0x17')](_0x5b6043));if(_0x5b6043['error']){if(_0x5b6043[_0xb591('0x18')][_0xb591('0x19')]===0x1f4){logger[_0xb591('0x18')](_0xb591('0x1a'),_0x41cea2,_0x5b6043[_0xb591('0x18')][_0xb591('0x1b')]);return _0x3d1f7c(_0x5b6043[_0xb591('0x18')][_0xb591('0x1b')]);}logger[_0xb591('0x18')](_0xb591('0x1a'),_0x41cea2,_0x5b6043[_0xb591('0x18')][_0xb591('0x1b')]);return _0x25d347(_0x5b6043[_0xb591('0x18')][_0xb591('0x1b')]);}else{logger[_0xb591('0x1c')]('MailMessage,\x20%s,\x20%s',_0x41cea2,_0xb591('0x15'));_0x25d347(_0x5b6043[_0xb591('0x1d')]['message']);}})['catch'](function(_0x1e428b){logger[_0xb591('0x18')](_0xb591('0x1a'),_0x41cea2,_0x1e428b);_0x3d1f7c(_0x1e428b);});});}function respondWithResult(_0x10bfff,_0x24d771){_0x24d771=_0x24d771||0xc8;return function(_0x490859){if(_0x490859){return _0x10bfff[_0xb591('0x1e')](_0x24d771)[_0xb591('0x1f')](_0x490859);}};}function respondWithFilteredResult(_0x150de1,_0x295977){return function(_0x11755b){if(_0x11755b){var _0x1d648f=typeof _0x295977[_0xb591('0x20')]==='undefined'&&typeof _0x295977[_0xb591('0x21')]===_0xb591('0x22');var _0x2503dd=_0x11755b[_0xb591('0x23')];var _0x3b29ea=_0x1d648f?0x0:_0x295977[_0xb591('0x20')];var _0x4a3095=_0x1d648f?_0x11755b[_0xb591('0x23')]:_0x295977[_0xb591('0x20')]+_0x295977[_0xb591('0x21')];var _0x216363;if(_0x4a3095>=_0x2503dd){_0x4a3095=_0x2503dd;_0x216363=0xc8;}else{_0x216363=0xce;}_0x150de1[_0xb591('0x1e')](_0x216363);return _0x150de1[_0xb591('0x24')](_0xb591('0x25'),_0x3b29ea+'-'+_0x4a3095+'/'+_0x2503dd)[_0xb591('0x1f')](_0x11755b);}return null;};}function saveUpdates(_0x46439e){return function(_0x58578a){if(_0x58578a){return _0x58578a[_0xb591('0x26')](_0x46439e)[_0xb591('0x27')](function(_0x1e231a){return _0x1e231a;});}return null;};}function removeEntity(_0xeabf70){return function(_0x1f4d3c){if(_0x1f4d3c){return _0x1f4d3c[_0xb591('0x28')]()[_0xb591('0x27')](function(){_0xeabf70['status'](0xcc)[_0xb591('0x29')]();});}};}function handleEntityNotFound(_0x93a158){return function(_0x44688d){if(!_0x44688d){_0x93a158[_0xb591('0x2a')](0x194);}return _0x44688d;};}function handleError(_0x40f356,_0x40b910){_0x40b910=_0x40b910||0x1f4;return function(_0x3e5106){logger[_0xb591('0x18')](_0x3e5106[_0xb591('0x2b')]);if(_0x3e5106[_0xb591('0x2c')]){delete _0x3e5106['name'];}_0x40f356[_0xb591('0x1e')](_0x40b910)[_0xb591('0x2d')](_0x3e5106);};}exports[_0xb591('0x2e')]=function(_0x5eba2c,_0x2b0bdc){var _0x4c41dc={},_0x2b3011={},_0x20a6f2={'count':0x0,'rows':[]};var _0x1b3ff0=_['map'](db[_0xb591('0x2f')]['rawAttributes'],function(_0x313e72){return{'name':_0x313e72[_0xb591('0x30')],'type':_0x313e72['type'][_0xb591('0x31')]};});_0x2b3011['model']=_[_0xb591('0x32')](_0x1b3ff0,_0xb591('0x2c'));_0x2b3011[_0xb591('0x33')]=_[_0xb591('0x34')](_0x5eba2c[_0xb591('0x33')]);_0x2b3011[_0xb591('0x35')]=_[_0xb591('0x36')](_0x2b3011[_0xb591('0x37')],_0x2b3011[_0xb591('0x33')]);_0x4c41dc['attributes']=_[_0xb591('0x36')](_0x2b3011[_0xb591('0x37')],qs[_0xb591('0x38')](_0x5eba2c[_0xb591('0x33')]['fields']));_0x4c41dc[_0xb591('0x39')]=_0x4c41dc[_0xb591('0x39')][_0xb591('0x3a')]?_0x4c41dc['attributes']:_0x2b3011[_0xb591('0x37')];if(!_0x5eba2c[_0xb591('0x33')]['hasOwnProperty']('nolimit')){_0x4c41dc[_0xb591('0x21')]=qs[_0xb591('0x21')](_0x5eba2c[_0xb591('0x33')][_0xb591('0x21')]);_0x4c41dc[_0xb591('0x20')]=qs['offset'](_0x5eba2c[_0xb591('0x33')][_0xb591('0x20')]);}_0x4c41dc[_0xb591('0x3b')]=qs['sort'](_0x5eba2c['query'][_0xb591('0x3c')]);_0x4c41dc[_0xb591('0x3d')]=qs[_0xb591('0x35')](_[_0xb591('0x3e')](_0x5eba2c[_0xb591('0x33')],_0x2b3011[_0xb591('0x35')]),_0x1b3ff0);if(_0x5eba2c['query'][_0xb591('0x3f')]){_0x4c41dc['where']=_[_0xb591('0x40')](_0x4c41dc[_0xb591('0x3d')],{'$or':_[_0xb591('0x32')](_0x1b3ff0,function(_0x1c6225){if(_0x1c6225['type']!==_0xb591('0x41')){var _0x2ff51b={};_0x2ff51b[_0x1c6225[_0xb591('0x2c')]]={'$like':'%'+_0x5eba2c[_0xb591('0x33')][_0xb591('0x3f')]+'%'};return _0x2ff51b;}})});}_0x4c41dc=_[_0xb591('0x40')]({},_0x4c41dc,_0x5eba2c[_0xb591('0x42')]);var _0x362208={'where':_0x4c41dc[_0xb591('0x3d')]};return db[_0xb591('0x2f')][_0xb591('0x23')](_0x362208)[_0xb591('0x27')](function(_0x209711){_0x20a6f2[_0xb591('0x23')]=_0x209711;if(_0x5eba2c[_0xb591('0x33')][_0xb591('0x43')]){_0x4c41dc[_0xb591('0x44')]=[{'all':!![]}];}return db[_0xb591('0x2f')][_0xb591('0x45')](_0x4c41dc);})[_0xb591('0x27')](function(_0x4a37da){_0x20a6f2[_0xb591('0x46')]=_0x4a37da;return _0x20a6f2;})[_0xb591('0x27')](respondWithFilteredResult(_0x2b0bdc,_0x4c41dc))[_0xb591('0x47')](handleError(_0x2b0bdc,null));};exports[_0xb591('0x48')]=function(_0x2736c5,_0xf8d937){var _0x593adc={'raw':!![],'where':{'id':_0x2736c5[_0xb591('0x49')]['id']}},_0x209c1e={};_0x209c1e[_0xb591('0x37')]=_[_0xb591('0x34')](db[_0xb591('0x2f')][_0xb591('0x4a')]);_0x209c1e[_0xb591('0x33')]=_[_0xb591('0x34')](_0x2736c5[_0xb591('0x33')]);_0x209c1e[_0xb591('0x35')]=_[_0xb591('0x36')](_0x209c1e['model'],_0x209c1e['query']);_0x593adc[_0xb591('0x39')]=_[_0xb591('0x36')](_0x209c1e['model'],qs[_0xb591('0x38')](_0x2736c5[_0xb591('0x33')]['fields']));_0x593adc['attributes']=_0x593adc[_0xb591('0x39')]['length']?_0x593adc[_0xb591('0x39')]:_0x209c1e[_0xb591('0x37')];if(_0x2736c5[_0xb591('0x33')][_0xb591('0x43')]){_0x593adc['include']=[{'all':!![]}];}_0x593adc=_[_0xb591('0x40')]({},_0x593adc,_0x2736c5['options']);return db[_0xb591('0x2f')][_0xb591('0x4b')](_0x593adc)['then'](handleEntityNotFound(_0xf8d937,null))[_0xb591('0x27')](respondWithResult(_0xf8d937,null))[_0xb591('0x47')](handleError(_0xf8d937,null));};exports[_0xb591('0x26')]=function(_0x44d637,_0x46dfd0){if(_0x44d637['body']['id']){delete _0x44d637['body']['id'];}return db['MailMessage'][_0xb591('0x4b')]({'where':{'id':_0x44d637[_0xb591('0x49')]['id']}})[_0xb591('0x27')](handleEntityNotFound(_0x46dfd0,null))[_0xb591('0x27')](saveUpdates(_0x44d637[_0xb591('0x4c')],null))[_0xb591('0x27')](respondWithResult(_0x46dfd0,null))[_0xb591('0x47')](handleError(_0x46dfd0,null));};exports[_0xb591('0x28')]=function(_0x3803,_0x5ab046){return db[_0xb591('0x2f')]['find']({'where':{'id':_0x3803[_0xb591('0x49')]['id']}})['then'](handleEntityNotFound(_0x5ab046,null))['then'](removeEntity(_0x5ab046,null))[_0xb591('0x47')](handleError(_0x5ab046,null));};exports[_0xb591('0x4d')]=function(_0x288308,_0x389371){return db[_0xb591('0x2f')][_0xb591('0x4d')]()[_0xb591('0x27')](respondWithResult(_0x389371,null))[_0xb591('0x47')](handleError(_0x389371,null));};exports[_0xb591('0x4e')]=function(_0x5a10b4,_0x446317){return db[_0xb591('0x2f')][_0xb591('0x4e')](_0x5a10b4[_0xb591('0x4c')])['then'](function(_0x3cd14d){if(_0x3cd14d){if(_0x3cd14d[_0xb591('0x4f')]===_0xb591('0x50')&&!_0x3cd14d[_0xb591('0x51')]){var _0x55d45b,_0xe6a12e,_0xaafa81;if(_0x5a10b4[_0xb591('0x4c')]['to']){_0xe6a12e=_0x5a10b4[_0xb591('0x4c')]['to'][_0xb591('0x52')](',')[0x0];}return db[_0xb591('0x53')][_0xb591('0x54')]({'where':{'id':_0x3cd14d[_0xb591('0x55')]},'include':[{'model':db[_0xb591('0x56')],'as':'List','include':[{'model':db['CmContact'],'as':_0xb591('0x57'),'where':{'email':_0xe6a12e},'limit':0x1,'order':[[_0xb591('0x58'),'DESC']]}]},{'model':db[_0xb591('0x59')],'as':_0xb591('0x5a'),'raw':!![],'include':[{'model':db[_0xb591('0x5b')],'as':_0xb591('0x5b'),'raw':!![]}]}]})[_0xb591('0x27')](function(_0x14189a){_0x55d45b=_0x14189a;if(!_0x55d45b||!_0x55d45b[_0xb591('0x5a')])return;var _0x32cb58=_0x55d45b[_0xb591('0x5c')]();if(_0x5a10b4['body'][_0xb591('0x5d')]&&_0x5a10b4[_0xb591('0x4c')][_0xb591('0x5d')]['length']){for(var _0x405eb6=0x0;_0x405eb6<_0x5a10b4[_0xb591('0x4c')][_0xb591('0x5d')][_0xb591('0x3a')];_0x405eb6+=0x1){_0x5a10b4[_0xb591('0x4c')][_0xb591('0x5d')][_0x405eb6]={'filename':_0x5a10b4[_0xb591('0x4c')]['attachments'][_0x405eb6]['name'],'path':path[_0xb591('0x5e')](config[_0xb591('0x5f')],_0xb591('0x60'),_0x5a10b4[_0xb591('0x4c')]['attachments'][_0x405eb6]['basename'])};}}_0xaafa81={'account':_0x32cb58,'message':_0x5a10b4[_0xb591('0x4c')]};return;})['then'](function(){if(_0x55d45b[_0xb591('0x61')]){if(_0x55d45b[_0xb591('0x61')][_0xb591('0x57')][_0xb591('0x3a')]){return _0x55d45b[_0xb591('0x61')][_0xb591('0x57')][0x0];}else{return db[_0xb591('0x62')]['create'](_[_0xb591('0xb')](_0x5a10b4[_0xb591('0x4c')],{'firstName':_0x5a10b4['body']['to'],'email':_0x5a10b4[_0xb591('0x4c')]['to'],'phone':_0x5a10b4[_0xb591('0x4c')]['to'],'ListId':_0x55d45b[_0xb591('0x63')]}));}}else{throw new Error('List\x20not\x20found');}})[_0xb591('0x27')](function(){if(_0xaafa81){return respondWithRpcPromise(_0xb591('0x64'),'sendMail',_0xaafa81,client9003)[_0xb591('0x27')](function(_0x9b3bac){return _0x3cd14d['update']({'read':!![],'messageId':_0x9b3bac[_0xb591('0x65')],'sentAt':moment()[_0xb591('0x66')](_0xb591('0x67'))});})[_0xb591('0x47')](function(_0x5bdee7){logger[_0xb591('0x18')]('%s',JSON[_0xb591('0x17')](_0x5bdee7));return _0x3cd14d;});}return _0x3cd14d;});}return _0x3cd14d;}})[_0xb591('0x27')](respondWithResult(_0x446317,0xc9))['catch'](handleError(_0x446317,null));};exports[_0xb591('0x68')]=function(_0x2157fa,_0x10ab1b){var _0x1c2965={'agent':{},'channel':_0xb591('0x69')};if(_0x2157fa[_0xb591('0x4c')]['id']){delete _0x2157fa[_0xb591('0x4c')]['id'];}_0x2157fa['body'][_0xb591('0x6a')]=!![];_0x2157fa[_0xb591('0x4c')][_0xb591('0x6b')]=moment()['format'](_0xb591('0x67'));_0x2157fa['body'][_0xb591('0x6c')]=_0x2157fa[_0xb591('0x4c')][_0xb591('0x6c')]||_0x2157fa[_0xb591('0x6d')]['id'];_0x1c2965[_0xb591('0x6e')]['id']=_0x2157fa['body']['UserId'];return db[_0xb591('0x2f')][_0xb591('0x4b')]({'where':{'id':_0x2157fa[_0xb591('0x49')]['id'],'UserId':null}})[_0xb591('0x27')](handleEntityNotFound(_0x10ab1b,null))['then'](saveUpdates(_0x2157fa[_0xb591('0x4c')],null))[_0xb591('0x27')](function(_0x2c8d36){if(_0x2c8d36){_0x1c2965[_0xb591('0x1b')]=_0x2c8d36[_0xb591('0x6f')]({'plain':!![]});return db[_0xb591('0x70')]['find']({'where':{'id':_0x2c8d36[_0xb591('0x71')]}});}return null;})[_0xb591('0x27')](handleEntityNotFound(_0x10ab1b,null))['then'](function(_0x44736d){if(_0x44736d){return _0x44736d[_0xb591('0x26')]({'UserId':_0x2157fa[_0xb591('0x4c')][_0xb591('0x6c')],'read1stAt':_['isNil'](_0x44736d[_0xb591('0x72')])?moment()['format'](_0xb591('0x67')):undefined});}return null;})[_0xb591('0x27')](function(_0x362328){if(_0x362328){_0x1c2965[_0xb591('0x73')]=_0x362328['get']({'plain':!![]});interaction_log[_0xb591('0x1c')](_0xb591('0x74'),_0x2157fa['user']['id'],_0x2157fa[_0xb591('0x6d')][_0xb591('0x2c')],_0x2157fa[_0xb591('0x6d')][_0xb591('0x75')],_0x1c2965[_0xb591('0x73')]['id'],_0x2157fa['body']?JSON[_0xb591('0x17')](_0x2157fa['body']):_0xb591('0x76'));return respondWithRpcPromise(_0xb591('0x77'),_0xb591('0x78'),_0x1c2965);}return null;})['then'](function(_0x2f8ba9){var _0x530cc4=_0xb591('0x79')+_0x2f8ba9[_0xb591('0x1b')]['ContactId'];return db[_0xb591('0x7a')][_0xb591('0x33')](_0x530cc4,{'type':db[_0xb591('0x7b')][_0xb591('0x7c')][_0xb591('0x7d')],'raw':!![]})[_0xb591('0x27')](function(_0x52ebc2){return _0x52ebc2;});})[_0xb591('0x27')](function(_0x33d30d){if(_0x33d30d){_0x1c2965[_0xb591('0x1b')][_0xb591('0x7e')]=_0x33d30d[0x0];if(!_0x2157fa[_0xb591('0x4c')][_0xb591('0x6c')])return;return db[_0xb591('0x7f')][_0xb591('0x4b')]({'where':{'id':_0x2157fa['body'][_0xb591('0x6c')],'role':_0xb591('0x6e')},'attributes':['id',_0xb591('0x2c'),'fullname',_0xb591('0x80'),'internal'],'raw':!![]});}return null;})[_0xb591('0x27')](function(_0x56e062){if(!_0x56e062)return null;_0x1c2965['message'][_0xb591('0x6e')]=_0x56e062;return _0x1c2965;})[_0xb591('0x27')](function(_0xb9cfe5){if(_0xb9cfe5){if(_0x2157fa['body']['manual']){_0x1c2965[_0xb591('0x1b')][_0xb591('0x81')]=util[_0xb591('0x66')](_0xb591('0x82'),_0x2157fa['user'][_0xb591('0x2c')]);_0x1c2965[_0xb591('0x1b')][_0xb591('0x83')]=_0x1c2965[_0xb591('0x83')];_0x1c2965[_0xb591('0x1b')]['motionChannel']=_0x1c2965['channel'];_0x1c2965[_0xb591('0x1b')]['event']=_0xb591('0x68');_0x1c2965['message']['body']=htmlToText[_0xb591('0x84')](_0x1c2965[_0xb591('0x1b')][_0xb591('0x4c')]);return respondWithRpcPromise(_0xb591('0x85'),_0xb591('0x85'),{'event':_0xb591('0x86'),'message':_0x1c2965[_0xb591('0x1b')]},client9002)[_0xb591('0x27')](function(){return _0x1c2965;});}return _0x1c2965;}return null;})[_0xb591('0x27')](respondWithResult(_0x10ab1b,null))[_0xb591('0x47')](handleError(_0x10ab1b,null));};exports[_0xb591('0x87')]=function(_0x2c331c,_0x231412){var _0x31219f={'agent':{},'channel':_0xb591('0x69')};if(_0x2c331c[_0xb591('0x4c')]['id']){delete _0x2c331c[_0xb591('0x4c')]['id'];}_0x2c331c[_0xb591('0x4c')][_0xb591('0x6c')]=_0x2c331c[_0xb591('0x4c')][_0xb591('0x6c')]||_0x2c331c[_0xb591('0x6d')]['id'];_0x31219f[_0xb591('0x6e')]['id']=_0x2c331c[_0xb591('0x4c')][_0xb591('0x6c')];return db[_0xb591('0x2f')][_0xb591('0x4b')]({'where':{'id':_0x2c331c[_0xb591('0x49')]['id'],'UserId':null}})[_0xb591('0x27')](handleEntityNotFound(_0x231412,null))[_0xb591('0x27')](function(_0x4bb91b){if(_0x4bb91b){_0x31219f[_0xb591('0x1b')]=_0x4bb91b[_0xb591('0x6f')]({'plain':!![]});return db[_0xb591('0x70')][_0xb591('0x4b')]({'where':{'id':_0x4bb91b[_0xb591('0x71')]}});}return null;})[_0xb591('0x27')](handleEntityNotFound(_0x231412,null))['then'](function(_0x49a07e){if(_0x49a07e){_0x31219f[_0xb591('0x73')]=_0x49a07e['get']({'plain':!![]});interaction_log[_0xb591('0x1c')](_0xb591('0x88'),_0x2c331c[_0xb591('0x6d')]['id'],_0x2c331c['user'][_0xb591('0x2c')],_0x2c331c[_0xb591('0x6d')][_0xb591('0x75')],_0x31219f[_0xb591('0x73')]['id'],_0x2c331c[_0xb591('0x4c')]?JSON[_0xb591('0x17')](_0x2c331c[_0xb591('0x4c')]):'null');return respondWithRpcPromise(_0xb591('0x89'),'rejectMessage',_0x31219f);}return null;})[_0xb591('0x27')](function(_0x335335){var _0x441c9a=_0xb591('0x79')+_0x335335['message']['ContactId'];return db['sequelize']['query'](_0x441c9a,{'type':db[_0xb591('0x7b')][_0xb591('0x7c')][_0xb591('0x7d')],'raw':!![]})[_0xb591('0x27')](function(_0x8387ed){return _0x8387ed;});})[_0xb591('0x27')](function(_0x5d93c4){if(_0x5d93c4){_0x31219f[_0xb591('0x1b')]['contact']=_0x5d93c4[0x0];if(!_0x2c331c['body']['UserId'])return;return db[_0xb591('0x7f')][_0xb591('0x4b')]({'where':{'id':_0x2c331c[_0xb591('0x4c')][_0xb591('0x6c')],'role':_0xb591('0x6e')},'attributes':['id',_0xb591('0x2c'),'fullname',_0xb591('0x80'),_0xb591('0x8a')],'raw':!![]});}return null;})[_0xb591('0x27')](function(_0x3cd071){if(!_0x3cd071)return null;_0x31219f[_0xb591('0x1b')][_0xb591('0x6e')]=_0x3cd071;return _0x31219f;})[_0xb591('0x27')](function(_0x93f9bc){if(_0x93f9bc){_0x93f9bc[_0xb591('0x1b')][_0xb591('0x81')]=util[_0xb591('0x66')](_0xb591('0x82'),_0x2c331c[_0xb591('0x6d')]['name']);_0x93f9bc[_0xb591('0x1b')][_0xb591('0x83')]=_0x31219f[_0xb591('0x83')];_0x93f9bc[_0xb591('0x1b')][_0xb591('0x8b')]=_0x31219f['channel'];_0x93f9bc[_0xb591('0x1b')][_0xb591('0x8c')]=_0xb591('0x87');_0x93f9bc[_0xb591('0x1b')][_0xb591('0x4c')]=htmlToText[_0xb591('0x84')](_0x31219f[_0xb591('0x1b')]['body']);respondWithRpcPromise(_0xb591('0x85'),_0xb591('0x85'),{'event':_0xb591('0x8d'),'message':_0x93f9bc['message']},client9002);return _0x31219f;}return null;})['then'](respondWithResult(_0x231412,null))[_0xb591('0x47')](handleError(_0x231412,null));};exports[_0xb591('0x8e')]=function(_0x54abdc,_0x3f359a){var _0x3baf84=moment()['unix']()['toString']();var _0x4f0ef8=path['join'](config['root'],_0xb591('0x8f'),'files',_0xb591('0x90'));var _0x25023f=path[_0xb591('0x5e')](config[_0xb591('0x5f')],'server',_0xb591('0x91'),_0xb591('0x5d'));var _0x200db0=util[_0xb591('0x66')](_0xb591('0x92'),_0x3baf84);return db[_0xb591('0x2f')][_0xb591('0x4b')]({'where':{'id':_0x54abdc['params']['id']},'attributes':['id',_0xb591('0x4c'),'from','to','cc','bcc',_0xb591('0x93'),_0xb591('0x94')],'include':_0x54abdc[_0xb591('0x33')]['attachments']?[{'model':db['Attachment'],'as':_0xb591('0x95')}]:undefined})['then'](handleEntityNotFound(_0x3f359a,null))[_0xb591('0x27')](function(_0xcd1d58){if(_0xcd1d58){var _0x8e5a44=_0xcd1d58;var _0x5189ac={'from':_0x8e5a44['from'],'to':_0x8e5a44['to'],'subject':_0x8e5a44[_0xb591('0x93')],'html':htmlEntities[_0xb591('0x96')](_0x8e5a44[_0xb591('0x4c')]),'headers':{'Date':moment(_0x8e5a44[_0xb591('0x94')])[_0xb591('0x66')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0xcd1d58['cc']){_0x5189ac[_0xb591('0x97')]['Cc']=_0xcd1d58['cc'];}if(_0xcd1d58[_0xb591('0x98')]){_0x5189ac['headers'][_0xb591('0x99')]=_0xcd1d58[_0xb591('0x98')];}return new BPromise(function(_0x344d4d,_0x502b32){if(_0xcd1d58[_0xb591('0x95')]){for(var _0x1f08c8=0x0;_0x1f08c8<_0xcd1d58[_0xb591('0x95')][_0xb591('0x3a')];_0x1f08c8++){var _0x1b2ec0=_0xcd1d58[_0xb591('0x95')][_0x1f08c8];var _0x298fda=path[_0xb591('0x5e')](_0x25023f,_0x1b2ec0[_0xb591('0x9a')]);if(fs['existsSync'](_0x298fda)){_0x5189ac['attachments'][_0xb591('0x9b')]({'name':_0x1b2ec0[_0xb591('0x2c')],'contentType':_0x1b2ec0[_0xb591('0x9c')],'data':fs['readFileSync'](_0x298fda)});}}}emlformat[_0xb591('0x9d')](_0x5189ac,function(_0x333724,_0x294ad4){if(_0x333724)return _0x502b32(_0x333724);fs[_0xb591('0x9e')](path[_0xb591('0x5e')](_0x4f0ef8,_0x200db0),_0x294ad4);return _0x344d4d(_0x294ad4);});});}})[_0xb591('0x27')](function(_0x2f6a53){if(_0x2f6a53){return _0x3f359a[_0xb591('0x8e')](path[_0xb591('0x5e')](_0x4f0ef8,_0x200db0),_0x200db0,function(_0x7101aa){if(!_0x7101aa)fs[_0xb591('0x9f')](path[_0xb591('0x5e')](_0x4f0ef8,_0x200db0));});}})['catch'](handleError(_0x3f359a,null));};
\ No newline at end of file