private static MemoryStream GetDecompressedMemoryStream(string id)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new InvalidIdEmptyException();
            }
            byte[] array = Convert.FromBase64String(id);
            if (array.Length == 0)
            {
                throw new InvalidIdEmptyException();
            }
            CompressionId compressionId = (CompressionId)array[0];

            if (compressionId != CompressionId.NoCompression && compressionId != CompressionId.RleCompression)
            {
                ServiceIdConverter.TraceDebug("[IdConverter::IsPublicFolder] Invalid compression id");
                throw new InvalidIdMalformedException();
            }
            IIdCompressor idCompressor2;

            if (compressionId != CompressionId.RleCompression)
            {
                IIdCompressor idCompressor = ServiceIdConverter.passthruCompressor;
                idCompressor2 = idCompressor;
            }
            else
            {
                idCompressor2 = ServiceIdConverter.rleCompressor;
            }
            IIdCompressor idCompressor3 = idCompressor2;

            return(idCompressor3.Decompress(array, 1024));
        }
        public static void ReadAttachmentIds(BinaryReader reader, List <AttachmentId> attachmentIds)
        {
            byte b = reader.ReadByte();

            if (b == 0)
            {
                ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Number of attachment indicator was set to 0.  Shouldn't be there at all in that case");
                throw new InvalidIdException();
            }
            if (b > 255)
            {
                ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Number of attachments in id is greater than allowed value");
                throw new InvalidIdMalformedException();
            }
            for (int i = 0; i < (int)b; i++)
            {
                short num = reader.ReadInt16();
                if (num <= 0)
                {
                    throw new InvalidIdMalformedException();
                }
                byte[] array = reader.ReadBytes((int)num);
                if (array.Length != (int)num)
                {
                    ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Attachment Id length did not match actual length");
                    throw new InvalidIdMalformedException();
                }
                attachmentIds.Add(AttachmentId.Deserialize(array));
            }
        }
 private static void ReadAttachmentIds(BinaryReader reader, BasicTypes expectedType, List <AttachmentId> attachmentIds)
 {
     if (expectedType != BasicTypes.Attachment && expectedType != BasicTypes.ItemOrAttachment)
     {
         ServiceIdConverter.TraceDebug("[IdConverter::ReadAttachmentIds] Did not expect attachments in id, but received attachments embedded in id");
         throw new InvalidIdException();
     }
     ServiceIdConverter.ReadAttachmentIds(reader, attachmentIds);
 }
        private static IdProcessingInstruction ReadIdProcessingInstruction(BinaryReader reader, BasicTypes expectedType)
        {
            IdProcessingInstruction idProcessingInstruction = (IdProcessingInstruction)reader.ReadByte();

            if (!EnumValidator.IsValidValue <IdProcessingInstruction>(idProcessingInstruction))
            {
                ServiceIdConverter.TraceDebug("[IdConverter::ReadEnumValue] Invalid value for id processing instruction");
                throw new InvalidIdMalformedException();
            }
            return(idProcessingInstruction);
        }
        private static IdStorageType ReadIdStorageType(BinaryReader reader, BasicTypes expectedType)
        {
            IdStorageType idStorageType = (IdStorageType)reader.ReadByte();

            if (!EnumValidator.IsValidValue <IdStorageType>(idStorageType))
            {
                ServiceIdConverter.TraceDebug("[IdConverter::ReadEnumValue] Invalid value for id storage type");
                throw new InvalidIdMalformedException();
            }
            return(idStorageType);
        }
        private static byte[] ReadStoreId(BinaryReader reader, BasicTypes expectedType)
        {
            short num = reader.ReadInt16();

            if (num < 0)
            {
                ServiceIdConverter.TraceDebug("[IdConverter::ReadStoreId] StoreId count < 0");
                throw new InvalidIdMalformedException();
            }
            byte[] array = reader.ReadBytes((int)num);
            if (array.Length != (int)num)
            {
                ServiceIdConverter.TraceDebug("[IdConverter::ReadStoreId] StoreId bytes length did not match actual length");
                throw new InvalidIdMalformedException();
            }
            return(array);
        }
        public static IdHeaderInformation ConvertFromConcatenatedId(string id, BasicTypes expectedType, List <AttachmentId> attachmentIds)
        {
            if (string.IsNullOrEmpty(id))
            {
                throw new InvalidIdEmptyException();
            }
            EnumValidator.ThrowIfInvalid <BasicTypes>(expectedType, "expectedType");
            IdHeaderInformation result;

            try
            {
                IdHeaderInformation idHeaderInformation = new IdHeaderInformation();
                using (MemoryStream decompressedMemoryStream = ServiceIdConverter.GetDecompressedMemoryStream(id))
                {
                    using (BinaryReader binaryReader = new BinaryReader(decompressedMemoryStream))
                    {
                        idHeaderInformation.IdStorageType = ServiceIdConverter.ReadIdStorageType(binaryReader, expectedType);
                        switch (idHeaderInformation.IdStorageType)
                        {
                        case IdStorageType.MailboxItemSmtpAddressBased:
                            idHeaderInformation.MailboxId = new MailboxId(MailboxIdSerializer.EmailAddressFromBytes(ServiceIdConverter.ReadMoniker(binaryReader, expectedType)));
                            idHeaderInformation.IdProcessingInstruction = ServiceIdConverter.ReadIdProcessingInstruction(binaryReader, expectedType);
                            idHeaderInformation.StoreIdBytes            = ServiceIdConverter.ReadStoreId(binaryReader, expectedType);
                            break;

                        case IdStorageType.PublicFolder:
                        case IdStorageType.ActiveDirectoryObject:
                            idHeaderInformation.StoreIdBytes = ServiceIdConverter.ReadStoreId(binaryReader, expectedType);
                            break;

                        case IdStorageType.PublicFolderItem:
                            idHeaderInformation.IdProcessingInstruction = ServiceIdConverter.ReadIdProcessingInstruction(binaryReader, expectedType);
                            idHeaderInformation.StoreIdBytes            = ServiceIdConverter.ReadStoreId(binaryReader, expectedType);
                            idHeaderInformation.FolderIdBytes           = ServiceIdConverter.ReadStoreId(binaryReader, expectedType);
                            break;

                        case IdStorageType.MailboxItemMailboxGuidBased:
                        case IdStorageType.ConversationIdMailboxGuidBased:
                            idHeaderInformation.MailboxId = new MailboxId(MailboxIdSerializer.MailboxGuidFromBytes(ServiceIdConverter.ReadMoniker(binaryReader, expectedType)));
                            idHeaderInformation.IdProcessingInstruction = ServiceIdConverter.ReadIdProcessingInstruction(binaryReader, expectedType);
                            idHeaderInformation.StoreIdBytes            = ServiceIdConverter.ReadStoreId(binaryReader, expectedType);
                            break;

                        default:
                            ServiceIdConverter.TraceDebug("[IdConverter::ConvertFromConcatenatedId] Invalid id storage type");
                            throw new InvalidIdMalformedException();
                        }
                        if (attachmentIds != null)
                        {
                            if (decompressedMemoryStream.Position < decompressedMemoryStream.Length)
                            {
                                ServiceIdConverter.ReadAttachmentIds(binaryReader, expectedType, attachmentIds);
                            }
                            else if (expectedType == BasicTypes.Attachment)
                            {
                                throw new InvalidIdNotAnItemAttachmentIdException();
                            }
                        }
                    }
                }
                result = idHeaderInformation;
            }
            catch (EndOfStreamException innerException)
            {
                throw new InvalidIdMalformedException(innerException);
            }
            catch (CorruptDataException innerException2)
            {
                throw new InvalidIdMalformedException(innerException2);
            }
            catch (FormatException innerException3)
            {
                throw new InvalidIdMalformedException(innerException3);
            }
            return(result);
        }