Built motion from commit (unavailable).|2.4.4
[motion2.git] / server / services / email / lib / email.js
index 780ee8d..935b493 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3a6d=['defaults','redis','localhost','socket.io-emitter','./imap','../rpc/mailAccount','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','name','status','Imap','messageStatus','total','isNil','emit','refresh','hasOwnProperty','handleImapBox','handleImapEmail','bind','end','disabled','connected','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','from','notify','Mail\x20accepted\x20from\x20routing','catch','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','stringify','handleImapEnd','handleImapError','sendMail','verifySmtp','Smtp','lastSync','verify','then','verified','exports','lodash','moment','md5','ioredis','../../../config/environment','../../../config/logger','email'];(function(_0x5dbd73,_0x3deb98){var _0x4fb942=function(_0x134510){while(--_0x134510){_0x5dbd73['push'](_0x5dbd73['shift']());}};_0x4fb942(++_0x3deb98);}(_0x3a6d,0x143));var _0xd3a6=function(_0x8c43de,_0x90ff31){_0x8c43de=_0x8c43de-0x0;var _0xa6591b=_0x3a6d[_0x8c43de];return _0xa6591b;};'use strict';var _=require(_0xd3a6('0x0'));var moment=require(_0xd3a6('0x1'));var BPromise=require('bluebird');var md5=require(_0xd3a6('0x2'));var Redis=require(_0xd3a6('0x3'));var config=require(_0xd3a6('0x4'));var logger=require(_0xd3a6('0x5'))(_0xd3a6('0x6'));config['redis']=_[_0xd3a6('0x7')](config[_0xd3a6('0x8')],{'host':_0xd3a6('0x9'),'port':0x18eb});var io=require(_0xd3a6('0xa'))(new Redis(config[_0xd3a6('0x8')]));var EmailImap=require(_0xd3a6('0xb'));var EmailSmtp=require('./smtp');var mailAccount=require(_0xd3a6('0xc'));var md5Accounts={};function EmailChannel(_0x134dd3){logger[_0xd3a6('0xd')](_0xd3a6('0xe'));this[_0xd3a6('0xf')]=_0x134dd3[_0xd3a6('0xf')];this[_0xd3a6('0x10')]={};this[_0xd3a6('0x11')]=new EmailSmtp();}EmailChannel[_0xd3a6('0x12')]['emit']=function(_0x172513){var _0x1a00f7=this[_0xd3a6('0xf')][_0x172513];var _0x225399={'id':_0x1a00f7['id'],'name':_0x1a00f7[_0xd3a6('0x13')],'key':_0x1a00f7['key'],'active':_0x1a00f7['active'],'Imap':{'status':_0x1a00f7['Imap'][_0xd3a6('0x14')],'messageStatus':_0x1a00f7[_0xd3a6('0x15')][_0xd3a6('0x16')],'total':_0x1a00f7[_0xd3a6('0x15')][_0xd3a6('0x17')]}};if(_[_0xd3a6('0x18')](md5Accounts[_0x172513])){md5Accounts[_0x172513]={};}var _0xa56452=md5(JSON['stringify'](_0x225399));if(md5Accounts[_0x172513][_0xd3a6('0x2')]!==_0xa56452){md5Accounts[_0x172513][_0xd3a6('0x2')]=_0xa56452;io[_0xd3a6('0x19')]('mailAccount:update',_0x225399);}};EmailChannel[_0xd3a6('0x12')][_0xd3a6('0x1a')]=function(_0x1781f6){for(var _0x57d826 in _0x1781f6){if(_0x1781f6[_0xd3a6('0x1b')](_0x57d826)){if(_0x1781f6[_0x57d826]['Imap']&&_0x1781f6[_0x57d826]['active']){var _0x28b63c=_0x1781f6[_0x57d826][_0xd3a6('0x15')];if(!this[_0xd3a6('0x10')][_0xd3a6('0x1b')](_0x28b63c['id'])){this[_0xd3a6('0x10')][_0x28b63c['id']]=new EmailImap(_0x28b63c,_0x1781f6[_0x57d826][_0xd3a6('0x6')]);this[_0xd3a6('0x10')][_0x28b63c['id']]['on']('box',this[_0xd3a6('0x1c')]['bind'](this,_0x57d826));this[_0xd3a6('0x10')][_0x28b63c['id']]['on'](_0xd3a6('0x6'),this[_0xd3a6('0x1d')][_0xd3a6('0x1e')](this,_0x57d826));this[_0xd3a6('0x10')][_0x28b63c['id']]['on'](_0xd3a6('0x1f'),this['handleImapEnd'][_0xd3a6('0x1e')](this,_0x57d826));this[_0xd3a6('0x10')][_0x28b63c['id']]['on']('error',this['handleImapError']['bind'](this,_0x57d826));}}else{if(_['isNil'](this['mailAccounts'][_0x57d826][_0xd3a6('0x15')])){this[_0xd3a6('0xf')][_0x57d826][_0xd3a6('0x15')]={};}this['mailAccounts'][_0x57d826][_0xd3a6('0x15')]['status']=_0xd3a6('0x20');this[_0xd3a6('0xf')][_0x57d826][_0xd3a6('0x15')]['messageStatus']='';this[_0xd3a6('0x19')](_0x57d826);}}}};EmailChannel[_0xd3a6('0x12')][_0xd3a6('0x1c')]=function(_0x219e32,_0x169d11){if(this[_0xd3a6('0xf')][_0x219e32]){this['mailAccounts'][_0x219e32][_0xd3a6('0x15')][_0xd3a6('0x14')]=_0xd3a6('0x21');this[_0xd3a6('0xf')][_0x219e32][_0xd3a6('0x15')][_0xd3a6('0x16')]=_0x169d11['name'];if(_0x169d11['messages']){this[_0xd3a6('0xf')][_0x219e32][_0xd3a6('0x15')][_0xd3a6('0x17')]=_0x169d11[_0xd3a6('0x22')]['total'];}return this[_0xd3a6('0x19')](_0x219e32);}};EmailChannel[_0xd3a6('0x12')]['handleImapEmail']=function(_0x14381c,_0x5d9867){logger[_0xd3a6('0xd')](_0xd3a6('0x23'),_0x5d9867[_0xd3a6('0x24')],_0x5d9867[_0xd3a6('0x25')],_0x5d9867[_0xd3a6('0x26')],_0x14381c);if(this[_0xd3a6('0xf')][_0x14381c]){return mailAccount[_0xd3a6('0x27')](_0x14381c,_0x5d9867)['then'](function(_0x4d7b56){if(_0x4d7b56){logger[_0xd3a6('0xd')](_0xd3a6('0x28'));}})[_0xd3a6('0x29')](function(_0x59337c){logger[_0xd3a6('0x2a')](_0xd3a6('0x2b'),JSON[_0xd3a6('0x2c')](_0x59337c));});}};EmailChannel[_0xd3a6('0x12')][_0xd3a6('0x2d')]=function(_0x36b28a){if(this[_0xd3a6('0xf')][_0x36b28a]&&this[_0xd3a6('0xf')][_0x36b28a]['Imap']){if(this[_0xd3a6('0x10')][this[_0xd3a6('0xf')][_0x36b28a][_0xd3a6('0x15')]['id']]){delete this[_0xd3a6('0x10')][this[_0xd3a6('0xf')][_0x36b28a][_0xd3a6('0x15')]['id']];}this['mailAccounts'][_0x36b28a][_0xd3a6('0x15')]['lastSync']=moment();this[_0xd3a6('0x19')](_0x36b28a);}};EmailChannel[_0xd3a6('0x12')][_0xd3a6('0x2e')]=function(_0x246735,_0x524779){if(this['mailAccounts'][_0x246735]){this[_0xd3a6('0xf')][_0x246735][_0xd3a6('0x15')][_0xd3a6('0x14')]='error';this[_0xd3a6('0xf')][_0x246735][_0xd3a6('0x15')]['messageStatus']=_0x524779;return this[_0xd3a6('0x19')](_0x246735);}};EmailChannel['prototype'][_0xd3a6('0x2f')]=function(_0x2aa1dc,_0x54251d){return this[_0xd3a6('0x11')]['send'](_0x2aa1dc,_0x54251d);};EmailChannel[_0xd3a6('0x12')][_0xd3a6('0x30')]=function(_0x51af61){var _0x2cba30=this;if(this[_0xd3a6('0xf')][_0x51af61['id']]){if(_[_0xd3a6('0x18')](this[_0xd3a6('0xf')][_0x51af61['id']]['Smtp'])){this[_0xd3a6('0xf')][_0x51af61['id']][_0xd3a6('0x31')]={};}this[_0xd3a6('0xf')][_0x51af61['id']][_0xd3a6('0x31')][_0xd3a6('0x32')]=moment();return new BPromise(function(_0x56d45f,_0x32ff68){return _0x2cba30['smtp'][_0xd3a6('0x33')](_0x51af61)[_0xd3a6('0x34')](function(_0x16764c){_0x2cba30['mailAccounts'][_0x51af61['id']][_0xd3a6('0x31')]['status']=_0xd3a6('0x35');_0x2cba30['mailAccounts'][_0x51af61['id']][_0xd3a6('0x31')][_0xd3a6('0x16')]='';_0x2cba30[_0xd3a6('0x19')](_0x51af61['id']);_0x56d45f(_0x16764c);})[_0xd3a6('0x29')](function(_0x346b26){_0x2cba30[_0xd3a6('0xf')][_0x51af61['id']][_0xd3a6('0x31')]['status']=_0xd3a6('0x2a');_0x2cba30[_0xd3a6('0xf')][_0x51af61['id']][_0xd3a6('0x31')][_0xd3a6('0x16')]=_0x346b26;_0x2cba30['emit'](_0x51af61['id']);_0x32ff68(_0x346b26);});});}return this[_0xd3a6('0x11')][_0xd3a6('0x33')](_0x51af61);};module[_0xd3a6('0x36')]=EmailChannel;
\ No newline at end of file
+var _0x2ef3=['mailAccounts','imapAccounts','smtp','key','Imap','messageStatus','isNil','stringify','emit','hasOwnProperty','box','handleImapBox','bind','handleImapEmail','handleImapEnd','error','handleImapError','status','prototype','connected','messages','total','firstName','from','then','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','sendMail','send','verifySmtp','Smtp','verify','verified','exports','lodash','moment','bluebird','md5','ioredis','../../../config/environment','email','redis','localhost','./imap','./smtp','../rpc/mailAccount','info','start\x20email\x20channel'];(function(_0x45d938,_0x156cb3){var _0x30fbda=function(_0x540106){while(--_0x540106){_0x45d938['push'](_0x45d938['shift']());}};_0x30fbda(++_0x156cb3);}(_0x2ef3,0xba));var _0x32ef=function(_0x332f67,_0x194ec2){_0x332f67=_0x332f67-0x0;var _0x3fa9d1=_0x2ef3[_0x332f67];return _0x3fa9d1;};'use strict';var _=require(_0x32ef('0x0'));var moment=require(_0x32ef('0x1'));var BPromise=require(_0x32ef('0x2'));var md5=require(_0x32ef('0x3'));var Redis=require(_0x32ef('0x4'));var config=require(_0x32ef('0x5'));var logger=require('../../../config/logger')(_0x32ef('0x6'));config[_0x32ef('0x7')]=_['defaults'](config[_0x32ef('0x7')],{'host':_0x32ef('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));var EmailImap=require(_0x32ef('0x9'));var EmailSmtp=require(_0x32ef('0xa'));var mailAccount=require(_0x32ef('0xb'));var md5Accounts={};function EmailChannel(_0x2fb8eb){logger[_0x32ef('0xc')](_0x32ef('0xd'));this[_0x32ef('0xe')]=_0x2fb8eb[_0x32ef('0xe')];this[_0x32ef('0xf')]={};this[_0x32ef('0x10')]=new EmailSmtp();}EmailChannel['prototype']['emit']=function(_0x401d0b){var _0x33281d=this[_0x32ef('0xe')][_0x401d0b];var _0x1499c2={'id':_0x33281d['id'],'name':_0x33281d['name'],'key':_0x33281d[_0x32ef('0x11')],'active':_0x33281d['active'],'Imap':{'status':_0x33281d[_0x32ef('0x12')]['status'],'messageStatus':_0x33281d[_0x32ef('0x12')][_0x32ef('0x13')],'total':_0x33281d['Imap']['total']}};if(_[_0x32ef('0x14')](md5Accounts[_0x401d0b])){md5Accounts[_0x401d0b]={};}var _0x4d8009=md5(JSON[_0x32ef('0x15')](_0x1499c2));if(md5Accounts[_0x401d0b][_0x32ef('0x3')]!==_0x4d8009){md5Accounts[_0x401d0b][_0x32ef('0x3')]=_0x4d8009;io[_0x32ef('0x16')]('mailAccount:update',_0x1499c2);}};EmailChannel['prototype']['refresh']=function(_0x13db1a){for(var _0x3950e6 in _0x13db1a){if(_0x13db1a[_0x32ef('0x17')](_0x3950e6)){if(_0x13db1a[_0x3950e6]['Imap']&&_0x13db1a[_0x3950e6]['active']){var _0x1eb468=_0x13db1a[_0x3950e6][_0x32ef('0x12')];if(!this[_0x32ef('0xf')]['hasOwnProperty'](_0x1eb468['id'])){this[_0x32ef('0xf')][_0x1eb468['id']]=new EmailImap(_0x1eb468,_0x13db1a[_0x3950e6][_0x32ef('0x6')]);this['imapAccounts'][_0x1eb468['id']]['on'](_0x32ef('0x18'),this[_0x32ef('0x19')][_0x32ef('0x1a')](this,_0x3950e6));this[_0x32ef('0xf')][_0x1eb468['id']]['on'](_0x32ef('0x6'),this[_0x32ef('0x1b')]['bind'](this,_0x3950e6));this[_0x32ef('0xf')][_0x1eb468['id']]['on']('end',this[_0x32ef('0x1c')][_0x32ef('0x1a')](this,_0x3950e6));this['imapAccounts'][_0x1eb468['id']]['on'](_0x32ef('0x1d'),this[_0x32ef('0x1e')][_0x32ef('0x1a')](this,_0x3950e6));}}else{if(_['isNil'](this['mailAccounts'][_0x3950e6][_0x32ef('0x12')])){this[_0x32ef('0xe')][_0x3950e6][_0x32ef('0x12')]={};}this['mailAccounts'][_0x3950e6]['Imap'][_0x32ef('0x1f')]='disabled';this['mailAccounts'][_0x3950e6][_0x32ef('0x12')][_0x32ef('0x13')]='';this[_0x32ef('0x16')](_0x3950e6);}}}};EmailChannel[_0x32ef('0x20')][_0x32ef('0x19')]=function(_0x234175,_0x1874ea){if(this[_0x32ef('0xe')][_0x234175]){this[_0x32ef('0xe')][_0x234175][_0x32ef('0x12')][_0x32ef('0x1f')]=_0x32ef('0x21');this['mailAccounts'][_0x234175][_0x32ef('0x12')][_0x32ef('0x13')]=_0x1874ea['name'];if(_0x1874ea[_0x32ef('0x22')]){this[_0x32ef('0xe')][_0x234175][_0x32ef('0x12')][_0x32ef('0x23')]=_0x1874ea['messages'][_0x32ef('0x23')];}return this[_0x32ef('0x16')](_0x234175);}};EmailChannel[_0x32ef('0x20')][_0x32ef('0x1b')]=function(_0x1b668a,_0x1a6ed2){logger[_0x32ef('0xc')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x1a6ed2[_0x32ef('0x24')],_0x1a6ed2['lastName'],_0x1a6ed2[_0x32ef('0x25')],_0x1b668a);if(this[_0x32ef('0xe')][_0x1b668a]){return mailAccount['notify'](_0x1b668a,_0x1a6ed2)[_0x32ef('0x26')](function(_0x17e4d1){if(_0x17e4d1){logger[_0x32ef('0xc')](_0x32ef('0x27'));}})[_0x32ef('0x28')](function(_0x59a4a3){logger['error'](_0x32ef('0x29'),JSON['stringify'](_0x59a4a3));});}};EmailChannel[_0x32ef('0x20')][_0x32ef('0x1c')]=function(_0x2f1349){if(this[_0x32ef('0xe')][_0x2f1349]&&this[_0x32ef('0xe')][_0x2f1349][_0x32ef('0x12')]){if(this['imapAccounts'][this['mailAccounts'][_0x2f1349]['Imap']['id']]){delete this[_0x32ef('0xf')][this[_0x32ef('0xe')][_0x2f1349][_0x32ef('0x12')]['id']];}this['mailAccounts'][_0x2f1349]['Imap'][_0x32ef('0x2a')]=moment();this[_0x32ef('0x16')](_0x2f1349);}};EmailChannel[_0x32ef('0x20')]['handleImapError']=function(_0x4abbd6,_0xcbdec8){if(this[_0x32ef('0xe')][_0x4abbd6]){this[_0x32ef('0xe')][_0x4abbd6][_0x32ef('0x12')][_0x32ef('0x1f')]=_0x32ef('0x1d');this[_0x32ef('0xe')][_0x4abbd6][_0x32ef('0x12')][_0x32ef('0x13')]=_0xcbdec8;return this['emit'](_0x4abbd6);}};EmailChannel[_0x32ef('0x20')][_0x32ef('0x2b')]=function(_0x14b54f,_0x4b97dc){return this[_0x32ef('0x10')][_0x32ef('0x2c')](_0x14b54f,_0x4b97dc);};EmailChannel[_0x32ef('0x20')][_0x32ef('0x2d')]=function(_0x1faf72){var _0x33a0fb=this;if(this[_0x32ef('0xe')][_0x1faf72['id']]){if(_[_0x32ef('0x14')](this[_0x32ef('0xe')][_0x1faf72['id']][_0x32ef('0x2e')])){this[_0x32ef('0xe')][_0x1faf72['id']][_0x32ef('0x2e')]={};}this['mailAccounts'][_0x1faf72['id']][_0x32ef('0x2e')][_0x32ef('0x2a')]=moment();return new BPromise(function(_0x26a40f,_0x1733e3){return _0x33a0fb[_0x32ef('0x10')][_0x32ef('0x2f')](_0x1faf72)[_0x32ef('0x26')](function(_0x596d5a){_0x33a0fb['mailAccounts'][_0x1faf72['id']][_0x32ef('0x2e')][_0x32ef('0x1f')]=_0x32ef('0x30');_0x33a0fb[_0x32ef('0xe')][_0x1faf72['id']]['Smtp'][_0x32ef('0x13')]='';_0x33a0fb[_0x32ef('0x16')](_0x1faf72['id']);_0x26a40f(_0x596d5a);})['catch'](function(_0x4744ba){_0x33a0fb['mailAccounts'][_0x1faf72['id']][_0x32ef('0x2e')][_0x32ef('0x1f')]=_0x32ef('0x1d');_0x33a0fb[_0x32ef('0xe')][_0x1faf72['id']][_0x32ef('0x2e')][_0x32ef('0x13')]=_0x4744ba;_0x33a0fb[_0x32ef('0x16')](_0x1faf72['id']);_0x1733e3(_0x4744ba);});});}return this[_0x32ef('0x10')][_0x32ef('0x2f')](_0x1faf72);};module[_0x32ef('0x31')]=EmailChannel;
\ No newline at end of file