示例#1
0
        public static string StoreIdToEwsId(Guid mailboxGuid, StoreId storeId)
        {
            Util.ThrowOnNullArgument(storeId, "storeId");
            MailboxId           mailboxId           = new MailboxId(mailboxGuid);
            IdHeaderInformation idHeaderInformation = new IdHeaderInformation();
            StoreObjectId       storeObjectId       = StoreId.GetStoreObjectId(storeId);

            if (storeObjectId.ObjectType == StoreObjectType.CalendarItemOccurrence)
            {
                idHeaderInformation.StoreIdBytes            = storeObjectId.GetBytes();
                idHeaderInformation.IdProcessingInstruction = IdProcessingInstruction.Recurrence;
            }
            else if (storeObjectId.ObjectType == StoreObjectType.CalendarItemSeries)
            {
                idHeaderInformation.StoreIdBytes            = storeObjectId.ProviderLevelItemId;
                idHeaderInformation.IdProcessingInstruction = IdProcessingInstruction.Series;
            }
            else
            {
                idHeaderInformation.StoreIdBytes            = storeObjectId.ProviderLevelItemId;
                idHeaderInformation.IdProcessingInstruction = IdProcessingInstruction.Normal;
            }
            idHeaderInformation.IdStorageType = IdStorageType.MailboxItemMailboxGuidBased;
            idHeaderInformation.MailboxId     = mailboxId;
            return(ServiceIdConverter.ConvertToConcatenatedId(idHeaderInformation, null, true));
        }
示例#2
0
        public static string PublicFolderStoreIdToEwsId(StoreId storeId, StoreId parentFolderId)
        {
            Util.ThrowOnNullArgument(storeId, "storeId");
            IdHeaderInformation idHeaderInformation = new IdHeaderInformation();
            StoreObjectId       storeObjectId       = StoreId.GetStoreObjectId(storeId);

            if (storeObjectId.ObjectType == StoreObjectType.CalendarItemOccurrence)
            {
                idHeaderInformation.StoreIdBytes            = storeObjectId.GetBytes();
                idHeaderInformation.IdProcessingInstruction = IdProcessingInstruction.Recurrence;
            }
            else if (storeObjectId.ObjectType == StoreObjectType.CalendarItemSeries)
            {
                idHeaderInformation.StoreIdBytes            = storeObjectId.ProviderLevelItemId;
                idHeaderInformation.IdProcessingInstruction = IdProcessingInstruction.Series;
            }
            else
            {
                idHeaderInformation.StoreIdBytes            = storeObjectId.ProviderLevelItemId;
                idHeaderInformation.IdProcessingInstruction = IdProcessingInstruction.Normal;
            }
            if (Folder.IsFolderId(storeObjectId))
            {
                idHeaderInformation.IdStorageType = IdStorageType.PublicFolder;
            }
            else
            {
                Util.ThrowOnNullArgument(parentFolderId, "parentFolderId");
                StoreObjectId storeObjectId2 = StoreId.GetStoreObjectId(parentFolderId);
                idHeaderInformation.FolderIdBytes = storeObjectId2.ProviderLevelItemId;
                idHeaderInformation.IdStorageType = IdStorageType.PublicFolderItem;
            }
            return(ServiceIdConverter.ConvertToConcatenatedId(idHeaderInformation, null, true));
        }
        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 bool IsPublicFolder(string id)
        {
            bool result;

            try
            {
                using (MemoryStream decompressedMemoryStream = ServiceIdConverter.GetDecompressedMemoryStream(id))
                {
                    using (BinaryReader binaryReader = new BinaryReader(decompressedMemoryStream))
                    {
                        result = (ServiceIdConverter.ReadIdStorageType(binaryReader, BasicTypes.Folder) == IdStorageType.PublicFolder);
                    }
                }
            }
            catch (EndOfStreamException innerException)
            {
                throw new InvalidIdMalformedException(innerException);
            }
            catch (CorruptDataException innerException2)
            {
                throw new InvalidIdMalformedException(innerException2);
            }
            catch (FormatException innerException3)
            {
                throw new InvalidIdMalformedException(innerException3);
            }
            return(result);
        }
        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);
        }
示例#10
0
        public static StoreObjectId EwsIdToFolderStoreObjectId(string id)
        {
            IdHeaderInformation idHeaderInformation = ServiceIdConverter.ConvertFromConcatenatedId(id, BasicTypes.Folder, null);

            return(idHeaderInformation.ToStoreObjectId());
        }
        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);
        }
        public static string ConvertToConcatenatedId(IdHeaderInformation idHeaderInformation, List <AttachmentId> attachmentIds, bool attemptCompression)
        {
            int num = 2;

            if (1024 < idHeaderInformation.StoreIdBytes.Length)
            {
                throw new InvalidIdStoreObjectIdTooLongException();
            }
            num += 2 + idHeaderInformation.StoreIdBytes.Length;
            int num2 = 0;

            if (idHeaderInformation.IdStorageType == IdStorageType.MailboxItemSmtpAddressBased)
            {
                num2 = MailboxIdSerializer.EmailAddressToByteCount(idHeaderInformation.MailboxId.SmtpAddress);
                if (num2 == 0 || 512 < num2)
                {
                    throw new InvalidIdMonikerTooLongException();
                }
                num += 2 + num2 + 1;
            }
            else if (idHeaderInformation.IdStorageType == IdStorageType.MailboxItemMailboxGuidBased || idHeaderInformation.IdStorageType == IdStorageType.ConversationIdMailboxGuidBased)
            {
                num2 = MailboxIdSerializer.MailboxGuidToByteCount(idHeaderInformation.MailboxId.MailboxGuid);
                if (num2 == 0 || 512 < num2)
                {
                    throw new InvalidIdMonikerTooLongException();
                }
                num += 2 + num2 + 1;
            }
            else if (idHeaderInformation.IdStorageType == IdStorageType.PublicFolderItem)
            {
                num += 3 + idHeaderInformation.FolderIdBytes.Length;
            }
            num += ServiceIdConverter.GetRequiredByteCountForAttachmentIds(attachmentIds);
            byte[] array = new byte[num];
            int    num3  = 0;

            array[num3++] = 0;
            array[num3++] = (byte)idHeaderInformation.IdStorageType;
            switch (idHeaderInformation.IdStorageType)
            {
            case IdStorageType.MailboxItemSmtpAddressBased:
            case IdStorageType.MailboxItemMailboxGuidBased:
            case IdStorageType.ConversationIdMailboxGuidBased:
                num3 += ExBitConverter.Write((short)num2, array, num3);
                if (idHeaderInformation.IdStorageType == IdStorageType.MailboxItemSmtpAddressBased)
                {
                    num3 += MailboxIdSerializer.EmailAddressToBytes(idHeaderInformation.MailboxId.SmtpAddress, array, num3);
                }
                else
                {
                    num3 += MailboxIdSerializer.MailboxGuidToBytes(idHeaderInformation.MailboxId.MailboxGuid, array, num3);
                }
                array[num3++] = (byte)idHeaderInformation.IdProcessingInstruction;
                num3         += ExBitConverter.Write((short)idHeaderInformation.StoreIdBytes.Length, array, num3);
                Array.Copy(idHeaderInformation.StoreIdBytes, 0, array, num3, idHeaderInformation.StoreIdBytes.Length);
                num3 += idHeaderInformation.StoreIdBytes.Length;
                break;

            case IdStorageType.PublicFolder:
            case IdStorageType.ActiveDirectoryObject:
                num3 += ExBitConverter.Write((short)idHeaderInformation.StoreIdBytes.Length, array, num3);
                Array.Copy(idHeaderInformation.StoreIdBytes, 0, array, num3, idHeaderInformation.StoreIdBytes.Length);
                num3 += idHeaderInformation.StoreIdBytes.Length;
                break;

            case IdStorageType.PublicFolderItem:
                array[num3++] = (byte)idHeaderInformation.IdProcessingInstruction;
                num3         += ExBitConverter.Write((short)idHeaderInformation.StoreIdBytes.Length, array, num3);
                Array.Copy(idHeaderInformation.StoreIdBytes, 0, array, num3, idHeaderInformation.StoreIdBytes.Length);
                num3 += idHeaderInformation.StoreIdBytes.Length;
                num3 += ExBitConverter.Write((short)idHeaderInformation.FolderIdBytes.Length, array, num3);
                Array.Copy(idHeaderInformation.FolderIdBytes, 0, array, num3, idHeaderInformation.FolderIdBytes.Length);
                num3 += idHeaderInformation.FolderIdBytes.Length;
                break;
            }
            ServiceIdConverter.WriteAttachmentIds(attachmentIds, array, num3);
            if (attemptCompression)
            {
                array = ServiceIdConverter.AttemptCompression(array, out num);
            }
            return(Convert.ToBase64String(array, 0, num));
        }