@@ -266,6 +266,8 @@ class ImapServerSwitchStream extends Stream.Transform {
266266 doNewMail ( ) {
267267 this . canDoLogout = true ;
268268 this . checkLogout ( ( ) => {
269+ if ( / L O G O U T / . test ( this . cmd ) )
270+ return ;
269271 this . canDoLogout = false ;
270272 this . runningCommand = 'doNewMail' ;
271273 this . seachUnseen ( ( err , newMailIds , havemore ) => {
@@ -312,6 +314,8 @@ class ImapServerSwitchStream extends Stream.Transform {
312314 idleNoop ( ) {
313315 this . canDoLogout = true ;
314316 this . checkLogout ( ( ) => {
317+ if ( / L O G O U T / . test ( this . cmd ) )
318+ return ;
315319 let newSwitchRet = false ;
316320 this . runningCommand = 'idle' ;
317321 if ( ! this . ready ) {
@@ -490,9 +494,11 @@ class ImapServerSwitchStream extends Stream.Transform {
490494 return this . logout_process ( this . waitLogoutCallBack ) ;
491495 }
492496 this . canDoLogout = false ;
493- this . doCommandCallback = ( ) => {
497+ this . doCommandCallback = err => {
494498 this . canDoLogout = true ;
495- this . checkLogout ( CallBack ) ;
499+ this . checkLogout ( ( ) => {
500+ CallBack ( err ) ;
501+ } ) ;
496502 } ;
497503 let out = `Content-Type: application/octet-stream\r\nContent-Disposition: attachment\r\nMessage-ID:<${ Uuid . v4 ( ) } @>${ this . imapServer . domainName } \r\nContent-Transfer-Encoding: base64\r\nMIME-Version: 1.0\r\n\r\n${ text } ` ;
498504 this . commandProcess = ( text1 , cmdArray , next , _callback ) => {
@@ -902,6 +908,7 @@ exports.imapAccountTest = (IMapConnect, CallBack) => {
902908 rImap . logout ( ) ;
903909 rImap = null ;
904910 const attach = exports . getMailAttached ( mail ) ;
911+ console . log ( `rImap on new mail!` , attach ) ;
905912 if ( ! attach && ! callbackCall ) {
906913 return doCallBack ( new Error ( `imapAccountTest ERROR: can't read attachment!` ) , null ) ;
907914 }
@@ -911,10 +918,18 @@ exports.imapAccountTest = (IMapConnect, CallBack) => {
911918 return doCallBack ( null , new Date ( ) . getTime ( ) - startTime ) ;
912919 } ) ;
913920 rImap . once ( 'ready' , ( ) => {
921+ console . log ( `rImap.once ( 'ready' )` ) ;
914922 wImap = new qtGateImapwrite ( IMapConnect , listenFolder ) ;
915923 wImap . once ( 'ready' , ( ) => {
924+ console . log ( `wImap.once ( 'ready' )` ) ;
916925 startTime = new Date ( ) . getTime ( ) ;
917- wImap . append ( ramdomText . toString ( 'base64' ) , ( ) => {
926+ wImap . append ( ramdomText . toString ( 'base64' ) , err => {
927+ if ( err ) {
928+ console . log ( `wImap.append err` , err ) ;
929+ }
930+ else {
931+ console . log ( `wImap.append success` ) ;
932+ }
918933 wImap . logout ( ) ;
919934 wImap = null ;
920935 } ) ;
@@ -946,6 +961,7 @@ class imapPeer extends Event.EventEmitter {
946961 this . doingDestroy = false ;
947962 this . wImapReady = false ;
948963 this . peerReady = false ;
964+ this . sendFirstPing = false ;
949965 this . rImap = null ;
950966 this . sendMailPool = [ ] ;
951967 this . wImap = null ;
@@ -961,14 +977,24 @@ class imapPeer extends Event.EventEmitter {
961977 const uu = JSON . parse ( data ) ;
962978 if ( uu . ping && uu . ping . length ) {
963979 saveLog ( 'GOT PING REPLY PONG!' ) ;
964- if ( this . wImapReady )
965- this . replyPing ( uu ) ;
966980 if ( ! this . peerReady ) {
981+ if ( / o u t l o o k \. c o m / i. test ( this . imapData . imapServer ) ) {
982+ saveLog ( `doing outlook server support!` ) ;
983+ return setTimeout ( ( ) => {
984+ saveLog ( `outlook replyPing ()` ) ;
985+ this . pingUuid = null ;
986+ if ( this . wImapReady )
987+ this . replyPing ( uu ) ;
988+ return this . Ping ( ) ;
989+ } , 5000 ) ;
990+ }
991+ if ( this . wImapReady )
992+ this . replyPing ( uu ) ;
967993 saveLog ( `THIS peerConnect have not ready send ping!` ) ;
968994 this . pingUuid = null ;
969995 return this . Ping ( ) ;
970996 }
971- return ;
997+ return this . replyPing ( uu ) ;
972998 }
973999 if ( uu . pong && uu . pong . length ) {
9741000 if ( ! this . pingUuid && this . pingUuid !== uu . ping )
@@ -995,30 +1021,35 @@ class imapPeer extends Event.EventEmitter {
9951021 } ) ;
9961022 }
9971023 Ping ( ) {
998- saveLog ( 'doing ping!' ) ;
9991024 if ( ! this . wImapReady || this . pingUuid !== null )
10001025 return saveLog ( `Ping do nothing : this.wImapReady [${ this . wImapReady } ] || this.pingUuid [${ this . pingUuid } ]` ) ;
10011026 this . pingUuid = Uuid . v4 ( ) ;
10021027 return this . enCrypto ( JSON . stringify ( { ping : this . pingUuid } ) , ( err , data ) => {
1003- if ( err )
1004- return saveLog ( `Ping enCrypto error! [${ err . message } ]` ) ;
1005- return this . append ( data ) ;
1028+ if ( err ) {
1029+ return saveLog ( `Ping enCrypto error: [${ err . message } ]` ) ;
1030+ }
1031+ const doSend = ( ) => {
1032+ this . sendToRemote ( Buffer . from ( data ) , err => {
1033+ if ( err ) {
1034+ this . emit ( 'wFolder' ) ;
1035+ return saveLog ( `Ping doSend error! [${ err . message } ]` ) ;
1036+ }
1037+ saveLog ( `PING success!` ) ;
1038+ } ) ;
1039+ } ;
1040+ doSend ( ) ;
10061041 } ) ;
10071042 }
10081043 sendAllMail ( ) {
1009- saveLog ( `sendAllMail ` ) ;
10101044 if ( ! this . sendMailPool . length || ! this . wImapReady )
10111045 return saveLog ( `sendAllMail do nothing! sendMailPool.length [${ this . sendMailPool . length } ] wImapReady [${ this . wImapReady } ]` ) ;
10121046 const uu = Buffer . from ( this . sendMailPool . pop ( ) ) ;
10131047 if ( ! uu )
10141048 return saveLog ( `sendAllMail this.sendMailPool.pop () got nothing!` ) ;
10151049 this . sendToRemote ( uu , err => {
10161050 if ( err ) {
1017- saveLog ( `this.wImap.append error [${ err . message } ] and do again ! ` ) ;
1051+ saveLog ( `this.wImap.append error [${ err . message } ]! ` ) ;
10181052 this . sendMailPool . push ( ) ;
1019- setTimeout ( ( ) => {
1020- return this . sendAllMail ( ) ;
1021- } , 500 ) ;
10221053 }
10231054 saveLog ( `sendAllMail sendToRemote success!` ) ;
10241055 } ) ;
@@ -1031,7 +1062,7 @@ class imapPeer extends Event.EventEmitter {
10311062 if ( ! this . doingDestroy )
10321063 return this . newWriteImap ( ) ;
10331064 } ) ;
1034- this . wImap . on ( 'error' , err => {
1065+ this . wImap . once ( 'error' , err => {
10351066 if ( err && err . message && / A U T H | c e r t i f i c a t e / i. test ( err . message ) ) {
10361067 return this . destroy ( 1 ) ;
10371068 }
@@ -1040,8 +1071,19 @@ class imapPeer extends Event.EventEmitter {
10401071 } ) ;
10411072 this . wImap . once ( 'ready' , ( ) => {
10421073 this . wImapReady = true ;
1043- saveLog ( `this.wImap.once on ready! send ping` ) ;
1044- this . Ping ( ) ;
1074+ if ( this . sendFirstPing ) {
1075+ this . sendAllMail ( ) ;
1076+ return saveLog ( `this.wImap.once on ready! already sent ping` ) ;
1077+ }
1078+ this . sendFirstPing = true ;
1079+ if ( / o u t l o o k \. c o m / i. test ( this . imapData . imapServer ) ) {
1080+ saveLog ( `outlook support!` ) ;
1081+ this . once ( 'wFolder' , ( ) => {
1082+ saveLog ( `this.once ( 'wFolder') do makeWriteFolder!` ) ;
1083+ return this . makeWriteFolder ( ) ;
1084+ } ) ;
1085+ }
1086+ return this . Ping ( ) ;
10451087 } ) ;
10461088 }
10471089 newReadImap ( ) {
@@ -1070,6 +1112,22 @@ class imapPeer extends Event.EventEmitter {
10701112 return this . newReadImap ( ) ;
10711113 } ) ;
10721114 }
1115+ makeWriteFolder ( ) {
1116+ let uu = new qtGateImapRead ( this . imapData , this . writeBox , false , false , email => { } ) ;
1117+ uu . once ( 'ready' , ( ) => {
1118+ uu . destroyAll ( null ) ;
1119+ this . pingUuid = null ;
1120+ this . wImap . destroyAll ( null ) ;
1121+ } ) ;
1122+ uu . once ( 'error' , err => {
1123+ saveLog ( `makeWriteFolder error! do again!` ) ;
1124+ uu = null ;
1125+ return this . makeWriteFolder ( ) ;
1126+ } ) ;
1127+ uu . once ( 'end' , ( ) => {
1128+ uu = null ;
1129+ } ) ;
1130+ }
10731131 destroy ( err ) {
10741132 if ( this . doingDestroy )
10751133 return ;
0 commit comments