private Stream GetRequestStreamProc() { var session = GetSession(); CloseMailbox(); // ignore error appendMessageBodyStream = new ImapWebClientAppendMessageBodyStream(ReadWriteTimeout); // Content-Length if (0 < ContentLength) appendMessageBodyStream.SetLength(ContentLength); // TODO: TRYCREATE when AllowCreateMailbox == true beginAppendAsyncResult = session.BeginAppend(appendMessageBodyStream, DateTimeOffset.Now, null, RequestMailbox); return appendMessageBodyStream; }
private ImapWebResponse GetAppendResponse() { if (beginAppendAsyncResult == null) throw new InvalidOperationException("GetRequestStream not called"); try { appendMessageBodyStream.UpdateLength(); ImapAppendedUidSet appendedUid; var response = new ImapWebResponse(Session.EndAppend(beginAppendAsyncResult, out appendedUid)); if (response.Result.Succeeded) { // set empty stream; WebClient.Upload*() methods call WebResponse.GetResponseStream response.SetResponseStream(Stream.Null, 0L, false); if (appendedUid != null) { var builder = new ImapUriBuilder(RequestUri); builder.UidValidity = appendedUid.UidValidity; builder.Uid = appendedUid.ToNumber(); // if appendedUid.IsSingle response.SetResponseUri(builder.Uri); } } return response; } finally { appendMessageBodyStream.InternalDispose(); appendMessageBodyStream = null; beginAppendAsyncResult = null; } }