Skip to content

Conversation

@yungcomputerchair
Copy link
Member

Unclaimed email attachments are currently not deleted if the email is deleted.
This is because email attachments are not formally related to emails in the DB with the current schema, so there's no way to ON DELETE CASCADE them.
Since email message indices are reused, the orphaned attachments can overlap with attachments in new emails, preventing them from being sent due to the UNIQUE constraint in the attachment table failing.

We don't want to change the schema, but we can fix this entirely in code, which is what this PR does.
For prevention: delete all email attachments when an email is deleted
For remediation: when the DB error is hit, attempt to delete the attachments from the deleted email, then try sending again

There was also a bad semicolon in one of the SQL queries which I think can cause some issues with attachment claiming; that has been fixed too.

@FinnHornhoover
Copy link
Contributor

FinnHornhoover commented Dec 8, 2025

On master:
Mail error on master

[Email] (GM) Kuki Jamlocke [2] (to (GM) Bodhi Cutecannon [1]): <No subject.>

[WARN] Database: Failed to send email: UNIQUE constraint failed: EmailItems.PlayerID, EmailItems.MsgIndex, EmailItems.Slot

On mailfix:
I'm able to send a second mail with attachments even if the other player deleted the first mail with attachment. Tried twice.

Getting into a broken state in master and then recompiling in mailfix, then trying to send another mail with attachment works without issues.

Copy link
Contributor

@FinnHornhoover FinnHornhoover left a comment

Choose a reason for hiding this comment

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

Looks good to go 👍

@yungcomputerchair yungcomputerchair merged commit 572df90 into master Dec 8, 2025
6 checks passed
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.

3 participants