Built motion from commit a8c4dd89.|2.6.33
[motion2.git] / server / services / email / lib / email.js
index bc730c0..48f9e85 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5bc7=['catch','exports','lodash','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','defaults','localhost','socket.io-emitter','redis','./smtp','info','start\x20email\x20channel','mailAccounts','imapAccounts','prototype','name','key','active','Imap','status','total','stringify','emit','mailAccount:update','refresh','hasOwnProperty','service','provider','custom','box','handleImapBox','bind','handleImapEmail','end','handleImapEnd','handleImapError','isNil','disabled','messageStatus','connected','messages','lastName','Mail\x20accepted\x20from\x20routing','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','sendMail','smtp','send','verifySmtp','Smtp','verify','then','verified'];(function(_0xfdf5c0,_0x54029d){var _0x27578a=function(_0x22913c){while(--_0x22913c){_0xfdf5c0['push'](_0xfdf5c0['shift']());}};_0x27578a(++_0x54029d);}(_0x5bc7,0xea));var _0x75bc=function(_0x376d9a,_0x26a6d9){_0x376d9a=_0x376d9a-0x0;var _0x5a12ea=_0x5bc7[_0x376d9a];return _0x5a12ea;};'use strict';var _=require(_0x75bc('0x0'));var moment=require('moment');var BPromise=require(_0x75bc('0x1'));var md5=require(_0x75bc('0x2'));var Redis=require(_0x75bc('0x3'));var config=require(_0x75bc('0x4'));var logger=require(_0x75bc('0x5'))(_0x75bc('0x6'));config['redis']=_[_0x75bc('0x7')](config['redis'],{'host':_0x75bc('0x8'),'port':0x18eb});var io=require(_0x75bc('0x9'))(new Redis(config[_0x75bc('0xa')]));var EmailImap=require('./imap');var EmailSmtp=require(_0x75bc('0xb'));var mailAccount=require('../rpc/mailAccount');var md5Accounts={};function EmailChannel(_0xf5cc2f){logger[_0x75bc('0xc')](_0x75bc('0xd'));this['mailAccounts']=_0xf5cc2f[_0x75bc('0xe')];this[_0x75bc('0xf')]={};this['smtp']=new EmailSmtp();}EmailChannel[_0x75bc('0x10')]['emit']=function(_0x3c6b23){var _0x8c5712=this['mailAccounts'][_0x3c6b23];var _0x3f5c86={'id':_0x8c5712['id'],'name':_0x8c5712[_0x75bc('0x11')],'key':_0x8c5712[_0x75bc('0x12')],'active':_0x8c5712[_0x75bc('0x13')],'Imap':{'status':_0x8c5712[_0x75bc('0x14')][_0x75bc('0x15')],'messageStatus':_0x8c5712[_0x75bc('0x14')]['messageStatus'],'total':_0x8c5712['Imap'][_0x75bc('0x16')]}};if(_['isNil'](md5Accounts[_0x3c6b23])){md5Accounts[_0x3c6b23]={};}var _0x731b15=md5(JSON[_0x75bc('0x17')](_0x3f5c86));if(md5Accounts[_0x3c6b23][_0x75bc('0x2')]!==_0x731b15){md5Accounts[_0x3c6b23]['md5']=_0x731b15;io[_0x75bc('0x18')](_0x75bc('0x19'),_0x3f5c86);}};EmailChannel[_0x75bc('0x10')][_0x75bc('0x1a')]=function(_0xe88fcd){for(var _0x322db4 in _0xe88fcd){if(_0xe88fcd[_0x75bc('0x1b')](_0x322db4)){if(_0xe88fcd[_0x322db4][_0x75bc('0x14')]&&_0xe88fcd[_0x322db4][_0x75bc('0x13')]){var _0x4bc939=_0xe88fcd[_0x322db4]['Imap'];if(!_0x4bc939[_0x75bc('0x1c')]&&_0xe88fcd[_0x322db4][_0x75bc('0x1d')]!==_0x75bc('0x1e'))_0x4bc939[_0x75bc('0x1c')]=_0xe88fcd[_0x322db4][_0x75bc('0x1d')];if(!this[_0x75bc('0xf')][_0x75bc('0x1b')](_0x4bc939['id'])){this[_0x75bc('0xf')][_0x4bc939['id']]=new EmailImap(_0x4bc939,_0xe88fcd[_0x322db4][_0x75bc('0x6')]);this['imapAccounts'][_0x4bc939['id']]['on'](_0x75bc('0x1f'),this[_0x75bc('0x20')][_0x75bc('0x21')](this,_0x322db4));this[_0x75bc('0xf')][_0x4bc939['id']]['on'](_0x75bc('0x6'),this[_0x75bc('0x22')]['bind'](this,_0x322db4));this[_0x75bc('0xf')][_0x4bc939['id']]['on'](_0x75bc('0x23'),this[_0x75bc('0x24')][_0x75bc('0x21')](this,_0x322db4));this[_0x75bc('0xf')][_0x4bc939['id']]['on']('error',this[_0x75bc('0x25')][_0x75bc('0x21')](this,_0x322db4));}}else{if(_[_0x75bc('0x26')](this[_0x75bc('0xe')][_0x322db4][_0x75bc('0x14')])){this[_0x75bc('0xe')][_0x322db4][_0x75bc('0x14')]={};}this['mailAccounts'][_0x322db4][_0x75bc('0x14')][_0x75bc('0x15')]=_0x75bc('0x27');this[_0x75bc('0xe')][_0x322db4][_0x75bc('0x14')][_0x75bc('0x28')]='';this[_0x75bc('0x18')](_0x322db4);}}}};EmailChannel[_0x75bc('0x10')]['handleImapBox']=function(_0x533ec8,_0x32b0a3){if(this[_0x75bc('0xe')][_0x533ec8]){this[_0x75bc('0xe')][_0x533ec8][_0x75bc('0x14')][_0x75bc('0x15')]=_0x75bc('0x29');this['mailAccounts'][_0x533ec8][_0x75bc('0x14')]['messageStatus']=_0x32b0a3['name'];if(_0x32b0a3[_0x75bc('0x2a')]){this[_0x75bc('0xe')][_0x533ec8]['Imap']['total']=_0x32b0a3[_0x75bc('0x2a')]['total'];}return this[_0x75bc('0x18')](_0x533ec8);}};EmailChannel['prototype'][_0x75bc('0x22')]=function(_0x50438c,_0xc38708){logger[_0x75bc('0xc')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0xc38708['firstName'],_0xc38708[_0x75bc('0x2b')],_0xc38708['from'],_0x50438c);if(this[_0x75bc('0xe')][_0x50438c]){return mailAccount['notify'](_0x50438c,_0xc38708)['then'](function(_0x2cb003){if(_0x2cb003){logger['info'](_0x75bc('0x2c'));}})['catch'](function(_0x1ed49f){logger[_0x75bc('0x2d')](_0x75bc('0x2e'),JSON[_0x75bc('0x17')](_0x1ed49f));});}};EmailChannel[_0x75bc('0x10')][_0x75bc('0x24')]=function(_0x4e9004){if(this[_0x75bc('0xe')][_0x4e9004]&&this['mailAccounts'][_0x4e9004][_0x75bc('0x14')]){if(this[_0x75bc('0xf')][this[_0x75bc('0xe')][_0x4e9004][_0x75bc('0x14')]['id']]){delete this[_0x75bc('0xf')][this[_0x75bc('0xe')][_0x4e9004]['Imap']['id']];}this[_0x75bc('0xe')][_0x4e9004]['Imap'][_0x75bc('0x2f')]=moment();this[_0x75bc('0x18')](_0x4e9004);}};EmailChannel[_0x75bc('0x10')]['handleImapError']=function(_0xdb99e8,_0x5c1ce1){if(this[_0x75bc('0xe')][_0xdb99e8]){this[_0x75bc('0xe')][_0xdb99e8][_0x75bc('0x14')][_0x75bc('0x15')]=_0x75bc('0x2d');this[_0x75bc('0xe')][_0xdb99e8][_0x75bc('0x14')][_0x75bc('0x28')]=_0x5c1ce1;return this[_0x75bc('0x18')](_0xdb99e8);}};EmailChannel['prototype'][_0x75bc('0x30')]=function(_0x439a18,_0x178a69){return this[_0x75bc('0x31')][_0x75bc('0x32')](_0x439a18,_0x178a69);};EmailChannel[_0x75bc('0x10')][_0x75bc('0x33')]=function(_0x2ba759){var _0xf2e806=this;if(this[_0x75bc('0xe')][_0x2ba759['id']]){if(_['isNil'](this[_0x75bc('0xe')][_0x2ba759['id']]['Smtp'])){this['mailAccounts'][_0x2ba759['id']][_0x75bc('0x34')]={};}this[_0x75bc('0xe')][_0x2ba759['id']]['Smtp'][_0x75bc('0x2f')]=moment();return new BPromise(function(_0x34f2b8,_0x4d6c36){return _0xf2e806[_0x75bc('0x31')][_0x75bc('0x35')](_0x2ba759)[_0x75bc('0x36')](function(_0x4e99a2){_0xf2e806[_0x75bc('0xe')][_0x2ba759['id']][_0x75bc('0x34')][_0x75bc('0x15')]=_0x75bc('0x37');_0xf2e806[_0x75bc('0xe')][_0x2ba759['id']][_0x75bc('0x34')][_0x75bc('0x28')]='';_0xf2e806['emit'](_0x2ba759['id']);_0x34f2b8(_0x4e99a2);})[_0x75bc('0x38')](function(_0x55656d){_0xf2e806[_0x75bc('0xe')][_0x2ba759['id']][_0x75bc('0x34')][_0x75bc('0x15')]=_0x75bc('0x2d');_0xf2e806[_0x75bc('0xe')][_0x2ba759['id']][_0x75bc('0x34')]['messageStatus']=_0x55656d;_0xf2e806['emit'](_0x2ba759['id']);_0x4d6c36(_0x55656d);});});}return this['smtp']['verify'](_0x2ba759);};module[_0x75bc('0x39')]=EmailChannel;
\ No newline at end of file
+var _0x3061=['active','Imap','status','messageStatus','total','isNil','stringify','mailAccount:update','provider','custom','service','box','handleImapBox','bind','handleImapEmail','end','handleImapEnd','handleImapError','name','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','from','then','info','Mail\x20accepted\x20from\x20routing','catch','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','sendMail','send','Smtp','verify','exports','moment','bluebird','md5','ioredis','email','redis','defaults','localhost','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','mailAccounts','imapAccounts','smtp','prototype','emit','key'];(function(_0x19e35c,_0x29cd1e){var _0x3e1fe8=function(_0x17258b){while(--_0x17258b){_0x19e35c['push'](_0x19e35c['shift']());}};_0x3e1fe8(++_0x29cd1e);}(_0x3061,0xfc));var _0x1306=function(_0x38622b,_0x3cfdf7){_0x38622b=_0x38622b-0x0;var _0x2c1a7a=_0x3061[_0x38622b];return _0x2c1a7a;};'use strict';var _=require('lodash');var moment=require(_0x1306('0x0'));var BPromise=require(_0x1306('0x1'));var md5=require(_0x1306('0x2'));var Redis=require(_0x1306('0x3'));var config=require('../../../config/environment');var logger=require('../../../config/logger')(_0x1306('0x4'));config[_0x1306('0x5')]=_[_0x1306('0x6')](config[_0x1306('0x5')],{'host':_0x1306('0x7'),'port':0x18eb});var io=require(_0x1306('0x8'))(new Redis(config[_0x1306('0x5')]));var EmailImap=require(_0x1306('0x9'));var EmailSmtp=require(_0x1306('0xa'));var mailAccount=require(_0x1306('0xb'));var md5Accounts={};function EmailChannel(_0x5241c6){logger['info']('start\x20email\x20channel');this['mailAccounts']=_0x5241c6[_0x1306('0xc')];this[_0x1306('0xd')]={};this[_0x1306('0xe')]=new EmailSmtp();}EmailChannel[_0x1306('0xf')][_0x1306('0x10')]=function(_0x15f088){var _0x1f445c=this[_0x1306('0xc')][_0x15f088];var _0x348c3a={'id':_0x1f445c['id'],'name':_0x1f445c['name'],'key':_0x1f445c[_0x1306('0x11')],'active':_0x1f445c[_0x1306('0x12')],'Imap':{'status':_0x1f445c[_0x1306('0x13')][_0x1306('0x14')],'messageStatus':_0x1f445c['Imap'][_0x1306('0x15')],'total':_0x1f445c[_0x1306('0x13')][_0x1306('0x16')]}};if(_[_0x1306('0x17')](md5Accounts[_0x15f088])){md5Accounts[_0x15f088]={};}var _0x16c329=md5(JSON[_0x1306('0x18')](_0x348c3a));if(md5Accounts[_0x15f088][_0x1306('0x2')]!==_0x16c329){md5Accounts[_0x15f088][_0x1306('0x2')]=_0x16c329;io['emit'](_0x1306('0x19'),_0x348c3a);}};EmailChannel[_0x1306('0xf')]['refresh']=function(_0x417c3f){for(var _0x266510 in _0x417c3f){if(_0x417c3f['hasOwnProperty'](_0x266510)){if(_0x417c3f[_0x266510][_0x1306('0x13')]&&_0x417c3f[_0x266510]['active']){var _0x18a7be=_0x417c3f[_0x266510][_0x1306('0x13')];if(!_0x18a7be['service']&&_0x417c3f[_0x266510][_0x1306('0x1a')]!==_0x1306('0x1b'))_0x18a7be[_0x1306('0x1c')]=_0x417c3f[_0x266510]['provider'];if(!this[_0x1306('0xd')]['hasOwnProperty'](_0x18a7be['id'])){this[_0x1306('0xd')][_0x18a7be['id']]=new EmailImap(_0x18a7be,_0x417c3f[_0x266510]['email']);this[_0x1306('0xd')][_0x18a7be['id']]['on'](_0x1306('0x1d'),this[_0x1306('0x1e')][_0x1306('0x1f')](this,_0x266510));this[_0x1306('0xd')][_0x18a7be['id']]['on']('email',this[_0x1306('0x20')][_0x1306('0x1f')](this,_0x266510));this[_0x1306('0xd')][_0x18a7be['id']]['on'](_0x1306('0x21'),this[_0x1306('0x22')]['bind'](this,_0x266510));this[_0x1306('0xd')][_0x18a7be['id']]['on']('error',this[_0x1306('0x23')][_0x1306('0x1f')](this,_0x266510));}}else{if(_[_0x1306('0x17')](this['mailAccounts'][_0x266510]['Imap'])){this[_0x1306('0xc')][_0x266510][_0x1306('0x13')]={};}this['mailAccounts'][_0x266510]['Imap']['status']='disabled';this[_0x1306('0xc')][_0x266510][_0x1306('0x13')][_0x1306('0x15')]='';this[_0x1306('0x10')](_0x266510);}}}};EmailChannel[_0x1306('0xf')]['handleImapBox']=function(_0x333862,_0xf57c2){if(this[_0x1306('0xc')][_0x333862]){this['mailAccounts'][_0x333862][_0x1306('0x13')][_0x1306('0x14')]='connected';this[_0x1306('0xc')][_0x333862][_0x1306('0x13')][_0x1306('0x15')]=_0xf57c2[_0x1306('0x24')];if(_0xf57c2[_0x1306('0x25')]){this[_0x1306('0xc')][_0x333862]['Imap'][_0x1306('0x16')]=_0xf57c2[_0x1306('0x25')][_0x1306('0x16')];}return this['emit'](_0x333862);}};EmailChannel[_0x1306('0xf')][_0x1306('0x20')]=function(_0x20e38b,_0x477795){logger['info'](_0x1306('0x26'),_0x477795[_0x1306('0x27')],_0x477795[_0x1306('0x28')],_0x477795[_0x1306('0x29')],_0x20e38b);if(this[_0x1306('0xc')][_0x20e38b]){return mailAccount['notify'](_0x20e38b,_0x477795)[_0x1306('0x2a')](function(_0xb04239){if(_0xb04239){logger[_0x1306('0x2b')](_0x1306('0x2c'));}})[_0x1306('0x2d')](function(_0x45dc17){logger[_0x1306('0x2e')](_0x1306('0x2f'),JSON[_0x1306('0x18')](_0x45dc17));});}};EmailChannel[_0x1306('0xf')]['handleImapEnd']=function(_0x6d407f){if(this['mailAccounts'][_0x6d407f]&&this[_0x1306('0xc')][_0x6d407f][_0x1306('0x13')]){if(this[_0x1306('0xd')][this[_0x1306('0xc')][_0x6d407f][_0x1306('0x13')]['id']]){delete this['imapAccounts'][this['mailAccounts'][_0x6d407f][_0x1306('0x13')]['id']];}this[_0x1306('0xc')][_0x6d407f]['Imap'][_0x1306('0x30')]=moment();this[_0x1306('0x10')](_0x6d407f);}};EmailChannel[_0x1306('0xf')][_0x1306('0x23')]=function(_0x5f3cda,_0x23aaf3){if(this['mailAccounts'][_0x5f3cda]){this[_0x1306('0xc')][_0x5f3cda]['Imap']['status']=_0x1306('0x2e');this['mailAccounts'][_0x5f3cda][_0x1306('0x13')][_0x1306('0x15')]=_0x23aaf3;return this[_0x1306('0x10')](_0x5f3cda);}};EmailChannel[_0x1306('0xf')][_0x1306('0x31')]=function(_0x36103a,_0x1fadad){return this[_0x1306('0xe')][_0x1306('0x32')](_0x36103a,_0x1fadad);};EmailChannel[_0x1306('0xf')]['verifySmtp']=function(_0x48856a){var _0x47a7cd=this;if(this[_0x1306('0xc')][_0x48856a['id']]){if(_[_0x1306('0x17')](this[_0x1306('0xc')][_0x48856a['id']]['Smtp'])){this[_0x1306('0xc')][_0x48856a['id']][_0x1306('0x33')]={};}this[_0x1306('0xc')][_0x48856a['id']][_0x1306('0x33')][_0x1306('0x30')]=moment();return new BPromise(function(_0xcfe2a,_0x939a0a){return _0x47a7cd[_0x1306('0xe')][_0x1306('0x34')](_0x48856a)['then'](function(_0x4ee831){_0x47a7cd[_0x1306('0xc')][_0x48856a['id']]['Smtp'][_0x1306('0x14')]='verified';_0x47a7cd[_0x1306('0xc')][_0x48856a['id']]['Smtp'][_0x1306('0x15')]='';_0x47a7cd[_0x1306('0x10')](_0x48856a['id']);_0xcfe2a(_0x4ee831);})[_0x1306('0x2d')](function(_0x2bf8dd){_0x47a7cd['mailAccounts'][_0x48856a['id']][_0x1306('0x33')]['status']=_0x1306('0x2e');_0x47a7cd[_0x1306('0xc')][_0x48856a['id']][_0x1306('0x33')][_0x1306('0x15')]=_0x2bf8dd;_0x47a7cd['emit'](_0x48856a['id']);_0x939a0a(_0x2bf8dd);});});}return this[_0x1306('0xe')][_0x1306('0x34')](_0x48856a);};module[_0x1306('0x35')]=EmailChannel;
\ No newline at end of file