19 package org.sleuthkit.autopsy.communications.relationships;
21 import java.awt.event.ActionEvent;
22 import java.util.logging.Level;
23 import javax.swing.AbstractAction;
24 import javax.swing.Action;
25 import org.apache.commons.lang3.StringUtils;
26 import org.openide.nodes.Sheet;
27 import org.openide.util.Exceptions;
28 import org.openide.util.NbBundle.Messages;
33 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME;
34 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT;
35 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM;
36 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO;
37 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM;
38 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO;
39 import static org.
sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT;
44 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG;
45 import static org.
sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE;
48 import org.
sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil;
49 import org.
sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
54 class MessageNode
extends BlackboardArtifactNode {
56 public static final String UNTHREADED_ID =
"<UNTHREADED>";
58 private static final Logger logger = Logger.getLogger(MessageNode.class.getName());
60 private final String threadID;
62 private final Action preferredAction;
64 private final Action defaultNoopAction =
new DefaultMessageAction();
66 MessageNode(BlackboardArtifact artifact, String threadID, Action preferredAction) {
69 this.preferredAction = preferredAction;
71 final String stripEnd = StringUtils.stripEnd(artifact.getDisplayName(),
"s");
72 String removeEndIgnoreCase = StringUtils.removeEndIgnoreCase(stripEnd,
"message");
73 setDisplayName(removeEndIgnoreCase.isEmpty() ? stripEnd : removeEndIgnoreCase);
75 this.threadID = threadID;
79 "MessageNode_Node_Property_Type=Type",
80 "MessageNode_Node_Property_From=From",
81 "MessageNode_Node_Property_To=To",
82 "MessageNode_Node_Property_Date=Date",
83 "MessageNode_Node_Property_Subject=Subject",
84 "MessageNode_Node_Property_Attms=Attachment Count"
88 protected Sheet createSheet() {
89 Sheet sheet = Sheet.createDefault();
90 Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
91 if (sheetSet == null) {
92 sheetSet = Sheet.createPropertiesSet();
96 sheetSet.put(
new NodeProperty<>(
"Type", Bundle.MessageNode_Node_Property_Type(),
"", getDisplayName()));
99 BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
102 || (fromID != TSK_EMAIL_MSG
103 && fromID != TSK_MESSAGE)) {
106 if (threadID != null) {
107 sheetSet.put(
new NodeProperty<>(
"ThreadID",
"ThreadID",
"", threadID));
109 sheetSet.put(
new NodeProperty<>(
"Subject", Bundle.MessageNode_Node_Property_Subject(),
"",
110 getAttributeDisplayString(artifact, TSK_SUBJECT)));
112 sheetSet.put(
new NodeProperty<>(
"Attms", Bundle.MessageNode_Node_Property_Attms(),
"", getAttachmentsCount()));
113 }
catch (TskCoreException ex) {
114 logger.log(Level.WARNING,
"Error loading attachment count for " + artifact, ex);
117 String msg_from = getAttributeDisplayString(artifact, TSK_EMAIL_FROM);
118 String msg_to = getAttributeDisplayString(artifact, TSK_EMAIL_TO);
119 String date = getAttributeDisplayString(artifact, TSK_DATETIME_SENT);
121 Account account_from = null;
122 Account account_to = null;
125 CommunicationsManager manager = Case.getCurrentCase().getSleuthkitCase().getCommunicationsManager();
127 if (msg_from.isEmpty()) {
128 msg_from = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM);
129 if(manager != null && !msg_from.isEmpty()) {
130 account_from = manager.getAccount(Account.Type.PHONE, msg_from);
132 }
else if(manager != null) {
134 String toStr = msg_to;
135 String[] strSplit = msg_to.split(
":");
136 if(strSplit.length > 0) {
137 toStr = strSplit[strSplit.length-1].trim();
139 account_from = manager.getAccount(Account.Type.EMAIL, toStr);
142 if (msg_to.isEmpty()) {
143 msg_to = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO);
144 if(manager != null && !msg_to.isEmpty()) {
145 account_to = manager.getAccount(Account.Type.PHONE, msg_to);
147 }
else if(manager != null) {
148 account_to = manager.getAccount(Account.Type.EMAIL, msg_to);
151 if (date.isEmpty()) {
152 date = getAttributeDisplayString(artifact, TSK_DATETIME);
154 }
catch (TskCoreException ex) {
158 sheetSet.put(
new AccountNodeProperty<>(
"From", Bundle.MessageNode_Node_Property_From(),
159 msg_from, account_from));
160 sheetSet.put(
new AccountNodeProperty<>(
"To", Bundle.MessageNode_Node_Property_To(),
161 msg_to, account_to));
162 sheetSet.put(
new NodeProperty<>(
"Date", Bundle.MessageNode_Node_Property_Date(),
"",
175 public String getSourceName() {
176 return getDisplayName();
179 String getThreadID() {
184 public Action getPreferredAction() {
185 return preferredAction != null ? preferredAction : defaultNoopAction;
188 private int getAttachmentsCount() throws TskCoreException {
190 int attachmentsCount;
193 BlackboardAttribute attachmentsAttr = artifact.getAttribute(
new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ATTACHMENTS));
194 if (attachmentsAttr != null) {
196 MessageAttachments msgAttachments = BlackboardJsonAttrUtil.fromAttribute(attachmentsAttr, MessageAttachments.class);
197 return msgAttachments.getAttachmentsCount();
198 }
catch (BlackboardJsonAttrUtil.InvalidJsonException ex) {
199 logger.log(Level.WARNING, String.format(
"Unable to parse json for MessageAttachments object in artifact: %s", artifact.getName()), ex);
203 attachmentsCount = artifact.getChildrenCount();
206 return attachmentsCount;
void actionPerformed(ActionEvent e)
static final long serialVersionUID
BlackboardArtifact getArtifact()