bf7c198f13bd7b2eb5967b26672f1e136410936d
[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 _0x4776=['handleReady','bind','end','error','inherits','prototype','connTimeout','authTimeout','user','modernAuthentication','xoauth2','generateXOAuth2Token','data5','password','anonymous@xcally.com','host','port','tls','autotls','required','openBox','handleOpenBox','handleError','emit','readUnseen','handleCloseBox','search','UNSEEN','handleReadUnseen','fetch','slice','message','handleFetchMessage','handleFetchError','handleFetchEnd','closeBox','body','attributes','handleMessageAttributes','handleMessageEnd','handleSimpleParser','handleEnd','hasOwnProperty','lodash','util','imap','mailparser','simpleParser','iconv','Iconv','events','EventEmitter','./utils','../../../config/logger','email','mailbox','getAccount','account','once','ready'];(function(_0x5dd8f9,_0x30a8ff){var _0x270d4a=function(_0x3e5c8b){while(--_0x3e5c8b){_0x5dd8f9['push'](_0x5dd8f9['shift']());}};_0x270d4a(++_0x30a8ff);}(_0x4776,0xdf));var _0x6477=function(_0x138adb,_0x193fee){_0x138adb=_0x138adb-0x0;var _0x1b27f2=_0x4776[_0x138adb];return _0x1b27f2;};'use strict';var _=require(_0x6477('0x0'));var util=require(_0x6477('0x1'));var Imap=require(_0x6477('0x2'));var simpleParser=require(_0x6477('0x3'))[_0x6477('0x4')];var Iconv=require(_0x6477('0x5'))[_0x6477('0x6')];var EventEmitter=require(_0x6477('0x7'))[_0x6477('0x8')];var utils=require(_0x6477('0x9'));var logger=require(_0x6477('0xa'))(_0x6477('0xb'));function EmailImap(_0x166696,_0x2788b1){this['mailbox']=_0x166696[_0x6477('0xc')];this['account']=this[_0x6477('0xd')](_0x166696,_0x2788b1);this[_0x6477('0x2')]=new Imap(this[_0x6477('0xe')]);this['imap'][_0x6477('0xf')](_0x6477('0x10'),this[_0x6477('0x11')][_0x6477('0x12')](this));this[_0x6477('0x2')][_0x6477('0xf')](_0x6477('0x13'),this['handleEnd'][_0x6477('0x12')](this));this['imap']['on'](_0x6477('0x14'),this['handleError'][_0x6477('0x12')](this));this[_0x6477('0x2')]['connect']();}util[_0x6477('0x15')](EmailImap,EventEmitter);EmailImap[_0x6477('0x16')][_0x6477('0xd')]=function(_0x11f523,_0x2fe8fe){var _0x1878eb={'connTimeout':_0x11f523['connTimeout']?_0x11f523[_0x6477('0x17')]*0x3e8:0x2710,'authTimeout':_0x11f523['authTimeout']?_0x11f523[_0x6477('0x18')]*0x3e8:0x1388};if(_0x11f523['service']){_0x1878eb[_0x6477('0x19')]=_0x11f523[_0x6477('0x19')];if(_0x11f523[_0x6477('0x1a')]){_0x1878eb[_0x6477('0x1b')]=utils[_0x6477('0x1c')](_0x11f523['CloudProvider'][_0x6477('0x1d')],_0x11f523[_0x6477('0x19')]);}else{_0x1878eb[_0x6477('0x1e')]=_0x11f523[_0x6477('0x1e')];}}else{if(_0x11f523['authentication']){_0x1878eb['user']=_0x11f523[_0x6477('0x19')];_0x1878eb['password']=_0x11f523['password'];}}_0x1878eb[_0x6477('0xb')]=_0x2fe8fe||_0x11f523[_0x6477('0x19')]||_0x6477('0x1f');_0x1878eb['host']=_0x11f523[_0x6477('0x20')];_0x1878eb[_0x6477('0x21')]=_0x11f523[_0x6477('0x21')]||0x3e1;if(_0x11f523[_0x6477('0x22')]){_0x1878eb[_0x6477('0x22')]=!![];}else{_0x1878eb[_0x6477('0x22')]=![];_0x1878eb[_0x6477('0x23')]=_0x6477('0x24');}return _0x1878eb;};EmailImap[_0x6477('0x16')]['handleReady']=function(){this[_0x6477('0x2')][_0x6477('0x25')](this[_0x6477('0xc')],![],this[_0x6477('0x26')][_0x6477('0x12')](this));};EmailImap[_0x6477('0x16')][_0x6477('0x26')]=function(_0x4ec09,_0x42c344){if(_0x4ec09){this[_0x6477('0x27')](_0x4ec09,!![]);}else{this[_0x6477('0x28')]('box',_0x42c344);this[_0x6477('0x29')]();}};EmailImap[_0x6477('0x16')][_0x6477('0x2a')]=function(_0x48621d){if(_0x48621d){this[_0x6477('0x27')](_0x48621d,!![]);}else{this[_0x6477('0x2')][_0x6477('0x13')]();}};EmailImap['prototype'][_0x6477('0x29')]=function(){this[_0x6477('0x2')][_0x6477('0x2b')]([_0x6477('0x2c')],this[_0x6477('0x2d')][_0x6477('0x12')](this));};EmailImap[_0x6477('0x16')][_0x6477('0x2d')]=function(_0x6e16ce,_0x2cff63){if(_0x6e16ce){this[_0x6477('0x27')](_0x6e16ce,!![]);}else{if(_0x2cff63['length']){try{var _0x319898=this[_0x6477('0x2')][_0x6477('0x2e')](_0x2cff63[_0x6477('0x2f')](0x0,0xa),{'bodies':'','markSeen':!![]});_0x319898['on'](_0x6477('0x30'),this[_0x6477('0x31')][_0x6477('0x12')](this));_0x319898['once'](_0x6477('0x14'),this[_0x6477('0x32')][_0x6477('0x12')](this));_0x319898[_0x6477('0xf')](_0x6477('0x13'),this[_0x6477('0x33')][_0x6477('0x12')](this));}catch(_0x1d2ae0){logger[_0x6477('0x14')](_0x1d2ae0);}}else{this['imap'][_0x6477('0x34')](!![],this[_0x6477('0x2a')][_0x6477('0x12')](this));}}};EmailImap[_0x6477('0x16')]['handleFetchMessage']=function(_0x2350f6){_0x2350f6['on'](_0x6477('0x35'),this['handleMessageBody'][_0x6477('0x12')](this));_0x2350f6[_0x6477('0xf')](_0x6477('0x36'),this[_0x6477('0x37')][_0x6477('0x12')](this));_0x2350f6['once'](_0x6477('0x13'),this[_0x6477('0x38')][_0x6477('0x12')](this));};EmailImap[_0x6477('0x16')]['handleMessageBody']=function(_0x5576c9){simpleParser(_0x5576c9,{'Iconv':Iconv},this[_0x6477('0x39')][_0x6477('0x12')](this));};EmailImap[_0x6477('0x16')][_0x6477('0x37')]=function(){};EmailImap['prototype'][_0x6477('0x38')]=function(){};EmailImap[_0x6477('0x16')]['handleSimpleParser']=function(_0x3ff2ff,_0x2d6065){if(_0x3ff2ff){logger[_0x6477('0x14')](_0x3ff2ff);}else{var _0x3ffea5=this;utils['parser'](this[_0x6477('0xe')],_0x2d6065,function(_0x4b64e4){_0x3ffea5[_0x6477('0x28')]('email',_0x4b64e4);});}};EmailImap[_0x6477('0x16')][_0x6477('0x33')]=function(){this[_0x6477('0x2')][_0x6477('0x34')](!![],this[_0x6477('0x2a')][_0x6477('0x12')](this));};EmailImap[_0x6477('0x16')]['handleFetchError']=function(_0x9eea1){this['handleError'](_0x9eea1);this[_0x6477('0x2')][_0x6477('0x34')](!![],this[_0x6477('0x2a')][_0x6477('0x12')](this));};EmailImap[_0x6477('0x16')][_0x6477('0x3a')]=function(){this['emit']('end');};EmailImap[_0x6477('0x16')][_0x6477('0x27')]=function(_0x130bbc,_0xc9f662){logger[_0x6477('0x14')]('handleError',this['account']['email'],JSON['stringify'](_0x130bbc));var _0x528c45='';if(_0x130bbc){if(_0x130bbc['textCode']){_0x528c45=_0x130bbc['textCode'];}else{for(var _0xe0c840 in _0x130bbc){if(_0x130bbc[_0x6477('0x3b')](_0xe0c840)){_0x528c45+=_['upperFirst'](_0xe0c840)+':\x20'+_0x130bbc[_0xe0c840]+'\x0a';}}}}if(_0xc9f662){this[_0x6477('0x2')][_0x6477('0x13')]();}else{this[_0x6477('0x28')](_0x6477('0x14'),_0x528c45);this[_0x6477('0x28')](_0x6477('0x13'));}};module['exports']=EmailImap;