Built motion from commit d5e4af8c.|2.6.23
[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 _0x3363=['handleFetchError','body','handleMessageAttributes','handleMessageEnd','handleSimpleParser','parser','handleFetchEnd','closeBox','textCode','hasOwnProperty','upperFirst','exports','lodash','util','simpleParser','iconv','events','EventEmitter','./utils','email','mailbox','account','imap','bind','once','handleEnd','error','handleError','connect','inherits','prototype','getAccount','connTimeout','authTimeout','service','user','modernAuthentication','xoauth2','generateXOAuth2Token','CloudProvider','data5','password','authentication','anonymous@xcally.com','host','port','tls','autotls','required','handleReady','openBox','handleOpenBox','emit','box','handleCloseBox','end','readUnseen','search','UNSEEN','handleReadUnseen','fetch','message','handleFetchMessage'];(function(_0x316904,_0x1e8b77){var _0xfa9a21=function(_0x2b75ae){while(--_0x2b75ae){_0x316904['push'](_0x316904['shift']());}};_0xfa9a21(++_0x1e8b77);}(_0x3363,0x8a));var _0x3336=function(_0x538cbd,_0x48d4ef){_0x538cbd=_0x538cbd-0x0;var _0x676281=_0x3363[_0x538cbd];return _0x676281;};'use strict';var _=require(_0x3336('0x0'));var util=require(_0x3336('0x1'));var Imap=require('imap');var simpleParser=require('mailparser')[_0x3336('0x2')];var Iconv=require(_0x3336('0x3'))['Iconv'];var EventEmitter=require(_0x3336('0x4'))[_0x3336('0x5')];var utils=require(_0x3336('0x6'));var logger=require('../../../config/logger')(_0x3336('0x7'));function EmailImap(_0x134f3c,_0x57db5b){this[_0x3336('0x8')]=_0x134f3c['mailbox'];this[_0x3336('0x9')]=this['getAccount'](_0x134f3c,_0x57db5b);this[_0x3336('0xa')]=new Imap(this[_0x3336('0x9')]);this[_0x3336('0xa')]['once']('ready',this['handleReady'][_0x3336('0xb')](this));this['imap'][_0x3336('0xc')]('end',this[_0x3336('0xd')]['bind'](this));this['imap']['on'](_0x3336('0xe'),this[_0x3336('0xf')][_0x3336('0xb')](this));this['imap'][_0x3336('0x10')]();}util[_0x3336('0x11')](EmailImap,EventEmitter);EmailImap[_0x3336('0x12')][_0x3336('0x13')]=function(_0x2bd9e4,_0x576cf9){var _0x10fbeb={'connTimeout':_0x2bd9e4[_0x3336('0x14')]?_0x2bd9e4['connTimeout']*0x3e8:0x2710,'authTimeout':_0x2bd9e4[_0x3336('0x15')]?_0x2bd9e4[_0x3336('0x15')]*0x3e8:0x1388};if(_0x2bd9e4[_0x3336('0x16')]){_0x10fbeb[_0x3336('0x17')]=_0x2bd9e4[_0x3336('0x17')];if(_0x2bd9e4[_0x3336('0x18')]){_0x10fbeb[_0x3336('0x19')]=utils[_0x3336('0x1a')](_0x2bd9e4[_0x3336('0x1b')][_0x3336('0x1c')],_0x2bd9e4[_0x3336('0x17')]);}else{_0x10fbeb['password']=_0x2bd9e4[_0x3336('0x1d')];}}else{if(_0x2bd9e4[_0x3336('0x1e')]){_0x10fbeb['user']=_0x2bd9e4['user'];_0x10fbeb[_0x3336('0x1d')]=_0x2bd9e4[_0x3336('0x1d')];}}_0x10fbeb[_0x3336('0x7')]=_0x576cf9||_0x2bd9e4[_0x3336('0x17')]||_0x3336('0x1f');_0x10fbeb['host']=_0x2bd9e4[_0x3336('0x20')];_0x10fbeb['port']=_0x2bd9e4[_0x3336('0x21')]||0x3e1;if(_0x2bd9e4[_0x3336('0x22')]){_0x10fbeb[_0x3336('0x22')]=!![];}else{_0x10fbeb[_0x3336('0x22')]=![];_0x10fbeb[_0x3336('0x23')]=_0x3336('0x24');}return _0x10fbeb;};EmailImap['prototype'][_0x3336('0x25')]=function(){this[_0x3336('0xa')][_0x3336('0x26')](this[_0x3336('0x8')],![],this['handleOpenBox'][_0x3336('0xb')](this));};EmailImap['prototype'][_0x3336('0x27')]=function(_0x5b2e45,_0x8dacd6){if(_0x5b2e45){this['handleError'](_0x5b2e45,!![]);}else{this[_0x3336('0x28')](_0x3336('0x29'),_0x8dacd6);this['readUnseen']();}};EmailImap[_0x3336('0x12')][_0x3336('0x2a')]=function(_0x1ec82a){if(_0x1ec82a){this[_0x3336('0xf')](_0x1ec82a,!![]);}else{this['imap'][_0x3336('0x2b')]();}};EmailImap[_0x3336('0x12')][_0x3336('0x2c')]=function(){this[_0x3336('0xa')][_0x3336('0x2d')]([_0x3336('0x2e')],this['handleReadUnseen'][_0x3336('0xb')](this));};EmailImap['prototype'][_0x3336('0x2f')]=function(_0xf4103d,_0x27c970){if(_0xf4103d){this[_0x3336('0xf')](_0xf4103d,!![]);}else{if(_0x27c970['length']){try{var _0x2b8428=this[_0x3336('0xa')][_0x3336('0x30')](_0x27c970,{'bodies':'','markSeen':!![]});_0x2b8428['on'](_0x3336('0x31'),this[_0x3336('0x32')][_0x3336('0xb')](this));_0x2b8428['once']('error',this[_0x3336('0x33')][_0x3336('0xb')](this));_0x2b8428[_0x3336('0xc')](_0x3336('0x2b'),this['handleFetchEnd']['bind'](this));}catch(_0xe8048e){logger[_0x3336('0xe')](_0xe8048e);}}else{this[_0x3336('0xa')]['closeBox'](!![],this[_0x3336('0x2a')][_0x3336('0xb')](this));}}};EmailImap[_0x3336('0x12')]['handleFetchMessage']=function(_0x13c488){_0x13c488['on'](_0x3336('0x34'),this['handleMessageBody'][_0x3336('0xb')](this));_0x13c488[_0x3336('0xc')]('attributes',this[_0x3336('0x35')][_0x3336('0xb')](this));_0x13c488['once']('end',this[_0x3336('0x36')]['bind'](this));};EmailImap[_0x3336('0x12')]['handleMessageBody']=function(_0x42e687){simpleParser(_0x42e687,{'Iconv':Iconv},this[_0x3336('0x37')][_0x3336('0xb')](this));};EmailImap[_0x3336('0x12')][_0x3336('0x35')]=function(){};EmailImap['prototype'][_0x3336('0x36')]=function(){};EmailImap[_0x3336('0x12')][_0x3336('0x37')]=function(_0x7b948f,_0x3ba821){if(_0x7b948f){logger[_0x3336('0xe')](_0x7b948f);}else{var _0x25169b=this;utils[_0x3336('0x38')](this['account'],_0x3ba821,function(_0x20eae9){_0x25169b[_0x3336('0x28')]('email',_0x20eae9);});}};EmailImap[_0x3336('0x12')][_0x3336('0x39')]=function(){this[_0x3336('0xa')][_0x3336('0x3a')](!![],this['handleCloseBox'][_0x3336('0xb')](this));};EmailImap[_0x3336('0x12')][_0x3336('0x33')]=function(_0xd1920){this[_0x3336('0xf')](_0xd1920);this['imap'][_0x3336('0x3a')](!![],this[_0x3336('0x2a')][_0x3336('0xb')](this));};EmailImap[_0x3336('0x12')][_0x3336('0xd')]=function(){this['emit']('end');};EmailImap['prototype'][_0x3336('0xf')]=function(_0x35a415,_0x10e606){logger[_0x3336('0xe')](_0x3336('0xf'),this[_0x3336('0x9')][_0x3336('0x7')],JSON['stringify'](_0x35a415));var _0x440637='';if(_0x35a415){if(_0x35a415[_0x3336('0x3b')]){_0x440637=_0x35a415[_0x3336('0x3b')];}else{for(var _0x15bce8 in _0x35a415){if(_0x35a415[_0x3336('0x3c')](_0x15bce8)){_0x440637+=_[_0x3336('0x3d')](_0x15bce8)+':\x20'+_0x35a415[_0x15bce8]+'\x0a';}}}}if(_0x10e606){this['imap'][_0x3336('0x2b')]();}else{this[_0x3336('0x28')]('error',_0x440637);this[_0x3336('0x28')](_0x3336('0x2b'));}};module[_0x3336('0x3e')]=EmailImap;