rjohnsondev / java-libpst

A library to read PST files with java, without need for external libraries.
251 stars 122 forks source link

check if a pst file is password protected #8

Closed vishesh04 closed 10 years ago

vishesh04 commented 11 years ago

is there a way to check ,if the pst file is password protected.The libpst opens password protected files also without the password.

vishesh04 commented 11 years ago

I used the following add.You can add it as a utility method in original code base

/**
 * checks if a pst file is password protected
 * 
 * @param file - pst file to check 
 * @return - true if protected,false otherwise
 * 
 * pstfile has the password stored against identifier 0x67FF.
 * if there is no password the value stored is 0x00000000.
 */
private static boolean ifProtected(PSTFile file,boolean reomovePwd){
    try {
        String fileDetails = file.getMessageStore().getDetails();
        String[] lines = fileDetails.split("\n");
        for(String line:lines){
            if(line.contains("0x67FF")){
                if(line.contains("0x00000000"))
                    return false;
                else
                    return true;
            }

        }
    } catch (PSTException e) {
        e.printStackTrace();
    } catch (IOException e) {
        e.printStackTrace();
    }
    return false;
}
rjohnsondev commented 10 years ago

Added in https://github.com/rjohnsondev/java-libpst/commit/b07df6e39cadca1b488b05a6abd94667ea7b4854