Built motion from commit d1eab355.|2.6.28
[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 _0x6cd7=['account','once','handleReady','bind','end','handleEnd','error','handleError','connect','inherits','prototype','connTimeout','authTimeout','service','modernAuthentication','generateXOAuth2Token','CloudProvider','data5','password','authentication','user','anonymous@xcally.com','host','port','tls','openBox','handleOpenBox','emit','box','readUnseen','handleCloseBox','search','UNSEEN','handleReadUnseen','length','fetch','handleFetchMessage','handleFetchError','handleFetchEnd','closeBox','body','handleMessageBody','attributes','handleMessageAttributes','handleMessageEnd','handleSimpleParser','parser','textCode','hasOwnProperty','upperFirst','exports','lodash','imap','mailparser','simpleParser','iconv','Iconv','events','EventEmitter','email','mailbox'];(function(_0x3f941c,_0x121c43){var _0x3740bc=function(_0x50dd2c){while(--_0x50dd2c){_0x3f941c['push'](_0x3f941c['shift']());}};_0x3740bc(++_0x121c43);}(_0x6cd7,0x1de));var _0x76cd=function(_0x35e9ce,_0x4ebb8d){_0x35e9ce=_0x35e9ce-0x0;var _0x32e808=_0x6cd7[_0x35e9ce];return _0x32e808;};'use strict';var _=require(_0x76cd('0x0'));var util=require('util');var Imap=require(_0x76cd('0x1'));var simpleParser=require(_0x76cd('0x2'))[_0x76cd('0x3')];var Iconv=require(_0x76cd('0x4'))[_0x76cd('0x5')];var EventEmitter=require(_0x76cd('0x6'))[_0x76cd('0x7')];var utils=require('./utils');var logger=require('../../../config/logger')(_0x76cd('0x8'));function EmailImap(_0x2b2548,_0x52e756){this[_0x76cd('0x9')]=_0x2b2548[_0x76cd('0x9')];this[_0x76cd('0xa')]=this['getAccount'](_0x2b2548,_0x52e756);this[_0x76cd('0x1')]=new Imap(this[_0x76cd('0xa')]);this[_0x76cd('0x1')][_0x76cd('0xb')]('ready',this[_0x76cd('0xc')][_0x76cd('0xd')](this));this[_0x76cd('0x1')][_0x76cd('0xb')](_0x76cd('0xe'),this[_0x76cd('0xf')]['bind'](this));this[_0x76cd('0x1')]['on'](_0x76cd('0x10'),this[_0x76cd('0x11')][_0x76cd('0xd')](this));this['imap'][_0x76cd('0x12')]();}util[_0x76cd('0x13')](EmailImap,EventEmitter);EmailImap[_0x76cd('0x14')]['getAccount']=function(_0x4d6b8c,_0x4643){var _0xc98880={'connTimeout':_0x4d6b8c[_0x76cd('0x15')]?_0x4d6b8c['connTimeout']*0x3e8:0x2710,'authTimeout':_0x4d6b8c[_0x76cd('0x16')]?_0x4d6b8c['authTimeout']*0x3e8:0x1388};if(_0x4d6b8c[_0x76cd('0x17')]){_0xc98880['user']=_0x4d6b8c['user'];if(_0x4d6b8c[_0x76cd('0x18')]){_0xc98880['xoauth2']=utils[_0x76cd('0x19')](_0x4d6b8c[_0x76cd('0x1a')][_0x76cd('0x1b')],_0x4d6b8c['user']);}else{_0xc98880[_0x76cd('0x1c')]=_0x4d6b8c[_0x76cd('0x1c')];}}else{if(_0x4d6b8c[_0x76cd('0x1d')]){_0xc98880[_0x76cd('0x1e')]=_0x4d6b8c[_0x76cd('0x1e')];_0xc98880[_0x76cd('0x1c')]=_0x4d6b8c['password'];}}_0xc98880[_0x76cd('0x8')]=_0x4643||_0x4d6b8c[_0x76cd('0x1e')]||_0x76cd('0x1f');_0xc98880['host']=_0x4d6b8c[_0x76cd('0x20')];_0xc98880[_0x76cd('0x21')]=_0x4d6b8c[_0x76cd('0x21')]||0x3e1;if(_0x4d6b8c['tls']){_0xc98880[_0x76cd('0x22')]=!![];}else{_0xc98880[_0x76cd('0x22')]=![];_0xc98880['autotls']='required';}return _0xc98880;};EmailImap[_0x76cd('0x14')][_0x76cd('0xc')]=function(){this['imap'][_0x76cd('0x23')](this[_0x76cd('0x9')],![],this[_0x76cd('0x24')][_0x76cd('0xd')](this));};EmailImap[_0x76cd('0x14')][_0x76cd('0x24')]=function(_0x783ce,_0x512a76){if(_0x783ce){this[_0x76cd('0x11')](_0x783ce,!![]);}else{this[_0x76cd('0x25')](_0x76cd('0x26'),_0x512a76);this[_0x76cd('0x27')]();}};EmailImap[_0x76cd('0x14')][_0x76cd('0x28')]=function(_0x227067){if(_0x227067){this[_0x76cd('0x11')](_0x227067,!![]);}else{this[_0x76cd('0x1')]['end']();}};EmailImap[_0x76cd('0x14')][_0x76cd('0x27')]=function(){this[_0x76cd('0x1')][_0x76cd('0x29')]([_0x76cd('0x2a')],this[_0x76cd('0x2b')][_0x76cd('0xd')](this));};EmailImap['prototype'][_0x76cd('0x2b')]=function(_0xd6c545,_0x51cd01){if(_0xd6c545){this[_0x76cd('0x11')](_0xd6c545,!![]);}else{if(_0x51cd01[_0x76cd('0x2c')]){try{var _0x4e6b92=this[_0x76cd('0x1')][_0x76cd('0x2d')](_0x51cd01,{'bodies':'','markSeen':!![]});_0x4e6b92['on']('message',this[_0x76cd('0x2e')][_0x76cd('0xd')](this));_0x4e6b92[_0x76cd('0xb')](_0x76cd('0x10'),this[_0x76cd('0x2f')][_0x76cd('0xd')](this));_0x4e6b92[_0x76cd('0xb')](_0x76cd('0xe'),this[_0x76cd('0x30')][_0x76cd('0xd')](this));}catch(_0x219631){logger['error'](_0x219631);}}else{this[_0x76cd('0x1')][_0x76cd('0x31')](!![],this[_0x76cd('0x28')][_0x76cd('0xd')](this));}}};EmailImap['prototype'][_0x76cd('0x2e')]=function(_0x461008){_0x461008['on'](_0x76cd('0x32'),this[_0x76cd('0x33')][_0x76cd('0xd')](this));_0x461008[_0x76cd('0xb')](_0x76cd('0x34'),this[_0x76cd('0x35')][_0x76cd('0xd')](this));_0x461008[_0x76cd('0xb')](_0x76cd('0xe'),this[_0x76cd('0x36')][_0x76cd('0xd')](this));};EmailImap[_0x76cd('0x14')][_0x76cd('0x33')]=function(_0x306602){simpleParser(_0x306602,{'Iconv':Iconv},this['handleSimpleParser'][_0x76cd('0xd')](this));};EmailImap[_0x76cd('0x14')]['handleMessageAttributes']=function(){};EmailImap[_0x76cd('0x14')][_0x76cd('0x36')]=function(){};EmailImap[_0x76cd('0x14')][_0x76cd('0x37')]=function(_0x25fc3d,_0x6ac822){if(_0x25fc3d){logger['error'](_0x25fc3d);}else{var _0xdfdfe9=this;utils[_0x76cd('0x38')](this[_0x76cd('0xa')],_0x6ac822,function(_0xb0b176){_0xdfdfe9['emit'](_0x76cd('0x8'),_0xb0b176);});}};EmailImap['prototype'][_0x76cd('0x30')]=function(){this[_0x76cd('0x1')][_0x76cd('0x31')](!![],this[_0x76cd('0x28')][_0x76cd('0xd')](this));};EmailImap[_0x76cd('0x14')][_0x76cd('0x2f')]=function(_0x38af37){this[_0x76cd('0x11')](_0x38af37);this[_0x76cd('0x1')][_0x76cd('0x31')](!![],this[_0x76cd('0x28')][_0x76cd('0xd')](this));};EmailImap[_0x76cd('0x14')][_0x76cd('0xf')]=function(){this[_0x76cd('0x25')]('end');};EmailImap[_0x76cd('0x14')]['handleError']=function(_0xc5b424,_0x384e67){logger[_0x76cd('0x10')](_0x76cd('0x11'),this[_0x76cd('0xa')]['email'],JSON['stringify'](_0xc5b424));var _0x5616ab='';if(_0xc5b424){if(_0xc5b424['textCode']){_0x5616ab=_0xc5b424[_0x76cd('0x39')];}else{for(var _0xfb0b56 in _0xc5b424){if(_0xc5b424[_0x76cd('0x3a')](_0xfb0b56)){_0x5616ab+=_[_0x76cd('0x3b')](_0xfb0b56)+':\x20'+_0xc5b424[_0xfb0b56]+'\x0a';}}}}if(_0x384e67){this[_0x76cd('0x1')]['end']();}else{this[_0x76cd('0x25')](_0x76cd('0x10'),_0x5616ab);this[_0x76cd('0x25')](_0x76cd('0xe'));}};module[_0x76cd('0x3c')]=EmailImap;