Built motion from commit 3d3e98f2.|2.6.29
[motion2.git] / server / services / email / lib / email.js
index 3fd776f..70421c9 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x9734=['firstName','lastName','from','notify','then','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','sendMail','verifySmtp','Smtp','verify','exports','moment','bluebird','md5','email','redis','defaults','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','emit','name','key','Imap','messageStatus','total','isNil','stringify','mailAccount:update','refresh','hasOwnProperty','active','provider','custom','service','box','handleImapBox','bind','handleImapEmail','end','handleImapEnd','error','handleImapError','status','disabled','connected','messages'];(function(_0x233de7,_0x109f02){var _0x26940c=function(_0x474b79){while(--_0x474b79){_0x233de7['push'](_0x233de7['shift']());}};_0x26940c(++_0x109f02);}(_0x9734,0x164));var _0x4973=function(_0x8afdd0,_0x548ad1){_0x8afdd0=_0x8afdd0-0x0;var _0x3de7ac=_0x9734[_0x8afdd0];return _0x3de7ac;};'use strict';var _=require('lodash');var moment=require(_0x4973('0x0'));var BPromise=require(_0x4973('0x1'));var md5=require(_0x4973('0x2'));var Redis=require('ioredis');var config=require('../../../config/environment');var logger=require('../../../config/logger')(_0x4973('0x3'));config[_0x4973('0x4')]=_[_0x4973('0x5')](config[_0x4973('0x4')],{'host':'localhost','port':0x18eb});var io=require(_0x4973('0x6'))(new Redis(config[_0x4973('0x4')]));var EmailImap=require(_0x4973('0x7'));var EmailSmtp=require(_0x4973('0x8'));var mailAccount=require(_0x4973('0x9'));var md5Accounts={};function EmailChannel(_0x28782c){logger[_0x4973('0xa')](_0x4973('0xb'));this[_0x4973('0xc')]=_0x28782c[_0x4973('0xc')];this[_0x4973('0xd')]={};this[_0x4973('0xe')]=new EmailSmtp();}EmailChannel[_0x4973('0xf')][_0x4973('0x10')]=function(_0x37cc16){var _0x576993=this['mailAccounts'][_0x37cc16];var _0x2df1d4={'id':_0x576993['id'],'name':_0x576993[_0x4973('0x11')],'key':_0x576993[_0x4973('0x12')],'active':_0x576993['active'],'Imap':{'status':_0x576993[_0x4973('0x13')]['status'],'messageStatus':_0x576993[_0x4973('0x13')][_0x4973('0x14')],'total':_0x576993[_0x4973('0x13')][_0x4973('0x15')]}};if(_[_0x4973('0x16')](md5Accounts[_0x37cc16])){md5Accounts[_0x37cc16]={};}var _0xf93909=md5(JSON[_0x4973('0x17')](_0x2df1d4));if(md5Accounts[_0x37cc16][_0x4973('0x2')]!==_0xf93909){md5Accounts[_0x37cc16][_0x4973('0x2')]=_0xf93909;io['emit'](_0x4973('0x18'),_0x2df1d4);}};EmailChannel[_0x4973('0xf')][_0x4973('0x19')]=function(_0x491b15){for(var _0x3cd348 in _0x491b15){if(_0x491b15[_0x4973('0x1a')](_0x3cd348)){if(_0x491b15[_0x3cd348]['Imap']&&_0x491b15[_0x3cd348][_0x4973('0x1b')]){var _0x10d6de=_0x491b15[_0x3cd348][_0x4973('0x13')];if(!_0x10d6de['service']&&_0x491b15[_0x3cd348][_0x4973('0x1c')]!==_0x4973('0x1d'))_0x10d6de[_0x4973('0x1e')]=_0x491b15[_0x3cd348][_0x4973('0x1c')];if(!this[_0x4973('0xd')][_0x4973('0x1a')](_0x10d6de['id'])){this[_0x4973('0xd')][_0x10d6de['id']]=new EmailImap(_0x10d6de,_0x491b15[_0x3cd348][_0x4973('0x3')]);this[_0x4973('0xd')][_0x10d6de['id']]['on'](_0x4973('0x1f'),this[_0x4973('0x20')][_0x4973('0x21')](this,_0x3cd348));this[_0x4973('0xd')][_0x10d6de['id']]['on'](_0x4973('0x3'),this[_0x4973('0x22')][_0x4973('0x21')](this,_0x3cd348));this['imapAccounts'][_0x10d6de['id']]['on'](_0x4973('0x23'),this[_0x4973('0x24')][_0x4973('0x21')](this,_0x3cd348));this[_0x4973('0xd')][_0x10d6de['id']]['on'](_0x4973('0x25'),this[_0x4973('0x26')][_0x4973('0x21')](this,_0x3cd348));}}else{if(_[_0x4973('0x16')](this[_0x4973('0xc')][_0x3cd348][_0x4973('0x13')])){this[_0x4973('0xc')][_0x3cd348][_0x4973('0x13')]={};}this[_0x4973('0xc')][_0x3cd348][_0x4973('0x13')][_0x4973('0x27')]=_0x4973('0x28');this[_0x4973('0xc')][_0x3cd348]['Imap']['messageStatus']='';this[_0x4973('0x10')](_0x3cd348);}}}};EmailChannel['prototype'][_0x4973('0x20')]=function(_0x349b7f,_0x1c80ea){if(this[_0x4973('0xc')][_0x349b7f]){this[_0x4973('0xc')][_0x349b7f][_0x4973('0x13')]['status']=_0x4973('0x29');this[_0x4973('0xc')][_0x349b7f][_0x4973('0x13')][_0x4973('0x14')]=_0x1c80ea['name'];if(_0x1c80ea[_0x4973('0x2a')]){this[_0x4973('0xc')][_0x349b7f][_0x4973('0x13')]['total']=_0x1c80ea[_0x4973('0x2a')][_0x4973('0x15')];}return this[_0x4973('0x10')](_0x349b7f);}};EmailChannel[_0x4973('0xf')][_0x4973('0x22')]=function(_0xf9c13e,_0x5e00cc){logger['info']('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x5e00cc[_0x4973('0x2b')],_0x5e00cc[_0x4973('0x2c')],_0x5e00cc[_0x4973('0x2d')],_0xf9c13e);if(this[_0x4973('0xc')][_0xf9c13e]){return mailAccount[_0x4973('0x2e')](_0xf9c13e,_0x5e00cc)[_0x4973('0x2f')](function(_0x219158){if(_0x219158){logger[_0x4973('0xa')](_0x4973('0x30'));}})[_0x4973('0x31')](function(_0x5a1b97){logger['error'](_0x4973('0x32'),JSON[_0x4973('0x17')](_0x5a1b97));});}};EmailChannel[_0x4973('0xf')][_0x4973('0x24')]=function(_0x832ed5){if(this['mailAccounts'][_0x832ed5]&&this[_0x4973('0xc')][_0x832ed5]['Imap']){if(this['imapAccounts'][this[_0x4973('0xc')][_0x832ed5][_0x4973('0x13')]['id']]){delete this[_0x4973('0xd')][this[_0x4973('0xc')][_0x832ed5][_0x4973('0x13')]['id']];}this['mailAccounts'][_0x832ed5][_0x4973('0x13')][_0x4973('0x33')]=moment();this[_0x4973('0x10')](_0x832ed5);}};EmailChannel[_0x4973('0xf')]['handleImapError']=function(_0x2095ef,_0x2311af){if(this[_0x4973('0xc')][_0x2095ef]){this[_0x4973('0xc')][_0x2095ef][_0x4973('0x13')][_0x4973('0x27')]=_0x4973('0x25');this[_0x4973('0xc')][_0x2095ef][_0x4973('0x13')][_0x4973('0x14')]=_0x2311af;return this[_0x4973('0x10')](_0x2095ef);}};EmailChannel[_0x4973('0xf')][_0x4973('0x34')]=function(_0x3cafa6,_0x3bcbe6){return this[_0x4973('0xe')]['send'](_0x3cafa6,_0x3bcbe6);};EmailChannel[_0x4973('0xf')][_0x4973('0x35')]=function(_0x439976){var _0x2ccdd7=this;if(this['mailAccounts'][_0x439976['id']]){if(_[_0x4973('0x16')](this[_0x4973('0xc')][_0x439976['id']]['Smtp'])){this[_0x4973('0xc')][_0x439976['id']][_0x4973('0x36')]={};}this[_0x4973('0xc')][_0x439976['id']][_0x4973('0x36')][_0x4973('0x33')]=moment();return new BPromise(function(_0x1e7120,_0x11a819){return _0x2ccdd7['smtp'][_0x4973('0x37')](_0x439976)[_0x4973('0x2f')](function(_0x35c07d){_0x2ccdd7[_0x4973('0xc')][_0x439976['id']][_0x4973('0x36')][_0x4973('0x27')]='verified';_0x2ccdd7[_0x4973('0xc')][_0x439976['id']][_0x4973('0x36')]['messageStatus']='';_0x2ccdd7[_0x4973('0x10')](_0x439976['id']);_0x1e7120(_0x35c07d);})[_0x4973('0x31')](function(_0x56f204){_0x2ccdd7['mailAccounts'][_0x439976['id']][_0x4973('0x36')][_0x4973('0x27')]=_0x4973('0x25');_0x2ccdd7[_0x4973('0xc')][_0x439976['id']][_0x4973('0x36')][_0x4973('0x14')]=_0x56f204;_0x2ccdd7['emit'](_0x439976['id']);_0x11a819(_0x56f204);});});}return this[_0x4973('0xe')][_0x4973('0x37')](_0x439976);};module[_0x4973('0x38')]=EmailChannel;
\ No newline at end of file
+var _0xde12=['Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','sendMail','send','verifySmtp','Smtp','lastSync','verify','verified','exports','moment','md5','ioredis','../../../config/environment','email','socket.io-emitter','redis','./imap','./smtp','../rpc/mailAccount','start\x20email\x20channel','mailAccounts','smtp','prototype','key','Imap','status','total','isNil','stringify','emit','mailAccount:update','refresh','provider','custom','service','imapAccounts','hasOwnProperty','box','handleImapBox','handleImapEmail','bind','end','handleImapEnd','error','disabled','messageStatus','connected','messages','info','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','notify','then'];(function(_0x514244,_0x332d0d){var _0x5785aa=function(_0x5166b8){while(--_0x5166b8){_0x514244['push'](_0x514244['shift']());}};_0x5785aa(++_0x332d0d);}(_0xde12,0x123));var _0x2de1=function(_0x642692,_0x1a7664){_0x642692=_0x642692-0x0;var _0xec9006=_0xde12[_0x642692];return _0xec9006;};'use strict';var _=require('lodash');var moment=require(_0x2de1('0x0'));var BPromise=require('bluebird');var md5=require(_0x2de1('0x1'));var Redis=require(_0x2de1('0x2'));var config=require(_0x2de1('0x3'));var logger=require('../../../config/logger')(_0x2de1('0x4'));config['redis']=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x2de1('0x5'))(new Redis(config[_0x2de1('0x6')]));var EmailImap=require(_0x2de1('0x7'));var EmailSmtp=require(_0x2de1('0x8'));var mailAccount=require(_0x2de1('0x9'));var md5Accounts={};function EmailChannel(_0xf378ea){logger['info'](_0x2de1('0xa'));this[_0x2de1('0xb')]=_0xf378ea[_0x2de1('0xb')];this['imapAccounts']={};this[_0x2de1('0xc')]=new EmailSmtp();}EmailChannel[_0x2de1('0xd')]['emit']=function(_0x13892c){var _0x3d5f81=this[_0x2de1('0xb')][_0x13892c];var _0x1fac44={'id':_0x3d5f81['id'],'name':_0x3d5f81['name'],'key':_0x3d5f81[_0x2de1('0xe')],'active':_0x3d5f81['active'],'Imap':{'status':_0x3d5f81[_0x2de1('0xf')][_0x2de1('0x10')],'messageStatus':_0x3d5f81['Imap']['messageStatus'],'total':_0x3d5f81[_0x2de1('0xf')][_0x2de1('0x11')]}};if(_[_0x2de1('0x12')](md5Accounts[_0x13892c])){md5Accounts[_0x13892c]={};}var _0x2aaeb1=md5(JSON[_0x2de1('0x13')](_0x1fac44));if(md5Accounts[_0x13892c][_0x2de1('0x1')]!==_0x2aaeb1){md5Accounts[_0x13892c][_0x2de1('0x1')]=_0x2aaeb1;io[_0x2de1('0x14')](_0x2de1('0x15'),_0x1fac44);}};EmailChannel[_0x2de1('0xd')][_0x2de1('0x16')]=function(_0x1efd85){for(var _0x6fccf3 in _0x1efd85){if(_0x1efd85['hasOwnProperty'](_0x6fccf3)){if(_0x1efd85[_0x6fccf3][_0x2de1('0xf')]&&_0x1efd85[_0x6fccf3]['active']){var _0x5287ef=_0x1efd85[_0x6fccf3][_0x2de1('0xf')];if(!_0x5287ef['service']&&_0x1efd85[_0x6fccf3][_0x2de1('0x17')]!==_0x2de1('0x18'))_0x5287ef[_0x2de1('0x19')]=_0x1efd85[_0x6fccf3][_0x2de1('0x17')];if(!this[_0x2de1('0x1a')][_0x2de1('0x1b')](_0x5287ef['id'])){this[_0x2de1('0x1a')][_0x5287ef['id']]=new EmailImap(_0x5287ef,_0x1efd85[_0x6fccf3][_0x2de1('0x4')]);this[_0x2de1('0x1a')][_0x5287ef['id']]['on'](_0x2de1('0x1c'),this[_0x2de1('0x1d')]['bind'](this,_0x6fccf3));this[_0x2de1('0x1a')][_0x5287ef['id']]['on'](_0x2de1('0x4'),this[_0x2de1('0x1e')][_0x2de1('0x1f')](this,_0x6fccf3));this['imapAccounts'][_0x5287ef['id']]['on'](_0x2de1('0x20'),this[_0x2de1('0x21')][_0x2de1('0x1f')](this,_0x6fccf3));this[_0x2de1('0x1a')][_0x5287ef['id']]['on'](_0x2de1('0x22'),this['handleImapError'][_0x2de1('0x1f')](this,_0x6fccf3));}}else{if(_[_0x2de1('0x12')](this[_0x2de1('0xb')][_0x6fccf3]['Imap'])){this[_0x2de1('0xb')][_0x6fccf3][_0x2de1('0xf')]={};}this[_0x2de1('0xb')][_0x6fccf3][_0x2de1('0xf')][_0x2de1('0x10')]=_0x2de1('0x23');this['mailAccounts'][_0x6fccf3][_0x2de1('0xf')][_0x2de1('0x24')]='';this[_0x2de1('0x14')](_0x6fccf3);}}}};EmailChannel[_0x2de1('0xd')][_0x2de1('0x1d')]=function(_0x1e560d,_0x3be32c){if(this[_0x2de1('0xb')][_0x1e560d]){this[_0x2de1('0xb')][_0x1e560d][_0x2de1('0xf')][_0x2de1('0x10')]=_0x2de1('0x25');this[_0x2de1('0xb')][_0x1e560d][_0x2de1('0xf')][_0x2de1('0x24')]=_0x3be32c['name'];if(_0x3be32c[_0x2de1('0x26')]){this[_0x2de1('0xb')][_0x1e560d]['Imap'][_0x2de1('0x11')]=_0x3be32c[_0x2de1('0x26')][_0x2de1('0x11')];}return this[_0x2de1('0x14')](_0x1e560d);}};EmailChannel[_0x2de1('0xd')][_0x2de1('0x1e')]=function(_0x32bcf6,_0x1b575e){logger[_0x2de1('0x27')](_0x2de1('0x28'),_0x1b575e[_0x2de1('0x29')],_0x1b575e[_0x2de1('0x2a')],_0x1b575e['from'],_0x32bcf6);if(this['mailAccounts'][_0x32bcf6]){return mailAccount[_0x2de1('0x2b')](_0x32bcf6,_0x1b575e)[_0x2de1('0x2c')](function(_0x3367af){if(_0x3367af){logger['info'](_0x2de1('0x2d'));}})[_0x2de1('0x2e')](function(_0x434478){logger['error'](_0x2de1('0x2f'),JSON[_0x2de1('0x13')](_0x434478));});}};EmailChannel[_0x2de1('0xd')][_0x2de1('0x21')]=function(_0x2cf5b8){if(this['mailAccounts'][_0x2cf5b8]&&this[_0x2de1('0xb')][_0x2cf5b8][_0x2de1('0xf')]){if(this[_0x2de1('0x1a')][this[_0x2de1('0xb')][_0x2cf5b8]['Imap']['id']]){delete this[_0x2de1('0x1a')][this[_0x2de1('0xb')][_0x2cf5b8][_0x2de1('0xf')]['id']];}this['mailAccounts'][_0x2cf5b8][_0x2de1('0xf')]['lastSync']=moment();this['emit'](_0x2cf5b8);}};EmailChannel[_0x2de1('0xd')]['handleImapError']=function(_0x148364,_0x21dc02){if(this[_0x2de1('0xb')][_0x148364]){this[_0x2de1('0xb')][_0x148364][_0x2de1('0xf')][_0x2de1('0x10')]=_0x2de1('0x22');this[_0x2de1('0xb')][_0x148364]['Imap']['messageStatus']=_0x21dc02;return this[_0x2de1('0x14')](_0x148364);}};EmailChannel[_0x2de1('0xd')][_0x2de1('0x30')]=function(_0x41aca6,_0x1d0d76){return this[_0x2de1('0xc')][_0x2de1('0x31')](_0x41aca6,_0x1d0d76);};EmailChannel[_0x2de1('0xd')][_0x2de1('0x32')]=function(_0x451e51){var _0xf0d2b3=this;if(this[_0x2de1('0xb')][_0x451e51['id']]){if(_['isNil'](this[_0x2de1('0xb')][_0x451e51['id']]['Smtp'])){this[_0x2de1('0xb')][_0x451e51['id']][_0x2de1('0x33')]={};}this[_0x2de1('0xb')][_0x451e51['id']][_0x2de1('0x33')][_0x2de1('0x34')]=moment();return new BPromise(function(_0x15a7dc,_0xae8a13){return _0xf0d2b3[_0x2de1('0xc')][_0x2de1('0x35')](_0x451e51)[_0x2de1('0x2c')](function(_0x45bf1c){_0xf0d2b3[_0x2de1('0xb')][_0x451e51['id']]['Smtp'][_0x2de1('0x10')]=_0x2de1('0x36');_0xf0d2b3[_0x2de1('0xb')][_0x451e51['id']][_0x2de1('0x33')][_0x2de1('0x24')]='';_0xf0d2b3['emit'](_0x451e51['id']);_0x15a7dc(_0x45bf1c);})[_0x2de1('0x2e')](function(_0x55c4fa){_0xf0d2b3[_0x2de1('0xb')][_0x451e51['id']][_0x2de1('0x33')]['status']=_0x2de1('0x22');_0xf0d2b3[_0x2de1('0xb')][_0x451e51['id']][_0x2de1('0x33')][_0x2de1('0x24')]=_0x55c4fa;_0xf0d2b3[_0x2de1('0x14')](_0x451e51['id']);_0xae8a13(_0x55c4fa);});});}return this[_0x2de1('0xc')][_0x2de1('0x35')](_0x451e51);};module[_0x2de1('0x37')]=EmailChannel;
\ No newline at end of file