mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-08 14:19:32 +00:00
Cleaned up EmailParser code
This commit is contained in:
parent
4974955ffa
commit
2103ce95f3
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2019 Basis Technology Corp.
|
* Copyright 2019-2020 Basis Technology Corp.
|
||||||
* Contact: carrier <at> sleuthkit <dot> org
|
* Contact: carrier <at> sleuthkit <dot> org
|
||||||
*
|
*
|
||||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||||
@ -31,7 +31,6 @@ import org.apache.james.mime4j.dom.Entity;
|
|||||||
import org.apache.james.mime4j.dom.Message;
|
import org.apache.james.mime4j.dom.Message;
|
||||||
import org.apache.james.mime4j.dom.MessageWriter;
|
import org.apache.james.mime4j.dom.MessageWriter;
|
||||||
import org.apache.james.mime4j.dom.Multipart;
|
import org.apache.james.mime4j.dom.Multipart;
|
||||||
import org.apache.james.mime4j.dom.SingleBody;
|
|
||||||
import org.apache.james.mime4j.dom.TextBody;
|
import org.apache.james.mime4j.dom.TextBody;
|
||||||
import org.apache.james.mime4j.dom.address.AddressList;
|
import org.apache.james.mime4j.dom.address.AddressList;
|
||||||
import org.apache.james.mime4j.dom.address.Mailbox;
|
import org.apache.james.mime4j.dom.address.Mailbox;
|
||||||
@ -348,8 +347,6 @@ class MimeJ4MessageParser implements AutoCloseable{
|
|||||||
logger.log(Level.WARNING, "Failed to create file output stream for: " + outPath, ex); //NON-NLS
|
logger.log(Level.WARNING, "Failed to create file output stream for: " + outPath, ex); //NON-NLS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -73,6 +73,7 @@ import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments.Fil
|
|||||||
* structure and metadata.
|
* structure and metadata.
|
||||||
*/
|
*/
|
||||||
public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
||||||
|
|
||||||
private static final Logger logger = Logger.getLogger(ThunderbirdMboxFileIngestModule.class.getName());
|
private static final Logger logger = Logger.getLogger(ThunderbirdMboxFileIngestModule.class.getName());
|
||||||
private final IngestServices services = IngestServices.getInstance();
|
private final IngestServices services = IngestServices.getInstance();
|
||||||
private FileManager fileManager;
|
private FileManager fileManager;
|
||||||
@ -113,8 +114,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
//skip unalloc
|
//skip unalloc
|
||||||
if ((abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS)) ||
|
if ((abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.UNALLOC_BLOCKS))
|
||||||
(abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK))) {
|
|| (abstractFile.getType().equals(TskData.TSK_DB_FILES_TYPE_ENUM.SLACK))) {
|
||||||
return ProcessResult.OK;
|
return ProcessResult.OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -375,8 +376,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
int len = in.read(buffer);
|
int len = in.read(buffer);
|
||||||
while (len != -1) {
|
while (len != -1) {
|
||||||
len = in.read(buffer);
|
len = in.read(buffer);
|
||||||
if (buffer[0] == 13 && buffer[1] == 10 && buffer[2] == 70 && buffer[3] == 114 &&
|
if (buffer[0] == 13 && buffer[1] == 10 && buffer[2] == 70 && buffer[3] == 114
|
||||||
buffer[4] == 111 && buffer[5] == 109 && buffer[6] == 32) {
|
&& buffer[4] == 111 && buffer[5] == 109 && buffer[6] == 32) {
|
||||||
mboxSplitOffset.add(in.getCurPosition() - 5);
|
mboxSplitOffset.add(in.getCurPosition() - 5);
|
||||||
in.skip(MBOX_SIZE_TO_SPLIT);
|
in.skip(MBOX_SIZE_TO_SPLIT);
|
||||||
}
|
}
|
||||||
@ -386,7 +387,6 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void processMboxFile(File file, AbstractFile abstractFile, String emailFolder) {
|
private void processMboxFile(File file, AbstractFile abstractFile, String emailFolder) {
|
||||||
|
|
||||||
try (MboxParser emailIterator = MboxParser.getEmailIterator(emailFolder, file, abstractFile.getId())) {
|
try (MboxParser emailIterator = MboxParser.getEmailIterator(emailFolder, file, abstractFile.getId())) {
|
||||||
@ -451,16 +451,9 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
List<AbstractFile> derivedFiles = new ArrayList<>();
|
List<AbstractFile> derivedFiles = new ArrayList<>();
|
||||||
|
|
||||||
AccountFileInstanceCache accountFileInstanceCache = new AccountFileInstanceCache(abstractFile, currentCase);
|
AccountFileInstanceCache accountFileInstanceCache = new AccountFileInstanceCache(abstractFile, currentCase);
|
||||||
// BlackboardArtifact msgArtifact = addEmailArtifact(message, abstractFile, accountFileInstanceCache);
|
|
||||||
|
|
||||||
createEmailArtifact(message, abstractFile, accountFileInstanceCache, derivedFiles);
|
createEmailArtifact(message, abstractFile, accountFileInstanceCache, derivedFiles);
|
||||||
|
|
||||||
accountFileInstanceCache.clear();
|
accountFileInstanceCache.clear();
|
||||||
|
|
||||||
// if ((msgArtifact != null) && (message.hasAttachment())) {
|
|
||||||
// derivedFiles.addAll(handleAttachments(message.getAttachments(), abstractFile, msgArtifact));
|
|
||||||
// }
|
|
||||||
|
|
||||||
if (derivedFiles.isEmpty() == false) {
|
if (derivedFiles.isEmpty() == false) {
|
||||||
for (AbstractFile derived : derivedFiles) {
|
for (AbstractFile derived : derivedFiles) {
|
||||||
services.fireModuleContentEvent(new ModuleContentEvent(derived));
|
services.fireModuleContentEvent(new ModuleContentEvent(derived));
|
||||||
@ -562,18 +555,11 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
if (partialEmailsForThreading.size() > msgCnt) {
|
if (partialEmailsForThreading.size() > msgCnt) {
|
||||||
EmailMessage threaded = partialEmailsForThreading.get(msgCnt++);
|
EmailMessage threaded = partialEmailsForThreading.get(msgCnt++);
|
||||||
|
|
||||||
if(threaded.getMessageID().equals(current.getMessageID()) &&
|
if (threaded.getMessageID().equals(current.getMessageID())
|
||||||
threaded.getSubject().equals(current.getSubject())) {
|
&& threaded.getSubject().equals(current.getSubject())) {
|
||||||
current.setMessageThreadID(threaded.getMessageThreadID());
|
current.setMessageThreadID(threaded.getMessageThreadID());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// BlackboardArtifact msgArtifact = addEmailArtifact(current, abstractFile, accountFileInstanceCache);
|
|
||||||
//
|
|
||||||
// if ((msgArtifact != null) && (current.hasAttachment())) {
|
|
||||||
// derivedFiles.addAll(handleAttachments(current.getAttachments(), abstractFile, msgArtifact ));
|
|
||||||
// }
|
|
||||||
|
|
||||||
createEmailArtifact(current, abstractFile, accountFileInstanceCache, derivedFiles);
|
createEmailArtifact(current, abstractFile, accountFileInstanceCache, derivedFiles);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -648,7 +634,6 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
communicationArtifactsHelper.addAttachments(messageArtifact, new MessageAttachments(fileAttachments, Collections.emptyList()));
|
communicationArtifactsHelper.addAttachments(messageArtifact, new MessageAttachments(fileAttachments, Collections.emptyList()));
|
||||||
} catch (TskCoreException ex) {
|
} catch (TskCoreException ex) {
|
||||||
@ -675,7 +660,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Finds and returns a set of unique email addresses found in the input string
|
* Finds and returns a set of unique email addresses found in the input
|
||||||
|
* string
|
||||||
*
|
*
|
||||||
* @param input - input string, like the To/CC line from an email header
|
* @param input - input string, like the To/CC line from an email header
|
||||||
*
|
*
|
||||||
@ -733,12 +719,10 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
senderAddress = senderAddressList.get(0);
|
senderAddress = senderAddressList.get(0);
|
||||||
try {
|
try {
|
||||||
senderAccountInstance = accountFileInstanceCache.getAccountInstance(senderAddress);
|
senderAccountInstance = accountFileInstanceCache.getAccountInstance(senderAddress);
|
||||||
}
|
} catch (TskCoreException ex) {
|
||||||
catch(TskCoreException ex) {
|
|
||||||
logger.log(Level.WARNING, "Failed to create account for email address " + senderAddress, ex); //NON-NLS
|
logger.log(Level.WARNING, "Failed to create account for email address " + senderAddress, ex); //NON-NLS
|
||||||
}
|
}
|
||||||
}
|
} else {
|
||||||
else {
|
|
||||||
logger.log(Level.WARNING, "Failed to find sender address, from = {0}", from); //NON-NLS
|
logger.log(Level.WARNING, "Failed to find sender address, from = {0}", from); //NON-NLS
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -759,8 +743,7 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
try {
|
try {
|
||||||
AccountFileInstance recipientAccountInstance = accountFileInstanceCache.getAccountInstance(addr);
|
AccountFileInstance recipientAccountInstance = accountFileInstanceCache.getAccountInstance(addr);
|
||||||
recipientAccountInstances.add(recipientAccountInstance);
|
recipientAccountInstances.add(recipientAccountInstance);
|
||||||
}
|
} catch (TskCoreException ex) {
|
||||||
catch(TskCoreException ex) {
|
|
||||||
logger.log(Level.WARNING, "Failed to create account for email address " + addr, ex); //NON-NLS
|
logger.log(Level.WARNING, "Failed to create account for email address " + addr, ex); //NON-NLS
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -786,7 +769,6 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
addArtifactAttribute(rtf, ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_RTF, bbattributes);
|
addArtifactAttribute(rtf, ATTRIBUTE_TYPE.TSK_EMAIL_CONTENT_RTF, bbattributes);
|
||||||
addArtifactAttribute(threadID, ATTRIBUTE_TYPE.TSK_THREAD_ID, bbattributes);
|
addArtifactAttribute(threadID, ATTRIBUTE_TYPE.TSK_THREAD_ID, bbattributes);
|
||||||
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
if (context.fileIngestIsCancelled()) {
|
if (context.fileIngestIsCancelled()) {
|
||||||
return null;
|
return null;
|
||||||
@ -860,17 +842,19 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Cache for storing AccountFileInstance.
|
* Cache for storing AccountFileInstance. The idea is that emails will be
|
||||||
* The idea is that emails will be used multiple times in a file and
|
* used multiple times in a file and we shouldn't do a database lookup each
|
||||||
* we shouldn't do a database lookup each time.
|
* time.
|
||||||
*/
|
*/
|
||||||
static private class AccountFileInstanceCache {
|
static private class AccountFileInstanceCache {
|
||||||
|
|
||||||
private final Map<String, AccountFileInstance> cacheMap;
|
private final Map<String, AccountFileInstance> cacheMap;
|
||||||
private final AbstractFile file;
|
private final AbstractFile file;
|
||||||
private final Case currentCase;
|
private final Case currentCase;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Create a new cache. Caches are linked to a specific file.
|
* Create a new cache. Caches are linked to a specific file.
|
||||||
|
*
|
||||||
* @param file
|
* @param file
|
||||||
* @param currentCase
|
* @param currentCase
|
||||||
*/
|
*/
|
||||||
@ -894,8 +878,8 @@ public final class ThunderbirdMboxFileIngestModule implements FileIngestModule {
|
|||||||
return cacheMap.get(email);
|
return cacheMap.get(email);
|
||||||
}
|
}
|
||||||
|
|
||||||
AccountFileInstance accountInstance =
|
AccountFileInstance accountInstance
|
||||||
currentCase.getSleuthkitCase().getCommunicationsManager().createAccountFileInstance(Account.Type.EMAIL, email,
|
= currentCase.getSleuthkitCase().getCommunicationsManager().createAccountFileInstance(Account.Type.EMAIL, email,
|
||||||
EmailParserModuleFactory.getModuleName(), file);
|
EmailParserModuleFactory.getModuleName(), file);
|
||||||
cacheMap.put(email, accountInstance);
|
cacheMap.put(email, accountInstance);
|
||||||
return accountInstance;
|
return accountInstance;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user