Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / services / email / lib / utils.js
index 292945d..746306b 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6eb1=['contentType','parser','from','subject','messageId','inReplyTo','date','YYYY-MM-DD\x20HH:mm:ss','first','BodyHTML','<p>Empty\x20message</p>','Attachments','Data','getHost','gmail','yahoo','hotmail','imap-mail.outlook.com','127.0.0.1','lodash','moment','randomstring','util','node-tnef','../../../config/logger','email','value','address','anonymous','generate','@xcally.com','head','name','length','slice','isEmpty','html','test','replace','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','originTo','message','includes','originCc','bcc','attachments','attach','type','attachment','filename','attachment-','format','%s-%s','now','join','root','server/files/attachments/','content','push'];(function(_0x27e811,_0x20137c){var _0x1627fa=function(_0x4498ca){while(--_0x4498ca){_0x27e811['push'](_0x27e811['shift']());}};_0x1627fa(++_0x20137c);}(_0x6eb1,0x181));var _0x16eb=function(_0x201043,_0x57e46b){_0x201043=_0x201043-0x0;var _0x29e5f2=_0x6eb1[_0x201043];return _0x29e5f2;};'use strict';var _=require(_0x16eb('0x0'));var moment=require(_0x16eb('0x1'));var random=require(_0x16eb('0x2'));var fs=require('fs');var path=require('path');var util=require(_0x16eb('0x3'));var tnef=require(_0x16eb('0x4'));var logger=require(_0x16eb('0x5'))(_0x16eb('0x6'));var config=require('../../../config/environment');function getAddress(_0x5c2e21){var _0x3cc8d2=_['head'](_0x5c2e21[_0x16eb('0x7')]);return _0x3cc8d2&&_0x3cc8d2[_0x16eb('0x8')]?_0x3cc8d2['address']:_0x16eb('0x9')+random[_0x16eb('0xa')](0x6)+_0x16eb('0xb');}function getFirstName(_0x375d55){var _0x3b95b7=_[_0x16eb('0xc')](_0x375d55[_0x16eb('0x7')]);if(_0x3b95b7&&_0x3b95b7[_0x16eb('0xd')]){var _0x2f497e=_0x3b95b7['name']['split'](/\s+/);return _0x2f497e[_0x16eb('0xe')]?_0x2f497e[_0x16eb('0xf')](0x0,-0x1)['join']('\x20'):_0x3b95b7['name'];}return'Anonymous';}function getLastName(_0x5f4678){var _0xfdd3a3=_[_0x16eb('0xc')](_0x5f4678['value']);if(_0xfdd3a3&&_0xfdd3a3['name']){var _0x315dfb=_0xfdd3a3[_0x16eb('0xd')]['split'](/\s+/);return _0x315dfb[_0x16eb('0xe')]>0x1?_0x315dfb['pop']():'';}return'';}function getMails(_0x24767e,_0xfe646){var _0x6a71e6='';for(var _0x2e8b5f=0x0;_0x2e8b5f<_0xfe646[_0x16eb('0x7')][_0x16eb('0xe')];_0x2e8b5f+=0x1){if(_0xfe646[_0x16eb('0x7')][_0x2e8b5f][_0x16eb('0x8')]!==_0x24767e){if(!_[_0x16eb('0x10')](_0x6a71e6)){_0x6a71e6+=',';}_0x6a71e6+=_0xfe646['value'][_0x2e8b5f][_0x16eb('0xd')]||_0xfe646[_0x16eb('0x7')][_0x2e8b5f][_0x16eb('0x8')]||'';_0x6a71e6+='\x20<';_0x6a71e6+=_0xfe646[_0x16eb('0x7')][_0x2e8b5f][_0x16eb('0x8')]?_0xfe646[_0x16eb('0x7')][_0x2e8b5f][_0x16eb('0x8')]:_0x16eb('0x9')+random[_0x16eb('0xa')](0x6)+_0x16eb('0xb');_0x6a71e6+='>';}}return _0x6a71e6;}function parseEmail(_0x31c528,_0xd0a142,_0x54871e){if(_0xd0a142[_0x16eb('0x11')]){var _0x175ecf=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x175ecf[_0x16eb('0x12')](_0xd0a142[_0x16eb('0x11')])){_0xd0a142['html']=_0xd0a142[_0x16eb('0x11')][_0x16eb('0x13')](_0x175ecf,'');}_0x54871e[_0x16eb('0x14')]=_0xd0a142[_0x16eb('0x11')];}else{_0x54871e[_0x16eb('0x14')]=_0xd0a142[_0x16eb('0x15')];}if(_0x54871e[_0x16eb('0x14')]){_0x54871e[_0x16eb('0x14')]=_0x54871e[_0x16eb('0x14')]['replace'](/<a\s+/gi,_0x16eb('0x16'));}if(_0xd0a142['to']){_0x54871e['message'][_0x16eb('0x17')]=getMails(null,_0xd0a142['to']);var _0x4962dd=getMails(_0x31c528[_0x16eb('0x6')],_0xd0a142['to']);if(!_['isEmpty'](_0x4962dd)){_0x54871e[_0x16eb('0x18')]['cc']+=_0x4962dd;}}if(_0xd0a142['cc']){_0x54871e['message']['originCc']=getMails(null,_0xd0a142['cc']);var _0x3b0936=getMails(_0x31c528[_0x16eb('0x6')],_0xd0a142['cc']);if(!_[_0x16eb('0x10')](_0x3b0936)){if(!_[_0x16eb('0x10')](_0x54871e[_0x16eb('0x18')]['cc'])){_0x54871e['message']['cc']+=',';}_0x54871e['message']['cc']+=_0x3b0936;}}if(!_[_0x16eb('0x19')](_0x54871e[_0x16eb('0x18')]['originTo'],_0x31c528['email'])&&!_[_0x16eb('0x19')](_0x54871e[_0x16eb('0x18')][_0x16eb('0x1a')],_0x31c528['email'])){_0x54871e[_0x16eb('0x18')][_0x16eb('0x1b')]=_0x31c528[_0x16eb('0x6')];}if(_0xd0a142[_0x16eb('0x1c')]&&_0xd0a142[_0x16eb('0x1c')][_0x16eb('0xe')]){_0x54871e[_0x16eb('0x18')][_0x16eb('0x1d')]=_0xd0a142[_0x16eb('0x1c')][_0x16eb('0xe')];for(var _0x1dc7f3=0x0,_0x55a18a,_0x5e5d2b,_0x2ddc14;_0x1dc7f3<_0xd0a142['attachments'][_0x16eb('0xe')];_0x1dc7f3+=0x1){if(_0xd0a142[_0x16eb('0x1c')][_0x1dc7f3][_0x16eb('0x1e')]===_0x16eb('0x1f')){_0x2ddc14=_0xd0a142[_0x16eb('0x1c')][_0x1dc7f3][_0x16eb('0x20')]||_0x16eb('0x21')+_0x1dc7f3;_0x55a18a=util[_0x16eb('0x22')](_0x16eb('0x23'),Date[_0x16eb('0x24')](),_0x2ddc14);_0x5e5d2b=path[_0x16eb('0x25')](config[_0x16eb('0x26')],_0x16eb('0x27'),_0x55a18a);fs['writeFileSync'](_0x5e5d2b,_0xd0a142[_0x16eb('0x1c')][_0x1dc7f3][_0x16eb('0x28')]);_0x54871e[_0x16eb('0x18')][_0x16eb('0x1c')][_0x16eb('0x29')]({'name':_0x2ddc14,'basename':_0x55a18a,'type':_0xd0a142[_0x16eb('0x1c')][_0x1dc7f3][_0x16eb('0x2a')],'filepath':_0x5e5d2b});}}}return _0x54871e;}exports[_0x16eb('0x2b')]=function(_0x18e4d0,_0x642850,_0x2c109b){var _0x1c56c0={'from':getAddress(_0x642850[_0x16eb('0x2c')]),'firstName':getFirstName(_0x642850[_0x16eb('0x2c')]),'lastName':getLastName(_0x642850[_0x16eb('0x2c')]),'mapKey':_0x16eb('0x6'),'message':{'from':getMails(_0x18e4d0[_0x16eb('0x6')],_0x642850[_0x16eb('0x2c')]),'to':_0x18e4d0[_0x16eb('0x6')],'cc':'','subject':_0x642850[_0x16eb('0x2d')]||'','messageId':_0x642850[_0x16eb('0x2e')],'inReplyTo':_0x642850[_0x16eb('0x2f')],'sentAt':moment(_0x642850[_0x16eb('0x30')])['format'](_0x16eb('0x31')),'attach':![],'attachments':[]}};if(!_0x642850[_0x16eb('0x11')]&&!_0x642850[_0x16eb('0x15')]){var _0x288ca3=_['filter'](_0x642850['attachments'],{'contentType':'application/ms-tnef'});if(_0x288ca3[_0x16eb('0xe')]){logger['info'](util['format']('Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system',_0x642850[_0x16eb('0x2e')]));tnef['parseBuffer'](_[_0x16eb('0x32')](_0x288ca3)[_0x16eb('0x28')],function(_0x542476,_0x588df0){if(_0x588df0){_0x642850['html']=_0x588df0[_0x16eb('0x33')]||_0x16eb('0x34');if(_0x588df0['Attachments']){for(var _0x3f0c94=0x0;_0x3f0c94<_0x588df0[_0x16eb('0x35')]['length'];_0x3f0c94++){var _0xe4bd63=_0x588df0['Attachments'][_0x3f0c94];_0x1c56c0['message'][_0x16eb('0x1c')][_0x16eb('0x29')]({'filename':_0xe4bd63['Title'],'content':new Buffer(_0xe4bd63[_0x16eb('0x36')])});}}}_0x2c109b(parseEmail(_0x18e4d0,_0x642850,_0x1c56c0));});}else{_0x642850[_0x16eb('0x11')]=_0x16eb('0x34');_0x2c109b(parseEmail(_0x18e4d0,_0x642850,_0x1c56c0));}}else{_0x2c109b(parseEmail(_0x18e4d0,_0x642850,_0x1c56c0));}};exports[_0x16eb('0x37')]=function(_0x37923a){switch(_0x37923a){case _0x16eb('0x38'):return'imap.gmail.com';case _0x16eb('0x39'):return'imap.mail.yahoo.com';case _0x16eb('0x3a'):return _0x16eb('0x3b');case'outlook365':return'outlook.office365.com';}return _0x16eb('0x3c');};
\ No newline at end of file
+var _0xaad8=['Data','generateXOAuth2Token','user=','auth=Bearer\x20','utf-8','toString','base64','lodash','moment','randomstring','path','util','node-tnef','../../../config/logger','email','../../../config/environment','head','value','address','anonymous','@xcally.com','name','substring','split','slice','join','Anonymous','length','pop','generate','html','test','replace','includes','<img','forEach','push','filename','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','message','isEmpty','originCc','bcc','attachments','attach','%s-%s','now','server/files/attachments/','writeFileSync','content','contentType','headerLines','Auto-Submitted:\x20auto-replied','X-Auto-Response-Suppress:\x20All','Precedence:\x20auto_reply','indexOf','line','isAutoreply','from','subject','messageId','date','format','filter','application/ms-tnef','info','parseBuffer','first','BodyHTML','Attachments','Title'];(function(_0xdeac17,_0x19ad66){var _0x33aabd=function(_0x558a9e){while(--_0x558a9e){_0xdeac17['push'](_0xdeac17['shift']());}};_0x33aabd(++_0x19ad66);}(_0xaad8,0xa1));var _0x8aad=function(_0x5e4d59,_0x9769e4){_0x5e4d59=_0x5e4d59-0x0;var _0x5666a3=_0xaad8[_0x5e4d59];return _0x5666a3;};'use strict';var _=require(_0x8aad('0x0'));var moment=require(_0x8aad('0x1'));var random=require(_0x8aad('0x2'));var fs=require('fs');var path=require(_0x8aad('0x3'));var util=require(_0x8aad('0x4'));var tnef=require(_0x8aad('0x5'));var logger=require(_0x8aad('0x6'))(_0x8aad('0x7'));var config=require(_0x8aad('0x8'));function getAddress(_0xb16f01){var _0x4b3e2d=_[_0x8aad('0x9')](_0xb16f01[_0x8aad('0xa')]);return _0x4b3e2d&&_0x4b3e2d[_0x8aad('0xb')]?_0x4b3e2d[_0x8aad('0xb')]:_0x8aad('0xc')+random['generate'](0x6)+_0x8aad('0xd');}function getFirstName(_0x4c26df){var _0x482df0=_['head'](_0x4c26df[_0x8aad('0xa')]);if(_0x482df0&&_0x482df0[_0x8aad('0xe')]){if(_0x482df0[_0x8aad('0xe')]==_0x482df0[_0x8aad('0xb')]){return _0x482df0['name'][_0x8aad('0xf')](0x0,_0x482df0['name']['indexOf']('@'));}var _0x5c86eb=_0x482df0[_0x8aad('0xe')][_0x8aad('0x10')](/\s+/);return _0x5c86eb['length']>0x1?_0x5c86eb[_0x8aad('0x11')](0x0,-0x1)[_0x8aad('0x12')]('\x20'):_0x482df0[_0x8aad('0xe')];}return _0x8aad('0x13');}function getLastName(_0x7addcd){var _0x48ce26=_[_0x8aad('0x9')](_0x7addcd['value']);if(_0x48ce26&&_0x48ce26['name']){var _0x54e1ee=_0x48ce26[_0x8aad('0xe')]['split'](/\s+/);return _0x54e1ee[_0x8aad('0x14')]>0x1?_0x54e1ee[_0x8aad('0x15')]():'';}return'';}function getMails(_0x47ce59,_0x4997ea){var _0x11b9b5='';for(var _0xa98d02=0x0;_0xa98d02<_0x4997ea[_0x8aad('0xa')]['length'];_0xa98d02+=0x1){if(_0x4997ea[_0x8aad('0xa')][_0xa98d02][_0x8aad('0xb')]!==_0x47ce59){if(!_['isEmpty'](_0x11b9b5)){_0x11b9b5+=',';}_0x11b9b5+=_0x4997ea[_0x8aad('0xa')][_0xa98d02][_0x8aad('0xe')]||_0x4997ea[_0x8aad('0xa')][_0xa98d02][_0x8aad('0xb')]||'';_0x11b9b5+='\x20<';_0x11b9b5+=_0x4997ea[_0x8aad('0xa')][_0xa98d02][_0x8aad('0xb')]?_0x4997ea[_0x8aad('0xa')][_0xa98d02][_0x8aad('0xb')]:_0x8aad('0xc')+random[_0x8aad('0x16')](0x6)+'@xcally.com';_0x11b9b5+='>';}}return _0x11b9b5;}function parseEmail(_0xe4fd4b,_0x953735,_0x2d56e9){if(_0x953735[_0x8aad('0x17')]){var _0x13fafc=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x13fafc[_0x8aad('0x18')](_0x953735['html'])){_0x953735[_0x8aad('0x17')]=_0x953735[_0x8aad('0x17')][_0x8aad('0x19')](_0x13fafc,'');}if(_0x953735[_0x8aad('0x17')][_0x8aad('0x1a')](_0x8aad('0x1b'))){var _0x482c64=[];_0x953735['attachments'][_0x8aad('0x1c')](_0x56004f=>{_0x482c64[_0x8aad('0x1d')](_0x56004f[_0x8aad('0x1e')]);});var _0x5c01be=/<img.*? _SRC(.*?)[^>]+>/g;var _0xf509d8=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x64514f=_0x953735[_0x8aad('0x17')][_0x8aad('0x19')](_0xf509d8,_0x8aad('0x1f'));var _0x2fb8dc=_0x64514f[_0x8aad('0x19')](_0x5c01be,_0x8aad('0x20'));for(let _0x4e3193=0x0;_0x4e3193<_0x482c64['length'];_0x4e3193++){var _0x1a7f01=_0x2fb8dc[_0x8aad('0x19')](_0x8aad('0x20'),_0x8aad('0x21')+_0x482c64[_0x4e3193]+_0x8aad('0x22'));_0x2fb8dc=_0x1a7f01;}_0x953735[_0x8aad('0x17')]=_0x2fb8dc;}_0x2d56e9[_0x8aad('0x23')]=_0x953735[_0x8aad('0x17')];}else{_0x2d56e9[_0x8aad('0x23')]=_0x953735[_0x8aad('0x24')];}if(_0x2d56e9[_0x8aad('0x23')]){_0x2d56e9[_0x8aad('0x23')]=_0x2d56e9[_0x8aad('0x23')][_0x8aad('0x19')](/<a\s+/gi,_0x8aad('0x25'));}if(_0x953735['to']){_0x2d56e9[_0x8aad('0x26')]['originTo']=getMails(null,_0x953735['to']);var _0x1ea6b6=getMails(_0xe4fd4b[_0x8aad('0x7')],_0x953735['to']);if(!_[_0x8aad('0x27')](_0x1ea6b6)){_0x2d56e9[_0x8aad('0x26')]['cc']+=_0x1ea6b6;}}if(_0x953735['cc']){_0x2d56e9[_0x8aad('0x26')][_0x8aad('0x28')]=getMails(null,_0x953735['cc']);var _0xdc00bd=getMails(_0xe4fd4b[_0x8aad('0x7')],_0x953735['cc']);if(!_[_0x8aad('0x27')](_0xdc00bd)){if(!_[_0x8aad('0x27')](_0x2d56e9[_0x8aad('0x26')]['cc'])){_0x2d56e9[_0x8aad('0x26')]['cc']+=',';}_0x2d56e9[_0x8aad('0x26')]['cc']+=_0xdc00bd;}}if(!_[_0x8aad('0x1a')](_0x2d56e9[_0x8aad('0x26')]['originTo'],_0xe4fd4b['email'])&&!_[_0x8aad('0x1a')](_0x2d56e9['message'][_0x8aad('0x28')],_0xe4fd4b[_0x8aad('0x7')])){_0x2d56e9[_0x8aad('0x26')][_0x8aad('0x29')]=_0xe4fd4b['email'];}if(_0x953735['attachments']&&_0x953735[_0x8aad('0x2a')]['length']){_0x2d56e9[_0x8aad('0x26')][_0x8aad('0x2b')]=_0x953735['attachments'][_0x8aad('0x14')];for(var _0x49230f=0x0,_0x43a12e,_0x1a3557,_0x416f05;_0x49230f<_0x953735[_0x8aad('0x2a')]['length'];_0x49230f+=0x1){if(_0x953735['attachments'][_0x49230f]['type']==='attachment'){_0x416f05=_0x953735['attachments'][_0x49230f][_0x8aad('0x1e')]||'attachment-'+_0x49230f;_0x43a12e=util['format'](_0x8aad('0x2c'),Date[_0x8aad('0x2d')](),_0x416f05);_0x1a3557=path[_0x8aad('0x12')](config['root'],_0x8aad('0x2e'),_0x43a12e);fs[_0x8aad('0x2f')](_0x1a3557,_0x953735[_0x8aad('0x2a')][_0x49230f][_0x8aad('0x30')]);_0x2d56e9[_0x8aad('0x26')][_0x8aad('0x2a')]['push']({'name':_0x416f05,'basename':_0x43a12e,'type':_0x953735['attachments'][_0x49230f][_0x8aad('0x31')],'filepath':_0x1a3557});}}}if(_0x953735[_0x8aad('0x32')]&&_0x953735[_0x8aad('0x32')][_0x8aad('0x14')]>0x0){var _0x7ca73d=[_0x8aad('0x33'),_0x8aad('0x34'),_0x8aad('0x35')];for(var _0x3f1a20=0x0;_0x3f1a20<_0x953735['headerLines']['length'];_0x3f1a20++){var _0x21ff6c=_[_0x8aad('0x36')](_0x7ca73d,_0x953735['headerLines'][_0x3f1a20][_0x8aad('0x37')]);if(_0x21ff6c>=0x0){_0x2d56e9[_0x8aad('0x38')]=!![];}}}return _0x2d56e9;}exports['parser']=function(_0x1c7e13,_0x201482,_0x4d0ed9){var _0xb289b8={'from':getAddress(_0x201482['from']),'firstName':getFirstName(_0x201482[_0x8aad('0x39')]),'lastName':getLastName(_0x201482[_0x8aad('0x39')]),'mapKey':_0x8aad('0x7'),'message':{'from':getMails(_0x1c7e13['email'],_0x201482[_0x8aad('0x39')]),'to':_0x1c7e13[_0x8aad('0x7')],'cc':'','subject':_0x201482[_0x8aad('0x3a')]||'','messageId':_0x201482[_0x8aad('0x3b')],'inReplyTo':_0x201482['inReplyTo'],'sentAt':moment(_0x201482[_0x8aad('0x3c')])[_0x8aad('0x3d')]('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x201482[_0x8aad('0x17')]&&!_0x201482[_0x8aad('0x24')]){var _0x38475e=_[_0x8aad('0x3e')](_0x201482['attachments'],{'contentType':_0x8aad('0x3f')});if(_0x38475e['length']){logger[_0x8aad('0x40')](util[_0x8aad('0x3d')]('Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system',_0x201482['messageId']));tnef[_0x8aad('0x41')](_[_0x8aad('0x42')](_0x38475e)[_0x8aad('0x30')],function(_0x5e13bf,_0x52a11d){if(_0x52a11d){_0x201482[_0x8aad('0x17')]=_0x52a11d[_0x8aad('0x43')]||'<p>Empty\x20message</p>';if(_0x52a11d[_0x8aad('0x44')]){for(var _0x93b8c0=0x0;_0x93b8c0<_0x52a11d[_0x8aad('0x44')][_0x8aad('0x14')];_0x93b8c0++){var _0x2b3ef9=_0x52a11d['Attachments'][_0x93b8c0];_0xb289b8[_0x8aad('0x26')][_0x8aad('0x2a')][_0x8aad('0x1d')]({'filename':_0x2b3ef9[_0x8aad('0x45')],'content':Buffer[_0x8aad('0x39')](_0x2b3ef9[_0x8aad('0x46')])});}}}_0x4d0ed9(parseEmail(_0x1c7e13,_0x201482,_0xb289b8));});}else{_0x201482[_0x8aad('0x17')]='<p>Empty\x20message</p>';_0x4d0ed9(parseEmail(_0x1c7e13,_0x201482,_0xb289b8));}}else{_0x4d0ed9(parseEmail(_0x1c7e13,_0x201482,_0xb289b8));}};exports[_0x8aad('0x47')]=function(_0x40a5e6,_0x20420f){var _0x4e5351=[_0x8aad('0x48')+(_0x20420f||''),_0x8aad('0x49')+_0x40a5e6,'',''];return Buffer['from'](_0x4e5351[_0x8aad('0x12')]('\ 1'),_0x8aad('0x4a'))[_0x8aad('0x4b')](_0x8aad('0x4c'));};
\ No newline at end of file