Autopsy  4.16.0
Graphical digital forensics platform for The Sleuth Kit and other tools.
MessageNode.java
Go to the documentation of this file.
1 /*
2  * Autopsy Forensic Browser
3  *
4  * Copyright 2019-2020 Basis Technology Corp.
5  * Contact: carrier <at> sleuthkit <dot> org
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  */
19 package org.sleuthkit.autopsy.communications.relationships;
20 
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.NbBundle.Messages;
30 import org.sleuthkit.datamodel.BlackboardArtifact;
31 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME;
32 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_DATETIME_SENT;
33 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM;
34 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO;
35 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM;
36 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO;
37 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT;
38 import org.sleuthkit.datamodel.TskCoreException;
39 import static org.sleuthkit.autopsy.communications.relationships.RelationshipsNodeUtilities.getAttributeDisplayString;
41 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG;
42 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE;
43 import org.sleuthkit.datamodel.BlackboardAttribute;
44 import org.sleuthkit.datamodel.blackboardutils.attributes.BlackboardJsonAttrUtil;
45 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
46 
50 class MessageNode extends BlackboardArtifactNode {
51 
52  public static final String UNTHREADED_ID = "<UNTHREADED>";
53 
54  private static final Logger logger = Logger.getLogger(MessageNode.class.getName());
55 
56  private final String threadID;
57 
58  private final Action preferredAction;
59 
60  private final Action defaultNoopAction = new DefaultMessageAction();
61 
62  MessageNode(BlackboardArtifact artifact, String threadID, Action preferredAction) {
63  super(artifact);
64 
65  this.preferredAction = preferredAction;
66 
67  final String stripEnd = StringUtils.stripEnd(artifact.getDisplayName(), "s"); // NON-NLS
68  String removeEndIgnoreCase = StringUtils.removeEndIgnoreCase(stripEnd, "message"); // NON-NLS
69  setDisplayName(removeEndIgnoreCase.isEmpty() ? stripEnd : removeEndIgnoreCase);
70 
71  this.threadID = threadID;
72  }
73 
74  @Messages({
75  "MessageNode_Node_Property_Type=Type",
76  "MessageNode_Node_Property_From=From",
77  "MessageNode_Node_Property_To=To",
78  "MessageNode_Node_Property_Date=Date",
79  "MessageNode_Node_Property_Subject=Subject",
80  "MessageNode_Node_Property_Attms=Attachment Count"
81  })
82 
83  @Override
84  protected Sheet createSheet() {
85  Sheet sheet = Sheet.createDefault();
86  Sheet.Set sheetSet = sheet.get(Sheet.PROPERTIES);
87  if (sheetSet == null) {
88  sheetSet = Sheet.createPropertiesSet();
89  sheet.put(sheetSet);
90  }
91 
92  sheetSet.put(new NodeProperty<>("Type", Bundle.MessageNode_Node_Property_Type(), "", getDisplayName())); //NON-NLS
93 
94  final BlackboardArtifact artifact = getArtifact();
95  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
96 
97  if (fromID == null
98  || (fromID != TSK_EMAIL_MSG
99  && fromID != TSK_MESSAGE)) {
100  return sheet;
101  }
102  if (threadID != null) {
103  sheetSet.put(new NodeProperty<>("ThreadID", "ThreadID", "", threadID)); //NON-NLS
104  }
105  sheetSet.put(new NodeProperty<>("Subject", Bundle.MessageNode_Node_Property_Subject(), "",
106  getAttributeDisplayString(artifact, TSK_SUBJECT))); //NON-NLS
107  try {
108  sheetSet.put(new NodeProperty<>("Attms", Bundle.MessageNode_Node_Property_Attms(), "", getAttachmentsCount())); //NON-NLS
109  } catch (TskCoreException ex) {
110  logger.log(Level.WARNING, "Error loading attachment count for " + artifact, ex); //NON-NLS
111  }
112 
113  String msg_from = getAttributeDisplayString(artifact, TSK_EMAIL_FROM);
114  String msg_to = getAttributeDisplayString(artifact, TSK_EMAIL_TO);
115  String date = getAttributeDisplayString(artifact, TSK_DATETIME_SENT);
116 
117  if (msg_from.isEmpty()) {
118  msg_from = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM);
119 
120  }
121  if (msg_to.isEmpty()) {
122  msg_to = getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO);
123  }
124  if (date.isEmpty()) {
125  date = getAttributeDisplayString(artifact, TSK_DATETIME);
126  }
127 
128  sheetSet.put(new NodeProperty<>("From", Bundle.MessageNode_Node_Property_From(), "",
129  msg_from)); //NON-NLS
130  sheetSet.put(new NodeProperty<>("To", Bundle.MessageNode_Node_Property_To(), "",
131  msg_to)); //NON-NLS
132  sheetSet.put(new NodeProperty<>("Date", Bundle.MessageNode_Node_Property_Date(), "",
133  date)); //NON-NLS
134 
135  return sheet;
136  }
137 
144  @Override
145  public String getSourceName() {
146  return getDisplayName();
147  }
148 
149  String getThreadID() {
150  return threadID;
151  }
152 
153  @Override
154  public Action getPreferredAction() {
155  return preferredAction != null ? preferredAction : defaultNoopAction;
156  }
157 
158  private int getAttachmentsCount() throws TskCoreException {
159  final BlackboardArtifact artifact = getArtifact();
160  int attachmentsCount;
161 
162  // Attachments are specified in an attribute TSK_ATTACHMENTS as JSON attribute
163  BlackboardAttribute attachmentsAttr = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.TSK_ATTACHMENTS));
164  if (attachmentsAttr != null) {
165  try {
166  MessageAttachments msgAttachments = BlackboardJsonAttrUtil.fromAttribute(attachmentsAttr, MessageAttachments.class);
167  return msgAttachments.getAttachmentsCount();
168  } catch (BlackboardJsonAttrUtil.InvalidJsonException ex) {
169  logger.log(Level.WARNING, String.format("Unable to parse json for MessageAttachments object in artifact: %s", artifact.getName()), ex);
170  return 0;
171  }
172  } else { // legacy attachments may be children of message artifact.
173  attachmentsCount = artifact.getChildrenCount();
174  }
175 
176  return attachmentsCount;
177  }
178 
182  private class DefaultMessageAction extends AbstractAction {
183 
184  private static final long serialVersionUID = 1L;
185 
186  @Override
187  public void actionPerformed(ActionEvent e) {
188  // Do Nothing.
189  }
190  }
191 }

Copyright © 2012-2020 Basis Technology. Generated on: Tue Sep 22 2020
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.