Autopsy  4.14.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 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;
29 import org.sleuthkit.datamodel.BlackboardArtifact;
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;
37 import org.sleuthkit.datamodel.TskCoreException;
38 import static org.sleuthkit.autopsy.communications.relationships.RelationshipsNodeUtilities.getAttributeDisplayString;
40 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG;
41 import static org.sleuthkit.datamodel.BlackboardArtifact.ARTIFACT_TYPE.TSK_MESSAGE;
42 import org.sleuthkit.datamodel.BlackboardAttribute;
43 import org.sleuthkit.datamodel.blackboardutils.attributes.MessageAttachments;
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  final BlackboardArtifact artifact = getArtifact();
91  BlackboardArtifact.ARTIFACT_TYPE fromID = BlackboardArtifact.ARTIFACT_TYPE.fromID(artifact.getArtifactTypeID());
92 
93  if(fromID == null ||
94  (fromID != TSK_EMAIL_MSG &&
95  fromID != TSK_MESSAGE)) {
96  return sheet;
97  }
98 
99  sheetSet.put(new NodeProperty<>("ThreadID", "ThreadID","",threadID == null ? UNTHREADED_ID : threadID)); //NON-NLS
100  sheetSet.put(new NodeProperty<>("Subject", Bundle.MessageNode_Node_Property_Subject(), "",
101  getAttributeDisplayString(artifact, TSK_SUBJECT))); //NON-NLS
102  try {
103  sheetSet.put(new NodeProperty<>("Attms", Bundle.MessageNode_Node_Property_Attms(), "", getAttachmentsCount())); //NON-NLS
104  } catch (TskCoreException ex) {
105  logger.log(Level.WARNING, "Error loading attachment count for " + artifact, ex); //NON-NLS
106  }
107 
108  switch (fromID) {
109  case TSK_EMAIL_MSG:
110  sheetSet.put(new NodeProperty<>("From", Bundle.MessageNode_Node_Property_From(), "",
111  StringUtils.strip(getAttributeDisplayString(artifact, TSK_EMAIL_FROM), " \t\n;"))); //NON-NLS
112  sheetSet.put(new NodeProperty<>("To", Bundle.MessageNode_Node_Property_To(), "",
113  StringUtils.strip(getAttributeDisplayString(artifact, TSK_EMAIL_TO), " \t\n;"))); //NON-NLS
114  sheetSet.put(new NodeProperty<>("Date", Bundle.MessageNode_Node_Property_Date(), "",
115  getAttributeDisplayString(artifact, TSK_DATETIME_SENT))); //NON-NLS
116  break;
117  case TSK_MESSAGE:
118  sheetSet.put(new NodeProperty<>("From", Bundle.MessageNode_Node_Property_From(), "",
119  getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_FROM))); //NON-NLS
120  sheetSet.put(new NodeProperty<>("To", Bundle.MessageNode_Node_Property_To(), "",
121  getAttributeDisplayString(artifact, TSK_PHONE_NUMBER_TO))); //NON-NLS
122  sheetSet.put(new NodeProperty<>("Date", Bundle.MessageNode_Node_Property_Date(), "",
123  getAttributeDisplayString(artifact, TSK_DATETIME))); //NON-NLS
124  break;
125  default:
126  break;
127  }
128  return sheet;
129  }
130 
137  @Override
138  public String getSourceName() {
139  return getDisplayName();
140  }
141 
142  String getThreadID() {
143  return threadID;
144  }
145 
146  @Override
147  public Action getPreferredAction() {
148  return preferredAction;
149  }
150 
151  private int getAttachmentsCount() throws TskCoreException {
152  final BlackboardArtifact artifact = getArtifact();
153  int attachmentsCount;
154 
155  // Attachments are specified in an attribute TSK_ATTACHMENTS as JSON attribute
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();
161  } else { // legacy attachments may be children of message artifact.
162  attachmentsCount = artifact.getChildrenCount();
163  }
164 
165  return attachmentsCount;
166  }
167 }

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