Built motion from commit 44377920.|2.6.11
[motion2.git] / server / services / email / lib / email.js
index d20a2f2..48d7a62 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x1e82=['start\x20email\x20channel','mailAccounts','imapAccounts','prototype','emit','key','active','Imap','messageStatus','isNil','stringify','refresh','hasOwnProperty','service','provider','handleImapBox','bind','handleImapEmail','error','handleImapError','status','name','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','from','notify','then','Mail\x20accepted\x20from\x20routing','catch','handleImapEnd','sendMail','smtp','send','verifySmtp','Smtp','lastSync','verified','verify','exports','lodash','moment','bluebird','md5','../../../config/environment','../../../config/logger','email','redis','localhost','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','info'];(function(_0x20a584,_0xe384a5){var _0x4b41a8=function(_0x2127c6){while(--_0x2127c6){_0x20a584['push'](_0x20a584['shift']());}};_0x4b41a8(++_0xe384a5);}(_0x1e82,0xce));var _0x21e8=function(_0x59ebb1,_0x1d4a68){_0x59ebb1=_0x59ebb1-0x0;var _0x5afcc1=_0x1e82[_0x59ebb1];return _0x5afcc1;};'use strict';var _=require(_0x21e8('0x0'));var moment=require(_0x21e8('0x1'));var BPromise=require(_0x21e8('0x2'));var md5=require(_0x21e8('0x3'));var Redis=require('ioredis');var config=require(_0x21e8('0x4'));var logger=require(_0x21e8('0x5'))(_0x21e8('0x6'));config[_0x21e8('0x7')]=_['defaults'](config[_0x21e8('0x7')],{'host':_0x21e8('0x8'),'port':0x18eb});var io=require(_0x21e8('0x9'))(new Redis(config[_0x21e8('0x7')]));var EmailImap=require(_0x21e8('0xa'));var EmailSmtp=require(_0x21e8('0xb'));var mailAccount=require(_0x21e8('0xc'));var md5Accounts={};function EmailChannel(_0x538fde){logger[_0x21e8('0xd')](_0x21e8('0xe'));this[_0x21e8('0xf')]=_0x538fde[_0x21e8('0xf')];this[_0x21e8('0x10')]={};this['smtp']=new EmailSmtp();}EmailChannel[_0x21e8('0x11')][_0x21e8('0x12')]=function(_0x1239eb){var _0x8ceaa=this[_0x21e8('0xf')][_0x1239eb];var _0xd147c0={'id':_0x8ceaa['id'],'name':_0x8ceaa['name'],'key':_0x8ceaa[_0x21e8('0x13')],'active':_0x8ceaa[_0x21e8('0x14')],'Imap':{'status':_0x8ceaa['Imap']['status'],'messageStatus':_0x8ceaa[_0x21e8('0x15')][_0x21e8('0x16')],'total':_0x8ceaa[_0x21e8('0x15')]['total']}};if(_[_0x21e8('0x17')](md5Accounts[_0x1239eb])){md5Accounts[_0x1239eb]={};}var _0x3b6058=md5(JSON[_0x21e8('0x18')](_0xd147c0));if(md5Accounts[_0x1239eb][_0x21e8('0x3')]!==_0x3b6058){md5Accounts[_0x1239eb][_0x21e8('0x3')]=_0x3b6058;io[_0x21e8('0x12')]('mailAccount:update',_0xd147c0);}};EmailChannel['prototype'][_0x21e8('0x19')]=function(_0xebb9ec){for(var _0x1a8975 in _0xebb9ec){if(_0xebb9ec[_0x21e8('0x1a')](_0x1a8975)){if(_0xebb9ec[_0x1a8975][_0x21e8('0x15')]&&_0xebb9ec[_0x1a8975][_0x21e8('0x14')]){var _0x115379=_0xebb9ec[_0x1a8975]['Imap'];if(!_0x115379[_0x21e8('0x1b')]&&_0xebb9ec[_0x1a8975][_0x21e8('0x1c')]!=='custom')_0x115379[_0x21e8('0x1b')]=_0xebb9ec[_0x1a8975][_0x21e8('0x1c')];if(!this[_0x21e8('0x10')]['hasOwnProperty'](_0x115379['id'])){this['imapAccounts'][_0x115379['id']]=new EmailImap(_0x115379,_0xebb9ec[_0x1a8975][_0x21e8('0x6')]);this[_0x21e8('0x10')][_0x115379['id']]['on']('box',this[_0x21e8('0x1d')][_0x21e8('0x1e')](this,_0x1a8975));this['imapAccounts'][_0x115379['id']]['on'](_0x21e8('0x6'),this[_0x21e8('0x1f')]['bind'](this,_0x1a8975));this[_0x21e8('0x10')][_0x115379['id']]['on']('end',this['handleImapEnd']['bind'](this,_0x1a8975));this[_0x21e8('0x10')][_0x115379['id']]['on'](_0x21e8('0x20'),this[_0x21e8('0x21')][_0x21e8('0x1e')](this,_0x1a8975));}}else{if(_['isNil'](this[_0x21e8('0xf')][_0x1a8975][_0x21e8('0x15')])){this[_0x21e8('0xf')][_0x1a8975]['Imap']={};}this['mailAccounts'][_0x1a8975][_0x21e8('0x15')][_0x21e8('0x22')]='disabled';this['mailAccounts'][_0x1a8975][_0x21e8('0x15')][_0x21e8('0x16')]='';this[_0x21e8('0x12')](_0x1a8975);}}}};EmailChannel[_0x21e8('0x11')][_0x21e8('0x1d')]=function(_0x36047f,_0x297bb1){if(this[_0x21e8('0xf')][_0x36047f]){this[_0x21e8('0xf')][_0x36047f][_0x21e8('0x15')][_0x21e8('0x22')]='connected';this[_0x21e8('0xf')][_0x36047f][_0x21e8('0x15')]['messageStatus']=_0x297bb1[_0x21e8('0x23')];if(_0x297bb1['messages']){this['mailAccounts'][_0x36047f][_0x21e8('0x15')]['total']=_0x297bb1[_0x21e8('0x24')]['total'];}return this['emit'](_0x36047f);}};EmailChannel[_0x21e8('0x11')][_0x21e8('0x1f')]=function(_0x1535d4,_0x35dcd4){logger[_0x21e8('0xd')](_0x21e8('0x25'),_0x35dcd4[_0x21e8('0x26')],_0x35dcd4[_0x21e8('0x27')],_0x35dcd4[_0x21e8('0x28')],_0x1535d4);if(this[_0x21e8('0xf')][_0x1535d4]){return mailAccount[_0x21e8('0x29')](_0x1535d4,_0x35dcd4)[_0x21e8('0x2a')](function(_0x5745cc){if(_0x5745cc){logger[_0x21e8('0xd')](_0x21e8('0x2b'));}})[_0x21e8('0x2c')](function(_0x5e2d86){logger[_0x21e8('0x20')]('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON['stringify'](_0x5e2d86));});}};EmailChannel[_0x21e8('0x11')][_0x21e8('0x2d')]=function(_0x4285c0){if(this[_0x21e8('0xf')][_0x4285c0]&&this['mailAccounts'][_0x4285c0][_0x21e8('0x15')]){if(this['imapAccounts'][this[_0x21e8('0xf')][_0x4285c0]['Imap']['id']]){delete this['imapAccounts'][this[_0x21e8('0xf')][_0x4285c0][_0x21e8('0x15')]['id']];}this[_0x21e8('0xf')][_0x4285c0][_0x21e8('0x15')]['lastSync']=moment();this[_0x21e8('0x12')](_0x4285c0);}};EmailChannel['prototype'][_0x21e8('0x21')]=function(_0x135970,_0xf7be93){if(this[_0x21e8('0xf')][_0x135970]){this[_0x21e8('0xf')][_0x135970]['Imap'][_0x21e8('0x22')]=_0x21e8('0x20');this[_0x21e8('0xf')][_0x135970][_0x21e8('0x15')]['messageStatus']=_0xf7be93;return this[_0x21e8('0x12')](_0x135970);}};EmailChannel[_0x21e8('0x11')][_0x21e8('0x2e')]=function(_0x555ec3,_0x2cf44a){return this[_0x21e8('0x2f')][_0x21e8('0x30')](_0x555ec3,_0x2cf44a);};EmailChannel[_0x21e8('0x11')][_0x21e8('0x31')]=function(_0x3f1d9d){var _0x18065a=this;if(this['mailAccounts'][_0x3f1d9d['id']]){if(_[_0x21e8('0x17')](this[_0x21e8('0xf')][_0x3f1d9d['id']]['Smtp'])){this[_0x21e8('0xf')][_0x3f1d9d['id']][_0x21e8('0x32')]={};}this['mailAccounts'][_0x3f1d9d['id']][_0x21e8('0x32')][_0x21e8('0x33')]=moment();return new BPromise(function(_0x2650b5,_0x4a433a){return _0x18065a[_0x21e8('0x2f')]['verify'](_0x3f1d9d)[_0x21e8('0x2a')](function(_0x48bb2e){_0x18065a[_0x21e8('0xf')][_0x3f1d9d['id']][_0x21e8('0x32')][_0x21e8('0x22')]=_0x21e8('0x34');_0x18065a[_0x21e8('0xf')][_0x3f1d9d['id']]['Smtp'][_0x21e8('0x16')]='';_0x18065a[_0x21e8('0x12')](_0x3f1d9d['id']);_0x2650b5(_0x48bb2e);})[_0x21e8('0x2c')](function(_0x3f782b){_0x18065a[_0x21e8('0xf')][_0x3f1d9d['id']][_0x21e8('0x32')]['status']=_0x21e8('0x20');_0x18065a[_0x21e8('0xf')][_0x3f1d9d['id']][_0x21e8('0x32')][_0x21e8('0x16')]=_0x3f782b;_0x18065a[_0x21e8('0x12')](_0x3f1d9d['id']);_0x4a433a(_0x3f782b);});});}return this[_0x21e8('0x2f')][_0x21e8('0x35')](_0x3f1d9d);};module[_0x21e8('0x36')]=EmailChannel;
\ No newline at end of file
+var _0x31c0=['verify','then','verified','exports','moment','bluebird','ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','localhost','socket.io-emitter','../rpc/mailAccount','info','start\x20email\x20channel','mailAccounts','imapAccounts','prototype','emit','name','key','active','Imap','messageStatus','isNil','stringify','md5','refresh','service','provider','hasOwnProperty','handleImapBox','bind','handleImapEmail','handleImapEnd','error','handleImapError','disabled','status','total','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','from','catch','sendMail','smtp','send','Smtp','lastSync'];(function(_0x4237d3,_0xc5b850){var _0x5ce29b=function(_0x232fe3){while(--_0x232fe3){_0x4237d3['push'](_0x4237d3['shift']());}};_0x5ce29b(++_0xc5b850);}(_0x31c0,0xa3));var _0x031c=function(_0x5001b6,_0x4bff81){_0x5001b6=_0x5001b6-0x0;var _0x40488c=_0x31c0[_0x5001b6];return _0x40488c;};'use strict';var _=require('lodash');var moment=require(_0x031c('0x0'));var BPromise=require(_0x031c('0x1'));var md5=require('md5');var Redis=require(_0x031c('0x2'));var config=require(_0x031c('0x3'));var logger=require(_0x031c('0x4'))(_0x031c('0x5'));config[_0x031c('0x6')]=_[_0x031c('0x7')](config[_0x031c('0x6')],{'host':_0x031c('0x8'),'port':0x18eb});var io=require(_0x031c('0x9'))(new Redis(config[_0x031c('0x6')]));var EmailImap=require('./imap');var EmailSmtp=require('./smtp');var mailAccount=require(_0x031c('0xa'));var md5Accounts={};function EmailChannel(_0x13e510){logger[_0x031c('0xb')](_0x031c('0xc'));this[_0x031c('0xd')]=_0x13e510[_0x031c('0xd')];this[_0x031c('0xe')]={};this['smtp']=new EmailSmtp();}EmailChannel[_0x031c('0xf')][_0x031c('0x10')]=function(_0x15a0f8){var _0x30f146=this[_0x031c('0xd')][_0x15a0f8];var _0x4881ea={'id':_0x30f146['id'],'name':_0x30f146[_0x031c('0x11')],'key':_0x30f146[_0x031c('0x12')],'active':_0x30f146[_0x031c('0x13')],'Imap':{'status':_0x30f146[_0x031c('0x14')]['status'],'messageStatus':_0x30f146['Imap'][_0x031c('0x15')],'total':_0x30f146['Imap']['total']}};if(_[_0x031c('0x16')](md5Accounts[_0x15a0f8])){md5Accounts[_0x15a0f8]={};}var _0x5ef7ad=md5(JSON[_0x031c('0x17')](_0x4881ea));if(md5Accounts[_0x15a0f8][_0x031c('0x18')]!==_0x5ef7ad){md5Accounts[_0x15a0f8]['md5']=_0x5ef7ad;io[_0x031c('0x10')]('mailAccount:update',_0x4881ea);}};EmailChannel[_0x031c('0xf')][_0x031c('0x19')]=function(_0x4164ae){for(var _0x56e675 in _0x4164ae){if(_0x4164ae['hasOwnProperty'](_0x56e675)){if(_0x4164ae[_0x56e675][_0x031c('0x14')]&&_0x4164ae[_0x56e675][_0x031c('0x13')]){var _0x327341=_0x4164ae[_0x56e675][_0x031c('0x14')];if(!_0x327341[_0x031c('0x1a')]&&_0x4164ae[_0x56e675][_0x031c('0x1b')]!=='custom')_0x327341[_0x031c('0x1a')]=_0x4164ae[_0x56e675][_0x031c('0x1b')];if(!this['imapAccounts'][_0x031c('0x1c')](_0x327341['id'])){this[_0x031c('0xe')][_0x327341['id']]=new EmailImap(_0x327341,_0x4164ae[_0x56e675][_0x031c('0x5')]);this[_0x031c('0xe')][_0x327341['id']]['on']('box',this[_0x031c('0x1d')][_0x031c('0x1e')](this,_0x56e675));this[_0x031c('0xe')][_0x327341['id']]['on'](_0x031c('0x5'),this[_0x031c('0x1f')]['bind'](this,_0x56e675));this[_0x031c('0xe')][_0x327341['id']]['on']('end',this[_0x031c('0x20')][_0x031c('0x1e')](this,_0x56e675));this[_0x031c('0xe')][_0x327341['id']]['on'](_0x031c('0x21'),this[_0x031c('0x22')][_0x031c('0x1e')](this,_0x56e675));}}else{if(_['isNil'](this[_0x031c('0xd')][_0x56e675][_0x031c('0x14')])){this['mailAccounts'][_0x56e675]['Imap']={};}this[_0x031c('0xd')][_0x56e675]['Imap']['status']=_0x031c('0x23');this[_0x031c('0xd')][_0x56e675][_0x031c('0x14')][_0x031c('0x15')]='';this[_0x031c('0x10')](_0x56e675);}}}};EmailChannel['prototype'][_0x031c('0x1d')]=function(_0x320fdd,_0x1d41bc){if(this[_0x031c('0xd')][_0x320fdd]){this[_0x031c('0xd')][_0x320fdd][_0x031c('0x14')][_0x031c('0x24')]='connected';this[_0x031c('0xd')][_0x320fdd][_0x031c('0x14')]['messageStatus']=_0x1d41bc[_0x031c('0x11')];if(_0x1d41bc['messages']){this['mailAccounts'][_0x320fdd][_0x031c('0x14')][_0x031c('0x25')]=_0x1d41bc[_0x031c('0x26')][_0x031c('0x25')];}return this[_0x031c('0x10')](_0x320fdd);}};EmailChannel[_0x031c('0xf')][_0x031c('0x1f')]=function(_0x4f802f,_0x5256aa){logger['info'](_0x031c('0x27'),_0x5256aa[_0x031c('0x28')],_0x5256aa[_0x031c('0x29')],_0x5256aa[_0x031c('0x2a')],_0x4f802f);if(this['mailAccounts'][_0x4f802f]){return mailAccount['notify'](_0x4f802f,_0x5256aa)['then'](function(_0x380183){if(_0x380183){logger[_0x031c('0xb')]('Mail\x20accepted\x20from\x20routing');}})[_0x031c('0x2b')](function(_0x4577b5){logger[_0x031c('0x21')]('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON[_0x031c('0x17')](_0x4577b5));});}};EmailChannel[_0x031c('0xf')]['handleImapEnd']=function(_0x348c53){if(this[_0x031c('0xd')][_0x348c53]&&this[_0x031c('0xd')][_0x348c53][_0x031c('0x14')]){if(this['imapAccounts'][this['mailAccounts'][_0x348c53][_0x031c('0x14')]['id']]){delete this['imapAccounts'][this[_0x031c('0xd')][_0x348c53][_0x031c('0x14')]['id']];}this[_0x031c('0xd')][_0x348c53][_0x031c('0x14')]['lastSync']=moment();this[_0x031c('0x10')](_0x348c53);}};EmailChannel[_0x031c('0xf')][_0x031c('0x22')]=function(_0x2fdaae,_0x2cc796){if(this[_0x031c('0xd')][_0x2fdaae]){this[_0x031c('0xd')][_0x2fdaae]['Imap'][_0x031c('0x24')]=_0x031c('0x21');this[_0x031c('0xd')][_0x2fdaae][_0x031c('0x14')]['messageStatus']=_0x2cc796;return this[_0x031c('0x10')](_0x2fdaae);}};EmailChannel[_0x031c('0xf')][_0x031c('0x2c')]=function(_0x22980d,_0x572a82){return this[_0x031c('0x2d')][_0x031c('0x2e')](_0x22980d,_0x572a82);};EmailChannel['prototype']['verifySmtp']=function(_0x511615){var _0x9ae504=this;if(this[_0x031c('0xd')][_0x511615['id']]){if(_[_0x031c('0x16')](this['mailAccounts'][_0x511615['id']][_0x031c('0x2f')])){this['mailAccounts'][_0x511615['id']][_0x031c('0x2f')]={};}this[_0x031c('0xd')][_0x511615['id']]['Smtp'][_0x031c('0x30')]=moment();return new BPromise(function(_0x42e355,_0x4be715){return _0x9ae504['smtp'][_0x031c('0x31')](_0x511615)[_0x031c('0x32')](function(_0x4bafa1){_0x9ae504[_0x031c('0xd')][_0x511615['id']][_0x031c('0x2f')]['status']=_0x031c('0x33');_0x9ae504['mailAccounts'][_0x511615['id']][_0x031c('0x2f')]['messageStatus']='';_0x9ae504['emit'](_0x511615['id']);_0x42e355(_0x4bafa1);})[_0x031c('0x2b')](function(_0x4b3af6){_0x9ae504[_0x031c('0xd')][_0x511615['id']][_0x031c('0x2f')][_0x031c('0x24')]='error';_0x9ae504['mailAccounts'][_0x511615['id']][_0x031c('0x2f')][_0x031c('0x15')]=_0x4b3af6;_0x9ae504[_0x031c('0x10')](_0x511615['id']);_0x4be715(_0x4b3af6);});});}return this['smtp'][_0x031c('0x31')](_0x511615);};module[_0x031c('0x34')]=EmailChannel;
\ No newline at end of file