Built motion from commit b5413ace.|2.6.9
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 2819e4f..26e532f 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x6adc=['http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result','status','json','limit','undefined','count','offset','set','Content-Range','update','destroy','end','sendStatus','stack','name','send','index','map','MailMessage','rawAttributes','fieldName','type','key','query','keys','model','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filters','VIRTUAL','filter','merge','options','where','include','findAll','catch','params','includeAll','find','body','describe','create','direction','out','secret','split','MailAccount','findOne','MailAccountId','CmContact','Contacts','updatedAt','MailServerOut','Smtp','getSmtpOptions','attachments','join','root','server/files/attachments','basename','List','ListId','List\x20not\x20found','SendMail','sendMail','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','read','readAt','UserId','agent','get','MailInteraction','isNil','read1stAt','interaction','user','AcceptMessage','acceptMessage','sequelize','Sequelize','SELECT','contact','User','email','internal','manual','interface','channel','event','EventManager','acceptmessage','reject','MailInteractionId','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','QueryTypes','fullname','SIP/%s','motionChannel','fromString','rejectmessage','download','unix','toString','server','files','message-%s.eml','from','bcc','createdAt','Attachment','Attachments','subject','headers','Bcc','existsSync','push','readFileSync','build','unlinkSync','bluebird','path','lodash','ioredis','html-to-text','api','../../config/logger','../../config/environment','../../mysqldb','redis','localhost','socket.io-emitter','html-entities','./mailMessage.socket','jayson/promise','client'];(function(_0x3229ee,_0x12b883){var _0x413f8d=function(_0x31d0cc){while(--_0x31d0cc){_0x3229ee['push'](_0x3229ee['shift']());}};_0x413f8d(++_0x12b883);}(_0x6adc,0x92));var _0xc6ad=function(_0x45fe42,_0x1aa6a0){_0x45fe42=_0x45fe42-0x0;var _0x1cdae0=_0x6adc[_0x45fe42];return _0x1cdae0;};'use strict';var emlformat=require('eml-format');var moment=require('moment');var BPromise=require(_0xc6ad('0x0'));var util=require('util');var path=require(_0xc6ad('0x1'));var fs=require('fs');var _=require(_0xc6ad('0x2'));var Redis=require(_0xc6ad('0x3'));var htmlToText=require(_0xc6ad('0x4'));var qs=require('../../components/parsers/qs');var logger=require('../../config/logger')(_0xc6ad('0x5'));var interaction_log=require(_0xc6ad('0x6'))('mail-interactions');var config=require(_0xc6ad('0x7'));var db=require(_0xc6ad('0x8'))['db'];config[_0xc6ad('0x9')]=_['defaults'](config[_0xc6ad('0x9')],{'host':_0xc6ad('0xa'),'port':0x18eb});var socket=require(_0xc6ad('0xb'))(new Redis(config['redis']));var htmlEntities=require(_0xc6ad('0xc'));require(_0xc6ad('0xd'))['register'](socket);var jayson=require(_0xc6ad('0xe'));var client=jayson[_0xc6ad('0xf')][_0xc6ad('0x10')]({'port':0x232c});var client9003=jayson[_0xc6ad('0xf')][_0xc6ad('0x10')]({'port':0x232b});var client9002=jayson[_0xc6ad('0xf')][_0xc6ad('0x10')]({'port':0x232a});function respondWithRpcPromise(_0x34747e,_0x5dddfc,_0x58a659,_0x199404){return new BPromise(function(_0x5b09d4,_0x2ff7e7){var _0x2d9b98=_0x199404||client;return _0x2d9b98[_0xc6ad('0x11')](_0x34747e,_0x58a659)[_0xc6ad('0x12')](function(_0x139d46){logger[_0xc6ad('0x13')](_0xc6ad('0x14'),_0x5dddfc,_0xc6ad('0x15'));logger[_0xc6ad('0x16')](_0xc6ad('0x17'),_0x5dddfc,_0xc6ad('0x15'),JSON[_0xc6ad('0x18')](_0x139d46));if(_0x139d46['error']){if(_0x139d46[_0xc6ad('0x19')][_0xc6ad('0x1a')]===0x1f4){logger[_0xc6ad('0x19')](_0xc6ad('0x14'),_0x5dddfc,_0x139d46['error'][_0xc6ad('0x1b')]);return _0x2ff7e7(_0x139d46[_0xc6ad('0x19')][_0xc6ad('0x1b')]);}logger[_0xc6ad('0x19')](_0xc6ad('0x14'),_0x5dddfc,_0x139d46[_0xc6ad('0x19')][_0xc6ad('0x1b')]);return _0x5b09d4(_0x139d46[_0xc6ad('0x19')][_0xc6ad('0x1b')]);}else{logger[_0xc6ad('0x13')]('MailMessage,\x20%s,\x20%s',_0x5dddfc,_0xc6ad('0x15'));_0x5b09d4(_0x139d46[_0xc6ad('0x1c')][_0xc6ad('0x1b')]);}})['catch'](function(_0x1f340){logger['error'](_0xc6ad('0x14'),_0x5dddfc,_0x1f340);_0x2ff7e7(_0x1f340);});});}function respondWithResult(_0xc0d390,_0x4d806e){_0x4d806e=_0x4d806e||0xc8;return function(_0x383250){if(_0x383250){return _0xc0d390[_0xc6ad('0x1d')](_0x4d806e)[_0xc6ad('0x1e')](_0x383250);}};}function respondWithFilteredResult(_0x4e6ae8,_0x270c48){return function(_0x1e3e40){if(_0x1e3e40){var _0x2684b8=typeof _0x270c48['offset']==='undefined'&&typeof _0x270c48[_0xc6ad('0x1f')]===_0xc6ad('0x20');var _0x1985ec=_0x1e3e40[_0xc6ad('0x21')];var _0x1bfcbf=_0x2684b8?0x0:_0x270c48['offset'];var _0x5d9d1e=_0x2684b8?_0x1e3e40[_0xc6ad('0x21')]:_0x270c48[_0xc6ad('0x22')]+_0x270c48[_0xc6ad('0x1f')];var _0x359ba7;if(_0x5d9d1e>=_0x1985ec){_0x5d9d1e=_0x1985ec;_0x359ba7=0xc8;}else{_0x359ba7=0xce;}_0x4e6ae8[_0xc6ad('0x1d')](_0x359ba7);return _0x4e6ae8[_0xc6ad('0x23')](_0xc6ad('0x24'),_0x1bfcbf+'-'+_0x5d9d1e+'/'+_0x1985ec)[_0xc6ad('0x1e')](_0x1e3e40);}return null;};}function saveUpdates(_0x43ffd4){return function(_0x27e11c){if(_0x27e11c){return _0x27e11c[_0xc6ad('0x25')](_0x43ffd4)[_0xc6ad('0x12')](function(_0x4c06e1){return _0x4c06e1;});}return null;};}function removeEntity(_0x361c4f){return function(_0x331b4e){if(_0x331b4e){return _0x331b4e[_0xc6ad('0x26')]()[_0xc6ad('0x12')](function(){_0x361c4f[_0xc6ad('0x1d')](0xcc)[_0xc6ad('0x27')]();});}};}function handleEntityNotFound(_0x34a1e8){return function(_0x3e1e5c){if(!_0x3e1e5c){_0x34a1e8[_0xc6ad('0x28')](0x194);}return _0x3e1e5c;};}function handleError(_0x312448,_0x3fbd7f){_0x3fbd7f=_0x3fbd7f||0x1f4;return function(_0x342b76){logger[_0xc6ad('0x19')](_0x342b76[_0xc6ad('0x29')]);if(_0x342b76[_0xc6ad('0x2a')]){delete _0x342b76[_0xc6ad('0x2a')];}_0x312448[_0xc6ad('0x1d')](_0x3fbd7f)[_0xc6ad('0x2b')](_0x342b76);};}exports[_0xc6ad('0x2c')]=function(_0x2037c8,_0x1faa14){var _0x4e7e8f={},_0x1cf69c={},_0x4f5422={'count':0x0,'rows':[]};var _0x5d2acd=_[_0xc6ad('0x2d')](db[_0xc6ad('0x2e')][_0xc6ad('0x2f')],function(_0x4fb842){return{'name':_0x4fb842[_0xc6ad('0x30')],'type':_0x4fb842[_0xc6ad('0x31')][_0xc6ad('0x32')]};});_0x1cf69c['model']=_[_0xc6ad('0x2d')](_0x5d2acd,_0xc6ad('0x2a'));_0x1cf69c[_0xc6ad('0x33')]=_[_0xc6ad('0x34')](_0x2037c8[_0xc6ad('0x33')]);_0x1cf69c['filters']=_['intersection'](_0x1cf69c[_0xc6ad('0x35')],_0x1cf69c[_0xc6ad('0x33')]);_0x4e7e8f[_0xc6ad('0x36')]=_[_0xc6ad('0x37')](_0x1cf69c[_0xc6ad('0x35')],qs['fields'](_0x2037c8[_0xc6ad('0x33')][_0xc6ad('0x38')]));_0x4e7e8f['attributes']=_0x4e7e8f[_0xc6ad('0x36')][_0xc6ad('0x39')]?_0x4e7e8f['attributes']:_0x1cf69c['model'];if(!_0x2037c8[_0xc6ad('0x33')][_0xc6ad('0x3a')](_0xc6ad('0x3b'))){_0x4e7e8f['limit']=qs[_0xc6ad('0x1f')](_0x2037c8[_0xc6ad('0x33')][_0xc6ad('0x1f')]);_0x4e7e8f[_0xc6ad('0x22')]=qs[_0xc6ad('0x22')](_0x2037c8[_0xc6ad('0x33')][_0xc6ad('0x22')]);}_0x4e7e8f[_0xc6ad('0x3c')]=qs['sort'](_0x2037c8[_0xc6ad('0x33')][_0xc6ad('0x3d')]);_0x4e7e8f['where']=qs['filters'](_[_0xc6ad('0x3e')](_0x2037c8[_0xc6ad('0x33')],_0x1cf69c[_0xc6ad('0x3f')]),_0x5d2acd);if(_0x2037c8[_0xc6ad('0x33')]['filter']){_0x4e7e8f['where']=_['merge'](_0x4e7e8f['where'],{'$or':_[_0xc6ad('0x2d')](_0x5d2acd,function(_0x365acc){if(_0x365acc[_0xc6ad('0x31')]!==_0xc6ad('0x40')){var _0x376664={};_0x376664[_0x365acc[_0xc6ad('0x2a')]]={'$like':'%'+_0x2037c8['query'][_0xc6ad('0x41')]+'%'};return _0x376664;}})});}_0x4e7e8f=_[_0xc6ad('0x42')]({},_0x4e7e8f,_0x2037c8[_0xc6ad('0x43')]);var _0x4629f6={'where':_0x4e7e8f[_0xc6ad('0x44')]};return db[_0xc6ad('0x2e')][_0xc6ad('0x21')](_0x4629f6)[_0xc6ad('0x12')](function(_0x3ba882){_0x4f5422[_0xc6ad('0x21')]=_0x3ba882;if(_0x2037c8[_0xc6ad('0x33')]['includeAll']){_0x4e7e8f[_0xc6ad('0x45')]=[{'all':!![]}];}return db['MailMessage'][_0xc6ad('0x46')](_0x4e7e8f);})['then'](function(_0x39c2f5){_0x4f5422['rows']=_0x39c2f5;return _0x4f5422;})[_0xc6ad('0x12')](respondWithFilteredResult(_0x1faa14,_0x4e7e8f))[_0xc6ad('0x47')](handleError(_0x1faa14,null));};exports['show']=function(_0x1c9fdf,_0x13484b){var _0x58e59e={'raw':!![],'where':{'id':_0x1c9fdf[_0xc6ad('0x48')]['id']}},_0x5a3d13={};_0x5a3d13['model']=_['keys'](db[_0xc6ad('0x2e')][_0xc6ad('0x2f')]);_0x5a3d13[_0xc6ad('0x33')]=_['keys'](_0x1c9fdf[_0xc6ad('0x33')]);_0x5a3d13[_0xc6ad('0x3f')]=_['intersection'](_0x5a3d13[_0xc6ad('0x35')],_0x5a3d13['query']);_0x58e59e['attributes']=_[_0xc6ad('0x37')](_0x5a3d13[_0xc6ad('0x35')],qs['fields'](_0x1c9fdf[_0xc6ad('0x33')][_0xc6ad('0x38')]));_0x58e59e[_0xc6ad('0x36')]=_0x58e59e[_0xc6ad('0x36')][_0xc6ad('0x39')]?_0x58e59e[_0xc6ad('0x36')]:_0x5a3d13['model'];if(_0x1c9fdf[_0xc6ad('0x33')][_0xc6ad('0x49')]){_0x58e59e[_0xc6ad('0x45')]=[{'all':!![]}];}_0x58e59e=_[_0xc6ad('0x42')]({},_0x58e59e,_0x1c9fdf[_0xc6ad('0x43')]);return db[_0xc6ad('0x2e')][_0xc6ad('0x4a')](_0x58e59e)[_0xc6ad('0x12')](handleEntityNotFound(_0x13484b,null))['then'](respondWithResult(_0x13484b,null))[_0xc6ad('0x47')](handleError(_0x13484b,null));};exports[_0xc6ad('0x25')]=function(_0x5513cc,_0x2e6fa9){if(_0x5513cc[_0xc6ad('0x4b')]['id']){delete _0x5513cc[_0xc6ad('0x4b')]['id'];}return db[_0xc6ad('0x2e')][_0xc6ad('0x4a')]({'where':{'id':_0x5513cc['params']['id']}})['then'](handleEntityNotFound(_0x2e6fa9,null))[_0xc6ad('0x12')](saveUpdates(_0x5513cc['body'],null))[_0xc6ad('0x12')](respondWithResult(_0x2e6fa9,null))[_0xc6ad('0x47')](handleError(_0x2e6fa9,null));};exports[_0xc6ad('0x26')]=function(_0xafb69,_0x4973ff){return db[_0xc6ad('0x2e')][_0xc6ad('0x4a')]({'where':{'id':_0xafb69[_0xc6ad('0x48')]['id']}})[_0xc6ad('0x12')](handleEntityNotFound(_0x4973ff,null))[_0xc6ad('0x12')](removeEntity(_0x4973ff,null))[_0xc6ad('0x47')](handleError(_0x4973ff,null));};exports[_0xc6ad('0x4c')]=function(_0x4d032f,_0x160e2a){return db[_0xc6ad('0x2e')][_0xc6ad('0x4c')]()['then'](respondWithResult(_0x160e2a,null))['catch'](handleError(_0x160e2a,null));};exports['create']=function(_0x1ab108,_0x2d8ee1){return db[_0xc6ad('0x2e')][_0xc6ad('0x4d')](_0x1ab108[_0xc6ad('0x4b')])['then'](function(_0x25361e){if(_0x25361e){if(_0x25361e[_0xc6ad('0x4e')]===_0xc6ad('0x4f')&&!_0x25361e[_0xc6ad('0x50')]){var _0xb07656,_0x50f6a5,_0x1e73fd;if(_0x1ab108[_0xc6ad('0x4b')]['to']){_0x50f6a5=_0x1ab108[_0xc6ad('0x4b')]['to'][_0xc6ad('0x51')](',')[0x0];}return db[_0xc6ad('0x52')][_0xc6ad('0x53')]({'where':{'id':_0x25361e[_0xc6ad('0x54')]},'include':[{'model':db['CmList'],'as':'List','include':[{'model':db[_0xc6ad('0x55')],'as':_0xc6ad('0x56'),'where':{'email':_0x50f6a5},'limit':0x1,'order':[[_0xc6ad('0x57'),'DESC']]}]},{'model':db[_0xc6ad('0x58')],'as':'Smtp','raw':!![],'include':[{'model':db['CloudProvider'],'as':'CloudProvider','raw':!![]}]}]})['then'](function(_0x31cfa2){_0xb07656=_0x31cfa2;if(!_0xb07656||!_0xb07656[_0xc6ad('0x59')])return;var _0x149cb9=_0xb07656[_0xc6ad('0x5a')]();if(_0x1ab108[_0xc6ad('0x4b')][_0xc6ad('0x5b')]&&_0x1ab108[_0xc6ad('0x4b')][_0xc6ad('0x5b')][_0xc6ad('0x39')]){for(var _0x316217=0x0;_0x316217<_0x1ab108[_0xc6ad('0x4b')]['attachments'][_0xc6ad('0x39')];_0x316217+=0x1){_0x1ab108[_0xc6ad('0x4b')][_0xc6ad('0x5b')][_0x316217]={'filename':_0x1ab108[_0xc6ad('0x4b')]['attachments'][_0x316217][_0xc6ad('0x2a')],'path':path[_0xc6ad('0x5c')](config[_0xc6ad('0x5d')],_0xc6ad('0x5e'),_0x1ab108[_0xc6ad('0x4b')][_0xc6ad('0x5b')][_0x316217][_0xc6ad('0x5f')])};}}_0x1e73fd={'account':_0x149cb9,'message':_0x1ab108[_0xc6ad('0x4b')]};return;})['then'](function(){if(_0xb07656[_0xc6ad('0x60')]){if(_0xb07656['List'][_0xc6ad('0x56')]['length']){return _0xb07656[_0xc6ad('0x60')][_0xc6ad('0x56')][0x0];}else{return db[_0xc6ad('0x55')]['create'](_['defaults'](_0x1ab108[_0xc6ad('0x4b')],{'firstName':_0x1ab108[_0xc6ad('0x4b')]['to'],'email':_0x1ab108[_0xc6ad('0x4b')]['to'],'phone':_0x1ab108[_0xc6ad('0x4b')]['to'],'ListId':_0xb07656[_0xc6ad('0x61')]}));}}else{throw new Error(_0xc6ad('0x62'));}})[_0xc6ad('0x12')](function(){if(_0x1e73fd){return respondWithRpcPromise(_0xc6ad('0x63'),_0xc6ad('0x64'),_0x1e73fd,client9003)[_0xc6ad('0x12')](function(_0x4e8993){return _0x25361e[_0xc6ad('0x25')]({'read':!![],'messageId':_0x4e8993['messageId'],'sentAt':moment()[_0xc6ad('0x65')](_0xc6ad('0x66'))});})[_0xc6ad('0x47')](function(_0xbd5b67){logger[_0xc6ad('0x19')]('%s',JSON[_0xc6ad('0x18')](_0xbd5b67));return _0x25361e;});}return _0x25361e;});}return _0x25361e;}})[_0xc6ad('0x12')](respondWithResult(_0x2d8ee1,0xc9))[_0xc6ad('0x47')](handleError(_0x2d8ee1,null));};exports[_0xc6ad('0x67')]=function(_0x541e60,_0x568813){var _0xc3dc04={'agent':{},'channel':_0xc6ad('0x68')};if(_0x541e60[_0xc6ad('0x4b')]['id']){delete _0x541e60['body']['id'];}_0x541e60[_0xc6ad('0x4b')][_0xc6ad('0x69')]=!![];_0x541e60['body'][_0xc6ad('0x6a')]=moment()[_0xc6ad('0x65')](_0xc6ad('0x66'));_0x541e60[_0xc6ad('0x4b')][_0xc6ad('0x6b')]=_0x541e60[_0xc6ad('0x4b')][_0xc6ad('0x6b')]||_0x541e60['user']['id'];_0xc3dc04[_0xc6ad('0x6c')]['id']=_0x541e60[_0xc6ad('0x4b')][_0xc6ad('0x6b')];return db[_0xc6ad('0x2e')][_0xc6ad('0x4a')]({'where':{'id':_0x541e60['params']['id'],'UserId':null}})[_0xc6ad('0x12')](handleEntityNotFound(_0x568813,null))[_0xc6ad('0x12')](saveUpdates(_0x541e60['body'],null))['then'](function(_0x116be6){if(_0x116be6){_0xc3dc04[_0xc6ad('0x1b')]=_0x116be6[_0xc6ad('0x6d')]({'plain':!![]});return db[_0xc6ad('0x6e')]['find']({'where':{'id':_0x116be6['MailInteractionId']}});}return null;})[_0xc6ad('0x12')](handleEntityNotFound(_0x568813,null))[_0xc6ad('0x12')](function(_0x53ecf0){if(_0x53ecf0){return _0x53ecf0['update']({'UserId':_0x541e60[_0xc6ad('0x4b')]['UserId'],'read1stAt':_[_0xc6ad('0x6f')](_0x53ecf0[_0xc6ad('0x70')])?moment()[_0xc6ad('0x65')](_0xc6ad('0x66')):undefined});}return null;})['then'](function(_0x20fafb){if(_0x20fafb){_0xc3dc04[_0xc6ad('0x71')]=_0x20fafb['get']({'plain':!![]});interaction_log[_0xc6ad('0x13')]('[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x541e60[_0xc6ad('0x72')]['id'],_0x541e60[_0xc6ad('0x72')][_0xc6ad('0x2a')],_0x541e60[_0xc6ad('0x72')]['role'],_0xc3dc04[_0xc6ad('0x71')]['id'],_0x541e60[_0xc6ad('0x4b')]?JSON[_0xc6ad('0x18')](_0x541e60[_0xc6ad('0x4b')]):'null');return respondWithRpcPromise(_0xc6ad('0x73'),_0xc6ad('0x74'),_0xc3dc04);}return null;})[_0xc6ad('0x12')](function(_0x26d486){var _0x338c12='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x26d486[_0xc6ad('0x1b')]['ContactId'];return db[_0xc6ad('0x75')]['query'](_0x338c12,{'type':db[_0xc6ad('0x76')]['QueryTypes'][_0xc6ad('0x77')],'raw':!![]})[_0xc6ad('0x12')](function(_0x2ac18d){return _0x2ac18d;});})['then'](function(_0x28cad0){if(_0x28cad0){_0xc3dc04[_0xc6ad('0x1b')][_0xc6ad('0x78')]=_0x28cad0[0x0];if(!_0x541e60['body'][_0xc6ad('0x6b')])return;return db[_0xc6ad('0x79')]['find']({'where':{'id':_0x541e60[_0xc6ad('0x4b')][_0xc6ad('0x6b')],'role':_0xc6ad('0x6c')},'attributes':['id',_0xc6ad('0x2a'),'fullname',_0xc6ad('0x7a'),_0xc6ad('0x7b')],'raw':!![]});}return null;})[_0xc6ad('0x12')](function(_0x332c44){if(!_0x332c44)return null;_0xc3dc04[_0xc6ad('0x1b')][_0xc6ad('0x6c')]=_0x332c44;return _0xc3dc04;})[_0xc6ad('0x12')](function(_0x1db966){if(_0x1db966){if(_0x541e60[_0xc6ad('0x4b')][_0xc6ad('0x7c')]){_0xc3dc04[_0xc6ad('0x1b')][_0xc6ad('0x7d')]=util['format']('SIP/%s',_0x541e60[_0xc6ad('0x72')]['name']);_0xc3dc04[_0xc6ad('0x1b')][_0xc6ad('0x7e')]=_0xc3dc04[_0xc6ad('0x7e')];_0xc3dc04[_0xc6ad('0x1b')]['motionChannel']=_0xc3dc04['channel'];_0xc3dc04['message'][_0xc6ad('0x7f')]='accept';_0xc3dc04[_0xc6ad('0x1b')][_0xc6ad('0x4b')]=htmlToText['fromString'](_0xc3dc04[_0xc6ad('0x1b')][_0xc6ad('0x4b')]);return respondWithRpcPromise(_0xc6ad('0x80'),_0xc6ad('0x80'),{'event':_0xc6ad('0x81'),'message':_0xc3dc04[_0xc6ad('0x1b')]},client9002)['then'](function(){return _0xc3dc04;});}return _0xc3dc04;}return null;})['then'](respondWithResult(_0x568813,null))['catch'](handleError(_0x568813,null));};exports[_0xc6ad('0x82')]=function(_0x4ad78a,_0x1f7722){var _0x2bd7bd={'agent':{},'channel':_0xc6ad('0x68')};if(_0x4ad78a[_0xc6ad('0x4b')]['id']){delete _0x4ad78a['body']['id'];}_0x4ad78a['body'][_0xc6ad('0x6b')]=_0x4ad78a[_0xc6ad('0x4b')][_0xc6ad('0x6b')]||_0x4ad78a['user']['id'];_0x2bd7bd[_0xc6ad('0x6c')]['id']=_0x4ad78a[_0xc6ad('0x4b')]['UserId'];return db[_0xc6ad('0x2e')][_0xc6ad('0x4a')]({'where':{'id':_0x4ad78a[_0xc6ad('0x48')]['id'],'UserId':null}})[_0xc6ad('0x12')](handleEntityNotFound(_0x1f7722,null))[_0xc6ad('0x12')](function(_0x2a5c9d){if(_0x2a5c9d){_0x2bd7bd[_0xc6ad('0x1b')]=_0x2a5c9d[_0xc6ad('0x6d')]({'plain':!![]});return db[_0xc6ad('0x6e')][_0xc6ad('0x4a')]({'where':{'id':_0x2a5c9d[_0xc6ad('0x83')]}});}return null;})[_0xc6ad('0x12')](handleEntityNotFound(_0x1f7722,null))['then'](function(_0x129adb){if(_0x129adb){_0x2bd7bd[_0xc6ad('0x71')]=_0x129adb[_0xc6ad('0x6d')]({'plain':!![]});interaction_log['info'](_0xc6ad('0x84'),_0x4ad78a[_0xc6ad('0x72')]['id'],_0x4ad78a['user'][_0xc6ad('0x2a')],_0x4ad78a[_0xc6ad('0x72')][_0xc6ad('0x85')],_0x2bd7bd[_0xc6ad('0x71')]['id'],_0x4ad78a['body']?JSON[_0xc6ad('0x18')](_0x4ad78a[_0xc6ad('0x4b')]):'null');return respondWithRpcPromise('RejectMessage',_0xc6ad('0x86'),_0x2bd7bd);}return null;})[_0xc6ad('0x12')](function(_0x5bb7a4){var _0xe3c27e=_0xc6ad('0x87')+_0x5bb7a4[_0xc6ad('0x1b')][_0xc6ad('0x88')];return db[_0xc6ad('0x75')]['query'](_0xe3c27e,{'type':db[_0xc6ad('0x76')][_0xc6ad('0x89')][_0xc6ad('0x77')],'raw':!![]})[_0xc6ad('0x12')](function(_0x3ae1a9){return _0x3ae1a9;});})[_0xc6ad('0x12')](function(_0x1a7b00){if(_0x1a7b00){_0x2bd7bd['message'][_0xc6ad('0x78')]=_0x1a7b00[0x0];if(!_0x4ad78a['body']['UserId'])return;return db[_0xc6ad('0x79')]['find']({'where':{'id':_0x4ad78a[_0xc6ad('0x4b')]['UserId'],'role':'agent'},'attributes':['id','name',_0xc6ad('0x8a'),_0xc6ad('0x7a'),_0xc6ad('0x7b')],'raw':!![]});}return null;})[_0xc6ad('0x12')](function(_0x52c76b){if(!_0x52c76b)return null;_0x2bd7bd['message'][_0xc6ad('0x6c')]=_0x52c76b;return _0x2bd7bd;})['then'](function(_0x594766){if(_0x594766){_0x594766[_0xc6ad('0x1b')][_0xc6ad('0x7d')]=util[_0xc6ad('0x65')](_0xc6ad('0x8b'),_0x4ad78a[_0xc6ad('0x72')][_0xc6ad('0x2a')]);_0x594766[_0xc6ad('0x1b')][_0xc6ad('0x7e')]=_0x2bd7bd['channel'];_0x594766['message'][_0xc6ad('0x8c')]=_0x2bd7bd[_0xc6ad('0x7e')];_0x594766[_0xc6ad('0x1b')][_0xc6ad('0x7f')]=_0xc6ad('0x82');_0x594766['message']['body']=htmlToText[_0xc6ad('0x8d')](_0x2bd7bd['message'][_0xc6ad('0x4b')]);respondWithRpcPromise('EventManager',_0xc6ad('0x80'),{'event':_0xc6ad('0x8e'),'message':_0x594766['message']},client9002);return _0x2bd7bd;}return null;})[_0xc6ad('0x12')](respondWithResult(_0x1f7722,null))[_0xc6ad('0x47')](handleError(_0x1f7722,null));};exports[_0xc6ad('0x8f')]=function(_0x471c64,_0x4e624d){var _0x421941=moment()[_0xc6ad('0x90')]()[_0xc6ad('0x91')]();var _0x240a0f=path[_0xc6ad('0x5c')](config[_0xc6ad('0x5d')],_0xc6ad('0x92'),_0xc6ad('0x93'),'tmp');var _0x1c5c9f=path['join'](config[_0xc6ad('0x5d')],_0xc6ad('0x92'),_0xc6ad('0x93'),_0xc6ad('0x5b'));var _0x2ab0ad=util[_0xc6ad('0x65')](_0xc6ad('0x94'),_0x421941);return db[_0xc6ad('0x2e')][_0xc6ad('0x4a')]({'where':{'id':_0x471c64[_0xc6ad('0x48')]['id']},'attributes':['id',_0xc6ad('0x4b'),_0xc6ad('0x95'),'to','cc',_0xc6ad('0x96'),'subject',_0xc6ad('0x97')],'include':_0x471c64[_0xc6ad('0x33')][_0xc6ad('0x5b')]?[{'model':db[_0xc6ad('0x98')],'as':_0xc6ad('0x99')}]:undefined})[_0xc6ad('0x12')](handleEntityNotFound(_0x4e624d,null))[_0xc6ad('0x12')](function(_0x5797ec){if(_0x5797ec){var _0x239894=_0x5797ec;var _0x3cd92c={'from':_0x239894['from'],'to':_0x239894['to'],'subject':_0x239894[_0xc6ad('0x9a')],'html':htmlEntities['decode'](_0x239894[_0xc6ad('0x4b')]),'headers':{'Date':moment(_0x239894['createdAt'])[_0xc6ad('0x65')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x5797ec['cc']){_0x3cd92c[_0xc6ad('0x9b')]['Cc']=_0x5797ec['cc'];}if(_0x5797ec[_0xc6ad('0x96')]){_0x3cd92c[_0xc6ad('0x9b')][_0xc6ad('0x9c')]=_0x5797ec['bcc'];}return new BPromise(function(_0x3dee90,_0x19f445){if(_0x5797ec['Attachments']){for(var _0x2a43a0=0x0;_0x2a43a0<_0x5797ec[_0xc6ad('0x99')][_0xc6ad('0x39')];_0x2a43a0++){var _0x43eec5=_0x5797ec['Attachments'][_0x2a43a0];var _0x369c52=path[_0xc6ad('0x5c')](_0x1c5c9f,_0x43eec5[_0xc6ad('0x5f')]);if(fs[_0xc6ad('0x9d')](_0x369c52)){_0x3cd92c[_0xc6ad('0x5b')][_0xc6ad('0x9e')]({'name':_0x43eec5[_0xc6ad('0x2a')],'contentType':_0x43eec5[_0xc6ad('0x31')],'data':fs[_0xc6ad('0x9f')](_0x369c52)});}}}emlformat[_0xc6ad('0xa0')](_0x3cd92c,function(_0x536170,_0x244da4){if(_0x536170)return _0x19f445(_0x536170);fs['writeFileSync'](path[_0xc6ad('0x5c')](_0x240a0f,_0x2ab0ad),_0x244da4);return _0x3dee90(_0x244da4);});});}})[_0xc6ad('0x12')](function(_0x261487){if(_0x261487){return _0x4e624d['download'](path['join'](_0x240a0f,_0x2ab0ad),_0x2ab0ad,function(_0x1cff11){if(!_0x1cff11)fs[_0xc6ad('0xa1')](path[_0xc6ad('0x5c')](_0x240a0f,_0x2ab0ad));});}})['catch'](handleError(_0x4e624d,null));};
\ No newline at end of file
+var _0x500d=['describe','create','out','secret','split','findOne','CmList','List','CmContact','updatedAt','DESC','MailServerOut','Smtp','getSmtpOptions','attachments','join','server/files/attachments','basename','Contacts','ListId','SendMail','sendMail','messageId','YYYY-MM-DD\x20HH:mm:ss','read','readAt','format','UserId','user','agent','get','MailInteraction','MailInteractionId','isNil','read1stAt','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','sequelize','SELECT','User','fullname','email','internal','interface','SIP/%s','channel','motionChannel','event','accept','fromString','EventManager','acceptmessage','mail','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','Sequelize','QueryTypes','contact','rejectmessage','download','unix','root','tmp','files','message-%s.eml','from','bcc','subject','createdAt','Attachments','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','existsSync','push','readFileSync','build','writeFileSync','unlinkSync','moment','bluebird','util','path','lodash','ioredis','html-to-text','../../components/parsers/qs','../../config/logger','../../mysqldb','defaults','redis','localhost','socket.io-emitter','register','jayson/promise','client','http','then','info','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','code','MailMessage,\x20%s,\x20%s','error','message','result','catch','offset','undefined','limit','count','status','set','json','update','destroy','end','sendStatus','stack','name','index','map','MailMessage','rawAttributes','fieldName','type','keys','filters','intersection','model','attributes','query','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','rows','show','params','body','find'];(function(_0x4d07cc,_0x587613){var _0x42de3b=function(_0x201f78){while(--_0x201f78){_0x4d07cc['push'](_0x4d07cc['shift']());}};_0x42de3b(++_0x587613);}(_0x500d,0x192));var _0xd500=function(_0x55336a,_0x240d59){_0x55336a=_0x55336a-0x0;var _0x28ceb3=_0x500d[_0x55336a];return _0x28ceb3;};'use strict';var emlformat=require('eml-format');var moment=require(_0xd500('0x0'));var BPromise=require(_0xd500('0x1'));var util=require(_0xd500('0x2'));var path=require(_0xd500('0x3'));var fs=require('fs');var _=require(_0xd500('0x4'));var Redis=require(_0xd500('0x5'));var htmlToText=require(_0xd500('0x6'));var qs=require(_0xd500('0x7'));var logger=require(_0xd500('0x8'))('api');var interaction_log=require(_0xd500('0x8'))('mail-interactions');var config=require('../../config/environment');var db=require(_0xd500('0x9'))['db'];config['redis']=_[_0xd500('0xa')](config[_0xd500('0xb')],{'host':_0xd500('0xc'),'port':0x18eb});var socket=require(_0xd500('0xd'))(new Redis(config[_0xd500('0xb')]));var htmlEntities=require('html-entities');require('./mailMessage.socket')[_0xd500('0xe')](socket);var jayson=require(_0xd500('0xf'));var client=jayson[_0xd500('0x10')]['http']({'port':0x232c});var client9003=jayson[_0xd500('0x10')][_0xd500('0x11')]({'port':0x232b});var client9002=jayson['client']['http']({'port':0x232a});function respondWithRpcPromise(_0x1bcecb,_0x47e156,_0x46b686,_0x3e1ad2){return new BPromise(function(_0x15d6f1,_0x1d6345){var _0xf78f96=_0x3e1ad2||client;return _0xf78f96['request'](_0x1bcecb,_0x46b686)[_0xd500('0x12')](function(_0x537b09){logger[_0xd500('0x13')]('MailMessage,\x20%s,\x20%s',_0x47e156,_0xd500('0x14'));logger[_0xd500('0x15')](_0xd500('0x16'),_0x47e156,'request\x20sent',JSON[_0xd500('0x17')](_0x537b09));if(_0x537b09['error']){if(_0x537b09['error'][_0xd500('0x18')]===0x1f4){logger['error'](_0xd500('0x19'),_0x47e156,_0x537b09[_0xd500('0x1a')][_0xd500('0x1b')]);return _0x1d6345(_0x537b09[_0xd500('0x1a')]['message']);}logger[_0xd500('0x1a')](_0xd500('0x19'),_0x47e156,_0x537b09[_0xd500('0x1a')][_0xd500('0x1b')]);return _0x15d6f1(_0x537b09[_0xd500('0x1a')][_0xd500('0x1b')]);}else{logger[_0xd500('0x13')](_0xd500('0x19'),_0x47e156,_0xd500('0x14'));_0x15d6f1(_0x537b09[_0xd500('0x1c')]['message']);}})[_0xd500('0x1d')](function(_0x32eb7d){logger[_0xd500('0x1a')]('MailMessage,\x20%s,\x20%s',_0x47e156,_0x32eb7d);_0x1d6345(_0x32eb7d);});});}function respondWithResult(_0x311541,_0x2bc2ea){_0x2bc2ea=_0x2bc2ea||0xc8;return function(_0x58610f){if(_0x58610f){return _0x311541['status'](_0x2bc2ea)['json'](_0x58610f);}};}function respondWithFilteredResult(_0x24f823,_0x51cb51){return function(_0x5228c9){if(_0x5228c9){var _0xe5892d=typeof _0x51cb51[_0xd500('0x1e')]===_0xd500('0x1f')&&typeof _0x51cb51[_0xd500('0x20')]===_0xd500('0x1f');var _0x4fe8fe=_0x5228c9[_0xd500('0x21')];var _0x545186=_0xe5892d?0x0:_0x51cb51[_0xd500('0x1e')];var _0x146ccf=_0xe5892d?_0x5228c9[_0xd500('0x21')]:_0x51cb51['offset']+_0x51cb51['limit'];var _0x4963f1;if(_0x146ccf>=_0x4fe8fe){_0x146ccf=_0x4fe8fe;_0x4963f1=0xc8;}else{_0x4963f1=0xce;}_0x24f823[_0xd500('0x22')](_0x4963f1);return _0x24f823[_0xd500('0x23')]('Content-Range',_0x545186+'-'+_0x146ccf+'/'+_0x4fe8fe)[_0xd500('0x24')](_0x5228c9);}return null;};}function saveUpdates(_0x24b2c2){return function(_0x24ff8b){if(_0x24ff8b){return _0x24ff8b[_0xd500('0x25')](_0x24b2c2)[_0xd500('0x12')](function(_0x2dcf38){return _0x2dcf38;});}return null;};}function removeEntity(_0xa5ce2f){return function(_0xdf3b8f){if(_0xdf3b8f){return _0xdf3b8f[_0xd500('0x26')]()['then'](function(){_0xa5ce2f[_0xd500('0x22')](0xcc)[_0xd500('0x27')]();});}};}function handleEntityNotFound(_0x266d8b){return function(_0xdb937){if(!_0xdb937){_0x266d8b[_0xd500('0x28')](0x194);}return _0xdb937;};}function handleError(_0x4b436f,_0x826688){_0x826688=_0x826688||0x1f4;return function(_0x3ac20d){logger[_0xd500('0x1a')](_0x3ac20d[_0xd500('0x29')]);if(_0x3ac20d[_0xd500('0x2a')]){delete _0x3ac20d[_0xd500('0x2a')];}_0x4b436f[_0xd500('0x22')](_0x826688)['send'](_0x3ac20d);};}exports[_0xd500('0x2b')]=function(_0x33d9ce,_0x217936){var _0x401ebd={},_0x5abda2={},_0x8229fa={'count':0x0,'rows':[]};var _0x33c43c=_[_0xd500('0x2c')](db[_0xd500('0x2d')][_0xd500('0x2e')],function(_0x1a7e3d){return{'name':_0x1a7e3d[_0xd500('0x2f')],'type':_0x1a7e3d[_0xd500('0x30')]['key']};});_0x5abda2['model']=_[_0xd500('0x2c')](_0x33c43c,_0xd500('0x2a'));_0x5abda2['query']=_[_0xd500('0x31')](_0x33d9ce['query']);_0x5abda2[_0xd500('0x32')]=_[_0xd500('0x33')](_0x5abda2[_0xd500('0x34')],_0x5abda2['query']);_0x401ebd[_0xd500('0x35')]=_[_0xd500('0x33')](_0x5abda2['model'],qs['fields'](_0x33d9ce[_0xd500('0x36')][_0xd500('0x37')]));_0x401ebd[_0xd500('0x35')]=_0x401ebd['attributes'][_0xd500('0x38')]?_0x401ebd[_0xd500('0x35')]:_0x5abda2[_0xd500('0x34')];if(!_0x33d9ce[_0xd500('0x36')][_0xd500('0x39')](_0xd500('0x3a'))){_0x401ebd[_0xd500('0x20')]=qs['limit'](_0x33d9ce[_0xd500('0x36')][_0xd500('0x20')]);_0x401ebd[_0xd500('0x1e')]=qs[_0xd500('0x1e')](_0x33d9ce[_0xd500('0x36')]['offset']);}_0x401ebd[_0xd500('0x3b')]=qs['sort'](_0x33d9ce[_0xd500('0x36')][_0xd500('0x3c')]);_0x401ebd['where']=qs[_0xd500('0x32')](_[_0xd500('0x3d')](_0x33d9ce[_0xd500('0x36')],_0x5abda2[_0xd500('0x32')]),_0x33c43c);if(_0x33d9ce[_0xd500('0x36')][_0xd500('0x3e')]){_0x401ebd[_0xd500('0x3f')]=_[_0xd500('0x40')](_0x401ebd['where'],{'$or':_[_0xd500('0x2c')](_0x33c43c,function(_0x2ca919){if(_0x2ca919[_0xd500('0x30')]!==_0xd500('0x41')){var _0x2db43a={};_0x2db43a[_0x2ca919[_0xd500('0x2a')]]={'$like':'%'+_0x33d9ce[_0xd500('0x36')][_0xd500('0x3e')]+'%'};return _0x2db43a;}})});}_0x401ebd=_[_0xd500('0x40')]({},_0x401ebd,_0x33d9ce[_0xd500('0x42')]);var _0x57730c={'where':_0x401ebd['where']};return db[_0xd500('0x2d')][_0xd500('0x21')](_0x57730c)['then'](function(_0x50b0d2){_0x8229fa[_0xd500('0x21')]=_0x50b0d2;if(_0x33d9ce['query'][_0xd500('0x43')]){_0x401ebd[_0xd500('0x44')]=[{'all':!![]}];}return db[_0xd500('0x2d')][_0xd500('0x45')](_0x401ebd);})[_0xd500('0x12')](function(_0xcdbe8c){_0x8229fa[_0xd500('0x46')]=_0xcdbe8c;return _0x8229fa;})[_0xd500('0x12')](respondWithFilteredResult(_0x217936,_0x401ebd))[_0xd500('0x1d')](handleError(_0x217936,null));};exports[_0xd500('0x47')]=function(_0x41116c,_0x456767){var _0x58ce5b={'raw':!![],'where':{'id':_0x41116c[_0xd500('0x48')]['id']}},_0x3071ff={};_0x3071ff['model']=_[_0xd500('0x31')](db[_0xd500('0x2d')]['rawAttributes']);_0x3071ff[_0xd500('0x36')]=_['keys'](_0x41116c[_0xd500('0x36')]);_0x3071ff[_0xd500('0x32')]=_[_0xd500('0x33')](_0x3071ff['model'],_0x3071ff['query']);_0x58ce5b[_0xd500('0x35')]=_[_0xd500('0x33')](_0x3071ff[_0xd500('0x34')],qs[_0xd500('0x37')](_0x41116c[_0xd500('0x36')][_0xd500('0x37')]));_0x58ce5b[_0xd500('0x35')]=_0x58ce5b[_0xd500('0x35')]['length']?_0x58ce5b[_0xd500('0x35')]:_0x3071ff[_0xd500('0x34')];if(_0x41116c[_0xd500('0x36')][_0xd500('0x43')]){_0x58ce5b[_0xd500('0x44')]=[{'all':!![]}];}_0x58ce5b=_[_0xd500('0x40')]({},_0x58ce5b,_0x41116c['options']);return db['MailMessage']['find'](_0x58ce5b)[_0xd500('0x12')](handleEntityNotFound(_0x456767,null))[_0xd500('0x12')](respondWithResult(_0x456767,null))[_0xd500('0x1d')](handleError(_0x456767,null));};exports[_0xd500('0x25')]=function(_0x1dae83,_0x1ff6cf){if(_0x1dae83[_0xd500('0x49')]['id']){delete _0x1dae83[_0xd500('0x49')]['id'];}return db[_0xd500('0x2d')][_0xd500('0x4a')]({'where':{'id':_0x1dae83[_0xd500('0x48')]['id']}})['then'](handleEntityNotFound(_0x1ff6cf,null))[_0xd500('0x12')](saveUpdates(_0x1dae83[_0xd500('0x49')],null))[_0xd500('0x12')](respondWithResult(_0x1ff6cf,null))['catch'](handleError(_0x1ff6cf,null));};exports[_0xd500('0x26')]=function(_0x52227d,_0x588fa8){return db[_0xd500('0x2d')][_0xd500('0x4a')]({'where':{'id':_0x52227d[_0xd500('0x48')]['id']}})[_0xd500('0x12')](handleEntityNotFound(_0x588fa8,null))['then'](removeEntity(_0x588fa8,null))[_0xd500('0x1d')](handleError(_0x588fa8,null));};exports['describe']=function(_0x3837b9,_0x312a04){return db[_0xd500('0x2d')][_0xd500('0x4b')]()['then'](respondWithResult(_0x312a04,null))[_0xd500('0x1d')](handleError(_0x312a04,null));};exports['create']=function(_0x41fb68,_0x40d74e){return db[_0xd500('0x2d')][_0xd500('0x4c')](_0x41fb68[_0xd500('0x49')])[_0xd500('0x12')](function(_0x16b59e){if(_0x16b59e){if(_0x16b59e['direction']===_0xd500('0x4d')&&!_0x16b59e[_0xd500('0x4e')]){var _0xc8e94a,_0x27ceed,_0x515df0;if(_0x41fb68[_0xd500('0x49')]['to']){_0x27ceed=_0x41fb68['body']['to'][_0xd500('0x4f')](',')[0x0];}return db['MailAccount'][_0xd500('0x50')]({'where':{'id':_0x16b59e['MailAccountId']},'include':[{'model':db[_0xd500('0x51')],'as':_0xd500('0x52'),'include':[{'model':db[_0xd500('0x53')],'as':'Contacts','where':{'email':_0x27ceed},'limit':0x1,'order':[[_0xd500('0x54'),_0xd500('0x55')]]}]},{'model':db[_0xd500('0x56')],'as':_0xd500('0x57'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':'CloudProvider','raw':!![]}]}]})['then'](function(_0x1df4de){_0xc8e94a=_0x1df4de;if(!_0xc8e94a||!_0xc8e94a[_0xd500('0x57')])return;var _0x53dd25=_0xc8e94a[_0xd500('0x58')]();if(_0x41fb68[_0xd500('0x49')][_0xd500('0x59')]&&_0x41fb68['body'][_0xd500('0x59')][_0xd500('0x38')]){for(var _0x391146=0x0;_0x391146<_0x41fb68['body'][_0xd500('0x59')][_0xd500('0x38')];_0x391146+=0x1){_0x41fb68[_0xd500('0x49')][_0xd500('0x59')][_0x391146]={'filename':_0x41fb68[_0xd500('0x49')]['attachments'][_0x391146][_0xd500('0x2a')],'path':path[_0xd500('0x5a')](config['root'],_0xd500('0x5b'),_0x41fb68[_0xd500('0x49')][_0xd500('0x59')][_0x391146][_0xd500('0x5c')])};}}_0x515df0={'account':_0x53dd25,'message':_0x41fb68[_0xd500('0x49')]};return;})['then'](function(){if(_0xc8e94a[_0xd500('0x52')]){if(_0xc8e94a[_0xd500('0x52')][_0xd500('0x5d')][_0xd500('0x38')]){return _0xc8e94a[_0xd500('0x52')][_0xd500('0x5d')][0x0];}else{return db[_0xd500('0x53')][_0xd500('0x4c')](_[_0xd500('0xa')](_0x41fb68[_0xd500('0x49')],{'firstName':_0x41fb68[_0xd500('0x49')]['to'],'email':_0x41fb68[_0xd500('0x49')]['to'],'phone':_0x41fb68[_0xd500('0x49')]['to'],'ListId':_0xc8e94a[_0xd500('0x5e')]}));}}else{throw new Error('List\x20not\x20found');}})[_0xd500('0x12')](function(){if(_0x515df0){return respondWithRpcPromise(_0xd500('0x5f'),_0xd500('0x60'),_0x515df0,client9003)['then'](function(_0x2d603c){return _0x16b59e['update']({'read':!![],'messageId':_0x2d603c[_0xd500('0x61')],'sentAt':moment()['format'](_0xd500('0x62'))});})[_0xd500('0x1d')](function(_0x1bcb5b){logger[_0xd500('0x1a')]('%s',JSON[_0xd500('0x17')](_0x1bcb5b));return _0x16b59e;});}return _0x16b59e;});}return _0x16b59e;}})[_0xd500('0x12')](respondWithResult(_0x40d74e,0xc9))[_0xd500('0x1d')](handleError(_0x40d74e,null));};exports['accept']=function(_0x37876b,_0x348d8b){var _0x357153={'agent':{},'channel':'mail'};if(_0x37876b[_0xd500('0x49')]['id']){delete _0x37876b['body']['id'];}_0x37876b['body'][_0xd500('0x63')]=!![];_0x37876b[_0xd500('0x49')][_0xd500('0x64')]=moment()[_0xd500('0x65')](_0xd500('0x62'));_0x37876b[_0xd500('0x49')]['UserId']=_0x37876b[_0xd500('0x49')][_0xd500('0x66')]||_0x37876b[_0xd500('0x67')]['id'];_0x357153[_0xd500('0x68')]['id']=_0x37876b[_0xd500('0x49')][_0xd500('0x66')];return db[_0xd500('0x2d')][_0xd500('0x4a')]({'where':{'id':_0x37876b[_0xd500('0x48')]['id'],'UserId':null}})[_0xd500('0x12')](handleEntityNotFound(_0x348d8b,null))['then'](saveUpdates(_0x37876b[_0xd500('0x49')],null))[_0xd500('0x12')](function(_0x565cec){if(_0x565cec){_0x357153[_0xd500('0x1b')]=_0x565cec[_0xd500('0x69')]({'plain':!![]});return db[_0xd500('0x6a')][_0xd500('0x4a')]({'where':{'id':_0x565cec[_0xd500('0x6b')]}});}return null;})[_0xd500('0x12')](handleEntityNotFound(_0x348d8b,null))[_0xd500('0x12')](function(_0x20862c){if(_0x20862c){return _0x20862c[_0xd500('0x25')]({'UserId':_0x37876b['body'][_0xd500('0x66')],'read1stAt':_[_0xd500('0x6c')](_0x20862c[_0xd500('0x6d')])?moment()[_0xd500('0x65')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0xd500('0x12')](function(_0x3dd8b5){if(_0x3dd8b5){_0x357153['interaction']=_0x3dd8b5[_0xd500('0x69')]({'plain':!![]});interaction_log[_0xd500('0x13')](_0xd500('0x6e'),_0x37876b[_0xd500('0x67')]['id'],_0x37876b[_0xd500('0x67')]['name'],_0x37876b['user'][_0xd500('0x6f')],_0x357153[_0xd500('0x70')]['id'],_0x37876b[_0xd500('0x49')]?JSON[_0xd500('0x17')](_0x37876b[_0xd500('0x49')]):_0xd500('0x71'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x357153);}return null;})[_0xd500('0x12')](function(_0x3d422b){var _0x35c900=_0xd500('0x72')+_0x3d422b[_0xd500('0x1b')][_0xd500('0x73')];return db[_0xd500('0x74')][_0xd500('0x36')](_0x35c900,{'type':db['Sequelize']['QueryTypes'][_0xd500('0x75')],'raw':!![]})[_0xd500('0x12')](function(_0x5f244b){return _0x5f244b;});})[_0xd500('0x12')](function(_0x461170){if(_0x461170){_0x357153[_0xd500('0x1b')]['contact']=_0x461170[0x0];if(!_0x37876b[_0xd500('0x49')][_0xd500('0x66')])return;return db[_0xd500('0x76')][_0xd500('0x4a')]({'where':{'id':_0x37876b[_0xd500('0x49')][_0xd500('0x66')],'role':_0xd500('0x68')},'attributes':['id',_0xd500('0x2a'),_0xd500('0x77'),_0xd500('0x78'),_0xd500('0x79')],'raw':!![]});}return null;})[_0xd500('0x12')](function(_0x154775){if(!_0x154775)return null;_0x357153['message'][_0xd500('0x68')]=_0x154775;return _0x357153;})['then'](function(_0x561960){if(_0x561960){if(_0x37876b[_0xd500('0x49')]['manual']){_0x357153['message'][_0xd500('0x7a')]=util['format'](_0xd500('0x7b'),_0x37876b[_0xd500('0x67')]['name']);_0x357153[_0xd500('0x1b')][_0xd500('0x7c')]=_0x357153[_0xd500('0x7c')];_0x357153['message'][_0xd500('0x7d')]=_0x357153['channel'];_0x357153[_0xd500('0x1b')][_0xd500('0x7e')]=_0xd500('0x7f');_0x357153[_0xd500('0x1b')][_0xd500('0x49')]=htmlToText[_0xd500('0x80')](_0x357153['message'][_0xd500('0x49')]);return respondWithRpcPromise('EventManager',_0xd500('0x81'),{'event':_0xd500('0x82'),'message':_0x357153[_0xd500('0x1b')]},client9002)[_0xd500('0x12')](function(){return _0x357153;});}return _0x357153;}return null;})[_0xd500('0x12')](respondWithResult(_0x348d8b,null))[_0xd500('0x1d')](handleError(_0x348d8b,null));};exports['reject']=function(_0x4df269,_0x3dcbbb){var _0x4c03b4={'agent':{},'channel':_0xd500('0x83')};if(_0x4df269['body']['id']){delete _0x4df269['body']['id'];}_0x4df269[_0xd500('0x49')][_0xd500('0x66')]=_0x4df269['body'][_0xd500('0x66')]||_0x4df269[_0xd500('0x67')]['id'];_0x4c03b4['agent']['id']=_0x4df269[_0xd500('0x49')][_0xd500('0x66')];return db[_0xd500('0x2d')][_0xd500('0x4a')]({'where':{'id':_0x4df269[_0xd500('0x48')]['id'],'UserId':null}})[_0xd500('0x12')](handleEntityNotFound(_0x3dcbbb,null))[_0xd500('0x12')](function(_0x11f55f){if(_0x11f55f){_0x4c03b4[_0xd500('0x1b')]=_0x11f55f[_0xd500('0x69')]({'plain':!![]});return db[_0xd500('0x6a')]['find']({'where':{'id':_0x11f55f[_0xd500('0x6b')]}});}return null;})[_0xd500('0x12')](handleEntityNotFound(_0x3dcbbb,null))[_0xd500('0x12')](function(_0x307f6d){if(_0x307f6d){_0x4c03b4[_0xd500('0x70')]=_0x307f6d[_0xd500('0x69')]({'plain':!![]});interaction_log[_0xd500('0x13')](_0xd500('0x84'),_0x4df269[_0xd500('0x67')]['id'],_0x4df269[_0xd500('0x67')][_0xd500('0x2a')],_0x4df269[_0xd500('0x67')][_0xd500('0x6f')],_0x4c03b4['interaction']['id'],_0x4df269[_0xd500('0x49')]?JSON[_0xd500('0x17')](_0x4df269['body']):_0xd500('0x71'));return respondWithRpcPromise(_0xd500('0x85'),_0xd500('0x86'),_0x4c03b4);}return null;})[_0xd500('0x12')](function(_0x4f4212){var _0x2b1c87=_0xd500('0x72')+_0x4f4212[_0xd500('0x1b')][_0xd500('0x73')];return db[_0xd500('0x74')][_0xd500('0x36')](_0x2b1c87,{'type':db[_0xd500('0x87')][_0xd500('0x88')]['SELECT'],'raw':!![]})[_0xd500('0x12')](function(_0x16f69b){return _0x16f69b;});})[_0xd500('0x12')](function(_0xa39a2e){if(_0xa39a2e){_0x4c03b4[_0xd500('0x1b')][_0xd500('0x89')]=_0xa39a2e[0x0];if(!_0x4df269[_0xd500('0x49')]['UserId'])return;return db['User']['find']({'where':{'id':_0x4df269[_0xd500('0x49')]['UserId'],'role':_0xd500('0x68')},'attributes':['id',_0xd500('0x2a'),_0xd500('0x77'),'email',_0xd500('0x79')],'raw':!![]});}return null;})[_0xd500('0x12')](function(_0x1bfeda){if(!_0x1bfeda)return null;_0x4c03b4[_0xd500('0x1b')][_0xd500('0x68')]=_0x1bfeda;return _0x4c03b4;})[_0xd500('0x12')](function(_0x569c1d){if(_0x569c1d){_0x569c1d[_0xd500('0x1b')][_0xd500('0x7a')]=util['format']('SIP/%s',_0x4df269[_0xd500('0x67')]['name']);_0x569c1d[_0xd500('0x1b')]['channel']=_0x4c03b4[_0xd500('0x7c')];_0x569c1d[_0xd500('0x1b')]['motionChannel']=_0x4c03b4[_0xd500('0x7c')];_0x569c1d[_0xd500('0x1b')][_0xd500('0x7e')]='reject';_0x569c1d[_0xd500('0x1b')][_0xd500('0x49')]=htmlToText[_0xd500('0x80')](_0x4c03b4[_0xd500('0x1b')][_0xd500('0x49')]);respondWithRpcPromise(_0xd500('0x81'),'EventManager',{'event':_0xd500('0x8a'),'message':_0x569c1d[_0xd500('0x1b')]},client9002);return _0x4c03b4;}return null;})[_0xd500('0x12')](respondWithResult(_0x3dcbbb,null))[_0xd500('0x1d')](handleError(_0x3dcbbb,null));};exports[_0xd500('0x8b')]=function(_0x5efe8c,_0x4e60d7){var _0x223785=moment()[_0xd500('0x8c')]()['toString']();var _0x122ef7=path[_0xd500('0x5a')](config[_0xd500('0x8d')],'server','files',_0xd500('0x8e'));var _0x4bb9f6=path[_0xd500('0x5a')](config[_0xd500('0x8d')],'server',_0xd500('0x8f'),'attachments');var _0xf05e61=util['format'](_0xd500('0x90'),_0x223785);return db[_0xd500('0x2d')]['find']({'where':{'id':_0x5efe8c[_0xd500('0x48')]['id']},'attributes':['id',_0xd500('0x49'),_0xd500('0x91'),'to','cc',_0xd500('0x92'),_0xd500('0x93'),_0xd500('0x94')],'include':_0x5efe8c[_0xd500('0x36')][_0xd500('0x59')]?[{'model':db['Attachment'],'as':_0xd500('0x95')}]:undefined})[_0xd500('0x12')](handleEntityNotFound(_0x4e60d7,null))[_0xd500('0x12')](function(_0xa5b8e2){if(_0xa5b8e2){var _0x58b0f6=_0xa5b8e2;var _0x43c4e6={'from':_0x58b0f6['from'],'to':_0x58b0f6['to'],'subject':_0x58b0f6[_0xd500('0x93')],'html':htmlEntities['decode'](_0x58b0f6[_0xd500('0x49')]),'headers':{'Date':moment(_0x58b0f6[_0xd500('0x94')])[_0xd500('0x65')](_0xd500('0x96'))},'attachments':[]};if(_0xa5b8e2['cc']){_0x43c4e6[_0xd500('0x97')]['Cc']=_0xa5b8e2['cc'];}if(_0xa5b8e2[_0xd500('0x92')]){_0x43c4e6[_0xd500('0x97')][_0xd500('0x98')]=_0xa5b8e2[_0xd500('0x92')];}return new BPromise(function(_0x256990,_0x4e1ddc){if(_0xa5b8e2['Attachments']){for(var _0x1d81cd=0x0;_0x1d81cd<_0xa5b8e2['Attachments'][_0xd500('0x38')];_0x1d81cd++){var _0x43dbef=_0xa5b8e2[_0xd500('0x95')][_0x1d81cd];var _0xff2643=path[_0xd500('0x5a')](_0x4bb9f6,_0x43dbef[_0xd500('0x5c')]);if(fs[_0xd500('0x99')](_0xff2643)){_0x43c4e6[_0xd500('0x59')][_0xd500('0x9a')]({'name':_0x43dbef[_0xd500('0x2a')],'contentType':_0x43dbef[_0xd500('0x30')],'data':fs[_0xd500('0x9b')](_0xff2643)});}}}emlformat[_0xd500('0x9c')](_0x43c4e6,function(_0x4cd197,_0x23585a){if(_0x4cd197)return _0x4e1ddc(_0x4cd197);fs[_0xd500('0x9d')](path['join'](_0x122ef7,_0xf05e61),_0x23585a);return _0x256990(_0x23585a);});});}})[_0xd500('0x12')](function(_0x1d9233){if(_0x1d9233){return _0x4e60d7['download'](path[_0xd500('0x5a')](_0x122ef7,_0xf05e61),_0xf05e61,function(_0x37bbab){if(!_0x37bbab)fs[_0xd500('0x9e')](path[_0xd500('0x5a')](_0x122ef7,_0xf05e61));});}})[_0xd500('0x1d')](handleError(_0x4e60d7,null));};
\ No newline at end of file