Built motion from commit d5e4af8c.|2.6.23
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 08cd4e7..0103475 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x767a=['user','get','MailInteraction','MailInteractionId','isNil','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','SELECT','contact','User','agent','fullname','interface','SIP/%s','channel','EventManager','acceptmessage','mail','RejectMessage','rejectMessage','QueryTypes','email','motionChannel','event','reject','fromString','rejectmessage','unix','toString','server','files','tmp','from','bcc','subject','Attachment','Attachments','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','readFileSync','build','download','unlinkSync','eml-format','bluebird','util','ioredis','html-to-text','../../config/logger','api','mail-interactions','../../config/environment','../../mysqldb','redis','localhost','register','jayson/promise','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','status','json','offset','undefined','limit','Content-Range','destroy','stack','name','send','index','map','fieldName','type','keys','query','attributes','intersection','model','fields','length','nolimit','order','sort','where','filters','pick','merge','filter','options','MailMessage','count','includeAll','include','findAll','rows','show','params','rawAttributes','find','update','body','describe','create','direction','out','secret','split','findOne','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','CloudProvider','attachments','join','root','basename','List','ListId','List\x20not\x20found','messageId','YYYY-MM-DD\x20HH:mm:ss','accept','read','format','UserId'];(function(_0x154e0d,_0x2d81a7){var _0x206294=function(_0xb5a963){while(--_0xb5a963){_0x154e0d['push'](_0x154e0d['shift']());}};_0x206294(++_0x2d81a7);}(_0x767a,0xce));var _0xa767=function(_0x297fd3,_0x115406){_0x297fd3=_0x297fd3-0x0;var _0x2af381=_0x767a[_0x297fd3];return _0x2af381;};'use strict';var emlformat=require(_0xa767('0x0'));var moment=require('moment');var BPromise=require(_0xa767('0x1'));var util=require(_0xa767('0x2'));var path=require('path');var fs=require('fs');var _=require('lodash');var Redis=require(_0xa767('0x3'));var htmlToText=require(_0xa767('0x4'));var qs=require('../../components/parsers/qs');var logger=require(_0xa767('0x5'))(_0xa767('0x6'));var interaction_log=require(_0xa767('0x5'))(_0xa767('0x7'));var config=require(_0xa767('0x8'));var db=require(_0xa767('0x9'))['db'];config[_0xa767('0xa')]=_['defaults'](config[_0xa767('0xa')],{'host':_0xa767('0xb'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xa767('0xa')]));var htmlEntities=require('html-entities');require('./mailMessage.socket')[_0xa767('0xc')](socket);var jayson=require(_0xa767('0xd'));var client=jayson[_0xa767('0xe')]['http']({'port':0x232c});var client9003=jayson['client'][_0xa767('0xf')]({'port':0x232b});var client9002=jayson['client'][_0xa767('0xf')]({'port':0x232a});function respondWithRpcPromise(_0x5c7e0a,_0x270a85,_0x3c7809,_0x486810){return new BPromise(function(_0x57c6cc,_0x32a595){var _0x1401f2=_0x486810||client;return _0x1401f2[_0xa767('0x10')](_0x5c7e0a,_0x3c7809)[_0xa767('0x11')](function(_0x55d784){logger[_0xa767('0x12')](_0xa767('0x13'),_0x270a85,_0xa767('0x14'));logger[_0xa767('0x15')](_0xa767('0x16'),_0x270a85,_0xa767('0x14'),JSON[_0xa767('0x17')](_0x55d784));if(_0x55d784[_0xa767('0x18')]){if(_0x55d784[_0xa767('0x18')][_0xa767('0x19')]===0x1f4){logger[_0xa767('0x18')](_0xa767('0x13'),_0x270a85,_0x55d784[_0xa767('0x18')][_0xa767('0x1a')]);return _0x32a595(_0x55d784[_0xa767('0x18')]['message']);}logger[_0xa767('0x18')]('MailMessage,\x20%s,\x20%s',_0x270a85,_0x55d784[_0xa767('0x18')]['message']);return _0x57c6cc(_0x55d784[_0xa767('0x18')][_0xa767('0x1a')]);}else{logger[_0xa767('0x12')]('MailMessage,\x20%s,\x20%s',_0x270a85,_0xa767('0x14'));_0x57c6cc(_0x55d784['result'][_0xa767('0x1a')]);}})[_0xa767('0x1b')](function(_0x1374ec){logger[_0xa767('0x18')]('MailMessage,\x20%s,\x20%s',_0x270a85,_0x1374ec);_0x32a595(_0x1374ec);});});}function respondWithResult(_0x33a0cf,_0x51d7f1){_0x51d7f1=_0x51d7f1||0xc8;return function(_0x7ffbaa){if(_0x7ffbaa){return _0x33a0cf[_0xa767('0x1c')](_0x51d7f1)[_0xa767('0x1d')](_0x7ffbaa);}};}function respondWithFilteredResult(_0x2a7cfa,_0x5225b7){return function(_0x2e1655){if(_0x2e1655){var _0x17fda8=typeof _0x5225b7[_0xa767('0x1e')]===_0xa767('0x1f')&&typeof _0x5225b7[_0xa767('0x20')]===_0xa767('0x1f');var _0x3bb576=_0x2e1655['count'];var _0x3fe796=_0x17fda8?0x0:_0x5225b7[_0xa767('0x1e')];var _0x514f11=_0x17fda8?_0x2e1655['count']:_0x5225b7[_0xa767('0x1e')]+_0x5225b7[_0xa767('0x20')];var _0x55de0b;if(_0x514f11>=_0x3bb576){_0x514f11=_0x3bb576;_0x55de0b=0xc8;}else{_0x55de0b=0xce;}_0x2a7cfa[_0xa767('0x1c')](_0x55de0b);return _0x2a7cfa['set'](_0xa767('0x21'),_0x3fe796+'-'+_0x514f11+'/'+_0x3bb576)[_0xa767('0x1d')](_0x2e1655);}return null;};}function saveUpdates(_0x402bdd){return function(_0x2d6c3d){if(_0x2d6c3d){return _0x2d6c3d['update'](_0x402bdd)[_0xa767('0x11')](function(_0x178795){return _0x178795;});}return null;};}function removeEntity(_0x58be9e){return function(_0x3cf9c1){if(_0x3cf9c1){return _0x3cf9c1[_0xa767('0x22')]()[_0xa767('0x11')](function(){_0x58be9e[_0xa767('0x1c')](0xcc)['end']();});}};}function handleEntityNotFound(_0x19f397){return function(_0x31051f){if(!_0x31051f){_0x19f397['sendStatus'](0x194);}return _0x31051f;};}function handleError(_0x326f4d,_0x425f82){_0x425f82=_0x425f82||0x1f4;return function(_0x5392a9){logger['error'](_0x5392a9[_0xa767('0x23')]);if(_0x5392a9['name']){delete _0x5392a9[_0xa767('0x24')];}_0x326f4d['status'](_0x425f82)[_0xa767('0x25')](_0x5392a9);};}exports[_0xa767('0x26')]=function(_0x5097fb,_0x1fd71b){var _0x62f7ea={},_0xde040e={},_0x2c67c7={'count':0x0,'rows':[]};var _0x1c3b68=_[_0xa767('0x27')](db['MailMessage']['rawAttributes'],function(_0x4a2beb){return{'name':_0x4a2beb[_0xa767('0x28')],'type':_0x4a2beb[_0xa767('0x29')]['key']};});_0xde040e['model']=_[_0xa767('0x27')](_0x1c3b68,_0xa767('0x24'));_0xde040e['query']=_[_0xa767('0x2a')](_0x5097fb['query']);_0xde040e['filters']=_['intersection'](_0xde040e['model'],_0xde040e[_0xa767('0x2b')]);_0x62f7ea[_0xa767('0x2c')]=_[_0xa767('0x2d')](_0xde040e[_0xa767('0x2e')],qs[_0xa767('0x2f')](_0x5097fb[_0xa767('0x2b')][_0xa767('0x2f')]));_0x62f7ea[_0xa767('0x2c')]=_0x62f7ea[_0xa767('0x2c')][_0xa767('0x30')]?_0x62f7ea[_0xa767('0x2c')]:_0xde040e[_0xa767('0x2e')];if(!_0x5097fb['query']['hasOwnProperty'](_0xa767('0x31'))){_0x62f7ea[_0xa767('0x20')]=qs[_0xa767('0x20')](_0x5097fb[_0xa767('0x2b')][_0xa767('0x20')]);_0x62f7ea['offset']=qs['offset'](_0x5097fb['query'][_0xa767('0x1e')]);}_0x62f7ea[_0xa767('0x32')]=qs[_0xa767('0x33')](_0x5097fb[_0xa767('0x2b')][_0xa767('0x33')]);_0x62f7ea[_0xa767('0x34')]=qs[_0xa767('0x35')](_[_0xa767('0x36')](_0x5097fb[_0xa767('0x2b')],_0xde040e['filters']),_0x1c3b68);if(_0x5097fb[_0xa767('0x2b')]['filter']){_0x62f7ea[_0xa767('0x34')]=_[_0xa767('0x37')](_0x62f7ea[_0xa767('0x34')],{'$or':_[_0xa767('0x27')](_0x1c3b68,function(_0x2b5339){if(_0x2b5339['type']!=='VIRTUAL'){var _0x434fc6={};_0x434fc6[_0x2b5339[_0xa767('0x24')]]={'$like':'%'+_0x5097fb[_0xa767('0x2b')][_0xa767('0x38')]+'%'};return _0x434fc6;}})});}_0x62f7ea=_['merge']({},_0x62f7ea,_0x5097fb[_0xa767('0x39')]);var _0x24f018={'where':_0x62f7ea['where']};return db[_0xa767('0x3a')][_0xa767('0x3b')](_0x24f018)[_0xa767('0x11')](function(_0x2946c3){_0x2c67c7['count']=_0x2946c3;if(_0x5097fb[_0xa767('0x2b')][_0xa767('0x3c')]){_0x62f7ea[_0xa767('0x3d')]=[{'all':!![]}];}return db['MailMessage'][_0xa767('0x3e')](_0x62f7ea);})['then'](function(_0x395bf4){_0x2c67c7[_0xa767('0x3f')]=_0x395bf4;return _0x2c67c7;})['then'](respondWithFilteredResult(_0x1fd71b,_0x62f7ea))[_0xa767('0x1b')](handleError(_0x1fd71b,null));};exports[_0xa767('0x40')]=function(_0x49f0f5,_0x35faca){var _0x4fe05e={'raw':!![],'where':{'id':_0x49f0f5[_0xa767('0x41')]['id']}},_0x19a09d={};_0x19a09d['model']=_[_0xa767('0x2a')](db[_0xa767('0x3a')][_0xa767('0x42')]);_0x19a09d[_0xa767('0x2b')]=_[_0xa767('0x2a')](_0x49f0f5['query']);_0x19a09d[_0xa767('0x35')]=_[_0xa767('0x2d')](_0x19a09d[_0xa767('0x2e')],_0x19a09d[_0xa767('0x2b')]);_0x4fe05e[_0xa767('0x2c')]=_[_0xa767('0x2d')](_0x19a09d[_0xa767('0x2e')],qs[_0xa767('0x2f')](_0x49f0f5[_0xa767('0x2b')][_0xa767('0x2f')]));_0x4fe05e[_0xa767('0x2c')]=_0x4fe05e[_0xa767('0x2c')][_0xa767('0x30')]?_0x4fe05e[_0xa767('0x2c')]:_0x19a09d[_0xa767('0x2e')];if(_0x49f0f5['query']['includeAll']){_0x4fe05e[_0xa767('0x3d')]=[{'all':!![]}];}_0x4fe05e=_[_0xa767('0x37')]({},_0x4fe05e,_0x49f0f5['options']);return db[_0xa767('0x3a')][_0xa767('0x43')](_0x4fe05e)[_0xa767('0x11')](handleEntityNotFound(_0x35faca,null))[_0xa767('0x11')](respondWithResult(_0x35faca,null))['catch'](handleError(_0x35faca,null));};exports[_0xa767('0x44')]=function(_0x13135f,_0x2684b6){if(_0x13135f['body']['id']){delete _0x13135f[_0xa767('0x45')]['id'];}return db['MailMessage']['find']({'where':{'id':_0x13135f[_0xa767('0x41')]['id']}})[_0xa767('0x11')](handleEntityNotFound(_0x2684b6,null))[_0xa767('0x11')](saveUpdates(_0x13135f[_0xa767('0x45')],null))[_0xa767('0x11')](respondWithResult(_0x2684b6,null))[_0xa767('0x1b')](handleError(_0x2684b6,null));};exports[_0xa767('0x22')]=function(_0x349f7b,_0x252e9f){return db[_0xa767('0x3a')][_0xa767('0x43')]({'where':{'id':_0x349f7b[_0xa767('0x41')]['id']}})[_0xa767('0x11')](handleEntityNotFound(_0x252e9f,null))[_0xa767('0x11')](removeEntity(_0x252e9f,null))[_0xa767('0x1b')](handleError(_0x252e9f,null));};exports[_0xa767('0x46')]=function(_0x4f4a60,_0x379bdf){return db[_0xa767('0x3a')][_0xa767('0x46')]()['then'](respondWithResult(_0x379bdf,null))[_0xa767('0x1b')](handleError(_0x379bdf,null));};exports[_0xa767('0x47')]=function(_0x527725,_0x16aa3c){return db[_0xa767('0x3a')][_0xa767('0x47')](_0x527725[_0xa767('0x45')])[_0xa767('0x11')](function(_0x1f6c62){if(_0x1f6c62){if(_0x1f6c62[_0xa767('0x48')]===_0xa767('0x49')&&!_0x1f6c62[_0xa767('0x4a')]){var _0x3cf75a,_0x40de57,_0x48d32a;if(_0x527725[_0xa767('0x45')]['to']){_0x40de57=_0x527725[_0xa767('0x45')]['to'][_0xa767('0x4b')](',')[0x0];}return db['MailAccount'][_0xa767('0x4c')]({'where':{'id':_0x1f6c62[_0xa767('0x4d')]},'include':[{'model':db[_0xa767('0x4e')],'as':'List','include':[{'model':db[_0xa767('0x4f')],'as':_0xa767('0x50'),'where':{'email':_0x40de57},'limit':0x1,'order':[[_0xa767('0x51'),_0xa767('0x52')]]}]},{'model':db[_0xa767('0x53')],'as':'Smtp','raw':!![],'include':[{'model':db[_0xa767('0x54')],'as':'CloudProvider','raw':!![]}]}]})[_0xa767('0x11')](function(_0x1de1b1){_0x3cf75a=_0x1de1b1;if(!_0x3cf75a||!_0x3cf75a['Smtp'])return;var _0x5b37e7=_0x3cf75a['getSmtpOptions']();if(_0x527725[_0xa767('0x45')][_0xa767('0x55')]&&_0x527725['body']['attachments'][_0xa767('0x30')]){for(var _0x4a7f89=0x0;_0x4a7f89<_0x527725[_0xa767('0x45')]['attachments'][_0xa767('0x30')];_0x4a7f89+=0x1){_0x527725[_0xa767('0x45')][_0xa767('0x55')][_0x4a7f89]={'filename':_0x527725[_0xa767('0x45')][_0xa767('0x55')][_0x4a7f89][_0xa767('0x24')],'path':path[_0xa767('0x56')](config[_0xa767('0x57')],'server/files/attachments',_0x527725['body'][_0xa767('0x55')][_0x4a7f89][_0xa767('0x58')])};}}_0x48d32a={'account':_0x5b37e7,'message':_0x527725[_0xa767('0x45')]};return;})['then'](function(){if(_0x3cf75a[_0xa767('0x59')]){if(_0x3cf75a[_0xa767('0x59')][_0xa767('0x50')][_0xa767('0x30')]){return _0x3cf75a[_0xa767('0x59')][_0xa767('0x50')][0x0];}else{return db['CmContact'][_0xa767('0x47')](_['defaults'](_0x527725[_0xa767('0x45')],{'firstName':_0x527725[_0xa767('0x45')]['to'],'email':_0x527725[_0xa767('0x45')]['to'],'phone':_0x527725[_0xa767('0x45')]['to'],'ListId':_0x3cf75a[_0xa767('0x5a')]}));}}else{throw new Error(_0xa767('0x5b'));}})[_0xa767('0x11')](function(){if(_0x48d32a){return respondWithRpcPromise('SendMail','sendMail',_0x48d32a,client9003)[_0xa767('0x11')](function(_0x424a82){return _0x1f6c62[_0xa767('0x44')]({'read':!![],'messageId':_0x424a82[_0xa767('0x5c')],'sentAt':moment()['format'](_0xa767('0x5d'))});})[_0xa767('0x1b')](function(_0x54176a){logger[_0xa767('0x18')]('%s',JSON[_0xa767('0x17')](_0x54176a));return _0x1f6c62;});}return _0x1f6c62;});}return _0x1f6c62;}})[_0xa767('0x11')](respondWithResult(_0x16aa3c,0xc9))[_0xa767('0x1b')](handleError(_0x16aa3c,null));};exports[_0xa767('0x5e')]=function(_0x47c756,_0x6abb3f){var _0x1d6518={'agent':{},'channel':'mail'};if(_0x47c756[_0xa767('0x45')]['id']){delete _0x47c756[_0xa767('0x45')]['id'];}_0x47c756[_0xa767('0x45')][_0xa767('0x5f')]=!![];_0x47c756[_0xa767('0x45')]['readAt']=moment()[_0xa767('0x60')](_0xa767('0x5d'));_0x47c756['body'][_0xa767('0x61')]=_0x47c756['body'][_0xa767('0x61')]||_0x47c756[_0xa767('0x62')]['id'];_0x1d6518['agent']['id']=_0x47c756['body'][_0xa767('0x61')];return db[_0xa767('0x3a')][_0xa767('0x43')]({'where':{'id':_0x47c756['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x6abb3f,null))[_0xa767('0x11')](saveUpdates(_0x47c756[_0xa767('0x45')],null))[_0xa767('0x11')](function(_0x255637){if(_0x255637){_0x1d6518[_0xa767('0x1a')]=_0x255637[_0xa767('0x63')]({'plain':!![]});return db[_0xa767('0x64')]['find']({'where':{'id':_0x255637[_0xa767('0x65')]}});}return null;})[_0xa767('0x11')](handleEntityNotFound(_0x6abb3f,null))[_0xa767('0x11')](function(_0x41e221){if(_0x41e221){return _0x41e221[_0xa767('0x44')]({'UserId':_0x47c756[_0xa767('0x45')][_0xa767('0x61')],'read1stAt':_[_0xa767('0x66')](_0x41e221[_0xa767('0x67')])?moment()['format'](_0xa767('0x5d')):undefined});}return null;})[_0xa767('0x11')](function(_0x58c437){if(_0x58c437){_0x1d6518[_0xa767('0x68')]=_0x58c437[_0xa767('0x63')]({'plain':!![]});interaction_log['info'](_0xa767('0x69'),_0x47c756['user']['id'],_0x47c756[_0xa767('0x62')][_0xa767('0x24')],_0x47c756['user'][_0xa767('0x6a')],_0x1d6518[_0xa767('0x68')]['id'],_0x47c756['body']?JSON['stringify'](_0x47c756[_0xa767('0x45')]):_0xa767('0x6b'));return respondWithRpcPromise(_0xa767('0x6c'),'acceptMessage',_0x1d6518);}return null;})['then'](function(_0x56906c){var _0x290412=_0xa767('0x6d')+_0x56906c[_0xa767('0x1a')][_0xa767('0x6e')];return db['sequelize'][_0xa767('0x2b')](_0x290412,{'type':db[_0xa767('0x6f')]['QueryTypes'][_0xa767('0x70')],'raw':!![]})['then'](function(_0x131e03){return _0x131e03;});})[_0xa767('0x11')](function(_0x42a084){if(_0x42a084){_0x1d6518['message'][_0xa767('0x71')]=_0x42a084[0x0];if(!_0x47c756['body'][_0xa767('0x61')])return;return db[_0xa767('0x72')][_0xa767('0x43')]({'where':{'id':_0x47c756[_0xa767('0x45')][_0xa767('0x61')],'role':_0xa767('0x73')},'attributes':['id',_0xa767('0x24'),_0xa767('0x74'),'email','internal'],'raw':!![]});}return null;})[_0xa767('0x11')](function(_0x355242){if(!_0x355242)return null;_0x1d6518['message'][_0xa767('0x73')]=_0x355242;return _0x1d6518;})[_0xa767('0x11')](function(_0x1af81e){if(_0x1af81e){if(_0x47c756['body']['manual']){_0x1d6518[_0xa767('0x1a')][_0xa767('0x75')]=util[_0xa767('0x60')](_0xa767('0x76'),_0x47c756[_0xa767('0x62')]['name']);_0x1d6518['message'][_0xa767('0x77')]=_0x1d6518['channel'];_0x1d6518[_0xa767('0x1a')]['motionChannel']=_0x1d6518[_0xa767('0x77')];_0x1d6518[_0xa767('0x1a')]['event']=_0xa767('0x5e');_0x1d6518[_0xa767('0x1a')][_0xa767('0x45')]=htmlToText['fromString'](_0x1d6518[_0xa767('0x1a')]['body']);return respondWithRpcPromise(_0xa767('0x78'),_0xa767('0x78'),{'event':_0xa767('0x79'),'message':_0x1d6518[_0xa767('0x1a')]},client9002)[_0xa767('0x11')](function(){return _0x1d6518;});}return _0x1d6518;}return null;})[_0xa767('0x11')](respondWithResult(_0x6abb3f,null))['catch'](handleError(_0x6abb3f,null));};exports['reject']=function(_0x1eadd4,_0xbf6144){var _0x46890f={'agent':{},'channel':_0xa767('0x7a')};if(_0x1eadd4[_0xa767('0x45')]['id']){delete _0x1eadd4[_0xa767('0x45')]['id'];}_0x1eadd4[_0xa767('0x45')][_0xa767('0x61')]=_0x1eadd4[_0xa767('0x45')]['UserId']||_0x1eadd4['user']['id'];_0x46890f[_0xa767('0x73')]['id']=_0x1eadd4[_0xa767('0x45')][_0xa767('0x61')];return db[_0xa767('0x3a')][_0xa767('0x43')]({'where':{'id':_0x1eadd4[_0xa767('0x41')]['id'],'UserId':null}})[_0xa767('0x11')](handleEntityNotFound(_0xbf6144,null))['then'](function(_0x32ed11){if(_0x32ed11){_0x46890f[_0xa767('0x1a')]=_0x32ed11[_0xa767('0x63')]({'plain':!![]});return db[_0xa767('0x64')][_0xa767('0x43')]({'where':{'id':_0x32ed11[_0xa767('0x65')]}});}return null;})[_0xa767('0x11')](handleEntityNotFound(_0xbf6144,null))['then'](function(_0x324a4f){if(_0x324a4f){_0x46890f[_0xa767('0x68')]=_0x324a4f[_0xa767('0x63')]({'plain':!![]});interaction_log[_0xa767('0x12')]('[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1eadd4[_0xa767('0x62')]['id'],_0x1eadd4['user'][_0xa767('0x24')],_0x1eadd4[_0xa767('0x62')][_0xa767('0x6a')],_0x46890f[_0xa767('0x68')]['id'],_0x1eadd4[_0xa767('0x45')]?JSON[_0xa767('0x17')](_0x1eadd4['body']):'null');return respondWithRpcPromise(_0xa767('0x7b'),_0xa767('0x7c'),_0x46890f);}return null;})[_0xa767('0x11')](function(_0x514962){var _0x174300=_0xa767('0x6d')+_0x514962[_0xa767('0x1a')][_0xa767('0x6e')];return db['sequelize'][_0xa767('0x2b')](_0x174300,{'type':db['Sequelize'][_0xa767('0x7d')]['SELECT'],'raw':!![]})[_0xa767('0x11')](function(_0x58cb22){return _0x58cb22;});})[_0xa767('0x11')](function(_0x54a059){if(_0x54a059){_0x46890f[_0xa767('0x1a')][_0xa767('0x71')]=_0x54a059[0x0];if(!_0x1eadd4[_0xa767('0x45')][_0xa767('0x61')])return;return db[_0xa767('0x72')][_0xa767('0x43')]({'where':{'id':_0x1eadd4[_0xa767('0x45')]['UserId'],'role':_0xa767('0x73')},'attributes':['id',_0xa767('0x24'),_0xa767('0x74'),_0xa767('0x7e'),'internal'],'raw':!![]});}return null;})['then'](function(_0x33c291){if(!_0x33c291)return null;_0x46890f[_0xa767('0x1a')]['agent']=_0x33c291;return _0x46890f;})['then'](function(_0x5e4b12){if(_0x5e4b12){_0x5e4b12[_0xa767('0x1a')]['interface']=util[_0xa767('0x60')](_0xa767('0x76'),_0x1eadd4[_0xa767('0x62')][_0xa767('0x24')]);_0x5e4b12[_0xa767('0x1a')]['channel']=_0x46890f[_0xa767('0x77')];_0x5e4b12[_0xa767('0x1a')][_0xa767('0x7f')]=_0x46890f['channel'];_0x5e4b12[_0xa767('0x1a')][_0xa767('0x80')]=_0xa767('0x81');_0x5e4b12[_0xa767('0x1a')][_0xa767('0x45')]=htmlToText[_0xa767('0x82')](_0x46890f[_0xa767('0x1a')][_0xa767('0x45')]);respondWithRpcPromise(_0xa767('0x78'),'EventManager',{'event':_0xa767('0x83'),'message':_0x5e4b12[_0xa767('0x1a')]},client9002);return _0x46890f;}return null;})[_0xa767('0x11')](respondWithResult(_0xbf6144,null))[_0xa767('0x1b')](handleError(_0xbf6144,null));};exports['download']=function(_0x2ae599,_0x54dba0){var _0x4da14c=moment()[_0xa767('0x84')]()[_0xa767('0x85')]();var _0x40d076=path[_0xa767('0x56')](config['root'],_0xa767('0x86'),_0xa767('0x87'),_0xa767('0x88'));var _0x1ae42d=path[_0xa767('0x56')](config[_0xa767('0x57')],_0xa767('0x86'),_0xa767('0x87'),_0xa767('0x55'));var _0x3105d3=util[_0xa767('0x60')]('message-%s.eml',_0x4da14c);return db[_0xa767('0x3a')][_0xa767('0x43')]({'where':{'id':_0x2ae599[_0xa767('0x41')]['id']},'attributes':['id',_0xa767('0x45'),_0xa767('0x89'),'to','cc',_0xa767('0x8a'),_0xa767('0x8b'),'createdAt'],'include':_0x2ae599[_0xa767('0x2b')][_0xa767('0x55')]?[{'model':db[_0xa767('0x8c')],'as':_0xa767('0x8d')}]:undefined})['then'](handleEntityNotFound(_0x54dba0,null))[_0xa767('0x11')](function(_0x19d9b5){if(_0x19d9b5){var _0x3cca0e=_0x19d9b5;var _0x241439={'from':_0x3cca0e[_0xa767('0x89')],'to':_0x3cca0e['to'],'subject':_0x3cca0e['subject'],'html':htmlEntities[_0xa767('0x8e')](_0x3cca0e[_0xa767('0x45')]),'headers':{'Date':moment(_0x3cca0e['createdAt'])['format'](_0xa767('0x8f'))},'attachments':[]};if(_0x19d9b5['cc']){_0x241439['headers']['Cc']=_0x19d9b5['cc'];}if(_0x19d9b5[_0xa767('0x8a')]){_0x241439[_0xa767('0x90')][_0xa767('0x91')]=_0x19d9b5[_0xa767('0x8a')];}return new BPromise(function(_0x140ced,_0x5e282f){if(_0x19d9b5[_0xa767('0x8d')]){for(var _0x33394c=0x0;_0x33394c<_0x19d9b5['Attachments'][_0xa767('0x30')];_0x33394c++){var _0x148a8a=_0x19d9b5[_0xa767('0x8d')][_0x33394c];var _0x10b6f4=path['join'](_0x1ae42d,_0x148a8a[_0xa767('0x58')]);if(fs[_0xa767('0x92')](_0x10b6f4)){_0x241439[_0xa767('0x55')][_0xa767('0x93')]({'name':_0x148a8a[_0xa767('0x24')],'contentType':_0x148a8a['type'],'data':fs[_0xa767('0x94')](_0x10b6f4)});}}}emlformat[_0xa767('0x95')](_0x241439,function(_0x40b0eb,_0x55ef98){if(_0x40b0eb)return _0x5e282f(_0x40b0eb);fs['writeFileSync'](path[_0xa767('0x56')](_0x40d076,_0x3105d3),_0x55ef98);return _0x140ced(_0x55ef98);});});}})[_0xa767('0x11')](function(_0x4e647b){if(_0x4e647b){return _0x54dba0[_0xa767('0x96')](path[_0xa767('0x56')](_0x40d076,_0x3105d3),_0x3105d3,function(_0x4898ae){if(!_0x4898ae)fs[_0xa767('0x97')](path[_0xa767('0x56')](_0x40d076,_0x3105d3));});}})[_0xa767('0x1b')](handleError(_0x54dba0,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