a67a4ee493cee237b8043688df19d95fd97d6279
[motion-next.git] / server / services / email / lib / email.js
1 const a1152_0x5dde=['exports','./imap','then','Mail\x20not\x20accepted\x20from\x20routing\x20%s','emit','refresh','../rpc/mailAccount','error','key','handleImapBox','verify','connected','verified','lodash','sendMail','stringify','../../../rediscache','mailAccounts','isNil','email','firstName','undefined','messages','catch','active','Mail\x20accepted\x20from\x20routing','handleImapEmail','../../../config/logger','start\x20email\x20channel','lastSync','Smtp','bind','end','total','imapAccounts','handleImapEnd','Imap','status','smtp','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','info','messageStatus','notify','md5','name','prototype'];(function(_0x2982d2,_0x5dde19){const _0xab9e94=function(_0x42a32d){while(--_0x42a32d){_0x2982d2['push'](_0x2982d2['shift']());}};_0xab9e94(++_0x5dde19);}(a1152_0x5dde,0x1bd));const a1152_0xab9e=function(_0x2982d2,_0x5dde19){_0x2982d2=_0x2982d2-0x0;let _0xab9e94=a1152_0x5dde[_0x2982d2];return _0xab9e94;};const _0xf869b0=a1152_0xab9e;'use strict';const _=require(_0xf869b0('0x1c')),moment=require('moment'),md5=require(_0xf869b0('0xc')),logger=require(_0xf869b0('0x2a'))(_0xf869b0('0x22')),{getSocket}=require(_0xf869b0('0x1f')),io=getSocket(),EmailImap=require(_0xf869b0('0x10')),EmailSmtp=require('./smtp'),mailAccount=require(_0xf869b0('0x15')),md5Accounts={};function EmailChannel(_0x42a32d){const _0x55d884=_0xf869b0;logger[_0x55d884('0x9')](_0x55d884('0x2b')),this['mailAccounts']=_0x42a32d[_0x55d884('0x20')],this[_0x55d884('0x3')]={},this['smtp']=new EmailSmtp();}EmailChannel[_0xf869b0('0xe')][_0xf869b0('0x13')]=function(_0x4484c1){const _0x3bb030=_0xf869b0,_0x151220=this[_0x3bb030('0x20')][_0x4484c1],_0x1bc485={'id':_0x151220['id'],'name':_0x151220['name'],'key':_0x151220[_0x3bb030('0x17')],'active':_0x151220[_0x3bb030('0x27')],'Imap':{'status':_0x151220['Imap']['status'],'messageStatus':_0x151220[_0x3bb030('0x5')][_0x3bb030('0xa')],'total':_0x151220[_0x3bb030('0x5')]['total']}};_['isNil'](md5Accounts[_0x4484c1])&&(md5Accounts[_0x4484c1]={});const _0x418fbe=md5(JSON[_0x3bb030('0x1e')](_0x1bc485));md5Accounts[_0x4484c1][_0x3bb030('0xc')]!==_0x418fbe&&(md5Accounts[_0x4484c1][_0x3bb030('0xc')]=_0x418fbe,io[_0x3bb030('0x13')]('mailAccount:update',_0x1bc485));},EmailChannel[_0xf869b0('0xe')][_0xf869b0('0x14')]=function(_0x5a0d69){const _0x277a22=_0xf869b0;for(const _0x1a006c in _0x5a0d69){if(typeof _0x5a0d69[_0x1a006c]!==_0x277a22('0x24')){if(_0x5a0d69[_0x1a006c]['Imap']&&_0x5a0d69[_0x1a006c][_0x277a22('0x27')]){const _0x4b4e67=_0x5a0d69[_0x1a006c]['Imap'];typeof this[_0x277a22('0x3')][_0x4b4e67['id']]===_0x277a22('0x24')&&(this[_0x277a22('0x3')][_0x4b4e67['id']]=new EmailImap(_0x4b4e67,_0x5a0d69[_0x1a006c][_0x277a22('0x22')]),this[_0x277a22('0x3')][_0x4b4e67['id']]['on']('box',this[_0x277a22('0x18')][_0x277a22('0x0')](this,_0x1a006c)),this[_0x277a22('0x3')][_0x4b4e67['id']]['on'](_0x277a22('0x22'),this['handleImapEmail']['bind'](this,_0x1a006c)),this[_0x277a22('0x3')][_0x4b4e67['id']]['on'](_0x277a22('0x1'),this[_0x277a22('0x4')][_0x277a22('0x0')](this,_0x1a006c)),this[_0x277a22('0x3')][_0x4b4e67['id']]['on'](_0x277a22('0x16'),this['handleImapError'][_0x277a22('0x0')](this,_0x1a006c)));}else _[_0x277a22('0x21')](this[_0x277a22('0x20')][_0x1a006c][_0x277a22('0x5')])&&(this[_0x277a22('0x20')][_0x1a006c][_0x277a22('0x5')]={}),this[_0x277a22('0x20')][_0x1a006c][_0x277a22('0x5')][_0x277a22('0x6')]='disabled',this[_0x277a22('0x20')][_0x1a006c][_0x277a22('0x5')][_0x277a22('0xa')]='',this['emit'](_0x1a006c);}}},EmailChannel[_0xf869b0('0xe')][_0xf869b0('0x18')]=function(_0x23430c,_0x153507){const _0x2987d1=_0xf869b0;if(this[_0x2987d1('0x20')][_0x23430c])return this['mailAccounts'][_0x23430c][_0x2987d1('0x5')][_0x2987d1('0x6')]=_0x2987d1('0x1a'),this[_0x2987d1('0x20')][_0x23430c][_0x2987d1('0x5')][_0x2987d1('0xa')]=_0x153507[_0x2987d1('0xd')],_0x153507[_0x2987d1('0x25')]&&(this[_0x2987d1('0x20')][_0x23430c][_0x2987d1('0x5')][_0x2987d1('0x2')]=_0x153507[_0x2987d1('0x25')][_0x2987d1('0x2')]),this[_0x2987d1('0x13')](_0x23430c);},EmailChannel[_0xf869b0('0xe')][_0xf869b0('0x29')]=function(_0x1f5a0f,_0x417277){const _0x14a3af=_0xf869b0;logger[_0x14a3af('0x9')](_0x14a3af('0x8'),_0x417277[_0x14a3af('0x23')],_0x417277['lastName'],_0x417277['from'],_0x1f5a0f);if(this[_0x14a3af('0x20')][_0x1f5a0f])return mailAccount[_0x14a3af('0xb')](_0x1f5a0f,_0x417277)[_0x14a3af('0x11')](function(_0x63733a){const _0x305de6=_0x14a3af;_0x63733a&&logger[_0x305de6('0x9')](_0x305de6('0x28'));})[_0x14a3af('0x26')](function(_0x3c0839){const _0x83d79c=_0x14a3af;logger[_0x83d79c('0x16')](_0x83d79c('0x12'),JSON[_0x83d79c('0x1e')](_0x3c0839));});},EmailChannel[_0xf869b0('0xe')][_0xf869b0('0x4')]=function(_0x28d014){const _0x4f3b41=_0xf869b0;this[_0x4f3b41('0x20')][_0x28d014]&&this[_0x4f3b41('0x20')][_0x28d014][_0x4f3b41('0x5')]&&(this[_0x4f3b41('0x3')][this[_0x4f3b41('0x20')][_0x28d014][_0x4f3b41('0x5')]['id']]&&delete this[_0x4f3b41('0x3')][this[_0x4f3b41('0x20')][_0x28d014][_0x4f3b41('0x5')]['id']],this[_0x4f3b41('0x20')][_0x28d014]['Imap'][_0x4f3b41('0x2c')]=moment(),this[_0x4f3b41('0x13')](_0x28d014));},EmailChannel[_0xf869b0('0xe')]['handleImapError']=function(_0x188c06,_0x3c9f75){const _0x4a416a=_0xf869b0;if(this[_0x4a416a('0x20')][_0x188c06])return this[_0x4a416a('0x20')][_0x188c06]['Imap']['status']=_0x4a416a('0x16'),this[_0x4a416a('0x20')][_0x188c06][_0x4a416a('0x5')]['messageStatus']=_0x3c9f75,this[_0x4a416a('0x13')](_0x188c06);},EmailChannel[_0xf869b0('0xe')][_0xf869b0('0x1d')]=function(_0x16cb2c,_0x18b255){const _0x37d238=_0xf869b0;return this[_0x37d238('0x7')]['send'](_0x16cb2c,_0x18b255);},EmailChannel[_0xf869b0('0xe')]['verifySmtp']=function(_0x4cc1b9){const _0x2c47bf=_0xf869b0,_0xdefce1=this;if(this['mailAccounts'][_0x4cc1b9['id']])return _[_0x2c47bf('0x21')](this[_0x2c47bf('0x20')][_0x4cc1b9['id']][_0x2c47bf('0x2d')])&&(this[_0x2c47bf('0x20')][_0x4cc1b9['id']][_0x2c47bf('0x2d')]={}),this[_0x2c47bf('0x20')][_0x4cc1b9['id']]['Smtp'][_0x2c47bf('0x2c')]=moment(),new Promise(function(_0xbf25f9,_0x3bd49d){const _0x2450a0=_0x2c47bf;return _0xdefce1[_0x2450a0('0x7')][_0x2450a0('0x19')](_0x4cc1b9)[_0x2450a0('0x11')](function(_0x1f6c54){const _0x293fdc=_0x2450a0;_0xdefce1[_0x293fdc('0x20')][_0x4cc1b9['id']][_0x293fdc('0x2d')][_0x293fdc('0x6')]=_0x293fdc('0x1b'),_0xdefce1['mailAccounts'][_0x4cc1b9['id']][_0x293fdc('0x2d')][_0x293fdc('0xa')]='',_0xdefce1['emit'](_0x4cc1b9['id']),_0xbf25f9(_0x1f6c54);})[_0x2450a0('0x26')](function(_0x33c732){const _0x34d0a5=_0x2450a0;_0xdefce1[_0x34d0a5('0x20')][_0x4cc1b9['id']]['Smtp']['status']=_0x34d0a5('0x16'),_0xdefce1[_0x34d0a5('0x20')][_0x4cc1b9['id']][_0x34d0a5('0x2d')][_0x34d0a5('0xa')]=_0x33c732,_0xdefce1[_0x34d0a5('0x13')](_0x4cc1b9['id']),_0x3bd49d(_0x33c732);});});return this['smtp']['verify'](_0x4cc1b9);},module[_0xf869b0('0xf')]=EmailChannel;