mirror of
https://github.com/chatmail/core.git
synced 2026-05-22 16:26:31 +03:00
refactor: flatten create_or_lookup_mailinglist()
This commit is contained in:
@@ -2007,39 +2007,40 @@ async fn apply_mailinglist_changes(
|
|||||||
mime_parser: &MimeMessage,
|
mime_parser: &MimeMessage,
|
||||||
chat_id: ChatId,
|
chat_id: ChatId,
|
||||||
) -> Result<()> {
|
) -> Result<()> {
|
||||||
if let Some(list_post) = &mime_parser.list_post {
|
let Some(list_post) = &mime_parser.list_post else {
|
||||||
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
return Ok(());
|
||||||
if chat.typ != Chattype::Mailinglist {
|
};
|
||||||
|
|
||||||
|
let mut chat = Chat::load_from_db(context, chat_id).await?;
|
||||||
|
if chat.typ != Chattype::Mailinglist {
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
let listid = &chat.grpid;
|
||||||
|
|
||||||
|
let list_post = match ContactAddress::new(list_post) {
|
||||||
|
Ok(list_post) => list_post,
|
||||||
|
Err(err) => {
|
||||||
|
warn!(context, "Invalid List-Post: {:#}.", err);
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
let listid = &chat.grpid;
|
};
|
||||||
|
let (contact_id, _) = Contact::add_or_lookup(context, "", list_post, Origin::Hidden).await?;
|
||||||
|
let mut contact = Contact::get_by_id(context, contact_id).await?;
|
||||||
|
if contact.param.get(Param::ListId) != Some(listid) {
|
||||||
|
contact.param.set(Param::ListId, listid);
|
||||||
|
contact.update_param(context).await?;
|
||||||
|
}
|
||||||
|
|
||||||
let list_post = match ContactAddress::new(list_post) {
|
if let Some(old_list_post) = chat.param.get(Param::ListPost) {
|
||||||
Ok(list_post) => list_post,
|
if list_post.as_ref() != old_list_post {
|
||||||
Err(err) => {
|
// Apparently the mailing list is using a different List-Post header in each message.
|
||||||
warn!(context, "Invalid List-Post: {:#}.", err);
|
// Make the mailing list read-only because we wouldn't know which message the user wants to reply to.
|
||||||
return Ok(());
|
chat.param.remove(Param::ListPost);
|
||||||
}
|
|
||||||
};
|
|
||||||
let (contact_id, _) =
|
|
||||||
Contact::add_or_lookup(context, "", list_post, Origin::Hidden).await?;
|
|
||||||
let mut contact = Contact::get_by_id(context, contact_id).await?;
|
|
||||||
if contact.param.get(Param::ListId) != Some(listid) {
|
|
||||||
contact.param.set(Param::ListId, listid);
|
|
||||||
contact.update_param(context).await?;
|
|
||||||
}
|
|
||||||
|
|
||||||
if let Some(old_list_post) = chat.param.get(Param::ListPost) {
|
|
||||||
if list_post.as_ref() != old_list_post {
|
|
||||||
// Apparently the mailing list is using a different List-Post header in each message.
|
|
||||||
// Make the mailing list read-only because we wouldn't know which message the user wants to reply to.
|
|
||||||
chat.param.remove(Param::ListPost);
|
|
||||||
chat.update_param(context).await?;
|
|
||||||
}
|
|
||||||
} else {
|
|
||||||
chat.param.set(Param::ListPost, list_post);
|
|
||||||
chat.update_param(context).await?;
|
chat.update_param(context).await?;
|
||||||
}
|
}
|
||||||
|
} else {
|
||||||
|
chat.param.set(Param::ListPost, list_post);
|
||||||
|
chat.update_param(context).await?;
|
||||||
}
|
}
|
||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
|
|||||||
Reference in New Issue
Block a user