Built motion from commit fa4c4286.|2.6.29
[motion2.git] / server / services / email / lib / email.js
index dd2d3cf..5684c9a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3c2a=['localhost','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','emit','name','key','active','Imap','messageStatus','total','isNil','stringify','prototype','refresh','hasOwnProperty','service','provider','custom','box','handleImapBox','bind','end','error','status','connected','messages','handleImapEmail','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','notify','then','catch','handleImapEnd','lastSync','send','verifySmtp','Smtp','verify','verified','exports','lodash','moment','bluebird','md5','ioredis','../../../config/logger','email','redis','defaults'];(function(_0x5fa520,_0xaf0e7d){var _0x1bf6c4=function(_0x2a7440){while(--_0x2a7440){_0x5fa520['push'](_0x5fa520['shift']());}};_0x1bf6c4(++_0xaf0e7d);}(_0x3c2a,0x186));var _0xa3c2=function(_0x580693,_0x334344){_0x580693=_0x580693-0x0;var _0x339e33=_0x3c2a[_0x580693];return _0x339e33;};'use strict';var _=require(_0xa3c2('0x0'));var moment=require(_0xa3c2('0x1'));var BPromise=require(_0xa3c2('0x2'));var md5=require(_0xa3c2('0x3'));var Redis=require(_0xa3c2('0x4'));var config=require('../../../config/environment');var logger=require(_0xa3c2('0x5'))(_0xa3c2('0x6'));config[_0xa3c2('0x7')]=_[_0xa3c2('0x8')](config[_0xa3c2('0x7')],{'host':_0xa3c2('0x9'),'port':0x18eb});var io=require(_0xa3c2('0xa'))(new Redis(config[_0xa3c2('0x7')]));var EmailImap=require(_0xa3c2('0xb'));var EmailSmtp=require(_0xa3c2('0xc'));var mailAccount=require(_0xa3c2('0xd'));var md5Accounts={};function EmailChannel(_0x274d76){logger[_0xa3c2('0xe')](_0xa3c2('0xf'));this[_0xa3c2('0x10')]=_0x274d76[_0xa3c2('0x10')];this[_0xa3c2('0x11')]={};this[_0xa3c2('0x12')]=new EmailSmtp();}EmailChannel['prototype'][_0xa3c2('0x13')]=function(_0x32abcc){var _0x2d213b=this[_0xa3c2('0x10')][_0x32abcc];var _0x54e802={'id':_0x2d213b['id'],'name':_0x2d213b[_0xa3c2('0x14')],'key':_0x2d213b[_0xa3c2('0x15')],'active':_0x2d213b[_0xa3c2('0x16')],'Imap':{'status':_0x2d213b[_0xa3c2('0x17')]['status'],'messageStatus':_0x2d213b[_0xa3c2('0x17')][_0xa3c2('0x18')],'total':_0x2d213b[_0xa3c2('0x17')][_0xa3c2('0x19')]}};if(_[_0xa3c2('0x1a')](md5Accounts[_0x32abcc])){md5Accounts[_0x32abcc]={};}var _0x3382e9=md5(JSON[_0xa3c2('0x1b')](_0x54e802));if(md5Accounts[_0x32abcc][_0xa3c2('0x3')]!==_0x3382e9){md5Accounts[_0x32abcc][_0xa3c2('0x3')]=_0x3382e9;io[_0xa3c2('0x13')]('mailAccount:update',_0x54e802);}};EmailChannel[_0xa3c2('0x1c')][_0xa3c2('0x1d')]=function(_0x3aca31){for(var _0x1fd895 in _0x3aca31){if(_0x3aca31[_0xa3c2('0x1e')](_0x1fd895)){if(_0x3aca31[_0x1fd895][_0xa3c2('0x17')]&&_0x3aca31[_0x1fd895][_0xa3c2('0x16')]){var _0x34ca97=_0x3aca31[_0x1fd895][_0xa3c2('0x17')];if(!_0x34ca97[_0xa3c2('0x1f')]&&_0x3aca31[_0x1fd895][_0xa3c2('0x20')]!==_0xa3c2('0x21'))_0x34ca97[_0xa3c2('0x1f')]=_0x3aca31[_0x1fd895][_0xa3c2('0x20')];if(!this[_0xa3c2('0x11')]['hasOwnProperty'](_0x34ca97['id'])){this[_0xa3c2('0x11')][_0x34ca97['id']]=new EmailImap(_0x34ca97,_0x3aca31[_0x1fd895][_0xa3c2('0x6')]);this[_0xa3c2('0x11')][_0x34ca97['id']]['on'](_0xa3c2('0x22'),this[_0xa3c2('0x23')]['bind'](this,_0x1fd895));this['imapAccounts'][_0x34ca97['id']]['on']('email',this['handleImapEmail'][_0xa3c2('0x24')](this,_0x1fd895));this['imapAccounts'][_0x34ca97['id']]['on'](_0xa3c2('0x25'),this['handleImapEnd'][_0xa3c2('0x24')](this,_0x1fd895));this['imapAccounts'][_0x34ca97['id']]['on'](_0xa3c2('0x26'),this['handleImapError'][_0xa3c2('0x24')](this,_0x1fd895));}}else{if(_[_0xa3c2('0x1a')](this[_0xa3c2('0x10')][_0x1fd895][_0xa3c2('0x17')])){this[_0xa3c2('0x10')][_0x1fd895][_0xa3c2('0x17')]={};}this[_0xa3c2('0x10')][_0x1fd895]['Imap']['status']='disabled';this['mailAccounts'][_0x1fd895]['Imap'][_0xa3c2('0x18')]='';this[_0xa3c2('0x13')](_0x1fd895);}}}};EmailChannel[_0xa3c2('0x1c')][_0xa3c2('0x23')]=function(_0x48672a,_0x4df431){if(this[_0xa3c2('0x10')][_0x48672a]){this['mailAccounts'][_0x48672a]['Imap'][_0xa3c2('0x27')]=_0xa3c2('0x28');this['mailAccounts'][_0x48672a]['Imap'][_0xa3c2('0x18')]=_0x4df431['name'];if(_0x4df431['messages']){this['mailAccounts'][_0x48672a]['Imap'][_0xa3c2('0x19')]=_0x4df431[_0xa3c2('0x29')][_0xa3c2('0x19')];}return this[_0xa3c2('0x13')](_0x48672a);}};EmailChannel[_0xa3c2('0x1c')][_0xa3c2('0x2a')]=function(_0x54e49c,_0x1c4b03){logger['info'](_0xa3c2('0x2b'),_0x1c4b03[_0xa3c2('0x2c')],_0x1c4b03[_0xa3c2('0x2d')],_0x1c4b03['from'],_0x54e49c);if(this[_0xa3c2('0x10')][_0x54e49c]){return mailAccount[_0xa3c2('0x2e')](_0x54e49c,_0x1c4b03)[_0xa3c2('0x2f')](function(_0xba83c6){if(_0xba83c6){logger[_0xa3c2('0xe')]('Mail\x20accepted\x20from\x20routing');}})[_0xa3c2('0x30')](function(_0x5888c5){logger[_0xa3c2('0x26')]('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON[_0xa3c2('0x1b')](_0x5888c5));});}};EmailChannel['prototype'][_0xa3c2('0x31')]=function(_0x2e986a){if(this[_0xa3c2('0x10')][_0x2e986a]&&this[_0xa3c2('0x10')][_0x2e986a]['Imap']){if(this[_0xa3c2('0x11')][this['mailAccounts'][_0x2e986a]['Imap']['id']]){delete this[_0xa3c2('0x11')][this[_0xa3c2('0x10')][_0x2e986a][_0xa3c2('0x17')]['id']];}this[_0xa3c2('0x10')][_0x2e986a]['Imap'][_0xa3c2('0x32')]=moment();this[_0xa3c2('0x13')](_0x2e986a);}};EmailChannel[_0xa3c2('0x1c')]['handleImapError']=function(_0x48a113,_0x149f62){if(this[_0xa3c2('0x10')][_0x48a113]){this['mailAccounts'][_0x48a113]['Imap'][_0xa3c2('0x27')]=_0xa3c2('0x26');this[_0xa3c2('0x10')][_0x48a113][_0xa3c2('0x17')][_0xa3c2('0x18')]=_0x149f62;return this[_0xa3c2('0x13')](_0x48a113);}};EmailChannel[_0xa3c2('0x1c')]['sendMail']=function(_0xad626b,_0x5a6afe){return this['smtp'][_0xa3c2('0x33')](_0xad626b,_0x5a6afe);};EmailChannel['prototype'][_0xa3c2('0x34')]=function(_0x49275b){var _0x4dfbe6=this;if(this[_0xa3c2('0x10')][_0x49275b['id']]){if(_['isNil'](this[_0xa3c2('0x10')][_0x49275b['id']][_0xa3c2('0x35')])){this[_0xa3c2('0x10')][_0x49275b['id']][_0xa3c2('0x35')]={};}this[_0xa3c2('0x10')][_0x49275b['id']][_0xa3c2('0x35')][_0xa3c2('0x32')]=moment();return new BPromise(function(_0x4e67fa,_0x54026f){return _0x4dfbe6['smtp'][_0xa3c2('0x36')](_0x49275b)[_0xa3c2('0x2f')](function(_0x58ac48){_0x4dfbe6[_0xa3c2('0x10')][_0x49275b['id']][_0xa3c2('0x35')][_0xa3c2('0x27')]=_0xa3c2('0x37');_0x4dfbe6['mailAccounts'][_0x49275b['id']][_0xa3c2('0x35')][_0xa3c2('0x18')]='';_0x4dfbe6[_0xa3c2('0x13')](_0x49275b['id']);_0x4e67fa(_0x58ac48);})['catch'](function(_0x235f91){_0x4dfbe6[_0xa3c2('0x10')][_0x49275b['id']][_0xa3c2('0x35')][_0xa3c2('0x27')]=_0xa3c2('0x26');_0x4dfbe6[_0xa3c2('0x10')][_0x49275b['id']]['Smtp'][_0xa3c2('0x18')]=_0x235f91;_0x4dfbe6[_0xa3c2('0x13')](_0x49275b['id']);_0x54026f(_0x235f91);});});}return this[_0xa3c2('0x12')][_0xa3c2('0x36')](_0x49275b);};module[_0xa3c2('0x38')]=EmailChannel;
\ No newline at end of file
+var _0xc04b=['provider','box','handleImapBox','bind','handleImapEmail','end','handleImapEnd','handleImapError','disabled','status','connected','name','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','notify','catch','stringify','lastSync','sendMail','send','verifySmtp','Smtp','verify','then','verified','error','lodash','moment','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','localhost','./imap','../rpc/mailAccount','info','mailAccounts','imapAccounts','smtp','prototype','emit','key','active','Imap','messageStatus','total','isNil','refresh','hasOwnProperty','service'];(function(_0x1ab346,_0x4f7c23){var _0x4e3fc5=function(_0x47b2f5){while(--_0x47b2f5){_0x1ab346['push'](_0x1ab346['shift']());}};_0x4e3fc5(++_0x4f7c23);}(_0xc04b,0xbc));var _0xbc04=function(_0x352e0c,_0x29076a){_0x352e0c=_0x352e0c-0x0;var _0x428195=_0xc04b[_0x352e0c];return _0x428195;};'use strict';var _=require(_0xbc04('0x0'));var moment=require(_0xbc04('0x1'));var BPromise=require(_0xbc04('0x2'));var md5=require(_0xbc04('0x3'));var Redis=require(_0xbc04('0x4'));var config=require(_0xbc04('0x5'));var logger=require(_0xbc04('0x6'))(_0xbc04('0x7'));config[_0xbc04('0x8')]=_[_0xbc04('0x9')](config['redis'],{'host':_0xbc04('0xa'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xbc04('0x8')]));var EmailImap=require(_0xbc04('0xb'));var EmailSmtp=require('./smtp');var mailAccount=require(_0xbc04('0xc'));var md5Accounts={};function EmailChannel(_0x54cf76){logger[_0xbc04('0xd')]('start\x20email\x20channel');this[_0xbc04('0xe')]=_0x54cf76[_0xbc04('0xe')];this[_0xbc04('0xf')]={};this[_0xbc04('0x10')]=new EmailSmtp();}EmailChannel[_0xbc04('0x11')][_0xbc04('0x12')]=function(_0x351a6d){var _0x570874=this[_0xbc04('0xe')][_0x351a6d];var _0x53b72a={'id':_0x570874['id'],'name':_0x570874['name'],'key':_0x570874[_0xbc04('0x13')],'active':_0x570874[_0xbc04('0x14')],'Imap':{'status':_0x570874[_0xbc04('0x15')]['status'],'messageStatus':_0x570874[_0xbc04('0x15')][_0xbc04('0x16')],'total':_0x570874[_0xbc04('0x15')][_0xbc04('0x17')]}};if(_[_0xbc04('0x18')](md5Accounts[_0x351a6d])){md5Accounts[_0x351a6d]={};}var _0x399cb2=md5(JSON['stringify'](_0x53b72a));if(md5Accounts[_0x351a6d][_0xbc04('0x3')]!==_0x399cb2){md5Accounts[_0x351a6d][_0xbc04('0x3')]=_0x399cb2;io[_0xbc04('0x12')]('mailAccount:update',_0x53b72a);}};EmailChannel[_0xbc04('0x11')][_0xbc04('0x19')]=function(_0x55b34f){for(var _0x7510c1 in _0x55b34f){if(_0x55b34f[_0xbc04('0x1a')](_0x7510c1)){if(_0x55b34f[_0x7510c1][_0xbc04('0x15')]&&_0x55b34f[_0x7510c1][_0xbc04('0x14')]){var _0x579926=_0x55b34f[_0x7510c1]['Imap'];if(!_0x579926[_0xbc04('0x1b')]&&_0x55b34f[_0x7510c1][_0xbc04('0x1c')]!=='custom')_0x579926[_0xbc04('0x1b')]=_0x55b34f[_0x7510c1][_0xbc04('0x1c')];if(!this['imapAccounts']['hasOwnProperty'](_0x579926['id'])){this['imapAccounts'][_0x579926['id']]=new EmailImap(_0x579926,_0x55b34f[_0x7510c1][_0xbc04('0x7')]);this[_0xbc04('0xf')][_0x579926['id']]['on'](_0xbc04('0x1d'),this[_0xbc04('0x1e')][_0xbc04('0x1f')](this,_0x7510c1));this[_0xbc04('0xf')][_0x579926['id']]['on'](_0xbc04('0x7'),this[_0xbc04('0x20')]['bind'](this,_0x7510c1));this['imapAccounts'][_0x579926['id']]['on'](_0xbc04('0x21'),this[_0xbc04('0x22')]['bind'](this,_0x7510c1));this[_0xbc04('0xf')][_0x579926['id']]['on']('error',this[_0xbc04('0x23')][_0xbc04('0x1f')](this,_0x7510c1));}}else{if(_[_0xbc04('0x18')](this[_0xbc04('0xe')][_0x7510c1]['Imap'])){this[_0xbc04('0xe')][_0x7510c1][_0xbc04('0x15')]={};}this[_0xbc04('0xe')][_0x7510c1][_0xbc04('0x15')]['status']=_0xbc04('0x24');this[_0xbc04('0xe')][_0x7510c1][_0xbc04('0x15')][_0xbc04('0x16')]='';this[_0xbc04('0x12')](_0x7510c1);}}}};EmailChannel[_0xbc04('0x11')][_0xbc04('0x1e')]=function(_0x1d91bc,_0x1c44c7){if(this[_0xbc04('0xe')][_0x1d91bc]){this[_0xbc04('0xe')][_0x1d91bc][_0xbc04('0x15')][_0xbc04('0x25')]=_0xbc04('0x26');this[_0xbc04('0xe')][_0x1d91bc][_0xbc04('0x15')][_0xbc04('0x16')]=_0x1c44c7[_0xbc04('0x27')];if(_0x1c44c7[_0xbc04('0x28')]){this[_0xbc04('0xe')][_0x1d91bc][_0xbc04('0x15')]['total']=_0x1c44c7[_0xbc04('0x28')]['total'];}return this[_0xbc04('0x12')](_0x1d91bc);}};EmailChannel[_0xbc04('0x11')][_0xbc04('0x20')]=function(_0x92c370,_0x38349e){logger[_0xbc04('0xd')](_0xbc04('0x29'),_0x38349e['firstName'],_0x38349e['lastName'],_0x38349e['from'],_0x92c370);if(this[_0xbc04('0xe')][_0x92c370]){return mailAccount[_0xbc04('0x2a')](_0x92c370,_0x38349e)['then'](function(_0x184411){if(_0x184411){logger[_0xbc04('0xd')]('Mail\x20accepted\x20from\x20routing');}})[_0xbc04('0x2b')](function(_0x4c53f9){logger['error']('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON[_0xbc04('0x2c')](_0x4c53f9));});}};EmailChannel[_0xbc04('0x11')][_0xbc04('0x22')]=function(_0x258e83){if(this['mailAccounts'][_0x258e83]&&this['mailAccounts'][_0x258e83][_0xbc04('0x15')]){if(this[_0xbc04('0xf')][this[_0xbc04('0xe')][_0x258e83]['Imap']['id']]){delete this[_0xbc04('0xf')][this[_0xbc04('0xe')][_0x258e83][_0xbc04('0x15')]['id']];}this['mailAccounts'][_0x258e83][_0xbc04('0x15')][_0xbc04('0x2d')]=moment();this['emit'](_0x258e83);}};EmailChannel['prototype']['handleImapError']=function(_0x114075,_0x36a5ae){if(this[_0xbc04('0xe')][_0x114075]){this[_0xbc04('0xe')][_0x114075][_0xbc04('0x15')][_0xbc04('0x25')]='error';this[_0xbc04('0xe')][_0x114075][_0xbc04('0x15')][_0xbc04('0x16')]=_0x36a5ae;return this[_0xbc04('0x12')](_0x114075);}};EmailChannel['prototype'][_0xbc04('0x2e')]=function(_0x26d307,_0x46f987){return this['smtp'][_0xbc04('0x2f')](_0x26d307,_0x46f987);};EmailChannel[_0xbc04('0x11')][_0xbc04('0x30')]=function(_0x43a90f){var _0x5a3596=this;if(this[_0xbc04('0xe')][_0x43a90f['id']]){if(_[_0xbc04('0x18')](this[_0xbc04('0xe')][_0x43a90f['id']][_0xbc04('0x31')])){this[_0xbc04('0xe')][_0x43a90f['id']][_0xbc04('0x31')]={};}this['mailAccounts'][_0x43a90f['id']]['Smtp'][_0xbc04('0x2d')]=moment();return new BPromise(function(_0x359652,_0x484f13){return _0x5a3596[_0xbc04('0x10')][_0xbc04('0x32')](_0x43a90f)[_0xbc04('0x33')](function(_0x354865){_0x5a3596[_0xbc04('0xe')][_0x43a90f['id']]['Smtp']['status']=_0xbc04('0x34');_0x5a3596[_0xbc04('0xe')][_0x43a90f['id']][_0xbc04('0x31')][_0xbc04('0x16')]='';_0x5a3596[_0xbc04('0x12')](_0x43a90f['id']);_0x359652(_0x354865);})['catch'](function(_0x509d1a){_0x5a3596['mailAccounts'][_0x43a90f['id']][_0xbc04('0x31')][_0xbc04('0x25')]=_0xbc04('0x35');_0x5a3596[_0xbc04('0xe')][_0x43a90f['id']]['Smtp'][_0xbc04('0x16')]=_0x509d1a;_0x5a3596[_0xbc04('0x12')](_0x43a90f['id']);_0x484f13(_0x509d1a);});});}return this['smtp'][_0xbc04('0x32')](_0x43a90f);};module['exports']=EmailChannel;
\ No newline at end of file