Built motion from commit 9d0783e6.|2.6.13
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 5227515..772b948 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x018b=['mail-interactions','readAt','UserId','Contact','get','MailInteractionId','isNil','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','acceptMessage','manual','interface','SIP/%s','channel','event','accept','EventManager','acceptmessage','mail','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectmessage','download','toString','root','files','tmp','server','message-%s.eml','from','bcc','createdAt','Attachment','Attachments','subject','headers','Bcc','existsSync','readFileSync','build','writeFileSync','log','err','html-pdf','eml-format','rimraf','zip-dir','fast-json-patch','request-promise','moment','bluebird','util','path','sox','to-csv','ejs','jsforce','desk.js','papaparse','ioredis','../../components/auth/service','../../config/license/hardware','../../config/utils','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','request','then','MailMessage,\x20%s,\x20%s','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','error','code','message','info','result','catch','sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','reject','save','update','name','send','index','map','MailMessage','rawAttributes','fieldName','key','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','order','sort','where','pick','filter','merge','type','VIRTUAL','options','includeAll','include','show','params','keys','find','body','destroy','describe','create','direction','out','secret','split','MailAccount','MailAccountId','CmList','List','CmContact','Contacts','DESC','MailServerOut','service','host','Smtp','port','secure','authentication','auth','pass','user','attachments','join','server/files/attachments','basename','List\x20not\x20found','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','stringify','../../config/logger'];(function(_0x3dd15e,_0x1f0015){var _0x231fd0=function(_0x4f680a){while(--_0x4f680a){_0x3dd15e['push'](_0x3dd15e['shift']());}};_0x231fd0(++_0x1f0015);}(_0x018b,0xd4));var _0xb018=function(_0x1203f,_0x554bbc){_0x1203f=_0x1203f-0x0;var _0x365f0a=_0x018b[_0x1203f];return _0x365f0a;};'use strict';var pdf=require(_0xb018('0x0'));var emlformat=require(_0xb018('0x1'));var rimraf=require(_0xb018('0x2'));var zipdir=require(_0xb018('0x3'));var jsonpatch=require(_0xb018('0x4'));var rp=require(_0xb018('0x5'));var moment=require(_0xb018('0x6'));var BPromise=require(_0xb018('0x7'));var Mustache=require('mustache');var util=require(_0xb018('0x8'));var path=require(_0xb018('0x9'));var sox=require(_0xb018('0xa'));var csv=require(_0xb018('0xb'));var ejs=require(_0xb018('0xc'));var fs=require('fs');var _=require('lodash');var squel=require('squel');var crypto=require('crypto');var jsforce=require(_0xb018('0xd'));var deskjs=require(_0xb018('0xe'));var toCsv=require(_0xb018('0xb'));var querystring=require('querystring');var Papa=require(_0xb018('0xf'));var Redis=require(_0xb018('0x10'));var authService=require(_0xb018('0x11'));var qs=require('../../components/parsers/qs');var as=require('../../components/parsers/advancedSearch');var hardwareService=require(_0xb018('0x12'));var logger=require('../../config/logger')('api');var utils=require(_0xb018('0x13'));var config=require(_0xb018('0x14'));var licenseUtil=require(_0xb018('0x15'));var db=require(_0xb018('0x16'))['db'];config['redis']=_[_0xb018('0x17')](config[_0xb018('0x18')],{'host':_0xb018('0x19'),'port':0x18eb});var socket=require(_0xb018('0x1a'))(new Redis(config[_0xb018('0x18')]));require('./mailMessage.socket')[_0xb018('0x1b')](socket);var jayson=require(_0xb018('0x1c'));var client=jayson[_0xb018('0x1d')][_0xb018('0x1e')]({'port':0x232c});var client9003=jayson['client'][_0xb018('0x1e')]({'port':0x232b});var client9002=jayson[_0xb018('0x1d')][_0xb018('0x1e')]({'port':0x232a});function respondWithRpcPromise(_0x5b6c85,_0x527a7f,_0x30f42a,_0x48fcb0){return new BPromise(function(_0x43a652,_0x5ec6ec){var _0x46b322=_0x48fcb0||client;return _0x46b322[_0xb018('0x1f')](_0x5b6c85,_0x30f42a)[_0xb018('0x20')](function(_0x144aed){logger['info'](_0xb018('0x21'),_0x527a7f,_0xb018('0x22'));logger['debug'](_0xb018('0x23'),_0x527a7f,_0xb018('0x22'),JSON['stringify'](_0x144aed));if(_0x144aed['error']){if(_0x144aed[_0xb018('0x24')][_0xb018('0x25')]===0x1f4){logger[_0xb018('0x24')](_0xb018('0x21'),_0x527a7f,_0x144aed[_0xb018('0x24')]['message']);return _0x5ec6ec(_0x144aed[_0xb018('0x24')][_0xb018('0x26')]);}logger[_0xb018('0x24')](_0xb018('0x21'),_0x527a7f,_0x144aed[_0xb018('0x24')][_0xb018('0x26')]);return _0x43a652(_0x144aed[_0xb018('0x24')][_0xb018('0x26')]);}else{logger[_0xb018('0x27')](_0xb018('0x21'),_0x527a7f,_0xb018('0x22'));_0x43a652(_0x144aed[_0xb018('0x28')][_0xb018('0x26')]);}})[_0xb018('0x29')](function(_0xdb027d){logger[_0xb018('0x24')](_0xb018('0x21'),_0x527a7f,_0xdb027d);_0x5ec6ec(_0xdb027d);});});}function respondWithStatusCode(_0x3b10af,_0x2c2f92){_0x2c2f92=_0x2c2f92||0xcc;return function(_0x293fc6){if(_0x293fc6){return _0x3b10af[_0xb018('0x2a')](_0x2c2f92);}return _0x3b10af['status'](_0x2c2f92)[_0xb018('0x2b')]();};}function respondWithResult(_0x52137a,_0x276fcb){_0x276fcb=_0x276fcb||0xc8;return function(_0x352486){if(_0x352486){return _0x52137a[_0xb018('0x2c')](_0x276fcb)[_0xb018('0x2d')](_0x352486);}};}function respondWithFilteredResult(_0xe39d66,_0x26594a){return function(_0x4f5fa3){if(_0x4f5fa3){var _0x43dae1=_0x4f5fa3[_0xb018('0x2e')],_0x3d9d59=_0x26594a[_0xb018('0x2f')],_0x575053=_0x26594a[_0xb018('0x2f')]+_0x26594a[_0xb018('0x30')],_0x13dc66;if(_0x575053>=_0x43dae1){_0x575053=_0x43dae1;_0x13dc66=0xc8;}else{_0x13dc66=0xce;}_0xe39d66[_0xb018('0x2c')](_0x13dc66);return _0xe39d66[_0xb018('0x31')](_0xb018('0x32'),_0x3d9d59+'-'+_0x575053+'/'+_0x43dae1)['json'](_0x4f5fa3);}return null;};}function patchUpdates(_0x2305f2){return function(_0x45c6fe){try{jsonpatch[_0xb018('0x33')](_0x45c6fe,_0x2305f2,!![]);}catch(_0x35e8db){return BPromise[_0xb018('0x34')](_0x35e8db);}return _0x45c6fe[_0xb018('0x35')]();};}function saveUpdates(_0x285fc7,_0x406837){return function(_0x232d65){if(_0x232d65){return _0x232d65[_0xb018('0x36')](_0x285fc7)[_0xb018('0x20')](function(_0x23cd0f){return _0x23cd0f;});}return null;};}function removeEntity(_0x349535,_0x39dc4d){return function(_0x34779b){if(_0x34779b){return _0x34779b['destroy']()[_0xb018('0x20')](function(){_0x349535[_0xb018('0x2c')](0xcc)[_0xb018('0x2b')]();});}};}function handleEntityNotFound(_0x233a31,_0x4c0cd5){return function(_0x32540d){if(!_0x32540d){_0x233a31['sendStatus'](0x194);}return _0x32540d;};}function handleError(_0x1b4045,_0x11430c){_0x11430c=_0x11430c||0x1f4;return function(_0x1df89c){logger['error'](_0x1df89c['stack']);if(_0x1df89c[_0xb018('0x37')]){delete _0x1df89c[_0xb018('0x37')];}_0x1b4045[_0xb018('0x2c')](_0x11430c)[_0xb018('0x38')](_0x1df89c);};}exports[_0xb018('0x39')]=function(_0x42588b,_0xdff3b9){var _0x4c827c={},_0x4431c5={},_0x4daca9={'count':0x0,'rows':[]};var _0x6cf9b6=_[_0xb018('0x3a')](db[_0xb018('0x3b')][_0xb018('0x3c')],function(_0x4dc82f){return{'name':_0x4dc82f[_0xb018('0x3d')],'type':_0x4dc82f['type'][_0xb018('0x3e')]};});_0x4431c5[_0xb018('0x3f')]=_[_0xb018('0x3a')](_0x6cf9b6,_0xb018('0x37'));_0x4431c5['query']=_['keys'](_0x42588b[_0xb018('0x40')]);_0x4431c5[_0xb018('0x41')]=_[_0xb018('0x42')](_0x4431c5['model'],_0x4431c5['query']);_0x4c827c[_0xb018('0x43')]=_[_0xb018('0x42')](_0x4431c5[_0xb018('0x3f')],qs[_0xb018('0x44')](_0x42588b[_0xb018('0x40')][_0xb018('0x44')]));_0x4c827c[_0xb018('0x43')]=_0x4c827c[_0xb018('0x43')][_0xb018('0x45')]?_0x4c827c[_0xb018('0x43')]:_0x4431c5[_0xb018('0x3f')];if(!_0x42588b[_0xb018('0x40')][_0xb018('0x46')]('nolimit')){_0x4c827c[_0xb018('0x30')]=qs[_0xb018('0x30')](_0x42588b[_0xb018('0x40')][_0xb018('0x30')]);_0x4c827c[_0xb018('0x2f')]=qs[_0xb018('0x2f')](_0x42588b[_0xb018('0x40')][_0xb018('0x2f')]);}_0x4c827c[_0xb018('0x47')]=qs[_0xb018('0x48')](_0x42588b[_0xb018('0x40')][_0xb018('0x48')]);_0x4c827c[_0xb018('0x49')]=qs['filters'](_[_0xb018('0x4a')](_0x42588b[_0xb018('0x40')],_0x4431c5[_0xb018('0x41')]),_0x6cf9b6);if(_0x42588b[_0xb018('0x40')][_0xb018('0x4b')]){_0x4c827c['where']=_[_0xb018('0x4c')](_0x4c827c[_0xb018('0x49')],{'$or':_[_0xb018('0x3a')](_0x6cf9b6,function(_0x4e503c){if(_0x4e503c[_0xb018('0x4d')]!==_0xb018('0x4e')){var _0x1f0339={};_0x1f0339[_0x4e503c[_0xb018('0x37')]]={'$like':'%'+_0x42588b['query'][_0xb018('0x4b')]+'%'};return _0x1f0339;}})});}_0x4c827c=_[_0xb018('0x4c')]({},_0x4c827c,_0x42588b[_0xb018('0x4f')]);var _0x319fd2={'where':_0x4c827c[_0xb018('0x49')]};return db['MailMessage']['count'](_0x319fd2)[_0xb018('0x20')](function(_0x5b0a52){_0x4daca9[_0xb018('0x2e')]=_0x5b0a52;if(_0x42588b['query'][_0xb018('0x50')]){_0x4c827c[_0xb018('0x51')]=[{'all':!![]}];}return db[_0xb018('0x3b')]['findAll'](_0x4c827c);})[_0xb018('0x20')](function(_0x5b56e5){_0x4daca9['rows']=_0x5b56e5;return _0x4daca9;})[_0xb018('0x20')](respondWithFilteredResult(_0xdff3b9,_0x4c827c))['catch'](handleError(_0xdff3b9,null));};exports[_0xb018('0x52')]=function(_0x58bfdc,_0x2b8c74){var _0x9a6978={'raw':!![],'where':{'id':_0x58bfdc[_0xb018('0x53')]['id']}},_0x106e03={};_0x106e03['model']=_[_0xb018('0x54')](db[_0xb018('0x3b')][_0xb018('0x3c')]);_0x106e03[_0xb018('0x40')]=_[_0xb018('0x54')](_0x58bfdc[_0xb018('0x40')]);_0x106e03['filters']=_[_0xb018('0x42')](_0x106e03[_0xb018('0x3f')],_0x106e03[_0xb018('0x40')]);_0x9a6978['attributes']=_[_0xb018('0x42')](_0x106e03[_0xb018('0x3f')],qs[_0xb018('0x44')](_0x58bfdc[_0xb018('0x40')][_0xb018('0x44')]));_0x9a6978[_0xb018('0x43')]=_0x9a6978['attributes'][_0xb018('0x45')]?_0x9a6978[_0xb018('0x43')]:_0x106e03['model'];if(_0x58bfdc['query'][_0xb018('0x50')]){_0x9a6978[_0xb018('0x51')]=[{'all':!![]}];}_0x9a6978=_[_0xb018('0x4c')]({},_0x9a6978,_0x58bfdc[_0xb018('0x4f')]);return db['MailMessage'][_0xb018('0x55')](_0x9a6978)['then'](handleEntityNotFound(_0x2b8c74,null))['then'](respondWithResult(_0x2b8c74,null))[_0xb018('0x29')](handleError(_0x2b8c74,null));};exports[_0xb018('0x36')]=function(_0x25283f,_0xe69e55){if(_0x25283f[_0xb018('0x56')]['id']){delete _0x25283f[_0xb018('0x56')]['id'];}return db[_0xb018('0x3b')][_0xb018('0x55')]({'where':{'id':_0x25283f[_0xb018('0x53')]['id']}})['then'](handleEntityNotFound(_0xe69e55,null))['then'](saveUpdates(_0x25283f[_0xb018('0x56')],null))[_0xb018('0x20')](respondWithResult(_0xe69e55,null))[_0xb018('0x29')](handleError(_0xe69e55,null));};exports[_0xb018('0x57')]=function(_0x5ecffb,_0x1abe8c){return db['MailMessage'][_0xb018('0x55')]({'where':{'id':_0x5ecffb['params']['id']}})[_0xb018('0x20')](handleEntityNotFound(_0x1abe8c,null))[_0xb018('0x20')](removeEntity(_0x1abe8c,null))['catch'](handleError(_0x1abe8c,null));};exports[_0xb018('0x58')]=function(_0x427a86,_0x552ef8){return db[_0xb018('0x3b')][_0xb018('0x58')]()[_0xb018('0x20')](respondWithResult(_0x552ef8,null))[_0xb018('0x29')](handleError(_0x552ef8,null));};exports[_0xb018('0x59')]=function(_0x11a34b,_0x24a19b){return db[_0xb018('0x3b')][_0xb018('0x59')](_0x11a34b[_0xb018('0x56')])[_0xb018('0x20')](function(_0x4d35eb){if(_0x4d35eb){if(_0x4d35eb[_0xb018('0x5a')]===_0xb018('0x5b')&&!_0x4d35eb[_0xb018('0x5c')]){var _0x4e6789,_0x1d1600,_0x12a7ac;if(_0x11a34b[_0xb018('0x56')]['to']){_0x1d1600=_0x11a34b[_0xb018('0x56')]['to'][_0xb018('0x5d')](',')[0x0];}return db[_0xb018('0x5e')]['findOne']({'where':{'id':_0x4d35eb[_0xb018('0x5f')]},'include':[{'model':db[_0xb018('0x60')],'as':_0xb018('0x61'),'include':[{'model':db[_0xb018('0x62')],'as':_0xb018('0x63'),'where':{'email':_0x1d1600},'limit':0x1,'order':[['updatedAt',_0xb018('0x64')]]}]},{'model':db[_0xb018('0x65')],'as':'Smtp','raw':!![]}]})[_0xb018('0x20')](function(_0xf05ac8){_0x4e6789=_0xf05ac8;if(_0x4e6789&&_0x4e6789['Smtp']){var _0x4d025f={'tls':{'rejectUnauthorized':![]}};if(_['isNil'](_0x4e6789['Smtp'][_0xb018('0x66')])){_0x4d025f[_0xb018('0x67')]=_0x4e6789[_0xb018('0x68')][_0xb018('0x67')];_0x4d025f[_0xb018('0x69')]=_0x4e6789[_0xb018('0x68')][_0xb018('0x69')];_0x4d025f[_0xb018('0x6a')]=_0x4e6789[_0xb018('0x68')][_0xb018('0x6a')];if(_0x4e6789[_0xb018('0x68')][_0xb018('0x6b')]){_0x4d025f[_0xb018('0x6c')]={'user':_0x4e6789['Smtp']['user'],'pass':_0x4e6789[_0xb018('0x68')][_0xb018('0x6d')]};}}else{_0x4d025f['service']=_0x4e6789[_0xb018('0x68')][_0xb018('0x66')];_0x4d025f[_0xb018('0x6c')]={'user':_0x4e6789[_0xb018('0x68')][_0xb018('0x6e')],'pass':_0x4e6789[_0xb018('0x68')][_0xb018('0x6d')]};_0x4d025f[_0xb018('0x6a')]=_0x4e6789[_0xb018('0x68')][_0xb018('0x6a')];}if(_0x11a34b[_0xb018('0x56')][_0xb018('0x6f')]&&_0x11a34b['body']['attachments'][_0xb018('0x45')]){for(var _0x3966e4=0x0;_0x3966e4<_0x11a34b['body']['attachments'][_0xb018('0x45')];_0x3966e4+=0x1){_0x11a34b[_0xb018('0x56')][_0xb018('0x6f')][_0x3966e4]={'filename':_0x11a34b[_0xb018('0x56')][_0xb018('0x6f')][_0x3966e4][_0xb018('0x37')],'path':path[_0xb018('0x70')](config['root'],_0xb018('0x71'),_0x11a34b[_0xb018('0x56')][_0xb018('0x6f')][_0x3966e4][_0xb018('0x72')])};}}_0x12a7ac={'account':_0x4d025f,'message':_0x11a34b[_0xb018('0x56')]};return;}})['then'](function(){if(_0x4e6789[_0xb018('0x61')]){if(_0x4e6789[_0xb018('0x61')][_0xb018('0x63')][_0xb018('0x45')]){return _0x4e6789[_0xb018('0x61')][_0xb018('0x63')][0x0];}else{return db[_0xb018('0x62')][_0xb018('0x59')](_[_0xb018('0x17')](_0x11a34b[_0xb018('0x56')],{'firstName':_0x11a34b['body']['to'],'email':_0x11a34b[_0xb018('0x56')]['to'],'phone':_0x11a34b['body']['to'],'ListId':_0x4e6789['ListId']}));}}else{throw new Error(_0xb018('0x73'));}})[_0xb018('0x20')](function(){if(_0x12a7ac){return respondWithRpcPromise('SendMail',_0xb018('0x74'),_0x12a7ac,client9003)[_0xb018('0x20')](function(_0x298b06){return _0x4d35eb['update']({'read':!![],'messageId':_0x298b06[_0xb018('0x75')],'sentAt':moment()[_0xb018('0x76')](_0xb018('0x77'))});})[_0xb018('0x29')](function(_0x3031a9){logger[_0xb018('0x24')]('%s',JSON[_0xb018('0x78')](_0x3031a9));return _0x4d35eb;});}return _0x4d35eb;});}return _0x4d35eb;}})[_0xb018('0x20')](respondWithResult(_0x24a19b,0xc9))[_0xb018('0x29')](handleError(_0x24a19b,null));};var interaction_log=require(_0xb018('0x79'))(_0xb018('0x7a'));exports['accept']=function(_0x453aea,_0x29ed72,_0x517b61){var _0x137bca={'channel':'mail'};if(_0x453aea[_0xb018('0x56')]['id']){delete _0x453aea[_0xb018('0x56')]['id'];}_0x453aea[_0xb018('0x56')]['read']=!![];_0x453aea[_0xb018('0x56')][_0xb018('0x7b')]=moment()[_0xb018('0x76')](_0xb018('0x77'));_0x453aea['body']['UserId']=_0x453aea[_0xb018('0x56')][_0xb018('0x7c')]||_0x453aea['user']['id'];return db[_0xb018('0x3b')]['find']({'where':{'id':_0x453aea['params']['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0xb018('0x7d')}]})[_0xb018('0x20')](handleEntityNotFound(_0x29ed72,null))[_0xb018('0x20')](saveUpdates(_0x453aea[_0xb018('0x56')],null))[_0xb018('0x20')](function(_0x2613e0){if(_0x2613e0){_0x137bca[_0xb018('0x26')]=_0x2613e0[_0xb018('0x7e')]({'plain':!![]});return db['MailInteraction'][_0xb018('0x55')]({'where':{'id':_0x2613e0[_0xb018('0x7f')]}});}return null;})['then'](handleEntityNotFound(_0x29ed72,null))['then'](function(_0x206a1f){if(_0x206a1f){return _0x206a1f[_0xb018('0x36')]({'UserId':_0x453aea[_0xb018('0x56')][_0xb018('0x7c')],'read1stAt':_[_0xb018('0x80')](_0x206a1f[_0xb018('0x81')])?moment()['format'](_0xb018('0x77')):undefined});}return null;})[_0xb018('0x20')](function(_0x12c87f){if(_0x12c87f){_0x137bca[_0xb018('0x82')]=_0x12c87f['get']({'plain':!![]});interaction_log[_0xb018('0x27')](_0xb018('0x83'),_0x453aea[_0xb018('0x6e')]['id'],_0x453aea[_0xb018('0x6e')][_0xb018('0x37')],_0x453aea[_0xb018('0x6e')]['role'],_0x137bca[_0xb018('0x82')]['id'],_0x453aea['body']?JSON[_0xb018('0x78')](_0x453aea[_0xb018('0x56')]):_0xb018('0x84'));return respondWithRpcPromise('AcceptMessage',_0xb018('0x85'),_0x137bca);}return null;})['then'](function(_0x151002){if(_0x151002){if(_0x453aea[_0xb018('0x56')][_0xb018('0x86')]){_0x137bca['message'][_0xb018('0x87')]=util['format'](_0xb018('0x88'),_0x453aea['user'][_0xb018('0x37')]);_0x137bca[_0xb018('0x26')][_0xb018('0x89')]=_0x137bca[_0xb018('0x89')];_0x137bca[_0xb018('0x26')][_0xb018('0x8a')]=_0xb018('0x8b');return respondWithRpcPromise(_0xb018('0x8c'),_0xb018('0x8c'),{'event':_0xb018('0x8d'),'message':_0x137bca[_0xb018('0x26')]},client9002)[_0xb018('0x20')](function(){return _0x137bca;});}return _0x137bca;}return null;})[_0xb018('0x20')](respondWithResult(_0x29ed72,null))[_0xb018('0x29')](handleError(_0x29ed72,null));};var interaction_log=require('../../config/logger')(_0xb018('0x7a'));exports['reject']=function(_0x212ca2,_0x294fff,_0x53d8e4){var _0xccc99a={'agent':{},'channel':_0xb018('0x8e')};if(_0x212ca2[_0xb018('0x56')]['id']){delete _0x212ca2[_0xb018('0x56')]['id'];}_0x212ca2[_0xb018('0x56')][_0xb018('0x7c')]=_0x212ca2['body']['UserId']||_0x212ca2[_0xb018('0x6e')]['id'];_0xccc99a['agent']['id']=_0x212ca2['body'][_0xb018('0x7c')];return db[_0xb018('0x3b')][_0xb018('0x55')]({'where':{'id':_0x212ca2[_0xb018('0x53')]['id'],'UserId':null}})[_0xb018('0x20')](handleEntityNotFound(_0x294fff,null))['then'](function(_0x32663d){if(_0x32663d){_0xccc99a[_0xb018('0x26')]=_0x32663d[_0xb018('0x7e')]({'plain':!![]});return db['MailInteraction'][_0xb018('0x55')]({'where':{'id':_0x32663d[_0xb018('0x7f')]}});}return null;})[_0xb018('0x20')](handleEntityNotFound(_0x294fff,null))[_0xb018('0x20')](function(_0x29e463){if(_0x29e463){_0xccc99a[_0xb018('0x82')]=_0x29e463[_0xb018('0x7e')]({'plain':!![]});interaction_log[_0xb018('0x27')](_0xb018('0x8f'),_0x212ca2['user']['id'],_0x212ca2[_0xb018('0x6e')][_0xb018('0x37')],_0x212ca2['user'][_0xb018('0x90')],_0xccc99a[_0xb018('0x82')]['id'],_0x212ca2[_0xb018('0x56')]?JSON[_0xb018('0x78')](_0x212ca2[_0xb018('0x56')]):'null');return respondWithRpcPromise('RejectMessage','rejectMessage',_0xccc99a);}return null;})[_0xb018('0x20')](function(_0x2a7abf){if(_0x2a7abf){_0x2a7abf[_0xb018('0x26')]['interface']=util['format'](_0xb018('0x88'),_0x212ca2[_0xb018('0x6e')][_0xb018('0x37')]);_0x2a7abf[_0xb018('0x26')][_0xb018('0x89')]=_0xccc99a['channel'];_0x2a7abf[_0xb018('0x26')][_0xb018('0x8a')]='reject';respondWithRpcPromise(_0xb018('0x8c'),'EventManager',{'event':_0xb018('0x91'),'message':_0x2a7abf[_0xb018('0x26')]},client9002);return _0xccc99a;}return null;})[_0xb018('0x20')](respondWithResult(_0x294fff,null))['catch'](handleError(_0x294fff,null));};exports[_0xb018('0x92')]=function(_0x30092b,_0x5e7e93){var _0x347020=moment()['unix']()[_0xb018('0x93')]();var _0xfc17c9=path[_0xb018('0x70')](config[_0xb018('0x94')],'server',_0xb018('0x95'),_0xb018('0x96'));var _0x29b6d8=path[_0xb018('0x70')](config[_0xb018('0x94')],_0xb018('0x97'),_0xb018('0x95'),_0xb018('0x6f'));var _0x39e47a=util[_0xb018('0x76')](_0xb018('0x98'),_0x347020);return db[_0xb018('0x3b')][_0xb018('0x55')]({'where':{'id':_0x30092b[_0xb018('0x53')]['id']},'attributes':['id',_0xb018('0x56'),_0xb018('0x99'),'to','cc',_0xb018('0x9a'),'subject',_0xb018('0x9b')],'include':_0x30092b[_0xb018('0x40')][_0xb018('0x6f')]?[{'model':db[_0xb018('0x9c')],'as':_0xb018('0x9d')}]:undefined})[_0xb018('0x20')](handleEntityNotFound(_0x5e7e93,null))[_0xb018('0x20')](function(_0x5cb2d){if(_0x5cb2d){var _0x13ce71=_0x5cb2d;var _0x393dc9={'from':_0x13ce71['from'],'to':_0x13ce71['to'],'subject':_0x13ce71[_0xb018('0x9e')],'html':_0x13ce71[_0xb018('0x56')],'headers':{'Date':moment(_0x13ce71[_0xb018('0x9b')])[_0xb018('0x76')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x5cb2d['cc']){_0x393dc9[_0xb018('0x9f')]['Cc']=_0x5cb2d['cc'];}if(_0x5cb2d[_0xb018('0x9a')]){_0x393dc9[_0xb018('0x9f')][_0xb018('0xa0')]=_0x5cb2d[_0xb018('0x9a')];}return new BPromise(function(_0x2e5ee4,_0x2500c2){if(_0x5cb2d['Attachments']){for(var _0x2e5c78=0x0;_0x2e5c78<_0x5cb2d['Attachments'][_0xb018('0x45')];_0x2e5c78++){var _0x33a9ad=_0x5cb2d[_0xb018('0x9d')][_0x2e5c78];var _0x3568f0=path['join'](_0x29b6d8,_0x33a9ad[_0xb018('0x72')]);if(fs[_0xb018('0xa1')](_0x3568f0)){_0x393dc9[_0xb018('0x6f')]['push']({'name':_0x33a9ad[_0xb018('0x37')],'contentType':_0x33a9ad[_0xb018('0x4d')],'data':fs[_0xb018('0xa2')](_0x3568f0)});}}}emlformat[_0xb018('0xa3')](_0x393dc9,function(_0xdb7869,_0x1be03d){if(_0xdb7869)return _0x2500c2(_0xdb7869);fs[_0xb018('0xa4')](path[_0xb018('0x70')](_0xfc17c9,_0x39e47a),_0x1be03d);return _0x2e5ee4(_0x1be03d);});});}})[_0xb018('0x20')](function(_0x56a1b4){if(_0x56a1b4){return _0x5e7e93[_0xb018('0x92')](path[_0xb018('0x70')](_0xfc17c9,_0x39e47a),_0x39e47a,function(_0x1b7736){if(_0x1b7736){console[_0xb018('0xa5')](_0xb018('0xa6'),_0x1b7736);}else{fs['unlinkSync'](path['join'](_0xfc17c9,_0x39e47a));}});}})[_0xb018('0x29')](handleError(_0x5e7e93,null));};
\ No newline at end of file
+var _0x1705=['destroy','sendStatus','stack','name','send','index','map','MailMessage','rawAttributes','type','key','query','keys','filters','intersection','model','attributes','length','sort','pick','where','merge','VIRTUAL','filter','includeAll','include','findAll','rows','catch','show','params','fields','find','update','body','describe','create','out','secret','MailAccount','CmList','List','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments','root','server/files/attachments','basename','List\x20not\x20found','SendMail','sendMail','format','stringify','accept','read','readAt','YYYY-MM-DD\x20HH:mm:ss','UserId','user','MailInteractionId','isNil','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','Sequelize','QueryTypes','SELECT','User','agent','fullname','email','internal','manual','interface','channel','motionChannel','event','EventManager','reject','MailInteraction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','RejectMessage','rejectMessage','contact','SIP/%s','fromString','rejectmessage','unix','join','server','tmp','files','message-%s.eml','subject','createdAt','Attachment','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','Bcc','existsSync','push','readFileSync','writeFileSync','download','unlinkSync','moment','bluebird','util','path','lodash','ioredis','html-to-text','../../config/logger','api','mail-interactions','redis','defaults','html-entities','client','http','then','info','request\x20sent','MailMessage,\x20%s,\x20%s,\x20%s','error','code','MailMessage,\x20%s,\x20%s','message','result','status','json','offset','limit','undefined','count','set'];(function(_0x1f80f7,_0x47da0b){var _0x481cf9=function(_0x2e18e0){while(--_0x2e18e0){_0x1f80f7['push'](_0x1f80f7['shift']());}};_0x481cf9(++_0x47da0b);}(_0x1705,0x19d));var _0x5170=function(_0x2a1b33,_0x409f50){_0x2a1b33=_0x2a1b33-0x0;var _0x4c50e7=_0x1705[_0x2a1b33];return _0x4c50e7;};'use strict';var emlformat=require('eml-format');var moment=require(_0x5170('0x0'));var BPromise=require(_0x5170('0x1'));var util=require(_0x5170('0x2'));var path=require(_0x5170('0x3'));var fs=require('fs');var _=require(_0x5170('0x4'));var Redis=require(_0x5170('0x5'));var htmlToText=require(_0x5170('0x6'));var qs=require('../../components/parsers/qs');var logger=require(_0x5170('0x7'))(_0x5170('0x8'));var interaction_log=require(_0x5170('0x7'))(_0x5170('0x9'));var config=require('../../config/environment');var db=require('../../mysqldb')['db'];config[_0x5170('0xa')]=_[_0x5170('0xb')](config[_0x5170('0xa')],{'host':'localhost','port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x5170('0xa')]));var htmlEntities=require(_0x5170('0xc'));require('./mailMessage.socket')['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x5170('0xd')][_0x5170('0xe')]({'port':0x232c});var client9003=jayson[_0x5170('0xd')][_0x5170('0xe')]({'port':0x232b});var client9002=jayson[_0x5170('0xd')][_0x5170('0xe')]({'port':0x232a});function respondWithRpcPromise(_0x3a7747,_0xf483cf,_0x2496e5,_0x5e3eed){return new BPromise(function(_0x2f5abe,_0x584686){var _0x13a42a=_0x5e3eed||client;return _0x13a42a['request'](_0x3a7747,_0x2496e5)[_0x5170('0xf')](function(_0x4a3721){logger[_0x5170('0x10')]('MailMessage,\x20%s,\x20%s',_0xf483cf,_0x5170('0x11'));logger['debug'](_0x5170('0x12'),_0xf483cf,_0x5170('0x11'),JSON['stringify'](_0x4a3721));if(_0x4a3721['error']){if(_0x4a3721[_0x5170('0x13')][_0x5170('0x14')]===0x1f4){logger['error'](_0x5170('0x15'),_0xf483cf,_0x4a3721['error'][_0x5170('0x16')]);return _0x584686(_0x4a3721[_0x5170('0x13')][_0x5170('0x16')]);}logger[_0x5170('0x13')]('MailMessage,\x20%s,\x20%s',_0xf483cf,_0x4a3721['error'][_0x5170('0x16')]);return _0x2f5abe(_0x4a3721[_0x5170('0x13')][_0x5170('0x16')]);}else{logger[_0x5170('0x10')]('MailMessage,\x20%s,\x20%s',_0xf483cf,_0x5170('0x11'));_0x2f5abe(_0x4a3721[_0x5170('0x17')][_0x5170('0x16')]);}})['catch'](function(_0x11b1d2){logger[_0x5170('0x13')](_0x5170('0x15'),_0xf483cf,_0x11b1d2);_0x584686(_0x11b1d2);});});}function respondWithResult(_0x26a232,_0x2d6b64){_0x2d6b64=_0x2d6b64||0xc8;return function(_0x463a86){if(_0x463a86){return _0x26a232[_0x5170('0x18')](_0x2d6b64)[_0x5170('0x19')](_0x463a86);}};}function respondWithFilteredResult(_0x4b1105,_0xa88532){return function(_0x140225){if(_0x140225){var _0x2f9e56=typeof _0xa88532[_0x5170('0x1a')]==='undefined'&&typeof _0xa88532[_0x5170('0x1b')]===_0x5170('0x1c');var _0x32928d=_0x140225['count'];var _0xbf1c9=_0x2f9e56?0x0:_0xa88532['offset'];var _0x4aa98b=_0x2f9e56?_0x140225[_0x5170('0x1d')]:_0xa88532['offset']+_0xa88532[_0x5170('0x1b')];var _0x2ce3e1;if(_0x4aa98b>=_0x32928d){_0x4aa98b=_0x32928d;_0x2ce3e1=0xc8;}else{_0x2ce3e1=0xce;}_0x4b1105[_0x5170('0x18')](_0x2ce3e1);return _0x4b1105[_0x5170('0x1e')]('Content-Range',_0xbf1c9+'-'+_0x4aa98b+'/'+_0x32928d)[_0x5170('0x19')](_0x140225);}return null;};}function saveUpdates(_0x442827){return function(_0x18f13c){if(_0x18f13c){return _0x18f13c['update'](_0x442827)[_0x5170('0xf')](function(_0xe181a2){return _0xe181a2;});}return null;};}function removeEntity(_0x3ba74e){return function(_0x2a4a96){if(_0x2a4a96){return _0x2a4a96[_0x5170('0x1f')]()[_0x5170('0xf')](function(){_0x3ba74e[_0x5170('0x18')](0xcc)['end']();});}};}function handleEntityNotFound(_0x2fc337){return function(_0x3a18c2){if(!_0x3a18c2){_0x2fc337[_0x5170('0x20')](0x194);}return _0x3a18c2;};}function handleError(_0x481004,_0x4fc7af){_0x4fc7af=_0x4fc7af||0x1f4;return function(_0x1cd4b1){logger['error'](_0x1cd4b1[_0x5170('0x21')]);if(_0x1cd4b1[_0x5170('0x22')]){delete _0x1cd4b1[_0x5170('0x22')];}_0x481004[_0x5170('0x18')](_0x4fc7af)[_0x5170('0x23')](_0x1cd4b1);};}exports[_0x5170('0x24')]=function(_0x44bf1d,_0x2b660e){var _0x260abf={},_0x345178={},_0x5bf67e={'count':0x0,'rows':[]};var _0x5a52e1=_[_0x5170('0x25')](db[_0x5170('0x26')][_0x5170('0x27')],function(_0x2a37fb){return{'name':_0x2a37fb['fieldName'],'type':_0x2a37fb[_0x5170('0x28')][_0x5170('0x29')]};});_0x345178['model']=_['map'](_0x5a52e1,_0x5170('0x22'));_0x345178[_0x5170('0x2a')]=_[_0x5170('0x2b')](_0x44bf1d[_0x5170('0x2a')]);_0x345178[_0x5170('0x2c')]=_[_0x5170('0x2d')](_0x345178[_0x5170('0x2e')],_0x345178['query']);_0x260abf[_0x5170('0x2f')]=_[_0x5170('0x2d')](_0x345178['model'],qs['fields'](_0x44bf1d[_0x5170('0x2a')]['fields']));_0x260abf[_0x5170('0x2f')]=_0x260abf['attributes'][_0x5170('0x30')]?_0x260abf[_0x5170('0x2f')]:_0x345178[_0x5170('0x2e')];if(!_0x44bf1d['query']['hasOwnProperty']('nolimit')){_0x260abf[_0x5170('0x1b')]=qs['limit'](_0x44bf1d[_0x5170('0x2a')]['limit']);_0x260abf[_0x5170('0x1a')]=qs[_0x5170('0x1a')](_0x44bf1d[_0x5170('0x2a')]['offset']);}_0x260abf['order']=qs['sort'](_0x44bf1d['query'][_0x5170('0x31')]);_0x260abf['where']=qs[_0x5170('0x2c')](_[_0x5170('0x32')](_0x44bf1d[_0x5170('0x2a')],_0x345178[_0x5170('0x2c')]),_0x5a52e1);if(_0x44bf1d[_0x5170('0x2a')]['filter']){_0x260abf[_0x5170('0x33')]=_[_0x5170('0x34')](_0x260abf['where'],{'$or':_[_0x5170('0x25')](_0x5a52e1,function(_0x59bb16){if(_0x59bb16['type']!==_0x5170('0x35')){var _0x22c047={};_0x22c047[_0x59bb16[_0x5170('0x22')]]={'$like':'%'+_0x44bf1d['query'][_0x5170('0x36')]+'%'};return _0x22c047;}})});}_0x260abf=_['merge']({},_0x260abf,_0x44bf1d['options']);var _0x3f55ba={'where':_0x260abf[_0x5170('0x33')]};return db[_0x5170('0x26')]['count'](_0x3f55ba)[_0x5170('0xf')](function(_0x5e0706){_0x5bf67e[_0x5170('0x1d')]=_0x5e0706;if(_0x44bf1d[_0x5170('0x2a')][_0x5170('0x37')]){_0x260abf[_0x5170('0x38')]=[{'all':!![]}];}return db['MailMessage'][_0x5170('0x39')](_0x260abf);})['then'](function(_0x2592c9){_0x5bf67e[_0x5170('0x3a')]=_0x2592c9;return _0x5bf67e;})['then'](respondWithFilteredResult(_0x2b660e,_0x260abf))[_0x5170('0x3b')](handleError(_0x2b660e,null));};exports[_0x5170('0x3c')]=function(_0x472363,_0xf9e4fc){var _0x2b9580={'raw':!![],'where':{'id':_0x472363[_0x5170('0x3d')]['id']}},_0x27e080={};_0x27e080[_0x5170('0x2e')]=_[_0x5170('0x2b')](db[_0x5170('0x26')][_0x5170('0x27')]);_0x27e080['query']=_[_0x5170('0x2b')](_0x472363[_0x5170('0x2a')]);_0x27e080[_0x5170('0x2c')]=_[_0x5170('0x2d')](_0x27e080[_0x5170('0x2e')],_0x27e080[_0x5170('0x2a')]);_0x2b9580[_0x5170('0x2f')]=_[_0x5170('0x2d')](_0x27e080[_0x5170('0x2e')],qs[_0x5170('0x3e')](_0x472363[_0x5170('0x2a')][_0x5170('0x3e')]));_0x2b9580[_0x5170('0x2f')]=_0x2b9580[_0x5170('0x2f')][_0x5170('0x30')]?_0x2b9580['attributes']:_0x27e080[_0x5170('0x2e')];if(_0x472363[_0x5170('0x2a')][_0x5170('0x37')]){_0x2b9580['include']=[{'all':!![]}];}_0x2b9580=_['merge']({},_0x2b9580,_0x472363['options']);return db[_0x5170('0x26')][_0x5170('0x3f')](_0x2b9580)[_0x5170('0xf')](handleEntityNotFound(_0xf9e4fc,null))[_0x5170('0xf')](respondWithResult(_0xf9e4fc,null))[_0x5170('0x3b')](handleError(_0xf9e4fc,null));};exports[_0x5170('0x40')]=function(_0x31b4a8,_0x22309d){if(_0x31b4a8[_0x5170('0x41')]['id']){delete _0x31b4a8[_0x5170('0x41')]['id'];}return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x31b4a8[_0x5170('0x3d')]['id']}})[_0x5170('0xf')](handleEntityNotFound(_0x22309d,null))['then'](saveUpdates(_0x31b4a8[_0x5170('0x41')],null))[_0x5170('0xf')](respondWithResult(_0x22309d,null))['catch'](handleError(_0x22309d,null));};exports[_0x5170('0x1f')]=function(_0x303daa,_0x21573d){return db['MailMessage'][_0x5170('0x3f')]({'where':{'id':_0x303daa[_0x5170('0x3d')]['id']}})[_0x5170('0xf')](handleEntityNotFound(_0x21573d,null))[_0x5170('0xf')](removeEntity(_0x21573d,null))[_0x5170('0x3b')](handleError(_0x21573d,null));};exports['describe']=function(_0x45731a,_0x304dce){return db[_0x5170('0x26')][_0x5170('0x42')]()[_0x5170('0xf')](respondWithResult(_0x304dce,null))[_0x5170('0x3b')](handleError(_0x304dce,null));};exports[_0x5170('0x43')]=function(_0x34d363,_0x3ef8fd){return db[_0x5170('0x26')][_0x5170('0x43')](_0x34d363[_0x5170('0x41')])[_0x5170('0xf')](function(_0x19d4d0){if(_0x19d4d0){if(_0x19d4d0['direction']===_0x5170('0x44')&&!_0x19d4d0[_0x5170('0x45')]){var _0x388b9f,_0x3d31ee,_0x16b840;if(_0x34d363[_0x5170('0x41')]['to']){_0x3d31ee=_0x34d363[_0x5170('0x41')]['to']['split'](',')[0x0];}return db[_0x5170('0x46')]['findOne']({'where':{'id':_0x19d4d0['MailAccountId']},'include':[{'model':db[_0x5170('0x47')],'as':_0x5170('0x48'),'include':[{'model':db[_0x5170('0x49')],'as':_0x5170('0x4a'),'where':{'email':_0x3d31ee},'limit':0x1,'order':[[_0x5170('0x4b'),_0x5170('0x4c')]]}]},{'model':db[_0x5170('0x4d')],'as':_0x5170('0x4e'),'raw':!![],'include':[{'model':db[_0x5170('0x4f')],'as':'CloudProvider','raw':!![]}]}]})[_0x5170('0xf')](function(_0x5634b5){_0x388b9f=_0x5634b5;if(!_0x388b9f||!_0x388b9f[_0x5170('0x4e')])return;var _0x309961=_0x388b9f[_0x5170('0x50')]();if(_0x34d363['body'][_0x5170('0x51')]&&_0x34d363['body'][_0x5170('0x51')][_0x5170('0x30')]){for(var _0x51c3a3=0x0;_0x51c3a3<_0x34d363[_0x5170('0x41')]['attachments']['length'];_0x51c3a3+=0x1){_0x34d363['body']['attachments'][_0x51c3a3]={'filename':_0x34d363[_0x5170('0x41')][_0x5170('0x51')][_0x51c3a3][_0x5170('0x22')],'path':path['join'](config[_0x5170('0x52')],_0x5170('0x53'),_0x34d363[_0x5170('0x41')][_0x5170('0x51')][_0x51c3a3][_0x5170('0x54')])};}}_0x16b840={'account':_0x309961,'message':_0x34d363[_0x5170('0x41')]};return;})['then'](function(){if(_0x388b9f[_0x5170('0x48')]){if(_0x388b9f[_0x5170('0x48')][_0x5170('0x4a')][_0x5170('0x30')]){return _0x388b9f[_0x5170('0x48')][_0x5170('0x4a')][0x0];}else{return db[_0x5170('0x49')]['create'](_[_0x5170('0xb')](_0x34d363[_0x5170('0x41')],{'firstName':_0x34d363[_0x5170('0x41')]['to'],'email':_0x34d363['body']['to'],'phone':_0x34d363[_0x5170('0x41')]['to'],'ListId':_0x388b9f['ListId']}));}}else{throw new Error(_0x5170('0x55'));}})[_0x5170('0xf')](function(){if(_0x16b840){return respondWithRpcPromise(_0x5170('0x56'),_0x5170('0x57'),_0x16b840,client9003)['then'](function(_0x438e25){return _0x19d4d0[_0x5170('0x40')]({'read':!![],'messageId':_0x438e25['messageId'],'sentAt':moment()[_0x5170('0x58')]('YYYY-MM-DD\x20HH:mm:ss')});})[_0x5170('0x3b')](function(_0x254fc3){logger[_0x5170('0x13')]('%s',JSON[_0x5170('0x59')](_0x254fc3));return _0x19d4d0;});}return _0x19d4d0;});}return _0x19d4d0;}})[_0x5170('0xf')](respondWithResult(_0x3ef8fd,0xc9))[_0x5170('0x3b')](handleError(_0x3ef8fd,null));};exports[_0x5170('0x5a')]=function(_0x2bf714,_0x4fbf4a){var _0x83b293={'agent':{},'channel':'mail'};if(_0x2bf714['body']['id']){delete _0x2bf714[_0x5170('0x41')]['id'];}_0x2bf714[_0x5170('0x41')][_0x5170('0x5b')]=!![];_0x2bf714[_0x5170('0x41')][_0x5170('0x5c')]=moment()['format'](_0x5170('0x5d'));_0x2bf714[_0x5170('0x41')]['UserId']=_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')]||_0x2bf714[_0x5170('0x5f')]['id'];_0x83b293['agent']['id']=_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')];return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x2bf714['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x4fbf4a,null))[_0x5170('0xf')](saveUpdates(_0x2bf714[_0x5170('0x41')],null))[_0x5170('0xf')](function(_0xd2b8cc){if(_0xd2b8cc){_0x83b293[_0x5170('0x16')]=_0xd2b8cc['get']({'plain':!![]});return db['MailInteraction'][_0x5170('0x3f')]({'where':{'id':_0xd2b8cc[_0x5170('0x60')]}});}return null;})[_0x5170('0xf')](handleEntityNotFound(_0x4fbf4a,null))['then'](function(_0x3c539f){if(_0x3c539f){return _0x3c539f['update']({'UserId':_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')],'read1stAt':_[_0x5170('0x61')](_0x3c539f['read1stAt'])?moment()[_0x5170('0x58')](_0x5170('0x5d')):undefined});}return null;})[_0x5170('0xf')](function(_0x3df92d){if(_0x3df92d){_0x83b293['interaction']=_0x3df92d[_0x5170('0x62')]({'plain':!![]});interaction_log[_0x5170('0x10')](_0x5170('0x63'),_0x2bf714['user']['id'],_0x2bf714[_0x5170('0x5f')]['name'],_0x2bf714['user']['role'],_0x83b293[_0x5170('0x64')]['id'],_0x2bf714['body']?JSON['stringify'](_0x2bf714[_0x5170('0x41')]):_0x5170('0x65'));return respondWithRpcPromise(_0x5170('0x66'),_0x5170('0x67'),_0x83b293);}return null;})[_0x5170('0xf')](function(_0x898c23){var _0x3f1c1d=_0x5170('0x68')+_0x898c23[_0x5170('0x16')][_0x5170('0x69')];return db['sequelize'][_0x5170('0x2a')](_0x3f1c1d,{'type':db[_0x5170('0x6a')][_0x5170('0x6b')][_0x5170('0x6c')],'raw':!![]})[_0x5170('0xf')](function(_0x5c836c){return _0x5c836c;});})[_0x5170('0xf')](function(_0x5583be){if(_0x5583be){_0x83b293[_0x5170('0x16')]['contact']=_0x5583be[0x0];if(!_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')])return;return db[_0x5170('0x6d')]['find']({'where':{'id':_0x2bf714[_0x5170('0x41')][_0x5170('0x5e')],'role':_0x5170('0x6e')},'attributes':['id',_0x5170('0x22'),_0x5170('0x6f'),_0x5170('0x70'),_0x5170('0x71')],'raw':!![]});}return null;})['then'](function(_0xdf021c){if(!_0xdf021c)return null;_0x83b293[_0x5170('0x16')]['agent']=_0xdf021c;return _0x83b293;})[_0x5170('0xf')](function(_0x2cf3f1){if(_0x2cf3f1){if(_0x2bf714[_0x5170('0x41')][_0x5170('0x72')]){_0x83b293['message'][_0x5170('0x73')]=util['format']('SIP/%s',_0x2bf714[_0x5170('0x5f')][_0x5170('0x22')]);_0x83b293[_0x5170('0x16')][_0x5170('0x74')]=_0x83b293[_0x5170('0x74')];_0x83b293[_0x5170('0x16')][_0x5170('0x75')]=_0x83b293['channel'];_0x83b293[_0x5170('0x16')][_0x5170('0x76')]=_0x5170('0x5a');_0x83b293[_0x5170('0x16')][_0x5170('0x41')]=htmlToText['fromString'](_0x83b293[_0x5170('0x16')]['body']);return respondWithRpcPromise(_0x5170('0x77'),_0x5170('0x77'),{'event':'acceptmessage','message':_0x83b293[_0x5170('0x16')]},client9002)[_0x5170('0xf')](function(){return _0x83b293;});}return _0x83b293;}return null;})[_0x5170('0xf')](respondWithResult(_0x4fbf4a,null))[_0x5170('0x3b')](handleError(_0x4fbf4a,null));};exports[_0x5170('0x78')]=function(_0x512278,_0xbfceb3){var _0xab4abe={'agent':{},'channel':'mail'};if(_0x512278[_0x5170('0x41')]['id']){delete _0x512278[_0x5170('0x41')]['id'];}_0x512278['body'][_0x5170('0x5e')]=_0x512278[_0x5170('0x41')][_0x5170('0x5e')]||_0x512278[_0x5170('0x5f')]['id'];_0xab4abe[_0x5170('0x6e')]['id']=_0x512278[_0x5170('0x41')][_0x5170('0x5e')];return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x512278[_0x5170('0x3d')]['id'],'UserId':null}})[_0x5170('0xf')](handleEntityNotFound(_0xbfceb3,null))[_0x5170('0xf')](function(_0x2e9b5f){if(_0x2e9b5f){_0xab4abe[_0x5170('0x16')]=_0x2e9b5f[_0x5170('0x62')]({'plain':!![]});return db[_0x5170('0x79')]['find']({'where':{'id':_0x2e9b5f['MailInteractionId']}});}return null;})['then'](handleEntityNotFound(_0xbfceb3,null))['then'](function(_0x3a9f39){if(_0x3a9f39){_0xab4abe[_0x5170('0x64')]=_0x3a9f39[_0x5170('0x62')]({'plain':!![]});interaction_log[_0x5170('0x10')](_0x5170('0x7a'),_0x512278[_0x5170('0x5f')]['id'],_0x512278[_0x5170('0x5f')][_0x5170('0x22')],_0x512278[_0x5170('0x5f')][_0x5170('0x7b')],_0xab4abe['interaction']['id'],_0x512278[_0x5170('0x41')]?JSON[_0x5170('0x59')](_0x512278[_0x5170('0x41')]):'null');return respondWithRpcPromise(_0x5170('0x7c'),_0x5170('0x7d'),_0xab4abe);}return null;})[_0x5170('0xf')](function(_0x4b7d12){var _0x319bb5=_0x5170('0x68')+_0x4b7d12[_0x5170('0x16')][_0x5170('0x69')];return db['sequelize']['query'](_0x319bb5,{'type':db['Sequelize'][_0x5170('0x6b')][_0x5170('0x6c')],'raw':!![]})[_0x5170('0xf')](function(_0x536d81){return _0x536d81;});})[_0x5170('0xf')](function(_0x3993d9){if(_0x3993d9){_0xab4abe[_0x5170('0x16')][_0x5170('0x7e')]=_0x3993d9[0x0];if(!_0x512278[_0x5170('0x41')][_0x5170('0x5e')])return;return db[_0x5170('0x6d')]['find']({'where':{'id':_0x512278['body'][_0x5170('0x5e')],'role':_0x5170('0x6e')},'attributes':['id',_0x5170('0x22'),'fullname',_0x5170('0x70'),_0x5170('0x71')],'raw':!![]});}return null;})[_0x5170('0xf')](function(_0x1823ee){if(!_0x1823ee)return null;_0xab4abe[_0x5170('0x16')][_0x5170('0x6e')]=_0x1823ee;return _0xab4abe;})['then'](function(_0x418156){if(_0x418156){_0x418156[_0x5170('0x16')]['interface']=util[_0x5170('0x58')](_0x5170('0x7f'),_0x512278[_0x5170('0x5f')][_0x5170('0x22')]);_0x418156[_0x5170('0x16')]['channel']=_0xab4abe['channel'];_0x418156[_0x5170('0x16')][_0x5170('0x75')]=_0xab4abe[_0x5170('0x74')];_0x418156[_0x5170('0x16')][_0x5170('0x76')]=_0x5170('0x78');_0x418156[_0x5170('0x16')][_0x5170('0x41')]=htmlToText[_0x5170('0x80')](_0xab4abe[_0x5170('0x16')][_0x5170('0x41')]);respondWithRpcPromise(_0x5170('0x77'),'EventManager',{'event':_0x5170('0x81'),'message':_0x418156[_0x5170('0x16')]},client9002);return _0xab4abe;}return null;})['then'](respondWithResult(_0xbfceb3,null))[_0x5170('0x3b')](handleError(_0xbfceb3,null));};exports['download']=function(_0x3ece65,_0x461fdb){var _0x3ace3e=moment()[_0x5170('0x82')]()['toString']();var _0x40d796=path[_0x5170('0x83')](config[_0x5170('0x52')],_0x5170('0x84'),'files',_0x5170('0x85'));var _0xd699d8=path['join'](config[_0x5170('0x52')],'server',_0x5170('0x86'),_0x5170('0x51'));var _0x161185=util[_0x5170('0x58')](_0x5170('0x87'),_0x3ace3e);return db[_0x5170('0x26')][_0x5170('0x3f')]({'where':{'id':_0x3ece65[_0x5170('0x3d')]['id']},'attributes':['id',_0x5170('0x41'),'from','to','cc','bcc',_0x5170('0x88'),_0x5170('0x89')],'include':_0x3ece65[_0x5170('0x2a')][_0x5170('0x51')]?[{'model':db[_0x5170('0x8a')],'as':_0x5170('0x8b')}]:undefined})[_0x5170('0xf')](handleEntityNotFound(_0x461fdb,null))[_0x5170('0xf')](function(_0x2dc03e){if(_0x2dc03e){var _0x36fdb1=_0x2dc03e;var _0x195f22={'from':_0x36fdb1['from'],'to':_0x36fdb1['to'],'subject':_0x36fdb1[_0x5170('0x88')],'html':htmlEntities['decode'](_0x36fdb1[_0x5170('0x41')]),'headers':{'Date':moment(_0x36fdb1[_0x5170('0x89')])[_0x5170('0x58')](_0x5170('0x8c'))},'attachments':[]};if(_0x2dc03e['cc']){_0x195f22['headers']['Cc']=_0x2dc03e['cc'];}if(_0x2dc03e['bcc']){_0x195f22['headers'][_0x5170('0x8d')]=_0x2dc03e['bcc'];}return new BPromise(function(_0x23e7ba,_0x51642d){if(_0x2dc03e['Attachments']){for(var _0x2e03f2=0x0;_0x2e03f2<_0x2dc03e[_0x5170('0x8b')][_0x5170('0x30')];_0x2e03f2++){var _0x3e0995=_0x2dc03e['Attachments'][_0x2e03f2];var _0x15d1c8=path['join'](_0xd699d8,_0x3e0995[_0x5170('0x54')]);if(fs[_0x5170('0x8e')](_0x15d1c8)){_0x195f22[_0x5170('0x51')][_0x5170('0x8f')]({'name':_0x3e0995[_0x5170('0x22')],'contentType':_0x3e0995['type'],'data':fs[_0x5170('0x90')](_0x15d1c8)});}}}emlformat['build'](_0x195f22,function(_0xa84862,_0x2b5632){if(_0xa84862)return _0x51642d(_0xa84862);fs[_0x5170('0x91')](path[_0x5170('0x83')](_0x40d796,_0x161185),_0x2b5632);return _0x23e7ba(_0x2b5632);});});}})[_0x5170('0xf')](function(_0x318586){if(_0x318586){return _0x461fdb[_0x5170('0x92')](path[_0x5170('0x83')](_0x40d796,_0x161185),_0x161185,function(_0x58c959){if(!_0x58c959)fs[_0x5170('0x93')](path[_0x5170('0x83')](_0x40d796,_0x161185));});}})[_0x5170('0x3b')](handleError(_0x461fdb,null));};
\ No newline at end of file