Built motion from commit 3a7e82ea.|2.6.29
[motion2.git] / server / api / mailAccount / mailAccount.rpc.js
index 163e95e..1b8ab5d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7d9f=['ChatOfflineMessageId','UserId','User','name','waitForTheAssignedAgent','queueId','unshift','queue','startRouting','lodash','moment','bluebird','randomstring','ioredis','../../config/logger','rpc','../../config/environment','jayson/promise','client','defaults','redis','socket.io-emitter','register','request','then','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','error','code','message','MailAccount,\x20%s,\x20%s','info','catch','GetMailAccount','MailAccount','findAll','options','raw','attributes','limit','map','include','model','stringify','ShowMailAccount','find','where','smtp','setDataValue','smtpOptions','NotifyMailAccount','body','difference','keys','CmContact','rawAttributes','createdAt','updatedAt','CompanyId','ListId','from','body\x20is\x20mandatory\x20and\x20not\x20empty','isNil','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','omit','getSmtpOptions','applications','list','orderBy','priority','asc','autoclose','push','close','*,*,*,*','length','create','List\x20not\x20found','contact','messageId','generate','subject','attach','format','YYYY-MM-DD\x20HH:mm:ss','MailMessage','inReplyTo','MailInteraction','Contact\x20not\x20found','update','interaction','created','attachments','originTo','originCc','bcc','ChatWebsiteId','originChannel','Email'];(function(_0x53fd23,_0xbdb442){var _0x97d025=function(_0x465372){while(--_0x465372){_0x53fd23['push'](_0x53fd23['shift']());}};_0x97d025(++_0xbdb442);}(_0x7d9f,0x15c));var _0xf7d9=function(_0x4d579b,_0x2327f3){_0x4d579b=_0x4d579b-0x0;var _0x288145=_0x7d9f[_0x4d579b];return _0x288145;};'use strict';var _=require(_0xf7d9('0x0'));var moment=require(_0xf7d9('0x1'));var BPromise=require(_0xf7d9('0x2'));var rs=require(_0xf7d9('0x3'));var Redis=require(_0xf7d9('0x4'));var db=require('../../mysqldb')['db'];var logger=require(_0xf7d9('0x5'))(_0xf7d9('0x6'));var config=require(_0xf7d9('0x7'));var jayson=require(_0xf7d9('0x8'));var client=jayson[_0xf7d9('0x9')]['http']({'port':0x232c});config['redis']=_[_0xf7d9('0xa')](config[_0xf7d9('0xb')],{'host':'localhost','port':0x18eb});var socket=require(_0xf7d9('0xc'))(new Redis(config[_0xf7d9('0xb')]));require('./mailAccount.socket')[_0xf7d9('0xd')](socket);function respondWithRpcPromise(_0x4cd620,_0x265548,_0x33360a){return new BPromise(function(_0x5d2735,_0x560a34){return client[_0xf7d9('0xe')](_0x4cd620,_0x33360a)[_0xf7d9('0xf')](function(_0x2a14e2){logger['info']('MailAccount,\x20%s,\x20%s',_0x265548,_0xf7d9('0x10'));logger[_0xf7d9('0x11')](_0xf7d9('0x12'),_0x265548,_0xf7d9('0x10'),JSON['stringify'](_0x2a14e2));if(_0x2a14e2[_0xf7d9('0x13')]){if(_0x2a14e2[_0xf7d9('0x13')][_0xf7d9('0x14')]===0x1f4){logger[_0xf7d9('0x13')]('MailAccount,\x20%s,\x20%s',_0x265548,_0x2a14e2[_0xf7d9('0x13')][_0xf7d9('0x15')]);return _0x560a34(_0x2a14e2[_0xf7d9('0x13')][_0xf7d9('0x15')]);}logger['error'](_0xf7d9('0x16'),_0x265548,_0x2a14e2[_0xf7d9('0x13')][_0xf7d9('0x15')]);return _0x5d2735(_0x2a14e2['error']['message']);}else{logger[_0xf7d9('0x17')](_0xf7d9('0x16'),_0x265548,_0xf7d9('0x10'));_0x5d2735(_0x2a14e2['result'][_0xf7d9('0x15')]);}})[_0xf7d9('0x18')](function(_0x5eb7c9){logger[_0xf7d9('0x13')]('MailAccount,\x20%s,\x20%s',_0x265548,_0x5eb7c9);_0x560a34(_0x5eb7c9);});});}exports[_0xf7d9('0x19')]=function(_0x1bbc77){var _0x5e0b9e=this;return new Promise(function(_0x34acd2,_0x43dcff){return db[_0xf7d9('0x1a')][_0xf7d9('0x1b')]({'raw':_0x1bbc77[_0xf7d9('0x1c')]?_0x1bbc77[_0xf7d9('0x1c')][_0xf7d9('0x1d')]===undefined?!![]:![]:!![],'where':_0x1bbc77[_0xf7d9('0x1c')]?_0x1bbc77['options']['where']||null:null,'attributes':_0x1bbc77[_0xf7d9('0x1c')]?_0x1bbc77['options'][_0xf7d9('0x1e')]||null:null,'limit':_0x1bbc77[_0xf7d9('0x1c')]?_0x1bbc77['options'][_0xf7d9('0x1f')]||null:null,'include':_0x1bbc77[_0xf7d9('0x1c')]?_0x1bbc77['options']['include']?_[_0xf7d9('0x20')](_0x1bbc77[_0xf7d9('0x1c')][_0xf7d9('0x21')],function(_0x595556){return{'model':db[_0x595556[_0xf7d9('0x22')]],'as':_0x595556['as'],'attributes':_0x595556['attributes'],'include':_0x595556[_0xf7d9('0x21')]?_[_0xf7d9('0x20')](_0x595556[_0xf7d9('0x21')],function(_0x5b1ea5){return{'model':db[_0x5b1ea5[_0xf7d9('0x22')]],'as':_0x5b1ea5['as'],'attributes':_0x5b1ea5[_0xf7d9('0x1e')],'include':_0x5b1ea5[_0xf7d9('0x21')]?_[_0xf7d9('0x20')](_0x5b1ea5[_0xf7d9('0x21')],function(_0x540086){return{'model':db[_0x540086[_0xf7d9('0x22')]],'as':_0x540086['as'],'attributes':_0x540086[_0xf7d9('0x1e')]};}):[]};}):[]};}):[]:[]})[_0xf7d9('0xf')](function(_0x2c04c3){logger['info'](_0xf7d9('0x19'),_0x1bbc77);logger[_0xf7d9('0x11')](_0xf7d9('0x19'),_0x1bbc77,JSON[_0xf7d9('0x23')](_0x2c04c3));_0x34acd2(_0x2c04c3);})[_0xf7d9('0x18')](function(_0x16318f){logger['error']('GetMailAccount',_0x16318f['message'],_0x1bbc77);_0x43dcff(_0x5e0b9e[_0xf7d9('0x13')](0x1f4,_0x16318f['message']));});});};exports[_0xf7d9('0x24')]=function(_0x48c13c){var _0x3ecbb9=this;return new Promise(function(_0x59c246,_0x4ecfbd){return db['MailAccount'][_0xf7d9('0x25')]({'raw':_0x48c13c['options']?_0x48c13c[_0xf7d9('0x1c')][_0xf7d9('0x1d')]===undefined?!![]:![]:!![],'where':_0x48c13c[_0xf7d9('0x1c')]?_0x48c13c[_0xf7d9('0x1c')][_0xf7d9('0x26')]||null:null,'attributes':_0x48c13c[_0xf7d9('0x1c')]?_0x48c13c[_0xf7d9('0x1c')][_0xf7d9('0x1e')]||null:null,'include':_0x48c13c['options']?_0x48c13c[_0xf7d9('0x1c')][_0xf7d9('0x21')]?_['map'](_0x48c13c['options'][_0xf7d9('0x21')],function(_0x1fd532){return{'model':db[_0x1fd532[_0xf7d9('0x22')]],'as':_0x1fd532['as'],'attributes':_0x1fd532['attributes'],'include':_0x1fd532[_0xf7d9('0x21')]?_[_0xf7d9('0x20')](_0x1fd532[_0xf7d9('0x21')],function(_0x1be610){return{'model':db[_0x1be610[_0xf7d9('0x22')]],'as':_0x1be610['as'],'attributes':_0x1be610[_0xf7d9('0x1e')],'include':_0x1be610[_0xf7d9('0x21')]?_[_0xf7d9('0x20')](_0x1be610[_0xf7d9('0x21')],function(_0x1c42bb){return{'model':db[_0x1c42bb[_0xf7d9('0x22')]],'as':_0x1c42bb['as'],'attributes':_0x1c42bb['attributes']};}):[]};}):[]};}):[]:[]})[_0xf7d9('0xf')](function(_0x4ce081){if(_0x48c13c[_0xf7d9('0x1c')][_0xf7d9('0x27')]===!![])_0x4ce081[_0xf7d9('0x28')](_0xf7d9('0x29'),_0x4ce081['getSmtpOptions']());logger['info'](_0xf7d9('0x24'),_0x48c13c);logger['debug'](_0xf7d9('0x24'),_0x48c13c,JSON[_0xf7d9('0x23')](_0x4ce081));_0x59c246(_0x4ce081);})[_0xf7d9('0x18')](function(_0x1e412b){logger['error']('ShowMailAccount',_0x1e412b[_0xf7d9('0x15')],_0x48c13c);_0x4ecfbd(_0x3ecbb9[_0xf7d9('0x13')](0x1f4,_0x1e412b[_0xf7d9('0x15')]));});});};exports[_0xf7d9('0x2a')]=function(_0x4b4389){var _0x17731b=this;return new Promise(function(_0xd6d84f,_0xd7f316){var _0x33e692={'body':_0x4b4389[_0xf7d9('0x2b')],'channel':'mail'};var _0x28c932=_[_0xf7d9('0x2c')](_[_0xf7d9('0x2d')](db[_0xf7d9('0x2e')][_0xf7d9('0x2f')]),[_0xf7d9('0x30'),_0xf7d9('0x31'),_0xf7d9('0x32'),_0xf7d9('0x33')]);var _0x3d056f=![];if(_0x4b4389[_0xf7d9('0x2b')]['id']){delete _0x4b4389[_0xf7d9('0x2b')]['id'];}if(_['isNil'](_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x34')])){return _0xd7f316(_0x17731b['error'](0x1f4,'from\x20is\x20mandatory'));}if(_['isNil'](_0x4b4389[_0xf7d9('0x2b')]['body'])||_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x2b')]===''){return _0xd7f316(_0x17731b[_0xf7d9('0x13')](0x1f4,_0xf7d9('0x35')));}if(_[_0xf7d9('0x36')](_0x4b4389['body'][_0xf7d9('0x37')])){return _0xd7f316(_0x17731b[_0xf7d9('0x13')](0x1f4,_0xf7d9('0x38')+_0x28c932));}if(!_[_0xf7d9('0x39')](_0x28c932,_0x4b4389[_0xf7d9('0x2b')]['mapKey'])){return _0xd7f316(_0x17731b['error'](0x1f4,_0xf7d9('0x3a')+_0x28c932));}var _0x113a2b={};_0x113a2b[_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x37')]]=_0x4b4389[_0xf7d9('0x2b')]['from'];return db[_0xf7d9('0x1a')]['find']({'where':{'id':_0x4b4389[_0xf7d9('0x3b')]['id']},'include':[{'model':db[_0xf7d9('0x3c')],'as':_0xf7d9('0x3d'),'include':[{'model':db[_0xf7d9('0x2e')],'as':_0xf7d9('0x3e'),'where':_0x113a2b,'limit':0x1,'order':[[_0xf7d9('0x31'),_0xf7d9('0x3f')]]}]},{'model':db[_0xf7d9('0x40')],'as':_0xf7d9('0x41')},{'model':db[_0xf7d9('0x42')],'as':_0xf7d9('0x43'),'include':[{'model':db[_0xf7d9('0x44')],'as':_0xf7d9('0x44')}]}]})[_0xf7d9('0xf')](function(_0x50731a){if(_0x50731a&&_0x50731a[_0xf7d9('0x3d')]){var _0x1f1ee5=_0x50731a['get']({'plain':!![]});_0x33e692['account']=_[_0xf7d9('0x45')](_0x1f1ee5,['Applications','List']);_0x33e692[_0xf7d9('0x3b')][_0xf7d9('0x29')]=_0x50731a[_0xf7d9('0x46')]();_0x33e692[_0xf7d9('0x47')]=_0x1f1ee5[_0xf7d9('0x41')];_0x33e692[_0xf7d9('0x48')]=_0x1f1ee5[_0xf7d9('0x3d')];_0x33e692[_0xf7d9('0x47')]=_[_0xf7d9('0x49')](_0x33e692[_0xf7d9('0x47')],[_0xf7d9('0x4a')],[_0xf7d9('0x4b')]);if(_0x33e692['account']&&_0x33e692['account'][_0xf7d9('0x4c')]){_0x33e692[_0xf7d9('0x47')][_0xf7d9('0x4d')]({'id':0x0,'priority':_0x33e692[_0xf7d9('0x47')]['length']+0x1,'app':_0xf7d9('0x4e'),'appdata':_0xf7d9('0x4c'),'interval':_0xf7d9('0x4f')});}if(_0x33e692[_0xf7d9('0x3b')][_0xf7d9('0x41')]){delete _0x33e692[_0xf7d9('0x3b')][_0xf7d9('0x41')];}if(_0x33e692[_0xf7d9('0x3b')][_0xf7d9('0x3d')]){delete _0x33e692[_0xf7d9('0x3b')][_0xf7d9('0x3d')];}if(_0x1f1ee5['List'][_0xf7d9('0x3e')][_0xf7d9('0x50')]){return _0x1f1ee5[_0xf7d9('0x3d')][_0xf7d9('0x3e')][0x0];}var _0x3c3bd3=_[_0xf7d9('0xa')](_0x4b4389['body'],{'firstName':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x34')],'ListId':_0x1f1ee5[_0xf7d9('0x33')]});_0x3c3bd3[_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x37')]]=_0x4b4389['body'][_0xf7d9('0x34')];return db[_0xf7d9('0x2e')][_0xf7d9('0x51')](_0x3c3bd3);}else{throw new Error(_0xf7d9('0x52'));}})[_0xf7d9('0xf')](function(_0x379f88){_0x33e692[_0xf7d9('0x53')]=_0x379f88;if(_0x379f88){if(!_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x54')]){_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x54')]=rs[_0xf7d9('0x55')]()+'\x20'+_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')]['from'];}var _0x310c05={'ContactId':_0x379f88['id'],'MailAccountId':_0x4b4389[_0xf7d9('0x3b')]['id'],'inReplyTo':_0x4b4389['body'][_0xf7d9('0x15')][_0xf7d9('0x54')],'to':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x34')],'cc':_0x4b4389['body'][_0xf7d9('0x15')]['cc'],'subject':_0x4b4389[_0xf7d9('0x2b')]['message'][_0xf7d9('0x56')],'attach':_0x4b4389[_0xf7d9('0x2b')]['message'][_0xf7d9('0x57')],'lastMsgAt':moment()[_0xf7d9('0x58')](_0xf7d9('0x59')),'lastMsgDirection':'in'};return db['MailInteraction']['find']({'where':{'closed':![],'MailAccountId':_0x4b4389['account']['id']},'include':[{'model':db[_0xf7d9('0x5a')],'as':'Messages','attributes':[_0xf7d9('0x54')],'where':{'messageId':_0x4b4389['body']['message'][_0xf7d9('0x5b')]}}]})[_0xf7d9('0xf')](function(_0x2f469c){if(_0x2f469c){return[_0x2f469c,![]];}return db[_0xf7d9('0x5c')][_0xf7d9('0x51')](_0x310c05)[_0xf7d9('0xf')](function(_0x56feae){return[_0x56feae,!![]];});});}else{throw new Error(_0xf7d9('0x5d'));}})['spread'](function(_0x2ca4e5,_0x3d33f2){if(_0x2ca4e5){_0x3d056f=_0x3d33f2;if(!_0x3d33f2){return _0x2ca4e5[_0xf7d9('0x5e')]({'inReplyTo':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x54')],'to':_0x4b4389[_0xf7d9('0x2b')]['message']['from'],'cc':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')]['cc'],'subject':_0x4b4389['body'][_0xf7d9('0x15')][_0xf7d9('0x56')],'attach':_0x2ca4e5['attach']?_0x2ca4e5[_0xf7d9('0x57')]:_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x57')],'substatus':null,'substatusAt':moment()[_0xf7d9('0x58')](_0xf7d9('0x59')),'lastMsgAt':moment()['format'](_0xf7d9('0x59')),'lastMsgDirection':'in'});}else{return _0x2ca4e5;}}})[_0xf7d9('0xf')](function(_0x5c25d6){_0x33e692[_0xf7d9('0x5f')]=_0x5c25d6['get']({'plain':!![]});_0x33e692[_0xf7d9('0x5f')][_0xf7d9('0x60')]=_0x3d056f;return db['MailMessage']['create']({'body':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x2b')],'MailAccountId':_0x4b4389[_0xf7d9('0x3b')]['id'],'MailInteractionId':_0x5c25d6['id'],'direction':'in','ContactId':_0x33e692[_0xf7d9('0x53')]['id'],'messageId':_0x4b4389['body'][_0xf7d9('0x15')][_0xf7d9('0x54')],'from':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x34')],'to':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')]['to'],'cc':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')]['cc'],'subject':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x56')],'attach':_0x4b4389['body'][_0xf7d9('0x15')][_0xf7d9('0x57')],'Attachments':_0x4b4389[_0xf7d9('0x2b')]['message'][_0xf7d9('0x61')],'originTo':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x62')],'originCc':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x63')],'bcc':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x64')],'ChatWebsiteId':_0x4b4389['body'][_0xf7d9('0x15')][_0xf7d9('0x65')]||null,'originChannel':_0x4b4389[_0xf7d9('0x2b')][_0xf7d9('0x15')][_0xf7d9('0x66')]||_0xf7d9('0x67'),'ChatOfflineMessageId':_0x4b4389[_0xf7d9('0x2b')]['message'][_0xf7d9('0x68')]||null},{'include':[{'model':db['Attachment'],'as':'Attachments'}]});})[_0xf7d9('0xf')](function(_0x437240){_0x33e692[_0xf7d9('0x15')]=_0x437240;if(!_0x33e692[_0xf7d9('0x5f')][_0xf7d9('0x69')]){return;}return db[_0xf7d9('0x6a')][_0xf7d9('0x25')]({'attributes':['id',_0xf7d9('0x6b')],'where':{'id':_0x33e692[_0xf7d9('0x5f')]['UserId']}});})[_0xf7d9('0xf')](function(_0x424774){if(_0x424774){_0x33e692['applications']['unshift']({'id':0x0,'priority':0x0,'app':'agent','appdata':_0x424774['name']+','+(_0x33e692[_0xf7d9('0x3b')][_0xf7d9('0x6c')]||0xa),'interval':_0xf7d9('0x4f')});}if(!_0x33e692['interaction'][_0xf7d9('0x6d')]){return;}return db['MailQueue'][_0xf7d9('0x25')]({'attributes':['id','name'],'where':{'id':_0x33e692[_0xf7d9('0x5f')]['queueId']}});})[_0xf7d9('0xf')](function(_0x4abd04){if(_0x4abd04){_0x33e692[_0xf7d9('0x47')][_0xf7d9('0x6e')]({'id':0x0,'priority':0x1,'app':_0xf7d9('0x6f'),'appdata':_0x4abd04[_0xf7d9('0x6b')]+','+(_0x33e692[_0xf7d9('0x3b')]['waitForTheAssignedQueue']||0x12c),'interval':_0xf7d9('0x4f')});}return respondWithRpcPromise('Start',_0xf7d9('0x70'),_0x33e692);})[_0xf7d9('0xf')](function(_0x52673b){_0xd6d84f(_0x52673b);})[_0xf7d9('0x18')](function(_0x50ec3c){_0xd7f316(_0x17731b[_0xf7d9('0x13')](0x1f4,_0x50ec3c[_0xf7d9('0x15')]));});});};
\ No newline at end of file
+var _0x3c6c=['MailQueue','queue','waitForTheAssignedQueue','Start','startRouting','lodash','bluebird','randomstring','ioredis','../../mysqldb','../../config/logger','rpc','../../config/environment','jayson/promise','http','defaults','register','request','info','MailAccount,\x20%s,\x20%s','MailAccount,\x20%s,\x20%s,\x20%s','request\x20sent','stringify','error','code','message','result','catch','GetMailAccount','MailAccount','findAll','options','raw','where','attributes','limit','include','map','model','then','debug','ShowMailAccount','find','setDataValue','smtpOptions','getSmtpOptions','NotifyMailAccount','mail','difference','keys','CmContact','rawAttributes','createdAt','updatedAt','CompanyId','ListId','body','isNil','from','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','list','orderBy','priority','asc','autoclose','length','*,*,*,*','create','List\x20not\x20found','contact','messageId','generate','subject','attach','MailInteraction','MailMessage','Messages','inReplyTo','Contact\x20not\x20found','spread','update','format','YYYY-MM-DD\x20HH:mm:ss','created','attachments','originTo','originCc','bcc','originChannel','Email','ChatOfflineMessageId','Attachment','Attachments','interaction','UserId','User','name','unshift','agent','waitForTheAssignedAgent','queueId'];(function(_0x53ccf2,_0x13cb67){var _0x5a2964=function(_0x3b0514){while(--_0x3b0514){_0x53ccf2['push'](_0x53ccf2['shift']());}};_0x5a2964(++_0x13cb67);}(_0x3c6c,0x7b));var _0xc3c6=function(_0x11ae92,_0x4742bb){_0x11ae92=_0x11ae92-0x0;var _0x1b9342=_0x3c6c[_0x11ae92];return _0x1b9342;};'use strict';var _=require(_0xc3c6('0x0'));var moment=require('moment');var BPromise=require(_0xc3c6('0x1'));var rs=require(_0xc3c6('0x2'));var Redis=require(_0xc3c6('0x3'));var db=require(_0xc3c6('0x4'))['db'];var logger=require(_0xc3c6('0x5'))(_0xc3c6('0x6'));var config=require(_0xc3c6('0x7'));var jayson=require(_0xc3c6('0x8'));var client=jayson['client'][_0xc3c6('0x9')]({'port':0x232c});config['redis']=_[_0xc3c6('0xa')](config['redis'],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config['redis']));require('./mailAccount.socket')[_0xc3c6('0xb')](socket);function respondWithRpcPromise(_0x1c04d4,_0x5bc1c1,_0x168fdc){return new BPromise(function(_0x1ba453,_0x44b9c9){return client[_0xc3c6('0xc')](_0x1c04d4,_0x168fdc)['then'](function(_0x115b59){logger[_0xc3c6('0xd')](_0xc3c6('0xe'),_0x5bc1c1,'request\x20sent');logger['debug'](_0xc3c6('0xf'),_0x5bc1c1,_0xc3c6('0x10'),JSON[_0xc3c6('0x11')](_0x115b59));if(_0x115b59[_0xc3c6('0x12')]){if(_0x115b59[_0xc3c6('0x12')][_0xc3c6('0x13')]===0x1f4){logger[_0xc3c6('0x12')](_0xc3c6('0xe'),_0x5bc1c1,_0x115b59[_0xc3c6('0x12')][_0xc3c6('0x14')]);return _0x44b9c9(_0x115b59[_0xc3c6('0x12')][_0xc3c6('0x14')]);}logger[_0xc3c6('0x12')](_0xc3c6('0xe'),_0x5bc1c1,_0x115b59[_0xc3c6('0x12')][_0xc3c6('0x14')]);return _0x1ba453(_0x115b59[_0xc3c6('0x12')][_0xc3c6('0x14')]);}else{logger[_0xc3c6('0xd')](_0xc3c6('0xe'),_0x5bc1c1,_0xc3c6('0x10'));_0x1ba453(_0x115b59[_0xc3c6('0x15')][_0xc3c6('0x14')]);}})[_0xc3c6('0x16')](function(_0x3003e1){logger[_0xc3c6('0x12')]('MailAccount,\x20%s,\x20%s',_0x5bc1c1,_0x3003e1);_0x44b9c9(_0x3003e1);});});}exports[_0xc3c6('0x17')]=function(_0x5a2456){var _0x2150e0=this;return new Promise(function(_0x248bfe,_0x3893c4){return db[_0xc3c6('0x18')][_0xc3c6('0x19')]({'raw':_0x5a2456[_0xc3c6('0x1a')]?_0x5a2456[_0xc3c6('0x1a')][_0xc3c6('0x1b')]===undefined?!![]:![]:!![],'where':_0x5a2456[_0xc3c6('0x1a')]?_0x5a2456[_0xc3c6('0x1a')][_0xc3c6('0x1c')]||null:null,'attributes':_0x5a2456[_0xc3c6('0x1a')]?_0x5a2456[_0xc3c6('0x1a')][_0xc3c6('0x1d')]||null:null,'limit':_0x5a2456['options']?_0x5a2456[_0xc3c6('0x1a')][_0xc3c6('0x1e')]||null:null,'include':_0x5a2456[_0xc3c6('0x1a')]?_0x5a2456['options'][_0xc3c6('0x1f')]?_[_0xc3c6('0x20')](_0x5a2456[_0xc3c6('0x1a')][_0xc3c6('0x1f')],function(_0x2bc9bf){return{'model':db[_0x2bc9bf[_0xc3c6('0x21')]],'as':_0x2bc9bf['as'],'attributes':_0x2bc9bf[_0xc3c6('0x1d')],'include':_0x2bc9bf['include']?_[_0xc3c6('0x20')](_0x2bc9bf[_0xc3c6('0x1f')],function(_0x4ca76f){return{'model':db[_0x4ca76f[_0xc3c6('0x21')]],'as':_0x4ca76f['as'],'attributes':_0x4ca76f[_0xc3c6('0x1d')],'include':_0x4ca76f[_0xc3c6('0x1f')]?_[_0xc3c6('0x20')](_0x4ca76f[_0xc3c6('0x1f')],function(_0x420723){return{'model':db[_0x420723[_0xc3c6('0x21')]],'as':_0x420723['as'],'attributes':_0x420723[_0xc3c6('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xc3c6('0x22')](function(_0x478a4b){logger[_0xc3c6('0xd')](_0xc3c6('0x17'),_0x5a2456);logger[_0xc3c6('0x23')](_0xc3c6('0x17'),_0x5a2456,JSON['stringify'](_0x478a4b));_0x248bfe(_0x478a4b);})[_0xc3c6('0x16')](function(_0x1bcc34){logger[_0xc3c6('0x12')](_0xc3c6('0x17'),_0x1bcc34[_0xc3c6('0x14')],_0x5a2456);_0x3893c4(_0x2150e0[_0xc3c6('0x12')](0x1f4,_0x1bcc34['message']));});});};exports[_0xc3c6('0x24')]=function(_0x249bad){var _0x2220ca=this;return new Promise(function(_0x2b715c,_0x380345){return db['MailAccount'][_0xc3c6('0x25')]({'raw':_0x249bad[_0xc3c6('0x1a')]?_0x249bad[_0xc3c6('0x1a')][_0xc3c6('0x1b')]===undefined?!![]:![]:!![],'where':_0x249bad[_0xc3c6('0x1a')]?_0x249bad[_0xc3c6('0x1a')][_0xc3c6('0x1c')]||null:null,'attributes':_0x249bad['options']?_0x249bad[_0xc3c6('0x1a')]['attributes']||null:null,'include':_0x249bad[_0xc3c6('0x1a')]?_0x249bad[_0xc3c6('0x1a')][_0xc3c6('0x1f')]?_[_0xc3c6('0x20')](_0x249bad[_0xc3c6('0x1a')][_0xc3c6('0x1f')],function(_0x4ba1ae){return{'model':db[_0x4ba1ae[_0xc3c6('0x21')]],'as':_0x4ba1ae['as'],'attributes':_0x4ba1ae[_0xc3c6('0x1d')],'include':_0x4ba1ae['include']?_[_0xc3c6('0x20')](_0x4ba1ae[_0xc3c6('0x1f')],function(_0x139944){return{'model':db[_0x139944[_0xc3c6('0x21')]],'as':_0x139944['as'],'attributes':_0x139944[_0xc3c6('0x1d')],'include':_0x139944[_0xc3c6('0x1f')]?_[_0xc3c6('0x20')](_0x139944['include'],function(_0x5daaf2){return{'model':db[_0x5daaf2[_0xc3c6('0x21')]],'as':_0x5daaf2['as'],'attributes':_0x5daaf2[_0xc3c6('0x1d')]};}):[]};}):[]};}):[]:[]})[_0xc3c6('0x22')](function(_0xfe1489){if(_0x249bad[_0xc3c6('0x1a')]['smtp']===!![])_0xfe1489[_0xc3c6('0x26')](_0xc3c6('0x27'),_0xfe1489[_0xc3c6('0x28')]());logger[_0xc3c6('0xd')](_0xc3c6('0x24'),_0x249bad);logger[_0xc3c6('0x23')](_0xc3c6('0x24'),_0x249bad,JSON[_0xc3c6('0x11')](_0xfe1489));_0x2b715c(_0xfe1489);})[_0xc3c6('0x16')](function(_0x52ef62){logger[_0xc3c6('0x12')](_0xc3c6('0x24'),_0x52ef62[_0xc3c6('0x14')],_0x249bad);_0x380345(_0x2220ca[_0xc3c6('0x12')](0x1f4,_0x52ef62[_0xc3c6('0x14')]));});});};exports[_0xc3c6('0x29')]=function(_0x3e839e){var _0x376e90=this;return new Promise(function(_0x59b2d9,_0x30692f){var _0x242e2b={'body':_0x3e839e['body'],'channel':_0xc3c6('0x2a')};var _0x5ea389=_[_0xc3c6('0x2b')](_[_0xc3c6('0x2c')](db[_0xc3c6('0x2d')][_0xc3c6('0x2e')]),[_0xc3c6('0x2f'),_0xc3c6('0x30'),_0xc3c6('0x31'),_0xc3c6('0x32')]);var _0x572339=![];if(_0x3e839e[_0xc3c6('0x33')]['id']){delete _0x3e839e['body']['id'];}if(_[_0xc3c6('0x34')](_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x35')])){return _0x30692f(_0x376e90[_0xc3c6('0x12')](0x1f4,'from\x20is\x20mandatory'));}if(_['isNil'](_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x33')])||_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x33')]===''){return _0x30692f(_0x376e90['error'](0x1f4,_0xc3c6('0x36')));}if(_[_0xc3c6('0x34')](_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x37')])){return _0x30692f(_0x376e90[_0xc3c6('0x12')](0x1f4,_0xc3c6('0x38')+_0x5ea389));}if(!_[_0xc3c6('0x39')](_0x5ea389,_0x3e839e['body']['mapKey'])){return _0x30692f(_0x376e90[_0xc3c6('0x12')](0x1f4,_0xc3c6('0x3a')+_0x5ea389));}var _0x490bbf={};_0x490bbf[_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x37')]]=_0x3e839e['body'][_0xc3c6('0x35')];return db[_0xc3c6('0x18')]['find']({'where':{'id':_0x3e839e[_0xc3c6('0x3b')]['id']},'include':[{'model':db[_0xc3c6('0x3c')],'as':_0xc3c6('0x3d'),'include':[{'model':db[_0xc3c6('0x2d')],'as':_0xc3c6('0x3e'),'where':_0x490bbf,'limit':0x1,'order':[[_0xc3c6('0x30'),_0xc3c6('0x3f')]]}]},{'model':db[_0xc3c6('0x40')],'as':_0xc3c6('0x41')},{'model':db[_0xc3c6('0x42')],'as':_0xc3c6('0x43'),'include':[{'model':db[_0xc3c6('0x44')],'as':_0xc3c6('0x44')}]}]})[_0xc3c6('0x22')](function(_0x55b8bc){if(_0x55b8bc&&_0x55b8bc['List']){var _0x387a41=_0x55b8bc[_0xc3c6('0x45')]({'plain':!![]});_0x242e2b[_0xc3c6('0x3b')]=_[_0xc3c6('0x46')](_0x387a41,['Applications','List']);_0x242e2b[_0xc3c6('0x3b')][_0xc3c6('0x27')]=_0x55b8bc[_0xc3c6('0x28')]();_0x242e2b[_0xc3c6('0x47')]=_0x387a41[_0xc3c6('0x41')];_0x242e2b[_0xc3c6('0x48')]=_0x387a41[_0xc3c6('0x3d')];_0x242e2b[_0xc3c6('0x47')]=_[_0xc3c6('0x49')](_0x242e2b[_0xc3c6('0x47')],[_0xc3c6('0x4a')],[_0xc3c6('0x4b')]);if(_0x242e2b[_0xc3c6('0x3b')]&&_0x242e2b[_0xc3c6('0x3b')][_0xc3c6('0x4c')]){_0x242e2b[_0xc3c6('0x47')]['push']({'id':0x0,'priority':_0x242e2b[_0xc3c6('0x47')][_0xc3c6('0x4d')]+0x1,'app':'close','appdata':'autoclose','interval':_0xc3c6('0x4e')});}if(_0x242e2b[_0xc3c6('0x3b')][_0xc3c6('0x41')]){delete _0x242e2b[_0xc3c6('0x3b')][_0xc3c6('0x41')];}if(_0x242e2b[_0xc3c6('0x3b')][_0xc3c6('0x3d')]){delete _0x242e2b['account']['List'];}if(_0x387a41[_0xc3c6('0x3d')][_0xc3c6('0x3e')][_0xc3c6('0x4d')]){return _0x387a41[_0xc3c6('0x3d')][_0xc3c6('0x3e')][0x0];}var _0x2e9314=_[_0xc3c6('0xa')](_0x3e839e[_0xc3c6('0x33')],{'firstName':_0x3e839e[_0xc3c6('0x33')]['from'],'ListId':_0x387a41[_0xc3c6('0x32')]});_0x2e9314[_0x3e839e['body']['mapKey']]=_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x35')];return db[_0xc3c6('0x2d')][_0xc3c6('0x4f')](_0x2e9314);}else{throw new Error(_0xc3c6('0x50'));}})[_0xc3c6('0x22')](function(_0x330cfc){_0x242e2b[_0xc3c6('0x51')]=_0x330cfc;if(_0x330cfc){if(!_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')]['messageId']){_0x3e839e[_0xc3c6('0x33')]['message'][_0xc3c6('0x52')]=rs[_0xc3c6('0x53')]()+'\x20'+_0x3e839e[_0xc3c6('0x33')]['message'][_0xc3c6('0x35')];}var _0x528383={'ContactId':_0x330cfc['id'],'MailAccountId':_0x3e839e['account']['id'],'inReplyTo':_0x3e839e['body'][_0xc3c6('0x14')][_0xc3c6('0x52')],'to':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x35')],'cc':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')]['cc'],'subject':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x54')],'attach':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x55')],'lastMsgAt':moment()['format']('YYYY-MM-DD\x20HH:mm:ss'),'lastMsgDirection':'in'};return db[_0xc3c6('0x56')][_0xc3c6('0x25')]({'where':{'closed':![],'MailAccountId':_0x3e839e[_0xc3c6('0x3b')]['id']},'include':[{'model':db[_0xc3c6('0x57')],'as':_0xc3c6('0x58'),'attributes':[_0xc3c6('0x52')],'where':{'messageId':_0x3e839e[_0xc3c6('0x33')]['message'][_0xc3c6('0x59')]}}]})['then'](function(_0x1709a8){if(_0x1709a8){return[_0x1709a8,![]];}return db['MailInteraction'][_0xc3c6('0x4f')](_0x528383)[_0xc3c6('0x22')](function(_0x5cc468){return[_0x5cc468,!![]];});});}else{throw new Error(_0xc3c6('0x5a'));}})[_0xc3c6('0x5b')](function(_0x333d8f,_0x501847){if(_0x333d8f){_0x572339=_0x501847;if(!_0x501847){return _0x333d8f[_0xc3c6('0x5c')]({'inReplyTo':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x52')],'to':_0x3e839e[_0xc3c6('0x33')]['message']['from'],'cc':_0x3e839e[_0xc3c6('0x33')]['message']['cc'],'subject':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')]['subject'],'attach':_0x333d8f[_0xc3c6('0x55')]?_0x333d8f[_0xc3c6('0x55')]:_0x3e839e['body']['message'][_0xc3c6('0x55')],'substatus':null,'substatusAt':moment()[_0xc3c6('0x5d')](_0xc3c6('0x5e')),'lastMsgAt':moment()['format'](_0xc3c6('0x5e')),'lastMsgDirection':'in'});}else{return _0x333d8f;}}})['then'](function(_0x3dd6d2){_0x242e2b['interaction']=_0x3dd6d2['get']({'plain':!![]});_0x242e2b['interaction'][_0xc3c6('0x5f')]=_0x572339;return db['MailMessage'][_0xc3c6('0x4f')]({'body':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x33')],'MailAccountId':_0x3e839e[_0xc3c6('0x3b')]['id'],'MailInteractionId':_0x3dd6d2['id'],'direction':'in','ContactId':_0x242e2b['contact']['id'],'messageId':_0x3e839e['body']['message']['messageId'],'from':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x35')],'to':_0x3e839e['body'][_0xc3c6('0x14')]['to'],'cc':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')]['cc'],'subject':_0x3e839e[_0xc3c6('0x33')]['message']['subject'],'attach':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x55')],'Attachments':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x60')],'originTo':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x61')],'originCc':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x62')],'bcc':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')][_0xc3c6('0x63')],'ChatWebsiteId':_0x3e839e[_0xc3c6('0x33')][_0xc3c6('0x14')]['ChatWebsiteId']||null,'originChannel':_0x3e839e[_0xc3c6('0x33')]['message'][_0xc3c6('0x64')]||_0xc3c6('0x65'),'ChatOfflineMessageId':_0x3e839e['body'][_0xc3c6('0x14')][_0xc3c6('0x66')]||null},{'include':[{'model':db[_0xc3c6('0x67')],'as':_0xc3c6('0x68')}]});})[_0xc3c6('0x22')](function(_0x408544){_0x242e2b[_0xc3c6('0x14')]=_0x408544;if(!_0x242e2b[_0xc3c6('0x69')][_0xc3c6('0x6a')]){return;}return db[_0xc3c6('0x6b')][_0xc3c6('0x25')]({'attributes':['id',_0xc3c6('0x6c')],'where':{'id':_0x242e2b['interaction'][_0xc3c6('0x6a')]}});})[_0xc3c6('0x22')](function(_0x25c747){if(_0x25c747){_0x242e2b[_0xc3c6('0x47')][_0xc3c6('0x6d')]({'id':0x0,'priority':0x0,'app':_0xc3c6('0x6e'),'appdata':_0x25c747[_0xc3c6('0x6c')]+','+(_0x242e2b['account'][_0xc3c6('0x6f')]||0xa),'interval':_0xc3c6('0x4e')});}if(!_0x242e2b[_0xc3c6('0x69')][_0xc3c6('0x70')]){return;}return db[_0xc3c6('0x71')]['find']({'attributes':['id',_0xc3c6('0x6c')],'where':{'id':_0x242e2b[_0xc3c6('0x69')]['queueId']}});})[_0xc3c6('0x22')](function(_0x104038){if(_0x104038){_0x242e2b[_0xc3c6('0x47')][_0xc3c6('0x6d')]({'id':0x0,'priority':0x1,'app':_0xc3c6('0x72'),'appdata':_0x104038[_0xc3c6('0x6c')]+','+(_0x242e2b[_0xc3c6('0x3b')][_0xc3c6('0x73')]||0x12c),'interval':_0xc3c6('0x4e')});}return respondWithRpcPromise(_0xc3c6('0x74'),_0xc3c6('0x75'),_0x242e2b);})[_0xc3c6('0x22')](function(_0x2ec1b5){_0x59b2d9(_0x2ec1b5);})['catch'](function(_0x2e7a09){_0x30692f(_0x376e90[_0xc3c6('0x12')](0x1f4,_0x2e7a09[_0xc3c6('0x14')]));});});};
\ No newline at end of file