Built motion from commit c738b9ac.|2.6.25
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 426f536..543a3d0 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-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));};
\ No newline at end of file
+var _0x48ff=['count','set','Content-Range','destroy','end','sendStatus','stack','name','send','index','map','MailMessage','fieldName','type','key','model','query','keys','filters','intersection','fields','attributes','length','nolimit','sort','where','filter','merge','VIRTUAL','options','includeAll','findAll','rows','show','params','rawAttributes','body','find','describe','direction','secret','split','MailAccount','MailAccountId','List','CmContact','updatedAt','DESC','Smtp','getSmtpOptions','attachments','join','root','server/files/attachments','basename','Contacts','create','ListId','List\x20not\x20found','SendMail','sendMail','update','messageId','format','YYYY-MM-DD\x20HH:mm:ss','accept','mail','read','readAt','UserId','user','agent','get','MailInteraction','MailInteractionId','isNil','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','AcceptMessage','acceptMessage','SELECT\x20*\x20FROM\x20cm_contacts\x20WHERE\x20id\x20=\x20','sequelize','Sequelize','QueryTypes','SELECT','User','fullname','email','internal','manual','interface','SIP/%s','channel','motionChannel','fromString','EventManager','reject','role','null','RejectMessage','rejectMessage','ContactId','contact','rejectmessage','unix','toString','files','tmp','server','message-%s.eml','from','bcc','Attachment','decode','ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ','headers','Bcc','Attachments','existsSync','push','readFileSync','build','writeFileSync','download','eml-format','moment','bluebird','lodash','html-to-text','../../components/parsers/qs','api','../../config/logger','../../config/environment','../../mysqldb','redis','defaults','socket.io-emitter','html-entities','./mailMessage.socket','register','client','http','request','then','info','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','MailMessage,\x20%s,\x20%s','message','catch','status','json','offset','undefined','limit'];(function(_0x40b378,_0x5b048c){var _0x636965=function(_0x2232cc){while(--_0x2232cc){_0x40b378['push'](_0x40b378['shift']());}};_0x636965(++_0x5b048c);}(_0x48ff,0x1bb));var _0xf48f=function(_0x23ef2a,_0x19bcd2){_0x23ef2a=_0x23ef2a-0x0;var _0x3eda6f=_0x48ff[_0x23ef2a];return _0x3eda6f;};'use strict';var emlformat=require(_0xf48f('0x0'));var moment=require(_0xf48f('0x1'));var BPromise=require(_0xf48f('0x2'));var util=require('util');var path=require('path');var fs=require('fs');var _=require(_0xf48f('0x3'));var Redis=require('ioredis');var htmlToText=require(_0xf48f('0x4'));var qs=require(_0xf48f('0x5'));var logger=require('../../config/logger')(_0xf48f('0x6'));var interaction_log=require(_0xf48f('0x7'))('mail-interactions');var config=require(_0xf48f('0x8'));var db=require(_0xf48f('0x9'))['db'];config[_0xf48f('0xa')]=_[_0xf48f('0xb')](config[_0xf48f('0xa')],{'host':'localhost','port':0x18eb});var socket=require(_0xf48f('0xc'))(new Redis(config[_0xf48f('0xa')]));var htmlEntities=require(_0xf48f('0xd'));require(_0xf48f('0xe'))[_0xf48f('0xf')](socket);var jayson=require('jayson/promise');var client=jayson[_0xf48f('0x10')][_0xf48f('0x11')]({'port':0x232c});var client9003=jayson[_0xf48f('0x10')][_0xf48f('0x11')]({'port':0x232b});var client9002=jayson['client'][_0xf48f('0x11')]({'port':0x232a});function respondWithRpcPromise(_0x190f5a,_0x163613,_0x292b7e,_0x371b7f){return new BPromise(function(_0x4f5dfd,_0x286997){var _0x155a2d=_0x371b7f||client;return _0x155a2d[_0xf48f('0x12')](_0x190f5a,_0x292b7e)[_0xf48f('0x13')](function(_0x161232){logger[_0xf48f('0x14')]('MailMessage,\x20%s,\x20%s',_0x163613,_0xf48f('0x15'));logger[_0xf48f('0x16')](_0xf48f('0x17'),_0x163613,_0xf48f('0x15'),JSON[_0xf48f('0x18')](_0x161232));if(_0x161232[_0xf48f('0x19')]){if(_0x161232['error']['code']===0x1f4){logger[_0xf48f('0x19')](_0xf48f('0x1a'),_0x163613,_0x161232['error'][_0xf48f('0x1b')]);return _0x286997(_0x161232[_0xf48f('0x19')]['message']);}logger[_0xf48f('0x19')](_0xf48f('0x1a'),_0x163613,_0x161232[_0xf48f('0x19')][_0xf48f('0x1b')]);return _0x4f5dfd(_0x161232['error'][_0xf48f('0x1b')]);}else{logger['info']('MailMessage,\x20%s,\x20%s',_0x163613,'request\x20sent');_0x4f5dfd(_0x161232['result'][_0xf48f('0x1b')]);}})[_0xf48f('0x1c')](function(_0x2e17ea){logger[_0xf48f('0x19')](_0xf48f('0x1a'),_0x163613,_0x2e17ea);_0x286997(_0x2e17ea);});});}function respondWithResult(_0x3932cb,_0x38f7e2){_0x38f7e2=_0x38f7e2||0xc8;return function(_0x4b4e24){if(_0x4b4e24){return _0x3932cb[_0xf48f('0x1d')](_0x38f7e2)[_0xf48f('0x1e')](_0x4b4e24);}};}function respondWithFilteredResult(_0x3f95bb,_0xd58437){return function(_0x357329){if(_0x357329){var _0x1084e8=typeof _0xd58437[_0xf48f('0x1f')]===_0xf48f('0x20')&&typeof _0xd58437[_0xf48f('0x21')]===_0xf48f('0x20');var _0x28ab7f=_0x357329['count'];var _0x12d870=_0x1084e8?0x0:_0xd58437['offset'];var _0xd6dcd2=_0x1084e8?_0x357329[_0xf48f('0x22')]:_0xd58437[_0xf48f('0x1f')]+_0xd58437[_0xf48f('0x21')];var _0xbfc413;if(_0xd6dcd2>=_0x28ab7f){_0xd6dcd2=_0x28ab7f;_0xbfc413=0xc8;}else{_0xbfc413=0xce;}_0x3f95bb[_0xf48f('0x1d')](_0xbfc413);return _0x3f95bb[_0xf48f('0x23')](_0xf48f('0x24'),_0x12d870+'-'+_0xd6dcd2+'/'+_0x28ab7f)[_0xf48f('0x1e')](_0x357329);}return null;};}function saveUpdates(_0x40828c){return function(_0x381df4){if(_0x381df4){return _0x381df4['update'](_0x40828c)[_0xf48f('0x13')](function(_0x5049f1){return _0x5049f1;});}return null;};}function removeEntity(_0x41a35e){return function(_0x52ff8c){if(_0x52ff8c){return _0x52ff8c[_0xf48f('0x25')]()[_0xf48f('0x13')](function(){_0x41a35e[_0xf48f('0x1d')](0xcc)[_0xf48f('0x26')]();});}};}function handleEntityNotFound(_0x507ab7){return function(_0x412f66){if(!_0x412f66){_0x507ab7[_0xf48f('0x27')](0x194);}return _0x412f66;};}function handleError(_0x14cca7,_0x41988e){_0x41988e=_0x41988e||0x1f4;return function(_0x51a521){logger[_0xf48f('0x19')](_0x51a521[_0xf48f('0x28')]);if(_0x51a521[_0xf48f('0x29')]){delete _0x51a521[_0xf48f('0x29')];}_0x14cca7[_0xf48f('0x1d')](_0x41988e)[_0xf48f('0x2a')](_0x51a521);};}exports[_0xf48f('0x2b')]=function(_0x1c8f5e,_0x305d6f){var _0x3ab5da={},_0x40bbb2={},_0x5c490a={'count':0x0,'rows':[]};var _0x31cab5=_[_0xf48f('0x2c')](db[_0xf48f('0x2d')]['rawAttributes'],function(_0x3fd7c9){return{'name':_0x3fd7c9[_0xf48f('0x2e')],'type':_0x3fd7c9[_0xf48f('0x2f')][_0xf48f('0x30')]};});_0x40bbb2[_0xf48f('0x31')]=_[_0xf48f('0x2c')](_0x31cab5,_0xf48f('0x29'));_0x40bbb2[_0xf48f('0x32')]=_[_0xf48f('0x33')](_0x1c8f5e['query']);_0x40bbb2[_0xf48f('0x34')]=_['intersection'](_0x40bbb2[_0xf48f('0x31')],_0x40bbb2[_0xf48f('0x32')]);_0x3ab5da['attributes']=_[_0xf48f('0x35')](_0x40bbb2[_0xf48f('0x31')],qs[_0xf48f('0x36')](_0x1c8f5e[_0xf48f('0x32')]['fields']));_0x3ab5da[_0xf48f('0x37')]=_0x3ab5da['attributes'][_0xf48f('0x38')]?_0x3ab5da['attributes']:_0x40bbb2['model'];if(!_0x1c8f5e[_0xf48f('0x32')]['hasOwnProperty'](_0xf48f('0x39'))){_0x3ab5da['limit']=qs['limit'](_0x1c8f5e[_0xf48f('0x32')][_0xf48f('0x21')]);_0x3ab5da[_0xf48f('0x1f')]=qs[_0xf48f('0x1f')](_0x1c8f5e['query'][_0xf48f('0x1f')]);}_0x3ab5da['order']=qs[_0xf48f('0x3a')](_0x1c8f5e['query']['sort']);_0x3ab5da[_0xf48f('0x3b')]=qs[_0xf48f('0x34')](_['pick'](_0x1c8f5e['query'],_0x40bbb2[_0xf48f('0x34')]),_0x31cab5);if(_0x1c8f5e['query'][_0xf48f('0x3c')]){_0x3ab5da[_0xf48f('0x3b')]=_[_0xf48f('0x3d')](_0x3ab5da[_0xf48f('0x3b')],{'$or':_[_0xf48f('0x2c')](_0x31cab5,function(_0x59c850){if(_0x59c850[_0xf48f('0x2f')]!==_0xf48f('0x3e')){var _0x40325d={};_0x40325d[_0x59c850['name']]={'$like':'%'+_0x1c8f5e[_0xf48f('0x32')][_0xf48f('0x3c')]+'%'};return _0x40325d;}})});}_0x3ab5da=_[_0xf48f('0x3d')]({},_0x3ab5da,_0x1c8f5e[_0xf48f('0x3f')]);var _0x687d88={'where':_0x3ab5da['where']};return db[_0xf48f('0x2d')][_0xf48f('0x22')](_0x687d88)[_0xf48f('0x13')](function(_0x4e91a0){_0x5c490a[_0xf48f('0x22')]=_0x4e91a0;if(_0x1c8f5e[_0xf48f('0x32')][_0xf48f('0x40')]){_0x3ab5da['include']=[{'all':!![]}];}return db[_0xf48f('0x2d')][_0xf48f('0x41')](_0x3ab5da);})[_0xf48f('0x13')](function(_0x5e6003){_0x5c490a[_0xf48f('0x42')]=_0x5e6003;return _0x5c490a;})[_0xf48f('0x13')](respondWithFilteredResult(_0x305d6f,_0x3ab5da))[_0xf48f('0x1c')](handleError(_0x305d6f,null));};exports[_0xf48f('0x43')]=function(_0x840fd1,_0x9b4db9){var _0x2b2016={'raw':!![],'where':{'id':_0x840fd1[_0xf48f('0x44')]['id']}},_0x4cbad1={};_0x4cbad1[_0xf48f('0x31')]=_[_0xf48f('0x33')](db[_0xf48f('0x2d')][_0xf48f('0x45')]);_0x4cbad1[_0xf48f('0x32')]=_[_0xf48f('0x33')](_0x840fd1[_0xf48f('0x32')]);_0x4cbad1[_0xf48f('0x34')]=_[_0xf48f('0x35')](_0x4cbad1[_0xf48f('0x31')],_0x4cbad1[_0xf48f('0x32')]);_0x2b2016[_0xf48f('0x37')]=_['intersection'](_0x4cbad1[_0xf48f('0x31')],qs[_0xf48f('0x36')](_0x840fd1['query']['fields']));_0x2b2016['attributes']=_0x2b2016['attributes']['length']?_0x2b2016[_0xf48f('0x37')]:_0x4cbad1[_0xf48f('0x31')];if(_0x840fd1['query'][_0xf48f('0x40')]){_0x2b2016['include']=[{'all':!![]}];}_0x2b2016=_['merge']({},_0x2b2016,_0x840fd1[_0xf48f('0x3f')]);return db[_0xf48f('0x2d')]['find'](_0x2b2016)[_0xf48f('0x13')](handleEntityNotFound(_0x9b4db9,null))[_0xf48f('0x13')](respondWithResult(_0x9b4db9,null))[_0xf48f('0x1c')](handleError(_0x9b4db9,null));};exports['update']=function(_0x2531e3,_0x37acef){if(_0x2531e3[_0xf48f('0x46')]['id']){delete _0x2531e3['body']['id'];}return db[_0xf48f('0x2d')][_0xf48f('0x47')]({'where':{'id':_0x2531e3[_0xf48f('0x44')]['id']}})[_0xf48f('0x13')](handleEntityNotFound(_0x37acef,null))[_0xf48f('0x13')](saveUpdates(_0x2531e3[_0xf48f('0x46')],null))[_0xf48f('0x13')](respondWithResult(_0x37acef,null))[_0xf48f('0x1c')](handleError(_0x37acef,null));};exports[_0xf48f('0x25')]=function(_0x27591f,_0x22ceef){return db[_0xf48f('0x2d')][_0xf48f('0x47')]({'where':{'id':_0x27591f[_0xf48f('0x44')]['id']}})[_0xf48f('0x13')](handleEntityNotFound(_0x22ceef,null))[_0xf48f('0x13')](removeEntity(_0x22ceef,null))[_0xf48f('0x1c')](handleError(_0x22ceef,null));};exports['describe']=function(_0x119474,_0x24c8c4){return db[_0xf48f('0x2d')][_0xf48f('0x48')]()[_0xf48f('0x13')](respondWithResult(_0x24c8c4,null))[_0xf48f('0x1c')](handleError(_0x24c8c4,null));};exports['create']=function(_0x2a1ed3,_0x2b34f5){return db[_0xf48f('0x2d')]['create'](_0x2a1ed3[_0xf48f('0x46')])['then'](function(_0xde6431){if(_0xde6431){if(_0xde6431[_0xf48f('0x49')]==='out'&&!_0xde6431[_0xf48f('0x4a')]){var _0x5851fa,_0x1e727f,_0x1b4c46;if(_0x2a1ed3[_0xf48f('0x46')]['to']){_0x1e727f=_0x2a1ed3['body']['to'][_0xf48f('0x4b')](',')[0x0];}return db[_0xf48f('0x4c')]['findOne']({'where':{'id':_0xde6431[_0xf48f('0x4d')]},'include':[{'model':db['CmList'],'as':_0xf48f('0x4e'),'include':[{'model':db[_0xf48f('0x4f')],'as':'Contacts','where':{'email':_0x1e727f},'limit':0x1,'order':[[_0xf48f('0x50'),_0xf48f('0x51')]]}]},{'model':db['MailServerOut'],'as':_0xf48f('0x52'),'raw':!![],'include':[{'model':db['CloudProvider'],'as':'CloudProvider','raw':!![]}]}]})['then'](function(_0x26cea1){_0x5851fa=_0x26cea1;if(!_0x5851fa||!_0x5851fa[_0xf48f('0x52')])return;var _0x176985=_0x5851fa[_0xf48f('0x53')]();if(_0x2a1ed3[_0xf48f('0x46')][_0xf48f('0x54')]&&_0x2a1ed3['body']['attachments'][_0xf48f('0x38')]){for(var _0x1ef5a9=0x0;_0x1ef5a9<_0x2a1ed3['body'][_0xf48f('0x54')][_0xf48f('0x38')];_0x1ef5a9+=0x1){_0x2a1ed3['body']['attachments'][_0x1ef5a9]={'filename':_0x2a1ed3[_0xf48f('0x46')][_0xf48f('0x54')][_0x1ef5a9][_0xf48f('0x29')],'path':path[_0xf48f('0x55')](config[_0xf48f('0x56')],_0xf48f('0x57'),_0x2a1ed3[_0xf48f('0x46')][_0xf48f('0x54')][_0x1ef5a9][_0xf48f('0x58')])};}}_0x1b4c46={'account':_0x176985,'message':_0x2a1ed3[_0xf48f('0x46')]};return;})[_0xf48f('0x13')](function(){if(_0x5851fa[_0xf48f('0x4e')]){if(_0x5851fa[_0xf48f('0x4e')][_0xf48f('0x59')][_0xf48f('0x38')]){return _0x5851fa[_0xf48f('0x4e')][_0xf48f('0x59')][0x0];}else{return db['CmContact'][_0xf48f('0x5a')](_['defaults'](_0x2a1ed3['body'],{'firstName':_0x2a1ed3[_0xf48f('0x46')]['to'],'email':_0x2a1ed3[_0xf48f('0x46')]['to'],'phone':_0x2a1ed3[_0xf48f('0x46')]['to'],'ListId':_0x5851fa[_0xf48f('0x5b')]}));}}else{throw new Error(_0xf48f('0x5c'));}})[_0xf48f('0x13')](function(){if(_0x1b4c46){return respondWithRpcPromise(_0xf48f('0x5d'),_0xf48f('0x5e'),_0x1b4c46,client9003)[_0xf48f('0x13')](function(_0x26b560){return _0xde6431[_0xf48f('0x5f')]({'read':!![],'messageId':_0x26b560[_0xf48f('0x60')],'sentAt':moment()[_0xf48f('0x61')](_0xf48f('0x62'))});})[_0xf48f('0x1c')](function(_0xf429eb){logger[_0xf48f('0x19')]('%s',JSON[_0xf48f('0x18')](_0xf429eb));return _0xde6431;});}return _0xde6431;});}return _0xde6431;}})[_0xf48f('0x13')](respondWithResult(_0x2b34f5,0xc9))[_0xf48f('0x1c')](handleError(_0x2b34f5,null));};exports[_0xf48f('0x63')]=function(_0x11306b,_0x5a79bc){var _0x2b5577={'agent':{},'channel':_0xf48f('0x64')};if(_0x11306b['body']['id']){delete _0x11306b[_0xf48f('0x46')]['id'];}_0x11306b[_0xf48f('0x46')][_0xf48f('0x65')]=!![];_0x11306b[_0xf48f('0x46')][_0xf48f('0x66')]=moment()[_0xf48f('0x61')](_0xf48f('0x62'));_0x11306b['body']['UserId']=_0x11306b['body'][_0xf48f('0x67')]||_0x11306b[_0xf48f('0x68')]['id'];_0x2b5577[_0xf48f('0x69')]['id']=_0x11306b[_0xf48f('0x46')][_0xf48f('0x67')];return db[_0xf48f('0x2d')][_0xf48f('0x47')]({'where':{'id':_0x11306b[_0xf48f('0x44')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0x5a79bc,null))['then'](saveUpdates(_0x11306b[_0xf48f('0x46')],null))[_0xf48f('0x13')](function(_0x2f6cf9){if(_0x2f6cf9){_0x2b5577['message']=_0x2f6cf9[_0xf48f('0x6a')]({'plain':!![]});return db[_0xf48f('0x6b')]['find']({'where':{'id':_0x2f6cf9[_0xf48f('0x6c')]}});}return null;})['then'](handleEntityNotFound(_0x5a79bc,null))[_0xf48f('0x13')](function(_0x2f5cb5){if(_0x2f5cb5){return _0x2f5cb5[_0xf48f('0x5f')]({'UserId':_0x11306b['body']['UserId'],'read1stAt':_[_0xf48f('0x6d')](_0x2f5cb5[_0xf48f('0x6e')])?moment()[_0xf48f('0x61')](_0xf48f('0x62')):undefined});}return null;})['then'](function(_0x596f9b){if(_0x596f9b){_0x2b5577[_0xf48f('0x6f')]=_0x596f9b[_0xf48f('0x6a')]({'plain':!![]});interaction_log['info'](_0xf48f('0x70'),_0x11306b[_0xf48f('0x68')]['id'],_0x11306b[_0xf48f('0x68')]['name'],_0x11306b[_0xf48f('0x68')]['role'],_0x2b5577[_0xf48f('0x6f')]['id'],_0x11306b['body']?JSON[_0xf48f('0x18')](_0x11306b['body']):'null');return respondWithRpcPromise(_0xf48f('0x71'),_0xf48f('0x72'),_0x2b5577);}return null;})['then'](function(_0x385537){var _0xca65dd=_0xf48f('0x73')+_0x385537[_0xf48f('0x1b')]['ContactId'];return db[_0xf48f('0x74')][_0xf48f('0x32')](_0xca65dd,{'type':db[_0xf48f('0x75')][_0xf48f('0x76')][_0xf48f('0x77')],'raw':!![]})['then'](function(_0x377d41){return _0x377d41;});})[_0xf48f('0x13')](function(_0x359928){if(_0x359928){_0x2b5577['message']['contact']=_0x359928[0x0];if(!_0x11306b['body']['UserId'])return;return db[_0xf48f('0x78')][_0xf48f('0x47')]({'where':{'id':_0x11306b['body'][_0xf48f('0x67')],'role':'agent'},'attributes':['id','name',_0xf48f('0x79'),_0xf48f('0x7a'),_0xf48f('0x7b')],'raw':!![]});}return null;})[_0xf48f('0x13')](function(_0x4161d9){if(!_0x4161d9)return null;_0x2b5577['message']['agent']=_0x4161d9;return _0x2b5577;})[_0xf48f('0x13')](function(_0x58f0fe){if(_0x58f0fe){if(_0x11306b[_0xf48f('0x46')][_0xf48f('0x7c')]){_0x2b5577['message'][_0xf48f('0x7d')]=util['format'](_0xf48f('0x7e'),_0x11306b['user'][_0xf48f('0x29')]);_0x2b5577['message'][_0xf48f('0x7f')]=_0x2b5577['channel'];_0x2b5577[_0xf48f('0x1b')][_0xf48f('0x80')]=_0x2b5577[_0xf48f('0x7f')];_0x2b5577['message']['event']=_0xf48f('0x63');_0x2b5577[_0xf48f('0x1b')][_0xf48f('0x46')]=htmlToText[_0xf48f('0x81')](_0x2b5577[_0xf48f('0x1b')][_0xf48f('0x46')]);return respondWithRpcPromise(_0xf48f('0x82'),_0xf48f('0x82'),{'event':'acceptmessage','message':_0x2b5577[_0xf48f('0x1b')]},client9002)['then'](function(){return _0x2b5577;});}return _0x2b5577;}return null;})[_0xf48f('0x13')](respondWithResult(_0x5a79bc,null))['catch'](handleError(_0x5a79bc,null));};exports[_0xf48f('0x83')]=function(_0x2656da,_0x3f04ee){var _0x1b3392={'agent':{},'channel':_0xf48f('0x64')};if(_0x2656da[_0xf48f('0x46')]['id']){delete _0x2656da[_0xf48f('0x46')]['id'];}_0x2656da[_0xf48f('0x46')][_0xf48f('0x67')]=_0x2656da[_0xf48f('0x46')][_0xf48f('0x67')]||_0x2656da[_0xf48f('0x68')]['id'];_0x1b3392[_0xf48f('0x69')]['id']=_0x2656da[_0xf48f('0x46')][_0xf48f('0x67')];return db[_0xf48f('0x2d')][_0xf48f('0x47')]({'where':{'id':_0x2656da['params']['id'],'UserId':null}})['then'](handleEntityNotFound(_0x3f04ee,null))[_0xf48f('0x13')](function(_0xc076cd){if(_0xc076cd){_0x1b3392[_0xf48f('0x1b')]=_0xc076cd[_0xf48f('0x6a')]({'plain':!![]});return db['MailInteraction'][_0xf48f('0x47')]({'where':{'id':_0xc076cd[_0xf48f('0x6c')]}});}return null;})[_0xf48f('0x13')](handleEntityNotFound(_0x3f04ee,null))[_0xf48f('0x13')](function(_0x2a48d2){if(_0x2a48d2){_0x1b3392[_0xf48f('0x6f')]=_0x2a48d2['get']({'plain':!![]});interaction_log[_0xf48f('0x14')]('[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s',_0x2656da[_0xf48f('0x68')]['id'],_0x2656da[_0xf48f('0x68')][_0xf48f('0x29')],_0x2656da['user'][_0xf48f('0x84')],_0x1b3392[_0xf48f('0x6f')]['id'],_0x2656da[_0xf48f('0x46')]?JSON[_0xf48f('0x18')](_0x2656da[_0xf48f('0x46')]):_0xf48f('0x85'));return respondWithRpcPromise(_0xf48f('0x86'),_0xf48f('0x87'),_0x1b3392);}return null;})[_0xf48f('0x13')](function(_0x385a24){var _0x4d6288=_0xf48f('0x73')+_0x385a24['message'][_0xf48f('0x88')];return db[_0xf48f('0x74')][_0xf48f('0x32')](_0x4d6288,{'type':db[_0xf48f('0x75')][_0xf48f('0x76')][_0xf48f('0x77')],'raw':!![]})['then'](function(_0x195dc2){return _0x195dc2;});})[_0xf48f('0x13')](function(_0x5a2920){if(_0x5a2920){_0x1b3392[_0xf48f('0x1b')][_0xf48f('0x89')]=_0x5a2920[0x0];if(!_0x2656da[_0xf48f('0x46')][_0xf48f('0x67')])return;return db['User']['find']({'where':{'id':_0x2656da['body'][_0xf48f('0x67')],'role':_0xf48f('0x69')},'attributes':['id',_0xf48f('0x29'),_0xf48f('0x79'),_0xf48f('0x7a'),_0xf48f('0x7b')],'raw':!![]});}return null;})[_0xf48f('0x13')](function(_0x1d2156){if(!_0x1d2156)return null;_0x1b3392[_0xf48f('0x1b')][_0xf48f('0x69')]=_0x1d2156;return _0x1b3392;})['then'](function(_0xa47d91){if(_0xa47d91){_0xa47d91[_0xf48f('0x1b')]['interface']=util[_0xf48f('0x61')](_0xf48f('0x7e'),_0x2656da['user'][_0xf48f('0x29')]);_0xa47d91[_0xf48f('0x1b')]['channel']=_0x1b3392['channel'];_0xa47d91['message'][_0xf48f('0x80')]=_0x1b3392[_0xf48f('0x7f')];_0xa47d91['message']['event']='reject';_0xa47d91['message']['body']=htmlToText['fromString'](_0x1b3392[_0xf48f('0x1b')]['body']);respondWithRpcPromise(_0xf48f('0x82'),_0xf48f('0x82'),{'event':_0xf48f('0x8a'),'message':_0xa47d91['message']},client9002);return _0x1b3392;}return null;})[_0xf48f('0x13')](respondWithResult(_0x3f04ee,null))['catch'](handleError(_0x3f04ee,null));};exports['download']=function(_0x13925e,_0x15ffde){var _0x4a280d=moment()[_0xf48f('0x8b')]()[_0xf48f('0x8c')]();var _0x1899cd=path[_0xf48f('0x55')](config['root'],'server',_0xf48f('0x8d'),_0xf48f('0x8e'));var _0x3fe04a=path[_0xf48f('0x55')](config['root'],_0xf48f('0x8f'),_0xf48f('0x8d'),_0xf48f('0x54'));var _0x2c86e7=util[_0xf48f('0x61')](_0xf48f('0x90'),_0x4a280d);return db[_0xf48f('0x2d')][_0xf48f('0x47')]({'where':{'id':_0x13925e['params']['id']},'attributes':['id','body',_0xf48f('0x91'),'to','cc',_0xf48f('0x92'),'subject','createdAt'],'include':_0x13925e['query'][_0xf48f('0x54')]?[{'model':db[_0xf48f('0x93')],'as':'Attachments'}]:undefined})[_0xf48f('0x13')](handleEntityNotFound(_0x15ffde,null))[_0xf48f('0x13')](function(_0x454301){if(_0x454301){var _0x8fecd1=_0x454301;var _0x3711bb={'from':_0x8fecd1[_0xf48f('0x91')],'to':_0x8fecd1['to'],'subject':_0x8fecd1['subject'],'html':htmlEntities[_0xf48f('0x94')](_0x8fecd1[_0xf48f('0x46')]),'headers':{'Date':moment(_0x8fecd1['createdAt'])['format'](_0xf48f('0x95'))},'attachments':[]};if(_0x454301['cc']){_0x3711bb[_0xf48f('0x96')]['Cc']=_0x454301['cc'];}if(_0x454301['bcc']){_0x3711bb[_0xf48f('0x96')][_0xf48f('0x97')]=_0x454301['bcc'];}return new BPromise(function(_0x1ba0bf,_0x59f198){if(_0x454301['Attachments']){for(var _0x34bcad=0x0;_0x34bcad<_0x454301[_0xf48f('0x98')][_0xf48f('0x38')];_0x34bcad++){var _0x1a51d4=_0x454301[_0xf48f('0x98')][_0x34bcad];var _0x58bbf5=path[_0xf48f('0x55')](_0x3fe04a,_0x1a51d4[_0xf48f('0x58')]);if(fs[_0xf48f('0x99')](_0x58bbf5)){_0x3711bb[_0xf48f('0x54')][_0xf48f('0x9a')]({'name':_0x1a51d4['name'],'contentType':_0x1a51d4['type'],'data':fs[_0xf48f('0x9b')](_0x58bbf5)});}}}emlformat[_0xf48f('0x9c')](_0x3711bb,function(_0x50f2cb,_0xb0cc1f){if(_0x50f2cb)return _0x59f198(_0x50f2cb);fs[_0xf48f('0x9d')](path[_0xf48f('0x55')](_0x1899cd,_0x2c86e7),_0xb0cc1f);return _0x1ba0bf(_0xb0cc1f);});});}})[_0xf48f('0x13')](function(_0x534afc){if(_0x534afc){return _0x15ffde[_0xf48f('0x9e')](path[_0xf48f('0x55')](_0x1899cd,_0x2c86e7),_0x2c86e7,function(_0x427124){if(!_0x427124)fs['unlinkSync'](path[_0xf48f('0x55')](_0x1899cd,_0x2c86e7));});}})[_0xf48f('0x1c')](handleError(_0x15ffde,null));};
\ No newline at end of file