Java Reference
In-Depth Information
if ( from != null ) System . out . println ( "From: " + from );
String to = InternetAddress . toString (
messages [ i ]. getRecipients ( Message . RecipientType . TO ));
if ( to != null ) System . out . println ( "To: " + to );
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 );
System . out . println ();
// Here's the attributes...
System . out . println ( "This message is approximately "
+ messages [ i ]. getSize () + " bytes long." );
System . out . println ( "This message has approximately "
+ messages [ i ]. getLineCount () + " lines." );
String disposition = messages [ i ]. getDisposition ();
if ( disposition == null ) ; // do nothing
else if ( disposition . equals ( Part . INLINE )) {
System . out . println ( "This part should be displayed inline" );
} else if ( disposition . equals ( Part . ATTACHMENT )) {
System . out . println ( "This part is an attachment" );
String fileName = messages [ i ]. getFileName ();
if ( fileName != null ) {
System . out . println ( "The file name of this attachment is "
+ fileName );
}
}
String description = messages [ i ]. getDescription ();
if ( description != null ) {
System . out . println ( "The description of this message is "
+ description );
}
}
// 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. I used an IMAP server because most of these methods don't
work nearly as well with POP servers. IMAP servers can give you the attributes of a
message without making you download the entire message, but POP servers aren't that
sophisticated:
Search WWH ::




Custom Search