Skip to content

Commit 643a551

Browse files
committed
Almost done with the distribution lists
1 parent 3900c8a commit 643a551

File tree

3 files changed

+80
-107
lines changed

3 files changed

+80
-107
lines changed

src/main/java/com/pff/PSTContact.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -835,7 +835,7 @@ public String toString() {
835835
"Display Name Prefix (Contact Title): "+getDisplayNamePrefix()+"\n"+
836836
"Profession: "+getProfession()+"\n"+
837837
"Preferred By Name: "+getPreferredByName()+"\n"+
838-
"Spouses Name: "+getSpouseName()+"\n"+
838+
"Spouse's Name: "+getSpouseName()+"\n"+
839839
"Computer Network Name: "+getComputerNetworkName()+"\n"+
840840
"Customer ID: "+getCustomerId()+"\n"+
841841
"TTY/TDD Phone: "+getTtytddPhoneNumber()+"\n"+

src/main/java/com/pff/PSTDistList.java

Lines changed: 24 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -83,31 +83,28 @@ public class OneOffEntry {
8383
public String addressType = "";
8484
public String emailAddress = "";
8585
int pos = 0;
86+
public String toString() {
87+
return String.format(
88+
"Display Name: %s\n" +
89+
"Address Type: %s\n" +
90+
"Email Address: %s\n",
91+
this.displayName,
92+
this.addressType,
93+
this.emailAddress);
94+
}
8695
}
8796

8897
private OneOffEntry parseOneOffEntry(byte[] data, int pos)
8998
throws IOException
9099
{
91-
/*
92-
dd01 0f54 0200 0001 8064 0069 0073 0074 Ý..T.....d.i.s.t
93-
0020 006e 0061 006d 0065 0020 0032 0000 ...n.a.m.e...2..
94-
0053 004d 0054 0050 0000 0064 0069 0073 .S.M.T.P...d.i.s
95-
0074 0032 0040 0072 006a 006f 0068 006e .t.2...r.j.o.h.n
96-
0073 006f 006e 002e 0069 0064 002e 0061 .s.o.n...i.d...a
97-
0075 0000 00 .u...
98-
*/
99100
int version = (int)PSTObject.convertLittleEndianBytesToLong(data, pos, pos+2);
100-
//System.out.println("Version: "+version);
101101
pos += 2;
102102

103103
// http://msdn.microsoft.com/en-us/library/ee202811(v=exchg.80).aspx
104104
int additionalFlags = (int)PSTObject.convertLittleEndianBytesToLong(data, pos, pos+2);
105-
//PSTObject.printFormattedNumber("Additional flags: ",additionalFlags);
106105
pos += 2;
107106

108-
//PSTObject.printFormattedNumber("flag: ",0x800);
109107
int pad = additionalFlags & 0x8000;
110-
//PSTObject.printFormattedNumber("Pad: ",pad);
111108
int mae = additionalFlags & 0x0C00;
112109
int format = additionalFlags & 0x1E00;
113110
int m = additionalFlags & 0x0100;
@@ -121,21 +118,18 @@ private OneOffEntry parseOneOffEntry(byte[] data, int pos)
121118
byte[] displayNameBytes = new byte[stringEnd - pos];
122119
System.arraycopy(data, pos, displayNameBytes, 0, displayNameBytes.length);
123120
String displayName = new String(displayNameBytes, "UTF-16LE");
124-
//System.out.println("displayName: "+displayName);
125121
pos = stringEnd + 2;
126122

127123
stringEnd = findNextNullChar(data, pos);
128124
byte[] addressTypeBytes = new byte[stringEnd - pos];
129125
System.arraycopy(data, pos, addressTypeBytes, 0, addressTypeBytes.length);
130126
String addressType = new String(addressTypeBytes, "UTF-16LE");
131-
//System.out.println("addressType "+addressType);
132127
pos = stringEnd + 2;
133128

134129
stringEnd = findNextNullChar(data, pos);
135130
byte[] emailAddressBytes = new byte[stringEnd - pos];
136131
System.arraycopy(data, pos, emailAddressBytes, 0, emailAddressBytes.length);
137132
String emailAddress = new String(emailAddressBytes, "UTF-16LE");
138-
//System.out.println("emailAddress "+emailAddress);
139133
pos = stringEnd + 2;
140134

141135
OneOffEntry out = new OneOffEntry();
@@ -146,82 +140,56 @@ private OneOffEntry parseOneOffEntry(byte[] data, int pos)
146140
return out;
147141
}
148142

149-
public String[] getDistributionListMembers()
143+
public Object[] getDistributionListMembers()
150144
throws PSTException, IOException
151145
{
152-
//PidLidDistributionListMembers
153-
// this looks like a Recipeint One-Off EntryID Structure
154146
PSTTableBCItem item = this.items.get(pstFile.getNameToIdMapItem(0x8055, PSTFile.PSETID_Address));
155-
//item = this.items.get(0x8047);
156-
String[] out = {};
147+
Object[] out = {};
157148
if (item != null) {
158-
PSTObject.printHexFormatted(item.data, true);
159-
160149
int pos = 0;
161-
162150
int count = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+4);
163-
//System.out.println("Count: "+count);
151+
out = new Object[count];
164152
pos += 4;
165153
pos = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+4);
166-
//System.out.println("pos: "+pos);
167154

168-
while (pos < item.data.length) {
169-
/*
170-
00 0000 00
171-
81 2b1f a4be a310 199d 6e00 dd01 0f54
172-
*/
155+
for (int x = 0; x < count; x++) {
173156
// http://msdn.microsoft.com/en-us/library/ee218661(v=exchg.80).aspx
174157
// http://msdn.microsoft.com/en-us/library/ee200559(v=exchg.80).aspx
175158
int flags = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+4);
176159
pos += 4;
177160

178161
byte[] guid = new byte[16];
179162
System.arraycopy(item.data, pos, guid, 0, guid.length);
180-
//PSTObject.printHexFormatted(guid, true);
181-
//System.out.println(Arrays.equals(guid, wrappedEntryIdUid));
182163
pos += 16;
183164

184165
if (Arrays.equals(guid, wrappedEntryIdUid)) {
185-
//System.out.println("Wrapped entry");
186-
187166
/* c3 */
188167
int entryType = item.data[pos] & 0x0F;
189168
int entryAddressType = item.data[pos] & 0x70 >> 4;
190169
boolean isOneOffEntryId = (item.data[pos] & 0x80) > 0;
191170
pos++;
192-
if (entryType == 3) {
193-
/*
194-
00 0000 00
195-
a4 1d63 dbc5 3b8e 4ab8 071e <- some guid from some where.
196-
15e5 5750 ce
197-
64 00 20 00
198-
*/
199-
int wrappedflags = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+4);
200-
pos += 4;
171+
int wrappedflags = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+4);
172+
pos += 4;
201173

202-
byte[] guid2 = new byte[16];
203-
System.arraycopy(item.data, pos, guid, 0, guid.length);
204-
//PSTObject.printHexFormatted(guid, true);
205-
pos += 16;
174+
byte[] guid2 = new byte[16];
175+
System.arraycopy(item.data, pos, guid, 0, guid.length);
176+
pos += 16;
206177

207-
int descriptorId = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+3);
208-
pos += 3;
178+
int descriptorIndex = (int)PSTObject.convertLittleEndianBytesToLong(item.data, pos, pos+3);
179+
pos += 3;
209180

210-
byte empty = item.data[pos];
211-
pos++;
181+
byte empty = item.data[pos];
182+
pos++;
212183

213-
}
184+
out[x] = PSTObject.detectAndLoadPSTObject(this.pstFile, descriptorIndex);
214185

215186
} else if (Arrays.equals(guid, oneOffEntryIdUid)) {
216187
OneOffEntry entry = parseOneOffEntry(item.data, pos);
217-
System.out.println(entry.emailAddress);
218188
pos = entry.pos;
189+
out[x] = entry;
219190
}
220-
221191
}
222192
}
223193
return out;
224194
}
225-
226-
227195
}

src/test/java/com/pff/DistListTest.java

Lines changed: 55 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -22,61 +22,66 @@ public class DistListTest {
2222
*/
2323
@Test
2424
public final void testGetDistList() {
25-
try {
26-
URL dir_url = ClassLoader.getSystemResource("dist-list.pst");
27-
PSTFile pstFile = new PSTFile(new File(dir_url.toURI()));
28-
PSTDistList obj = (PSTDistList)PSTObject.detectAndLoadPSTObject(pstFile, 2097188);
29-
System.out.println(obj);
30-
String[] members =obj.getDistributionListMembers();
31-
for (String member : members) {
32-
System.out.println(member);
33-
}
25+
try {
26+
URL dir_url = ClassLoader.getSystemResource("dist-list.pst");
27+
PSTFile pstFile = new PSTFile(new File(dir_url.toURI()));
28+
PSTDistList obj = (PSTDistList)PSTObject.detectAndLoadPSTObject(pstFile, 2097188);
29+
System.out.println(obj);
30+
Object[] members = obj.getDistributionListMembers();
31+
for (Object member : members) {
32+
if (member instanceof PSTContact) {
33+
PSTContact contact = (PSTContact)member;
34+
System.out.println(contact);
35+
} else {
36+
System.out.println(member);
37+
}
38+
}
3439

35-
//System.out.println(pstFile.getMessageStore().getDisplayName());
36-
//processFolder(pstFile.getRootFolder());
37-
} catch (Exception err) {
38-
err.printStackTrace();
39-
}
40+
//System.out.println(pstFile.getMessageStore().getDisplayName());
41+
//processFolder(pstFile.getRootFolder());
42+
} catch (Exception err) {
43+
err.printStackTrace();
44+
}
4045
//org.junit.Assert.assertTrue(false);
4146
}
4247

43-
int depth = -1;
44-
public void processFolder(PSTFolder folder)
45-
throws PSTException, java.io.IOException
46-
{
47-
depth++;
48-
// the root folder doesn't have a display name
49-
if (depth > 0) {
50-
printDepth();
51-
System.out.println(folder.getDisplayName());
52-
}
48+
int depth = -1;
49+
public void processFolder(PSTFolder folder)
50+
throws PSTException, java.io.IOException
51+
{
52+
depth++;
53+
// the root folder doesn't have a display name
54+
if (depth > 0) {
55+
printDepth();
56+
System.out.println(folder.getDisplayName());
57+
}
5358

54-
// go through the folders...
55-
if (folder.hasSubfolders()) {
56-
Vector<PSTFolder> childFolders = folder.getSubFolders();
57-
for (PSTFolder childFolder : childFolders) {
58-
processFolder(childFolder);
59-
}
60-
}
59+
// go through the folders...
60+
if (folder.hasSubfolders()) {
61+
Vector<PSTFolder> childFolders = folder.getSubFolders();
62+
for (PSTFolder childFolder : childFolders) {
63+
processFolder(childFolder);
64+
}
65+
}
6166

62-
// and now the emails for this folder
63-
if (folder.getContentCount() > 0) {
64-
depth++;
65-
PSTMessage email = (PSTMessage)folder.getNextChild();
66-
while (email != null) {
67-
printDepth();
68-
System.out.println("Email: "+email.getDescriptorNodeId()+" "+email.getSubject());
69-
email = (PSTMessage)folder.getNextChild();
70-
}
71-
depth--;
72-
}
73-
depth--;
74-
}
67+
// and now the emails for this folder
68+
if (folder.getContentCount() > 0) {
69+
depth++;
70+
PSTMessage email = (PSTMessage)folder.getNextChild();
71+
while (email != null) {
72+
printDepth();
73+
System.out.println("Email: "+email.getDescriptorNodeId()+" "+email.getSubject());
74+
email = (PSTMessage)folder.getNextChild();
75+
}
76+
depth--;
77+
}
78+
depth--;
79+
}
7580

76-
public void printDepth() {
77-
for (int x = 0; x < depth-1; x++) {
78-
System.out.print(" | ");
79-
}
80-
System.out.print(" |- ");
81-
}
81+
public void printDepth() {
82+
for (int x = 0; x < depth-1; x++) {
83+
System.out.print(" | ");
84+
}
85+
System.out.print(" |- ");
86+
}
8287
}

0 commit comments

Comments
 (0)