19package org.sleuthkit.autopsy.communications.relationships;
21import java.awt.event.ActionEvent;
22import java.util.logging.Level;
23import javax.swing.AbstractAction;
24import javax.swing.Action;
25import org.apache.commons.lang3.StringUtils;
26import org.openide.nodes.Sheet;
27import org.openide.util.Exceptions;
28import org.openide.util.NbBundle.Messages;
29import org.sleuthkit.autopsy.casemodule.Case;
30import org.sleuthkit.autopsy.coreutils.Logger;
31import org.sleuthkit.autopsy.datamodel.NodeProperty;
32import org.sleuthkit.datamodel.BlackboardArtifact;
33import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME;
34import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT;
35import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM;
36import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO;
37import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM;
38import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO;
39import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT;
40import org.sleuthkit.datamodel.TskCoreException;
41import static org.sleuthkit.autopsy.communications.relationships.RelationshipsNodeUtilities.getAttributeDisplayString;
42import org.sleuthkit.autopsy.datamodel.BlackboardArtifactNode;
43import org.sleuthkit.datamodel.Account;
44import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG;
45import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE;
46import org.sleuthkit.datamodel.BlackboardAttribute;
47import org.sleuthkit.datamodel.CommunicationsManager;
48import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil;
49import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
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;
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"
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(),
"",
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;
static final long serialVersionUID
void actionPerformed(ActionEvent e)
BlackboardArtifact getArtifact()
final BlackboardArtifact artifact