Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / services / email / lib / email.js
index e40c311..5aadbbb 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xe9fd=['service','provider','imapAccounts','hasOwnProperty','email','box','handleImapBox','bind','handleImapEmail','end','handleImapEnd','handleImapError','disabled','connected','messages','total','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','from','then','info','catch','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','stringify','sendMail','send','verifySmtp','Smtp','verify','verified','exports','lodash','moment','bluebird','../../../config/environment','../../../config/logger','redis','defaults','localhost','socket.io-emitter','./imap','start\x20email\x20channel','mailAccounts','smtp','prototype','emit','name','key','Imap','status','messageStatus','isNil','md5','mailAccount:update','refresh','active'];(function(_0x5aa1c2,_0x1adfb1){var _0x44a665=function(_0x3910ef){while(--_0x3910ef){_0x5aa1c2['push'](_0x5aa1c2['shift']());}};_0x44a665(++_0x1adfb1);}(_0xe9fd,0x176));var _0xde9f=function(_0x54d87e,_0x25dde1){_0x54d87e=_0x54d87e-0x0;var _0x2538c4=_0xe9fd[_0x54d87e];return _0x2538c4;};'use strict';var _=require(_0xde9f('0x0'));var moment=require(_0xde9f('0x1'));var BPromise=require(_0xde9f('0x2'));var md5=require('md5');var Redis=require('ioredis');var config=require(_0xde9f('0x3'));var logger=require(_0xde9f('0x4'))('email');config[_0xde9f('0x5')]=_[_0xde9f('0x6')](config[_0xde9f('0x5')],{'host':_0xde9f('0x7'),'port':0x18eb});var io=require(_0xde9f('0x8'))(new Redis(config[_0xde9f('0x5')]));var EmailImap=require(_0xde9f('0x9'));var EmailSmtp=require('./smtp');var mailAccount=require('../rpc/mailAccount');var md5Accounts={};function EmailChannel(_0x258c71){logger['info'](_0xde9f('0xa'));this[_0xde9f('0xb')]=_0x258c71['mailAccounts'];this['imapAccounts']={};this[_0xde9f('0xc')]=new EmailSmtp();}EmailChannel[_0xde9f('0xd')][_0xde9f('0xe')]=function(_0x1fa3e5){var _0x441e8f=this[_0xde9f('0xb')][_0x1fa3e5];var _0x5d68db={'id':_0x441e8f['id'],'name':_0x441e8f[_0xde9f('0xf')],'key':_0x441e8f[_0xde9f('0x10')],'active':_0x441e8f['active'],'Imap':{'status':_0x441e8f[_0xde9f('0x11')][_0xde9f('0x12')],'messageStatus':_0x441e8f['Imap'][_0xde9f('0x13')],'total':_0x441e8f[_0xde9f('0x11')]['total']}};if(_[_0xde9f('0x14')](md5Accounts[_0x1fa3e5])){md5Accounts[_0x1fa3e5]={};}var _0x3ee018=md5(JSON['stringify'](_0x5d68db));if(md5Accounts[_0x1fa3e5][_0xde9f('0x15')]!==_0x3ee018){md5Accounts[_0x1fa3e5][_0xde9f('0x15')]=_0x3ee018;io['emit'](_0xde9f('0x16'),_0x5d68db);}};EmailChannel[_0xde9f('0xd')][_0xde9f('0x17')]=function(_0x378a27){for(var _0x2d8224 in _0x378a27){if(_0x378a27['hasOwnProperty'](_0x2d8224)){if(_0x378a27[_0x2d8224][_0xde9f('0x11')]&&_0x378a27[_0x2d8224][_0xde9f('0x18')]){var _0x21d9d5=_0x378a27[_0x2d8224][_0xde9f('0x11')];if(!_0x21d9d5[_0xde9f('0x19')]&&_0x378a27[_0x2d8224][_0xde9f('0x1a')]!=='custom')_0x21d9d5['service']=_0x378a27[_0x2d8224][_0xde9f('0x1a')];if(!this[_0xde9f('0x1b')][_0xde9f('0x1c')](_0x21d9d5['id'])){this[_0xde9f('0x1b')][_0x21d9d5['id']]=new EmailImap(_0x21d9d5,_0x378a27[_0x2d8224][_0xde9f('0x1d')]);this['imapAccounts'][_0x21d9d5['id']]['on'](_0xde9f('0x1e'),this[_0xde9f('0x1f')][_0xde9f('0x20')](this,_0x2d8224));this[_0xde9f('0x1b')][_0x21d9d5['id']]['on'](_0xde9f('0x1d'),this[_0xde9f('0x21')]['bind'](this,_0x2d8224));this['imapAccounts'][_0x21d9d5['id']]['on'](_0xde9f('0x22'),this[_0xde9f('0x23')][_0xde9f('0x20')](this,_0x2d8224));this[_0xde9f('0x1b')][_0x21d9d5['id']]['on']('error',this[_0xde9f('0x24')]['bind'](this,_0x2d8224));}}else{if(_[_0xde9f('0x14')](this[_0xde9f('0xb')][_0x2d8224][_0xde9f('0x11')])){this['mailAccounts'][_0x2d8224][_0xde9f('0x11')]={};}this['mailAccounts'][_0x2d8224][_0xde9f('0x11')][_0xde9f('0x12')]=_0xde9f('0x25');this[_0xde9f('0xb')][_0x2d8224][_0xde9f('0x11')][_0xde9f('0x13')]='';this[_0xde9f('0xe')](_0x2d8224);}}}};EmailChannel[_0xde9f('0xd')]['handleImapBox']=function(_0x1b5dba,_0x4d0265){if(this['mailAccounts'][_0x1b5dba]){this[_0xde9f('0xb')][_0x1b5dba]['Imap'][_0xde9f('0x12')]=_0xde9f('0x26');this[_0xde9f('0xb')][_0x1b5dba][_0xde9f('0x11')][_0xde9f('0x13')]=_0x4d0265[_0xde9f('0xf')];if(_0x4d0265['messages']){this[_0xde9f('0xb')][_0x1b5dba][_0xde9f('0x11')]['total']=_0x4d0265[_0xde9f('0x27')][_0xde9f('0x28')];}return this['emit'](_0x1b5dba);}};EmailChannel[_0xde9f('0xd')][_0xde9f('0x21')]=function(_0x11fe3c,_0x467da7){logger['info'](_0xde9f('0x29'),_0x467da7[_0xde9f('0x2a')],_0x467da7['lastName'],_0x467da7[_0xde9f('0x2b')],_0x11fe3c);if(this[_0xde9f('0xb')][_0x11fe3c]){return mailAccount['notify'](_0x11fe3c,_0x467da7)[_0xde9f('0x2c')](function(_0x1fc2ab){if(_0x1fc2ab){logger[_0xde9f('0x2d')]('Mail\x20accepted\x20from\x20routing');}})[_0xde9f('0x2e')](function(_0x52395d){logger[_0xde9f('0x2f')](_0xde9f('0x30'),JSON[_0xde9f('0x31')](_0x52395d));});}};EmailChannel[_0xde9f('0xd')][_0xde9f('0x23')]=function(_0xb086d8){if(this[_0xde9f('0xb')][_0xb086d8]&&this[_0xde9f('0xb')][_0xb086d8]['Imap']){if(this[_0xde9f('0x1b')][this[_0xde9f('0xb')][_0xb086d8][_0xde9f('0x11')]['id']]){delete this['imapAccounts'][this[_0xde9f('0xb')][_0xb086d8][_0xde9f('0x11')]['id']];}this[_0xde9f('0xb')][_0xb086d8][_0xde9f('0x11')]['lastSync']=moment();this[_0xde9f('0xe')](_0xb086d8);}};EmailChannel[_0xde9f('0xd')][_0xde9f('0x24')]=function(_0x59dd96,_0x37a7f3){if(this[_0xde9f('0xb')][_0x59dd96]){this[_0xde9f('0xb')][_0x59dd96][_0xde9f('0x11')]['status']='error';this[_0xde9f('0xb')][_0x59dd96][_0xde9f('0x11')][_0xde9f('0x13')]=_0x37a7f3;return this['emit'](_0x59dd96);}};EmailChannel[_0xde9f('0xd')][_0xde9f('0x32')]=function(_0x26c0a3,_0x4a9495){return this[_0xde9f('0xc')][_0xde9f('0x33')](_0x26c0a3,_0x4a9495);};EmailChannel[_0xde9f('0xd')][_0xde9f('0x34')]=function(_0x2bd4d5){var _0x391ee1=this;if(this[_0xde9f('0xb')][_0x2bd4d5['id']]){if(_[_0xde9f('0x14')](this[_0xde9f('0xb')][_0x2bd4d5['id']][_0xde9f('0x35')])){this['mailAccounts'][_0x2bd4d5['id']][_0xde9f('0x35')]={};}this[_0xde9f('0xb')][_0x2bd4d5['id']]['Smtp']['lastSync']=moment();return new BPromise(function(_0x2445b0,_0x319d21){return _0x391ee1[_0xde9f('0xc')][_0xde9f('0x36')](_0x2bd4d5)[_0xde9f('0x2c')](function(_0x3c082c){_0x391ee1[_0xde9f('0xb')][_0x2bd4d5['id']][_0xde9f('0x35')]['status']=_0xde9f('0x37');_0x391ee1['mailAccounts'][_0x2bd4d5['id']][_0xde9f('0x35')][_0xde9f('0x13')]='';_0x391ee1[_0xde9f('0xe')](_0x2bd4d5['id']);_0x2445b0(_0x3c082c);})[_0xde9f('0x2e')](function(_0x545faa){_0x391ee1[_0xde9f('0xb')][_0x2bd4d5['id']][_0xde9f('0x35')][_0xde9f('0x12')]=_0xde9f('0x2f');_0x391ee1['mailAccounts'][_0x2bd4d5['id']]['Smtp'][_0xde9f('0x13')]=_0x545faa;_0x391ee1['emit'](_0x2bd4d5['id']);_0x319d21(_0x545faa);});});}return this[_0xde9f('0xc')][_0xde9f('0x36')](_0x2bd4d5);};module[_0xde9f('0x38')]=EmailChannel;
\ No newline at end of file
+var _0xdff6=['sendMail','verifySmtp','Smtp','verify','then','verified','exports','lodash','moment','bluebird','md5','ioredis','../../../config/environment','email','redis','socket.io-emitter','./imap','./smtp','../rpc/mailAccount','mailAccounts','imapAccounts','smtp','prototype','emit','name','active','Imap','status','messageStatus','stringify','mailAccount:update','refresh','hasOwnProperty','service','provider','custom','handleImapBox','bind','end','error','handleImapError','isNil','disabled','messages','total','handleImapEmail','firstName','lastName','notify','info','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync'];(function(_0x5f08a6,_0x400121){var _0x5d0641=function(_0x304467){while(--_0x304467){_0x5f08a6['push'](_0x5f08a6['shift']());}};_0x5d0641(++_0x400121);}(_0xdff6,0xa9));var _0x6dff=function(_0x5a769c,_0x5f16e5){_0x5a769c=_0x5a769c-0x0;var _0xe27e80=_0xdff6[_0x5a769c];return _0xe27e80;};'use strict';var _=require(_0x6dff('0x0'));var moment=require(_0x6dff('0x1'));var BPromise=require(_0x6dff('0x2'));var md5=require(_0x6dff('0x3'));var Redis=require(_0x6dff('0x4'));var config=require(_0x6dff('0x5'));var logger=require('../../../config/logger')(_0x6dff('0x6'));config[_0x6dff('0x7')]=_['defaults'](config['redis'],{'host':'localhost','port':0x18eb});var io=require(_0x6dff('0x8'))(new Redis(config[_0x6dff('0x7')]));var EmailImap=require(_0x6dff('0x9'));var EmailSmtp=require(_0x6dff('0xa'));var mailAccount=require(_0x6dff('0xb'));var md5Accounts={};function EmailChannel(_0x24a7ad){logger['info']('start\x20email\x20channel');this[_0x6dff('0xc')]=_0x24a7ad[_0x6dff('0xc')];this[_0x6dff('0xd')]={};this[_0x6dff('0xe')]=new EmailSmtp();}EmailChannel[_0x6dff('0xf')][_0x6dff('0x10')]=function(_0x18caf1){var _0x3a4f3e=this[_0x6dff('0xc')][_0x18caf1];var _0x4afcfe={'id':_0x3a4f3e['id'],'name':_0x3a4f3e[_0x6dff('0x11')],'key':_0x3a4f3e['key'],'active':_0x3a4f3e[_0x6dff('0x12')],'Imap':{'status':_0x3a4f3e[_0x6dff('0x13')][_0x6dff('0x14')],'messageStatus':_0x3a4f3e[_0x6dff('0x13')][_0x6dff('0x15')],'total':_0x3a4f3e[_0x6dff('0x13')]['total']}};if(_['isNil'](md5Accounts[_0x18caf1])){md5Accounts[_0x18caf1]={};}var _0xd27204=md5(JSON[_0x6dff('0x16')](_0x4afcfe));if(md5Accounts[_0x18caf1][_0x6dff('0x3')]!==_0xd27204){md5Accounts[_0x18caf1]['md5']=_0xd27204;io[_0x6dff('0x10')](_0x6dff('0x17'),_0x4afcfe);}};EmailChannel[_0x6dff('0xf')][_0x6dff('0x18')]=function(_0x489d73){for(var _0x4e5469 in _0x489d73){if(_0x489d73[_0x6dff('0x19')](_0x4e5469)){if(_0x489d73[_0x4e5469][_0x6dff('0x13')]&&_0x489d73[_0x4e5469][_0x6dff('0x12')]){var _0x49e52f=_0x489d73[_0x4e5469][_0x6dff('0x13')];if(!_0x49e52f[_0x6dff('0x1a')]&&_0x489d73[_0x4e5469][_0x6dff('0x1b')]!==_0x6dff('0x1c'))_0x49e52f[_0x6dff('0x1a')]=_0x489d73[_0x4e5469][_0x6dff('0x1b')];if(!this['imapAccounts'][_0x6dff('0x19')](_0x49e52f['id'])){this[_0x6dff('0xd')][_0x49e52f['id']]=new EmailImap(_0x49e52f,_0x489d73[_0x4e5469][_0x6dff('0x6')]);this[_0x6dff('0xd')][_0x49e52f['id']]['on']('box',this[_0x6dff('0x1d')][_0x6dff('0x1e')](this,_0x4e5469));this[_0x6dff('0xd')][_0x49e52f['id']]['on'](_0x6dff('0x6'),this['handleImapEmail'][_0x6dff('0x1e')](this,_0x4e5469));this[_0x6dff('0xd')][_0x49e52f['id']]['on'](_0x6dff('0x1f'),this['handleImapEnd'][_0x6dff('0x1e')](this,_0x4e5469));this[_0x6dff('0xd')][_0x49e52f['id']]['on'](_0x6dff('0x20'),this[_0x6dff('0x21')][_0x6dff('0x1e')](this,_0x4e5469));}}else{if(_[_0x6dff('0x22')](this[_0x6dff('0xc')][_0x4e5469][_0x6dff('0x13')])){this[_0x6dff('0xc')][_0x4e5469][_0x6dff('0x13')]={};}this[_0x6dff('0xc')][_0x4e5469][_0x6dff('0x13')][_0x6dff('0x14')]=_0x6dff('0x23');this[_0x6dff('0xc')][_0x4e5469]['Imap']['messageStatus']='';this[_0x6dff('0x10')](_0x4e5469);}}}};EmailChannel[_0x6dff('0xf')][_0x6dff('0x1d')]=function(_0x128a43,_0x42d592){if(this[_0x6dff('0xc')][_0x128a43]){this[_0x6dff('0xc')][_0x128a43][_0x6dff('0x13')][_0x6dff('0x14')]='connected';this['mailAccounts'][_0x128a43]['Imap'][_0x6dff('0x15')]=_0x42d592[_0x6dff('0x11')];if(_0x42d592[_0x6dff('0x24')]){this['mailAccounts'][_0x128a43]['Imap'][_0x6dff('0x25')]=_0x42d592[_0x6dff('0x24')][_0x6dff('0x25')];}return this[_0x6dff('0x10')](_0x128a43);}};EmailChannel[_0x6dff('0xf')][_0x6dff('0x26')]=function(_0x42e268,_0x32f8ce){logger['info']('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x32f8ce[_0x6dff('0x27')],_0x32f8ce[_0x6dff('0x28')],_0x32f8ce['from'],_0x42e268);if(this['mailAccounts'][_0x42e268]){return mailAccount[_0x6dff('0x29')](_0x42e268,_0x32f8ce)['then'](function(_0x65f79a){if(_0x65f79a){logger[_0x6dff('0x2a')](_0x6dff('0x2b'));}})[_0x6dff('0x2c')](function(_0x5cce57){logger[_0x6dff('0x20')](_0x6dff('0x2d'),JSON[_0x6dff('0x16')](_0x5cce57));});}};EmailChannel[_0x6dff('0xf')]['handleImapEnd']=function(_0x3ad2f4){if(this[_0x6dff('0xc')][_0x3ad2f4]&&this['mailAccounts'][_0x3ad2f4][_0x6dff('0x13')]){if(this[_0x6dff('0xd')][this[_0x6dff('0xc')][_0x3ad2f4]['Imap']['id']]){delete this[_0x6dff('0xd')][this['mailAccounts'][_0x3ad2f4]['Imap']['id']];}this[_0x6dff('0xc')][_0x3ad2f4]['Imap'][_0x6dff('0x2e')]=moment();this[_0x6dff('0x10')](_0x3ad2f4);}};EmailChannel['prototype']['handleImapError']=function(_0x31ced7,_0x1eedb2){if(this[_0x6dff('0xc')][_0x31ced7]){this[_0x6dff('0xc')][_0x31ced7][_0x6dff('0x13')][_0x6dff('0x14')]=_0x6dff('0x20');this[_0x6dff('0xc')][_0x31ced7][_0x6dff('0x13')][_0x6dff('0x15')]=_0x1eedb2;return this[_0x6dff('0x10')](_0x31ced7);}};EmailChannel['prototype'][_0x6dff('0x2f')]=function(_0xc7a4c6,_0x595111){return this[_0x6dff('0xe')]['send'](_0xc7a4c6,_0x595111);};EmailChannel[_0x6dff('0xf')][_0x6dff('0x30')]=function(_0x119f33){var _0x3d3f58=this;if(this[_0x6dff('0xc')][_0x119f33['id']]){if(_[_0x6dff('0x22')](this[_0x6dff('0xc')][_0x119f33['id']][_0x6dff('0x31')])){this[_0x6dff('0xc')][_0x119f33['id']][_0x6dff('0x31')]={};}this[_0x6dff('0xc')][_0x119f33['id']]['Smtp'][_0x6dff('0x2e')]=moment();return new BPromise(function(_0x77d20b,_0x3a1bd4){return _0x3d3f58[_0x6dff('0xe')][_0x6dff('0x32')](_0x119f33)[_0x6dff('0x33')](function(_0x3183bb){_0x3d3f58[_0x6dff('0xc')][_0x119f33['id']][_0x6dff('0x31')][_0x6dff('0x14')]=_0x6dff('0x34');_0x3d3f58[_0x6dff('0xc')][_0x119f33['id']]['Smtp'][_0x6dff('0x15')]='';_0x3d3f58[_0x6dff('0x10')](_0x119f33['id']);_0x77d20b(_0x3183bb);})[_0x6dff('0x2c')](function(_0x224238){_0x3d3f58[_0x6dff('0xc')][_0x119f33['id']][_0x6dff('0x31')][_0x6dff('0x14')]='error';_0x3d3f58[_0x6dff('0xc')][_0x119f33['id']][_0x6dff('0x31')][_0x6dff('0x15')]=_0x224238;_0x3d3f58[_0x6dff('0x10')](_0x119f33['id']);_0x3a1bd4(_0x224238);});});}return this[_0x6dff('0xe')][_0x6dff('0x32')](_0x119f33);};module[_0x6dff('0x35')]=EmailChannel;
\ No newline at end of file