mirror of
https://github.com/chatmail/core.git
synced 2026-04-23 00:16:34 +03:00
job: do not render messages without recipients
This commit is contained in:
committed by
Floris Bruynooghe
parent
1144a536a5
commit
aadeb3b87e
63
src/job.rs
63
src/job.rs
@@ -792,7 +792,32 @@ pub fn job_send_msg(context: &Context, msg_id: MsgId) -> Result<()> {
|
||||
};
|
||||
|
||||
let mimefactory = MimeFactory::from_msg(context, &msg, attach_selfavatar)?;
|
||||
let mut rendered_msg = mimefactory.render().map_err(|err| {
|
||||
|
||||
let mut recipients = mimefactory.recipients();
|
||||
|
||||
let from = context
|
||||
.get_config(Config::ConfiguredAddr)
|
||||
.unwrap_or_default();
|
||||
let lowercase_from = from.to_lowercase();
|
||||
if context.get_config_bool(Config::BccSelf)
|
||||
&& !recipients
|
||||
.iter()
|
||||
.any(|x| x.to_lowercase() == lowercase_from)
|
||||
{
|
||||
recipients.push(from);
|
||||
}
|
||||
|
||||
if recipients.is_empty() {
|
||||
// may happen eg. for groups with only SELF and bcc_self disabled
|
||||
info!(
|
||||
context,
|
||||
"message {} has no recipient, skipping smtp-send", msg_id
|
||||
);
|
||||
set_delivered(context, msg_id);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
let rendered_msg = mimefactory.render().map_err(|err| {
|
||||
message::set_msg_failed(context, msg_id, Some(err.to_string()));
|
||||
err
|
||||
})?;
|
||||
@@ -811,26 +836,6 @@ pub fn job_send_msg(context: &Context, msg_id: MsgId) -> Result<()> {
|
||||
);
|
||||
}
|
||||
|
||||
let lowercase_from = rendered_msg.from.to_lowercase();
|
||||
if context.get_config_bool(Config::BccSelf)
|
||||
&& !rendered_msg
|
||||
.recipients
|
||||
.iter()
|
||||
.any(|x| x.to_lowercase() == lowercase_from)
|
||||
{
|
||||
rendered_msg.recipients.push(rendered_msg.from.clone());
|
||||
}
|
||||
|
||||
if rendered_msg.recipients.is_empty() {
|
||||
// may happen eg. for groups with only SELF and bcc_self disabled
|
||||
info!(
|
||||
context,
|
||||
"message {} has no recipient, skipping smtp-send", msg_id
|
||||
);
|
||||
set_delivered(context, msg_id);
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if rendered_msg.is_gossiped {
|
||||
chat::set_gossiped_timestamp(context, msg.chat_id, time())?;
|
||||
}
|
||||
@@ -859,7 +864,13 @@ pub fn job_send_msg(context: &Context, msg_id: MsgId) -> Result<()> {
|
||||
msg.save_param_to_disk(context);
|
||||
}
|
||||
|
||||
add_smtp_job(context, Action::SendMsgToSmtp, msg.id, &rendered_msg)?;
|
||||
add_smtp_job(
|
||||
context,
|
||||
Action::SendMsgToSmtp,
|
||||
msg.id,
|
||||
recipients,
|
||||
&rendered_msg,
|
||||
)?;
|
||||
|
||||
Ok(())
|
||||
}
|
||||
@@ -1080,17 +1091,15 @@ fn add_smtp_job(
|
||||
context: &Context,
|
||||
action: Action,
|
||||
msg_id: MsgId,
|
||||
recipients: Vec<String>,
|
||||
rendered_msg: &RenderedEmail,
|
||||
) -> Result<()> {
|
||||
ensure!(
|
||||
!rendered_msg.recipients.is_empty(),
|
||||
"no recipients for smtp job set"
|
||||
);
|
||||
ensure!(!recipients.is_empty(), "no recipients for smtp job set");
|
||||
let mut param = Params::new();
|
||||
let bytes = &rendered_msg.message;
|
||||
let blob = BlobObject::create(context, &rendered_msg.rfc724_mid, bytes)?;
|
||||
|
||||
let recipients = rendered_msg.recipients.join("\x1e");
|
||||
let recipients = recipients.join("\x1e");
|
||||
param.set(Param::File, blob.as_name());
|
||||
param.set(Param::Recipients, &recipients);
|
||||
|
||||
|
||||
@@ -60,9 +60,6 @@ pub struct RenderedEmail {
|
||||
pub is_gossiped: bool,
|
||||
pub last_added_location_id: u32,
|
||||
|
||||
pub from: String,
|
||||
pub recipients: Vec<String>,
|
||||
|
||||
/// Message ID (Message in the sense of Email)
|
||||
pub rfc724_mid: String,
|
||||
}
|
||||
@@ -349,6 +346,13 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
}
|
||||
}
|
||||
|
||||
pub fn recipients(&self) -> Vec<String> {
|
||||
self.recipients
|
||||
.iter()
|
||||
.map(|(_, addr)| addr.clone())
|
||||
.collect()
|
||||
}
|
||||
|
||||
pub fn render(mut self) -> Result<RenderedEmail, Error> {
|
||||
// Headers that are encrypted
|
||||
// - Chat-*, except Chat-Version
|
||||
@@ -565,8 +569,6 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
};
|
||||
|
||||
let MimeFactory {
|
||||
recipients,
|
||||
from_addr,
|
||||
last_added_location_id,
|
||||
..
|
||||
} = self;
|
||||
@@ -577,8 +579,6 @@ impl<'a, 'b> MimeFactory<'a, 'b> {
|
||||
is_encrypted,
|
||||
is_gossiped,
|
||||
last_added_location_id,
|
||||
recipients: recipients.into_iter().map(|(_, addr)| addr).collect(),
|
||||
from: from_addr,
|
||||
rfc724_mid,
|
||||
})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user