Built motion from commit 58b0471d.|2.6.29
[motion2.git] / server / services / email / lib / imap.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 _0xcd11=['box','readUnseen','handleCloseBox','end','search','handleReadUnseen','length','fetch','message','error','handleFetchError','handleFetchEnd','closeBox','handleMessageBody','attributes','handleMessageAttributes','handleSimpleParser','handleMessageEnd','stringify','textCode','hasOwnProperty','upperFirst','lodash','util','imap','mailparser','iconv','Iconv','events','./utils','../../../config/logger','email','mailbox','account','getAccount','once','ready','handleReady','bind','handleEnd','handleError','connect','prototype','connTimeout','authTimeout','user','modernAuthentication','generateXOAuth2Token','CloudProvider','data5','password','anonymous@xcally.com','host','port','tls','required','openBox','handleOpenBox','emit'];(function(_0x10635a,_0x320f30){var _0x2e3b5b=function(_0x51668a){while(--_0x51668a){_0x10635a['push'](_0x10635a['shift']());}};_0x2e3b5b(++_0x320f30);}(_0xcd11,0x102));var _0x1cd1=function(_0x4e265f,_0x34beac){_0x4e265f=_0x4e265f-0x0;var _0x30375f=_0xcd11[_0x4e265f];return _0x30375f;};'use strict';var _=require(_0x1cd1('0x0'));var util=require(_0x1cd1('0x1'));var Imap=require(_0x1cd1('0x2'));var simpleParser=require(_0x1cd1('0x3'))['simpleParser'];var Iconv=require(_0x1cd1('0x4'))[_0x1cd1('0x5')];var EventEmitter=require(_0x1cd1('0x6'))['EventEmitter'];var utils=require(_0x1cd1('0x7'));var logger=require(_0x1cd1('0x8'))(_0x1cd1('0x9'));function EmailImap(_0x27e7f8,_0x1bbe9d){this[_0x1cd1('0xa')]=_0x27e7f8[_0x1cd1('0xa')];this[_0x1cd1('0xb')]=this[_0x1cd1('0xc')](_0x27e7f8,_0x1bbe9d);this[_0x1cd1('0x2')]=new Imap(this['account']);this[_0x1cd1('0x2')][_0x1cd1('0xd')](_0x1cd1('0xe'),this[_0x1cd1('0xf')][_0x1cd1('0x10')](this));this[_0x1cd1('0x2')]['once']('end',this[_0x1cd1('0x11')]['bind'](this));this[_0x1cd1('0x2')]['on']('error',this[_0x1cd1('0x12')][_0x1cd1('0x10')](this));this[_0x1cd1('0x2')][_0x1cd1('0x13')]();}util['inherits'](EmailImap,EventEmitter);EmailImap[_0x1cd1('0x14')][_0x1cd1('0xc')]=function(_0x1a71e8,_0x326cec){var _0x3509c5={'connTimeout':_0x1a71e8[_0x1cd1('0x15')]?_0x1a71e8[_0x1cd1('0x15')]*0x3e8:0x2710,'authTimeout':_0x1a71e8[_0x1cd1('0x16')]?_0x1a71e8['authTimeout']*0x3e8:0x1388};if(_0x1a71e8['service']){_0x3509c5[_0x1cd1('0x17')]=_0x1a71e8[_0x1cd1('0x17')];if(_0x1a71e8[_0x1cd1('0x18')]){_0x3509c5['xoauth2']=utils[_0x1cd1('0x19')](_0x1a71e8[_0x1cd1('0x1a')][_0x1cd1('0x1b')],_0x1a71e8[_0x1cd1('0x17')]);}else{_0x3509c5[_0x1cd1('0x1c')]=_0x1a71e8['password'];}}else{if(_0x1a71e8['authentication']){_0x3509c5[_0x1cd1('0x17')]=_0x1a71e8[_0x1cd1('0x17')];_0x3509c5[_0x1cd1('0x1c')]=_0x1a71e8[_0x1cd1('0x1c')];}}_0x3509c5['email']=_0x326cec||_0x1a71e8[_0x1cd1('0x17')]||_0x1cd1('0x1d');_0x3509c5[_0x1cd1('0x1e')]=_0x1a71e8[_0x1cd1('0x1e')];_0x3509c5[_0x1cd1('0x1f')]=_0x1a71e8[_0x1cd1('0x1f')]||0x3e1;if(_0x1a71e8[_0x1cd1('0x20')]){_0x3509c5[_0x1cd1('0x20')]=!![];}else{_0x3509c5[_0x1cd1('0x20')]=![];_0x3509c5['autotls']=_0x1cd1('0x21');}return _0x3509c5;};EmailImap['prototype'][_0x1cd1('0xf')]=function(){this[_0x1cd1('0x2')][_0x1cd1('0x22')](this[_0x1cd1('0xa')],![],this[_0x1cd1('0x23')][_0x1cd1('0x10')](this));};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x23')]=function(_0x4898d5,_0x5e6ee0){if(_0x4898d5){this[_0x1cd1('0x12')](_0x4898d5,!![]);}else{this[_0x1cd1('0x24')](_0x1cd1('0x25'),_0x5e6ee0);this[_0x1cd1('0x26')]();}};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x27')]=function(_0x448ad2){if(_0x448ad2){this[_0x1cd1('0x12')](_0x448ad2,!![]);}else{this[_0x1cd1('0x2')][_0x1cd1('0x28')]();}};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x26')]=function(){this[_0x1cd1('0x2')][_0x1cd1('0x29')](['UNSEEN'],this[_0x1cd1('0x2a')][_0x1cd1('0x10')](this));};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x2a')]=function(_0x1c048e,_0x3a405d){if(_0x1c048e){this[_0x1cd1('0x12')](_0x1c048e,!![]);}else{if(_0x3a405d[_0x1cd1('0x2b')]){try{var _0x2f7620=this[_0x1cd1('0x2')][_0x1cd1('0x2c')](_0x3a405d,{'bodies':'','markSeen':!![]});_0x2f7620['on'](_0x1cd1('0x2d'),this['handleFetchMessage']['bind'](this));_0x2f7620['once'](_0x1cd1('0x2e'),this[_0x1cd1('0x2f')][_0x1cd1('0x10')](this));_0x2f7620[_0x1cd1('0xd')](_0x1cd1('0x28'),this[_0x1cd1('0x30')]['bind'](this));}catch(_0x4b6782){logger[_0x1cd1('0x2e')](_0x4b6782);}}else{this[_0x1cd1('0x2')][_0x1cd1('0x31')](!![],this[_0x1cd1('0x27')][_0x1cd1('0x10')](this));}}};EmailImap[_0x1cd1('0x14')]['handleFetchMessage']=function(_0x2e5ea8){_0x2e5ea8['on']('body',this[_0x1cd1('0x32')][_0x1cd1('0x10')](this));_0x2e5ea8[_0x1cd1('0xd')](_0x1cd1('0x33'),this[_0x1cd1('0x34')][_0x1cd1('0x10')](this));_0x2e5ea8[_0x1cd1('0xd')](_0x1cd1('0x28'),this['handleMessageEnd'][_0x1cd1('0x10')](this));};EmailImap[_0x1cd1('0x14')]['handleMessageBody']=function(_0x231a42){simpleParser(_0x231a42,{'Iconv':Iconv},this[_0x1cd1('0x35')][_0x1cd1('0x10')](this));};EmailImap[_0x1cd1('0x14')]['handleMessageAttributes']=function(){};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x36')]=function(){};EmailImap['prototype'][_0x1cd1('0x35')]=function(_0x2e5b48,_0x2e4645){if(_0x2e5b48){logger['error'](_0x2e5b48);}else{var _0x8fc04f=this;utils['parser'](this[_0x1cd1('0xb')],_0x2e4645,function(_0x15c43c){_0x8fc04f[_0x1cd1('0x24')](_0x1cd1('0x9'),_0x15c43c);});}};EmailImap[_0x1cd1('0x14')]['handleFetchEnd']=function(){this[_0x1cd1('0x2')]['closeBox'](!![],this[_0x1cd1('0x27')][_0x1cd1('0x10')](this));};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x2f')]=function(_0x132fe5){this[_0x1cd1('0x12')](_0x132fe5);this[_0x1cd1('0x2')][_0x1cd1('0x31')](!![],this['handleCloseBox'][_0x1cd1('0x10')](this));};EmailImap[_0x1cd1('0x14')][_0x1cd1('0x11')]=function(){this[_0x1cd1('0x24')]('end');};EmailImap[_0x1cd1('0x14')]['handleError']=function(_0x37217f,_0x399420){logger[_0x1cd1('0x2e')](_0x1cd1('0x12'),this['account'][_0x1cd1('0x9')],JSON[_0x1cd1('0x37')](_0x37217f));var _0x22fcbb='';if(_0x37217f){if(_0x37217f[_0x1cd1('0x38')]){_0x22fcbb=_0x37217f[_0x1cd1('0x38')];}else{for(var _0x2f0963 in _0x37217f){if(_0x37217f[_0x1cd1('0x39')](_0x2f0963)){_0x22fcbb+=_[_0x1cd1('0x3a')](_0x2f0963)+':\x20'+_0x37217f[_0x2f0963]+'\x0a';}}}}if(_0x399420){this[_0x1cd1('0x2')][_0x1cd1('0x28')]();}else{this[_0x1cd1('0x24')]('error',_0x22fcbb);this[_0x1cd1('0x24')](_0x1cd1('0x28'));}};module['exports']=EmailImap;