appendMessageBytes method

Future<GenericImapResult> appendMessageBytes(
  1. Uint8List messageBytes, {
  2. List<String>? flags,
  3. Mailbox? targetMailbox,
  4. String? targetMailboxPath,
  5. DateTime? internalDate,
  6. Duration? responseTimeout,
})

Appends the specified MIME message given as raw messageBytes.

Byte-exact counterpart to appendMessageText: that method's {n} byte count and the socket's IOSink.write both agree on UTF-8, which is right for a message rendered as a String. This method exists for callers holding already-encoded MIME source as bytes, e.g. a message fetched with BODY[] being copied to another account. Sending those through appendMessageText would first turn them into a String, and any byte outside 7-bit ASCII would come back out re-encoded as multi-byte UTF-8, corrupting the message and desyncing the declared literal length from what is actually sent. Here {n} is computed over messageBytes directly and the same bytes reach the socket, via Command.withRawContinuation.

See appendMessageText for the other parameters.

Implementation

Future<GenericImapResult> appendMessageBytes(
  Uint8List messageBytes, {
  List<String>? flags,
  Mailbox? targetMailbox,
  String? targetMailboxPath,
  DateTime? internalDate,
  Duration? responseTimeout,
}) {
  final cmdText = _buildAppendCommandText(
    targetMailbox,
    targetMailboxPath,
    flags,
    internalDate,
    messageBytes.length,
  );
  final cmd = Command.withRawContinuation(
    cmdText,
    messageBytes,
    responseTimeout: responseTimeout,
  );

  return sendCommand<GenericImapResult>(
    cmd,
    GenericParser(this, _selectedMailbox),
  );
}