Built motion from commit 9d7072cc.|2.5.39
[motion2.git] / server / services / email / lib / utils.js
index 5ff9eab..0e552ce 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 _0x1bb4=['value','address','generate','@xcally.com','head','name','substring','split','length','slice','join','Anonymous','pop','anonymous','html','replace','<img','attachments','push','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','message','originTo','email','isEmpty','includes','originCc','bcc','attach','type','attachment','filename','now','root','server/files/attachments/','content','headerLines','Auto-Submitted:\x20auto-replied','X-Auto-Response-Suppress:\x20All','Precedence:\x20auto_reply','indexOf','line','isAutoreply','parser','from','subject','messageId','date','format','YYYY-MM-DD\x20HH:mm:ss','filter','application/ms-tnef','parseBuffer','first','BodyHTML','<p>Empty\x20message</p>','Attachments','Data','getHost','gmail','imap.gmail.com','imap.mail.yahoo.com','hotmail','imap-mail.outlook.com','outlook.office365.com','lodash','moment','randomstring','path','util','../../../config/logger','../../../config/environment'];(function(_0x2dafbe,_0x5d04de){var _0x58a45a=function(_0x50ac96){while(--_0x50ac96){_0x2dafbe['push'](_0x2dafbe['shift']());}};_0x58a45a(++_0x5d04de);}(_0x1bb4,0x1c7));var _0x41bb=function(_0x3fece8,_0x33ceab){_0x3fece8=_0x3fece8-0x0;var _0x30ce84=_0x1bb4[_0x3fece8];return _0x30ce84;};'use strict';var _=require(_0x41bb('0x0'));var moment=require(_0x41bb('0x1'));var random=require(_0x41bb('0x2'));var fs=require('fs');var path=require(_0x41bb('0x3'));var util=require(_0x41bb('0x4'));var tnef=require('node-tnef');var logger=require(_0x41bb('0x5'))('email');var config=require(_0x41bb('0x6'));function getAddress(_0x5a5b83){var _0xf2cea6=_['head'](_0x5a5b83[_0x41bb('0x7')]);return _0xf2cea6&&_0xf2cea6[_0x41bb('0x8')]?_0xf2cea6[_0x41bb('0x8')]:'anonymous'+random[_0x41bb('0x9')](0x6)+_0x41bb('0xa');}function getFirstName(_0x4af8b1){var _0x22092e=_[_0x41bb('0xb')](_0x4af8b1[_0x41bb('0x7')]);if(_0x22092e&&_0x22092e['name']){if(_0x22092e[_0x41bb('0xc')]==_0x22092e[_0x41bb('0x8')]){return _0x22092e[_0x41bb('0xc')][_0x41bb('0xd')](0x0,_0x22092e[_0x41bb('0xc')]['indexOf']('@'));}var _0x78af1d=_0x22092e[_0x41bb('0xc')][_0x41bb('0xe')](/\s+/);return _0x78af1d[_0x41bb('0xf')]>0x1?_0x78af1d[_0x41bb('0x10')](0x0,-0x1)[_0x41bb('0x11')]('\x20'):_0x22092e[_0x41bb('0xc')];}return _0x41bb('0x12');}function getLastName(_0x485296){var _0x49d246=_['head'](_0x485296[_0x41bb('0x7')]);if(_0x49d246&&_0x49d246[_0x41bb('0xc')]){var _0xf1a18f=_0x49d246['name']['split'](/\s+/);return _0xf1a18f[_0x41bb('0xf')]>0x1?_0xf1a18f[_0x41bb('0x13')]():'';}return'';}function getMails(_0xfa8f14,_0x2b3dbd){var _0x358246='';for(var _0x4a1687=0x0;_0x4a1687<_0x2b3dbd[_0x41bb('0x7')]['length'];_0x4a1687+=0x1){if(_0x2b3dbd[_0x41bb('0x7')][_0x4a1687][_0x41bb('0x8')]!==_0xfa8f14){if(!_['isEmpty'](_0x358246)){_0x358246+=',';}_0x358246+=_0x2b3dbd[_0x41bb('0x7')][_0x4a1687][_0x41bb('0xc')]||_0x2b3dbd['value'][_0x4a1687]['address']||'';_0x358246+='\x20<';_0x358246+=_0x2b3dbd[_0x41bb('0x7')][_0x4a1687]['address']?_0x2b3dbd[_0x41bb('0x7')][_0x4a1687][_0x41bb('0x8')]:_0x41bb('0x14')+random[_0x41bb('0x9')](0x6)+_0x41bb('0xa');_0x358246+='>';}}return _0x358246;}function parseEmail(_0xfa64ee,_0x44d02d,_0x46994f){if(_0x44d02d[_0x41bb('0x15')]){var _0x407480=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x407480['test'](_0x44d02d[_0x41bb('0x15')])){_0x44d02d[_0x41bb('0x15')]=_0x44d02d[_0x41bb('0x15')][_0x41bb('0x16')](_0x407480,'');}if(_0x44d02d['html']['includes'](_0x41bb('0x17'))){var _0x1d4909=[];_0x44d02d[_0x41bb('0x18')]['forEach'](_0x7f614=>{_0x1d4909[_0x41bb('0x19')](_0x7f614['filename']);});var _0x310f09=/<img.*? _SRC(.*?)[^>]+>/g;var _0x5c09bf=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x20ebe6=_0x44d02d[_0x41bb('0x15')][_0x41bb('0x16')](_0x5c09bf,_0x41bb('0x1a'));var _0x3d515e=_0x20ebe6[_0x41bb('0x16')](_0x310f09,_0x41bb('0x1b'));for(let _0x252a99=0x0;_0x252a99<_0x1d4909[_0x41bb('0xf')];_0x252a99++){var _0x2ba1cd=_0x3d515e[_0x41bb('0x16')](_0x41bb('0x1b'),_0x41bb('0x1c')+_0x1d4909[_0x252a99]+_0x41bb('0x1d'));_0x3d515e=_0x2ba1cd;}_0x44d02d['html']=_0x3d515e;}_0x46994f[_0x41bb('0x1e')]=_0x44d02d[_0x41bb('0x15')];}else{_0x46994f[_0x41bb('0x1e')]=_0x44d02d[_0x41bb('0x1f')];}if(_0x46994f[_0x41bb('0x1e')]){_0x46994f[_0x41bb('0x1e')]=_0x46994f[_0x41bb('0x1e')][_0x41bb('0x16')](/<a\s+/gi,_0x41bb('0x20'));}if(_0x44d02d['to']){_0x46994f[_0x41bb('0x21')][_0x41bb('0x22')]=getMails(null,_0x44d02d['to']);var _0x7c3a3c=getMails(_0xfa64ee[_0x41bb('0x23')],_0x44d02d['to']);if(!_[_0x41bb('0x24')](_0x7c3a3c)){_0x46994f[_0x41bb('0x21')]['cc']+=_0x7c3a3c;}}if(_0x44d02d['cc']){_0x46994f[_0x41bb('0x21')]['originCc']=getMails(null,_0x44d02d['cc']);var _0x3fd905=getMails(_0xfa64ee[_0x41bb('0x23')],_0x44d02d['cc']);if(!_[_0x41bb('0x24')](_0x3fd905)){if(!_[_0x41bb('0x24')](_0x46994f[_0x41bb('0x21')]['cc'])){_0x46994f[_0x41bb('0x21')]['cc']+=',';}_0x46994f[_0x41bb('0x21')]['cc']+=_0x3fd905;}}if(!_['includes'](_0x46994f['message'][_0x41bb('0x22')],_0xfa64ee[_0x41bb('0x23')])&&!_[_0x41bb('0x25')](_0x46994f[_0x41bb('0x21')][_0x41bb('0x26')],_0xfa64ee[_0x41bb('0x23')])){_0x46994f[_0x41bb('0x21')][_0x41bb('0x27')]=_0xfa64ee['email'];}if(_0x44d02d['attachments']&&_0x44d02d['attachments'][_0x41bb('0xf')]){_0x46994f[_0x41bb('0x21')][_0x41bb('0x28')]=_0x44d02d[_0x41bb('0x18')][_0x41bb('0xf')];for(var _0x5b130a=0x0,_0x233fa2,_0x2293c7,_0x463fd0;_0x5b130a<_0x44d02d[_0x41bb('0x18')][_0x41bb('0xf')];_0x5b130a+=0x1){if(_0x44d02d[_0x41bb('0x18')][_0x5b130a][_0x41bb('0x29')]===_0x41bb('0x2a')){_0x463fd0=_0x44d02d[_0x41bb('0x18')][_0x5b130a][_0x41bb('0x2b')]||'attachment-'+_0x5b130a;_0x233fa2=util['format']('%s-%s',Date[_0x41bb('0x2c')](),_0x463fd0);_0x2293c7=path[_0x41bb('0x11')](config[_0x41bb('0x2d')],_0x41bb('0x2e'),_0x233fa2);fs['writeFileSync'](_0x2293c7,_0x44d02d[_0x41bb('0x18')][_0x5b130a][_0x41bb('0x2f')]);_0x46994f['message']['attachments'][_0x41bb('0x19')]({'name':_0x463fd0,'basename':_0x233fa2,'type':_0x44d02d[_0x41bb('0x18')][_0x5b130a]['contentType'],'filepath':_0x2293c7});}}}if(_0x44d02d[_0x41bb('0x30')]&&_0x44d02d['headerLines'][_0x41bb('0xf')]>0x0){var _0x426ee0=[_0x41bb('0x31'),_0x41bb('0x32'),_0x41bb('0x33')];for(var _0x2199d8=0x0;_0x2199d8<_0x44d02d[_0x41bb('0x30')][_0x41bb('0xf')];_0x2199d8++){var _0x30dbde=_[_0x41bb('0x34')](_0x426ee0,_0x44d02d['headerLines'][_0x2199d8][_0x41bb('0x35')]);if(_0x30dbde>=0x0){_0x46994f[_0x41bb('0x36')]=!![];}}}return _0x46994f;}exports[_0x41bb('0x37')]=function(_0x59ed00,_0x2deafc,_0x20f3c4){var _0x19b4a8={'from':getAddress(_0x2deafc['from']),'firstName':getFirstName(_0x2deafc[_0x41bb('0x38')]),'lastName':getLastName(_0x2deafc[_0x41bb('0x38')]),'mapKey':_0x41bb('0x23'),'message':{'from':getMails(_0x59ed00[_0x41bb('0x23')],_0x2deafc[_0x41bb('0x38')]),'to':_0x59ed00[_0x41bb('0x23')],'cc':'','subject':_0x2deafc[_0x41bb('0x39')]||'','messageId':_0x2deafc[_0x41bb('0x3a')],'inReplyTo':_0x2deafc['inReplyTo'],'sentAt':moment(_0x2deafc[_0x41bb('0x3b')])[_0x41bb('0x3c')](_0x41bb('0x3d')),'attach':![],'attachments':[]}};if(!_0x2deafc['html']&&!_0x2deafc[_0x41bb('0x1f')]){var _0x44a291=_[_0x41bb('0x3e')](_0x2deafc[_0x41bb('0x18')],{'contentType':_0x41bb('0x3f')});if(_0x44a291[_0x41bb('0xf')]){logger['info'](util['format']('Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system',_0x2deafc[_0x41bb('0x3a')]));tnef[_0x41bb('0x40')](_[_0x41bb('0x41')](_0x44a291)['content'],function(_0x595cb5,_0x4cb646){if(_0x4cb646){_0x2deafc[_0x41bb('0x15')]=_0x4cb646[_0x41bb('0x42')]||_0x41bb('0x43');if(_0x4cb646[_0x41bb('0x44')]){for(var _0x69292a=0x0;_0x69292a<_0x4cb646[_0x41bb('0x44')]['length'];_0x69292a++){var _0x2f1557=_0x4cb646[_0x41bb('0x44')][_0x69292a];_0x19b4a8[_0x41bb('0x21')]['attachments']['push']({'filename':_0x2f1557['Title'],'content':Buffer[_0x41bb('0x38')](_0x2f1557[_0x41bb('0x45')])});}}}_0x20f3c4(parseEmail(_0x59ed00,_0x2deafc,_0x19b4a8));});}else{_0x2deafc[_0x41bb('0x15')]=_0x41bb('0x43');_0x20f3c4(parseEmail(_0x59ed00,_0x2deafc,_0x19b4a8));}}else{_0x20f3c4(parseEmail(_0x59ed00,_0x2deafc,_0x19b4a8));}};exports[_0x41bb('0x46')]=function(_0x4a2469){switch(_0x4a2469){case _0x41bb('0x47'):return _0x41bb('0x48');case'yahoo':return _0x41bb('0x49');case _0x41bb('0x4a'):return _0x41bb('0x4b');case'outlook365':return _0x41bb('0x4c');}return'127.0.0.1';};
\ No newline at end of file