Built motion from commit (unavailable).|2.6.0
[motion2.git] / server / api / mailAccount / mailAccount.rpc.js
index 0bf7488..3188a37 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc1d0=['lodash','util','moment','randomstring','../../config/utils','../../config/logger','../../config/environment','client','http','redis','localhost','socket.io-emitter','./mailAccount.socket','register','then','info','MailAccount,\x20%s,\x20%s','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','GetMailAccount','MailAccount','findAll','options','raw','attributes','limit','include','map','model','ShowMailAccount','find','where','NotifyMailAccount','body','mail','difference','keys','CmContact','createdAt','updatedAt','CompanyId','ListId','isNil','from','from\x20is\x20mandatory','body\x20is\x20mandatory\x20and\x20not\x20empty','mapKey','includes','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','account','CmList','List','DESC','MailApplication','Applications','Smtp','get','omit','applications','list','orderBy','priority','asc','autoclose','push','length','Contacts','defaults','create','List\x20not\x20found','contact','messageId','generate','subject','attach','format','YYYY-MM-DD\x20HH:mm:ss','MailInteraction','MailMessage','Contact\x20not\x20found','spread','interaction','created','originTo','originCc','ChatWebsiteId','originChannel','Email','ChatOfflineMessageId','Attachment','UserId','User','name','agent','waitForTheAssignedAgent','*,*,*,*','Start','startRouting'];(function(_0x1013e3,_0xccc357){var _0x1b948c=function(_0x516477){while(--_0x516477){_0x1013e3['push'](_0x1013e3['shift']());}};_0x1b948c(++_0xccc357);}(_0xc1d0,0x1a0));var _0x0c1d=function(_0x3c6835,_0x952d5c){_0x3c6835=_0x3c6835-0x0;var _0x1adeb9=_0xc1d0[_0x3c6835];return _0x1adeb9;};'use strict';var _=require(_0x0c1d('0x0'));var util=require(_0x0c1d('0x1'));var moment=require(_0x0c1d('0x2'));var BPromise=require('bluebird');var rs=require(_0x0c1d('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require('../../mysqldb')['db'];var utils=require(_0x0c1d('0x4'));var logger=require(_0x0c1d('0x5'))('rpc');var config=require(_0x0c1d('0x6'));var jayson=require('jayson/promise');var client=jayson[_0x0c1d('0x7')][_0x0c1d('0x8')]({'port':0x232c});config[_0x0c1d('0x9')]=_['defaults'](config['redis'],{'host':_0x0c1d('0xa'),'port':0x18eb});var socket=require(_0x0c1d('0xb'))(new Redis(config[_0x0c1d('0x9')]));require(_0x0c1d('0xc'))[_0x0c1d('0xd')](socket);function respondWithRpcPromise(_0x5806e7,_0x59feca,_0x53c408){return new BPromise(function(_0x12b9fc,_0x26ecee){return client['request'](_0x5806e7,_0x53c408)[_0x0c1d('0xe')](function(_0xb40b9a){logger[_0x0c1d('0xf')](_0x0c1d('0x10'),_0x59feca,_0x0c1d('0x11'));logger[_0x0c1d('0x12')](_0x0c1d('0x13'),_0x59feca,_0x0c1d('0x11'),JSON[_0x0c1d('0x14')](_0xb40b9a));if(_0xb40b9a[_0x0c1d('0x15')]){if(_0xb40b9a[_0x0c1d('0x15')][_0x0c1d('0x16')]===0x1f4){logger[_0x0c1d('0x15')]('MailAccount,\x20%s,\x20%s',_0x59feca,_0xb40b9a['error'][_0x0c1d('0x17')]);return _0x26ecee(_0xb40b9a[_0x0c1d('0x15')][_0x0c1d('0x17')]);}logger[_0x0c1d('0x15')](_0x0c1d('0x10'),_0x59feca,_0xb40b9a[_0x0c1d('0x15')][_0x0c1d('0x17')]);return _0x12b9fc(_0xb40b9a[_0x0c1d('0x15')][_0x0c1d('0x17')]);}else{logger[_0x0c1d('0xf')]('MailAccount,\x20%s,\x20%s',_0x59feca,_0x0c1d('0x11'));_0x12b9fc(_0xb40b9a['result'][_0x0c1d('0x17')]);}})[_0x0c1d('0x18')](function(_0x329782){logger[_0x0c1d('0x15')](_0x0c1d('0x10'),_0x59feca,_0x329782);_0x26ecee(_0x329782);});});}exports[_0x0c1d('0x19')]=function(_0x40eff8){var _0x333c9e=this;return new Promise(function(_0x208cb2,_0xbf01ca){return db[_0x0c1d('0x1a')][_0x0c1d('0x1b')]({'raw':_0x40eff8[_0x0c1d('0x1c')]?_0x40eff8[_0x0c1d('0x1c')][_0x0c1d('0x1d')]===undefined?!![]:![]:!![],'where':_0x40eff8['options']?_0x40eff8[_0x0c1d('0x1c')]['where']||null:null,'attributes':_0x40eff8[_0x0c1d('0x1c')]?_0x40eff8[_0x0c1d('0x1c')][_0x0c1d('0x1e')]||null:null,'limit':_0x40eff8[_0x0c1d('0x1c')]?_0x40eff8[_0x0c1d('0x1c')][_0x0c1d('0x1f')]||null:null,'include':_0x40eff8['options']?_0x40eff8[_0x0c1d('0x1c')][_0x0c1d('0x20')]?_[_0x0c1d('0x21')](_0x40eff8[_0x0c1d('0x1c')][_0x0c1d('0x20')],function(_0x42119d){return{'model':db[_0x42119d[_0x0c1d('0x22')]],'as':_0x42119d['as'],'attributes':_0x42119d['attributes'],'include':_0x42119d[_0x0c1d('0x20')]?_[_0x0c1d('0x21')](_0x42119d[_0x0c1d('0x20')],function(_0x5200a3){return{'model':db[_0x5200a3[_0x0c1d('0x22')]],'as':_0x5200a3['as'],'attributes':_0x5200a3[_0x0c1d('0x1e')],'include':_0x5200a3[_0x0c1d('0x20')]?_[_0x0c1d('0x21')](_0x5200a3[_0x0c1d('0x20')],function(_0x3e8454){return{'model':db[_0x3e8454[_0x0c1d('0x22')]],'as':_0x3e8454['as'],'attributes':_0x3e8454[_0x0c1d('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x0c1d('0xe')](function(_0x505836){logger[_0x0c1d('0xf')]('GetMailAccount',_0x40eff8);logger[_0x0c1d('0x12')]('GetMailAccount',_0x40eff8,JSON[_0x0c1d('0x14')](_0x505836));_0x208cb2(_0x505836);})['catch'](function(_0x58d141){logger[_0x0c1d('0x15')](_0x0c1d('0x19'),_0x58d141[_0x0c1d('0x17')],_0x40eff8);_0xbf01ca(_0x333c9e[_0x0c1d('0x15')](0x1f4,_0x58d141[_0x0c1d('0x17')]));});});};exports[_0x0c1d('0x23')]=function(_0x466632){var _0x341b45=this;return new Promise(function(_0x5bdae4,_0x59eb28){return db[_0x0c1d('0x1a')][_0x0c1d('0x24')]({'raw':_0x466632[_0x0c1d('0x1c')]?_0x466632[_0x0c1d('0x1c')][_0x0c1d('0x1d')]===undefined?!![]:![]:!![],'where':_0x466632[_0x0c1d('0x1c')]?_0x466632[_0x0c1d('0x1c')][_0x0c1d('0x25')]||null:null,'attributes':_0x466632[_0x0c1d('0x1c')]?_0x466632[_0x0c1d('0x1c')][_0x0c1d('0x1e')]||null:null,'include':_0x466632[_0x0c1d('0x1c')]?_0x466632[_0x0c1d('0x1c')][_0x0c1d('0x20')]?_[_0x0c1d('0x21')](_0x466632[_0x0c1d('0x1c')][_0x0c1d('0x20')],function(_0x24ed30){return{'model':db[_0x24ed30[_0x0c1d('0x22')]],'as':_0x24ed30['as'],'attributes':_0x24ed30[_0x0c1d('0x1e')],'include':_0x24ed30[_0x0c1d('0x20')]?_[_0x0c1d('0x21')](_0x24ed30[_0x0c1d('0x20')],function(_0x388a80){return{'model':db[_0x388a80['model']],'as':_0x388a80['as'],'attributes':_0x388a80['attributes'],'include':_0x388a80[_0x0c1d('0x20')]?_['map'](_0x388a80[_0x0c1d('0x20')],function(_0x4e7518){return{'model':db[_0x4e7518[_0x0c1d('0x22')]],'as':_0x4e7518['as'],'attributes':_0x4e7518[_0x0c1d('0x1e')]};}):[]};}):[]};}):[]:[]})[_0x0c1d('0xe')](function(_0x9098a4){logger[_0x0c1d('0xf')](_0x0c1d('0x23'),_0x466632);logger[_0x0c1d('0x12')](_0x0c1d('0x23'),_0x466632,JSON[_0x0c1d('0x14')](_0x9098a4));_0x5bdae4(_0x9098a4);})[_0x0c1d('0x18')](function(_0x2391d8){logger[_0x0c1d('0x15')]('ShowMailAccount',_0x2391d8['message'],_0x466632);_0x59eb28(_0x341b45['error'](0x1f4,_0x2391d8[_0x0c1d('0x17')]));});});};exports[_0x0c1d('0x26')]=function(_0x275e97){var _0x367c70=this;return new Promise(function(_0x16c052,_0x3c8624){var _0x48d37e={'body':_0x275e97[_0x0c1d('0x27')],'channel':_0x0c1d('0x28')};var _0x205d4a=_[_0x0c1d('0x29')](_[_0x0c1d('0x2a')](db[_0x0c1d('0x2b')]['rawAttributes']),[_0x0c1d('0x2c'),_0x0c1d('0x2d'),_0x0c1d('0x2e'),_0x0c1d('0x2f')]);var _0x12653f=![];if(_0x275e97[_0x0c1d('0x27')]['id']){delete _0x275e97[_0x0c1d('0x27')]['id'];}if(_[_0x0c1d('0x30')](_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x31')])){return _0x3c8624(_0x367c70['error'](0x1f4,_0x0c1d('0x32')));}if(_[_0x0c1d('0x30')](_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x27')])||_0x275e97[_0x0c1d('0x27')]['body']===''){return _0x3c8624(_0x367c70[_0x0c1d('0x15')](0x1f4,_0x0c1d('0x33')));}if(_[_0x0c1d('0x30')](_0x275e97['body'][_0x0c1d('0x34')])){return _0x3c8624(_0x367c70[_0x0c1d('0x15')](0x1f4,'mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x205d4a));}if(!_[_0x0c1d('0x35')](_0x205d4a,_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x34')])){return _0x3c8624(_0x367c70[_0x0c1d('0x15')](0x1f4,_0x0c1d('0x36')+_0x205d4a));}var _0x53de63={};_0x53de63[_0x275e97['body']['mapKey']]=_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x31')];return db['MailAccount'][_0x0c1d('0x24')]({'where':{'id':_0x275e97[_0x0c1d('0x37')]['id']},'include':[{'model':db[_0x0c1d('0x38')],'as':_0x0c1d('0x39'),'include':[{'model':db[_0x0c1d('0x2b')],'as':'Contacts','where':_0x53de63,'limit':0x1,'order':[[_0x0c1d('0x2d'),_0x0c1d('0x3a')]]}]},{'model':db[_0x0c1d('0x3b')],'as':_0x0c1d('0x3c')},{'model':db['MailServerOut'],'as':_0x0c1d('0x3d')}]})[_0x0c1d('0xe')](function(_0x223b4c){if(_0x223b4c&&_0x223b4c[_0x0c1d('0x39')]){var _0x59180c=_0x223b4c[_0x0c1d('0x3e')]({'plain':!![]});_0x48d37e[_0x0c1d('0x37')]=_[_0x0c1d('0x3f')](_0x59180c,['Applications','List']);_0x48d37e[_0x0c1d('0x40')]=_0x59180c['Applications'];_0x48d37e[_0x0c1d('0x41')]=_0x59180c[_0x0c1d('0x39')];_0x48d37e[_0x0c1d('0x40')]=_[_0x0c1d('0x42')](_0x48d37e[_0x0c1d('0x40')],[_0x0c1d('0x43')],[_0x0c1d('0x44')]);if(_0x48d37e[_0x0c1d('0x37')]&&_0x48d37e['account'][_0x0c1d('0x45')]){_0x48d37e[_0x0c1d('0x40')][_0x0c1d('0x46')]({'id':0x0,'priority':_0x48d37e[_0x0c1d('0x40')][_0x0c1d('0x47')]+0x1,'app':'close','appdata':_0x0c1d('0x45'),'interval':'*,*,*,*'});}if(_0x48d37e[_0x0c1d('0x37')]['Applications']){delete _0x48d37e['account'][_0x0c1d('0x3c')];}if(_0x48d37e[_0x0c1d('0x37')]['List']){delete _0x48d37e['account'][_0x0c1d('0x39')];}if(_0x59180c[_0x0c1d('0x39')][_0x0c1d('0x48')]['length']){return _0x59180c['List'][_0x0c1d('0x48')][0x0];}var _0x2234fc=_[_0x0c1d('0x49')](_0x275e97[_0x0c1d('0x27')],{'firstName':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x31')],'ListId':_0x59180c[_0x0c1d('0x2f')]});_0x2234fc[_0x275e97['body']['mapKey']]=_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x31')];return db['CmContact'][_0x0c1d('0x4a')](_0x2234fc);}else{throw new Error(_0x0c1d('0x4b'));}})[_0x0c1d('0xe')](function(_0xb90349){_0x48d37e[_0x0c1d('0x4c')]=_0xb90349;if(_0xb90349){if(!_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x4d')]){_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x4d')]=rs[_0x0c1d('0x4e')]()+'\x20'+_0x275e97['body'][_0x0c1d('0x17')][_0x0c1d('0x31')];}var _0x339a11={'ContactId':_0xb90349['id'],'MailAccountId':_0x275e97['account']['id'],'inReplyTo':_0x275e97['body']['message'][_0x0c1d('0x4d')],'to':_0x275e97[_0x0c1d('0x27')]['message'][_0x0c1d('0x31')],'cc':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')]['cc'],'subject':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x4f')],'attach':_0x275e97['body'][_0x0c1d('0x17')][_0x0c1d('0x50')],'lastMsgAt':moment()[_0x0c1d('0x51')](_0x0c1d('0x52')),'lastMsgDirection':'in'};return db[_0x0c1d('0x53')]['find']({'where':{'closed':![],'MailAccountId':_0x275e97[_0x0c1d('0x37')]['id']},'include':[{'model':db[_0x0c1d('0x54')],'as':'Messages','attributes':['messageId'],'where':{'messageId':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')]['inReplyTo']}}]})[_0x0c1d('0xe')](function(_0xaf1322){if(_0xaf1322){return[_0xaf1322,![]];}return db['MailInteraction']['create'](_0x339a11)[_0x0c1d('0xe')](function(_0x32cf03){return[_0x32cf03,!![]];});});}else{throw new Error(_0x0c1d('0x55'));}})[_0x0c1d('0x56')](function(_0x14bf4c,_0x34761d){if(_0x14bf4c){_0x12653f=_0x34761d;if(!_0x34761d){return _0x14bf4c['update']({'inReplyTo':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x4d')],'to':_0x275e97[_0x0c1d('0x27')]['message'][_0x0c1d('0x31')],'cc':_0x275e97[_0x0c1d('0x27')]['message']['cc'],'subject':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x4f')],'attach':_0x14bf4c[_0x0c1d('0x50')]?_0x14bf4c[_0x0c1d('0x50')]:_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x50')],'substatus':null,'substatusAt':moment()['format'](_0x0c1d('0x52')),'lastMsgAt':moment()[_0x0c1d('0x51')](_0x0c1d('0x52')),'lastMsgDirection':'in'});}else{return _0x14bf4c;}}})[_0x0c1d('0xe')](function(_0x1d13ae){_0x48d37e[_0x0c1d('0x57')]=_0x1d13ae[_0x0c1d('0x3e')]({'plain':!![]});_0x48d37e[_0x0c1d('0x57')][_0x0c1d('0x58')]=_0x12653f;return db['MailMessage'][_0x0c1d('0x4a')]({'body':_0x275e97[_0x0c1d('0x27')]['body'],'MailAccountId':_0x275e97[_0x0c1d('0x37')]['id'],'MailInteractionId':_0x1d13ae['id'],'direction':'in','ContactId':_0x48d37e[_0x0c1d('0x4c')]['id'],'messageId':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x4d')],'from':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')]['from'],'to':_0x275e97[_0x0c1d('0x27')]['message']['to'],'cc':_0x275e97['body'][_0x0c1d('0x17')]['cc'],'subject':_0x275e97['body'][_0x0c1d('0x17')][_0x0c1d('0x4f')],'attach':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x50')],'Attachments':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')]['attachments'],'originTo':_0x275e97[_0x0c1d('0x27')]['message'][_0x0c1d('0x59')],'originCc':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x5a')],'bcc':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')]['bcc'],'ChatWebsiteId':_0x275e97['body']['message'][_0x0c1d('0x5b')]||null,'originChannel':_0x275e97[_0x0c1d('0x27')][_0x0c1d('0x17')][_0x0c1d('0x5c')]||_0x0c1d('0x5d'),'ChatOfflineMessageId':_0x275e97['body']['message'][_0x0c1d('0x5e')]||null},{'include':[{'model':db[_0x0c1d('0x5f')],'as':'Attachments'}]});})['then'](function(_0x37ac19){_0x48d37e[_0x0c1d('0x17')]=_0x37ac19;if(_0x48d37e['interaction'][_0x0c1d('0x60')]){return db[_0x0c1d('0x61')][_0x0c1d('0x24')]({'attributes':['id',_0x0c1d('0x62')],'where':{'id':_0x48d37e[_0x0c1d('0x57')][_0x0c1d('0x60')]}})['then'](function(_0x5782fe){if(_0x5782fe){_0x48d37e[_0x0c1d('0x40')]['unshift']({'id':0x0,'priority':0x0,'app':_0x0c1d('0x63'),'appdata':_0x5782fe[_0x0c1d('0x62')]+','+(_0x48d37e[_0x0c1d('0x37')][_0x0c1d('0x64')]||0xa),'interval':_0x0c1d('0x65')});}return respondWithRpcPromise(_0x0c1d('0x66'),_0x0c1d('0x67'),_0x48d37e);});}return respondWithRpcPromise(_0x0c1d('0x66'),'startRouting',_0x48d37e);})[_0x0c1d('0xe')](function(_0xbcbe6){_0x16c052(_0xbcbe6);})[_0x0c1d('0x18')](function(_0x5f24e2){_0x3c8624(_0x367c70[_0x0c1d('0x15')](0x1f4,_0x5f24e2[_0x0c1d('0x17')]));});});};
\ No newline at end of file
+var _0x3316=['Applications','List','get','omit','applications','list','orderBy','priority','asc','autoclose','push','length','close','*,*,*,*','create','List\x20not\x20found','messageId','generate','subject','attach','YYYY-MM-DD\x20HH:mm:ss','MailInteraction','MailMessage','Messages','Contact\x20not\x20found','spread','update','format','interaction','created','contact','attachments','originTo','originCc','bcc','ChatWebsiteId','Email','Attachments','User','name','UserId','unshift','agent','waitForTheAssignedAgent','Start','startRouting','lodash','util','bluebird','randomstring','../../mysqldb','../../config/utils','../../config/logger','rpc','../../config/environment','jayson/promise','client','http','defaults','socket.io-emitter','redis','./mailAccount.socket','register','request','then','MailAccount,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','info','result','GetMailAccount','MailAccount','findAll','options','raw','where','attributes','limit','include','map','model','catch','ShowMailAccount','find','NotifyMailAccount','mail','difference','keys','CmContact','rawAttributes','createdAt','updatedAt','CompanyId','ListId','isNil','body','mapKey\x20invalid,\x20please\x20use\x20one\x20of\x20these:\x20','mapKey','from','account','Contacts','DESC'];(function(_0x2fa393,_0x57e26d){var _0x15a4fb=function(_0x2a8eb9){while(--_0x2a8eb9){_0x2fa393['push'](_0x2fa393['shift']());}};_0x15a4fb(++_0x57e26d);}(_0x3316,0x16c));var _0x6331=function(_0x4024a8,_0x24792b){_0x4024a8=_0x4024a8-0x0;var _0x4d7178=_0x3316[_0x4024a8];return _0x4d7178;};'use strict';var _=require(_0x6331('0x0'));var util=require(_0x6331('0x1'));var moment=require('moment');var BPromise=require(_0x6331('0x2'));var rs=require(_0x6331('0x3'));var fs=require('fs');var Redis=require('ioredis');var db=require(_0x6331('0x4'))['db'];var utils=require(_0x6331('0x5'));var logger=require(_0x6331('0x6'))(_0x6331('0x7'));var config=require(_0x6331('0x8'));var jayson=require(_0x6331('0x9'));var client=jayson[_0x6331('0xa')][_0x6331('0xb')]({'port':0x232c});config['redis']=_[_0x6331('0xc')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require(_0x6331('0xd'))(new Redis(config[_0x6331('0xe')]));require(_0x6331('0xf'))[_0x6331('0x10')](socket);function respondWithRpcPromise(_0x42a17e,_0x13e12c,_0x29906f){return new BPromise(function(_0x510ab0,_0x43f275){return client[_0x6331('0x11')](_0x42a17e,_0x29906f)[_0x6331('0x12')](function(_0x57787f){logger['info'](_0x6331('0x13'),_0x13e12c,_0x6331('0x14'));logger[_0x6331('0x15')]('MailAccount,\x20%s,\x20%s,\x20%s',_0x13e12c,_0x6331('0x14'),JSON[_0x6331('0x16')](_0x57787f));if(_0x57787f[_0x6331('0x17')]){if(_0x57787f[_0x6331('0x17')][_0x6331('0x18')]===0x1f4){logger[_0x6331('0x17')]('MailAccount,\x20%s,\x20%s',_0x13e12c,_0x57787f['error']['message']);return _0x43f275(_0x57787f['error'][_0x6331('0x19')]);}logger[_0x6331('0x17')](_0x6331('0x13'),_0x13e12c,_0x57787f[_0x6331('0x17')]['message']);return _0x510ab0(_0x57787f[_0x6331('0x17')][_0x6331('0x19')]);}else{logger[_0x6331('0x1a')](_0x6331('0x13'),_0x13e12c,_0x6331('0x14'));_0x510ab0(_0x57787f[_0x6331('0x1b')][_0x6331('0x19')]);}})['catch'](function(_0x38ca0a){logger['error'](_0x6331('0x13'),_0x13e12c,_0x38ca0a);_0x43f275(_0x38ca0a);});});}exports[_0x6331('0x1c')]=function(_0x68e1bf){var _0x3c8a37=this;return new Promise(function(_0x2bd36f,_0x3287b5){return db[_0x6331('0x1d')][_0x6331('0x1e')]({'raw':_0x68e1bf['options']?_0x68e1bf[_0x6331('0x1f')][_0x6331('0x20')]===undefined?!![]:![]:!![],'where':_0x68e1bf[_0x6331('0x1f')]?_0x68e1bf[_0x6331('0x1f')][_0x6331('0x21')]||null:null,'attributes':_0x68e1bf[_0x6331('0x1f')]?_0x68e1bf[_0x6331('0x1f')][_0x6331('0x22')]||null:null,'limit':_0x68e1bf[_0x6331('0x1f')]?_0x68e1bf['options'][_0x6331('0x23')]||null:null,'include':_0x68e1bf[_0x6331('0x1f')]?_0x68e1bf[_0x6331('0x1f')][_0x6331('0x24')]?_[_0x6331('0x25')](_0x68e1bf['options']['include'],function(_0x129ebb){return{'model':db[_0x129ebb[_0x6331('0x26')]],'as':_0x129ebb['as'],'attributes':_0x129ebb[_0x6331('0x22')],'include':_0x129ebb[_0x6331('0x24')]?_[_0x6331('0x25')](_0x129ebb['include'],function(_0xd4c3a3){return{'model':db[_0xd4c3a3[_0x6331('0x26')]],'as':_0xd4c3a3['as'],'attributes':_0xd4c3a3[_0x6331('0x22')],'include':_0xd4c3a3[_0x6331('0x24')]?_[_0x6331('0x25')](_0xd4c3a3[_0x6331('0x24')],function(_0x61c725){return{'model':db[_0x61c725['model']],'as':_0x61c725['as'],'attributes':_0x61c725[_0x6331('0x22')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x3f8fc3){logger[_0x6331('0x1a')](_0x6331('0x1c'),_0x68e1bf);logger[_0x6331('0x15')]('GetMailAccount',_0x68e1bf,JSON[_0x6331('0x16')](_0x3f8fc3));_0x2bd36f(_0x3f8fc3);})[_0x6331('0x27')](function(_0x195d8d){logger[_0x6331('0x17')](_0x6331('0x1c'),_0x195d8d[_0x6331('0x19')],_0x68e1bf);_0x3287b5(_0x3c8a37[_0x6331('0x17')](0x1f4,_0x195d8d[_0x6331('0x19')]));});});};exports[_0x6331('0x28')]=function(_0x404509){var _0x4ea71f=this;return new Promise(function(_0x41f513,_0x515f5a){return db[_0x6331('0x1d')][_0x6331('0x29')]({'raw':_0x404509['options']?_0x404509[_0x6331('0x1f')]['raw']===undefined?!![]:![]:!![],'where':_0x404509[_0x6331('0x1f')]?_0x404509[_0x6331('0x1f')][_0x6331('0x21')]||null:null,'attributes':_0x404509[_0x6331('0x1f')]?_0x404509[_0x6331('0x1f')][_0x6331('0x22')]||null:null,'include':_0x404509[_0x6331('0x1f')]?_0x404509[_0x6331('0x1f')][_0x6331('0x24')]?_['map'](_0x404509[_0x6331('0x1f')][_0x6331('0x24')],function(_0x111b13){return{'model':db[_0x111b13[_0x6331('0x26')]],'as':_0x111b13['as'],'attributes':_0x111b13[_0x6331('0x22')],'include':_0x111b13['include']?_[_0x6331('0x25')](_0x111b13[_0x6331('0x24')],function(_0x473204){return{'model':db[_0x473204[_0x6331('0x26')]],'as':_0x473204['as'],'attributes':_0x473204['attributes'],'include':_0x473204[_0x6331('0x24')]?_[_0x6331('0x25')](_0x473204['include'],function(_0x9a77b8){return{'model':db[_0x9a77b8['model']],'as':_0x9a77b8['as'],'attributes':_0x9a77b8[_0x6331('0x22')]};}):[]};}):[]};}):[]:[]})['then'](function(_0x50d93a){logger[_0x6331('0x1a')](_0x6331('0x28'),_0x404509);logger[_0x6331('0x15')](_0x6331('0x28'),_0x404509,JSON[_0x6331('0x16')](_0x50d93a));_0x41f513(_0x50d93a);})[_0x6331('0x27')](function(_0x1ab311){logger[_0x6331('0x17')](_0x6331('0x28'),_0x1ab311['message'],_0x404509);_0x515f5a(_0x4ea71f[_0x6331('0x17')](0x1f4,_0x1ab311['message']));});});};exports[_0x6331('0x2a')]=function(_0x74999a){var _0x18a6c3=this;return new Promise(function(_0x18f368,_0x19982f){var _0x50eb9b={'body':_0x74999a['body'],'channel':_0x6331('0x2b')};var _0x3f8f76=_[_0x6331('0x2c')](_[_0x6331('0x2d')](db[_0x6331('0x2e')][_0x6331('0x2f')]),[_0x6331('0x30'),_0x6331('0x31'),_0x6331('0x32'),_0x6331('0x33')]);var _0x59cd18=![];if(_0x74999a['body']['id']){delete _0x74999a['body']['id'];}if(_[_0x6331('0x34')](_0x74999a[_0x6331('0x35')]['from'])){return _0x19982f(_0x18a6c3[_0x6331('0x17')](0x1f4,'from\x20is\x20mandatory'));}if(_['isNil'](_0x74999a[_0x6331('0x35')][_0x6331('0x35')])||_0x74999a[_0x6331('0x35')][_0x6331('0x35')]===''){return _0x19982f(_0x18a6c3['error'](0x1f4,'body\x20is\x20mandatory\x20and\x20not\x20empty'));}if(_[_0x6331('0x34')](_0x74999a['body']['mapKey'])){return _0x19982f(_0x18a6c3[_0x6331('0x17')](0x1f4,'mapKey\x20is\x20mandatory,\x20please\x20use\x20one\x20of\x20these:\x20'+_0x3f8f76));}if(!_['includes'](_0x3f8f76,_0x74999a[_0x6331('0x35')]['mapKey'])){return _0x19982f(_0x18a6c3['error'](0x1f4,_0x6331('0x36')+_0x3f8f76));}var _0x33e548={};_0x33e548[_0x74999a[_0x6331('0x35')][_0x6331('0x37')]]=_0x74999a[_0x6331('0x35')][_0x6331('0x38')];return db[_0x6331('0x1d')][_0x6331('0x29')]({'where':{'id':_0x74999a[_0x6331('0x39')]['id']},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db['CmContact'],'as':_0x6331('0x3a'),'where':_0x33e548,'limit':0x1,'order':[[_0x6331('0x31'),_0x6331('0x3b')]]}]},{'model':db['MailApplication'],'as':_0x6331('0x3c')},{'model':db['MailServerOut'],'as':'Smtp'}]})[_0x6331('0x12')](function(_0x4ce311){if(_0x4ce311&&_0x4ce311[_0x6331('0x3d')]){var _0x26dde7=_0x4ce311[_0x6331('0x3e')]({'plain':!![]});_0x50eb9b['account']=_[_0x6331('0x3f')](_0x26dde7,[_0x6331('0x3c'),_0x6331('0x3d')]);_0x50eb9b[_0x6331('0x40')]=_0x26dde7[_0x6331('0x3c')];_0x50eb9b[_0x6331('0x41')]=_0x26dde7['List'];_0x50eb9b[_0x6331('0x40')]=_[_0x6331('0x42')](_0x50eb9b[_0x6331('0x40')],[_0x6331('0x43')],[_0x6331('0x44')]);if(_0x50eb9b['account']&&_0x50eb9b[_0x6331('0x39')][_0x6331('0x45')]){_0x50eb9b[_0x6331('0x40')][_0x6331('0x46')]({'id':0x0,'priority':_0x50eb9b['applications'][_0x6331('0x47')]+0x1,'app':_0x6331('0x48'),'appdata':_0x6331('0x45'),'interval':_0x6331('0x49')});}if(_0x50eb9b[_0x6331('0x39')][_0x6331('0x3c')]){delete _0x50eb9b[_0x6331('0x39')][_0x6331('0x3c')];}if(_0x50eb9b[_0x6331('0x39')][_0x6331('0x3d')]){delete _0x50eb9b['account']['List'];}if(_0x26dde7[_0x6331('0x3d')]['Contacts'][_0x6331('0x47')]){return _0x26dde7['List']['Contacts'][0x0];}var _0x5b6be9=_[_0x6331('0xc')](_0x74999a[_0x6331('0x35')],{'firstName':_0x74999a[_0x6331('0x35')][_0x6331('0x38')],'ListId':_0x26dde7[_0x6331('0x33')]});_0x5b6be9[_0x74999a['body'][_0x6331('0x37')]]=_0x74999a[_0x6331('0x35')][_0x6331('0x38')];return db['CmContact'][_0x6331('0x4a')](_0x5b6be9);}else{throw new Error(_0x6331('0x4b'));}})['then'](function(_0xe6f3f0){_0x50eb9b['contact']=_0xe6f3f0;if(_0xe6f3f0){if(!_0x74999a[_0x6331('0x35')]['message'][_0x6331('0x4c')]){_0x74999a['body']['message'][_0x6331('0x4c')]=rs[_0x6331('0x4d')]()+'\x20'+_0x74999a[_0x6331('0x35')]['message']['from'];}var _0x36eae4={'ContactId':_0xe6f3f0['id'],'MailAccountId':_0x74999a['account']['id'],'inReplyTo':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x4c')],'to':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x38')],'cc':_0x74999a[_0x6331('0x35')][_0x6331('0x19')]['cc'],'subject':_0x74999a['body'][_0x6331('0x19')][_0x6331('0x4e')],'attach':_0x74999a['body']['message'][_0x6331('0x4f')],'lastMsgAt':moment()['format'](_0x6331('0x50')),'lastMsgDirection':'in'};return db[_0x6331('0x51')][_0x6331('0x29')]({'where':{'closed':![],'MailAccountId':_0x74999a[_0x6331('0x39')]['id']},'include':[{'model':db[_0x6331('0x52')],'as':_0x6331('0x53'),'attributes':[_0x6331('0x4c')],'where':{'messageId':_0x74999a['body'][_0x6331('0x19')]['inReplyTo']}}]})[_0x6331('0x12')](function(_0x11d710){if(_0x11d710){return[_0x11d710,![]];}return db['MailInteraction'][_0x6331('0x4a')](_0x36eae4)['then'](function(_0x15315c){return[_0x15315c,!![]];});});}else{throw new Error(_0x6331('0x54'));}})[_0x6331('0x55')](function(_0x460044,_0x65cd86){if(_0x460044){_0x59cd18=_0x65cd86;if(!_0x65cd86){return _0x460044[_0x6331('0x56')]({'inReplyTo':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x4c')],'to':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x38')],'cc':_0x74999a[_0x6331('0x35')]['message']['cc'],'subject':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x4e')],'attach':_0x460044[_0x6331('0x4f')]?_0x460044[_0x6331('0x4f')]:_0x74999a[_0x6331('0x35')]['message']['attach'],'substatus':null,'substatusAt':moment()[_0x6331('0x57')](_0x6331('0x50')),'lastMsgAt':moment()[_0x6331('0x57')]('YYYY-MM-DD\x20HH:mm:ss'),'lastMsgDirection':'in'});}else{return _0x460044;}}})[_0x6331('0x12')](function(_0x4357c0){_0x50eb9b[_0x6331('0x58')]=_0x4357c0[_0x6331('0x3e')]({'plain':!![]});_0x50eb9b[_0x6331('0x58')][_0x6331('0x59')]=_0x59cd18;return db['MailMessage'][_0x6331('0x4a')]({'body':_0x74999a['body'][_0x6331('0x35')],'MailAccountId':_0x74999a[_0x6331('0x39')]['id'],'MailInteractionId':_0x4357c0['id'],'direction':'in','ContactId':_0x50eb9b[_0x6331('0x5a')]['id'],'messageId':_0x74999a['body'][_0x6331('0x19')][_0x6331('0x4c')],'from':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x38')],'to':_0x74999a[_0x6331('0x35')]['message']['to'],'cc':_0x74999a[_0x6331('0x35')][_0x6331('0x19')]['cc'],'subject':_0x74999a[_0x6331('0x35')]['message'][_0x6331('0x4e')],'attach':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x4f')],'Attachments':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x5b')],'originTo':_0x74999a['body'][_0x6331('0x19')][_0x6331('0x5c')],'originCc':_0x74999a[_0x6331('0x35')][_0x6331('0x19')][_0x6331('0x5d')],'bcc':_0x74999a['body'][_0x6331('0x19')][_0x6331('0x5e')],'ChatWebsiteId':_0x74999a['body']['message'][_0x6331('0x5f')]||null,'originChannel':_0x74999a[_0x6331('0x35')][_0x6331('0x19')]['originChannel']||_0x6331('0x60'),'ChatOfflineMessageId':_0x74999a[_0x6331('0x35')][_0x6331('0x19')]['ChatOfflineMessageId']||null},{'include':[{'model':db['Attachment'],'as':_0x6331('0x61')}]});})[_0x6331('0x12')](function(_0x32e626){_0x50eb9b['message']=_0x32e626;if(_0x50eb9b[_0x6331('0x58')]['UserId']){return db[_0x6331('0x62')][_0x6331('0x29')]({'attributes':['id',_0x6331('0x63')],'where':{'id':_0x50eb9b[_0x6331('0x58')][_0x6331('0x64')]}})[_0x6331('0x12')](function(_0x2038ac){if(_0x2038ac){_0x50eb9b['applications'][_0x6331('0x65')]({'id':0x0,'priority':0x0,'app':_0x6331('0x66'),'appdata':_0x2038ac[_0x6331('0x63')]+','+(_0x50eb9b['account'][_0x6331('0x67')]||0xa),'interval':'*,*,*,*'});}return respondWithRpcPromise('Start','startRouting',_0x50eb9b);});}return respondWithRpcPromise(_0x6331('0x68'),_0x6331('0x69'),_0x50eb9b);})[_0x6331('0x12')](function(_0x491d31){_0x18f368(_0x491d31);})[_0x6331('0x27')](function(_0x39ec75){_0x19982f(_0x18a6c3[_0x6331('0x17')](0x1f4,_0x39ec75[_0x6331('0x19')]));});});};
\ No newline at end of file