61946efcfb8cffc938bce2949e10638a9fb4cbbd
[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 _0xea30=['handleFetchMessage','error','handleFetchError','handleFetchEnd','closeBox','body','handleMessageBody','handleMessageAttributes','handleSimpleParser','handleMessageEnd','parser','stringify','textCode','hasOwnProperty','upperFirst','exports','util','mailparser','simpleParser','iconv','Iconv','EventEmitter','./utils','../../../config/logger','email','mailbox','account','imap','ready','once','end','handleEnd','handleError','inherits','getAccount','connTimeout','authTimeout','service','user','generateXOAuth2Token','data5','password','anonymous@xcally.com','host','tls','autotls','required','prototype','handleReady','bind','emit','readUnseen','handleCloseBox','search','handleReadUnseen','length','fetch','message'];(function(_0x242a2d,_0x4ed72e){var _0x762099=function(_0x4f20ab){while(--_0x4f20ab){_0x242a2d['push'](_0x242a2d['shift']());}};_0x762099(++_0x4ed72e);}(_0xea30,0x1a6));var _0x0ea3=function(_0x588742,_0x52257c){_0x588742=_0x588742-0x0;var _0x527ef5=_0xea30[_0x588742];return _0x527ef5;};'use strict';var _=require('lodash');var util=require(_0x0ea3('0x0'));var Imap=require('imap');var simpleParser=require(_0x0ea3('0x1'))[_0x0ea3('0x2')];var Iconv=require(_0x0ea3('0x3'))[_0x0ea3('0x4')];var EventEmitter=require('events')[_0x0ea3('0x5')];var utils=require(_0x0ea3('0x6'));var logger=require(_0x0ea3('0x7'))(_0x0ea3('0x8'));function EmailImap(_0x26965a,_0xcdcb99){this[_0x0ea3('0x9')]=_0x26965a[_0x0ea3('0x9')];this[_0x0ea3('0xa')]=this['getAccount'](_0x26965a,_0xcdcb99);this[_0x0ea3('0xb')]=new Imap(this[_0x0ea3('0xa')]);this[_0x0ea3('0xb')]['once'](_0x0ea3('0xc'),this['handleReady']['bind'](this));this[_0x0ea3('0xb')][_0x0ea3('0xd')](_0x0ea3('0xe'),this[_0x0ea3('0xf')]['bind'](this));this[_0x0ea3('0xb')]['on']('error',this[_0x0ea3('0x10')]['bind'](this));this[_0x0ea3('0xb')]['connect']();}util[_0x0ea3('0x11')](EmailImap,EventEmitter);EmailImap['prototype'][_0x0ea3('0x12')]=function(_0x49f68e,_0x28fd71){var _0x1dcd1f={'connTimeout':_0x49f68e[_0x0ea3('0x13')]?_0x49f68e[_0x0ea3('0x13')]*0x3e8:0x2710,'authTimeout':_0x49f68e[_0x0ea3('0x14')]?_0x49f68e[_0x0ea3('0x14')]*0x3e8:0x1388};if(_0x49f68e[_0x0ea3('0x15')]){_0x1dcd1f['user']=_0x49f68e[_0x0ea3('0x16')];if(_0x49f68e['modernAuthentication']){_0x1dcd1f['xoauth2']=utils[_0x0ea3('0x17')](_0x49f68e['CloudProvider'][_0x0ea3('0x18')],_0x49f68e[_0x0ea3('0x16')]);}else{_0x1dcd1f[_0x0ea3('0x19')]=_0x49f68e[_0x0ea3('0x19')];}}else{if(_0x49f68e['authentication']){_0x1dcd1f[_0x0ea3('0x16')]=_0x49f68e['user'];_0x1dcd1f['password']=_0x49f68e[_0x0ea3('0x19')];}}_0x1dcd1f[_0x0ea3('0x8')]=_0x28fd71||_0x49f68e['user']||_0x0ea3('0x1a');_0x1dcd1f['host']=_0x49f68e[_0x0ea3('0x1b')];_0x1dcd1f['port']=_0x49f68e['port']||0x3e1;if(_0x49f68e[_0x0ea3('0x1c')]){_0x1dcd1f[_0x0ea3('0x1c')]=!![];}else{_0x1dcd1f[_0x0ea3('0x1c')]=![];_0x1dcd1f[_0x0ea3('0x1d')]=_0x0ea3('0x1e');}return _0x1dcd1f;};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x20')]=function(){this[_0x0ea3('0xb')]['openBox'](this[_0x0ea3('0x9')],![],this['handleOpenBox'][_0x0ea3('0x21')](this));};EmailImap[_0x0ea3('0x1f')]['handleOpenBox']=function(_0x3f0fee,_0x32b04a){if(_0x3f0fee){this[_0x0ea3('0x10')](_0x3f0fee,!![]);}else{this[_0x0ea3('0x22')]('box',_0x32b04a);this[_0x0ea3('0x23')]();}};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x24')]=function(_0x558ea3){if(_0x558ea3){this[_0x0ea3('0x10')](_0x558ea3,!![]);}else{this[_0x0ea3('0xb')][_0x0ea3('0xe')]();}};EmailImap['prototype'][_0x0ea3('0x23')]=function(){this[_0x0ea3('0xb')][_0x0ea3('0x25')](['UNSEEN'],this[_0x0ea3('0x26')][_0x0ea3('0x21')](this));};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x26')]=function(_0x492c48,_0x149f05){if(_0x492c48){this[_0x0ea3('0x10')](_0x492c48,!![]);}else{if(_0x149f05[_0x0ea3('0x27')]){try{var _0x2c3d20=this[_0x0ea3('0xb')][_0x0ea3('0x28')](_0x149f05,{'bodies':'','markSeen':!![]});_0x2c3d20['on'](_0x0ea3('0x29'),this[_0x0ea3('0x2a')][_0x0ea3('0x21')](this));_0x2c3d20[_0x0ea3('0xd')](_0x0ea3('0x2b'),this[_0x0ea3('0x2c')]['bind'](this));_0x2c3d20[_0x0ea3('0xd')]('end',this[_0x0ea3('0x2d')][_0x0ea3('0x21')](this));}catch(_0x117e9b){logger[_0x0ea3('0x2b')](_0x117e9b);}}else{this[_0x0ea3('0xb')][_0x0ea3('0x2e')](!![],this['handleCloseBox'][_0x0ea3('0x21')](this));}}};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x2a')]=function(_0x235075){_0x235075['on'](_0x0ea3('0x2f'),this[_0x0ea3('0x30')][_0x0ea3('0x21')](this));_0x235075[_0x0ea3('0xd')]('attributes',this[_0x0ea3('0x31')][_0x0ea3('0x21')](this));_0x235075[_0x0ea3('0xd')]('end',this['handleMessageEnd'][_0x0ea3('0x21')](this));};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x30')]=function(_0x28a7aa){simpleParser(_0x28a7aa,{'Iconv':Iconv},this[_0x0ea3('0x32')]['bind'](this));};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x31')]=function(){};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x33')]=function(){};EmailImap['prototype']['handleSimpleParser']=function(_0x5029e3,_0x5b4f0e){if(_0x5029e3){logger[_0x0ea3('0x2b')](_0x5029e3);}else{var _0x283c72=this;utils[_0x0ea3('0x34')](this[_0x0ea3('0xa')],_0x5b4f0e,function(_0x2d25a7){_0x283c72['emit'](_0x0ea3('0x8'),_0x2d25a7);});}};EmailImap['prototype'][_0x0ea3('0x2d')]=function(){this[_0x0ea3('0xb')]['closeBox'](!![],this['handleCloseBox'][_0x0ea3('0x21')](this));};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x2c')]=function(_0x11b83b){this[_0x0ea3('0x10')](_0x11b83b);this[_0x0ea3('0xb')]['closeBox'](!![],this['handleCloseBox'][_0x0ea3('0x21')](this));};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0xf')]=function(){this[_0x0ea3('0x22')](_0x0ea3('0xe'));};EmailImap[_0x0ea3('0x1f')][_0x0ea3('0x10')]=function(_0x1489b2,_0x202fea){logger[_0x0ea3('0x2b')](_0x0ea3('0x10'),this[_0x0ea3('0xa')][_0x0ea3('0x8')],JSON[_0x0ea3('0x35')](_0x1489b2));var _0x4e857d='';if(_0x1489b2){if(_0x1489b2[_0x0ea3('0x36')]){_0x4e857d=_0x1489b2[_0x0ea3('0x36')];}else{for(var _0x226f10 in _0x1489b2){if(_0x1489b2[_0x0ea3('0x37')](_0x226f10)){_0x4e857d+=_[_0x0ea3('0x38')](_0x226f10)+':\x20'+_0x1489b2[_0x226f10]+'\x0a';}}}}if(_0x202fea){this['imap'][_0x0ea3('0xe')]();}else{this[_0x0ea3('0x22')](_0x0ea3('0x2b'),_0x4e857d);this[_0x0ea3('0x22')](_0x0ea3('0xe'));}};module[_0x0ea3('0x39')]=EmailImap;