Skip to content

Commit b07df6e

Browse files
committed
Addition of isPasswordProtected
1 parent 15bc1b4 commit b07df6e

File tree

4 files changed

+63
-6
lines changed

4 files changed

+63
-6
lines changed

src/main/java/com/pff/PSTFile.java

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -479,8 +479,6 @@ public PSTFolder getRootFolder()
479479
return output;
480480
}
481481

482-
483-
484482
PSTNodeInputStream readLeaf(long bid)
485483
throws IOException, PSTException
486484
{
@@ -901,5 +899,4 @@ private void processDescriptorBTree(long btreeStartOffset)
901899
}
902900
}
903901

904-
905902
}

src/main/java/com/pff/PSTMessageStore.java

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,21 @@ public String getDisplayName() {
8484
}
8585

8686

87-
public String getDetails() {
88-
return this.items.toString();
89-
}
87+
public String getDetails() {
88+
return this.items.toString();
89+
}
90+
91+
/**
92+
* Is this pst file is password protected.
93+
* @throws PSTException on corrupted pst
94+
* @throws IOException on bad read
95+
* @return - true if protected,false otherwise
96+
* pstfile has the password stored against identifier 0x67FF.
97+
* if there is no password the value stored is 0x00000000.
98+
*/
99+
public boolean isPasswordProtected()
100+
throws PSTException, IOException {
101+
return (this.getLongItem(0x67FF) != 0);
102+
}
90103

91104
}
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package com.pff;
2+
3+
import java.io.File;
4+
import java.io.IOException;
5+
import java.net.URISyntaxException;
6+
import java.net.URL;
7+
import java.util.HashSet;
8+
import java.util.Arrays;
9+
import org.junit.Assert;
10+
import org.junit.Test;
11+
import org.junit.runner.RunWith;
12+
import org.junit.runners.JUnit4;
13+
14+
/**
15+
* Tests for {@link PSTDistList}.
16+
*
17+
* @author Richard Johnson
18+
*/
19+
@RunWith(JUnit4.class)
20+
public class PasswordTest {
21+
22+
/**
23+
* Test for password protectedness.
24+
*/
25+
@Test
26+
public final void testPasswordProtected()
27+
throws PSTException, IOException, URISyntaxException {
28+
URL dirUrl = ClassLoader.getSystemResource("passworded.pst");
29+
PSTFile pstFile = new PSTFile(new File(dirUrl.toURI()));
30+
Assert.assertEquals("Is password protected",
31+
pstFile.getMessageStore().isPasswordProtected(),
32+
true);
33+
}
34+
35+
/**
36+
* Test for non-password protectedness.
37+
*/
38+
@Test
39+
public final void testNotPasswordProtected()
40+
throws PSTException, IOException, URISyntaxException {
41+
URL dirUrl = ClassLoader.getSystemResource("dist-list.pst");
42+
PSTFile pstFile = new PSTFile(new File(dirUrl.toURI()));
43+
Assert.assertEquals("Is password protected",
44+
pstFile.getMessageStore().isPasswordProtected(),
45+
false);
46+
}
47+
}

src/test/resources/passworded.pst

265 KB
Binary file not shown.

0 commit comments

Comments
 (0)