Built motion from commit ded33658aad58fc8de845a8299a9db59a88cc353. Version 3.0.0...
[motion-next.git] / server / services / email / lib / utils.js
1 const a1154_0xc430=['127.0.0.1','path','type','format','attachment-','messageId','<p>Empty\x20message</p>','inReplyTo','value','html','imap.gmail.com','application/ms-tnef','attachments','message','util','slice','../../../config/environment','originCc','subject','isEmpty','generate','Title','from','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','outlook.office365.com','address','name','Data','BodyHTML','moment','bcc','textAsHtml','push','%s-%s','head','gmail','root','writeFileSync','outlook365','anonymous','date','@xcally.com','content','../../../config/logger','email','imap.mail.yahoo.com','body','files/attachments/','info','<a\x20target=\x22_blank\x22\x20','yahoo','originTo','YYYY-MM-DD\x20HH:mm:ss','length','first','split','Attachments','parser','filename','Anonymous','test','randomstring','join','contentType','includes'];(function(_0x6b5a5b,_0xc4300a){const _0x2a053c=function(_0x10f86a){while(--_0x10f86a){_0x6b5a5b['push'](_0x6b5a5b['shift']());}};_0x2a053c(++_0xc4300a);}(a1154_0xc430,0x12e));const a1154_0x2a05=function(_0x6b5a5b,_0xc4300a){_0x6b5a5b=_0x6b5a5b-0x0;let _0x2a053c=a1154_0xc430[_0x6b5a5b];return _0x2a053c;};const _0x224e9d=a1154_0x2a05;'use strict';const _=require('lodash'),moment=require(_0x224e9d('0x34')),random=require(_0x224e9d('0x13')),fs=require('fs'),path=require(_0x224e9d('0x18')),util=require(_0x224e9d('0x25')),tnef=require('node-tnef'),logger=require(_0x224e9d('0x1'))(_0x224e9d('0x2')),config=require(_0x224e9d('0x27'));function getAddress(_0x10f86a){const _0x4a22fd=_0x224e9d,_0x5e6e92=_['head'](_0x10f86a[_0x4a22fd('0x1f')]);return _0x5e6e92&&_0x5e6e92[_0x4a22fd('0x30')]?_0x5e6e92[_0x4a22fd('0x30')]:_0x4a22fd('0x3e')+random[_0x4a22fd('0x2b')](0x6)+_0x4a22fd('0x40');}function getFirstName(_0x50afc0){const _0x28e082=_0x224e9d,_0x560542=_[_0x28e082('0x39')](_0x50afc0['value']);if(_0x560542&&_0x560542['name']){const _0x28b670=_0x560542['name']['split'](/\s+/);return _0x28b670['length']?_0x28b670[_0x28e082('0x26')](0x0,-0x1)[_0x28e082('0x14')]('\x20'):_0x560542['name'];}return _0x28e082('0x11');}function getLastName(_0x51d542){const _0x4b4acf=_0x224e9d,_0x4d32df=_['head'](_0x51d542[_0x4b4acf('0x1f')]);if(_0x4d32df&&_0x4d32df['name']){const _0x13cfb0=_0x4d32df[_0x4b4acf('0x31')][_0x4b4acf('0xd')](/\s+/);return _0x13cfb0[_0x4b4acf('0xb')]>0x1?_0x13cfb0['pop']():'';}return'';}function getMails(_0x319d9c,_0x37e9f9){const _0x213fb1=_0x224e9d;let _0xd4a30b='';for(let _0x19d2aa=0x0;_0x19d2aa<_0x37e9f9[_0x213fb1('0x1f')]['length'];_0x19d2aa+=0x1){_0x37e9f9[_0x213fb1('0x1f')][_0x19d2aa][_0x213fb1('0x30')]!==_0x319d9c&&(!_[_0x213fb1('0x2a')](_0xd4a30b)&&(_0xd4a30b+=','),_0xd4a30b+=_0x37e9f9[_0x213fb1('0x1f')][_0x19d2aa][_0x213fb1('0x31')]||_0x37e9f9[_0x213fb1('0x1f')][_0x19d2aa]['address']||'',_0xd4a30b+='\x20<',_0xd4a30b+=_0x37e9f9[_0x213fb1('0x1f')][_0x19d2aa][_0x213fb1('0x30')]?_0x37e9f9[_0x213fb1('0x1f')][_0x19d2aa]['address']:_0x213fb1('0x3e')+random[_0x213fb1('0x2b')](0x6)+_0x213fb1('0x40'),_0xd4a30b+='>');}return _0xd4a30b;}function parseEmail(_0x424ad6,_0x3596b8,_0x45f506){const _0x3fd4ab=_0x224e9d;if(_0x3596b8[_0x3fd4ab('0x20')]){const _0x1d3f3c=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x1d3f3c[_0x3fd4ab('0x12')](_0x3596b8[_0x3fd4ab('0x20')])){_0x3596b8[_0x3fd4ab('0x20')]=_0x3596b8[_0x3fd4ab('0x20')]['replace'](_0x1d3f3c,'');}_0x45f506[_0x3fd4ab('0x4')]=_0x3596b8['html'];}else _0x45f506['body']=_0x3596b8[_0x3fd4ab('0x36')];_0x45f506['body']&&(_0x45f506[_0x3fd4ab('0x4')]=_0x45f506[_0x3fd4ab('0x4')]['replace'](/<a\s+/gi,_0x3fd4ab('0x7')));if(_0x3596b8['to']){_0x45f506[_0x3fd4ab('0x24')][_0x3fd4ab('0x9')]=getMails(null,_0x3596b8['to']);const _0x4970d0=getMails(_0x424ad6[_0x3fd4ab('0x2')],_0x3596b8['to']);!_[_0x3fd4ab('0x2a')](_0x4970d0)&&(_0x45f506[_0x3fd4ab('0x24')]['cc']+=_0x4970d0);}if(_0x3596b8['cc']){_0x45f506[_0x3fd4ab('0x24')][_0x3fd4ab('0x28')]=getMails(null,_0x3596b8['cc']);const _0x1be2a2=getMails(_0x424ad6[_0x3fd4ab('0x2')],_0x3596b8['cc']);!_[_0x3fd4ab('0x2a')](_0x1be2a2)&&(!_[_0x3fd4ab('0x2a')](_0x45f506['message']['cc'])&&(_0x45f506['message']['cc']+=','),_0x45f506[_0x3fd4ab('0x24')]['cc']+=_0x1be2a2);}!_[_0x3fd4ab('0x16')](_0x45f506[_0x3fd4ab('0x24')]['originTo'],_0x424ad6['email'])&&!_['includes'](_0x45f506[_0x3fd4ab('0x24')][_0x3fd4ab('0x28')],_0x424ad6[_0x3fd4ab('0x2')])&&(_0x45f506['message'][_0x3fd4ab('0x35')]=_0x424ad6[_0x3fd4ab('0x2')]);if(_0x3596b8[_0x3fd4ab('0x23')]&&_0x3596b8[_0x3fd4ab('0x23')]['length']){_0x45f506[_0x3fd4ab('0x24')]['attach']=_0x3596b8[_0x3fd4ab('0x23')]['length'];for(let _0x1f2a5f=0x0,_0x5e78bb,_0x2f5bc4,_0x548b0d;_0x1f2a5f<_0x3596b8['attachments'][_0x3fd4ab('0xb')];_0x1f2a5f+=0x1){_0x3596b8[_0x3fd4ab('0x23')][_0x1f2a5f][_0x3fd4ab('0x19')]==='attachment'&&(_0x548b0d=_0x3596b8[_0x3fd4ab('0x23')][_0x1f2a5f][_0x3fd4ab('0x10')]||_0x3fd4ab('0x1b')+_0x1f2a5f,_0x5e78bb=util['format'](_0x3fd4ab('0x38'),Date['now'](),_0x548b0d),_0x2f5bc4=path[_0x3fd4ab('0x14')](config[_0x3fd4ab('0x3b')],_0x3fd4ab('0x5'),_0x5e78bb),fs[_0x3fd4ab('0x3c')](_0x2f5bc4,_0x3596b8[_0x3fd4ab('0x23')][_0x1f2a5f]['content']),_0x45f506[_0x3fd4ab('0x24')][_0x3fd4ab('0x23')][_0x3fd4ab('0x37')]({'name':_0x548b0d,'basename':_0x5e78bb,'type':_0x3596b8[_0x3fd4ab('0x23')][_0x1f2a5f][_0x3fd4ab('0x15')],'filepath':_0x2f5bc4}));}}return _0x45f506;}exports[_0x224e9d('0xf')]=function(_0x32ec4e,_0x202e33,_0x4f24a0){const _0x37183d=_0x224e9d,_0x301d42={'from':getAddress(_0x202e33['from']),'firstName':getFirstName(_0x202e33[_0x37183d('0x2d')]),'lastName':getLastName(_0x202e33[_0x37183d('0x2d')]),'mapKey':_0x37183d('0x2'),'message':{'from':getMails(_0x32ec4e[_0x37183d('0x2')],_0x202e33[_0x37183d('0x2d')]),'to':_0x32ec4e[_0x37183d('0x2')],'cc':'','subject':_0x202e33[_0x37183d('0x29')]||'','messageId':_0x202e33[_0x37183d('0x1c')],'inReplyTo':_0x202e33[_0x37183d('0x1e')],'sentAt':moment(_0x202e33[_0x37183d('0x3f')])[_0x37183d('0x1a')](_0x37183d('0xa')),'attach':![],'attachments':[]}};if(!_0x202e33['html']&&!_0x202e33[_0x37183d('0x36')]){const _0xa01dd=_['filter'](_0x202e33[_0x37183d('0x23')],{'contentType':_0x37183d('0x22')});_0xa01dd[_0x37183d('0xb')]?(logger[_0x37183d('0x6')](util[_0x37183d('0x1a')](_0x37183d('0x2e'),_0x202e33[_0x37183d('0x1c')])),tnef['parseBuffer'](_[_0x37183d('0xc')](_0xa01dd)[_0x37183d('0x0')],function(_0x55124c,_0x67ba43){const _0x24bc0d=_0x37183d;if(_0x67ba43){_0x202e33[_0x24bc0d('0x20')]=_0x67ba43[_0x24bc0d('0x33')]||'<p>Empty\x20message</p>';if(_0x67ba43[_0x24bc0d('0xe')])for(let _0xd5890a=0x0;_0xd5890a<_0x67ba43[_0x24bc0d('0xe')][_0x24bc0d('0xb')];_0xd5890a++){const _0xbc67ea=_0x67ba43['Attachments'][_0xd5890a];_0x301d42[_0x24bc0d('0x24')][_0x24bc0d('0x23')][_0x24bc0d('0x37')]({'filename':_0xbc67ea[_0x24bc0d('0x2c')],'content':Buffer[_0x24bc0d('0x2d')](_0xbc67ea[_0x24bc0d('0x32')])});}}_0x4f24a0(parseEmail(_0x32ec4e,_0x202e33,_0x301d42));})):(_0x202e33['html']=_0x37183d('0x1d'),_0x4f24a0(parseEmail(_0x32ec4e,_0x202e33,_0x301d42)));}else _0x4f24a0(parseEmail(_0x32ec4e,_0x202e33,_0x301d42));},exports['getHost']=function(_0x3d99ae){const _0x690d48=_0x224e9d;switch(_0x3d99ae){case _0x690d48('0x3a'):return _0x690d48('0x21');case _0x690d48('0x8'):return _0x690d48('0x3');case'hotmail':return'imap-mail.outlook.com';case _0x690d48('0x3d'):return _0x690d48('0x2f');}return _0x690d48('0x17');};