acc32d84372b15d9d7ca419127b7ca5f02c15eb7
[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 _0xe0d5=['util','imap','iconv','Iconv','events','EventEmitter','./utils','../../../config/logger','email','mailbox','account','getAccount','once','handleReady','bind','handleEnd','error','handleError','connect','prototype','connTimeout','authTimeout','user','modernAuthentication','xoauth2','CloudProvider','data5','password','anonymous@xcally.com','host','tls','openBox','handleOpenBox','box','readUnseen','handleCloseBox','end','search','UNSEEN','handleReadUnseen','length','fetch','slice','message','handleFetchMessage','handleFetchError','body','handleMessageBody','handleMessageAttributes','handleMessageEnd','handleSimpleParser','parser','emit','handleFetchEnd','closeBox','stringify','textCode','hasOwnProperty','exports','lodash'];(function(_0x2788b2,_0x4e735c){var _0xbca93f=function(_0x4dccf8){while(--_0x4dccf8){_0x2788b2['push'](_0x2788b2['shift']());}};_0xbca93f(++_0x4e735c);}(_0xe0d5,0xb3));var _0x5e0d=function(_0x23d3dd,_0x3be1be){_0x23d3dd=_0x23d3dd-0x0;var _0x872358=_0xe0d5[_0x23d3dd];return _0x872358;};'use strict';var _=require(_0x5e0d('0x0'));var util=require(_0x5e0d('0x1'));var Imap=require(_0x5e0d('0x2'));var simpleParser=require('mailparser')['simpleParser'];var Iconv=require(_0x5e0d('0x3'))[_0x5e0d('0x4')];var EventEmitter=require(_0x5e0d('0x5'))[_0x5e0d('0x6')];var utils=require(_0x5e0d('0x7'));var logger=require(_0x5e0d('0x8'))(_0x5e0d('0x9'));function EmailImap(_0x33e044,_0x4cc05c){this['mailbox']=_0x33e044[_0x5e0d('0xa')];this[_0x5e0d('0xb')]=this[_0x5e0d('0xc')](_0x33e044,_0x4cc05c);this[_0x5e0d('0x2')]=new Imap(this[_0x5e0d('0xb')]);this[_0x5e0d('0x2')][_0x5e0d('0xd')]('ready',this[_0x5e0d('0xe')][_0x5e0d('0xf')](this));this[_0x5e0d('0x2')][_0x5e0d('0xd')]('end',this[_0x5e0d('0x10')][_0x5e0d('0xf')](this));this[_0x5e0d('0x2')]['on'](_0x5e0d('0x11'),this[_0x5e0d('0x12')][_0x5e0d('0xf')](this));this[_0x5e0d('0x2')][_0x5e0d('0x13')]();}util['inherits'](EmailImap,EventEmitter);EmailImap[_0x5e0d('0x14')][_0x5e0d('0xc')]=function(_0x6db885,_0x27f68b){var _0x3d1d14={'connTimeout':_0x6db885['connTimeout']?_0x6db885[_0x5e0d('0x15')]*0x3e8:0x2710,'authTimeout':_0x6db885['authTimeout']?_0x6db885[_0x5e0d('0x16')]*0x3e8:0x1388};if(_0x6db885['service']){_0x3d1d14[_0x5e0d('0x17')]=_0x6db885[_0x5e0d('0x17')];if(_0x6db885[_0x5e0d('0x18')]){_0x3d1d14[_0x5e0d('0x19')]=utils['generateXOAuth2Token'](_0x6db885[_0x5e0d('0x1a')][_0x5e0d('0x1b')],_0x6db885['user']);}else{_0x3d1d14[_0x5e0d('0x1c')]=_0x6db885[_0x5e0d('0x1c')];}}else{if(_0x6db885['authentication']){_0x3d1d14[_0x5e0d('0x17')]=_0x6db885[_0x5e0d('0x17')];_0x3d1d14[_0x5e0d('0x1c')]=_0x6db885['password'];}}_0x3d1d14[_0x5e0d('0x9')]=_0x27f68b||_0x6db885[_0x5e0d('0x17')]||_0x5e0d('0x1d');_0x3d1d14[_0x5e0d('0x1e')]=_0x6db885['host'];_0x3d1d14['port']=_0x6db885['port']||0x3e1;if(_0x6db885[_0x5e0d('0x1f')]){_0x3d1d14['tls']=!![];}else{_0x3d1d14[_0x5e0d('0x1f')]=![];_0x3d1d14['autotls']='required';}return _0x3d1d14;};EmailImap[_0x5e0d('0x14')][_0x5e0d('0xe')]=function(){this[_0x5e0d('0x2')][_0x5e0d('0x20')](this['mailbox'],![],this[_0x5e0d('0x21')][_0x5e0d('0xf')](this));};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x21')]=function(_0x1daebb,_0x159bd7){if(_0x1daebb){this[_0x5e0d('0x12')](_0x1daebb,!![]);}else{this['emit'](_0x5e0d('0x22'),_0x159bd7);this[_0x5e0d('0x23')]();}};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x24')]=function(_0x30e96a){if(_0x30e96a){this[_0x5e0d('0x12')](_0x30e96a,!![]);}else{this['imap'][_0x5e0d('0x25')]();}};EmailImap[_0x5e0d('0x14')]['readUnseen']=function(){this[_0x5e0d('0x2')][_0x5e0d('0x26')]([_0x5e0d('0x27')],this['handleReadUnseen'][_0x5e0d('0xf')](this));};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x28')]=function(_0x129942,_0x3d33f8){if(_0x129942){this[_0x5e0d('0x12')](_0x129942,!![]);}else{if(_0x3d33f8[_0x5e0d('0x29')]){try{var _0x10f94c=this[_0x5e0d('0x2')][_0x5e0d('0x2a')](_0x3d33f8[_0x5e0d('0x2b')](0x0,0xa),{'bodies':'','markSeen':!![]});_0x10f94c['on'](_0x5e0d('0x2c'),this[_0x5e0d('0x2d')][_0x5e0d('0xf')](this));_0x10f94c[_0x5e0d('0xd')](_0x5e0d('0x11'),this[_0x5e0d('0x2e')]['bind'](this));_0x10f94c[_0x5e0d('0xd')](_0x5e0d('0x25'),this['handleFetchEnd'][_0x5e0d('0xf')](this));}catch(_0x3ae409){logger['error'](_0x3ae409);}}else{this[_0x5e0d('0x2')]['closeBox'](!![],this['handleCloseBox'][_0x5e0d('0xf')](this));}}};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x2d')]=function(_0x5a879b){_0x5a879b['on'](_0x5e0d('0x2f'),this[_0x5e0d('0x30')][_0x5e0d('0xf')](this));_0x5a879b[_0x5e0d('0xd')]('attributes',this[_0x5e0d('0x31')][_0x5e0d('0xf')](this));_0x5a879b['once'](_0x5e0d('0x25'),this[_0x5e0d('0x32')][_0x5e0d('0xf')](this));};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x30')]=function(_0x415b72){simpleParser(_0x415b72,{'Iconv':Iconv},this['handleSimpleParser']['bind'](this));};EmailImap['prototype'][_0x5e0d('0x31')]=function(){};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x32')]=function(){};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x33')]=function(_0x46d2d3,_0x47dfa8){if(_0x46d2d3){logger[_0x5e0d('0x11')](_0x46d2d3);}else{var _0x5922fe=this;utils[_0x5e0d('0x34')](this[_0x5e0d('0xb')],_0x47dfa8,function(_0x292d57){_0x5922fe[_0x5e0d('0x35')](_0x5e0d('0x9'),_0x292d57);});}};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x36')]=function(){this[_0x5e0d('0x2')][_0x5e0d('0x37')](!![],this['handleCloseBox'][_0x5e0d('0xf')](this));};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x2e')]=function(_0x4a8dd6){this[_0x5e0d('0x12')](_0x4a8dd6);this[_0x5e0d('0x2')]['closeBox'](!![],this[_0x5e0d('0x24')][_0x5e0d('0xf')](this));};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x10')]=function(){this['emit'](_0x5e0d('0x25'));};EmailImap[_0x5e0d('0x14')][_0x5e0d('0x12')]=function(_0x3fcf4b,_0x24e581){logger[_0x5e0d('0x11')](_0x5e0d('0x12'),this['account'][_0x5e0d('0x9')],JSON[_0x5e0d('0x38')](_0x3fcf4b));var _0x225839='';if(_0x3fcf4b){if(_0x3fcf4b[_0x5e0d('0x39')]){_0x225839=_0x3fcf4b['textCode'];}else{for(var _0x32af66 in _0x3fcf4b){if(_0x3fcf4b[_0x5e0d('0x3a')](_0x32af66)){_0x225839+=_['upperFirst'](_0x32af66)+':\x20'+_0x3fcf4b[_0x32af66]+'\x0a';}}}}if(_0x24e581){this[_0x5e0d('0x2')][_0x5e0d('0x25')]();}else{this['emit'](_0x5e0d('0x11'),_0x225839);this[_0x5e0d('0x35')](_0x5e0d('0x25'));}};module[_0x5e0d('0x3b')]=EmailImap;