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

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

Open
urkle opened this issue Sep 27, 2022 · 1 comment

Comments

@urkle
Copy link
Contributor

urkle commented Sep 27, 2022

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.

@jonhoo
Copy link
Owner

jonhoo commented Oct 15, 2022

I'll follow up in the PR 👍

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

No branches or pull requests

2 participants