19 package org.sleuthkit.autopsy.report.modules.stix;
25 import java.util.List;
26 import java.util.ArrayList;
28 import org.mitre.cybox.objects.EmailMessage;
29 import org.mitre.cybox.objects.Address;
34 class EvalEmailObj
extends EvaluatableObject {
36 private final EmailMessage obj;
38 private List<BlackboardArtifact> finalHits;
40 public EvalEmailObj(EmailMessage a_obj, String a_id, String a_spacing) {
49 public synchronized ObservableResult evaluate() {
53 List<BlackboardArtifact> toHits = null;
54 boolean hadToFields =
false;
55 List<BlackboardArtifact> ccHits = null;
56 boolean hadCcFields =
false;
57 List<BlackboardArtifact> fromHits = null;
58 boolean hadFromField =
false;
59 List<BlackboardArtifact> subjectHits = null;
60 boolean hadSubjectField =
false;
62 if (obj.getHeader() != null) {
63 if ((obj.getHeader().getTo() != null)
64 && (obj.getHeader().getTo().getRecipients() != null)
65 && (!obj.getHeader().getTo().getRecipients().isEmpty())) {
66 for (Address addr : obj.getHeader().getTo().getRecipients()) {
67 if (addr.getAddressValue() != null) {
72 toHits = findArtifactsBySubstring(addr.getAddressValue(),
73 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_TO);
74 }
catch (TskCoreException ex) {
75 addWarning(ex.getLocalizedMessage());
81 if ((obj.getHeader().getCC() != null)
82 && (obj.getHeader().getCC().getRecipients() != null)
83 && (!obj.getHeader().getCC().getRecipients().isEmpty())) {
84 for (Address addr : obj.getHeader().getCC().getRecipients()) {
85 if (addr.getAddressValue() != null) {
90 ccHits = findArtifactsBySubstring(addr.getAddressValue(),
91 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_CC);
92 }
catch (TskCoreException ex) {
93 addWarning(ex.getLocalizedMessage());
99 if ((obj.getHeader().getFrom() != null)
100 && (obj.getHeader().getFrom().getAddressValue() != null)) {
105 fromHits = findArtifactsBySubstring(obj.getHeader().getFrom().getAddressValue(),
106 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_EMAIL_FROM);
107 }
catch (TskCoreException ex) {
108 addWarning(ex.getLocalizedMessage());
112 if ((obj.getHeader().getSubject() != null)
113 && (obj.getHeader().getSubject().getValue() != null)) {
115 hadSubjectField =
true;
118 subjectHits = findArtifactsBySubstring(obj.getHeader().getSubject(),
119 BlackboardAttribute.ATTRIBUTE_TYPE.TSK_SUBJECT);
120 }
catch (TskCoreException ex) {
121 addWarning(ex.getLocalizedMessage());
127 if ((!hadToFields) && (!hadFromField) && (!hadCcFields) && (!hadSubjectField)) {
128 return new ObservableResult(
id,
"EmailMessage: Could not find any parsable EmailMessage fields "
129 + getPrintableWarnings(),
130 spacing, ObservableResult.ObservableState.INDETERMINATE, null);
134 String fieldNames = getListOfUnsupportedFields();
135 if (fieldNames.length() > 0) {
136 addWarning(
"Unsupported field(s) found: " + fieldNames);
141 boolean finalHitsStarted =
false;
144 combineHits(toHits, finalHitsStarted);
145 finalHitsStarted =
true;
148 combineHits(ccHits, finalHitsStarted);
149 finalHitsStarted =
true;
152 combineHits(fromHits, finalHitsStarted);
153 finalHitsStarted =
true;
155 if (hadSubjectField) {
156 combineHits(subjectHits, finalHitsStarted);
157 finalHitsStarted =
true;
160 if (!finalHitsStarted) {
162 return new ObservableResult(
id,
"EmailMessage: EmailObj parsing incomplete " + getPrintableWarnings(),
163 spacing, ObservableResult.ObservableState.INDETERMINATE, null);
167 if (finalHits.size() > 0) {
168 List<StixArtifactData> artData =
new ArrayList<StixArtifactData>();
169 for (BlackboardArtifact a : finalHits) {
170 artData.add(
new StixArtifactData(a.getObjectID(), id,
"EmailMessage"));
172 return new ObservableResult(
id,
"EmailMessage: " + finalHits.size() +
" matching artifacts found " + getPrintableWarnings(),
173 spacing, ObservableResult.ObservableState.TRUE, artData);
175 return new ObservableResult(
id,
"EmailMessage: No matching artifacts found " + getPrintableWarnings(),
176 spacing, ObservableResult.ObservableState.FALSE, null);
188 private void combineHits(List<BlackboardArtifact> newHits,
boolean finalHitsStarted) {
189 if (finalHitsStarted && (finalHits != null)) {
190 finalHits.retainAll(newHits);
202 private String getListOfUnsupportedFields() {
203 String fieldNames =
"";
204 if (obj.getHeader() != null) {
205 if (obj.getHeader().getReceivedLines() != null) {
206 fieldNames +=
"Received_Lines ";
208 if (obj.getHeader().getBCC() != null) {
209 fieldNames +=
"BCC ";
211 if (obj.getHeader().getInReplyTo() != null) {
212 fieldNames +=
"In_Reply_To ";
214 if (obj.getHeader().getDate() != null) {
215 fieldNames +=
"Date ";
217 if (obj.getHeader().getMessageID() != null) {
218 fieldNames +=
"Message_ID ";
220 if (obj.getHeader().getSender() != null) {
221 fieldNames +=
"Sender ";
223 if (obj.getHeader().getReplyTo() != null) {
224 fieldNames +=
"Reply_To ";
226 if (obj.getHeader().getErrorsTo() != null) {
227 fieldNames +=
"Errors_To ";
229 if (obj.getHeader().getBoundary() != null) {
230 fieldNames +=
"Boundary ";
232 if (obj.getHeader().getContentType() != null) {
233 fieldNames +=
"Content_Type ";
235 if (obj.getHeader().getMIMEVersion() != null) {
236 fieldNames +=
"MIME_Version ";
238 if (obj.getHeader().getPrecedence() != null) {
239 fieldNames +=
"Precedence ";
241 if (obj.getHeader().getUserAgent() != null) {
242 fieldNames +=
"User_Agent ";
244 if (obj.getHeader().getXMailer() != null) {
245 fieldNames +=
"X_Mailer ";
247 if (obj.getHeader().getXOriginatingIP() != null) {
248 fieldNames +=
"X_Originiating_IP ";
250 if (obj.getHeader().getXPriority() != null) {
251 fieldNames +=
"X_Priority ";
255 if (obj.getEmailServer() != null) {
256 fieldNames +=
"Email_Server ";
258 if (obj.getRawBody() != null) {
259 fieldNames +=
"Raw_Body ";
261 if (obj.getRawHeader() != null) {
262 fieldNames +=
"Raw_Header ";
264 if (obj.getAttachments() != null) {
265 fieldNames +=
"Attachments ";
267 if (obj.getLinks() != null) {
268 fieldNames +=
"Links ";