mirror of
https://github.com/overcuriousity/autopsy-flatpak.git
synced 2025-07-18 18:47:43 +00:00
cleanup and refactoring in MessageContentViewer
This commit is contained in:
parent
a292bb83d2
commit
d981789c3b
@ -1,7 +1,7 @@
|
|||||||
/*
|
/*
|
||||||
* Autopsy Forensic Browser
|
* Autopsy Forensic Browser
|
||||||
*
|
*
|
||||||
* Copyright 2011-2017 Basis Technology Corp.
|
* Copyright 2017 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");
|
||||||
@ -75,6 +75,7 @@ public class MessageContentViewer extends javax.swing.JPanel implements DataCont
|
|||||||
|
|
||||||
private static final long serialVersionUID = 1L;
|
private static final long serialVersionUID = 1L;
|
||||||
private static final Logger LOGGER = Logger.getLogger(MessageContentViewer.class.getName());
|
private static final Logger LOGGER = Logger.getLogger(MessageContentViewer.class.getName());
|
||||||
|
private static final BlackboardAttribute.Type TSK_ASSOCIATED_TYPE = new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT);
|
||||||
|
|
||||||
private static final int HDR_TAB_INDEX = 0;
|
private static final int HDR_TAB_INDEX = 0;
|
||||||
private static final int TEXT_TAB_INDEX = 1;
|
private static final int TEXT_TAB_INDEX = 1;
|
||||||
@ -94,9 +95,10 @@ public class MessageContentViewer extends javax.swing.JPanel implements DataCont
|
|||||||
/**
|
/**
|
||||||
* Creates new MessageContentViewer
|
* Creates new MessageContentViewer
|
||||||
*/
|
*/
|
||||||
|
@NbBundle.Messages("MessageContentViewer.AtrachmentsPanel.title=Attachments")
|
||||||
public MessageContentViewer() {
|
public MessageContentViewer() {
|
||||||
initComponents();
|
initComponents();
|
||||||
drp = DataResultPanel.createInstanceUninitialized("Attachments", "", Node.EMPTY, 0, null);
|
drp = DataResultPanel.createInstanceUninitialized(Bundle.MessageContentViewer_AtrachmentsPanel_title(), "", Node.EMPTY, 0, null);
|
||||||
attachmentsScrollPane.setViewportView(drp);
|
attachmentsScrollPane.setViewportView(drp);
|
||||||
msgbodyTabbedPane.setEnabledAt(ATTM_TAB_INDEX, true);
|
msgbodyTabbedPane.setEnabledAt(ATTM_TAB_INDEX, true);
|
||||||
|
|
||||||
@ -408,17 +410,20 @@ public class MessageContentViewer extends javax.swing.JPanel implements DataCont
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* If the artifact is a keyword hit, use the associated artifact as the
|
||||||
|
* one to show in this viewer
|
||||||
|
*/
|
||||||
if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
|
if (artifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
|
||||||
try {
|
try {
|
||||||
BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT));
|
getAssociatedArtifact(artifact).ifPresent(associatedArtifact -> {
|
||||||
if (attribute != null) {
|
artifact = associatedArtifact;
|
||||||
final long associatedArtifactID = attribute.getValueLong();
|
});
|
||||||
artifact = artifact.getSleuthkitCase().getArtifactByArtifactId(associatedArtifactID);
|
|
||||||
}
|
|
||||||
} catch (TskCoreException ex) {
|
} catch (TskCoreException ex) {
|
||||||
LOGGER.log(Level.SEVERE, "error getting associated artifact", ex);
|
LOGGER.log(Level.SEVERE, "error getting associated artifact", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (artifact.getArtifactTypeID() == TSK_MESSAGE.getTypeID()) {
|
if (artifact.getArtifactTypeID() == TSK_MESSAGE.getTypeID()) {
|
||||||
displayMsg();
|
displayMsg();
|
||||||
} else if (artifact.getArtifactTypeID() == TSK_EMAIL_MSG.getTypeID()) {
|
} else if (artifact.getArtifactTypeID() == TSK_EMAIL_MSG.getTypeID()) {
|
||||||
@ -428,6 +433,24 @@ public class MessageContentViewer extends javax.swing.JPanel implements DataCont
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Get the artifact associated with the given artifact, if there is one.
|
||||||
|
*
|
||||||
|
* @param artifact The artifact to get the associated artifact from. Must
|
||||||
|
* not be null
|
||||||
|
*
|
||||||
|
* @throws TskCoreException If there is a critical error querying the DB.
|
||||||
|
* @return An optional containing the artifact associated with the given
|
||||||
|
* artifact, if there is one.
|
||||||
|
*/
|
||||||
|
private static Optional<BlackboardArtifact> getAssociatedArtifact(final BlackboardArtifact artifact) throws TskCoreException {
|
||||||
|
BlackboardAttribute attribute = artifact.getAttribute(TSK_ASSOCIATED_TYPE);
|
||||||
|
if (attribute != null) {
|
||||||
|
return Optional.of(artifact.getSleuthkitCase().getArtifactByArtifactId(attribute.getValueLong()));
|
||||||
|
}
|
||||||
|
return Optional.empty();
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@NbBundle.Messages("MessageContentViewer.title=Message")
|
@NbBundle.Messages("MessageContentViewer.title=Message")
|
||||||
public String getTitle() {
|
public String getTitle() {
|
||||||
@ -477,25 +500,36 @@ public class MessageContentViewer extends javax.swing.JPanel implements DataCont
|
|||||||
@Override
|
@Override
|
||||||
public boolean isSupported(Node node) {
|
public boolean isSupported(Node node) {
|
||||||
BlackboardArtifact nodeArtifact = node.getLookup().lookup(BlackboardArtifact.class);
|
BlackboardArtifact nodeArtifact = node.getLookup().lookup(BlackboardArtifact.class);
|
||||||
if (nodeArtifact != null && nodeArtifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
|
|
||||||
try {
|
if (nodeArtifact == null) {
|
||||||
BlackboardAttribute attribute = nodeArtifact.getAttribute(new BlackboardAttribute.Type(TSK_ASSOCIATED_ARTIFACT));
|
return false;
|
||||||
if (attribute != null) {
|
|
||||||
final long associatedArtifactID = attribute.getValueLong();
|
|
||||||
BlackboardArtifact assoc = nodeArtifact.getSleuthkitCase().getArtifactByArtifactId(associatedArtifactID);
|
|
||||||
if ((assoc != null)
|
|
||||||
&& ((assoc.getArtifactTypeID() == TSK_EMAIL_MSG.getTypeID())
|
|
||||||
|| (assoc.getArtifactTypeID() == TSK_MESSAGE.getTypeID()))) {
|
|
||||||
return true;
|
|
||||||
}
|
}
|
||||||
|
//if the artifact is a keyword hit, check if its associated artifact is a message or email.
|
||||||
|
if (nodeArtifact.getArtifactTypeID() == TSK_KEYWORD_HIT.getTypeID()) {
|
||||||
|
try {
|
||||||
|
if (getAssociatedArtifact(nodeArtifact).map(MessageContentViewer::isMessageArtifact).orElse(false)) {
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
} catch (TskCoreException ex) {
|
} catch (TskCoreException ex) {
|
||||||
LOGGER.log(Level.SEVERE, "error getting associated artifact", ex);
|
LOGGER.log(Level.SEVERE, "error getting associated artifact", ex);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return ((nodeArtifact != null)
|
return isMessageArtifact(nodeArtifact);
|
||||||
&& ((nodeArtifact.getArtifactTypeID() == TSK_EMAIL_MSG.getTypeID())
|
}
|
||||||
|| (nodeArtifact.getArtifactTypeID() == TSK_MESSAGE.getTypeID())));
|
|
||||||
|
/**
|
||||||
|
* Is the given artifact one that can be shown in this viewer?
|
||||||
|
*
|
||||||
|
* @param nodeArtifact An artifact that might be a message. Must not be
|
||||||
|
* null.
|
||||||
|
*
|
||||||
|
* @return True if the given artifact can be shown as a message in this
|
||||||
|
* viewer.
|
||||||
|
*/
|
||||||
|
private static boolean isMessageArtifact(BlackboardArtifact nodeArtifact) {
|
||||||
|
final int artifactTypeID = nodeArtifact.getArtifactTypeID();
|
||||||
|
return artifactTypeID == TSK_EMAIL_MSG.getTypeID()
|
||||||
|
|| artifactTypeID == TSK_MESSAGE.getTypeID();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
Loading…
x
Reference in New Issue
Block a user