Skip to content

fix: Send pre-message after successful sending of post-message (#8063)#8222

Open
iequidoo wants to merge 2 commits into
mainfrom
iequidoo/send-post-msg-first
Open

fix: Send pre-message after successful sending of post-message (#8063)#8222
iequidoo wants to merge 2 commits into
mainfrom
iequidoo/send-post-msg-first

Conversation

@iequidoo

@iequidoo iequidoo commented May 8, 2026

Copy link
Copy Markdown
Collaborator

Also, send the message text in the post-message too, we can't support the workaround for duplicated
message text shown in ancient versions anymore, otherwise newer versions won't show the message text
at all.

On the receiving side, don't download a post-message w/o known pre-message if the post-message
exceeds DownloadLimit to save user's traffic.

This isn't easy to test in Rust though because the smtp sending code requires an SMTP connection,
so it's only tested (by already existing tests) that messages are queued in the right order.

Another problem is that the smtp sending logic doesn't try to send any messages following a
failed-to-send message until the retry limit is reached, so if there's smth wrong with a
post-message, other unrelated messages are delayed, but this problem has already existed.

Fix #8063

@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch 2 times, most recently from 04832ec to fed3a6a Compare May 11, 2026 08:01
Comment thread src/receive_imf.rs
}

async fn handle_post_message(
async fn update_from_post_msg(

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.

Decided to rename it to underline that only an already existing message is updated, to avoid more bugs caused by not fully handling post-messages

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.

What bug was caused by this?

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.

See #8222 (comment), probably the wrong condition was added there because handle_post_message() looks like hadndling post-messages in all cases. Actually it only updates existing messages

Comment thread src/receive_imf.rs

// Maybe set logging xdc and add gossip topics for webxdcs.
for (part, msg_id) in mime_parser.parts.iter().zip(&created_db_entries) {
if mime_parser.pre_message != PreMessageMode::Post

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.

Compat problem: missing iroh topic id

Comment thread src/download.rs Outdated
Comment thread src/mimefactory.rs
@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch from fed3a6a to 42d09d4 Compare May 18, 2026 10:24
@iequidoo iequidoo marked this pull request as ready for review May 18, 2026 11:26
@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch from 42d09d4 to f6eacd1 Compare May 20, 2026 13:39
@iequidoo iequidoo requested a review from Hocuri May 20, 2026 13:39
@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch from f6eacd1 to 2947c49 Compare May 25, 2026 23:46
@iequidoo iequidoo marked this pull request as draft May 27, 2026 04:20
@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch from 2947c49 to 29a6f8d Compare May 27, 2026 04:43
@iequidoo iequidoo marked this pull request as ready for review May 27, 2026 05:07
Comment thread src/download.rs Outdated
Comment thread src/imap.rs
Comment thread src/mimefactory.rs
Comment thread src/download.rs Outdated
Comment thread src/receive_imf.rs
"Message {rfc724_mid} is already in some chat or deleted."
);
if mime_parser.incoming {
return Ok(None);

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'm having problems understanding why the changes here are necessary, can you clarify?

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.

If a post-message appears on IMAP, it should be deleted from smtp because it was sent successfully. Now this logic is common for all outgoing messages. One test started failing before i made this change, but i've forgotten which one exactly.

Comment thread src/receive_imf.rs
}

async fn handle_post_message(
async fn update_from_post_msg(

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.

What bug was caused by this?

@iequidoo

iequidoo commented Jun 9, 2026

Copy link
Copy Markdown
Collaborator Author

I see the main problem with this PR is adding the available_post_msgs.timestamp column which breaks forward compatibility. Possible solutions:

  • Increment BACKUP_VERSION (@Hocuri is against this AFAIU)
  • Add a new table and add available post-messages to the both tables for the case of possible Core downgrade.
  • Don't download post-messages having no pre-messages at all. Though, we can immediately download messages fitting into DownloadLimit, we already do that. Finally i think this may even be good as we save traffic.

Need to take some decision here. For now have chosen the last one.

@iequidoo iequidoo requested review from Hocuri and r10s June 9, 2026 05:37
Messages are deleted from the inbox loop, so it should be interrupted. The SMTP doesn't need to be
interrupted explicitly however, chat::sync() already does this internally.
@iequidoo iequidoo marked this pull request as draft June 9, 2026 06:25
@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch from 29a6f8d to e6de2a6 Compare June 9, 2026 07:47
Also, send the message text in the post-message too, we can't support the workaround for duplicated
message text shown in ancient versions anymore, otherwise newer versions won't show the message text
at all.

On the receiving side, don't download a post-message w/o known pre-message if the post-message
exceeds DownloadLimit to save user's traffic.

This isn't easy to test in Rust though because the `smtp` sending code requires an SMTP connection,
so it's only tested (by already existing tests) that messages are queued in the right order.

Another problem is that the `smtp` sending logic doesn't try to send any messages following a
failed-to-send message until the retry limit is reached, so if there's smth wrong with a
post-message, other unrelated messages are delayed, but this problem has already existed.
@iequidoo iequidoo force-pushed the iequidoo/send-post-msg-first branch from e6de2a6 to 773f6fb Compare June 9, 2026 15:24
@iequidoo iequidoo marked this pull request as ready for review June 9, 2026 15:24
Comment thread src/sql/migrations.rs
.await?;
}

sql.execute("DELETE FROM available_post_msgs", ()).await?;

@iequidoo iequidoo Jun 9, 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.

Usually we don't do so, but decided to clean up the table in case of an "upgrade again" scenario. Don't want to add a migration and migrations are executed only once. Can be removed once we add a migration deleting the table.

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.

Do not send pre-message if post-message sending failed

2 participants