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();
76 private final Map<String, Map<String, List<Long>>>
accounts =
new LinkedHashMap<>();
84 return accounts.keySet();
90 return accounts.get(account).keySet();
96 return accounts.get(account).get(folder);
100 @SuppressWarnings(
"deprecation")
105 if (skCase == null) {
109 int artId = BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID();
110 int pathAttrId = BlackboardAttribute.ATTRIBUTE_TYPE.TSK_PATH.getTypeID();
111 String query =
"SELECT value_text,blackboard_attributes.artifact_id,attribute_type_id "
112 +
"FROM blackboard_attributes,blackboard_artifacts WHERE "
113 +
"attribute_type_id=" + pathAttrId
114 +
" AND blackboard_attributes.artifact_id=blackboard_artifacts.artifact_id"
115 +
" AND blackboard_artifacts.artifact_type_id=" + artId;
117 try (CaseDbQuery dbQuery = skCase.executeQuery(query)) {
118 ResultSet resultSet = dbQuery.getResultSet();
120 while (resultSet.next()) {
121 final String path = resultSet.getString(
"value_text");
122 final long artifactId = resultSet.getLong(
"artifact_id");
123 final Map<String, String> parsedPath =
parsePath(path);
124 final String account = parsedPath.get(MAIL_ACCOUNT);
125 final String folder = parsedPath.get(MAIL_FOLDER);
127 Map<String, List<Long>> folders = accounts.get(account);
128 if (folders == null) {
129 folders =
new LinkedHashMap<>();
130 accounts.put(account, folders);
132 List<Long> messages = folders.get(folder);
133 if (messages == null) {
134 messages =
new ArrayList<>();
135 folders.put(folder, messages);
137 messages.add(artifactId);
140 }
catch (TskCoreException | SQLException ex) {
141 logger.log(Level.WARNING,
"Cannot initialize email extraction: ", ex);
148 Map<String, String> parsed =
new HashMap<>();
149 String[] split = path.split(MAIL_PATH_SEPARATOR);
150 if (split.length < 4) {
151 parsed.put(MAIL_ACCOUNT, NbBundle.getMessage(
EmailExtracted.class,
"EmailExtracted.defaultAcct.text"));
152 parsed.put(MAIL_FOLDER, NbBundle.getMessage(
EmailExtracted.class,
"EmailExtracted.defaultFolder.text"));
155 parsed.put(MAIL_ACCOUNT, split[2]);
156 parsed.put(MAIL_FOLDER, split[3]);
163 return v.
visit(
this);
173 super(Children.create(
new AccountFactory(),
true), Lookups.singleton(DISPLAY_NAME));
174 super.setName(LABEL_NAME);
175 super.setDisplayName(DISPLAY_NAME);
176 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/mail-icon-16.png");
187 return v.
visit(
this);
192 Sheet s = super.createSheet();
193 Sheet.Set ss = s.get(Sheet.PROPERTIES);
195 ss = Sheet.createPropertiesSet();
199 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.name"),
200 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.displayName"),
201 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.desc"),
221 private class AccountFactory extends ChildFactory.Detachable<String> implements Observer {
227 private final PropertyChangeListener
pcl =
new PropertyChangeListener() {
229 public void propertyChange(PropertyChangeEvent evt) {
230 String eventType = evt.getPropertyName();
247 if (null != eventData && eventData.
getBlackboardArtifactType().getTypeID() == BlackboardArtifact.ARTIFACT_TYPE.TSK_EMAIL_MSG.getTypeID()) {
250 }
catch (IllegalStateException notUsed) {
266 }
catch (IllegalStateException notUsed) {
273 if (evt.getNewValue() == null) {
287 emailResults.addObserver(
this);
295 emailResults.deleteObserver(
this);
310 public void update(Observable o, Object arg) {
323 super(Children.create(
new FolderFactory(accountName),
true), Lookups.singleton(accountName));
324 super.setName(accountName);
326 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/account-icon-16.png");
328 emailResults.addObserver(
this);
332 super.setDisplayName(accountName +
" (" + emailResults.
getFolders(accountName) +
")");
337 Sheet s = super.createSheet();
338 Sheet.Set ss = s.get(Sheet.PROPERTIES);
340 ss = Sheet.createPropertiesSet();
344 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.name"),
345 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.displayName"),
346 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.desc"),
359 return v.
visit(
this);
363 public void update(Observable o, Object arg) {
381 private class FolderFactory extends ChildFactory<String> implements Observer {
388 emailResults.addObserver(
this);
393 list.addAll(emailResults.
getFolders(accountName));
399 return new FolderNode(accountName, folderName);
403 public void update(Observable o, Object arg) {
417 super(Children.create(
new MessageFactory(accountName, folderName),
true), Lookups.singleton(accountName));
418 super.setName(folderName);
419 this.setIconBaseWithExtension(
"org/sleuthkit/autopsy/images/folder-icon-16.png");
423 emailResults.addObserver(
this);
427 super.setDisplayName(folderName +
" (" + emailResults.
getArtifactIds(accountName, folderName).size() +
")");
438 Sheet s = super.createSheet();
439 Sheet.Set ss = s.get(Sheet.PROPERTIES);
441 ss = Sheet.createPropertiesSet();
445 ss.put(
new NodeProperty<>(NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.name"),
446 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.displayName"),
447 NbBundle.getMessage(
this.getClass(),
"EmailExtracted.createSheet.name.desc"),
455 return v.
visit(
this);
459 public void update(Observable o, Object arg) {
486 emailResults.addObserver(
this);
491 list.addAll(emailResults.
getArtifactIds(accountName, folderName));
497 if (skCase == null) {
501 BlackboardArtifact artifact = skCase.getBlackboardArtifact(artifactId);
503 }
catch (TskException ex) {
504 logger.log(Level.WARNING,
"Error creating mail messages nodes", ex);
510 public void update(Observable o, Object arg) {
BlackboardArtifact.Type getBlackboardArtifactType()
void removeIngestModuleEventListener(final PropertyChangeListener listener)
static synchronized IngestManager getInstance()
static void removePropertyChangeListener(PropertyChangeListener listener)
T visit(DataSourcesNode in)
void removeIngestJobEventListener(final PropertyChangeListener listener)
void addIngestJobEventListener(final PropertyChangeListener listener)
static void addPropertyChangeListener(PropertyChangeListener listener)
void addIngestModuleEventListener(final PropertyChangeListener listener)
static Case getCurrentCase()
synchronized static Logger getLogger(String name)