IDontKnow IDontKnow - 1 month ago 11
Java Question

Extract Email adresses from .pst file with java-libpst

i have several .pst files and need all the mail-addresses, i sent mails to. The example code of the library allows me to traverse every mail in the file, but i can't find the right getter to extract the mail address of the receiver.

To traverse every mail, i use the code from this site:
https://code.google.com/p/java-libpst/

PSTMessage email = (PSTMessage) folder.getNextChild();
while (email != null) {
printDepth();
System.out.println("Email: " + email.getSubject());
printDepth();
System.out.println("Adress: " + email.getDisplayTo());
email = (PSTMessage) folder.getNextChild();
}


The getDisplayTo() method only displays the receivers names but not their mail addresses.
What getter do i need to use to get the addresses?

Best,
Michael

Answer

First method : : available getters

getSenderEmailAddress
getNumberOfRecipients
getRecipient(int)

Second Method : parse the header and collect the email address (a_sHeader is a string)

    Session s = Session.getDefaultInstance(new Properties());
    InputStream is = new ByteArrayInputStream(a_sHeader.getBytes());
    try {
        m_message = new MimeMessage(s, is);

        m_message.getAllHeaderLines();
        for (Enumeration<Header> e = m_message.getAllHeaders(); e.hasMoreElements();) {
            Header h = e.nextElement();
            // Recipients
            if (h.getName().equalsIgnoreCase(getHeaderName(RecipientType.REC_TYPE_TO))) {
                m_RecipientsTo = processAddresses(h.getValue());
            }
            ...             
        }
    } catch (MessagingException e1) {
        ...             
    }
Comments