melib/smtp: add recipient argument in mail_transaction()

master
Manos Pitsidianakis 2020-08-16 15:16:27 +03:00
parent 30c390443a
commit b9e53a7451
Signed by: Manos Pitsidianakis
GPG Key ID: 73627C2F690DF710
2 changed files with 7 additions and 5 deletions

View File

@ -68,7 +68,7 @@
*/
use crate::connections::{lookup_ipv4, Connection};
use crate::email::{parser::BytesExt, Envelope};
use crate::email::{parser::BytesExt, Address, Envelope};
use crate::error::{MeliError, Result, ResultIntoMeliError};
use futures::io::{AsyncReadExt, AsyncWriteExt};
use native_tls::TlsConnector;
@ -515,7 +515,7 @@ impl SmtpConnection {
}
/// Sends mail
pub async fn mail_transaction(&mut self, mail: &str) -> Result<()> {
pub async fn mail_transaction(&mut self, mail: &str, tos: Option<&[Address]>) -> Result<()> {
let mut res = String::with_capacity(8 * 1024);
let mut pipelining_queue: SmallVec<[ExpectedReplyCode; 16]> = SmallVec::new();
let mut pipelining_results: SmallVec<[Result<ReplyCode>; 16]> = SmallVec::new();
@ -524,7 +524,8 @@ impl SmtpConnection {
let envelope_from = self.server_conf.envelope_from.clone();
let envelope = Envelope::from_bytes(mail.as_bytes(), None)
.chain_err_summary(|| "SMTP submission was aborted")?;
if envelope.to().is_empty() {
let tos = tos.unwrap_or_else(|| envelope.to());
if tos.is_empty() {
return Err(MeliError::new("SMTP submission was aborted because there was no e-mail address found in the To: header field. Consider adding recipients."));
}
let mut current_command: SmallVec<[&[u8]; 16]> = SmallVec::new();
@ -559,7 +560,8 @@ impl SmtpConnection {
//return a reply indicating whether the failure is permanent (i.e., will occur again if
//the client tries to send the same address again) or temporary (i.e., the address might
//be accepted if the client tries again later).
for addr in envelope.to() {
for addr in tos {
current_command.clear();
current_command.push(b"RCPT TO:<");
current_command.push(addr.address_spec_raw().trim());
if let Some(dsn_notify) = dsn_notify.as_ref() {

View File

@ -1376,7 +1376,7 @@ impl Account {
let (chan, handle, job_id) = self.job_executor.spawn_specialized(async move {
let mut smtp_connection =
melib::smtp::SmtpConnection::new_connection(conf).await?;
smtp_connection.mail_transaction(&message).await
smtp_connection.mail_transaction(&message, None).await
});
self.sender
.send(ThreadEvent::UIEvent(UIEvent::StatusEvent(