Built motion from commit (unavailable).|2.5.21
[motion2.git] / server / api / mailMessage / mailMessage.controller.js
index 24bd310..473d2c6 100644 (file)
@@ -15,4 +15,4 @@
 // * treaties. The SOFTWARE PRODUCT is licensed, not sold.                        *
 // *                                                                       *
 // *************************************************************************
-var _0x7f19=['../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/logger','api','../../config/utils','../../config/license/util','../../mysqldb','defaults','localhost','socket.io-emitter','redis','./mailMessage.socket','register','jayson/promise','client','http','request','request\x20sent','stringify','error','message','MailMessage,\x20%s,\x20%s','info','result','sendStatus','status','end','json','count','offset','set','Content-Range','apply','reject','destroy','stack','name','send','map','MailMessage','rawAttributes','type','key','model','query','filters','attributes','intersection','fields','length','nolimit','limit','order','sort','where','pick','filter','merge','VIRTUAL','options','then','include','findAll','rows','catch','params','includeAll','find','update','body','describe','create','direction','secret','split','MailAccount','findOne','MailAccountId','CmList','List','CmContact','Contacts','updatedAt','MailServerOut','Smtp','isNil','service','port','secure','authentication','auth','pass','user','attachments','join','server/files/attachments','basename','List\x20not\x20found','SendMail','sendMail','messageId','format','YYYY-MM-DD\x20HH:mm:ss','mail-interactions','accept','mail','read','readAt','UserId','agent','Contact','get','MailInteraction','MailInteractionId','read1stAt','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','interaction','null','manual','interface','channel','event','EventManager','acceptmessage','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','SIP/%s','rejectmessage','unix','toString','server','files','message-%s.eml','from','bcc','subject','Attachment','Attachments','createdAt','headers','Bcc','existsSync','push','readFileSync','build','writeFileSync','log','err','html-pdf','rimraf','zip-dir','request-promise','moment','bluebird','mustache','util','to-csv','ejs','fs-extra','lodash','squel','querystring','papaparse','ioredis'];(function(_0x21f02f,_0x3fa84d){var _0x56cccc=function(_0x4aab2e){while(--_0x4aab2e){_0x21f02f['push'](_0x21f02f['shift']());}};_0x56cccc(++_0x3fa84d);}(_0x7f19,0x96));var _0x97f1=function(_0x3020a5,_0x33a4bc){_0x3020a5=_0x3020a5-0x0;var _0x2ff197=_0x7f19[_0x3020a5];return _0x2ff197;};'use strict';var pdf=require(_0x97f1('0x0'));var emlformat=require('eml-format');var rimraf=require(_0x97f1('0x1'));var zipdir=require(_0x97f1('0x2'));var jsonpatch=require('fast-json-patch');var rp=require(_0x97f1('0x3'));var moment=require(_0x97f1('0x4'));var BPromise=require(_0x97f1('0x5'));var Mustache=require(_0x97f1('0x6'));var util=require(_0x97f1('0x7'));var path=require('path');var sox=require('sox');var csv=require(_0x97f1('0x8'));var ejs=require(_0x97f1('0x9'));var fs=require('fs');var fs_extra=require(_0x97f1('0xa'));var _=require(_0x97f1('0xb'));var squel=require(_0x97f1('0xc'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require('desk.js');var toCsv=require(_0x97f1('0x8'));var querystring=require(_0x97f1('0xd'));var Papa=require(_0x97f1('0xe'));var Redis=require(_0x97f1('0xf'));var authService=require(_0x97f1('0x10'));var qs=require(_0x97f1('0x11'));var as=require(_0x97f1('0x12'));var hardwareService=require('../../config/license/hardware');var logger=require(_0x97f1('0x13'))(_0x97f1('0x14'));var utils=require(_0x97f1('0x15'));var config=require('../../config/environment');var licenseUtil=require(_0x97f1('0x16'));var db=require(_0x97f1('0x17'))['db'];config['redis']=_[_0x97f1('0x18')](config['redis'],{'host':_0x97f1('0x19'),'port':0x18eb});var socket=require(_0x97f1('0x1a'))(new Redis(config[_0x97f1('0x1b')]));require(_0x97f1('0x1c'))[_0x97f1('0x1d')](socket);var jayson=require(_0x97f1('0x1e'));var client=jayson[_0x97f1('0x1f')]['http']({'port':0x232c});var client9003=jayson['client']['http']({'port':0x232b});var client9002=jayson['client'][_0x97f1('0x20')]({'port':0x232a});function respondWithRpcPromise(_0x30269e,_0x52cfc6,_0x67d032,_0x535934){return new BPromise(function(_0x181a6f,_0x10190a){var _0x57a660=_0x535934||client;return _0x57a660[_0x97f1('0x21')](_0x30269e,_0x67d032)['then'](function(_0x4d7c25){logger['info']('MailMessage,\x20%s,\x20%s',_0x52cfc6,_0x97f1('0x22'));logger['debug']('MailMessage,\x20%s,\x20%s,\x20%s',_0x52cfc6,'request\x20sent',JSON[_0x97f1('0x23')](_0x4d7c25));if(_0x4d7c25[_0x97f1('0x24')]){if(_0x4d7c25[_0x97f1('0x24')]['code']===0x1f4){logger['error']('MailMessage,\x20%s,\x20%s',_0x52cfc6,_0x4d7c25[_0x97f1('0x24')][_0x97f1('0x25')]);return _0x10190a(_0x4d7c25[_0x97f1('0x24')][_0x97f1('0x25')]);}logger['error'](_0x97f1('0x26'),_0x52cfc6,_0x4d7c25['error'][_0x97f1('0x25')]);return _0x181a6f(_0x4d7c25['error'][_0x97f1('0x25')]);}else{logger[_0x97f1('0x27')](_0x97f1('0x26'),_0x52cfc6,'request\x20sent');_0x181a6f(_0x4d7c25[_0x97f1('0x28')][_0x97f1('0x25')]);}})['catch'](function(_0x5da36e){logger[_0x97f1('0x24')]('MailMessage,\x20%s,\x20%s',_0x52cfc6,_0x5da36e);_0x10190a(_0x5da36e);});});}function respondWithStatusCode(_0x335aef,_0x412d15){_0x412d15=_0x412d15||0xcc;return function(_0x178671){if(_0x178671){return _0x335aef[_0x97f1('0x29')](_0x412d15);}return _0x335aef[_0x97f1('0x2a')](_0x412d15)[_0x97f1('0x2b')]();};}function respondWithResult(_0x5f3d64,_0x147084){_0x147084=_0x147084||0xc8;return function(_0x473c52){if(_0x473c52){return _0x5f3d64[_0x97f1('0x2a')](_0x147084)[_0x97f1('0x2c')](_0x473c52);}};}function respondWithFilteredResult(_0x39b9eb,_0x273527){return function(_0x4b5c77){if(_0x4b5c77){var _0xe6e3e3=_0x4b5c77[_0x97f1('0x2d')],_0x1cae64=_0x273527[_0x97f1('0x2e')],_0xe1c02c=_0x273527[_0x97f1('0x2e')]+_0x273527['limit'],_0x5eb1c4;if(_0xe1c02c>=_0xe6e3e3){_0xe1c02c=_0xe6e3e3;_0x5eb1c4=0xc8;}else{_0x5eb1c4=0xce;}_0x39b9eb[_0x97f1('0x2a')](_0x5eb1c4);return _0x39b9eb[_0x97f1('0x2f')](_0x97f1('0x30'),_0x1cae64+'-'+_0xe1c02c+'/'+_0xe6e3e3)[_0x97f1('0x2c')](_0x4b5c77);}return null;};}function patchUpdates(_0x8d209c){return function(_0x1bf43b){try{jsonpatch[_0x97f1('0x31')](_0x1bf43b,_0x8d209c,!![]);}catch(_0x56d779){return BPromise[_0x97f1('0x32')](_0x56d779);}return _0x1bf43b['save']();};}function saveUpdates(_0x3e61ea,_0x5558d0){return function(_0x4db260){if(_0x4db260){return _0x4db260['update'](_0x3e61ea)['then'](function(_0x1b22cd){return _0x1b22cd;});}return null;};}function removeEntity(_0x4c6394,_0x21e84f){return function(_0x1e88b3){if(_0x1e88b3){return _0x1e88b3[_0x97f1('0x33')]()['then'](function(){_0x4c6394[_0x97f1('0x2a')](0xcc)[_0x97f1('0x2b')]();});}};}function handleEntityNotFound(_0x383d84,_0x402c14){return function(_0x5d20da){if(!_0x5d20da){_0x383d84[_0x97f1('0x29')](0x194);}return _0x5d20da;};}function handleError(_0xebb59d,_0x148824){_0x148824=_0x148824||0x1f4;return function(_0x171f39){logger[_0x97f1('0x24')](_0x171f39[_0x97f1('0x34')]);if(_0x171f39[_0x97f1('0x35')]){delete _0x171f39[_0x97f1('0x35')];}_0xebb59d[_0x97f1('0x2a')](_0x148824)[_0x97f1('0x36')](_0x171f39);};}exports['index']=function(_0xe501b1,_0x4ba50f){var _0x38559c={},_0x89b4f4={},_0x2c5b84={'count':0x0,'rows':[]};var _0x51bdfa=_[_0x97f1('0x37')](db[_0x97f1('0x38')][_0x97f1('0x39')],function(_0x51faba){return{'name':_0x51faba['fieldName'],'type':_0x51faba[_0x97f1('0x3a')][_0x97f1('0x3b')]};});_0x89b4f4[_0x97f1('0x3c')]=_[_0x97f1('0x37')](_0x51bdfa,'name');_0x89b4f4[_0x97f1('0x3d')]=_['keys'](_0xe501b1[_0x97f1('0x3d')]);_0x89b4f4[_0x97f1('0x3e')]=_['intersection'](_0x89b4f4[_0x97f1('0x3c')],_0x89b4f4['query']);_0x38559c[_0x97f1('0x3f')]=_[_0x97f1('0x40')](_0x89b4f4[_0x97f1('0x3c')],qs['fields'](_0xe501b1['query'][_0x97f1('0x41')]));_0x38559c[_0x97f1('0x3f')]=_0x38559c[_0x97f1('0x3f')][_0x97f1('0x42')]?_0x38559c[_0x97f1('0x3f')]:_0x89b4f4[_0x97f1('0x3c')];if(!_0xe501b1[_0x97f1('0x3d')]['hasOwnProperty'](_0x97f1('0x43'))){_0x38559c[_0x97f1('0x44')]=qs[_0x97f1('0x44')](_0xe501b1[_0x97f1('0x3d')][_0x97f1('0x44')]);_0x38559c[_0x97f1('0x2e')]=qs[_0x97f1('0x2e')](_0xe501b1[_0x97f1('0x3d')]['offset']);}_0x38559c[_0x97f1('0x45')]=qs[_0x97f1('0x46')](_0xe501b1[_0x97f1('0x3d')][_0x97f1('0x46')]);_0x38559c[_0x97f1('0x47')]=qs[_0x97f1('0x3e')](_[_0x97f1('0x48')](_0xe501b1[_0x97f1('0x3d')],_0x89b4f4[_0x97f1('0x3e')]),_0x51bdfa);if(_0xe501b1[_0x97f1('0x3d')][_0x97f1('0x49')]){_0x38559c[_0x97f1('0x47')]=_[_0x97f1('0x4a')](_0x38559c[_0x97f1('0x47')],{'$or':_[_0x97f1('0x37')](_0x51bdfa,function(_0x4fdecd){if(_0x4fdecd['type']!==_0x97f1('0x4b')){var _0xee5fab={};_0xee5fab[_0x4fdecd[_0x97f1('0x35')]]={'$like':'%'+_0xe501b1[_0x97f1('0x3d')]['filter']+'%'};return _0xee5fab;}})});}_0x38559c=_['merge']({},_0x38559c,_0xe501b1[_0x97f1('0x4c')]);var _0x15b80b={'where':_0x38559c[_0x97f1('0x47')]};return db[_0x97f1('0x38')][_0x97f1('0x2d')](_0x15b80b)[_0x97f1('0x4d')](function(_0xe03c24){_0x2c5b84[_0x97f1('0x2d')]=_0xe03c24;if(_0xe501b1['query']['includeAll']){_0x38559c[_0x97f1('0x4e')]=[{'all':!![]}];}return db[_0x97f1('0x38')][_0x97f1('0x4f')](_0x38559c);})[_0x97f1('0x4d')](function(_0x3dc041){_0x2c5b84[_0x97f1('0x50')]=_0x3dc041;return _0x2c5b84;})[_0x97f1('0x4d')](respondWithFilteredResult(_0x4ba50f,_0x38559c))[_0x97f1('0x51')](handleError(_0x4ba50f,null));};exports['show']=function(_0x11d235,_0x224558){var _0x2f343c={'raw':!![],'where':{'id':_0x11d235[_0x97f1('0x52')]['id']}},_0x7a9419={};_0x7a9419['model']=_['keys'](db[_0x97f1('0x38')][_0x97f1('0x39')]);_0x7a9419[_0x97f1('0x3d')]=_['keys'](_0x11d235[_0x97f1('0x3d')]);_0x7a9419[_0x97f1('0x3e')]=_['intersection'](_0x7a9419[_0x97f1('0x3c')],_0x7a9419[_0x97f1('0x3d')]);_0x2f343c[_0x97f1('0x3f')]=_[_0x97f1('0x40')](_0x7a9419[_0x97f1('0x3c')],qs[_0x97f1('0x41')](_0x11d235[_0x97f1('0x3d')][_0x97f1('0x41')]));_0x2f343c[_0x97f1('0x3f')]=_0x2f343c[_0x97f1('0x3f')][_0x97f1('0x42')]?_0x2f343c[_0x97f1('0x3f')]:_0x7a9419[_0x97f1('0x3c')];if(_0x11d235[_0x97f1('0x3d')][_0x97f1('0x53')]){_0x2f343c[_0x97f1('0x4e')]=[{'all':!![]}];}_0x2f343c=_['merge']({},_0x2f343c,_0x11d235['options']);return db[_0x97f1('0x38')][_0x97f1('0x54')](_0x2f343c)[_0x97f1('0x4d')](handleEntityNotFound(_0x224558,null))['then'](respondWithResult(_0x224558,null))[_0x97f1('0x51')](handleError(_0x224558,null));};exports[_0x97f1('0x55')]=function(_0x5d3dd6,_0x29734c){if(_0x5d3dd6[_0x97f1('0x56')]['id']){delete _0x5d3dd6[_0x97f1('0x56')]['id'];}return db[_0x97f1('0x38')][_0x97f1('0x54')]({'where':{'id':_0x5d3dd6[_0x97f1('0x52')]['id']}})['then'](handleEntityNotFound(_0x29734c,null))[_0x97f1('0x4d')](saveUpdates(_0x5d3dd6[_0x97f1('0x56')],null))[_0x97f1('0x4d')](respondWithResult(_0x29734c,null))[_0x97f1('0x51')](handleError(_0x29734c,null));};exports['destroy']=function(_0x3953cd,_0x37e671){return db[_0x97f1('0x38')][_0x97f1('0x54')]({'where':{'id':_0x3953cd['params']['id']}})[_0x97f1('0x4d')](handleEntityNotFound(_0x37e671,null))[_0x97f1('0x4d')](removeEntity(_0x37e671,null))[_0x97f1('0x51')](handleError(_0x37e671,null));};exports[_0x97f1('0x57')]=function(_0x59d179,_0xc61a60){return db[_0x97f1('0x38')]['describe']()[_0x97f1('0x4d')](respondWithResult(_0xc61a60,null))['catch'](handleError(_0xc61a60,null));};exports[_0x97f1('0x58')]=function(_0xc6ee87,_0x17ff6f){return db['MailMessage'][_0x97f1('0x58')](_0xc6ee87[_0x97f1('0x56')])[_0x97f1('0x4d')](function(_0x215223){if(_0x215223){if(_0x215223[_0x97f1('0x59')]==='out'&&!_0x215223[_0x97f1('0x5a')]){var _0x426209,_0x414818,_0x35bdfd;if(_0xc6ee87[_0x97f1('0x56')]['to']){_0x414818=_0xc6ee87['body']['to'][_0x97f1('0x5b')](',')[0x0];}return db[_0x97f1('0x5c')][_0x97f1('0x5d')]({'where':{'id':_0x215223[_0x97f1('0x5e')]},'include':[{'model':db[_0x97f1('0x5f')],'as':_0x97f1('0x60'),'include':[{'model':db[_0x97f1('0x61')],'as':_0x97f1('0x62'),'where':{'email':_0x414818},'limit':0x1,'order':[[_0x97f1('0x63'),'DESC']]}]},{'model':db[_0x97f1('0x64')],'as':_0x97f1('0x65'),'raw':!![]}]})[_0x97f1('0x4d')](function(_0x495e1a){_0x426209=_0x495e1a;if(_0x426209&&_0x426209[_0x97f1('0x65')]){var _0x46f4ff={'tls':{'rejectUnauthorized':![]}};if(_[_0x97f1('0x66')](_0x426209[_0x97f1('0x65')][_0x97f1('0x67')])){_0x46f4ff['host']=_0x426209['Smtp']['host'];_0x46f4ff['port']=_0x426209['Smtp'][_0x97f1('0x68')];_0x46f4ff[_0x97f1('0x69')]=_0x426209[_0x97f1('0x65')][_0x97f1('0x69')];if(_0x426209[_0x97f1('0x65')][_0x97f1('0x6a')]){_0x46f4ff[_0x97f1('0x6b')]={'user':_0x426209[_0x97f1('0x65')]['user'],'pass':_0x426209[_0x97f1('0x65')][_0x97f1('0x6c')]};}}else{_0x46f4ff[_0x97f1('0x67')]=_0x426209['Smtp'][_0x97f1('0x67')];_0x46f4ff['auth']={'user':_0x426209['Smtp'][_0x97f1('0x6d')],'pass':_0x426209[_0x97f1('0x65')][_0x97f1('0x6c')]};_0x46f4ff[_0x97f1('0x69')]=_0x426209[_0x97f1('0x65')][_0x97f1('0x69')];}if(_0xc6ee87[_0x97f1('0x56')][_0x97f1('0x6e')]&&_0xc6ee87['body'][_0x97f1('0x6e')]['length']){for(var _0x13366e=0x0;_0x13366e<_0xc6ee87[_0x97f1('0x56')]['attachments'][_0x97f1('0x42')];_0x13366e+=0x1){_0xc6ee87[_0x97f1('0x56')]['attachments'][_0x13366e]={'filename':_0xc6ee87[_0x97f1('0x56')][_0x97f1('0x6e')][_0x13366e][_0x97f1('0x35')],'path':path[_0x97f1('0x6f')](config['root'],_0x97f1('0x70'),_0xc6ee87[_0x97f1('0x56')][_0x97f1('0x6e')][_0x13366e][_0x97f1('0x71')])};}}_0x35bdfd={'account':_0x46f4ff,'message':_0xc6ee87[_0x97f1('0x56')]};return;}})['then'](function(){if(_0x426209['List']){if(_0x426209[_0x97f1('0x60')][_0x97f1('0x62')][_0x97f1('0x42')]){return _0x426209[_0x97f1('0x60')]['Contacts'][0x0];}else{return db[_0x97f1('0x61')][_0x97f1('0x58')](_[_0x97f1('0x18')](_0xc6ee87[_0x97f1('0x56')],{'firstName':_0xc6ee87[_0x97f1('0x56')]['to'],'email':_0xc6ee87[_0x97f1('0x56')]['to'],'phone':_0xc6ee87[_0x97f1('0x56')]['to'],'ListId':_0x426209['ListId']}));}}else{throw new Error(_0x97f1('0x72'));}})['then'](function(){if(_0x35bdfd){return respondWithRpcPromise(_0x97f1('0x73'),_0x97f1('0x74'),_0x35bdfd,client9003)[_0x97f1('0x4d')](function(_0x4fabff){return _0x215223['update']({'read':!![],'messageId':_0x4fabff[_0x97f1('0x75')],'sentAt':moment()[_0x97f1('0x76')](_0x97f1('0x77'))});})[_0x97f1('0x51')](function(_0x5cdcb7){logger[_0x97f1('0x24')]('%s',JSON[_0x97f1('0x23')](_0x5cdcb7));return _0x215223;});}return _0x215223;});}return _0x215223;}})[_0x97f1('0x4d')](respondWithResult(_0x17ff6f,0xc9))[_0x97f1('0x51')](handleError(_0x17ff6f,null));};var interaction_log=require(_0x97f1('0x13'))(_0x97f1('0x78'));exports[_0x97f1('0x79')]=function(_0x448aca,_0x111eae,_0x2f0b26){var _0x2cc472={'agent':{},'channel':_0x97f1('0x7a')};if(_0x448aca[_0x97f1('0x56')]['id']){delete _0x448aca['body']['id'];}_0x448aca[_0x97f1('0x56')][_0x97f1('0x7b')]=!![];_0x448aca[_0x97f1('0x56')][_0x97f1('0x7c')]=moment()['format']('YYYY-MM-DD\x20HH:mm:ss');_0x448aca[_0x97f1('0x56')][_0x97f1('0x7d')]=_0x448aca['body'][_0x97f1('0x7d')]||_0x448aca[_0x97f1('0x6d')]['id'];_0x2cc472[_0x97f1('0x7e')]['id']=_0x448aca[_0x97f1('0x56')][_0x97f1('0x7d')];return db['MailMessage'][_0x97f1('0x54')]({'where':{'id':_0x448aca[_0x97f1('0x52')]['id'],'UserId':null},'include':[{'model':db[_0x97f1('0x61')],'as':_0x97f1('0x7f')}]})[_0x97f1('0x4d')](handleEntityNotFound(_0x111eae,null))['then'](saveUpdates(_0x448aca[_0x97f1('0x56')],null))[_0x97f1('0x4d')](function(_0x49bbb3){if(_0x49bbb3){_0x2cc472[_0x97f1('0x25')]=_0x49bbb3[_0x97f1('0x80')]({'plain':!![]});return db[_0x97f1('0x81')][_0x97f1('0x54')]({'where':{'id':_0x49bbb3[_0x97f1('0x82')]}});}return null;})['then'](handleEntityNotFound(_0x111eae,null))[_0x97f1('0x4d')](function(_0xacdb9a){if(_0xacdb9a){return _0xacdb9a[_0x97f1('0x55')]({'UserId':_0x448aca['body'][_0x97f1('0x7d')],'read1stAt':_[_0x97f1('0x66')](_0xacdb9a[_0x97f1('0x83')])?moment()[_0x97f1('0x76')](_0x97f1('0x77')):undefined});}return null;})[_0x97f1('0x4d')](function(_0x21ced0){if(_0x21ced0){_0x2cc472['interaction']=_0x21ced0[_0x97f1('0x80')]({'plain':!![]});interaction_log['info'](_0x97f1('0x84'),_0x448aca[_0x97f1('0x6d')]['id'],_0x448aca[_0x97f1('0x6d')][_0x97f1('0x35')],_0x448aca[_0x97f1('0x6d')][_0x97f1('0x85')],_0x2cc472[_0x97f1('0x86')]['id'],_0x448aca[_0x97f1('0x56')]?JSON['stringify'](_0x448aca['body']):_0x97f1('0x87'));return respondWithRpcPromise('AcceptMessage','acceptMessage',_0x2cc472);}return null;})['then'](function(_0x441c71){if(_0x441c71){if(_0x448aca[_0x97f1('0x56')][_0x97f1('0x88')]){_0x2cc472['message'][_0x97f1('0x89')]=util['format']('SIP/%s',_0x448aca[_0x97f1('0x6d')][_0x97f1('0x35')]);_0x2cc472[_0x97f1('0x25')][_0x97f1('0x8a')]=_0x2cc472[_0x97f1('0x8a')];_0x2cc472[_0x97f1('0x25')][_0x97f1('0x8b')]=_0x97f1('0x79');return respondWithRpcPromise('EventManager',_0x97f1('0x8c'),{'event':_0x97f1('0x8d'),'message':_0x2cc472[_0x97f1('0x25')]},client9002)[_0x97f1('0x4d')](function(){return _0x2cc472;});}return _0x2cc472;}return null;})[_0x97f1('0x4d')](respondWithResult(_0x111eae,null))[_0x97f1('0x51')](handleError(_0x111eae,null));};var interaction_log=require(_0x97f1('0x13'))('mail-interactions');exports['reject']=function(_0x2ac300,_0x1d0a3f,_0x2368b4){var _0x121bdc={'agent':{},'channel':_0x97f1('0x7a')};if(_0x2ac300[_0x97f1('0x56')]['id']){delete _0x2ac300['body']['id'];}_0x2ac300[_0x97f1('0x56')]['UserId']=_0x2ac300['body'][_0x97f1('0x7d')]||_0x2ac300['user']['id'];_0x121bdc[_0x97f1('0x7e')]['id']=_0x2ac300[_0x97f1('0x56')][_0x97f1('0x7d')];return db[_0x97f1('0x38')][_0x97f1('0x54')]({'where':{'id':_0x2ac300[_0x97f1('0x52')]['id'],'UserId':null}})[_0x97f1('0x4d')](handleEntityNotFound(_0x1d0a3f,null))['then'](function(_0x58017d){if(_0x58017d){_0x121bdc[_0x97f1('0x25')]=_0x58017d['get']({'plain':!![]});return db[_0x97f1('0x81')]['find']({'where':{'id':_0x58017d[_0x97f1('0x82')]}});}return null;})[_0x97f1('0x4d')](handleEntityNotFound(_0x1d0a3f,null))['then'](function(_0x1d54ed){if(_0x1d54ed){_0x121bdc[_0x97f1('0x86')]=_0x1d54ed['get']({'plain':!![]});interaction_log[_0x97f1('0x27')](_0x97f1('0x8e'),_0x2ac300[_0x97f1('0x6d')]['id'],_0x2ac300['user'][_0x97f1('0x35')],_0x2ac300[_0x97f1('0x6d')][_0x97f1('0x85')],_0x121bdc[_0x97f1('0x86')]['id'],_0x2ac300['body']?JSON[_0x97f1('0x23')](_0x2ac300[_0x97f1('0x56')]):_0x97f1('0x87'));return respondWithRpcPromise(_0x97f1('0x8f'),'rejectMessage',_0x121bdc);}return null;})[_0x97f1('0x4d')](function(_0x459f67){if(_0x459f67){_0x459f67['message']['interface']=util[_0x97f1('0x76')](_0x97f1('0x90'),_0x2ac300[_0x97f1('0x6d')]['name']);_0x459f67[_0x97f1('0x25')][_0x97f1('0x8a')]=_0x121bdc[_0x97f1('0x8a')];_0x459f67[_0x97f1('0x25')][_0x97f1('0x8b')]=_0x97f1('0x32');respondWithRpcPromise(_0x97f1('0x8c'),_0x97f1('0x8c'),{'event':_0x97f1('0x91'),'message':_0x459f67[_0x97f1('0x25')]},client9002);return _0x121bdc;}return null;})[_0x97f1('0x4d')](respondWithResult(_0x1d0a3f,null))[_0x97f1('0x51')](handleError(_0x1d0a3f,null));};exports['download']=function(_0x5ca012,_0x51fcf5){var _0x3cc032=moment()[_0x97f1('0x92')]()[_0x97f1('0x93')]();var _0x298bf7=path[_0x97f1('0x6f')](config['root'],_0x97f1('0x94'),_0x97f1('0x95'),'tmp');var _0x30846c=path[_0x97f1('0x6f')](config['root'],_0x97f1('0x94'),'files',_0x97f1('0x6e'));var _0x201ef5=util['format'](_0x97f1('0x96'),_0x3cc032);return db[_0x97f1('0x38')][_0x97f1('0x54')]({'where':{'id':_0x5ca012[_0x97f1('0x52')]['id']},'attributes':['id',_0x97f1('0x56'),_0x97f1('0x97'),'to','cc',_0x97f1('0x98'),_0x97f1('0x99'),'createdAt'],'include':_0x5ca012['query'][_0x97f1('0x6e')]?[{'model':db[_0x97f1('0x9a')],'as':_0x97f1('0x9b')}]:undefined})[_0x97f1('0x4d')](handleEntityNotFound(_0x51fcf5,null))[_0x97f1('0x4d')](function(_0x235c53){if(_0x235c53){var _0x537037=_0x235c53;var _0x315f07={'from':_0x537037[_0x97f1('0x97')],'to':_0x537037['to'],'subject':_0x537037['subject'],'html':_0x537037[_0x97f1('0x56')],'headers':{'Date':moment(_0x537037[_0x97f1('0x9c')])['format']('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x235c53['cc']){_0x315f07[_0x97f1('0x9d')]['Cc']=_0x235c53['cc'];}if(_0x235c53['bcc']){_0x315f07['headers'][_0x97f1('0x9e')]=_0x235c53[_0x97f1('0x98')];}return new BPromise(function(_0x5d0f8d,_0x3e6d26){if(_0x235c53[_0x97f1('0x9b')]){for(var _0x122725=0x0;_0x122725<_0x235c53['Attachments'][_0x97f1('0x42')];_0x122725++){var _0x81ee85=_0x235c53['Attachments'][_0x122725];var _0x1b4238=path[_0x97f1('0x6f')](_0x30846c,_0x81ee85['basename']);if(fs[_0x97f1('0x9f')](_0x1b4238)){_0x315f07[_0x97f1('0x6e')][_0x97f1('0xa0')]({'name':_0x81ee85[_0x97f1('0x35')],'contentType':_0x81ee85[_0x97f1('0x3a')],'data':fs[_0x97f1('0xa1')](_0x1b4238)});}}}emlformat[_0x97f1('0xa2')](_0x315f07,function(_0x4b0879,_0x5eb0f0){if(_0x4b0879)return _0x3e6d26(_0x4b0879);fs[_0x97f1('0xa3')](path['join'](_0x298bf7,_0x201ef5),_0x5eb0f0);return _0x5d0f8d(_0x5eb0f0);});});}})[_0x97f1('0x4d')](function(_0x53a8d6){if(_0x53a8d6){return _0x51fcf5['download'](path[_0x97f1('0x6f')](_0x298bf7,_0x201ef5),_0x201ef5,function(_0xbe16a5){if(_0xbe16a5){console[_0x97f1('0xa4')](_0x97f1('0xa5'),_0xbe16a5);}else{fs['unlinkSync'](path[_0x97f1('0x6f')](_0x298bf7,_0x201ef5));}});}})[_0x97f1('0x51')](handleError(_0x51fcf5,null));};
\ No newline at end of file
+var _0xa9e0=['sendStatus','end','status','json','count','offset','limit','set','Content-Range','apply','save','update','destroy','stack','name','send','index','map','MailMessage','fieldName','type','model','query','filters','attributes','intersection','fields','length','hasOwnProperty','nolimit','order','sort','pick','filter','where','merge','VIRTUAL','options','includeAll','findAll','rows','catch','params','keys','rawAttributes','body','find','describe','create','out','secret','findOne','CmList','List','CmContact','Contacts','updatedAt','DESC','Smtp','service','host','port','secure','authentication','user','auth','pass','attachments','root','server/files/attachments','basename','ListId','List\x20not\x20found','sendMail','format','YYYY-MM-DD\x20HH:mm:ss','../../config/logger','accept','mail','read','readAt','UserId','Contact','get','MailInteractionId','isNil','read1stAt','interaction','[MAILMESSAGE:ACCEPT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','role','null','AcceptMessage','acceptMessage','interface','channel','event','EventManager','acceptmessage','mail-interactions','reject','MailInteraction','[MAILMESSAGE:REJECT]\x20id=%s\x20name=%s\x20role=%s\x20interaction=%s\x20body=%s','RejectMessage','rejectMessage','rejectmessage','download','unix','toString','join','server','files','tmp','from','createdAt','Attachment','Attachments','bcc','headers','push','readFileSync','build','writeFileSync','log','err','unlinkSync','html-pdf','eml-format','rimraf','request-promise','bluebird','mustache','util','path','sox','ejs','lodash','squel','desk.js','papaparse','ioredis','../../components/auth/service','../../components/parsers/qs','../../components/parsers/advancedSearch','../../config/license/hardware','../../config/license/util','../../mysqldb','redis','defaults','localhost','./mailMessage.socket','register','jayson/promise','client','http','request','then','info','MailMessage,\x20%s,\x20%s','request\x20sent','debug','MailMessage,\x20%s,\x20%s,\x20%s','stringify','error','code','message','result'];(function(_0x2d5afc,_0x3252e1){var _0x1c79d7=function(_0x3296c9){while(--_0x3296c9){_0x2d5afc['push'](_0x2d5afc['shift']());}};_0x1c79d7(++_0x3252e1);}(_0xa9e0,0x123));var _0x0a9e=function(_0x134c2e,_0x3573c4){_0x134c2e=_0x134c2e-0x0;var _0x2825db=_0xa9e0[_0x134c2e];return _0x2825db;};'use strict';var pdf=require(_0x0a9e('0x0'));var emlformat=require(_0x0a9e('0x1'));var rimraf=require(_0x0a9e('0x2'));var zipdir=require('zip-dir');var jsonpatch=require('fast-json-patch');var rp=require(_0x0a9e('0x3'));var moment=require('moment');var BPromise=require(_0x0a9e('0x4'));var Mustache=require(_0x0a9e('0x5'));var util=require(_0x0a9e('0x6'));var path=require(_0x0a9e('0x7'));var sox=require(_0x0a9e('0x8'));var csv=require('to-csv');var ejs=require(_0x0a9e('0x9'));var fs=require('fs');var _=require(_0x0a9e('0xa'));var squel=require(_0x0a9e('0xb'));var crypto=require('crypto');var jsforce=require('jsforce');var deskjs=require(_0x0a9e('0xc'));var toCsv=require('to-csv');var querystring=require('querystring');var Papa=require(_0x0a9e('0xd'));var Redis=require(_0x0a9e('0xe'));var authService=require(_0x0a9e('0xf'));var qs=require(_0x0a9e('0x10'));var as=require(_0x0a9e('0x11'));var hardwareService=require(_0x0a9e('0x12'));var logger=require('../../config/logger')('api');var utils=require('../../config/utils');var config=require('../../config/environment');var licenseUtil=require(_0x0a9e('0x13'));var db=require(_0x0a9e('0x14'))['db'];config[_0x0a9e('0x15')]=_[_0x0a9e('0x16')](config[_0x0a9e('0x15')],{'host':_0x0a9e('0x17'),'port':0x18eb});var socket=require('socket.io-emitter')(new Redis(config[_0x0a9e('0x15')]));require(_0x0a9e('0x18'))[_0x0a9e('0x19')](socket);var jayson=require(_0x0a9e('0x1a'));var client=jayson[_0x0a9e('0x1b')][_0x0a9e('0x1c')]({'port':0x232c});var client9003=jayson['client'][_0x0a9e('0x1c')]({'port':0x232b});var client9002=jayson['client'][_0x0a9e('0x1c')]({'port':0x232a});function respondWithRpcPromise(_0x519dfd,_0x16033c,_0x12066b,_0x48f32d){return new BPromise(function(_0x225616,_0x5a0a06){var _0x459eb1=_0x48f32d||client;return _0x459eb1[_0x0a9e('0x1d')](_0x519dfd,_0x12066b)[_0x0a9e('0x1e')](function(_0x205fd6){logger[_0x0a9e('0x1f')](_0x0a9e('0x20'),_0x16033c,_0x0a9e('0x21'));logger[_0x0a9e('0x22')](_0x0a9e('0x23'),_0x16033c,_0x0a9e('0x21'),JSON[_0x0a9e('0x24')](_0x205fd6));if(_0x205fd6[_0x0a9e('0x25')]){if(_0x205fd6['error'][_0x0a9e('0x26')]===0x1f4){logger[_0x0a9e('0x25')]('MailMessage,\x20%s,\x20%s',_0x16033c,_0x205fd6[_0x0a9e('0x25')]['message']);return _0x5a0a06(_0x205fd6['error'][_0x0a9e('0x27')]);}logger[_0x0a9e('0x25')](_0x0a9e('0x20'),_0x16033c,_0x205fd6[_0x0a9e('0x25')]['message']);return _0x225616(_0x205fd6[_0x0a9e('0x25')][_0x0a9e('0x27')]);}else{logger[_0x0a9e('0x1f')](_0x0a9e('0x20'),_0x16033c,_0x0a9e('0x21'));_0x225616(_0x205fd6[_0x0a9e('0x28')][_0x0a9e('0x27')]);}})['catch'](function(_0x59181e){logger[_0x0a9e('0x25')](_0x0a9e('0x20'),_0x16033c,_0x59181e);_0x5a0a06(_0x59181e);});});}function respondWithStatusCode(_0x40c424,_0x33161b){_0x33161b=_0x33161b||0xcc;return function(_0x526cf3){if(_0x526cf3){return _0x40c424[_0x0a9e('0x29')](_0x33161b);}return _0x40c424['status'](_0x33161b)[_0x0a9e('0x2a')]();};}function respondWithResult(_0x5bfb33,_0x1dc186){_0x1dc186=_0x1dc186||0xc8;return function(_0x34dc65){if(_0x34dc65){return _0x5bfb33[_0x0a9e('0x2b')](_0x1dc186)[_0x0a9e('0x2c')](_0x34dc65);}};}function respondWithFilteredResult(_0x140511,_0x1538a4){return function(_0x11c3b6){if(_0x11c3b6){var _0x14de77=_0x11c3b6[_0x0a9e('0x2d')],_0x5a101a=_0x1538a4[_0x0a9e('0x2e')],_0x3652a7=_0x1538a4['offset']+_0x1538a4[_0x0a9e('0x2f')],_0x468813;if(_0x3652a7>=_0x14de77){_0x3652a7=_0x14de77;_0x468813=0xc8;}else{_0x468813=0xce;}_0x140511[_0x0a9e('0x2b')](_0x468813);return _0x140511[_0x0a9e('0x30')](_0x0a9e('0x31'),_0x5a101a+'-'+_0x3652a7+'/'+_0x14de77)[_0x0a9e('0x2c')](_0x11c3b6);}return null;};}function patchUpdates(_0x563b45){return function(_0x296f41){try{jsonpatch[_0x0a9e('0x32')](_0x296f41,_0x563b45,!![]);}catch(_0x1dbde2){return BPromise['reject'](_0x1dbde2);}return _0x296f41[_0x0a9e('0x33')]();};}function saveUpdates(_0x5d1e0e,_0x2407f9){return function(_0x3ae878){if(_0x3ae878){return _0x3ae878[_0x0a9e('0x34')](_0x5d1e0e)[_0x0a9e('0x1e')](function(_0x25ce3a){return _0x25ce3a;});}return null;};}function removeEntity(_0x5180f1,_0x66c1d2){return function(_0x46f0a5){if(_0x46f0a5){return _0x46f0a5[_0x0a9e('0x35')]()[_0x0a9e('0x1e')](function(){_0x5180f1[_0x0a9e('0x2b')](0xcc)[_0x0a9e('0x2a')]();});}};}function handleEntityNotFound(_0x332d35,_0x39e565){return function(_0x5583a4){if(!_0x5583a4){_0x332d35[_0x0a9e('0x29')](0x194);}return _0x5583a4;};}function handleError(_0x5e7238,_0x2cc7a0){_0x2cc7a0=_0x2cc7a0||0x1f4;return function(_0x14b13f){logger[_0x0a9e('0x25')](_0x14b13f[_0x0a9e('0x36')]);if(_0x14b13f['name']){delete _0x14b13f[_0x0a9e('0x37')];}_0x5e7238[_0x0a9e('0x2b')](_0x2cc7a0)[_0x0a9e('0x38')](_0x14b13f);};}exports[_0x0a9e('0x39')]=function(_0x4853b1,_0x54135e){var _0x1e8694={},_0x5640eb={},_0x24936a={'count':0x0,'rows':[]};var _0x3d9717=_[_0x0a9e('0x3a')](db[_0x0a9e('0x3b')]['rawAttributes'],function(_0x31916f){return{'name':_0x31916f[_0x0a9e('0x3c')],'type':_0x31916f[_0x0a9e('0x3d')]['key']};});_0x5640eb[_0x0a9e('0x3e')]=_[_0x0a9e('0x3a')](_0x3d9717,_0x0a9e('0x37'));_0x5640eb['query']=_['keys'](_0x4853b1[_0x0a9e('0x3f')]);_0x5640eb[_0x0a9e('0x40')]=_['intersection'](_0x5640eb[_0x0a9e('0x3e')],_0x5640eb[_0x0a9e('0x3f')]);_0x1e8694[_0x0a9e('0x41')]=_[_0x0a9e('0x42')](_0x5640eb['model'],qs['fields'](_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x43')]));_0x1e8694['attributes']=_0x1e8694[_0x0a9e('0x41')][_0x0a9e('0x44')]?_0x1e8694[_0x0a9e('0x41')]:_0x5640eb['model'];if(!_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x45')](_0x0a9e('0x46'))){_0x1e8694[_0x0a9e('0x2f')]=qs[_0x0a9e('0x2f')](_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x2f')]);_0x1e8694[_0x0a9e('0x2e')]=qs[_0x0a9e('0x2e')](_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x2e')]);}_0x1e8694[_0x0a9e('0x47')]=qs[_0x0a9e('0x48')](_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x48')]);_0x1e8694['where']=qs['filters'](_[_0x0a9e('0x49')](_0x4853b1[_0x0a9e('0x3f')],_0x5640eb[_0x0a9e('0x40')]),_0x3d9717);if(_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x4a')]){_0x1e8694[_0x0a9e('0x4b')]=_[_0x0a9e('0x4c')](_0x1e8694[_0x0a9e('0x4b')],{'$or':_[_0x0a9e('0x3a')](_0x3d9717,function(_0x25c6e6){if(_0x25c6e6[_0x0a9e('0x3d')]!==_0x0a9e('0x4d')){var _0x5026aa={};_0x5026aa[_0x25c6e6[_0x0a9e('0x37')]]={'$like':'%'+_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x4a')]+'%'};return _0x5026aa;}})});}_0x1e8694=_[_0x0a9e('0x4c')]({},_0x1e8694,_0x4853b1[_0x0a9e('0x4e')]);var _0xbe9d19={'where':_0x1e8694[_0x0a9e('0x4b')]};return db[_0x0a9e('0x3b')]['count'](_0xbe9d19)[_0x0a9e('0x1e')](function(_0x48fd45){_0x24936a[_0x0a9e('0x2d')]=_0x48fd45;if(_0x4853b1[_0x0a9e('0x3f')][_0x0a9e('0x4f')]){_0x1e8694['include']=[{'all':!![]}];}return db[_0x0a9e('0x3b')][_0x0a9e('0x50')](_0x1e8694);})[_0x0a9e('0x1e')](function(_0x34aa5a){_0x24936a[_0x0a9e('0x51')]=_0x34aa5a;return _0x24936a;})[_0x0a9e('0x1e')](respondWithFilteredResult(_0x54135e,_0x1e8694))[_0x0a9e('0x52')](handleError(_0x54135e,null));};exports['show']=function(_0x13f44d,_0x1bde3c){var _0x1b5e80={'raw':!![],'where':{'id':_0x13f44d[_0x0a9e('0x53')]['id']}},_0x16f976={};_0x16f976[_0x0a9e('0x3e')]=_[_0x0a9e('0x54')](db[_0x0a9e('0x3b')][_0x0a9e('0x55')]);_0x16f976['query']=_[_0x0a9e('0x54')](_0x13f44d[_0x0a9e('0x3f')]);_0x16f976['filters']=_['intersection'](_0x16f976['model'],_0x16f976[_0x0a9e('0x3f')]);_0x1b5e80[_0x0a9e('0x41')]=_[_0x0a9e('0x42')](_0x16f976[_0x0a9e('0x3e')],qs[_0x0a9e('0x43')](_0x13f44d[_0x0a9e('0x3f')][_0x0a9e('0x43')]));_0x1b5e80[_0x0a9e('0x41')]=_0x1b5e80['attributes']['length']?_0x1b5e80['attributes']:_0x16f976[_0x0a9e('0x3e')];if(_0x13f44d[_0x0a9e('0x3f')][_0x0a9e('0x4f')]){_0x1b5e80['include']=[{'all':!![]}];}_0x1b5e80=_[_0x0a9e('0x4c')]({},_0x1b5e80,_0x13f44d[_0x0a9e('0x4e')]);return db['MailMessage']['find'](_0x1b5e80)[_0x0a9e('0x1e')](handleEntityNotFound(_0x1bde3c,null))['then'](respondWithResult(_0x1bde3c,null))[_0x0a9e('0x52')](handleError(_0x1bde3c,null));};exports['update']=function(_0x2e5e62,_0x3c20b2){if(_0x2e5e62[_0x0a9e('0x56')]['id']){delete _0x2e5e62['body']['id'];}return db[_0x0a9e('0x3b')][_0x0a9e('0x57')]({'where':{'id':_0x2e5e62['params']['id']}})['then'](handleEntityNotFound(_0x3c20b2,null))[_0x0a9e('0x1e')](saveUpdates(_0x2e5e62[_0x0a9e('0x56')],null))['then'](respondWithResult(_0x3c20b2,null))[_0x0a9e('0x52')](handleError(_0x3c20b2,null));};exports['destroy']=function(_0x211ef9,_0x523cd2){return db[_0x0a9e('0x3b')]['find']({'where':{'id':_0x211ef9['params']['id']}})['then'](handleEntityNotFound(_0x523cd2,null))[_0x0a9e('0x1e')](removeEntity(_0x523cd2,null))['catch'](handleError(_0x523cd2,null));};exports[_0x0a9e('0x58')]=function(_0x65432,_0x3cfd00){return db[_0x0a9e('0x3b')][_0x0a9e('0x58')]()[_0x0a9e('0x1e')](respondWithResult(_0x3cfd00,null))[_0x0a9e('0x52')](handleError(_0x3cfd00,null));};exports[_0x0a9e('0x59')]=function(_0x4e67ab,_0x1c693e){return db[_0x0a9e('0x3b')][_0x0a9e('0x59')](_0x4e67ab[_0x0a9e('0x56')])[_0x0a9e('0x1e')](function(_0x156662){if(_0x156662){if(_0x156662['direction']===_0x0a9e('0x5a')&&!_0x156662[_0x0a9e('0x5b')]){var _0x5239ef,_0x3649cc,_0x5cc8fb;if(_0x4e67ab[_0x0a9e('0x56')]['to']){_0x3649cc=_0x4e67ab['body']['to']['split'](',')[0x0];}return db['MailAccount'][_0x0a9e('0x5c')]({'where':{'id':_0x156662['MailAccountId']},'include':[{'model':db[_0x0a9e('0x5d')],'as':_0x0a9e('0x5e'),'include':[{'model':db[_0x0a9e('0x5f')],'as':_0x0a9e('0x60'),'where':{'email':_0x3649cc},'limit':0x1,'order':[[_0x0a9e('0x61'),_0x0a9e('0x62')]]}]},{'model':db['MailServerOut'],'as':_0x0a9e('0x63'),'raw':!![]}]})['then'](function(_0xca4ade){_0x5239ef=_0xca4ade;if(_0x5239ef&&_0x5239ef[_0x0a9e('0x63')]){var _0x51aaf7={'tls':{'rejectUnauthorized':![]}};if(_['isNil'](_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x64')])){_0x51aaf7[_0x0a9e('0x65')]=_0x5239ef[_0x0a9e('0x63')]['host'];_0x51aaf7[_0x0a9e('0x66')]=_0x5239ef[_0x0a9e('0x63')]['port'];_0x51aaf7[_0x0a9e('0x67')]=_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x67')];if(_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x68')]){_0x51aaf7['auth']={'user':_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x69')],'pass':_0x5239ef[_0x0a9e('0x63')]['pass']};}}else{_0x51aaf7[_0x0a9e('0x64')]=_0x5239ef['Smtp']['service'];_0x51aaf7[_0x0a9e('0x6a')]={'user':_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x69')],'pass':_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x6b')]};_0x51aaf7[_0x0a9e('0x67')]=_0x5239ef[_0x0a9e('0x63')][_0x0a9e('0x67')];}if(_0x4e67ab[_0x0a9e('0x56')][_0x0a9e('0x6c')]&&_0x4e67ab[_0x0a9e('0x56')][_0x0a9e('0x6c')][_0x0a9e('0x44')]){for(var _0x2b8192=0x0;_0x2b8192<_0x4e67ab[_0x0a9e('0x56')][_0x0a9e('0x6c')][_0x0a9e('0x44')];_0x2b8192+=0x1){_0x4e67ab[_0x0a9e('0x56')]['attachments'][_0x2b8192]={'filename':_0x4e67ab[_0x0a9e('0x56')][_0x0a9e('0x6c')][_0x2b8192][_0x0a9e('0x37')],'path':path['join'](config[_0x0a9e('0x6d')],_0x0a9e('0x6e'),_0x4e67ab['body'][_0x0a9e('0x6c')][_0x2b8192][_0x0a9e('0x6f')])};}}_0x5cc8fb={'account':_0x51aaf7,'message':_0x4e67ab[_0x0a9e('0x56')]};return;}})[_0x0a9e('0x1e')](function(){if(_0x5239ef[_0x0a9e('0x5e')]){if(_0x5239ef['List']['Contacts']['length']){return _0x5239ef[_0x0a9e('0x5e')][_0x0a9e('0x60')][0x0];}else{return db[_0x0a9e('0x5f')][_0x0a9e('0x59')](_[_0x0a9e('0x16')](_0x4e67ab[_0x0a9e('0x56')],{'firstName':_0x4e67ab[_0x0a9e('0x56')]['to'],'email':_0x4e67ab[_0x0a9e('0x56')]['to'],'phone':_0x4e67ab['body']['to'],'ListId':_0x5239ef[_0x0a9e('0x70')]}));}}else{throw new Error(_0x0a9e('0x71'));}})[_0x0a9e('0x1e')](function(){if(_0x5cc8fb){return respondWithRpcPromise('SendMail',_0x0a9e('0x72'),_0x5cc8fb,client9003)['then'](function(_0x4437ff){return _0x156662[_0x0a9e('0x34')]({'read':!![],'messageId':_0x4437ff['messageId'],'sentAt':moment()[_0x0a9e('0x73')](_0x0a9e('0x74'))});})[_0x0a9e('0x52')](function(_0x317c0c){logger['error']('%s',JSON[_0x0a9e('0x24')](_0x317c0c));return _0x156662;});}return _0x156662;});}return _0x156662;}})[_0x0a9e('0x1e')](respondWithResult(_0x1c693e,0xc9))[_0x0a9e('0x52')](handleError(_0x1c693e,null));};var interaction_log=require(_0x0a9e('0x75'))('mail-interactions');exports[_0x0a9e('0x76')]=function(_0x3d91db,_0x2d5506,_0x361b21){var _0x4abc8f={'agent':{},'channel':_0x0a9e('0x77')};if(_0x3d91db[_0x0a9e('0x56')]['id']){delete _0x3d91db[_0x0a9e('0x56')]['id'];}_0x3d91db[_0x0a9e('0x56')][_0x0a9e('0x78')]=!![];_0x3d91db[_0x0a9e('0x56')][_0x0a9e('0x79')]=moment()[_0x0a9e('0x73')](_0x0a9e('0x74'));_0x3d91db[_0x0a9e('0x56')][_0x0a9e('0x7a')]=_0x3d91db[_0x0a9e('0x56')][_0x0a9e('0x7a')]||_0x3d91db[_0x0a9e('0x69')]['id'];_0x4abc8f['agent']['id']=_0x3d91db[_0x0a9e('0x56')][_0x0a9e('0x7a')];return db[_0x0a9e('0x3b')]['find']({'where':{'id':_0x3d91db[_0x0a9e('0x53')]['id'],'UserId':null},'include':[{'model':db[_0x0a9e('0x5f')],'as':_0x0a9e('0x7b')}]})[_0x0a9e('0x1e')](handleEntityNotFound(_0x2d5506,null))['then'](saveUpdates(_0x3d91db['body'],null))[_0x0a9e('0x1e')](function(_0x2bbdb5){if(_0x2bbdb5){_0x4abc8f['message']=_0x2bbdb5[_0x0a9e('0x7c')]({'plain':!![]});return db['MailInteraction'][_0x0a9e('0x57')]({'where':{'id':_0x2bbdb5[_0x0a9e('0x7d')]}});}return null;})['then'](handleEntityNotFound(_0x2d5506,null))[_0x0a9e('0x1e')](function(_0x41cf12){if(_0x41cf12){return _0x41cf12[_0x0a9e('0x34')]({'UserId':_0x3d91db[_0x0a9e('0x56')][_0x0a9e('0x7a')],'read1stAt':_[_0x0a9e('0x7e')](_0x41cf12[_0x0a9e('0x7f')])?moment()['format'](_0x0a9e('0x74')):undefined});}return null;})[_0x0a9e('0x1e')](function(_0x45c109){if(_0x45c109){_0x4abc8f[_0x0a9e('0x80')]=_0x45c109['get']({'plain':!![]});interaction_log[_0x0a9e('0x1f')](_0x0a9e('0x81'),_0x3d91db['user']['id'],_0x3d91db[_0x0a9e('0x69')]['name'],_0x3d91db[_0x0a9e('0x69')][_0x0a9e('0x82')],_0x4abc8f[_0x0a9e('0x80')]['id'],_0x3d91db[_0x0a9e('0x56')]?JSON['stringify'](_0x3d91db['body']):_0x0a9e('0x83'));return respondWithRpcPromise(_0x0a9e('0x84'),_0x0a9e('0x85'),_0x4abc8f);}return null;})['then'](function(_0x3b4a9f){if(_0x3b4a9f){if(_0x3d91db[_0x0a9e('0x56')]['manual']){_0x4abc8f['message'][_0x0a9e('0x86')]=util['format']('SIP/%s',_0x3d91db['user'][_0x0a9e('0x37')]);_0x4abc8f[_0x0a9e('0x27')][_0x0a9e('0x87')]=_0x4abc8f[_0x0a9e('0x87')];_0x4abc8f[_0x0a9e('0x27')][_0x0a9e('0x88')]='accept';return respondWithRpcPromise(_0x0a9e('0x89'),'EventManager',{'event':_0x0a9e('0x8a'),'message':_0x4abc8f[_0x0a9e('0x27')]},client9002)[_0x0a9e('0x1e')](function(){return _0x4abc8f;});}return _0x4abc8f;}return null;})[_0x0a9e('0x1e')](respondWithResult(_0x2d5506,null))['catch'](handleError(_0x2d5506,null));};var interaction_log=require(_0x0a9e('0x75'))(_0x0a9e('0x8b'));exports[_0x0a9e('0x8c')]=function(_0x5b74c3,_0xb6e411,_0x21e592){var _0x2a563d={'agent':{},'channel':_0x0a9e('0x77')};if(_0x5b74c3[_0x0a9e('0x56')]['id']){delete _0x5b74c3[_0x0a9e('0x56')]['id'];}_0x5b74c3[_0x0a9e('0x56')][_0x0a9e('0x7a')]=_0x5b74c3['body'][_0x0a9e('0x7a')]||_0x5b74c3[_0x0a9e('0x69')]['id'];_0x2a563d['agent']['id']=_0x5b74c3[_0x0a9e('0x56')][_0x0a9e('0x7a')];return db[_0x0a9e('0x3b')]['find']({'where':{'id':_0x5b74c3[_0x0a9e('0x53')]['id'],'UserId':null}})['then'](handleEntityNotFound(_0xb6e411,null))[_0x0a9e('0x1e')](function(_0x2b5148){if(_0x2b5148){_0x2a563d[_0x0a9e('0x27')]=_0x2b5148[_0x0a9e('0x7c')]({'plain':!![]});return db[_0x0a9e('0x8d')][_0x0a9e('0x57')]({'where':{'id':_0x2b5148[_0x0a9e('0x7d')]}});}return null;})[_0x0a9e('0x1e')](handleEntityNotFound(_0xb6e411,null))['then'](function(_0x329d88){if(_0x329d88){_0x2a563d[_0x0a9e('0x80')]=_0x329d88[_0x0a9e('0x7c')]({'plain':!![]});interaction_log[_0x0a9e('0x1f')](_0x0a9e('0x8e'),_0x5b74c3[_0x0a9e('0x69')]['id'],_0x5b74c3[_0x0a9e('0x69')][_0x0a9e('0x37')],_0x5b74c3[_0x0a9e('0x69')][_0x0a9e('0x82')],_0x2a563d[_0x0a9e('0x80')]['id'],_0x5b74c3[_0x0a9e('0x56')]?JSON[_0x0a9e('0x24')](_0x5b74c3['body']):_0x0a9e('0x83'));return respondWithRpcPromise(_0x0a9e('0x8f'),_0x0a9e('0x90'),_0x2a563d);}return null;})[_0x0a9e('0x1e')](function(_0xb0599a){if(_0xb0599a){_0xb0599a['message'][_0x0a9e('0x86')]=util[_0x0a9e('0x73')]('SIP/%s',_0x5b74c3[_0x0a9e('0x69')]['name']);_0xb0599a[_0x0a9e('0x27')][_0x0a9e('0x87')]=_0x2a563d[_0x0a9e('0x87')];_0xb0599a[_0x0a9e('0x27')]['event']=_0x0a9e('0x8c');respondWithRpcPromise('EventManager',_0x0a9e('0x89'),{'event':_0x0a9e('0x91'),'message':_0xb0599a['message']},client9002);return _0x2a563d;}return null;})[_0x0a9e('0x1e')](respondWithResult(_0xb6e411,null))[_0x0a9e('0x52')](handleError(_0xb6e411,null));};exports[_0x0a9e('0x92')]=function(_0x4ab276,_0x4c788f){var _0x1b82b7=moment()[_0x0a9e('0x93')]()[_0x0a9e('0x94')]();var _0x413190=path[_0x0a9e('0x95')](config[_0x0a9e('0x6d')],_0x0a9e('0x96'),_0x0a9e('0x97'),_0x0a9e('0x98'));var _0x586510=path[_0x0a9e('0x95')](config['root'],_0x0a9e('0x96'),_0x0a9e('0x97'),_0x0a9e('0x6c'));var _0x28ce92=util[_0x0a9e('0x73')]('message-%s.eml',_0x1b82b7);return db[_0x0a9e('0x3b')][_0x0a9e('0x57')]({'where':{'id':_0x4ab276[_0x0a9e('0x53')]['id']},'attributes':['id',_0x0a9e('0x56'),_0x0a9e('0x99'),'to','cc','bcc','subject',_0x0a9e('0x9a')],'include':_0x4ab276['query'][_0x0a9e('0x6c')]?[{'model':db[_0x0a9e('0x9b')],'as':_0x0a9e('0x9c')}]:undefined})[_0x0a9e('0x1e')](handleEntityNotFound(_0x4c788f,null))[_0x0a9e('0x1e')](function(_0x213e5d){if(_0x213e5d){var _0x596312=_0x213e5d;var _0x4db918={'from':_0x596312[_0x0a9e('0x99')],'to':_0x596312['to'],'subject':_0x596312['subject'],'html':_0x596312[_0x0a9e('0x56')],'headers':{'Date':moment(_0x596312['createdAt'])[_0x0a9e('0x73')]('ddd,\x20DD\x20MMM\x20YYYY\x20HH:mm:ss\x20ZZ')},'attachments':[]};if(_0x213e5d['cc']){_0x4db918['headers']['Cc']=_0x213e5d['cc'];}if(_0x213e5d[_0x0a9e('0x9d')]){_0x4db918[_0x0a9e('0x9e')]['Bcc']=_0x213e5d[_0x0a9e('0x9d')];}return new BPromise(function(_0x17cb30,_0x15c6b9){if(_0x213e5d[_0x0a9e('0x9c')]){for(var _0x2eb028=0x0;_0x2eb028<_0x213e5d['Attachments']['length'];_0x2eb028++){var _0x16449b=_0x213e5d[_0x0a9e('0x9c')][_0x2eb028];var _0x41c8cd=path[_0x0a9e('0x95')](_0x586510,_0x16449b[_0x0a9e('0x6f')]);if(fs['existsSync'](_0x41c8cd)){_0x4db918[_0x0a9e('0x6c')][_0x0a9e('0x9f')]({'name':_0x16449b['name'],'contentType':_0x16449b[_0x0a9e('0x3d')],'data':fs[_0x0a9e('0xa0')](_0x41c8cd)});}}}emlformat[_0x0a9e('0xa1')](_0x4db918,function(_0x2427d5,_0x23b25b){if(_0x2427d5)return _0x15c6b9(_0x2427d5);fs[_0x0a9e('0xa2')](path[_0x0a9e('0x95')](_0x413190,_0x28ce92),_0x23b25b);return _0x17cb30(_0x23b25b);});});}})[_0x0a9e('0x1e')](function(_0x40dd2a){if(_0x40dd2a){return _0x4c788f[_0x0a9e('0x92')](path['join'](_0x413190,_0x28ce92),_0x28ce92,function(_0x1065a7){if(_0x1065a7){console[_0x0a9e('0xa3')](_0x0a9e('0xa4'),_0x1065a7);}else{fs[_0x0a9e('0xa5')](path[_0x0a9e('0x95')](_0x413190,_0x28ce92));}});}})['catch'](handleError(_0x4c788f,null));};
\ No newline at end of file