Esempio n. 1
0
        internal static string GetHeaderParameter(ComplexHeader header, string parameterName, int lengthLimit)
        {
            if (header == null)
            {
                return(null);
            }
            MimeParameter mimeParameter = header[parameterName];

            if (mimeParameter == null)
            {
                return(null);
            }
            string text = null;

            try
            {
                text = mimeParameter.Value;
            }
            catch (InvalidCharsetException)
            {
                StorageGlobals.ContextTraceDebug <string, string>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter::GetHeaderParameter: Header[{0},{1}].Value throws InvalidCharsetException", header.Name, parameterName);
                return(null);
            }
            if (text != null && text.Length > lengthLimit)
            {
                StorageGlobals.ContextTraceDebug <string, string, int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter::GetHeaderParameter: Header[{0},{1}].Value exceeds length limit ({2})", header.Name, parameterName, lengthLimit);
                return(null);
            }
            return(text);
        }
Esempio n. 2
0
        internal static Item OpenAttachedItem(ItemAttachment attachment)
        {
            Item result;

            try
            {
                result = attachment.GetItem(InternalSchema.ContentConversionProperties);
            }
            catch (ObjectNotFoundException arg)
            {
                StorageGlobals.ContextTraceDebug <ObjectNotFoundException>(ExTraceGlobals.CcOutboundGenericTracer, "ConvertUtils::OpenAttachedItem - unable to open embedded message, exc = {0}", arg);
                result = null;
            }
            return(result);
        }
Esempio n. 3
0
        internal static string GetHeaderValue(Header header, int lengthLimit)
        {
            if (header == null)
            {
                return(null);
            }
            string text = null;

            try
            {
                text = header.Value;
            }
            catch (InvalidCharsetException)
            {
                StorageGlobals.ContextTraceDebug <string>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter::GetHeaderValue: Header[{0}].Value throws InvalidCharsetException", header.Name);
                return(null);
            }
            if (text != null && text.Length > lengthLimit)
            {
                StorageGlobals.ContextTraceDebug <string, int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter::GetHeaderValue: Header[{0}].Value exceeds length limit ({1})", header.Name, lengthLimit);
                return(null);
            }
            return(text);
        }
        private void ReadAttribute()
        {
            TnefPropertyTag @null = TnefPropertyTag.Null;

            if (base.CurrentComponentType == ConversionComponentType.FileAttachment)
            {
                TnefAttributeTag attributeTag = this.reader.AttributeTag;
                if (attributeTag <= TnefAttributeTag.AttachModifyDate)
                {
                    if (attributeTag != TnefAttributeTag.AttachTitle)
                    {
                        switch (attributeTag)
                        {
                        case TnefAttributeTag.AttachCreateDate:
                        case TnefAttributeTag.AttachModifyDate:
                            break;

                        default:
                            goto IL_71;
                        }
                    }
                }
                else
                {
                    switch (attributeTag)
                    {
                    case TnefAttributeTag.AttachData:
                    case TnefAttributeTag.AttachMetaFile:
                        break;

                    case (TnefAttributeTag)426000:
                        goto IL_71;

                    default:
                        if (attributeTag != TnefAttributeTag.AttachTransportFilename && attributeTag != TnefAttributeTag.Attachment)
                        {
                            goto IL_71;
                        }
                        break;
                    }
                }
                this.ParseAttachmentProperties();
                goto IL_77;
IL_71:
                this.EndAttachment();
            }
IL_77:
            if (base.CurrentComponentType == ConversionComponentType.Message)
            {
                TnefAttributeTag attributeTag2 = this.reader.AttributeTag;
                if (attributeTag2 <= TnefAttributeTag.RequestResponse)
                {
                    if (attributeTag2 <= TnefAttributeTag.Body)
                    {
                        if (attributeTag2 <= TnefAttributeTag.Subject)
                        {
                            if (attributeTag2 != TnefAttributeTag.From && attributeTag2 != TnefAttributeTag.Subject)
                            {
                                goto IL_211;
                            }
                        }
                        else
                        {
                            switch (attributeTag2)
                            {
                            case TnefAttributeTag.MessageId:
                            case TnefAttributeTag.ParentId:
                            case TnefAttributeTag.ConversationId:
                                break;

                            default:
                                if (attributeTag2 != TnefAttributeTag.Body)
                                {
                                    goto IL_211;
                                }
                                break;
                            }
                        }
                    }
                    else if (attributeTag2 <= TnefAttributeTag.DateReceived)
                    {
                        switch (attributeTag2)
                        {
                        case TnefAttributeTag.DateStart:
                        case TnefAttributeTag.DateEnd:
                            break;

                        default:
                            switch (attributeTag2)
                            {
                            case TnefAttributeTag.DateSent:
                            case TnefAttributeTag.DateReceived:
                                break;

                            default:
                                goto IL_211;
                            }
                            break;
                        }
                    }
                    else if (attributeTag2 != TnefAttributeTag.DateModified && attributeTag2 != TnefAttributeTag.RequestResponse)
                    {
                        goto IL_211;
                    }
                }
                else if (attributeTag2 <= TnefAttributeTag.MessageStatus)
                {
                    if (attributeTag2 <= TnefAttributeTag.AidOwner)
                    {
                        if (attributeTag2 != TnefAttributeTag.Priority && attributeTag2 != TnefAttributeTag.AidOwner)
                        {
                            goto IL_211;
                        }
                    }
                    else
                    {
                        switch (attributeTag2)
                        {
                        case TnefAttributeTag.Owner:
                        case TnefAttributeTag.SentFor:
                        case TnefAttributeTag.Delegate:
                            break;

                        default:
                            if (attributeTag2 != TnefAttributeTag.MessageStatus)
                            {
                                goto IL_211;
                            }
                            this.ParseMapiProperties(true);
                            return;
                        }
                    }
                }
                else if (attributeTag2 <= TnefAttributeTag.OriginalMessageClass)
                {
                    switch (attributeTag2)
                    {
                    case TnefAttributeTag.AttachRenderData:
                        this.StartNewAttachment();
                        this.ParseAttachRenderData();
                        return;

                    case TnefAttributeTag.MapiProperties:
                        break;

                    case TnefAttributeTag.RecipientTable:
                        this.ParseRecipientTable();
                        return;

                    case TnefAttributeTag.Attachment:
                    case (TnefAttributeTag)430086:
                        goto IL_211;

                    case TnefAttributeTag.OemCodepage:
                        base.SetProperty(InternalSchema.Codepage, this.reader.MessageCodepage);
                        return;

                    default:
                        if (attributeTag2 != TnefAttributeTag.OriginalMessageClass)
                        {
                            goto IL_211;
                        }
                        break;
                    }
                }
                else if (attributeTag2 != TnefAttributeTag.MessageClass)
                {
                    if (attributeTag2 != TnefAttributeTag.TnefVersion)
                    {
                        goto IL_211;
                    }
                    return;
                }
                this.ParseMapiProperties(false);
                return;

IL_211:
                StorageGlobals.ContextTraceDebug <uint>(ExTraceGlobals.CcInboundTnefTracer, "Unknown TNEF attribute encountered: 0x{0:X}. Ignoring.", (uint)this.reader.AttributeTag);
            }
        }
Esempio n. 5
0
        public static bool GetOpaqueContent(Stream inputStream, Stream outputStream)
        {
            bool result = false;
            int  num    = 0;

            using (Asn1Reader asn1Reader = new Asn1Reader(inputStream))
            {
                while (asn1Reader.ReadNext() && asn1Reader.EncodingType == EncodingType.Sequence)
                {
                    if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.ObjectIdentifier)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected ContentType=EncodingType.ObjectIdentifier", ++num);
                    }
                    else if (asn1Reader.ReadValueAsOID() != OID.RSASignedData)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected RSA_signedData OID", ++num);
                    }
                    else if (!asn1Reader.ReadNextSibling() || asn1Reader.TagClass != TagClass.Context || asn1Reader.TagNumber != 0)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected content tag", ++num);
                    }
                    else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.Sequence)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected EncodingType.Sequence", ++num);
                    }
                    else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.Integer)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected version number", ++num);
                    }
                    else if (!asn1Reader.ReadNextSibling() || asn1Reader.EncodingType != EncodingType.Set)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected digest algorithm set", ++num);
                    }
                    else if (!asn1Reader.ReadNextSibling() || asn1Reader.EncodingType != EncodingType.Sequence)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected content tag", ++num);
                    }
                    else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.ObjectIdentifier)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected ContentType = EncodingType.ObjectIdentifier for SignedData", ++num);
                    }
                    else if (asn1Reader.ReadValueAsOID() != OID.RSAData)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected RSA_Data OID", ++num);
                    }
                    else if (!asn1Reader.ReadNextSibling())
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find any content in S/MIME blob", ++num);
                    }
                    else if (asn1Reader.TagClass != TagClass.Context || asn1Reader.TagNumber != 0)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected tag class or value for S/MIME blob", ++num);
                    }
                    else if (!asn1Reader.ReadFirstChild() || asn1Reader.EncodingType != EncodingType.OctetString)
                    {
                        StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected EncodingType for S/MIME blob", ++num);
                    }
                    else
                    {
                        BufferPoolCollection.BufferSize bufferSize = BufferPoolCollection.BufferSize.Size20K;
                        BufferPool bufferPool = BufferPoolCollection.AutoCleanupCollection.Acquire(bufferSize);
                        byte[]     array      = null;
                        try
                        {
                            array = bufferPool.Acquire();
                            do
                            {
                                if (!asn1Reader.IsConstructedTag)
                                {
                                    for (;;)
                                    {
                                        int num2 = asn1Reader.ReadBytesValue(array, 0, array.Length);
                                        if (num2 == 0)
                                        {
                                            break;
                                        }
                                        outputStream.Write(array, 0, num2);
                                        result = true;
                                    }
                                }
                                asn1Reader.ReadNext();
                            }while (asn1Reader.EncodingType == EncodingType.OctetString);
                            continue;
                        }
                        finally
                        {
                            if (array != null)
                            {
                                bufferPool.Release(array);
                            }
                        }
                    }
                    return(result);
                }
                StorageGlobals.ContextTraceDebug <int>(ExTraceGlobals.CcInboundMimeTracer, "InboundMimeConverter.GetOpaqueContent ({0}): did not find expected ContentInfo=EncodingType.Sequence", ++num);
            }
            return(result);
        }