Skip to content

Add abstraction for connection to "hide away" that whether the connection is TCP, or TLS. #244

@urkle

Description

@urkle

Currently the way the data types are for rust-imap you must know the exact type of connection you will be using and which tls implementation you are going to use in order to define your types.

I would like to make a PR that abstracts that all away into an enum so that it is hidden from the user.

A user should be able to do something like this.

let mut builder = ClientBuilder::new(
            self.config.imap_host.as_ref().unwrap(),
            self.config.imap_port,
        );
if use_starttls {
   // tag that we want start tls
   builder.starttls();
} else if use_ssl {
   // tag that we are doing FULL ssl mode
   builder.ssl();
}
// otherwise we are doing RAW tcp (still valid as it is useful for internal only connections)

// connects and returns an opaque ImapClient that abstracts away the Tcp stream type)
let client : ImapClient = builder.connect()?;
// connects and returns an opaque ImapSession that abstracts away the Tcp stream type)
let session : ImapSession = client.login("user", "pass")?;

Other crates do this and it greatly simplifies client-code as I don't have to know how I compiled the code in order to connect. And I can choose to conditionally connect via SSL / TLS / raw.

One example is ldap3, which uses a simple ENUM to differentiate between Tcp, Tls, and Unix sockets (imap would only need the 2).

Let me know if you are open to this and I can build up a PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions