Skip to content

refactor: Remove FolderMeaning and target_folder - #8456

Merged
Hocuri merged 2 commits into
mainfrom
hoc/remove-folder-meaning
Jul 27, 2026
Merged

refactor: Remove FolderMeaning and target_folder#8456
Hocuri merged 2 commits into
mainfrom
hoc/remove-folder-meaning

Conversation

@Hocuri

@Hocuri Hocuri commented Jul 24, 2026

Copy link
Copy Markdown
Collaborator

The FolderMeaning and the target_folder() function and related code were needed for the message moving logic. The message moving logic isn't needed anymore, so, this PR is a first step to remove it.

We only ever look at one folder by now (usually the Inbox folder), so, any message moving logic isn't needed anymore because we will never notice a message that is supposed to be moved.

The target column of the imap table is mostly the same as the folder column now. Except when the message is supposed to be deleted, then it's an empty string.

@Hocuri Hocuri changed the title [WIP] refactor: Remove FolderMeaning [WIP] refactor: Remove FolderMeaning and target_folder Jul 24, 2026
Comment thread src/imap.rs

impl Session {
/// Synchronizes UIDs for all folders.
pub(crate) async fn resync_folders(&mut self, context: &Context) -> Result<()> {

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.

We only look at one folder, so, resync_folder_uids() (which I renamed to resync_uids_with_server()) can be called directly, rather than needing this intermediate function that iterates over all the folders.

Comment thread src/imap.rs
Comment on lines 846 to +851
"INSERT INTO imap (transport_id, rfc724_mid, folder, uid, uidvalidity, target)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(transport_id, folder, uid, uidvalidity)
DO UPDATE SET rfc724_mid=excluded.rfc724_mid,
target=excluded.target",
(transport_id, rfc724_mid, folder, uid, uid_validity, target),
(transport_id, rfc724_mid, folder, uid, uid_validity, folder),

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 SQL statement might be the only thing that needs attentive review in this PR, the rest is just removing unused functions, enums, and constants

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

your PR doesn't change it, but the "DELETE FROM" could have empty target (indicating deletion) and then these deleted messages become un-deleted, right? However, re-sync is rare, and it's a pre-existing issue. Would probably need msgs to also carry a 'target' computed from whether the message was marked deleted around line 821.

@Hocuri Hocuri Jul 24, 2026

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.

I'm just trying to understand the whole deletion-on-server vs deletion-locally logic.

msgs already has a deleted column, but it's only checked if the message later arrives via IMAP (in imap.rs with message::rfc724_mid_exists_ex(context, message_id, "deleted=1")). And it is only set by ChatId::delete_ex() and MsgId::trash(). It is:

  • not set by delete_expired_messages() (which deletes ephemeral messages locally)
  • not checked by delete_expired_imap_messages() (which marks ephemeral messages for deletion on IMAP, and if bcc_self is off it marks all fully downloaded messages for deletion on IMAP [non non-chatmail accounts, only encrypted ones])

There actually is another bug here that prevents ephemeral messages from being deleted on the server: delete_expired_messages() deletes the message locally, then delete_expired_imap_messages() doesn't find the message anymore, and can't mark it for deletion. I could reproduce this bug.

If we make delete_expired_messages() set the deleted flag and make delete_expired_imap_messages() check it, then this should fix both the bug @hpk42 just saw as well as the one I just found.

Note that insert_tombstone() also creates a trashed message without the deleted flag set; this is probably fine.

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.

Will fix this in a separate PR: #8460

@Hocuri Hocuri changed the title [WIP] refactor: Remove FolderMeaning and target_folder refactor: Remove FolderMeaning and target_folder Jul 24, 2026
@Hocuri
Hocuri requested review from j-g00da and link2xt July 24, 2026 11:59

@hpk42 hpk42 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

great, more removals :) PR looks good to me including the SQL statement. Just a note about a pre-existing issue that should be easy to fix.

Comment thread src/imap.rs
Comment on lines 846 to +851
"INSERT INTO imap (transport_id, rfc724_mid, folder, uid, uidvalidity, target)
VALUES (?, ?, ?, ?, ?, ?)
ON CONFLICT(transport_id, folder, uid, uidvalidity)
DO UPDATE SET rfc724_mid=excluded.rfc724_mid,
target=excluded.target",
(transport_id, rfc724_mid, folder, uid, uid_validity, target),
(transport_id, rfc724_mid, folder, uid, uid_validity, folder),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

your PR doesn't change it, but the "DELETE FROM" could have empty target (indicating deletion) and then these deleted messages become un-deleted, right? However, re-sync is rare, and it's a pre-existing issue. Would probably need msgs to also carry a 'target' computed from whether the message was marked deleted around line 821.

@Hocuri
Hocuri merged commit 682baff into main Jul 27, 2026
30 checks passed
@Hocuri
Hocuri deleted the hoc/remove-folder-meaning branch July 27, 2026 12:54
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