Built motion from commit da617fac.|2.6.6
[motion2.git] / server / services / email / lib / email.js
index 96951da..40e115e 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6581=['defaults','localhost','socket.io-emitter','./imap','./smtp','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','emit','name','active','Imap','messageStatus','isNil','refresh','hasOwnProperty','box','handleImapBox','handleImapEmail','bind','end','handleImapEnd','error','disabled','connected','total','messages','lastName','from','notify','then','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','stringify','lastSync','handleImapError','status','sendMail','Smtp','verify','verified','exports','lodash','bluebird','md5','ioredis','../../../config/logger','email','redis'];(function(_0x50b10d,_0xa721aa){var _0x4e5822=function(_0x2ba01c){while(--_0x2ba01c){_0x50b10d['push'](_0x50b10d['shift']());}};_0x4e5822(++_0xa721aa);}(_0x6581,0x199));var _0x1658=function(_0x274d9d,_0x3a9a8e){_0x274d9d=_0x274d9d-0x0;var _0x269995=_0x6581[_0x274d9d];return _0x269995;};'use strict';var _=require(_0x1658('0x0'));var moment=require('moment');var BPromise=require(_0x1658('0x1'));var md5=require(_0x1658('0x2'));var Redis=require(_0x1658('0x3'));var config=require('../../../config/environment');var logger=require(_0x1658('0x4'))(_0x1658('0x5'));config[_0x1658('0x6')]=_[_0x1658('0x7')](config[_0x1658('0x6')],{'host':_0x1658('0x8'),'port':0x18eb});var io=require(_0x1658('0x9'))(new Redis(config[_0x1658('0x6')]));var EmailImap=require(_0x1658('0xa'));var EmailSmtp=require(_0x1658('0xb'));var mailAccount=require('../rpc/mailAccount');var md5Accounts={};function EmailChannel(_0x3a0792){logger[_0x1658('0xc')](_0x1658('0xd'));this[_0x1658('0xe')]=_0x3a0792[_0x1658('0xe')];this[_0x1658('0xf')]={};this[_0x1658('0x10')]=new EmailSmtp();}EmailChannel[_0x1658('0x11')][_0x1658('0x12')]=function(_0x5025b0){var _0x35b042=this[_0x1658('0xe')][_0x5025b0];var _0x3c4938={'id':_0x35b042['id'],'name':_0x35b042[_0x1658('0x13')],'key':_0x35b042['key'],'active':_0x35b042[_0x1658('0x14')],'Imap':{'status':_0x35b042[_0x1658('0x15')]['status'],'messageStatus':_0x35b042['Imap'][_0x1658('0x16')],'total':_0x35b042[_0x1658('0x15')]['total']}};if(_[_0x1658('0x17')](md5Accounts[_0x5025b0])){md5Accounts[_0x5025b0]={};}var _0x7bae5=md5(JSON['stringify'](_0x3c4938));if(md5Accounts[_0x5025b0][_0x1658('0x2')]!==_0x7bae5){md5Accounts[_0x5025b0][_0x1658('0x2')]=_0x7bae5;io[_0x1658('0x12')]('mailAccount:update',_0x3c4938);}};EmailChannel[_0x1658('0x11')][_0x1658('0x18')]=function(_0x4ec371){for(var _0x314b19 in _0x4ec371){if(_0x4ec371[_0x1658('0x19')](_0x314b19)){if(_0x4ec371[_0x314b19]['Imap']&&_0x4ec371[_0x314b19][_0x1658('0x14')]){var _0x3e567f=_0x4ec371[_0x314b19][_0x1658('0x15')];if(!this['imapAccounts']['hasOwnProperty'](_0x3e567f['id'])){this['imapAccounts'][_0x3e567f['id']]=new EmailImap(_0x3e567f,_0x4ec371[_0x314b19][_0x1658('0x5')]);this[_0x1658('0xf')][_0x3e567f['id']]['on'](_0x1658('0x1a'),this[_0x1658('0x1b')]['bind'](this,_0x314b19));this['imapAccounts'][_0x3e567f['id']]['on'](_0x1658('0x5'),this[_0x1658('0x1c')][_0x1658('0x1d')](this,_0x314b19));this[_0x1658('0xf')][_0x3e567f['id']]['on'](_0x1658('0x1e'),this[_0x1658('0x1f')]['bind'](this,_0x314b19));this['imapAccounts'][_0x3e567f['id']]['on'](_0x1658('0x20'),this['handleImapError'][_0x1658('0x1d')](this,_0x314b19));}}else{if(_['isNil'](this[_0x1658('0xe')][_0x314b19][_0x1658('0x15')])){this[_0x1658('0xe')][_0x314b19]['Imap']={};}this[_0x1658('0xe')][_0x314b19][_0x1658('0x15')]['status']=_0x1658('0x21');this[_0x1658('0xe')][_0x314b19][_0x1658('0x15')][_0x1658('0x16')]='';this[_0x1658('0x12')](_0x314b19);}}}};EmailChannel[_0x1658('0x11')][_0x1658('0x1b')]=function(_0x302cea,_0x4ed1af){if(this[_0x1658('0xe')][_0x302cea]){this['mailAccounts'][_0x302cea][_0x1658('0x15')]['status']=_0x1658('0x22');this[_0x1658('0xe')][_0x302cea]['Imap'][_0x1658('0x16')]=_0x4ed1af['name'];if(_0x4ed1af['messages']){this[_0x1658('0xe')][_0x302cea][_0x1658('0x15')][_0x1658('0x23')]=_0x4ed1af[_0x1658('0x24')][_0x1658('0x23')];}return this[_0x1658('0x12')](_0x302cea);}};EmailChannel[_0x1658('0x11')]['handleImapEmail']=function(_0x29a7e1,_0x15cb78){logger[_0x1658('0xc')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x15cb78['firstName'],_0x15cb78[_0x1658('0x25')],_0x15cb78[_0x1658('0x26')],_0x29a7e1);if(this[_0x1658('0xe')][_0x29a7e1]){return mailAccount[_0x1658('0x27')](_0x29a7e1,_0x15cb78)[_0x1658('0x28')](function(_0x286869){if(_0x286869){logger[_0x1658('0xc')]('Mail\x20accepted\x20from\x20routing');}})[_0x1658('0x29')](function(_0x57bbb9){logger[_0x1658('0x20')](_0x1658('0x2a'),JSON[_0x1658('0x2b')](_0x57bbb9));});}};EmailChannel[_0x1658('0x11')]['handleImapEnd']=function(_0x504e83){if(this['mailAccounts'][_0x504e83]&&this[_0x1658('0xe')][_0x504e83][_0x1658('0x15')]){if(this[_0x1658('0xf')][this['mailAccounts'][_0x504e83][_0x1658('0x15')]['id']]){delete this[_0x1658('0xf')][this[_0x1658('0xe')][_0x504e83]['Imap']['id']];}this[_0x1658('0xe')][_0x504e83][_0x1658('0x15')][_0x1658('0x2c')]=moment();this['emit'](_0x504e83);}};EmailChannel[_0x1658('0x11')][_0x1658('0x2d')]=function(_0x257730,_0x1e9e66){if(this[_0x1658('0xe')][_0x257730]){this[_0x1658('0xe')][_0x257730][_0x1658('0x15')][_0x1658('0x2e')]=_0x1658('0x20');this[_0x1658('0xe')][_0x257730]['Imap']['messageStatus']=_0x1e9e66;return this['emit'](_0x257730);}};EmailChannel[_0x1658('0x11')][_0x1658('0x2f')]=function(_0x8f9a25,_0x1fe5ef){return this[_0x1658('0x10')]['send'](_0x8f9a25,_0x1fe5ef);};EmailChannel[_0x1658('0x11')]['verifySmtp']=function(_0x35ab3f){var _0x2997d0=this;if(this[_0x1658('0xe')][_0x35ab3f['id']]){if(_['isNil'](this[_0x1658('0xe')][_0x35ab3f['id']][_0x1658('0x30')])){this['mailAccounts'][_0x35ab3f['id']][_0x1658('0x30')]={};}this['mailAccounts'][_0x35ab3f['id']][_0x1658('0x30')]['lastSync']=moment();return new BPromise(function(_0x3dfe5f,_0x539549){return _0x2997d0[_0x1658('0x10')][_0x1658('0x31')](_0x35ab3f)['then'](function(_0xc4af02){_0x2997d0[_0x1658('0xe')][_0x35ab3f['id']][_0x1658('0x30')][_0x1658('0x2e')]=_0x1658('0x32');_0x2997d0[_0x1658('0xe')][_0x35ab3f['id']][_0x1658('0x30')][_0x1658('0x16')]='';_0x2997d0['emit'](_0x35ab3f['id']);_0x3dfe5f(_0xc4af02);})[_0x1658('0x29')](function(_0x46d4e3){_0x2997d0[_0x1658('0xe')][_0x35ab3f['id']][_0x1658('0x30')][_0x1658('0x2e')]=_0x1658('0x20');_0x2997d0[_0x1658('0xe')][_0x35ab3f['id']][_0x1658('0x30')]['messageStatus']=_0x46d4e3;_0x2997d0['emit'](_0x35ab3f['id']);_0x539549(_0x46d4e3);});});}return this[_0x1658('0x10')][_0x1658('0x31')](_0x35ab3f);};module[_0x1658('0x33')]=EmailChannel;
\ No newline at end of file
+var _0x87bd=['stringify','md5','emit','mailAccount:update','hasOwnProperty','active','service','custom','provider','imapAccounts','box','handleImapBox','bind','end','handleImapEnd','error','handleImapError','disabled','messageStatus','connected','messages','total','info','lastName','from','notify','then','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','sendMail','send','verifySmtp','Smtp','verify','verified','smtp','exports','lodash','moment','bluebird','ioredis','../../../config/logger','email','redis','defaults','localhost','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','start\x20email\x20channel','mailAccounts','prototype','name','key','status','Imap','isNil'];(function(_0x53cf8e,_0x3d290f){var _0x459197=function(_0x67073c){while(--_0x67073c){_0x53cf8e['push'](_0x53cf8e['shift']());}};_0x459197(++_0x3d290f);}(_0x87bd,0x117));var _0xd87b=function(_0x874cf1,_0x2a4954){_0x874cf1=_0x874cf1-0x0;var _0x233579=_0x87bd[_0x874cf1];return _0x233579;};'use strict';var _=require(_0xd87b('0x0'));var moment=require(_0xd87b('0x1'));var BPromise=require(_0xd87b('0x2'));var md5=require('md5');var Redis=require(_0xd87b('0x3'));var config=require('../../../config/environment');var logger=require(_0xd87b('0x4'))(_0xd87b('0x5'));config[_0xd87b('0x6')]=_[_0xd87b('0x7')](config[_0xd87b('0x6')],{'host':_0xd87b('0x8'),'port':0x18eb});var io=require(_0xd87b('0x9'))(new Redis(config[_0xd87b('0x6')]));var EmailImap=require(_0xd87b('0xa'));var EmailSmtp=require(_0xd87b('0xb'));var mailAccount=require(_0xd87b('0xc'));var md5Accounts={};function EmailChannel(_0x1f25c4){logger['info'](_0xd87b('0xd'));this[_0xd87b('0xe')]=_0x1f25c4[_0xd87b('0xe')];this['imapAccounts']={};this['smtp']=new EmailSmtp();}EmailChannel[_0xd87b('0xf')]['emit']=function(_0x5dd330){var _0x44f3d9=this[_0xd87b('0xe')][_0x5dd330];var _0x339ad7={'id':_0x44f3d9['id'],'name':_0x44f3d9[_0xd87b('0x10')],'key':_0x44f3d9[_0xd87b('0x11')],'active':_0x44f3d9['active'],'Imap':{'status':_0x44f3d9['Imap'][_0xd87b('0x12')],'messageStatus':_0x44f3d9[_0xd87b('0x13')]['messageStatus'],'total':_0x44f3d9[_0xd87b('0x13')]['total']}};if(_[_0xd87b('0x14')](md5Accounts[_0x5dd330])){md5Accounts[_0x5dd330]={};}var _0x1aeaba=md5(JSON[_0xd87b('0x15')](_0x339ad7));if(md5Accounts[_0x5dd330][_0xd87b('0x16')]!==_0x1aeaba){md5Accounts[_0x5dd330]['md5']=_0x1aeaba;io[_0xd87b('0x17')](_0xd87b('0x18'),_0x339ad7);}};EmailChannel[_0xd87b('0xf')]['refresh']=function(_0x241d17){for(var _0x2d91cf in _0x241d17){if(_0x241d17[_0xd87b('0x19')](_0x2d91cf)){if(_0x241d17[_0x2d91cf][_0xd87b('0x13')]&&_0x241d17[_0x2d91cf][_0xd87b('0x1a')]){var _0x42390b=_0x241d17[_0x2d91cf][_0xd87b('0x13')];if(!_0x42390b[_0xd87b('0x1b')]&&_0x241d17[_0x2d91cf]['provider']!==_0xd87b('0x1c'))_0x42390b[_0xd87b('0x1b')]=_0x241d17[_0x2d91cf][_0xd87b('0x1d')];if(!this[_0xd87b('0x1e')]['hasOwnProperty'](_0x42390b['id'])){this[_0xd87b('0x1e')][_0x42390b['id']]=new EmailImap(_0x42390b,_0x241d17[_0x2d91cf]['email']);this[_0xd87b('0x1e')][_0x42390b['id']]['on'](_0xd87b('0x1f'),this[_0xd87b('0x20')][_0xd87b('0x21')](this,_0x2d91cf));this[_0xd87b('0x1e')][_0x42390b['id']]['on'](_0xd87b('0x5'),this['handleImapEmail'][_0xd87b('0x21')](this,_0x2d91cf));this[_0xd87b('0x1e')][_0x42390b['id']]['on'](_0xd87b('0x22'),this[_0xd87b('0x23')]['bind'](this,_0x2d91cf));this[_0xd87b('0x1e')][_0x42390b['id']]['on'](_0xd87b('0x24'),this[_0xd87b('0x25')]['bind'](this,_0x2d91cf));}}else{if(_[_0xd87b('0x14')](this[_0xd87b('0xe')][_0x2d91cf][_0xd87b('0x13')])){this[_0xd87b('0xe')][_0x2d91cf][_0xd87b('0x13')]={};}this['mailAccounts'][_0x2d91cf][_0xd87b('0x13')][_0xd87b('0x12')]=_0xd87b('0x26');this[_0xd87b('0xe')][_0x2d91cf]['Imap'][_0xd87b('0x27')]='';this[_0xd87b('0x17')](_0x2d91cf);}}}};EmailChannel['prototype'][_0xd87b('0x20')]=function(_0xa423ec,_0x4b857b){if(this['mailAccounts'][_0xa423ec]){this[_0xd87b('0xe')][_0xa423ec]['Imap'][_0xd87b('0x12')]=_0xd87b('0x28');this[_0xd87b('0xe')][_0xa423ec][_0xd87b('0x13')]['messageStatus']=_0x4b857b[_0xd87b('0x10')];if(_0x4b857b[_0xd87b('0x29')]){this[_0xd87b('0xe')][_0xa423ec][_0xd87b('0x13')][_0xd87b('0x2a')]=_0x4b857b[_0xd87b('0x29')][_0xd87b('0x2a')];}return this[_0xd87b('0x17')](_0xa423ec);}};EmailChannel[_0xd87b('0xf')]['handleImapEmail']=function(_0x2bfcb9,_0x3fd56f){logger[_0xd87b('0x2b')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x3fd56f['firstName'],_0x3fd56f[_0xd87b('0x2c')],_0x3fd56f[_0xd87b('0x2d')],_0x2bfcb9);if(this[_0xd87b('0xe')][_0x2bfcb9]){return mailAccount[_0xd87b('0x2e')](_0x2bfcb9,_0x3fd56f)[_0xd87b('0x2f')](function(_0xcbbbd9){if(_0xcbbbd9){logger[_0xd87b('0x2b')](_0xd87b('0x30'));}})[_0xd87b('0x31')](function(_0x406e65){logger['error'](_0xd87b('0x32'),JSON['stringify'](_0x406e65));});}};EmailChannel[_0xd87b('0xf')][_0xd87b('0x23')]=function(_0x107cc9){if(this['mailAccounts'][_0x107cc9]&&this['mailAccounts'][_0x107cc9][_0xd87b('0x13')]){if(this['imapAccounts'][this['mailAccounts'][_0x107cc9][_0xd87b('0x13')]['id']]){delete this[_0xd87b('0x1e')][this[_0xd87b('0xe')][_0x107cc9][_0xd87b('0x13')]['id']];}this['mailAccounts'][_0x107cc9][_0xd87b('0x13')][_0xd87b('0x33')]=moment();this[_0xd87b('0x17')](_0x107cc9);}};EmailChannel[_0xd87b('0xf')][_0xd87b('0x25')]=function(_0x1d913f,_0x2ae8af){if(this[_0xd87b('0xe')][_0x1d913f]){this[_0xd87b('0xe')][_0x1d913f][_0xd87b('0x13')]['status']='error';this[_0xd87b('0xe')][_0x1d913f][_0xd87b('0x13')]['messageStatus']=_0x2ae8af;return this[_0xd87b('0x17')](_0x1d913f);}};EmailChannel[_0xd87b('0xf')][_0xd87b('0x34')]=function(_0x311f4f,_0x3707f4){return this['smtp'][_0xd87b('0x35')](_0x311f4f,_0x3707f4);};EmailChannel[_0xd87b('0xf')][_0xd87b('0x36')]=function(_0x2463b9){var _0xab80ab=this;if(this['mailAccounts'][_0x2463b9['id']]){if(_[_0xd87b('0x14')](this['mailAccounts'][_0x2463b9['id']][_0xd87b('0x37')])){this['mailAccounts'][_0x2463b9['id']][_0xd87b('0x37')]={};}this[_0xd87b('0xe')][_0x2463b9['id']][_0xd87b('0x37')][_0xd87b('0x33')]=moment();return new BPromise(function(_0x1bdf8a,_0x314d81){return _0xab80ab['smtp'][_0xd87b('0x38')](_0x2463b9)[_0xd87b('0x2f')](function(_0x47b1cd){_0xab80ab['mailAccounts'][_0x2463b9['id']]['Smtp'][_0xd87b('0x12')]=_0xd87b('0x39');_0xab80ab['mailAccounts'][_0x2463b9['id']][_0xd87b('0x37')]['messageStatus']='';_0xab80ab[_0xd87b('0x17')](_0x2463b9['id']);_0x1bdf8a(_0x47b1cd);})[_0xd87b('0x31')](function(_0x2b8e91){_0xab80ab[_0xd87b('0xe')][_0x2463b9['id']]['Smtp']['status']='error';_0xab80ab[_0xd87b('0xe')][_0x2463b9['id']][_0xd87b('0x37')][_0xd87b('0x27')]=_0x2b8e91;_0xab80ab[_0xd87b('0x17')](_0x2463b9['id']);_0x314d81(_0x2b8e91);});});}return this[_0xd87b('0x3a')][_0xd87b('0x38')](_0x2463b9);};module[_0xd87b('0x3b')]=EmailChannel;
\ No newline at end of file