Built motion from commit (unavailable).|2.5.6
[motion2.git] / server / services / email / lib / email.js
index ef44697..5bc5338 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xfe9f=['Imap','messageStatus','total','isNil','stringify','mailAccount:update','refresh','hasOwnProperty','email','box','handleImapBox','handleImapEmail','handleImapEnd','bind','disabled','connected','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','lastName','from','notify','then','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','handleImapError','error','send','verifySmtp','Smtp','verified','verify','lodash','moment','bluebird','md5','ioredis','../../../config/environment','defaults','redis','../rpc/mailAccount','info','start\x20email\x20channel','imapAccounts','smtp','prototype','emit','mailAccounts','name','key','active','status'];(function(_0x22ffc4,_0x3297d9){var _0x455220=function(_0x1fd6db){while(--_0x1fd6db){_0x22ffc4['push'](_0x22ffc4['shift']());}};_0x455220(++_0x3297d9);}(_0xfe9f,0x151));var _0xffe9=function(_0x2c1cd1,_0x7269b4){_0x2c1cd1=_0x2c1cd1-0x0;var _0x23b45c=_0xfe9f[_0x2c1cd1];return _0x23b45c;};'use strict';var _=require(_0xffe9('0x0'));var moment=require(_0xffe9('0x1'));var BPromise=require(_0xffe9('0x2'));var md5=require(_0xffe9('0x3'));var Redis=require(_0xffe9('0x4'));var config=require(_0xffe9('0x5'));var logger=require('../../../config/logger')('email');config['redis']=_[_0xffe9('0x6')](config[_0xffe9('0x7')],{'host':'localhost','port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xffe9('0x7')]));var EmailImap=require('./imap');var EmailSmtp=require('./smtp');var mailAccount=require(_0xffe9('0x8'));var md5Accounts={};function EmailChannel(_0x5d1092){logger[_0xffe9('0x9')](_0xffe9('0xa'));this['mailAccounts']=_0x5d1092['mailAccounts'];this[_0xffe9('0xb')]={};this[_0xffe9('0xc')]=new EmailSmtp();}EmailChannel[_0xffe9('0xd')][_0xffe9('0xe')]=function(_0x1e0007){var _0x3d366c=this[_0xffe9('0xf')][_0x1e0007];var _0x11d5e2={'id':_0x3d366c['id'],'name':_0x3d366c[_0xffe9('0x10')],'key':_0x3d366c[_0xffe9('0x11')],'active':_0x3d366c[_0xffe9('0x12')],'Imap':{'status':_0x3d366c['Imap'][_0xffe9('0x13')],'messageStatus':_0x3d366c[_0xffe9('0x14')][_0xffe9('0x15')],'total':_0x3d366c['Imap'][_0xffe9('0x16')]}};if(_[_0xffe9('0x17')](md5Accounts[_0x1e0007])){md5Accounts[_0x1e0007]={};}var _0x347402=md5(JSON[_0xffe9('0x18')](_0x11d5e2));if(md5Accounts[_0x1e0007][_0xffe9('0x3')]!==_0x347402){md5Accounts[_0x1e0007]['md5']=_0x347402;io['emit'](_0xffe9('0x19'),_0x11d5e2);}};EmailChannel[_0xffe9('0xd')][_0xffe9('0x1a')]=function(_0x158c6d){for(var _0x9ed22c in _0x158c6d){if(_0x158c6d[_0xffe9('0x1b')](_0x9ed22c)){if(_0x158c6d[_0x9ed22c]['Imap']&&_0x158c6d[_0x9ed22c][_0xffe9('0x12')]){var _0x88778f=_0x158c6d[_0x9ed22c][_0xffe9('0x14')];if(!this[_0xffe9('0xb')][_0xffe9('0x1b')](_0x88778f['id'])){this['imapAccounts'][_0x88778f['id']]=new EmailImap(_0x88778f,_0x158c6d[_0x9ed22c][_0xffe9('0x1c')]);this[_0xffe9('0xb')][_0x88778f['id']]['on'](_0xffe9('0x1d'),this[_0xffe9('0x1e')]['bind'](this,_0x9ed22c));this[_0xffe9('0xb')][_0x88778f['id']]['on'](_0xffe9('0x1c'),this[_0xffe9('0x1f')]['bind'](this,_0x9ed22c));this[_0xffe9('0xb')][_0x88778f['id']]['on']('end',this[_0xffe9('0x20')]['bind'](this,_0x9ed22c));this[_0xffe9('0xb')][_0x88778f['id']]['on']('error',this['handleImapError'][_0xffe9('0x21')](this,_0x9ed22c));}}else{if(_[_0xffe9('0x17')](this[_0xffe9('0xf')][_0x9ed22c]['Imap'])){this[_0xffe9('0xf')][_0x9ed22c][_0xffe9('0x14')]={};}this['mailAccounts'][_0x9ed22c][_0xffe9('0x14')]['status']=_0xffe9('0x22');this[_0xffe9('0xf')][_0x9ed22c][_0xffe9('0x14')]['messageStatus']='';this[_0xffe9('0xe')](_0x9ed22c);}}}};EmailChannel[_0xffe9('0xd')][_0xffe9('0x1e')]=function(_0x5a1b22,_0x26e681){if(this[_0xffe9('0xf')][_0x5a1b22]){this[_0xffe9('0xf')][_0x5a1b22][_0xffe9('0x14')][_0xffe9('0x13')]=_0xffe9('0x23');this[_0xffe9('0xf')][_0x5a1b22][_0xffe9('0x14')][_0xffe9('0x15')]=_0x26e681['name'];if(_0x26e681[_0xffe9('0x24')]){this['mailAccounts'][_0x5a1b22]['Imap'][_0xffe9('0x16')]=_0x26e681['messages'][_0xffe9('0x16')];}return this['emit'](_0x5a1b22);}};EmailChannel[_0xffe9('0xd')]['handleImapEmail']=function(_0x529e76,_0x22fe69){logger['info'](_0xffe9('0x25'),_0x22fe69['firstName'],_0x22fe69[_0xffe9('0x26')],_0x22fe69[_0xffe9('0x27')],_0x529e76);if(this[_0xffe9('0xf')][_0x529e76]){return mailAccount[_0xffe9('0x28')](_0x529e76,_0x22fe69)[_0xffe9('0x29')](function(_0x40df35){if(_0x40df35){logger['info']('Mail\x20accepted\x20from\x20routing');}})['catch'](function(_0x26c587){logger['error'](_0xffe9('0x2a'),JSON['stringify'](_0x26c587));});}};EmailChannel[_0xffe9('0xd')][_0xffe9('0x20')]=function(_0x329f32){if(this[_0xffe9('0xf')][_0x329f32]&&this[_0xffe9('0xf')][_0x329f32][_0xffe9('0x14')]){if(this[_0xffe9('0xb')][this['mailAccounts'][_0x329f32][_0xffe9('0x14')]['id']]){delete this['imapAccounts'][this[_0xffe9('0xf')][_0x329f32][_0xffe9('0x14')]['id']];}this['mailAccounts'][_0x329f32][_0xffe9('0x14')][_0xffe9('0x2b')]=moment();this[_0xffe9('0xe')](_0x329f32);}};EmailChannel[_0xffe9('0xd')][_0xffe9('0x2c')]=function(_0x513222,_0x427a82){if(this['mailAccounts'][_0x513222]){this[_0xffe9('0xf')][_0x513222]['Imap'][_0xffe9('0x13')]=_0xffe9('0x2d');this[_0xffe9('0xf')][_0x513222][_0xffe9('0x14')][_0xffe9('0x15')]=_0x427a82;return this[_0xffe9('0xe')](_0x513222);}};EmailChannel[_0xffe9('0xd')]['sendMail']=function(_0x102f95,_0x174732){return this[_0xffe9('0xc')][_0xffe9('0x2e')](_0x102f95,_0x174732);};EmailChannel[_0xffe9('0xd')][_0xffe9('0x2f')]=function(_0x3f4563){var _0x46a17c=this;if(this[_0xffe9('0xf')][_0x3f4563['id']]){if(_['isNil'](this['mailAccounts'][_0x3f4563['id']][_0xffe9('0x30')])){this[_0xffe9('0xf')][_0x3f4563['id']][_0xffe9('0x30')]={};}this['mailAccounts'][_0x3f4563['id']][_0xffe9('0x30')][_0xffe9('0x2b')]=moment();return new BPromise(function(_0xbc675,_0x2bd8c6){return _0x46a17c['smtp']['verify'](_0x3f4563)[_0xffe9('0x29')](function(_0x562a60){_0x46a17c[_0xffe9('0xf')][_0x3f4563['id']][_0xffe9('0x30')]['status']=_0xffe9('0x31');_0x46a17c['mailAccounts'][_0x3f4563['id']][_0xffe9('0x30')]['messageStatus']='';_0x46a17c[_0xffe9('0xe')](_0x3f4563['id']);_0xbc675(_0x562a60);})['catch'](function(_0x49f4f0){_0x46a17c[_0xffe9('0xf')][_0x3f4563['id']][_0xffe9('0x30')][_0xffe9('0x13')]=_0xffe9('0x2d');_0x46a17c[_0xffe9('0xf')][_0x3f4563['id']][_0xffe9('0x30')][_0xffe9('0x15')]=_0x49f4f0;_0x46a17c[_0xffe9('0xe')](_0x3f4563['id']);_0x2bd8c6(_0x49f4f0);});});}return this[_0xffe9('0xc')][_0xffe9('0x32')](_0x3f4563);};module['exports']=EmailChannel;
\ No newline at end of file
+var _0xfd14=['handleImapBox','connected','messages','firstName','lastName','notify','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','handleImapError','sendMail','send','Smtp','verify','verified','exports','lodash','moment','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','localhost','socket.io-emitter','./smtp','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','emit','name','key','Imap','status','messageStatus','total','isNil','stringify','mailAccount:update','refresh','hasOwnProperty','box','bind','handleImapEmail','end','handleImapEnd','error','disabled'];(function(_0x40e0d6,_0xb1e94b){var _0x32cfe8=function(_0x31e355){while(--_0x31e355){_0x40e0d6['push'](_0x40e0d6['shift']());}};_0x32cfe8(++_0xb1e94b);}(_0xfd14,0x1c9));var _0x4fd1=function(_0x1f99a9,_0x2609b8){_0x1f99a9=_0x1f99a9-0x0;var _0x9a86b1=_0xfd14[_0x1f99a9];return _0x9a86b1;};'use strict';var _=require(_0x4fd1('0x0'));var moment=require(_0x4fd1('0x1'));var BPromise=require(_0x4fd1('0x2'));var md5=require(_0x4fd1('0x3'));var Redis=require(_0x4fd1('0x4'));var config=require(_0x4fd1('0x5'));var logger=require(_0x4fd1('0x6'))(_0x4fd1('0x7'));config[_0x4fd1('0x8')]=_[_0x4fd1('0x9')](config['redis'],{'host':_0x4fd1('0xa'),'port':0x18eb});var io=require(_0x4fd1('0xb'))(new Redis(config[_0x4fd1('0x8')]));var EmailImap=require('./imap');var EmailSmtp=require(_0x4fd1('0xc'));var mailAccount=require('../rpc/mailAccount');var md5Accounts={};function EmailChannel(_0x41aac9){logger[_0x4fd1('0xd')](_0x4fd1('0xe'));this[_0x4fd1('0xf')]=_0x41aac9[_0x4fd1('0xf')];this[_0x4fd1('0x10')]={};this[_0x4fd1('0x11')]=new EmailSmtp();}EmailChannel[_0x4fd1('0x12')][_0x4fd1('0x13')]=function(_0x2f63d3){var _0x4916e7=this[_0x4fd1('0xf')][_0x2f63d3];var _0x3bd7cd={'id':_0x4916e7['id'],'name':_0x4916e7[_0x4fd1('0x14')],'key':_0x4916e7[_0x4fd1('0x15')],'active':_0x4916e7['active'],'Imap':{'status':_0x4916e7[_0x4fd1('0x16')][_0x4fd1('0x17')],'messageStatus':_0x4916e7[_0x4fd1('0x16')][_0x4fd1('0x18')],'total':_0x4916e7[_0x4fd1('0x16')][_0x4fd1('0x19')]}};if(_[_0x4fd1('0x1a')](md5Accounts[_0x2f63d3])){md5Accounts[_0x2f63d3]={};}var _0x1ff797=md5(JSON[_0x4fd1('0x1b')](_0x3bd7cd));if(md5Accounts[_0x2f63d3]['md5']!==_0x1ff797){md5Accounts[_0x2f63d3][_0x4fd1('0x3')]=_0x1ff797;io[_0x4fd1('0x13')](_0x4fd1('0x1c'),_0x3bd7cd);}};EmailChannel[_0x4fd1('0x12')][_0x4fd1('0x1d')]=function(_0x5903cf){for(var _0x2f83ef in _0x5903cf){if(_0x5903cf['hasOwnProperty'](_0x2f83ef)){if(_0x5903cf[_0x2f83ef][_0x4fd1('0x16')]&&_0x5903cf[_0x2f83ef]['active']){var _0x444353=_0x5903cf[_0x2f83ef]['Imap'];if(!this['imapAccounts'][_0x4fd1('0x1e')](_0x444353['id'])){this['imapAccounts'][_0x444353['id']]=new EmailImap(_0x444353,_0x5903cf[_0x2f83ef]['email']);this[_0x4fd1('0x10')][_0x444353['id']]['on'](_0x4fd1('0x1f'),this['handleImapBox'][_0x4fd1('0x20')](this,_0x2f83ef));this[_0x4fd1('0x10')][_0x444353['id']]['on'](_0x4fd1('0x7'),this[_0x4fd1('0x21')][_0x4fd1('0x20')](this,_0x2f83ef));this[_0x4fd1('0x10')][_0x444353['id']]['on'](_0x4fd1('0x22'),this[_0x4fd1('0x23')][_0x4fd1('0x20')](this,_0x2f83ef));this[_0x4fd1('0x10')][_0x444353['id']]['on'](_0x4fd1('0x24'),this['handleImapError'][_0x4fd1('0x20')](this,_0x2f83ef));}}else{if(_[_0x4fd1('0x1a')](this[_0x4fd1('0xf')][_0x2f83ef][_0x4fd1('0x16')])){this[_0x4fd1('0xf')][_0x2f83ef][_0x4fd1('0x16')]={};}this[_0x4fd1('0xf')][_0x2f83ef]['Imap'][_0x4fd1('0x17')]=_0x4fd1('0x25');this[_0x4fd1('0xf')][_0x2f83ef][_0x4fd1('0x16')][_0x4fd1('0x18')]='';this[_0x4fd1('0x13')](_0x2f83ef);}}}};EmailChannel['prototype'][_0x4fd1('0x26')]=function(_0x51d166,_0x358f0f){if(this[_0x4fd1('0xf')][_0x51d166]){this[_0x4fd1('0xf')][_0x51d166][_0x4fd1('0x16')][_0x4fd1('0x17')]=_0x4fd1('0x27');this[_0x4fd1('0xf')][_0x51d166][_0x4fd1('0x16')][_0x4fd1('0x18')]=_0x358f0f[_0x4fd1('0x14')];if(_0x358f0f[_0x4fd1('0x28')]){this['mailAccounts'][_0x51d166][_0x4fd1('0x16')]['total']=_0x358f0f[_0x4fd1('0x28')][_0x4fd1('0x19')];}return this[_0x4fd1('0x13')](_0x51d166);}};EmailChannel[_0x4fd1('0x12')][_0x4fd1('0x21')]=function(_0x8276e4,_0x2feb9e){logger[_0x4fd1('0xd')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x2feb9e[_0x4fd1('0x29')],_0x2feb9e[_0x4fd1('0x2a')],_0x2feb9e['from'],_0x8276e4);if(this[_0x4fd1('0xf')][_0x8276e4]){return mailAccount[_0x4fd1('0x2b')](_0x8276e4,_0x2feb9e)['then'](function(_0xeb5c82){if(_0xeb5c82){logger[_0x4fd1('0xd')](_0x4fd1('0x2c'));}})[_0x4fd1('0x2d')](function(_0x5cdb79){logger['error'](_0x4fd1('0x2e'),JSON['stringify'](_0x5cdb79));});}};EmailChannel[_0x4fd1('0x12')][_0x4fd1('0x23')]=function(_0x4893a8){if(this[_0x4fd1('0xf')][_0x4893a8]&&this[_0x4fd1('0xf')][_0x4893a8][_0x4fd1('0x16')]){if(this[_0x4fd1('0x10')][this[_0x4fd1('0xf')][_0x4893a8][_0x4fd1('0x16')]['id']]){delete this[_0x4fd1('0x10')][this[_0x4fd1('0xf')][_0x4893a8]['Imap']['id']];}this['mailAccounts'][_0x4893a8][_0x4fd1('0x16')][_0x4fd1('0x2f')]=moment();this[_0x4fd1('0x13')](_0x4893a8);}};EmailChannel[_0x4fd1('0x12')][_0x4fd1('0x30')]=function(_0x583d70,_0x31f98e){if(this[_0x4fd1('0xf')][_0x583d70]){this[_0x4fd1('0xf')][_0x583d70][_0x4fd1('0x16')][_0x4fd1('0x17')]=_0x4fd1('0x24');this[_0x4fd1('0xf')][_0x583d70][_0x4fd1('0x16')][_0x4fd1('0x18')]=_0x31f98e;return this[_0x4fd1('0x13')](_0x583d70);}};EmailChannel['prototype'][_0x4fd1('0x31')]=function(_0x15071f,_0x39c7ff){return this[_0x4fd1('0x11')][_0x4fd1('0x32')](_0x15071f,_0x39c7ff);};EmailChannel[_0x4fd1('0x12')]['verifySmtp']=function(_0x380989){var _0x42602f=this;if(this[_0x4fd1('0xf')][_0x380989['id']]){if(_[_0x4fd1('0x1a')](this[_0x4fd1('0xf')][_0x380989['id']]['Smtp'])){this[_0x4fd1('0xf')][_0x380989['id']]['Smtp']={};}this[_0x4fd1('0xf')][_0x380989['id']][_0x4fd1('0x33')][_0x4fd1('0x2f')]=moment();return new BPromise(function(_0x24aaa1,_0x6cbd7c){return _0x42602f[_0x4fd1('0x11')][_0x4fd1('0x34')](_0x380989)['then'](function(_0x41c377){_0x42602f[_0x4fd1('0xf')][_0x380989['id']][_0x4fd1('0x33')][_0x4fd1('0x17')]=_0x4fd1('0x35');_0x42602f[_0x4fd1('0xf')][_0x380989['id']][_0x4fd1('0x33')][_0x4fd1('0x18')]='';_0x42602f[_0x4fd1('0x13')](_0x380989['id']);_0x24aaa1(_0x41c377);})['catch'](function(_0x52e001){_0x42602f[_0x4fd1('0xf')][_0x380989['id']][_0x4fd1('0x33')][_0x4fd1('0x17')]=_0x4fd1('0x24');_0x42602f[_0x4fd1('0xf')][_0x380989['id']][_0x4fd1('0x33')]['messageStatus']=_0x52e001;_0x42602f[_0x4fd1('0x13')](_0x380989['id']);_0x6cbd7c(_0x52e001);});});}return this[_0x4fd1('0x11')][_0x4fd1('0x34')](_0x380989);};module[_0x4fd1('0x36')]=EmailChannel;
\ No newline at end of file