23630234ddb78eb2cfe19ed3ab8a90a934c50c2e
[motion-next.git] / server / services / email / lib / email.js
1 const a1151_0xec90=['end','verified','messages','lastName','email','sendMail','messageStatus','handleImapEmail','verifySmtp','md5','start\x20email\x20channel','../../../rediscache','box','key','error','mailAccount:update','catch','lastSync','Mail\x20accepted\x20from\x20routing','../rpc/mailAccount','handleImapBox','bind','isNil','status','info','mailAccounts','stringify','name','smtp','verify','handleImapError','emit','undefined','Imap','firstName','exports','total','moment','Smtp','prototype','New\x20email\x20from\x20%s\x20%s\x20%s\x20to\x20%s','send','then','refresh','imapAccounts','active','disabled','./imap'];(function(_0x727632,_0xec900c){const _0x34b15f=function(_0x636813){while(--_0x636813){_0x727632['push'](_0x727632['shift']());}};_0x34b15f(++_0xec900c);}(a1151_0xec90,0x13a));const a1151_0x34b1=function(_0x727632,_0xec900c){_0x727632=_0x727632-0x0;let _0x34b15f=a1151_0xec90[_0x727632];return _0x34b15f;};const _0x16e3e2=a1151_0x34b1;'use strict';const _=require('lodash'),moment=require(_0x16e3e2('0xb')),md5=require(_0x16e3e2('0x1f')),logger=require('../../../config/logger')(_0x16e3e2('0x1a')),{getSocket}=require(_0x16e3e2('0x21')),io=getSocket(),EmailImap=require(_0x16e3e2('0x15')),EmailSmtp=require('./smtp'),mailAccount=require(_0x16e3e2('0x29')),md5Accounts={};function EmailChannel(_0x636813){const _0x16da13=_0x16e3e2;logger[_0x16da13('0x2e')](_0x16da13('0x20')),this['mailAccounts']=_0x636813[_0x16da13('0x2f')],this[_0x16da13('0x12')]={},this[_0x16da13('0x2')]=new EmailSmtp();}EmailChannel[_0x16e3e2('0xd')][_0x16e3e2('0x5')]=function(_0x2f61d6){const _0x2c5529=_0x16e3e2,_0x579ef0=this[_0x2c5529('0x2f')][_0x2f61d6],_0x3654e8={'id':_0x579ef0['id'],'name':_0x579ef0[_0x2c5529('0x1')],'key':_0x579ef0[_0x2c5529('0x23')],'active':_0x579ef0[_0x2c5529('0x13')],'Imap':{'status':_0x579ef0[_0x2c5529('0x7')]['status'],'messageStatus':_0x579ef0['Imap'][_0x2c5529('0x1c')],'total':_0x579ef0[_0x2c5529('0x7')][_0x2c5529('0xa')]}};_[_0x2c5529('0x2c')](md5Accounts[_0x2f61d6])&&(md5Accounts[_0x2f61d6]={});const _0xa0e294=md5(JSON[_0x2c5529('0x0')](_0x3654e8));md5Accounts[_0x2f61d6][_0x2c5529('0x1f')]!==_0xa0e294&&(md5Accounts[_0x2f61d6][_0x2c5529('0x1f')]=_0xa0e294,io[_0x2c5529('0x5')](_0x2c5529('0x25'),_0x3654e8));},EmailChannel['prototype'][_0x16e3e2('0x11')]=function(_0x5e98a2){const _0x30866c=_0x16e3e2;for(const _0x5f234b in _0x5e98a2){if(typeof _0x5e98a2[_0x5f234b]!=='undefined'){if(_0x5e98a2[_0x5f234b]['Imap']&&_0x5e98a2[_0x5f234b][_0x30866c('0x13')]){const _0x1b8dd7=_0x5e98a2[_0x5f234b][_0x30866c('0x7')];typeof this[_0x30866c('0x12')][_0x1b8dd7['id']]===_0x30866c('0x6')&&(this['imapAccounts'][_0x1b8dd7['id']]=new EmailImap(_0x1b8dd7,_0x5e98a2[_0x5f234b][_0x30866c('0x1a')]),this[_0x30866c('0x12')][_0x1b8dd7['id']]['on'](_0x30866c('0x22'),this[_0x30866c('0x2a')][_0x30866c('0x2b')](this,_0x5f234b)),this[_0x30866c('0x12')][_0x1b8dd7['id']]['on'](_0x30866c('0x1a'),this[_0x30866c('0x1d')][_0x30866c('0x2b')](this,_0x5f234b)),this[_0x30866c('0x12')][_0x1b8dd7['id']]['on'](_0x30866c('0x16'),this['handleImapEnd'][_0x30866c('0x2b')](this,_0x5f234b)),this[_0x30866c('0x12')][_0x1b8dd7['id']]['on'](_0x30866c('0x24'),this[_0x30866c('0x4')]['bind'](this,_0x5f234b)));}else _[_0x30866c('0x2c')](this['mailAccounts'][_0x5f234b][_0x30866c('0x7')])&&(this[_0x30866c('0x2f')][_0x5f234b][_0x30866c('0x7')]={}),this[_0x30866c('0x2f')][_0x5f234b]['Imap'][_0x30866c('0x2d')]=_0x30866c('0x14'),this[_0x30866c('0x2f')][_0x5f234b]['Imap'][_0x30866c('0x1c')]='',this[_0x30866c('0x5')](_0x5f234b);}}},EmailChannel[_0x16e3e2('0xd')][_0x16e3e2('0x2a')]=function(_0x1caed4,_0x54b88b){const _0x42873d=_0x16e3e2;if(this[_0x42873d('0x2f')][_0x1caed4])return this[_0x42873d('0x2f')][_0x1caed4][_0x42873d('0x7')]['status']='connected',this[_0x42873d('0x2f')][_0x1caed4][_0x42873d('0x7')][_0x42873d('0x1c')]=_0x54b88b[_0x42873d('0x1')],_0x54b88b[_0x42873d('0x18')]&&(this[_0x42873d('0x2f')][_0x1caed4][_0x42873d('0x7')][_0x42873d('0xa')]=_0x54b88b[_0x42873d('0x18')]['total']),this[_0x42873d('0x5')](_0x1caed4);},EmailChannel['prototype']['handleImapEmail']=function(_0x5b32e1,_0x3afc58){const _0x354cec=_0x16e3e2;logger[_0x354cec('0x2e')](_0x354cec('0xe'),_0x3afc58[_0x354cec('0x8')],_0x3afc58[_0x354cec('0x19')],_0x3afc58['from'],_0x5b32e1);if(this[_0x354cec('0x2f')][_0x5b32e1])return mailAccount['notify'](_0x5b32e1,_0x3afc58)[_0x354cec('0x10')](function(_0x4b907e){const _0x1e4168=_0x354cec;_0x4b907e&&logger[_0x1e4168('0x2e')](_0x1e4168('0x28'));})[_0x354cec('0x26')](function(_0x3ce62b){const _0x161797=_0x354cec;logger[_0x161797('0x24')]('Mail\x20not\x20accepted\x20from\x20routing\x20%s',JSON[_0x161797('0x0')](_0x3ce62b));});},EmailChannel[_0x16e3e2('0xd')]['handleImapEnd']=function(_0xb8f458){const _0x5a6fd2=_0x16e3e2;this[_0x5a6fd2('0x2f')][_0xb8f458]&&this[_0x5a6fd2('0x2f')][_0xb8f458]['Imap']&&(this[_0x5a6fd2('0x12')][this['mailAccounts'][_0xb8f458]['Imap']['id']]&&delete this['imapAccounts'][this[_0x5a6fd2('0x2f')][_0xb8f458][_0x5a6fd2('0x7')]['id']],this[_0x5a6fd2('0x2f')][_0xb8f458][_0x5a6fd2('0x7')][_0x5a6fd2('0x27')]=moment(),this[_0x5a6fd2('0x5')](_0xb8f458));},EmailChannel[_0x16e3e2('0xd')][_0x16e3e2('0x4')]=function(_0x4a89d0,_0x4faa87){const _0x32c2ec=_0x16e3e2;if(this[_0x32c2ec('0x2f')][_0x4a89d0])return this[_0x32c2ec('0x2f')][_0x4a89d0]['Imap']['status']=_0x32c2ec('0x24'),this[_0x32c2ec('0x2f')][_0x4a89d0][_0x32c2ec('0x7')][_0x32c2ec('0x1c')]=_0x4faa87,this[_0x32c2ec('0x5')](_0x4a89d0);},EmailChannel[_0x16e3e2('0xd')][_0x16e3e2('0x1b')]=function(_0xa2a9bb,_0x378cd4){const _0x468cf6=_0x16e3e2;return this['smtp'][_0x468cf6('0xf')](_0xa2a9bb,_0x378cd4);},EmailChannel[_0x16e3e2('0xd')][_0x16e3e2('0x1e')]=function(_0x317a52){const _0x29766e=_0x16e3e2,_0x2dee4d=this;if(this[_0x29766e('0x2f')][_0x317a52['id']])return _[_0x29766e('0x2c')](this[_0x29766e('0x2f')][_0x317a52['id']][_0x29766e('0xc')])&&(this[_0x29766e('0x2f')][_0x317a52['id']]['Smtp']={}),this['mailAccounts'][_0x317a52['id']]['Smtp'][_0x29766e('0x27')]=moment(),new Promise(function(_0x337332,_0x23eb3b){const _0x5e1fcf=_0x29766e;return _0x2dee4d['smtp'][_0x5e1fcf('0x3')](_0x317a52)[_0x5e1fcf('0x10')](function(_0x5cb0eb){const _0x66e889=_0x5e1fcf;_0x2dee4d[_0x66e889('0x2f')][_0x317a52['id']][_0x66e889('0xc')][_0x66e889('0x2d')]=_0x66e889('0x17'),_0x2dee4d[_0x66e889('0x2f')][_0x317a52['id']][_0x66e889('0xc')][_0x66e889('0x1c')]='',_0x2dee4d[_0x66e889('0x5')](_0x317a52['id']),_0x337332(_0x5cb0eb);})['catch'](function(_0x26203b){const _0x169b3a=_0x5e1fcf;_0x2dee4d[_0x169b3a('0x2f')][_0x317a52['id']][_0x169b3a('0xc')][_0x169b3a('0x2d')]=_0x169b3a('0x24'),_0x2dee4d['mailAccounts'][_0x317a52['id']][_0x169b3a('0xc')]['messageStatus']=_0x26203b,_0x2dee4d[_0x169b3a('0x5')](_0x317a52['id']),_0x23eb3b(_0x26203b);});});return this[_0x29766e('0x2')][_0x29766e('0x3')](_0x317a52);},module[_0x16e3e2('0x9')]=EmailChannel;