core icon indicating copy to clipboard operation
core copied to clipboard

`download_msg` should fail to download full message if UIDVALIDITY has changed

Open link2xt opened this issue 2 months ago • 1 comments

When the user has requested full download of a partially downloaded message, download_msg looks up the folder and UID of the message in imap table: https://github.com/chatmail/core/blob/51b9e86d71fe1e80bb0935c1c3bb711555ec36d5/src/download.rs#L160

imap table also stores UID validity. If UID validity of the folder has changed since the time the message was partially downloaded, then imap entry becomes invalid. To avoid attempting to download unrelated message with different uidvalidity and the same UID, download_msg should check again after calling select_with_uidvalidity that selected folder has the same uidvalidity as the database entry. The folder should not be unselected until the message is downloaded and passed to receive_imf.

Moving the discussion out of https://github.com/chatmail/core/pull/6877#discussion_r2160511811 because this bug was always there, not introduced in https://github.com/chatmail/core/pull/6877

It is also very unlikely that this happens in practice, so this issue is very low priority. If this is fixed there definitely has to be an online test deleting and recreating a folder to change uid validity because there is no chance regressions will be noticed otherwise.

link2xt avatar Oct 21 '25 20:10 link2xt

move_delete_messages also does not seem to check that it has the folder with unchanged UID validity is selected and may delete wrong messages if the folder is swapped right before move_delete_messages. This is a more serious problem then accidentally downloading wrong message and wasting a few mbytes of traffic.

link2xt avatar Oct 21 '25 20:10 link2xt