public Stream GetReadOnlyApplefileStream() { base.CheckDisposed("GetReadOnlyApplefileStream"); if (this.IsFlaggedAsMacAttachment) { object obj = base.TryGetProperty(InternalSchema.AttachmentMacInfo); if (obj is byte[]) { return(new MemoryStream(obj as byte[], false)); } if (PropertyError.IsPropertyValueTooBig(obj)) { return(this.OpenPropertyStream(InternalSchema.AttachmentMacInfo, PropertyOpenMode.ReadOnly)); } using (Stream rawContentStream = this.GetRawContentStream(PropertyOpenMode.ReadOnly)) { if (this.IsMacAttachmentInternal(rawContentStream)) { using (DisposeGuard disposeGuard = default(DisposeGuard)) { Stream stream = disposeGuard.Add <MemoryStream>(new MemoryStream()); string text = null; byte[] array = null; MimeAppleTranscoder.MacBinToApplefile(rawContentStream, stream, out text, out array); disposeGuard.Success(); return(stream); } } throw new CorruptDataException(ServerStrings.ConversionFailedInvalidMacBin); } } throw new InvalidOperationException(); }
private bool IsMacAttachmentInternal(Stream attachStream) { this.isMacAttachment = new bool?(false); if (this.IsFlaggedAsMacAttachment && attachStream != null) { this.isMacAttachment = new bool?(MimeAppleTranscoder.IsMacBinStream(attachStream)); } return(this.isMacAttachment.Value); }
public override Stream GetContentStream(PropertyOpenMode openMode) { base.CheckDisposed("GetContentStream"); Stream contentStream = base.GetContentStream(openMode); if (!this.IsMacAttachmentInternal(contentStream)) { return(contentStream); } if (openMode == PropertyOpenMode.ReadOnly) { return(MimeAppleTranscoder.ExtractDataFork(contentStream)); } throw new InvalidOperationException("Unable to get write stream for mac attachment."); }