Skip to content

refactor: replace MimeFactory::from_mdn() with a standalone mimefactory::mdn() - #8748

Open
link2xt wants to merge 1 commit into
mainfrom
link2xt/mimefactory-mdn-refactor
Open

link2xt wants to merge 1 commit into
mainfrom
link2xt/mimefactory-mdn-refactor

Conversation

@link2xt

@link2xt link2xt commented Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

This factors out all MDN-related code that was previously inside MimeFactory
into a mimefactory::mdn function that constructs QueuedMail directly,
similarly to mimefactory::keyupdate_message.

Removing MDN-related code from MimeFactory also means that MimeFactory only handles non-MDN messages now
and we don't have to match on MimeFactory.loaded everywhere to access msg and chat.

Unlike MimeFactory::from_mdn, mimefactory::mdn does not need to fill MimeFactory.from_addr.
This removes one get_primary_self_addr() call. mimefactory::mdn also does not need to fill
various fields that are never used for MDNs such as past_members.


Make sure to enable "hide whitespace" when reviewing on GitHub, there is some code that was inside match or if let for Loaded::Message that stays the same with just the branching around removed.

Comment thread src/mimefactory.rs
)
}

pub(crate) async fn mdn(

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Main change is the addition of this function that builds QueuedMail directly without ever creating MimeFactory structure. And all code that uses MimeFactory structure does not have to consider MDN case.

@link2xt
link2xt force-pushed the link2xt/mimefactory-mdn-refactor branch from cedfd0d to 91245c4 Compare September 24, 2026 16:17
@link2xt
link2xt force-pushed the link2xt/mimefactory-mdn-refactor branch from c282e62 to cc74979 Compare September 24, 2026 18:20
Comment thread src/mimefactory.rs
additional_msg_ids: Vec<String>,
) -> Result<MimeFactory> {
let contact = Contact::get_by_id(context, from_id).await?;
let from_addr = context.get_primary_self_addr().await?;

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This get_primary_self_addr() result was not used anywhere, but now it is not even called.

@link2xt
link2xt marked this pull request as ready for review September 24, 2026 19:40
@link2xt
link2xt force-pushed the link2xt/mimefactory-mdn-refactor branch from 2cbb986 to 9e6a360 Compare September 24, 2026 19:47
@link2xt link2xt changed the title refactor: move MDN construction into mimefactory::mdn refactor: replace MimeFactory::from_mdn() with a standalone mimefactory::mdn() Sep 24, 2026
@link2xt
link2xt force-pushed the link2xt/mimefactory-mdn-refactor branch from 9e6a360 to 2af2b9a Compare September 24, 2026 20:02
@link2xt
link2xt requested a review from Hocuri September 24, 2026 20:08

@Hocuri Hocuri left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Partial review.

Looks good overall; I don't think this should go into a potential hotfix-release, but ofc we can merge it and then potentially backport a fix if we need one.

Comment thread src/mimefactory.rs
Comment on lines +2317 to +2320
} else {
recipients = vec![addr.clone()];
QueuedEncryption::No
};

@Hocuri Hocuri Sep 24, 2026 •

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I thought we don't send unencrypted MDNs anymore? In either case, I don't think we want them.

I would actually be surprised if they're still working at this point; fn mdn seems to forget to add the To and Date headers to unencrypted MDNs (I didn't check whether this problem was there before this PR). So, let's just remove them.

Comment thread src/mimefactory.rs Outdated
Comment thread src/mimefactory.rs
let bcc_self = context.get_config_bool(Config::BccSelf).await?;

let date = chrono::DateTime::<chrono::Utc>::from_timestamp(timestamp, 0)
.unwrap()

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wouldn't it be better to use ? here rather than unwrap()?

I'm surprised that we don't have #![cfg_attr(not(test), forbid(clippy::unwrap_used))], is there a reason for it or did we just overlook it?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Seems the last commit mentioning them is 0725fe3 and we probably did not figure out cfg_attr or maybe it did not even exist back then.

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, turns out that we're using unwrap() in not so few places, I'm getting 24 errors when I enable the lint. Maybe it's fine not to enable the lint, I can't remember any problems with panics recently.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Removed some .unwrap() calls in #8751

Comment thread src/mimefactory.rs Outdated
…ry::mdn()

This factors out all MDN-related code that was previously inside `MimeFactory`
into a `mimefactory::mdn` function that constructs `QueuedMail` directly,
similarly to `mimefactory::keyupdate_message`.

Removing MDN-related code from MimeFactory also means that MimeFactory only handles non-MDN messages now
and we don't have to `match` on `MimeFactory.loaded` everywhere to access `msg` and `chat`.

Unlike `MimeFactory::from_mdn`, `mimefactory::mdn` does not need to fill `MimeFactory.from_addr`.
This removes one `get_primary_self_addr()` call. `mimefactory::mdn` also does not need to fill
various fields that are never used for MDNs such as `past_members`.
@link2xt
link2xt force-pushed the link2xt/mimefactory-mdn-refactor branch from 434c32a to ce94c0c Compare September 25, 2026 12:51

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants