Skip to content
This repository was archived by the owner on Dec 11, 2023. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ public String build()
output.append(" <th>From</th>\n");
output.append(" <th>To</th>\n");
output.append(" <th>Subject</th>\n");
output.append(" <th>Details</th>\n");
output.append(" <th>Action</th>\n");
output.append(" </thead>\n");
output.append(" <tbody>\n");
Expand Down Expand Up @@ -77,7 +78,8 @@ private String buildMailRow(MockMail mail)
"<tr>\n" +
" <td>" + fromOutput + "</td>\n" +
" <td>" + toOutput + "</td>\n" +
" <td><a title=\"" + StringEscapeUtils.escapeHtml(mail.getSubject()) + "\" href=\"/view/" + mail.getId() + "\">" + subjectOutput + "</a></td>\n" +
" <td><a title=\"" + StringEscapeUtils.escapeHtml(mail.getSubject()) + "\" href=\"/view/html/" + mail.getId() + "\">" + subjectOutput + "</a></td>\n" +
" <td><a title=\"View detailed info\" href=\"/view/" + mail.getId() + "\"><em>Details</em></a></td>\n" +
" <td><a title=\"Delete this mail\" href=\"/delete/" + mail.getId() + "\"><em>Delete</em></a></td>\n" +
"</tr>";
}
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/com/mockmock/mail/MockMail.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,14 @@ public class MockMail implements Comparable<MockMail>
private String rawMail;
private MimeMessage mimeMessage;
private long receivedTime;
private String fail;

public String getFail(){
return fail;
}
public void setFail(String fail){
this.fail = fail;
}

public long getId()
{
Expand Down
31 changes: 17 additions & 14 deletions src/main/java/com/mockmock/mail/MockMockMessageHandlerFactory.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@
@Service
public class MockMockMessageHandlerFactory implements MessageHandlerFactory
{
private EventBus eventBus;
private final EventBus eventBus;
private Settings settings;

@Autowired
Expand Down Expand Up @@ -57,7 +57,7 @@ public MockMockHandler(MessageContext context)
this.mockMail = new MockMail();

// give the mockmail a unique id (currently its just a timestamp in ms)
this.mockMail.setId(DateTime.now().getMillis());
this.mockMail.setId(System.nanoTime());
}

/**
Expand Down Expand Up @@ -101,19 +101,19 @@ public void recipient(String recipient) throws RejectException
* Called when the DATA part of the SMTP exchange begins.
* @param data InputStream
* @throws RejectException never
* @throws IOException if there is a problem getting the message contents
*/
@Override
public void data(InputStream data) throws RejectException, IOException
public void data(InputStream data) throws RejectException
{
String rawMail = this.convertStreamToString(data);
mockMail.setRawMail(rawMail);

Session session = Session.getDefaultInstance(new Properties());
InputStream is = new ByteArrayInputStream(rawMail.getBytes());


try
{
String rawMail = this.convertStreamToString(data);
mockMail.setRawMail(rawMail);

Session session = Session.getDefaultInstance(new Properties());
InputStream is = new ByteArrayInputStream(rawMail.getBytes());

MimeMessage message = new MimeMessage(session, is);
mockMail.setSubject(message.getSubject());
mockMail.setMimeMessage(message);
Expand Down Expand Up @@ -155,9 +155,9 @@ else if(contentType.matches("text/html.*"))
}
}
}
catch (MessagingException e)
catch (MessagingException | IOException e)
{
e.printStackTrace();
mockMail.setFail(e.getClass().getSimpleName() + ": " + e.getMessage());
}

if(settings.getShowEmailInConsole())
Expand Down Expand Up @@ -186,6 +186,9 @@ public void done()
return;
}

if(mockMail.getFail() != null){
return;
}
// set the received date
mockMail.setReceivedTime(DateTime.now().getMillis());

Expand All @@ -202,7 +205,7 @@ public void done()
* @param is InputStream
* @return String
*/
protected String convertStreamToString(InputStream is)
protected String convertStreamToString(InputStream is) throws MessagingException
{
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder stringBuilder = new StringBuilder();
Expand All @@ -218,7 +221,7 @@ protected String convertStreamToString(InputStream is)
}
catch (IOException e)
{
e.printStackTrace();
throw new MessagingException("Error while converting email", e);
}

return stringBuilder.toString();
Expand Down