public void WriteTo (ImapStream stream, CancellationToken cancellationToken)
{
if (Type == ImapLiteralType.String) {
var bytes = (byte[]) Literal;
stream.Write (bytes, 0, bytes.Length, cancellationToken);
stream.Flush (cancellationToken);
return;
}
if (Type == ImapLiteralType.MimeMessage) {
var message = (MimeMessage) Literal;
using (var s = new ProgressStream (stream, update)) {
message.WriteTo (format, s, cancellationToken);
s.Flush (cancellationToken);
return;
}
}
var literal = (Stream) Literal;
var buf = new byte[4096];
int nread;
while ((nread = literal.Read (buf, 0, buf.Length)) > 0)
stream.Write (buf, 0, nread, cancellationToken);
stream.Flush (cancellationToken);
}
}