Java Code Examples for javax.mail.Message#getSubject()
The following examples show how to use
javax.mail.Message#getSubject() .
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: SubjectTerm.java From FairEmail with GNU General Public License v3.0 | 6 votes |
/** * The match method. * * @param msg the pattern match is applied to this Message's * subject header * @return true if the pattern match succeeds, otherwise false */ @Override public boolean match(Message msg) { String subj; try { subj = msg.getSubject(); } catch (Exception e) { return false; } if (subj == null) return false; return super.match(subj); }
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: Email.java From smslib-v3 with Apache License 2.0 | 6 votes |
@Override public Collection<OutboundMessage> getMessagesToSend() throws Exception { List<OutboundMessage> retValue = new ArrayList<OutboundMessage>(); Store s = this.mailSession.getStore(); s.connect(); Folder inbox = s.getFolder(getProperty("mailbox_name", "INBOX")); inbox.open(Folder.READ_WRITE); for (Message m : inbox.getMessages()) { OutboundMessage om = new OutboundMessage(m.getSubject(), m.getContent().toString()); om.setFrom(m.getFrom().toString()); om.setDate(m.getReceivedDate()); retValue.add(om); // Delete message from inbox m.setFlag(Flags.Flag.DELETED, true); } inbox.close(true); s.close(); return retValue; }
Example 7
Source File: Pop3Util.java From anyline with Apache License 2.0 | 5 votes |
/** * 删除邮件 * @param messages messages */ public static void delete(Message ...messages){ for (int i = 0, count = messages.length; i < count; i++) { Message message = messages[i]; String subject; try { subject = message.getSubject(); message.setFlag(Flags.Flag.DELETED, true); log.warn("[删除邮件][subject:{}]",subject); } catch (MessagingException e) { e.printStackTrace(); } } }
Example 8
Source File: Pop3Util.java From anyline with Apache License 2.0 | 5 votes |
/** * 标记为已读 * @param messages messages */ public static void seen(Message ...messages) { for (int i = 0, count = messages.length; i < count; i++) { Message message = messages[i]; String subject; try { subject = message.getSubject(); message.setFlag(Flags.Flag.SEEN, true); log.warn("[标记为已读][subject:{}]",subject); } catch (MessagingException e) { e.printStackTrace(); } } }
Example 9
Source File: SubjectSearchTerm.java From bobcat with Apache License 2.0 | 5 votes |
private String getSubjectFromMessage(Message msg) { String result = null; try { result = msg.getSubject(); } catch (MessagingException e) { LOGGER.error("error when getting email subject", e); } return result; }
Example 10
Source File: ClassifyBounce.java From james-project with Apache License 2.0 | 5 votes |
public Classifier(Message message) throws MessagingException { subject = message.getSubject(); try { text = getRawText(message.getContent()); } catch (IOException e) { throw (new MessagingException("Unable to extract message body.", e)); } }
Example 11
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 12
Source File: EmailDataFactory.java From bobcat with Apache License 2.0 | 4 votes |
private String getSubjectString(Message message) throws MessagingException { return message.getSubject(); }
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; }