Autopsy  4.11.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 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.util.TimeZone;
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;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
30 import org.sleuthkit.datamodel.BlackboardAttribute;
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_DATETIME_START;
34 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM;
35 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO;
36 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_FROM;
37 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PHONE_NUMBER_TO;
38 import static org.sleuthkit.datamodel.BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT;
39 import static org.sleuthkit.datamodel.BlackboardAttribute.TSK_BLACKBOARD_ATTRIBUTE_VALUE_TYPE.DATETIME;
40 import org.sleuthkit.datamodel.TimeUtilities;
41 import org.sleuthkit.datamodel.TskCoreException;
44 
48 class MessageNode extends BlackboardArtifactNode {
49 
50  public static final String UNTHREADED_ID = "<UNTHREADED>";
51 
52  private static final Logger logger = Logger.getLogger(MessageNode.class.getName());
53 
54  private final String threadID;
55 
56  private final Action preferredAction;
57 
58  MessageNode(BlackboardArtifact artifact, String threadID, Action preferredAction) {
59  super(artifact);
60 
61  this.preferredAction = preferredAction;
62 
63  final String stripEnd = StringUtils.stripEnd(artifact.getDisplayName(), "s"); // NON-NLS
64  String removeEndIgnoreCase = StringUtils.removeEndIgnoreCase(stripEnd, "message"); // NON-NLS
65  setDisplayName(removeEndIgnoreCase.isEmpty() ? stripEnd : removeEndIgnoreCase);
66 
67  this.threadID = threadID;
68  }
69 
70  @Messages({
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"
77  })
78 
79  @Override
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();
85  sheet.put(sheetSet);
86  }
87 
88  sheetSet.put(new NodeProperty<>("Type", Bundle.MessageNode_Node_Property_Type(), "", getDisplayName())); //NON-NLS
89 
90  BlackboardArtifact artifact = this.getArtifact();
91 
92  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
93  if (null != fromID) {
94  //Consider refactoring this to reduce boilerplate
95  switch (fromID) {
96  case TSK_EMAIL_MSG:
97  sheetSet.put(new NodeProperty<>("From", Bundle.MessageNode_Node_Property_From(), "",
98  StringUtils.strip(getAttributeDisplayString(artifact, TSK_EMAIL_FROM), " \t\n;"))); //NON-NLS
99  sheetSet.put(new NodeProperty<>("To", Bundle.MessageNode_Node_Property_To(), "",
100  StringUtils.strip(getAttributeDisplayString(artifact, TSK_EMAIL_TO), " \t\n;"))); //NON-NLS
101  sheetSet.put(new NodeProperty<>("Date", Bundle.MessageNode_Node_Property_Date(), "",
102  getAttributeDisplayString(artifact, TSK_DATETIME_SENT))); //NON-NLS
103  sheetSet.put(new NodeProperty<>("Subject", Bundle.MessageNode_Node_Property_Subject(), "",
104  getAttributeDisplayString(artifact, TSK_SUBJECT))); //NON-NLS
105  try {
106  sheetSet.put(new NodeProperty<>("Attms", Bundle.MessageNode_Node_Property_Attms(), "", artifact.getChildrenCount())); //NON-NLS
107  } catch (TskCoreException ex) {
108  logger.log(Level.WARNING, "Error loading attachment count for " + artifact, ex); //NON-NLS
109  }
110 
111  sheetSet.put(new NodeProperty<>("ThreadID", "ThreadID","",threadID == null ? "" : threadID)); //NON-NLS
112 
113  break;
114  case TSK_MESSAGE:
115  sheetSet.put(new NodeProperty<>("From", Bundle.MessageNode_Node_Property_From(), "",
116  getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM))); //NON-NLS
117  sheetSet.put(new NodeProperty<>("To", Bundle.MessageNode_Node_Property_To(), "",
118  getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO))); //NON-NLS
119  sheetSet.put(new NodeProperty<>("Date", Bundle.MessageNode_Node_Property_Date(), "",
120  getAttributeDisplayString(artifact, TSK_DATETIME))); //NON-NLS
121  sheetSet.put(new NodeProperty<>("Subject", Bundle.MessageNode_Node_Property_Subject(), "",
122  getAttributeDisplayString(artifact, TSK_SUBJECT))); //NON-NLS
123  try {
124  sheetSet.put(new NodeProperty<>("Attms", Bundle.MessageNode_Node_Property_Attms(), "", artifact.getChildrenCount())); //NON-NLS
125  } catch (TskCoreException ex) {
126  logger.log(Level.WARNING, "Error loading attachment count for " + artifact, ex); //NON-NLS
127  }
128  break;
129  case TSK_CALLLOG:
130  sheetSet.put(new NodeProperty<>("From", Bundle.MessageNode_Node_Property_From(), "",
131  getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM))); //NON-NLS
132  sheetSet.put(new NodeProperty<>("To", Bundle.MessageNode_Node_Property_To(), "",
133  getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO))); //NON-NLS
134  sheetSet.put(new NodeProperty<>("Date", Bundle.MessageNode_Node_Property_Date(), "",
135  getAttributeDisplayString(artifact, TSK_DATETIME_START))); //NON-NLS
136  break;
137  default:
138  break;
139  }
140  }
141 
142  return sheet;
143  }
144 
156  private static String getAttributeDisplayString(final BlackboardArtifact artifact, final BlackboardAttribute.ATTRIBUTE_TYPE attributeType) {
157  try {
158  BlackboardAttribute attribute = artifact.getAttribute(new BlackboardAttribute.Type(BlackboardAttribute.ATTRIBUTE_TYPE.fromID(attributeType.getTypeID())));
159  if (attribute == null) {
160  return "";
161  } else if (attributeType.getValueType() == DATETIME) {
162  return TimeUtilities.epochToTime(attribute.getValueLong(),
163  TimeZone.getTimeZone(Utils.getUserPreferredZoneId()));
164  } else {
165  return attribute.getDisplayString();
166  }
167  } catch (TskCoreException tskCoreException) {
168  logger.log(Level.WARNING, "Error getting attribute value.", tskCoreException); //NON-NLS
169  return "";
170  }
171  }
172 
179  @Override
180  public String getSourceName() {
181  return getDisplayName();
182  }
183 
184  String getThreadID() {
185  return threadID;
186  }
187 
188  @Override
189  public Action getPreferredAction() {
190  return preferredAction;
191  }
192 }

Copyright © 2012-2018 Basis Technology. Generated on: Fri Jun 21 2019
This work is licensed under a Creative Commons Attribution-Share Alike 3.0 United States License.