Exemplo n.º 1
0
        internal MsgStorageWriter OpenAttachedMessageWriter()
        {
            if (this.attachMethod != 5)
            {
                throw new InvalidOperationException(MsgStorageStrings.NotAMessageAttachment);
            }
            ComStorage       comStorage       = null;
            MsgStorageWriter msgStorageWriter = null;

            try
            {
                TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj;
                string          storageName   = Util.PropertyStreamName(attachDataObj);
                MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Message);
                comStorage = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite);
                comStorage.StorageClass = Util.ClassIdMessageAttachment;
                msgStorageWriter        = new MsgStorageWriter(this.owner, comStorage);
            }
            finally
            {
                if (msgStorageWriter == null && comStorage != null)
                {
                    comStorage.Dispose();
                }
            }
            return(msgStorageWriter);
        }
Exemplo n.º 2
0
        internal Stream OpenOleAttachmentStream()
        {
            if (this.attachMethod != 6)
            {
                throw new InvalidOperationException(MsgStorageStrings.NotAnOleAttachment);
            }
            Stream cacheStream = Streams.CreateTemporaryStorageStream();
            MsgStorageWriteStream msgStorageWriteStream = new MsgStorageWriteStream(cacheStream, 0);

            msgStorageWriteStream.AddOnCloseNotifier(delegate(MsgStorageWriteStream stream, Exception onCloseException)
            {
                if (onCloseException != null)
                {
                    this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.ComExceptionThrown, onCloseException));
                    return;
                }
                TnefPropertyTag attachDataObj = TnefPropertyTag.AttachDataObj;
                ComStorage comStorage         = null;
                ComStorage comStorage2        = null;
                string storageName            = Util.PropertyStreamName(attachDataObj);
                try
                {
                    cacheStream.Flush();
                    cacheStream.Position     = 0L;
                    comStorage               = ComStorage.OpenStorageOnStream(cacheStream, ComStorage.OpenMode.Read);
                    comStorage2              = this.subStorage.CreateStorage(storageName, ComStorage.OpenMode.CreateWrite);
                    comStorage2.StorageClass = Util.ClassIdFileAttachment;
                    ComStorage.CopyStorageContent(comStorage, comStorage2);
                    comStorage2.Flush();
                    MsgStoragePropertyData.WriteObject(this.propertiesWriter, attachDataObj, MsgStoragePropertyData.ObjectType.Storage);
                }
                catch (IOException exc)
                {
                    this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc));
                }
                catch (COMException exc2)
                {
                    this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc2));
                }
                finally
                {
                    if (comStorage2 != null)
                    {
                        comStorage2.Dispose();
                    }
                    if (comStorage != null)
                    {
                        comStorage.Dispose();
                    }
                    if (cacheStream != null)
                    {
                        cacheStream.Dispose();
                    }
                }
            });
            return(msgStorageWriteStream);
        }
        private static void WriteDouble(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            double?num = value as double?;

            if (num == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(double), value.GetType()));
            }
            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, num.Value);
        }
 private static void WriteBinary(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
 {
     byte[] array = value as byte[];
     if (array == null)
     {
         throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(byte[]), value.GetType()));
     }
     writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array);
     MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, array.Length);
 }
        private static void InternalWriteString(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, string value)
        {
            MsgSubStorageWriter.WriterBuffer valueBuffer = writer.ValueBuffer;
            int unicodeByteCount = Util.GetUnicodeByteCount(value);

            byte[] array = valueBuffer.PreallocateBuffer(unicodeByteCount);
            int    num   = Util.StringToUnicodeBytes(value, array);

            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array, num);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, num);
        }
        private static void WriteGuid(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            Guid?guid = value as Guid?;

            if (guid == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(Guid), value.GetType()));
            }
            byte[] array = guid.Value.ToByteArray();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), array);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, array.Length);
        }
        private static void WriteBoolean(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            bool?flag = value as bool?;

            if (flag == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(bool), value.GetType()));
            }
            short propertyValue = flag.Value ? 1 : 0;

            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, propertyValue);
        }
        private static void WriteArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, int arrayLength, MsgStorageRulesTable.WriteValueDelegate writeValue)
        {
            MsgSubStorageWriter.WriterBuffer valueBuffer = writer.ValueBuffer;
            for (int num = 0; num != arrayLength; num++)
            {
                writeValue(valueBuffer.Writer, num);
            }
            int length = valueBuffer.GetLength();

            byte[] buffer = valueBuffer.GetBuffer();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), buffer, length);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, length);
        }
        private static object ReadSysTime(byte[] data, int propertyOffset)
        {
            long   fileTime = MsgStoragePropertyData.ReadValueAsInt64(data, propertyOffset);
            object result;

            try
            {
                result = DateTime.FromFileTimeUtc(fileTime);
            }
            catch (ArgumentOutOfRangeException)
            {
                result = DateTime.MinValue;
            }
            return(result);
        }
Exemplo n.º 10
0
        internal Stream OpenPropertyStream(TnefPropertyTag propertyTag)
        {
            int num = this.prefix.Size;

            while (num + 16 <= this.propertiesContent.Length)
            {
                TnefPropertyTag propertyTag2 = MsgStoragePropertyData.ReadPropertyTag(this.propertiesContent, num);
                if (propertyTag2.ToUnicode() == propertyTag)
                {
                    return(this.InternalOpenPropertyStream(propertyTag2));
                }
                num += 16;
            }
            throw new InvalidOperationException(MsgStorageStrings.PropertyNotFound(propertyTag));
        }
Exemplo n.º 11
0
        private static void InternalWriteStringArray(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, string[] arrayValue)
        {
            MsgSubStorageWriter.WriterBuffer lengthsBuffer = writer.LengthsBuffer;
            for (int num = 0; num != arrayValue.Length; num++)
            {
                MsgSubStorageWriter.WriterBuffer valueBuffer = writer.ValueBuffer;
                int    unicodeByteCount = Util.GetUnicodeByteCount(arrayValue[num]);
                byte[] array            = valueBuffer.PreallocateBuffer(unicodeByteCount);
                int    num2             = Util.StringToUnicodeBytes(arrayValue[num], array);
                lengthsBuffer.Writer.Write(num2);
                writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag, num), array, num2);
            }
            int length = lengthsBuffer.GetLength();

            byte[] buffer = lengthsBuffer.GetBuffer();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), buffer, length);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, length);
        }
Exemplo n.º 12
0
        private void ReadCurrentProperty()
        {
            TnefPropertyTag            tnefPropertyTag = MsgStoragePropertyData.ReadPropertyTag(this.propertiesContent, this.currentOffset);
            int                        propertyLength  = 0;
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule;

            if (!MsgStorageRulesTable.TryFindRule(tnefPropertyTag, out msgStoragePropertyTypeRule))
            {
                throw new MsgStorageException(MsgStorageErrorCode.InvalidPropertyType, MsgStorageStrings.CorruptData);
            }
            if (!msgStoragePropertyTypeRule.IsFixedValue)
            {
                propertyLength = MsgStoragePropertyData.ReadPropertyByteCount(this.propertiesContent, this.currentOffset);
            }
            this.currentProperty                = default(MsgSubStorageReader.PropertyInfo);
            this.currentProperty.Tag            = tnefPropertyTag;
            this.currentProperty.Rule           = msgStoragePropertyTypeRule;
            this.currentProperty.PropertyLength = propertyLength;
        }
Exemplo n.º 13
0
        private static void WriteArrayOfBinary(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            byte[][] array = value as byte[][];
            if (array == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(byte[][]), value.GetType()));
            }
            MsgSubStorageWriter.WriterBuffer lengthsBuffer = writer.LengthsBuffer;
            for (int num = 0; num != array.Length; num++)
            {
                lengthsBuffer.Writer.Write(array[num].Length);
                lengthsBuffer.Writer.Write(0);
                writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag, num), array[num]);
            }
            int length = lengthsBuffer.GetLength();

            byte[] buffer = lengthsBuffer.GetBuffer();
            writer.Storage.WriteBytesToStream(Util.PropertyStreamName(propertyTag), buffer, length);
            MsgStoragePropertyData.WriteStream(writer.PropertiesWriter, propertyTag, length);
        }
Exemplo n.º 14
0
        private static void WriteSysTime(MsgSubStorageWriter writer, TnefPropertyTag propertyTag, object value)
        {
            DateTime?dateTime = value as DateTime?;

            if (dateTime == null)
            {
                throw new InvalidOperationException(MsgStorageStrings.InvalidValueType(typeof(DateTime), value.GetType()));
            }
            long propertyValue = 0L;

            try
            {
                propertyValue = dateTime.Value.ToFileTimeUtc();
            }
            catch (ArgumentOutOfRangeException)
            {
                propertyValue = 0L;
            }
            MsgStoragePropertyData.WriteProperty(writer.PropertiesWriter, propertyTag, propertyValue);
        }
Exemplo n.º 15
0
        internal Stream OpenPropertyStream(TnefPropertyTag propertyTag)
        {
            if (this.subStorageType == MsgSubStorageType.Recipient)
            {
                throw new InvalidOperationException(MsgStorageStrings.RecipientPropertiesNotStreamable);
            }
            MsgStoragePropertyTypeRule msgStoragePropertyTypeRule;

            MsgStorageRulesTable.TryFindRule(propertyTag, out msgStoragePropertyTypeRule);
            if (!msgStoragePropertyTypeRule.CanOpenStream)
            {
                throw new InvalidOperationException(MsgStorageStrings.NonStreamableProperty);
            }
            Stream stream3 = null;
            Stream stream2 = null;

            try
            {
                int addStringTerminators = 0;
                if (propertyTag.TnefType == TnefPropertyType.Unicode)
                {
                    addStringTerminators = 2;
                }
                else if (propertyTag.TnefType == TnefPropertyType.String8)
                {
                    addStringTerminators = 1;
                }
                string streamName = Util.PropertyStreamName(propertyTag);
                stream3 = this.subStorage.CreateStream(streamName, ComStorage.OpenMode.CreateWrite);
                MsgStorageWriteStream msgStorageWriteStream = new MsgStorageWriteStream(stream3, addStringTerminators);
                stream3 = msgStorageWriteStream;
                stream3 = new BufferedStream(msgStorageWriteStream, 32768);
                msgStorageWriteStream.AddOnCloseNotifier(delegate(MsgStorageWriteStream stream, Exception onCloseException)
                {
                    if (onCloseException != null)
                    {
                        this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWrite, MsgStorageStrings.ComExceptionThrown, onCloseException));
                        return;
                    }
                    try
                    {
                        MsgStoragePropertyData.WriteStream(this.propertiesWriter, propertyTag, (int)stream.Length);
                    }
                    catch (IOException exc)
                    {
                        this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc));
                    }
                    catch (COMException exc2)
                    {
                        this.owner.SetFailure(new MsgStorageException(MsgStorageErrorCode.FailedWriteOle, MsgStorageStrings.CorruptData, exc2));
                    }
                });
                stream2 = stream3;
            }
            finally
            {
                if (stream2 == null && stream3 != null)
                {
                    stream3.Dispose();
                }
            }
            return(stream2);
        }
Exemplo n.º 16
0
 private static object ReadDouble(byte[] data, int propertyOffset)
 {
     return(MsgStoragePropertyData.ReadValueAsDouble(data, propertyOffset));
 }
Exemplo n.º 17
0
        private static object ReadBoolean(byte[] data, int propertyOffset)
        {
            short num = MsgStoragePropertyData.ReadValueAsInt16(data, propertyOffset);

            return(num != 0);
        }