updateMessageFlags method
Update flags on a message (IMAP STORE)
messageId The message to update
addFlags Flags to add (use MessageFlags constants)
removeFlags Flags to remove
Implementation
Future<UpdateFlagsAck?> updateMessageFlags(
String messageId, {
PeerId? serverPeerId,
int addFlags = 0,
int removeFlags = 0,
}) async {
_logger.info('Updating flags for message $messageId: +$addFlags -$removeFlags');
// Select server
final serverId = serverPeerId ??
await _serverSelector.selectServer(config.preferredServers);
if (serverId == null) {
_logger.warning('No S&F server available');
return null;
}
P2PStream? stream;
try {
// Use MAA (Mail Access Agent) protocol for IMAP-style operations
final context = Context();
stream = await host.newStream(
serverId,
[AccessHandler.protocolId],
context,
).timeout(config.connectionTimeout);
final ack = await AccessHandler.updateFlags(
stream,
messageId,
addFlags: addFlags,
removeFlags: removeFlags,
).timeout(config.messageTimeout);
_logger.info('Updated flags: success=${ack.success}, newFlags=${ack.newFlags}');
return ack;
} on TimeoutException {
_logger.warning('Update flags timed out');
return null;
} catch (e) {
_logger.warning('Failed to update flags: $e');
return null;
} finally {
// The stream is closed on every path: a stream left open holds a slot
// on the connection for as long as the session lives.
if (stream != null && !stream.isClosed) {
try {
await stream.close();
} catch (e) {
_logger.fine('Error closing stream: $e');
}
}
}
}