appendMessageText method

Future<GenericImapResult> appendMessageText(
  1. String messageText, {
  2. List<String>? flags,
  3. Mailbox? targetMailbox,
  4. String? targetMailboxPath,
})

Appends the specified MIME messageText.

When no targetMailbox or targetMailboxPath is specified, then the message will be appended to the currently selected mailbox. You can specify flags such as \Seen or \Draft in the flags parameter. Compare also the appendMessageText method.

Implementation

Future<GenericImapResult> appendMessageText(String messageText,
    {List<String>? flags,
    Mailbox? targetMailbox,
    String? targetMailboxPath}) {
  var path =
      targetMailbox?.path ?? targetMailboxPath ?? _selectedMailbox?.path;
  if (path == null) {
    throw StateError(
        'no target mailbox specified and no mailbox is currently selected.');
  }
  path = _encodeMailboxPath(path);
  final buffer = StringBuffer()..write('APPEND ')..write(path);
  if (flags != null && flags.isNotEmpty) {
    buffer..write(' (')..write(flags.join(' '))..write(')');
  }
  final numberOfBytes = utf8.encode(messageText).length;
  buffer..write(' {')..write(numberOfBytes)..write('}');
  final cmdText = buffer.toString();
  final cmd = Command.withContinuation([cmdText, messageText]);
  return sendCommand<GenericImapResult>(
      cmd, GenericParser(this, _selectedMailbox));
}