Built motion from commit 7ab0e143.|2.5.49
[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 _0xd8fb=['emit','box','readUnseen','handleCloseBox','search','UNSEEN','handleReadUnseen','length','fetch','message','handleFetchMessage','handleFetchError','end','closeBox','body','attributes','handleMessageAttributes','handleMessageEnd','handleSimpleParser','parser','account','handleFetchEnd','handleEnd','stringify','textCode','hasOwnProperty','upperFirst','lodash','util','imap','mailparser','events','EventEmitter','../../../config/logger','email','INBOX','getAccount','once','ready','handleReady','bind','error','connect','inherits','prototype','connTimeout','authTimeout','service','user','anonymous@xcally.com','modernAuthentication','generateXOAuth2Token','CloudProvider','password','host','port','tls','autotls','required','openBox','mailbox','handleOpenBox','handleError'];(function(_0x29c934,_0x3c30e2){var _0x4302de=function(_0x179a5a){while(--_0x179a5a){_0x29c934['push'](_0x29c934['shift']());}};_0x4302de(++_0x3c30e2);}(_0xd8fb,0x99));var _0xbd8f=function(_0x5aadf9,_0x337f84){_0x5aadf9=_0x5aadf9-0x0;var _0x197118=_0xd8fb[_0x5aadf9];return _0x197118;};'use strict';var _=require(_0xbd8f('0x0'));var util=require(_0xbd8f('0x1'));var Imap=require(_0xbd8f('0x2'));var simpleParser=require(_0xbd8f('0x3'))['simpleParser'];var Iconv=require('iconv')['Iconv'];var EventEmitter=require(_0xbd8f('0x4'))[_0xbd8f('0x5')];var utils=require('./utils');var logger=require(_0xbd8f('0x6'))(_0xbd8f('0x7'));function EmailImap(_0x5543b2,_0x33d541){this['mailbox']=_0xbd8f('0x8');this['account']=this[_0xbd8f('0x9')](_0x5543b2,_0x33d541);this[_0xbd8f('0x2')]=new Imap(this['account']);this['imap'][_0xbd8f('0xa')](_0xbd8f('0xb'),this[_0xbd8f('0xc')]['bind'](this));this[_0xbd8f('0x2')][_0xbd8f('0xa')]('end',this['handleEnd'][_0xbd8f('0xd')](this));this[_0xbd8f('0x2')]['on'](_0xbd8f('0xe'),this['handleError'][_0xbd8f('0xd')](this));this[_0xbd8f('0x2')][_0xbd8f('0xf')]();}util[_0xbd8f('0x10')](EmailImap,EventEmitter);EmailImap[_0xbd8f('0x11')][_0xbd8f('0x9')]=function(_0x37d4d5,_0x29ffe8){var _0x14606c={'connTimeout':_0x37d4d5['connTimeout']?_0x37d4d5[_0xbd8f('0x12')]*0x3e8:0x2710,'authTimeout':_0x37d4d5[_0xbd8f('0x13')]?_0x37d4d5[_0xbd8f('0x13')]*0x3e8:0x1388};if(_0x37d4d5[_0xbd8f('0x14')]){_0x14606c['user']=_0x37d4d5[_0xbd8f('0x15')];_0x14606c[_0xbd8f('0x7')]=_0x29ffe8||_0x37d4d5['user']||_0xbd8f('0x16');if(_0x37d4d5[_0xbd8f('0x17')]){_0x14606c['xoauth2']=utils[_0xbd8f('0x18')](_0x37d4d5[_0xbd8f('0x19')]['data5'],_0x37d4d5['user']);}else{_0x14606c[_0xbd8f('0x1a')]=_0x37d4d5['password'];}}else{if(_0x37d4d5['authentication']){_0x14606c[_0xbd8f('0x15')]=_0x37d4d5['user'];_0x14606c[_0xbd8f('0x1a')]=_0x37d4d5[_0xbd8f('0x1a')];}}_0x14606c[_0xbd8f('0x1b')]=_0x37d4d5[_0xbd8f('0x1b')];_0x14606c[_0xbd8f('0x1c')]=_0x37d4d5[_0xbd8f('0x1c')]||0x3e1;if(_0x37d4d5[_0xbd8f('0x1d')]){_0x14606c[_0xbd8f('0x1d')]=!![];}else{_0x14606c[_0xbd8f('0x1d')]=![];_0x14606c[_0xbd8f('0x1e')]=_0xbd8f('0x1f');}return _0x14606c;};EmailImap[_0xbd8f('0x11')][_0xbd8f('0xc')]=function(){this[_0xbd8f('0x2')][_0xbd8f('0x20')](this[_0xbd8f('0x21')],![],this[_0xbd8f('0x22')]['bind'](this));};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x22')]=function(_0x1f9fcc,_0x2f3df7){if(_0x1f9fcc){this[_0xbd8f('0x23')](_0x1f9fcc,!![]);}else{this[_0xbd8f('0x24')](_0xbd8f('0x25'),_0x2f3df7);this[_0xbd8f('0x26')]();}};EmailImap['prototype'][_0xbd8f('0x27')]=function(_0x421f3e){if(_0x421f3e){this['handleError'](_0x421f3e,!![]);}else{this[_0xbd8f('0x2')]['end']();}};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x26')]=function(){this[_0xbd8f('0x2')][_0xbd8f('0x28')]([_0xbd8f('0x29')],this[_0xbd8f('0x2a')]['bind'](this));};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x2a')]=function(_0x39714d,_0x3ee851){if(_0x39714d){this[_0xbd8f('0x23')](_0x39714d,!![]);}else{if(_0x3ee851[_0xbd8f('0x2b')]){try{var _0x2a4b32=this['imap'][_0xbd8f('0x2c')](_0x3ee851,{'bodies':'','markSeen':!![]});_0x2a4b32['on'](_0xbd8f('0x2d'),this[_0xbd8f('0x2e')][_0xbd8f('0xd')](this));_0x2a4b32['once']('error',this[_0xbd8f('0x2f')][_0xbd8f('0xd')](this));_0x2a4b32[_0xbd8f('0xa')](_0xbd8f('0x30'),this['handleFetchEnd'][_0xbd8f('0xd')](this));}catch(_0x1f550a){logger[_0xbd8f('0xe')](_0x1f550a);}}else{this[_0xbd8f('0x2')][_0xbd8f('0x31')](!![],this['handleCloseBox'][_0xbd8f('0xd')](this));}}};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x2e')]=function(_0x3949c2){_0x3949c2['on'](_0xbd8f('0x32'),this['handleMessageBody'][_0xbd8f('0xd')](this));_0x3949c2['once'](_0xbd8f('0x33'),this[_0xbd8f('0x34')][_0xbd8f('0xd')](this));_0x3949c2[_0xbd8f('0xa')](_0xbd8f('0x30'),this[_0xbd8f('0x35')]['bind'](this));};EmailImap['prototype']['handleMessageBody']=function(_0x22d1de){simpleParser(_0x22d1de,{'Iconv':Iconv},this[_0xbd8f('0x36')][_0xbd8f('0xd')](this));};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x34')]=function(){};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x35')]=function(){};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x36')]=function(_0x2a6145,_0x3d4c9a){if(_0x2a6145){logger[_0xbd8f('0xe')](_0x2a6145);}else{var _0x26133b=this;utils[_0xbd8f('0x37')](this[_0xbd8f('0x38')],_0x3d4c9a,function(_0x50e081){_0x26133b[_0xbd8f('0x24')](_0xbd8f('0x7'),_0x50e081);});}};EmailImap['prototype'][_0xbd8f('0x39')]=function(){this[_0xbd8f('0x2')][_0xbd8f('0x31')](!![],this['handleCloseBox'][_0xbd8f('0xd')](this));};EmailImap['prototype'][_0xbd8f('0x2f')]=function(_0x32f7d5){this[_0xbd8f('0x23')](_0x32f7d5);this['imap'][_0xbd8f('0x31')](!![],this[_0xbd8f('0x27')][_0xbd8f('0xd')](this));};EmailImap['prototype'][_0xbd8f('0x3a')]=function(){this[_0xbd8f('0x24')](_0xbd8f('0x30'));};EmailImap[_0xbd8f('0x11')][_0xbd8f('0x23')]=function(_0x1db8c7,_0x25f054){logger[_0xbd8f('0xe')](_0xbd8f('0x23'),this['account']['email'],JSON[_0xbd8f('0x3b')](_0x1db8c7));var _0x1070cb='';if(_0x1db8c7){if(_0x1db8c7[_0xbd8f('0x3c')]){_0x1070cb=_0x1db8c7[_0xbd8f('0x3c')];}else{for(var _0x5e9f71 in _0x1db8c7){if(_0x1db8c7[_0xbd8f('0x3d')](_0x5e9f71)){_0x1070cb+=_[_0xbd8f('0x3e')](_0x5e9f71)+':\x20'+_0x1db8c7[_0x5e9f71]+'\x0a';}}}}if(_0x25f054){this[_0xbd8f('0x2')][_0xbd8f('0x30')]();}else{this[_0xbd8f('0x24')]('error',_0x1070cb);this['emit'](_0xbd8f('0x30'));}};module['exports']=EmailImap;