public override void Export(ContactWriter writer, Contact contact, OutboundVCardConverter.PropertyExporter.Context context) { object obj = contact.TryGetProperty(this.prop); if (obj is string) { writer.WriteProperty(this.propName, obj as string); return; } if (PropertyError.IsPropertyValueTooBig(obj)) { writer.StartProperty(this.propName); using (Stream stream = contact.OpenPropertyStream(this.prop, PropertyOpenMode.ReadOnly)) { using (Stream stream2 = new ConverterStream(stream, new TextToText { InputEncoding = Encoding.Unicode, OutputEncoding = context.Encoding }, ConverterStreamAccess.Read)) { writer.WritePropertyValue(stream2); } } } }
private long WriteAttachmentProperties(Attachment attachment) { long result = 0L; this.tnefWriter.StartAttribute(TnefAttributeTag.Attachment, TnefAttributeLevel.Attachment); foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in attachment.AllNativeProperties) { if (nativeStorePropertyDefinition.Equals(InternalSchema.AttachDataObj)) { result = this.WriteAttachDataObj(attachment); } else if (!nativeStorePropertyDefinition.Equals(InternalSchema.AttachDataBin) && this.propertyChecker.IsAttachmentPropertyWritable(nativeStorePropertyDefinition)) { object obj = attachment.TryGetProperty(nativeStorePropertyDefinition); PropertyError propertyError = obj as PropertyError; if (propertyError != null && PropertyError.IsPropertyValueTooBig(propertyError)) { this.WritePropertyStreamData(attachment.PropertyBag, nativeStorePropertyDefinition); } else if (propertyError == null) { obj = ExTimeZoneHelperForMigrationOnly.ToLegacyUtcIfDateTime(obj); this.tnefWriter.WriteProperty(nativeStorePropertyDefinition, obj); } } } ItemAttachment itemAttachment = attachment as ItemAttachment; if (itemAttachment != null) { result = this.WriteAttachedItem(itemAttachment); } return(result); }
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(); }
internal byte[] GetLargeBinaryProperty(PropertyDefinition propertyDefinition) { object obj = base.TryGetProperty(propertyDefinition); byte[] array = obj as byte[]; if (array != null) { return(array); } if (PropertyError.IsPropertyValueTooBig(obj)) { ExTraceGlobals.StorageTracer.Information <PropertyDefinition>((long)this.GetHashCode(), "PersitablePropertyBag::GetLargeBinaryProperty, {0} too big to fit in GetProp, streaming it", propertyDefinition); using (Stream stream = this.OpenPropertyStream(propertyDefinition, PropertyOpenMode.ReadOnly)) { return(Util.ReadByteArray(stream)); } } PropertyError propertyError = obj as PropertyError; if (propertyError != null && propertyError.PropertyErrorCode == PropertyErrorCode.NotFound) { ExTraceGlobals.StorageTracer.Information <PropertyDefinition>((long)this.GetHashCode(), "PersitablePropertyBag::GetLargeBinaryProperty, {0} not found", propertyDefinition); return(null); } ExTraceGlobals.StorageTracer.TraceError <PropertyDefinition>((long)this.GetHashCode(), "PersitablePropertyBag::GetLargeBinaryProperty, Error when accessing {0}", propertyDefinition); throw new CorruptDataException(ServerStrings.ErrorAccessingLargeProperty); }
internal static StoreObjectType ReadStoreObjectTypeFromPropertyBag(ICorePropertyBag propertyBag) { object propertyValue = propertyBag.TryGetProperty(CoreItemSchema.ItemClass); string text; if (PropertyError.IsPropertyValueTooBig(propertyValue) || PropertyError.IsPropertyNotFound(propertyValue)) { text = string.Empty; } else { text = PropertyBag.CheckPropertyValue <string>(CoreItemSchema.ItemClass, propertyValue); } StoreObjectType objectType = ObjectClass.GetObjectType(text); for (int i = 0; i < ItemBuilder.storeObjectTypeDetectionChain.Length; i++) { StoreObjectType?storeObjectType = ItemBuilder.storeObjectTypeDetectionChain[i](propertyBag, text, objectType); if (storeObjectType != null) { return(storeObjectType.Value); } } return(objectType); }
internal override StoreObjectValidationError Validate(ValidationContext context, IValidatablePropertyBag validatablePropertyBag) { object obj = validatablePropertyBag.TryGetProperty(this.propertyDefinition); if (PropertyError.IsPropertyError(obj) && !PropertyError.IsPropertyValueTooBig(obj)) { return(new StoreObjectValidationError(context, this.propertyDefinition, obj, this)); } return(null); }
private void WritePropertyIfMissing(NativeStorePropertyDefinition property, PersistablePropertyBag propertyBag, OutboundMsgConverter.ComputeValueDelegate computeValue) { PropertyError propertyError = ((IDirectPropertyBag)propertyBag).GetValue(property) as PropertyError; if (propertyError != null && !PropertyError.IsPropertyValueTooBig(propertyError)) { object obj = computeValue(); if (!(obj is PropertyError)) { this.WriteProperty(property, obj); } } }
private CalendarCorrelationMatch(PropertyBag propertyBag, GlobalObjectId globalObjectId) { this.Id = propertyBag.GetValueOrDefault <VersionedId>(InternalSchema.ItemId); this.documentId = propertyBag.GetValueOrDefault <int>(InternalSchema.DocumentId, int.MinValue); byte[] goidBytes = CalendarCorrelationMatch.GetGoidBytes(propertyBag); this.goid = ((goidBytes == null) ? null : new GlobalObjectId(goidBytes)); object obj = propertyBag.TryGetProperty(InternalSchema.AppointmentRecurrenceBlob); this.isRecurringMaster = (obj is byte[] || PropertyError.IsPropertyValueTooBig(obj)); this.appointmentSequenceNumber = propertyBag.GetValueAsNullable <int>(InternalSchema.AppointmentSequenceNumber); this.lastModifiedTime = propertyBag.GetValueAsNullable <ExDateTime>(InternalSchema.LastModifiedTime); this.ownerCriticalChangeTime = propertyBag.GetValueAsNullable <ExDateTime>(InternalSchema.OwnerCriticalChangeTime); this.IsCorrelated = this.CheckIsCorrelated(globalObjectId, out this.isMasterMatchingTheOccurrence); this.properties = propertyBag; }
private void WriteProperty(NativeStorePropertyDefinition property, PersistablePropertyBag propertyBag) { object obj = propertyBag.TryGetProperty(property); PropertyError propertyError = obj as PropertyError; if (propertyError == null) { this.WriteProperty(property, obj); return; } if (PropertyError.IsPropertyValueTooBig(propertyError)) { this.StreamProperty(property, propertyBag); } }
public static RightsManagedMessageItem CreateFromInMemory(MessageItem item, MailboxSession session, StoreId destFolderId, OutboundConversionOptions options) { Util.ThrowOnNullArgument(item, "item"); Util.ThrowOnNullArgument(session, "session"); Util.ThrowOnNullArgument(destFolderId, "destFolderId"); Util.ThrowOnNullArgument(options, "options"); RightsManagedMessageItem.CheckSession(session); if (item.Session != null) { throw new InvalidOperationException("Item should be in-memory, not backed by store."); } RightsManagedMessageItem result; using (DisposeGuard disposeGuard = default(DisposeGuard)) { RightsManagedMessageItem rightsManagedMessageItem = RightsManagedMessageItem.Create(session, destFolderId, options); disposeGuard.Add <RightsManagedMessageItem>(rightsManagedMessageItem); RightsManagedMessageItem.CopyProtectableData(item, rightsManagedMessageItem.decodedItem); foreach (NativeStorePropertyDefinition nativeStorePropertyDefinition in item.AllNativeProperties) { if (!Body.BodyPropSet.Contains(nativeStorePropertyDefinition) && nativeStorePropertyDefinition != StoreObjectSchema.ContentClass) { object obj = item.TryGetProperty(nativeStorePropertyDefinition); if (!(obj is PropertyError)) { rightsManagedMessageItem[nativeStorePropertyDefinition] = obj; } else if (PropertyError.IsPropertyValueTooBig(obj)) { using (Stream stream = item.OpenPropertyStream(nativeStorePropertyDefinition, PropertyOpenMode.ReadOnly)) { using (Stream stream2 = rightsManagedMessageItem.OpenPropertyStream(nativeStorePropertyDefinition, PropertyOpenMode.Create)) { Util.StreamHandler.CopyStreamData(stream, stream2); } } } } } rightsManagedMessageItem.Recipients.CopyRecipientsFrom(item.Recipients); rightsManagedMessageItem.SaveFlags |= (PropertyBagSaveFlags.IgnoreMapiComputedErrors | PropertyBagSaveFlags.IgnoreUnresolvedHeaders); disposeGuard.Success(); result = rightsManagedMessageItem; } return(result); }
protected virtual void OnBeforeSaveUpdateAttachSize() { if (base.MapiAttach != null) { return; } base.Load(new PropertyDefinition[] { InternalSchema.AttachSize, this.ContentStreamProperty }); int num = base.GetValueOrDefault <int>(InternalSchema.AttachSize); if (num != 0) { return; } object obj = base.TryGetProperty(this.ContentStreamProperty); PropertyError propertyError = obj as PropertyError; if (propertyError != null) { if (!PropertyError.IsPropertyValueTooBig(propertyError)) { goto IL_8B; } try { using (Stream stream = this.OpenPropertyStream(this.ContentStreamProperty, PropertyOpenMode.ReadOnly)) { num = (int)stream.Length; } goto IL_8B; } catch (ObjectNotFoundException) { goto IL_8B; } } num = ((byte[])obj).Length; IL_8B: base[InternalSchema.AttachSize] = num; }
internal static void GetEntryIds(ICorePropertyBag propertyBag, out ParticipantEntryId[] mainEntryIds, out ParticipantEntryId[] oneOffEntryIds, out byte[][] extraBytes, out uint computedCheckSum, out bool alwaysStream) { mainEntryIds = new ParticipantEntryId[0]; oneOffEntryIds = new ParticipantEntryId[0]; extraBytes = new byte[0][]; computedCheckSum = 0U; alwaysStream = false; PropertyError propertyError = propertyBag.TryGetProperty(DistributionListSchema.DLStream) as PropertyError; if (propertyError == null || PropertyError.IsPropertyValueTooBig(propertyError)) { long num = -1L; try { using (Stream stream = propertyBag.OpenPropertyStream(DistributionListSchema.DLStream, PropertyOpenMode.ReadOnly)) { if (stream != null && stream.Length > 0L) { num = stream.Length; byte[][] memberIds; DistributionList.ParseEntryIdStream(stream, out mainEntryIds, out oneOffEntryIds, out memberIds, out extraBytes, out alwaysStream); computedCheckSum = DistributionList.ComputeChecksum(memberIds); return; } ExTraceGlobals.StorageTracer.TraceWarning <string>(0L, "DistributionList::GetEntryIds. DLStream property is {0}.", (stream == null) ? "null" : "empty"); } } catch (EndOfStreamException innerException) { string arg = (propertyError == null) ? "<null>" : propertyError.ToLocalizedString(); LocalizedString message = ServerStrings.ExPDLCorruptOutlookBlob(string.Format("EndOfStreamException: propertyError={0}, streamLength={1}", arg, num.ToString())); throw new CorruptDataException(message, innerException); } catch (OutOfMemoryException innerException2) { throw new CorruptDataException(ServerStrings.ExPDLCorruptOutlookBlob("OutOfMemoryException"), innerException2); } } mainEntryIds = DistributionList.ParseEntryIds(propertyBag.GetValueOrDefault <byte[][]>(DistributionListSchema.Members, DistributionList.EmptyEntryIds)); oneOffEntryIds = DistributionList.ParseEntryIds(propertyBag.GetValueOrDefault <byte[][]>(DistributionListSchema.OneOffMembers, DistributionList.EmptyEntryIds)); extraBytes = new byte[mainEntryIds.Length][]; computedCheckSum = DistributionList.ComputeChecksum(propertyBag.GetValueOrDefault <byte[][]>(DistributionListSchema.Members, DistributionList.EmptyEntryIds)); }
private static bool PropertyValuesAreEqual(PropertyDefinition property, object x, object y) { if (!PropertyError.IsPropertyError(x) && !PropertyError.IsPropertyError(y)) { if (property.Type.IsArray) { Array array = x as Array; Array array2 = y as Array; if (array == null || array2 == null || array.Length != array2.Length) { return(false); } for (int i = 0; i < array2.Length; i++) { if (!array.GetValue(i).Equals(array2.GetValue(i))) { return(false); } } } else if (!x.Equals(y)) { return(false); } } else { if (PropertyError.IsPropertyNotFound(x) && !PropertyError.IsPropertyNotFound(y)) { return(false); } if (PropertyError.IsPropertyNotFound(y) && !PropertyError.IsPropertyNotFound(x)) { return(false); } if (PropertyError.IsPropertyValueTooBig(x) || PropertyError.IsPropertyValueTooBig(y)) { return(false); } } return(true); }
internal static GroupExpansionRecipients RetrieveFromStore(MessageItem messageItem, StorePropertyDefinition propertyDefinition) { if (messageItem == null) { return(null); } try { object propertyValue = messageItem.TryGetProperty(propertyDefinition); if (PropertyError.IsPropertyNotFound(propertyValue)) { return(null); } if (PropertyError.IsPropertyValueTooBig(propertyValue)) { using (Stream stream = messageItem.OpenPropertyStream(propertyDefinition, PropertyOpenMode.ReadOnly)) { Encoding encoding = new UnicodeEncoding(false, false); using (StreamReader streamReader = new StreamReader(stream, encoding)) { string data = streamReader.ReadToEnd(); return(GroupExpansionRecipients.Parse(data)); } } } if (PropertyError.IsPropertyError(propertyValue)) { return(null); } string text = messageItem[propertyDefinition] as string; if (!string.IsNullOrEmpty(text)) { return(GroupExpansionRecipients.Parse(text)); } } catch (PropertyErrorException) { return(null); } return(null); }
private bool WriteMessageProperty(NativeStorePropertyDefinition property, out long totalBytesRead) { totalBytesRead = 0L; object obj = this.item.PropertyBag.TryGetProperty(property); PropertyError propertyError = obj as PropertyError; if (propertyError == null) { this.tnefWriter.WriteProperty(property, obj); if (ItemToTnefConverter.bodyProperties.Contains(property)) { byte[] array = obj as byte[]; if (array != null) { totalBytesRead = (long)array.Length; } } return(true); } return(PropertyError.IsPropertyValueTooBig(propertyError) && this.WritePropertyStreamData(this.item.PropertyBag, property, out totalBytesRead)); }
internal static void CopyProperty(PersistablePropertyBag source, PropertyDefinition property, PersistablePropertyBag destination) { object obj = source.TryGetProperty(property); PropertyError propertyError = obj as PropertyError; if (propertyError == null) { destination[property] = obj; return; } if (PropertyError.IsPropertyValueTooBig(propertyError)) { Stream stream; Stream readStream = stream = source.OpenPropertyStream(property, PropertyOpenMode.ReadOnly); try { Stream stream2; Stream writeStream = stream2 = destination.OpenPropertyStream(property, PropertyOpenMode.Create); try { Util.StreamHandler.CopyStreamData(readStream, writeStream); } finally { if (stream2 != null) { ((IDisposable)stream2).Dispose(); } } } finally { if (stream != null) { ((IDisposable)stream).Dispose(); } } } }
internal static List <BlobRecipient> ReadRecipients(Item item, PropertyDefinition propertyDefinition) { item.Load(new PropertyDefinition[] { propertyDefinition }); try { Stream stream = null; object obj = item.TryGetProperty(propertyDefinition); try { if (obj is byte[]) { stream = new MemoryStream(obj as byte[], false); } else if (PropertyError.IsPropertyValueTooBig(obj)) { stream = item.OpenPropertyStream(propertyDefinition, PropertyOpenMode.ReadOnly); } if (stream != null) { return(BlobRecipientParser.ReadRecipients(item.PropertyBag.ExTimeZone, stream)); } } finally { if (stream != null) { stream.Dispose(); } } } catch (PropertyErrorException) { } return(new List <BlobRecipient>()); }
private void WriteMessageAttribute(TnefAttributeTag attribute, TnefPropertyTag tnefProperty, StorePropertyDefinition property) { object obj = this.item.TryGetProperty(property); PropertyError propertyError = obj as PropertyError; if (propertyError == null) { if (attribute == TnefAttributeTag.OriginalMessageClass || attribute == TnefAttributeTag.MessageClass) { string value = obj as string; if (string.IsNullOrEmpty(value)) { return; } } this.tnefWriter.StartAttribute(attribute, TnefAttributeLevel.Message); this.tnefWriter.WriteProperty(tnefProperty, obj); return; } if (PropertyError.IsPropertyValueTooBig(propertyError)) { try { using (Stream stream = this.item.OpenPropertyStream(property, PropertyOpenMode.ReadOnly)) { using (Stream stream2 = this.tnefWriter.OpenAttributeStream(attribute, TnefAttributeLevel.Message)) { Util.StreamHandler.CopyStreamData(stream, stream2); } } } catch (ObjectNotFoundException) { } } }
private void RetryBigProperties(IList <NativeStorePropertyDefinition> allPropDefs, ICollection <PropTag> allPropTags, object[] allValues) { List <int> list = null; int count = allPropDefs.Count; for (int i = 0; i < count; i++) { if (PropertyError.IsPropertyValueTooBig(allValues[i]) && MapiPropertyBag.IsPropertyRetriable(allPropDefs[i])) { if (list == null) { list = new List <int>(10); } list.Add(i); } } if (list == null) { return; } PropTag[] array = new PropTag[count]; allPropTags.CopyTo(array, 0); bool flag = true; while (flag && list.Count > 0) { flag = false; PropTag[] array2 = new PropTag[list.Count]; for (int j = 0; j < array2.Length; j++) { array2[j] = array[list[j]]; } PropValue[] array3 = null; StoreSession storeSession = this.StoreSession; bool flag2 = false; try { if (storeSession != null) { storeSession.BeginMapiCall(); storeSession.BeginServerHealthCall(); flag2 = true; } if (StorageGlobals.MapiTestHookBeforeCall != null) { StorageGlobals.MapiTestHookBeforeCall(MethodBase.GetCurrentMethod()); } array3 = this.mapiProp.GetProps(array2); } catch (MapiPermanentException ex) { throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex, storeSession, this, "{0}. MapiException = {1}.", new object[] { string.Format("MapiPropertyBag::RetryBigProperties. MapiProp = {0}.", this.MapiProp), ex }); } catch (MapiRetryableException ex2) { throw StorageGlobals.TranslateMapiException(ServerStrings.ExGetPropsFailed, ex2, storeSession, this, "{0}. MapiException = {1}.", new object[] { string.Format("MapiPropertyBag::RetryBigProperties. MapiProp = {0}.", this.MapiProp), ex2 }); } finally { try { if (storeSession != null) { storeSession.EndMapiCall(); if (flag2) { storeSession.EndServerHealthCall(); } } } finally { if (StorageGlobals.MapiTestHookAfterCall != null) { StorageGlobals.MapiTestHookAfterCall(MethodBase.GetCurrentMethod()); } } } for (int k = array3.Length - 1; k >= 0; k--) { int num = list[k]; object valueFromPropValue = MapiPropertyBag.GetValueFromPropValue(this.storeSession, this.ExTimeZone, InternalSchema.ToStorePropertyDefinition(allPropDefs[num]), array3[k]); if (!PropertyError.IsPropertyValueTooBig(valueFromPropValue)) { allValues[num] = valueFromPropValue; list.RemoveAt(k); flag = true; } } } }
private void CreateStream() { if ((this.property.PropertyFlags & PropertyFlags.Streamable) == PropertyFlags.None) { ExTraceGlobals.PropertyBagTracer.TraceDebug <NativeStorePropertyDefinition>(0L, "StoreObjectStream::CreateStream property {0} is not marked as streamable.", this.property); } if (this.property.MapiPropertyType == PropType.Object) { this.OpenMapiStream(false); return; } if (this.property.MapiPropertyType != PropType.String && this.property.MapiPropertyType != PropType.Binary) { throw new InvalidOperationException(ServerStrings.ExPropertyNotStreamable(this.property.ToString())); } switch (this.openMode) { case PropertyOpenMode.ReadOnly: case PropertyOpenMode.Modify: { if (!((IDirectPropertyBag)this.storePropertyBag.MemoryPropertyBag).IsLoaded(this.property)) { this.OpenMapiStream(false); return; } object obj = this.storePropertyBag.MemoryPropertyBag.TryGetProperty(this.property); PropertyError propertyError = obj as PropertyError; if (propertyError == null) { this.CreateCache(obj); return; } if (PropertyError.IsPropertyValueTooBig(obj)) { this.OpenMapiStream(false); return; } if (propertyError.PropertyErrorCode != PropertyErrorCode.NotFound) { throw PropertyError.ToException(new PropertyError[] { propertyError }); } if (Array.IndexOf <StorePropertyDefinition>(StoreObjectStream.bodyProperties, this.property) != -1) { this.OpenMapiStream(false); return; } if (this.openMode != PropertyOpenMode.Modify) { throw new ObjectNotFoundException(ServerStrings.ExUnableToGetStreamProperty(this.property.Name)); } break; } case PropertyOpenMode.Create: break; default: return; } this.CreateCache(null); this.dataChanged = true; }