IDontKnow IDontKnow - 1 year ago 110
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:

PSTMessage email = (PSTMessage) folder.getNextChild();
while (email != null) {
System.out.println("Email: " + email.getSubject());
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?


Answer Source

First method : : available getters


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);

        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) {
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download