Java Code Examples for javax.mail.Message#getAllHeaders()

The following examples show how to use javax.mail.Message#getAllHeaders() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: cfPOP3.java    From openbd-core with GNU General Public License v3.0 5 votes vote down vote up
private static String formatHeader( Message thisMessage ) throws Exception {
	Enumeration<Header> E	= thisMessage.getAllHeaders();
	StringBuilder	tmp	= new StringBuilder(128);
	while (E.hasMoreElements()){
		Header hdr = E.nextElement();
		tmp.append( hdr.getName() );
		tmp.append( ": " );
		tmp.append( hdr.getValue() );
		tmp.append( "\r\n" );
	}
	
	return tmp.toString();
}
 
Example 2
Source File: cfMailMessageData.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
private boolean extractMessage( Message Mess, long messageID, String attachURI, String attachDIR ){
cfArrayData ADD	= cfArrayData.createArray(1);

try{

	setData( "subject", 	new cfStringData( Mess.getSubject() ) );
	setData( "id",				new cfNumberData( messageID ) );
	
	//--- Pull out all the headers
	cfStructData	headers	= new cfStructData();
	Enumeration<Header> eH	= Mess.getAllHeaders();
	String headerKey;
	while (eH.hasMoreElements()){
		Header hdr	= eH.nextElement();
		
		headerKey = hdr.getName().replace('-','_').toLowerCase();
		if ( headers.containsKey(headerKey) ){
			headers.setData( headerKey, new cfStringData( headers.getData(headerKey).toString() + ";" + hdr.getValue() ) );
		}else
			headers.setData( headerKey, new cfStringData( hdr.getValue() ) );
	}
	
	setData( "headers",  headers );

	// Get the Date
    Date DD = Mess.getReceivedDate();
    if ( DD == null )
			setData( "rxddate", 	new cfDateData( System.currentTimeMillis() ) );
	  else
			setData( "rxddate", 	new cfDateData( DD.getTime() ) );


    DD = Mess.getSentDate();
    if ( DD == null )
			setData( "sentdate", 	new cfDateData( System.currentTimeMillis() ) );
	  else
			setData( "sentdate", 	new cfDateData( DD.getTime() ) );
	
	// Get the FROM field
	Address[] from	= Mess.getFrom();
	if ( from != null && from.length > 0 ){
		cfStructData sdFrom	= new cfStructData();
		String name =  ((InternetAddress)from[0]).getPersonal();
		if ( name != null )
				sdFrom.setData( "name", new cfStringData(name) );
				
		sdFrom.setData( "email", new cfStringData( ((InternetAddress)from[0]).getAddress() ) );
		setData( "from", sdFrom );
	}
	
	//--[ Get the TO/CC/BCC field
	cfArrayData	AD	= extractAddresses( Mess.getRecipients(Message.RecipientType.TO) );
	if ( AD != null )
		setData( "to", AD );

	AD	= extractAddresses( Mess.getRecipients(Message.RecipientType.CC) );
	if ( AD != null )
		setData( "cc", AD );		

	AD	= extractAddresses( Mess.getRecipients(Message.RecipientType.BCC) );
	if ( AD != null )
		setData( "bcc", AD );
		
	AD	= extractAddresses( Mess.getReplyTo() );
	if ( AD != null )
		setData( "replyto", AD );
		
	//--[ Set the flags
	setData( "answered",	cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.ANSWERED ) ) );
	setData( "deleted",		cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.DELETED ) ) );
	setData( "draft",			cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.DRAFT ) ) );
	setData( "flagged",		cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.FLAGGED ) ) );
	setData( "recent",		cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.RECENT ) ) );
	setData( "seen",			cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.SEEN ) ) );

	setData( "size",			new cfNumberData( Mess.getSize() ) );
		setData( "lines",			new cfNumberData( Mess.getLineCount() ) );
	
	String tmp	= Mess.getContentType();
	if ( tmp.indexOf(";") != -1 )
		tmp	= tmp.substring( 0, tmp.indexOf(";") );

	setData( "mimetype", new cfStringData( tmp ) );
	
	// Get the body of the email
	extractBody( Mess, ADD, attachURI, attachDIR );

}catch(Exception E){
	return false;
}
	
setData( "body",	ADD );
return true;
}