Built motion from commit 8c034dcd.|2.6.31
[motion2.git] / server / services / email / lib / email.js
index a3423ae..5319c53 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xac23=['ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','info','mailAccounts','imapAccounts','smtp','prototype','emit','name','Imap','status','messageStatus','total','isNil','refresh','hasOwnProperty','active','service','custom','provider','handleImapBox','bind','handleImapEmail','end','handleImapEnd','error','handleImapError','disabled','connected','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','from','notify','then','Mail\x20accepted\x20from\x20routing','catch','lastSync','sendMail','verifySmtp','Smtp','verify','verified','lodash','moment','bluebird','md5'];(function(_0x50c3fe,_0x1d1776){var _0x50b2f2=function(_0x105468){while(--_0x105468){_0x50c3fe['push'](_0x50c3fe['shift']());}};_0x50b2f2(++_0x1d1776);}(_0xac23,0xd4));var _0x3ac2=function(_0x45313f,_0x46caf4){_0x45313f=_0x45313f-0x0;var _0x402910=_0xac23[_0x45313f];return _0x402910;};'use strict';var _=require(_0x3ac2('0x0'));var moment=require(_0x3ac2('0x1'));var BPromise=require(_0x3ac2('0x2'));var md5=require(_0x3ac2('0x3'));var Redis=require(_0x3ac2('0x4'));var config=require(_0x3ac2('0x5'));var logger=require(_0x3ac2('0x6'))(_0x3ac2('0x7'));config[_0x3ac2('0x8')]=_[_0x3ac2('0x9')](config[_0x3ac2('0x8')],{'host':'localhost','port':0x18eb});var io=require(_0x3ac2('0xa'))(new Redis(config[_0x3ac2('0x8')]));var EmailImap=require(_0x3ac2('0xb'));var EmailSmtp=require(_0x3ac2('0xc'));var mailAccount=require(_0x3ac2('0xd'));var md5Accounts={};function EmailChannel(_0x5d50d9){logger[_0x3ac2('0xe')]('start\x20email\x20channel');this[_0x3ac2('0xf')]=_0x5d50d9[_0x3ac2('0xf')];this[_0x3ac2('0x10')]={};this[_0x3ac2('0x11')]=new EmailSmtp();}EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x13')]=function(_0x2781e9){var _0x5ef9c4=this[_0x3ac2('0xf')][_0x2781e9];var _0x3a0c97={'id':_0x5ef9c4['id'],'name':_0x5ef9c4[_0x3ac2('0x14')],'key':_0x5ef9c4['key'],'active':_0x5ef9c4['active'],'Imap':{'status':_0x5ef9c4[_0x3ac2('0x15')][_0x3ac2('0x16')],'messageStatus':_0x5ef9c4[_0x3ac2('0x15')][_0x3ac2('0x17')],'total':_0x5ef9c4[_0x3ac2('0x15')][_0x3ac2('0x18')]}};if(_[_0x3ac2('0x19')](md5Accounts[_0x2781e9])){md5Accounts[_0x2781e9]={};}var _0x1f0b34=md5(JSON['stringify'](_0x3a0c97));if(md5Accounts[_0x2781e9]['md5']!==_0x1f0b34){md5Accounts[_0x2781e9][_0x3ac2('0x3')]=_0x1f0b34;io[_0x3ac2('0x13')]('mailAccount:update',_0x3a0c97);}};EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x1a')]=function(_0x27100c){for(var _0x44c52c in _0x27100c){if(_0x27100c[_0x3ac2('0x1b')](_0x44c52c)){if(_0x27100c[_0x44c52c][_0x3ac2('0x15')]&&_0x27100c[_0x44c52c][_0x3ac2('0x1c')]){var _0x5181e8=_0x27100c[_0x44c52c][_0x3ac2('0x15')];if(!_0x5181e8[_0x3ac2('0x1d')]&&_0x27100c[_0x44c52c]['provider']!==_0x3ac2('0x1e'))_0x5181e8['service']=_0x27100c[_0x44c52c][_0x3ac2('0x1f')];if(!this[_0x3ac2('0x10')][_0x3ac2('0x1b')](_0x5181e8['id'])){this[_0x3ac2('0x10')][_0x5181e8['id']]=new EmailImap(_0x5181e8,_0x27100c[_0x44c52c]['email']);this[_0x3ac2('0x10')][_0x5181e8['id']]['on']('box',this[_0x3ac2('0x20')][_0x3ac2('0x21')](this,_0x44c52c));this[_0x3ac2('0x10')][_0x5181e8['id']]['on']('email',this[_0x3ac2('0x22')][_0x3ac2('0x21')](this,_0x44c52c));this[_0x3ac2('0x10')][_0x5181e8['id']]['on'](_0x3ac2('0x23'),this[_0x3ac2('0x24')][_0x3ac2('0x21')](this,_0x44c52c));this[_0x3ac2('0x10')][_0x5181e8['id']]['on'](_0x3ac2('0x25'),this[_0x3ac2('0x26')][_0x3ac2('0x21')](this,_0x44c52c));}}else{if(_[_0x3ac2('0x19')](this[_0x3ac2('0xf')][_0x44c52c][_0x3ac2('0x15')])){this[_0x3ac2('0xf')][_0x44c52c]['Imap']={};}this[_0x3ac2('0xf')][_0x44c52c][_0x3ac2('0x15')][_0x3ac2('0x16')]=_0x3ac2('0x27');this['mailAccounts'][_0x44c52c][_0x3ac2('0x15')][_0x3ac2('0x17')]='';this['emit'](_0x44c52c);}}}};EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x20')]=function(_0x47fa4d,_0x50d300){if(this[_0x3ac2('0xf')][_0x47fa4d]){this[_0x3ac2('0xf')][_0x47fa4d][_0x3ac2('0x15')][_0x3ac2('0x16')]=_0x3ac2('0x28');this['mailAccounts'][_0x47fa4d][_0x3ac2('0x15')][_0x3ac2('0x17')]=_0x50d300[_0x3ac2('0x14')];if(_0x50d300['messages']){this[_0x3ac2('0xf')][_0x47fa4d]['Imap'][_0x3ac2('0x18')]=_0x50d300[_0x3ac2('0x29')][_0x3ac2('0x18')];}return this[_0x3ac2('0x13')](_0x47fa4d);}};EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x22')]=function(_0x1d104c,_0x1cfc88){logger['info'](_0x3ac2('0x2a'),_0x1cfc88['firstName'],_0x1cfc88['lastName'],_0x1cfc88[_0x3ac2('0x2b')],_0x1d104c);if(this[_0x3ac2('0xf')][_0x1d104c]){return mailAccount[_0x3ac2('0x2c')](_0x1d104c,_0x1cfc88)[_0x3ac2('0x2d')](function(_0x542637){if(_0x542637){logger[_0x3ac2('0xe')](_0x3ac2('0x2e'));}})[_0x3ac2('0x2f')](function(_0xbe4e38){logger[_0x3ac2('0x25')]('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON['stringify'](_0xbe4e38));});}};EmailChannel['prototype'][_0x3ac2('0x24')]=function(_0x50d7c2){if(this['mailAccounts'][_0x50d7c2]&&this[_0x3ac2('0xf')][_0x50d7c2][_0x3ac2('0x15')]){if(this['imapAccounts'][this[_0x3ac2('0xf')][_0x50d7c2]['Imap']['id']]){delete this[_0x3ac2('0x10')][this[_0x3ac2('0xf')][_0x50d7c2][_0x3ac2('0x15')]['id']];}this[_0x3ac2('0xf')][_0x50d7c2][_0x3ac2('0x15')][_0x3ac2('0x30')]=moment();this['emit'](_0x50d7c2);}};EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x26')]=function(_0x5d217a,_0x499c25){if(this['mailAccounts'][_0x5d217a]){this['mailAccounts'][_0x5d217a][_0x3ac2('0x15')]['status']='error';this[_0x3ac2('0xf')][_0x5d217a][_0x3ac2('0x15')][_0x3ac2('0x17')]=_0x499c25;return this[_0x3ac2('0x13')](_0x5d217a);}};EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x31')]=function(_0x50bab0,_0x1d4b5a){return this['smtp']['send'](_0x50bab0,_0x1d4b5a);};EmailChannel[_0x3ac2('0x12')][_0x3ac2('0x32')]=function(_0x40505a){var _0x29b4b8=this;if(this[_0x3ac2('0xf')][_0x40505a['id']]){if(_[_0x3ac2('0x19')](this[_0x3ac2('0xf')][_0x40505a['id']]['Smtp'])){this[_0x3ac2('0xf')][_0x40505a['id']]['Smtp']={};}this[_0x3ac2('0xf')][_0x40505a['id']][_0x3ac2('0x33')]['lastSync']=moment();return new BPromise(function(_0x4a2a97,_0x3db54d){return _0x29b4b8[_0x3ac2('0x11')][_0x3ac2('0x34')](_0x40505a)[_0x3ac2('0x2d')](function(_0x31aabc){_0x29b4b8['mailAccounts'][_0x40505a['id']][_0x3ac2('0x33')]['status']=_0x3ac2('0x35');_0x29b4b8[_0x3ac2('0xf')][_0x40505a['id']]['Smtp'][_0x3ac2('0x17')]='';_0x29b4b8[_0x3ac2('0x13')](_0x40505a['id']);_0x4a2a97(_0x31aabc);})[_0x3ac2('0x2f')](function(_0x519818){_0x29b4b8[_0x3ac2('0xf')][_0x40505a['id']][_0x3ac2('0x33')][_0x3ac2('0x16')]=_0x3ac2('0x25');_0x29b4b8['mailAccounts'][_0x40505a['id']]['Smtp'][_0x3ac2('0x17')]=_0x519818;_0x29b4b8[_0x3ac2('0x13')](_0x40505a['id']);_0x3db54d(_0x519818);});});}return this['smtp']['verify'](_0x40505a);};module['exports']=EmailChannel;
\ No newline at end of file
+var _0x96e6=['Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','send','Smtp','verify','verified','catch','exports','moment','bluebird','ioredis','../../../config/environment','../../../config/logger','email','defaults','socket.io-emitter','redis','./imap','../rpc/mailAccount','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','name','key','active','Imap','status','messageStatus','total','isNil','stringify','md5','mailAccount:update','hasOwnProperty','service','provider','custom','bind','handleImapEmail','end','handleImapEnd','error','handleImapError','disabled','emit','handleImapBox','messages','from','notify','then','Mail\x20accepted\x20from\x20routing'];(function(_0x5e77db,_0x356d1c){var _0x34b675=function(_0x4914b5){while(--_0x4914b5){_0x5e77db['push'](_0x5e77db['shift']());}};_0x34b675(++_0x356d1c);}(_0x96e6,0x116));var _0x696e=function(_0x47bc94,_0x1b1e48){_0x47bc94=_0x47bc94-0x0;var _0x4065c1=_0x96e6[_0x47bc94];return _0x4065c1;};'use strict';var _=require('lodash');var moment=require(_0x696e('0x0'));var BPromise=require(_0x696e('0x1'));var md5=require('md5');var Redis=require(_0x696e('0x2'));var config=require(_0x696e('0x3'));var logger=require(_0x696e('0x4'))(_0x696e('0x5'));config['redis']=_[_0x696e('0x6')](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x696e('0x7'))(new Redis(config[_0x696e('0x8')]));var EmailImap=require(_0x696e('0x9'));var EmailSmtp=require('./smtp');var mailAccount=require(_0x696e('0xa'));var md5Accounts={};function EmailChannel(_0x283b62){logger[_0x696e('0xb')](_0x696e('0xc'));this[_0x696e('0xd')]=_0x283b62['mailAccounts'];this[_0x696e('0xe')]={};this[_0x696e('0xf')]=new EmailSmtp();}EmailChannel[_0x696e('0x10')]['emit']=function(_0x506a80){var _0xfd2c86=this[_0x696e('0xd')][_0x506a80];var _0x485d65={'id':_0xfd2c86['id'],'name':_0xfd2c86[_0x696e('0x11')],'key':_0xfd2c86[_0x696e('0x12')],'active':_0xfd2c86[_0x696e('0x13')],'Imap':{'status':_0xfd2c86[_0x696e('0x14')][_0x696e('0x15')],'messageStatus':_0xfd2c86[_0x696e('0x14')][_0x696e('0x16')],'total':_0xfd2c86[_0x696e('0x14')][_0x696e('0x17')]}};if(_[_0x696e('0x18')](md5Accounts[_0x506a80])){md5Accounts[_0x506a80]={};}var _0x31c7e2=md5(JSON[_0x696e('0x19')](_0x485d65));if(md5Accounts[_0x506a80][_0x696e('0x1a')]!==_0x31c7e2){md5Accounts[_0x506a80][_0x696e('0x1a')]=_0x31c7e2;io['emit'](_0x696e('0x1b'),_0x485d65);}};EmailChannel['prototype']['refresh']=function(_0x592d00){for(var _0x43c73b in _0x592d00){if(_0x592d00[_0x696e('0x1c')](_0x43c73b)){if(_0x592d00[_0x43c73b][_0x696e('0x14')]&&_0x592d00[_0x43c73b]['active']){var _0x478725=_0x592d00[_0x43c73b][_0x696e('0x14')];if(!_0x478725[_0x696e('0x1d')]&&_0x592d00[_0x43c73b][_0x696e('0x1e')]!==_0x696e('0x1f'))_0x478725[_0x696e('0x1d')]=_0x592d00[_0x43c73b][_0x696e('0x1e')];if(!this[_0x696e('0xe')][_0x696e('0x1c')](_0x478725['id'])){this[_0x696e('0xe')][_0x478725['id']]=new EmailImap(_0x478725,_0x592d00[_0x43c73b][_0x696e('0x5')]);this[_0x696e('0xe')][_0x478725['id']]['on']('box',this['handleImapBox'][_0x696e('0x20')](this,_0x43c73b));this[_0x696e('0xe')][_0x478725['id']]['on'](_0x696e('0x5'),this[_0x696e('0x21')][_0x696e('0x20')](this,_0x43c73b));this['imapAccounts'][_0x478725['id']]['on'](_0x696e('0x22'),this[_0x696e('0x23')]['bind'](this,_0x43c73b));this[_0x696e('0xe')][_0x478725['id']]['on'](_0x696e('0x24'),this[_0x696e('0x25')][_0x696e('0x20')](this,_0x43c73b));}}else{if(_[_0x696e('0x18')](this[_0x696e('0xd')][_0x43c73b][_0x696e('0x14')])){this[_0x696e('0xd')][_0x43c73b][_0x696e('0x14')]={};}this[_0x696e('0xd')][_0x43c73b][_0x696e('0x14')][_0x696e('0x15')]=_0x696e('0x26');this[_0x696e('0xd')][_0x43c73b][_0x696e('0x14')][_0x696e('0x16')]='';this[_0x696e('0x27')](_0x43c73b);}}}};EmailChannel[_0x696e('0x10')][_0x696e('0x28')]=function(_0x455bc2,_0x3e6f46){if(this[_0x696e('0xd')][_0x455bc2]){this['mailAccounts'][_0x455bc2][_0x696e('0x14')]['status']='connected';this[_0x696e('0xd')][_0x455bc2][_0x696e('0x14')]['messageStatus']=_0x3e6f46[_0x696e('0x11')];if(_0x3e6f46[_0x696e('0x29')]){this['mailAccounts'][_0x455bc2][_0x696e('0x14')][_0x696e('0x17')]=_0x3e6f46[_0x696e('0x29')]['total'];}return this['emit'](_0x455bc2);}};EmailChannel[_0x696e('0x10')][_0x696e('0x21')]=function(_0x58bce3,_0x117921){logger[_0x696e('0xb')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x117921['firstName'],_0x117921['lastName'],_0x117921[_0x696e('0x2a')],_0x58bce3);if(this[_0x696e('0xd')][_0x58bce3]){return mailAccount[_0x696e('0x2b')](_0x58bce3,_0x117921)[_0x696e('0x2c')](function(_0x3a9fb5){if(_0x3a9fb5){logger[_0x696e('0xb')](_0x696e('0x2d'));}})['catch'](function(_0x585410){logger['error'](_0x696e('0x2e'),JSON[_0x696e('0x19')](_0x585410));});}};EmailChannel[_0x696e('0x10')]['handleImapEnd']=function(_0x43042e){if(this[_0x696e('0xd')][_0x43042e]&&this['mailAccounts'][_0x43042e][_0x696e('0x14')]){if(this[_0x696e('0xe')][this[_0x696e('0xd')][_0x43042e][_0x696e('0x14')]['id']]){delete this['imapAccounts'][this['mailAccounts'][_0x43042e][_0x696e('0x14')]['id']];}this[_0x696e('0xd')][_0x43042e][_0x696e('0x14')][_0x696e('0x2f')]=moment();this[_0x696e('0x27')](_0x43042e);}};EmailChannel[_0x696e('0x10')][_0x696e('0x25')]=function(_0x505d84,_0x1e5375){if(this[_0x696e('0xd')][_0x505d84]){this[_0x696e('0xd')][_0x505d84]['Imap'][_0x696e('0x15')]=_0x696e('0x24');this['mailAccounts'][_0x505d84][_0x696e('0x14')][_0x696e('0x16')]=_0x1e5375;return this[_0x696e('0x27')](_0x505d84);}};EmailChannel[_0x696e('0x10')]['sendMail']=function(_0x555f66,_0x46d0de){return this['smtp'][_0x696e('0x30')](_0x555f66,_0x46d0de);};EmailChannel[_0x696e('0x10')]['verifySmtp']=function(_0x14ed5e){var _0x37dda4=this;if(this[_0x696e('0xd')][_0x14ed5e['id']]){if(_[_0x696e('0x18')](this['mailAccounts'][_0x14ed5e['id']][_0x696e('0x31')])){this[_0x696e('0xd')][_0x14ed5e['id']][_0x696e('0x31')]={};}this[_0x696e('0xd')][_0x14ed5e['id']][_0x696e('0x31')][_0x696e('0x2f')]=moment();return new BPromise(function(_0x13660a,_0x4ad2d7){return _0x37dda4[_0x696e('0xf')][_0x696e('0x32')](_0x14ed5e)[_0x696e('0x2c')](function(_0x239e5a){_0x37dda4[_0x696e('0xd')][_0x14ed5e['id']][_0x696e('0x31')][_0x696e('0x15')]=_0x696e('0x33');_0x37dda4[_0x696e('0xd')][_0x14ed5e['id']][_0x696e('0x31')][_0x696e('0x16')]='';_0x37dda4[_0x696e('0x27')](_0x14ed5e['id']);_0x13660a(_0x239e5a);})[_0x696e('0x34')](function(_0x47ddbe){_0x37dda4[_0x696e('0xd')][_0x14ed5e['id']]['Smtp'][_0x696e('0x15')]=_0x696e('0x24');_0x37dda4['mailAccounts'][_0x14ed5e['id']]['Smtp'][_0x696e('0x16')]=_0x47ddbe;_0x37dda4[_0x696e('0x27')](_0x14ed5e['id']);_0x4ad2d7(_0x47ddbe);});});}return this[_0x696e('0xf')][_0x696e('0x32')](_0x14ed5e);};module[_0x696e('0x35')]=EmailChannel;
\ No newline at end of file