Built motion from commit b4f7ded2.|2.0.69
[motion2.git] / server / services / email / lib / email.js
index e69c8f8..e6d36d4 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5d8e=['end','handleImapEnd','handleImapError','isNil','Imap','status','disabled','messageStatus','connected','name','messages','total','handleImapEmail','info','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','lastName','Mail\x20accepted\x20from\x20routing','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','stringify','sendMail','verifySmtp','Smtp','verify','then','verified','catch','exports','lodash','moment','./imap','../../../config/logger','email','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','emit','refresh','hasOwnProperty','active','box','handleImapBox','bind'];(function(_0x2aa429,_0xdcc091){var _0x299889=function(_0x57fcf4){while(--_0x57fcf4){_0x2aa429['push'](_0x2aa429['shift']());}};_0x299889(++_0xdcc091);}(_0x5d8e,0xd5));var _0xe5d8=function(_0x468015,_0x14829d){_0x468015=_0x468015-0x0;var _0x4eafda=_0x5d8e[_0x468015];return _0x4eafda;};'use strict';var _=require(_0xe5d8('0x0'));var moment=require(_0xe5d8('0x1'));var BPromise=require('bluebird');var io=require('socket.io-emitter')({'host':'localhost','port':0x18eb});var EmailImap=require(_0xe5d8('0x2'));var EmailSmtp=require('./smtp');var logger=require(_0xe5d8('0x3'))(_0xe5d8('0x4'));var mailAccount=require('../rpc/mailAccount');function EmailChannel(_0x8606b6){logger['info'](_0xe5d8('0x5'));this[_0xe5d8('0x6')]=_0x8606b6['mailAccounts'];this[_0xe5d8('0x7')]={};this[_0xe5d8('0x8')]=new EmailSmtp();}EmailChannel[_0xe5d8('0x9')][_0xe5d8('0xa')]=function(_0x456846){io[_0xe5d8('0xa')]('mailAccount:update',this[_0xe5d8('0x6')][_0x456846]);};EmailChannel[_0xe5d8('0x9')][_0xe5d8('0xb')]=function(_0x392416){for(var _0xa9a435 in _0x392416){if(_0x392416[_0xe5d8('0xc')](_0xa9a435)){if(_0x392416[_0xa9a435]['Imap']&&_0x392416[_0xa9a435][_0xe5d8('0xd')]){var _0x3be02e=_0x392416[_0xa9a435]['Imap'];if(!this[_0xe5d8('0x7')][_0xe5d8('0xc')](_0x3be02e['id'])){this[_0xe5d8('0x7')][_0x3be02e['id']]=new EmailImap(_0x3be02e,_0x392416[_0xa9a435][_0xe5d8('0x4')]);this['imapAccounts'][_0x3be02e['id']]['on'](_0xe5d8('0xe'),this[_0xe5d8('0xf')][_0xe5d8('0x10')](this,_0xa9a435));this[_0xe5d8('0x7')][_0x3be02e['id']]['on'](_0xe5d8('0x4'),this['handleImapEmail'][_0xe5d8('0x10')](this,_0xa9a435));this[_0xe5d8('0x7')][_0x3be02e['id']]['on'](_0xe5d8('0x11'),this[_0xe5d8('0x12')][_0xe5d8('0x10')](this,_0xa9a435));this['imapAccounts'][_0x3be02e['id']]['on']('error',this[_0xe5d8('0x13')][_0xe5d8('0x10')](this,_0xa9a435));}}else{if(_[_0xe5d8('0x14')](this[_0xe5d8('0x6')][_0xa9a435][_0xe5d8('0x15')])){this[_0xe5d8('0x6')][_0xa9a435][_0xe5d8('0x15')]={};}this[_0xe5d8('0x6')][_0xa9a435]['Imap'][_0xe5d8('0x16')]=_0xe5d8('0x17');this[_0xe5d8('0x6')][_0xa9a435][_0xe5d8('0x15')][_0xe5d8('0x18')]='';this[_0xe5d8('0xa')](_0xa9a435);}}}};EmailChannel[_0xe5d8('0x9')][_0xe5d8('0xf')]=function(_0x3447b8,_0x4bc0a4){if(this[_0xe5d8('0x6')][_0x3447b8]){this[_0xe5d8('0x6')][_0x3447b8][_0xe5d8('0x15')]['status']=_0xe5d8('0x19');this[_0xe5d8('0x6')][_0x3447b8][_0xe5d8('0x15')][_0xe5d8('0x18')]=_0x4bc0a4[_0xe5d8('0x1a')];if(_0x4bc0a4['messages']){this['mailAccounts'][_0x3447b8][_0xe5d8('0x15')]['total']=_0x4bc0a4[_0xe5d8('0x1b')][_0xe5d8('0x1c')];}return this[_0xe5d8('0xa')](_0x3447b8);}};EmailChannel[_0xe5d8('0x9')][_0xe5d8('0x1d')]=function(_0x10fee6,_0x3ef5aa){logger[_0xe5d8('0x1e')](_0xe5d8('0x1f'),_0x3ef5aa[_0xe5d8('0x20')],_0x3ef5aa[_0xe5d8('0x21')],_0x3ef5aa['from'],_0x10fee6);if(this[_0xe5d8('0x6')][_0x10fee6]){return mailAccount['notify'](_0x10fee6,_0x3ef5aa)['then'](function(_0x5e33a5){if(_0x5e33a5){logger['info'](_0xe5d8('0x22'));}})['catch'](function(_0x8322a9){logger[_0xe5d8('0x23')](_0xe5d8('0x24'),JSON[_0xe5d8('0x25')](_0x8322a9));});}};EmailChannel[_0xe5d8('0x9')]['handleImapEnd']=function(_0x378e5b){if(this['mailAccounts'][_0x378e5b]&&this[_0xe5d8('0x6')][_0x378e5b][_0xe5d8('0x15')]){if(this[_0xe5d8('0x7')][this['mailAccounts'][_0x378e5b][_0xe5d8('0x15')]['id']]){delete this[_0xe5d8('0x7')][this['mailAccounts'][_0x378e5b]['Imap']['id']];}this[_0xe5d8('0x6')][_0x378e5b][_0xe5d8('0x15')]['lastSync']=moment();this['emit'](_0x378e5b);}};EmailChannel[_0xe5d8('0x9')][_0xe5d8('0x13')]=function(_0x9f3ec7,_0x1ceed0){if(this[_0xe5d8('0x6')][_0x9f3ec7]){this[_0xe5d8('0x6')][_0x9f3ec7][_0xe5d8('0x15')][_0xe5d8('0x16')]=_0xe5d8('0x23');this[_0xe5d8('0x6')][_0x9f3ec7][_0xe5d8('0x15')][_0xe5d8('0x18')]=_0x1ceed0;return this[_0xe5d8('0xa')](_0x9f3ec7);}};EmailChannel[_0xe5d8('0x9')][_0xe5d8('0x26')]=function(_0x54c388,_0x558de3){return this['smtp']['send'](_0x54c388,_0x558de3);};EmailChannel['prototype'][_0xe5d8('0x27')]=function(_0x47d030){var _0x4f38f7=this;if(this[_0xe5d8('0x6')][_0x47d030['id']]){if(_[_0xe5d8('0x14')](this[_0xe5d8('0x6')][_0x47d030['id']]['Smtp'])){this[_0xe5d8('0x6')][_0x47d030['id']]['Smtp']={};}this[_0xe5d8('0x6')][_0x47d030['id']][_0xe5d8('0x28')]['lastSync']=moment();return new BPromise(function(_0x1d281b,_0x5c0d75){return _0x4f38f7[_0xe5d8('0x8')][_0xe5d8('0x29')](_0x47d030)[_0xe5d8('0x2a')](function(_0x1b3b3f){_0x4f38f7[_0xe5d8('0x6')][_0x47d030['id']][_0xe5d8('0x28')][_0xe5d8('0x16')]=_0xe5d8('0x2b');_0x4f38f7['mailAccounts'][_0x47d030['id']][_0xe5d8('0x28')][_0xe5d8('0x18')]='';_0x4f38f7[_0xe5d8('0xa')](_0x47d030['id']);_0x1d281b(_0x1b3b3f);})[_0xe5d8('0x2c')](function(_0x5e3d5f){_0x4f38f7[_0xe5d8('0x6')][_0x47d030['id']][_0xe5d8('0x28')][_0xe5d8('0x16')]=_0xe5d8('0x23');_0x4f38f7['mailAccounts'][_0x47d030['id']][_0xe5d8('0x28')]['messageStatus']=_0x5e3d5f;_0x4f38f7['emit'](_0x47d030['id']);_0x5c0d75(_0x5e3d5f);});});}return this[_0xe5d8('0x8')]['verify'](_0x47d030);};module[_0xe5d8('0x2d')]=EmailChannel;
\ No newline at end of file
+var _0x0917=['send','verifySmtp','Smtp','verify','verified','messageStatus','exports','lodash','moment','bluebird','md5','socket.io-emitter','./imap','email','../rpc/mailAccount','info','start\x20email\x20channel','mailAccounts','smtp','prototype','emit','name','key','active','status','Imap','total','isNil','stringify','mailAccount:update','refresh','hasOwnProperty','imapAccounts','box','handleImapBox','bind','handleImapEmail','end','handleImapEnd','disabled','connected','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','firstName','from','then','catch','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','handleImapError','sendMail'];(function(_0x35eff5,_0x4703b1){var _0x44a3e2=function(_0x4c7aa8){while(--_0x4c7aa8){_0x35eff5['push'](_0x35eff5['shift']());}};_0x44a3e2(++_0x4703b1);}(_0x0917,0xa3));var _0x7091=function(_0x290201,_0x279632){_0x290201=_0x290201-0x0;var _0x3d5c08=_0x0917[_0x290201];return _0x3d5c08;};'use strict';var _=require(_0x7091('0x0'));var moment=require(_0x7091('0x1'));var BPromise=require(_0x7091('0x2'));var md5=require(_0x7091('0x3'));var io=require(_0x7091('0x4'))({'host':'localhost','port':0x18eb});var EmailImap=require(_0x7091('0x5'));var EmailSmtp=require('./smtp');var logger=require('../../../config/logger')(_0x7091('0x6'));var mailAccount=require(_0x7091('0x7'));var md5Accounts={};function EmailChannel(_0x4a6c1a){logger[_0x7091('0x8')](_0x7091('0x9'));this[_0x7091('0xa')]=_0x4a6c1a[_0x7091('0xa')];this['imapAccounts']={};this[_0x7091('0xb')]=new EmailSmtp();}EmailChannel[_0x7091('0xc')][_0x7091('0xd')]=function(_0x415bab){var _0x20135d=this[_0x7091('0xa')][_0x415bab];var _0x403e07={'id':_0x20135d['id'],'name':_0x20135d[_0x7091('0xe')],'key':_0x20135d[_0x7091('0xf')],'active':_0x20135d[_0x7091('0x10')],'Imap':{'status':_0x20135d['Imap'][_0x7091('0x11')],'messageStatus':_0x20135d['Imap']['messageStatus'],'total':_0x20135d[_0x7091('0x12')][_0x7091('0x13')]}};if(_[_0x7091('0x14')](md5Accounts[_0x415bab])){md5Accounts[_0x415bab]={};}var _0x454e75=md5(JSON[_0x7091('0x15')](_0x403e07));if(md5Accounts[_0x415bab][_0x7091('0x3')]!==_0x454e75){md5Accounts[_0x415bab][_0x7091('0x3')]=_0x454e75;io[_0x7091('0xd')](_0x7091('0x16'),_0x403e07);}};EmailChannel[_0x7091('0xc')][_0x7091('0x17')]=function(_0x403a40){for(var _0x15462f in _0x403a40){if(_0x403a40['hasOwnProperty'](_0x15462f)){if(_0x403a40[_0x15462f][_0x7091('0x12')]&&_0x403a40[_0x15462f][_0x7091('0x10')]){var _0x593405=_0x403a40[_0x15462f][_0x7091('0x12')];if(!this['imapAccounts'][_0x7091('0x18')](_0x593405['id'])){this['imapAccounts'][_0x593405['id']]=new EmailImap(_0x593405,_0x403a40[_0x15462f]['email']);this[_0x7091('0x19')][_0x593405['id']]['on'](_0x7091('0x1a'),this[_0x7091('0x1b')][_0x7091('0x1c')](this,_0x15462f));this['imapAccounts'][_0x593405['id']]['on'](_0x7091('0x6'),this[_0x7091('0x1d')][_0x7091('0x1c')](this,_0x15462f));this['imapAccounts'][_0x593405['id']]['on'](_0x7091('0x1e'),this[_0x7091('0x1f')]['bind'](this,_0x15462f));this['imapAccounts'][_0x593405['id']]['on']('error',this['handleImapError'][_0x7091('0x1c')](this,_0x15462f));}}else{if(_[_0x7091('0x14')](this['mailAccounts'][_0x15462f][_0x7091('0x12')])){this[_0x7091('0xa')][_0x15462f]['Imap']={};}this[_0x7091('0xa')][_0x15462f][_0x7091('0x12')]['status']=_0x7091('0x20');this[_0x7091('0xa')][_0x15462f]['Imap']['messageStatus']='';this[_0x7091('0xd')](_0x15462f);}}}};EmailChannel[_0x7091('0xc')][_0x7091('0x1b')]=function(_0x3bf5b7,_0x4169c3){if(this['mailAccounts'][_0x3bf5b7]){this[_0x7091('0xa')][_0x3bf5b7][_0x7091('0x12')][_0x7091('0x11')]=_0x7091('0x21');this[_0x7091('0xa')][_0x3bf5b7]['Imap']['messageStatus']=_0x4169c3['name'];if(_0x4169c3[_0x7091('0x22')]){this['mailAccounts'][_0x3bf5b7][_0x7091('0x12')][_0x7091('0x13')]=_0x4169c3['messages'][_0x7091('0x13')];}return this[_0x7091('0xd')](_0x3bf5b7);}};EmailChannel[_0x7091('0xc')][_0x7091('0x1d')]=function(_0x213487,_0x3f9215){logger['info'](_0x7091('0x23'),_0x3f9215[_0x7091('0x24')],_0x3f9215['lastName'],_0x3f9215[_0x7091('0x25')],_0x213487);if(this[_0x7091('0xa')][_0x213487]){return mailAccount['notify'](_0x213487,_0x3f9215)[_0x7091('0x26')](function(_0x110c3b){if(_0x110c3b){logger['info']('Mail\x20accepted\x20from\x20routing');}})[_0x7091('0x27')](function(_0x2134a1){logger[_0x7091('0x28')](_0x7091('0x29'),JSON['stringify'](_0x2134a1));});}};EmailChannel[_0x7091('0xc')][_0x7091('0x1f')]=function(_0x1caca2){if(this[_0x7091('0xa')][_0x1caca2]&&this[_0x7091('0xa')][_0x1caca2][_0x7091('0x12')]){if(this['imapAccounts'][this[_0x7091('0xa')][_0x1caca2][_0x7091('0x12')]['id']]){delete this[_0x7091('0x19')][this[_0x7091('0xa')][_0x1caca2][_0x7091('0x12')]['id']];}this[_0x7091('0xa')][_0x1caca2][_0x7091('0x12')][_0x7091('0x2a')]=moment();this[_0x7091('0xd')](_0x1caca2);}};EmailChannel[_0x7091('0xc')][_0x7091('0x2b')]=function(_0x3f9097,_0x13c5b0){if(this[_0x7091('0xa')][_0x3f9097]){this['mailAccounts'][_0x3f9097]['Imap'][_0x7091('0x11')]='error';this[_0x7091('0xa')][_0x3f9097][_0x7091('0x12')]['messageStatus']=_0x13c5b0;return this[_0x7091('0xd')](_0x3f9097);}};EmailChannel['prototype'][_0x7091('0x2c')]=function(_0x40a190,_0x4dfcd1){return this[_0x7091('0xb')][_0x7091('0x2d')](_0x40a190,_0x4dfcd1);};EmailChannel[_0x7091('0xc')][_0x7091('0x2e')]=function(_0x4ee65c){var _0x80005e=this;if(this[_0x7091('0xa')][_0x4ee65c['id']]){if(_['isNil'](this[_0x7091('0xa')][_0x4ee65c['id']][_0x7091('0x2f')])){this[_0x7091('0xa')][_0x4ee65c['id']][_0x7091('0x2f')]={};}this[_0x7091('0xa')][_0x4ee65c['id']][_0x7091('0x2f')][_0x7091('0x2a')]=moment();return new BPromise(function(_0x16058f,_0x5cb510){return _0x80005e[_0x7091('0xb')][_0x7091('0x30')](_0x4ee65c)['then'](function(_0x2547a8){_0x80005e[_0x7091('0xa')][_0x4ee65c['id']]['Smtp'][_0x7091('0x11')]=_0x7091('0x31');_0x80005e[_0x7091('0xa')][_0x4ee65c['id']][_0x7091('0x2f')][_0x7091('0x32')]='';_0x80005e[_0x7091('0xd')](_0x4ee65c['id']);_0x16058f(_0x2547a8);})['catch'](function(_0x38d4ee){_0x80005e[_0x7091('0xa')][_0x4ee65c['id']][_0x7091('0x2f')]['status']=_0x7091('0x28');_0x80005e[_0x7091('0xa')][_0x4ee65c['id']][_0x7091('0x2f')]['messageStatus']=_0x38d4ee;_0x80005e[_0x7091('0xd')](_0x4ee65c['id']);_0x5cb510(_0x38d4ee);});});}return this[_0x7091('0xb')][_0x7091('0x30')](_0x4ee65c);};module[_0x7091('0x33')]=EmailChannel;
\ No newline at end of file