// Token: 0x060002AD RID: 685 RVA: 0x0000F1B4 File Offset: 0x0000D3B4 public void CopyStream(Stream outputStream, int count) { if (outputStream == null) { throw new ArgumentNullException("outputStream"); } if (this.DoBase64Conversion) { StreamHelper.CopyStreamWithBase64Conversion(this.internalStream, outputStream, count, true); return; } StreamHelper.CopyStream(this.internalStream, outputStream, count); }
// Token: 0x06000C2F RID: 3119 RVA: 0x0003FD5C File Offset: 0x0003DF5C private void BuildMultiPartResponse(XmlDocument xmlResponse) { StringBuilder stringBuilder = null; if (base.MailboxLoggingEnabled && base.MailboxLogger != null) { stringBuilder = new StringBuilder(); stringBuilder.Append("----------------------- Multipart Response ---------------------\r\n"); } using (BinaryWriter binaryWriter = new BinaryWriter(base.OutputStream)) { AirSyncStream airSyncStream = new AirSyncStream(); base.Context.Response.BuildMultiPartWbXmlResponse(xmlResponse, airSyncStream); this.multipartStreams.Insert(0, airSyncStream); binaryWriter.Write(this.multipartStreams.Count); if (stringBuilder != null) { stringBuilder.AppendFormat("Number of Parts: {0}\r\n", this.multipartStreams.Count); } int num = 4 + this.multipartStreams.Count * 8; for (int i = 0; i < this.multipartStreams.Count; i++) { long length = this.multipartStreams[i].Length; binaryWriter.Write(num); binaryWriter.Write((int)length); if (stringBuilder != null) { stringBuilder.AppendFormat("Part {0}: offset {1}, size {2}\r\n", i, num, length); } num += (int)length; } for (int j = 0; j < this.multipartStreams.Count; j++) { StreamHelper.CopyStream(this.multipartStreams[j], base.OutputStream, (int)this.multipartStreams[j].Length); if (stringBuilder != null && j == 0) { stringBuilder.AppendLine(); this.multipartStreams[j].Seek(0L, SeekOrigin.Begin); using (WbxmlReader wbxmlReader = new WbxmlReader(this.multipartStreams[j])) { stringBuilder.Append(AirSyncUtility.BuildOuterXml(wbxmlReader.ReadXmlDocument(), !GlobalSettings.EnableMailboxLoggingVerboseMode)); } stringBuilder.AppendLine(); } } if (stringBuilder != null) { base.MailboxLogger.SetData(MailboxLogDataName.ResponseBody, stringBuilder.ToString()); } } }
private static int WriteDrmLicenseToStream(Item item, Stream outStream, int offset, int count, Unlimited <ByteQuantifiedSize> maxAttachmentSize) { object obj = item.TryGetProperty(MessageItemSchema.DRMLicense); byte[][] array = obj as byte[][]; if (array == null) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Failed to get license property for item: {0} returned: {1}", new object[] { item.Id.ToBase64String(), (obj != null) ? obj.ToString() : "null" })); } if (array.Length <= 0) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Invalid license property for item: {0} length: {1}", new object[] { item.Id.ToBase64String(), array })); } if (!maxAttachmentSize.IsUnlimited && (long)array[0].Length > (long)maxAttachmentSize.Value.ToBytes()) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } int result; using (Stream stream = new MemoryStream(array[0])) { if (stream.Length > 0L) { if ((long)offset >= stream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num = (count == -1) ? ((int)stream.Length) : count; if (num > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(stream, outStream, offset, num); } result = (int)stream.Length; } return(result); }
// Token: 0x0600074D RID: 1869 RVA: 0x00027EFC File Offset: 0x000260FC public void Execute() { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "DocumentLibrary Fetch command received. Processing request..."); Uri uri = null; try { uri = new Uri(this.linkId); } catch (UriFormatException innerException) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Bad document Uri {0} was specified!", new object[] { this.linkId })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, innerException, false); } AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "Processing Fetch command with Uri {0}.", uri.AbsoluteUri); if (!DocumentLibraryUtility.IsTrustedProtocol(uri.Scheme)) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: untrusted protocol: {0}!", new object[] { uri.Scheme })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadProtocolInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } if (!DocumentLibraryUtility.IsInternalUri(uri)) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Uri must be internal: {0}!", new object[] { uri.Host })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "ExternalProtocolInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } AuthenticationContext authenticationContext = new AuthenticationContext(); try { IPrincipal principal; if (this.userPassword == null) { principal = this.user.WindowsPrincipal; if (principal == null) { if (GlobalSettings.EnableCredentialRequest && this.user.Context.Request.Version >= 121) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedPromptForCredsToProxy2"); throw new AirSyncPermanentException(StatusCode.ItemOperations_CredentialsRequired, false); } this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NeedCredsToProxy2"); throw new AirSyncPermanentException(HttpStatusCode.Forbidden, StatusCode.AccessDenied, null, false); } } else { SecurityStatus securityStatus = authenticationContext.LogonUser(this.userName, this.userPassword); this.userPassword.Dispose(); this.userPassword = null; if (securityStatus != SecurityStatus.OK) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, string.Format(CultureInfo.InvariantCulture, "ItemOperationsFetchProvider: Authentication failed with status {0}.", new object[] { securityStatus })); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, string.Format(CultureInfo.InvariantCulture, "AuthenticationErrorStatus{0}", new object[] { securityStatus })); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false); } principal = new WindowsPrincipal(authenticationContext.Identity); } ClassifyResult classifyResult = LinkClassifier.ClassifyLinks(principal, new Uri[] { uri })[0]; if (classifyResult.Error != ClassificationError.None) { AirSyncDiagnostics.TraceDebug <string, ClassificationError>(ExTraceGlobals.RequestsTracer, this, "The LinkClassifier failed to classify the link {0}, returned {1}", this.linkId, classifyResult.Error); switch (classifyResult.Error) { case ClassificationError.ConnectionFailed: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassConnFailedInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_Conflict, null, false); case ClassificationError.AccessDenied: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassDeniedInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ServerError, null, false); case ClassificationError.ObjectNotFound: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassNotFoundInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ClientServerConversion, null, false); case ClassificationError.UriTypeNotSupported: case ClassificationError.InvalidUri: this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassBadUriInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ProtocolError, null, false); } this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "LinkClassFailureInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false); } IDocument document = null; UncSession uncSession = null; SharepointSession sharepointSession = null; if ((classifyResult.UriFlags & UriFlags.UncDocument) == UriFlags.UncDocument) { if (!DocumentLibraryUtility.IsUncAccessEnabled(this.user)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } if (DocumentLibraryUtility.IsBlockedHostName(uri.Host)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } uncSession = UncSession.Open(classifyResult.ObjectId, principal); } else { if ((classifyResult.UriFlags & UriFlags.SharepointDocument) != UriFlags.SharepointDocument) { AirSyncDiagnostics.TraceDebug <string, UriFlags>(ExTraceGlobals.RequestsTracer, this, "The Uri {0} of type {1} is not supported for Fetch", this.linkId, classifyResult.UriFlags); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadLinkInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_ProtocolError, false); } if (!DocumentLibraryUtility.IsWssAccessEnabled(this.user)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "WssDeniedInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } if (DocumentLibraryUtility.IsBlockedHostName(uri.Host)) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "HostBlockedInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_Retry, false); } this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.SharePointDocs); sharepointSession = SharepointSession.Open(classifyResult.ObjectId, principal); } try { if (uncSession != null) { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Reading UNC document..."); document = UncDocument.Read(uncSession, classifyResult.ObjectId); } else { AirSyncDiagnostics.TraceDebug(ExTraceGlobals.RequestsTracer, this, "Reading Sharepoint document..."); AirSyncDiagnostics.Assert(sharepointSession != null); document = SharepointDocument.Read(sharepointSession, classifyResult.ObjectId); } } catch (ObjectNotFoundException innerException2) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException2, false); } catch (AccessDeniedException innerException3) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException3, false); } this.documentSize = (int)document.Size; if (this.documentSize == 0) { AirSyncDiagnostics.TraceDebug <string>(ExTraceGlobals.RequestsTracer, this, "The file {0} was found to be empty!", this.linkId); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "EmptyDocInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_NotificationGUID, null, false); } object obj = document.TryGetProperty(DocumentLibraryItemSchema.LastModifiedDate); if (obj is PropertyError) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "GeneralErrorInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, false); } ExDateTime exDateTime; if (obj is DateTime) { exDateTime = new ExDateTime(ExTimeZone.UtcTimeZone, (DateTime)obj); } else { exDateTime = (ExDateTime)obj; } this.version = exDateTime.ToString("yyyy-MM-dd\\THH:mm:ss.fff\\Z", CultureInfo.InvariantCulture); if (this.rangeSpecified && this.minRange >= this.documentSize) { AirSyncDiagnostics.TraceDebug <int, int>(ExTraceGlobals.RequestsTracer, this, "The minimum range specified {0} is greater than the document size {1}", this.minRange, this.documentSize); this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "BadMinSizeInDocFetch"); throw new AirSyncPermanentException(HttpStatusCode.OK, StatusCode.Sync_ObjectNotFound, null, false); } using (Stream document2 = document.GetDocument()) { int num; if (this.rangeSpecified) { num = this.maxRange - this.minRange + 1; } else { num = this.documentSize; } if (uncSession != null) { this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.UNCFiles); this.user.Context.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.UNCBytes, num); } if (sharepointSession != null) { this.user.Context.ProtocolLogger.IncrementValue(ProtocolLoggerData.SharePointDocs); this.user.Context.ProtocolLogger.IncrementValueBy(ProtocolLoggerData.SharePointBytes, num); } this.outStream = new MemoryStream(num); if (num > GlobalSettings.MaxDocumentDataSize) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "DocTooBigInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_NotificationsNotProvisioned, false); } try { StreamHelper.CopyStream(document2, this.outStream, this.minRange, num); } catch (IOException innerException4) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch"); throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException4, false); } } } catch (UnknownErrorException innerException5) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException5, false); } catch (DocumentModifiedException innerException6) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "IOErrorInDocFetch3"); throw new AirSyncPermanentException(StatusCode.Sync_FolderHierarchyRequired, innerException6, false); } catch (DocumentStreamAccessDeniedException innerException7) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "AccessDeniedInDocFetch3"); throw new AirSyncPermanentException(StatusCode.Sync_ServerError, innerException7, false); } catch (ObjectMovedOrDeletedException innerException8) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "NotFoundInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_ClientServerConversion, innerException8, false); } catch (DocumentLibraryException innerException9) { this.user.Context.ProtocolLogger.SetValue(ProtocolLoggerData.Error, "GeneralErrorInDocFetch2"); throw new AirSyncPermanentException(StatusCode.Sync_InvalidSyncKey, innerException9, false); } finally { if (authenticationContext != null) { authenticationContext.Dispose(); authenticationContext = null; } } }
// Token: 0x0600159E RID: 5534 RVA: 0x00080150 File Offset: 0x0007E350 internal static int CopyStream(Stream source, Stream target, int offset, int count) { uint num; return(StreamHelper.CopyStream(source, target, offset, count, false, out num)); }
// Token: 0x0600159D RID: 5533 RVA: 0x00080141 File Offset: 0x0007E341 internal static int CopyStream(Stream source, Stream target, int byteCount, out uint crc) { return(StreamHelper.CopyStream(source, target, 0, byteCount, true, out crc)); }
// Token: 0x0600159C RID: 5532 RVA: 0x00080128 File Offset: 0x0007E328 internal static int CopyStream(Stream source, Stream target, int byteCount) { uint num; return(StreamHelper.CopyStream(source, target, 0, byteCount, false, out num)); }
// Token: 0x0600159B RID: 5531 RVA: 0x00080118 File Offset: 0x0007E318 internal static int CopyStream(Stream source, Stream target) { return(StreamHelper.CopyStream(source, target, int.MaxValue)); }
private static string GetAttachmentItself(Attachment attachment, Stream outStream, int offset, int count, out int total) { string text = string.Empty; total = 0; StreamAttachmentBase streamAttachmentBase = attachment as StreamAttachmentBase; if (streamAttachmentBase != null) { OleAttachment oleAttachment = streamAttachmentBase as OleAttachment; Stream stream = null; try { if (oleAttachment != null) { stream = oleAttachment.TryConvertToImage(ImageFormat.Jpeg); if (stream != null) { text = "image/jpeg"; } } if (stream == null) { stream = streamAttachmentBase.GetContentStream(); } if (string.IsNullOrEmpty(text)) { text = attachment.ContentType; } if (string.IsNullOrEmpty(text)) { text = attachment.CalculatedContentType; } if (stream.Length > 0L) { if ((long)offset >= stream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num = (count == -1) ? ((int)stream.Length) : count; if (num > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(stream, outStream, offset, num); total = (int)stream.Length; } } finally { if (stream != null) { stream.Dispose(); stream = null; } } return(text); } ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { using (Item item = itemAttachment.GetItem(StoreObjectSchema.ContentConversionProperties)) { text = "message/rfc822"; OutboundConversionOptions outboundConversionOptions = AirSyncUtility.GetOutboundConversionOptions(); using (AirSyncStream airSyncStream = new AirSyncStream()) { try { ItemConversion.ConvertItemToMime(item, airSyncStream, outboundConversionOptions); } catch (ConversionFailedException innerException) { throw new FormatException(string.Format(CultureInfo.InvariantCulture, "MIME conversion failed for Attachment {0}!", new object[] { attachment }), innerException); } if (airSyncStream.Length > 0L) { if ((long)offset >= airSyncStream.Length) { throw new ArgumentOutOfRangeException("offset"); } int num2 = (count == -1) ? ((int)airSyncStream.Length) : count; if (num2 > GlobalSettings.MaxDocumentDataSize) { throw new DataTooLargeException(StatusCode.AttachmentIsTooLarge); } StreamHelper.CopyStream(airSyncStream, outStream, offset, num2); total = (int)airSyncStream.Length; } } } return(text); } throw new FormatException(string.Format(CultureInfo.InvariantCulture, "Attachment {0} is of invalid format!", new object[] { attachment })); }