Built motion from commit da617fac.|2.6.6
[motion2.git] / server / services / email / lib / utils.js
index 3b2f668..6d4ad3c 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x86ee=['content','contentType','parser','from','inReplyTo','date','filter','application/ms-tnef','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','messageId','parseBuffer','first','BodyHTML','<p>Empty\x20message</p>','Attachments','Title','Data','getHost','imap.gmail.com','yahoo','hotmail','outlook.office365.com','lodash','randomstring','util','node-tnef','../../../config/logger','head','value','address','anonymous','generate','@xcally.com','split','length','slice','join','name','isEmpty','html','test','replace','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','email','message','includes','originTo','attachments','attach','type','attachment','filename','attachment-','format','%s-%s','now','server/files/attachments/','writeFileSync'];(function(_0x44dfea,_0x3a370e){var _0x5087ee=function(_0x49f066){while(--_0x49f066){_0x44dfea['push'](_0x44dfea['shift']());}};_0x5087ee(++_0x3a370e);}(_0x86ee,0xce));var _0xe86e=function(_0x3c2a69,_0x4c8b41){_0x3c2a69=_0x3c2a69-0x0;var _0x596bc8=_0x86ee[_0x3c2a69];return _0x596bc8;};'use strict';var _=require(_0xe86e('0x0'));var moment=require('moment');var random=require(_0xe86e('0x1'));var fs=require('fs');var path=require('path');var util=require(_0xe86e('0x2'));var tnef=require(_0xe86e('0x3'));var logger=require(_0xe86e('0x4'))('email');var config=require('../../../config/environment');function getAddress(_0x3f1bf7){var _0x272618=_[_0xe86e('0x5')](_0x3f1bf7[_0xe86e('0x6')]);return _0x272618&&_0x272618[_0xe86e('0x7')]?_0x272618[_0xe86e('0x7')]:_0xe86e('0x8')+random[_0xe86e('0x9')](0x6)+_0xe86e('0xa');}function getFirstName(_0x5bf968){var _0x1f9447=_[_0xe86e('0x5')](_0x5bf968[_0xe86e('0x6')]);if(_0x1f9447&&_0x1f9447['name']){var _0x4d3806=_0x1f9447['name'][_0xe86e('0xb')](/\s+/);return _0x4d3806[_0xe86e('0xc')]?_0x4d3806[_0xe86e('0xd')](0x0,-0x1)[_0xe86e('0xe')]('\x20'):_0x1f9447['name'];}return'Anonymous';}function getLastName(_0x44961a){var _0x6ede5b=_['head'](_0x44961a[_0xe86e('0x6')]);if(_0x6ede5b&&_0x6ede5b[_0xe86e('0xf')]){var _0x1531ef=_0x6ede5b['name'][_0xe86e('0xb')](/\s+/);return _0x1531ef[_0xe86e('0xc')]>0x1?_0x1531ef['pop']():'';}return'';}function getMails(_0x812c1e,_0x1d6501){var _0x1d16f9='';for(var _0x615015=0x0;_0x615015<_0x1d6501[_0xe86e('0x6')][_0xe86e('0xc')];_0x615015+=0x1){if(_0x1d6501['value'][_0x615015][_0xe86e('0x7')]!==_0x812c1e){if(!_[_0xe86e('0x10')](_0x1d16f9)){_0x1d16f9+=',';}_0x1d16f9+=_0x1d6501[_0xe86e('0x6')][_0x615015]['name']||_0x1d6501[_0xe86e('0x6')][_0x615015]['address']||'';_0x1d16f9+='\x20<';_0x1d16f9+=_0x1d6501[_0xe86e('0x6')][_0x615015]['address']?_0x1d6501[_0xe86e('0x6')][_0x615015][_0xe86e('0x7')]:_0xe86e('0x8')+random[_0xe86e('0x9')](0x6)+_0xe86e('0xa');_0x1d16f9+='>';}}return _0x1d16f9;}function parseEmail(_0x50c274,_0xc9658a,_0x41e3eb){if(_0xc9658a[_0xe86e('0x11')]){var _0x269e5a=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x269e5a[_0xe86e('0x12')](_0xc9658a[_0xe86e('0x11')])){_0xc9658a[_0xe86e('0x11')]=_0xc9658a[_0xe86e('0x11')][_0xe86e('0x13')](_0x269e5a,'');}_0x41e3eb['body']=_0xc9658a[_0xe86e('0x11')];}else{_0x41e3eb[_0xe86e('0x14')]=_0xc9658a[_0xe86e('0x15')];}if(_0x41e3eb[_0xe86e('0x14')]){_0x41e3eb[_0xe86e('0x14')]=_0x41e3eb[_0xe86e('0x14')][_0xe86e('0x13')](/<a\s+/gi,_0xe86e('0x16'));}if(_0xc9658a['to']){_0x41e3eb['message']['originTo']=getMails(null,_0xc9658a['to']);var _0x336744=getMails(_0x50c274[_0xe86e('0x17')],_0xc9658a['to']);if(!_['isEmpty'](_0x336744)){_0x41e3eb[_0xe86e('0x18')]['cc']+=_0x336744;}}if(_0xc9658a['cc']){_0x41e3eb[_0xe86e('0x18')]['originCc']=getMails(null,_0xc9658a['cc']);var _0x49c749=getMails(_0x50c274[_0xe86e('0x17')],_0xc9658a['cc']);if(!_[_0xe86e('0x10')](_0x49c749)){if(!_[_0xe86e('0x10')](_0x41e3eb[_0xe86e('0x18')]['cc'])){_0x41e3eb[_0xe86e('0x18')]['cc']+=',';}_0x41e3eb[_0xe86e('0x18')]['cc']+=_0x49c749;}}if(!_[_0xe86e('0x19')](_0x41e3eb['message'][_0xe86e('0x1a')],_0x50c274[_0xe86e('0x17')])&&!_['includes'](_0x41e3eb[_0xe86e('0x18')]['originCc'],_0x50c274[_0xe86e('0x17')])){_0x41e3eb[_0xe86e('0x18')]['bcc']=_0x50c274[_0xe86e('0x17')];}if(_0xc9658a[_0xe86e('0x1b')]&&_0xc9658a[_0xe86e('0x1b')][_0xe86e('0xc')]){_0x41e3eb[_0xe86e('0x18')][_0xe86e('0x1c')]=_0xc9658a[_0xe86e('0x1b')][_0xe86e('0xc')];for(var _0x37506f=0x0,_0x263fa3,_0x53ab38,_0x38235a;_0x37506f<_0xc9658a[_0xe86e('0x1b')]['length'];_0x37506f+=0x1){if(_0xc9658a[_0xe86e('0x1b')][_0x37506f][_0xe86e('0x1d')]===_0xe86e('0x1e')){_0x38235a=_0xc9658a['attachments'][_0x37506f][_0xe86e('0x1f')]||_0xe86e('0x20')+_0x37506f;_0x263fa3=util[_0xe86e('0x21')](_0xe86e('0x22'),Date[_0xe86e('0x23')](),_0x38235a);_0x53ab38=path[_0xe86e('0xe')](config['root'],_0xe86e('0x24'),_0x263fa3);fs[_0xe86e('0x25')](_0x53ab38,_0xc9658a[_0xe86e('0x1b')][_0x37506f][_0xe86e('0x26')]);_0x41e3eb[_0xe86e('0x18')][_0xe86e('0x1b')]['push']({'name':_0x38235a,'basename':_0x263fa3,'type':_0xc9658a[_0xe86e('0x1b')][_0x37506f][_0xe86e('0x27')],'filepath':_0x53ab38});}}}return _0x41e3eb;}exports[_0xe86e('0x28')]=function(_0x46faaf,_0x47e901,_0x3e8dbe){var _0x5a7356={'from':getAddress(_0x47e901[_0xe86e('0x29')]),'firstName':getFirstName(_0x47e901[_0xe86e('0x29')]),'lastName':getLastName(_0x47e901[_0xe86e('0x29')]),'mapKey':'email','message':{'from':getMails(_0x46faaf[_0xe86e('0x17')],_0x47e901[_0xe86e('0x29')]),'to':_0x46faaf[_0xe86e('0x17')],'cc':'','subject':_0x47e901['subject']||'','messageId':_0x47e901['messageId'],'inReplyTo':_0x47e901[_0xe86e('0x2a')],'sentAt':moment(_0x47e901[_0xe86e('0x2b')])['format']('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x47e901[_0xe86e('0x11')]&&!_0x47e901[_0xe86e('0x15')]){var _0x31c669=_[_0xe86e('0x2c')](_0x47e901[_0xe86e('0x1b')],{'contentType':_0xe86e('0x2d')});if(_0x31c669[_0xe86e('0xc')]){logger[_0xe86e('0x2e')](util[_0xe86e('0x21')](_0xe86e('0x2f'),_0x47e901[_0xe86e('0x30')]));tnef[_0xe86e('0x31')](_[_0xe86e('0x32')](_0x31c669)[_0xe86e('0x26')],function(_0x2901bc,_0x533465){if(_0x533465){_0x47e901[_0xe86e('0x11')]=_0x533465[_0xe86e('0x33')]||_0xe86e('0x34');if(_0x533465['Attachments']){for(var _0x5f2b73=0x0;_0x5f2b73<_0x533465[_0xe86e('0x35')][_0xe86e('0xc')];_0x5f2b73++){var _0x175d43=_0x533465[_0xe86e('0x35')][_0x5f2b73];_0x5a7356[_0xe86e('0x18')]['attachments']['push']({'filename':_0x175d43[_0xe86e('0x36')],'content':new Buffer(_0x175d43[_0xe86e('0x37')])});}}}_0x3e8dbe(parseEmail(_0x46faaf,_0x47e901,_0x5a7356));});}else{_0x47e901[_0xe86e('0x11')]=_0xe86e('0x34');_0x3e8dbe(parseEmail(_0x46faaf,_0x47e901,_0x5a7356));}}else{_0x3e8dbe(parseEmail(_0x46faaf,_0x47e901,_0x5a7356));}};exports[_0xe86e('0x38')]=function(_0x1104cf){switch(_0x1104cf){case'gmail':return _0xe86e('0x39');case _0xe86e('0x3a'):return'imap.mail.yahoo.com';case _0xe86e('0x3b'):return'imap-mail.outlook.com';case'outlook365':return _0xe86e('0x3c');}return'127.0.0.1';};
\ No newline at end of file
+var _0xb6fd=['line','isAutoreply','parser','from','subject','messageId','inReplyTo','date','YYYY-MM-DD\x20HH:mm:ss','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','first','BodyHTML','<p>Empty\x20message</p>','Attachments','Data','user=','auth=Bearer\x20','utf-8','toString','base64','lodash','moment','randomstring','path','util','node-tnef','../../../config/logger','email','head','value','address','generate','@xcally.com','name','substring','indexOf','split','join','length','pop','isEmpty','anonymous','html','replace','includes','<img','forEach','filename','_SRC','<span\x20style=font-weight:bold>\x20[Attachment:\x20','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','message','originCc','originTo','bcc','attachments','type','attachment','attachment-','format','%s-%s','now','root','server/files/attachments/','writeFileSync','content','push','contentType','headerLines','Auto-Submitted:\x20auto-replied','X-Auto-Response-Suppress:\x20All'];(function(_0x20ae13,_0x2a0c8e){var _0x533fd5=function(_0x3bb746){while(--_0x3bb746){_0x20ae13['push'](_0x20ae13['shift']());}};_0x533fd5(++_0x2a0c8e);}(_0xb6fd,0x13d));var _0xdb6f=function(_0x5047a1,_0x1bd26d){_0x5047a1=_0x5047a1-0x0;var _0x51d17b=_0xb6fd[_0x5047a1];return _0x51d17b;};'use strict';var _=require(_0xdb6f('0x0'));var moment=require(_0xdb6f('0x1'));var random=require(_0xdb6f('0x2'));var fs=require('fs');var path=require(_0xdb6f('0x3'));var util=require(_0xdb6f('0x4'));var tnef=require(_0xdb6f('0x5'));var logger=require(_0xdb6f('0x6'))(_0xdb6f('0x7'));var config=require('../../../config/environment');function getAddress(_0x2998a7){var _0x2fab4e=_[_0xdb6f('0x8')](_0x2998a7[_0xdb6f('0x9')]);return _0x2fab4e&&_0x2fab4e[_0xdb6f('0xa')]?_0x2fab4e[_0xdb6f('0xa')]:'anonymous'+random[_0xdb6f('0xb')](0x6)+_0xdb6f('0xc');}function getFirstName(_0x1b02d6){var _0x577f9a=_[_0xdb6f('0x8')](_0x1b02d6['value']);if(_0x577f9a&&_0x577f9a[_0xdb6f('0xd')]){if(_0x577f9a[_0xdb6f('0xd')]==_0x577f9a[_0xdb6f('0xa')]){return _0x577f9a[_0xdb6f('0xd')][_0xdb6f('0xe')](0x0,_0x577f9a[_0xdb6f('0xd')][_0xdb6f('0xf')]('@'));}var _0x5328af=_0x577f9a[_0xdb6f('0xd')][_0xdb6f('0x10')](/\s+/);return _0x5328af['length']>0x1?_0x5328af['slice'](0x0,-0x1)[_0xdb6f('0x11')]('\x20'):_0x577f9a[_0xdb6f('0xd')];}return'Anonymous';}function getLastName(_0x2c7231){var _0x3fd7b0=_[_0xdb6f('0x8')](_0x2c7231[_0xdb6f('0x9')]);if(_0x3fd7b0&&_0x3fd7b0['name']){var _0x1fc3bb=_0x3fd7b0[_0xdb6f('0xd')][_0xdb6f('0x10')](/\s+/);return _0x1fc3bb[_0xdb6f('0x12')]>0x1?_0x1fc3bb[_0xdb6f('0x13')]():'';}return'';}function getMails(_0x261a0a,_0x592506){var _0x3fda97='';for(var _0x2dbf90=0x0;_0x2dbf90<_0x592506[_0xdb6f('0x9')][_0xdb6f('0x12')];_0x2dbf90+=0x1){if(_0x592506[_0xdb6f('0x9')][_0x2dbf90][_0xdb6f('0xa')]!==_0x261a0a){if(!_[_0xdb6f('0x14')](_0x3fda97)){_0x3fda97+=',';}_0x3fda97+=_0x592506[_0xdb6f('0x9')][_0x2dbf90]['name']||_0x592506[_0xdb6f('0x9')][_0x2dbf90][_0xdb6f('0xa')]||'';_0x3fda97+='\x20<';_0x3fda97+=_0x592506[_0xdb6f('0x9')][_0x2dbf90][_0xdb6f('0xa')]?_0x592506[_0xdb6f('0x9')][_0x2dbf90][_0xdb6f('0xa')]:_0xdb6f('0x15')+random[_0xdb6f('0xb')](0x6)+_0xdb6f('0xc');_0x3fda97+='>';}}return _0x3fda97;}function parseEmail(_0x22a7fc,_0x298471,_0x5788eb){if(_0x298471[_0xdb6f('0x16')]){var _0x12c4dc=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x12c4dc['test'](_0x298471[_0xdb6f('0x16')])){_0x298471[_0xdb6f('0x16')]=_0x298471['html'][_0xdb6f('0x17')](_0x12c4dc,'');}if(_0x298471[_0xdb6f('0x16')][_0xdb6f('0x18')](_0xdb6f('0x19'))){var _0x1d8b97=[];_0x298471['attachments'][_0xdb6f('0x1a')](_0xbe4641=>{_0x1d8b97['push'](_0xbe4641[_0xdb6f('0x1b')]);});var _0x2e0546=/<img.*? _SRC(.*?)[^>]+>/g;var _0x1f71eb=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x47d1a6=_0x298471['html'][_0xdb6f('0x17')](_0x1f71eb,_0xdb6f('0x1c'));var _0x53769a=_0x47d1a6[_0xdb6f('0x17')](_0x2e0546,'_IMG');for(let _0x3eaf41=0x0;_0x3eaf41<_0x1d8b97[_0xdb6f('0x12')];_0x3eaf41++){var _0x186c7b=_0x53769a[_0xdb6f('0x17')]('_IMG',_0xdb6f('0x1d')+_0x1d8b97[_0x3eaf41]+'\x20]</span>');_0x53769a=_0x186c7b;}_0x298471['html']=_0x53769a;}_0x5788eb['body']=_0x298471[_0xdb6f('0x16')];}else{_0x5788eb[_0xdb6f('0x1e')]=_0x298471[_0xdb6f('0x1f')];}if(_0x5788eb['body']){_0x5788eb[_0xdb6f('0x1e')]=_0x5788eb[_0xdb6f('0x1e')]['replace'](/<a\s+/gi,_0xdb6f('0x20'));}if(_0x298471['to']){_0x5788eb[_0xdb6f('0x21')]['originTo']=getMails(null,_0x298471['to']);var _0x30fdd2=getMails(_0x22a7fc[_0xdb6f('0x7')],_0x298471['to']);if(!_[_0xdb6f('0x14')](_0x30fdd2)){_0x5788eb[_0xdb6f('0x21')]['cc']+=_0x30fdd2;}}if(_0x298471['cc']){_0x5788eb['message'][_0xdb6f('0x22')]=getMails(null,_0x298471['cc']);var _0x2423b4=getMails(_0x22a7fc[_0xdb6f('0x7')],_0x298471['cc']);if(!_[_0xdb6f('0x14')](_0x2423b4)){if(!_['isEmpty'](_0x5788eb[_0xdb6f('0x21')]['cc'])){_0x5788eb[_0xdb6f('0x21')]['cc']+=',';}_0x5788eb[_0xdb6f('0x21')]['cc']+=_0x2423b4;}}if(!_[_0xdb6f('0x18')](_0x5788eb[_0xdb6f('0x21')][_0xdb6f('0x23')],_0x22a7fc['email'])&&!_[_0xdb6f('0x18')](_0x5788eb['message'][_0xdb6f('0x22')],_0x22a7fc['email'])){_0x5788eb[_0xdb6f('0x21')][_0xdb6f('0x24')]=_0x22a7fc[_0xdb6f('0x7')];}if(_0x298471['attachments']&&_0x298471[_0xdb6f('0x25')][_0xdb6f('0x12')]){_0x5788eb[_0xdb6f('0x21')]['attach']=_0x298471[_0xdb6f('0x25')][_0xdb6f('0x12')];for(var _0x3f0bcc=0x0,_0xfd1b9b,_0x5ea172,_0x43860e;_0x3f0bcc<_0x298471[_0xdb6f('0x25')][_0xdb6f('0x12')];_0x3f0bcc+=0x1){if(_0x298471[_0xdb6f('0x25')][_0x3f0bcc][_0xdb6f('0x26')]===_0xdb6f('0x27')){_0x43860e=_0x298471[_0xdb6f('0x25')][_0x3f0bcc][_0xdb6f('0x1b')]||_0xdb6f('0x28')+_0x3f0bcc;_0xfd1b9b=util[_0xdb6f('0x29')](_0xdb6f('0x2a'),Date[_0xdb6f('0x2b')](),_0x43860e);_0x5ea172=path['join'](config[_0xdb6f('0x2c')],_0xdb6f('0x2d'),_0xfd1b9b);fs[_0xdb6f('0x2e')](_0x5ea172,_0x298471[_0xdb6f('0x25')][_0x3f0bcc][_0xdb6f('0x2f')]);_0x5788eb[_0xdb6f('0x21')][_0xdb6f('0x25')][_0xdb6f('0x30')]({'name':_0x43860e,'basename':_0xfd1b9b,'type':_0x298471[_0xdb6f('0x25')][_0x3f0bcc][_0xdb6f('0x31')],'filepath':_0x5ea172});}}}if(_0x298471[_0xdb6f('0x32')]&&_0x298471[_0xdb6f('0x32')][_0xdb6f('0x12')]>0x0){var _0x5d4c94=[_0xdb6f('0x33'),_0xdb6f('0x34'),'Precedence:\x20auto_reply'];for(var _0x10d1cd=0x0;_0x10d1cd<_0x298471[_0xdb6f('0x32')][_0xdb6f('0x12')];_0x10d1cd++){var _0x4c18f8=_['indexOf'](_0x5d4c94,_0x298471[_0xdb6f('0x32')][_0x10d1cd][_0xdb6f('0x35')]);if(_0x4c18f8>=0x0){_0x5788eb[_0xdb6f('0x36')]=!![];}}}return _0x5788eb;}exports[_0xdb6f('0x37')]=function(_0x2cd9b6,_0x24ea45,_0x2aa1db){var _0xc4bce6={'from':getAddress(_0x24ea45[_0xdb6f('0x38')]),'firstName':getFirstName(_0x24ea45[_0xdb6f('0x38')]),'lastName':getLastName(_0x24ea45[_0xdb6f('0x38')]),'mapKey':_0xdb6f('0x7'),'message':{'from':getMails(_0x2cd9b6[_0xdb6f('0x7')],_0x24ea45[_0xdb6f('0x38')]),'to':_0x2cd9b6['email'],'cc':'','subject':_0x24ea45[_0xdb6f('0x39')]||'','messageId':_0x24ea45[_0xdb6f('0x3a')],'inReplyTo':_0x24ea45[_0xdb6f('0x3b')],'sentAt':moment(_0x24ea45[_0xdb6f('0x3c')])[_0xdb6f('0x29')](_0xdb6f('0x3d')),'attach':![],'attachments':[]}};if(!_0x24ea45[_0xdb6f('0x16')]&&!_0x24ea45[_0xdb6f('0x1f')]){var _0x1da4dd=_['filter'](_0x24ea45[_0xdb6f('0x25')],{'contentType':'application/ms-tnef'});if(_0x1da4dd[_0xdb6f('0x12')]){logger[_0xdb6f('0x3e')](util[_0xdb6f('0x29')](_0xdb6f('0x3f'),_0x24ea45[_0xdb6f('0x3a')]));tnef['parseBuffer'](_[_0xdb6f('0x40')](_0x1da4dd)['content'],function(_0x27599a,_0x369058){if(_0x369058){_0x24ea45[_0xdb6f('0x16')]=_0x369058[_0xdb6f('0x41')]||_0xdb6f('0x42');if(_0x369058[_0xdb6f('0x43')]){for(var _0x38c0f4=0x0;_0x38c0f4<_0x369058['Attachments'][_0xdb6f('0x12')];_0x38c0f4++){var _0x4f82da=_0x369058['Attachments'][_0x38c0f4];_0xc4bce6['message'][_0xdb6f('0x25')][_0xdb6f('0x30')]({'filename':_0x4f82da['Title'],'content':Buffer['from'](_0x4f82da[_0xdb6f('0x44')])});}}}_0x2aa1db(parseEmail(_0x2cd9b6,_0x24ea45,_0xc4bce6));});}else{_0x24ea45[_0xdb6f('0x16')]=_0xdb6f('0x42');_0x2aa1db(parseEmail(_0x2cd9b6,_0x24ea45,_0xc4bce6));}}else{_0x2aa1db(parseEmail(_0x2cd9b6,_0x24ea45,_0xc4bce6));}};exports['generateXOAuth2Token']=function(_0x4d7060,_0x33330b){var _0x3cebef=[_0xdb6f('0x45')+(_0x33330b||''),_0xdb6f('0x46')+_0x4d7060,'',''];return Buffer[_0xdb6f('0x38')](_0x3cebef[_0xdb6f('0x11')]('\ 1'),_0xdb6f('0x47'))[_0xdb6f('0x48')](_0xdb6f('0x49'));};
\ No newline at end of file