Skip to content

Modern API #3

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

Draft
wants to merge 10 commits into
base: main
Choose a base branch
from
Draft

Modern API #3

wants to merge 10 commits into from

Conversation

LoveAndCoding
Copy link
Owner

@LoveAndCoding LoveAndCoding commented Jul 3, 2022

Goals

Have clean and easy to understand API that utilizes modern JS functionality. Under the hood, the code should also better differentiate between an IMAP connection and an IMAP session, and utilize the rewritten parser engine.

Work

  • Split connection code from the concept of a session
  • Change connection API to utilize async/await/promise methods
  • Create command/control structured queue
  • Port supported IMAP commands to new command/control queue
    • CAPABILITY
    • NOOP
    • LOGOUT
    • ID
    • STARTTLS
    • AUTHENTICATE
    • LOGIN
    • ENABLE
    • SELECT
    • EXAMINE
    • CREATE
    • DELETE
    • RENAME
    • SUBSCRIBE
    • UNSUBSCRIBE
    • LIST
    • NAMESPACE
    • STATUS
    • APPEND
    • IDLE
    • CLOSE
    • UNSELECT
    • EXPUNGE
    • SEARCH
    • FETCH
    • STORE
    • COPY
    • MOVE
    • UID
  • Create wrapper classes for IMAP objects
    • Session
    • Box
    • Message
  • Convert existing tests

This is the beginning of the new command style strcture. Commands will
be added as self managing classes that know how to generate and send the
actual command text as well as process parsed responses.

The base class implements a common strategy of sending a tagged command
and listening for a tagged response, capturing everything in between.

The no-op is the most simple implementation of this command system.
Adding command classes for the ID and Capability commands, which will be
common to run on intiating the connection.

Also included is the first command encoding function for creating IMAP
safe strings.
This class will eventually serve as the base class that is exposed and
that other systems would interface with. This will contain the public-
facing API for the library and will be both a mirror and an update of
existing functionality.

Note that this commit does not expose this class nor remove or change
the original `Connection` class which currently acts as the public
interface. Eventually the `Connection` class will be cleaned up and it
will serve purely as the connection for the session without any logic
for actual commands.
Pulled everything out of the connection class that is not actually
related to the connection. This means almost all IMAP related commands
and controls will be in a new class. The code went from almost 2k lines
to around 300, which should be a lot easier to understand.

From a practical perspective, I chose to write a brand new class and
just remove the old copy completely. The old code was inter-weaved with
a lot of implicit assumptions and untangling that would have been a
nightmare. This does, however, mean this is all (or almost all) new
code. Which is extra terrifying. But that's a future me problem.
@LoveAndCoding LoveAndCoding added the enhancement New feature or request label Jul 3, 2022
@LoveAndCoding LoveAndCoding added this to the v1.0.0 milestone Jul 3, 2022
@LoveAndCoding LoveAndCoding self-assigned this Jul 3, 2022
Actually connects and exposes the Session class so that it functions and
can create and manage an IMAP session!

This is exciting, and I was able to connect a new session to GMail and
get the capabilities and server info 💃

**Test plan:**
Connect to GMail using the Session class
Celebrate 🙌
Instead of just using A0, A1, etc. we want to use A1, B1, etc. This
us to send *a lot* more commands before we reuse tags
Creating a baseline E2E suite that can be used to test compatibility
against various servers.

**Test plan:**
yarn test:e2e
With the update to tag names, the tests needed updating.

**Test plan:**
`yarn test`
`yarn test:e2e`
Testing out reporting coverage via GH Actions.

**Test plan:**
Hope that this all works because GH actions are a pain sometimes
Languages that use indentation as syntax should burn. Spacing should not
determine validity 🔥
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant