Built motion from commit 85328c08.|2.5.50
[motion2.git] / server / services / email / lib / utils.js
index 5ff9eab..2fcf108 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xaf8b=['anonymous','generate','@xcally.com','head','value','name','split','length','slice','join','Anonymous','address','isEmpty','html','test','replace','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','message','originTo','originCc','bcc','attachments','attach','attachment','filename','attachment-','format','%s-%s','now','server/files/attachments/','writeFileSync','content','push','contentType','parser','from','subject','messageId','inReplyTo','YYYY-MM-DD\x20HH:mm:ss','filter','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','first','BodyHTML','Attachments','Title','Data','<p>Empty\x20message</p>','gmail','imap.gmail.com','yahoo','outlook365','outlook.office365.com','127.0.0.1','moment','randomstring','path','util','node-tnef','../../../config/logger','email','../../../config/environment'];(function(_0x443697,_0x438d17){var _0x36f6d2=function(_0x6eaa91){while(--_0x6eaa91){_0x443697['push'](_0x443697['shift']());}};_0x36f6d2(++_0x438d17);}(_0xaf8b,0x13d));var _0xbaf8=function(_0x436c67,_0x1a7db2){_0x436c67=_0x436c67-0x0;var _0x2745dd=_0xaf8b[_0x436c67];return _0x2745dd;};'use strict';var _=require('lodash');var moment=require(_0xbaf8('0x0'));var random=require(_0xbaf8('0x1'));var fs=require('fs');var path=require(_0xbaf8('0x2'));var util=require(_0xbaf8('0x3'));var tnef=require(_0xbaf8('0x4'));var logger=require(_0xbaf8('0x5'))(_0xbaf8('0x6'));var config=require(_0xbaf8('0x7'));function getAddress(_0x5a2cf6){var _0x28bc0e=_['head'](_0x5a2cf6['value']);return _0x28bc0e&&_0x28bc0e['address']?_0x28bc0e['address']:_0xbaf8('0x8')+random[_0xbaf8('0x9')](0x6)+_0xbaf8('0xa');}function getFirstName(_0x279a48){var _0x3ea8d9=_[_0xbaf8('0xb')](_0x279a48[_0xbaf8('0xc')]);if(_0x3ea8d9&&_0x3ea8d9[_0xbaf8('0xd')]){var _0xe2be8e=_0x3ea8d9['name'][_0xbaf8('0xe')](/\s+/);return _0xe2be8e[_0xbaf8('0xf')]?_0xe2be8e[_0xbaf8('0x10')](0x0,-0x1)[_0xbaf8('0x11')]('\x20'):_0x3ea8d9[_0xbaf8('0xd')];}return _0xbaf8('0x12');}function getLastName(_0x281fdb){var _0x4b94ba=_[_0xbaf8('0xb')](_0x281fdb[_0xbaf8('0xc')]);if(_0x4b94ba&&_0x4b94ba[_0xbaf8('0xd')]){var _0x17ab9a=_0x4b94ba['name'][_0xbaf8('0xe')](/\s+/);return _0x17ab9a[_0xbaf8('0xf')]>0x1?_0x17ab9a['pop']():'';}return'';}function getMails(_0x728285,_0x3892f3){var _0x41d63e='';for(var _0x334115=0x0;_0x334115<_0x3892f3[_0xbaf8('0xc')]['length'];_0x334115+=0x1){if(_0x3892f3[_0xbaf8('0xc')][_0x334115][_0xbaf8('0x13')]!==_0x728285){if(!_[_0xbaf8('0x14')](_0x41d63e)){_0x41d63e+=',';}_0x41d63e+=_0x3892f3[_0xbaf8('0xc')][_0x334115][_0xbaf8('0xd')]||_0x3892f3[_0xbaf8('0xc')][_0x334115][_0xbaf8('0x13')]||'';_0x41d63e+='\x20<';_0x41d63e+=_0x3892f3[_0xbaf8('0xc')][_0x334115][_0xbaf8('0x13')]?_0x3892f3[_0xbaf8('0xc')][_0x334115][_0xbaf8('0x13')]:_0xbaf8('0x8')+random[_0xbaf8('0x9')](0x6)+_0xbaf8('0xa');_0x41d63e+='>';}}return _0x41d63e;}function parseEmail(_0x22b5d2,_0x2433a0,_0x449f92){if(_0x2433a0[_0xbaf8('0x15')]){var _0x3aa9fb=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x3aa9fb[_0xbaf8('0x16')](_0x2433a0[_0xbaf8('0x15')])){_0x2433a0['html']=_0x2433a0[_0xbaf8('0x15')][_0xbaf8('0x17')](_0x3aa9fb,'');}_0x449f92[_0xbaf8('0x18')]=_0x2433a0[_0xbaf8('0x15')];}else{_0x449f92[_0xbaf8('0x18')]=_0x2433a0[_0xbaf8('0x19')];}if(_0x449f92['body']){_0x449f92[_0xbaf8('0x18')]=_0x449f92[_0xbaf8('0x18')][_0xbaf8('0x17')](/<a\s+/gi,_0xbaf8('0x1a'));}if(_0x2433a0['to']){_0x449f92[_0xbaf8('0x1b')][_0xbaf8('0x1c')]=getMails(null,_0x2433a0['to']);var _0x14626a=getMails(_0x22b5d2[_0xbaf8('0x6')],_0x2433a0['to']);if(!_['isEmpty'](_0x14626a)){_0x449f92[_0xbaf8('0x1b')]['cc']+=_0x14626a;}}if(_0x2433a0['cc']){_0x449f92['message'][_0xbaf8('0x1d')]=getMails(null,_0x2433a0['cc']);var _0x59d774=getMails(_0x22b5d2[_0xbaf8('0x6')],_0x2433a0['cc']);if(!_['isEmpty'](_0x59d774)){if(!_[_0xbaf8('0x14')](_0x449f92[_0xbaf8('0x1b')]['cc'])){_0x449f92[_0xbaf8('0x1b')]['cc']+=',';}_0x449f92[_0xbaf8('0x1b')]['cc']+=_0x59d774;}}if(!_['includes'](_0x449f92[_0xbaf8('0x1b')][_0xbaf8('0x1c')],_0x22b5d2[_0xbaf8('0x6')])&&!_['includes'](_0x449f92[_0xbaf8('0x1b')][_0xbaf8('0x1d')],_0x22b5d2['email'])){_0x449f92[_0xbaf8('0x1b')][_0xbaf8('0x1e')]=_0x22b5d2['email'];}if(_0x2433a0[_0xbaf8('0x1f')]&&_0x2433a0[_0xbaf8('0x1f')]['length']){_0x449f92[_0xbaf8('0x1b')][_0xbaf8('0x20')]=_0x2433a0[_0xbaf8('0x1f')][_0xbaf8('0xf')];for(var _0x20364c=0x0,_0x10e3be,_0xfe0270,_0x155147;_0x20364c<_0x2433a0['attachments'][_0xbaf8('0xf')];_0x20364c+=0x1){if(_0x2433a0['attachments'][_0x20364c]['type']===_0xbaf8('0x21')){_0x155147=_0x2433a0['attachments'][_0x20364c][_0xbaf8('0x22')]||_0xbaf8('0x23')+_0x20364c;_0x10e3be=util[_0xbaf8('0x24')](_0xbaf8('0x25'),Date[_0xbaf8('0x26')](),_0x155147);_0xfe0270=path[_0xbaf8('0x11')](config['root'],_0xbaf8('0x27'),_0x10e3be);fs[_0xbaf8('0x28')](_0xfe0270,_0x2433a0['attachments'][_0x20364c][_0xbaf8('0x29')]);_0x449f92[_0xbaf8('0x1b')][_0xbaf8('0x1f')][_0xbaf8('0x2a')]({'name':_0x155147,'basename':_0x10e3be,'type':_0x2433a0['attachments'][_0x20364c][_0xbaf8('0x2b')],'filepath':_0xfe0270});}}}return _0x449f92;}exports[_0xbaf8('0x2c')]=function(_0x43bf4e,_0x5a5b30,_0x4e6798){var _0x16a48b={'from':getAddress(_0x5a5b30[_0xbaf8('0x2d')]),'firstName':getFirstName(_0x5a5b30[_0xbaf8('0x2d')]),'lastName':getLastName(_0x5a5b30[_0xbaf8('0x2d')]),'mapKey':'email','message':{'from':getMails(_0x43bf4e[_0xbaf8('0x6')],_0x5a5b30[_0xbaf8('0x2d')]),'to':_0x43bf4e[_0xbaf8('0x6')],'cc':'','subject':_0x5a5b30[_0xbaf8('0x2e')]||'','messageId':_0x5a5b30[_0xbaf8('0x2f')],'inReplyTo':_0x5a5b30[_0xbaf8('0x30')],'sentAt':moment(_0x5a5b30['date'])[_0xbaf8('0x24')](_0xbaf8('0x31')),'attach':![],'attachments':[]}};if(!_0x5a5b30[_0xbaf8('0x15')]&&!_0x5a5b30[_0xbaf8('0x19')]){var _0x414cde=_[_0xbaf8('0x32')](_0x5a5b30[_0xbaf8('0x1f')],{'contentType':'application/ms-tnef'});if(_0x414cde['length']){logger[_0xbaf8('0x33')](util[_0xbaf8('0x24')](_0xbaf8('0x34'),_0x5a5b30['messageId']));tnef['parseBuffer'](_[_0xbaf8('0x35')](_0x414cde)['content'],function(_0xbd5aad,_0x414d3c){if(_0x414d3c){_0x5a5b30[_0xbaf8('0x15')]=_0x414d3c[_0xbaf8('0x36')]||'<p>Empty\x20message</p>';if(_0x414d3c[_0xbaf8('0x37')]){for(var _0x3450b1=0x0;_0x3450b1<_0x414d3c[_0xbaf8('0x37')][_0xbaf8('0xf')];_0x3450b1++){var _0x3e6197=_0x414d3c['Attachments'][_0x3450b1];_0x16a48b['message'][_0xbaf8('0x1f')][_0xbaf8('0x2a')]({'filename':_0x3e6197[_0xbaf8('0x38')],'content':new Buffer(_0x3e6197[_0xbaf8('0x39')])});}}}_0x4e6798(parseEmail(_0x43bf4e,_0x5a5b30,_0x16a48b));});}else{_0x5a5b30[_0xbaf8('0x15')]=_0xbaf8('0x3a');_0x4e6798(parseEmail(_0x43bf4e,_0x5a5b30,_0x16a48b));}}else{_0x4e6798(parseEmail(_0x43bf4e,_0x5a5b30,_0x16a48b));}};exports['getHost']=function(_0x6e7330){switch(_0x6e7330){case _0xbaf8('0x3b'):return _0xbaf8('0x3c');case _0xbaf8('0x3d'):return'imap.mail.yahoo.com';case'hotmail':return'imap-mail.outlook.com';case _0xbaf8('0x3e'):return _0xbaf8('0x3f');}return _0xbaf8('0x40');};
\ No newline at end of file
+var _0x3458=['generate','html','<img','attachments','forEach','filename','replace','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','textAsHtml','body','<a\x20target=\x22_blank\x22\x20','message','originTo','includes','originCc','bcc','attach','type','attachment-','format','%s-%s','root','server/files/attachments/','writeFileSync','content','push','contentType','headerLines','Auto-Submitted:\x20auto-replied','X-Auto-Response-Suppress:\x20All','line','isAutoreply','parser','from','subject','inReplyTo','date','filter','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','user=','utf-8','toString','lodash','moment','randomstring','path','util','email','../../../config/environment','value','address','@xcally.com','head','name','indexOf','split','length','slice','join','Anonymous','isEmpty'];(function(_0x48d3ad,_0x290e43){var _0xa60d6e=function(_0x424a3e){while(--_0x424a3e){_0x48d3ad['push'](_0x48d3ad['shift']());}};_0xa60d6e(++_0x290e43);}(_0x3458,0x19d));var _0x8345=function(_0x19f07d,_0x670b92){_0x19f07d=_0x19f07d-0x0;var _0x60f613=_0x3458[_0x19f07d];return _0x60f613;};'use strict';var _=require(_0x8345('0x0'));var moment=require(_0x8345('0x1'));var random=require(_0x8345('0x2'));var fs=require('fs');var path=require(_0x8345('0x3'));var util=require(_0x8345('0x4'));var tnef=require('node-tnef');var logger=require('../../../config/logger')(_0x8345('0x5'));var config=require(_0x8345('0x6'));function getAddress(_0x416f7a){var _0x4d250f=_['head'](_0x416f7a[_0x8345('0x7')]);return _0x4d250f&&_0x4d250f[_0x8345('0x8')]?_0x4d250f[_0x8345('0x8')]:'anonymous'+random['generate'](0x6)+_0x8345('0x9');}function getFirstName(_0x5eea57){var _0x54fca3=_[_0x8345('0xa')](_0x5eea57[_0x8345('0x7')]);if(_0x54fca3&&_0x54fca3[_0x8345('0xb')]){if(_0x54fca3[_0x8345('0xb')]==_0x54fca3[_0x8345('0x8')]){return _0x54fca3['name']['substring'](0x0,_0x54fca3[_0x8345('0xb')][_0x8345('0xc')]('@'));}var _0x13cf4c=_0x54fca3[_0x8345('0xb')][_0x8345('0xd')](/\s+/);return _0x13cf4c[_0x8345('0xe')]>0x1?_0x13cf4c[_0x8345('0xf')](0x0,-0x1)[_0x8345('0x10')]('\x20'):_0x54fca3[_0x8345('0xb')];}return _0x8345('0x11');}function getLastName(_0x43861e){var _0x4e84db=_[_0x8345('0xa')](_0x43861e[_0x8345('0x7')]);if(_0x4e84db&&_0x4e84db[_0x8345('0xb')]){var _0x49c205=_0x4e84db[_0x8345('0xb')]['split'](/\s+/);return _0x49c205['length']>0x1?_0x49c205['pop']():'';}return'';}function getMails(_0x223330,_0x704073){var _0x2a0e1a='';for(var _0x4977e9=0x0;_0x4977e9<_0x704073[_0x8345('0x7')][_0x8345('0xe')];_0x4977e9+=0x1){if(_0x704073[_0x8345('0x7')][_0x4977e9][_0x8345('0x8')]!==_0x223330){if(!_[_0x8345('0x12')](_0x2a0e1a)){_0x2a0e1a+=',';}_0x2a0e1a+=_0x704073['value'][_0x4977e9][_0x8345('0xb')]||_0x704073[_0x8345('0x7')][_0x4977e9][_0x8345('0x8')]||'';_0x2a0e1a+='\x20<';_0x2a0e1a+=_0x704073[_0x8345('0x7')][_0x4977e9][_0x8345('0x8')]?_0x704073[_0x8345('0x7')][_0x4977e9][_0x8345('0x8')]:'anonymous'+random[_0x8345('0x13')](0x6)+_0x8345('0x9');_0x2a0e1a+='>';}}return _0x2a0e1a;}function parseEmail(_0x2c025e,_0x61b172,_0x45e873){if(_0x61b172['html']){var _0x1d931a=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x1d931a['test'](_0x61b172[_0x8345('0x14')])){_0x61b172[_0x8345('0x14')]=_0x61b172[_0x8345('0x14')]['replace'](_0x1d931a,'');}if(_0x61b172[_0x8345('0x14')]['includes'](_0x8345('0x15'))){var _0x479611=[];_0x61b172[_0x8345('0x16')][_0x8345('0x17')](_0x12c2cd=>{_0x479611['push'](_0x12c2cd[_0x8345('0x18')]);});var _0x492f9a=/<img.*? _SRC(.*?)[^>]+>/g;var _0x2f7eef=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x35e73d=_0x61b172[_0x8345('0x14')][_0x8345('0x19')](_0x2f7eef,_0x8345('0x1a'));var _0x1d1da2=_0x35e73d['replace'](_0x492f9a,_0x8345('0x1b'));for(let _0x5604ea=0x0;_0x5604ea<_0x479611['length'];_0x5604ea++){var _0x33697f=_0x1d1da2[_0x8345('0x19')](_0x8345('0x1b'),_0x8345('0x1c')+_0x479611[_0x5604ea]+_0x8345('0x1d'));_0x1d1da2=_0x33697f;}_0x61b172[_0x8345('0x14')]=_0x1d1da2;}_0x45e873['body']=_0x61b172[_0x8345('0x14')];}else{_0x45e873['body']=_0x61b172[_0x8345('0x1e')];}if(_0x45e873['body']){_0x45e873['body']=_0x45e873[_0x8345('0x1f')][_0x8345('0x19')](/<a\s+/gi,_0x8345('0x20'));}if(_0x61b172['to']){_0x45e873[_0x8345('0x21')][_0x8345('0x22')]=getMails(null,_0x61b172['to']);var _0xc3bc72=getMails(_0x2c025e[_0x8345('0x5')],_0x61b172['to']);if(!_[_0x8345('0x12')](_0xc3bc72)){_0x45e873['message']['cc']+=_0xc3bc72;}}if(_0x61b172['cc']){_0x45e873[_0x8345('0x21')]['originCc']=getMails(null,_0x61b172['cc']);var _0xd913a2=getMails(_0x2c025e[_0x8345('0x5')],_0x61b172['cc']);if(!_[_0x8345('0x12')](_0xd913a2)){if(!_['isEmpty'](_0x45e873['message']['cc'])){_0x45e873[_0x8345('0x21')]['cc']+=',';}_0x45e873[_0x8345('0x21')]['cc']+=_0xd913a2;}}if(!_['includes'](_0x45e873[_0x8345('0x21')]['originTo'],_0x2c025e[_0x8345('0x5')])&&!_[_0x8345('0x23')](_0x45e873[_0x8345('0x21')][_0x8345('0x24')],_0x2c025e['email'])){_0x45e873['message'][_0x8345('0x25')]=_0x2c025e[_0x8345('0x5')];}if(_0x61b172['attachments']&&_0x61b172[_0x8345('0x16')]['length']){_0x45e873[_0x8345('0x21')][_0x8345('0x26')]=_0x61b172[_0x8345('0x16')][_0x8345('0xe')];for(var _0x143a6d=0x0,_0x135e1e,_0xeef7f9,_0x569668;_0x143a6d<_0x61b172['attachments'][_0x8345('0xe')];_0x143a6d+=0x1){if(_0x61b172['attachments'][_0x143a6d][_0x8345('0x27')]==='attachment'){_0x569668=_0x61b172[_0x8345('0x16')][_0x143a6d][_0x8345('0x18')]||_0x8345('0x28')+_0x143a6d;_0x135e1e=util[_0x8345('0x29')](_0x8345('0x2a'),Date['now'](),_0x569668);_0xeef7f9=path[_0x8345('0x10')](config[_0x8345('0x2b')],_0x8345('0x2c'),_0x135e1e);fs[_0x8345('0x2d')](_0xeef7f9,_0x61b172[_0x8345('0x16')][_0x143a6d][_0x8345('0x2e')]);_0x45e873[_0x8345('0x21')][_0x8345('0x16')][_0x8345('0x2f')]({'name':_0x569668,'basename':_0x135e1e,'type':_0x61b172[_0x8345('0x16')][_0x143a6d][_0x8345('0x30')],'filepath':_0xeef7f9});}}}if(_0x61b172[_0x8345('0x31')]&&_0x61b172[_0x8345('0x31')][_0x8345('0xe')]>0x0){var _0x7b3e4d=[_0x8345('0x32'),_0x8345('0x33'),'Precedence:\x20auto_reply'];for(var _0x3adc09=0x0;_0x3adc09<_0x61b172[_0x8345('0x31')][_0x8345('0xe')];_0x3adc09++){var _0x1292fa=_[_0x8345('0xc')](_0x7b3e4d,_0x61b172[_0x8345('0x31')][_0x3adc09][_0x8345('0x34')]);if(_0x1292fa>=0x0){_0x45e873[_0x8345('0x35')]=!![];}}}return _0x45e873;}exports[_0x8345('0x36')]=function(_0x54a953,_0x24113a,_0x163984){var _0x3b1499={'from':getAddress(_0x24113a[_0x8345('0x37')]),'firstName':getFirstName(_0x24113a['from']),'lastName':getLastName(_0x24113a[_0x8345('0x37')]),'mapKey':_0x8345('0x5'),'message':{'from':getMails(_0x54a953[_0x8345('0x5')],_0x24113a['from']),'to':_0x54a953[_0x8345('0x5')],'cc':'','subject':_0x24113a[_0x8345('0x38')]||'','messageId':_0x24113a['messageId'],'inReplyTo':_0x24113a[_0x8345('0x39')],'sentAt':moment(_0x24113a[_0x8345('0x3a')])[_0x8345('0x29')]('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x24113a[_0x8345('0x14')]&&!_0x24113a['textAsHtml']){var _0x40ee54=_[_0x8345('0x3b')](_0x24113a[_0x8345('0x16')],{'contentType':'application/ms-tnef'});if(_0x40ee54[_0x8345('0xe')]){logger['info'](util[_0x8345('0x29')](_0x8345('0x3c'),_0x24113a[_0x8345('0x3d')]));tnef[_0x8345('0x3e')](_[_0x8345('0x3f')](_0x40ee54)['content'],function(_0x5382d0,_0x1f08fd){if(_0x1f08fd){_0x24113a[_0x8345('0x14')]=_0x1f08fd[_0x8345('0x40')]||_0x8345('0x41');if(_0x1f08fd[_0x8345('0x42')]){for(var _0x282858=0x0;_0x282858<_0x1f08fd[_0x8345('0x42')][_0x8345('0xe')];_0x282858++){var _0x5cbdb0=_0x1f08fd[_0x8345('0x42')][_0x282858];_0x3b1499[_0x8345('0x21')][_0x8345('0x16')]['push']({'filename':_0x5cbdb0[_0x8345('0x43')],'content':Buffer[_0x8345('0x37')](_0x5cbdb0[_0x8345('0x44')])});}}}_0x163984(parseEmail(_0x54a953,_0x24113a,_0x3b1499));});}else{_0x24113a[_0x8345('0x14')]=_0x8345('0x41');_0x163984(parseEmail(_0x54a953,_0x24113a,_0x3b1499));}}else{_0x163984(parseEmail(_0x54a953,_0x24113a,_0x3b1499));}};exports['generateXOAuth2Token']=function(_0x486f7b,_0x35f99d){var _0x435e12=[_0x8345('0x45')+(_0x35f99d||''),'auth=Bearer\x20'+_0x486f7b,'',''];return Buffer[_0x8345('0x37')](_0x435e12[_0x8345('0x10')]('\ 1'),_0x8345('0x46'))[_0x8345('0x47')]('base64');};
\ No newline at end of file