Beispiel #1
0
        public override void Parse(ref IList <MIMER.RFC822.Field> fields, ref string fieldString)
        {
            CompilePattern();

            DecoratedFieldParser.Parse(ref fields, ref fieldString);

            foreach (RFC822.Field field in fields)
            {
                if (m_EncodedWordPattern.RegularExpression.IsMatch(field.Body))
                {
                    string charset  = m_CharsetPattern.RegularExpression.Match(field.Body).Value;
                    string text     = m_EncodedTextPattern.RegularExpression.Match(field.Body).Value;
                    string encoding = m_EncodingPattern.RegularExpression.Match(field.Body).Value;

                    Encoding enc = Encoding.GetEncoding(charset);

                    byte[] bytes;

                    if (m_QPDecoder.CanDecode(encoding))
                    {
                        bytes = m_QPDecoder.Decode(ref text, charset);
                    }
                    else
                    {
                        bytes = m_B64decoder.Decode(ref text);
                    }
                    text = enc.GetString(bytes);

                    field.Body = Regex.Replace(field.Body,
                                               m_EncodedWordPattern.TextPattern, text);
                    field.Body = field.Body.Replace('_', ' ');
                }
            }
        }
Beispiel #2
0
        public override void Parse(ref IList <RFC822.Field> fields, ref string fieldString)
        {
            if (!IsCompiled())
            {
                CompilePattern();
            }

            if (fields.Count == 0)
            {
                base.Parse(ref fields, ref fieldString);
            }

            foreach (RFC822.Field field in fields)
            {
                if (m_EncodedWord.IsMatch(field.Body))
                {
                    string charset  = m_Charset.Match(field.Body).Value;
                    string text     = m_EncodedText.Match(field.Body).Value;
                    string encoding = m_Encoding.Match(field.Body).Value;

                    Encoding enc = Encoding.GetEncoding(charset);
                    byte[]   bar = enc.GetBytes(text);
                    bar  = Encoding.Convert(enc, m_TargetEncoding, bar);
                    text = m_TargetEncoding.GetString(bar);

                    if (encoding.ToLower().Equals("q"))
                    {
                        text = m_QPDecoder.DecodeToString(ref text);
                    }
                    else
                    {
                        bar  = m_B64decoder.Decode(ref text);
                        text = m_TargetEncoding.GetString(bar);
                    }

                    field.Body = Regex.Replace(field.Body,
                                               m_EncodedWordPattern, text);
                    field.Body = field.Body.Replace('_', ' ');
                }
            }
        }