Built motion from commit bbec7235.|2.6.20
[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 _0xf893=['handleReadUnseen','length','fetch','handleFetchMessage','handleFetchError','handleFetchEnd','closeBox','handleMessageBody','attributes','handleMessageEnd','handleSimpleParser','handleMessageAttributes','parser','handleCloseBox','stringify','textCode','hasOwnProperty','upperFirst','exports','lodash','util','imap','mailparser','simpleParser','iconv','Iconv','events','EventEmitter','./utils','../../../config/logger','mailbox','account','once','ready','handleReady','bind','end','handleEnd','error','handleError','inherits','prototype','getAccount','connTimeout','authTimeout','user','modernAuthentication','xoauth2','generateXOAuth2Token','CloudProvider','password','email','anonymous@xcally.com','host','port','tls','autotls','required','openBox','handleOpenBox','emit','box','readUnseen','UNSEEN'];(function(_0x30e579,_0x19cbd7){var _0x2b75fd=function(_0x251fb1){while(--_0x251fb1){_0x30e579['push'](_0x30e579['shift']());}};_0x2b75fd(++_0x19cbd7);}(_0xf893,0xd3));var _0x3f89=function(_0x2d3495,_0x30ca21){_0x2d3495=_0x2d3495-0x0;var _0x1e4fbb=_0xf893[_0x2d3495];return _0x1e4fbb;};'use strict';var _=require(_0x3f89('0x0'));var util=require(_0x3f89('0x1'));var Imap=require(_0x3f89('0x2'));var simpleParser=require(_0x3f89('0x3'))[_0x3f89('0x4')];var Iconv=require(_0x3f89('0x5'))[_0x3f89('0x6')];var EventEmitter=require(_0x3f89('0x7'))[_0x3f89('0x8')];var utils=require(_0x3f89('0x9'));var logger=require(_0x3f89('0xa'))('email');function EmailImap(_0x2cc071,_0x42dd32){this[_0x3f89('0xb')]=_0x2cc071[_0x3f89('0xb')];this['account']=this['getAccount'](_0x2cc071,_0x42dd32);this['imap']=new Imap(this[_0x3f89('0xc')]);this[_0x3f89('0x2')][_0x3f89('0xd')](_0x3f89('0xe'),this[_0x3f89('0xf')][_0x3f89('0x10')](this));this[_0x3f89('0x2')]['once'](_0x3f89('0x11'),this[_0x3f89('0x12')]['bind'](this));this[_0x3f89('0x2')]['on'](_0x3f89('0x13'),this[_0x3f89('0x14')]['bind'](this));this[_0x3f89('0x2')]['connect']();}util[_0x3f89('0x15')](EmailImap,EventEmitter);EmailImap[_0x3f89('0x16')][_0x3f89('0x17')]=function(_0xe878d3,_0x20a6f3){var _0x1e7152={'connTimeout':_0xe878d3[_0x3f89('0x18')]?_0xe878d3['connTimeout']*0x3e8:0x2710,'authTimeout':_0xe878d3[_0x3f89('0x19')]?_0xe878d3[_0x3f89('0x19')]*0x3e8:0x1388};if(_0xe878d3['service']){_0x1e7152[_0x3f89('0x1a')]=_0xe878d3[_0x3f89('0x1a')];if(_0xe878d3[_0x3f89('0x1b')]){_0x1e7152[_0x3f89('0x1c')]=utils[_0x3f89('0x1d')](_0xe878d3[_0x3f89('0x1e')]['data5'],_0xe878d3[_0x3f89('0x1a')]);}else{_0x1e7152['password']=_0xe878d3[_0x3f89('0x1f')];}}else{if(_0xe878d3['authentication']){_0x1e7152[_0x3f89('0x1a')]=_0xe878d3[_0x3f89('0x1a')];_0x1e7152['password']=_0xe878d3[_0x3f89('0x1f')];}}_0x1e7152[_0x3f89('0x20')]=_0x20a6f3||_0xe878d3[_0x3f89('0x1a')]||_0x3f89('0x21');_0x1e7152['host']=_0xe878d3[_0x3f89('0x22')];_0x1e7152['port']=_0xe878d3[_0x3f89('0x23')]||0x3e1;if(_0xe878d3['tls']){_0x1e7152['tls']=!![];}else{_0x1e7152[_0x3f89('0x24')]=![];_0x1e7152[_0x3f89('0x25')]=_0x3f89('0x26');}return _0x1e7152;};EmailImap[_0x3f89('0x16')][_0x3f89('0xf')]=function(){this[_0x3f89('0x2')][_0x3f89('0x27')](this[_0x3f89('0xb')],![],this['handleOpenBox'][_0x3f89('0x10')](this));};EmailImap[_0x3f89('0x16')][_0x3f89('0x28')]=function(_0xf3e41d,_0xd53213){if(_0xf3e41d){this[_0x3f89('0x14')](_0xf3e41d,!![]);}else{this[_0x3f89('0x29')](_0x3f89('0x2a'),_0xd53213);this[_0x3f89('0x2b')]();}};EmailImap[_0x3f89('0x16')]['handleCloseBox']=function(_0x454ab5){if(_0x454ab5){this['handleError'](_0x454ab5,!![]);}else{this[_0x3f89('0x2')]['end']();}};EmailImap[_0x3f89('0x16')]['readUnseen']=function(){this[_0x3f89('0x2')]['search']([_0x3f89('0x2c')],this[_0x3f89('0x2d')]['bind'](this));};EmailImap[_0x3f89('0x16')]['handleReadUnseen']=function(_0x521d7c,_0x432253){if(_0x521d7c){this[_0x3f89('0x14')](_0x521d7c,!![]);}else{if(_0x432253[_0x3f89('0x2e')]){try{var _0x5e48bc=this[_0x3f89('0x2')][_0x3f89('0x2f')](_0x432253,{'bodies':'','markSeen':!![]});_0x5e48bc['on']('message',this[_0x3f89('0x30')][_0x3f89('0x10')](this));_0x5e48bc[_0x3f89('0xd')](_0x3f89('0x13'),this[_0x3f89('0x31')]['bind'](this));_0x5e48bc[_0x3f89('0xd')](_0x3f89('0x11'),this[_0x3f89('0x32')][_0x3f89('0x10')](this));}catch(_0x49da45){logger[_0x3f89('0x13')](_0x49da45);}}else{this['imap'][_0x3f89('0x33')](!![],this['handleCloseBox'][_0x3f89('0x10')](this));}}};EmailImap['prototype']['handleFetchMessage']=function(_0x1649d5){_0x1649d5['on']('body',this[_0x3f89('0x34')][_0x3f89('0x10')](this));_0x1649d5[_0x3f89('0xd')](_0x3f89('0x35'),this['handleMessageAttributes']['bind'](this));_0x1649d5[_0x3f89('0xd')](_0x3f89('0x11'),this[_0x3f89('0x36')][_0x3f89('0x10')](this));};EmailImap[_0x3f89('0x16')][_0x3f89('0x34')]=function(_0x293c3d){simpleParser(_0x293c3d,{'Iconv':Iconv},this[_0x3f89('0x37')]['bind'](this));};EmailImap[_0x3f89('0x16')][_0x3f89('0x38')]=function(){};EmailImap[_0x3f89('0x16')][_0x3f89('0x36')]=function(){};EmailImap[_0x3f89('0x16')][_0x3f89('0x37')]=function(_0x30a326,_0x2f7194){if(_0x30a326){logger[_0x3f89('0x13')](_0x30a326);}else{var _0x1a6e0d=this;utils[_0x3f89('0x39')](this[_0x3f89('0xc')],_0x2f7194,function(_0x3e75e7){_0x1a6e0d['emit']('email',_0x3e75e7);});}};EmailImap['prototype'][_0x3f89('0x32')]=function(){this[_0x3f89('0x2')]['closeBox'](!![],this[_0x3f89('0x3a')]['bind'](this));};EmailImap[_0x3f89('0x16')][_0x3f89('0x31')]=function(_0x187993){this['handleError'](_0x187993);this[_0x3f89('0x2')][_0x3f89('0x33')](!![],this['handleCloseBox'][_0x3f89('0x10')](this));};EmailImap[_0x3f89('0x16')][_0x3f89('0x12')]=function(){this[_0x3f89('0x29')](_0x3f89('0x11'));};EmailImap[_0x3f89('0x16')][_0x3f89('0x14')]=function(_0x47c4e8,_0x2dfca0){logger[_0x3f89('0x13')](_0x3f89('0x14'),this[_0x3f89('0xc')][_0x3f89('0x20')],JSON[_0x3f89('0x3b')](_0x47c4e8));var _0x302932='';if(_0x47c4e8){if(_0x47c4e8[_0x3f89('0x3c')]){_0x302932=_0x47c4e8['textCode'];}else{for(var _0x2bbe4f in _0x47c4e8){if(_0x47c4e8[_0x3f89('0x3d')](_0x2bbe4f)){_0x302932+=_[_0x3f89('0x3e')](_0x2bbe4f)+':\x20'+_0x47c4e8[_0x2bbe4f]+'\x0a';}}}}if(_0x2dfca0){this[_0x3f89('0x2')][_0x3f89('0x11')]();}else{this[_0x3f89('0x29')](_0x3f89('0x13'),_0x302932);this[_0x3f89('0x29')](_0x3f89('0x11'));}};module[_0x3f89('0x3f')]=EmailImap;