Built motion from commit 06a208af.|2.6.26
[motion2.git] / server / services / email / lib / email.js
index acae13b..73bb18f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xdd1b=['lastName','from','Mail\x20accepted\x20from\x20routing','catch','Mail\x20not\x20accepted\x20from\x20routing\x20%s','smtp','send','verifySmtp','verify','then','Smtp','verified','exports','lodash','bluebird','md5','ioredis','../../../config/environment','../../../config/logger','email','redis','localhost','socket.io-emitter','./imap','./smtp','info','mailAccounts','imapAccounts','prototype','emit','name','key','active','Imap','status','messageStatus','total','stringify','refresh','hasOwnProperty','service','provider','custom','box','handleImapBox','bind','end','handleImapEnd','error','handleImapError','isNil','connected','messages','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s'];(function(_0x53886c,_0x17cd41){var _0x19d33a=function(_0x269b49){while(--_0x269b49){_0x53886c['push'](_0x53886c['shift']());}};_0x19d33a(++_0x17cd41);}(_0xdd1b,0x79));var _0xbdd1=function(_0x42d41d,_0x17b8ea){_0x42d41d=_0x42d41d-0x0;var _0x2e6184=_0xdd1b[_0x42d41d];return _0x2e6184;};'use strict';var _=require(_0xbdd1('0x0'));var moment=require('moment');var BPromise=require(_0xbdd1('0x1'));var md5=require(_0xbdd1('0x2'));var Redis=require(_0xbdd1('0x3'));var config=require(_0xbdd1('0x4'));var logger=require(_0xbdd1('0x5'))(_0xbdd1('0x6'));config['redis']=_['defaults'](config[_0xbdd1('0x7')],{'host':_0xbdd1('0x8'),'port':0x18eb});var io=require(_0xbdd1('0x9'))(new Redis(config[_0xbdd1('0x7')]));var EmailImap=require(_0xbdd1('0xa'));var EmailSmtp=require(_0xbdd1('0xb'));var mailAccount=require('../rpc/mailAccount');var md5Accounts={};function EmailChannel(_0x4009c2){logger[_0xbdd1('0xc')]('start\x20email\x20channel');this[_0xbdd1('0xd')]=_0x4009c2['mailAccounts'];this[_0xbdd1('0xe')]={};this['smtp']=new EmailSmtp();}EmailChannel[_0xbdd1('0xf')][_0xbdd1('0x10')]=function(_0x542a75){var _0x455e45=this['mailAccounts'][_0x542a75];var _0x4de7ce={'id':_0x455e45['id'],'name':_0x455e45[_0xbdd1('0x11')],'key':_0x455e45[_0xbdd1('0x12')],'active':_0x455e45[_0xbdd1('0x13')],'Imap':{'status':_0x455e45[_0xbdd1('0x14')][_0xbdd1('0x15')],'messageStatus':_0x455e45[_0xbdd1('0x14')][_0xbdd1('0x16')],'total':_0x455e45[_0xbdd1('0x14')][_0xbdd1('0x17')]}};if(_['isNil'](md5Accounts[_0x542a75])){md5Accounts[_0x542a75]={};}var _0x5949bd=md5(JSON[_0xbdd1('0x18')](_0x4de7ce));if(md5Accounts[_0x542a75][_0xbdd1('0x2')]!==_0x5949bd){md5Accounts[_0x542a75]['md5']=_0x5949bd;io[_0xbdd1('0x10')]('mailAccount:update',_0x4de7ce);}};EmailChannel[_0xbdd1('0xf')][_0xbdd1('0x19')]=function(_0x4a9cc2){for(var _0x5e12b1 in _0x4a9cc2){if(_0x4a9cc2[_0xbdd1('0x1a')](_0x5e12b1)){if(_0x4a9cc2[_0x5e12b1]['Imap']&&_0x4a9cc2[_0x5e12b1][_0xbdd1('0x13')]){var _0x549fc3=_0x4a9cc2[_0x5e12b1][_0xbdd1('0x14')];if(!_0x549fc3[_0xbdd1('0x1b')]&&_0x4a9cc2[_0x5e12b1][_0xbdd1('0x1c')]!==_0xbdd1('0x1d'))_0x549fc3[_0xbdd1('0x1b')]=_0x4a9cc2[_0x5e12b1][_0xbdd1('0x1c')];if(!this[_0xbdd1('0xe')][_0xbdd1('0x1a')](_0x549fc3['id'])){this[_0xbdd1('0xe')][_0x549fc3['id']]=new EmailImap(_0x549fc3,_0x4a9cc2[_0x5e12b1][_0xbdd1('0x6')]);this[_0xbdd1('0xe')][_0x549fc3['id']]['on'](_0xbdd1('0x1e'),this[_0xbdd1('0x1f')][_0xbdd1('0x20')](this,_0x5e12b1));this[_0xbdd1('0xe')][_0x549fc3['id']]['on'](_0xbdd1('0x6'),this['handleImapEmail'][_0xbdd1('0x20')](this,_0x5e12b1));this[_0xbdd1('0xe')][_0x549fc3['id']]['on'](_0xbdd1('0x21'),this[_0xbdd1('0x22')][_0xbdd1('0x20')](this,_0x5e12b1));this[_0xbdd1('0xe')][_0x549fc3['id']]['on'](_0xbdd1('0x23'),this[_0xbdd1('0x24')][_0xbdd1('0x20')](this,_0x5e12b1));}}else{if(_[_0xbdd1('0x25')](this[_0xbdd1('0xd')][_0x5e12b1][_0xbdd1('0x14')])){this[_0xbdd1('0xd')][_0x5e12b1][_0xbdd1('0x14')]={};}this['mailAccounts'][_0x5e12b1]['Imap'][_0xbdd1('0x15')]='disabled';this[_0xbdd1('0xd')][_0x5e12b1][_0xbdd1('0x14')]['messageStatus']='';this[_0xbdd1('0x10')](_0x5e12b1);}}}};EmailChannel['prototype']['handleImapBox']=function(_0x3c9ee6,_0x278b78){if(this[_0xbdd1('0xd')][_0x3c9ee6]){this[_0xbdd1('0xd')][_0x3c9ee6][_0xbdd1('0x14')][_0xbdd1('0x15')]=_0xbdd1('0x26');this[_0xbdd1('0xd')][_0x3c9ee6]['Imap'][_0xbdd1('0x16')]=_0x278b78['name'];if(_0x278b78[_0xbdd1('0x27')]){this[_0xbdd1('0xd')][_0x3c9ee6][_0xbdd1('0x14')][_0xbdd1('0x17')]=_0x278b78['messages'][_0xbdd1('0x17')];}return this['emit'](_0x3c9ee6);}};EmailChannel['prototype']['handleImapEmail']=function(_0x4ba387,_0x19c9f5){logger[_0xbdd1('0xc')](_0xbdd1('0x28'),_0x19c9f5['firstName'],_0x19c9f5[_0xbdd1('0x29')],_0x19c9f5[_0xbdd1('0x2a')],_0x4ba387);if(this[_0xbdd1('0xd')][_0x4ba387]){return mailAccount['notify'](_0x4ba387,_0x19c9f5)['then'](function(_0x25325a){if(_0x25325a){logger[_0xbdd1('0xc')](_0xbdd1('0x2b'));}})[_0xbdd1('0x2c')](function(_0x35cf68){logger['error'](_0xbdd1('0x2d'),JSON['stringify'](_0x35cf68));});}};EmailChannel[_0xbdd1('0xf')]['handleImapEnd']=function(_0x4e7205){if(this[_0xbdd1('0xd')][_0x4e7205]&&this[_0xbdd1('0xd')][_0x4e7205]['Imap']){if(this['imapAccounts'][this[_0xbdd1('0xd')][_0x4e7205][_0xbdd1('0x14')]['id']]){delete this[_0xbdd1('0xe')][this[_0xbdd1('0xd')][_0x4e7205][_0xbdd1('0x14')]['id']];}this[_0xbdd1('0xd')][_0x4e7205][_0xbdd1('0x14')]['lastSync']=moment();this[_0xbdd1('0x10')](_0x4e7205);}};EmailChannel[_0xbdd1('0xf')]['handleImapError']=function(_0x47a2bd,_0x252f6d){if(this[_0xbdd1('0xd')][_0x47a2bd]){this[_0xbdd1('0xd')][_0x47a2bd][_0xbdd1('0x14')][_0xbdd1('0x15')]=_0xbdd1('0x23');this['mailAccounts'][_0x47a2bd][_0xbdd1('0x14')][_0xbdd1('0x16')]=_0x252f6d;return this[_0xbdd1('0x10')](_0x47a2bd);}};EmailChannel['prototype']['sendMail']=function(_0x25da8f,_0xe4e03){return this[_0xbdd1('0x2e')][_0xbdd1('0x2f')](_0x25da8f,_0xe4e03);};EmailChannel[_0xbdd1('0xf')][_0xbdd1('0x30')]=function(_0x411d9f){var _0x31c0b1=this;if(this['mailAccounts'][_0x411d9f['id']]){if(_[_0xbdd1('0x25')](this['mailAccounts'][_0x411d9f['id']]['Smtp'])){this[_0xbdd1('0xd')][_0x411d9f['id']]['Smtp']={};}this[_0xbdd1('0xd')][_0x411d9f['id']]['Smtp']['lastSync']=moment();return new BPromise(function(_0x1c5dcf,_0x49722d){return _0x31c0b1[_0xbdd1('0x2e')][_0xbdd1('0x31')](_0x411d9f)[_0xbdd1('0x32')](function(_0x2f425d){_0x31c0b1[_0xbdd1('0xd')][_0x411d9f['id']][_0xbdd1('0x33')]['status']=_0xbdd1('0x34');_0x31c0b1['mailAccounts'][_0x411d9f['id']][_0xbdd1('0x33')][_0xbdd1('0x16')]='';_0x31c0b1[_0xbdd1('0x10')](_0x411d9f['id']);_0x1c5dcf(_0x2f425d);})[_0xbdd1('0x2c')](function(_0x1de288){_0x31c0b1[_0xbdd1('0xd')][_0x411d9f['id']][_0xbdd1('0x33')][_0xbdd1('0x15')]='error';_0x31c0b1[_0xbdd1('0xd')][_0x411d9f['id']][_0xbdd1('0x33')][_0xbdd1('0x16')]=_0x1de288;_0x31c0b1[_0xbdd1('0x10')](_0x411d9f['id']);_0x49722d(_0x1de288);});});}return this[_0xbdd1('0x2e')]['verify'](_0x411d9f);};module[_0xbdd1('0x35')]=EmailChannel;
\ No newline at end of file
+var _0xb5fe=['send','verifySmtp','Smtp','verify','verified','exports','moment','bluebird','email','defaults','localhost','redis','./smtp','../rpc/mailAccount','start\x20email\x20channel','mailAccounts','imapAccounts','smtp','prototype','name','key','active','Imap','messageStatus','total','stringify','mailAccount:update','refresh','hasOwnProperty','service','custom','provider','handleImapEmail','bind','handleImapEnd','isNil','status','disabled','handleImapBox','connected','messages','emit','info','firstName','lastName','from','notify','then','Mail\x20accepted\x20from\x20routing','catch','error','Mail\x20not\x20accepted\x20from\x20routing\x20%s','lastSync','handleImapError','sendMail'];(function(_0x35885a,_0x42fed7){var _0xe86249=function(_0x98edb3){while(--_0x98edb3){_0x35885a['push'](_0x35885a['shift']());}};_0xe86249(++_0x42fed7);}(_0xb5fe,0x150));var _0xeb5f=function(_0x1af4f9,_0x2c1ef8){_0x1af4f9=_0x1af4f9-0x0;var _0x3364ce=_0xb5fe[_0x1af4f9];return _0x3364ce;};'use strict';var _=require('lodash');var moment=require(_0xeb5f('0x0'));var BPromise=require(_0xeb5f('0x1'));var md5=require('md5');var Redis=require('ioredis');var config=require('../../../config/environment');var logger=require('../../../config/logger')(_0xeb5f('0x2'));config['redis']=_[_0xeb5f('0x3')](config['redis'],{'host':_0xeb5f('0x4'),'port':0x18eb});var io=require('socket.io-emitter')(new Redis(config[_0xeb5f('0x5')]));var EmailImap=require('./imap');var EmailSmtp=require(_0xeb5f('0x6'));var mailAccount=require(_0xeb5f('0x7'));var md5Accounts={};function EmailChannel(_0x2b0e6f){logger['info'](_0xeb5f('0x8'));this[_0xeb5f('0x9')]=_0x2b0e6f[_0xeb5f('0x9')];this[_0xeb5f('0xa')]={};this[_0xeb5f('0xb')]=new EmailSmtp();}EmailChannel[_0xeb5f('0xc')]['emit']=function(_0x230f51){var _0x45065d=this[_0xeb5f('0x9')][_0x230f51];var _0x4b520a={'id':_0x45065d['id'],'name':_0x45065d[_0xeb5f('0xd')],'key':_0x45065d[_0xeb5f('0xe')],'active':_0x45065d[_0xeb5f('0xf')],'Imap':{'status':_0x45065d[_0xeb5f('0x10')]['status'],'messageStatus':_0x45065d['Imap'][_0xeb5f('0x11')],'total':_0x45065d[_0xeb5f('0x10')][_0xeb5f('0x12')]}};if(_['isNil'](md5Accounts[_0x230f51])){md5Accounts[_0x230f51]={};}var _0x46d411=md5(JSON[_0xeb5f('0x13')](_0x4b520a));if(md5Accounts[_0x230f51]['md5']!==_0x46d411){md5Accounts[_0x230f51]['md5']=_0x46d411;io['emit'](_0xeb5f('0x14'),_0x4b520a);}};EmailChannel['prototype'][_0xeb5f('0x15')]=function(_0x1c0ac8){for(var _0x5611b7 in _0x1c0ac8){if(_0x1c0ac8[_0xeb5f('0x16')](_0x5611b7)){if(_0x1c0ac8[_0x5611b7]['Imap']&&_0x1c0ac8[_0x5611b7]['active']){var _0x1081da=_0x1c0ac8[_0x5611b7]['Imap'];if(!_0x1081da[_0xeb5f('0x17')]&&_0x1c0ac8[_0x5611b7]['provider']!==_0xeb5f('0x18'))_0x1081da[_0xeb5f('0x17')]=_0x1c0ac8[_0x5611b7][_0xeb5f('0x19')];if(!this[_0xeb5f('0xa')][_0xeb5f('0x16')](_0x1081da['id'])){this[_0xeb5f('0xa')][_0x1081da['id']]=new EmailImap(_0x1081da,_0x1c0ac8[_0x5611b7][_0xeb5f('0x2')]);this[_0xeb5f('0xa')][_0x1081da['id']]['on']('box',this['handleImapBox']['bind'](this,_0x5611b7));this['imapAccounts'][_0x1081da['id']]['on'](_0xeb5f('0x2'),this[_0xeb5f('0x1a')][_0xeb5f('0x1b')](this,_0x5611b7));this[_0xeb5f('0xa')][_0x1081da['id']]['on']('end',this[_0xeb5f('0x1c')][_0xeb5f('0x1b')](this,_0x5611b7));this[_0xeb5f('0xa')][_0x1081da['id']]['on']('error',this['handleImapError'][_0xeb5f('0x1b')](this,_0x5611b7));}}else{if(_[_0xeb5f('0x1d')](this[_0xeb5f('0x9')][_0x5611b7][_0xeb5f('0x10')])){this[_0xeb5f('0x9')][_0x5611b7][_0xeb5f('0x10')]={};}this[_0xeb5f('0x9')][_0x5611b7]['Imap'][_0xeb5f('0x1e')]=_0xeb5f('0x1f');this[_0xeb5f('0x9')][_0x5611b7][_0xeb5f('0x10')][_0xeb5f('0x11')]='';this['emit'](_0x5611b7);}}}};EmailChannel[_0xeb5f('0xc')][_0xeb5f('0x20')]=function(_0x48a97d,_0x25a32d){if(this[_0xeb5f('0x9')][_0x48a97d]){this[_0xeb5f('0x9')][_0x48a97d][_0xeb5f('0x10')][_0xeb5f('0x1e')]=_0xeb5f('0x21');this[_0xeb5f('0x9')][_0x48a97d][_0xeb5f('0x10')][_0xeb5f('0x11')]=_0x25a32d[_0xeb5f('0xd')];if(_0x25a32d['messages']){this[_0xeb5f('0x9')][_0x48a97d][_0xeb5f('0x10')][_0xeb5f('0x12')]=_0x25a32d[_0xeb5f('0x22')][_0xeb5f('0x12')];}return this[_0xeb5f('0x23')](_0x48a97d);}};EmailChannel[_0xeb5f('0xc')]['handleImapEmail']=function(_0x5cc755,_0x30aeb7){logger[_0xeb5f('0x24')]('New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s',_0x30aeb7[_0xeb5f('0x25')],_0x30aeb7[_0xeb5f('0x26')],_0x30aeb7[_0xeb5f('0x27')],_0x5cc755);if(this['mailAccounts'][_0x5cc755]){return mailAccount[_0xeb5f('0x28')](_0x5cc755,_0x30aeb7)[_0xeb5f('0x29')](function(_0x17cad0){if(_0x17cad0){logger[_0xeb5f('0x24')](_0xeb5f('0x2a'));}})[_0xeb5f('0x2b')](function(_0x266c9c){logger[_0xeb5f('0x2c')](_0xeb5f('0x2d'),JSON['stringify'](_0x266c9c));});}};EmailChannel[_0xeb5f('0xc')][_0xeb5f('0x1c')]=function(_0x487b80){if(this[_0xeb5f('0x9')][_0x487b80]&&this['mailAccounts'][_0x487b80][_0xeb5f('0x10')]){if(this[_0xeb5f('0xa')][this[_0xeb5f('0x9')][_0x487b80][_0xeb5f('0x10')]['id']]){delete this[_0xeb5f('0xa')][this['mailAccounts'][_0x487b80][_0xeb5f('0x10')]['id']];}this[_0xeb5f('0x9')][_0x487b80][_0xeb5f('0x10')][_0xeb5f('0x2e')]=moment();this[_0xeb5f('0x23')](_0x487b80);}};EmailChannel[_0xeb5f('0xc')][_0xeb5f('0x2f')]=function(_0xec640b,_0x4d18e3){if(this['mailAccounts'][_0xec640b]){this[_0xeb5f('0x9')][_0xec640b][_0xeb5f('0x10')][_0xeb5f('0x1e')]=_0xeb5f('0x2c');this[_0xeb5f('0x9')][_0xec640b][_0xeb5f('0x10')][_0xeb5f('0x11')]=_0x4d18e3;return this[_0xeb5f('0x23')](_0xec640b);}};EmailChannel[_0xeb5f('0xc')][_0xeb5f('0x30')]=function(_0xeb030b,_0x484517){return this['smtp'][_0xeb5f('0x31')](_0xeb030b,_0x484517);};EmailChannel[_0xeb5f('0xc')][_0xeb5f('0x32')]=function(_0x172194){var _0x53d4cf=this;if(this[_0xeb5f('0x9')][_0x172194['id']]){if(_[_0xeb5f('0x1d')](this[_0xeb5f('0x9')][_0x172194['id']][_0xeb5f('0x33')])){this['mailAccounts'][_0x172194['id']][_0xeb5f('0x33')]={};}this[_0xeb5f('0x9')][_0x172194['id']][_0xeb5f('0x33')][_0xeb5f('0x2e')]=moment();return new BPromise(function(_0x3de576,_0x4038d9){return _0x53d4cf[_0xeb5f('0xb')][_0xeb5f('0x34')](_0x172194)['then'](function(_0x26edc3){_0x53d4cf[_0xeb5f('0x9')][_0x172194['id']]['Smtp']['status']=_0xeb5f('0x35');_0x53d4cf[_0xeb5f('0x9')][_0x172194['id']][_0xeb5f('0x33')][_0xeb5f('0x11')]='';_0x53d4cf[_0xeb5f('0x23')](_0x172194['id']);_0x3de576(_0x26edc3);})['catch'](function(_0x8fe873){_0x53d4cf[_0xeb5f('0x9')][_0x172194['id']][_0xeb5f('0x33')][_0xeb5f('0x1e')]=_0xeb5f('0x2c');_0x53d4cf[_0xeb5f('0x9')][_0x172194['id']][_0xeb5f('0x33')][_0xeb5f('0x11')]=_0x8fe873;_0x53d4cf[_0xeb5f('0x23')](_0x172194['id']);_0x4038d9(_0x8fe873);});});}return this['smtp']['verify'](_0x172194);};module[_0xeb5f('0x36')]=EmailChannel;
\ No newline at end of file