739b3095c74503773d5b304f78b426f3875719fd
[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 _0x8ac4=['nolimit','limit','order','sort','where','pick','filter','merge','type','count','includeAll','include','findAll','rows','catch','show','params','MailMessage','options','find','update','body','describe','create','direction','out','split','MailAccountId','CmList','List','updatedAt','DESC','MailServerOut','isNil','Smtp','service','host','port','secure','auth','pass','user','attachments','root','basename','Contacts','CmContact','List\x20not\x20found','SendMail','sendMail','messageId','YYYY-MM-DD\x20HH:mm:ss','mail-interactions','mail','read','readAt','format','UserId','Contact','get','MailInteraction','MailInteractionId','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','AcceptMessage','acceptMessage','interface','SIP/%s','channel','accept','EventManager','acceptmessage','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','event','unix','join','server','files','from','bcc','subject','Attachment','createdAt','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','Attachments','push','build','writeFileSync','download','log','err','unlinkSync','html-pdf','eml-format','rimraf','fast-json-patch','request-promise','moment','bluebird','util','path','to-csv','lodash','squel','crypto','jsforce','desk.js','querystring','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/environment','../../config/license/util','../../mysqldb','defaults','redis','socket.io-emitter','http','client','request','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','MailMessage,\x20%s,\x20%s','message','info','result','sendStatus','end','status','json','offset','set','Content-Range','apply','reject','then','destroy','stack','name','index','map','rawAttributes','key','query','keys','filters','intersection','model','fields','attributes','length'];(function(_0x1d44e2,_0x19284e){var _0x1f41c3=function(_0x17fa08){while(--_0x17fa08){_0x1d44e2['push'](_0x1d44e2['shift']());}};_0x1f41c3(++_0x19284e);}(_0x8ac4,0x104));var _0x48ac=function(_0x136e40,_0x4bbef6){_0x136e40=_0x136e40-0x0;var _0x5c1807=_0x8ac4[_0x136e40];return _0x5c1807;};'use strict';var pdf=require(_0x48ac('0x0'));var emlformat=require(_0x48ac('0x1'));var rimraf=require(_0x48ac('0x2'));var zipdir=require('zip-dir');var jsonpatch=require(_0x48ac('0x3'));var rp=require(_0x48ac('0x4'));var moment=require(_0x48ac('0x5'));var BPromise=require(_0x48ac('0x6'));var Mustache=require('mustache');var util=require(_0x48ac('0x7'));var path=require(_0x48ac('0x8'));var sox=require('sox');var csv=require(_0x48ac('0x9'));var ejs=require('ejs');var fs=require('fs');var _=require(_0x48ac('0xa'));var squel=require(_0x48ac('0xb'));var crypto=require(_0x48ac('0xc'));var jsforce=require(_0x48ac('0xd'));var deskjs=require(_0x48ac('0xe'));var toCsv=require(_0x48ac('0x9'));var querystring=require(_0x48ac('0xf'));var Papa=require('papaparse');var Redis=require(_0x48ac('0x10'));var authService=require(_0x48ac('0x11'));var qs=require(_0x48ac('0x12'));var as=require(_0x48ac('0x13'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x48ac('0x14'))(_0x48ac('0x15'));var utils=require('../../config/utils');var config=require(_0x48ac('0x16'));var licenseUtil=require(_0x48ac('0x17'));var db=require(_0x48ac('0x18'))['db'];config['redis']=_[_0x48ac('0x19')](config[_0x48ac('0x1a')],{'host':'localhost','port':0x18eb});var socket=require(_0x48ac('0x1b'))(new Redis(config[_0x48ac('0x1a')]));require('./mailMessage.socket')['register'](socket);var jayson=require('jayson/promise');var client=jayson['client'][_0x48ac('0x1c')]({'port':0x232c});var client9003=jayson[_0x48ac('0x1d')][_0x48ac('0x1c')]({'port':0x232b});var client9002=jayson[_0x48ac('0x1d')][_0x48ac('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x2c7418,_0x3c9a24,_0x5a28d5,_0x693d80){return new BPromise(function(_0x447eb7,_0x157e56){var _0x55860f=_0x693d80||client;return _0x55860f[_0x48ac('0x1e')](_0x2c7418,_0x5a28d5)['then'](function(_0x185406){logger['info']('MailMessage,\x20%s,\x20%s',_0x3c9a24,_0x48ac('0x1f'));logger[_0x48ac('0x20')](_0x48ac('0x21'),_0x3c9a24,'request\x20sent',JSON[_0x48ac('0x22')](_0x185406));if(_0x185406['error']){if(_0x185406[_0x48ac('0x23')][_0x48ac('0x24')]===0x1f4){logger[_0x48ac('0x23')](_0x48ac('0x25'),_0x3c9a24,_0x185406[_0x48ac('0x23')][_0x48ac('0x26')]);return _0x157e56(_0x185406[_0x48ac('0x23')][_0x48ac('0x26')]);}logger[_0x48ac('0x23')](_0x48ac('0x25'),_0x3c9a24,_0x185406[_0x48ac('0x23')][_0x48ac('0x26')]);return _0x447eb7(_0x185406['error']['message']);}else{logger[_0x48ac('0x27')](_0x48ac('0x25'),_0x3c9a24,'request\x20sent');_0x447eb7(_0x185406[_0x48ac('0x28')][_0x48ac('0x26')]);}})['catch'](function(_0x5ae2e6){logger[_0x48ac('0x23')](_0x48ac('0x25'),_0x3c9a24,_0x5ae2e6);_0x157e56(_0x5ae2e6);});});}function respondWithStatusCode(_0x29d6f2,_0x2a2051){_0x2a2051=_0x2a2051||0xcc;return function(_0x4fb292){if(_0x4fb292){return _0x29d6f2[_0x48ac('0x29')](_0x2a2051);}return _0x29d6f2['status'](_0x2a2051)[_0x48ac('0x2a')]();};}function respondWithResult(_0x16b74f,_0x417be2){_0x417be2=_0x417be2||0xc8;return function(_0x5ddf5b){if(_0x5ddf5b){return _0x16b74f[_0x48ac('0x2b')](_0x417be2)[_0x48ac('0x2c')](_0x5ddf5b);}};}function respondWithFilteredResult(_0x2339d0,_0x3a3e7b){return function(_0x77b512){if(_0x77b512){var _0x25e323=_0x77b512['count'],_0x37c0ff=_0x3a3e7b[_0x48ac('0x2d')],_0x5a195c=_0x3a3e7b[_0x48ac('0x2d')]+_0x3a3e7b['limit'],_0x19120c;if(_0x5a195c>=_0x25e323){_0x5a195c=_0x25e323;_0x19120c=0xc8;}else{_0x19120c=0xce;}_0x2339d0[_0x48ac('0x2b')](_0x19120c);return _0x2339d0[_0x48ac('0x2e')](_0x48ac('0x2f'),_0x37c0ff+'-'+_0x5a195c+'/'+_0x25e323)[_0x48ac('0x2c')](_0x77b512);}return null;};}function patchUpdates(_0x3cf089){return function(_0xe849dc){try{jsonpatch[_0x48ac('0x30')](_0xe849dc,_0x3cf089,!![]);}catch(_0x4cc9be){return BPromise[_0x48ac('0x31')](_0x4cc9be);}return _0xe849dc['save']();};}function saveUpdates(_0x3c5a40,_0x2e10aa){return function(_0x50e20a){if(_0x50e20a){return _0x50e20a['update'](_0x3c5a40)[_0x48ac('0x32')](function(_0x255856){return _0x255856;});}return null;};}function removeEntity(_0x2450ac,_0x1ff829){return function(_0x50218c){if(_0x50218c){return _0x50218c[_0x48ac('0x33')]()[_0x48ac('0x32')](function(){_0x2450ac[_0x48ac('0x2b')](0xcc)[_0x48ac('0x2a')]();});}};}function handleEntityNotFound(_0xa52060,_0x175651){return function(_0x594783){if(!_0x594783){_0xa52060[_0x48ac('0x29')](0x194);}return _0x594783;};}function handleError(_0x3d4219,_0x205241){_0x205241=_0x205241||0x1f4;return function(_0x44db29){logger[_0x48ac('0x23')](_0x44db29[_0x48ac('0x34')]);if(_0x44db29[_0x48ac('0x35')]){delete _0x44db29['name'];}_0x3d4219[_0x48ac('0x2b')](_0x205241)['send'](_0x44db29);};}exports[_0x48ac('0x36')]=function(_0x1ac626,_0x16ee80){var _0x57da98={},_0x3de95e={},_0x577204={'count':0x0,'rows':[]};var _0x39e371=_[_0x48ac('0x37')](db['MailMessage'][_0x48ac('0x38')],function(_0x1878f6){return{'name':_0x1878f6['fieldName'],'type':_0x1878f6['type'][_0x48ac('0x39')]};});_0x3de95e['model']=_[_0x48ac('0x37')](_0x39e371,_0x48ac('0x35'));_0x3de95e[_0x48ac('0x3a')]=_[_0x48ac('0x3b')](_0x1ac626['query']);_0x3de95e[_0x48ac('0x3c')]=_[_0x48ac('0x3d')](_0x3de95e[_0x48ac('0x3e')],_0x3de95e[_0x48ac('0x3a')]);_0x57da98['attributes']=_['intersection'](_0x3de95e[_0x48ac('0x3e')],qs[_0x48ac('0x3f')](_0x1ac626['query'][_0x48ac('0x3f')]));_0x57da98[_0x48ac('0x40')]=_0x57da98[_0x48ac('0x40')][_0x48ac('0x41')]?_0x57da98[_0x48ac('0x40')]:_0x3de95e['model'];if(!_0x1ac626[_0x48ac('0x3a')]['hasOwnProperty'](_0x48ac('0x42'))){_0x57da98[_0x48ac('0x43')]=qs[_0x48ac('0x43')](_0x1ac626['query'][_0x48ac('0x43')]);_0x57da98['offset']=qs[_0x48ac('0x2d')](_0x1ac626[_0x48ac('0x3a')][_0x48ac('0x2d')]);}_0x57da98[_0x48ac('0x44')]=qs['sort'](_0x1ac626[_0x48ac('0x3a')][_0x48ac('0x45')]);_0x57da98[_0x48ac('0x46')]=qs['filters'](_[_0x48ac('0x47')](_0x1ac626[_0x48ac('0x3a')],_0x3de95e[_0x48ac('0x3c')]),_0x39e371);if(_0x1ac626[_0x48ac('0x3a')][_0x48ac('0x48')]){_0x57da98[_0x48ac('0x46')]=_[_0x48ac('0x49')](_0x57da98[_0x48ac('0x46')],{'$or':_[_0x48ac('0x37')](_0x39e371,function(_0x322d54){if(_0x322d54[_0x48ac('0x4a')]!=='VIRTUAL'){var _0x2305c3={};_0x2305c3[_0x322d54['name']]={'$like':'%'+_0x1ac626[_0x48ac('0x3a')][_0x48ac('0x48')]+'%'};return _0x2305c3;}})});}_0x57da98=_[_0x48ac('0x49')]({},_0x57da98,_0x1ac626['options']);var _0x1efc93={'where':_0x57da98['where']};return db['MailMessage'][_0x48ac('0x4b')](_0x1efc93)[_0x48ac('0x32')](function(_0x2aa1bd){_0x577204[_0x48ac('0x4b')]=_0x2aa1bd;if(_0x1ac626[_0x48ac('0x3a')][_0x48ac('0x4c')]){_0x57da98[_0x48ac('0x4d')]=[{'all':!![]}];}return db['MailMessage'][_0x48ac('0x4e')](_0x57da98);})[_0x48ac('0x32')](function(_0x1ce052){_0x577204[_0x48ac('0x4f')]=_0x1ce052;return _0x577204;})[_0x48ac('0x32')](respondWithFilteredResult(_0x16ee80,_0x57da98))[_0x48ac('0x50')](handleError(_0x16ee80,null));};exports[_0x48ac('0x51')]=function(_0x471130,_0x574960){var _0x492d43={'raw':!![],'where':{'id':_0x471130[_0x48ac('0x52')]['id']}},_0x28514d={};_0x28514d['model']=_[_0x48ac('0x3b')](db[_0x48ac('0x53')][_0x48ac('0x38')]);_0x28514d['query']=_[_0x48ac('0x3b')](_0x471130['query']);_0x28514d[_0x48ac('0x3c')]=_[_0x48ac('0x3d')](_0x28514d[_0x48ac('0x3e')],_0x28514d[_0x48ac('0x3a')]);_0x492d43[_0x48ac('0x40')]=_[_0x48ac('0x3d')](_0x28514d['model'],qs[_0x48ac('0x3f')](_0x471130[_0x48ac('0x3a')]['fields']));_0x492d43[_0x48ac('0x40')]=_0x492d43[_0x48ac('0x40')][_0x48ac('0x41')]?_0x492d43[_0x48ac('0x40')]:_0x28514d[_0x48ac('0x3e')];if(_0x471130['query'][_0x48ac('0x4c')]){_0x492d43[_0x48ac('0x4d')]=[{'all':!![]}];}_0x492d43=_['merge']({},_0x492d43,_0x471130[_0x48ac('0x54')]);return db[_0x48ac('0x53')][_0x48ac('0x55')](_0x492d43)['then'](handleEntityNotFound(_0x574960,null))[_0x48ac('0x32')](respondWithResult(_0x574960,null))['catch'](handleError(_0x574960,null));};exports[_0x48ac('0x56')]=function(_0x28ea5f,_0x3fed49){if(_0x28ea5f[_0x48ac('0x57')]['id']){delete _0x28ea5f['body']['id'];}return db[_0x48ac('0x53')][_0x48ac('0x55')]({'where':{'id':_0x28ea5f[_0x48ac('0x52')]['id']}})[_0x48ac('0x32')](handleEntityNotFound(_0x3fed49,null))[_0x48ac('0x32')](saveUpdates(_0x28ea5f[_0x48ac('0x57')],null))[_0x48ac('0x32')](respondWithResult(_0x3fed49,null))[_0x48ac('0x50')](handleError(_0x3fed49,null));};exports[_0x48ac('0x33')]=function(_0xa891f8,_0x1f5f8b){return db[_0x48ac('0x53')][_0x48ac('0x55')]({'where':{'id':_0xa891f8[_0x48ac('0x52')]['id']}})[_0x48ac('0x32')](handleEntityNotFound(_0x1f5f8b,null))['then'](removeEntity(_0x1f5f8b,null))['catch'](handleError(_0x1f5f8b,null));};exports['describe']=function(_0x24c1c2,_0x2409e9){return db[_0x48ac('0x53')][_0x48ac('0x58')]()[_0x48ac('0x32')](respondWithResult(_0x2409e9,null))[_0x48ac('0x50')](handleError(_0x2409e9,null));};exports['create']=function(_0x107f71,_0x252682){return db['MailMessage'][_0x48ac('0x59')](_0x107f71[_0x48ac('0x57')])[_0x48ac('0x32')](function(_0x52197c){if(_0x52197c){if(_0x52197c[_0x48ac('0x5a')]===_0x48ac('0x5b')&&!_0x52197c['secret']){var _0x5709d4,_0x2398e2,_0x16a600;if(_0x107f71[_0x48ac('0x57')]['to']){_0x2398e2=_0x107f71[_0x48ac('0x57')]['to'][_0x48ac('0x5c')](',')[0x0];}return db['MailAccount']['findOne']({'where':{'id':_0x52197c[_0x48ac('0x5d')]},'include':[{'model':db[_0x48ac('0x5e')],'as':_0x48ac('0x5f'),'include':[{'model':db['CmContact'],'as':'Contacts','where':{'email':_0x2398e2},'limit':0x1,'order':[[_0x48ac('0x60'),_0x48ac('0x61')]]}]},{'model':db[_0x48ac('0x62')],'as':'Smtp','raw':!![]}]})[_0x48ac('0x32')](function(_0x3d933b){_0x5709d4=_0x3d933b;if(_0x5709d4&&_0x5709d4['Smtp']){var _0x5b89bc={'tls':{'rejectUnauthorized':![]}};if(_[_0x48ac('0x63')](_0x5709d4[_0x48ac('0x64')][_0x48ac('0x65')])){_0x5b89bc[_0x48ac('0x66')]=_0x5709d4[_0x48ac('0x64')][_0x48ac('0x66')];_0x5b89bc[_0x48ac('0x67')]=_0x5709d4['Smtp'][_0x48ac('0x67')];_0x5b89bc['secure']=_0x5709d4['Smtp'][_0x48ac('0x68')];if(_0x5709d4[_0x48ac('0x64')]['authentication']){_0x5b89bc[_0x48ac('0x69')]={'user':_0x5709d4[_0x48ac('0x64')]['user'],'pass':_0x5709d4[_0x48ac('0x64')][_0x48ac('0x6a')]};}}else{_0x5b89bc[_0x48ac('0x65')]=_0x5709d4[_0x48ac('0x64')][_0x48ac('0x65')];_0x5b89bc[_0x48ac('0x69')]={'user':_0x5709d4[_0x48ac('0x64')][_0x48ac('0x6b')],'pass':_0x5709d4['Smtp']['pass']};_0x5b89bc[_0x48ac('0x68')]=_0x5709d4[_0x48ac('0x64')]['secure'];}if(_0x107f71[_0x48ac('0x57')][_0x48ac('0x6c')]&&_0x107f71['body']['attachments']['length']){for(var _0x29c175=0x0;_0x29c175<_0x107f71[_0x48ac('0x57')]['attachments'][_0x48ac('0x41')];_0x29c175+=0x1){_0x107f71[_0x48ac('0x57')]['attachments'][_0x29c175]={'filename':_0x107f71[_0x48ac('0x57')][_0x48ac('0x6c')][_0x29c175][_0x48ac('0x35')],'path':path['join'](config[_0x48ac('0x6d')],'server/files/attachments',_0x107f71[_0x48ac('0x57')]['attachments'][_0x29c175][_0x48ac('0x6e')])};}}_0x16a600={'account':_0x5b89bc,'message':_0x107f71[_0x48ac('0x57')]};return;}})[_0x48ac('0x32')](function(){if(_0x5709d4['List']){if(_0x5709d4['List'][_0x48ac('0x6f')][_0x48ac('0x41')]){return _0x5709d4[_0x48ac('0x5f')]['Contacts'][0x0];}else{return db[_0x48ac('0x70')][_0x48ac('0x59')](_[_0x48ac('0x19')](_0x107f71[_0x48ac('0x57')],{'firstName':_0x107f71[_0x48ac('0x57')]['to'],'email':_0x107f71['body']['to'],'phone':_0x107f71[_0x48ac('0x57')]['to'],'ListId':_0x5709d4['ListId']}));}}else{throw new Error(_0x48ac('0x71'));}})[_0x48ac('0x32')](function(){if(_0x16a600){return respondWithRpcPromise(_0x48ac('0x72'),_0x48ac('0x73'),_0x16a600,client9003)[_0x48ac('0x32')](function(_0x4efec5){return _0x52197c[_0x48ac('0x56')]({'read':!![],'messageId':_0x4efec5[_0x48ac('0x74')],'sentAt':moment()['format'](_0x48ac('0x75'))});})[_0x48ac('0x50')](function(_0x527da5){logger[_0x48ac('0x23')]('%s',JSON[_0x48ac('0x22')](_0x527da5));return _0x52197c;});}return _0x52197c;});}return _0x52197c;}})['then'](respondWithResult(_0x252682,0xc9))[_0x48ac('0x50')](handleError(_0x252682,null));};var interaction_log=require(_0x48ac('0x14'))(_0x48ac('0x76'));exports['accept']=function(_0x3b51cc,_0x102b64,_0x28a0c3){var _0x374289={'channel':_0x48ac('0x77')};if(_0x3b51cc[_0x48ac('0x57')]['id']){delete _0x3b51cc[_0x48ac('0x57')]['id'];}_0x3b51cc[_0x48ac('0x57')][_0x48ac('0x78')]=!![];_0x3b51cc[_0x48ac('0x57')][_0x48ac('0x79')]=moment()[_0x48ac('0x7a')](_0x48ac('0x75'));_0x3b51cc[_0x48ac('0x57')]['UserId']=_0x3b51cc[_0x48ac('0x57')][_0x48ac('0x7b')]||_0x3b51cc[_0x48ac('0x6b')]['id'];return db[_0x48ac('0x53')][_0x48ac('0x55')]({'where':{'id':_0x3b51cc[_0x48ac('0x52')]['id'],'UserId':null},'include':[{'model':db[_0x48ac('0x70')],'as':_0x48ac('0x7c')}]})[_0x48ac('0x32')](handleEntityNotFound(_0x102b64,null))['then'](saveUpdates(_0x3b51cc[_0x48ac('0x57')],null))[_0x48ac('0x32')](function(_0x59cc04){if(_0x59cc04){_0x374289['message']=_0x59cc04[_0x48ac('0x7d')]({'plain':!![]});return db[_0x48ac('0x7e')][_0x48ac('0x55')]({'where':{'id':_0x59cc04[_0x48ac('0x7f')]}});}return null;})[_0x48ac('0x32')](handleEntityNotFound(_0x102b64,null))[_0x48ac('0x32')](function(_0x1f4ee0){if(_0x1f4ee0){return _0x1f4ee0[_0x48ac('0x56')]({'UserId':_0x3b51cc['body'][_0x48ac('0x7b')],'read1stAt':_[_0x48ac('0x63')](_0x1f4ee0[_0x48ac('0x80')])?moment()[_0x48ac('0x7a')](_0x48ac('0x75')):undefined});}return null;})[_0x48ac('0x32')](function(_0xfeb5f0){if(_0xfeb5f0){_0x374289[_0x48ac('0x81')]=_0xfeb5f0[_0x48ac('0x7d')]({'plain':!![]});interaction_log[_0x48ac('0x27')](_0x48ac('0x82'),_0x3b51cc['user']['id'],_0x3b51cc[_0x48ac('0x6b')][_0x48ac('0x35')],_0x3b51cc['user'][_0x48ac('0x83')],_0x374289[_0x48ac('0x81')]['id'],_0x3b51cc[_0x48ac('0x57')]?JSON[_0x48ac('0x22')](_0x3b51cc[_0x48ac('0x57')]):'null');return respondWithRpcPromise(_0x48ac('0x84'),_0x48ac('0x85'),_0x374289);}return null;})[_0x48ac('0x32')](function(_0x50fb39){if(_0x50fb39){if(_0x3b51cc[_0x48ac('0x57')]['manual']){_0x374289[_0x48ac('0x26')][_0x48ac('0x86')]=util['format'](_0x48ac('0x87'),_0x3b51cc[_0x48ac('0x6b')][_0x48ac('0x35')]);_0x374289[_0x48ac('0x26')][_0x48ac('0x88')]=_0x374289['channel'];_0x374289['message']['event']=_0x48ac('0x89');return respondWithRpcPromise(_0x48ac('0x8a'),_0x48ac('0x8a'),{'event':_0x48ac('0x8b'),'message':_0x374289[_0x48ac('0x26')]},client9002)[_0x48ac('0x32')](function(){return _0x374289;});}return _0x374289;}return null;})[_0x48ac('0x32')](respondWithResult(_0x102b64,null))[_0x48ac('0x50')](handleError(_0x102b64,null));};var interaction_log=require(_0x48ac('0x14'))(_0x48ac('0x76'));exports['reject']=function(_0x402087,_0x17cfa7,_0x5e2f8e){var _0x7a03d7={'agent':{},'channel':_0x48ac('0x77')};if(_0x402087[_0x48ac('0x57')]['id']){delete _0x402087[_0x48ac('0x57')]['id'];}_0x402087['body'][_0x48ac('0x7b')]=_0x402087[_0x48ac('0x57')]['UserId']||_0x402087[_0x48ac('0x6b')]['id'];_0x7a03d7['agent']['id']=_0x402087[_0x48ac('0x57')][_0x48ac('0x7b')];return db[_0x48ac('0x53')][_0x48ac('0x55')]({'where':{'id':_0x402087[_0x48ac('0x52')]['id'],'UserId':null}})[_0x48ac('0x32')](handleEntityNotFound(_0x17cfa7,null))[_0x48ac('0x32')](function(_0x173583){if(_0x173583){_0x7a03d7[_0x48ac('0x26')]=_0x173583[_0x48ac('0x7d')]({'plain':!![]});return db['MailInteraction'][_0x48ac('0x55')]({'where':{'id':_0x173583[_0x48ac('0x7f')]}});}return null;})[_0x48ac('0x32')](handleEntityNotFound(_0x17cfa7,null))[_0x48ac('0x32')](function(_0x148ef8){if(_0x148ef8){_0x7a03d7[_0x48ac('0x81')]=_0x148ef8[_0x48ac('0x7d')]({'plain':!![]});interaction_log['info'](_0x48ac('0x8c'),_0x402087[_0x48ac('0x6b')]['id'],_0x402087[_0x48ac('0x6b')][_0x48ac('0x35')],_0x402087[_0x48ac('0x6b')][_0x48ac('0x83')],_0x7a03d7[_0x48ac('0x81')]['id'],_0x402087['body']?JSON[_0x48ac('0x22')](_0x402087[_0x48ac('0x57')]):'null');return respondWithRpcPromise(_0x48ac('0x8d'),'rejectMessage',_0x7a03d7);}return null;})[_0x48ac('0x32')](function(_0x1f40f8){if(_0x1f40f8){_0x1f40f8[_0x48ac('0x26')]['interface']=util[_0x48ac('0x7a')](_0x48ac('0x87'),_0x402087['user']['name']);_0x1f40f8[_0x48ac('0x26')][_0x48ac('0x88')]=_0x7a03d7['channel'];_0x1f40f8[_0x48ac('0x26')][_0x48ac('0x8e')]=_0x48ac('0x31');respondWithRpcPromise(_0x48ac('0x8a'),_0x48ac('0x8a'),{'event':'rejectmessage','message':_0x1f40f8['message']},client9002);return _0x7a03d7;}return null;})['then'](respondWithResult(_0x17cfa7,null))[_0x48ac('0x50')](handleError(_0x17cfa7,null));};exports['download']=function(_0x44468a,_0x13c49f){var _0x3ae583=moment()[_0x48ac('0x8f')]()['toString']();var _0x4790b9=path[_0x48ac('0x90')](config[_0x48ac('0x6d')],_0x48ac('0x91'),'files','tmp');var _0x342b52=path['join'](config[_0x48ac('0x6d')],_0x48ac('0x91'),_0x48ac('0x92'),'attachments');var _0x1734a1=util[_0x48ac('0x7a')]('message-%s.eml',_0x3ae583);return db[_0x48ac('0x53')][_0x48ac('0x55')]({'where':{'id':_0x44468a[_0x48ac('0x52')]['id']},'attributes':['id',_0x48ac('0x57'),_0x48ac('0x93'),'to','cc',_0x48ac('0x94'),_0x48ac('0x95'),'createdAt'],'include':_0x44468a[_0x48ac('0x3a')]['attachments']?[{'model':db[_0x48ac('0x96')],'as':'Attachments'}]:undefined})[_0x48ac('0x32')](handleEntityNotFound(_0x13c49f,null))[_0x48ac('0x32')](function(_0x32861e){if(_0x32861e){var _0x408147=_0x32861e;var _0x5d828e={'from':_0x408147['from'],'to':_0x408147['to'],'subject':_0x408147[_0x48ac('0x95')],'html':_0x408147[_0x48ac('0x57')],'headers':{'Date':moment(_0x408147[_0x48ac('0x97')])[_0x48ac('0x7a')](_0x48ac('0x98'))},'attachments':[]};if(_0x32861e['cc']){_0x5d828e[_0x48ac('0x99')]['Cc']=_0x32861e['cc'];}if(_0x32861e['bcc']){_0x5d828e['headers'][_0x48ac('0x9a')]=_0x32861e[_0x48ac('0x94')];}return new BPromise(function(_0x3c016b,_0x31aed7){if(_0x32861e[_0x48ac('0x9b')]){for(var _0x3cd979=0x0;_0x3cd979<_0x32861e[_0x48ac('0x9b')][_0x48ac('0x41')];_0x3cd979++){var _0x2f4cc2=_0x32861e['Attachments'][_0x3cd979];var _0x584cb4=path[_0x48ac('0x90')](_0x342b52,_0x2f4cc2[_0x48ac('0x6e')]);if(fs['existsSync'](_0x584cb4)){_0x5d828e[_0x48ac('0x6c')][_0x48ac('0x9c')]({'name':_0x2f4cc2['name'],'contentType':_0x2f4cc2[_0x48ac('0x4a')],'data':fs['readFileSync'](_0x584cb4)});}}}emlformat[_0x48ac('0x9d')](_0x5d828e,function(_0x4ddc88,_0x5b8513){if(_0x4ddc88)return _0x31aed7(_0x4ddc88);fs[_0x48ac('0x9e')](path['join'](_0x4790b9,_0x1734a1),_0x5b8513);return _0x3c016b(_0x5b8513);});});}})['then'](function(_0xf69d14){if(_0xf69d14){return _0x13c49f[_0x48ac('0x9f')](path[_0x48ac('0x90')](_0x4790b9,_0x1734a1),_0x1734a1,function(_0x1aeb11){if(_0x1aeb11){console[_0x48ac('0xa0')](_0x48ac('0xa1'),_0x1aeb11);}else{fs[_0x48ac('0xa2')](path[_0x48ac('0x90')](_0x4790b9,_0x1734a1));}});}})[_0x48ac('0x50')](handleError(_0x13c49f,null));};