Java Code Examples for javax.mail.Message#getSentDate()
The following examples show how to use
javax.mail.Message#getSentDate() .
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: JavaMailSenderTests.java From spring-analysis-note with MIT License | 6 votes |
@Override public void sendMessage(Message message, Address[] addresses) throws MessagingException { if ("fail".equals(message.getSubject())) { throw new MessagingException("failed"); } if (addresses == null || (message.getAllRecipients() == null ? addresses.length > 0 : !ObjectUtils.nullSafeEquals(addresses, message.getAllRecipients()))) { throw new MessagingException("addresses not correct"); } if (message.getSentDate() == null) { throw new MessagingException("No sentDate specified"); } if (message.getSubject() != null && message.getSubject().contains("custom")) { assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate()); } this.sentMessages.add(message); }
Example 2
Source File: JavaMailSenderTests.java From java-technology-stack with MIT License | 6 votes |
@Override public void sendMessage(Message message, Address[] addresses) throws MessagingException { if ("fail".equals(message.getSubject())) { throw new MessagingException("failed"); } if (addresses == null || (message.getAllRecipients() == null ? addresses.length > 0 : !ObjectUtils.nullSafeEquals(addresses, message.getAllRecipients()))) { throw new MessagingException("addresses not correct"); } if (message.getSentDate() == null) { throw new MessagingException("No sentDate specified"); } if (message.getSubject() != null && message.getSubject().contains("custom")) { assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate()); } this.sentMessages.add(message); }
Example 3
Source File: SentDateTerm.java From FairEmail with GNU General Public License v3.0 | 6 votes |
/** * The match method. * * @param msg the date comparator is applied to this Message's * sent date * @return true if the comparison succeeds, otherwise false */ @Override public boolean match(Message msg) { Date d; try { d = msg.getSentDate(); } catch (Exception e) { return false; } if (d == null) return false; return super.match(d); }
Example 4
Source File: JavaMailSenderTests.java From spring4-understanding with Apache License 2.0 | 6 votes |
@Override public void sendMessage(Message message, Address[] addresses) throws MessagingException { if ("fail".equals(message.getSubject())) { throw new MessagingException("failed"); } if (!ObjectUtils.nullSafeEquals(addresses, message.getAllRecipients())) { throw new MessagingException("addresses not correct"); } if (message.getSentDate() == null) { throw new MessagingException("No sentDate specified"); } if (message.getSubject() != null && message.getSubject().contains("custom")) { assertEquals(new GregorianCalendar(2005, 3, 1).getTime(), message.getSentDate()); } this.sentMessages.add(message); }
Example 5
Source File: Mail.java From camunda-bpm-mail with Apache License 2.0 | 6 votes |
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 6
Source File: EmailReader.java From baleen with Apache License 2.0 | 5 votes |
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: cfPOP3.java From openbd-core with GNU General Public License v3.0 | 5 votes |
private void populateMessage( cfSession _Session, Message thisMessage, cfQueryResultData popData, boolean GetAll, File attachmentDir, Folder _parent ) throws Exception { popData.addRow( 1 ); int Row = popData.getNoRows(); Date date = thisMessage.getSentDate(); if ( date != null ){ cfDateData cfdate = new cfDateData( date ); cfdate.setPOPDate(); popData.setCell( Row, 1, cfdate ); }else{ popData.setCell( Row, 1, new cfStringData("") ); } popData.setCell( Row, 2, new cfStringData( formatAddress( thisMessage.getFrom() ) ) ); popData.setCell( Row, 3, new cfNumberData( thisMessage.getMessageNumber() ) ); popData.setCell( Row, 4, new cfStringData( formatAddress( thisMessage.getReplyTo() ) ) ); popData.setCell( Row, 5, new cfStringData( thisMessage.getSubject() ) ); popData.setCell( Row, 6, new cfStringData( formatAddress( thisMessage.getRecipients(Message.RecipientType.CC) ) ) ); popData.setCell( Row, 7, new cfStringData( formatAddress( thisMessage.getRecipients(Message.RecipientType.TO) ) ) ); String [] msgid = thisMessage.getHeader( "Message-ID" ); popData.setCell( Row, 8, new cfStringData( msgid != null ? msgid[0] : "" ) ); popData.setCell( Row, 9, new cfStringData( getMessageUID( _parent, thisMessage ) ) ); popData.setCell( Row, 10, new cfStringData( formatHeader( thisMessage ) ) ); if ( GetAll ){ retrieveBody( _Session, thisMessage, popData, Row, attachmentDir ); } }
Example 8
Source File: MimeFileObject.java From commons-vfs with Apache License 2.0 | 5 votes |
/** * 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 |
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: cfMailMessageData.java From openbd-core with GNU General Public License v3.0 | 4 votes |
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 11
Source File: cfMailFolderMessagesData.java From openbd-core with GNU General Public License v3.0 | 4 votes |
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 12
Source File: MailAccount.java From projectforge-webapp with GNU General Public License v3.0 | 4 votes |
protected void setEnvelope(final Mail mail, final Message message) throws javax.mail.MessagingException { mail.setMessage(message); Address[] addr; // ID mail.setMessageNumber(message.getMessageNumber()); // FROM StringBuffer buf = new StringBuffer(); addr = message.getFrom(); if (addr != null) { for (int j = 0; j < addr.length; j++) { if (j > 0) buf.append(","); buf.append(addr[j].toString()); } } mail.setFrom(buf.toString()); // TO addr = message.getRecipients(Message.RecipientType.TO); buf = new StringBuffer(); if (addr != null) { for (int j = 0; j < addr.length; j++) { if (j > 0) buf.append(","); buf.append(addr[j].toString()); } } mail.setTo(buf.toString()); // SUBJECT mail.setSubject(message.getSubject()); // DATE final Date date = message.getSentDate(); if (date != null) { mail.setDate(date); } else { // Needed for compareTo (assume 1.1.1970) mail.setDate(new Date(0)); } // FLAGS final Flags flags = message.getFlags(); final Flags.Flag[] systemFlags = flags.getSystemFlags(); // get the system flags for (int i = 0; i < systemFlags.length; i++) { final Flags.Flag flag = systemFlags[i]; if (flag == Flags.Flag.ANSWERED) { // Ignore this flag } else if (flag == Flags.Flag.DELETED) { mail.setDeleted(true); } else if (flag == Flags.Flag.DRAFT) { // Ignore this flag } else if (flag == Flags.Flag.FLAGGED) { // Ignore this flag } else if (flag == Flags.Flag.RECENT) { mail.setRecent(true); } else if (flag == Flags.Flag.SEEN) { mail.setSeen(true); } else { // skip it } } }
Example 13
Source File: MailInput.java From pentaho-kettle with Apache License 2.0 | 4 votes |
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; }