Example #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);
        }
Example #2
0
        internal static MimePart CreateBodyPart(string type, string charsetName)
        {
            MimePart          mimePart          = new MimePart();
            ContentTypeHeader contentTypeHeader = new ContentTypeHeader(type);
            MimeParameter     newChild          = new MimeParameter("charset", charsetName);

            contentTypeHeader.AppendChild(newChild);
            mimePart.Headers.AppendChild(contentTypeHeader);
            return(mimePart);
        }
Example #3
0
        internal static string GetParameterValue(ComplexHeader header, string parameterName)
        {
            string        result        = null;
            MimeParameter mimeParameter = header[parameterName];

            if (mimeParameter != null)
            {
                DecodingResults decodingResults;
                mimeParameter.TryGetValue(Utility.DecodeOrFallBack, out decodingResults, out result);
                return(result);
            }
            return(result);
        }
Example #4
0
        internal void WriteHeaderParameter(string parameterName, string parameterValue)
        {
            if (this.hasAllHeaders)
            {
                return;
            }
            ComplexHeader complexHeader = (ComplexHeader)this.currentHeader;
            MimeParameter mimeParameter = complexHeader[parameterName];

            if (mimeParameter == null)
            {
                mimeParameter = new MimeParameter(parameterName);
                complexHeader.AppendChild(mimeParameter);
            }
            mimeParameter.Value = parameterValue;
        }
Example #5
0
        internal static void StoreFileNameInHeader(MimePart attachmentPart, HeaderId headerId, GetDefaultValue getDefaultValue, string parameterName, string value)
        {
            ComplexHeader complexHeader = attachmentPart.Headers.FindFirst(headerId) as ComplexHeader;

            if (complexHeader == null)
            {
                complexHeader       = (Header.Create(headerId) as ComplexHeader);
                complexHeader.Value = getDefaultValue();
                attachmentPart.Headers.AppendChild(complexHeader);
            }
            MimeParameter mimeParameter = complexHeader[parameterName];

            if (mimeParameter == null)
            {
                mimeParameter = new MimeParameter(parameterName);
                complexHeader.AppendChild(mimeParameter);
            }
            mimeParameter.Value = value;
        }
Example #6
0
        internal static Charset GetCharsetFromMime(MimePart part)
        {
            Charset result = Charset.ASCII;
            Header  header = part.Headers.FindFirst(HeaderId.ContentType);

            if (header != null)
            {
                MimeParameter mimeParameter = (header as ComplexHeader)["charset"];
                if (mimeParameter != null)
                {
                    Charset charset = null;
                    if (Charset.TryGetCharset(mimeParameter.Value, out charset))
                    {
                        result = charset;
                    }
                }
            }
            return(result);
        }
Example #7
0
        internal static void SetParameterValue(MimePart part, HeaderId headerId, string parameterName, string value)
        {
            ComplexHeader complexHeader = part.Headers.FindFirst(headerId) as ComplexHeader;

            if (complexHeader == null)
            {
                complexHeader = (Header.Create(headerId) as ComplexHeader);
                complexHeader.AppendChild(new MimeParameter(parameterName, value));
                part.Headers.AppendChild(complexHeader);
                return;
            }
            MimeParameter mimeParameter = complexHeader[parameterName];

            if (mimeParameter != null)
            {
                mimeParameter.Value = value;
                return;
            }
            complexHeader.AppendChild(new MimeParameter(parameterName, value));
        }