Built motion from commit (unavailable).|2.5.28
[motion2.git] / server / services / email / lib / utils.js
index cd91106..e2e5aa2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xb79c=['hotmail','outlook365','outlook.office365.com','127.0.0.1','moment','randomstring','path','node-tnef','../../../config/logger','email','../../../config/environment','value','address','@xcally.com','head','name','length','join','Anonymous','pop','isEmpty','anonymous','html','replace','body','message','originTo','originCc','includes','bcc','attachments','attach','type','attachment','filename','attachment-','%s-%s','server/files/attachments/','writeFileSync','content','push','from','subject','messageId','inReplyTo','format','YYYY-MM-DD\x20HH:mm:ss','textAsHtml','filter','application/ms-tnef','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','BodyHTML','<p>Empty\x20message</p>','Attachments','Title','Data','getHost','imap.gmail.com','imap.mail.yahoo.com'];(function(_0xfa7c81,_0x1ae420){var _0x31c582=function(_0x8c8917){while(--_0x8c8917){_0xfa7c81['push'](_0xfa7c81['shift']());}};_0x31c582(++_0x1ae420);}(_0xb79c,0x1dc));var _0xcb79=function(_0x1ba085,_0x4d584b){_0x1ba085=_0x1ba085-0x0;var _0x154d04=_0xb79c[_0x1ba085];return _0x154d04;};'use strict';var _=require('lodash');var moment=require(_0xcb79('0x0'));var random=require(_0xcb79('0x1'));var fs=require('fs');var path=require(_0xcb79('0x2'));var util=require('util');var tnef=require(_0xcb79('0x3'));var logger=require(_0xcb79('0x4'))(_0xcb79('0x5'));var config=require(_0xcb79('0x6'));function getAddress(_0x2995e4){var _0x48167c=_['head'](_0x2995e4[_0xcb79('0x7')]);return _0x48167c&&_0x48167c[_0xcb79('0x8')]?_0x48167c['address']:'anonymous'+random['generate'](0x6)+_0xcb79('0x9');}function getFirstName(_0x5c91e9){var _0x4dce4e=_[_0xcb79('0xa')](_0x5c91e9[_0xcb79('0x7')]);if(_0x4dce4e&&_0x4dce4e[_0xcb79('0xb')]){var _0x1ccb79=_0x4dce4e['name']['split'](/\s+/);return _0x1ccb79[_0xcb79('0xc')]?_0x1ccb79['slice'](0x0,-0x1)[_0xcb79('0xd')]('\x20'):_0x4dce4e[_0xcb79('0xb')];}return _0xcb79('0xe');}function getLastName(_0x488696){var _0x2f89a8=_[_0xcb79('0xa')](_0x488696[_0xcb79('0x7')]);if(_0x2f89a8&&_0x2f89a8[_0xcb79('0xb')]){var _0x3c13b8=_0x2f89a8[_0xcb79('0xb')]['split'](/\s+/);return _0x3c13b8['length']>0x1?_0x3c13b8[_0xcb79('0xf')]():'';}return'';}function getMails(_0x42e258,_0x35fae0){var _0x404d7b='';for(var _0xe200b7=0x0;_0xe200b7<_0x35fae0[_0xcb79('0x7')][_0xcb79('0xc')];_0xe200b7+=0x1){if(_0x35fae0[_0xcb79('0x7')][_0xe200b7][_0xcb79('0x8')]!==_0x42e258){if(!_[_0xcb79('0x10')](_0x404d7b)){_0x404d7b+=',';}_0x404d7b+=_0x35fae0[_0xcb79('0x7')][_0xe200b7][_0xcb79('0xb')]||_0x35fae0['value'][_0xe200b7][_0xcb79('0x8')]||'';_0x404d7b+='\x20<';_0x404d7b+=_0x35fae0[_0xcb79('0x7')][_0xe200b7][_0xcb79('0x8')]?_0x35fae0[_0xcb79('0x7')][_0xe200b7]['address']:_0xcb79('0x11')+random['generate'](0x6)+_0xcb79('0x9');_0x404d7b+='>';}}return _0x404d7b;}function parseEmail(_0x1adf3d,_0x157cee,_0x37e2dd){if(_0x157cee[_0xcb79('0x12')]){var _0x33063e=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x33063e['test'](_0x157cee[_0xcb79('0x12')])){_0x157cee['html']=_0x157cee['html'][_0xcb79('0x13')](_0x33063e,'');}_0x37e2dd['body']=_0x157cee[_0xcb79('0x12')];}else{_0x37e2dd[_0xcb79('0x14')]=_0x157cee['textAsHtml'];}if(_0x37e2dd['body']){_0x37e2dd['body']=_0x37e2dd[_0xcb79('0x14')]['replace'](/<a\s+/gi,'<a\x20target=\x22_blank\x22\x20');}if(_0x157cee['to']){_0x37e2dd[_0xcb79('0x15')][_0xcb79('0x16')]=getMails(null,_0x157cee['to']);var _0x594fb1=getMails(_0x1adf3d[_0xcb79('0x5')],_0x157cee['to']);if(!_[_0xcb79('0x10')](_0x594fb1)){_0x37e2dd[_0xcb79('0x15')]['cc']+=_0x594fb1;}}if(_0x157cee['cc']){_0x37e2dd[_0xcb79('0x15')][_0xcb79('0x17')]=getMails(null,_0x157cee['cc']);var _0xe9be9c=getMails(_0x1adf3d[_0xcb79('0x5')],_0x157cee['cc']);if(!_['isEmpty'](_0xe9be9c)){if(!_['isEmpty'](_0x37e2dd[_0xcb79('0x15')]['cc'])){_0x37e2dd[_0xcb79('0x15')]['cc']+=',';}_0x37e2dd[_0xcb79('0x15')]['cc']+=_0xe9be9c;}}if(!_['includes'](_0x37e2dd[_0xcb79('0x15')][_0xcb79('0x16')],_0x1adf3d[_0xcb79('0x5')])&&!_[_0xcb79('0x18')](_0x37e2dd[_0xcb79('0x15')]['originCc'],_0x1adf3d[_0xcb79('0x5')])){_0x37e2dd[_0xcb79('0x15')][_0xcb79('0x19')]=_0x1adf3d[_0xcb79('0x5')];}if(_0x157cee[_0xcb79('0x1a')]&&_0x157cee[_0xcb79('0x1a')][_0xcb79('0xc')]){_0x37e2dd[_0xcb79('0x15')][_0xcb79('0x1b')]=_0x157cee[_0xcb79('0x1a')][_0xcb79('0xc')];for(var _0x28196d=0x0,_0x962a2b,_0x9bb8fd,_0x219819;_0x28196d<_0x157cee['attachments'][_0xcb79('0xc')];_0x28196d+=0x1){if(_0x157cee[_0xcb79('0x1a')][_0x28196d][_0xcb79('0x1c')]===_0xcb79('0x1d')){_0x219819=_0x157cee['attachments'][_0x28196d][_0xcb79('0x1e')]||_0xcb79('0x1f')+_0x28196d;_0x962a2b=util['format'](_0xcb79('0x20'),Date['now'](),_0x219819);_0x9bb8fd=path[_0xcb79('0xd')](config['root'],_0xcb79('0x21'),_0x962a2b);fs[_0xcb79('0x22')](_0x9bb8fd,_0x157cee[_0xcb79('0x1a')][_0x28196d][_0xcb79('0x23')]);_0x37e2dd['message'][_0xcb79('0x1a')][_0xcb79('0x24')]({'name':_0x219819,'basename':_0x962a2b,'type':_0x157cee['attachments'][_0x28196d]['contentType'],'filepath':_0x9bb8fd});}}}return _0x37e2dd;}exports['parser']=function(_0x168032,_0x5752f4,_0x5a9397){var _0x5dadc2={'from':getAddress(_0x5752f4[_0xcb79('0x25')]),'firstName':getFirstName(_0x5752f4[_0xcb79('0x25')]),'lastName':getLastName(_0x5752f4[_0xcb79('0x25')]),'mapKey':_0xcb79('0x5'),'message':{'from':getMails(_0x168032[_0xcb79('0x5')],_0x5752f4[_0xcb79('0x25')]),'to':_0x168032['email'],'cc':'','subject':_0x5752f4[_0xcb79('0x26')]||'','messageId':_0x5752f4[_0xcb79('0x27')],'inReplyTo':_0x5752f4[_0xcb79('0x28')],'sentAt':moment(_0x5752f4['date'])[_0xcb79('0x29')](_0xcb79('0x2a')),'attach':![],'attachments':[]}};if(!_0x5752f4[_0xcb79('0x12')]&&!_0x5752f4[_0xcb79('0x2b')]){var _0x52d55d=_[_0xcb79('0x2c')](_0x5752f4[_0xcb79('0x1a')],{'contentType':_0xcb79('0x2d')});if(_0x52d55d[_0xcb79('0xc')]){logger['info'](util[_0xcb79('0x29')](_0xcb79('0x2e'),_0x5752f4[_0xcb79('0x27')]));tnef['parseBuffer'](_['first'](_0x52d55d)[_0xcb79('0x23')],function(_0x455986,_0x3b7ab1){if(_0x3b7ab1){_0x5752f4[_0xcb79('0x12')]=_0x3b7ab1[_0xcb79('0x2f')]||_0xcb79('0x30');if(_0x3b7ab1[_0xcb79('0x31')]){for(var _0x1360b6=0x0;_0x1360b6<_0x3b7ab1[_0xcb79('0x31')][_0xcb79('0xc')];_0x1360b6++){var _0x44b257=_0x3b7ab1[_0xcb79('0x31')][_0x1360b6];_0x5dadc2[_0xcb79('0x15')][_0xcb79('0x1a')][_0xcb79('0x24')]({'filename':_0x44b257[_0xcb79('0x32')],'content':new Buffer(_0x44b257[_0xcb79('0x33')])});}}}_0x5a9397(parseEmail(_0x168032,_0x5752f4,_0x5dadc2));});}else{_0x5752f4[_0xcb79('0x12')]=_0xcb79('0x30');_0x5a9397(parseEmail(_0x168032,_0x5752f4,_0x5dadc2));}}else{_0x5a9397(parseEmail(_0x168032,_0x5752f4,_0x5dadc2));}};exports[_0xcb79('0x34')]=function(_0x18702f){switch(_0x18702f){case'gmail':return _0xcb79('0x35');case'yahoo':return _0xcb79('0x36');case _0xcb79('0x37'):return'imap-mail.outlook.com';case _0xcb79('0x38'):return _0xcb79('0x39');}return _0xcb79('0x3a');};
\ No newline at end of file
+var _0x5dd2=['<p>Empty\x20message</p>','Attachments','Data','gmail','imap.gmail.com','imap-mail.outlook.com','outlook365','outlook.office365.com','127.0.0.1','lodash','randomstring','util','node-tnef','../../../config/logger','email','../../../config/environment','value','address','anonymous','generate','@xcally.com','name','split','length','slice','join','head','pop','html','replace','includes','<img','attachments','push','filename','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','textAsHtml','body','<a\x20target=\x22_blank\x22\x20','message','isEmpty','originCc','originTo','bcc','attach','type','attachment','format','%s-%s','now','root','server/files/attachments/','content','contentType','parser','from','subject','messageId','inReplyTo','date','filter','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','parseBuffer','first','BodyHTML'];(function(_0x432682,_0x253044){var _0x463d05=function(_0xa73403){while(--_0xa73403){_0x432682['push'](_0x432682['shift']());}};_0x463d05(++_0x253044);}(_0x5dd2,0x1a7));var _0x25dd=function(_0x1694f5,_0x49b7c3){_0x1694f5=_0x1694f5-0x0;var _0x5b4321=_0x5dd2[_0x1694f5];return _0x5b4321;};'use strict';var _=require(_0x25dd('0x0'));var moment=require('moment');var random=require(_0x25dd('0x1'));var fs=require('fs');var path=require('path');var util=require(_0x25dd('0x2'));var tnef=require(_0x25dd('0x3'));var logger=require(_0x25dd('0x4'))(_0x25dd('0x5'));var config=require(_0x25dd('0x6'));function getAddress(_0x51a14a){var _0xa76cd=_['head'](_0x51a14a[_0x25dd('0x7')]);return _0xa76cd&&_0xa76cd[_0x25dd('0x8')]?_0xa76cd[_0x25dd('0x8')]:_0x25dd('0x9')+random[_0x25dd('0xa')](0x6)+_0x25dd('0xb');}function getFirstName(_0x1fc3aa){var _0x2ca243=_['head'](_0x1fc3aa[_0x25dd('0x7')]);if(_0x2ca243&&_0x2ca243[_0x25dd('0xc')]){var _0x56f328=_0x2ca243['name'][_0x25dd('0xd')](/\s+/);return _0x56f328[_0x25dd('0xe')]?_0x56f328[_0x25dd('0xf')](0x0,-0x1)[_0x25dd('0x10')]('\x20'):_0x2ca243['name'];}return'Anonymous';}function getLastName(_0x2d4ee9){var _0x560b16=_[_0x25dd('0x11')](_0x2d4ee9['value']);if(_0x560b16&&_0x560b16[_0x25dd('0xc')]){var _0x1df64a=_0x560b16[_0x25dd('0xc')][_0x25dd('0xd')](/\s+/);return _0x1df64a[_0x25dd('0xe')]>0x1?_0x1df64a[_0x25dd('0x12')]():'';}return'';}function getMails(_0x5b67b0,_0x37d3cd){var _0x5e9b2d='';for(var _0x1f83c7=0x0;_0x1f83c7<_0x37d3cd['value']['length'];_0x1f83c7+=0x1){if(_0x37d3cd[_0x25dd('0x7')][_0x1f83c7][_0x25dd('0x8')]!==_0x5b67b0){if(!_['isEmpty'](_0x5e9b2d)){_0x5e9b2d+=',';}_0x5e9b2d+=_0x37d3cd[_0x25dd('0x7')][_0x1f83c7][_0x25dd('0xc')]||_0x37d3cd[_0x25dd('0x7')][_0x1f83c7][_0x25dd('0x8')]||'';_0x5e9b2d+='\x20<';_0x5e9b2d+=_0x37d3cd['value'][_0x1f83c7][_0x25dd('0x8')]?_0x37d3cd[_0x25dd('0x7')][_0x1f83c7][_0x25dd('0x8')]:'anonymous'+random[_0x25dd('0xa')](0x6)+_0x25dd('0xb');_0x5e9b2d+='>';}}return _0x5e9b2d;}function parseEmail(_0xcf40a3,_0x35d0c5,_0x27bf58){if(_0x35d0c5['html']){var _0xf51101=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0xf51101['test'](_0x35d0c5[_0x25dd('0x13')])){_0x35d0c5[_0x25dd('0x13')]=_0x35d0c5['html'][_0x25dd('0x14')](_0xf51101,'');}if(_0x35d0c5[_0x25dd('0x13')][_0x25dd('0x15')](_0x25dd('0x16'))){var _0x5a972f=[];_0x35d0c5[_0x25dd('0x17')]['forEach'](_0x4eecdb=>{_0x5a972f[_0x25dd('0x18')](_0x4eecdb[_0x25dd('0x19')]);});var _0x5cba87=/<img.*? _SRC(.*?)[^\>]+>/g;var _0x214065=/src=\"data:image\/([a-zA-Z]*);base64,([^\"]*)\"/g;var _0x2486bc=_0x35d0c5[_0x25dd('0x13')][_0x25dd('0x14')](_0x214065,_0x25dd('0x1a'));var _0x5746f8=_0x2486bc[_0x25dd('0x14')](_0x5cba87,_0x25dd('0x1b'));for(let _0x4c3f5c=0x0;_0x4c3f5c<_0x5a972f[_0x25dd('0xe')];_0x4c3f5c++){var _0x3416b3=_0x5746f8[_0x25dd('0x14')](_0x25dd('0x1b'),_0x25dd('0x1c')+_0x5a972f[_0x4c3f5c]+_0x25dd('0x1d'));_0x5746f8=_0x3416b3;}_0x35d0c5[_0x25dd('0x13')]=_0x5746f8;}_0x27bf58['body']=_0x35d0c5[_0x25dd('0x13')];}else{_0x27bf58['body']=_0x35d0c5[_0x25dd('0x1e')];}if(_0x27bf58[_0x25dd('0x1f')]){_0x27bf58[_0x25dd('0x1f')]=_0x27bf58[_0x25dd('0x1f')][_0x25dd('0x14')](/<a\s+/gi,_0x25dd('0x20'));}if(_0x35d0c5['to']){_0x27bf58[_0x25dd('0x21')]['originTo']=getMails(null,_0x35d0c5['to']);var _0x2d7b84=getMails(_0xcf40a3[_0x25dd('0x5')],_0x35d0c5['to']);if(!_[_0x25dd('0x22')](_0x2d7b84)){_0x27bf58[_0x25dd('0x21')]['cc']+=_0x2d7b84;}}if(_0x35d0c5['cc']){_0x27bf58[_0x25dd('0x21')][_0x25dd('0x23')]=getMails(null,_0x35d0c5['cc']);var _0x2f5f18=getMails(_0xcf40a3[_0x25dd('0x5')],_0x35d0c5['cc']);if(!_[_0x25dd('0x22')](_0x2f5f18)){if(!_[_0x25dd('0x22')](_0x27bf58['message']['cc'])){_0x27bf58['message']['cc']+=',';}_0x27bf58['message']['cc']+=_0x2f5f18;}}if(!_[_0x25dd('0x15')](_0x27bf58[_0x25dd('0x21')][_0x25dd('0x24')],_0xcf40a3[_0x25dd('0x5')])&&!_[_0x25dd('0x15')](_0x27bf58[_0x25dd('0x21')][_0x25dd('0x23')],_0xcf40a3[_0x25dd('0x5')])){_0x27bf58['message'][_0x25dd('0x25')]=_0xcf40a3['email'];}if(_0x35d0c5[_0x25dd('0x17')]&&_0x35d0c5['attachments'][_0x25dd('0xe')]){_0x27bf58[_0x25dd('0x21')][_0x25dd('0x26')]=_0x35d0c5[_0x25dd('0x17')]['length'];for(var _0x1e3dfc=0x0,_0x32c522,_0x3323ab,_0x24c158;_0x1e3dfc<_0x35d0c5[_0x25dd('0x17')][_0x25dd('0xe')];_0x1e3dfc+=0x1){if(_0x35d0c5[_0x25dd('0x17')][_0x1e3dfc][_0x25dd('0x27')]===_0x25dd('0x28')){_0x24c158=_0x35d0c5[_0x25dd('0x17')][_0x1e3dfc]['filename']||'attachment-'+_0x1e3dfc;_0x32c522=util[_0x25dd('0x29')](_0x25dd('0x2a'),Date[_0x25dd('0x2b')](),_0x24c158);_0x3323ab=path[_0x25dd('0x10')](config[_0x25dd('0x2c')],_0x25dd('0x2d'),_0x32c522);fs['writeFileSync'](_0x3323ab,_0x35d0c5[_0x25dd('0x17')][_0x1e3dfc][_0x25dd('0x2e')]);_0x27bf58['message'][_0x25dd('0x17')][_0x25dd('0x18')]({'name':_0x24c158,'basename':_0x32c522,'type':_0x35d0c5['attachments'][_0x1e3dfc][_0x25dd('0x2f')],'filepath':_0x3323ab});}}}return _0x27bf58;}exports[_0x25dd('0x30')]=function(_0x559907,_0x1afc85,_0x412086){var _0x85fa86={'from':getAddress(_0x1afc85['from']),'firstName':getFirstName(_0x1afc85[_0x25dd('0x31')]),'lastName':getLastName(_0x1afc85[_0x25dd('0x31')]),'mapKey':_0x25dd('0x5'),'message':{'from':getMails(_0x559907['email'],_0x1afc85['from']),'to':_0x559907['email'],'cc':'','subject':_0x1afc85[_0x25dd('0x32')]||'','messageId':_0x1afc85[_0x25dd('0x33')],'inReplyTo':_0x1afc85[_0x25dd('0x34')],'sentAt':moment(_0x1afc85[_0x25dd('0x35')])['format']('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x1afc85[_0x25dd('0x13')]&&!_0x1afc85['textAsHtml']){var _0x2df0a4=_[_0x25dd('0x36')](_0x1afc85[_0x25dd('0x17')],{'contentType':'application/ms-tnef'});if(_0x2df0a4['length']){logger[_0x25dd('0x37')](util[_0x25dd('0x29')](_0x25dd('0x38'),_0x1afc85[_0x25dd('0x33')]));tnef[_0x25dd('0x39')](_[_0x25dd('0x3a')](_0x2df0a4)['content'],function(_0x39fda3,_0x4f11e5){if(_0x4f11e5){_0x1afc85['html']=_0x4f11e5[_0x25dd('0x3b')]||_0x25dd('0x3c');if(_0x4f11e5[_0x25dd('0x3d')]){for(var _0x1dab19=0x0;_0x1dab19<_0x4f11e5['Attachments']['length'];_0x1dab19++){var _0x350b87=_0x4f11e5['Attachments'][_0x1dab19];_0x85fa86[_0x25dd('0x21')]['attachments'][_0x25dd('0x18')]({'filename':_0x350b87['Title'],'content':new Buffer(_0x350b87[_0x25dd('0x3e')])});}}}_0x412086(parseEmail(_0x559907,_0x1afc85,_0x85fa86));});}else{_0x1afc85[_0x25dd('0x13')]='<p>Empty\x20message</p>';_0x412086(parseEmail(_0x559907,_0x1afc85,_0x85fa86));}}else{_0x412086(parseEmail(_0x559907,_0x1afc85,_0x85fa86));}};exports['getHost']=function(_0x573bc4){switch(_0x573bc4){case _0x25dd('0x3f'):return _0x25dd('0x40');case'yahoo':return'imap.mail.yahoo.com';case'hotmail':return _0x25dd('0x41');case _0x25dd('0x42'):return _0x25dd('0x43');}return _0x25dd('0x44');};
\ No newline at end of file