c1aba77a26dba2941b0ca8182fc6b9c1100a9365
[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 _0x98c7=['once','ready','handleReady','bind','end','handleEnd','error','handleError','connect','inherits','prototype','authTimeout','service','user','password','host','port','autotls','getHost','tls','anonymous@xcally.com','openBox','mailbox','handleOpenBox','emit','box','readUnseen','search','UNSEEN','handleReadUnseen','length','fetch','handleFetchMessage','handleFetchError','closeBox','handleCloseBox','body','handleMessageBody','attributes','handleMessageAttributes','handleMessageEnd','handleSimpleParser','parser','handleFetchEnd','stringify','textCode','hasOwnProperty','upperFirst','exports','path','util','imap','randomstring','mailparser','iconv','events','EventEmitter','./utils','email','INBOX','account','getAccount'];(function(_0x1a36a5,_0x746928){var _0x746243=function(_0x481966){while(--_0x481966){_0x1a36a5['push'](_0x1a36a5['shift']());}};_0x746243(++_0x746928);}(_0x98c7,0x129));var _0x798c=function(_0x3dee92,_0x55e1eb){_0x3dee92=_0x3dee92-0x0;var _0x44d36e=_0x98c7[_0x3dee92];return _0x44d36e;};'use strict';var fs=require('fs');var path=require(_0x798c('0x0'));var util=require(_0x798c('0x1'));var Imap=require(_0x798c('0x2'));var _=require('lodash');var rs=require(_0x798c('0x3'));var simpleParser=require(_0x798c('0x4'))['simpleParser'];var Iconv=require(_0x798c('0x5'))['Iconv'];var EventEmitter=require(_0x798c('0x6'))[_0x798c('0x7')];var utils=require(_0x798c('0x8'));var logger=require('../../../config/logger')(_0x798c('0x9'));function EmailImap(_0x1067bd,_0x9d09b){this['mailbox']=_0x798c('0xa');this[_0x798c('0xb')]=this[_0x798c('0xc')](_0x1067bd,_0x9d09b);this[_0x798c('0x2')]=new Imap(this['account']);this[_0x798c('0x2')][_0x798c('0xd')](_0x798c('0xe'),this[_0x798c('0xf')][_0x798c('0x10')](this));this['imap'][_0x798c('0xd')](_0x798c('0x11'),this[_0x798c('0x12')][_0x798c('0x10')](this));this['imap']['on'](_0x798c('0x13'),this[_0x798c('0x14')][_0x798c('0x10')](this));this[_0x798c('0x2')][_0x798c('0x15')]();}util[_0x798c('0x16')](EmailImap,EventEmitter);EmailImap[_0x798c('0x17')][_0x798c('0xc')]=function(_0x30696c,_0x5e926a){var _0x2addfa={'connTimeout':_0x30696c['connTimeout']?_0x30696c['connTimeout']*0x3e8:0x2710,'authTimeout':_0x30696c[_0x798c('0x18')]?_0x30696c[_0x798c('0x18')]*0x3e8:0x1388};if(_['isNil'](_0x30696c[_0x798c('0x19')])){if(_0x30696c['authentication']){_0x2addfa[_0x798c('0x1a')]=_0x30696c[_0x798c('0x1a')];_0x2addfa[_0x798c('0x1b')]=_0x30696c[_0x798c('0x1b')];}_0x2addfa[_0x798c('0x1c')]=_0x30696c['host'];_0x2addfa[_0x798c('0x1d')]=_0x30696c[_0x798c('0x1d')]||0x3e1;if(_0x30696c['tls']){_0x2addfa['tls']=!![];}else{_0x2addfa['tls']=![];_0x2addfa[_0x798c('0x1e')]='required';}}else{_0x2addfa[_0x798c('0x1a')]=_0x30696c[_0x798c('0x1a')];_0x2addfa[_0x798c('0x1b')]=_0x30696c[_0x798c('0x1b')];_0x2addfa[_0x798c('0x1c')]=utils[_0x798c('0x1f')](_0x30696c[_0x798c('0x19')]);_0x2addfa[_0x798c('0x1d')]=0x3e1;_0x2addfa[_0x798c('0x20')]=!![];}_0x2addfa[_0x798c('0x9')]=_0x5e926a||_0x30696c[_0x798c('0x1a')]||_0x798c('0x21');return _0x2addfa;};EmailImap[_0x798c('0x17')][_0x798c('0xf')]=function(){this['imap'][_0x798c('0x22')](this[_0x798c('0x23')],![],this[_0x798c('0x24')][_0x798c('0x10')](this));};EmailImap[_0x798c('0x17')][_0x798c('0x24')]=function(_0x18cb9b,_0x27c266){if(_0x18cb9b){this[_0x798c('0x14')](_0x18cb9b,!![]);}else{this[_0x798c('0x25')](_0x798c('0x26'),_0x27c266);this[_0x798c('0x27')]();}};EmailImap[_0x798c('0x17')]['handleCloseBox']=function(_0x4ed92b){if(_0x4ed92b){this[_0x798c('0x14')](_0x4ed92b,!![]);}else{this[_0x798c('0x2')][_0x798c('0x11')]();}};EmailImap[_0x798c('0x17')][_0x798c('0x27')]=function(){this['imap'][_0x798c('0x28')]([_0x798c('0x29')],this['handleReadUnseen'][_0x798c('0x10')](this));};EmailImap[_0x798c('0x17')][_0x798c('0x2a')]=function(_0x333e36,_0x106174){if(_0x333e36){this['handleError'](_0x333e36,!![]);}else{if(_0x106174[_0x798c('0x2b')]){try{var _0x21a52b=this[_0x798c('0x2')][_0x798c('0x2c')](_0x106174,{'bodies':'','markSeen':!![]});_0x21a52b['on']('message',this[_0x798c('0x2d')][_0x798c('0x10')](this));_0x21a52b[_0x798c('0xd')](_0x798c('0x13'),this[_0x798c('0x2e')][_0x798c('0x10')](this));_0x21a52b[_0x798c('0xd')](_0x798c('0x11'),this['handleFetchEnd']['bind'](this));}catch(_0x12860a){logger[_0x798c('0x13')](_0x12860a);}}else{this[_0x798c('0x2')][_0x798c('0x2f')](!![],this[_0x798c('0x30')][_0x798c('0x10')](this));}}};EmailImap[_0x798c('0x17')]['handleFetchMessage']=function(_0x1426c4,_0x2019b9){_0x1426c4['on'](_0x798c('0x31'),this[_0x798c('0x32')][_0x798c('0x10')](this));_0x1426c4['once'](_0x798c('0x33'),this[_0x798c('0x34')][_0x798c('0x10')](this));_0x1426c4[_0x798c('0xd')](_0x798c('0x11'),this[_0x798c('0x35')][_0x798c('0x10')](this));};EmailImap['prototype'][_0x798c('0x32')]=function(_0x4b84d2,_0x3874d7){simpleParser(_0x4b84d2,{'Iconv':Iconv},this['handleSimpleParser'][_0x798c('0x10')](this));};EmailImap['prototype'][_0x798c('0x34')]=function(_0x309253){};EmailImap[_0x798c('0x17')][_0x798c('0x35')]=function(){};EmailImap[_0x798c('0x17')][_0x798c('0x36')]=function(_0x10fc7d,_0x234d07){if(_0x10fc7d){logger[_0x798c('0x13')](_0x10fc7d);}else{var _0x1cc987=this;utils[_0x798c('0x37')](this['account'],_0x234d07,function(_0x5e1a06){_0x1cc987[_0x798c('0x25')]('email',_0x5e1a06);});}};EmailImap[_0x798c('0x17')][_0x798c('0x38')]=function(){this['imap']['closeBox'](!![],this['handleCloseBox'][_0x798c('0x10')](this));};EmailImap[_0x798c('0x17')][_0x798c('0x2e')]=function(_0x19acfd){this[_0x798c('0x14')](_0x19acfd);this['imap']['closeBox'](!![],this['handleCloseBox'][_0x798c('0x10')](this));};EmailImap[_0x798c('0x17')]['handleEnd']=function(){this[_0x798c('0x25')](_0x798c('0x11'));};EmailImap[_0x798c('0x17')][_0x798c('0x14')]=function(_0x18c8ff,_0x1cd275){logger['error'](_0x798c('0x14'),this[_0x798c('0xb')]['email'],JSON[_0x798c('0x39')](_0x18c8ff));var _0x47e0a1='';if(_0x18c8ff){if(_0x18c8ff[_0x798c('0x3a')]){_0x47e0a1=_0x18c8ff[_0x798c('0x3a')];}else{for(var _0x348c3f in _0x18c8ff){if(_0x18c8ff[_0x798c('0x3b')](_0x348c3f)){_0x47e0a1+=_[_0x798c('0x3c')](_0x348c3f)+':\x20'+_0x18c8ff[_0x348c3f]+'\x0a';}}}}if(_0x1cd275){this[_0x798c('0x2')][_0x798c('0x11')]();}else{this['emit'](_0x798c('0x13'),_0x47e0a1);this[_0x798c('0x25')](_0x798c('0x11'));}};module[_0x798c('0x3d')]=EmailImap;