public bool TryParse(string record, string domain, out DmarcRecord dmarcRecord) { if (string.IsNullOrEmpty(record)) { dmarcRecord = null; return(false); } string[] stringTags = record.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries).Select(_ => _.Trim()).ToArray(); List <Tag> tags = _tagParser.Parse(stringTags.ToList()); tags = tags.Concat(_implicitProvider.GetImplicitValues(tags)).ToList(); foreach (Tag tag in tags) { string explanation; if (_explainer.TryExplain(tag, out explanation)) { tag.Explanation = explanation; } } dmarcRecord = new DmarcRecord(record, tags, domain); dmarcRecord.AddErrors(_ruleEvaluator.Evaluate(dmarcRecord)); return(true); }
public async Task <SpfRecord> Parse(string domain, List <string> spfRecordParts) { string record = string.Join(string.Empty, spfRecordParts); if (string.IsNullOrEmpty(record)) { return(null); } string[] stringTokens = record.Split(Separator, StringSplitOptions.RemoveEmptyEntries); string versionToken = stringTokens.ElementAtOrDefault(0); Domain.Version version = _versionParser.Parse(versionToken); List <Term> terms = stringTokens.Skip(1).Select(_termParser.Parse).ToList(); terms = terms.Concat(_implicitTermProvider.GetImplicitValues(terms)).ToList(); SpfRecord spfRecord = new SpfRecord(spfRecordParts, version, terms); EvaluationResult <DomainSpfRecord> result = await _spfRecordRulesEvaluator.Evaluate(new DomainSpfRecord(domain, spfRecord)); spfRecord.AddErrors(result.Errors); return(spfRecord); }
public DkimRecord Parse(DnsRecord record) { string[] stringTags = record.Record.Split(Separator, StringSplitOptions.RemoveEmptyEntries) .Select(_ => _.Trim()) .ToArray(); EvaluationResult <List <Tag> > evaluatedTags = _tagParser.Parse(stringTags.ToList()); List <Tag> implicitTags = _implicitProvider.GetImplicitValues(evaluatedTags.Item); DkimRecord dkimRecord = new DkimRecord(record, evaluatedTags.Item.Concat(implicitTags).ToList(), evaluatedTags.Errors); if (evaluatedTags.Errors != null && evaluatedTags.Errors.All(x => x.ErrorType != EvaluationErrorType.Error)) { EvaluationResult <DkimRecord> evaluationResult = _ruleEvaluator.Evaluate(dkimRecord).Result; dkimRecord.Errors.AddRange(evaluationResult.Errors); } return(dkimRecord); }
public SpfRecord Parse(string record, string domain) { if (string.IsNullOrEmpty(record)) { return(null); } string[] stringTokens = record.Split(new[] { Separator }, StringSplitOptions.RemoveEmptyEntries); string versionToken = stringTokens.ElementAtOrDefault(0); Domain.Version version = _versionParser.Parse(versionToken); string explanation; if (_versionExplainer.TryExplain(version, out explanation)) { version.Explanation = explanation; } List <Term> terms = stringTokens.Skip(1).Select(_termParser.Parse).ToList(); terms = terms.Concat(_implicitTermProvider.GetImplicitValues(terms)).ToList(); foreach (Term term in terms) { if (_termExplainer.TryExplain(term, out explanation)) { term.Explanation = explanation; } } SpfRecord spfRecord = new SpfRecord(record, version, terms, domain); spfRecord.AddErrors(_spfRecordRulesEvaluator.Evaluate(spfRecord)); return(spfRecord); }