Built motion from commit 14588770.|2.5.38
[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 _0x35b0=['redis','defaults','localhost','socket.io-emitter','html-entities','./mailMessage.socket','register','jayson/promise','http','client','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','code','error','message','result','catch','json','offset','limit','undefined','count','set','Content-Range','update','status','end','sendStatus','name','index','map','MailMessage','rawAttributes','type','model','query','filters','intersection','attributes','fields','length','hasOwnProperty','nolimit','sort','filter','where','merge','VIRTUAL','options','include','findAll','rows','show','keys','includeAll','find','body','params','destroy','describe','create','direction','out','secret','split','MailAccount','findOne','MailAccountId','CmList','CmContact','Contacts','updatedAt','MailServerOut','Smtp','isNil','service','host','port','secure','authentication','auth','user','pass','attachments','root','server/files/attachments','List','ListId','List\x20not\x20found','SendMail','messageId','YYYY-MM-DD\x20HH:mm:ss','accept','mail','readAt','format','UserId','agent','get','MailInteraction','MailInteractionId','read1stAt','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','AcceptMessage','acceptMessage','sequelize','SELECT','contact','fullname','internal','manual','interface','SIP/%s','channel','motionChannel','fromString','EventManager','acceptmessage','RejectMessage','rejectMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','ContactId','QueryTypes','User','email','event','reject','download','unix','toString','files','tmp','join','server','message-%s.eml','from','bcc','createdAt','Attachments','subject','headers','basename','existsSync','push','readFileSync','build','writeFileSync','unlinkSync','bluebird','util','lodash','html-to-text','../../components/parsers/qs','../../config/logger','../../mysqldb'];(function(_0x34f701,_0x37e407){var _0x3e2429=function(_0x20c0c3){while(--_0x20c0c3){_0x34f701['push'](_0x34f701['shift']());}};_0x3e2429(++_0x37e407);}(_0x35b0,0x9d));var _0x035b=function(_0x5d8008,_0x23e45b){_0x5d8008=_0x5d8008-0x0;var _0x583783=_0x35b0[_0x5d8008];return _0x583783;};'use strict';var emlformat=require('eml-format');var moment=require('moment');var BPromise=require(_0x035b('0x0'));var util=require(_0x035b('0x1'));var path=require('path');var fs=require('fs');var _=require(_0x035b('0x2'));var Redis=require('ioredis');var htmlToText=require(_0x035b('0x3'));var qs=require(_0x035b('0x4'));var logger=require(_0x035b('0x5'))('api');var interaction_log=require(_0x035b('0x5'))('mail-interactions');var config=require('../../config/environment');var db=require(_0x035b('0x6'))['db'];config[_0x035b('0x7')]=_[_0x035b('0x8')](config['redis'],{'host':_0x035b('0x9'),'port':0x18eb});var socket=require(_0x035b('0xa'))(new Redis(config[_0x035b('0x7')]));var htmlEntities=require(_0x035b('0xb'));require(_0x035b('0xc'))[_0x035b('0xd')](socket);var jayson=require(_0x035b('0xe'));var client=jayson['client'][_0x035b('0xf')]({'port':0x232c});var client9003=jayson[_0x035b('0x10')][_0x035b('0xf')]({'port':0x232b});var client9002=jayson[_0x035b('0x10')][_0x035b('0xf')]({'port':0x232a});function respondWithRpcPromise(_0xa577d0,_0x3071df,_0x57d1c0,_0x4dd646){return new BPromise(function(_0x28cf16,_0x3d83be){var _0x320ee9=_0x4dd646||client;return _0x320ee9[_0x035b('0x11')](_0xa577d0,_0x57d1c0)[_0x035b('0x12')](function(_0x4b08b3){logger[_0x035b('0x13')](_0x035b('0x14'),_0x3071df,_0x035b('0x15'));logger[_0x035b('0x16')](_0x035b('0x17'),_0x3071df,'request\x20sent',JSON[_0x035b('0x18')](_0x4b08b3));if(_0x4b08b3['error']){if(_0x4b08b3['error'][_0x035b('0x19')]===0x1f4){logger['error'](_0x035b('0x14'),_0x3071df,_0x4b08b3[_0x035b('0x1a')]['message']);return _0x3d83be(_0x4b08b3[_0x035b('0x1a')][_0x035b('0x1b')]);}logger[_0x035b('0x1a')](_0x035b('0x14'),_0x3071df,_0x4b08b3[_0x035b('0x1a')][_0x035b('0x1b')]);return _0x28cf16(_0x4b08b3[_0x035b('0x1a')][_0x035b('0x1b')]);}else{logger['info'](_0x035b('0x14'),_0x3071df,'request\x20sent');_0x28cf16(_0x4b08b3[_0x035b('0x1c')][_0x035b('0x1b')]);}})[_0x035b('0x1d')](function(_0x28377b){logger[_0x035b('0x1a')](_0x035b('0x14'),_0x3071df,_0x28377b);_0x3d83be(_0x28377b);});});}function respondWithResult(_0x316c31,_0x3cf12d){_0x3cf12d=_0x3cf12d||0xc8;return function(_0x50067a){if(_0x50067a){return _0x316c31['status'](_0x3cf12d)[_0x035b('0x1e')](_0x50067a);}};}function respondWithFilteredResult(_0x7845df,_0x3756fc){return function(_0x4b963c){if(_0x4b963c){var _0x419265=typeof _0x3756fc[_0x035b('0x1f')]==='undefined'&&typeof _0x3756fc[_0x035b('0x20')]===_0x035b('0x21');var _0x45fcdf=_0x4b963c[_0x035b('0x22')];var _0x3c70b4=_0x419265?0x0:_0x3756fc[_0x035b('0x1f')];var _0xb365ce=_0x419265?_0x4b963c[_0x035b('0x22')]:_0x3756fc['offset']+_0x3756fc[_0x035b('0x20')];var _0x42fedc;if(_0xb365ce>=_0x45fcdf){_0xb365ce=_0x45fcdf;_0x42fedc=0xc8;}else{_0x42fedc=0xce;}_0x7845df['status'](_0x42fedc);return _0x7845df[_0x035b('0x23')](_0x035b('0x24'),_0x3c70b4+'-'+_0xb365ce+'/'+_0x45fcdf)[_0x035b('0x1e')](_0x4b963c);}return null;};}function saveUpdates(_0x47cfcc){return function(_0x25360c){if(_0x25360c){return _0x25360c[_0x035b('0x25')](_0x47cfcc)[_0x035b('0x12')](function(_0x5f15bc){return _0x5f15bc;});}return null;};}function removeEntity(_0x36d877){return function(_0x277e19){if(_0x277e19){return _0x277e19['destroy']()[_0x035b('0x12')](function(){_0x36d877[_0x035b('0x26')](0xcc)[_0x035b('0x27')]();});}};}function handleEntityNotFound(_0x1b4fe7){return function(_0x2ef6df){if(!_0x2ef6df){_0x1b4fe7[_0x035b('0x28')](0x194);}return _0x2ef6df;};}function handleError(_0x35fec3,_0x2d3990){_0x2d3990=_0x2d3990||0x1f4;return function(_0x650213){logger[_0x035b('0x1a')](_0x650213['stack']);if(_0x650213[_0x035b('0x29')]){delete _0x650213[_0x035b('0x29')];}_0x35fec3[_0x035b('0x26')](_0x2d3990)['send'](_0x650213);};}exports[_0x035b('0x2a')]=function(_0x532750,_0x40a9a1){var _0x4b3461={},_0x74dc55={},_0x17465c={'count':0x0,'rows':[]};var _0x19ce75=_[_0x035b('0x2b')](db[_0x035b('0x2c')][_0x035b('0x2d')],function(_0x202dce){return{'name':_0x202dce['fieldName'],'type':_0x202dce[_0x035b('0x2e')]['key']};});_0x74dc55[_0x035b('0x2f')]=_[_0x035b('0x2b')](_0x19ce75,_0x035b('0x29'));_0x74dc55['query']=_['keys'](_0x532750[_0x035b('0x30')]);_0x74dc55[_0x035b('0x31')]=_[_0x035b('0x32')](_0x74dc55[_0x035b('0x2f')],_0x74dc55[_0x035b('0x30')]);_0x4b3461[_0x035b('0x33')]=_[_0x035b('0x32')](_0x74dc55[_0x035b('0x2f')],qs[_0x035b('0x34')](_0x532750[_0x035b('0x30')][_0x035b('0x34')]));_0x4b3461['attributes']=_0x4b3461[_0x035b('0x33')][_0x035b('0x35')]?_0x4b3461['attributes']:_0x74dc55[_0x035b('0x2f')];if(!_0x532750[_0x035b('0x30')][_0x035b('0x36')](_0x035b('0x37'))){_0x4b3461[_0x035b('0x20')]=qs['limit'](_0x532750[_0x035b('0x30')][_0x035b('0x20')]);_0x4b3461['offset']=qs['offset'](_0x532750['query'][_0x035b('0x1f')]);}_0x4b3461['order']=qs[_0x035b('0x38')](_0x532750[_0x035b('0x30')]['sort']);_0x4b3461['where']=qs[_0x035b('0x31')](_['pick'](_0x532750[_0x035b('0x30')],_0x74dc55[_0x035b('0x31')]),_0x19ce75);if(_0x532750[_0x035b('0x30')][_0x035b('0x39')]){_0x4b3461[_0x035b('0x3a')]=_[_0x035b('0x3b')](_0x4b3461[_0x035b('0x3a')],{'$or':_['map'](_0x19ce75,function(_0x100f8a){if(_0x100f8a[_0x035b('0x2e')]!==_0x035b('0x3c')){var _0x258f07={};_0x258f07[_0x100f8a[_0x035b('0x29')]]={'$like':'%'+_0x532750[_0x035b('0x30')][_0x035b('0x39')]+'%'};return _0x258f07;}})});}_0x4b3461=_[_0x035b('0x3b')]({},_0x4b3461,_0x532750[_0x035b('0x3d')]);var _0x4cfd6d={'where':_0x4b3461[_0x035b('0x3a')]};return db['MailMessage'][_0x035b('0x22')](_0x4cfd6d)[_0x035b('0x12')](function(_0x3f606e){_0x17465c['count']=_0x3f606e;if(_0x532750[_0x035b('0x30')]['includeAll']){_0x4b3461[_0x035b('0x3e')]=[{'all':!![]}];}return db[_0x035b('0x2c')][_0x035b('0x3f')](_0x4b3461);})[_0x035b('0x12')](function(_0x55c59c){_0x17465c[_0x035b('0x40')]=_0x55c59c;return _0x17465c;})[_0x035b('0x12')](respondWithFilteredResult(_0x40a9a1,_0x4b3461))[_0x035b('0x1d')](handleError(_0x40a9a1,null));};exports[_0x035b('0x41')]=function(_0x330d7c,_0x3600b0){var _0x5032fe={'raw':!![],'where':{'id':_0x330d7c['params']['id']}},_0x702f20={};_0x702f20[_0x035b('0x2f')]=_[_0x035b('0x42')](db[_0x035b('0x2c')][_0x035b('0x2d')]);_0x702f20['query']=_[_0x035b('0x42')](_0x330d7c[_0x035b('0x30')]);_0x702f20[_0x035b('0x31')]=_[_0x035b('0x32')](_0x702f20[_0x035b('0x2f')],_0x702f20[_0x035b('0x30')]);_0x5032fe['attributes']=_[_0x035b('0x32')](_0x702f20[_0x035b('0x2f')],qs[_0x035b('0x34')](_0x330d7c[_0x035b('0x30')][_0x035b('0x34')]));_0x5032fe[_0x035b('0x33')]=_0x5032fe[_0x035b('0x33')][_0x035b('0x35')]?_0x5032fe['attributes']:_0x702f20['model'];if(_0x330d7c[_0x035b('0x30')][_0x035b('0x43')]){_0x5032fe[_0x035b('0x3e')]=[{'all':!![]}];}_0x5032fe=_[_0x035b('0x3b')]({},_0x5032fe,_0x330d7c['options']);return db[_0x035b('0x2c')][_0x035b('0x44')](_0x5032fe)[_0x035b('0x12')](handleEntityNotFound(_0x3600b0,null))[_0x035b('0x12')](respondWithResult(_0x3600b0,null))[_0x035b('0x1d')](handleError(_0x3600b0,null));};exports['update']=function(_0x558593,_0x122570){if(_0x558593[_0x035b('0x45')]['id']){delete _0x558593['body']['id'];}return db[_0x035b('0x2c')][_0x035b('0x44')]({'where':{'id':_0x558593[_0x035b('0x46')]['id']}})[_0x035b('0x12')](handleEntityNotFound(_0x122570,null))[_0x035b('0x12')](saveUpdates(_0x558593[_0x035b('0x45')],null))['then'](respondWithResult(_0x122570,null))['catch'](handleError(_0x122570,null));};exports[_0x035b('0x47')]=function(_0x212c6d,_0x1c49a7){return db[_0x035b('0x2c')][_0x035b('0x44')]({'where':{'id':_0x212c6d[_0x035b('0x46')]['id']}})['then'](handleEntityNotFound(_0x1c49a7,null))[_0x035b('0x12')](removeEntity(_0x1c49a7,null))[_0x035b('0x1d')](handleError(_0x1c49a7,null));};exports[_0x035b('0x48')]=function(_0x2d14dc,_0x3f2a96){return db[_0x035b('0x2c')][_0x035b('0x48')]()['then'](respondWithResult(_0x3f2a96,null))['catch'](handleError(_0x3f2a96,null));};exports[_0x035b('0x49')]=function(_0x424f42,_0x407f18){return db[_0x035b('0x2c')][_0x035b('0x49')](_0x424f42[_0x035b('0x45')])[_0x035b('0x12')](function(_0x37dff7){if(_0x37dff7){if(_0x37dff7[_0x035b('0x4a')]===_0x035b('0x4b')&&!_0x37dff7[_0x035b('0x4c')]){var _0x331326,_0x3b8353,_0x516746;if(_0x424f42[_0x035b('0x45')]['to']){_0x3b8353=_0x424f42['body']['to'][_0x035b('0x4d')](',')[0x0];}return db[_0x035b('0x4e')][_0x035b('0x4f')]({'where':{'id':_0x37dff7[_0x035b('0x50')]},'include':[{'model':db[_0x035b('0x51')],'as':'List','include':[{'model':db[_0x035b('0x52')],'as':_0x035b('0x53'),'where':{'email':_0x3b8353},'limit':0x1,'order':[[_0x035b('0x54'),'DESC']]}]},{'model':db[_0x035b('0x55')],'as':_0x035b('0x56'),'raw':!![]}]})[_0x035b('0x12')](function(_0x1e3a5b){_0x331326=_0x1e3a5b;if(_0x331326&&_0x331326[_0x035b('0x56')]){var _0x474388={'tls':{'rejectUnauthorized':![]}};if(_[_0x035b('0x57')](_0x331326[_0x035b('0x56')][_0x035b('0x58')])){_0x474388['host']=_0x331326[_0x035b('0x56')][_0x035b('0x59')];_0x474388[_0x035b('0x5a')]=_0x331326['Smtp']['port'];_0x474388['secure']=_0x331326['Smtp'][_0x035b('0x5b')];if(_0x331326[_0x035b('0x56')][_0x035b('0x5c')]){_0x474388[_0x035b('0x5d')]={'user':_0x331326[_0x035b('0x56')][_0x035b('0x5e')],'pass':_0x331326[_0x035b('0x56')][_0x035b('0x5f')]};}}else{_0x474388[_0x035b('0x58')]=_0x331326[_0x035b('0x56')][_0x035b('0x58')];_0x474388['auth']={'user':_0x331326[_0x035b('0x56')][_0x035b('0x5e')],'pass':_0x331326[_0x035b('0x56')][_0x035b('0x5f')]};_0x474388[_0x035b('0x5b')]=_0x331326[_0x035b('0x56')][_0x035b('0x5b')];}if(_0x424f42[_0x035b('0x45')][_0x035b('0x60')]&&_0x424f42['body'][_0x035b('0x60')][_0x035b('0x35')]){for(var _0xc5bd60=0x0;_0xc5bd60<_0x424f42[_0x035b('0x45')][_0x035b('0x60')][_0x035b('0x35')];_0xc5bd60+=0x1){_0x424f42['body']['attachments'][_0xc5bd60]={'filename':_0x424f42[_0x035b('0x45')]['attachments'][_0xc5bd60][_0x035b('0x29')],'path':path['join'](config[_0x035b('0x61')],_0x035b('0x62'),_0x424f42[_0x035b('0x45')][_0x035b('0x60')][_0xc5bd60]['basename'])};}}_0x516746={'account':_0x474388,'message':_0x424f42[_0x035b('0x45')]};return;}})['then'](function(){if(_0x331326[_0x035b('0x63')]){if(_0x331326[_0x035b('0x63')][_0x035b('0x53')][_0x035b('0x35')]){return _0x331326['List'][_0x035b('0x53')][0x0];}else{return db[_0x035b('0x52')][_0x035b('0x49')](_[_0x035b('0x8')](_0x424f42[_0x035b('0x45')],{'firstName':_0x424f42[_0x035b('0x45')]['to'],'email':_0x424f42[_0x035b('0x45')]['to'],'phone':_0x424f42[_0x035b('0x45')]['to'],'ListId':_0x331326[_0x035b('0x64')]}));}}else{throw new Error(_0x035b('0x65'));}})[_0x035b('0x12')](function(){if(_0x516746){return respondWithRpcPromise(_0x035b('0x66'),'sendMail',_0x516746,client9003)[_0x035b('0x12')](function(_0x9254aa){return _0x37dff7[_0x035b('0x25')]({'read':!![],'messageId':_0x9254aa[_0x035b('0x67')],'sentAt':moment()['format'](_0x035b('0x68'))});})['catch'](function(_0x143b33){logger[_0x035b('0x1a')]('%s',JSON['stringify'](_0x143b33));return _0x37dff7;});}return _0x37dff7;});}return _0x37dff7;}})['then'](respondWithResult(_0x407f18,0xc9))[_0x035b('0x1d')](handleError(_0x407f18,null));};exports[_0x035b('0x69')]=function(_0x521a4e,_0x2197dc){var _0x31a789={'agent':{},'channel':_0x035b('0x6a')};if(_0x521a4e[_0x035b('0x45')]['id']){delete _0x521a4e[_0x035b('0x45')]['id'];}_0x521a4e['body']['read']=!![];_0x521a4e[_0x035b('0x45')][_0x035b('0x6b')]=moment()[_0x035b('0x6c')](_0x035b('0x68'));_0x521a4e['body'][_0x035b('0x6d')]=_0x521a4e['body']['UserId']||_0x521a4e[_0x035b('0x5e')]['id'];_0x31a789[_0x035b('0x6e')]['id']=_0x521a4e[_0x035b('0x45')][_0x035b('0x6d')];return db[_0x035b('0x2c')][_0x035b('0x44')]({'where':{'id':_0x521a4e[_0x035b('0x46')]['id'],'UserId':null}})[_0x035b('0x12')](handleEntityNotFound(_0x2197dc,null))['then'](saveUpdates(_0x521a4e[_0x035b('0x45')],null))[_0x035b('0x12')](function(_0x4bc875){if(_0x4bc875){_0x31a789[_0x035b('0x1b')]=_0x4bc875[_0x035b('0x6f')]({'plain':!![]});return db[_0x035b('0x70')][_0x035b('0x44')]({'where':{'id':_0x4bc875[_0x035b('0x71')]}});}return null;})[_0x035b('0x12')](handleEntityNotFound(_0x2197dc,null))[_0x035b('0x12')](function(_0x35c014){if(_0x35c014){return _0x35c014[_0x035b('0x25')]({'UserId':_0x521a4e[_0x035b('0x45')][_0x035b('0x6d')],'read1stAt':_['isNil'](_0x35c014[_0x035b('0x72')])?moment()[_0x035b('0x6c')](_0x035b('0x68')):undefined});}return null;})[_0x035b('0x12')](function(_0x104a61){if(_0x104a61){_0x31a789['interaction']=_0x104a61['get']({'plain':!![]});interaction_log['info'](_0x035b('0x73'),_0x521a4e['user']['id'],_0x521a4e['user']['name'],_0x521a4e['user'][_0x035b('0x74')],_0x31a789[_0x035b('0x75')]['id'],_0x521a4e[_0x035b('0x45')]?JSON[_0x035b('0x18')](_0x521a4e['body']):_0x035b('0x76'));return respondWithRpcPromise(_0x035b('0x77'),_0x035b('0x78'),_0x31a789);}return null;})[_0x035b('0x12')](function(_0x3b4d84){var _0x4f20c8='SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20'+_0x3b4d84[_0x035b('0x1b')]['ContactId'];return db[_0x035b('0x79')][_0x035b('0x30')](_0x4f20c8,{'type':db['Sequelize']['QueryTypes'][_0x035b('0x7a')],'raw':!![]})['then'](function(_0xa4c8e4){return _0xa4c8e4;});})[_0x035b('0x12')](function(_0x3391df){if(_0x3391df){_0x31a789['message'][_0x035b('0x7b')]=_0x3391df[0x0];if(!_0x521a4e['body'][_0x035b('0x6d')])return;return db['User']['find']({'where':{'id':_0x521a4e[_0x035b('0x45')]['UserId'],'role':'agent'},'attributes':['id',_0x035b('0x29'),_0x035b('0x7c'),'email',_0x035b('0x7d')],'raw':!![]});}return null;})[_0x035b('0x12')](function(_0xabbe77){if(!_0xabbe77)return null;_0x31a789['message'][_0x035b('0x6e')]=_0xabbe77;return _0x31a789;})[_0x035b('0x12')](function(_0x3f6114){if(_0x3f6114){if(_0x521a4e[_0x035b('0x45')][_0x035b('0x7e')]){_0x31a789[_0x035b('0x1b')][_0x035b('0x7f')]=util[_0x035b('0x6c')](_0x035b('0x80'),_0x521a4e[_0x035b('0x5e')]['name']);_0x31a789['message'][_0x035b('0x81')]=_0x31a789[_0x035b('0x81')];_0x31a789['message'][_0x035b('0x82')]=_0x31a789['channel'];_0x31a789[_0x035b('0x1b')]['event']=_0x035b('0x69');_0x31a789[_0x035b('0x1b')]['body']=htmlToText[_0x035b('0x83')](_0x31a789[_0x035b('0x1b')]['body']);return respondWithRpcPromise(_0x035b('0x84'),_0x035b('0x84'),{'event':_0x035b('0x85'),'message':_0x31a789['message']},client9002)[_0x035b('0x12')](function(){return _0x31a789;});}return _0x31a789;}return null;})[_0x035b('0x12')](respondWithResult(_0x2197dc,null))[_0x035b('0x1d')](handleError(_0x2197dc,null));};exports['reject']=function(_0x1a6223,_0x6e180e){var _0xd96046={'agent':{},'channel':_0x035b('0x6a')};if(_0x1a6223[_0x035b('0x45')]['id']){delete _0x1a6223[_0x035b('0x45')]['id'];}_0x1a6223['body'][_0x035b('0x6d')]=_0x1a6223[_0x035b('0x45')][_0x035b('0x6d')]||_0x1a6223[_0x035b('0x5e')]['id'];_0xd96046['agent']['id']=_0x1a6223['body'][_0x035b('0x6d')];return db['MailMessage'][_0x035b('0x44')]({'where':{'id':_0x1a6223[_0x035b('0x46')]['id'],'UserId':null}})[_0x035b('0x12')](handleEntityNotFound(_0x6e180e,null))[_0x035b('0x12')](function(_0x105134){if(_0x105134){_0xd96046['message']=_0x105134[_0x035b('0x6f')]({'plain':!![]});return db['MailInteraction'][_0x035b('0x44')]({'where':{'id':_0x105134[_0x035b('0x71')]}});}return null;})['then'](handleEntityNotFound(_0x6e180e,null))[_0x035b('0x12')](function(_0x398174){if(_0x398174){_0xd96046['interaction']=_0x398174[_0x035b('0x6f')]({'plain':!![]});interaction_log[_0x035b('0x13')]('[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x1a6223[_0x035b('0x5e')]['id'],_0x1a6223[_0x035b('0x5e')][_0x035b('0x29')],_0x1a6223[_0x035b('0x5e')][_0x035b('0x74')],_0xd96046[_0x035b('0x75')]['id'],_0x1a6223[_0x035b('0x45')]?JSON['stringify'](_0x1a6223[_0x035b('0x45')]):_0x035b('0x76'));return respondWithRpcPromise(_0x035b('0x86'),_0x035b('0x87'),_0xd96046);}return null;})['then'](function(_0x1a0f5e){var _0x5986fc=_0x035b('0x88')+_0x1a0f5e[_0x035b('0x1b')][_0x035b('0x89')];return db[_0x035b('0x79')]['query'](_0x5986fc,{'type':db['Sequelize'][_0x035b('0x8a')][_0x035b('0x7a')],'raw':!![]})[_0x035b('0x12')](function(_0x2020bb){return _0x2020bb;});})[_0x035b('0x12')](function(_0x302a8b){if(_0x302a8b){_0xd96046[_0x035b('0x1b')]['contact']=_0x302a8b[0x0];if(!_0x1a6223['body'][_0x035b('0x6d')])return;return db[_0x035b('0x8b')][_0x035b('0x44')]({'where':{'id':_0x1a6223[_0x035b('0x45')][_0x035b('0x6d')],'role':_0x035b('0x6e')},'attributes':['id',_0x035b('0x29'),_0x035b('0x7c'),_0x035b('0x8c'),_0x035b('0x7d')],'raw':!![]});}return null;})[_0x035b('0x12')](function(_0x2092b9){if(!_0x2092b9)return null;_0xd96046[_0x035b('0x1b')][_0x035b('0x6e')]=_0x2092b9;return _0xd96046;})[_0x035b('0x12')](function(_0x19fdae){if(_0x19fdae){_0x19fdae[_0x035b('0x1b')]['interface']=util['format'](_0x035b('0x80'),_0x1a6223[_0x035b('0x5e')][_0x035b('0x29')]);_0x19fdae[_0x035b('0x1b')][_0x035b('0x81')]=_0xd96046[_0x035b('0x81')];_0x19fdae[_0x035b('0x1b')]['motionChannel']=_0xd96046['channel'];_0x19fdae['message'][_0x035b('0x8d')]=_0x035b('0x8e');_0x19fdae[_0x035b('0x1b')][_0x035b('0x45')]=htmlToText[_0x035b('0x83')](_0xd96046[_0x035b('0x1b')][_0x035b('0x45')]);respondWithRpcPromise(_0x035b('0x84'),_0x035b('0x84'),{'event':'rejectmessage','message':_0x19fdae['message']},client9002);return _0xd96046;}return null;})[_0x035b('0x12')](respondWithResult(_0x6e180e,null))[_0x035b('0x1d')](handleError(_0x6e180e,null));};exports[_0x035b('0x8f')]=function(_0x4d1df0,_0x3d6f41){var _0x56ac02=moment()[_0x035b('0x90')]()[_0x035b('0x91')]();var _0xb35a18=path['join'](config['root'],'server',_0x035b('0x92'),_0x035b('0x93'));var _0x4d9a7b=path[_0x035b('0x94')](config[_0x035b('0x61')],_0x035b('0x95'),_0x035b('0x92'),'attachments');var _0x57853b=util[_0x035b('0x6c')](_0x035b('0x96'),_0x56ac02);return db[_0x035b('0x2c')][_0x035b('0x44')]({'where':{'id':_0x4d1df0[_0x035b('0x46')]['id']},'attributes':['id','body',_0x035b('0x97'),'to','cc',_0x035b('0x98'),'subject',_0x035b('0x99')],'include':_0x4d1df0[_0x035b('0x30')][_0x035b('0x60')]?[{'model':db['Attachment'],'as':_0x035b('0x9a')}]:undefined})[_0x035b('0x12')](handleEntityNotFound(_0x3d6f41,null))[_0x035b('0x12')](function(_0x5e53be){if(_0x5e53be){var _0x43307b=_0x5e53be;var _0x1ef534={'from':_0x43307b[_0x035b('0x97')],'to':_0x43307b['to'],'subject':_0x43307b[_0x035b('0x9b')],'html':htmlEntities['decode'](_0x43307b[_0x035b('0x45')]),'headers':{'Date':moment(_0x43307b[_0x035b('0x99')])[_0x035b('0x6c')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x5e53be['cc']){_0x1ef534[_0x035b('0x9c')]['Cc']=_0x5e53be['cc'];}if(_0x5e53be[_0x035b('0x98')]){_0x1ef534[_0x035b('0x9c')]['Bcc']=_0x5e53be[_0x035b('0x98')];}return new BPromise(function(_0xce644e,_0xc12635){if(_0x5e53be[_0x035b('0x9a')]){for(var _0x3e3f55=0x0;_0x3e3f55<_0x5e53be[_0x035b('0x9a')]['length'];_0x3e3f55++){var _0x56a640=_0x5e53be[_0x035b('0x9a')][_0x3e3f55];var _0x136b1c=path[_0x035b('0x94')](_0x4d9a7b,_0x56a640[_0x035b('0x9d')]);if(fs[_0x035b('0x9e')](_0x136b1c)){_0x1ef534[_0x035b('0x60')][_0x035b('0x9f')]({'name':_0x56a640[_0x035b('0x29')],'contentType':_0x56a640['type'],'data':fs[_0x035b('0xa0')](_0x136b1c)});}}}emlformat[_0x035b('0xa1')](_0x1ef534,function(_0x3066c7,_0x5694ce){if(_0x3066c7)return _0xc12635(_0x3066c7);fs[_0x035b('0xa2')](path[_0x035b('0x94')](_0xb35a18,_0x57853b),_0x5694ce);return _0xce644e(_0x5694ce);});});}})[_0x035b('0x12')](function(_0x5158cc){if(_0x5158cc){return _0x3d6f41[_0x035b('0x8f')](path['join'](_0xb35a18,_0x57853b),_0x57853b,function(_0x5b4c21){if(!_0x5b4c21)fs[_0x035b('0xa3')](path[_0x035b('0x94')](_0xb35a18,_0x57853b));});}})[_0x035b('0x1d')](handleError(_0x3d6f41,null));};