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

The following examples show how to use javax.mail.Message#getReceivedDate() . 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: YoungerTerm.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
/**
    * The match method.
    *
    * @param msg	the date comparator is applied to this Message's
    *			received date
    * @return		true if the comparison succeeds, otherwise false
    */
   @Override
   public boolean match(Message msg) {
Date d;

try {
    d = msg.getReceivedDate();
} catch (Exception e) {
    return false;
}

if (d == null)
    return false;

return d.getTime() >=
	    System.currentTimeMillis() - ((long)interval * 1000);
   }
 
Example 2
Source File: OlderTerm.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
/**
    * The match method.
    *
    * @param msg	the date comparator is applied to this Message's
    *			received date
    * @return		true if the comparison succeeds, otherwise false
    */
   @Override
   public boolean match(Message msg) {
Date d;

try {
    d = msg.getReceivedDate();
} catch (Exception e) {
    return false;
}

if (d == null)
    return false;

return d.getTime() <=
	    System.currentTimeMillis() - ((long)interval * 1000);
   }
 
Example 3
Source File: ReceivedDateTerm.java    From FairEmail with GNU General Public License v3.0 6 votes vote down vote up
/**
    * The match method.
    *
    * @param msg	the date comparator is applied to this Message's
    *			received date
    * @return		true if the comparison succeeds, otherwise false
    */
   @Override
   public boolean match(Message msg) {
Date d;

try {
    d = msg.getReceivedDate();
} catch (Exception e) {
    return false;
}

if (d == null)
    return false;

return super.match(d);
   }
 
Example 4
Source File: Mail.java    From camunda-bpm-mail with Apache License 2.0 6 votes vote down vote up
public static Mail from(Message message) throws MessagingException, IOException {
  Mail mail = new Mail();

  mail.from = InternetAddress.toString(message.getFrom());
  mail.to =  InternetAddress.toString(message.getRecipients(RecipientType.TO));
  mail.cc = InternetAddress.toString(message.getRecipients(RecipientType.CC));

  mail.subject = message.getSubject();
  mail.sentDate = message.getSentDate();
  mail.receivedDate = message.getReceivedDate();

  mail.messageNumber = message.getMessageNumber();

  if (message instanceof MimeMessage) {
    MimeMessage mimeMessage = (MimeMessage) message;
    // extract more informations
    mail.messageId = mimeMessage.getMessageID();
  }

  processMessageContent(message, mail);

  return mail;
}
 
Example 5
Source File: DefaultReceiveEmailProvider.java    From xframium-java with GNU General Public License v3.0 5 votes vote down vote up
@Override
public int compare( Message o1, Message o2 )
{
    try
    {
        if ( o1.getReceivedDate() != null && o2.getReceivedDate() != null )
        {
            if ( o1.getReceivedDate().getTime() > o2.getReceivedDate().getTime() )
                return -1;
            else if ( o1.getReceivedDate().getTime() < o2.getReceivedDate().getTime() )
                return 1;
        }
        else
        {
            if ( o1.getSentDate().getTime() > o2.getSentDate().getTime() )
                return -1;
            else if ( o1.getSentDate().getTime() < o2.getSentDate().getTime() )
                return 1;
        }

        return 0;
    }
    catch ( Exception e )
    {
        e.printStackTrace();
        return 0;
    }
}
 
Example 6
Source File: EmailReader.java    From baleen with Apache License 2.0 5 votes vote down vote up
private String generateUniqueId(Message msg) throws MessagingException {
  String sentDate = "NOSD";
  String receivedDate = "NORD";

  if (msg.getSentDate() != null) {
    sentDate = String.valueOf(msg.getSentDate().toInstant().toEpochMilli());
  }
  if (msg.getReceivedDate() != null) {
    receivedDate = String.valueOf(msg.getReceivedDate().toInstant().toEpochMilli());
  }

  String sender = getAddress(msg.getFrom()[0]);

  return joinStrings(msg.getSubject(), sender, sentDate, receivedDate);
}
 
Example 7
Source File: Email.java    From BotLibre with Eclipse Public License 1.0 5 votes vote down vote up
/**
 * Process the text sentence.
 */
public void inputSentence(String text, String subject, String userName, String targetUserName, Message message, Network network) throws MessagingException {
	Vertex input = createInputParagraph(text.trim(), network);
	Vertex user = network.createUniqueSpeaker(new Primitive(userName), Primitive.EMAIL, Utils.upTo(userName, "@"));
	user.addRelationship(Primitive.EMAIL, network.createVertex(userName));
	input.addRelationship(Primitive.INSTANTIATION, Primitive.EMAIL);
	input.getRelationship(Primitive.INPUT).addRelationship(Primitive.INSTANTIATION, Primitive.EMAIL);
	long date = 0;
	if (message.getReceivedDate() == null) {
		date = message.getSentDate().getTime();
	} else {
		date = message.getReceivedDate().getTime();
	}
	input.addRelationship(Primitive.CREATEDAT, network.createVertex(date));
	input.addRelationship(Primitive.ID, network.createVertex(message.getMessageNumber()));
	input.addRelationship(Primitive.SPEAKER, user);
	input.addRelationship(Primitive.TOPIC, network.createSentence(subject));
	// TODO, figure out reply chains
	Vertex conversation = network.createInstance(Primitive.CONVERSATION);
	Language.addToConversation(input, conversation);
	conversation.addRelationship(Primitive.SPEAKER, user);
	conversation.addRelationship(Primitive.TYPE, Primitive.EMAIL);
	if (targetUserName != null) {
		Vertex targetUser = null;
		if (targetUserName.equals(getEmailAddress())) {
			targetUser = network.createVertex(Primitive.SELF);
		} else {
			targetUser = network.createUniqueSpeaker(new Primitive(targetUserName), Primitive.EMAIL, Utils.upTo(targetUserName, "@"));
		}
		input.addRelationship(Primitive.TARGET, targetUser);
		conversation.addRelationship(Primitive.SPEAKER, targetUser);
	}
	
	//user.addRelationship(Primitive.INPUT, input);
	//user.addRelationship(Primitive.EMAIL, input);
	
	network.save();
	getBot().memory().addActiveMemory(input);
}
 
Example 8
Source File: MimeFileObject.java    From commons-vfs with Apache License 2.0 5 votes vote down vote up
/**
 * Returns the last modified time of this file.
 */
@Override
protected long doGetLastModifiedTime() throws Exception {
    final Message mm = getMessage();
    if (mm == null) {
        return -1;
    }
    if (mm.getSentDate() != null) {
        return mm.getSentDate().getTime();
    }
    if (mm.getReceivedDate() != null) {
        mm.getReceivedDate();
    }
    return 0;
}
 
Example 9
Source File: MailInput.java    From hop with Apache License 2.0 4 votes vote down vote up
Object[] parseToArray( Object[] r, Message message ) throws Exception {

      // Execute for each Input field...
      for ( int i = 0; i < data.nrFields; i++ ) {
        int index = data.totalpreviousfields + i;

        try {

          switch ( meta.getInputFields()[ i ].getColumn() ) {
            case MailInputField.COLUMN_MESSAGE_NR:
              r[ index ] = new Long( message.getMessageNumber() );
              break;
            case MailInputField.COLUMN_SUBJECT:
              r[ index ] = message.getSubject();
              break;
            case MailInputField.COLUMN_SENDER:
              r[ index ] = StringUtils.join( message.getFrom(), ";" );
              break;
            case MailInputField.COLUMN_REPLY_TO:
              r[ index ] = StringUtils.join( message.getReplyTo(), ";" );
              break;
            case MailInputField.COLUMN_RECIPIENTS:
              r[ index ] = StringUtils.join( message.getAllRecipients(), ";" );
              break;
            case MailInputField.COLUMN_DESCRIPTION:
              r[ index ] = message.getDescription();
              break;
            case MailInputField.COLUMN_BODY:
              r[ index ] = data.mailConn.getMessageBody( message );
              break;
            case MailInputField.COLUMN_RECEIVED_DATE:
              Date receivedDate = message.getReceivedDate();
              r[ index ] = receivedDate != null ? new Date( receivedDate.getTime() ) : null;
              break;
            case MailInputField.COLUMN_SENT_DATE:
              Date sentDate = message.getSentDate();
              r[ index ] = sentDate != null ? new Date( sentDate.getTime() ) : null;
              break;
            case MailInputField.COLUMN_CONTENT_TYPE:
              r[ index ] = message.getContentType();
              break;
            case MailInputField.COLUMN_FOLDER_NAME:
              r[ index ] = data.mailConn.getFolderName();
              break;
            case MailInputField.COLUMN_SIZE:
              r[ index ] = new Long( message.getSize() );
              break;
            case MailInputField.COLUMN_FLAG_DRAFT:
              r[ index ] = new Boolean( data.mailConn.isMessageDraft( message ) );
              break;
            case MailInputField.COLUMN_FLAG_FLAGGED:
              r[ index ] = new Boolean( data.mailConn.isMessageFlagged( message ) );
              break;
            case MailInputField.COLUMN_FLAG_NEW:
              r[ index ] = new Boolean( data.mailConn.isMessageNew( message ) );
              break;
            case MailInputField.COLUMN_FLAG_READ:
              r[ index ] = new Boolean( data.mailConn.isMessageRead( message ) );
              break;
            case MailInputField.COLUMN_FLAG_DELETED:
              r[ index ] = new Boolean( data.mailConn.isMessageDeleted( message ) );
              break;
            case MailInputField.COLUMN_ATTACHED_FILES_COUNT:
              r[ index ] = new Long( data.mailConn.getAttachedFilesCount( message, null ) );
              break;
            case MailInputField.COLUMN_HEADER:
              String name = meta.getInputFields()[ i ].getName();
              // *only one name
              String[] arr = { name };
              // this code was before generic epoch
              Enumeration<?> en = message.getMatchingHeaders( arr );
              if ( en == null ) {
                r[ index ] = "";
                break;
              }
              List<String> headers = new ArrayList<>();
              while ( en.hasMoreElements() ) {
                Header next = Header.class.cast( en.nextElement() );
                headers.add( next.getValue() );
              }
              // [PDI-6532] if there is no matching headers return empty String
              r[ index ] = headers.isEmpty() ? "" : StringUtils.join( headers, ";" );
              break;
            case MailInputField.COLUMN_BODY_CONTENT_TYPE:
              r[ index ] = data.mailConn.getMessageBodyContentType( message );
              break;
            default:

              break;
          }
        } catch ( Exception e ) {
          String errMsg = "Error adding value for field " + meta.getInputFields()[ i ].getName();
          throw new Exception( errMsg, e );
        }
      }
      return r;
    }
 
Example 10
Source File: EmailDataFactory.java    From bobcat with Apache License 2.0 4 votes vote down vote up
private LocalDateTime getReceivedDate(Message message) throws MessagingException {
  return message.getReceivedDate() != null ? message.getReceivedDate().toInstant()
      .atZone(ZoneId.systemDefault()).toLocalDateTime() : LocalDateTime.now();
}
 
Example 11
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;
}
 
Example 12
Source File: cfMailFolderMessagesData.java    From openbd-core with GNU General Public License v3.0 4 votes vote down vote up
private Map<String, cfData> extractMessage( Message Mess ){
 	Map<String, cfData> HT	= new FastMap<String, cfData>();
	
try{
	HT.put( "subject", 	new cfStringData( Mess.getSubject() ) );
	
	Folder parentFolder	= Mess.getFolder();
	if ( parentFolder instanceof UIDFolder )
		HT.put( "id",	new cfNumberData( ((UIDFolder)parentFolder).getUID( Mess) ) );
	else
		HT.put( "id",	new cfNumberData( Mess.getMessageNumber() ) );
	
	//--[ 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() ) );
		HT.put( "from", sdFrom );
	}
	
	//--[ Get the TO/CC/BCC field
	cfArrayData	AD	= extractAddresses( Mess.getRecipients(Message.RecipientType.TO) );
	if ( AD != null )
		HT.put( "to", AD );
    else
      HT.put( "to", cfNullData.NULL );
      

	AD	= extractAddresses( Mess.getRecipients(Message.RecipientType.CC) );
	if ( AD != null )
		HT.put( "cc", AD );		
    else
      HT.put( "cc", cfNullData.NULL );

	AD	= extractAddresses( Mess.getRecipients(Message.RecipientType.BCC) );
	if ( AD != null )
		HT.put( "bcc", AD );
    else
      HT.put( "bcc", cfNullData.NULL );

	//--[ Set the flags
	HT.put( "answered",	cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.ANSWERED ) ) );
	HT.put( "deleted",	cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.DELETED ) ) );
	HT.put( "draft",		cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.DRAFT ) ) );
	HT.put( "flagged",	cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.FLAGGED ) ) );
	HT.put( "recent",		cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.RECENT ) ) );
	HT.put( "seen",			cfBooleanData.getcfBooleanData( Mess.isSet( Flags.Flag.SEEN ) ) );

	HT.put( "size",			new cfNumberData( Mess.getSize() ) );
	HT.put( "lines",		new cfNumberData( Mess.getLineCount() ) );

    Date DD = Mess.getReceivedDate();
    if ( DD == null )
			HT.put( "rxddate", 	new cfDateData( System.currentTimeMillis() ) );
	  else
			HT.put( "rxddate", 	new cfDateData( DD.getTime() ) );


    DD = Mess.getSentDate();
    if ( DD == null )
			HT.put( "sentdate", 	new cfDateData( System.currentTimeMillis() ) );
	  else
			HT.put( "sentdate", 	new cfDateData( DD.getTime() ) );

}catch(Exception E){
  com.nary.Debug.printStackTrace( E );
}
	
return HT;  	  
}
 
Example 13
Source File: MailInput.java    From pentaho-kettle with Apache License 2.0 4 votes vote down vote up
Object[] parseToArray( Object[] r, Message message ) throws Exception {

      // Execute for each Input field...
      for ( int i = 0; i < data.nrFields; i++ ) {
        int index = data.totalpreviousfields + i;

        try {

          switch ( meta.getInputFields()[i].getColumn() ) {
            case MailInputField.COLUMN_MESSAGE_NR:
              r[index] = new Long( message.getMessageNumber() );
              break;
            case MailInputField.COLUMN_SUBJECT:
              r[index] = message.getSubject();
              break;
            case MailInputField.COLUMN_SENDER:
              r[index] = StringUtils.join( message.getFrom(), ";" );
              break;
            case MailInputField.COLUMN_REPLY_TO:
              r[index] = StringUtils.join( message.getReplyTo(), ";" );
              break;
            case MailInputField.COLUMN_RECIPIENTS:
              r[index] = StringUtils.join( message.getAllRecipients(), ";" );
              break;
            case MailInputField.COLUMN_DESCRIPTION:
              r[index] = message.getDescription();
              break;
            case MailInputField.COLUMN_BODY:
              r[index] = data.mailConn.getMessageBody( message );
              break;
            case MailInputField.COLUMN_RECEIVED_DATE:
              Date receivedDate = message.getReceivedDate();
              r[index] = receivedDate != null ? new Date( receivedDate.getTime() ) : null;
              break;
            case MailInputField.COLUMN_SENT_DATE:
              Date sentDate = message.getSentDate();
              r[index] = sentDate != null ? new Date( sentDate.getTime() ) : null;
              break;
            case MailInputField.COLUMN_CONTENT_TYPE:
              r[index] = message.getContentType();
              break;
            case MailInputField.COLUMN_FOLDER_NAME:
              r[index] = data.mailConn.getFolderName();
              break;
            case MailInputField.COLUMN_SIZE:
              r[index] = new Long( message.getSize() );
              break;
            case MailInputField.COLUMN_FLAG_DRAFT:
              r[index] = new Boolean( data.mailConn.isMessageDraft( message ) );
              break;
            case MailInputField.COLUMN_FLAG_FLAGGED:
              r[index] = new Boolean( data.mailConn.isMessageFlagged( message ) );
              break;
            case MailInputField.COLUMN_FLAG_NEW:
              r[index] = new Boolean( data.mailConn.isMessageNew( message ) );
              break;
            case MailInputField.COLUMN_FLAG_READ:
              r[index] = new Boolean( data.mailConn.isMessageRead( message ) );
              break;
            case MailInputField.COLUMN_FLAG_DELETED:
              r[index] = new Boolean( data.mailConn.isMessageDeleted( message ) );
              break;
            case MailInputField.COLUMN_ATTACHED_FILES_COUNT:
              r[index] = new Long( data.mailConn.getAttachedFilesCount( message, null ) );
              break;
            case MailInputField.COLUMN_HEADER:
              String name = meta.getInputFields()[i].getName();
              // *only one name
              String[] arr = { name };
              // this code was before generic epoch
              Enumeration<?> en = message.getMatchingHeaders( arr );
              if ( en == null ) {
                r[index] = "";
                break;
              }
              List<String> headers = new ArrayList<String>();
              while ( en.hasMoreElements() ) {
                Header next = Header.class.cast( en.nextElement() );
                headers.add( next.getValue() );
              }
              // [PDI-6532] if there is no matching headers return empty String
              r[index] = headers.isEmpty() ? "" : StringUtils.join( headers, ";" );
              break;
            case MailInputField.COLUMN_BODY_CONTENT_TYPE:
              r[index] = data.mailConn.getMessageBodyContentType( message );
              break;
            default:

              break;
          }
        } catch ( Exception e ) {
          String errMsg = "Error adding value for field " + meta.getInputFields()[i].getName();
          throw new Exception( errMsg, e );
        }
      }
      return r;
    }