internal MsgStorageReader(ComStorage storage, NamedPropertyList namedPropertyList, Encoding parentEncoding)
 {
     this.isTopLevelMessage = false;
     this.messageStorage    = storage;
     this.namedPropertyList = namedPropertyList;
     this.Initialize(parentEncoding);
 }
Beispiel #2
0
 public void WriteTo(ComStorage messageStorage)
 {
     using (ComStorage comStorage = messageStorage.CreateStorage("__nameid_version1.0", ComStorage.OpenMode.CreateWrite))
     {
         List <Guid> list = new List <Guid>(32);
         list.AddRange(NamedPropertyList.StandardGuids);
         Dictionary <Guid, int> dictionary = new Dictionary <Guid, int>(32);
         int num = 0;
         foreach (Guid key in list)
         {
             dictionary[key] = num++;
         }
         using (BinaryWriter binaryWriter = new BinaryWriter(new BufferedStream(comStorage.CreateStream("__substg1.0_00030102", ComStorage.OpenMode.CreateWrite), 8192)))
         {
             using (BinaryWriter binaryWriter2 = new BinaryWriter(new BufferedStream(comStorage.CreateStream("__substg1.0_00040102", ComStorage.OpenMode.CreateWrite), 8192), new UnicodeEncoding(false, false)))
             {
                 foreach (TnefPropertyId tnefPropertyId in this.idToName.Keys)
                 {
                     bool isString = false;
                     TnefNameIdWrapper tnefNameIdWrapper = this.idToName[tnefPropertyId];
                     int count;
                     if (!dictionary.TryGetValue(tnefNameIdWrapper.PropertySetGuid, out count))
                     {
                         count = list.Count;
                         list.Add(tnefNameIdWrapper.PropertySetGuid);
                         dictionary.Add(tnefNameIdWrapper.PropertySetGuid, count);
                     }
                     int namedId;
                     if (tnefNameIdWrapper.Kind == TnefNameIdKind.Id)
                     {
                         namedId = tnefNameIdWrapper.Id;
                     }
                     else
                     {
                         namedId  = NamedPropertyList.WriteName(binaryWriter2, tnefNameIdWrapper.Name);
                         isString = true;
                     }
                     NamedPropertyList.NamedPropertyEntry namedPropertyEntry = new NamedPropertyList.NamedPropertyEntry(tnefPropertyId, isString, (ushort)count, namedId);
                     namedPropertyEntry.WriteEntry(binaryWriter);
                 }
             }
         }
         using (Stream stream = new BufferedStream(comStorage.CreateStream("__substg1.0_00020102", ComStorage.OpenMode.CreateWrite), 8192))
         {
             for (int i = 3; i < list.Count; i++)
             {
                 byte[] array = list[i].ToByteArray();
                 stream.Write(array, 0, array.Length);
             }
         }
         comStorage.Flush();
     }
 }
        private void Initialize(Encoding messageEncoding)
        {
            this.readBuffers = default(MsgSubStorageReader.ReaderBuffers);
            this.reader      = new MsgStoragePropertyReader(this);
            MsgSubStorageType subStorageType;

            if (this.isTopLevelMessage)
            {
                subStorageType         = MsgSubStorageType.TopLevelMessage;
                this.namedPropertyList = NamedPropertyList.ReadNamedPropertyList(this.messageStorage);
            }
            else
            {
                subStorageType = MsgSubStorageType.AttachedMessage;
            }
            this.subStorageParser = new MsgSubStorageReader(this, this.messageStorage, messageEncoding, subStorageType);
            this.attachmentCount  = this.subStorageParser.AttachmentCount;
            this.recipientCount   = this.subStorageParser.RecipientCount;
            this.encoding         = this.subStorageParser.MessageEncoding;
        }
Beispiel #4
0
        public static NamedPropertyList ReadNamedPropertyList(ComStorage messageStorage)
        {
            ComStorage comStorage = null;

            NamedPropertyList.NamedPropertyEntry[] array = null;
            byte[]            array2            = null;
            List <Guid>       list              = null;
            NamedPropertyList namedPropertyList = new NamedPropertyList();
            NamedPropertyList result;

            try
            {
                try
                {
                    comStorage = messageStorage.OpenStorage("__nameid_version1.0", ComStorage.OpenMode.Read);
                    array      = NamedPropertyList.ReadEntryList(comStorage);
                }
                catch (MsgStorageNotFoundException)
                {
                    namedPropertyList.canModify = false;
                    return(namedPropertyList);
                }
                list = new List <Guid>(32);
                list.AddRange(NamedPropertyList.StandardGuids);
                try
                {
                    NamedPropertyList.ReadGuidList(comStorage, list);
                }
                catch (MsgStorageNotFoundException)
                {
                }
                try
                {
                    array2 = comStorage.ReadFromStreamMaxLength("__substg1.0_00040102", 262144);
                }
                catch (MsgStorageNotFoundException)
                {
                    array2 = Util.EmptyByteArray;
                }
                foreach (NamedPropertyList.NamedPropertyEntry namedPropertyEntry in array)
                {
                    ushort guidIndex = namedPropertyEntry.GuidIndex;
                    if ((int)guidIndex > list.Count)
                    {
                        throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData);
                    }
                    Guid           propertySetGuid = list[(int)guidIndex];
                    TnefPropertyId tnefPropertyId  = namedPropertyEntry.TnefPropertyId;
                    TnefNameId     namedProperty;
                    if (namedPropertyEntry.IsString)
                    {
                        int num = namedPropertyEntry.NamedId;
                        if (num + 4 > array2.Length)
                        {
                            throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData);
                        }
                        int num2 = BitConverter.ToInt32(array2, num);
                        num += 4;
                        if (num + num2 < num || num + num2 > array2.Length)
                        {
                            throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData);
                        }
                        string @string = Util.UnicodeEncoding.GetString(array2, num, num2);
                        namedProperty = new TnefNameId(propertySetGuid, @string);
                    }
                    else
                    {
                        namedProperty = new TnefNameId(propertySetGuid, namedPropertyEntry.NamedId);
                    }
                    if (!namedPropertyList.TryAdd(tnefPropertyId, namedProperty))
                    {
                        throw new MsgStorageException(MsgStorageErrorCode.CorruptNamedPropertyData, MsgStorageStrings.CorruptData);
                    }
                }
                namedPropertyList.canModify = false;
                result = namedPropertyList;
            }
            finally
            {
                if (comStorage != null)
                {
                    comStorage.Dispose();
                }
            }
            return(result);
        }