Built motion from commit 67e5df37.|2.0.66
[motion2.git] / server / api / mailAccount / mailAccount.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 _0x5f2f=['MailAccount','rawAttributes','query','dateEnd','dateStart','keys','filters','intersection','attributes','fields','length','nolimit','order','sort','where','add','day','merge','filter','include','findAll','rows','MailServerIn','includeAll','options','catch','update','body','find','Smtp','describe','addAnswer','params','MailAccountId','CannedAnswer','create','findOne','hasOwnProperty','map','removeAnswers','ids','email','ListId','isNil','active','user','cuser','cpassword','authentication','host','port','service','cservice','password','getImap','addImap','removeImap','getSmtp','addSmtp','removeSmtp','setSmtp','addInteraction','MailInteraction','getInteractions','pick','Contact','Owner','fullname','internal','Tags','color','tag','addApplications','MailApplication','bulkCreate','findAndCountAll','priority','getApplications','MailDisposition','mailDisposition','omit','getDispositions','getMessages','MailMessage','$gte','format','split','CmList','List','CmContact','DESC','from','attachments','join','root','basename','pass','secure','auth','SendMail','sendMail','List\x20not\x20found','Contacts','defaults','subject','attach','out','YYYY-MM-DD\x20HH:mm:ss','messageId','Interaction','Messages','VerifySmtp','Sequelize','ValidationError','You\x20can\x27t\x20remove\x20the\x20mail\x20service\x20account','fast-json-patch','request-promise','moment','bluebird','mustache','util','path','sox','lodash','squel','crypto','jsforce','desk.js','to-csv','papaparse','../../components/parsers/qs','../../config/logger','../../config/utils','../../config/environment','../../mysqldb','client','request','then','MailAccount,\x20%s,\x20%s','request\x20sent','debug','MailAccount,\x20%s,\x20%s,\x20%s','error','code','message','info','result','sendStatus','status','end','json','count','offset','limit','Content-Range','apply','destroy','stack','name','send','index','Imap','MailServerOut','model'];(function(_0x4d3a9b,_0x20b47d){var _0x1b5471=function(_0x51bf57){while(--_0x51bf57){_0x4d3a9b['push'](_0x4d3a9b['shift']());}};_0x1b5471(++_0x20b47d);}(_0x5f2f,0x73));var _0xf5f2=function(_0x5461d2,_0x3dd4cf){_0x5461d2=_0x5461d2-0x0;var _0x2fc3d6=_0x5f2f[_0x5461d2];return _0x2fc3d6;};'use strict';var jsonpatch=require(_0xf5f2('0x0'));var rp=require(_0xf5f2('0x1'));var moment=require(_0xf5f2('0x2'));var BPromise=require(_0xf5f2('0x3'));var Mustache=require(_0xf5f2('0x4'));var util=require(_0xf5f2('0x5'));var path=require(_0xf5f2('0x6'));var sox=require(_0xf5f2('0x7'));var csv=require('to-csv');var ejs=require('ejs');var fs=require('fs');var _=require(_0xf5f2('0x8'));var squel=require(_0xf5f2('0x9'));var crypto=require(_0xf5f2('0xa'));var jsforce=require(_0xf5f2('0xb'));var deskjs=require(_0xf5f2('0xc'));var toCsv=require(_0xf5f2('0xd'));var querystring=require('querystring');var Papa=require(_0xf5f2('0xe'));var qs=require(_0xf5f2('0xf'));var logger=require(_0xf5f2('0x10'))('api');var utils=require(_0xf5f2('0x11'));var config=require(_0xf5f2('0x12'));var db=require(_0xf5f2('0x13'))['db'];var jayson=require('jayson/promise');var client=jayson[_0xf5f2('0x14')]['http']({'port':0x232b});function respondWithRpcPromise(_0x53fb33,_0xa7e1a6,_0x151aba,_0x4b78cd){return new BPromise(function(_0x336f6b,_0x14b51f){var _0x331482=_0x4b78cd||client;return _0x331482[_0xf5f2('0x15')](_0x53fb33,_0x151aba)[_0xf5f2('0x16')](function(_0x3e5956){logger['info'](_0xf5f2('0x17'),_0xa7e1a6,_0xf5f2('0x18'));logger[_0xf5f2('0x19')](_0xf5f2('0x1a'),_0xa7e1a6,_0xf5f2('0x18'),JSON['stringify'](_0x3e5956));if(_0x3e5956[_0xf5f2('0x1b')]){if(_0x3e5956[_0xf5f2('0x1b')][_0xf5f2('0x1c')]===0x1f4){logger[_0xf5f2('0x1b')](_0xf5f2('0x17'),_0xa7e1a6,_0x3e5956[_0xf5f2('0x1b')][_0xf5f2('0x1d')]);return _0x14b51f(_0x3e5956[_0xf5f2('0x1b')][_0xf5f2('0x1d')]);}logger[_0xf5f2('0x1b')](_0xf5f2('0x17'),_0xa7e1a6,_0x3e5956[_0xf5f2('0x1b')][_0xf5f2('0x1d')]);return _0x336f6b(_0x3e5956[_0xf5f2('0x1b')][_0xf5f2('0x1d')]);}else{logger[_0xf5f2('0x1e')](_0xf5f2('0x17'),_0xa7e1a6,'request\x20sent');_0x336f6b(_0x3e5956[_0xf5f2('0x1f')][_0xf5f2('0x1d')]);}})['catch'](function(_0x47acfc){logger[_0xf5f2('0x1b')](_0xf5f2('0x17'),_0xa7e1a6,_0x47acfc);_0x14b51f(_0x47acfc);});});}function respondWithStatusCode(_0x4ae323,_0x45b74f){_0x45b74f=_0x45b74f||0xcc;return function(_0x170042){if(_0x170042){return _0x4ae323[_0xf5f2('0x20')](_0x45b74f);}return _0x4ae323[_0xf5f2('0x21')](_0x45b74f)[_0xf5f2('0x22')]();};}function respondWithResult(_0x4c691a,_0x21cd91){_0x21cd91=_0x21cd91||0xc8;return function(_0x4669a6){if(_0x4669a6){return _0x4c691a[_0xf5f2('0x21')](_0x21cd91)[_0xf5f2('0x23')](_0x4669a6);}};}function respondWithFilteredResult(_0x287ad5,_0x5bdf4a){return function(_0x529f07){if(_0x529f07){var _0x5f1124=_0x529f07[_0xf5f2('0x24')],_0x3f79d5=_0x5bdf4a[_0xf5f2('0x25')],_0x13da6f=_0x5bdf4a[_0xf5f2('0x25')]+_0x5bdf4a[_0xf5f2('0x26')],_0x1a5bb3;if(_0x13da6f>=_0x5f1124){_0x13da6f=_0x5f1124;_0x1a5bb3=0xc8;}else{_0x1a5bb3=0xce;}_0x287ad5[_0xf5f2('0x21')](_0x1a5bb3);return _0x287ad5['set'](_0xf5f2('0x27'),_0x3f79d5+'-'+_0x13da6f+'/'+_0x5f1124)[_0xf5f2('0x23')](_0x529f07);}return null;};}function patchUpdates(_0x375ca8){return function(_0x31bfcb){try{jsonpatch[_0xf5f2('0x28')](_0x31bfcb,_0x375ca8,!![]);}catch(_0x477604){return BPromise['reject'](_0x477604);}return _0x31bfcb['save']();};}function saveUpdates(_0x22c826,_0x14c829){return function(_0x11c771){if(_0x11c771){return _0x11c771['update'](_0x22c826)['then'](function(_0x29571b){return _0x29571b;});}return null;};}function removeEntity(_0x50b8a2,_0x17394a){return function(_0x153924){if(_0x153924){return _0x153924[_0xf5f2('0x29')]()['then'](function(){_0x50b8a2['status'](0xcc)[_0xf5f2('0x22')]();});}};}function handleEntityNotFound(_0x4e19cb,_0xb744b9){return function(_0x58a4df){if(!_0x58a4df){_0x4e19cb[_0xf5f2('0x20')](0x194);}return _0x58a4df;};}function handleError(_0x31087c,_0x7b6817){_0x7b6817=_0x7b6817||0x1f4;return function(_0x428770){logger[_0xf5f2('0x1b')](_0x428770[_0xf5f2('0x2a')]);if(_0x428770[_0xf5f2('0x2b')]){delete _0x428770[_0xf5f2('0x2b')];}_0x31087c['status'](_0x7b6817)[_0xf5f2('0x2c')](_0x428770);};}exports[_0xf5f2('0x2d')]=function(_0x4590ec,_0x43c77d){var _0x1408b9={'include':[{'model':db['MailServerIn'],'as':_0xf5f2('0x2e')},{'model':db[_0xf5f2('0x2f')],'as':'Smtp'}]},_0x27c0e7={},_0x297c0c={'count':0x0,'rows':[]};_0x27c0e7[_0xf5f2('0x30')]=_['keys'](db[_0xf5f2('0x31')][_0xf5f2('0x32')]);var _0x2a2c31={'dateStart':_0x4590ec[_0xf5f2('0x33')]['dateStart'],'dateEnd':_0x4590ec['query'][_0xf5f2('0x34')]};delete _0x4590ec[_0xf5f2('0x33')][_0xf5f2('0x35')];delete _0x4590ec['query'][_0xf5f2('0x34')];_0x27c0e7['query']=_[_0xf5f2('0x36')](_0x4590ec['query']);_0x27c0e7[_0xf5f2('0x37')]=_[_0xf5f2('0x38')](_0x27c0e7['model'],_0x27c0e7[_0xf5f2('0x33')]);_0x1408b9[_0xf5f2('0x39')]=_[_0xf5f2('0x38')](_0x27c0e7[_0xf5f2('0x30')],qs['fields'](_0x4590ec['query'][_0xf5f2('0x3a')]));_0x1408b9[_0xf5f2('0x39')]=_0x1408b9[_0xf5f2('0x39')][_0xf5f2('0x3b')]?_0x1408b9[_0xf5f2('0x39')]:_0x27c0e7[_0xf5f2('0x30')];if(!_0x4590ec[_0xf5f2('0x33')]['hasOwnProperty'](_0xf5f2('0x3c'))){_0x1408b9[_0xf5f2('0x26')]=qs['limit'](_0x4590ec[_0xf5f2('0x33')][_0xf5f2('0x26')]);_0x1408b9[_0xf5f2('0x25')]=qs[_0xf5f2('0x25')](_0x4590ec[_0xf5f2('0x33')][_0xf5f2('0x25')]);}_0x1408b9[_0xf5f2('0x3d')]=qs[_0xf5f2('0x3e')](_0x4590ec['query'][_0xf5f2('0x3e')]);_0x1408b9[_0xf5f2('0x3f')]=qs[_0xf5f2('0x37')](_['pick'](_0x4590ec['query'],_0x27c0e7['filters']));if(_0x2a2c31[_0xf5f2('0x35')]){if(_0x2a2c31[_0xf5f2('0x34')]){_0x2a2c31['dateEnd']=moment(_0x2a2c31[_0xf5f2('0x34')])[_0xf5f2('0x40')](0x1,_0xf5f2('0x41'));}else{_0x2a2c31[_0xf5f2('0x34')]=moment(_0x2a2c31[_0xf5f2('0x35')])[_0xf5f2('0x40')](0x1,_0xf5f2('0x41'));}_[_0xf5f2('0x42')](_0x1408b9[_0xf5f2('0x3f')],{'createdAt':{'$gte':_0x2a2c31[_0xf5f2('0x35')],'$lte':_0x2a2c31[_0xf5f2('0x34')]}});}if(_0x4590ec[_0xf5f2('0x33')][_0xf5f2('0x43')]){_0x1408b9[_0xf5f2('0x3f')]=_['merge'](_0x1408b9[_0xf5f2('0x3f')],{'$or':_['map'](_0x1408b9[_0xf5f2('0x39')],function(_0xc04f44){var _0x218def={};_0x218def[_0xc04f44]={'$like':'%'+_0x4590ec[_0xf5f2('0x33')][_0xf5f2('0x43')]+'%'};return _0x218def;})});}_0x1408b9=_[_0xf5f2('0x42')]({},_0x1408b9,_0x4590ec['options']);var _0x3e89e8={'where':_0x1408b9[_0xf5f2('0x3f')]};return db[_0xf5f2('0x31')][_0xf5f2('0x24')](_0x3e89e8)[_0xf5f2('0x16')](function(_0x10753a){_0x297c0c[_0xf5f2('0x24')]=_0x10753a;if(_0x4590ec[_0xf5f2('0x33')]['includeAll']){_0x1408b9[_0xf5f2('0x44')]=[{'all':!![]}];}return db[_0xf5f2('0x31')][_0xf5f2('0x45')](_0x1408b9);})['then'](function(_0x1177ba){_0x297c0c[_0xf5f2('0x46')]=_0x1177ba;return _0x297c0c;})[_0xf5f2('0x16')](respondWithFilteredResult(_0x43c77d,_0x1408b9))['catch'](handleError(_0x43c77d,null));};exports['show']=function(_0x7bb942,_0x27c472){var _0x5db519={'raw':![],'where':{'id':_0x7bb942['params']['id']},'include':[{'model':db[_0xf5f2('0x47')],'as':'Imap'},{'model':db[_0xf5f2('0x2f')],'as':'Smtp'}]},_0x14aa81={};_0x14aa81[_0xf5f2('0x30')]=_[_0xf5f2('0x36')](db[_0xf5f2('0x31')][_0xf5f2('0x32')]);_0x14aa81['query']=_[_0xf5f2('0x36')](_0x7bb942[_0xf5f2('0x33')]);_0x14aa81['filters']=_['intersection'](_0x14aa81[_0xf5f2('0x30')],_0x14aa81[_0xf5f2('0x33')]);_0x5db519['attributes']=_[_0xf5f2('0x38')](_0x14aa81[_0xf5f2('0x30')],qs[_0xf5f2('0x3a')](_0x7bb942[_0xf5f2('0x33')]['fields']));_0x5db519['attributes']=_0x5db519[_0xf5f2('0x39')][_0xf5f2('0x3b')]?_0x5db519['attributes']:_0x14aa81[_0xf5f2('0x30')];if(_0x7bb942[_0xf5f2('0x33')][_0xf5f2('0x48')]){_0x5db519[_0xf5f2('0x44')]=[{'all':!![]}];}_0x5db519=_[_0xf5f2('0x42')]({},_0x5db519,_0x7bb942[_0xf5f2('0x49')]);return db[_0xf5f2('0x31')]['find'](_0x5db519)['then'](handleEntityNotFound(_0x27c472,null))[_0xf5f2('0x16')](respondWithResult(_0x27c472,null))[_0xf5f2('0x4a')](handleError(_0x27c472,null));};exports[_0xf5f2('0x4b')]=function(_0x46a905,_0x21b0d3){if(_0x46a905['body']['id']){delete _0x46a905[_0xf5f2('0x4c')]['id'];}return db[_0xf5f2('0x31')][_0xf5f2('0x4d')]({'where':{'id':_0x46a905['params']['id']},'include':[{'model':db[_0xf5f2('0x47')],'as':'Imap'},{'model':db[_0xf5f2('0x2f')],'as':_0xf5f2('0x4e')}]})[_0xf5f2('0x16')](handleEntityNotFound(_0x21b0d3,null))[_0xf5f2('0x16')](saveUpdates(_0x46a905['body'],null))['then'](function(_0x756f1f){if(_0x756f1f&&_0x46a905['body'][_0xf5f2('0x2e')]){return db[_0xf5f2('0x47')]['update'](_0x46a905[_0xf5f2('0x4c')][_0xf5f2('0x2e')],{'where':{'MailAccountId':_0x756f1f['id']}})[_0xf5f2('0x16')](function(){return _0x756f1f;});}return _0x756f1f;})['then'](function(_0x397b99){if(_0x397b99&&_0x46a905[_0xf5f2('0x4c')][_0xf5f2('0x4e')]){return db[_0xf5f2('0x2f')]['update'](_0x46a905[_0xf5f2('0x4c')]['Smtp'],{'where':{'MailAccountId':_0x397b99['id']}})[_0xf5f2('0x16')](function(){return _0x397b99;});}return _0x397b99;})[_0xf5f2('0x16')](respondWithResult(_0x21b0d3,null))[_0xf5f2('0x4a')](handleError(_0x21b0d3,null));};exports[_0xf5f2('0x4f')]=function(_0x9f210e,_0x5583c2){return db[_0xf5f2('0x31')][_0xf5f2('0x4f')]()[_0xf5f2('0x16')](respondWithResult(_0x5583c2,null))[_0xf5f2('0x4a')](handleError(_0x5583c2,null));};exports[_0xf5f2('0x50')]=function(_0x5359b5,_0x31e16b,_0x5ee6bc){if(_0x5359b5['body']['id']){delete _0x5359b5[_0xf5f2('0x4c')]['id'];}return db['MailAccount'][_0xf5f2('0x4d')]({'where':{'id':_0x5359b5[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x31e16b,null))[_0xf5f2('0x16')](function(_0x5767fc){if(_0x5767fc){_0x5359b5[_0xf5f2('0x4c')][_0xf5f2('0x52')]=_0x5767fc['id'];return db[_0xf5f2('0x53')][_0xf5f2('0x54')](_0x5359b5[_0xf5f2('0x4c')]);}})[_0xf5f2('0x16')](respondWithResult(_0x31e16b,null))[_0xf5f2('0x4a')](handleError(_0x31e16b,null));};exports['getAnswers']=function(_0x1f55af,_0x2d171d,_0xb39a6e){var _0x45c7c1={'raw':![],'where':{}};var _0x5a5b2b={};var _0x1de396={'count':0x0,'rows':[]};return db['MailAccount'][_0xf5f2('0x55')]({'where':{'id':_0x1f55af[_0xf5f2('0x51')]['id']}})['then'](handleEntityNotFound(_0x2d171d,null))[_0xf5f2('0x16')](function(_0x975bd8){if(_0x975bd8){_0x5a5b2b[_0xf5f2('0x30')]=_[_0xf5f2('0x36')](db[_0xf5f2('0x53')]['rawAttributes']);_0x5a5b2b[_0xf5f2('0x33')]=_[_0xf5f2('0x36')](_0x1f55af[_0xf5f2('0x33')]);_0x5a5b2b[_0xf5f2('0x37')]=_[_0xf5f2('0x38')](_0x5a5b2b[_0xf5f2('0x30')],_0x5a5b2b['query']);_0x45c7c1[_0xf5f2('0x39')]=_[_0xf5f2('0x38')](_0x5a5b2b['model'],qs[_0xf5f2('0x3a')](_0x1f55af[_0xf5f2('0x33')][_0xf5f2('0x3a')]));_0x45c7c1['attributes']=_0x45c7c1['attributes']['length']?_0x45c7c1[_0xf5f2('0x39')]:_0x5a5b2b[_0xf5f2('0x30')];if(!_0x1f55af[_0xf5f2('0x33')][_0xf5f2('0x56')](_0xf5f2('0x3c'))){_0x45c7c1['limit']=qs[_0xf5f2('0x26')](_0x1f55af[_0xf5f2('0x33')][_0xf5f2('0x26')]);_0x45c7c1[_0xf5f2('0x25')]=qs[_0xf5f2('0x25')](_0x1f55af[_0xf5f2('0x33')][_0xf5f2('0x25')]);}_0x45c7c1[_0xf5f2('0x3d')]=qs[_0xf5f2('0x3e')](_0x1f55af[_0xf5f2('0x33')][_0xf5f2('0x3e')]);_0x45c7c1['where']=qs['filters'](_['pick'](_0x1f55af[_0xf5f2('0x33')],_0x5a5b2b[_0xf5f2('0x37')]));_0x45c7c1[_0xf5f2('0x3f')][_0xf5f2('0x52')]=_0x975bd8['id'];if(_0x1f55af[_0xf5f2('0x33')]['filter']){_0x45c7c1[_0xf5f2('0x3f')]=_[_0xf5f2('0x42')](_0x45c7c1[_0xf5f2('0x3f')],{'$or':_[_0xf5f2('0x57')](_0x45c7c1[_0xf5f2('0x39')],function(_0x55748d){var _0x2986ed={};_0x2986ed[_0x55748d]={'$like':'%'+_0x1f55af[_0xf5f2('0x33')]['filter']+'%'};return _0x2986ed;})});}_0x45c7c1=_[_0xf5f2('0x42')]({},_0x45c7c1,_0x1f55af[_0xf5f2('0x49')]);return db[_0xf5f2('0x53')][_0xf5f2('0x24')]({'where':_0x45c7c1['where']})[_0xf5f2('0x16')](function(_0xead8){_0x1de396[_0xf5f2('0x24')]=_0xead8;if(_0x1f55af[_0xf5f2('0x33')][_0xf5f2('0x48')]){_0x45c7c1['include']=[{'all':!![]}];}return db['CannedAnswer'][_0xf5f2('0x45')](_0x45c7c1);})[_0xf5f2('0x16')](function(_0x17eb69){_0x1de396[_0xf5f2('0x46')]=_0x17eb69;return _0x1de396;});}})['then'](respondWithFilteredResult(_0x2d171d,_0x45c7c1))['catch'](handleError(_0x2d171d,null));};exports[_0xf5f2('0x58')]=function(_0x4f2fcc,_0x4c4420,_0x4c899a){var _0x57cb18;return db[_0xf5f2('0x31')][_0xf5f2('0x4d')]({'where':{'id':_0x4f2fcc[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x4c4420,null))[_0xf5f2('0x16')](function(_0x9f941e){if(_0x9f941e){return _0x9f941e[_0xf5f2('0x58')](_0x4f2fcc[_0xf5f2('0x33')][_0xf5f2('0x59')]);}})[_0xf5f2('0x16')](respondWithStatusCode(_0x4c4420,null))[_0xf5f2('0x4a')](handleError(_0x4c4420,null));};exports[_0xf5f2('0x54')]=function(_0x1ba503,_0x1680a6){var _0x796b01={'name':_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x2b')],'key':_0x1ba503[_0xf5f2('0x4c')]['key'],'email':_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x5a')],'ListId':_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x5b')],'active':!_[_0xf5f2('0x5c')](_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x5d')])?_0x1ba503[_0xf5f2('0x4c')]['active']:!![],'description':_0x1ba503[_0xf5f2('0x4c')]['description']||null,'Imap':{},'Smtp':{}};if(_['isNil'](_0x1ba503['body']['cservice'])){if(_0x1ba503['body']['cauthentication']){_0x796b01[_0xf5f2('0x2e')][_0xf5f2('0x5e')]=_0x796b01[_0xf5f2('0x4e')][_0xf5f2('0x5e')]=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x5f')];_0x796b01['Imap']['password']=_0x796b01[_0xf5f2('0x4e')]['pass']=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x60')];}else{_0x796b01['Imap']['authentication']=_0x796b01[_0xf5f2('0x4e')][_0xf5f2('0x61')]=![];}_0x796b01['Imap'][_0xf5f2('0x62')]=_0x1ba503[_0xf5f2('0x4c')]['Imap'][_0xf5f2('0x62')];_0x796b01[_0xf5f2('0x2e')][_0xf5f2('0x63')]=_0x1ba503['body'][_0xf5f2('0x2e')][_0xf5f2('0x63')];_0x796b01[_0xf5f2('0x4e')][_0xf5f2('0x62')]=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x4e')][_0xf5f2('0x62')];_0x796b01[_0xf5f2('0x4e')][_0xf5f2('0x63')]=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x4e')][_0xf5f2('0x63')];}else{_0x796b01[_0xf5f2('0x2e')][_0xf5f2('0x64')]=_0x796b01[_0xf5f2('0x4e')][_0xf5f2('0x64')]=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x65')];_0x796b01[_0xf5f2('0x2e')][_0xf5f2('0x5e')]=_0x796b01[_0xf5f2('0x4e')]['user']=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x5f')];_0x796b01['Imap'][_0xf5f2('0x66')]=_0x796b01[_0xf5f2('0x4e')]['pass']=_0x1ba503[_0xf5f2('0x4c')][_0xf5f2('0x60')];}return db[_0xf5f2('0x31')]['create'](_0x796b01,{'include':[{'model':db['MailServerOut'],'as':_0xf5f2('0x4e')},{'model':db[_0xf5f2('0x47')],'as':_0xf5f2('0x2e')}]})['then'](respondWithResult(_0x1680a6,0xc9))['catch'](handleError(_0x1680a6,null));};exports[_0xf5f2('0x67')]=function(_0xcdc6fd,_0x139fdb,_0x563fb5){return db['MailAccount']['findOne']({'where':{'id':_0xcdc6fd['params']['id']}})['then'](handleEntityNotFound(_0x139fdb,null))[_0xf5f2('0x16')](function(_0x561bab){if(_0x561bab){return _0x561bab[_0xf5f2('0x67')]();}return null;})[_0xf5f2('0x16')](respondWithResult(_0x139fdb,null))[_0xf5f2('0x4a')](handleError(_0x139fdb,null));};exports[_0xf5f2('0x68')]=function(_0x29ab74,_0x398f2b,_0xa10f88){if(_0x29ab74[_0xf5f2('0x4c')]['id']){delete _0x29ab74[_0xf5f2('0x4c')]['id'];}return db[_0xf5f2('0x31')][_0xf5f2('0x4d')]({'where':{'id':_0x29ab74[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x398f2b,null))['then'](function(_0x29f40b){if(_0x29f40b){_0x29ab74[_0xf5f2('0x4c')]['MailAccountId']=_0x29f40b['id'];return db[_0xf5f2('0x47')][_0xf5f2('0x54')](_0x29ab74['body']);}})[_0xf5f2('0x16')](respondWithResult(_0x398f2b,null))[_0xf5f2('0x4a')](handleError(_0x398f2b,null));};exports[_0xf5f2('0x69')]=function(_0x4bd9e8,_0x21c5fc,_0x4270fd){return db['MailAccount'][_0xf5f2('0x55')]({'where':{'id':_0x4bd9e8[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x21c5fc,null))['then'](function(_0x21b179){if(_0x21b179){return _0x21b179['setImap'](null);}return null;})[_0xf5f2('0x16')](respondWithStatusCode(_0x21c5fc,null))['catch'](handleError(_0x21c5fc,null));};exports[_0xf5f2('0x6a')]=function(_0x3cbc58,_0x120e2b,_0x42c915){return db['MailAccount'][_0xf5f2('0x55')]({'where':{'id':_0x3cbc58['params']['id']}})['then'](handleEntityNotFound(_0x120e2b,null))['then'](function(_0x2a253a){if(_0x2a253a){return _0x2a253a[_0xf5f2('0x6a')]();}return null;})['then'](respondWithResult(_0x120e2b,null))[_0xf5f2('0x4a')](handleError(_0x120e2b,null));};exports[_0xf5f2('0x6b')]=function(_0x35790b,_0x3962b2,_0x28873e){if(_0x35790b[_0xf5f2('0x4c')]['id']){delete _0x35790b['body']['id'];}return db[_0xf5f2('0x31')][_0xf5f2('0x4d')]({'where':{'id':_0x35790b['params']['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x3962b2,null))[_0xf5f2('0x16')](function(_0x58042c){if(_0x58042c){_0x35790b[_0xf5f2('0x4c')][_0xf5f2('0x52')]=_0x58042c['id'];return db[_0xf5f2('0x2f')][_0xf5f2('0x54')](_0x35790b[_0xf5f2('0x4c')]);}})[_0xf5f2('0x16')](respondWithResult(_0x3962b2,null))['catch'](handleError(_0x3962b2,null));};exports[_0xf5f2('0x6c')]=function(_0x5a8af6,_0x13fcb0,_0x792c75){return db[_0xf5f2('0x31')][_0xf5f2('0x55')]({'where':{'id':_0x5a8af6[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x13fcb0,null))[_0xf5f2('0x16')](function(_0x5cabb2){if(_0x5cabb2){return _0x5cabb2[_0xf5f2('0x6d')](null);}return null;})[_0xf5f2('0x16')](respondWithStatusCode(_0x13fcb0,null))[_0xf5f2('0x4a')](handleError(_0x13fcb0,null));};exports[_0xf5f2('0x6e')]=function(_0x35fe1a,_0x37c1a1,_0x35e855){return db[_0xf5f2('0x6f')][_0xf5f2('0x4d')]({'where':{'id':_0x35fe1a[_0xf5f2('0x51')]['id']}})['then'](handleEntityNotFound(_0x37c1a1,null))['then'](function(_0x2076c7){if(_0x2076c7){return _0x2076c7[_0xf5f2('0x6e')](_0x35fe1a[_0xf5f2('0x4c')][_0xf5f2('0x59')],_['omit'](_0x35fe1a[_0xf5f2('0x4c')],[_0xf5f2('0x59'),'id'])||{});}})[_0xf5f2('0x16')](respondWithResult(_0x37c1a1,null))[_0xf5f2('0x4a')](handleError(_0x37c1a1,null));};exports[_0xf5f2('0x70')]=function(_0x591325,_0xf7885f,_0x18d727){var _0x4bdb72={'raw':![],'where':{}};var _0x4511f4={};var _0x3ff714={'count':0x0,'rows':[]};return db[_0xf5f2('0x31')][_0xf5f2('0x55')]({'where':{'id':_0x591325['params']['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0xf7885f,null))[_0xf5f2('0x16')](function(_0x261f15){if(_0x261f15){_0x4511f4['model']=_['keys'](db[_0xf5f2('0x6f')][_0xf5f2('0x32')]);_0x4511f4[_0xf5f2('0x33')]=_[_0xf5f2('0x36')](_0x591325[_0xf5f2('0x33')]);_0x4511f4[_0xf5f2('0x37')]=_['intersection'](_0x4511f4[_0xf5f2('0x30')],_0x4511f4['query']);_0x4bdb72[_0xf5f2('0x39')]=_[_0xf5f2('0x38')](_0x4511f4[_0xf5f2('0x30')],qs[_0xf5f2('0x3a')](_0x591325[_0xf5f2('0x33')][_0xf5f2('0x3a')]));_0x4bdb72['attributes']=_0x4bdb72[_0xf5f2('0x39')][_0xf5f2('0x3b')]?_0x4bdb72[_0xf5f2('0x39')]:_0x4511f4[_0xf5f2('0x30')];if(!_0x591325[_0xf5f2('0x33')][_0xf5f2('0x56')](_0xf5f2('0x3c'))){_0x4bdb72['limit']=qs[_0xf5f2('0x26')](_0x591325['query']['limit']);_0x4bdb72['offset']=qs[_0xf5f2('0x25')](_0x591325[_0xf5f2('0x33')]['offset']);}_0x4bdb72[_0xf5f2('0x3d')]=qs[_0xf5f2('0x3e')](_0x591325[_0xf5f2('0x33')][_0xf5f2('0x3e')]);_0x4bdb72['where']=qs[_0xf5f2('0x37')](_[_0xf5f2('0x71')](_0x591325[_0xf5f2('0x33')],_0x4511f4['filters']));_0x4bdb72[_0xf5f2('0x3f')][_0xf5f2('0x52')]=_0x261f15['id'];if(_0x591325['query'][_0xf5f2('0x43')]){_0x4bdb72[_0xf5f2('0x3f')]=_[_0xf5f2('0x42')](_0x4bdb72[_0xf5f2('0x3f')],{'$or':_[_0xf5f2('0x57')](_0x4bdb72[_0xf5f2('0x39')],function(_0xd08e70){var _0x2c242b={};_0x2c242b[_0xd08e70]={'$like':'%'+_0x591325[_0xf5f2('0x33')][_0xf5f2('0x43')]+'%'};return _0x2c242b;})});}_0x4bdb72=_[_0xf5f2('0x42')]({},_0x4bdb72,_0x591325['options']);return db[_0xf5f2('0x6f')][_0xf5f2('0x24')]({'where':_0x4bdb72['where']})[_0xf5f2('0x16')](function(_0x588444){_0x3ff714[_0xf5f2('0x24')]=_0x588444;if(_0x591325[_0xf5f2('0x33')][_0xf5f2('0x48')]){_0x4bdb72[_0xf5f2('0x44')]=[{'model':db['CmContact'],'as':_0xf5f2('0x72'),'required':![]},{'model':db['User'],'as':_0xf5f2('0x73'),'attributes':['name',_0xf5f2('0x74'),_0xf5f2('0x75')],'required':![]},{'model':db['Tag'],'as':_0xf5f2('0x76'),'attributes':['id',_0xf5f2('0x2b'),_0xf5f2('0x77')],'where':_0x591325[_0xf5f2('0x33')][_0xf5f2('0x78')]?{'id':_0x591325[_0xf5f2('0x33')]['tag']}:undefined,'required':_0x591325['query'][_0xf5f2('0x78')]?!![]:![]}];}return db[_0xf5f2('0x6f')]['findAll'](_0x4bdb72);})[_0xf5f2('0x16')](function(_0x29ff42){_0x3ff714[_0xf5f2('0x46')]=_0x29ff42;return _0x3ff714;});}})[_0xf5f2('0x16')](respondWithFilteredResult(_0xf7885f,_0x4bdb72))[_0xf5f2('0x4a')](handleError(_0xf7885f,null));};exports[_0xf5f2('0x79')]=function(_0x475425,_0x4f9e2d,_0x1744b3){return db['MailAccount'][_0xf5f2('0x55')]({'where':{'id':_0x475425['params']['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x4f9e2d,null))['then'](function(_0xc51962){if(_0xc51962){return db['sequelize']['transaction'](function(_0x2c285c){return db[_0xf5f2('0x7a')]['destroy']({'where':{'MailAccountId':_0x475425[_0xf5f2('0x51')]['id']},'transaction':_0x2c285c})[_0xf5f2('0x16')](function(_0x2c7ab9){var _0x3a76f4=_[_0xf5f2('0x57')](_0x475425[_0xf5f2('0x4c')],function(_0xd0b5d){_0xd0b5d[_0xf5f2('0x52')]=_0x475425['params']['id'];return _0xd0b5d;});return db['MailApplication'][_0xf5f2('0x7b')](_0x3a76f4,{'transaction':_0x2c285c});});})['then'](function(){return db[_0xf5f2('0x7a')][_0xf5f2('0x7c')]({'where':{'MailAccountId':_0x475425[_0xf5f2('0x51')]['id']},'order':_0xf5f2('0x7d')});});}})[_0xf5f2('0x16')](respondWithResult(_0x4f9e2d,null))[_0xf5f2('0x4a')](handleError(_0x4f9e2d,null));};exports[_0xf5f2('0x7e')]=function(_0x63dc22,_0x28f65b,_0x16cbd3){var _0x275fb7={};var _0x1e8c73={};var _0x4ff443;var _0x960dbc;return db['MailAccount'][_0xf5f2('0x55')]({'where':{'id':_0x63dc22[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x28f65b,null))[_0xf5f2('0x16')](function(_0x3644c9){if(_0x3644c9){_0x4ff443=_0x3644c9;_0x1e8c73[_0xf5f2('0x30')]=_[_0xf5f2('0x36')](db[_0xf5f2('0x7a')][_0xf5f2('0x32')]);_0x1e8c73[_0xf5f2('0x33')]=_[_0xf5f2('0x36')](_0x63dc22['query']);_0x1e8c73[_0xf5f2('0x37')]=_[_0xf5f2('0x38')](_0x1e8c73[_0xf5f2('0x30')],_0x1e8c73[_0xf5f2('0x33')]);_0x275fb7[_0xf5f2('0x39')]=_[_0xf5f2('0x38')](_0x1e8c73[_0xf5f2('0x30')],qs['fields'](_0x63dc22[_0xf5f2('0x33')][_0xf5f2('0x3a')]));_0x275fb7[_0xf5f2('0x39')]=_0x275fb7[_0xf5f2('0x39')][_0xf5f2('0x3b')]?_0x275fb7[_0xf5f2('0x39')]:_0x1e8c73[_0xf5f2('0x30')];_0x275fb7[_0xf5f2('0x3d')]=qs[_0xf5f2('0x3e')](_0x63dc22[_0xf5f2('0x33')][_0xf5f2('0x3e')]);_0x275fb7[_0xf5f2('0x3f')]=qs[_0xf5f2('0x37')](_[_0xf5f2('0x71')](_0x63dc22[_0xf5f2('0x33')],_0x1e8c73[_0xf5f2('0x37')]));if(_0x63dc22['query'][_0xf5f2('0x43')]){_0x275fb7[_0xf5f2('0x3f')]=_['merge'](_0x275fb7['where'],{'$or':_[_0xf5f2('0x57')](_0x275fb7[_0xf5f2('0x39')],function(_0x41b8bd){var _0x2c8f4c={};_0x2c8f4c[_0x41b8bd]={'$like':'%'+_0x63dc22['query'][_0xf5f2('0x43')]+'%'};return _0x2c8f4c;})});}_0x275fb7=_[_0xf5f2('0x42')]({},_0x275fb7,_0x63dc22[_0xf5f2('0x49')]);return _0x4ff443[_0xf5f2('0x7e')](_0x275fb7);}})[_0xf5f2('0x16')](function(_0x1e0b63){if(_0x1e0b63){_0x960dbc=_0x1e0b63['length'];if(!_0x63dc22[_0xf5f2('0x33')]['hasOwnProperty']('nolimit')){_0x275fb7[_0xf5f2('0x26')]=qs[_0xf5f2('0x26')](_0x63dc22[_0xf5f2('0x33')][_0xf5f2('0x26')]);_0x275fb7[_0xf5f2('0x25')]=qs[_0xf5f2('0x25')](_0x63dc22[_0xf5f2('0x33')]['offset']);}return _0x4ff443[_0xf5f2('0x7e')](_0x275fb7);}})[_0xf5f2('0x16')](function(_0x2c1160){if(_0x2c1160){return _0x2c1160?{'count':_0x960dbc,'rows':_0x2c1160}:null;}})['then'](respondWithResult(_0x28f65b,null))[_0xf5f2('0x4a')](handleError(_0x28f65b,null));};exports['addDisposition']=function(_0x569a45,_0x221d3a,_0x587a0c){if(_0x569a45[_0xf5f2('0x4c')]['id']){delete _0x569a45[_0xf5f2('0x4c')]['id'];}return db['MailAccount'][_0xf5f2('0x4d')]({'where':{'id':_0x569a45[_0xf5f2('0x51')]['id']}})['then'](handleEntityNotFound(_0x221d3a,null))[_0xf5f2('0x16')](function(_0xf60679){if(_0xf60679){_0x569a45[_0xf5f2('0x4c')][_0xf5f2('0x52')]=_0xf60679['id'];return db[_0xf5f2('0x7f')]['create'](_0x569a45[_0xf5f2('0x4c')]);}})[_0xf5f2('0x16')](respondWithResult(_0x221d3a,null))['catch'](handleError(_0x221d3a,null));};exports['addDispositions']=function(_0x3dd6e8,_0x37f2f1,_0x2d3ed2){return db[_0xf5f2('0x80')][_0xf5f2('0x4d')]({'where':{'id':_0x3dd6e8[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x37f2f1,null))[_0xf5f2('0x16')](function(_0x484341){if(_0x484341){return _0x484341['addDispositions'](_0x3dd6e8[_0xf5f2('0x4c')]['ids'],_[_0xf5f2('0x81')](_0x3dd6e8[_0xf5f2('0x4c')],[_0xf5f2('0x59'),'id'])||{});}})[_0xf5f2('0x16')](respondWithResult(_0x37f2f1,null))['catch'](handleError(_0x37f2f1,null));};exports[_0xf5f2('0x82')]=function(_0x2c9a1b,_0x29cb4b,_0x1ed9aa){var _0x77e9b9={};var _0x48f1ae={};var _0xe45e4a;var _0x2ee157;return db[_0xf5f2('0x31')][_0xf5f2('0x55')]({'where':{'id':_0x2c9a1b[_0xf5f2('0x51')]['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x29cb4b,null))[_0xf5f2('0x16')](function(_0x3f7f3b){if(_0x3f7f3b){_0xe45e4a=_0x3f7f3b;_0x48f1ae[_0xf5f2('0x30')]=_[_0xf5f2('0x36')](db[_0xf5f2('0x7f')][_0xf5f2('0x32')]);_0x48f1ae['query']=_[_0xf5f2('0x36')](_0x2c9a1b['query']);_0x48f1ae[_0xf5f2('0x37')]=_[_0xf5f2('0x38')](_0x48f1ae[_0xf5f2('0x30')],_0x48f1ae[_0xf5f2('0x33')]);_0x77e9b9[_0xf5f2('0x39')]=_[_0xf5f2('0x38')](_0x48f1ae[_0xf5f2('0x30')],qs[_0xf5f2('0x3a')](_0x2c9a1b[_0xf5f2('0x33')][_0xf5f2('0x3a')]));_0x77e9b9[_0xf5f2('0x39')]=_0x77e9b9[_0xf5f2('0x39')][_0xf5f2('0x3b')]?_0x77e9b9[_0xf5f2('0x39')]:_0x48f1ae[_0xf5f2('0x30')];_0x77e9b9[_0xf5f2('0x3d')]=qs[_0xf5f2('0x3e')](_0x2c9a1b[_0xf5f2('0x33')]['sort']);_0x77e9b9[_0xf5f2('0x3f')]=qs['filters'](_['pick'](_0x2c9a1b[_0xf5f2('0x33')],_0x48f1ae[_0xf5f2('0x37')]));if(_0x2c9a1b['query'][_0xf5f2('0x43')]){_0x77e9b9[_0xf5f2('0x3f')]=_[_0xf5f2('0x42')](_0x77e9b9[_0xf5f2('0x3f')],{'$or':_[_0xf5f2('0x57')](_0x77e9b9[_0xf5f2('0x39')],function(_0x228e5a){var _0x82580e={};_0x82580e[_0x228e5a]={'$like':'%'+_0x2c9a1b['query'][_0xf5f2('0x43')]+'%'};return _0x82580e;})});}_0x77e9b9=_[_0xf5f2('0x42')]({},_0x77e9b9,_0x2c9a1b[_0xf5f2('0x49')]);return _0xe45e4a['getDispositions'](_0x77e9b9);}})[_0xf5f2('0x16')](function(_0x889002){if(_0x889002){_0x2ee157=_0x889002[_0xf5f2('0x3b')];if(!_0x2c9a1b[_0xf5f2('0x33')]['hasOwnProperty']('nolimit')){_0x77e9b9[_0xf5f2('0x26')]=qs[_0xf5f2('0x26')](_0x2c9a1b[_0xf5f2('0x33')][_0xf5f2('0x26')]);_0x77e9b9[_0xf5f2('0x25')]=qs[_0xf5f2('0x25')](_0x2c9a1b[_0xf5f2('0x33')][_0xf5f2('0x25')]);}return _0xe45e4a[_0xf5f2('0x82')](_0x77e9b9);}})[_0xf5f2('0x16')](function(_0x59070b){if(_0x59070b){return _0x59070b?{'count':_0x2ee157,'rows':_0x59070b}:null;}})[_0xf5f2('0x16')](respondWithResult(_0x29cb4b,null))[_0xf5f2('0x4a')](handleError(_0x29cb4b,null));};exports[_0xf5f2('0x83')]=function(_0x540e2c,_0x3f9d1d,_0x4a3ff){var _0x51f883={'raw':!![],'where':{}};var _0x3096d7={};var _0x4fc28b={'count':0x0,'rows':[]};return db[_0xf5f2('0x31')][_0xf5f2('0x55')]({'where':{'id':_0x540e2c['params']['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x3f9d1d,null))['then'](function(_0x3815bf){if(_0x3815bf){_0x3096d7[_0xf5f2('0x30')]=_['keys'](db[_0xf5f2('0x84')][_0xf5f2('0x32')]);_0x3096d7[_0xf5f2('0x33')]=_[_0xf5f2('0x36')](_0x540e2c[_0xf5f2('0x33')]);_0x3096d7['filters']=_[_0xf5f2('0x38')](_0x3096d7[_0xf5f2('0x30')],_0x3096d7[_0xf5f2('0x33')]);_0x51f883[_0xf5f2('0x39')]=_[_0xf5f2('0x38')](_0x3096d7[_0xf5f2('0x30')],qs[_0xf5f2('0x3a')](_0x540e2c[_0xf5f2('0x33')][_0xf5f2('0x3a')]));_0x51f883['attributes']=_0x51f883[_0xf5f2('0x39')]['length']?_0x51f883['attributes']:_0x3096d7[_0xf5f2('0x30')];if(!_0x540e2c[_0xf5f2('0x33')][_0xf5f2('0x56')](_0xf5f2('0x3c'))){_0x51f883[_0xf5f2('0x26')]=qs[_0xf5f2('0x26')](_0x540e2c[_0xf5f2('0x33')][_0xf5f2('0x26')]);_0x51f883[_0xf5f2('0x25')]=qs[_0xf5f2('0x25')](_0x540e2c['query']['offset']);}_0x51f883['order']=qs[_0xf5f2('0x3e')](_0x540e2c['query'][_0xf5f2('0x3e')]);_0x51f883[_0xf5f2('0x3f')]=qs[_0xf5f2('0x37')](_['pick'](_0x540e2c[_0xf5f2('0x33')],_0x3096d7[_0xf5f2('0x37')]));_0x51f883['where']['MailAccountId']=_0x3815bf['id'];if(_0x540e2c['query'][_0xf5f2('0x43')]){_0x51f883[_0xf5f2('0x3f')]=_[_0xf5f2('0x42')](_0x51f883['where'],{'$or':_[_0xf5f2('0x57')](_0x51f883['attributes'],function(_0x7cf1b6){var _0x103c39={};_0x103c39[_0x7cf1b6]={'$like':'%'+_0x540e2c[_0xf5f2('0x33')]['filter']+'%'};return _0x103c39;})});}if(_0x540e2c[_0xf5f2('0x33')]['$gte']){var _0x1b88b5=_0x540e2c[_0xf5f2('0x33')][_0xf5f2('0x85')]['split'](',');var _0x38217e={};_0x38217e[_0x1b88b5[0x0]]={'$gte':moment(_0x1b88b5[0x1])[_0xf5f2('0x86')]('YYYY-MM-DD\x20HH:mm:ss')};_0x51f883[_0xf5f2('0x3f')]=_[_0xf5f2('0x42')](_0x51f883[_0xf5f2('0x3f')],_0x38217e);}_0x51f883=_[_0xf5f2('0x42')]({},_0x51f883,_0x540e2c[_0xf5f2('0x49')]);return db[_0xf5f2('0x84')][_0xf5f2('0x24')]({'where':_0x51f883[_0xf5f2('0x3f')]})[_0xf5f2('0x16')](function(_0x2cbe4d){_0x4fc28b[_0xf5f2('0x24')]=_0x2cbe4d;if(_0x540e2c[_0xf5f2('0x33')][_0xf5f2('0x48')]){_0x51f883[_0xf5f2('0x44')]=[{'all':!![]}];}return db[_0xf5f2('0x84')][_0xf5f2('0x45')](_0x51f883);})[_0xf5f2('0x16')](function(_0x129e10){_0x4fc28b[_0xf5f2('0x46')]=_0x129e10;return _0x4fc28b;});}})[_0xf5f2('0x16')](respondWithFilteredResult(_0x3f9d1d,_0x51f883))[_0xf5f2('0x4a')](handleError(_0x3f9d1d,null));};exports[_0xf5f2('0x2c')]=function(_0x4f1006,_0x22964e,_0xc089a6){var _0x44f031,_0x3c8cb8={},_0x533da4;if(_0x4f1006[_0xf5f2('0x4c')]['to']){_0x533da4=_0x4f1006['body']['to'][_0xf5f2('0x87')](',')[0x0];}return db[_0xf5f2('0x31')][_0xf5f2('0x4d')]({'where':{'id':_0x4f1006[_0xf5f2('0x51')]['id']},'include':[{'model':db[_0xf5f2('0x88')],'as':_0xf5f2('0x89'),'include':[{'model':db[_0xf5f2('0x8a')],'as':'Contacts','where':{'email':_0x533da4},'limit':0x1,'order':[['updatedAt',_0xf5f2('0x8b')]]}]},{'model':db[_0xf5f2('0x2f')],'as':_0xf5f2('0x4e'),'raw':!![]}]})[_0xf5f2('0x16')](handleEntityNotFound(_0x22964e,null))['then'](function(_0x2428d5){if(_0x2428d5){_0x44f031=_0x2428d5;if(_0x2428d5[_0xf5f2('0x4e')]){if(_[_0xf5f2('0x5c')](_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x8c')])){_0x4f1006[_0xf5f2('0x4c')]['from']=util['format']('\x22%s\x22\x20<%s>',_0x2428d5[_0xf5f2('0x2b')],_0x2428d5[_0xf5f2('0x5a')]||_0x2428d5[_0xf5f2('0x4e')]['user']);}if(_0x4f1006[_0xf5f2('0x4c')]['attachments']&&_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x8d')][_0xf5f2('0x3b')]){for(var _0x3608d7=0x0;_0x3608d7<_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x8d')][_0xf5f2('0x3b')];_0x3608d7+=0x1){_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x8d')][_0x3608d7]={'filename':_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x8d')][_0x3608d7][_0xf5f2('0x2b')],'path':path[_0xf5f2('0x8e')](config[_0xf5f2('0x8f')],'server/files/attachments',_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x8d')][_0x3608d7][_0xf5f2('0x90')])};}}var _0xb15998={'tls':{'rejectUnauthorized':![]}};if(_['isNil'](_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x64')])){if(_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x61')]){_0xb15998['auth']={'user':_0x2428d5[_0xf5f2('0x4e')]['user'],'pass':_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x91')]};}_0xb15998[_0xf5f2('0x62')]=_0x2428d5[_0xf5f2('0x4e')]['host'];_0xb15998[_0xf5f2('0x63')]=_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x63')];_0xb15998[_0xf5f2('0x92')]=_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x92')];}else{_0xb15998['service']=_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x64')];_0xb15998[_0xf5f2('0x93')]={'user':_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x5e')],'pass':_0x2428d5[_0xf5f2('0x4e')][_0xf5f2('0x91')]};}return respondWithRpcPromise(_0xf5f2('0x94'),_0xf5f2('0x95'),{'account':_0xb15998,'message':_0x4f1006['body']});}else{throw new Error(_0xf5f2('0x96'));}}})[_0xf5f2('0x16')](function(_0x35a983){if(_0x35a983){_0x3c8cb8=_0x35a983;if(_0x44f031[_0xf5f2('0x89')]){if(_0x44f031['List']['Contacts'][_0xf5f2('0x3b')]){return _0x44f031[_0xf5f2('0x89')][_0xf5f2('0x97')][0x0];}else{return db['CmContact']['create'](_[_0xf5f2('0x98')](_0x4f1006[_0xf5f2('0x4c')],{'firstName':_0x4f1006[_0xf5f2('0x4c')]['to'],'email':_0x4f1006[_0xf5f2('0x4c')]['to'],'phone':_0x4f1006[_0xf5f2('0x4c')]['to'],'ListId':_0x44f031[_0xf5f2('0x5b')]}));}}else{throw new Error('List\x20not\x20found');}}})[_0xf5f2('0x16')](function(_0x30f6d7){if(_0x30f6d7){var _0x1c18a0={'UserId':_0x4f1006[_0xf5f2('0x5e')]['id'],'ContactId':_0x30f6d7['id'],'MailAccountId':_0x44f031['id'],'inReplyTo':_0x3c8cb8['messageId'],'to':_0x4f1006['body'][_0xf5f2('0x8c')],'cc':_0x4f1006['body']['cc'],'subject':_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x99')],'attach':_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x9a')],'firstMsgDirection':_0xf5f2('0x9b'),'lastMsgAt':moment()[_0xf5f2('0x86')](_0xf5f2('0x9c')),'lastMsgDirection':_0xf5f2('0x9b'),'lastMsgBody':_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x4c')],'Messages':[_[_0xf5f2('0x42')](_0x4f1006[_0xf5f2('0x4c')],{'messageId':_0x3c8cb8[_0xf5f2('0x9d')],'sentAt':moment()[_0xf5f2('0x86')]('YYYY-MM-DD\x20HH:mm:ss'),'read':!![],'MailAccountId':_0x44f031['id'],'UserId':_0x4f1006[_0xf5f2('0x5e')]['id'],'ContactId':_0x30f6d7['id']})]};if(_0x4f1006[_0xf5f2('0x4c')][_0xf5f2('0x9e')]){_0x1c18a0=_[_0xf5f2('0x42')](_0x1c18a0,_0x4f1006[_0xf5f2('0x4c')]['Interaction']);}return db[_0xf5f2('0x6f')][_0xf5f2('0x54')](_0x1c18a0,{'include':[{'model':db['MailMessage'],'as':_0xf5f2('0x9f')}]});}})[_0xf5f2('0x16')](respondWithResult(_0x22964e,null))['catch'](handleError(_0x22964e,null));};exports['verifySmtp']=function(_0xd04990,_0x305b07,_0x3e7f54){return db['MailAccount']['find']({'where':{'id':_0xd04990[_0xf5f2('0x51')]['id']},'include':[{'model':db[_0xf5f2('0x2f')],'as':_0xf5f2('0x4e'),'raw':!![]}]})[_0xf5f2('0x16')](handleEntityNotFound(_0x305b07,null))[_0xf5f2('0x16')](function(_0xac4331){if(_0xac4331&&_0xac4331[_0xf5f2('0x4e')]){var _0x461618={'id':_0xac4331['id'],'tls':{'rejectUnauthorized':![]}};if(_0xac4331[_0xf5f2('0x4e')][_0xf5f2('0x64')]){_0x461618['service']=_0xac4331[_0xf5f2('0x4e')][_0xf5f2('0x64')];}else{_0x461618['host']=_0xac4331[_0xf5f2('0x4e')][_0xf5f2('0x62')];_0x461618[_0xf5f2('0x63')]=_0xac4331[_0xf5f2('0x4e')][_0xf5f2('0x63')];_0x461618['secure']=_0xac4331['Smtp'][_0xf5f2('0x92')];}if(_0xac4331[_0xf5f2('0x4e')][_0xf5f2('0x61')]){_0x461618[_0xf5f2('0x93')]={'user':_0xac4331['Smtp'][_0xf5f2('0x5e')],'pass':_0xac4331[_0xf5f2('0x4e')][_0xf5f2('0x91')]};}return respondWithRpcPromise(_0xf5f2('0xa0'),'verifySmtp',{'account':_0x461618});}})['then'](respondWithResult(_0x305b07,null))['catch'](handleError(_0x305b07,null));};exports['destroy']=function(_0x2e9d3b,_0x496802){return db['MailAccount']['find']({'where':{'id':_0x2e9d3b['params']['id']}})[_0xf5f2('0x16')](handleEntityNotFound(_0x496802,null))['then'](function(_0x4b6023){if(_0x4b6023&&_0x4b6023[_0xf5f2('0x64')]){throw new db[(_0xf5f2('0xa1'))][(_0xf5f2('0xa2'))](_0xf5f2('0xa3'));}return _0x4b6023;})['then'](removeEntity(_0x496802,null))[_0xf5f2('0x4a')](handleError(_0x496802,null));};