Built motion from commit e0fa946e.|2.6.5
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 92e1190..17e264a 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x5c1f=['where','filters','pick','filter','merge','VIRTUAL','includeAll','include','findAll','rows','params','rawAttributes','find','describe','create','body','out','secret','split','MailAccount','findOne','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','isNil','service','port','secure','authentication','auth','user','pass','attachments','join','root','basename','List','ListId','List\x20not\x20found','SendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','mail-interactions','mail','read','readAt','Contact','MailInteraction','MailInteractionId','UserId','read1stAt','interaction','get','info','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','AcceptMessage','acceptMessage','manual','SIP/%s','channel','accept','EventManager','agent','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','interface','event','download','unix','toString','server','files','tmp','message-%s.eml','from','bcc','Attachments','subject','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','readFileSync','build','writeFileSync','log','err','unlinkSync','html-pdf','rimraf','zip-dir','request-promise','moment','bluebird','sox','to-csv','lodash','squel','crypto','jsforce','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/logger','api','../../config/utils','../../mysqldb','redis','defaults','localhost','register','jayson/promise','client','http','test','Sequelize','The\x20password\x20must\x20be\x20at\x20least\x208\x20characters\x20long\x20and\x20have\x201\x20lowercase\x20character,\x201\x20uppercase\x20character,\x201\x20number\x20and\x201\x20special\x20character\x20~!@#$%^&-_=+[{]}.','then','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','catch','sendStatus','status','end','json','count','offset','limit','set','Content-Range','apply','save','update','destroy','stack','name','send','map','MailMessage','type','model','query','keys','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort'];(function(_0x40f6d4,_0x5b116d){var _0x42a3ad=function(_0x3d7611){while(--_0x3d7611){_0x40f6d4['push'](_0x40f6d4['shift']());}};_0x42a3ad(++_0x5b116d);}(_0x5c1f,0x1b3));var _0xf5c1=function(_0x87239,_0x38c793){_0x87239=_0x87239-0x0;var _0x53af1e=_0x5c1f[_0x87239];return _0x53af1e;};'use strict';var pdf=require(_0xf5c1('0x0'));var emlformat=require('eml-format');var rimraf=require(_0xf5c1('0x1'));var zipdir=require(_0xf5c1('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0xf5c1('0x3'));var moment=require(_0xf5c1('0x4'));var BPromise=require(_0xf5c1('0x5'));var Mustache=require('mustache');var util=require('util');var path=require('path');var sox=require(_0xf5c1('0x6'));var csv=require(_0xf5c1('0x7'));var ejs=require('ejs');var fs=require('fs');var _=require(_0xf5c1('0x8'));var squel=require(_0xf5c1('0x9'));var crypto=require(_0xf5c1('0xa'));var jsforce=require(_0xf5c1('0xb'));var deskjs=require('desk.js');var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require('papaparse');var Redis=require(_0xf5c1('0xc'));var authService=require(_0xf5c1('0xd'));var qs=require(_0xf5c1('0xe'));var as=require(_0xf5c1('0xf'));var hardwareService=require(_0xf5c1('0x10'));var logger=require(_0xf5c1('0x11'))(_0xf5c1('0x12'));var utils=require(_0xf5c1('0x13'));var config=require('../../config/environment');var db=require(_0xf5c1('0x14'))['db'];config[_0xf5c1('0x15')]=_[_0xf5c1('0x16')](config[_0xf5c1('0x15')],{'host':_0xf5c1('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0xf5c1('0x15')]));require('./mailMessage.socket')[_0xf5c1('0x18')](socket);var jayson=require(_0xf5c1('0x19'));var client=jayson[_0xf5c1('0x1a')]['http']({'port':0x232c});var client9003=jayson[_0xf5c1('0x1a')][_0xf5c1('0x1b')]({'port':0x232b});var client9002=jayson[_0xf5c1('0x1a')][_0xf5c1('0x1b')]({'port':0x232a});function checkPasswordPattern(_0x5891a9,_0x453d5b,_0x14934a){if(_0x14934a){var _0x312d6b=new RegExp(/(?=.*[a-z])(?=.*[A-Z])(?=.*[0-9])(?=.*[?!@#\$%\^&\*~\-_=+[{\]\}])(?=.{8,})/);if(_0x312d6b[_0xf5c1('0x1c')](_0x453d5b)){return _0x5891a9;}else{throw new db[(_0xf5c1('0x1d'))]['ValidationError'](_0xf5c1('0x1e'));}}else{return _0x5891a9;}}function respondWithRpcPromise(_0x280727,_0x2d1db9,_0x17d627,_0x4055c4){return new BPromise(function(_0x31f1a8,_0x199e25){var _0xe73adc=_0x4055c4||client;return _0xe73adc['request'](_0x280727,_0x17d627)[_0xf5c1('0x1f')](function(_0x21c7f4){logger['info'](_0xf5c1('0x20'),_0x2d1db9,_0xf5c1('0x21'));logger[_0xf5c1('0x22')](_0xf5c1('0x23'),_0x2d1db9,_0xf5c1('0x21'),JSON[_0xf5c1('0x24')](_0x21c7f4));if(_0x21c7f4[_0xf5c1('0x25')]){if(_0x21c7f4['error'][_0xf5c1('0x26')]===0x1f4){logger[_0xf5c1('0x25')](_0xf5c1('0x20'),_0x2d1db9,_0x21c7f4['error'][_0xf5c1('0x27')]);return _0x199e25(_0x21c7f4[_0xf5c1('0x25')][_0xf5c1('0x27')]);}logger[_0xf5c1('0x25')]('MailMessage,\x20%s,\x20%s',_0x2d1db9,_0x21c7f4[_0xf5c1('0x25')][_0xf5c1('0x27')]);return _0x31f1a8(_0x21c7f4[_0xf5c1('0x25')][_0xf5c1('0x27')]);}else{logger['info']('MailMessage,\x20%s,\x20%s',_0x2d1db9,_0xf5c1('0x21'));_0x31f1a8(_0x21c7f4[_0xf5c1('0x28')][_0xf5c1('0x27')]);}})[_0xf5c1('0x29')](function(_0x5392be){logger[_0xf5c1('0x25')](_0xf5c1('0x20'),_0x2d1db9,_0x5392be);_0x199e25(_0x5392be);});});}function respondWithStatusCode(_0x579eea,_0x58c355){_0x58c355=_0x58c355||0xcc;return function(_0x3ac679){if(_0x3ac679){return _0x579eea[_0xf5c1('0x2a')](_0x58c355);}return _0x579eea[_0xf5c1('0x2b')](_0x58c355)[_0xf5c1('0x2c')]();};}function respondWithResult(_0x5eb7cd,_0x24ff24){_0x24ff24=_0x24ff24||0xc8;return function(_0x2cd483){if(_0x2cd483){return _0x5eb7cd[_0xf5c1('0x2b')](_0x24ff24)[_0xf5c1('0x2d')](_0x2cd483);}};}function respondWithFilteredResult(_0x4670ad,_0x220e31){return function(_0x5212a7){if(_0x5212a7){var _0x14ca67=_0x5212a7[_0xf5c1('0x2e')],_0x2a6ec1=_0x220e31['offset'],_0x50efb7=_0x220e31[_0xf5c1('0x2f')]+_0x220e31[_0xf5c1('0x30')],_0x5a8495;if(_0x50efb7>=_0x14ca67){_0x50efb7=_0x14ca67;_0x5a8495=0xc8;}else{_0x5a8495=0xce;}_0x4670ad[_0xf5c1('0x2b')](_0x5a8495);return _0x4670ad[_0xf5c1('0x31')](_0xf5c1('0x32'),_0x2a6ec1+'-'+_0x50efb7+'/'+_0x14ca67)[_0xf5c1('0x2d')](_0x5212a7);}return null;};}function patchUpdates(_0x1874e0){return function(_0x439104){try{jsonpatch[_0xf5c1('0x33')](_0x439104,_0x1874e0,!![]);}catch(_0x447b35){return BPromise['reject'](_0x447b35);}return _0x439104[_0xf5c1('0x34')]();};}function saveUpdates(_0xc16cd7,_0x129945){return function(_0x12510e){if(_0x12510e){return _0x12510e[_0xf5c1('0x35')](_0xc16cd7)[_0xf5c1('0x1f')](function(_0x2c6eab){return _0x2c6eab;});}return null;};}function removeEntity(_0x3ab69b,_0x33c7a9){return function(_0x47bc09){if(_0x47bc09){return _0x47bc09[_0xf5c1('0x36')]()[_0xf5c1('0x1f')](function(){_0x3ab69b[_0xf5c1('0x2b')](0xcc)[_0xf5c1('0x2c')]();});}};}function handleEntityNotFound(_0x2a1123,_0x25070f){return function(_0x7371f8){if(!_0x7371f8){_0x2a1123[_0xf5c1('0x2a')](0x194);}return _0x7371f8;};}function handleError(_0x5f2055,_0x7392fc){_0x7392fc=_0x7392fc||0x1f4;return function(_0x552994){logger[_0xf5c1('0x25')](_0x552994[_0xf5c1('0x37')]);if(_0x552994[_0xf5c1('0x38')]){delete _0x552994[_0xf5c1('0x38')];}_0x5f2055[_0xf5c1('0x2b')](_0x7392fc)[_0xf5c1('0x39')](_0x552994);};}exports['index']=function(_0xf5dd29,_0x28ebe3){var _0x18e751={},_0x1e536b={},_0x48c050={'count':0x0,'rows':[]};var _0x644960=_[_0xf5c1('0x3a')](db[_0xf5c1('0x3b')]['rawAttributes'],function(_0x44b397){return{'name':_0x44b397['fieldName'],'type':_0x44b397[_0xf5c1('0x3c')]['key']};});_0x1e536b[_0xf5c1('0x3d')]=_[_0xf5c1('0x3a')](_0x644960,_0xf5c1('0x38'));_0x1e536b[_0xf5c1('0x3e')]=_[_0xf5c1('0x3f')](_0xf5dd29[_0xf5c1('0x3e')]);_0x1e536b['filters']=_['intersection'](_0x1e536b['model'],_0x1e536b['query']);_0x18e751[_0xf5c1('0x40')]=_[_0xf5c1('0x41')](_0x1e536b[_0xf5c1('0x3d')],qs[_0xf5c1('0x42')](_0xf5dd29[_0xf5c1('0x3e')][_0xf5c1('0x42')]));_0x18e751[_0xf5c1('0x40')]=_0x18e751[_0xf5c1('0x40')][_0xf5c1('0x43')]?_0x18e751[_0xf5c1('0x40')]:_0x1e536b['model'];if(!_0xf5dd29[_0xf5c1('0x3e')][_0xf5c1('0x44')](_0xf5c1('0x45'))){_0x18e751[_0xf5c1('0x30')]=qs[_0xf5c1('0x30')](_0xf5dd29['query']['limit']);_0x18e751[_0xf5c1('0x2f')]=qs['offset'](_0xf5dd29[_0xf5c1('0x3e')][_0xf5c1('0x2f')]);}_0x18e751[_0xf5c1('0x46')]=qs['sort'](_0xf5dd29[_0xf5c1('0x3e')][_0xf5c1('0x47')]);_0x18e751[_0xf5c1('0x48')]=qs[_0xf5c1('0x49')](_[_0xf5c1('0x4a')](_0xf5dd29['query'],_0x1e536b[_0xf5c1('0x49')]),_0x644960);if(_0xf5dd29[_0xf5c1('0x3e')][_0xf5c1('0x4b')]){_0x18e751[_0xf5c1('0x48')]=_[_0xf5c1('0x4c')](_0x18e751[_0xf5c1('0x48')],{'$or':_['map'](_0x644960,function(_0x1cd41f){if(_0x1cd41f[_0xf5c1('0x3c')]!==_0xf5c1('0x4d')){var _0x5868cf={};_0x5868cf[_0x1cd41f[_0xf5c1('0x38')]]={'$like':'%'+_0xf5dd29[_0xf5c1('0x3e')]['filter']+'%'};return _0x5868cf;}})});}_0x18e751=_[_0xf5c1('0x4c')]({},_0x18e751,_0xf5dd29['options']);var _0x33ff54={'where':_0x18e751[_0xf5c1('0x48')]};return db[_0xf5c1('0x3b')][_0xf5c1('0x2e')](_0x33ff54)[_0xf5c1('0x1f')](function(_0xf2df6a){_0x48c050['count']=_0xf2df6a;if(_0xf5dd29['query'][_0xf5c1('0x4e')]){_0x18e751[_0xf5c1('0x4f')]=[{'all':!![]}];}return db[_0xf5c1('0x3b')][_0xf5c1('0x50')](_0x18e751);})[_0xf5c1('0x1f')](function(_0x11d912){_0x48c050[_0xf5c1('0x51')]=_0x11d912;return _0x48c050;})[_0xf5c1('0x1f')](respondWithFilteredResult(_0x28ebe3,_0x18e751))[_0xf5c1('0x29')](handleError(_0x28ebe3,null));};exports['show']=function(_0x5d6aaf,_0x231969){var _0x42bb91={'raw':!![],'where':{'id':_0x5d6aaf[_0xf5c1('0x52')]['id']}},_0x22e389={};_0x22e389[_0xf5c1('0x3d')]=_['keys'](db[_0xf5c1('0x3b')][_0xf5c1('0x53')]);_0x22e389[_0xf5c1('0x3e')]=_[_0xf5c1('0x3f')](_0x5d6aaf['query']);_0x22e389[_0xf5c1('0x49')]=_[_0xf5c1('0x41')](_0x22e389['model'],_0x22e389[_0xf5c1('0x3e')]);_0x42bb91['attributes']=_[_0xf5c1('0x41')](_0x22e389['model'],qs[_0xf5c1('0x42')](_0x5d6aaf[_0xf5c1('0x3e')][_0xf5c1('0x42')]));_0x42bb91[_0xf5c1('0x40')]=_0x42bb91[_0xf5c1('0x40')][_0xf5c1('0x43')]?_0x42bb91[_0xf5c1('0x40')]:_0x22e389[_0xf5c1('0x3d')];if(_0x5d6aaf[_0xf5c1('0x3e')][_0xf5c1('0x4e')]){_0x42bb91[_0xf5c1('0x4f')]=[{'all':!![]}];}_0x42bb91=_[_0xf5c1('0x4c')]({},_0x42bb91,_0x5d6aaf['options']);return db[_0xf5c1('0x3b')][_0xf5c1('0x54')](_0x42bb91)[_0xf5c1('0x1f')](handleEntityNotFound(_0x231969,null))[_0xf5c1('0x1f')](respondWithResult(_0x231969,null))[_0xf5c1('0x29')](handleError(_0x231969,null));};exports[_0xf5c1('0x35')]=function(_0xf26982,_0x437466){if(_0xf26982['body']['id']){delete _0xf26982['body']['id'];}return db[_0xf5c1('0x3b')]['find']({'where':{'id':_0xf26982[_0xf5c1('0x52')]['id']}})[_0xf5c1('0x1f')](handleEntityNotFound(_0x437466,null))[_0xf5c1('0x1f')](saveUpdates(_0xf26982['body'],null))['then'](respondWithResult(_0x437466,null))['catch'](handleError(_0x437466,null));};exports[_0xf5c1('0x36')]=function(_0x15f93f,_0x22cfd2){return db['MailMessage'][_0xf5c1('0x54')]({'where':{'id':_0x15f93f['params']['id']}})[_0xf5c1('0x1f')](handleEntityNotFound(_0x22cfd2,null))['then'](removeEntity(_0x22cfd2,null))[_0xf5c1('0x29')](handleError(_0x22cfd2,null));};exports['describe']=function(_0xda4e93,_0x17c807){return db[_0xf5c1('0x3b')][_0xf5c1('0x55')]()[_0xf5c1('0x1f')](respondWithResult(_0x17c807,null))[_0xf5c1('0x29')](handleError(_0x17c807,null));};exports[_0xf5c1('0x56')]=function(_0x5e2ee4,_0x5bd778){return db['MailMessage'][_0xf5c1('0x56')](_0x5e2ee4[_0xf5c1('0x57')])[_0xf5c1('0x1f')](function(_0x1a4a2d){if(_0x1a4a2d){if(_0x1a4a2d['direction']===_0xf5c1('0x58')&&!_0x1a4a2d[_0xf5c1('0x59')]){var _0x36fd86,_0x35ff76,_0x40c7de;if(_0x5e2ee4['body']['to']){_0x35ff76=_0x5e2ee4[_0xf5c1('0x57')]['to'][_0xf5c1('0x5a')](',')[0x0];}return db[_0xf5c1('0x5b')][_0xf5c1('0x5c')]({'where':{'id':_0x1a4a2d[_0xf5c1('0x5d')]},'include':[{'model':db[_0xf5c1('0x5e')],'as':'List','include':[{'model':db[_0xf5c1('0x5f')],'as':_0xf5c1('0x60'),'where':{'email':_0x35ff76},'limit':0x1,'order':[[_0xf5c1('0x61'),_0xf5c1('0x62')]]}]},{'model':db[_0xf5c1('0x63')],'as':'Smtp','raw':!![]}]})[_0xf5c1('0x1f')](function(_0x403e75){_0x36fd86=_0x403e75;if(_0x36fd86&&_0x36fd86[_0xf5c1('0x64')]){var _0x21bc08={'tls':{'rejectUnauthorized':![]}};if(_[_0xf5c1('0x65')](_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x66')])){_0x21bc08['host']=_0x36fd86['Smtp']['host'];_0x21bc08[_0xf5c1('0x67')]=_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x67')];_0x21bc08[_0xf5c1('0x68')]=_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x68')];if(_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x69')]){_0x21bc08[_0xf5c1('0x6a')]={'user':_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x6b')],'pass':_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x6c')]};}}else{_0x21bc08['service']=_0x36fd86[_0xf5c1('0x64')]['service'];_0x21bc08['auth']={'user':_0x36fd86[_0xf5c1('0x64')]['user'],'pass':_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x6c')]};_0x21bc08[_0xf5c1('0x68')]=_0x36fd86[_0xf5c1('0x64')][_0xf5c1('0x68')];}if(_0x5e2ee4[_0xf5c1('0x57')][_0xf5c1('0x6d')]&&_0x5e2ee4[_0xf5c1('0x57')][_0xf5c1('0x6d')]['length']){for(var _0x327ed7=0x0;_0x327ed7<_0x5e2ee4[_0xf5c1('0x57')]['attachments'][_0xf5c1('0x43')];_0x327ed7+=0x1){_0x5e2ee4['body'][_0xf5c1('0x6d')][_0x327ed7]={'filename':_0x5e2ee4['body']['attachments'][_0x327ed7][_0xf5c1('0x38')],'path':path[_0xf5c1('0x6e')](config[_0xf5c1('0x6f')],'server/files/attachments',_0x5e2ee4[_0xf5c1('0x57')][_0xf5c1('0x6d')][_0x327ed7][_0xf5c1('0x70')])};}}_0x40c7de={'account':_0x21bc08,'message':_0x5e2ee4[_0xf5c1('0x57')]};return;}})[_0xf5c1('0x1f')](function(){if(_0x36fd86[_0xf5c1('0x71')]){if(_0x36fd86[_0xf5c1('0x71')][_0xf5c1('0x60')][_0xf5c1('0x43')]){return _0x36fd86[_0xf5c1('0x71')][_0xf5c1('0x60')][0x0];}else{return db['CmContact'][_0xf5c1('0x56')](_[_0xf5c1('0x16')](_0x5e2ee4[_0xf5c1('0x57')],{'firstName':_0x5e2ee4[_0xf5c1('0x57')]['to'],'email':_0x5e2ee4['body']['to'],'phone':_0x5e2ee4[_0xf5c1('0x57')]['to'],'ListId':_0x36fd86[_0xf5c1('0x72')]}));}}else{throw new Error(_0xf5c1('0x73'));}})[_0xf5c1('0x1f')](function(){if(_0x40c7de){return respondWithRpcPromise(_0xf5c1('0x74'),'sendMail',_0x40c7de,client9003)['then'](function(_0x2c9994){return _0x1a4a2d['update']({'read':!![],'messageId':_0x2c9994[_0xf5c1('0x75')],'sentAt':moment()[_0xf5c1('0x76')](_0xf5c1('0x77'))});})[_0xf5c1('0x29')](function(_0x18ccc3){logger[_0xf5c1('0x25')]('%s',JSON[_0xf5c1('0x24')](_0x18ccc3));return _0x1a4a2d;});}return _0x1a4a2d;});}return _0x1a4a2d;}})[_0xf5c1('0x1f')](respondWithResult(_0x5bd778,0xc9))[_0xf5c1('0x29')](handleError(_0x5bd778,null));};var interaction_log=require('../../config/logger')(_0xf5c1('0x78'));exports['accept']=function(_0x57dcd3,_0x139025,_0x5cca57){var _0x34d676={'channel':_0xf5c1('0x79')};if(_0x57dcd3[_0xf5c1('0x57')]['id']){delete _0x57dcd3[_0xf5c1('0x57')]['id'];}_0x57dcd3[_0xf5c1('0x57')][_0xf5c1('0x7a')]=!![];_0x57dcd3['body'][_0xf5c1('0x7b')]=moment()['format'](_0xf5c1('0x77'));_0x57dcd3['body']['UserId']=_0x57dcd3[_0xf5c1('0x57')]['UserId']||_0x57dcd3[_0xf5c1('0x6b')]['id'];return db[_0xf5c1('0x3b')][_0xf5c1('0x54')]({'where':{'id':_0x57dcd3[_0xf5c1('0x52')]['id'],'UserId':null},'include':[{'model':db['CmContact'],'as':_0xf5c1('0x7c')}]})['then'](handleEntityNotFound(_0x139025,null))[_0xf5c1('0x1f')](saveUpdates(_0x57dcd3[_0xf5c1('0x57')],null))[_0xf5c1('0x1f')](function(_0x4fab89){if(_0x4fab89){_0x34d676[_0xf5c1('0x27')]=_0x4fab89['get']({'plain':!![]});return db[_0xf5c1('0x7d')][_0xf5c1('0x54')]({'where':{'id':_0x4fab89[_0xf5c1('0x7e')]}});}return null;})[_0xf5c1('0x1f')](handleEntityNotFound(_0x139025,null))[_0xf5c1('0x1f')](function(_0x542853){if(_0x542853){return _0x542853['update']({'UserId':_0x57dcd3[_0xf5c1('0x57')][_0xf5c1('0x7f')],'read1stAt':_['isNil'](_0x542853[_0xf5c1('0x80')])?moment()[_0xf5c1('0x76')](_0xf5c1('0x77')):undefined});}return null;})['then'](function(_0x5a86fd){if(_0x5a86fd){_0x34d676[_0xf5c1('0x81')]=_0x5a86fd[_0xf5c1('0x82')]({'plain':!![]});interaction_log[_0xf5c1('0x83')](_0xf5c1('0x84'),_0x57dcd3[_0xf5c1('0x6b')]['id'],_0x57dcd3[_0xf5c1('0x6b')][_0xf5c1('0x38')],_0x57dcd3[_0xf5c1('0x6b')]['role'],_0x34d676[_0xf5c1('0x81')]['id'],_0x57dcd3['body']?JSON[_0xf5c1('0x24')](_0x57dcd3[_0xf5c1('0x57')]):_0xf5c1('0x85'));return respondWithRpcPromise(_0xf5c1('0x86'),_0xf5c1('0x87'),_0x34d676);}return null;})['then'](function(_0x3f6a20){if(_0x3f6a20){if(_0x57dcd3[_0xf5c1('0x57')][_0xf5c1('0x88')]){_0x34d676[_0xf5c1('0x27')]['interface']=util['format'](_0xf5c1('0x89'),_0x57dcd3[_0xf5c1('0x6b')][_0xf5c1('0x38')]);_0x34d676[_0xf5c1('0x27')]['channel']=_0x34d676[_0xf5c1('0x8a')];_0x34d676['message']['event']=_0xf5c1('0x8b');return respondWithRpcPromise(_0xf5c1('0x8c'),_0xf5c1('0x8c'),{'event':'acceptmessage','message':_0x34d676[_0xf5c1('0x27')]},client9002)[_0xf5c1('0x1f')](function(){return _0x34d676;});}return _0x34d676;}return null;})['then'](respondWithResult(_0x139025,null))[_0xf5c1('0x29')](handleError(_0x139025,null));};var interaction_log=require(_0xf5c1('0x11'))(_0xf5c1('0x78'));exports['reject']=function(_0xe134bf,_0x1223fe,_0x3ea1e3){var _0xb774b6={'agent':{},'channel':'mail'};if(_0xe134bf[_0xf5c1('0x57')]['id']){delete _0xe134bf[_0xf5c1('0x57')]['id'];}_0xe134bf[_0xf5c1('0x57')][_0xf5c1('0x7f')]=_0xe134bf['body']['UserId']||_0xe134bf['user']['id'];_0xb774b6[_0xf5c1('0x8d')]['id']=_0xe134bf['body'][_0xf5c1('0x7f')];return db['MailMessage'][_0xf5c1('0x54')]({'where':{'id':_0xe134bf[_0xf5c1('0x52')]['id'],'UserId':null}})[_0xf5c1('0x1f')](handleEntityNotFound(_0x1223fe,null))[_0xf5c1('0x1f')](function(_0x116169){if(_0x116169){_0xb774b6[_0xf5c1('0x27')]=_0x116169['get']({'plain':!![]});return db[_0xf5c1('0x7d')][_0xf5c1('0x54')]({'where':{'id':_0x116169[_0xf5c1('0x7e')]}});}return null;})[_0xf5c1('0x1f')](handleEntityNotFound(_0x1223fe,null))[_0xf5c1('0x1f')](function(_0x15437c){if(_0x15437c){_0xb774b6[_0xf5c1('0x81')]=_0x15437c[_0xf5c1('0x82')]({'plain':!![]});interaction_log[_0xf5c1('0x83')](_0xf5c1('0x8e'),_0xe134bf[_0xf5c1('0x6b')]['id'],_0xe134bf[_0xf5c1('0x6b')][_0xf5c1('0x38')],_0xe134bf[_0xf5c1('0x6b')]['role'],_0xb774b6[_0xf5c1('0x81')]['id'],_0xe134bf[_0xf5c1('0x57')]?JSON[_0xf5c1('0x24')](_0xe134bf[_0xf5c1('0x57')]):'null');return respondWithRpcPromise(_0xf5c1('0x8f'),_0xf5c1('0x90'),_0xb774b6);}return null;})[_0xf5c1('0x1f')](function(_0x3c2f58){if(_0x3c2f58){_0x3c2f58[_0xf5c1('0x27')][_0xf5c1('0x91')]=util['format']('SIP/%s',_0xe134bf[_0xf5c1('0x6b')]['name']);_0x3c2f58['message'][_0xf5c1('0x8a')]=_0xb774b6[_0xf5c1('0x8a')];_0x3c2f58[_0xf5c1('0x27')][_0xf5c1('0x92')]='reject';respondWithRpcPromise(_0xf5c1('0x8c'),_0xf5c1('0x8c'),{'event':'rejectmessage','message':_0x3c2f58[_0xf5c1('0x27')]},client9002);return _0xb774b6;}return null;})[_0xf5c1('0x1f')](respondWithResult(_0x1223fe,null))[_0xf5c1('0x29')](handleError(_0x1223fe,null));};exports[_0xf5c1('0x93')]=function(_0x430af2,_0x9949f2){var _0x21b2cb=moment()[_0xf5c1('0x94')]()[_0xf5c1('0x95')]();var _0x4d4316=path[_0xf5c1('0x6e')](config[_0xf5c1('0x6f')],_0xf5c1('0x96'),_0xf5c1('0x97'),_0xf5c1('0x98'));var _0x17d46a=path[_0xf5c1('0x6e')](config[_0xf5c1('0x6f')],_0xf5c1('0x96'),_0xf5c1('0x97'),_0xf5c1('0x6d'));var _0x10b2ac=util[_0xf5c1('0x76')](_0xf5c1('0x99'),_0x21b2cb);return db[_0xf5c1('0x3b')]['find']({'where':{'id':_0x430af2[_0xf5c1('0x52')]['id']},'attributes':['id',_0xf5c1('0x57'),_0xf5c1('0x9a'),'to','cc',_0xf5c1('0x9b'),'subject','createdAt'],'include':_0x430af2[_0xf5c1('0x3e')]['attachments']?[{'model':db['Attachment'],'as':_0xf5c1('0x9c')}]:undefined})['then'](handleEntityNotFound(_0x9949f2,null))[_0xf5c1('0x1f')](function(_0x2e62e7){if(_0x2e62e7){var _0x17b5ec=_0x2e62e7;var _0x212a77={'from':_0x17b5ec[_0xf5c1('0x9a')],'to':_0x17b5ec['to'],'subject':_0x17b5ec[_0xf5c1('0x9d')],'html':_0x17b5ec[_0xf5c1('0x57')],'headers':{'Date':moment(_0x17b5ec['createdAt'])[_0xf5c1('0x76')](_0xf5c1('0x9e'))},'attachments':[]};if(_0x2e62e7['cc']){_0x212a77[_0xf5c1('0x9f')]['Cc']=_0x2e62e7['cc'];}if(_0x2e62e7[_0xf5c1('0x9b')]){_0x212a77['headers'][_0xf5c1('0xa0')]=_0x2e62e7[_0xf5c1('0x9b')];}return new BPromise(function(_0xfe2632,_0x4a9b3b){if(_0x2e62e7[_0xf5c1('0x9c')]){for(var _0x189b3f=0x0;_0x189b3f<_0x2e62e7['Attachments']['length'];_0x189b3f++){var _0x34036d=_0x2e62e7[_0xf5c1('0x9c')][_0x189b3f];var _0x1dc66f=path[_0xf5c1('0x6e')](_0x17d46a,_0x34036d[_0xf5c1('0x70')]);if(fs[_0xf5c1('0xa1')](_0x1dc66f)){_0x212a77[_0xf5c1('0x6d')][_0xf5c1('0xa2')]({'name':_0x34036d[_0xf5c1('0x38')],'contentType':_0x34036d['type'],'data':fs[_0xf5c1('0xa3')](_0x1dc66f)});}}}emlformat[_0xf5c1('0xa4')](_0x212a77,function(_0x202117,_0x4fa5ce){if(_0x202117)return _0x4a9b3b(_0x202117);fs[_0xf5c1('0xa5')](path['join'](_0x4d4316,_0x10b2ac),_0x4fa5ce);return _0xfe2632(_0x4fa5ce);});});}})[_0xf5c1('0x1f')](function(_0x3371cd){if(_0x3371cd){return _0x9949f2[_0xf5c1('0x93')](path['join'](_0x4d4316,_0x10b2ac),_0x10b2ac,function(_0x331fce){if(_0x331fce){console[_0xf5c1('0xa6')](_0xf5c1('0xa7'),_0x331fce);}else{fs[_0xf5c1('0xa8')](path[_0xf5c1('0x6e')](_0x4d4316,_0x10b2ac));}});}})[_0xf5c1('0x29')](handleError(_0x9949f2,null));};
\ No newline at end of file
+var _0x5a76=['join','root','server/files/attachments','basename','List','ListId','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','read','readAt','UserId','user','agent','MailInteraction','MailInteractionId','isNil','get','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','Sequelize','contact','User','fullname','email','internal','channel','motionChannel','event','fromString','EventManager','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','null','rejectMessage','SIP/%s','reject','rejectmessage','download','toString','files','tmp','server','message-%s.eml','from','bcc','createdAt','Attachment','Attachments','subject','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','existsSync','push','type','readFileSync','build','unlinkSync','eml-format','moment','util','path','lodash','ioredis','html-to-text','../../components/parsers/qs','../../config/logger','mail-interactions','../../mysqldb','redis','defaults','localhost','socket.io-emitter','html-entities','./mailMessage.socket','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','catch','status','json','offset','undefined','limit','count','Content-Range','update','destroy','end','sendStatus','stack','name','send','index','map','rawAttributes','key','model','query','keys','filters','intersection','attributes','length','hasOwnProperty','nolimit','order','sort','where','pick','filter','merge','MailMessage','includeAll','findAll','rows','params','fields','include','options','find','body','describe','create','direction','MailAccount','findOne','MailAccountId','CmList','CmContact','Contacts','updatedAt','DESC','MailServerOut','Smtp','CloudProvider','getSmtpOptions','attachments'];(function(_0x1006d5,_0x31bf70){var _0x4513da=function(_0x345cb6){while(--_0x345cb6){_0x1006d5['push'](_0x1006d5['shift']());}};_0x4513da(++_0x31bf70);}(_0x5a76,0xe2));var _0x65a7=function(_0x57dbbe,_0x70f5bb){_0x57dbbe=_0x57dbbe-0x0;var _0x4b82ab=_0x5a76[_0x57dbbe];return _0x4b82ab;};'use strict';var emlformat=require(_0x65a7('0x0'));var moment=require(_0x65a7('0x1'));var BPromise=require('bluebird');var util=require(_0x65a7('0x2'));var path=require(_0x65a7('0x3'));var fs=require('fs');var _=require(_0x65a7('0x4'));var Redis=require(_0x65a7('0x5'));var htmlToText=require(_0x65a7('0x6'));var qs=require(_0x65a7('0x7'));var logger=require('../../config/logger')('api');var interaction_log=require(_0x65a7('0x8'))(_0x65a7('0x9'));var config=require('../../config/environment');var db=require(_0x65a7('0xa'))['db'];config[_0x65a7('0xb')]=_[_0x65a7('0xc')](config['redis'],{'host':_0x65a7('0xd'),'port':0x18eb});var socket=require(_0x65a7('0xe'))(new Redis(config[_0x65a7('0xb')]));var htmlEntities=require(_0x65a7('0xf'));require(_0x65a7('0x10'))['register'](socket);var jayson=require('jayson/promise');var client=jayson[_0x65a7('0x11')][_0x65a7('0x12')]({'port':0x232c});var client9003=jayson['client'][_0x65a7('0x12')]({'port':0x232b});var client9002=jayson[_0x65a7('0x11')]['http']({'port':0x232a});function respondWithRpcPromise(_0xe0424e,_0x5c1bd5,_0x26bde5,_0x3ccb97){return new BPromise(function(_0x268d8e,_0x3caf23){var _0x10fdf1=_0x3ccb97||client;return _0x10fdf1[_0x65a7('0x13')](_0xe0424e,_0x26bde5)[_0x65a7('0x14')](function(_0x57056f){logger[_0x65a7('0x15')](_0x65a7('0x16'),_0x5c1bd5,_0x65a7('0x17'));logger[_0x65a7('0x18')](_0x65a7('0x19'),_0x5c1bd5,'request\x20sent',JSON[_0x65a7('0x1a')](_0x57056f));if(_0x57056f[_0x65a7('0x1b')]){if(_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1c')]===0x1f4){logger[_0x65a7('0x1b')](_0x65a7('0x16'),_0x5c1bd5,_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1d')]);return _0x3caf23(_0x57056f[_0x65a7('0x1b')]['message']);}logger[_0x65a7('0x1b')]('MailMessage,\x20%s,\x20%s',_0x5c1bd5,_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1d')]);return _0x268d8e(_0x57056f[_0x65a7('0x1b')][_0x65a7('0x1d')]);}else{logger[_0x65a7('0x15')](_0x65a7('0x16'),_0x5c1bd5,'request\x20sent');_0x268d8e(_0x57056f['result'][_0x65a7('0x1d')]);}})[_0x65a7('0x1e')](function(_0x11e78e){logger['error']('MailMessage,\x20%s,\x20%s',_0x5c1bd5,_0x11e78e);_0x3caf23(_0x11e78e);});});}function respondWithResult(_0x2f0ea4,_0x440748){_0x440748=_0x440748||0xc8;return function(_0x4a56dc){if(_0x4a56dc){return _0x2f0ea4[_0x65a7('0x1f')](_0x440748)[_0x65a7('0x20')](_0x4a56dc);}};}function respondWithFilteredResult(_0x5d3690,_0x1265b7){return function(_0x5bca20){if(_0x5bca20){var _0x54a25b=typeof _0x1265b7[_0x65a7('0x21')]===_0x65a7('0x22')&&typeof _0x1265b7[_0x65a7('0x23')]==='undefined';var _0xa5c745=_0x5bca20[_0x65a7('0x24')];var _0x395d93=_0x54a25b?0x0:_0x1265b7[_0x65a7('0x21')];var _0x13805d=_0x54a25b?_0x5bca20[_0x65a7('0x24')]:_0x1265b7[_0x65a7('0x21')]+_0x1265b7[_0x65a7('0x23')];var _0x3b039c;if(_0x13805d>=_0xa5c745){_0x13805d=_0xa5c745;_0x3b039c=0xc8;}else{_0x3b039c=0xce;}_0x5d3690['status'](_0x3b039c);return _0x5d3690['set'](_0x65a7('0x25'),_0x395d93+'-'+_0x13805d+'/'+_0xa5c745)[_0x65a7('0x20')](_0x5bca20);}return null;};}function saveUpdates(_0x3a82be){return function(_0x10a4d4){if(_0x10a4d4){return _0x10a4d4[_0x65a7('0x26')](_0x3a82be)[_0x65a7('0x14')](function(_0x416398){return _0x416398;});}return null;};}function removeEntity(_0x3cf50c){return function(_0x1006cb){if(_0x1006cb){return _0x1006cb[_0x65a7('0x27')]()[_0x65a7('0x14')](function(){_0x3cf50c[_0x65a7('0x1f')](0xcc)[_0x65a7('0x28')]();});}};}function handleEntityNotFound(_0x2f070d){return function(_0x4f0cd7){if(!_0x4f0cd7){_0x2f070d[_0x65a7('0x29')](0x194);}return _0x4f0cd7;};}function handleError(_0x20471a,_0x326d52){_0x326d52=_0x326d52||0x1f4;return function(_0x4dafb0){logger[_0x65a7('0x1b')](_0x4dafb0[_0x65a7('0x2a')]);if(_0x4dafb0[_0x65a7('0x2b')]){delete _0x4dafb0[_0x65a7('0x2b')];}_0x20471a['status'](_0x326d52)[_0x65a7('0x2c')](_0x4dafb0);};}exports[_0x65a7('0x2d')]=function(_0x43b2e5,_0x41af2e){var _0x33570f={},_0x1e57ca={},_0x3be263={'count':0x0,'rows':[]};var _0x2a2cbf=_[_0x65a7('0x2e')](db['MailMessage'][_0x65a7('0x2f')],function(_0x1077c8){return{'name':_0x1077c8['fieldName'],'type':_0x1077c8['type'][_0x65a7('0x30')]};});_0x1e57ca[_0x65a7('0x31')]=_[_0x65a7('0x2e')](_0x2a2cbf,_0x65a7('0x2b'));_0x1e57ca[_0x65a7('0x32')]=_[_0x65a7('0x33')](_0x43b2e5[_0x65a7('0x32')]);_0x1e57ca[_0x65a7('0x34')]=_[_0x65a7('0x35')](_0x1e57ca['model'],_0x1e57ca[_0x65a7('0x32')]);_0x33570f[_0x65a7('0x36')]=_[_0x65a7('0x35')](_0x1e57ca['model'],qs['fields'](_0x43b2e5[_0x65a7('0x32')]['fields']));_0x33570f[_0x65a7('0x36')]=_0x33570f[_0x65a7('0x36')][_0x65a7('0x37')]?_0x33570f['attributes']:_0x1e57ca['model'];if(!_0x43b2e5[_0x65a7('0x32')][_0x65a7('0x38')](_0x65a7('0x39'))){_0x33570f[_0x65a7('0x23')]=qs[_0x65a7('0x23')](_0x43b2e5[_0x65a7('0x32')]['limit']);_0x33570f[_0x65a7('0x21')]=qs[_0x65a7('0x21')](_0x43b2e5[_0x65a7('0x32')]['offset']);}_0x33570f[_0x65a7('0x3a')]=qs['sort'](_0x43b2e5['query'][_0x65a7('0x3b')]);_0x33570f[_0x65a7('0x3c')]=qs[_0x65a7('0x34')](_[_0x65a7('0x3d')](_0x43b2e5['query'],_0x1e57ca['filters']),_0x2a2cbf);if(_0x43b2e5['query'][_0x65a7('0x3e')]){_0x33570f['where']=_['merge'](_0x33570f[_0x65a7('0x3c')],{'$or':_[_0x65a7('0x2e')](_0x2a2cbf,function(_0x5c4efd){if(_0x5c4efd['type']!=='VIRTUAL'){var _0x54c762={};_0x54c762[_0x5c4efd[_0x65a7('0x2b')]]={'$like':'%'+_0x43b2e5['query'][_0x65a7('0x3e')]+'%'};return _0x54c762;}})});}_0x33570f=_[_0x65a7('0x3f')]({},_0x33570f,_0x43b2e5['options']);var _0x3c6bb7={'where':_0x33570f[_0x65a7('0x3c')]};return db[_0x65a7('0x40')][_0x65a7('0x24')](_0x3c6bb7)['then'](function(_0x4c659c){_0x3be263[_0x65a7('0x24')]=_0x4c659c;if(_0x43b2e5['query'][_0x65a7('0x41')]){_0x33570f['include']=[{'all':!![]}];}return db['MailMessage'][_0x65a7('0x42')](_0x33570f);})[_0x65a7('0x14')](function(_0x4360b2){_0x3be263[_0x65a7('0x43')]=_0x4360b2;return _0x3be263;})['then'](respondWithFilteredResult(_0x41af2e,_0x33570f))[_0x65a7('0x1e')](handleError(_0x41af2e,null));};exports['show']=function(_0x3dbd46,_0x59f62c){var _0x5e5706={'raw':!![],'where':{'id':_0x3dbd46[_0x65a7('0x44')]['id']}},_0x51f186={};_0x51f186[_0x65a7('0x31')]=_[_0x65a7('0x33')](db[_0x65a7('0x40')][_0x65a7('0x2f')]);_0x51f186[_0x65a7('0x32')]=_[_0x65a7('0x33')](_0x3dbd46[_0x65a7('0x32')]);_0x51f186['filters']=_[_0x65a7('0x35')](_0x51f186['model'],_0x51f186[_0x65a7('0x32')]);_0x5e5706[_0x65a7('0x36')]=_[_0x65a7('0x35')](_0x51f186[_0x65a7('0x31')],qs[_0x65a7('0x45')](_0x3dbd46[_0x65a7('0x32')][_0x65a7('0x45')]));_0x5e5706[_0x65a7('0x36')]=_0x5e5706[_0x65a7('0x36')][_0x65a7('0x37')]?_0x5e5706['attributes']:_0x51f186['model'];if(_0x3dbd46[_0x65a7('0x32')][_0x65a7('0x41')]){_0x5e5706[_0x65a7('0x46')]=[{'all':!![]}];}_0x5e5706=_['merge']({},_0x5e5706,_0x3dbd46[_0x65a7('0x47')]);return db[_0x65a7('0x40')][_0x65a7('0x48')](_0x5e5706)['then'](handleEntityNotFound(_0x59f62c,null))[_0x65a7('0x14')](respondWithResult(_0x59f62c,null))[_0x65a7('0x1e')](handleError(_0x59f62c,null));};exports[_0x65a7('0x26')]=function(_0x52a353,_0x3bc066){if(_0x52a353[_0x65a7('0x49')]['id']){delete _0x52a353[_0x65a7('0x49')]['id'];}return db['MailMessage'][_0x65a7('0x48')]({'where':{'id':_0x52a353[_0x65a7('0x44')]['id']}})[_0x65a7('0x14')](handleEntityNotFound(_0x3bc066,null))[_0x65a7('0x14')](saveUpdates(_0x52a353[_0x65a7('0x49')],null))['then'](respondWithResult(_0x3bc066,null))[_0x65a7('0x1e')](handleError(_0x3bc066,null));};exports[_0x65a7('0x27')]=function(_0x1f749e,_0x2cf774){return db[_0x65a7('0x40')][_0x65a7('0x48')]({'where':{'id':_0x1f749e[_0x65a7('0x44')]['id']}})[_0x65a7('0x14')](handleEntityNotFound(_0x2cf774,null))['then'](removeEntity(_0x2cf774,null))[_0x65a7('0x1e')](handleError(_0x2cf774,null));};exports[_0x65a7('0x4a')]=function(_0x588ba3,_0x3aa564){return db['MailMessage']['describe']()[_0x65a7('0x14')](respondWithResult(_0x3aa564,null))[_0x65a7('0x1e')](handleError(_0x3aa564,null));};exports[_0x65a7('0x4b')]=function(_0xbf8ccd,_0x3d3029){return db[_0x65a7('0x40')]['create'](_0xbf8ccd['body'])[_0x65a7('0x14')](function(_0x165898){if(_0x165898){if(_0x165898[_0x65a7('0x4c')]==='out'&&!_0x165898['secret']){var _0x4e2f52,_0x691899,_0x4d4ba2;if(_0xbf8ccd['body']['to']){_0x691899=_0xbf8ccd[_0x65a7('0x49')]['to']['split'](',')[0x0];}return db[_0x65a7('0x4d')][_0x65a7('0x4e')]({'where':{'id':_0x165898[_0x65a7('0x4f')]},'include':[{'model':db[_0x65a7('0x50')],'as':'List','include':[{'model':db[_0x65a7('0x51')],'as':_0x65a7('0x52'),'where':{'email':_0x691899},'limit':0x1,'order':[[_0x65a7('0x53'),_0x65a7('0x54')]]}]},{'model':db[_0x65a7('0x55')],'as':_0x65a7('0x56'),'raw':!![],'include':[{'model':db[_0x65a7('0x57')],'as':'CloudProvider','raw':!![]}]}]})[_0x65a7('0x14')](function(_0x36a720){_0x4e2f52=_0x36a720;if(!_0x4e2f52||!_0x4e2f52[_0x65a7('0x56')])return;var _0x365415=_0x4e2f52[_0x65a7('0x58')]();if(_0xbf8ccd[_0x65a7('0x49')][_0x65a7('0x59')]&&_0xbf8ccd[_0x65a7('0x49')][_0x65a7('0x59')]['length']){for(var _0x5caef3=0x0;_0x5caef3<_0xbf8ccd['body']['attachments'][_0x65a7('0x37')];_0x5caef3+=0x1){_0xbf8ccd[_0x65a7('0x49')]['attachments'][_0x5caef3]={'filename':_0xbf8ccd['body'][_0x65a7('0x59')][_0x5caef3][_0x65a7('0x2b')],'path':path[_0x65a7('0x5a')](config[_0x65a7('0x5b')],_0x65a7('0x5c'),_0xbf8ccd[_0x65a7('0x49')][_0x65a7('0x59')][_0x5caef3][_0x65a7('0x5d')])};}}_0x4d4ba2={'account':_0x365415,'message':_0xbf8ccd[_0x65a7('0x49')]};return;})[_0x65a7('0x14')](function(){if(_0x4e2f52['List']){if(_0x4e2f52[_0x65a7('0x5e')][_0x65a7('0x52')][_0x65a7('0x37')]){return _0x4e2f52[_0x65a7('0x5e')][_0x65a7('0x52')][0x0];}else{return db['CmContact'][_0x65a7('0x4b')](_[_0x65a7('0xc')](_0xbf8ccd[_0x65a7('0x49')],{'firstName':_0xbf8ccd[_0x65a7('0x49')]['to'],'email':_0xbf8ccd['body']['to'],'phone':_0xbf8ccd[_0x65a7('0x49')]['to'],'ListId':_0x4e2f52[_0x65a7('0x5f')]}));}}else{throw new Error(_0x65a7('0x60'));}})[_0x65a7('0x14')](function(){if(_0x4d4ba2){return respondWithRpcPromise(_0x65a7('0x61'),_0x65a7('0x62'),_0x4d4ba2,client9003)[_0x65a7('0x14')](function(_0x3b7537){return _0x165898[_0x65a7('0x26')]({'read':!![],'messageId':_0x3b7537[_0x65a7('0x63')],'sentAt':moment()[_0x65a7('0x64')](_0x65a7('0x65'))});})[_0x65a7('0x1e')](function(_0xb1a570){logger[_0x65a7('0x1b')]('%s',JSON[_0x65a7('0x1a')](_0xb1a570));return _0x165898;});}return _0x165898;});}return _0x165898;}})[_0x65a7('0x14')](respondWithResult(_0x3d3029,0xc9))['catch'](handleError(_0x3d3029,null));};exports[_0x65a7('0x66')]=function(_0x3d8593,_0x31b204){var _0xbc9c96={'agent':{},'channel':'mail'};if(_0x3d8593[_0x65a7('0x49')]['id']){delete _0x3d8593[_0x65a7('0x49')]['id'];}_0x3d8593[_0x65a7('0x49')][_0x65a7('0x67')]=!![];_0x3d8593[_0x65a7('0x49')][_0x65a7('0x68')]=moment()['format'](_0x65a7('0x65'));_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')]=_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')]||_0x3d8593[_0x65a7('0x6a')]['id'];_0xbc9c96[_0x65a7('0x6b')]['id']=_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')];return db['MailMessage']['find']({'where':{'id':_0x3d8593[_0x65a7('0x44')]['id'],'UserId':null}})[_0x65a7('0x14')](handleEntityNotFound(_0x31b204,null))[_0x65a7('0x14')](saveUpdates(_0x3d8593['body'],null))[_0x65a7('0x14')](function(_0x2e008e){if(_0x2e008e){_0xbc9c96[_0x65a7('0x1d')]=_0x2e008e['get']({'plain':!![]});return db[_0x65a7('0x6c')][_0x65a7('0x48')]({'where':{'id':_0x2e008e[_0x65a7('0x6d')]}});}return null;})[_0x65a7('0x14')](handleEntityNotFound(_0x31b204,null))[_0x65a7('0x14')](function(_0x4a9827){if(_0x4a9827){return _0x4a9827[_0x65a7('0x26')]({'UserId':_0x3d8593['body'][_0x65a7('0x69')],'read1stAt':_[_0x65a7('0x6e')](_0x4a9827['read1stAt'])?moment()['format'](_0x65a7('0x65')):undefined});}return null;})[_0x65a7('0x14')](function(_0x41546b){if(_0x41546b){_0xbc9c96['interaction']=_0x41546b[_0x65a7('0x6f')]({'plain':!![]});interaction_log[_0x65a7('0x15')](_0x65a7('0x70'),_0x3d8593[_0x65a7('0x6a')]['id'],_0x3d8593[_0x65a7('0x6a')][_0x65a7('0x2b')],_0x3d8593['user'][_0x65a7('0x71')],_0xbc9c96[_0x65a7('0x72')]['id'],_0x3d8593[_0x65a7('0x49')]?JSON[_0x65a7('0x1a')](_0x3d8593[_0x65a7('0x49')]):'null');return respondWithRpcPromise(_0x65a7('0x73'),_0x65a7('0x74'),_0xbc9c96);}return null;})['then'](function(_0x129793){var _0x220667=_0x65a7('0x75')+_0x129793[_0x65a7('0x1d')][_0x65a7('0x76')];return db[_0x65a7('0x77')]['query'](_0x220667,{'type':db[_0x65a7('0x78')]['QueryTypes']['SELECT'],'raw':!![]})['then'](function(_0x299e65){return _0x299e65;});})[_0x65a7('0x14')](function(_0x3c20dd){if(_0x3c20dd){_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x79')]=_0x3c20dd[0x0];if(!_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')])return;return db[_0x65a7('0x7a')][_0x65a7('0x48')]({'where':{'id':_0x3d8593[_0x65a7('0x49')][_0x65a7('0x69')],'role':_0x65a7('0x6b')},'attributes':['id',_0x65a7('0x2b'),_0x65a7('0x7b'),_0x65a7('0x7c'),_0x65a7('0x7d')],'raw':!![]});}return null;})['then'](function(_0x105232){if(!_0x105232)return null;_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x6b')]=_0x105232;return _0xbc9c96;})[_0x65a7('0x14')](function(_0x5609e9){if(_0x5609e9){if(_0x3d8593[_0x65a7('0x49')]['manual']){_0xbc9c96[_0x65a7('0x1d')]['interface']=util[_0x65a7('0x64')]('SIP/%s',_0x3d8593['user'][_0x65a7('0x2b')]);_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x7e')]=_0xbc9c96[_0x65a7('0x7e')];_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x7f')]=_0xbc9c96[_0x65a7('0x7e')];_0xbc9c96[_0x65a7('0x1d')][_0x65a7('0x80')]=_0x65a7('0x66');_0xbc9c96['message'][_0x65a7('0x49')]=htmlToText[_0x65a7('0x81')](_0xbc9c96[_0x65a7('0x1d')]['body']);return respondWithRpcPromise(_0x65a7('0x82'),'EventManager',{'event':'acceptmessage','message':_0xbc9c96[_0x65a7('0x1d')]},client9002)['then'](function(){return _0xbc9c96;});}return _0xbc9c96;}return null;})[_0x65a7('0x14')](respondWithResult(_0x31b204,null))['catch'](handleError(_0x31b204,null));};exports['reject']=function(_0x46e9eb,_0x33aef2){var _0x4613dc={'agent':{},'channel':'mail'};if(_0x46e9eb[_0x65a7('0x49')]['id']){delete _0x46e9eb[_0x65a7('0x49')]['id'];}_0x46e9eb['body'][_0x65a7('0x69')]=_0x46e9eb['body'][_0x65a7('0x69')]||_0x46e9eb[_0x65a7('0x6a')]['id'];_0x4613dc[_0x65a7('0x6b')]['id']=_0x46e9eb['body'][_0x65a7('0x69')];return db[_0x65a7('0x40')][_0x65a7('0x48')]({'where':{'id':_0x46e9eb[_0x65a7('0x44')]['id'],'UserId':null}})[_0x65a7('0x14')](handleEntityNotFound(_0x33aef2,null))[_0x65a7('0x14')](function(_0x5f1bec){if(_0x5f1bec){_0x4613dc[_0x65a7('0x1d')]=_0x5f1bec[_0x65a7('0x6f')]({'plain':!![]});return db[_0x65a7('0x6c')][_0x65a7('0x48')]({'where':{'id':_0x5f1bec[_0x65a7('0x6d')]}});}return null;})[_0x65a7('0x14')](handleEntityNotFound(_0x33aef2,null))[_0x65a7('0x14')](function(_0x243b32){if(_0x243b32){_0x4613dc[_0x65a7('0x72')]=_0x243b32[_0x65a7('0x6f')]({'plain':!![]});interaction_log[_0x65a7('0x15')](_0x65a7('0x83'),_0x46e9eb[_0x65a7('0x6a')]['id'],_0x46e9eb[_0x65a7('0x6a')]['name'],_0x46e9eb[_0x65a7('0x6a')][_0x65a7('0x71')],_0x4613dc[_0x65a7('0x72')]['id'],_0x46e9eb['body']?JSON['stringify'](_0x46e9eb['body']):_0x65a7('0x84'));return respondWithRpcPromise('RejectMessage',_0x65a7('0x85'),_0x4613dc);}return null;})['then'](function(_0x1472fd){var _0x2f6aa8=_0x65a7('0x75')+_0x1472fd['message'][_0x65a7('0x76')];return db[_0x65a7('0x77')]['query'](_0x2f6aa8,{'type':db[_0x65a7('0x78')]['QueryTypes']['SELECT'],'raw':!![]})[_0x65a7('0x14')](function(_0x1f073f){return _0x1f073f;});})[_0x65a7('0x14')](function(_0x1f329d){if(_0x1f329d){_0x4613dc['message']['contact']=_0x1f329d[0x0];if(!_0x46e9eb['body'][_0x65a7('0x69')])return;return db['User'][_0x65a7('0x48')]({'where':{'id':_0x46e9eb['body']['UserId'],'role':'agent'},'attributes':['id','name',_0x65a7('0x7b'),_0x65a7('0x7c'),_0x65a7('0x7d')],'raw':!![]});}return null;})[_0x65a7('0x14')](function(_0x418ef8){if(!_0x418ef8)return null;_0x4613dc[_0x65a7('0x1d')][_0x65a7('0x6b')]=_0x418ef8;return _0x4613dc;})[_0x65a7('0x14')](function(_0xb6df7c){if(_0xb6df7c){_0xb6df7c[_0x65a7('0x1d')]['interface']=util['format'](_0x65a7('0x86'),_0x46e9eb[_0x65a7('0x6a')][_0x65a7('0x2b')]);_0xb6df7c[_0x65a7('0x1d')][_0x65a7('0x7e')]=_0x4613dc['channel'];_0xb6df7c['message'][_0x65a7('0x7f')]=_0x4613dc[_0x65a7('0x7e')];_0xb6df7c[_0x65a7('0x1d')][_0x65a7('0x80')]=_0x65a7('0x87');_0xb6df7c[_0x65a7('0x1d')][_0x65a7('0x49')]=htmlToText[_0x65a7('0x81')](_0x4613dc[_0x65a7('0x1d')][_0x65a7('0x49')]);respondWithRpcPromise(_0x65a7('0x82'),_0x65a7('0x82'),{'event':_0x65a7('0x88'),'message':_0xb6df7c['message']},client9002);return _0x4613dc;}return null;})[_0x65a7('0x14')](respondWithResult(_0x33aef2,null))['catch'](handleError(_0x33aef2,null));};exports[_0x65a7('0x89')]=function(_0x311c84,_0xdacbf4){var _0x5c816f=moment()['unix']()[_0x65a7('0x8a')]();var _0x5b23f4=path[_0x65a7('0x5a')](config[_0x65a7('0x5b')],'server',_0x65a7('0x8b'),_0x65a7('0x8c'));var _0x4c98f4=path['join'](config[_0x65a7('0x5b')],_0x65a7('0x8d'),_0x65a7('0x8b'),'attachments');var _0x14bafd=util[_0x65a7('0x64')](_0x65a7('0x8e'),_0x5c816f);return db[_0x65a7('0x40')]['find']({'where':{'id':_0x311c84[_0x65a7('0x44')]['id']},'attributes':['id',_0x65a7('0x49'),_0x65a7('0x8f'),'to','cc',_0x65a7('0x90'),'subject',_0x65a7('0x91')],'include':_0x311c84[_0x65a7('0x32')]['attachments']?[{'model':db[_0x65a7('0x92')],'as':_0x65a7('0x93')}]:undefined})[_0x65a7('0x14')](handleEntityNotFound(_0xdacbf4,null))[_0x65a7('0x14')](function(_0x16ae51){if(_0x16ae51){var _0xfda4be=_0x16ae51;var _0x4d8aa4={'from':_0xfda4be[_0x65a7('0x8f')],'to':_0xfda4be['to'],'subject':_0xfda4be[_0x65a7('0x94')],'html':htmlEntities[_0x65a7('0x95')](_0xfda4be[_0x65a7('0x49')]),'headers':{'Date':moment(_0xfda4be[_0x65a7('0x91')])[_0x65a7('0x64')](_0x65a7('0x96'))},'attachments':[]};if(_0x16ae51['cc']){_0x4d8aa4[_0x65a7('0x97')]['Cc']=_0x16ae51['cc'];}if(_0x16ae51[_0x65a7('0x90')]){_0x4d8aa4[_0x65a7('0x97')]['Bcc']=_0x16ae51[_0x65a7('0x90')];}return new BPromise(function(_0x1e2206,_0x130b9a){if(_0x16ae51[_0x65a7('0x93')]){for(var _0x2be09a=0x0;_0x2be09a<_0x16ae51[_0x65a7('0x93')][_0x65a7('0x37')];_0x2be09a++){var _0x2f6a6b=_0x16ae51['Attachments'][_0x2be09a];var _0x550e0a=path['join'](_0x4c98f4,_0x2f6a6b[_0x65a7('0x5d')]);if(fs[_0x65a7('0x98')](_0x550e0a)){_0x4d8aa4['attachments'][_0x65a7('0x99')]({'name':_0x2f6a6b[_0x65a7('0x2b')],'contentType':_0x2f6a6b[_0x65a7('0x9a')],'data':fs[_0x65a7('0x9b')](_0x550e0a)});}}}emlformat[_0x65a7('0x9c')](_0x4d8aa4,function(_0x164029,_0x4fdc70){if(_0x164029)return _0x130b9a(_0x164029);fs['writeFileSync'](path[_0x65a7('0x5a')](_0x5b23f4,_0x14bafd),_0x4fdc70);return _0x1e2206(_0x4fdc70);});});}})[_0x65a7('0x14')](function(_0x4e7459){if(_0x4e7459){return _0xdacbf4['download'](path[_0x65a7('0x5a')](_0x5b23f4,_0x14bafd),_0x14bafd,function(_0x386a17){if(!_0x386a17)fs[_0x65a7('0x9d')](path['join'](_0x5b23f4,_0x14bafd));});}})[_0x65a7('0x1e')](handleError(_0xdacbf4,null));};
\ No newline at end of file