37591c4cb7c9a003c17c9cf35b9958ef5249a746
[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 _0xe055=['readUnseen','handleCloseBox','search','UNSEEN','handleReadUnseen','length','fetch','message','handleFetchMessage','once','handleFetchEnd','closeBox','body','handleMessageBody','handleMessageEnd','handleSimpleParser','handleMessageAttributes','parser','handleFetchError','stringify','textCode','hasOwnProperty','lodash','util','imap','mailparser','simpleParser','Iconv','events','EventEmitter','../../../config/logger','mailbox','account','getAccount','handleReady','bind','end','handleEnd','error','connect','inherits','prototype','connTimeout','authTimeout','service','user','xoauth2','generateXOAuth2Token','CloudProvider','password','authentication','email','anonymous@xcally.com','host','port','tls','autotls','required','openBox','handleOpenBox','handleError','emit','box'];(function(_0x3248e0,_0x5d929b){var _0x38ec8e=function(_0x68d8ad){while(--_0x68d8ad){_0x3248e0['push'](_0x3248e0['shift']());}};_0x38ec8e(++_0x5d929b);}(_0xe055,0x1cf));var _0x5e05=function(_0x4a690d,_0x51473d){_0x4a690d=_0x4a690d-0x0;var _0x31e44c=_0xe055[_0x4a690d];return _0x31e44c;};'use strict';var _=require(_0x5e05('0x0'));var util=require(_0x5e05('0x1'));var Imap=require(_0x5e05('0x2'));var simpleParser=require(_0x5e05('0x3'))[_0x5e05('0x4')];var Iconv=require('iconv')[_0x5e05('0x5')];var EventEmitter=require(_0x5e05('0x6'))[_0x5e05('0x7')];var utils=require('./utils');var logger=require(_0x5e05('0x8'))('email');function EmailImap(_0x98e9b3,_0x3a74ac){this[_0x5e05('0x9')]=_0x98e9b3[_0x5e05('0x9')];this[_0x5e05('0xa')]=this[_0x5e05('0xb')](_0x98e9b3,_0x3a74ac);this['imap']=new Imap(this[_0x5e05('0xa')]);this[_0x5e05('0x2')]['once']('ready',this[_0x5e05('0xc')][_0x5e05('0xd')](this));this[_0x5e05('0x2')]['once'](_0x5e05('0xe'),this[_0x5e05('0xf')][_0x5e05('0xd')](this));this['imap']['on'](_0x5e05('0x10'),this['handleError'][_0x5e05('0xd')](this));this[_0x5e05('0x2')][_0x5e05('0x11')]();}util[_0x5e05('0x12')](EmailImap,EventEmitter);EmailImap[_0x5e05('0x13')][_0x5e05('0xb')]=function(_0x489e62,_0x441c9e){var _0x485e18={'connTimeout':_0x489e62[_0x5e05('0x14')]?_0x489e62['connTimeout']*0x3e8:0x2710,'authTimeout':_0x489e62[_0x5e05('0x15')]?_0x489e62['authTimeout']*0x3e8:0x1388};if(_0x489e62[_0x5e05('0x16')]){_0x485e18[_0x5e05('0x17')]=_0x489e62[_0x5e05('0x17')];if(_0x489e62['modernAuthentication']){_0x485e18[_0x5e05('0x18')]=utils[_0x5e05('0x19')](_0x489e62[_0x5e05('0x1a')]['data5'],_0x489e62[_0x5e05('0x17')]);}else{_0x485e18['password']=_0x489e62[_0x5e05('0x1b')];}}else{if(_0x489e62[_0x5e05('0x1c')]){_0x485e18['user']=_0x489e62[_0x5e05('0x17')];_0x485e18[_0x5e05('0x1b')]=_0x489e62[_0x5e05('0x1b')];}}_0x485e18[_0x5e05('0x1d')]=_0x441c9e||_0x489e62[_0x5e05('0x17')]||_0x5e05('0x1e');_0x485e18[_0x5e05('0x1f')]=_0x489e62[_0x5e05('0x1f')];_0x485e18[_0x5e05('0x20')]=_0x489e62[_0x5e05('0x20')]||0x3e1;if(_0x489e62[_0x5e05('0x21')]){_0x485e18[_0x5e05('0x21')]=!![];}else{_0x485e18[_0x5e05('0x21')]=![];_0x485e18[_0x5e05('0x22')]=_0x5e05('0x23');}return _0x485e18;};EmailImap[_0x5e05('0x13')]['handleReady']=function(){this['imap'][_0x5e05('0x24')](this[_0x5e05('0x9')],![],this[_0x5e05('0x25')][_0x5e05('0xd')](this));};EmailImap[_0x5e05('0x13')][_0x5e05('0x25')]=function(_0x26b970,_0x5c8c1d){if(_0x26b970){this[_0x5e05('0x26')](_0x26b970,!![]);}else{this[_0x5e05('0x27')](_0x5e05('0x28'),_0x5c8c1d);this[_0x5e05('0x29')]();}};EmailImap['prototype'][_0x5e05('0x2a')]=function(_0x182c0b){if(_0x182c0b){this['handleError'](_0x182c0b,!![]);}else{this[_0x5e05('0x2')]['end']();}};EmailImap[_0x5e05('0x13')]['readUnseen']=function(){this[_0x5e05('0x2')][_0x5e05('0x2b')]([_0x5e05('0x2c')],this[_0x5e05('0x2d')][_0x5e05('0xd')](this));};EmailImap['prototype'][_0x5e05('0x2d')]=function(_0x9aef4f,_0xe08ffd){if(_0x9aef4f){this[_0x5e05('0x26')](_0x9aef4f,!![]);}else{if(_0xe08ffd[_0x5e05('0x2e')]){try{var _0x26c212=this[_0x5e05('0x2')][_0x5e05('0x2f')](_0xe08ffd,{'bodies':'','markSeen':!![]});_0x26c212['on'](_0x5e05('0x30'),this[_0x5e05('0x31')][_0x5e05('0xd')](this));_0x26c212[_0x5e05('0x32')](_0x5e05('0x10'),this['handleFetchError'][_0x5e05('0xd')](this));_0x26c212[_0x5e05('0x32')]('end',this[_0x5e05('0x33')][_0x5e05('0xd')](this));}catch(_0x1877ac){logger[_0x5e05('0x10')](_0x1877ac);}}else{this[_0x5e05('0x2')][_0x5e05('0x34')](!![],this[_0x5e05('0x2a')]['bind'](this));}}};EmailImap[_0x5e05('0x13')][_0x5e05('0x31')]=function(_0x12bc5d){_0x12bc5d['on'](_0x5e05('0x35'),this[_0x5e05('0x36')][_0x5e05('0xd')](this));_0x12bc5d[_0x5e05('0x32')]('attributes',this['handleMessageAttributes'][_0x5e05('0xd')](this));_0x12bc5d[_0x5e05('0x32')](_0x5e05('0xe'),this[_0x5e05('0x37')][_0x5e05('0xd')](this));};EmailImap[_0x5e05('0x13')][_0x5e05('0x36')]=function(_0x53c73e){simpleParser(_0x53c73e,{'Iconv':Iconv},this[_0x5e05('0x38')][_0x5e05('0xd')](this));};EmailImap[_0x5e05('0x13')][_0x5e05('0x39')]=function(){};EmailImap['prototype']['handleMessageEnd']=function(){};EmailImap['prototype'][_0x5e05('0x38')]=function(_0x22c7e0,_0x43b99e){if(_0x22c7e0){logger[_0x5e05('0x10')](_0x22c7e0);}else{var _0x3f432f=this;utils[_0x5e05('0x3a')](this[_0x5e05('0xa')],_0x43b99e,function(_0x5899a7){_0x3f432f[_0x5e05('0x27')]('email',_0x5899a7);});}};EmailImap[_0x5e05('0x13')]['handleFetchEnd']=function(){this[_0x5e05('0x2')][_0x5e05('0x34')](!![],this[_0x5e05('0x2a')][_0x5e05('0xd')](this));};EmailImap[_0x5e05('0x13')][_0x5e05('0x3b')]=function(_0x1b86bc){this[_0x5e05('0x26')](_0x1b86bc);this[_0x5e05('0x2')][_0x5e05('0x34')](!![],this[_0x5e05('0x2a')]['bind'](this));};EmailImap['prototype'][_0x5e05('0xf')]=function(){this['emit'](_0x5e05('0xe'));};EmailImap['prototype'][_0x5e05('0x26')]=function(_0x57d90e,_0x534519){logger[_0x5e05('0x10')](_0x5e05('0x26'),this[_0x5e05('0xa')][_0x5e05('0x1d')],JSON[_0x5e05('0x3c')](_0x57d90e));var _0x317e32='';if(_0x57d90e){if(_0x57d90e[_0x5e05('0x3d')]){_0x317e32=_0x57d90e['textCode'];}else{for(var _0x54ce0c in _0x57d90e){if(_0x57d90e[_0x5e05('0x3e')](_0x54ce0c)){_0x317e32+=_['upperFirst'](_0x54ce0c)+':\x20'+_0x57d90e[_0x54ce0c]+'\x0a';}}}}if(_0x534519){this['imap'][_0x5e05('0xe')]();}else{this[_0x5e05('0x27')]('error',_0x317e32);this['emit'](_0x5e05('0xe'));}};module['exports']=EmailImap;