Built motion from commit (unavailable).|2.5.28
[motion2.git] / server / services / email / lib / utils.js
index 395e90f..e2e5aa2 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xd517=['inReplyTo','filter','first','BodyHTML','<p>Empty\x20message</p>','Attachments','push','getHost','gmail','imap.gmail.com','yahoo','imap.mail.yahoo.com','imap-mail.outlook.com','outlook365','outlook.office365.com','moment','path','util','node-tnef','../../../config/logger','head','value','address','anonymous','generate','split','length','slice','Anonymous','name','pop','@xcally.com','html','test','replace','textAsHtml','body','<a\x20target=\x22_blank\x22\x20','message','email','isEmpty','originCc','includes','originTo','attachments','attach','type','attachment','format','%s-%s','now','join','server/files/attachments/','writeFileSync','content','contentType','parser','from','messageId'];(function(_0x13b0a3,_0x41b97a){var _0x6d318e=function(_0x564d58){while(--_0x564d58){_0x13b0a3['push'](_0x13b0a3['shift']());}};_0x6d318e(++_0x41b97a);}(_0xd517,0xfb));var _0x7d51=function(_0x450bf9,_0x1895de){_0x450bf9=_0x450bf9-0x0;var _0x268350=_0xd517[_0x450bf9];return _0x268350;};'use strict';var _=require('lodash');var moment=require(_0x7d51('0x0'));var random=require('randomstring');var fs=require('fs');var path=require(_0x7d51('0x1'));var util=require(_0x7d51('0x2'));var tnef=require(_0x7d51('0x3'));var logger=require(_0x7d51('0x4'))('email');var config=require('../../../config/environment');function getAddress(_0x16c841){var _0x422548=_[_0x7d51('0x5')](_0x16c841[_0x7d51('0x6')]);return _0x422548&&_0x422548[_0x7d51('0x7')]?_0x422548[_0x7d51('0x7')]:_0x7d51('0x8')+random[_0x7d51('0x9')](0x6)+'@xcally.com';}function getFirstName(_0x8f2f1){var _0x2ab49f=_['head'](_0x8f2f1[_0x7d51('0x6')]);if(_0x2ab49f&&_0x2ab49f['name']){var _0x4191fb=_0x2ab49f['name'][_0x7d51('0xa')](/\s+/);return _0x4191fb[_0x7d51('0xb')]?_0x4191fb[_0x7d51('0xc')](0x0,-0x1)['join']('\x20'):_0x2ab49f['name'];}return _0x7d51('0xd');}function getLastName(_0x576d8f){var _0xca79b2=_[_0x7d51('0x5')](_0x576d8f[_0x7d51('0x6')]);if(_0xca79b2&&_0xca79b2[_0x7d51('0xe')]){var _0xdbcd1d=_0xca79b2[_0x7d51('0xe')][_0x7d51('0xa')](/\s+/);return _0xdbcd1d[_0x7d51('0xb')]>0x1?_0xdbcd1d[_0x7d51('0xf')]():'';}return'';}function getMails(_0x2530c3,_0x16db1e){var _0xa1f3c3='';for(var _0x1f966d=0x0;_0x1f966d<_0x16db1e[_0x7d51('0x6')][_0x7d51('0xb')];_0x1f966d+=0x1){if(_0x16db1e[_0x7d51('0x6')][_0x1f966d]['address']!==_0x2530c3){if(!_['isEmpty'](_0xa1f3c3)){_0xa1f3c3+=',';}_0xa1f3c3+=_0x16db1e[_0x7d51('0x6')][_0x1f966d][_0x7d51('0xe')]||_0x16db1e['value'][_0x1f966d][_0x7d51('0x7')]||'';_0xa1f3c3+='\x20<';_0xa1f3c3+=_0x16db1e[_0x7d51('0x6')][_0x1f966d][_0x7d51('0x7')]?_0x16db1e[_0x7d51('0x6')][_0x1f966d][_0x7d51('0x7')]:'anonymous'+random[_0x7d51('0x9')](0x6)+_0x7d51('0x10');_0xa1f3c3+='>';}}return _0xa1f3c3;}function parseEmail(_0x41d7d2,_0x1c8a22,_0x32b491){if(_0x1c8a22[_0x7d51('0x11')]){var _0x43fe9d=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x43fe9d[_0x7d51('0x12')](_0x1c8a22['html'])){_0x1c8a22[_0x7d51('0x11')]=_0x1c8a22['html'][_0x7d51('0x13')](_0x43fe9d,'');}_0x32b491['body']=_0x1c8a22['html'];}else{_0x32b491['body']=_0x1c8a22[_0x7d51('0x14')];}if(_0x32b491['body']){_0x32b491[_0x7d51('0x15')]=_0x32b491['body']['replace'](/<a\s+/gi,_0x7d51('0x16'));}if(_0x1c8a22['to']){_0x32b491[_0x7d51('0x17')]['originTo']=getMails(null,_0x1c8a22['to']);var _0x4a622a=getMails(_0x41d7d2[_0x7d51('0x18')],_0x1c8a22['to']);if(!_[_0x7d51('0x19')](_0x4a622a)){_0x32b491['message']['cc']+=_0x4a622a;}}if(_0x1c8a22['cc']){_0x32b491[_0x7d51('0x17')][_0x7d51('0x1a')]=getMails(null,_0x1c8a22['cc']);var _0x299744=getMails(_0x41d7d2[_0x7d51('0x18')],_0x1c8a22['cc']);if(!_[_0x7d51('0x19')](_0x299744)){if(!_['isEmpty'](_0x32b491['message']['cc'])){_0x32b491[_0x7d51('0x17')]['cc']+=',';}_0x32b491[_0x7d51('0x17')]['cc']+=_0x299744;}}if(!_[_0x7d51('0x1b')](_0x32b491['message'][_0x7d51('0x1c')],_0x41d7d2['email'])&&!_[_0x7d51('0x1b')](_0x32b491[_0x7d51('0x17')]['originCc'],_0x41d7d2[_0x7d51('0x18')])){_0x32b491[_0x7d51('0x17')]['bcc']=_0x41d7d2['email'];}if(_0x1c8a22[_0x7d51('0x1d')]&&_0x1c8a22[_0x7d51('0x1d')][_0x7d51('0xb')]){_0x32b491['message'][_0x7d51('0x1e')]=_0x1c8a22[_0x7d51('0x1d')][_0x7d51('0xb')];for(var _0x4bd940=0x0,_0x87e5df,_0x22fd52,_0x5c5924;_0x4bd940<_0x1c8a22[_0x7d51('0x1d')]['length'];_0x4bd940+=0x1){if(_0x1c8a22[_0x7d51('0x1d')][_0x4bd940][_0x7d51('0x1f')]===_0x7d51('0x20')){_0x5c5924=_0x1c8a22[_0x7d51('0x1d')][_0x4bd940]['filename']||'attachment-'+_0x4bd940;_0x87e5df=util[_0x7d51('0x21')](_0x7d51('0x22'),Date[_0x7d51('0x23')](),_0x5c5924);_0x22fd52=path[_0x7d51('0x24')](config['root'],_0x7d51('0x25'),_0x87e5df);fs[_0x7d51('0x26')](_0x22fd52,_0x1c8a22[_0x7d51('0x1d')][_0x4bd940][_0x7d51('0x27')]);_0x32b491[_0x7d51('0x17')][_0x7d51('0x1d')]['push']({'name':_0x5c5924,'basename':_0x87e5df,'type':_0x1c8a22[_0x7d51('0x1d')][_0x4bd940][_0x7d51('0x28')],'filepath':_0x22fd52});}}}return _0x32b491;}exports[_0x7d51('0x29')]=function(_0x2d8809,_0x50cffa,_0x41742c){var _0xd763c1={'from':getAddress(_0x50cffa[_0x7d51('0x2a')]),'firstName':getFirstName(_0x50cffa['from']),'lastName':getLastName(_0x50cffa[_0x7d51('0x2a')]),'mapKey':_0x7d51('0x18'),'message':{'from':getMails(_0x2d8809[_0x7d51('0x18')],_0x50cffa[_0x7d51('0x2a')]),'to':_0x2d8809['email'],'cc':'','subject':_0x50cffa['subject']||'','messageId':_0x50cffa[_0x7d51('0x2b')],'inReplyTo':_0x50cffa[_0x7d51('0x2c')],'sentAt':moment(_0x50cffa['date'])[_0x7d51('0x21')]('YYYY-MM-DD\x20HH:mm:ss'),'attach':![],'attachments':[]}};if(!_0x50cffa[_0x7d51('0x11')]&&!_0x50cffa[_0x7d51('0x14')]){var _0xae2f0a=_[_0x7d51('0x2d')](_0x50cffa[_0x7d51('0x1d')],{'contentType':'application/ms-tnef'});if(_0xae2f0a[_0x7d51('0xb')]){logger['info'](util['format']('Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system',_0x50cffa[_0x7d51('0x2b')]));tnef['parseBuffer'](_[_0x7d51('0x2e')](_0xae2f0a)[_0x7d51('0x27')],function(_0x86a992,_0x309656){if(_0x309656){_0x50cffa['html']=_0x309656[_0x7d51('0x2f')]||_0x7d51('0x30');if(_0x309656['Attachments']){for(var _0x47e49e=0x0;_0x47e49e<_0x309656[_0x7d51('0x31')]['length'];_0x47e49e++){var _0x4a90dc=_0x309656[_0x7d51('0x31')][_0x47e49e];_0xd763c1[_0x7d51('0x17')][_0x7d51('0x1d')][_0x7d51('0x32')]({'filename':_0x4a90dc['Title'],'content':new Buffer(_0x4a90dc['Data'])});}}}_0x41742c(parseEmail(_0x2d8809,_0x50cffa,_0xd763c1));});}else{_0x50cffa[_0x7d51('0x11')]='<p>Empty\x20message</p>';_0x41742c(parseEmail(_0x2d8809,_0x50cffa,_0xd763c1));}}else{_0x41742c(parseEmail(_0x2d8809,_0x50cffa,_0xd763c1));}};exports[_0x7d51('0x33')]=function(_0x2bad44){switch(_0x2bad44){case _0x7d51('0x34'):return _0x7d51('0x35');case _0x7d51('0x36'):return _0x7d51('0x37');case'hotmail':return _0x7d51('0x38');case _0x7d51('0x39'):return _0x7d51('0x3a');}return'127.0.0.1';};
\ 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