sendmail: upgrade to async_std::process from the 1.8.0 release (#520)
This commit is contained in:
3
.github/workflows/test.yml
vendored
3
.github/workflows/test.yml
vendored
@@ -6,6 +6,9 @@ on:
|
|||||||
branches:
|
branches:
|
||||||
- master
|
- master
|
||||||
|
|
||||||
|
env:
|
||||||
|
RUST_BACKTRACE: full
|
||||||
|
|
||||||
jobs:
|
jobs:
|
||||||
rustfmt:
|
rustfmt:
|
||||||
name: rustfmt / stable
|
name: rustfmt / stable
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ futures-util = { version = "0.3.7", features = ["io"], optional = true }
|
|||||||
|
|
||||||
## async-std
|
## async-std
|
||||||
async-attributes = { version = "1.1", optional = true }
|
async-attributes = { version = "1.1", optional = true }
|
||||||
async-std = { version = "1.5", optional = true, features = ["unstable"] }
|
async-std = { version = "1.8", optional = true, features = ["unstable"] }
|
||||||
async-trait = { version = "0.1", optional = true }
|
async-trait = { version = "0.1", optional = true }
|
||||||
|
|
||||||
## tokio
|
## tokio
|
||||||
|
|||||||
@@ -164,6 +164,25 @@ impl SendmailTransport {
|
|||||||
.stderr(Stdio::piped());
|
.stderr(Stdio::piped());
|
||||||
c
|
c
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[cfg(feature = "async-std1")]
|
||||||
|
fn async_std_command(&self, envelope: &Envelope) -> async_std::process::Command {
|
||||||
|
use async_std::process::Command;
|
||||||
|
|
||||||
|
let mut c = Command::new(&self.command);
|
||||||
|
// TODO: figure out why enabling this kills it earlier
|
||||||
|
// c.kill_on_drop(true);
|
||||||
|
c.arg("-i");
|
||||||
|
if let Some(from) = envelope.from() {
|
||||||
|
c.arg("-f").arg(from);
|
||||||
|
}
|
||||||
|
c.arg("--")
|
||||||
|
.args(envelope.to())
|
||||||
|
.stdin(Stdio::piped())
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped());
|
||||||
|
c
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
impl Default for SendmailTransport {
|
impl Default for SendmailTransport {
|
||||||
@@ -198,18 +217,15 @@ impl AsyncStd1Transport for SendmailTransport {
|
|||||||
type Error = Error;
|
type Error = Error;
|
||||||
|
|
||||||
async fn send_raw(&self, envelope: &Envelope, email: &[u8]) -> Result<Self::Ok, Self::Error> {
|
async fn send_raw(&self, envelope: &Envelope, email: &[u8]) -> Result<Self::Ok, Self::Error> {
|
||||||
let mut command = self.command(envelope);
|
use async_std::io::prelude::WriteExt;
|
||||||
let email = email.to_vec();
|
|
||||||
|
|
||||||
// TODO: Convert to real async, once async-std has a process implementation.
|
let mut command = self.async_std_command(envelope);
|
||||||
let output = async_std::task::spawn_blocking(move || {
|
|
||||||
// Spawn the sendmail command
|
|
||||||
let mut process = command.spawn()?;
|
|
||||||
|
|
||||||
process.stdin.as_mut().unwrap().write_all(&email)?;
|
// Spawn the sendmail command
|
||||||
process.wait_with_output()
|
let mut process = command.spawn()?;
|
||||||
})
|
|
||||||
.await?;
|
process.stdin.as_mut().unwrap().write_all(&email).await?;
|
||||||
|
let output = process.output().await?;
|
||||||
|
|
||||||
if output.status.success() {
|
if output.status.success() {
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
@@ -39,6 +39,7 @@ mod test {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let result = sender.send(email).await;
|
let result = sender.send(email).await;
|
||||||
|
println!("{:?}", result);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -58,6 +59,7 @@ mod test {
|
|||||||
.unwrap();
|
.unwrap();
|
||||||
|
|
||||||
let result = sender.send(email).await;
|
let result = sender.send(email).await;
|
||||||
|
println!("{:?}", result);
|
||||||
assert!(result.is_ok());
|
assert!(result.is_ok());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user