Built motion from commit (unavailable).|2.3.4
[motion2.git] / server / services / email / lib / email.js
index 2168bda..4ed4929 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x0af5=['end','handleImapEnd','error','handleImapError','isNil','emit','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','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','sendMail','send','verifySmtp','Smtp','verified','verify','exports','moment','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','localhost','socket.io-emitter','./smtp','../rpc/mailAccount','start\x20email\x20channel','mailAccounts','smtp','prototype','key','active','Imap','status','messageStatus','refresh','hasOwnProperty','imapAccounts','handleImapBox','bind'];(function(_0x45c262,_0x2e3ce5){var _0x4f2ba6=function(_0x4912d1){while(--_0x4912d1){_0x45c262['push'](_0x45c262['shift']());}};_0x4f2ba6(++_0x2e3ce5);}(_0x0af5,0x158));var _0x50af=function(_0x1f0082,_0x1fdc1d){_0x1f0082=_0x1f0082-0x0;var _0x55ecf9=_0x0af5[_0x1f0082];return _0x55ecf9;};'use strict';var _=require('lodash');var moment=require(_0x50af('0x0'));var BPromise=require(_0x50af('0x1'));var md5=require(_0x50af('0x2'));var Redis=require(_0x50af('0x3'));var config=require(_0x50af('0x4'));var logger=require(_0x50af('0x5'))(_0x50af('0x6'));config[_0x50af('0x7')]=_[_0x50af('0x8')](config[_0x50af('0x7')],{'host':_0x50af('0x9'),'port':0x18eb});var io=require(_0x50af('0xa'))(new Redis(config['redis']));var EmailImap=require('./imap');var EmailSmtp=require(_0x50af('0xb'));var mailAccount=require(_0x50af('0xc'));var md5Accounts={};function EmailChannel(_0x4dc2b9){logger['info'](_0x50af('0xd'));this[_0x50af('0xe')]=_0x4dc2b9['mailAccounts'];this['imapAccounts']={};this[_0x50af('0xf')]=new EmailSmtp();}EmailChannel[_0x50af('0x10')]['emit']=function(_0x3ccbee){var _0x28a92c=this[_0x50af('0xe')][_0x3ccbee];var _0x3a4c2f={'id':_0x28a92c['id'],'name':_0x28a92c['name'],'key':_0x28a92c[_0x50af('0x11')],'active':_0x28a92c[_0x50af('0x12')],'Imap':{'status':_0x28a92c[_0x50af('0x13')][_0x50af('0x14')],'messageStatus':_0x28a92c[_0x50af('0x13')][_0x50af('0x15')],'total':_0x28a92c['Imap']['total']}};if(_['isNil'](md5Accounts[_0x3ccbee])){md5Accounts[_0x3ccbee]={};}var _0x620389=md5(JSON['stringify'](_0x3a4c2f));if(md5Accounts[_0x3ccbee][_0x50af('0x2')]!==_0x620389){md5Accounts[_0x3ccbee][_0x50af('0x2')]=_0x620389;io['emit']('mailAccount:update',_0x3a4c2f);}};EmailChannel[_0x50af('0x10')][_0x50af('0x16')]=function(_0x4a3106){for(var _0x4b0775 in _0x4a3106){if(_0x4a3106[_0x50af('0x17')](_0x4b0775)){if(_0x4a3106[_0x4b0775][_0x50af('0x13')]&&_0x4a3106[_0x4b0775][_0x50af('0x12')]){var _0x30e2ec=_0x4a3106[_0x4b0775][_0x50af('0x13')];if(!this[_0x50af('0x18')][_0x50af('0x17')](_0x30e2ec['id'])){this[_0x50af('0x18')][_0x30e2ec['id']]=new EmailImap(_0x30e2ec,_0x4a3106[_0x4b0775][_0x50af('0x6')]);this[_0x50af('0x18')][_0x30e2ec['id']]['on']('box',this[_0x50af('0x19')][_0x50af('0x1a')](this,_0x4b0775));this[_0x50af('0x18')][_0x30e2ec['id']]['on'](_0x50af('0x6'),this['handleImapEmail'][_0x50af('0x1a')](this,_0x4b0775));this[_0x50af('0x18')][_0x30e2ec['id']]['on'](_0x50af('0x1b'),this[_0x50af('0x1c')][_0x50af('0x1a')](this,_0x4b0775));this[_0x50af('0x18')][_0x30e2ec['id']]['on'](_0x50af('0x1d'),this[_0x50af('0x1e')][_0x50af('0x1a')](this,_0x4b0775));}}else{if(_[_0x50af('0x1f')](this['mailAccounts'][_0x4b0775][_0x50af('0x13')])){this[_0x50af('0xe')][_0x4b0775][_0x50af('0x13')]={};}this[_0x50af('0xe')][_0x4b0775][_0x50af('0x13')][_0x50af('0x14')]='disabled';this[_0x50af('0xe')][_0x4b0775][_0x50af('0x13')]['messageStatus']='';this[_0x50af('0x20')](_0x4b0775);}}}};EmailChannel[_0x50af('0x10')][_0x50af('0x19')]=function(_0x5dc58a,_0x53af9d){if(this[_0x50af('0xe')][_0x5dc58a]){this[_0x50af('0xe')][_0x5dc58a][_0x50af('0x13')][_0x50af('0x14')]=_0x50af('0x21');this[_0x50af('0xe')][_0x5dc58a][_0x50af('0x13')][_0x50af('0x15')]=_0x53af9d['name'];if(_0x53af9d[_0x50af('0x22')]){this[_0x50af('0xe')][_0x5dc58a][_0x50af('0x13')]['total']=_0x53af9d[_0x50af('0x22')]['total'];}return this[_0x50af('0x20')](_0x5dc58a);}};EmailChannel['prototype']['handleImapEmail']=function(_0x52ce35,_0x27b476){logger[_0x50af('0x23')](_0x50af('0x24'),_0x27b476[_0x50af('0x25')],_0x27b476[_0x50af('0x26')],_0x27b476[_0x50af('0x27')],_0x52ce35);if(this[_0x50af('0xe')][_0x52ce35]){return mailAccount[_0x50af('0x28')](_0x52ce35,_0x27b476)[_0x50af('0x29')](function(_0x27435d){if(_0x27435d){logger['info'](_0x50af('0x2a'));}})[_0x50af('0x2b')](function(_0x30988a){logger[_0x50af('0x1d')](_0x50af('0x2c'),JSON['stringify'](_0x30988a));});}};EmailChannel[_0x50af('0x10')]['handleImapEnd']=function(_0x5ac19f){if(this['mailAccounts'][_0x5ac19f]&&this[_0x50af('0xe')][_0x5ac19f][_0x50af('0x13')]){if(this[_0x50af('0x18')][this[_0x50af('0xe')][_0x5ac19f][_0x50af('0x13')]['id']]){delete this['imapAccounts'][this['mailAccounts'][_0x5ac19f][_0x50af('0x13')]['id']];}this[_0x50af('0xe')][_0x5ac19f][_0x50af('0x13')][_0x50af('0x2d')]=moment();this[_0x50af('0x20')](_0x5ac19f);}};EmailChannel['prototype'][_0x50af('0x1e')]=function(_0x398dcf,_0x10cf90){if(this[_0x50af('0xe')][_0x398dcf]){this['mailAccounts'][_0x398dcf][_0x50af('0x13')][_0x50af('0x14')]=_0x50af('0x1d');this[_0x50af('0xe')][_0x398dcf][_0x50af('0x13')]['messageStatus']=_0x10cf90;return this['emit'](_0x398dcf);}};EmailChannel['prototype'][_0x50af('0x2e')]=function(_0x35d38f,_0x366f6b){return this[_0x50af('0xf')][_0x50af('0x2f')](_0x35d38f,_0x366f6b);};EmailChannel[_0x50af('0x10')][_0x50af('0x30')]=function(_0x1b094e){var _0x394352=this;if(this[_0x50af('0xe')][_0x1b094e['id']]){if(_[_0x50af('0x1f')](this[_0x50af('0xe')][_0x1b094e['id']][_0x50af('0x31')])){this[_0x50af('0xe')][_0x1b094e['id']][_0x50af('0x31')]={};}this[_0x50af('0xe')][_0x1b094e['id']]['Smtp'][_0x50af('0x2d')]=moment();return new BPromise(function(_0x2740fd,_0x1c5b54){return _0x394352['smtp']['verify'](_0x1b094e)[_0x50af('0x29')](function(_0x38182e){_0x394352[_0x50af('0xe')][_0x1b094e['id']][_0x50af('0x31')][_0x50af('0x14')]=_0x50af('0x32');_0x394352[_0x50af('0xe')][_0x1b094e['id']][_0x50af('0x31')]['messageStatus']='';_0x394352['emit'](_0x1b094e['id']);_0x2740fd(_0x38182e);})[_0x50af('0x2b')](function(_0x2d0750){_0x394352['mailAccounts'][_0x1b094e['id']]['Smtp'][_0x50af('0x14')]=_0x50af('0x1d');_0x394352[_0x50af('0xe')][_0x1b094e['id']]['Smtp'][_0x50af('0x15')]=_0x2d0750;_0x394352[_0x50af('0x20')](_0x1b094e['id']);_0x1c5b54(_0x2d0750);});});}return this[_0x50af('0xf')][_0x50af('0x33')](_0x1b094e);};module[_0x50af('0x34')]=EmailChannel;
\ No newline at end of file
+var _0x524e=['sendMail','send','verifySmtp','Smtp','verify','verified','exports','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','redis','defaults','localhost','./imap','./smtp','info','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','emit','name','key','active','Imap','messageStatus','total','isNil','stringify','hasOwnProperty','handleImapBox','bind','handleImapEmail','end','handleImapEnd','error','status','connected','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','lastName','notify','then','catch','lastSync'];(function(_0x4cf98e,_0xba4b79){var _0x1623ac=function(_0x459bc0){while(--_0x459bc0){_0x4cf98e['push'](_0x4cf98e['shift']());}};_0x1623ac(++_0xba4b79);}(_0x524e,0x15e));var _0xe524=function(_0xefa016,_0xf36638){_0xefa016=_0xefa016-0x0;var _0x1726b1=_0x524e[_0xefa016];return _0x1726b1;};'use strict';var _=require('lodash');var moment=require('moment');var BPromise=require(_0xe524('0x0'));var md5=require(_0xe524('0x1'));var Redis=require(_0xe524('0x2'));var config=require(_0xe524('0x3'));var logger=require(_0xe524('0x4'))(_0xe524('0x5'));config[_0xe524('0x6')]=_[_0xe524('0x7')](config[_0xe524('0x6')],{'host':_0xe524('0x8'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xe524('0x6')]));var EmailImap=require(_0xe524('0x9'));var EmailSmtp=require(_0xe524('0xa'));var mailAccount=require('../rpc/mailAccount');var md5Accounts={};function EmailChannel(_0x384935){logger[_0xe524('0xb')](_0xe524('0xc'));this[_0xe524('0xd')]=_0x384935[_0xe524('0xd')];this[_0xe524('0xe')]={};this[_0xe524('0xf')]=new EmailSmtp();}EmailChannel[_0xe524('0x10')][_0xe524('0x11')]=function(_0x1641ec){var _0x1e4459=this[_0xe524('0xd')][_0x1641ec];var _0x1184df={'id':_0x1e4459['id'],'name':_0x1e4459[_0xe524('0x12')],'key':_0x1e4459[_0xe524('0x13')],'active':_0x1e4459[_0xe524('0x14')],'Imap':{'status':_0x1e4459['Imap']['status'],'messageStatus':_0x1e4459[_0xe524('0x15')][_0xe524('0x16')],'total':_0x1e4459[_0xe524('0x15')][_0xe524('0x17')]}};if(_[_0xe524('0x18')](md5Accounts[_0x1641ec])){md5Accounts[_0x1641ec]={};}var _0x57c1b6=md5(JSON[_0xe524('0x19')](_0x1184df));if(md5Accounts[_0x1641ec]['md5']!==_0x57c1b6){md5Accounts[_0x1641ec][_0xe524('0x1')]=_0x57c1b6;io[_0xe524('0x11')]('mailAccount:update',_0x1184df);}};EmailChannel[_0xe524('0x10')]['refresh']=function(_0x109795){for(var _0x538754 in _0x109795){if(_0x109795[_0xe524('0x1a')](_0x538754)){if(_0x109795[_0x538754]['Imap']&&_0x109795[_0x538754]['active']){var _0x5a5c0d=_0x109795[_0x538754][_0xe524('0x15')];if(!this['imapAccounts'][_0xe524('0x1a')](_0x5a5c0d['id'])){this[_0xe524('0xe')][_0x5a5c0d['id']]=new EmailImap(_0x5a5c0d,_0x109795[_0x538754][_0xe524('0x5')]);this[_0xe524('0xe')][_0x5a5c0d['id']]['on']('box',this[_0xe524('0x1b')][_0xe524('0x1c')](this,_0x538754));this['imapAccounts'][_0x5a5c0d['id']]['on'](_0xe524('0x5'),this[_0xe524('0x1d')][_0xe524('0x1c')](this,_0x538754));this[_0xe524('0xe')][_0x5a5c0d['id']]['on'](_0xe524('0x1e'),this[_0xe524('0x1f')][_0xe524('0x1c')](this,_0x538754));this[_0xe524('0xe')][_0x5a5c0d['id']]['on'](_0xe524('0x20'),this['handleImapError'][_0xe524('0x1c')](this,_0x538754));}}else{if(_['isNil'](this['mailAccounts'][_0x538754][_0xe524('0x15')])){this[_0xe524('0xd')][_0x538754][_0xe524('0x15')]={};}this[_0xe524('0xd')][_0x538754]['Imap'][_0xe524('0x21')]='disabled';this[_0xe524('0xd')][_0x538754][_0xe524('0x15')][_0xe524('0x16')]='';this[_0xe524('0x11')](_0x538754);}}}};EmailChannel[_0xe524('0x10')][_0xe524('0x1b')]=function(_0x2141db,_0x583cc3){if(this['mailAccounts'][_0x2141db]){this[_0xe524('0xd')][_0x2141db][_0xe524('0x15')][_0xe524('0x21')]=_0xe524('0x22');this[_0xe524('0xd')][_0x2141db]['Imap']['messageStatus']=_0x583cc3[_0xe524('0x12')];if(_0x583cc3[_0xe524('0x23')]){this[_0xe524('0xd')][_0x2141db][_0xe524('0x15')][_0xe524('0x17')]=_0x583cc3['messages'][_0xe524('0x17')];}return this[_0xe524('0x11')](_0x2141db);}};EmailChannel['prototype']['handleImapEmail']=function(_0x20688e,_0x376324){logger['info'](_0xe524('0x24'),_0x376324['firstName'],_0x376324[_0xe524('0x25')],_0x376324['from'],_0x20688e);if(this[_0xe524('0xd')][_0x20688e]){return mailAccount[_0xe524('0x26')](_0x20688e,_0x376324)[_0xe524('0x27')](function(_0x5600d2){if(_0x5600d2){logger[_0xe524('0xb')]('Mail\x20accepted\x20from\x20routing');}})[_0xe524('0x28')](function(_0x16eff9){logger[_0xe524('0x20')]('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON[_0xe524('0x19')](_0x16eff9));});}};EmailChannel[_0xe524('0x10')]['handleImapEnd']=function(_0x27817e){if(this[_0xe524('0xd')][_0x27817e]&&this[_0xe524('0xd')][_0x27817e][_0xe524('0x15')]){if(this['imapAccounts'][this[_0xe524('0xd')][_0x27817e][_0xe524('0x15')]['id']]){delete this[_0xe524('0xe')][this[_0xe524('0xd')][_0x27817e][_0xe524('0x15')]['id']];}this[_0xe524('0xd')][_0x27817e][_0xe524('0x15')][_0xe524('0x29')]=moment();this['emit'](_0x27817e);}};EmailChannel[_0xe524('0x10')]['handleImapError']=function(_0x1d463b,_0x53eeee){if(this['mailAccounts'][_0x1d463b]){this[_0xe524('0xd')][_0x1d463b]['Imap'][_0xe524('0x21')]=_0xe524('0x20');this[_0xe524('0xd')][_0x1d463b][_0xe524('0x15')][_0xe524('0x16')]=_0x53eeee;return this[_0xe524('0x11')](_0x1d463b);}};EmailChannel[_0xe524('0x10')][_0xe524('0x2a')]=function(_0x5e8e64,_0x311aec){return this[_0xe524('0xf')][_0xe524('0x2b')](_0x5e8e64,_0x311aec);};EmailChannel[_0xe524('0x10')][_0xe524('0x2c')]=function(_0x3885f6){var _0x1d9648=this;if(this[_0xe524('0xd')][_0x3885f6['id']]){if(_['isNil'](this[_0xe524('0xd')][_0x3885f6['id']][_0xe524('0x2d')])){this[_0xe524('0xd')][_0x3885f6['id']]['Smtp']={};}this[_0xe524('0xd')][_0x3885f6['id']]['Smtp'][_0xe524('0x29')]=moment();return new BPromise(function(_0x217e85,_0x43c314){return _0x1d9648[_0xe524('0xf')][_0xe524('0x2e')](_0x3885f6)[_0xe524('0x27')](function(_0xbeb2a9){_0x1d9648['mailAccounts'][_0x3885f6['id']][_0xe524('0x2d')][_0xe524('0x21')]=_0xe524('0x2f');_0x1d9648[_0xe524('0xd')][_0x3885f6['id']][_0xe524('0x2d')][_0xe524('0x16')]='';_0x1d9648['emit'](_0x3885f6['id']);_0x217e85(_0xbeb2a9);})[_0xe524('0x28')](function(_0x2982a0){_0x1d9648[_0xe524('0xd')][_0x3885f6['id']]['Smtp'][_0xe524('0x21')]='error';_0x1d9648['mailAccounts'][_0x3885f6['id']][_0xe524('0x2d')][_0xe524('0x16')]=_0x2982a0;_0x1d9648['emit'](_0x3885f6['id']);_0x43c314(_0x2982a0);});});}return this[_0xe524('0xf')][_0xe524('0x2e')](_0x3885f6);};module[_0xe524('0x30')]=EmailChannel;
\ No newline at end of file