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:
|
||||
- master
|
||||
|
||||
env:
|
||||
RUST_BACKTRACE: full
|
||||
|
||||
jobs:
|
||||
rustfmt:
|
||||
name: rustfmt / stable
|
||||
|
||||
@@ -52,7 +52,7 @@ futures-util = { version = "0.3.7", features = ["io"], optional = true }
|
||||
|
||||
## async-std
|
||||
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 }
|
||||
|
||||
## tokio
|
||||
|
||||
@@ -164,6 +164,25 @@ impl SendmailTransport {
|
||||
.stderr(Stdio::piped());
|
||||
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 {
|
||||
@@ -198,18 +217,15 @@ impl AsyncStd1Transport for SendmailTransport {
|
||||
type Error = Error;
|
||||
|
||||
async fn send_raw(&self, envelope: &Envelope, email: &[u8]) -> Result<Self::Ok, Self::Error> {
|
||||
let mut command = self.command(envelope);
|
||||
let email = email.to_vec();
|
||||
use async_std::io::prelude::WriteExt;
|
||||
|
||||
// TODO: Convert to real async, once async-std has a process implementation.
|
||||
let output = async_std::task::spawn_blocking(move || {
|
||||
// Spawn the sendmail command
|
||||
let mut process = command.spawn()?;
|
||||
let mut command = self.async_std_command(envelope);
|
||||
|
||||
process.stdin.as_mut().unwrap().write_all(&email)?;
|
||||
process.wait_with_output()
|
||||
})
|
||||
.await?;
|
||||
// Spawn the sendmail command
|
||||
let mut process = command.spawn()?;
|
||||
|
||||
process.stdin.as_mut().unwrap().write_all(&email).await?;
|
||||
let output = process.output().await?;
|
||||
|
||||
if output.status.success() {
|
||||
Ok(())
|
||||
|
||||
@@ -39,6 +39,7 @@ mod test {
|
||||
.unwrap();
|
||||
|
||||
let result = sender.send(email).await;
|
||||
println!("{:?}", result);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
|
||||
@@ -58,6 +59,7 @@ mod test {
|
||||
.unwrap();
|
||||
|
||||
let result = sender.send(email).await;
|
||||
println!("{:?}", result);
|
||||
assert!(result.is_ok());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user