19 package org.sleuthkit.autopsy.communications.relationships;
21 import com.google.gson.Gson;
22 import java.util.logging.Level;
23 import javax.swing.Action;
24 import org.apache.commons.lang3.StringUtils;
25 import org.openide.nodes.Sheet;
26 import org.openide.util.NbBundle.Messages;
30 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME;
31 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT;
32 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM;
33 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO;
34 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM;
35 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO;
36 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT;
40 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG;
41 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE;
43 import org.
sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
48 class MessageNode
extends BlackboardArtifactNode {
50 public static final String UNTHREADED_ID =
"<UNTHREADED>";
52 private static final Logger logger = Logger.getLogger(MessageNode.class.getName());
54 private final String threadID;
56 private final Action preferredAction;
58 MessageNode(BlackboardArtifact artifact, String threadID, Action preferredAction) {
61 this.preferredAction = preferredAction;
63 final String stripEnd = StringUtils.stripEnd(artifact.getDisplayName(),
"s");
64 String removeEndIgnoreCase = StringUtils.removeEndIgnoreCase(stripEnd,
"message");
65 setDisplayName(removeEndIgnoreCase.isEmpty() ? stripEnd : removeEndIgnoreCase);
67 this.threadID = threadID;
71 "MessageNode_Node_Property_Type=Type",
72 "MessageNode_Node_Property_From=From",
73 "MessageNode_Node_Property_To=To",
74 "MessageNode_Node_Property_Date=Date",
75 "MessageNode_Node_Property_Subject=Subject",
76 "MessageNode_Node_Property_Attms=Attachments"
80 protected Sheet createSheet() {
81 Sheet sheet = super.createSheet();
82 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
83 if (sheetSet == null) {
84 sheetSet = Sheet.createPropertiesSet();
88 sheetSet.put(
new NodeProperty<>(
"Type", Bundle.MessageNode_Node_Property_Type(),
"", getDisplayName()));
91 BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
94 (fromID != TSK_EMAIL_MSG &&
95 fromID != TSK_MESSAGE)) {
99 sheetSet.put(
new NodeProperty<>(
"ThreadID",
"ThreadID",
"",threadID == null ? UNTHREADED_ID : threadID));
100 sheetSet.put(
new NodeProperty<>(
"Subject", Bundle.MessageNode_Node_Property_Subject(),
"",
101 getAttributeDisplayString(artifact, TSK_SUBJECT)));
103 sheetSet.put(
new NodeProperty<>(
"Attms", Bundle.MessageNode_Node_Property_Attms(),
"", getAttachmentsCount()));
104 }
catch (TskCoreException ex) {
105 logger.log(Level.WARNING,
"Error loading attachment count for " + artifact, ex);
110 sheetSet.put(
new NodeProperty<>(
"From", Bundle.MessageNode_Node_Property_From(),
"",
111 StringUtils.strip(getAttributeDisplayString(artifact, TSK_EMAIL_FROM),
" \t\n;")));
112 sheetSet.put(
new NodeProperty<>(
"To", Bundle.MessageNode_Node_Property_To(),
"",
113 StringUtils.strip(getAttributeDisplayString(artifact, TSK_EMAIL_TO),
" \t\n;")));
114 sheetSet.put(
new NodeProperty<>(
"Date", Bundle.MessageNode_Node_Property_Date(),
"",
115 getAttributeDisplayString(artifact, TSK_DATETIME_SENT)));
118 sheetSet.put(
new NodeProperty<>(
"From", Bundle.MessageNode_Node_Property_From(),
"",
119 getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM)));
120 sheetSet.put(
new NodeProperty<>(
"To", Bundle.MessageNode_Node_Property_To(),
"",
121 getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO)));
122 sheetSet.put(
new NodeProperty<>(
"Date", Bundle.MessageNode_Node_Property_Date(),
"",
123 getAttributeDisplayString(artifact, TSK_DATETIME)));
138 public String getSourceName() {
139 return getDisplayName();
142 String getThreadID() {
147 public Action getPreferredAction() {
148 return preferredAction;
151 private int getAttachmentsCount() throws TskCoreException {
153 int attachmentsCount;
156 BlackboardAttribute attachmentsAttr = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ATTACHMENTS));
157 if (attachmentsAttr != null) {
158 String jsonVal = attachmentsAttr.getValueString();
159 MessageAttachments msgAttachments =
new Gson().fromJson(jsonVal, MessageAttachments.class);
160 attachmentsCount = msgAttachments.getAttachmentsCount();
162 attachmentsCount = artifact.getChildrenCount();
165 return attachmentsCount;
BlackboardArtifact getArtifact()