Beispiel #1
0
        private void AddFragment(FragmentDTO fragment)
        {
            if (fragment.IsQuoted || fragment.IsSignature || IsEmpty(fragment))
            {
                fragment.IsHidden = true;
            }

            fragments.Add(fragment);
        }
Beispiel #2
0
        private Email ParseImpl(string text)
        {
            text = RegexLinefeedWithCarriage.Replace(text, "\n");

            text = quoteHeadersRegex.Aggregate(text, (sourceText, regex) =>
            {
                var matches = regex.Match(sourceText);

                if (matches.Success)
                {
                    var replaceBy = matches.Groups[1].Value.Replace("\n", " ");
                    sourceText    = sourceText.Replace(matches.Groups[1].Value, replaceBy);
                }

                return(sourceText);
            });

            FragmentDTO fragment = null;

            foreach (var newLine in StringReverse(text).Split(new[] { "\n" }, StringSplitOptions.None))
            {
                var line = StringRTrim(newLine, '\n');

                if (!IsSignature(line))
                {
                    line = StringLTrim(line);
                }

                if (fragment != null)
                {
                    var last = fragment.Lines[fragment.Lines.Count - 1];
                    if (IsSignature(last))
                    {
                        fragment.IsSignature = true;
                        AddFragment(fragment);
                        fragment = null;
                    }
                    else if (line == "" && IsQuoteHeader(last))
                    {
                        fragment.IsQuoted = true;
                        AddFragment(fragment);
                        fragment = null;
                    }
                }

                var isQuoted = IsQuote(line);

                if (fragment == null || !IsFragmentLine(fragment, line, isQuoted))
                {
                    if (fragment != null)
                    {
                        AddFragment(fragment);
                    }

                    fragment = new FragmentDTO {
                        IsQuoted = isQuoted
                    };
                }

                fragment.Lines.Add(line);
            }

            if (fragment != null)
            {
                AddFragment(fragment);
            }

            var email = CreateEmail(fragments);

            return(email);
        }
Beispiel #3
0
 private bool IsFragmentLine(FragmentDTO fragment, string line, bool isQuoted)
 {
     return(fragment.IsQuoted == isQuoted ||
            fragment.IsQuoted && (IsQuoteHeader(line) || line == ""));
 }
Beispiel #4
0
 private static bool IsEmpty(FragmentDTO fragment)
 {
     return("".Equals(string.Join("", fragment.Lines), StringComparison.Ordinal));
 }