Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / services / email / lib / utils.js
index 0a01704..0e8f7b1 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4db5=['Attachments','Title','Data','gmail','yahoo','hotmail','outlook365','127.0.0.1','lodash','moment','randomstring','path','node-tnef','../../../config/logger','email','head','value','anonymous','@xcally.com','name','slice','join','Anonymous','split','length','pop','address','generate','html','test','replace','body','<a\x20target=\x22_blank\x22\x20','message','isEmpty','originCc','bcc','attachments','attach','type','attachment-','format','%s-%s','server/files/attachments/','writeFileSync','content','push','parser','from','subject','messageId','inReplyTo','textAsHtml','application/ms-tnef','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','parseBuffer','first','BodyHTML','<p>Empty\x20message</p>'];(function(_0xc0d362,_0x5f3a6f){var _0x3e433e=function(_0x1b0c9e){while(--_0x1b0c9e){_0xc0d362['push'](_0xc0d362['shift']());}};_0x3e433e(++_0x5f3a6f);}(_0x4db5,0xbc));var _0x54db=function(_0x29412f,_0x541395){_0x29412f=_0x29412f-0x0;var _0x3f0e2e=_0x4db5[_0x29412f];return _0x3f0e2e;};'use strict';var _=require(_0x54db('0x0'));var moment=require(_0x54db('0x1'));var random=require(_0x54db('0x2'));var fs=require('fs');var path=require(_0x54db('0x3'));var util=require('util');var tnef=require(_0x54db('0x4'));var logger=require(_0x54db('0x5'))(_0x54db('0x6'));var config=require('../../../config/environment');function getAddress(_0xa0837b){var _0x1a7bc6=_[_0x54db('0x7')](_0xa0837b[_0x54db('0x8')]);return _0x1a7bc6&&_0x1a7bc6['address']?_0x1a7bc6['address']:_0x54db('0x9')+random['generate'](0x6)+_0x54db('0xa');}function getFirstName(_0x18e3ce){var _0x58f93b=_[_0x54db('0x7')](_0x18e3ce[_0x54db('0x8')]);if(_0x58f93b&&_0x58f93b['name']){var _0x5dcb93=_0x58f93b[_0x54db('0xb')]['split'](/\s+/);return _0x5dcb93['length']?_0x5dcb93[_0x54db('0xc')](0x0,-0x1)[_0x54db('0xd')]('\x20'):_0x58f93b[_0x54db('0xb')];}return _0x54db('0xe');}function getLastName(_0x49bcc4){var _0x1411c8=_[_0x54db('0x7')](_0x49bcc4[_0x54db('0x8')]);if(_0x1411c8&&_0x1411c8[_0x54db('0xb')]){var _0x5b6fb9=_0x1411c8[_0x54db('0xb')][_0x54db('0xf')](/\s+/);return _0x5b6fb9[_0x54db('0x10')]>0x1?_0x5b6fb9[_0x54db('0x11')]():'';}return'';}function getMails(_0x35fbe7,_0x1ac960){var _0x1dbdf9='';for(var _0xb76917=0x0;_0xb76917<_0x1ac960['value'][_0x54db('0x10')];_0xb76917+=0x1){if(_0x1ac960[_0x54db('0x8')][_0xb76917][_0x54db('0x12')]!==_0x35fbe7){if(!_['isEmpty'](_0x1dbdf9)){_0x1dbdf9+=',';}_0x1dbdf9+=_0x1ac960[_0x54db('0x8')][_0xb76917][_0x54db('0xb')]||_0x1ac960[_0x54db('0x8')][_0xb76917][_0x54db('0x12')]||'';_0x1dbdf9+='\x20<';_0x1dbdf9+=_0x1ac960[_0x54db('0x8')][_0xb76917][_0x54db('0x12')]?_0x1ac960[_0x54db('0x8')][_0xb76917][_0x54db('0x12')]:_0x54db('0x9')+random[_0x54db('0x13')](0x6)+_0x54db('0xa');_0x1dbdf9+='>';}}return _0x1dbdf9;}function parseEmail(_0x356f8a,_0x2a9d24,_0x25b71e){if(_0x2a9d24[_0x54db('0x14')]){var _0x1f37a6=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x1f37a6[_0x54db('0x15')](_0x2a9d24[_0x54db('0x14')])){_0x2a9d24[_0x54db('0x14')]=_0x2a9d24[_0x54db('0x14')][_0x54db('0x16')](_0x1f37a6,'');}_0x25b71e[_0x54db('0x17')]=_0x2a9d24['html'];}else{_0x25b71e['body']=_0x2a9d24['textAsHtml'];}if(_0x25b71e[_0x54db('0x17')]){_0x25b71e['body']=_0x25b71e['body']['replace'](/<a\s+/gi,_0x54db('0x18'));}if(_0x2a9d24['to']){_0x25b71e[_0x54db('0x19')]['originTo']=getMails(null,_0x2a9d24['to']);var _0xd4c12c=getMails(_0x356f8a['email'],_0x2a9d24['to']);if(!_[_0x54db('0x1a')](_0xd4c12c)){_0x25b71e[_0x54db('0x19')]['cc']+=_0xd4c12c;}}if(_0x2a9d24['cc']){_0x25b71e[_0x54db('0x19')][_0x54db('0x1b')]=getMails(null,_0x2a9d24['cc']);var _0x3ef071=getMails(_0x356f8a['email'],_0x2a9d24['cc']);if(!_[_0x54db('0x1a')](_0x3ef071)){if(!_['isEmpty'](_0x25b71e[_0x54db('0x19')]['cc'])){_0x25b71e[_0x54db('0x19')]['cc']+=',';}_0x25b71e['message']['cc']+=_0x3ef071;}}if(!_['includes'](_0x25b71e[_0x54db('0x19')]['originTo'],_0x356f8a[_0x54db('0x6')])&&!_['includes'](_0x25b71e[_0x54db('0x19')][_0x54db('0x1b')],_0x356f8a[_0x54db('0x6')])){_0x25b71e[_0x54db('0x19')][_0x54db('0x1c')]=_0x356f8a[_0x54db('0x6')];}if(_0x2a9d24[_0x54db('0x1d')]&&_0x2a9d24['attachments'][_0x54db('0x10')]){_0x25b71e[_0x54db('0x19')][_0x54db('0x1e')]=_0x2a9d24[_0x54db('0x1d')][_0x54db('0x10')];for(var _0x4b450f=0x0,_0x4634b2,_0x11d754,_0x59f728;_0x4b450f<_0x2a9d24[_0x54db('0x1d')][_0x54db('0x10')];_0x4b450f+=0x1){if(_0x2a9d24[_0x54db('0x1d')][_0x4b450f][_0x54db('0x1f')]==='attachment'){_0x59f728=_0x2a9d24[_0x54db('0x1d')][_0x4b450f]['filename']||_0x54db('0x20')+_0x4b450f;_0x4634b2=util[_0x54db('0x21')](_0x54db('0x22'),Date['now'](),_0x59f728);_0x11d754=path[_0x54db('0xd')](config['root'],_0x54db('0x23'),_0x4634b2);fs[_0x54db('0x24')](_0x11d754,_0x2a9d24[_0x54db('0x1d')][_0x4b450f][_0x54db('0x25')]);_0x25b71e[_0x54db('0x19')]['attachments'][_0x54db('0x26')]({'name':_0x59f728,'basename':_0x4634b2,'type':_0x2a9d24[_0x54db('0x1d')][_0x4b450f]['contentType'],'filepath':_0x11d754});}}}return _0x25b71e;}exports[_0x54db('0x27')]=function(_0x14275e,_0x463b4f,_0x493a81){var _0x59f05a={'from':getAddress(_0x463b4f[_0x54db('0x28')]),'firstName':getFirstName(_0x463b4f['from']),'lastName':getLastName(_0x463b4f[_0x54db('0x28')]),'mapKey':_0x54db('0x6'),'message':{'from':getMails(_0x14275e[_0x54db('0x6')],_0x463b4f['from']),'to':_0x14275e[_0x54db('0x6')],'cc':'','subject':_0x463b4f[_0x54db('0x29')]||'','messageId':_0x463b4f[_0x54db('0x2a')],'inReplyTo':_0x463b4f[_0x54db('0x2b')],'sentAt':moment(_0x463b4f['date'])[_0x54db('0x21')]('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x463b4f[_0x54db('0x14')]&&!_0x463b4f[_0x54db('0x2c')]){var _0x1b79ef=_['filter'](_0x463b4f[_0x54db('0x1d')],{'contentType':_0x54db('0x2d')});if(_0x1b79ef[_0x54db('0x10')]){logger[_0x54db('0x2e')](util[_0x54db('0x21')](_0x54db('0x2f'),_0x463b4f[_0x54db('0x2a')]));tnef[_0x54db('0x30')](_[_0x54db('0x31')](_0x1b79ef)[_0x54db('0x25')],function(_0x3595cf,_0x382fd4){if(_0x382fd4){_0x463b4f[_0x54db('0x14')]=_0x382fd4[_0x54db('0x32')]||_0x54db('0x33');if(_0x382fd4['Attachments']){for(var _0x4b30df=0x0;_0x4b30df<_0x382fd4[_0x54db('0x34')][_0x54db('0x10')];_0x4b30df++){var _0x231cc6=_0x382fd4[_0x54db('0x34')][_0x4b30df];_0x59f05a[_0x54db('0x19')]['attachments'][_0x54db('0x26')]({'filename':_0x231cc6[_0x54db('0x35')],'content':new Buffer(_0x231cc6[_0x54db('0x36')])});}}}_0x493a81(parseEmail(_0x14275e,_0x463b4f,_0x59f05a));});}else{_0x463b4f['html']='<p>Empty\x20message</p>';_0x493a81(parseEmail(_0x14275e,_0x463b4f,_0x59f05a));}}else{_0x493a81(parseEmail(_0x14275e,_0x463b4f,_0x59f05a));}};exports['getHost']=function(_0x33e28f){switch(_0x33e28f){case _0x54db('0x37'):return'imap.gmail.com';case _0x54db('0x38'):return'imap.mail.yahoo.com';case _0x54db('0x39'):return'imap-mail.outlook.com';case _0x54db('0x3a'):return'outlook.office365.com';}return _0x54db('0x3b');};
\ No newline at end of file
+var _0x921d=['attach','type','attachment','format','%s-%s','now','root','server/files/attachments/','writeFileSync','content','contentType','headerLines','X-Auto-Response-Suppress:\x20All','Precedence:\x20auto_reply','line','isAutoreply','parser','from','messageId','inReplyTo','date','filter','application/ms-tnef','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','parseBuffer','first','BodyHTML','Attachments','<p>Empty\x20message</p>','generateXOAuth2Token','auth=Bearer\x20','utf-8','base64','randomstring','util','node-tnef','../../../config/logger','email','../../../config/environment','value','address','anonymous','generate','@xcally.com','head','name','substring','indexOf','split','length','slice','join','Anonymous','isEmpty','html','test','includes','<img','attachments','forEach','push','filename','replace','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','body','textAsHtml','message','originTo','originCc','bcc'];(function(_0x3e3663,_0x4712be){var _0xc20576=function(_0x53ec5c){while(--_0x53ec5c){_0x3e3663['push'](_0x3e3663['shift']());}};_0xc20576(++_0x4712be);}(_0x921d,0x1de));var _0xd921=function(_0x2c46ba,_0x51febd){_0x2c46ba=_0x2c46ba-0x0;var _0x1aa617=_0x921d[_0x2c46ba];return _0x1aa617;};'use strict';var _=require('lodash');var moment=require('moment');var random=require(_0xd921('0x0'));var fs=require('fs');var path=require('path');var util=require(_0xd921('0x1'));var tnef=require(_0xd921('0x2'));var logger=require(_0xd921('0x3'))(_0xd921('0x4'));var config=require(_0xd921('0x5'));function getAddress(_0xb2ad0f){var _0x302f47=_['head'](_0xb2ad0f[_0xd921('0x6')]);return _0x302f47&&_0x302f47[_0xd921('0x7')]?_0x302f47[_0xd921('0x7')]:_0xd921('0x8')+random[_0xd921('0x9')](0x6)+_0xd921('0xa');}function getFirstName(_0x34c1b9){var _0x4aca1f=_[_0xd921('0xb')](_0x34c1b9[_0xd921('0x6')]);if(_0x4aca1f&&_0x4aca1f[_0xd921('0xc')]){if(_0x4aca1f[_0xd921('0xc')]==_0x4aca1f[_0xd921('0x7')]){return _0x4aca1f[_0xd921('0xc')][_0xd921('0xd')](0x0,_0x4aca1f['name'][_0xd921('0xe')]('@'));}var _0x2d921f=_0x4aca1f[_0xd921('0xc')][_0xd921('0xf')](/\s+/);return _0x2d921f[_0xd921('0x10')]>0x1?_0x2d921f[_0xd921('0x11')](0x0,-0x1)[_0xd921('0x12')]('\x20'):_0x4aca1f[_0xd921('0xc')];}return _0xd921('0x13');}function getLastName(_0x44d4df){var _0x261fea=_[_0xd921('0xb')](_0x44d4df['value']);if(_0x261fea&&_0x261fea[_0xd921('0xc')]){var _0x1f79f0=_0x261fea[_0xd921('0xc')][_0xd921('0xf')](/\s+/);return _0x1f79f0['length']>0x1?_0x1f79f0['pop']():'';}return'';}function getMails(_0x16438c,_0x2af8b2){var _0x43abd9='';for(var _0x66ee00=0x0;_0x66ee00<_0x2af8b2[_0xd921('0x6')][_0xd921('0x10')];_0x66ee00+=0x1){if(_0x2af8b2['value'][_0x66ee00][_0xd921('0x7')]!==_0x16438c){if(!_[_0xd921('0x14')](_0x43abd9)){_0x43abd9+=',';}_0x43abd9+=_0x2af8b2[_0xd921('0x6')][_0x66ee00][_0xd921('0xc')]||_0x2af8b2[_0xd921('0x6')][_0x66ee00]['address']||'';_0x43abd9+='\x20<';_0x43abd9+=_0x2af8b2[_0xd921('0x6')][_0x66ee00][_0xd921('0x7')]?_0x2af8b2[_0xd921('0x6')][_0x66ee00][_0xd921('0x7')]:_0xd921('0x8')+random[_0xd921('0x9')](0x6)+_0xd921('0xa');_0x43abd9+='>';}}return _0x43abd9;}function parseEmail(_0x480a60,_0x146b9d,_0x1d1922){if(_0x146b9d[_0xd921('0x15')]){var _0x31f1de=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x31f1de[_0xd921('0x16')](_0x146b9d[_0xd921('0x15')])){_0x146b9d[_0xd921('0x15')]=_0x146b9d['html']['replace'](_0x31f1de,'');}if(_0x146b9d[_0xd921('0x15')][_0xd921('0x17')](_0xd921('0x18'))){var _0x30e8ea=[];_0x146b9d[_0xd921('0x19')][_0xd921('0x1a')](_0x57ebc6=>{_0x30e8ea[_0xd921('0x1b')](_0x57ebc6[_0xd921('0x1c')]);});var _0x1ba9fa=/<img.*? _SRC(.*?)[^>]+>/g;var _0x56b4f4=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x54f5c=_0x146b9d[_0xd921('0x15')][_0xd921('0x1d')](_0x56b4f4,_0xd921('0x1e'));var _0x4a93ea=_0x54f5c[_0xd921('0x1d')](_0x1ba9fa,_0xd921('0x1f'));for(let _0x1ae8d5=0x0;_0x1ae8d5<_0x30e8ea[_0xd921('0x10')];_0x1ae8d5++){var _0x3b85fc=_0x4a93ea[_0xd921('0x1d')]('_IMG',_0xd921('0x20')+_0x30e8ea[_0x1ae8d5]+_0xd921('0x21'));_0x4a93ea=_0x3b85fc;}_0x146b9d[_0xd921('0x15')]=_0x4a93ea;}_0x1d1922[_0xd921('0x22')]=_0x146b9d['html'];}else{_0x1d1922['body']=_0x146b9d[_0xd921('0x23')];}if(_0x1d1922[_0xd921('0x22')]){_0x1d1922[_0xd921('0x22')]=_0x1d1922[_0xd921('0x22')]['replace'](/<a\s+/gi,'<a\x20target=\x22_blank\x22\x20');}if(_0x146b9d['to']){_0x1d1922[_0xd921('0x24')][_0xd921('0x25')]=getMails(null,_0x146b9d['to']);var _0x8ba1bc=getMails(_0x480a60[_0xd921('0x4')],_0x146b9d['to']);if(!_['isEmpty'](_0x8ba1bc)){_0x1d1922['message']['cc']+=_0x8ba1bc;}}if(_0x146b9d['cc']){_0x1d1922[_0xd921('0x24')][_0xd921('0x26')]=getMails(null,_0x146b9d['cc']);var _0x3d29c6=getMails(_0x480a60[_0xd921('0x4')],_0x146b9d['cc']);if(!_[_0xd921('0x14')](_0x3d29c6)){if(!_[_0xd921('0x14')](_0x1d1922[_0xd921('0x24')]['cc'])){_0x1d1922[_0xd921('0x24')]['cc']+=',';}_0x1d1922[_0xd921('0x24')]['cc']+=_0x3d29c6;}}if(!_[_0xd921('0x17')](_0x1d1922[_0xd921('0x24')][_0xd921('0x25')],_0x480a60[_0xd921('0x4')])&&!_['includes'](_0x1d1922[_0xd921('0x24')]['originCc'],_0x480a60[_0xd921('0x4')])){_0x1d1922[_0xd921('0x24')][_0xd921('0x27')]=_0x480a60['email'];}if(_0x146b9d[_0xd921('0x19')]&&_0x146b9d['attachments'][_0xd921('0x10')]){_0x1d1922[_0xd921('0x24')][_0xd921('0x28')]=_0x146b9d[_0xd921('0x19')]['length'];for(var _0x2d2ea6=0x0,_0x223bf8,_0x56ed41,_0x24945d;_0x2d2ea6<_0x146b9d[_0xd921('0x19')]['length'];_0x2d2ea6+=0x1){if(_0x146b9d[_0xd921('0x19')][_0x2d2ea6][_0xd921('0x29')]===_0xd921('0x2a')){_0x24945d=_0x146b9d[_0xd921('0x19')][_0x2d2ea6][_0xd921('0x1c')]||'attachment-'+_0x2d2ea6;_0x223bf8=util[_0xd921('0x2b')](_0xd921('0x2c'),Date[_0xd921('0x2d')](),_0x24945d);_0x56ed41=path[_0xd921('0x12')](config[_0xd921('0x2e')],_0xd921('0x2f'),_0x223bf8);fs[_0xd921('0x30')](_0x56ed41,_0x146b9d[_0xd921('0x19')][_0x2d2ea6][_0xd921('0x31')]);_0x1d1922['message']['attachments'][_0xd921('0x1b')]({'name':_0x24945d,'basename':_0x223bf8,'type':_0x146b9d[_0xd921('0x19')][_0x2d2ea6][_0xd921('0x32')],'filepath':_0x56ed41});}}}if(_0x146b9d[_0xd921('0x33')]&&_0x146b9d[_0xd921('0x33')]['length']>0x0){var _0x2e1e94=['Auto-Submitted:\x20auto-replied',_0xd921('0x34'),_0xd921('0x35')];for(var _0x506059=0x0;_0x506059<_0x146b9d[_0xd921('0x33')][_0xd921('0x10')];_0x506059++){var _0x395db8=_[_0xd921('0xe')](_0x2e1e94,_0x146b9d[_0xd921('0x33')][_0x506059][_0xd921('0x36')]);if(_0x395db8>=0x0){_0x1d1922[_0xd921('0x37')]=!![];}}}return _0x1d1922;}exports[_0xd921('0x38')]=function(_0x4e9b1a,_0x3270d6,_0x5a48d3){var _0x9d12ea={'from':getAddress(_0x3270d6[_0xd921('0x39')]),'firstName':getFirstName(_0x3270d6[_0xd921('0x39')]),'lastName':getLastName(_0x3270d6[_0xd921('0x39')]),'mapKey':_0xd921('0x4'),'message':{'from':getMails(_0x4e9b1a[_0xd921('0x4')],_0x3270d6[_0xd921('0x39')]),'to':_0x4e9b1a[_0xd921('0x4')],'cc':'','subject':_0x3270d6['subject']||'','messageId':_0x3270d6[_0xd921('0x3a')],'inReplyTo':_0x3270d6[_0xd921('0x3b')],'sentAt':moment(_0x3270d6[_0xd921('0x3c')])[_0xd921('0x2b')]('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x3270d6[_0xd921('0x15')]&&!_0x3270d6[_0xd921('0x23')]){var _0x1e8d6f=_[_0xd921('0x3d')](_0x3270d6[_0xd921('0x19')],{'contentType':_0xd921('0x3e')});if(_0x1e8d6f['length']){logger[_0xd921('0x3f')](util['format'](_0xd921('0x40'),_0x3270d6['messageId']));tnef[_0xd921('0x41')](_[_0xd921('0x42')](_0x1e8d6f)[_0xd921('0x31')],function(_0x6e86e7,_0x2e7f4f){if(_0x2e7f4f){_0x3270d6[_0xd921('0x15')]=_0x2e7f4f[_0xd921('0x43')]||'<p>Empty\x20message</p>';if(_0x2e7f4f['Attachments']){for(var _0x284f83=0x0;_0x284f83<_0x2e7f4f[_0xd921('0x44')][_0xd921('0x10')];_0x284f83++){var _0x499d1d=_0x2e7f4f['Attachments'][_0x284f83];_0x9d12ea['message'][_0xd921('0x19')]['push']({'filename':_0x499d1d['Title'],'content':Buffer[_0xd921('0x39')](_0x499d1d['Data'])});}}}_0x5a48d3(parseEmail(_0x4e9b1a,_0x3270d6,_0x9d12ea));});}else{_0x3270d6[_0xd921('0x15')]=_0xd921('0x45');_0x5a48d3(parseEmail(_0x4e9b1a,_0x3270d6,_0x9d12ea));}}else{_0x5a48d3(parseEmail(_0x4e9b1a,_0x3270d6,_0x9d12ea));}};exports[_0xd921('0x46')]=function(_0x423948,_0xc1815e){var _0x2902a7=['user='+(_0xc1815e||''),_0xd921('0x47')+_0x423948,'',''];return Buffer[_0xd921('0x39')](_0x2902a7[_0xd921('0x12')]('\ 1'),_0xd921('0x48'))['toString'](_0xd921('0x49'));};
\ No newline at end of file