Built motion from commit ffdca78c.|2.6.24
[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 _0xf4eb=['EventEmitter','./utils','email','mailbox','account','getAccount','once','handleReady','bind','end','error','inherits','prototype','connTimeout','authTimeout','service','user','modernAuthentication','CloudProvider','data5','password','authentication','anonymous@xcally.com','host','port','tls','autotls','required','handleOpenBox','handleError','emit','box','readUnseen','search','handleReadUnseen','message','handleFetchMessage','handleFetchError','handleFetchEnd','closeBox','body','handleMessageBody','attributes','handleMessageAttributes','handleSimpleParser','handleCloseBox','handleEnd','stringify','textCode','hasOwnProperty','upperFirst','lodash','imap','mailparser','Iconv','events'];(function(_0x47e9b7,_0x47f72c){var _0x506af3=function(_0xaff41b){while(--_0xaff41b){_0x47e9b7['push'](_0x47e9b7['shift']());}};_0x506af3(++_0x47f72c);}(_0xf4eb,0x1bb));var _0xbf4e=function(_0xb3401d,_0x5ede67){_0xb3401d=_0xb3401d-0x0;var _0xda36d5=_0xf4eb[_0xb3401d];return _0xda36d5;};'use strict';var _=require(_0xbf4e('0x0'));var util=require('util');var Imap=require(_0xbf4e('0x1'));var simpleParser=require(_0xbf4e('0x2'))['simpleParser'];var Iconv=require('iconv')[_0xbf4e('0x3')];var EventEmitter=require(_0xbf4e('0x4'))[_0xbf4e('0x5')];var utils=require(_0xbf4e('0x6'));var logger=require('../../../config/logger')(_0xbf4e('0x7'));function EmailImap(_0xaa2eb7,_0x558d72){this[_0xbf4e('0x8')]=_0xaa2eb7[_0xbf4e('0x8')];this[_0xbf4e('0x9')]=this[_0xbf4e('0xa')](_0xaa2eb7,_0x558d72);this[_0xbf4e('0x1')]=new Imap(this[_0xbf4e('0x9')]);this[_0xbf4e('0x1')][_0xbf4e('0xb')]('ready',this[_0xbf4e('0xc')][_0xbf4e('0xd')](this));this[_0xbf4e('0x1')][_0xbf4e('0xb')](_0xbf4e('0xe'),this['handleEnd'][_0xbf4e('0xd')](this));this['imap']['on'](_0xbf4e('0xf'),this['handleError']['bind'](this));this[_0xbf4e('0x1')]['connect']();}util[_0xbf4e('0x10')](EmailImap,EventEmitter);EmailImap[_0xbf4e('0x11')]['getAccount']=function(_0x2b6e61,_0x2e144d){var _0x551d39={'connTimeout':_0x2b6e61[_0xbf4e('0x12')]?_0x2b6e61[_0xbf4e('0x12')]*0x3e8:0x2710,'authTimeout':_0x2b6e61[_0xbf4e('0x13')]?_0x2b6e61[_0xbf4e('0x13')]*0x3e8:0x1388};if(_0x2b6e61[_0xbf4e('0x14')]){_0x551d39['user']=_0x2b6e61[_0xbf4e('0x15')];if(_0x2b6e61[_0xbf4e('0x16')]){_0x551d39['xoauth2']=utils['generateXOAuth2Token'](_0x2b6e61[_0xbf4e('0x17')][_0xbf4e('0x18')],_0x2b6e61[_0xbf4e('0x15')]);}else{_0x551d39[_0xbf4e('0x19')]=_0x2b6e61[_0xbf4e('0x19')];}}else{if(_0x2b6e61[_0xbf4e('0x1a')]){_0x551d39[_0xbf4e('0x15')]=_0x2b6e61['user'];_0x551d39[_0xbf4e('0x19')]=_0x2b6e61['password'];}}_0x551d39[_0xbf4e('0x7')]=_0x2e144d||_0x2b6e61[_0xbf4e('0x15')]||_0xbf4e('0x1b');_0x551d39[_0xbf4e('0x1c')]=_0x2b6e61['host'];_0x551d39['port']=_0x2b6e61[_0xbf4e('0x1d')]||0x3e1;if(_0x2b6e61[_0xbf4e('0x1e')]){_0x551d39['tls']=!![];}else{_0x551d39['tls']=![];_0x551d39[_0xbf4e('0x1f')]=_0xbf4e('0x20');}return _0x551d39;};EmailImap[_0xbf4e('0x11')][_0xbf4e('0xc')]=function(){this[_0xbf4e('0x1')]['openBox'](this[_0xbf4e('0x8')],![],this[_0xbf4e('0x21')][_0xbf4e('0xd')](this));};EmailImap[_0xbf4e('0x11')]['handleOpenBox']=function(_0x49b0f4,_0x27ac85){if(_0x49b0f4){this[_0xbf4e('0x22')](_0x49b0f4,!![]);}else{this[_0xbf4e('0x23')](_0xbf4e('0x24'),_0x27ac85);this['readUnseen']();}};EmailImap['prototype']['handleCloseBox']=function(_0x255166){if(_0x255166){this[_0xbf4e('0x22')](_0x255166,!![]);}else{this['imap'][_0xbf4e('0xe')]();}};EmailImap[_0xbf4e('0x11')][_0xbf4e('0x25')]=function(){this[_0xbf4e('0x1')][_0xbf4e('0x26')](['UNSEEN'],this['handleReadUnseen']['bind'](this));};EmailImap[_0xbf4e('0x11')][_0xbf4e('0x27')]=function(_0x486096,_0x5a7522){if(_0x486096){this['handleError'](_0x486096,!![]);}else{if(_0x5a7522['length']){try{var _0x2fd09a=this['imap']['fetch'](_0x5a7522,{'bodies':'','markSeen':!![]});_0x2fd09a['on'](_0xbf4e('0x28'),this[_0xbf4e('0x29')]['bind'](this));_0x2fd09a[_0xbf4e('0xb')](_0xbf4e('0xf'),this[_0xbf4e('0x2a')][_0xbf4e('0xd')](this));_0x2fd09a[_0xbf4e('0xb')]('end',this[_0xbf4e('0x2b')][_0xbf4e('0xd')](this));}catch(_0x44f962){logger[_0xbf4e('0xf')](_0x44f962);}}else{this[_0xbf4e('0x1')][_0xbf4e('0x2c')](!![],this['handleCloseBox'][_0xbf4e('0xd')](this));}}};EmailImap[_0xbf4e('0x11')][_0xbf4e('0x29')]=function(_0x4c7f99){_0x4c7f99['on'](_0xbf4e('0x2d'),this[_0xbf4e('0x2e')][_0xbf4e('0xd')](this));_0x4c7f99[_0xbf4e('0xb')](_0xbf4e('0x2f'),this[_0xbf4e('0x30')]['bind'](this));_0x4c7f99[_0xbf4e('0xb')](_0xbf4e('0xe'),this['handleMessageEnd']['bind'](this));};EmailImap['prototype'][_0xbf4e('0x2e')]=function(_0x2d6eef){simpleParser(_0x2d6eef,{'Iconv':Iconv},this['handleSimpleParser'][_0xbf4e('0xd')](this));};EmailImap['prototype'][_0xbf4e('0x30')]=function(){};EmailImap[_0xbf4e('0x11')]['handleMessageEnd']=function(){};EmailImap[_0xbf4e('0x11')][_0xbf4e('0x31')]=function(_0x2e98be,_0x2f052d){if(_0x2e98be){logger[_0xbf4e('0xf')](_0x2e98be);}else{var _0x3eee19=this;utils['parser'](this[_0xbf4e('0x9')],_0x2f052d,function(_0x200a91){_0x3eee19['emit'](_0xbf4e('0x7'),_0x200a91);});}};EmailImap[_0xbf4e('0x11')]['handleFetchEnd']=function(){this[_0xbf4e('0x1')][_0xbf4e('0x2c')](!![],this[_0xbf4e('0x32')][_0xbf4e('0xd')](this));};EmailImap['prototype'][_0xbf4e('0x2a')]=function(_0x1ccf36){this[_0xbf4e('0x22')](_0x1ccf36);this[_0xbf4e('0x1')][_0xbf4e('0x2c')](!![],this[_0xbf4e('0x32')]['bind'](this));};EmailImap[_0xbf4e('0x11')][_0xbf4e('0x33')]=function(){this[_0xbf4e('0x23')](_0xbf4e('0xe'));};EmailImap[_0xbf4e('0x11')]['handleError']=function(_0x33e0c0,_0x57602f){logger[_0xbf4e('0xf')](_0xbf4e('0x22'),this[_0xbf4e('0x9')][_0xbf4e('0x7')],JSON[_0xbf4e('0x34')](_0x33e0c0));var _0x8b79fe='';if(_0x33e0c0){if(_0x33e0c0[_0xbf4e('0x35')]){_0x8b79fe=_0x33e0c0['textCode'];}else{for(var _0x4c2c36 in _0x33e0c0){if(_0x33e0c0[_0xbf4e('0x36')](_0x4c2c36)){_0x8b79fe+=_[_0xbf4e('0x37')](_0x4c2c36)+':\x20'+_0x33e0c0[_0x4c2c36]+'\x0a';}}}}if(_0x57602f){this[_0xbf4e('0x1')][_0xbf4e('0xe')]();}else{this['emit'](_0xbf4e('0xf'),_0x8b79fe);this[_0xbf4e('0x23')]('end');}};module['exports']=EmailImap;