Built motion from commit e0fa946e.|2.6.5
[motion2.git] / server / services / email / lib / utils.js
index 506f86d..d14784d 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x3151=['subject','inReplyTo','YYYY-MM-DD\x20HH:mm:ss','textAsHtml','filter','application/ms-tnef','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','messageId','first','content','<p>Empty\x20message</p>','Attachments','push','Data','getHost','gmail','imap.gmail.com','yahoo','outlook365','outlook.office365.com','127.0.0.1','lodash','moment','randomstring','path','util','node-tnef','../../../config/logger','email','../../../config/environment','value','address','anonymous','generate','head','name','split','join','Anonymous','length','pop','isEmpty','@xcally.com','html','test','includes','<img','attachments','filename','replace','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','body','<a\x20target=\x22_blank\x22\x20','originTo','message','originCc','bcc','attach','type','attachment','attachment-','format','%s-%s','root','server/files/attachments/','writeFileSync','parser','from'];(function(_0x3d27a,_0x31311d){var _0x314fd7=function(_0x20ac55){while(--_0x20ac55){_0x3d27a['push'](_0x3d27a['shift']());}};_0x314fd7(++_0x31311d);}(_0x3151,0x1c0));var _0x1315=function(_0x13137e,_0x29c0f3){_0x13137e=_0x13137e-0x0;var _0x346261=_0x3151[_0x13137e];return _0x346261;};'use strict';var _=require(_0x1315('0x0'));var moment=require(_0x1315('0x1'));var random=require(_0x1315('0x2'));var fs=require('fs');var path=require(_0x1315('0x3'));var util=require(_0x1315('0x4'));var tnef=require(_0x1315('0x5'));var logger=require(_0x1315('0x6'))(_0x1315('0x7'));var config=require(_0x1315('0x8'));function getAddress(_0x45cab0){var _0x47ef41=_['head'](_0x45cab0[_0x1315('0x9')]);return _0x47ef41&&_0x47ef41['address']?_0x47ef41[_0x1315('0xa')]:_0x1315('0xb')+random[_0x1315('0xc')](0x6)+'@xcally.com';}function getFirstName(_0x8ab545){var _0x2f4d73=_[_0x1315('0xd')](_0x8ab545[_0x1315('0x9')]);if(_0x2f4d73&&_0x2f4d73[_0x1315('0xe')]){var _0x28ceb=_0x2f4d73[_0x1315('0xe')][_0x1315('0xf')](/\s+/);return _0x28ceb['length']?_0x28ceb['slice'](0x0,-0x1)[_0x1315('0x10')]('\x20'):_0x2f4d73[_0x1315('0xe')];}return _0x1315('0x11');}function getLastName(_0x15dd95){var _0x11fc33=_[_0x1315('0xd')](_0x15dd95[_0x1315('0x9')]);if(_0x11fc33&&_0x11fc33['name']){var _0x45b0c1=_0x11fc33[_0x1315('0xe')][_0x1315('0xf')](/\s+/);return _0x45b0c1[_0x1315('0x12')]>0x1?_0x45b0c1[_0x1315('0x13')]():'';}return'';}function getMails(_0x3c96ff,_0x5bd026){var _0x219650='';for(var _0x4182e8=0x0;_0x4182e8<_0x5bd026[_0x1315('0x9')]['length'];_0x4182e8+=0x1){if(_0x5bd026[_0x1315('0x9')][_0x4182e8]['address']!==_0x3c96ff){if(!_[_0x1315('0x14')](_0x219650)){_0x219650+=',';}_0x219650+=_0x5bd026[_0x1315('0x9')][_0x4182e8]['name']||_0x5bd026[_0x1315('0x9')][_0x4182e8][_0x1315('0xa')]||'';_0x219650+='\x20<';_0x219650+=_0x5bd026['value'][_0x4182e8][_0x1315('0xa')]?_0x5bd026[_0x1315('0x9')][_0x4182e8][_0x1315('0xa')]:'anonymous'+random[_0x1315('0xc')](0x6)+_0x1315('0x15');_0x219650+='>';}}return _0x219650;}function parseEmail(_0x2f3763,_0x5acab1,_0x969748){if(_0x5acab1[_0x1315('0x16')]){var _0x4fe850=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x4fe850[_0x1315('0x17')](_0x5acab1[_0x1315('0x16')])){_0x5acab1[_0x1315('0x16')]=_0x5acab1[_0x1315('0x16')]['replace'](_0x4fe850,'');}if(_0x5acab1[_0x1315('0x16')][_0x1315('0x18')](_0x1315('0x19'))){var _0x1c7a15=[];_0x5acab1[_0x1315('0x1a')]['forEach'](_0x451773=>{_0x1c7a15['push'](_0x451773[_0x1315('0x1b')]);});var _0x755a3a=/<img.*? _SRC(.*?)[^\>]+>/g;var _0x45a8ea=/src=\"data:image\/([a-zA-Z]*);base64,([^\"]*)\"/g;var _0x1471bc=_0x5acab1['html'][_0x1315('0x1c')](_0x45a8ea,_0x1315('0x1d'));var _0x206e07=_0x1471bc['replace'](_0x755a3a,'_IMG');for(let _0x258a9a=0x0;_0x258a9a<_0x1c7a15[_0x1315('0x12')];_0x258a9a++){var _0x573844=_0x206e07[_0x1315('0x1c')](_0x1315('0x1e'),_0x1315('0x1f')+_0x1c7a15[_0x258a9a]+'\x20]</span>');_0x206e07=_0x573844;}_0x5acab1[_0x1315('0x16')]=_0x206e07;}_0x969748[_0x1315('0x20')]=_0x5acab1['html'];}else{_0x969748['body']=_0x5acab1['textAsHtml'];}if(_0x969748['body']){_0x969748[_0x1315('0x20')]=_0x969748[_0x1315('0x20')][_0x1315('0x1c')](/<a\s+/gi,_0x1315('0x21'));}if(_0x5acab1['to']){_0x969748['message'][_0x1315('0x22')]=getMails(null,_0x5acab1['to']);var _0x18eed5=getMails(_0x2f3763[_0x1315('0x7')],_0x5acab1['to']);if(!_[_0x1315('0x14')](_0x18eed5)){_0x969748[_0x1315('0x23')]['cc']+=_0x18eed5;}}if(_0x5acab1['cc']){_0x969748[_0x1315('0x23')][_0x1315('0x24')]=getMails(null,_0x5acab1['cc']);var _0x53a981=getMails(_0x2f3763['email'],_0x5acab1['cc']);if(!_[_0x1315('0x14')](_0x53a981)){if(!_[_0x1315('0x14')](_0x969748['message']['cc'])){_0x969748['message']['cc']+=',';}_0x969748[_0x1315('0x23')]['cc']+=_0x53a981;}}if(!_[_0x1315('0x18')](_0x969748[_0x1315('0x23')][_0x1315('0x22')],_0x2f3763[_0x1315('0x7')])&&!_[_0x1315('0x18')](_0x969748['message'][_0x1315('0x24')],_0x2f3763[_0x1315('0x7')])){_0x969748[_0x1315('0x23')][_0x1315('0x25')]=_0x2f3763['email'];}if(_0x5acab1[_0x1315('0x1a')]&&_0x5acab1[_0x1315('0x1a')][_0x1315('0x12')]){_0x969748['message'][_0x1315('0x26')]=_0x5acab1[_0x1315('0x1a')][_0x1315('0x12')];for(var _0x1c0c7d=0x0,_0x34f665,_0xef3ef0,_0x507838;_0x1c0c7d<_0x5acab1[_0x1315('0x1a')][_0x1315('0x12')];_0x1c0c7d+=0x1){if(_0x5acab1[_0x1315('0x1a')][_0x1c0c7d][_0x1315('0x27')]===_0x1315('0x28')){_0x507838=_0x5acab1[_0x1315('0x1a')][_0x1c0c7d][_0x1315('0x1b')]||_0x1315('0x29')+_0x1c0c7d;_0x34f665=util[_0x1315('0x2a')](_0x1315('0x2b'),Date['now'](),_0x507838);_0xef3ef0=path[_0x1315('0x10')](config[_0x1315('0x2c')],_0x1315('0x2d'),_0x34f665);fs[_0x1315('0x2e')](_0xef3ef0,_0x5acab1[_0x1315('0x1a')][_0x1c0c7d]['content']);_0x969748[_0x1315('0x23')][_0x1315('0x1a')]['push']({'name':_0x507838,'basename':_0x34f665,'type':_0x5acab1[_0x1315('0x1a')][_0x1c0c7d]['contentType'],'filepath':_0xef3ef0});}}}return _0x969748;}exports[_0x1315('0x2f')]=function(_0xbdd1c3,_0x329960,_0x368c3a){var _0x76523c={'from':getAddress(_0x329960[_0x1315('0x30')]),'firstName':getFirstName(_0x329960[_0x1315('0x30')]),'lastName':getLastName(_0x329960[_0x1315('0x30')]),'mapKey':_0x1315('0x7'),'message':{'from':getMails(_0xbdd1c3[_0x1315('0x7')],_0x329960[_0x1315('0x30')]),'to':_0xbdd1c3[_0x1315('0x7')],'cc':'','subject':_0x329960[_0x1315('0x31')]||'','messageId':_0x329960['messageId'],'inReplyTo':_0x329960[_0x1315('0x32')],'sentAt':moment(_0x329960['date'])[_0x1315('0x2a')](_0x1315('0x33')),'attach':![],'attachments':[]}};if(!_0x329960[_0x1315('0x16')]&&!_0x329960[_0x1315('0x34')]){var _0x416093=_[_0x1315('0x35')](_0x329960[_0x1315('0x1a')],{'contentType':_0x1315('0x36')});if(_0x416093['length']){logger[_0x1315('0x37')](util[_0x1315('0x2a')](_0x1315('0x38'),_0x329960[_0x1315('0x39')]));tnef['parseBuffer'](_[_0x1315('0x3a')](_0x416093)[_0x1315('0x3b')],function(_0x11173d,_0x29b263){if(_0x29b263){_0x329960['html']=_0x29b263['BodyHTML']||_0x1315('0x3c');if(_0x29b263[_0x1315('0x3d')]){for(var _0x570b9c=0x0;_0x570b9c<_0x29b263[_0x1315('0x3d')]['length'];_0x570b9c++){var _0x400f8f=_0x29b263[_0x1315('0x3d')][_0x570b9c];_0x76523c[_0x1315('0x23')][_0x1315('0x1a')][_0x1315('0x3e')]({'filename':_0x400f8f['Title'],'content':new Buffer(_0x400f8f[_0x1315('0x3f')])});}}}_0x368c3a(parseEmail(_0xbdd1c3,_0x329960,_0x76523c));});}else{_0x329960['html']=_0x1315('0x3c');_0x368c3a(parseEmail(_0xbdd1c3,_0x329960,_0x76523c));}}else{_0x368c3a(parseEmail(_0xbdd1c3,_0x329960,_0x76523c));}};exports[_0x1315('0x40')]=function(_0x66925e){switch(_0x66925e){case _0x1315('0x41'):return _0x1315('0x42');case _0x1315('0x43'):return'imap.mail.yahoo.com';case'hotmail':return'imap-mail.outlook.com';case _0x1315('0x44'):return _0x1315('0x45');}return _0x1315('0x46');};
\ No newline at end of file
+var _0x469d=['BodyHTML','Attachments','<p>Empty\x20message</p>','user=','auth=Bearer\x20','utf-8','toString','moment','randomstring','util','node-tnef','email','../../../config/environment','head','value','address','anonymous','generate','@xcally.com','substring','name','indexOf','split','length','slice','join','Anonymous','pop','isEmpty','html','test','replace','<img','attachments','filename','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','body','originTo','message','originCc','includes','attach','type','attachment','attachment-','format','%s-%s','root','server/files/attachments/','writeFileSync','push','contentType','headerLines','Auto-Submitted:\x20auto-replied','X-Auto-Response-Suppress:\x20All','line','isAutoreply','from','subject','messageId','inReplyTo','date','YYYY-MM-DD\x20HH:mm:ss','textAsHtml','application/ms-tnef','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','parseBuffer','first','content'];(function(_0x469a00,_0x573952){var _0x4813c0=function(_0x1c9f15){while(--_0x1c9f15){_0x469a00['push'](_0x469a00['shift']());}};_0x4813c0(++_0x573952);}(_0x469d,0x97));var _0xd469=function(_0x297246,_0x46b402){_0x297246=_0x297246-0x0;var _0x3038a9=_0x469d[_0x297246];return _0x3038a9;};'use strict';var _=require('lodash');var moment=require(_0xd469('0x0'));var random=require(_0xd469('0x1'));var fs=require('fs');var path=require('path');var util=require(_0xd469('0x2'));var tnef=require(_0xd469('0x3'));var logger=require('../../../config/logger')(_0xd469('0x4'));var config=require(_0xd469('0x5'));function getAddress(_0x50e1b6){var _0x2ef488=_[_0xd469('0x6')](_0x50e1b6[_0xd469('0x7')]);return _0x2ef488&&_0x2ef488[_0xd469('0x8')]?_0x2ef488[_0xd469('0x8')]:_0xd469('0x9')+random[_0xd469('0xa')](0x6)+_0xd469('0xb');}function getFirstName(_0x5c6f99){var _0x4e6b84=_[_0xd469('0x6')](_0x5c6f99[_0xd469('0x7')]);if(_0x4e6b84&&_0x4e6b84['name']){if(_0x4e6b84['name']==_0x4e6b84[_0xd469('0x8')]){return _0x4e6b84['name'][_0xd469('0xc')](0x0,_0x4e6b84[_0xd469('0xd')][_0xd469('0xe')]('@'));}var _0x15ce2d=_0x4e6b84[_0xd469('0xd')][_0xd469('0xf')](/\s+/);return _0x15ce2d[_0xd469('0x10')]>0x1?_0x15ce2d[_0xd469('0x11')](0x0,-0x1)[_0xd469('0x12')]('\x20'):_0x4e6b84[_0xd469('0xd')];}return _0xd469('0x13');}function getLastName(_0x15d42e){var _0x5216fd=_[_0xd469('0x6')](_0x15d42e['value']);if(_0x5216fd&&_0x5216fd[_0xd469('0xd')]){var _0x24120b=_0x5216fd[_0xd469('0xd')]['split'](/\s+/);return _0x24120b[_0xd469('0x10')]>0x1?_0x24120b[_0xd469('0x14')]():'';}return'';}function getMails(_0xa3c0f6,_0x36fe55){var _0x195a2b='';for(var _0x251fc6=0x0;_0x251fc6<_0x36fe55[_0xd469('0x7')][_0xd469('0x10')];_0x251fc6+=0x1){if(_0x36fe55[_0xd469('0x7')][_0x251fc6][_0xd469('0x8')]!==_0xa3c0f6){if(!_[_0xd469('0x15')](_0x195a2b)){_0x195a2b+=',';}_0x195a2b+=_0x36fe55[_0xd469('0x7')][_0x251fc6][_0xd469('0xd')]||_0x36fe55[_0xd469('0x7')][_0x251fc6][_0xd469('0x8')]||'';_0x195a2b+='\x20<';_0x195a2b+=_0x36fe55[_0xd469('0x7')][_0x251fc6][_0xd469('0x8')]?_0x36fe55[_0xd469('0x7')][_0x251fc6]['address']:'anonymous'+random[_0xd469('0xa')](0x6)+_0xd469('0xb');_0x195a2b+='>';}}return _0x195a2b;}function parseEmail(_0x50f918,_0x39bb10,_0x32476d){if(_0x39bb10[_0xd469('0x16')]){var _0x5e92ea=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x5e92ea[_0xd469('0x17')](_0x39bb10[_0xd469('0x16')])){_0x39bb10[_0xd469('0x16')]=_0x39bb10['html'][_0xd469('0x18')](_0x5e92ea,'');}if(_0x39bb10[_0xd469('0x16')]['includes'](_0xd469('0x19'))){var _0x404b03=[];_0x39bb10[_0xd469('0x1a')]['forEach'](_0x2f3e47=>{_0x404b03['push'](_0x2f3e47[_0xd469('0x1b')]);});var _0x1b2ea7=/<img.*? _SRC(.*?)[^>]+>/g;var _0x489857=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x443fe3=_0x39bb10[_0xd469('0x16')][_0xd469('0x18')](_0x489857,'_SRC');var _0x52911a=_0x443fe3[_0xd469('0x18')](_0x1b2ea7,_0xd469('0x1c'));for(let _0x4d2b5e=0x0;_0x4d2b5e<_0x404b03[_0xd469('0x10')];_0x4d2b5e++){var _0x2375ee=_0x52911a[_0xd469('0x18')](_0xd469('0x1c'),_0xd469('0x1d')+_0x404b03[_0x4d2b5e]+_0xd469('0x1e'));_0x52911a=_0x2375ee;}_0x39bb10[_0xd469('0x16')]=_0x52911a;}_0x32476d[_0xd469('0x1f')]=_0x39bb10['html'];}else{_0x32476d[_0xd469('0x1f')]=_0x39bb10['textAsHtml'];}if(_0x32476d[_0xd469('0x1f')]){_0x32476d[_0xd469('0x1f')]=_0x32476d[_0xd469('0x1f')]['replace'](/<a\s+/gi,'<a\x20target=\x22_blank\x22\x20');}if(_0x39bb10['to']){_0x32476d['message'][_0xd469('0x20')]=getMails(null,_0x39bb10['to']);var _0x496c5c=getMails(_0x50f918[_0xd469('0x4')],_0x39bb10['to']);if(!_['isEmpty'](_0x496c5c)){_0x32476d[_0xd469('0x21')]['cc']+=_0x496c5c;}}if(_0x39bb10['cc']){_0x32476d[_0xd469('0x21')][_0xd469('0x22')]=getMails(null,_0x39bb10['cc']);var _0x2cb366=getMails(_0x50f918[_0xd469('0x4')],_0x39bb10['cc']);if(!_['isEmpty'](_0x2cb366)){if(!_[_0xd469('0x15')](_0x32476d[_0xd469('0x21')]['cc'])){_0x32476d['message']['cc']+=',';}_0x32476d['message']['cc']+=_0x2cb366;}}if(!_['includes'](_0x32476d[_0xd469('0x21')]['originTo'],_0x50f918[_0xd469('0x4')])&&!_[_0xd469('0x23')](_0x32476d[_0xd469('0x21')][_0xd469('0x22')],_0x50f918[_0xd469('0x4')])){_0x32476d['message']['bcc']=_0x50f918[_0xd469('0x4')];}if(_0x39bb10[_0xd469('0x1a')]&&_0x39bb10[_0xd469('0x1a')][_0xd469('0x10')]){_0x32476d[_0xd469('0x21')][_0xd469('0x24')]=_0x39bb10[_0xd469('0x1a')][_0xd469('0x10')];for(var _0x2bb203=0x0,_0x3cc0b7,_0x2b5cdd,_0x384967;_0x2bb203<_0x39bb10[_0xd469('0x1a')][_0xd469('0x10')];_0x2bb203+=0x1){if(_0x39bb10['attachments'][_0x2bb203][_0xd469('0x25')]===_0xd469('0x26')){_0x384967=_0x39bb10['attachments'][_0x2bb203][_0xd469('0x1b')]||_0xd469('0x27')+_0x2bb203;_0x3cc0b7=util[_0xd469('0x28')](_0xd469('0x29'),Date['now'](),_0x384967);_0x2b5cdd=path['join'](config[_0xd469('0x2a')],_0xd469('0x2b'),_0x3cc0b7);fs[_0xd469('0x2c')](_0x2b5cdd,_0x39bb10['attachments'][_0x2bb203]['content']);_0x32476d[_0xd469('0x21')][_0xd469('0x1a')][_0xd469('0x2d')]({'name':_0x384967,'basename':_0x3cc0b7,'type':_0x39bb10[_0xd469('0x1a')][_0x2bb203][_0xd469('0x2e')],'filepath':_0x2b5cdd});}}}if(_0x39bb10[_0xd469('0x2f')]&&_0x39bb10['headerLines'][_0xd469('0x10')]>0x0){var _0x55b25c=[_0xd469('0x30'),_0xd469('0x31'),'Precedence:\x20auto_reply'];for(var _0x1597ab=0x0;_0x1597ab<_0x39bb10['headerLines']['length'];_0x1597ab++){var _0x3f9bb8=_[_0xd469('0xe')](_0x55b25c,_0x39bb10[_0xd469('0x2f')][_0x1597ab][_0xd469('0x32')]);if(_0x3f9bb8>=0x0){_0x32476d[_0xd469('0x33')]=!![];}}}return _0x32476d;}exports['parser']=function(_0x1fb963,_0x4c3311,_0x43b4ef){var _0x1d9008={'from':getAddress(_0x4c3311[_0xd469('0x34')]),'firstName':getFirstName(_0x4c3311['from']),'lastName':getLastName(_0x4c3311[_0xd469('0x34')]),'mapKey':_0xd469('0x4'),'message':{'from':getMails(_0x1fb963[_0xd469('0x4')],_0x4c3311['from']),'to':_0x1fb963[_0xd469('0x4')],'cc':'','subject':_0x4c3311[_0xd469('0x35')]||'','messageId':_0x4c3311[_0xd469('0x36')],'inReplyTo':_0x4c3311[_0xd469('0x37')],'sentAt':moment(_0x4c3311[_0xd469('0x38')])[_0xd469('0x28')](_0xd469('0x39')),'attach':![],'attachments':[]}};if(!_0x4c3311[_0xd469('0x16')]&&!_0x4c3311[_0xd469('0x3a')]){var _0x2ad44f=_['filter'](_0x4c3311[_0xd469('0x1a')],{'contentType':_0xd469('0x3b')});if(_0x2ad44f[_0xd469('0x10')]){logger[_0xd469('0x3c')](util['format'](_0xd469('0x3d'),_0x4c3311[_0xd469('0x36')]));tnef[_0xd469('0x3e')](_[_0xd469('0x3f')](_0x2ad44f)[_0xd469('0x40')],function(_0x5cc524,_0x4e1964){if(_0x4e1964){_0x4c3311[_0xd469('0x16')]=_0x4e1964[_0xd469('0x41')]||'<p>Empty\x20message</p>';if(_0x4e1964[_0xd469('0x42')]){for(var _0x379302=0x0;_0x379302<_0x4e1964['Attachments'][_0xd469('0x10')];_0x379302++){var _0x4dfc4b=_0x4e1964[_0xd469('0x42')][_0x379302];_0x1d9008['message']['attachments'][_0xd469('0x2d')]({'filename':_0x4dfc4b['Title'],'content':Buffer['from'](_0x4dfc4b['Data'])});}}}_0x43b4ef(parseEmail(_0x1fb963,_0x4c3311,_0x1d9008));});}else{_0x4c3311[_0xd469('0x16')]=_0xd469('0x43');_0x43b4ef(parseEmail(_0x1fb963,_0x4c3311,_0x1d9008));}}else{_0x43b4ef(parseEmail(_0x1fb963,_0x4c3311,_0x1d9008));}};exports['generateXOAuth2Token']=function(_0x17ddb0,_0xc7bb9e){var _0x2a0a4b=[_0xd469('0x44')+(_0xc7bb9e||''),_0xd469('0x45')+_0x17ddb0,'',''];return Buffer['from'](_0x2a0a4b[_0xd469('0x12')]('\ 1'),_0xd469('0x46'))[_0xd469('0x47')]('base64');};
\ No newline at end of file