Java Reference
In-Depth Information
if ( to != null ) System . out . println ( "To: " + to );
String cc = InternetAddress . toString (
messages [ i ]. getRecipients ( Message . RecipientType . CC ));
if ( cc != null ) System . out . println ( "Cc: " + cc );
String bcc = InternetAddress . toString (
messages [ i ]. getRecipients ( Message . RecipientType . BCC ));
if ( bcc != null ) System . out . println ( "Bcc: " + bcc );
String subject = messages [ i ]. getSubject ();
if ( subject != null ) System . out . println ( "Subject: " + subject );
Date sent = messages [ i ]. getSentDate ();
if ( sent != null ) System . out . println ( "Sent: " + sent );
Date received = messages [ i ]. getReceivedDate ();
if ( received != null ) System . out . println ( "Received: " + received );
System . out . println ();
}
// Close the connection
// but don't remove the messages from the server
folder . close ( false );
} catch ( MessagingException ex ) {
ex . printStackTrace ();
}
// Since we may have brought up a GUI to authenticate,
// we can't rely on returning from main() to exit
System . exit ( 0 );
}
}
Here's some typical output. Several of the requested strings were null because the fields
simply weren't present in the messages in the INBOX; for instance, Cc: and Bcc:. Head
erClient checks for the fields and simply omits them if they're not present.
% java HeaderClient pop3://eharold@utopia.poly.edu/INBOX
------------ Message 1 ------------
From: Elliotte Harold <eharold@utopia.poly.edu>
Reply-to: Elliotte Harold <eharold@utopia.poly.edu>
To: eharold@utopia.poly.edu
Subject: test
Sent: Mon Nov 30 13:14:29 PST 2009
------------ Message 2 ------------
From: Elliotte Rusty Harold <elharo@macfaq.com>
Reply-to: Elliotte Rusty Harold <elharo@macfaq.com>
To: eharold@utopia.poly.edu
Subject: New system
Sent: Tue Dec 01 10:55:40 PST 2009
------------ Message 3 ------------
From: Dr. Mickel <Greatsmiles@mail.com>
Reply-to: Dr. Mickel <Greatsmiles@mail.com>
Search WWH ::




Custom Search