Example #1
0
        public async Task <IActionResult> Analyze(string messageId)
        {
            var(mail, uniqueId) = await _mailKitRepository.GetUnreadEmailByIdAsync(messageId).ConfigureAwait(false);

            var receivedHeaders       = mail.Headers.Where(header => header.Field == "Received").ToList();
            var receivedDatesAsString = receivedHeaders.Select(header => header.Value.Split(";")[1].Trim().Substring(0, 31)).ToList();
            var receivedDates         = receivedDatesAsString.Select(date => DateTimeOffset.Parse(date, CultureInfo.CurrentCulture)).OrderBy(date => date).ToList();

            var authorizationResultsHeaders       = mail.Headers.Where(header => header.Field == "Authentication-Results");
            var authorizationResultsHeadersValues = authorizationResultsHeaders.Select(authorizationResultsHeader => authorizationResultsHeader.Value).ToList();

            var senderPolicyFrameworkProtocolsResults    = _informationExtractorService.GetSenderPolicyFrameworkResults(authorizationResultsHeadersValues);
            var domainKeysIdentifiedMailProtocolsResults = _informationExtractorService.GetDomainKeysIdentifiedMailResults(authorizationResultsHeadersValues);
            var domainBasedMessageAuthenticationReportingConformanceProtocolsResults = _informationExtractorService.GetDomainBasedMessageAuthenticationReportingConformanceResults(authorizationResultsHeadersValues);

            // https://developers.virustotal.com/v3.0/reference#file-info see how to analize files
            var attachmentsNames = mail.Attachments.Select(attachment => attachment.ContentDisposition.FileName);
            var fileExtensions   = attachmentsNames.Select(attachmentsName => Path.GetExtension(attachmentsName).ToLower());

            var vector = new int[8];
            var receivedDatesDistance        = _classificationService.CalculateReceivedDateDistance(receivedDates);
            var receivedQuantity             = _classificationService.CalculateReceivedQuantity(receivedHeaders.Count);
            var domainCorrespondsToMessageId = _classificationService.CalculateFromAndMessageIdDomains(messageId, mail.From.Select(from => ((MailboxAddress)from).Address));
            var byAndFromChainMatches        = 0;
            var spfProtocol           = _classificationService.CalculateSenderPolicyFrameworkProtocolAssessment(senderPolicyFrameworkProtocolsResults);
            var dkimProtocol          = _classificationService.CalculateDomainKeysIdentifiedMailProtocolAssessment(domainKeysIdentifiedMailProtocolsResults);
            var dmarkProtocol         = _classificationService.CalculateDomainBasedMessageAuthenticationReportingConformanceProtocolsAssessment(domainBasedMessageAuthenticationReportingConformanceProtocolsResults);
            var attachmentsExtensions = _classificationService.CalculateFileExtensionTypes(fileExtensions);
            var linksNumber           = 0;
            var anchorLinksMatches    = 0;

            return(View());
        }