Built motion from commit 192134f6.|2.6.25
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
1 // *************************************************************************
2 // *                                                                       *
3 // * xCALLY Motion -  The Omnichannel Contact Center                       *
4 // * Copyright (c) Xenialab s.r.l. All Rights Reserved                     *
5 // *                                                                       *
6 // *************************************************************************
7 // *                                                                       *
8 // * Email: info@xcally.com                                                *
9 // * Website: https://www.xcally.com                                       *
10 // *                                                                       *
11 // *************************************************************************
12 // *                                                                       *
13 // * The SOFTWARE PRODUCT is protected by copyright laws and international *
14 // * copyright treaties, as well as other intellectual property laws and   *
15 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                         *
16 // *                                                                       *
17 // *************************************************************************
18 var _0x535f=['RejectMessage','ContactId','Sequelize','SELECT','email','internal','interface','reject','rejectmessage','download','unix','join','server','message-%s.eml','bcc','createdAt','Attachment','Attachments','from','subject','headers','existsSync','push','build','unlinkSync','eml-format','moment','bluebird','util','path','lodash','ioredis','../../components/parsers/qs','api','../../config/logger','mail-interactions','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','html-entities','./mailMessage.socket','register','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','message','result','status','json','offset','undefined','limit','count','Content-Range','update','destroy','end','sendStatus','stack','name','map','MailMessage','rawAttributes','fieldName','type','model','query','keys','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','filters','filter','where','merge','VIRTUAL','options','includeAll','include','findAll','catch','show','find','body','params','describe','direction','out','split','MailAccount','CmList','List','CmContact','Contacts','updatedAt','DESC','Smtp','CloudProvider','attachments','root','server/files/attachments','basename','create','List\x20not\x20found','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','readAt','UserId','user','agent','get','MailInteraction','MailInteractionId','isNil','read1stAt','interaction','null','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','QueryTypes','contact','User','fullname','manual','SIP/%s','channel','motionChannel','event','fromString','EventManager','acceptmessage','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s'];(function(_0x1c8bb1,_0x5621e8){var _0x1f5c9f=function(_0x2293ad){while(--_0x2293ad){_0x1c8bb1['push'](_0x1c8bb1['shift']());}};_0x1f5c9f(++_0x5621e8);}(_0x535f,0x1db));var _0xf535=function(_0xf8e486,_0x5d2f29){_0xf8e486=_0xf8e486-0x0;var _0x5dcc9a=_0x535f[_0xf8e486];return _0x5dcc9a;};'use strict';var emlformat=require(_0xf535('0x0'));var moment=require(_0xf535('0x1'));var BPromise=require(_0xf535('0x2'));var util=require(_0xf535('0x3'));var path=require(_0xf535('0x4'));var fs=require('fs');var _=require(_0xf535('0x5'));var Redis=require(_0xf535('0x6'));var htmlToText=require('html-to-text');var qs=require(_0xf535('0x7'));var logger=require('../../config/logger')(_0xf535('0x8'));var interaction_log=require(_0xf535('0x9'))(_0xf535('0xa'));var config=require(_0xf535('0xb'));var db=require(_0xf535('0xc'))['db'];config[_0xf535('0xd')]=_[_0xf535('0xe')](config[_0xf535('0xd')],{'host':'localhost','port':0x18eb});var socket=require(_0xf535('0xf'))(new Redis(config[_0xf535('0xd')]));var htmlEntities=require(_0xf535('0x10'));require(_0xf535('0x11'))[_0xf535('0x12')](socket);var jayson=require('jayson/promise');var client=jayson[_0xf535('0x13')][_0xf535('0x14')]({'port':0x232c});var client9003=jayson['client'][_0xf535('0x14')]({'port':0x232b});var client9002=jayson[_0xf535('0x13')][_0xf535('0x14')]({'port':0x232a});function respondWithRpcPromise(_0x1ba887,_0x251d7e,_0x2b8b8d,_0x539729){return new BPromise(function(_0x14c67e,_0x284405){var _0x360c40=_0x539729||client;return _0x360c40[_0xf535('0x15')](_0x1ba887,_0x2b8b8d)[_0xf535('0x16')](function(_0x15cf35){logger[_0xf535('0x17')](_0xf535('0x18'),_0x251d7e,_0xf535('0x19'));logger[_0xf535('0x1a')](_0xf535('0x1b'),_0x251d7e,'request\x20sent',JSON[_0xf535('0x1c')](_0x15cf35));if(_0x15cf35['error']){if(_0x15cf35[_0xf535('0x1d')]['code']===0x1f4){logger[_0xf535('0x1d')](_0xf535('0x18'),_0x251d7e,_0x15cf35[_0xf535('0x1d')]['message']);return _0x284405(_0x15cf35[_0xf535('0x1d')][_0xf535('0x1e')]);}logger[_0xf535('0x1d')]('MailMessage,\x20%s,\x20%s',_0x251d7e,_0x15cf35['error'][_0xf535('0x1e')]);return _0x14c67e(_0x15cf35['error']['message']);}else{logger[_0xf535('0x17')](_0xf535('0x18'),_0x251d7e,_0xf535('0x19'));_0x14c67e(_0x15cf35[_0xf535('0x1f')][_0xf535('0x1e')]);}})['catch'](function(_0x49c195){logger[_0xf535('0x1d')](_0xf535('0x18'),_0x251d7e,_0x49c195);_0x284405(_0x49c195);});});}function respondWithResult(_0x5c0f39,_0x3b34cb){_0x3b34cb=_0x3b34cb||0xc8;return function(_0x141045){if(_0x141045){return _0x5c0f39[_0xf535('0x20')](_0x3b34cb)[_0xf535('0x21')](_0x141045);}};}function respondWithFilteredResult(_0x3c561c,_0x1c3f57){return function(_0x5b277a){if(_0x5b277a){var _0x4d6876=typeof _0x1c3f57[_0xf535('0x22')]===_0xf535('0x23')&&typeof _0x1c3f57[_0xf535('0x24')]===_0xf535('0x23');var _0x38e44=_0x5b277a[_0xf535('0x25')];var _0x5a34cc=_0x4d6876?0x0:_0x1c3f57[_0xf535('0x22')];var _0x299563=_0x4d6876?_0x5b277a['count']:_0x1c3f57[_0xf535('0x22')]+_0x1c3f57[_0xf535('0x24')];var _0x4714d5;if(_0x299563>=_0x38e44){_0x299563=_0x38e44;_0x4714d5=0xc8;}else{_0x4714d5=0xce;}_0x3c561c['status'](_0x4714d5);return _0x3c561c['set'](_0xf535('0x26'),_0x5a34cc+'-'+_0x299563+'/'+_0x38e44)[_0xf535('0x21')](_0x5b277a);}return null;};}function saveUpdates(_0x1b391d){return function(_0xd77f2b){if(_0xd77f2b){return _0xd77f2b[_0xf535('0x27')](_0x1b391d)[_0xf535('0x16')](function(_0x5094e0){return _0x5094e0;});}return null;};}function removeEntity(_0x3dde2d){return function(_0x16b2a0){if(_0x16b2a0){return _0x16b2a0[_0xf535('0x28')]()[_0xf535('0x16')](function(){_0x3dde2d[_0xf535('0x20')](0xcc)[_0xf535('0x29')]();});}};}function handleEntityNotFound(_0x6a453f){return function(_0x16d727){if(!_0x16d727){_0x6a453f[_0xf535('0x2a')](0x194);}return _0x16d727;};}function handleError(_0xda1598,_0xea9d13){_0xea9d13=_0xea9d13||0x1f4;return function(_0x37c58a){logger[_0xf535('0x1d')](_0x37c58a[_0xf535('0x2b')]);if(_0x37c58a[_0xf535('0x2c')]){delete _0x37c58a[_0xf535('0x2c')];}_0xda1598[_0xf535('0x20')](_0xea9d13)['send'](_0x37c58a);};}exports['index']=function(_0x5bece3,_0x154edd){var _0xb2de37={},_0x1953d8={},_0x294de8={'count':0x0,'rows':[]};var _0x1941e8=_[_0xf535('0x2d')](db[_0xf535('0x2e')][_0xf535('0x2f')],function(_0x171fc9){return{'name':_0x171fc9[_0xf535('0x30')],'type':_0x171fc9[_0xf535('0x31')]['key']};});_0x1953d8[_0xf535('0x32')]=_[_0xf535('0x2d')](_0x1941e8,'name');_0x1953d8[_0xf535('0x33')]=_[_0xf535('0x34')](_0x5bece3[_0xf535('0x33')]);_0x1953d8['filters']=_[_0xf535('0x35')](_0x1953d8['model'],_0x1953d8['query']);_0xb2de37[_0xf535('0x36')]=_[_0xf535('0x35')](_0x1953d8['model'],qs[_0xf535('0x37')](_0x5bece3[_0xf535('0x33')][_0xf535('0x37')]));_0xb2de37[_0xf535('0x36')]=_0xb2de37['attributes'][_0xf535('0x38')]?_0xb2de37[_0xf535('0x36')]:_0x1953d8[_0xf535('0x32')];if(!_0x5bece3[_0xf535('0x33')][_0xf535('0x39')](_0xf535('0x3a'))){_0xb2de37[_0xf535('0x24')]=qs[_0xf535('0x24')](_0x5bece3[_0xf535('0x33')][_0xf535('0x24')]);_0xb2de37['offset']=qs[_0xf535('0x22')](_0x5bece3[_0xf535('0x33')][_0xf535('0x22')]);}_0xb2de37['order']=qs[_0xf535('0x3b')](_0x5bece3[_0xf535('0x33')]['sort']);_0xb2de37['where']=qs[_0xf535('0x3c')](_['pick'](_0x5bece3[_0xf535('0x33')],_0x1953d8[_0xf535('0x3c')]),_0x1941e8);if(_0x5bece3['query'][_0xf535('0x3d')]){_0xb2de37[_0xf535('0x3e')]=_[_0xf535('0x3f')](_0xb2de37[_0xf535('0x3e')],{'$or':_[_0xf535('0x2d')](_0x1941e8,function(_0x524875){if(_0x524875[_0xf535('0x31')]!==_0xf535('0x40')){var _0x3485f1={};_0x3485f1[_0x524875[_0xf535('0x2c')]]={'$like':'%'+_0x5bece3[_0xf535('0x33')]['filter']+'%'};return _0x3485f1;}})});}_0xb2de37=_[_0xf535('0x3f')]({},_0xb2de37,_0x5bece3[_0xf535('0x41')]);var _0x6b86c2={'where':_0xb2de37[_0xf535('0x3e')]};return db['MailMessage'][_0xf535('0x25')](_0x6b86c2)[_0xf535('0x16')](function(_0xfa5dcc){_0x294de8[_0xf535('0x25')]=_0xfa5dcc;if(_0x5bece3[_0xf535('0x33')][_0xf535('0x42')]){_0xb2de37[_0xf535('0x43')]=[{'all':!![]}];}return db[_0xf535('0x2e')][_0xf535('0x44')](_0xb2de37);})[_0xf535('0x16')](function(_0x5c55c9){_0x294de8['rows']=_0x5c55c9;return _0x294de8;})[_0xf535('0x16')](respondWithFilteredResult(_0x154edd,_0xb2de37))[_0xf535('0x45')](handleError(_0x154edd,null));};exports[_0xf535('0x46')]=function(_0x5c9a8e,_0x10ab8a){var _0x53d612={'raw':!![],'where':{'id':_0x5c9a8e['params']['id']}},_0x26f668={};_0x26f668['model']=_['keys'](db[_0xf535('0x2e')]['rawAttributes']);_0x26f668[_0xf535('0x33')]=_[_0xf535('0x34')](_0x5c9a8e[_0xf535('0x33')]);_0x26f668[_0xf535('0x3c')]=_['intersection'](_0x26f668['model'],_0x26f668['query']);_0x53d612['attributes']=_[_0xf535('0x35')](_0x26f668['model'],qs[_0xf535('0x37')](_0x5c9a8e['query'][_0xf535('0x37')]));_0x53d612['attributes']=_0x53d612['attributes']['length']?_0x53d612[_0xf535('0x36')]:_0x26f668[_0xf535('0x32')];if(_0x5c9a8e[_0xf535('0x33')]['includeAll']){_0x53d612['include']=[{'all':!![]}];}_0x53d612=_[_0xf535('0x3f')]({},_0x53d612,_0x5c9a8e[_0xf535('0x41')]);return db[_0xf535('0x2e')][_0xf535('0x47')](_0x53d612)[_0xf535('0x16')](handleEntityNotFound(_0x10ab8a,null))['then'](respondWithResult(_0x10ab8a,null))[_0xf535('0x45')](handleError(_0x10ab8a,null));};exports[_0xf535('0x27')]=function(_0x3f785e,_0x3d6b4e){if(_0x3f785e[_0xf535('0x48')]['id']){delete _0x3f785e[_0xf535('0x48')]['id'];}return db[_0xf535('0x2e')][_0xf535('0x47')]({'where':{'id':_0x3f785e[_0xf535('0x49')]['id']}})['then'](handleEntityNotFound(_0x3d6b4e,null))[_0xf535('0x16')](saveUpdates(_0x3f785e[_0xf535('0x48')],null))[_0xf535('0x16')](respondWithResult(_0x3d6b4e,null))[_0xf535('0x45')](handleError(_0x3d6b4e,null));};exports[_0xf535('0x28')]=function(_0x268715,_0x215285){return db[_0xf535('0x2e')][_0xf535('0x47')]({'where':{'id':_0x268715[_0xf535('0x49')]['id']}})[_0xf535('0x16')](handleEntityNotFound(_0x215285,null))[_0xf535('0x16')](removeEntity(_0x215285,null))[_0xf535('0x45')](handleError(_0x215285,null));};exports[_0xf535('0x4a')]=function(_0x3ada54,_0x457d75){return db[_0xf535('0x2e')][_0xf535('0x4a')]()['then'](respondWithResult(_0x457d75,null))[_0xf535('0x45')](handleError(_0x457d75,null));};exports['create']=function(_0x4238c0,_0x15c49a){return db['MailMessage']['create'](_0x4238c0[_0xf535('0x48')])[_0xf535('0x16')](function(_0x4c8a97){if(_0x4c8a97){if(_0x4c8a97[_0xf535('0x4b')]===_0xf535('0x4c')&&!_0x4c8a97['secret']){var _0x8aa9a4,_0x2ceb5d,_0x40c180;if(_0x4238c0[_0xf535('0x48')]['to']){_0x2ceb5d=_0x4238c0[_0xf535('0x48')]['to'][_0xf535('0x4d')](',')[0x0];}return db[_0xf535('0x4e')]['findOne']({'where':{'id':_0x4c8a97['MailAccountId']},'include':[{'model':db[_0xf535('0x4f')],'as':_0xf535('0x50'),'include':[{'model':db[_0xf535('0x51')],'as':_0xf535('0x52'),'where':{'email':_0x2ceb5d},'limit':0x1,'order':[[_0xf535('0x53'),_0xf535('0x54')]]}]},{'model':db['MailServerOut'],'as':_0xf535('0x55'),'raw':!![],'include':[{'model':db[_0xf535('0x56')],'as':_0xf535('0x56'),'raw':!![]}]}]})[_0xf535('0x16')](function(_0x52567a){_0x8aa9a4=_0x52567a;if(!_0x8aa9a4||!_0x8aa9a4['Smtp'])return;var _0x5324bd=_0x8aa9a4['getSmtpOptions']();if(_0x4238c0[_0xf535('0x48')]['attachments']&&_0x4238c0['body']['attachments'][_0xf535('0x38')]){for(var _0x4c1c3f=0x0;_0x4c1c3f<_0x4238c0[_0xf535('0x48')][_0xf535('0x57')]['length'];_0x4c1c3f+=0x1){_0x4238c0[_0xf535('0x48')][_0xf535('0x57')][_0x4c1c3f]={'filename':_0x4238c0[_0xf535('0x48')]['attachments'][_0x4c1c3f]['name'],'path':path['join'](config[_0xf535('0x58')],_0xf535('0x59'),_0x4238c0['body'][_0xf535('0x57')][_0x4c1c3f][_0xf535('0x5a')])};}}_0x40c180={'account':_0x5324bd,'message':_0x4238c0[_0xf535('0x48')]};return;})[_0xf535('0x16')](function(){if(_0x8aa9a4[_0xf535('0x50')]){if(_0x8aa9a4[_0xf535('0x50')]['Contacts'][_0xf535('0x38')]){return _0x8aa9a4[_0xf535('0x50')][_0xf535('0x52')][0x0];}else{return db[_0xf535('0x51')][_0xf535('0x5b')](_[_0xf535('0xe')](_0x4238c0[_0xf535('0x48')],{'firstName':_0x4238c0['body']['to'],'email':_0x4238c0[_0xf535('0x48')]['to'],'phone':_0x4238c0['body']['to'],'ListId':_0x8aa9a4['ListId']}));}}else{throw new Error(_0xf535('0x5c'));}})[_0xf535('0x16')](function(){if(_0x40c180){return respondWithRpcPromise('SendMail','sendMail',_0x40c180,client9003)['then'](function(_0x5c7ac0){return _0x4c8a97[_0xf535('0x27')]({'read':!![],'messageId':_0x5c7ac0[_0xf535('0x5d')],'sentAt':moment()[_0xf535('0x5e')](_0xf535('0x5f'))});})[_0xf535('0x45')](function(_0x4c1206){logger[_0xf535('0x1d')]('%s',JSON[_0xf535('0x1c')](_0x4c1206));return _0x4c8a97;});}return _0x4c8a97;});}return _0x4c8a97;}})[_0xf535('0x16')](respondWithResult(_0x15c49a,0xc9))[_0xf535('0x45')](handleError(_0x15c49a,null));};exports[_0xf535('0x60')]=function(_0x6254cf,_0xf64dd8){var _0x1aa6a3={'agent':{},'channel':'mail'};if(_0x6254cf['body']['id']){delete _0x6254cf[_0xf535('0x48')]['id'];}_0x6254cf[_0xf535('0x48')]['read']=!![];_0x6254cf['body'][_0xf535('0x61')]=moment()[_0xf535('0x5e')](_0xf535('0x5f'));_0x6254cf[_0xf535('0x48')][_0xf535('0x62')]=_0x6254cf[_0xf535('0x48')]['UserId']||_0x6254cf[_0xf535('0x63')]['id'];_0x1aa6a3[_0xf535('0x64')]['id']=_0x6254cf['body'][_0xf535('0x62')];return db['MailMessage'][_0xf535('0x47')]({'where':{'id':_0x6254cf[_0xf535('0x49')]['id'],'UserId':null}})[_0xf535('0x16')](handleEntityNotFound(_0xf64dd8,null))[_0xf535('0x16')](saveUpdates(_0x6254cf['body'],null))[_0xf535('0x16')](function(_0x49fc71){if(_0x49fc71){_0x1aa6a3[_0xf535('0x1e')]=_0x49fc71[_0xf535('0x65')]({'plain':!![]});return db[_0xf535('0x66')][_0xf535('0x47')]({'where':{'id':_0x49fc71[_0xf535('0x67')]}});}return null;})['then'](handleEntityNotFound(_0xf64dd8,null))[_0xf535('0x16')](function(_0x150b8d){if(_0x150b8d){return _0x150b8d[_0xf535('0x27')]({'UserId':_0x6254cf[_0xf535('0x48')]['UserId'],'read1stAt':_[_0xf535('0x68')](_0x150b8d[_0xf535('0x69')])?moment()[_0xf535('0x5e')]('YYYY-MM-DD\x20HH:mm:ss'):undefined});}return null;})[_0xf535('0x16')](function(_0x8759b9){if(_0x8759b9){_0x1aa6a3[_0xf535('0x6a')]=_0x8759b9[_0xf535('0x65')]({'plain':!![]});interaction_log[_0xf535('0x17')]('[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x6254cf[_0xf535('0x63')]['id'],_0x6254cf[_0xf535('0x63')][_0xf535('0x2c')],_0x6254cf['user']['role'],_0x1aa6a3[_0xf535('0x6a')]['id'],_0x6254cf[_0xf535('0x48')]?JSON[_0xf535('0x1c')](_0x6254cf['body']):_0xf535('0x6b'));return respondWithRpcPromise(_0xf535('0x6c'),_0xf535('0x6d'),_0x1aa6a3);}return null;})[_0xf535('0x16')](function(_0x417180){var _0x344dae=_0xf535('0x6e')+_0x417180[_0xf535('0x1e')]['ContactId'];return db[_0xf535('0x6f')][_0xf535('0x33')](_0x344dae,{'type':db['Sequelize'][_0xf535('0x70')]['SELECT'],'raw':!![]})[_0xf535('0x16')](function(_0x524f0a){return _0x524f0a;});})['then'](function(_0x34719a){if(_0x34719a){_0x1aa6a3[_0xf535('0x1e')][_0xf535('0x71')]=_0x34719a[0x0];if(!_0x6254cf['body'][_0xf535('0x62')])return;return db[_0xf535('0x72')]['find']({'where':{'id':_0x6254cf[_0xf535('0x48')][_0xf535('0x62')],'role':'agent'},'attributes':['id',_0xf535('0x2c'),_0xf535('0x73'),'email','internal'],'raw':!![]});}return null;})[_0xf535('0x16')](function(_0x37bb7f){if(!_0x37bb7f)return null;_0x1aa6a3[_0xf535('0x1e')][_0xf535('0x64')]=_0x37bb7f;return _0x1aa6a3;})[_0xf535('0x16')](function(_0x574c84){if(_0x574c84){if(_0x6254cf[_0xf535('0x48')][_0xf535('0x74')]){_0x1aa6a3['message']['interface']=util['format'](_0xf535('0x75'),_0x6254cf[_0xf535('0x63')][_0xf535('0x2c')]);_0x1aa6a3[_0xf535('0x1e')][_0xf535('0x76')]=_0x1aa6a3[_0xf535('0x76')];_0x1aa6a3[_0xf535('0x1e')][_0xf535('0x77')]=_0x1aa6a3['channel'];_0x1aa6a3[_0xf535('0x1e')][_0xf535('0x78')]='accept';_0x1aa6a3[_0xf535('0x1e')][_0xf535('0x48')]=htmlToText[_0xf535('0x79')](_0x1aa6a3[_0xf535('0x1e')]['body']);return respondWithRpcPromise('EventManager',_0xf535('0x7a'),{'event':_0xf535('0x7b'),'message':_0x1aa6a3[_0xf535('0x1e')]},client9002)[_0xf535('0x16')](function(){return _0x1aa6a3;});}return _0x1aa6a3;}return null;})['then'](respondWithResult(_0xf64dd8,null))[_0xf535('0x45')](handleError(_0xf64dd8,null));};exports['reject']=function(_0x32f5ea,_0x183018){var _0xee1e9a={'agent':{},'channel':'mail'};if(_0x32f5ea[_0xf535('0x48')]['id']){delete _0x32f5ea[_0xf535('0x48')]['id'];}_0x32f5ea[_0xf535('0x48')][_0xf535('0x62')]=_0x32f5ea[_0xf535('0x48')]['UserId']||_0x32f5ea[_0xf535('0x63')]['id'];_0xee1e9a[_0xf535('0x64')]['id']=_0x32f5ea['body']['UserId'];return db[_0xf535('0x2e')][_0xf535('0x47')]({'where':{'id':_0x32f5ea[_0xf535('0x49')]['id'],'UserId':null}})[_0xf535('0x16')](handleEntityNotFound(_0x183018,null))[_0xf535('0x16')](function(_0x42da1b){if(_0x42da1b){_0xee1e9a[_0xf535('0x1e')]=_0x42da1b[_0xf535('0x65')]({'plain':!![]});return db['MailInteraction'][_0xf535('0x47')]({'where':{'id':_0x42da1b[_0xf535('0x67')]}});}return null;})[_0xf535('0x16')](handleEntityNotFound(_0x183018,null))['then'](function(_0xb8eff9){if(_0xb8eff9){_0xee1e9a[_0xf535('0x6a')]=_0xb8eff9[_0xf535('0x65')]({'plain':!![]});interaction_log['info'](_0xf535('0x7c'),_0x32f5ea[_0xf535('0x63')]['id'],_0x32f5ea[_0xf535('0x63')][_0xf535('0x2c')],_0x32f5ea[_0xf535('0x63')]['role'],_0xee1e9a['interaction']['id'],_0x32f5ea['body']?JSON[_0xf535('0x1c')](_0x32f5ea[_0xf535('0x48')]):_0xf535('0x6b'));return respondWithRpcPromise(_0xf535('0x7d'),'rejectMessage',_0xee1e9a);}return null;})[_0xf535('0x16')](function(_0x2d03b1){var _0x33230f=_0xf535('0x6e')+_0x2d03b1[_0xf535('0x1e')][_0xf535('0x7e')];return db[_0xf535('0x6f')]['query'](_0x33230f,{'type':db[_0xf535('0x7f')][_0xf535('0x70')][_0xf535('0x80')],'raw':!![]})[_0xf535('0x16')](function(_0x3711cd){return _0x3711cd;});})[_0xf535('0x16')](function(_0x1700c9){if(_0x1700c9){_0xee1e9a[_0xf535('0x1e')]['contact']=_0x1700c9[0x0];if(!_0x32f5ea[_0xf535('0x48')]['UserId'])return;return db[_0xf535('0x72')][_0xf535('0x47')]({'where':{'id':_0x32f5ea['body']['UserId'],'role':_0xf535('0x64')},'attributes':['id','name','fullname',_0xf535('0x81'),_0xf535('0x82')],'raw':!![]});}return null;})[_0xf535('0x16')](function(_0x3d9ede){if(!_0x3d9ede)return null;_0xee1e9a[_0xf535('0x1e')]['agent']=_0x3d9ede;return _0xee1e9a;})[_0xf535('0x16')](function(_0x5c4fe1){if(_0x5c4fe1){_0x5c4fe1[_0xf535('0x1e')][_0xf535('0x83')]=util[_0xf535('0x5e')](_0xf535('0x75'),_0x32f5ea[_0xf535('0x63')]['name']);_0x5c4fe1[_0xf535('0x1e')][_0xf535('0x76')]=_0xee1e9a['channel'];_0x5c4fe1['message']['motionChannel']=_0xee1e9a[_0xf535('0x76')];_0x5c4fe1[_0xf535('0x1e')][_0xf535('0x78')]=_0xf535('0x84');_0x5c4fe1[_0xf535('0x1e')][_0xf535('0x48')]=htmlToText[_0xf535('0x79')](_0xee1e9a[_0xf535('0x1e')][_0xf535('0x48')]);respondWithRpcPromise(_0xf535('0x7a'),_0xf535('0x7a'),{'event':_0xf535('0x85'),'message':_0x5c4fe1[_0xf535('0x1e')]},client9002);return _0xee1e9a;}return null;})[_0xf535('0x16')](respondWithResult(_0x183018,null))[_0xf535('0x45')](handleError(_0x183018,null));};exports[_0xf535('0x86')]=function(_0x405011,_0x131415){var _0x25721c=moment()[_0xf535('0x87')]()['toString']();var _0x3e07e3=path[_0xf535('0x88')](config['root'],_0xf535('0x89'),'files','tmp');var _0x29f9b2=path[_0xf535('0x88')](config[_0xf535('0x58')],_0xf535('0x89'),'files',_0xf535('0x57'));var _0x922dab=util[_0xf535('0x5e')](_0xf535('0x8a'),_0x25721c);return db[_0xf535('0x2e')][_0xf535('0x47')]({'where':{'id':_0x405011[_0xf535('0x49')]['id']},'attributes':['id','body','from','to','cc',_0xf535('0x8b'),'subject',_0xf535('0x8c')],'include':_0x405011[_0xf535('0x33')][_0xf535('0x57')]?[{'model':db[_0xf535('0x8d')],'as':_0xf535('0x8e')}]:undefined})[_0xf535('0x16')](handleEntityNotFound(_0x131415,null))['then'](function(_0x1e6ff6){if(_0x1e6ff6){var _0xe1c7a3=_0x1e6ff6;var _0x212dd2={'from':_0xe1c7a3[_0xf535('0x8f')],'to':_0xe1c7a3['to'],'subject':_0xe1c7a3[_0xf535('0x90')],'html':htmlEntities['decode'](_0xe1c7a3[_0xf535('0x48')]),'headers':{'Date':moment(_0xe1c7a3[_0xf535('0x8c')])[_0xf535('0x5e')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x1e6ff6['cc']){_0x212dd2['headers']['Cc']=_0x1e6ff6['cc'];}if(_0x1e6ff6[_0xf535('0x8b')]){_0x212dd2[_0xf535('0x91')]['Bcc']=_0x1e6ff6[_0xf535('0x8b')];}return new BPromise(function(_0x50dc52,_0x562e8b){if(_0x1e6ff6['Attachments']){for(var _0x19aeb4=0x0;_0x19aeb4<_0x1e6ff6[_0xf535('0x8e')]['length'];_0x19aeb4++){var _0x113fd8=_0x1e6ff6['Attachments'][_0x19aeb4];var _0x4088dd=path[_0xf535('0x88')](_0x29f9b2,_0x113fd8[_0xf535('0x5a')]);if(fs[_0xf535('0x92')](_0x4088dd)){_0x212dd2['attachments'][_0xf535('0x93')]({'name':_0x113fd8[_0xf535('0x2c')],'contentType':_0x113fd8['type'],'data':fs['readFileSync'](_0x4088dd)});}}}emlformat[_0xf535('0x94')](_0x212dd2,function(_0x1ab746,_0x49d378){if(_0x1ab746)return _0x562e8b(_0x1ab746);fs['writeFileSync'](path['join'](_0x3e07e3,_0x922dab),_0x49d378);return _0x50dc52(_0x49d378);});});}})[_0xf535('0x16')](function(_0x383bb5){if(_0x383bb5){return _0x131415[_0xf535('0x86')](path[_0xf535('0x88')](_0x3e07e3,_0x922dab),_0x922dab,function(_0x303183){if(!_0x303183)fs[_0xf535('0x95')](path[_0xf535('0x88')](_0x3e07e3,_0x922dab));});}})[_0xf535('0x45')](handleError(_0x131415,null));};