Built motion from commit 3c2ce842.|2.6.31
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index e53b042..4a43a54 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0xc793=['lodash','squel','crypto','jsforce','desk.js','querystring','papaparse','ioredis','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/license/util','../../mysqldb','redis','defaults','localhost','socket.io-emitter','./mailMessage.socket','register','jayson/promise','client','http','then','info','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','MailMessage,\x20%s,\x20%s','message','result','sendStatus','status','json','offset','undefined','limit','count','set','Content-Range','apply','update','destroy','stack','name','index','map','rawAttributes','fieldName','type','key','keys','query','filters','intersection','model','attributes','fields','length','hasOwnProperty','nolimit','order','sort','where','merge','VIRTUAL','filter','options','MailMessage','includeAll','include','findAll','rows','show','params','find','body','catch','describe','create','out','secret','split','MailAccount','MailAccountId','CmList','List','CmContact','Contacts','updatedAt','DESC','Smtp','service','host','port','secure','authentication','auth','user','pass','attachments','join','server/files/attachments','basename','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','mail-interactions','accept','mail','read','readAt','UserId','agent','Contact','get','MailInteraction','MailInteractionId','read1stAt','interaction','null','AcceptMessage','acceptMessage','manual','interface','channel','EventManager','acceptmessage','reject','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','event','rejectmessage','download','unix','root','server','tmp','message-%s.eml','bcc','subject','Attachments','from','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','push','readFileSync','build','writeFileSync','log','unlinkSync','eml-format','rimraf','zip-dir','request-promise','bluebird','path','sox','to-csv','ejs'];(function(_0x1a7846,_0x59723e){var _0x48049=function(_0x203ff6){while(--_0x203ff6){_0x1a7846['push'](_0x1a7846['shift']());}};_0x48049(++_0x59723e);}(_0xc793,0xa2));var _0x3c79=function(_0x323a2e,_0x3c0082){_0x323a2e=_0x323a2e-0x0;var _0x2a0b2c=_0xc793[_0x323a2e];return _0x2a0b2c;};'use strict';var emlformat=require(_0x3c79('0x0'));var rimraf=require(_0x3c79('0x1'));var zipdir=require(_0x3c79('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x3c79('0x3'));var moment=require('moment');var BPromise=require(_0x3c79('0x4'));var Mustache=require('mustache');var util=require('util');var path=require(_0x3c79('0x5'));var sox=require(_0x3c79('0x6'));var csv=require(_0x3c79('0x7'));var ejs=require(_0x3c79('0x8'));var fs=require('fs');var fs_extra=require('fs-extra');var _=require(_0x3c79('0x9'));var squel=require(_0x3c79('0xa'));var crypto=require(_0x3c79('0xb'));var jsforce=require(_0x3c79('0xc'));var deskjs=require(_0x3c79('0xd'));var toCsv=require(_0x3c79('0x7'));var querystring=require(_0x3c79('0xe'));var Papa=require(_0x3c79('0xf'));var Redis=require(_0x3c79('0x10'));var authService=require('../../components/auth/service');var qs=require(_0x3c79('0x11'));var as=require(_0x3c79('0x12'));var hardwareService=require(_0x3c79('0x13'));var logger=require(_0x3c79('0x14'))(_0x3c79('0x15'));var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x3c79('0x16'));var db=require(_0x3c79('0x17'))['db'];config[_0x3c79('0x18')]=_[_0x3c79('0x19')](config[_0x3c79('0x18')],{'host':_0x3c79('0x1a'),'port':0x18eb});var socket=require(_0x3c79('0x1b'))(new Redis(config[_0x3c79('0x18')]));require(_0x3c79('0x1c'))[_0x3c79('0x1d')](socket);var jayson=require(_0x3c79('0x1e'));var client=jayson[_0x3c79('0x1f')][_0x3c79('0x20')]({'port':0x232c});var client9003=jayson[_0x3c79('0x1f')][_0x3c79('0x20')]({'port':0x232b});var client9002=jayson[_0x3c79('0x1f')][_0x3c79('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x1b75ff,_0xb1837e,_0x14ec9b,_0x25a562){return new BPromise(function(_0x39fb0d,_0x1de330){var _0x39d062=_0x25a562||client;return _0x39d062['request'](_0x1b75ff,_0x14ec9b)[_0x3c79('0x21')](function(_0x262bb8){logger[_0x3c79('0x22')]('MailMessage,\x20%s,\x20%s',_0xb1837e,_0x3c79('0x23'));logger[_0x3c79('0x24')](_0x3c79('0x25'),_0xb1837e,'request\x20sent',JSON[_0x3c79('0x26')](_0x262bb8));if(_0x262bb8['error']){if(_0x262bb8[_0x3c79('0x27')][_0x3c79('0x28')]===0x1f4){logger[_0x3c79('0x27')](_0x3c79('0x29'),_0xb1837e,_0x262bb8[_0x3c79('0x27')]['message']);return _0x1de330(_0x262bb8['error'][_0x3c79('0x2a')]);}logger[_0x3c79('0x27')]('MailMessage,\x20%s,\x20%s',_0xb1837e,_0x262bb8[_0x3c79('0x27')][_0x3c79('0x2a')]);return _0x39fb0d(_0x262bb8[_0x3c79('0x27')]['message']);}else{logger[_0x3c79('0x22')](_0x3c79('0x29'),_0xb1837e,_0x3c79('0x23'));_0x39fb0d(_0x262bb8[_0x3c79('0x2b')]['message']);}})['catch'](function(_0x2eb39e){logger['error'](_0x3c79('0x29'),_0xb1837e,_0x2eb39e);_0x1de330(_0x2eb39e);});});}function respondWithStatusCode(_0x16653d,_0x2765b5){_0x2765b5=_0x2765b5||0xcc;return function(_0xb93d3b){if(_0xb93d3b){return _0x16653d[_0x3c79('0x2c')](_0x2765b5);}return _0x16653d['status'](_0x2765b5)['end']();};}function respondWithResult(_0x90a297,_0x4ff995){_0x4ff995=_0x4ff995||0xc8;return function(_0x25d8a){if(_0x25d8a){return _0x90a297[_0x3c79('0x2d')](_0x4ff995)[_0x3c79('0x2e')](_0x25d8a);}};}function respondWithFilteredResult(_0x55572d,_0x810c3b){return function(_0x2b1745){if(_0x2b1745){var _0x373aa7=typeof _0x810c3b[_0x3c79('0x2f')]===_0x3c79('0x30')&&typeof _0x810c3b[_0x3c79('0x31')]===_0x3c79('0x30');var _0x48b63d=_0x2b1745['count'];var _0x34306d=_0x373aa7?0x0:_0x810c3b[_0x3c79('0x2f')];var _0x22221a=_0x373aa7?_0x2b1745[_0x3c79('0x32')]:_0x810c3b[_0x3c79('0x2f')]+_0x810c3b[_0x3c79('0x31')];var _0x2cab2a;if(_0x22221a>=_0x48b63d){_0x22221a=_0x48b63d;_0x2cab2a=0xc8;}else{_0x2cab2a=0xce;}_0x55572d['status'](_0x2cab2a);return _0x55572d[_0x3c79('0x33')](_0x3c79('0x34'),_0x34306d+'-'+_0x22221a+'/'+_0x48b63d)[_0x3c79('0x2e')](_0x2b1745);}return null;};}function patchUpdates(_0x33315b){return function(_0xb71b5){try{jsonpatch[_0x3c79('0x35')](_0xb71b5,_0x33315b,!![]);}catch(_0x91f9af){return BPromise['reject'](_0x91f9af);}return _0xb71b5['save']();};}function saveUpdates(_0x458e6b,_0x329d4f){return function(_0x12b349){if(_0x12b349){return _0x12b349[_0x3c79('0x36')](_0x458e6b)[_0x3c79('0x21')](function(_0x4aa176){return _0x4aa176;});}return null;};}function removeEntity(_0x29e8c5,_0x488e3f){return function(_0x43c22f){if(_0x43c22f){return _0x43c22f[_0x3c79('0x37')]()[_0x3c79('0x21')](function(){_0x29e8c5[_0x3c79('0x2d')](0xcc)['end']();});}};}function handleEntityNotFound(_0x3a2777,_0x50c574){return function(_0x1eb481){if(!_0x1eb481){_0x3a2777[_0x3c79('0x2c')](0x194);}return _0x1eb481;};}function handleError(_0x51f754,_0x5b346f){_0x5b346f=_0x5b346f||0x1f4;return function(_0x140422){logger[_0x3c79('0x27')](_0x140422[_0x3c79('0x38')]);if(_0x140422[_0x3c79('0x39')]){delete _0x140422[_0x3c79('0x39')];}_0x51f754['status'](_0x5b346f)['send'](_0x140422);};}exports[_0x3c79('0x3a')]=function(_0x4335f0,_0x2e235a){var _0x414cd1={},_0x1fc061={},_0x2436cf={'count':0x0,'rows':[]};var _0x2f061f=_[_0x3c79('0x3b')](db['MailMessage'][_0x3c79('0x3c')],function(_0x1653c0){return{'name':_0x1653c0[_0x3c79('0x3d')],'type':_0x1653c0[_0x3c79('0x3e')][_0x3c79('0x3f')]};});_0x1fc061['model']=_['map'](_0x2f061f,_0x3c79('0x39'));_0x1fc061['query']=_[_0x3c79('0x40')](_0x4335f0[_0x3c79('0x41')]);_0x1fc061[_0x3c79('0x42')]=_[_0x3c79('0x43')](_0x1fc061[_0x3c79('0x44')],_0x1fc061[_0x3c79('0x41')]);_0x414cd1[_0x3c79('0x45')]=_['intersection'](_0x1fc061['model'],qs[_0x3c79('0x46')](_0x4335f0[_0x3c79('0x41')]['fields']));_0x414cd1[_0x3c79('0x45')]=_0x414cd1[_0x3c79('0x45')][_0x3c79('0x47')]?_0x414cd1[_0x3c79('0x45')]:_0x1fc061[_0x3c79('0x44')];if(!_0x4335f0[_0x3c79('0x41')][_0x3c79('0x48')](_0x3c79('0x49'))){_0x414cd1['limit']=qs[_0x3c79('0x31')](_0x4335f0[_0x3c79('0x41')][_0x3c79('0x31')]);_0x414cd1[_0x3c79('0x2f')]=qs[_0x3c79('0x2f')](_0x4335f0[_0x3c79('0x41')]['offset']);}_0x414cd1[_0x3c79('0x4a')]=qs[_0x3c79('0x4b')](_0x4335f0[_0x3c79('0x41')][_0x3c79('0x4b')]);_0x414cd1[_0x3c79('0x4c')]=qs[_0x3c79('0x42')](_['pick'](_0x4335f0[_0x3c79('0x41')],_0x1fc061[_0x3c79('0x42')]),_0x2f061f);if(_0x4335f0[_0x3c79('0x41')]['filter']){_0x414cd1[_0x3c79('0x4c')]=_[_0x3c79('0x4d')](_0x414cd1[_0x3c79('0x4c')],{'$or':_[_0x3c79('0x3b')](_0x2f061f,function(_0x360a76){if(_0x360a76['type']!==_0x3c79('0x4e')){var _0x5eeabf={};_0x5eeabf[_0x360a76[_0x3c79('0x39')]]={'$like':'%'+_0x4335f0[_0x3c79('0x41')][_0x3c79('0x4f')]+'%'};return _0x5eeabf;}})});}_0x414cd1=_[_0x3c79('0x4d')]({},_0x414cd1,_0x4335f0[_0x3c79('0x50')]);var _0x516e47={'where':_0x414cd1[_0x3c79('0x4c')]};return db[_0x3c79('0x51')][_0x3c79('0x32')](_0x516e47)[_0x3c79('0x21')](function(_0x289aaf){_0x2436cf[_0x3c79('0x32')]=_0x289aaf;if(_0x4335f0[_0x3c79('0x41')][_0x3c79('0x52')]){_0x414cd1[_0x3c79('0x53')]=[{'all':!![]}];}return db[_0x3c79('0x51')][_0x3c79('0x54')](_0x414cd1);})[_0x3c79('0x21')](function(_0x17c0d2){_0x2436cf[_0x3c79('0x55')]=_0x17c0d2;return _0x2436cf;})[_0x3c79('0x21')](respondWithFilteredResult(_0x2e235a,_0x414cd1))['catch'](handleError(_0x2e235a,null));};exports[_0x3c79('0x56')]=function(_0x3f4dd7,_0x21b5bc){var _0x221457={'raw':!![],'where':{'id':_0x3f4dd7[_0x3c79('0x57')]['id']}},_0x561717={};_0x561717[_0x3c79('0x44')]=_['keys'](db[_0x3c79('0x51')][_0x3c79('0x3c')]);_0x561717[_0x3c79('0x41')]=_[_0x3c79('0x40')](_0x3f4dd7[_0x3c79('0x41')]);_0x561717[_0x3c79('0x42')]=_['intersection'](_0x561717[_0x3c79('0x44')],_0x561717['query']);_0x221457[_0x3c79('0x45')]=_['intersection'](_0x561717[_0x3c79('0x44')],qs[_0x3c79('0x46')](_0x3f4dd7[_0x3c79('0x41')][_0x3c79('0x46')]));_0x221457[_0x3c79('0x45')]=_0x221457[_0x3c79('0x45')][_0x3c79('0x47')]?_0x221457[_0x3c79('0x45')]:_0x561717[_0x3c79('0x44')];if(_0x3f4dd7[_0x3c79('0x41')][_0x3c79('0x52')]){_0x221457['include']=[{'all':!![]}];}_0x221457=_[_0x3c79('0x4d')]({},_0x221457,_0x3f4dd7[_0x3c79('0x50')]);return db[_0x3c79('0x51')][_0x3c79('0x58')](_0x221457)[_0x3c79('0x21')](handleEntityNotFound(_0x21b5bc,null))[_0x3c79('0x21')](respondWithResult(_0x21b5bc,null))['catch'](handleError(_0x21b5bc,null));};exports[_0x3c79('0x36')]=function(_0x441acd,_0x2586f5){if(_0x441acd[_0x3c79('0x59')]['id']){delete _0x441acd[_0x3c79('0x59')]['id'];}return db[_0x3c79('0x51')]['find']({'where':{'id':_0x441acd[_0x3c79('0x57')]['id']}})[_0x3c79('0x21')](handleEntityNotFound(_0x2586f5,null))[_0x3c79('0x21')](saveUpdates(_0x441acd['body'],null))['then'](respondWithResult(_0x2586f5,null))[_0x3c79('0x5a')](handleError(_0x2586f5,null));};exports[_0x3c79('0x37')]=function(_0x5466a6,_0x45e95a){return db[_0x3c79('0x51')]['find']({'where':{'id':_0x5466a6['params']['id']}})[_0x3c79('0x21')](handleEntityNotFound(_0x45e95a,null))[_0x3c79('0x21')](removeEntity(_0x45e95a,null))[_0x3c79('0x5a')](handleError(_0x45e95a,null));};exports[_0x3c79('0x5b')]=function(_0x3f06d8,_0xd63a78){return db[_0x3c79('0x51')]['describe']()['then'](respondWithResult(_0xd63a78,null))['catch'](handleError(_0xd63a78,null));};exports[_0x3c79('0x5c')]=function(_0x584b51,_0xc8e0b2){return db[_0x3c79('0x51')][_0x3c79('0x5c')](_0x584b51[_0x3c79('0x59')])[_0x3c79('0x21')](function(_0x3dc3ca){if(_0x3dc3ca){if(_0x3dc3ca['direction']===_0x3c79('0x5d')&&!_0x3dc3ca[_0x3c79('0x5e')]){var _0x45bd4f,_0x6ead67,_0x1b021c;if(_0x584b51[_0x3c79('0x59')]['to']){_0x6ead67=_0x584b51[_0x3c79('0x59')]['to'][_0x3c79('0x5f')](',')[0x0];}return db[_0x3c79('0x60')]['findOne']({'where':{'id':_0x3dc3ca[_0x3c79('0x61')]},'include':[{'model':db[_0x3c79('0x62')],'as':_0x3c79('0x63'),'include':[{'model':db[_0x3c79('0x64')],'as':_0x3c79('0x65'),'where':{'email':_0x6ead67},'limit':0x1,'order':[[_0x3c79('0x66'),_0x3c79('0x67')]]}]},{'model':db['MailServerOut'],'as':_0x3c79('0x68'),'raw':!![]}]})[_0x3c79('0x21')](function(_0x3110fa){_0x45bd4f=_0x3110fa;if(_0x45bd4f&&_0x45bd4f[_0x3c79('0x68')]){var _0x28c9e0={'tls':{'rejectUnauthorized':![]}};if(_['isNil'](_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x69')])){_0x28c9e0[_0x3c79('0x6a')]=_0x45bd4f['Smtp'][_0x3c79('0x6a')];_0x28c9e0[_0x3c79('0x6b')]=_0x45bd4f['Smtp'][_0x3c79('0x6b')];_0x28c9e0[_0x3c79('0x6c')]=_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x6c')];if(_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x6d')]){_0x28c9e0[_0x3c79('0x6e')]={'user':_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x6f')],'pass':_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x70')]};}}else{_0x28c9e0['service']=_0x45bd4f[_0x3c79('0x68')]['service'];_0x28c9e0[_0x3c79('0x6e')]={'user':_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x6f')],'pass':_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x70')]};_0x28c9e0[_0x3c79('0x6c')]=_0x45bd4f[_0x3c79('0x68')][_0x3c79('0x6c')];}if(_0x584b51[_0x3c79('0x59')]['attachments']&&_0x584b51[_0x3c79('0x59')][_0x3c79('0x71')][_0x3c79('0x47')]){for(var _0x1bce42=0x0;_0x1bce42<_0x584b51[_0x3c79('0x59')]['attachments']['length'];_0x1bce42+=0x1){_0x584b51[_0x3c79('0x59')][_0x3c79('0x71')][_0x1bce42]={'filename':_0x584b51[_0x3c79('0x59')][_0x3c79('0x71')][_0x1bce42][_0x3c79('0x39')],'path':path[_0x3c79('0x72')](config['root'],_0x3c79('0x73'),_0x584b51[_0x3c79('0x59')][_0x3c79('0x71')][_0x1bce42][_0x3c79('0x74')])};}}_0x1b021c={'account':_0x28c9e0,'message':_0x584b51[_0x3c79('0x59')]};return;}})['then'](function(){if(_0x45bd4f[_0x3c79('0x63')]){if(_0x45bd4f[_0x3c79('0x63')][_0x3c79('0x65')][_0x3c79('0x47')]){return _0x45bd4f[_0x3c79('0x63')][_0x3c79('0x65')][0x0];}else{return db['CmContact'][_0x3c79('0x5c')](_['defaults'](_0x584b51[_0x3c79('0x59')],{'firstName':_0x584b51['body']['to'],'email':_0x584b51[_0x3c79('0x59')]['to'],'phone':_0x584b51[_0x3c79('0x59')]['to'],'ListId':_0x45bd4f[_0x3c79('0x75')]}));}}else{throw new Error(_0x3c79('0x76'));}})['then'](function(){if(_0x1b021c){return respondWithRpcPromise(_0x3c79('0x77'),_0x3c79('0x78'),_0x1b021c,client9003)[_0x3c79('0x21')](function(_0xfea1dd){return _0x3dc3ca['update']({'read':!![],'messageId':_0xfea1dd[_0x3c79('0x79')],'sentAt':moment()[_0x3c79('0x7a')](_0x3c79('0x7b'))});})[_0x3c79('0x5a')](function(_0x56c1e8){logger[_0x3c79('0x27')]('%s',JSON[_0x3c79('0x26')](_0x56c1e8));return _0x3dc3ca;});}return _0x3dc3ca;});}return _0x3dc3ca;}})[_0x3c79('0x21')](respondWithResult(_0xc8e0b2,0xc9))[_0x3c79('0x5a')](handleError(_0xc8e0b2,null));};var interaction_log=require(_0x3c79('0x14'))(_0x3c79('0x7c'));exports[_0x3c79('0x7d')]=function(_0x2ebaa1,_0x7f152e,_0x2d8a9b){var _0x257774={'agent':{},'channel':_0x3c79('0x7e')};if(_0x2ebaa1['body']['id']){delete _0x2ebaa1[_0x3c79('0x59')]['id'];}_0x2ebaa1[_0x3c79('0x59')][_0x3c79('0x7f')]=!![];_0x2ebaa1[_0x3c79('0x59')][_0x3c79('0x80')]=moment()[_0x3c79('0x7a')](_0x3c79('0x7b'));_0x2ebaa1[_0x3c79('0x59')][_0x3c79('0x81')]=_0x2ebaa1['body']['UserId']||_0x2ebaa1['user']['id'];_0x257774[_0x3c79('0x82')]['id']=_0x2ebaa1['body']['UserId'];return db[_0x3c79('0x51')]['find']({'where':{'id':_0x2ebaa1['params']['id'],'UserId':null},'include':[{'model':db[_0x3c79('0x64')],'as':_0x3c79('0x83')}]})[_0x3c79('0x21')](handleEntityNotFound(_0x7f152e,null))[_0x3c79('0x21')](saveUpdates(_0x2ebaa1[_0x3c79('0x59')],null))[_0x3c79('0x21')](function(_0x544b7d){if(_0x544b7d){_0x257774[_0x3c79('0x2a')]=_0x544b7d[_0x3c79('0x84')]({'plain':!![]});return db[_0x3c79('0x85')][_0x3c79('0x58')]({'where':{'id':_0x544b7d[_0x3c79('0x86')]}});}return null;})[_0x3c79('0x21')](handleEntityNotFound(_0x7f152e,null))['then'](function(_0x3621d4){if(_0x3621d4){return _0x3621d4[_0x3c79('0x36')]({'UserId':_0x2ebaa1[_0x3c79('0x59')][_0x3c79('0x81')],'read1stAt':_['isNil'](_0x3621d4[_0x3c79('0x87')])?moment()['format']('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0x3c79('0x21')](function(_0x34b45e){if(_0x34b45e){_0x257774[_0x3c79('0x88')]=_0x34b45e[_0x3c79('0x84')]({'plain':!![]});interaction_log[_0x3c79('0x22')]('[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x2ebaa1[_0x3c79('0x6f')]['id'],_0x2ebaa1['user'][_0x3c79('0x39')],_0x2ebaa1[_0x3c79('0x6f')]['role'],_0x257774[_0x3c79('0x88')]['id'],_0x2ebaa1[_0x3c79('0x59')]?JSON[_0x3c79('0x26')](_0x2ebaa1['body']):_0x3c79('0x89'));return respondWithRpcPromise(_0x3c79('0x8a'),_0x3c79('0x8b'),_0x257774);}return null;})[_0x3c79('0x21')](function(_0x2eba05){if(_0x2eba05){if(_0x2ebaa1[_0x3c79('0x59')][_0x3c79('0x8c')]){_0x257774[_0x3c79('0x2a')][_0x3c79('0x8d')]=util[_0x3c79('0x7a')]('SIP/%s',_0x2ebaa1[_0x3c79('0x6f')][_0x3c79('0x39')]);_0x257774[_0x3c79('0x2a')][_0x3c79('0x8e')]=_0x257774[_0x3c79('0x8e')];_0x257774[_0x3c79('0x2a')]['event']=_0x3c79('0x7d');return respondWithRpcPromise('EventManager',_0x3c79('0x8f'),{'event':_0x3c79('0x90'),'message':_0x257774[_0x3c79('0x2a')]},client9002)[_0x3c79('0x21')](function(){return _0x257774;});}return _0x257774;}return null;})[_0x3c79('0x21')](respondWithResult(_0x7f152e,null))[_0x3c79('0x5a')](handleError(_0x7f152e,null));};var interaction_log=require(_0x3c79('0x14'))(_0x3c79('0x7c'));exports[_0x3c79('0x91')]=function(_0x3b038a,_0x3f1b8a,_0x4d237e){var _0x5046d8={'agent':{},'channel':'mail'};if(_0x3b038a['body']['id']){delete _0x3b038a[_0x3c79('0x59')]['id'];}_0x3b038a[_0x3c79('0x59')][_0x3c79('0x81')]=_0x3b038a['body'][_0x3c79('0x81')]||_0x3b038a[_0x3c79('0x6f')]['id'];_0x5046d8[_0x3c79('0x82')]['id']=_0x3b038a[_0x3c79('0x59')][_0x3c79('0x81')];return db[_0x3c79('0x51')][_0x3c79('0x58')]({'where':{'id':_0x3b038a['params']['id'],'UserId':null}})[_0x3c79('0x21')](handleEntityNotFound(_0x3f1b8a,null))[_0x3c79('0x21')](function(_0x80b93c){if(_0x80b93c){_0x5046d8[_0x3c79('0x2a')]=_0x80b93c['get']({'plain':!![]});return db[_0x3c79('0x85')][_0x3c79('0x58')]({'where':{'id':_0x80b93c[_0x3c79('0x86')]}});}return null;})[_0x3c79('0x21')](handleEntityNotFound(_0x3f1b8a,null))[_0x3c79('0x21')](function(_0x1875e1){if(_0x1875e1){_0x5046d8[_0x3c79('0x88')]=_0x1875e1['get']({'plain':!![]});interaction_log['info'](_0x3c79('0x92'),_0x3b038a[_0x3c79('0x6f')]['id'],_0x3b038a[_0x3c79('0x6f')][_0x3c79('0x39')],_0x3b038a[_0x3c79('0x6f')][_0x3c79('0x93')],_0x5046d8['interaction']['id'],_0x3b038a[_0x3c79('0x59')]?JSON['stringify'](_0x3b038a[_0x3c79('0x59')]):_0x3c79('0x89'));return respondWithRpcPromise(_0x3c79('0x94'),_0x3c79('0x95'),_0x5046d8);}return null;})[_0x3c79('0x21')](function(_0x1159a){if(_0x1159a){_0x1159a['message'][_0x3c79('0x8d')]=util[_0x3c79('0x7a')]('SIP/%s',_0x3b038a[_0x3c79('0x6f')][_0x3c79('0x39')]);_0x1159a[_0x3c79('0x2a')][_0x3c79('0x8e')]=_0x5046d8[_0x3c79('0x8e')];_0x1159a[_0x3c79('0x2a')][_0x3c79('0x96')]=_0x3c79('0x91');respondWithRpcPromise(_0x3c79('0x8f'),_0x3c79('0x8f'),{'event':_0x3c79('0x97'),'message':_0x1159a[_0x3c79('0x2a')]},client9002);return _0x5046d8;}return null;})[_0x3c79('0x21')](respondWithResult(_0x3f1b8a,null))[_0x3c79('0x5a')](handleError(_0x3f1b8a,null));};exports[_0x3c79('0x98')]=function(_0xbf509d,_0x327768){var _0x2f8db3=moment()[_0x3c79('0x99')]()['toString']();var _0x529358=path[_0x3c79('0x72')](config[_0x3c79('0x9a')],_0x3c79('0x9b'),'files',_0x3c79('0x9c'));var _0xbd573b=path[_0x3c79('0x72')](config[_0x3c79('0x9a')],'server','files',_0x3c79('0x71'));var _0x7d7b88=util[_0x3c79('0x7a')](_0x3c79('0x9d'),_0x2f8db3);return db[_0x3c79('0x51')][_0x3c79('0x58')]({'where':{'id':_0xbf509d[_0x3c79('0x57')]['id']},'attributes':['id',_0x3c79('0x59'),'from','to','cc',_0x3c79('0x9e'),_0x3c79('0x9f'),'createdAt'],'include':_0xbf509d['query'][_0x3c79('0x71')]?[{'model':db['Attachment'],'as':_0x3c79('0xa0')}]:undefined})[_0x3c79('0x21')](handleEntityNotFound(_0x327768,null))[_0x3c79('0x21')](function(_0x10a8ee){if(_0x10a8ee){var _0x31b6ba=_0x10a8ee;var _0xee7696={'from':_0x31b6ba[_0x3c79('0xa1')],'to':_0x31b6ba['to'],'subject':_0x31b6ba[_0x3c79('0x9f')],'html':_0x31b6ba[_0x3c79('0x59')],'headers':{'Date':moment(_0x31b6ba['createdAt'])[_0x3c79('0x7a')](_0x3c79('0xa2'))},'attachments':[]};if(_0x10a8ee['cc']){_0xee7696[_0x3c79('0xa3')]['Cc']=_0x10a8ee['cc'];}if(_0x10a8ee[_0x3c79('0x9e')]){_0xee7696[_0x3c79('0xa3')][_0x3c79('0xa4')]=_0x10a8ee[_0x3c79('0x9e')];}return new BPromise(function(_0xcfe682,_0x1d3df4){if(_0x10a8ee[_0x3c79('0xa0')]){for(var _0x1c5377=0x0;_0x1c5377<_0x10a8ee[_0x3c79('0xa0')]['length'];_0x1c5377++){var _0x22bc1e=_0x10a8ee[_0x3c79('0xa0')][_0x1c5377];var _0x319553=path[_0x3c79('0x72')](_0xbd573b,_0x22bc1e[_0x3c79('0x74')]);if(fs['existsSync'](_0x319553)){_0xee7696['attachments'][_0x3c79('0xa5')]({'name':_0x22bc1e[_0x3c79('0x39')],'contentType':_0x22bc1e[_0x3c79('0x3e')],'data':fs[_0x3c79('0xa6')](_0x319553)});}}}emlformat[_0x3c79('0xa7')](_0xee7696,function(_0x52408f,_0x3d706c){if(_0x52408f)return _0x1d3df4(_0x52408f);fs[_0x3c79('0xa8')](path[_0x3c79('0x72')](_0x529358,_0x7d7b88),_0x3d706c);return _0xcfe682(_0x3d706c);});});}})['then'](function(_0x335270){if(_0x335270){return _0x327768[_0x3c79('0x98')](path[_0x3c79('0x72')](_0x529358,_0x7d7b88),_0x7d7b88,function(_0x32b791){if(_0x32b791){console[_0x3c79('0xa9')]('err',_0x32b791);}else{fs[_0x3c79('0xaa')](path[_0x3c79('0x72')](_0x529358,_0x7d7b88));}});}})[_0x3c79('0x5a')](handleError(_0x327768,null));};
\ No newline at end of file
+var _0xc26a=['map','MailMessage','fieldName','type','key','model','query','keys','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','filter','where','merge','VIRTUAL','includeAll','include','findAll','rows','show','params','options','find','body','destroy','describe','create','direction','out','secret','split','MailAccount','findOne','CmList','List','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','join','root','basename','CmContact','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','acceptMessage','reject','UserId','user','agent','get','MailInteraction','MailInteractionId','interaction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','QueryTypes','contact','User','email','interface','channel','event','fromString','EventManager','rejectmessage','unix','toString','server','files','from','bcc','subject','createdAt','Attachment','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','readFileSync','writeFileSync','download','unlinkSync','moment','util','path','lodash','ioredis','html-to-text','../../components/interaction/service','../../components/parsers/qs','../../config/logger','api','../../mysqldb','redis','defaults','localhost','html-entities','./mailMessage.socket','register','jayson/promise','client','http','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','stringify','error','code','message','result','catch','status','json','offset','undefined','limit','count','set','Content-Range','update','then','end','stack','name','send','index'];(function(_0x5e9326,_0x28038a){var _0x3654b6=function(_0x43b044){while(--_0x43b044){_0x5e9326['push'](_0x5e9326['shift']());}};_0x3654b6(++_0x28038a);}(_0xc26a,0x103));var _0xac26=function(_0x1177d5,_0x22b649){_0x1177d5=_0x1177d5-0x0;var _0xc3ddc2=_0xc26a[_0x1177d5];return _0xc3ddc2;};'use strict';var emlformat=require('eml-format');var moment=require(_0xac26('0x0'));var util=require(_0xac26('0x1'));var path=require(_0xac26('0x2'));var fs=require('fs');var _=require(_0xac26('0x3'));var Redis=require(_0xac26('0x4'));var htmlToText=require(_0xac26('0x5'));var interactionService=require(_0xac26('0x6'));var qs=require(_0xac26('0x7'));var logger=require(_0xac26('0x8'))(_0xac26('0x9'));var interaction_log=require('../../config/logger')('mail-interactions');var config=require('../../config/environment');var db=require(_0xac26('0xa'))['db'];config[_0xac26('0xb')]=_[_0xac26('0xc')](config[_0xac26('0xb')],{'host':_0xac26('0xd'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xac26('0xb')]));var htmlEntities=require(_0xac26('0xe'));require(_0xac26('0xf'))[_0xac26('0x10')](socket);var jayson=require(_0xac26('0x11'));var client=jayson[_0xac26('0x12')]['http']({'port':0x232c});var client9003=jayson[_0xac26('0x12')][_0xac26('0x13')]({'port':0x232b});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x35602a,_0xa659e3,_0x4d4162,_0x425380){return new Promise(function(_0x27106e,_0x4a9c5d){var _0x8ef42d=_0x425380||client;return _0x8ef42d['request'](_0x35602a,_0x4d4162)['then'](function(_0x4cbfad){logger[_0xac26('0x14')](_0xac26('0x15'),_0xa659e3,_0xac26('0x16'));logger[_0xac26('0x17')]('MailMessage,\x20%s,\x20%s,\x20%s',_0xa659e3,_0xac26('0x16'),JSON[_0xac26('0x18')](_0x4cbfad));if(_0x4cbfad[_0xac26('0x19')]){if(_0x4cbfad['error'][_0xac26('0x1a')]===0x1f4){logger['error']('MailMessage,\x20%s,\x20%s',_0xa659e3,_0x4cbfad[_0xac26('0x19')]['message']);return _0x4a9c5d(_0x4cbfad['error'][_0xac26('0x1b')]);}logger['error'](_0xac26('0x15'),_0xa659e3,_0x4cbfad[_0xac26('0x19')][_0xac26('0x1b')]);return _0x27106e(_0x4cbfad[_0xac26('0x19')][_0xac26('0x1b')]);}else{logger[_0xac26('0x14')]('MailMessage,\x20%s,\x20%s',_0xa659e3,'request\x20sent');_0x27106e(_0x4cbfad[_0xac26('0x1c')][_0xac26('0x1b')]);}})[_0xac26('0x1d')](function(_0x2bd35f){logger[_0xac26('0x19')](_0xac26('0x15'),_0xa659e3,_0x2bd35f);_0x4a9c5d(_0x2bd35f);});});}function respondWithResult(_0x533cd6,_0x55c3ef){_0x55c3ef=_0x55c3ef||0xc8;return function(_0x27edd){if(_0x27edd){return _0x533cd6[_0xac26('0x1e')](_0x55c3ef)[_0xac26('0x1f')](_0x27edd);}};}function respondWithFilteredResult(_0x3f2219,_0x56e1f4){return function(_0x429c08){if(_0x429c08){var _0x17851c=typeof _0x56e1f4[_0xac26('0x20')]===_0xac26('0x21')&&typeof _0x56e1f4[_0xac26('0x22')]===_0xac26('0x21');var _0x50e88c=_0x429c08[_0xac26('0x23')];var _0x39f82b=_0x17851c?0x0:_0x56e1f4[_0xac26('0x20')];var _0x934c71=_0x17851c?_0x429c08[_0xac26('0x23')]:_0x56e1f4[_0xac26('0x20')]+_0x56e1f4[_0xac26('0x22')];var _0x280b97;if(_0x934c71>=_0x50e88c){_0x934c71=_0x50e88c;_0x280b97=0xc8;}else{_0x280b97=0xce;}_0x3f2219[_0xac26('0x1e')](_0x280b97);return _0x3f2219[_0xac26('0x24')](_0xac26('0x25'),_0x39f82b+'-'+_0x934c71+'/'+_0x50e88c)['json'](_0x429c08);}return null;};}function saveUpdates(_0x31aeed){return function(_0x537fd3){if(_0x537fd3){return _0x537fd3[_0xac26('0x26')](_0x31aeed)[_0xac26('0x27')](function(_0xbb652f){return _0xbb652f;});}return null;};}function removeEntity(_0x214f45){return function(_0x49a3a5){if(_0x49a3a5){return _0x49a3a5['destroy']()[_0xac26('0x27')](function(){_0x214f45[_0xac26('0x1e')](0xcc)[_0xac26('0x28')]();});}};}function handleEntityNotFound(_0x7dfa67){return function(_0x3b3fef){if(!_0x3b3fef){_0x7dfa67['sendStatus'](0x194);}return _0x3b3fef;};}function handleError(_0x26ec81,_0x521c98){_0x521c98=_0x521c98||0x1f4;return function(_0x5c6662){logger[_0xac26('0x19')](_0x5c6662[_0xac26('0x29')]);if(_0x5c6662[_0xac26('0x2a')]){delete _0x5c6662[_0xac26('0x2a')];}_0x26ec81['status'](_0x521c98)[_0xac26('0x2b')](_0x5c6662);};}exports[_0xac26('0x2c')]=function(_0x45b653,_0x4014f8){var _0xb5009f={},_0x1b33f3={},_0x3d0912={'count':0x0,'rows':[]};var _0x4c84ce=_[_0xac26('0x2d')](db[_0xac26('0x2e')]['rawAttributes'],function(_0x8ea2de){return{'name':_0x8ea2de[_0xac26('0x2f')],'type':_0x8ea2de[_0xac26('0x30')][_0xac26('0x31')]};});_0x1b33f3[_0xac26('0x32')]=_[_0xac26('0x2d')](_0x4c84ce,_0xac26('0x2a'));_0x1b33f3[_0xac26('0x33')]=_[_0xac26('0x34')](_0x45b653[_0xac26('0x33')]);_0x1b33f3[_0xac26('0x35')]=_['intersection'](_0x1b33f3[_0xac26('0x32')],_0x1b33f3[_0xac26('0x33')]);_0xb5009f[_0xac26('0x36')]=_[_0xac26('0x37')](_0x1b33f3[_0xac26('0x32')],qs[_0xac26('0x38')](_0x45b653[_0xac26('0x33')][_0xac26('0x38')]));_0xb5009f['attributes']=_0xb5009f[_0xac26('0x36')][_0xac26('0x39')]?_0xb5009f[_0xac26('0x36')]:_0x1b33f3['model'];if(!_0x45b653[_0xac26('0x33')][_0xac26('0x3a')](_0xac26('0x3b'))){_0xb5009f['limit']=qs[_0xac26('0x22')](_0x45b653[_0xac26('0x33')][_0xac26('0x22')]);_0xb5009f['offset']=qs[_0xac26('0x20')](_0x45b653[_0xac26('0x33')]['offset']);}_0xb5009f[_0xac26('0x3c')]=qs[_0xac26('0x3d')](_0x45b653[_0xac26('0x33')]['sort']);_0xb5009f['where']=qs['filters'](_['pick'](_0x45b653[_0xac26('0x33')],_0x1b33f3[_0xac26('0x35')]),_0x4c84ce);if(_0x45b653[_0xac26('0x33')][_0xac26('0x3e')]){_0xb5009f[_0xac26('0x3f')]=_[_0xac26('0x40')](_0xb5009f[_0xac26('0x3f')],{'$or':_[_0xac26('0x2d')](_0x4c84ce,function(_0x8693f7){if(_0x8693f7[_0xac26('0x30')]!==_0xac26('0x41')){var _0x35df68={};_0x35df68[_0x8693f7[_0xac26('0x2a')]]={'$like':'%'+_0x45b653[_0xac26('0x33')][_0xac26('0x3e')]+'%'};return _0x35df68;}})});}_0xb5009f=_['merge']({},_0xb5009f,_0x45b653['options']);var _0x34ac9d={'where':_0xb5009f['where']};return db[_0xac26('0x2e')][_0xac26('0x23')](_0x34ac9d)[_0xac26('0x27')](function(_0x217f61){_0x3d0912[_0xac26('0x23')]=_0x217f61;if(_0x45b653[_0xac26('0x33')][_0xac26('0x42')]){_0xb5009f[_0xac26('0x43')]=[{'all':!![]}];}return db['MailMessage'][_0xac26('0x44')](_0xb5009f);})[_0xac26('0x27')](function(_0x1294ee){_0x3d0912[_0xac26('0x45')]=_0x1294ee;return _0x3d0912;})[_0xac26('0x27')](respondWithFilteredResult(_0x4014f8,_0xb5009f))[_0xac26('0x1d')](handleError(_0x4014f8,null));};exports[_0xac26('0x46')]=function(_0x5b52c0,_0x53732c){var _0x51ddcc={'raw':!![],'where':{'id':_0x5b52c0[_0xac26('0x47')]['id']}},_0x4fdfc1={};_0x4fdfc1[_0xac26('0x32')]=_[_0xac26('0x34')](db['MailMessage']['rawAttributes']);_0x4fdfc1[_0xac26('0x33')]=_[_0xac26('0x34')](_0x5b52c0[_0xac26('0x33')]);_0x4fdfc1[_0xac26('0x35')]=_[_0xac26('0x37')](_0x4fdfc1[_0xac26('0x32')],_0x4fdfc1[_0xac26('0x33')]);_0x51ddcc[_0xac26('0x36')]=_[_0xac26('0x37')](_0x4fdfc1[_0xac26('0x32')],qs[_0xac26('0x38')](_0x5b52c0[_0xac26('0x33')][_0xac26('0x38')]));_0x51ddcc['attributes']=_0x51ddcc[_0xac26('0x36')][_0xac26('0x39')]?_0x51ddcc['attributes']:_0x4fdfc1[_0xac26('0x32')];if(_0x5b52c0[_0xac26('0x33')][_0xac26('0x42')]){_0x51ddcc[_0xac26('0x43')]=[{'all':!![]}];}_0x51ddcc=_[_0xac26('0x40')]({},_0x51ddcc,_0x5b52c0[_0xac26('0x48')]);return db[_0xac26('0x2e')][_0xac26('0x49')](_0x51ddcc)[_0xac26('0x27')](handleEntityNotFound(_0x53732c,null))[_0xac26('0x27')](respondWithResult(_0x53732c,null))[_0xac26('0x1d')](handleError(_0x53732c,null));};exports['update']=function(_0x12bf7a,_0x270ee5){if(_0x12bf7a[_0xac26('0x4a')]['id']){delete _0x12bf7a[_0xac26('0x4a')]['id'];}return db['MailMessage'][_0xac26('0x49')]({'where':{'id':_0x12bf7a[_0xac26('0x47')]['id']}})[_0xac26('0x27')](handleEntityNotFound(_0x270ee5,null))[_0xac26('0x27')](saveUpdates(_0x12bf7a[_0xac26('0x4a')],null))[_0xac26('0x27')](respondWithResult(_0x270ee5,null))[_0xac26('0x1d')](handleError(_0x270ee5,null));};exports[_0xac26('0x4b')]=function(_0x2aa7ae,_0xa2ff5b){return db[_0xac26('0x2e')]['find']({'where':{'id':_0x2aa7ae[_0xac26('0x47')]['id']}})[_0xac26('0x27')](handleEntityNotFound(_0xa2ff5b,null))['then'](removeEntity(_0xa2ff5b,null))[_0xac26('0x1d')](handleError(_0xa2ff5b,null));};exports[_0xac26('0x4c')]=function(_0xdd33b8,_0x2f8fa4){return db[_0xac26('0x2e')][_0xac26('0x4c')]()[_0xac26('0x27')](respondWithResult(_0x2f8fa4,null))[_0xac26('0x1d')](handleError(_0x2f8fa4,null));};exports[_0xac26('0x4d')]=function(_0x368b3a,_0x551132){return db[_0xac26('0x2e')][_0xac26('0x4d')](_0x368b3a[_0xac26('0x4a')])[_0xac26('0x27')](function(_0x57f037){if(_0x57f037){if(_0x57f037[_0xac26('0x4e')]===_0xac26('0x4f')&&!_0x57f037[_0xac26('0x50')]){var _0x164bac,_0x3eee4c,_0x103bd5;if(_0x368b3a[_0xac26('0x4a')]['to']){_0x3eee4c=_0x368b3a['body']['to'][_0xac26('0x51')](',')[0x0];}return db[_0xac26('0x52')][_0xac26('0x53')]({'where':{'id':_0x57f037['MailAccountId']},'include':[{'model':db[_0xac26('0x54')],'as':_0xac26('0x55'),'include':[{'model':db['CmContact'],'as':_0xac26('0x56'),'where':{'email':_0x3eee4c},'limit':0x1,'order':[[_0xac26('0x57'),_0xac26('0x58')]]}]},{'model':db[_0xac26('0x59')],'as':_0xac26('0x5a'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':_0xac26('0x5b'),'raw':!![]}]}]})[_0xac26('0x27')](function(_0x25d166){_0x164bac=_0x25d166;if(!_0x164bac||!_0x164bac[_0xac26('0x5a')])return;var _0x25a34f=_0x164bac[_0xac26('0x5c')]();if(_0x368b3a['body']['attachments']&&_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0xac26('0x39')]){for(var _0x23b03b=0x0;_0x23b03b<_0x368b3a['body'][_0xac26('0x5d')][_0xac26('0x39')];_0x23b03b+=0x1){_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0x23b03b]={'filename':_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0x23b03b]['name'],'path':path[_0xac26('0x5e')](config[_0xac26('0x5f')],'server/files/attachments',_0x368b3a[_0xac26('0x4a')][_0xac26('0x5d')][_0x23b03b][_0xac26('0x60')])};}}_0x103bd5={'account':_0x25a34f,'message':_0x368b3a[_0xac26('0x4a')]};return;})[_0xac26('0x27')](function(){if(_0x164bac[_0xac26('0x55')]){if(_0x164bac['List']['Contacts'][_0xac26('0x39')]){return _0x164bac[_0xac26('0x55')]['Contacts'][0x0];}else{return db[_0xac26('0x61')][_0xac26('0x4d')](_['defaults'](_0x368b3a[_0xac26('0x4a')],{'firstName':_0x368b3a[_0xac26('0x4a')]['to'],'email':_0x368b3a[_0xac26('0x4a')]['to'],'phone':_0x368b3a[_0xac26('0x4a')]['to'],'ListId':_0x164bac[_0xac26('0x62')]}));}}else{throw new Error(_0xac26('0x63'));}})['then'](function(){if(_0x103bd5){return respondWithRpcPromise(_0xac26('0x64'),_0xac26('0x65'),_0x103bd5,client9003)[_0xac26('0x27')](function(_0xc76ed){return _0x57f037['update']({'read':!![],'messageId':_0xc76ed[_0xac26('0x66')],'sentAt':moment()[_0xac26('0x67')](_0xac26('0x68'))});})['catch'](function(_0x3f4726){logger['error']('%s',JSON[_0xac26('0x18')](_0x3f4726));return _0x57f037;});}return _0x57f037;});}return _0x57f037;}})[_0xac26('0x27')](respondWithResult(_0x551132,0xc9))[_0xac26('0x1d')](handleError(_0x551132,null));};exports[_0xac26('0x69')]=function(_0x430877,_0x4724b4){var _0x43f7ce=_0xac26('0x6a');return interactionService[_0xac26('0x6b')](_0x430877,_0x43f7ce)[_0xac26('0x27')](respondWithResult(_0x4724b4,null))[_0xac26('0x1d')](handleError(_0x4724b4,null));};exports[_0xac26('0x6c')]=function(_0x43a1c0,_0x5327c7){var _0xa9056d={'agent':{},'channel':_0xac26('0x6a')};if(_0x43a1c0[_0xac26('0x4a')]['id']){delete _0x43a1c0[_0xac26('0x4a')]['id'];}_0x43a1c0['body'][_0xac26('0x6d')]=_0x43a1c0[_0xac26('0x4a')][_0xac26('0x6d')]||_0x43a1c0[_0xac26('0x6e')]['id'];_0xa9056d[_0xac26('0x6f')]['id']=_0x43a1c0[_0xac26('0x4a')][_0xac26('0x6d')];return db[_0xac26('0x2e')][_0xac26('0x49')]({'where':{'id':_0x43a1c0[_0xac26('0x47')]['id'],'UserId':null}})[_0xac26('0x27')](handleEntityNotFound(_0x5327c7,null))[_0xac26('0x27')](function(_0x581afe){if(_0x581afe){_0xa9056d[_0xac26('0x1b')]=_0x581afe[_0xac26('0x70')]({'plain':!![]});return db[_0xac26('0x71')]['find']({'where':{'id':_0x581afe[_0xac26('0x72')]}});}return null;})[_0xac26('0x27')](handleEntityNotFound(_0x5327c7,null))[_0xac26('0x27')](function(_0x1f9415){if(_0x1f9415){_0xa9056d[_0xac26('0x73')]=_0x1f9415[_0xac26('0x70')]({'plain':!![]});interaction_log[_0xac26('0x14')](_0xac26('0x74'),_0x43a1c0['user']['id'],_0x43a1c0['user'][_0xac26('0x2a')],_0x43a1c0['user'][_0xac26('0x75')],_0xa9056d[_0xac26('0x73')]['id'],_0x43a1c0[_0xac26('0x4a')]?JSON[_0xac26('0x18')](_0x43a1c0[_0xac26('0x4a')]):_0xac26('0x76'));return respondWithRpcPromise('RejectMessage',_0xac26('0x77'),_0xa9056d);}return null;})[_0xac26('0x27')](function(_0x3de492){var _0xa2c6e0=_0xac26('0x78')+_0x3de492[_0xac26('0x1b')][_0xac26('0x79')];return db[_0xac26('0x7a')][_0xac26('0x33')](_0xa2c6e0,{'type':db['Sequelize'][_0xac26('0x7b')]['SELECT'],'raw':!![]})['then'](function(_0x5aca66){return _0x5aca66;});})['then'](function(_0x527211){if(_0x527211){_0xa9056d[_0xac26('0x1b')][_0xac26('0x7c')]=_0x527211[0x0];if(!_0x43a1c0[_0xac26('0x4a')][_0xac26('0x6d')])return;return db[_0xac26('0x7d')]['find']({'where':{'id':_0x43a1c0['body'][_0xac26('0x6d')],'role':_0xac26('0x6f')},'attributes':['id','name','fullname',_0xac26('0x7e'),'internal'],'raw':!![]});}return null;})[_0xac26('0x27')](function(_0x36bd76){if(!_0x36bd76)return null;_0xa9056d[_0xac26('0x1b')][_0xac26('0x6f')]=_0x36bd76;return _0xa9056d;})[_0xac26('0x27')](function(_0x5ed7d9){if(_0x5ed7d9){_0x5ed7d9['message'][_0xac26('0x7f')]=util['format']('SIP/%s',_0x43a1c0['user'][_0xac26('0x2a')]);_0x5ed7d9[_0xac26('0x1b')][_0xac26('0x80')]=_0xa9056d[_0xac26('0x80')];_0x5ed7d9[_0xac26('0x1b')]['motionChannel']=_0xa9056d[_0xac26('0x80')];_0x5ed7d9[_0xac26('0x1b')][_0xac26('0x81')]=_0xac26('0x6c');_0x5ed7d9[_0xac26('0x1b')][_0xac26('0x4a')]=htmlToText[_0xac26('0x82')](_0xa9056d[_0xac26('0x1b')]['body']);respondWithRpcPromise('EventManager',_0xac26('0x83'),{'event':_0xac26('0x84'),'message':_0x5ed7d9[_0xac26('0x1b')]},client9002);return _0xa9056d;}return null;})[_0xac26('0x27')](respondWithResult(_0x5327c7,null))[_0xac26('0x1d')](handleError(_0x5327c7,null));};exports['download']=function(_0x92110b,_0x3beb2b){var _0x4ac939=moment()[_0xac26('0x85')]()[_0xac26('0x86')]();var _0x113f2c=path[_0xac26('0x5e')](config[_0xac26('0x5f')],_0xac26('0x87'),_0xac26('0x88'),'tmp');var _0x5b01c3=path['join'](config[_0xac26('0x5f')],_0xac26('0x87'),'files',_0xac26('0x5d'));var _0x1b3102=util['format']('message-%s.eml',_0x4ac939);return db[_0xac26('0x2e')][_0xac26('0x49')]({'where':{'id':_0x92110b[_0xac26('0x47')]['id']},'attributes':['id','body',_0xac26('0x89'),'to','cc',_0xac26('0x8a'),_0xac26('0x8b'),_0xac26('0x8c')],'include':_0x92110b[_0xac26('0x33')][_0xac26('0x5d')]?[{'model':db[_0xac26('0x8d')],'as':_0xac26('0x8e')}]:undefined})[_0xac26('0x27')](handleEntityNotFound(_0x3beb2b,null))[_0xac26('0x27')](function(_0x399604){if(_0x399604){var _0x4dbb78=_0x399604;var _0x3b4a34={'from':_0x4dbb78[_0xac26('0x89')],'to':_0x4dbb78['to'],'subject':_0x4dbb78[_0xac26('0x8b')],'html':htmlEntities['decode'](_0x4dbb78[_0xac26('0x4a')]),'headers':{'Date':moment(_0x4dbb78['createdAt'])[_0xac26('0x67')](_0xac26('0x8f'))},'attachments':[]};if(_0x399604['cc']){_0x3b4a34[_0xac26('0x90')]['Cc']=_0x399604['cc'];}if(_0x399604[_0xac26('0x8a')]){_0x3b4a34[_0xac26('0x90')][_0xac26('0x91')]=_0x399604[_0xac26('0x8a')];}return new Promise(function(_0x48e5db,_0xc971f7){if(_0x399604['Attachments']){for(var _0x5cf33b=0x0;_0x5cf33b<_0x399604[_0xac26('0x8e')][_0xac26('0x39')];_0x5cf33b++){var _0xbdc13a=_0x399604[_0xac26('0x8e')][_0x5cf33b];var _0x3ebf0d=path[_0xac26('0x5e')](_0x5b01c3,_0xbdc13a[_0xac26('0x60')]);if(fs[_0xac26('0x92')](_0x3ebf0d)){_0x3b4a34['attachments'][_0xac26('0x93')]({'name':_0xbdc13a[_0xac26('0x2a')],'contentType':_0xbdc13a[_0xac26('0x30')],'data':fs[_0xac26('0x94')](_0x3ebf0d)});}}}emlformat['build'](_0x3b4a34,function(_0x234239,_0x311406){if(_0x234239)return _0xc971f7(_0x234239);fs[_0xac26('0x95')](path[_0xac26('0x5e')](_0x113f2c,_0x1b3102),_0x311406);return _0x48e5db(_0x311406);});});}})[_0xac26('0x27')](function(_0x1a53af){if(_0x1a53af){return _0x3beb2b[_0xac26('0x96')](path['join'](_0x113f2c,_0x1b3102),_0x1b3102,function(_0x4cf2c0){if(!_0x4cf2c0)fs[_0xac26('0x97')](path[_0xac26('0x5e')](_0x113f2c,_0x1b3102));});}})[_0xac26('0x1d')](handleError(_0x3beb2b,null));};
\ No newline at end of file