Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added message ID and received date #81

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
23 changes: 22 additions & 1 deletion src/main/java/org/subethamail/wiser/Wiser.java
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,13 @@ public void deliver(String from, String recipient, InputStream data) throws TooM
log.debug("Creating message from data with " + bytes.length + " bytes");

// create a new WiserMessage.
this.messages.add(new WiserMessage(this, from, recipient, bytes));
WiserMessage mess = new WiserMessage(this, from, recipient, bytes);
if (this.messages.add(mess)) {
mess.setId( this.messages.size());
}
else {
log.error( "Failed to add new message from "+from+" to list");
}
}

/**
Expand All @@ -157,6 +163,21 @@ public List<WiserMessage> getMessages()
{
return this.messages;
}

/**
* Returns WiserMessage identified with ID.
* <p>
* Message is currently identified by position in messages array.
* Because arrays are 0 based, we need to subtract 1 to get the proper index
*/
public WiserMessage getMessage( long id )
{
if (id > 0 && id <= this.messages.size()) {
int index = (int) id-1;
return this.messages.get(index);
}
return null;
}

/**
* @return the server implementation
Expand Down
31 changes: 31 additions & 0 deletions src/main/java/org/subethamail/wiser/WiserMessage.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import java.io.ByteArrayInputStream;
import java.io.PrintStream;
import java.util.Date;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;
Expand All @@ -14,17 +15,23 @@
*/
public class WiserMessage
{
static final long NO_ID = -1L;

byte[] messageData;
Wiser wiser;
String envelopeSender;
String envelopeReceiver;
Date receivedAt;
long id = NO_ID;

WiserMessage(Wiser wiser, String envelopeSender, String envelopeReceiver, byte[] messageData)
{
this.wiser = wiser;
this.envelopeSender = envelopeSender;
this.envelopeReceiver = envelopeReceiver;
this.messageData = messageData;
this.receivedAt = new Date();
this.id = NO_ID; // id is set by Wiser.deliver
}

/**
Expand All @@ -36,6 +43,22 @@ public MimeMessage getMimeMessage() throws MessagingException
return new MimeMessage(this.wiser.getSession(), new ByteArrayInputStream(this.messageData));
}

/**
* Get message identifier
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded space.

public long getId() {
return this.id;
}

/**
* Set message identifier
*/

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unneeded space.

public void setId( long id ) {
this.id = id;
}

/**
* Get's the raw message DATA.
*/
Expand All @@ -59,6 +82,14 @@ public String getEnvelopeSender()
{
return this.envelopeSender;
}

/**
* Get's date the mail was received
*/
public Date getReceivedAt()
{
return this.receivedAt;
}

/**
* Dumps the rough contents of the message for debugging purposes
Expand Down