Built motion from commit 5b761a7b.|2.5.36
[motion2.git] / server / services / email / lib / utils.js
index 680fdb5..8ffd9e8 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x4325=['subject','messageId','date','YYYY-MM-DD\x20HH:mm:ss','textAsHtml','info','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','parseBuffer','first','BodyHTML','<p>Empty\x20message</p>','Attachments','Title','imap.gmail.com','yahoo','imap-mail.outlook.com','outlook365','outlook.office365.com','127.0.0.1','lodash','moment','path','util','node-tnef','../../../config/environment','value','address','anonymous','@xcally.com','head','split','length','slice','join','name','isEmpty','generate','test','html','<img','attachments','forEach','filename','replace','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','body','message','originTo','originCc','email','includes','bcc','attach','type','attachment','attachment-','format','%s-%s','now','server/files/attachments/','content','parser','from'];(function(_0x3626ab,_0x46cf71){var _0x3d3f52=function(_0x3f7e88){while(--_0x3f7e88){_0x3626ab['push'](_0x3626ab['shift']());}};_0x3d3f52(++_0x46cf71);}(_0x4325,0x1da));var _0x5432=function(_0x3b380d,_0x4bf247){_0x3b380d=_0x3b380d-0x0;var _0x54502b=_0x4325[_0x3b380d];return _0x54502b;};'use strict';var _=require(_0x5432('0x0'));var moment=require(_0x5432('0x1'));var random=require('randomstring');var fs=require('fs');var path=require(_0x5432('0x2'));var util=require(_0x5432('0x3'));var tnef=require(_0x5432('0x4'));var logger=require('../../../config/logger')('email');var config=require(_0x5432('0x5'));function getAddress(_0x36ce53){var _0xad26e9=_['head'](_0x36ce53[_0x5432('0x6')]);return _0xad26e9&&_0xad26e9[_0x5432('0x7')]?_0xad26e9['address']:_0x5432('0x8')+random['generate'](0x6)+_0x5432('0x9');}function getFirstName(_0x1c9762){var _0x40e756=_[_0x5432('0xa')](_0x1c9762[_0x5432('0x6')]);if(_0x40e756&&_0x40e756['name']){var _0xcc52a=_0x40e756['name'][_0x5432('0xb')](/\s+/);return _0xcc52a[_0x5432('0xc')]?_0xcc52a[_0x5432('0xd')](0x0,-0x1)[_0x5432('0xe')]('\x20'):_0x40e756['name'];}return'Anonymous';}function getLastName(_0x11b25c){var _0x24fb02=_['head'](_0x11b25c[_0x5432('0x6')]);if(_0x24fb02&&_0x24fb02[_0x5432('0xf')]){var _0x3b1127=_0x24fb02[_0x5432('0xf')][_0x5432('0xb')](/\s+/);return _0x3b1127[_0x5432('0xc')]>0x1?_0x3b1127['pop']():'';}return'';}function getMails(_0x5617ce,_0x43bb16){var _0x44e70c='';for(var _0x3859d1=0x0;_0x3859d1<_0x43bb16[_0x5432('0x6')][_0x5432('0xc')];_0x3859d1+=0x1){if(_0x43bb16[_0x5432('0x6')][_0x3859d1]['address']!==_0x5617ce){if(!_[_0x5432('0x10')](_0x44e70c)){_0x44e70c+=',';}_0x44e70c+=_0x43bb16['value'][_0x3859d1][_0x5432('0xf')]||_0x43bb16[_0x5432('0x6')][_0x3859d1][_0x5432('0x7')]||'';_0x44e70c+='\x20<';_0x44e70c+=_0x43bb16[_0x5432('0x6')][_0x3859d1][_0x5432('0x7')]?_0x43bb16['value'][_0x3859d1][_0x5432('0x7')]:_0x5432('0x8')+random[_0x5432('0x11')](0x6)+_0x5432('0x9');_0x44e70c+='>';}}return _0x44e70c;}function parseEmail(_0x1cf960,_0x451de4,_0x29e699){if(_0x451de4['html']){var _0x66911a=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x66911a[_0x5432('0x12')](_0x451de4[_0x5432('0x13')])){_0x451de4[_0x5432('0x13')]=_0x451de4[_0x5432('0x13')]['replace'](_0x66911a,'');}if(_0x451de4['html']['includes'](_0x5432('0x14'))){var _0xb900f2=[];_0x451de4[_0x5432('0x15')][_0x5432('0x16')](_0x4af9f6=>{_0xb900f2['push'](_0x4af9f6[_0x5432('0x17')]);});var _0x8ed74b=/<img.*? _SRC(.*?)[^\>]+>/g;var _0x4a40fc=/src=\"data:image\/([a-zA-Z]*);base64,([^\"]*)\"/g;var _0x19e6b2=_0x451de4[_0x5432('0x13')][_0x5432('0x18')](_0x4a40fc,'_SRC');var _0xd9928a=_0x19e6b2[_0x5432('0x18')](_0x8ed74b,_0x5432('0x19'));for(let _0x520da1=0x0;_0x520da1<_0xb900f2['length'];_0x520da1++){var _0x1f2055=_0xd9928a[_0x5432('0x18')]('_IMG',_0x5432('0x1a')+_0xb900f2[_0x520da1]+_0x5432('0x1b'));_0xd9928a=_0x1f2055;}_0x451de4[_0x5432('0x13')]=_0xd9928a;}_0x29e699['body']=_0x451de4[_0x5432('0x13')];}else{_0x29e699['body']=_0x451de4['textAsHtml'];}if(_0x29e699[_0x5432('0x1c')]){_0x29e699['body']=_0x29e699[_0x5432('0x1c')]['replace'](/<a\s+/gi,'<a\x20target=\x22_blank\x22\x20');}if(_0x451de4['to']){_0x29e699[_0x5432('0x1d')][_0x5432('0x1e')]=getMails(null,_0x451de4['to']);var _0x345b51=getMails(_0x1cf960['email'],_0x451de4['to']);if(!_[_0x5432('0x10')](_0x345b51)){_0x29e699[_0x5432('0x1d')]['cc']+=_0x345b51;}}if(_0x451de4['cc']){_0x29e699[_0x5432('0x1d')][_0x5432('0x1f')]=getMails(null,_0x451de4['cc']);var _0x1a5612=getMails(_0x1cf960[_0x5432('0x20')],_0x451de4['cc']);if(!_[_0x5432('0x10')](_0x1a5612)){if(!_[_0x5432('0x10')](_0x29e699[_0x5432('0x1d')]['cc'])){_0x29e699['message']['cc']+=',';}_0x29e699['message']['cc']+=_0x1a5612;}}if(!_[_0x5432('0x21')](_0x29e699[_0x5432('0x1d')][_0x5432('0x1e')],_0x1cf960[_0x5432('0x20')])&&!_[_0x5432('0x21')](_0x29e699['message'][_0x5432('0x1f')],_0x1cf960['email'])){_0x29e699[_0x5432('0x1d')][_0x5432('0x22')]=_0x1cf960[_0x5432('0x20')];}if(_0x451de4[_0x5432('0x15')]&&_0x451de4[_0x5432('0x15')][_0x5432('0xc')]){_0x29e699['message'][_0x5432('0x23')]=_0x451de4[_0x5432('0x15')][_0x5432('0xc')];for(var _0xcfb6e8=0x0,_0x555b6e,_0xe01f4b,_0x43676e;_0xcfb6e8<_0x451de4[_0x5432('0x15')][_0x5432('0xc')];_0xcfb6e8+=0x1){if(_0x451de4[_0x5432('0x15')][_0xcfb6e8][_0x5432('0x24')]===_0x5432('0x25')){_0x43676e=_0x451de4[_0x5432('0x15')][_0xcfb6e8][_0x5432('0x17')]||_0x5432('0x26')+_0xcfb6e8;_0x555b6e=util[_0x5432('0x27')](_0x5432('0x28'),Date[_0x5432('0x29')](),_0x43676e);_0xe01f4b=path[_0x5432('0xe')](config['root'],_0x5432('0x2a'),_0x555b6e);fs['writeFileSync'](_0xe01f4b,_0x451de4[_0x5432('0x15')][_0xcfb6e8][_0x5432('0x2b')]);_0x29e699[_0x5432('0x1d')][_0x5432('0x15')]['push']({'name':_0x43676e,'basename':_0x555b6e,'type':_0x451de4['attachments'][_0xcfb6e8]['contentType'],'filepath':_0xe01f4b});}}}return _0x29e699;}exports[_0x5432('0x2c')]=function(_0x2053ed,_0x139d0a,_0x39c9c0){var _0x52b296={'from':getAddress(_0x139d0a[_0x5432('0x2d')]),'firstName':getFirstName(_0x139d0a[_0x5432('0x2d')]),'lastName':getLastName(_0x139d0a[_0x5432('0x2d')]),'mapKey':'email','message':{'from':getMails(_0x2053ed[_0x5432('0x20')],_0x139d0a[_0x5432('0x2d')]),'to':_0x2053ed['email'],'cc':'','subject':_0x139d0a[_0x5432('0x2e')]||'','messageId':_0x139d0a[_0x5432('0x2f')],'inReplyTo':_0x139d0a['inReplyTo'],'sentAt':moment(_0x139d0a[_0x5432('0x30')])['format'](_0x5432('0x31')),'attach':![],'attachments':[]}};if(!_0x139d0a[_0x5432('0x13')]&&!_0x139d0a[_0x5432('0x32')]){var _0x11c7f2=_['filter'](_0x139d0a[_0x5432('0x15')],{'contentType':'application/ms-tnef'});if(_0x11c7f2[_0x5432('0xc')]){logger[_0x5432('0x33')](util[_0x5432('0x27')](_0x5432('0x34'),_0x139d0a[_0x5432('0x2f')]));tnef[_0x5432('0x35')](_[_0x5432('0x36')](_0x11c7f2)['content'],function(_0x31fca4,_0x534d47){if(_0x534d47){_0x139d0a[_0x5432('0x13')]=_0x534d47[_0x5432('0x37')]||_0x5432('0x38');if(_0x534d47[_0x5432('0x39')]){for(var _0x2134c9=0x0;_0x2134c9<_0x534d47['Attachments'][_0x5432('0xc')];_0x2134c9++){var _0x2cb48f=_0x534d47[_0x5432('0x39')][_0x2134c9];_0x52b296[_0x5432('0x1d')][_0x5432('0x15')]['push']({'filename':_0x2cb48f[_0x5432('0x3a')],'content':new Buffer(_0x2cb48f['Data'])});}}}_0x39c9c0(parseEmail(_0x2053ed,_0x139d0a,_0x52b296));});}else{_0x139d0a[_0x5432('0x13')]=_0x5432('0x38');_0x39c9c0(parseEmail(_0x2053ed,_0x139d0a,_0x52b296));}}else{_0x39c9c0(parseEmail(_0x2053ed,_0x139d0a,_0x52b296));}};exports['getHost']=function(_0x40e036){switch(_0x40e036){case'gmail':return _0x5432('0x3b');case _0x5432('0x3c'):return'imap.mail.yahoo.com';case'hotmail':return _0x5432('0x3d');case _0x5432('0x3e'):return _0x5432('0x3f');}return _0x5432('0x40');};
\ No newline at end of file
+var _0x199d=['@xcally.com','head','name','substring','indexOf','split','length','slice','join','Anonymous','isEmpty','test','html','replace','<img','attachments','forEach','push','filename','_SRC','_IMG','<span\x20style=font-weight:bold>\x20[Attachment:\x20','\x20]</span>','body','textAsHtml','<a\x20target=\x22_blank\x22\x20','message','originTo','originCc','email','includes','bcc','attach','type','attachment','attachment-','format','%s-%s','now','root','server/files/attachments/','writeFileSync','content','headerLines','Auto-Submitted:\x20auto-replied','X-Auto-Response-Suppress:\x20All','Precedence:\x20auto_reply','line','isAutoreply','parser','from','subject','messageId','date','YYYY-MM-DD\x20HH:mm:ss','filter','application/ms-tnef','Email\x20message\x20%s\x20is\x20in\x20TNEF\x20format:\x20message\x20content\x20will\x20be\x20converted\x20by\x20the\x20system','parseBuffer','first','BodyHTML','<p>Empty\x20message</p>','Attachments','Title','getHost','gmail','yahoo','imap.mail.yahoo.com','imap-mail.outlook.com','outlook365','outlook.office365.com','lodash','moment','randomstring','path','util','../../../config/logger','../../../config/environment','value','address','anonymous','generate'];(function(_0xe9506d,_0x137018){var _0x40db58=function(_0x2a4a42){while(--_0x2a4a42){_0xe9506d['push'](_0xe9506d['shift']());}};_0x40db58(++_0x137018);}(_0x199d,0x13d));var _0xd199=function(_0x590a38,_0x2bc65c){_0x590a38=_0x590a38-0x0;var _0xf36626=_0x199d[_0x590a38];return _0xf36626;};'use strict';var _=require(_0xd199('0x0'));var moment=require(_0xd199('0x1'));var random=require(_0xd199('0x2'));var fs=require('fs');var path=require(_0xd199('0x3'));var util=require(_0xd199('0x4'));var tnef=require('node-tnef');var logger=require(_0xd199('0x5'))('email');var config=require(_0xd199('0x6'));function getAddress(_0x338d17){var _0x1df29b=_['head'](_0x338d17[_0xd199('0x7')]);return _0x1df29b&&_0x1df29b[_0xd199('0x8')]?_0x1df29b['address']:_0xd199('0x9')+random[_0xd199('0xa')](0x6)+_0xd199('0xb');}function getFirstName(_0x57a6d7){var _0x2bcbbd=_[_0xd199('0xc')](_0x57a6d7[_0xd199('0x7')]);if(_0x2bcbbd&&_0x2bcbbd['name']){if(_0x2bcbbd[_0xd199('0xd')]==_0x2bcbbd[_0xd199('0x8')]){return _0x2bcbbd['name'][_0xd199('0xe')](0x0,_0x2bcbbd['name'][_0xd199('0xf')]('@'));}var _0x98e9af=_0x2bcbbd[_0xd199('0xd')][_0xd199('0x10')](/\s+/);return _0x98e9af[_0xd199('0x11')]>0x1?_0x98e9af[_0xd199('0x12')](0x0,-0x1)[_0xd199('0x13')]('\x20'):_0x2bcbbd[_0xd199('0xd')];}return _0xd199('0x14');}function getLastName(_0x13d636){var _0xe50ec5=_['head'](_0x13d636[_0xd199('0x7')]);if(_0xe50ec5&&_0xe50ec5['name']){var _0x3568b7=_0xe50ec5[_0xd199('0xd')][_0xd199('0x10')](/\s+/);return _0x3568b7[_0xd199('0x11')]>0x1?_0x3568b7['pop']():'';}return'';}function getMails(_0x1e8132,_0xe48c1b){var _0x1251a6='';for(var _0x16a7c5=0x0;_0x16a7c5<_0xe48c1b[_0xd199('0x7')]['length'];_0x16a7c5+=0x1){if(_0xe48c1b[_0xd199('0x7')][_0x16a7c5]['address']!==_0x1e8132){if(!_[_0xd199('0x15')](_0x1251a6)){_0x1251a6+=',';}_0x1251a6+=_0xe48c1b[_0xd199('0x7')][_0x16a7c5][_0xd199('0xd')]||_0xe48c1b[_0xd199('0x7')][_0x16a7c5][_0xd199('0x8')]||'';_0x1251a6+='\x20<';_0x1251a6+=_0xe48c1b[_0xd199('0x7')][_0x16a7c5][_0xd199('0x8')]?_0xe48c1b['value'][_0x16a7c5][_0xd199('0x8')]:_0xd199('0x9')+random[_0xd199('0xa')](0x6)+_0xd199('0xb');_0x1251a6+='>';}}return _0x1251a6;}function parseEmail(_0x487ace,_0x236962,_0x48458f){if(_0x236962['html']){var _0x217cc1=/<script\b[^<]*(?:(?!<\/script>)<[^<]*)*<\/script>/gi;while(_0x217cc1[_0xd199('0x16')](_0x236962[_0xd199('0x17')])){_0x236962['html']=_0x236962['html'][_0xd199('0x18')](_0x217cc1,'');}if(_0x236962[_0xd199('0x17')]['includes'](_0xd199('0x19'))){var _0x429a37=[];_0x236962[_0xd199('0x1a')][_0xd199('0x1b')](_0x360753=>{_0x429a37[_0xd199('0x1c')](_0x360753[_0xd199('0x1d')]);});var _0x3f5b4c=/<img.*? _SRC(.*?)[^>]+>/g;var _0x59408c=/src="data:image\/([a-zA-Z]*);base64,([^"]*)"/g;var _0x5b50b2=_0x236962['html'][_0xd199('0x18')](_0x59408c,_0xd199('0x1e'));var _0x9df93b=_0x5b50b2['replace'](_0x3f5b4c,'_IMG');for(let _0x44c073=0x0;_0x44c073<_0x429a37[_0xd199('0x11')];_0x44c073++){var _0x2a3bb4=_0x9df93b[_0xd199('0x18')](_0xd199('0x1f'),_0xd199('0x20')+_0x429a37[_0x44c073]+_0xd199('0x21'));_0x9df93b=_0x2a3bb4;}_0x236962[_0xd199('0x17')]=_0x9df93b;}_0x48458f[_0xd199('0x22')]=_0x236962[_0xd199('0x17')];}else{_0x48458f['body']=_0x236962[_0xd199('0x23')];}if(_0x48458f['body']){_0x48458f['body']=_0x48458f[_0xd199('0x22')][_0xd199('0x18')](/<a\s+/gi,_0xd199('0x24'));}if(_0x236962['to']){_0x48458f[_0xd199('0x25')][_0xd199('0x26')]=getMails(null,_0x236962['to']);var _0x364343=getMails(_0x487ace['email'],_0x236962['to']);if(!_[_0xd199('0x15')](_0x364343)){_0x48458f[_0xd199('0x25')]['cc']+=_0x364343;}}if(_0x236962['cc']){_0x48458f[_0xd199('0x25')][_0xd199('0x27')]=getMails(null,_0x236962['cc']);var _0x50ab5b=getMails(_0x487ace[_0xd199('0x28')],_0x236962['cc']);if(!_[_0xd199('0x15')](_0x50ab5b)){if(!_['isEmpty'](_0x48458f['message']['cc'])){_0x48458f['message']['cc']+=',';}_0x48458f[_0xd199('0x25')]['cc']+=_0x50ab5b;}}if(!_[_0xd199('0x29')](_0x48458f[_0xd199('0x25')]['originTo'],_0x487ace['email'])&&!_[_0xd199('0x29')](_0x48458f['message'][_0xd199('0x27')],_0x487ace[_0xd199('0x28')])){_0x48458f[_0xd199('0x25')][_0xd199('0x2a')]=_0x487ace['email'];}if(_0x236962[_0xd199('0x1a')]&&_0x236962[_0xd199('0x1a')][_0xd199('0x11')]){_0x48458f[_0xd199('0x25')][_0xd199('0x2b')]=_0x236962[_0xd199('0x1a')][_0xd199('0x11')];for(var _0x59f04f=0x0,_0x4c5dda,_0x50549c,_0x3fbae3;_0x59f04f<_0x236962['attachments'][_0xd199('0x11')];_0x59f04f+=0x1){if(_0x236962[_0xd199('0x1a')][_0x59f04f][_0xd199('0x2c')]===_0xd199('0x2d')){_0x3fbae3=_0x236962['attachments'][_0x59f04f]['filename']||_0xd199('0x2e')+_0x59f04f;_0x4c5dda=util[_0xd199('0x2f')](_0xd199('0x30'),Date[_0xd199('0x31')](),_0x3fbae3);_0x50549c=path['join'](config[_0xd199('0x32')],_0xd199('0x33'),_0x4c5dda);fs[_0xd199('0x34')](_0x50549c,_0x236962[_0xd199('0x1a')][_0x59f04f][_0xd199('0x35')]);_0x48458f[_0xd199('0x25')][_0xd199('0x1a')][_0xd199('0x1c')]({'name':_0x3fbae3,'basename':_0x4c5dda,'type':_0x236962[_0xd199('0x1a')][_0x59f04f]['contentType'],'filepath':_0x50549c});}}}if(_0x236962['headerLines']&&_0x236962[_0xd199('0x36')][_0xd199('0x11')]>0x0){var _0x19324f=[_0xd199('0x37'),_0xd199('0x38'),_0xd199('0x39')];for(var _0x4029e2=0x0;_0x4029e2<_0x236962[_0xd199('0x36')][_0xd199('0x11')];_0x4029e2++){var _0x7bc29b=_[_0xd199('0xf')](_0x19324f,_0x236962[_0xd199('0x36')][_0x4029e2][_0xd199('0x3a')]);if(_0x7bc29b>=0x0){_0x48458f[_0xd199('0x3b')]=!![];}}}return _0x48458f;}exports[_0xd199('0x3c')]=function(_0x54dcd4,_0x14874d,_0x2dbd25){var _0x12ec54={'from':getAddress(_0x14874d[_0xd199('0x3d')]),'firstName':getFirstName(_0x14874d[_0xd199('0x3d')]),'lastName':getLastName(_0x14874d[_0xd199('0x3d')]),'mapKey':'email','message':{'from':getMails(_0x54dcd4['email'],_0x14874d[_0xd199('0x3d')]),'to':_0x54dcd4[_0xd199('0x28')],'cc':'','subject':_0x14874d[_0xd199('0x3e')]||'','messageId':_0x14874d[_0xd199('0x3f')],'inReplyTo':_0x14874d['inReplyTo'],'sentAt':moment(_0x14874d[_0xd199('0x40')])[_0xd199('0x2f')](_0xd199('0x41')),'attach':![],'attachments':[]}};if(!_0x14874d[_0xd199('0x17')]&&!_0x14874d[_0xd199('0x23')]){var _0xa85c88=_[_0xd199('0x42')](_0x14874d['attachments'],{'contentType':_0xd199('0x43')});if(_0xa85c88['length']){logger['info'](util[_0xd199('0x2f')](_0xd199('0x44'),_0x14874d[_0xd199('0x3f')]));tnef[_0xd199('0x45')](_[_0xd199('0x46')](_0xa85c88)['content'],function(_0x3ed4e6,_0x3d34c8){if(_0x3d34c8){_0x14874d['html']=_0x3d34c8[_0xd199('0x47')]||_0xd199('0x48');if(_0x3d34c8['Attachments']){for(var _0x3389c5=0x0;_0x3389c5<_0x3d34c8[_0xd199('0x49')][_0xd199('0x11')];_0x3389c5++){var _0x3218e8=_0x3d34c8[_0xd199('0x49')][_0x3389c5];_0x12ec54[_0xd199('0x25')][_0xd199('0x1a')][_0xd199('0x1c')]({'filename':_0x3218e8[_0xd199('0x4a')],'content':Buffer[_0xd199('0x3d')](_0x3218e8['Data'])});}}}_0x2dbd25(parseEmail(_0x54dcd4,_0x14874d,_0x12ec54));});}else{_0x14874d[_0xd199('0x17')]=_0xd199('0x48');_0x2dbd25(parseEmail(_0x54dcd4,_0x14874d,_0x12ec54));}}else{_0x2dbd25(parseEmail(_0x54dcd4,_0x14874d,_0x12ec54));}};exports[_0xd199('0x4b')]=function(_0x59bf49){switch(_0x59bf49){case _0xd199('0x4c'):return'imap.gmail.com';case _0xd199('0x4d'):return _0xd199('0x4e');case'hotmail':return _0xd199('0x4f');case _0xd199('0x50'):return _0xd199('0x51');}return'127.0.0.1';};
\ No newline at end of file