From 43adb0fb11de92f23b4a86015612c612c0d00e39 Mon Sep 17 00:00:00 2001 From: Paolo Barbolini Date: Tue, 21 Jul 2020 19:00:59 +0200 Subject: [PATCH] Replace unmaintained bufstream crate with std::io::BufReader --- Cargo.toml | 3 +-- src/transport/smtp/client/mod.rs | 16 +++++++--------- 2 files changed, 8 insertions(+), 11 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 739086b..0d90385 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -21,7 +21,6 @@ async-attributes = { version = "1.1", optional = true } async-std = { version = "1.5", optional = true, features = ["unstable"] } async-trait = { version = "0.1", optional = true } base64 = { version = "0.12", optional = true } -bufstream = { version = "0.1", optional = true } hostname = { version = "0.3", optional = true } hyperx = { version = "1", optional = true, features = ["headers"] } idna = "0.2" @@ -59,7 +58,7 @@ default = ["file-transport", "smtp-transport", "rustls-tls", "hostname", "r2d2", file-transport = ["serde", "serde_json"] rustls-tls = ["webpki", "webpki-roots", "rustls"] sendmail-transport = [] -smtp-transport = ["bufstream", "base64", "nom"] +smtp-transport = ["base64", "nom"] unstable = [] [[example]] diff --git a/src/transport/smtp/client/mod.rs b/src/transport/smtp/client/mod.rs index 3ce9b21..3968109 100644 --- a/src/transport/smtp/client/mod.rs +++ b/src/transport/smtp/client/mod.rs @@ -11,14 +11,13 @@ use crate::{ }, Envelope, }; -use bufstream::BufStream; #[cfg(feature = "log")] use log::debug; #[cfg(feature = "serde")] use std::fmt::Debug; use std::{ fmt::Display, - io::{self, BufRead, Write}, + io::{self, BufRead, BufReader, Write}, net::ToSocketAddrs, string::String, time::Duration, @@ -99,7 +98,7 @@ macro_rules! try_smtp ( pub struct SmtpConnection { /// TCP stream between client and server /// Value is None before connection - stream: BufStream, + stream: BufReader, /// Panic state panic: bool, /// Information about the server @@ -122,7 +121,7 @@ impl SmtpConnection { hello_name: &ClientId, tls_parameters: Option<&TlsParameters>, ) -> Result { - let stream = BufStream::new(NetworkStream::connect(server, timeout, tls_parameters)?); + let stream = BufReader::new(NetworkStream::connect(server, timeout, tls_parameters)?); let mut conn = SmtpConnection { stream, panic: false, @@ -170,8 +169,7 @@ impl SmtpConnection { } pub fn can_starttls(&self) -> bool { - !self.stream.get_ref().is_encrypted() - && self.server_info.supports_feature(Extension::StartTls) + !self.is_encrypted() && self.server_info.supports_feature(Extension::StartTls) } #[allow(unused_variables)] @@ -224,7 +222,7 @@ impl SmtpConnection { /// Sets the underlying stream pub fn set_stream(&mut self, stream: NetworkStream) { - self.stream = BufStream::new(stream); + self.stream = BufReader::new(stream); } /// Tells if the underlying stream is currently encrypted @@ -299,8 +297,8 @@ impl SmtpConnection { /// Writes a string to the server fn write(&mut self, string: &[u8]) -> Result<(), Error> { - self.stream.write_all(string)?; - self.stream.flush()?; + self.stream.get_mut().write_all(string)?; + self.stream.get_mut().flush()?; #[cfg(feature = "log")] debug!(