19 package org.sleuthkit.autopsy.datamodel;
21 import java.beans.PropertyChangeEvent;
22 import java.beans.PropertyChangeListener;
23 import java.sql.ResultSet;
24 import java.sql.SQLException;
25 import java.util.ArrayList;
26 import java.util.HashMap;
27 import java.util.LinkedHashMap;
28 import java.util.List;
30 import java.util.Observable;
31 import java.util.Observer;
33 import java.util.logging.Level;
34 import org.openide.nodes.ChildFactory;
35 import org.openide.nodes.Children;
36 import org.openide.nodes.Node;
37 import org.openide.nodes.Sheet;
38 import org.openide.util.NbBundle;
39 import org.openide.util.lookup.Lookups;
47 import org.
sleuthkit.datamodel.SleuthkitCase.CaseDbQuery;
59 private static final String
LABEL_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getLabel();
60 private static final String
DISPLAY_NAME = BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getDisplayName();
75 private final Map<String, Map<String, List<Long>>>
accounts =
new LinkedHashMap<>();
82 return accounts.keySet();
86 return accounts.get(account).keySet();
90 return accounts.get(account).get(folder);
93 @SuppressWarnings(
"deprecation")
100 int artId = BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID();
101 int pathAttrId = BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID();
102 String query =
"SELECT value_text,blackboard_attributes.artifact_id,attribute_type_id "
103 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
104 +
"attribute_type_id=" + pathAttrId
105 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
106 +
" AND blackboard_artifacts.artifact_type_id=" + artId;
108 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
109 ResultSet resultSet = dbQuery.getResultSet();
110 while (resultSet.next()) {
111 final String path = resultSet.getString(
"value_text");
112 final long artifactId = resultSet.getLong(
"artifact_id");
113 final Map<String, String> parsedPath =
parsePath(path);
114 final String account = parsedPath.get(MAIL_ACCOUNT);
115 final String folder = parsedPath.get(MAIL_FOLDER);
117 Map<String, List<Long>> folders = accounts.get(account);
118 if (folders == null) {
119 folders =
new LinkedHashMap<>();
120 accounts.put(account, folders);
122 List<Long> messages = folders.get(folder);
123 if (messages == null) {
124 messages =
new ArrayList<>();
125 folders.put(folder, messages);
127 messages.add(artifactId);
129 }
catch (TskCoreException | SQLException ex) {
130 logger.log(Level.WARNING,
"Cannot initialize email extraction: ", ex);
135 Map<String, String> parsed =
new HashMap<>();
136 String[] split = path.split(MAIL_PATH_SEPARATOR);
137 if (split.length < 4) {
138 parsed.put(MAIL_ACCOUNT, NbBundle.getMessage(
EmailExtracted.class,
"EmailExtracted.defaultAcct.text"));
139 parsed.put(MAIL_FOLDER, NbBundle.getMessage(
EmailExtracted.class,
"EmailExtracted.defaultFolder.text"));
142 parsed.put(MAIL_ACCOUNT, split[2]);
143 parsed.put(MAIL_FOLDER, split[3]);
149 public <T> T accept(AutopsyItemVisitor<T> v) {
150 return v.visit(
this);
160 super(Children.create(
new AccountFactory(),
true), Lookups.singleton(DISPLAY_NAME));
161 super.setName(LABEL_NAME);
162 super.setDisplayName(DISPLAY_NAME);
163 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/mail-icon-16.png");
174 return v.
visit(
this);
179 Sheet s = super.createSheet();
180 Sheet.Set ss = s.get(Sheet.PROPERTIES);
182 ss = Sheet.createPropertiesSet();
186 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.name"),
187 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.displayName"),
188 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.desc"),
208 private class AccountFactory extends ChildFactory.Detachable<String> implements Observer {
214 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
216 public void propertyChange(PropertyChangeEvent evt) {
217 String eventType = evt.getPropertyName();
234 if (null != eventData && eventData.
getBlackboardArtifactType().getTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()) {
237 }
catch (IllegalStateException notUsed) {
253 }
catch (IllegalStateException notUsed) {
260 if (evt.getNewValue() == null) {
274 emailResults.addObserver(
this);
282 emailResults.deleteObserver(
this);
297 public void update(Observable o, Object arg) {
310 super(Children.create(
new FolderFactory(accountName),
true), Lookups.singleton(accountName));
311 super.setName(accountName);
313 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/account-icon-16.png");
315 emailResults.addObserver(
this);
319 super.setDisplayName(accountName +
" (" + emailResults.
getFolders(accountName) +
")");
324 Sheet s = super.createSheet();
325 Sheet.Set ss = s.get(Sheet.PROPERTIES);
327 ss = Sheet.createPropertiesSet();
331 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.name"),
332 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.displayName"),
333 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.desc"),
346 return v.
visit(
this);
350 public void update(Observable o, Object arg) {
368 private class FolderFactory extends ChildFactory<String> implements Observer {
375 emailResults.addObserver(
this);
380 list.addAll(emailResults.
getFolders(accountName));
386 return new FolderNode(accountName, folderName);
390 public void update(Observable o, Object arg) {
404 super(Children.create(
new MessageFactory(accountName, folderName),
true), Lookups.singleton(accountName));
405 super.setName(folderName);
406 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/folder-icon-16.png");
410 emailResults.addObserver(
this);
414 super.setDisplayName(folderName +
" (" + emailResults.
getArtifactIds(accountName, folderName).size() +
")");
425 Sheet s = super.createSheet();
426 Sheet.Set ss = s.get(Sheet.PROPERTIES);
428 ss = Sheet.createPropertiesSet();
432 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.name"),
433 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.displayName"),
434 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.desc"),
442 return v.
visit(
this);
446 public void update(Observable o, Object arg) {
473 emailResults.addObserver(
this);
478 list.addAll(emailResults.
getArtifactIds(accountName, folderName));
484 if (skCase == null) {
488 BlackboardArtifact artifact = skCase.getBlackboardArtifact(artifactId);
490 }
catch (TskException ex) {
491 logger.log(Level.WARNING,
"Error creating mail messages nodes", ex);
497 public void update(Observable o, Object arg) {
BlackboardArtifact.Type getBlackboardArtifactType()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
T visit(DataSourcesNode in)
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)
static synchronized void removePropertyChangeListener(PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized void addPropertyChangeListener(PropertyChangeListener listener)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)