Skip to content

Conversation

@vasilevich
Copy link

Added folder.getPreviousChild() method to PSTFolder.java ,
it allows you to scan the emails backwards until it reaches 0,
you must set the cursor further than 0 first (eg: folder.moveChildCursorTo(folder.getContentCount()-1)

try:
` package example;
import com.pff.;
import java.util.
;

public class Test {
public static void main(String[] args)
{
    new Test();
}

public Test() {
    try {
        PSTFile pstFile = new     PSTFile("C:\\Users\\alonpi\\AppData\\Local\\Microsoft\\Outlook\\Outlook.pst");
        System.out.println(pstFile.getMessageStore().getDisplayName());
        processFolder(pstFile.getRootFolder());
    } catch (Exception err) {
        err.printStackTrace();
    }
}

int depth = -1;
public void processFolder(PSTFolder folder)
        throws PSTException, java.io.IOException
{
    depth++;
    // the root folder doesn't have a display name
    if (depth > 0) {
        printDepth();
        System.out.println(folder.getDisplayName());
    }

    // go through the folders...
    if (folder.hasSubfolders()) {
        Vector<PSTFolder> childFolders = folder.getSubFolders();
        for (PSTFolder childFolder : childFolders) {
            processFolder(childFolder);
        }
    }

    // and now the emails for this folder
    if (folder.getContentCount() > 0) {
        depth++;

        folder.moveChildCursorTo(folder.getContentCount()-1);

        PSTMessage email = (PSTMessage)folder.getPreviousChild();
        while (email != null) {
            printDepth();

                System.out.println(email.getSenderEmailAddress() + "  " + "Email: " + email.getDescriptorNodeId() + " - " + email.getSubject());

            email = (PSTMessage)folder.getPreviousChild();
        }
        depth--;
    }
    depth--;
}

public void printDepth() {
    for (int x = 0; x < depth-1; x++) {
        System.out.print(" | ");
    }
    System.out.print(" |- ");
}

}
`

…you to scan the emails backwards until it reaches 0, you must set the cursor further than 0 first (eg: folder.moveChildCursorTo(folder.getContentCount()-1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant