Built motion from commit (unavailable).|2.5.31
[motion2.git] / server / services / email / lib / email.js
index b47c8be..84b02ec 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xa265=['sendMail','smtp','send','Smtp','verify','verified','bluebird','ioredis','../../../config/environment','../../../config/logger','email','defaults','localhost','./imap','./smtp','../rpc/mailAccount','info','mailAccounts','imapAccounts','prototype','emit','name','key','active','status','Imap','messageStatus','isNil','md5','mailAccount:update','refresh','hasOwnProperty','box','bind','handleImapEmail','end','handleImapEnd','error','disabled','handleImapBox','connected','total','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','then','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','handleImapError'];(function(_0x406e46,_0x5799cb){var _0x4a3742=function(_0x1fa435){while(--_0x1fa435){_0x406e46['push'](_0x406e46['shift']());}};_0x4a3742(++_0x5799cb);}(_0xa265,0x16b));var _0x5a26=function(_0x294df2,_0x5c96e6){_0x294df2=_0x294df2-0x0;var _0x2ef934=_0xa265[_0x294df2];return _0x2ef934;};'use strict';var _=require('lodash');var moment=require('moment');var BPromise=require(_0x5a26('0x0'));var md5=require('md5');var Redis=require(_0x5a26('0x1'));var config=require(_0x5a26('0x2'));var logger=require(_0x5a26('0x3'))(_0x5a26('0x4'));config['redis']=_[_0x5a26('0x5')](config['redis'],{'host':_0x5a26('0x6'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config['redis']));var EmailImap=require(_0x5a26('0x7'));var EmailSmtp=require(_0x5a26('0x8'));var mailAccount=require(_0x5a26('0x9'));var md5Accounts={};function EmailChannel(_0x2b1fa0){logger[_0x5a26('0xa')]('start\x20email\x20channel');this['mailAccounts']=_0x2b1fa0[_0x5a26('0xb')];this[_0x5a26('0xc')]={};this['smtp']=new EmailSmtp();}EmailChannel[_0x5a26('0xd')][_0x5a26('0xe')]=function(_0x4bf027){var _0x1aeda5=this['mailAccounts'][_0x4bf027];var _0x333f6c={'id':_0x1aeda5['id'],'name':_0x1aeda5[_0x5a26('0xf')],'key':_0x1aeda5[_0x5a26('0x10')],'active':_0x1aeda5[_0x5a26('0x11')],'Imap':{'status':_0x1aeda5['Imap'][_0x5a26('0x12')],'messageStatus':_0x1aeda5[_0x5a26('0x13')][_0x5a26('0x14')],'total':_0x1aeda5[_0x5a26('0x13')]['total']}};if(_[_0x5a26('0x15')](md5Accounts[_0x4bf027])){md5Accounts[_0x4bf027]={};}var _0x1a8160=md5(JSON['stringify'](_0x333f6c));if(md5Accounts[_0x4bf027][_0x5a26('0x16')]!==_0x1a8160){md5Accounts[_0x4bf027][_0x5a26('0x16')]=_0x1a8160;io['emit'](_0x5a26('0x17'),_0x333f6c);}};EmailChannel[_0x5a26('0xd')][_0x5a26('0x18')]=function(_0x4bbe7c){for(var _0x38bbad in _0x4bbe7c){if(_0x4bbe7c[_0x5a26('0x19')](_0x38bbad)){if(_0x4bbe7c[_0x38bbad][_0x5a26('0x13')]&&_0x4bbe7c[_0x38bbad][_0x5a26('0x11')]){var _0x2d1498=_0x4bbe7c[_0x38bbad]['Imap'];if(!this[_0x5a26('0xc')][_0x5a26('0x19')](_0x2d1498['id'])){this[_0x5a26('0xc')][_0x2d1498['id']]=new EmailImap(_0x2d1498,_0x4bbe7c[_0x38bbad][_0x5a26('0x4')]);this['imapAccounts'][_0x2d1498['id']]['on'](_0x5a26('0x1a'),this['handleImapBox'][_0x5a26('0x1b')](this,_0x38bbad));this[_0x5a26('0xc')][_0x2d1498['id']]['on'](_0x5a26('0x4'),this[_0x5a26('0x1c')][_0x5a26('0x1b')](this,_0x38bbad));this[_0x5a26('0xc')][_0x2d1498['id']]['on'](_0x5a26('0x1d'),this[_0x5a26('0x1e')][_0x5a26('0x1b')](this,_0x38bbad));this[_0x5a26('0xc')][_0x2d1498['id']]['on'](_0x5a26('0x1f'),this['handleImapError'][_0x5a26('0x1b')](this,_0x38bbad));}}else{if(_[_0x5a26('0x15')](this[_0x5a26('0xb')][_0x38bbad]['Imap'])){this[_0x5a26('0xb')][_0x38bbad][_0x5a26('0x13')]={};}this[_0x5a26('0xb')][_0x38bbad][_0x5a26('0x13')][_0x5a26('0x12')]=_0x5a26('0x20');this[_0x5a26('0xb')][_0x38bbad][_0x5a26('0x13')][_0x5a26('0x14')]='';this[_0x5a26('0xe')](_0x38bbad);}}}};EmailChannel['prototype'][_0x5a26('0x21')]=function(_0x26c1bc,_0x512514){if(this[_0x5a26('0xb')][_0x26c1bc]){this[_0x5a26('0xb')][_0x26c1bc][_0x5a26('0x13')][_0x5a26('0x12')]=_0x5a26('0x22');this[_0x5a26('0xb')][_0x26c1bc][_0x5a26('0x13')][_0x5a26('0x14')]=_0x512514[_0x5a26('0xf')];if(_0x512514['messages']){this[_0x5a26('0xb')][_0x26c1bc][_0x5a26('0x13')][_0x5a26('0x23')]=_0x512514['messages']['total'];}return this['emit'](_0x26c1bc);}};EmailChannel[_0x5a26('0xd')]['handleImapEmail']=function(_0x525806,_0x35fd78){logger[_0x5a26('0xa')](_0x5a26('0x24'),_0x35fd78[_0x5a26('0x25')],_0x35fd78[_0x5a26('0x26')],_0x35fd78['from'],_0x525806);if(this[_0x5a26('0xb')][_0x525806]){return mailAccount['notify'](_0x525806,_0x35fd78)[_0x5a26('0x27')](function(_0x697d13){if(_0x697d13){logger[_0x5a26('0xa')](_0x5a26('0x28'));}})[_0x5a26('0x29')](function(_0x429220){logger[_0x5a26('0x1f')](_0x5a26('0x2a'),JSON['stringify'](_0x429220));});}};EmailChannel[_0x5a26('0xd')][_0x5a26('0x1e')]=function(_0x57bdc4){if(this[_0x5a26('0xb')][_0x57bdc4]&&this[_0x5a26('0xb')][_0x57bdc4][_0x5a26('0x13')]){if(this[_0x5a26('0xc')][this[_0x5a26('0xb')][_0x57bdc4]['Imap']['id']]){delete this[_0x5a26('0xc')][this[_0x5a26('0xb')][_0x57bdc4][_0x5a26('0x13')]['id']];}this[_0x5a26('0xb')][_0x57bdc4][_0x5a26('0x13')][_0x5a26('0x2b')]=moment();this[_0x5a26('0xe')](_0x57bdc4);}};EmailChannel[_0x5a26('0xd')][_0x5a26('0x2c')]=function(_0x4faa78,_0x1be5ad){if(this['mailAccounts'][_0x4faa78]){this[_0x5a26('0xb')][_0x4faa78][_0x5a26('0x13')][_0x5a26('0x12')]=_0x5a26('0x1f');this[_0x5a26('0xb')][_0x4faa78][_0x5a26('0x13')][_0x5a26('0x14')]=_0x1be5ad;return this[_0x5a26('0xe')](_0x4faa78);}};EmailChannel[_0x5a26('0xd')][_0x5a26('0x2d')]=function(_0x459f68,_0x48dfab){return this[_0x5a26('0x2e')][_0x5a26('0x2f')](_0x459f68,_0x48dfab);};EmailChannel[_0x5a26('0xd')]['verifySmtp']=function(_0x15414b){var _0x18a076=this;if(this['mailAccounts'][_0x15414b['id']]){if(_['isNil'](this[_0x5a26('0xb')][_0x15414b['id']][_0x5a26('0x30')])){this['mailAccounts'][_0x15414b['id']][_0x5a26('0x30')]={};}this[_0x5a26('0xb')][_0x15414b['id']]['Smtp']['lastSync']=moment();return new BPromise(function(_0x266b3b,_0x4010b0){return _0x18a076['smtp'][_0x5a26('0x31')](_0x15414b)['then'](function(_0x42ec11){_0x18a076[_0x5a26('0xb')][_0x15414b['id']][_0x5a26('0x30')]['status']=_0x5a26('0x32');_0x18a076[_0x5a26('0xb')][_0x15414b['id']][_0x5a26('0x30')][_0x5a26('0x14')]='';_0x18a076[_0x5a26('0xe')](_0x15414b['id']);_0x266b3b(_0x42ec11);})[_0x5a26('0x29')](function(_0x1f0cc6){_0x18a076[_0x5a26('0xb')][_0x15414b['id']][_0x5a26('0x30')][_0x5a26('0x12')]='error';_0x18a076[_0x5a26('0xb')][_0x15414b['id']][_0x5a26('0x30')][_0x5a26('0x14')]=_0x1f0cc6;_0x18a076[_0x5a26('0xe')](_0x15414b['id']);_0x4010b0(_0x1f0cc6);});});}return this[_0x5a26('0x2e')][_0x5a26('0x31')](_0x15414b);};module['exports']=EmailChannel;
\ No newline at end of file
+var _0xf377=['Smtp','smtp','verify','verified','exports','lodash','moment','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','localhost','socket.io-emitter','./imap','../rpc/mailAccount','start\x20email\x20channel','mailAccounts','imapAccounts','emit','name','key','Imap','messageStatus','total','isNil','stringify','prototype','refresh','hasOwnProperty','active','handleImapBox','bind','handleImapEmail','handleImapError','connected','messages','info','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','from','notify','then','Mail\x20accepted\x20from\x20routing','catch','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','handleImapEnd','lastSync','status','send','verifySmtp'];(function(_0x35b5e3,_0xa50391){var _0x3a7cff=function(_0xd83327){while(--_0xd83327){_0x35b5e3['push'](_0x35b5e3['shift']());}};_0x3a7cff(++_0xa50391);}(_0xf377,0x18d));var _0x7f37=function(_0xbca1b1,_0x33f0ce){_0xbca1b1=_0xbca1b1-0x0;var _0x4e1686=_0xf377[_0xbca1b1];return _0x4e1686;};'use strict';var _=require(_0x7f37('0x0'));var moment=require(_0x7f37('0x1'));var BPromise=require(_0x7f37('0x2'));var md5=require(_0x7f37('0x3'));var Redis=require(_0x7f37('0x4'));var config=require(_0x7f37('0x5'));var logger=require(_0x7f37('0x6'))(_0x7f37('0x7'));config[_0x7f37('0x8')]=_[_0x7f37('0x9')](config[_0x7f37('0x8')],{'host':_0x7f37('0xa'),'port':0x18eb});var io=require(_0x7f37('0xb'))(new Redis(config[_0x7f37('0x8')]));var EmailImap=require(_0x7f37('0xc'));var EmailSmtp=require('./smtp');var mailAccount=require(_0x7f37('0xd'));var md5Accounts={};function EmailChannel(_0x34ee92){logger['info'](_0x7f37('0xe'));this[_0x7f37('0xf')]=_0x34ee92[_0x7f37('0xf')];this[_0x7f37('0x10')]={};this['smtp']=new EmailSmtp();}EmailChannel['prototype'][_0x7f37('0x11')]=function(_0x16f799){var _0x4f11c2=this[_0x7f37('0xf')][_0x16f799];var _0x212fde={'id':_0x4f11c2['id'],'name':_0x4f11c2[_0x7f37('0x12')],'key':_0x4f11c2[_0x7f37('0x13')],'active':_0x4f11c2['active'],'Imap':{'status':_0x4f11c2[_0x7f37('0x14')]['status'],'messageStatus':_0x4f11c2['Imap'][_0x7f37('0x15')],'total':_0x4f11c2[_0x7f37('0x14')][_0x7f37('0x16')]}};if(_[_0x7f37('0x17')](md5Accounts[_0x16f799])){md5Accounts[_0x16f799]={};}var _0x5d7997=md5(JSON[_0x7f37('0x18')](_0x212fde));if(md5Accounts[_0x16f799]['md5']!==_0x5d7997){md5Accounts[_0x16f799][_0x7f37('0x3')]=_0x5d7997;io['emit']('mailAccount:update',_0x212fde);}};EmailChannel[_0x7f37('0x19')][_0x7f37('0x1a')]=function(_0x5f0751){for(var _0x25c1de in _0x5f0751){if(_0x5f0751[_0x7f37('0x1b')](_0x25c1de)){if(_0x5f0751[_0x25c1de]['Imap']&&_0x5f0751[_0x25c1de][_0x7f37('0x1c')]){var _0x379505=_0x5f0751[_0x25c1de][_0x7f37('0x14')];if(!this[_0x7f37('0x10')][_0x7f37('0x1b')](_0x379505['id'])){this[_0x7f37('0x10')][_0x379505['id']]=new EmailImap(_0x379505,_0x5f0751[_0x25c1de][_0x7f37('0x7')]);this[_0x7f37('0x10')][_0x379505['id']]['on']('box',this[_0x7f37('0x1d')][_0x7f37('0x1e')](this,_0x25c1de));this[_0x7f37('0x10')][_0x379505['id']]['on']('email',this[_0x7f37('0x1f')][_0x7f37('0x1e')](this,_0x25c1de));this['imapAccounts'][_0x379505['id']]['on']('end',this['handleImapEnd'][_0x7f37('0x1e')](this,_0x25c1de));this[_0x7f37('0x10')][_0x379505['id']]['on']('error',this[_0x7f37('0x20')][_0x7f37('0x1e')](this,_0x25c1de));}}else{if(_[_0x7f37('0x17')](this[_0x7f37('0xf')][_0x25c1de][_0x7f37('0x14')])){this[_0x7f37('0xf')][_0x25c1de][_0x7f37('0x14')]={};}this[_0x7f37('0xf')][_0x25c1de][_0x7f37('0x14')]['status']='disabled';this[_0x7f37('0xf')][_0x25c1de][_0x7f37('0x14')][_0x7f37('0x15')]='';this[_0x7f37('0x11')](_0x25c1de);}}}};EmailChannel[_0x7f37('0x19')]['handleImapBox']=function(_0x186636,_0x97db97){if(this[_0x7f37('0xf')][_0x186636]){this[_0x7f37('0xf')][_0x186636][_0x7f37('0x14')]['status']=_0x7f37('0x21');this[_0x7f37('0xf')][_0x186636]['Imap'][_0x7f37('0x15')]=_0x97db97[_0x7f37('0x12')];if(_0x97db97['messages']){this[_0x7f37('0xf')][_0x186636][_0x7f37('0x14')][_0x7f37('0x16')]=_0x97db97[_0x7f37('0x22')][_0x7f37('0x16')];}return this[_0x7f37('0x11')](_0x186636);}};EmailChannel[_0x7f37('0x19')]['handleImapEmail']=function(_0x5e38ff,_0x61be4b){logger[_0x7f37('0x23')](_0x7f37('0x24'),_0x61be4b[_0x7f37('0x25')],_0x61be4b[_0x7f37('0x26')],_0x61be4b[_0x7f37('0x27')],_0x5e38ff);if(this[_0x7f37('0xf')][_0x5e38ff]){return mailAccount[_0x7f37('0x28')](_0x5e38ff,_0x61be4b)[_0x7f37('0x29')](function(_0x2d2bc3){if(_0x2d2bc3){logger[_0x7f37('0x23')](_0x7f37('0x2a'));}})[_0x7f37('0x2b')](function(_0x519ba5){logger[_0x7f37('0x2c')](_0x7f37('0x2d'),JSON[_0x7f37('0x18')](_0x519ba5));});}};EmailChannel['prototype'][_0x7f37('0x2e')]=function(_0x422b28){if(this[_0x7f37('0xf')][_0x422b28]&&this[_0x7f37('0xf')][_0x422b28][_0x7f37('0x14')]){if(this[_0x7f37('0x10')][this[_0x7f37('0xf')][_0x422b28][_0x7f37('0x14')]['id']]){delete this[_0x7f37('0x10')][this[_0x7f37('0xf')][_0x422b28][_0x7f37('0x14')]['id']];}this[_0x7f37('0xf')][_0x422b28][_0x7f37('0x14')][_0x7f37('0x2f')]=moment();this[_0x7f37('0x11')](_0x422b28);}};EmailChannel[_0x7f37('0x19')][_0x7f37('0x20')]=function(_0x4f1d58,_0x53cbb0){if(this[_0x7f37('0xf')][_0x4f1d58]){this[_0x7f37('0xf')][_0x4f1d58][_0x7f37('0x14')][_0x7f37('0x30')]=_0x7f37('0x2c');this[_0x7f37('0xf')][_0x4f1d58][_0x7f37('0x14')]['messageStatus']=_0x53cbb0;return this[_0x7f37('0x11')](_0x4f1d58);}};EmailChannel[_0x7f37('0x19')]['sendMail']=function(_0x337a4d,_0x1f5f58){return this['smtp'][_0x7f37('0x31')](_0x337a4d,_0x1f5f58);};EmailChannel[_0x7f37('0x19')][_0x7f37('0x32')]=function(_0x4c7a19){var _0x29237e=this;if(this['mailAccounts'][_0x4c7a19['id']]){if(_[_0x7f37('0x17')](this[_0x7f37('0xf')][_0x4c7a19['id']][_0x7f37('0x33')])){this['mailAccounts'][_0x4c7a19['id']][_0x7f37('0x33')]={};}this[_0x7f37('0xf')][_0x4c7a19['id']][_0x7f37('0x33')][_0x7f37('0x2f')]=moment();return new BPromise(function(_0x374f96,_0x19b394){return _0x29237e[_0x7f37('0x34')][_0x7f37('0x35')](_0x4c7a19)['then'](function(_0x3316f3){_0x29237e['mailAccounts'][_0x4c7a19['id']][_0x7f37('0x33')]['status']=_0x7f37('0x36');_0x29237e[_0x7f37('0xf')][_0x4c7a19['id']][_0x7f37('0x33')]['messageStatus']='';_0x29237e[_0x7f37('0x11')](_0x4c7a19['id']);_0x374f96(_0x3316f3);})[_0x7f37('0x2b')](function(_0x535b51){_0x29237e[_0x7f37('0xf')][_0x4c7a19['id']][_0x7f37('0x33')][_0x7f37('0x30')]=_0x7f37('0x2c');_0x29237e['mailAccounts'][_0x4c7a19['id']][_0x7f37('0x33')][_0x7f37('0x15')]=_0x535b51;_0x29237e['emit'](_0x4c7a19['id']);_0x19b394(_0x535b51);});});}return this[_0x7f37('0x34')]['verify'](_0x4c7a19);};module[_0x7f37('0x37')]=EmailChannel;
\ No newline at end of file