mirror of
https://github.com/chatmail/core.git
synced 2026-05-02 04:46:29 +03:00
fix: do not subscribe to heartbeat if already subscribed via metadata
This commit is contained in:
84
src/imap.rs
84
src/imap.rs
@@ -1560,52 +1560,54 @@ impl Session {
|
|||||||
return Ok(());
|
return Ok(());
|
||||||
};
|
};
|
||||||
|
|
||||||
let device_token_changed = context
|
if self.can_metadata() && self.can_push() {
|
||||||
.get_config(Config::DeviceToken)
|
let device_token_changed = context
|
||||||
.await?
|
.get_config(Config::DeviceToken)
|
||||||
.map_or(true, |config_token| device_token != config_token);
|
|
||||||
|
|
||||||
if device_token_changed && self.can_metadata() && self.can_push() {
|
|
||||||
let folder = context
|
|
||||||
.get_config(Config::ConfiguredInboxFolder)
|
|
||||||
.await?
|
.await?
|
||||||
.context("INBOX is not configured")?;
|
.map_or(true, |config_token| device_token != config_token);
|
||||||
|
|
||||||
let encrypted_device_token =
|
if device_token_changed {
|
||||||
encrypt_device_token(&device_token).context("Failed to encrypt device token")?;
|
let folder = context
|
||||||
|
.get_config(Config::ConfiguredInboxFolder)
|
||||||
|
.await?
|
||||||
|
.context("INBOX is not configured")?;
|
||||||
|
|
||||||
// We expect that the server supporting `XDELTAPUSH` capability
|
let encrypted_device_token = encrypt_device_token(&device_token)
|
||||||
// has non-synchronizing literals support as well:
|
.context("Failed to encrypt device token")?;
|
||||||
// <https://www.rfc-editor.org/rfc/rfc7888>.
|
|
||||||
let encrypted_device_token_len = encrypted_device_token.len();
|
|
||||||
|
|
||||||
if encrypted_device_token_len <= 4096 {
|
// We expect that the server supporting `XDELTAPUSH` capability
|
||||||
self.run_command_and_check_ok(&format_setmetadata(
|
// has non-synchronizing literals support as well:
|
||||||
&folder,
|
// <https://www.rfc-editor.org/rfc/rfc7888>.
|
||||||
&encrypted_device_token,
|
let encrypted_device_token_len = encrypted_device_token.len();
|
||||||
))
|
|
||||||
.await
|
|
||||||
.context("SETMETADATA command failed")?;
|
|
||||||
|
|
||||||
// Store device token saved on the server
|
if encrypted_device_token_len <= 4096 {
|
||||||
// to prevent storing duplicate tokens.
|
self.run_command_and_check_ok(&format_setmetadata(
|
||||||
// The server cannot deduplicate on its own
|
&folder,
|
||||||
// because encryption gives a different
|
&encrypted_device_token,
|
||||||
// result each time.
|
))
|
||||||
context
|
.await
|
||||||
.set_config_internal(Config::DeviceToken, Some(&device_token))
|
.context("SETMETADATA command failed")?;
|
||||||
.await?;
|
|
||||||
} else {
|
// Store device token saved on the server
|
||||||
// If Apple or Google (FCM) gives us a very large token,
|
// to prevent storing duplicate tokens.
|
||||||
// do not even try to give it to IMAP servers.
|
// The server cannot deduplicate on its own
|
||||||
//
|
// because encryption gives a different
|
||||||
// Limit of 4096 is arbitrarily selected
|
// result each time.
|
||||||
// to be the same as required by LITERAL- IMAP extension.
|
context
|
||||||
//
|
.set_config_internal(Config::DeviceToken, Some(&device_token))
|
||||||
// Dovecot supports LITERAL+ and non-synchronizing literals
|
.await?;
|
||||||
// of any length, but there is no reason for tokens
|
} else {
|
||||||
// to be that large even after OpenPGP encryption.
|
// If Apple or Google (FCM) gives us a very large token,
|
||||||
warn!(context, "Device token is too long for LITERAL-, ignoring.");
|
// do not even try to give it to IMAP servers.
|
||||||
|
//
|
||||||
|
// Limit of 4096 is arbitrarily selected
|
||||||
|
// to be the same as required by LITERAL- IMAP extension.
|
||||||
|
//
|
||||||
|
// Dovecot supports LITERAL+ and non-synchronizing literals
|
||||||
|
// of any length, but there is no reason for tokens
|
||||||
|
// to be that large even after OpenPGP encryption.
|
||||||
|
warn!(context, "Device token is too long for LITERAL-, ignoring.");
|
||||||
|
}
|
||||||
}
|
}
|
||||||
context.push_subscribed.store(true, Ordering::Relaxed);
|
context.push_subscribed.store(true, Ordering::Relaxed);
|
||||||
} else if !context.push_subscriber.heartbeat_subscribed().await {
|
} else if !context.push_subscriber.heartbeat_subscribed().await {
|
||||||
|
|||||||
Reference in New Issue
Block a user