Built motion from commit 00bf23f6.|2.6.16
[motion2.git] / server / api / mailAccount / mailAccount.rpc.js
index 2c5985d..f1ee61e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0271=['then','info','request\x20sent','MailAccount,\x20%s,\x20%s,\x20%s','error','message','MailAccount,\x20%s,\x20%s','catch','GetMailAccount','MailAccount','options','attributes','limit','include','map','model','debug','find','raw','where','ShowMailAccount','stringify','NotifyMailAccount','mail','difference','keys','CmContact','rawAttributes','updatedAt','CompanyId','ListId','body','from','from\x20is\x20mandatory','isNil','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','account','CmList','Contacts','MailApplication','List','get','omit','Applications','applications','list','orderBy','priority','asc','autoclose','close','length','defaults','create','List\x20not\x20found','contact','messageId','generate','attach','format','YYYY-MM-DD\x20HH:mm:ss','MailMessage','inReplyTo','MailInteraction','spread','update','interaction','attachments','originTo','originCc','bcc','ChatWebsiteId','originChannel','Email','ChatOfflineMessageId','Attachment','Attachments','UserId','User','name','unshift','waitForTheAssignedAgent','*,*,*,*','Start','startRouting','lodash','util','moment','bluebird','../../mysqldb','../../config/utils','rpc','jayson/promise','client','http','redis','localhost','socket.io-emitter','./mailAccount.socket','register'];(function(_0x5103b6,_0x15d61b){var _0x5bcfe5=function(_0x44edb6){while(--_0x44edb6){_0x5103b6['push'](_0x5103b6['shift']());}};_0x5bcfe5(++_0x15d61b);}(_0x0271,0x189));var _0x1027=function(_0x424c39,_0xfc231d){_0x424c39=_0x424c39-0x0;var _0x222b08=_0x0271[_0x424c39];return _0x222b08;};'use strict';var _=require(_0x1027('0x0'));var util=require(_0x1027('0x1'));var moment=require(_0x1027('0x2'));var BPromise=require(_0x1027('0x3'));var rs=require('randomstring');var fs=require('fs');var Redis=require('ioredis');var db=require(_0x1027('0x4'))['db'];var utils=require(_0x1027('0x5'));var logger=require('../../config/logger')(_0x1027('0x6'));var config=require('../../config/environment');var jayson=require(_0x1027('0x7'));var client=jayson[_0x1027('0x8')][_0x1027('0x9')]({'port':0x232c});config['redis']=_['defaults'](config[_0x1027('0xa')],{'host':_0x1027('0xb'),'port':0x18eb});var socket=require(_0x1027('0xc'))(new Redis(config[_0x1027('0xa')]));require(_0x1027('0xd'))[_0x1027('0xe')](socket);function respondWithRpcPromise(_0x586275,_0x1cdc16,_0x177c5c){return new BPromise(function(_0x47504c,_0x44afdd){return client['request'](_0x586275,_0x177c5c)[_0x1027('0xf')](function(_0x2606de){logger[_0x1027('0x10')]('MailAccount,\x20%s,\x20%s',_0x1cdc16,_0x1027('0x11'));logger['debug'](_0x1027('0x12'),_0x1cdc16,_0x1027('0x11'),JSON['stringify'](_0x2606de));if(_0x2606de[_0x1027('0x13')]){if(_0x2606de['error']['code']===0x1f4){logger[_0x1027('0x13')]('MailAccount,\x20%s,\x20%s',_0x1cdc16,_0x2606de[_0x1027('0x13')]['message']);return _0x44afdd(_0x2606de[_0x1027('0x13')][_0x1027('0x14')]);}logger[_0x1027('0x13')](_0x1027('0x15'),_0x1cdc16,_0x2606de[_0x1027('0x13')][_0x1027('0x14')]);return _0x47504c(_0x2606de[_0x1027('0x13')][_0x1027('0x14')]);}else{logger[_0x1027('0x10')](_0x1027('0x15'),_0x1cdc16,_0x1027('0x11'));_0x47504c(_0x2606de['result'][_0x1027('0x14')]);}})[_0x1027('0x16')](function(_0x45da6d){logger[_0x1027('0x13')](_0x1027('0x15'),_0x1cdc16,_0x45da6d);_0x44afdd(_0x45da6d);});});}exports[_0x1027('0x17')]=function(_0x150e01){var _0x404b39=this;return new Promise(function(_0x14fc39,_0x5cf269){return db[_0x1027('0x18')]['findAll']({'raw':_0x150e01['options']?_0x150e01[_0x1027('0x19')]['raw']===undefined?!![]:![]:!![],'where':_0x150e01[_0x1027('0x19')]?_0x150e01['options']['where']||null:null,'attributes':_0x150e01[_0x1027('0x19')]?_0x150e01[_0x1027('0x19')][_0x1027('0x1a')]||null:null,'limit':_0x150e01['options']?_0x150e01[_0x1027('0x19')][_0x1027('0x1b')]||null:null,'include':_0x150e01[_0x1027('0x19')]?_0x150e01[_0x1027('0x19')][_0x1027('0x1c')]?_[_0x1027('0x1d')](_0x150e01[_0x1027('0x19')][_0x1027('0x1c')],function(_0x14d810){return{'model':db[_0x14d810['model']],'as':_0x14d810['as'],'attributes':_0x14d810[_0x1027('0x1a')],'include':_0x14d810['include']?_[_0x1027('0x1d')](_0x14d810[_0x1027('0x1c')],function(_0x1dac76){return{'model':db[_0x1dac76[_0x1027('0x1e')]],'as':_0x1dac76['as'],'attributes':_0x1dac76[_0x1027('0x1a')],'include':_0x1dac76['include']?_[_0x1027('0x1d')](_0x1dac76[_0x1027('0x1c')],function(_0x197ed6){return{'model':db[_0x197ed6[_0x1027('0x1e')]],'as':_0x197ed6['as'],'attributes':_0x197ed6[_0x1027('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x1027('0xf')](function(_0x4c8a25){logger[_0x1027('0x10')](_0x1027('0x17'),_0x150e01);logger[_0x1027('0x1f')](_0x1027('0x17'),_0x150e01,JSON['stringify'](_0x4c8a25));_0x14fc39(_0x4c8a25);})['catch'](function(_0x1d356c){logger['error'](_0x1027('0x17'),_0x1d356c[_0x1027('0x14')],_0x150e01);_0x5cf269(_0x404b39[_0x1027('0x13')](0x1f4,_0x1d356c['message']));});});};exports['ShowMailAccount']=function(_0x2030c2){var _0xfc28f8=this;return new Promise(function(_0xcfe54e,_0x423f10){return db['MailAccount'][_0x1027('0x20')]({'raw':_0x2030c2[_0x1027('0x19')]?_0x2030c2[_0x1027('0x19')][_0x1027('0x21')]===undefined?!![]:![]:!![],'where':_0x2030c2[_0x1027('0x19')]?_0x2030c2[_0x1027('0x19')][_0x1027('0x22')]||null:null,'attributes':_0x2030c2[_0x1027('0x19')]?_0x2030c2['options'][_0x1027('0x1a')]||null:null,'include':_0x2030c2['options']?_0x2030c2[_0x1027('0x19')][_0x1027('0x1c')]?_[_0x1027('0x1d')](_0x2030c2[_0x1027('0x19')][_0x1027('0x1c')],function(_0xce4251){return{'model':db[_0xce4251[_0x1027('0x1e')]],'as':_0xce4251['as'],'attributes':_0xce4251[_0x1027('0x1a')],'include':_0xce4251[_0x1027('0x1c')]?_[_0x1027('0x1d')](_0xce4251['include'],function(_0x43a241){return{'model':db[_0x43a241[_0x1027('0x1e')]],'as':_0x43a241['as'],'attributes':_0x43a241[_0x1027('0x1a')],'include':_0x43a241[_0x1027('0x1c')]?_['map'](_0x43a241['include'],function(_0x1761bb){return{'model':db[_0x1761bb['model']],'as':_0x1761bb['as'],'attributes':_0x1761bb[_0x1027('0x1a')]};}):[]};}):[]};}):[]:[]})[_0x1027('0xf')](function(_0x52d2b0){logger[_0x1027('0x10')](_0x1027('0x23'),_0x2030c2);logger[_0x1027('0x1f')](_0x1027('0x23'),_0x2030c2,JSON[_0x1027('0x24')](_0x52d2b0));_0xcfe54e(_0x52d2b0);})['catch'](function(_0x4652a3){logger[_0x1027('0x13')](_0x1027('0x23'),_0x4652a3[_0x1027('0x14')],_0x2030c2);_0x423f10(_0xfc28f8[_0x1027('0x13')](0x1f4,_0x4652a3['message']));});});};exports[_0x1027('0x25')]=function(_0x310e05){var _0x28a54e=this;return new Promise(function(_0x8612fb,_0x1f20b0){var _0x1700df={'body':_0x310e05['body'],'channel':_0x1027('0x26')};var _0x5d2cd2=_[_0x1027('0x27')](_[_0x1027('0x28')](db[_0x1027('0x29')][_0x1027('0x2a')]),['createdAt',_0x1027('0x2b'),_0x1027('0x2c'),_0x1027('0x2d')]);var _0x2e0d24=![];if(_0x310e05[_0x1027('0x2e')]['id']){delete _0x310e05['body']['id'];}if(_['isNil'](_0x310e05['body'][_0x1027('0x2f')])){return _0x1f20b0(_0x28a54e[_0x1027('0x13')](0x1f4,_0x1027('0x30')));}if(_[_0x1027('0x31')](_0x310e05[_0x1027('0x2e')][_0x1027('0x2e')])||_0x310e05[_0x1027('0x2e')][_0x1027('0x2e')]===''){return _0x1f20b0(_0x28a54e[_0x1027('0x13')](0x1f4,'body\x20is\x20mandatory\x20and\x20not\x20empty'));}if(_[_0x1027('0x31')](_0x310e05[_0x1027('0x2e')][_0x1027('0x32')])){return _0x1f20b0(_0x28a54e['error'](0x1f4,'mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x5d2cd2));}if(!_[_0x1027('0x33')](_0x5d2cd2,_0x310e05[_0x1027('0x2e')][_0x1027('0x32')])){return _0x1f20b0(_0x28a54e[_0x1027('0x13')](0x1f4,_0x1027('0x34')+_0x5d2cd2));}var _0x230808={};_0x230808[_0x310e05[_0x1027('0x2e')][_0x1027('0x32')]]=_0x310e05[_0x1027('0x2e')][_0x1027('0x2f')];return db[_0x1027('0x18')]['find']({'where':{'id':_0x310e05[_0x1027('0x35')]['id']},'include':[{'model':db[_0x1027('0x36')],'as':'List','include':[{'model':db['CmContact'],'as':_0x1027('0x37'),'where':_0x230808,'limit':0x1,'order':[[_0x1027('0x2b'),'DESC']]}]},{'model':db[_0x1027('0x38')],'as':'Applications'},{'model':db['MailServerOut'],'as':'Smtp'}]})['then'](function(_0x204774){if(_0x204774&&_0x204774[_0x1027('0x39')]){var _0x2af2a1=_0x204774[_0x1027('0x3a')]({'plain':!![]});_0x1700df[_0x1027('0x35')]=_[_0x1027('0x3b')](_0x2af2a1,[_0x1027('0x3c'),_0x1027('0x39')]);_0x1700df[_0x1027('0x3d')]=_0x2af2a1[_0x1027('0x3c')];_0x1700df[_0x1027('0x3e')]=_0x2af2a1['List'];_0x1700df['applications']=_[_0x1027('0x3f')](_0x1700df[_0x1027('0x3d')],[_0x1027('0x40')],[_0x1027('0x41')]);if(_0x1700df[_0x1027('0x35')]&&_0x1700df['account'][_0x1027('0x42')]){_0x1700df[_0x1027('0x3d')]['push']({'id':0x0,'priority':_0x1700df[_0x1027('0x3d')]['length']+0x1,'app':_0x1027('0x43'),'appdata':_0x1027('0x42'),'interval':'*,*,*,*'});}if(_0x1700df[_0x1027('0x35')]['Applications']){delete _0x1700df[_0x1027('0x35')][_0x1027('0x3c')];}if(_0x1700df['account']['List']){delete _0x1700df[_0x1027('0x35')][_0x1027('0x39')];}if(_0x2af2a1[_0x1027('0x39')][_0x1027('0x37')][_0x1027('0x44')]){return _0x2af2a1[_0x1027('0x39')][_0x1027('0x37')][0x0];}var _0x17e6a9=_[_0x1027('0x45')](_0x310e05[_0x1027('0x2e')],{'firstName':_0x310e05[_0x1027('0x2e')]['from'],'ListId':_0x2af2a1[_0x1027('0x2d')]});_0x17e6a9[_0x310e05[_0x1027('0x2e')][_0x1027('0x32')]]=_0x310e05[_0x1027('0x2e')][_0x1027('0x2f')];return db[_0x1027('0x29')][_0x1027('0x46')](_0x17e6a9);}else{throw new Error(_0x1027('0x47'));}})['then'](function(_0x4288ef){_0x1700df[_0x1027('0x48')]=_0x4288ef;if(_0x4288ef){if(!_0x310e05['body'][_0x1027('0x14')][_0x1027('0x49')]){_0x310e05[_0x1027('0x2e')]['message'][_0x1027('0x49')]=rs[_0x1027('0x4a')]()+'\x20'+_0x310e05[_0x1027('0x2e')]['message'][_0x1027('0x2f')];}var _0x52e996={'ContactId':_0x4288ef['id'],'MailAccountId':_0x310e05['account']['id'],'inReplyTo':_0x310e05['body'][_0x1027('0x14')]['messageId'],'to':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')][_0x1027('0x2f')],'cc':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')]['cc'],'subject':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')]['subject'],'attach':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')][_0x1027('0x4b')],'lastMsgAt':moment()[_0x1027('0x4c')](_0x1027('0x4d')),'lastMsgDirection':'in'};return db['MailInteraction']['find']({'where':{'closed':![],'MailAccountId':_0x310e05['account']['id']},'include':[{'model':db[_0x1027('0x4e')],'as':'Messages','attributes':[_0x1027('0x49')],'where':{'messageId':_0x310e05['body']['message'][_0x1027('0x4f')]}}]})[_0x1027('0xf')](function(_0x15deb0){if(_0x15deb0){return[_0x15deb0,![]];}return db[_0x1027('0x50')][_0x1027('0x46')](_0x52e996)[_0x1027('0xf')](function(_0x5a2dd0){return[_0x5a2dd0,!![]];});});}else{throw new Error('Contact\x20not\x20found');}})[_0x1027('0x51')](function(_0x3ee39d,_0x3a04d1){if(_0x3ee39d){_0x2e0d24=_0x3a04d1;if(!_0x3a04d1){return _0x3ee39d[_0x1027('0x52')]({'inReplyTo':_0x310e05['body'][_0x1027('0x14')][_0x1027('0x49')],'to':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')][_0x1027('0x2f')],'cc':_0x310e05[_0x1027('0x2e')]['message']['cc'],'subject':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')]['subject'],'attach':_0x3ee39d[_0x1027('0x4b')]?_0x3ee39d[_0x1027('0x4b')]:_0x310e05['body'][_0x1027('0x14')]['attach'],'substatus':null,'substatusAt':moment()[_0x1027('0x4c')](_0x1027('0x4d')),'lastMsgAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'lastMsgDirection':'in'});}else{return _0x3ee39d;}}})[_0x1027('0xf')](function(_0x1e7e92){_0x1700df['interaction']=_0x1e7e92['get']({'plain':!![]});_0x1700df[_0x1027('0x53')]['created']=_0x2e0d24;return db[_0x1027('0x4e')][_0x1027('0x46')]({'body':_0x310e05['body'][_0x1027('0x2e')],'MailAccountId':_0x310e05[_0x1027('0x35')]['id'],'MailInteractionId':_0x1e7e92['id'],'direction':'in','ContactId':_0x1700df[_0x1027('0x48')]['id'],'messageId':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')]['messageId'],'from':_0x310e05['body'][_0x1027('0x14')][_0x1027('0x2f')],'to':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')]['to'],'cc':_0x310e05['body']['message']['cc'],'subject':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')]['subject'],'attach':_0x310e05['body'][_0x1027('0x14')][_0x1027('0x4b')],'Attachments':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')][_0x1027('0x54')],'originTo':_0x310e05[_0x1027('0x2e')]['message'][_0x1027('0x55')],'originCc':_0x310e05[_0x1027('0x2e')]['message'][_0x1027('0x56')],'bcc':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')][_0x1027('0x57')],'ChatWebsiteId':_0x310e05['body'][_0x1027('0x14')][_0x1027('0x58')]||null,'originChannel':_0x310e05[_0x1027('0x2e')][_0x1027('0x14')][_0x1027('0x59')]||_0x1027('0x5a'),'ChatOfflineMessageId':_0x310e05['body'][_0x1027('0x14')][_0x1027('0x5b')]||null},{'include':[{'model':db[_0x1027('0x5c')],'as':_0x1027('0x5d')}]});})[_0x1027('0xf')](function(_0x49945d){_0x1700df[_0x1027('0x14')]=_0x49945d;if(_0x1700df[_0x1027('0x53')][_0x1027('0x5e')]){return db[_0x1027('0x5f')][_0x1027('0x20')]({'attributes':['id',_0x1027('0x60')],'where':{'id':_0x1700df['interaction'][_0x1027('0x5e')]}})[_0x1027('0xf')](function(_0x1692c5){if(_0x1692c5){_0x1700df[_0x1027('0x3d')][_0x1027('0x61')]({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x1692c5['name']+','+(_0x1700df[_0x1027('0x35')][_0x1027('0x62')]||0xa),'interval':_0x1027('0x63')});}return respondWithRpcPromise(_0x1027('0x64'),_0x1027('0x65'),_0x1700df);});}return respondWithRpcPromise(_0x1027('0x64'),_0x1027('0x65'),_0x1700df);})[_0x1027('0xf')](function(_0xa033bd){_0x8612fb(_0xa033bd);})['catch'](function(_0x3dbdde){_0x1f20b0(_0x28a54e['error'](0x1f4,_0x3dbdde[_0x1027('0x14')]));});});};
\ No newline at end of file
+var _0x0295=['setDataValue','smtpOptions','getSmtpOptions','stringify','NotifyMailAccount','body','keys','CmContact','rawAttributes','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','account','CmList','List','Contacts','DESC','MailApplication','Applications','MailServerOut','Smtp','CloudProvider','get','omit','applications','priority','asc','autoclose','close','*,*,*,*','length','contact','messageId','generate','subject','attach','format','YYYY-MM-DD\x20HH:mm:ss','MailMessage','Messages','inReplyTo','MailInteraction','Contact\x20not\x20found','spread','update','created','create','attachments','originTo','originCc','bcc','originChannel','Email','ChatOfflineMessageId','Attachment','Attachments','interaction','UserId','User','name','agent','Start','startRouting','lodash','randomstring','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','redis','defaults','./mailAccount.socket','request','then','info','MailAccount,\x20%s,\x20%s','request\x20sent','MailAccount,\x20%s,\x20%s,\x20%s','error','message','catch','GetMailAccount','MailAccount','findAll','options','attributes','limit','include','model','map','debug','ShowMailAccount','find','where','smtp'];(function(_0x2dea58,_0x59d6f0){var _0x2b23c2=function(_0x3e5c44){while(--_0x3e5c44){_0x2dea58['push'](_0x2dea58['shift']());}};_0x2b23c2(++_0x59d6f0);}(_0x0295,0x1f0));var _0x5029=function(_0xc691d8,_0x69a50a){_0xc691d8=_0xc691d8-0x0;var _0x307e60=_0x0295[_0xc691d8];return _0x307e60;};'use strict';var _=require(_0x5029('0x0'));var moment=require('moment');var BPromise=require('bluebird');var rs=require(_0x5029('0x1'));var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var logger=require(_0x5029('0x2'))(_0x5029('0x3'));var config=require(_0x5029('0x4'));var jayson=require(_0x5029('0x5'));var client=jayson[_0x5029('0x6')][_0x5029('0x7')]({'port':0x232c});config[_0x5029('0x8')]=_[_0x5029('0x9')](config[_0x5029('0x8')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require(_0x5029('0xa'))['register'](socket);function respondWithRpcPromise(_0x1532e9,_0x5bccfc,_0x14d4ef){return new BPromise(function(_0x520bc3,_0x222ddb){return client[_0x5029('0xb')](_0x1532e9,_0x14d4ef)[_0x5029('0xc')](function(_0x52fa95){logger[_0x5029('0xd')](_0x5029('0xe'),_0x5bccfc,_0x5029('0xf'));logger['debug'](_0x5029('0x10'),_0x5bccfc,_0x5029('0xf'),JSON['stringify'](_0x52fa95));if(_0x52fa95['error']){if(_0x52fa95['error']['code']===0x1f4){logger[_0x5029('0x11')](_0x5029('0xe'),_0x5bccfc,_0x52fa95[_0x5029('0x11')][_0x5029('0x12')]);return _0x222ddb(_0x52fa95[_0x5029('0x11')][_0x5029('0x12')]);}logger[_0x5029('0x11')](_0x5029('0xe'),_0x5bccfc,_0x52fa95[_0x5029('0x11')][_0x5029('0x12')]);return _0x520bc3(_0x52fa95[_0x5029('0x11')][_0x5029('0x12')]);}else{logger[_0x5029('0xd')](_0x5029('0xe'),_0x5bccfc,_0x5029('0xf'));_0x520bc3(_0x52fa95['result'][_0x5029('0x12')]);}})[_0x5029('0x13')](function(_0x35de81){logger[_0x5029('0x11')](_0x5029('0xe'),_0x5bccfc,_0x35de81);_0x222ddb(_0x35de81);});});}exports[_0x5029('0x14')]=function(_0xaba461){var _0x4adbb3=this;return new Promise(function(_0x226a5c,_0x5696b1){return db[_0x5029('0x15')][_0x5029('0x16')]({'raw':_0xaba461[_0x5029('0x17')]?_0xaba461[_0x5029('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0xaba461['options']?_0xaba461[_0x5029('0x17')]['where']||null:null,'attributes':_0xaba461[_0x5029('0x17')]?_0xaba461[_0x5029('0x17')][_0x5029('0x18')]||null:null,'limit':_0xaba461[_0x5029('0x17')]?_0xaba461[_0x5029('0x17')][_0x5029('0x19')]||null:null,'include':_0xaba461[_0x5029('0x17')]?_0xaba461[_0x5029('0x17')][_0x5029('0x1a')]?_['map'](_0xaba461['options']['include'],function(_0x588d90){return{'model':db[_0x588d90[_0x5029('0x1b')]],'as':_0x588d90['as'],'attributes':_0x588d90['attributes'],'include':_0x588d90['include']?_[_0x5029('0x1c')](_0x588d90[_0x5029('0x1a')],function(_0x36d810){return{'model':db[_0x36d810['model']],'as':_0x36d810['as'],'attributes':_0x36d810[_0x5029('0x18')],'include':_0x36d810[_0x5029('0x1a')]?_['map'](_0x36d810[_0x5029('0x1a')],function(_0x31f0a0){return{'model':db[_0x31f0a0[_0x5029('0x1b')]],'as':_0x31f0a0['as'],'attributes':_0x31f0a0['attributes']};}):[]};}):[]};}):[]:[]})[_0x5029('0xc')](function(_0x251f99){logger[_0x5029('0xd')]('GetMailAccount',_0xaba461);logger[_0x5029('0x1d')](_0x5029('0x14'),_0xaba461,JSON['stringify'](_0x251f99));_0x226a5c(_0x251f99);})[_0x5029('0x13')](function(_0x25032b){logger[_0x5029('0x11')](_0x5029('0x14'),_0x25032b[_0x5029('0x12')],_0xaba461);_0x5696b1(_0x4adbb3[_0x5029('0x11')](0x1f4,_0x25032b[_0x5029('0x12')]));});});};exports[_0x5029('0x1e')]=function(_0x250156){var _0x22559a=this;return new Promise(function(_0x358a2b,_0x4519c8){return db['MailAccount'][_0x5029('0x1f')]({'raw':_0x250156['options']?_0x250156[_0x5029('0x17')]['raw']===undefined?!![]:![]:!![],'where':_0x250156['options']?_0x250156[_0x5029('0x17')][_0x5029('0x20')]||null:null,'attributes':_0x250156[_0x5029('0x17')]?_0x250156['options'][_0x5029('0x18')]||null:null,'include':_0x250156[_0x5029('0x17')]?_0x250156[_0x5029('0x17')][_0x5029('0x1a')]?_[_0x5029('0x1c')](_0x250156[_0x5029('0x17')][_0x5029('0x1a')],function(_0x22205e){return{'model':db[_0x22205e[_0x5029('0x1b')]],'as':_0x22205e['as'],'attributes':_0x22205e['attributes'],'include':_0x22205e[_0x5029('0x1a')]?_[_0x5029('0x1c')](_0x22205e[_0x5029('0x1a')],function(_0x1b3817){return{'model':db[_0x1b3817['model']],'as':_0x1b3817['as'],'attributes':_0x1b3817[_0x5029('0x18')],'include':_0x1b3817[_0x5029('0x1a')]?_[_0x5029('0x1c')](_0x1b3817['include'],function(_0x4904cc){return{'model':db[_0x4904cc[_0x5029('0x1b')]],'as':_0x4904cc['as'],'attributes':_0x4904cc[_0x5029('0x18')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x57784c){if(_0x250156[_0x5029('0x17')][_0x5029('0x21')]===!![])_0x57784c[_0x5029('0x22')](_0x5029('0x23'),_0x57784c[_0x5029('0x24')]());logger[_0x5029('0xd')](_0x5029('0x1e'),_0x250156);logger[_0x5029('0x1d')](_0x5029('0x1e'),_0x250156,JSON[_0x5029('0x25')](_0x57784c));_0x358a2b(_0x57784c);})[_0x5029('0x13')](function(_0xbdb3fa){logger[_0x5029('0x11')](_0x5029('0x1e'),_0xbdb3fa['message'],_0x250156);_0x4519c8(_0x22559a['error'](0x1f4,_0xbdb3fa[_0x5029('0x12')]));});});};exports[_0x5029('0x26')]=function(_0x423ed1){var _0x48c9eb=this;return new Promise(function(_0x32d8a3,_0x39b216){var _0x52572a={'body':_0x423ed1[_0x5029('0x27')],'channel':'mail'};var _0x506f0d=_['difference'](_[_0x5029('0x28')](db[_0x5029('0x29')][_0x5029('0x2a')]),[_0x5029('0x2b'),_0x5029('0x2c'),_0x5029('0x2d'),_0x5029('0x2e')]);var _0x1021ea=![];if(_0x423ed1[_0x5029('0x27')]['id']){delete _0x423ed1['body']['id'];}if(_[_0x5029('0x2f')](_0x423ed1[_0x5029('0x27')][_0x5029('0x30')])){return _0x39b216(_0x48c9eb[_0x5029('0x11')](0x1f4,_0x5029('0x31')));}if(_[_0x5029('0x2f')](_0x423ed1['body'][_0x5029('0x27')])||_0x423ed1[_0x5029('0x27')][_0x5029('0x27')]===''){return _0x39b216(_0x48c9eb[_0x5029('0x11')](0x1f4,_0x5029('0x32')));}if(_['isNil'](_0x423ed1[_0x5029('0x27')][_0x5029('0x33')])){return _0x39b216(_0x48c9eb[_0x5029('0x11')](0x1f4,_0x5029('0x34')+_0x506f0d));}if(!_[_0x5029('0x35')](_0x506f0d,_0x423ed1[_0x5029('0x27')][_0x5029('0x33')])){return _0x39b216(_0x48c9eb[_0x5029('0x11')](0x1f4,_0x5029('0x36')+_0x506f0d));}var _0x51514e={};_0x51514e[_0x423ed1[_0x5029('0x27')][_0x5029('0x33')]]=_0x423ed1[_0x5029('0x27')][_0x5029('0x30')];return db['MailAccount']['find']({'where':{'id':_0x423ed1[_0x5029('0x37')]['id']},'include':[{'model':db[_0x5029('0x38')],'as':_0x5029('0x39'),'include':[{'model':db[_0x5029('0x29')],'as':_0x5029('0x3a'),'where':_0x51514e,'limit':0x1,'order':[[_0x5029('0x2c'),_0x5029('0x3b')]]}]},{'model':db[_0x5029('0x3c')],'as':_0x5029('0x3d')},{'model':db[_0x5029('0x3e')],'as':_0x5029('0x3f'),'include':[{'model':db[_0x5029('0x40')],'as':_0x5029('0x40')}]}]})[_0x5029('0xc')](function(_0x3168bd){if(_0x3168bd&&_0x3168bd[_0x5029('0x39')]){var _0x10fc07=_0x3168bd[_0x5029('0x41')]({'plain':!![]});_0x52572a[_0x5029('0x37')]=_[_0x5029('0x42')](_0x10fc07,[_0x5029('0x3d'),'List']);_0x52572a[_0x5029('0x37')]['smtpOptions']=_0x3168bd[_0x5029('0x24')]();_0x52572a[_0x5029('0x43')]=_0x10fc07['Applications'];_0x52572a['list']=_0x10fc07[_0x5029('0x39')];_0x52572a['applications']=_['orderBy'](_0x52572a[_0x5029('0x43')],[_0x5029('0x44')],[_0x5029('0x45')]);if(_0x52572a['account']&&_0x52572a['account'][_0x5029('0x46')]){_0x52572a[_0x5029('0x43')]['push']({'id':0x0,'priority':_0x52572a[_0x5029('0x43')]['length']+0x1,'app':_0x5029('0x47'),'appdata':'autoclose','interval':_0x5029('0x48')});}if(_0x52572a[_0x5029('0x37')][_0x5029('0x3d')]){delete _0x52572a[_0x5029('0x37')][_0x5029('0x3d')];}if(_0x52572a[_0x5029('0x37')][_0x5029('0x39')]){delete _0x52572a[_0x5029('0x37')]['List'];}if(_0x10fc07[_0x5029('0x39')]['Contacts'][_0x5029('0x49')]){return _0x10fc07[_0x5029('0x39')]['Contacts'][0x0];}var _0x2a2da5=_['defaults'](_0x423ed1['body'],{'firstName':_0x423ed1['body'][_0x5029('0x30')],'ListId':_0x10fc07['ListId']});_0x2a2da5[_0x423ed1[_0x5029('0x27')][_0x5029('0x33')]]=_0x423ed1[_0x5029('0x27')]['from'];return db[_0x5029('0x29')]['create'](_0x2a2da5);}else{throw new Error('List\x20not\x20found');}})[_0x5029('0xc')](function(_0x98abd1){_0x52572a[_0x5029('0x4a')]=_0x98abd1;if(_0x98abd1){if(!_0x423ed1[_0x5029('0x27')][_0x5029('0x12')]['messageId']){_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x4b')]=rs[_0x5029('0x4c')]()+'\x20'+_0x423ed1['body'][_0x5029('0x12')][_0x5029('0x30')];}var _0x4d4a2d={'ContactId':_0x98abd1['id'],'MailAccountId':_0x423ed1['account']['id'],'inReplyTo':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x4b')],'to':_0x423ed1[_0x5029('0x27')]['message'][_0x5029('0x30')],'cc':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')]['cc'],'subject':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x4d')],'attach':_0x423ed1['body']['message'][_0x5029('0x4e')],'lastMsgAt':moment()[_0x5029('0x4f')](_0x5029('0x50')),'lastMsgDirection':'in'};return db['MailInteraction'][_0x5029('0x1f')]({'where':{'closed':![],'MailAccountId':_0x423ed1[_0x5029('0x37')]['id']},'include':[{'model':db[_0x5029('0x51')],'as':_0x5029('0x52'),'attributes':[_0x5029('0x4b')],'where':{'messageId':_0x423ed1['body'][_0x5029('0x12')][_0x5029('0x53')]}}]})[_0x5029('0xc')](function(_0x5bf867){if(_0x5bf867){return[_0x5bf867,![]];}return db[_0x5029('0x54')]['create'](_0x4d4a2d)[_0x5029('0xc')](function(_0x4f2f0c){return[_0x4f2f0c,!![]];});});}else{throw new Error(_0x5029('0x55'));}})[_0x5029('0x56')](function(_0x2ad2e3,_0x2f5301){if(_0x2ad2e3){_0x1021ea=_0x2f5301;if(!_0x2f5301){return _0x2ad2e3[_0x5029('0x57')]({'inReplyTo':_0x423ed1[_0x5029('0x27')]['message'][_0x5029('0x4b')],'to':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x30')],'cc':_0x423ed1[_0x5029('0x27')]['message']['cc'],'subject':_0x423ed1[_0x5029('0x27')]['message'][_0x5029('0x4d')],'attach':_0x2ad2e3['attach']?_0x2ad2e3[_0x5029('0x4e')]:_0x423ed1['body'][_0x5029('0x12')]['attach'],'substatus':null,'substatusAt':moment()['format'](_0x5029('0x50')),'lastMsgAt':moment()['format'](_0x5029('0x50')),'lastMsgDirection':'in'});}else{return _0x2ad2e3;}}})[_0x5029('0xc')](function(_0x382994){_0x52572a['interaction']=_0x382994[_0x5029('0x41')]({'plain':!![]});_0x52572a['interaction'][_0x5029('0x58')]=_0x1021ea;return db[_0x5029('0x51')][_0x5029('0x59')]({'body':_0x423ed1[_0x5029('0x27')][_0x5029('0x27')],'MailAccountId':_0x423ed1['account']['id'],'MailInteractionId':_0x382994['id'],'direction':'in','ContactId':_0x52572a[_0x5029('0x4a')]['id'],'messageId':_0x423ed1[_0x5029('0x27')]['message'][_0x5029('0x4b')],'from':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x30')],'to':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')]['to'],'cc':_0x423ed1['body']['message']['cc'],'subject':_0x423ed1[_0x5029('0x27')]['message'][_0x5029('0x4d')],'attach':_0x423ed1[_0x5029('0x27')]['message'][_0x5029('0x4e')],'Attachments':_0x423ed1['body']['message'][_0x5029('0x5a')],'originTo':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x5b')],'originCc':_0x423ed1['body'][_0x5029('0x12')][_0x5029('0x5c')],'bcc':_0x423ed1['body'][_0x5029('0x12')][_0x5029('0x5d')],'ChatWebsiteId':_0x423ed1['body']['message']['ChatWebsiteId']||null,'originChannel':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x5e')]||_0x5029('0x5f'),'ChatOfflineMessageId':_0x423ed1[_0x5029('0x27')][_0x5029('0x12')][_0x5029('0x60')]||null},{'include':[{'model':db[_0x5029('0x61')],'as':_0x5029('0x62')}]});})['then'](function(_0x4bf5cf){_0x52572a[_0x5029('0x12')]=_0x4bf5cf;if(_0x52572a[_0x5029('0x63')][_0x5029('0x64')]){return db[_0x5029('0x65')][_0x5029('0x1f')]({'attributes':['id',_0x5029('0x66')],'where':{'id':_0x52572a[_0x5029('0x63')]['UserId']}})[_0x5029('0xc')](function(_0x3a0d6f){if(_0x3a0d6f){_0x52572a[_0x5029('0x43')]['unshift']({'id':0x0,'priority':0x0,'app':_0x5029('0x67'),'appdata':_0x3a0d6f[_0x5029('0x66')]+','+(_0x52572a[_0x5029('0x37')]['waitForTheAssignedAgent']||0xa),'interval':_0x5029('0x48')});}return respondWithRpcPromise(_0x5029('0x68'),_0x5029('0x69'),_0x52572a);});}return respondWithRpcPromise('Start',_0x5029('0x69'),_0x52572a);})[_0x5029('0xc')](function(_0x5a35bc){_0x32d8a3(_0x5a35bc);})[_0x5029('0x13')](function(_0x42d795){_0x39b216(_0x48c9eb[_0x5029('0x11')](0x1f4,_0x42d795[_0x5029('0x12')]));});});};
\ No newline at end of file