Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #147 #148

Closed
wants to merge 1 commit into from
Closed

Fixes #147 #148

wants to merge 1 commit into from

Conversation

rickhall
Copy link

Fixed #147

Not sure if the proposed patch is the best way to do this or it has other ramifications, but it appears to work for me.

…ere being handling improperly and would not continue to look for additional literals since it wasn't clear that a literal was found. Introduce a flag to indicate that a literal was found, so we know to keep looking for more literals regardless of whether literal has any length or not.
@rickhall
Copy link
Author

Not sure what that test failure is, it works for me locally:

$ npm run test

> [email protected] test /Users/rickhall/Projects/emailjs-imap-client
> grunt

Running "jshint:all" (jshint) task
>> 9 files lint free.

Running "mochaTest:test" (mochaTest) task


  browserbox integration tests
    Connection tests
      ✓ should use STARTTLS by default (55ms)
      ✓ should ignore STARTTLS
      ✓ should fail connecting to non-STARTTLS host
      ✓ should connect to non secure host
    Post login tests
      #listMailboxes
        ✓ should succeed
      #listMessages
        ✓ should succeed
      #upload
        ✓ should succeed
      #search
        ✓ should return a sequence number
        ✓ should return an uid
        ✓ should work with complex queries
      #setFlags
        ✓ should set flags for a message
        ✓ should add flags to a message
        ✓ should remove flags from a message
        ✓ should not return anything on silent mode
      #store
        ✓ should add labels for a message
        ✓ should set labels for a message
        ✓ should remove labels from a message
      #deleteMessages
        ✓ should delete a message
      #copyMessages
        ✓ should copy a message
      #moveMessages
        ✓ should move a message
      precheck
(node:17068) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 2): TypeError: Cannot read property 'length' of undefined
(node:17068) DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
        ✓ should handle precheck error correctly
        ✓ should select correct mailboxes in prechecks on concurrent calls
        ✓ should send precheck commands in correct order on concurrent calls
    Timeout
      ✓ should timeout
(node:17068) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 3): Error: 24 Socket timed out!
      ✓ should reject all pending commands on timeout

  browserbox imap unit tests
    #close
      ✓ should call socket.close
      ✓ should call socket.close
    #upgrade
      ✓ should upgrade socket
      ✓ should not upgrade socket
    #setHandler
      ✓ should set global handler for keyword
    #socket.onerror
      ✓ should emit error and close connection
    #socket.onclose
      ✓ should emit error 
    #_onData
      ✓ should process input
    #_iterateIncomingBuffer
      ✓ Parse multiple zero-length literals
      ✓ should iterate chunked input
      ✓ should process chunked literals
      ✓ should process chunked literals 2
      ✓ should process chunked literals 3
      ✓ should process chunked literals 4
      ✓ should process CRLF literal
      ✓ should process CRLF literal 2
      ✓ should process two commands when CRLF arrives in 2 parts
      ✓ should process literal when literal count arrives in 2 parts
      ✓ should process literal when literal count arrives in 2 parts 2
      ✓ should process literal when literal count arrives in 2 parts 3
      ✓ should process literal when literal count arrives in 2 parts 4
      ✓ should process literal when literal count arrives in 3 parts
      ✓ should process SEARCH response when it arrives in 2 parts
      ✓ should not process {} in string as literal 1
      ✓ should not process {} in string as literal 2
    #_parseIncomingCommands
      ✓ should process a tagged item from the queue
      ✓ should process an untagged item from the queue
      ✓ should process a plus tagged item from the queue
      ✓ should process an XOAUTH2 error challenge
    #_handleResponse
      ✓ should invoke global handler by default
      ✓ should invoke global handler if needed
      ✓ should push to payload
      ✓ should invoke command callback
    #enqueueCommand
      ✓ should reject on NO/BAD
      ✓ should invoke sending
      ✓ should only queue
    #_sendRequest
      ✓ should enter idle if nothing is to process
      ✓ should send data
      ✓ should send partial data
      ✓ should run precheck
    #_enterIdle
      ✓ should set idle timer
    #_processResponse
      ✓ should set humanReadable
      ✓ should set response code
    #isError
      ✓ should detect if an object is an error
    #enableCompression
      ✓ should create inflater and deflater streams
    #getPreviouslyQueued
      ✓ should return undefined with empty queue and no current command
      ✓ should return undefined with empty queue and non-SELECT current command
      ✓ should return current command with empty queue and SELECT current command
      ✓ should return current command with non-SELECT commands in queue and SELECT current command
      ✓ should return last SELECT before ctx with multiple SELECT commands in queue (1)
      ✓ should return last SELECT before ctx with multiple SELECT commands in queue (2)
      ✓ should return last SELECT before ctx with multiple SELECT commands in queue (3)

  browserbox unit tests
    #_onIdle
      ✓ should call enterIdle
      ✓ should not call enterIdle
    #connect
      ✓ should connect
(node:17068) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 5): Error
      ✓ should fail to login
(node:17068) PromiseRejectionHandledWarning: Promise rejection was handled asynchronously (rejection id: 5)
      ✓ should timeout
    #close
      ✓ should force-close
    #exec
      ✓ should send string command
      ✓ should update capability from response
    #enterIdle
      ✓ should periodically send NOOP if IDLE not supported
      ✓ should break IDLE after timeout
    #breakIdle
      ✓ should send DONE to socket
    #upgradeConnection
      ✓ should do nothing if already secured
      ✓ should do nothing if STARTTLS not available
      ✓ should run STARTTLS
    #updateCapability
      ✓ should do nothing if capability is set
      ✓ should run CAPABILITY if capability not set
      ✓ should force run CAPABILITY
      ✓ should do nothing if connection is not yet upgraded
    #listNamespaces
      ✓ should run NAMESPACE if supported
      ✓ should do nothing if not supported
    #compressConnection
      ✓ should run COMPRESS=DEFLATE if supported
      ✓ should do nothing if not supported
      ✓ should do nothing if not enabled
    #login
      ✓ should call LOGIN
      ✓ should call XOAUTH2
    #updateId
      ✓ should not nothing if not supported
      ✓ should send NIL
      ✓ should exhange ID values
    #listMailboxes
      ✓ should call LIST and LSUB in sequence
      ✓ should not die on NIL separators
    #createMailbox
      ✓ should call CREATE with a string payload
      ✓ should call mutf7 encode the argument
      ✓ should treat an ALREADYEXISTS response as success
    #listMessages
      ✓ should call FETCH
    #search
      ✓ should call SEARCH
    #upload
      ✓ should call APPEND with custom flag
      ✓ should call APPEND w/o flags
    #setFlags
      ✓ should call STORE
    #store
      ✓ should call STORE
    #deleteMessages
      ✓ should call UID EXPUNGE
      ✓ should call EXPUNGE
    #copyMessages
      ✓ should call COPY
    #moveMessages
      ✓ should call MOVE if supported
      ✓ should fallback to copy+expunge
    #_shouldSelectMailbox
      ✓ should return true when ctx is undefined
      ✓ should return true when a different path is queued
      ✓ should return false when the same path is queued
    #selectMailbox
      ✓ should run SELECT
      ✓ should run SELECT with CONDSTORE
      ✓ should emit onclosemailbox
      should emit onselectmailbox before selectMailbox is resolved
        ✓ when it returns a promise
        ✓ when it does not return a promise
    #hasCapability
      ✓ should detect existing capability
      ✓ should detect non existing capability
    #_untaggedOkHandler
      ✓ should update capability if present
    #_untaggedCapabilityHandler
      ✓ should update capability
    #_untaggedExistsHandler
      ✓ should emit onupdate
    #_untaggedExpungeHandler
      ✓ should emit onupdate
    #_untaggedFetchHandler
      ✓ should emit onupdate
    #_parseSELECT
      ✓ should parse a complete response
      ✓ should parse response with no modseq
      ✓ should parse response with read-only
      ✓ should parse response with NOMODSEQ flag
    #_parseNAMESPACE
      ✓ should not succeed for no namespace response
      ✓ should return single personal namespace
      ✓ should return single personal, single users, multiple shared
      ✓ should handle NIL namespace hierarchy delim
    #_buildFETCHCommand
      ✓ should build single ALL
      ✓ should build FETCH with uid
      ✓ should build FETCH with uid, envelope
      ✓ should build FETCH with modseq
      ✓ should build FETCH with section
      ✓ should build FETCH with section and list
      ✓ should build FETCH with 
      ✓ should build FETCH with partial
    #_parseFETCH
      ✓ should return values lowercase keys
      ✓ should merge multiple responses based on sequence number
    #_parseENVELOPE
      ✓ should parsed envelope object
    #_parseBODYSTRUCTURE
      ✓ should parse bodystructure object
      ✓ should parse bodystructure with unicode filename
    #_buildSEARCHCommand
      ✓ should compose a search command
      ✓ should compose an unicode search command
    #_parseSEARCH
      ✓ should parse SEARCH response
      ✓ should parse empty SEARCH response
    #_buildSTORECommand
      ✓ should compose a store command from an array
      ✓ should compose a store set flags command
      ✓ should compose a store add flags command
      ✓ should compose a store remove flags command
      ✓ should compose a store remove silent flags command
      ✓ should compose a uid store flags command
    #_changeState
      ✓ should set the state value
      ✓ should emit onclosemailbox if mailbox was closed
    #_ensurePath
      ✓ should create the path if not present
      ✓ should return existing path if possible
      ✓ should handle case insensitive Inbox
    #_checkSpecialUse
      ✓ should return a matching special use flag
      ✓ should fail for non-existent flag
      ✓ should fail for invalid flag
      ✓ should return special use flag if a matching name is found
      ✓ should prefer matching special use flag over a matching name
    #_buildXOAuth2Token
      ✓ should return base64 encoded XOAUTH2 token
    untagged updates
      ✓ should receive information about untagged exists
      ✓ should receive information about untagged expunge
      ✓ should receive information about untagged fetch


  181 passing (2s)


Done, without errors.

@rickhall
Copy link
Author

rickhall commented Sep 1, 2017

I want to close this pull request, since I no longer think it should be applied.

I've been investigating another issue I saw while resolving this issue. It turns out the _iterateIncomingBuffer() method has multiple issues. I am finishing up a complete rewrite which I believe will address #143 and #147.

@rickhall rickhall closed this Sep 1, 2017
@nifgraup
Copy link
Contributor

nifgraup commented Sep 3, 2017

That test failure unrelated, it fails sporadically. I think the change looks good as a fix for zero-length literals, but it's great if you have a more readable rewrite that tackles #143 as well. Be aware that _iterateIncomingBuffer was rewritten in 56a951d to be more memory efficient, but the result was a bit cryptic.

@rickhall
Copy link
Author

rickhall commented Sep 4, 2017

Well, I think my proposal should be similar in its memory efficiency, but hopefully quite a bit more understandable. It took me a while to figure out what _iterateIncomingBuffer() was doing...of course, it didn't help that this was the first time I had ever seen a generator function either. :-)

Labor Day weekend here in the USA, so I probably won't create the new pull request until Tuesday or so, but it appears to be working and passing all tests.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants