Fix bug where recipients of the same domain receive message twice
This commit is contained in:
parent
7604f4dee3
commit
72bdacf055
@ -128,9 +128,23 @@ public class DMTPConnection implements Runnable {
|
||||
private synchronized void storeMessage() {
|
||||
logger.info("Storing message " + msg.toString());
|
||||
this.msg.setId(MailboxServer.id++);
|
||||
boolean alreadyPresent;
|
||||
for (Email recipient : this.msg.getTo()) {
|
||||
alreadyPresent = false;
|
||||
logger.info("storeMessage(): checking if msg " + msg.listMessage() + " already exists for recipient " + recipient.toString());
|
||||
if (this.messageStorage.containsKey(recipient)) {
|
||||
this.messageStorage.get(recipient).add(this.msg);
|
||||
// Check if message already exists for user
|
||||
for (Message m : this.messageStorage.get(recipient)) {
|
||||
if (this.msg.getId().equals(m.getId())) {
|
||||
logger.info("storeMessage(): msg " + msg.listMessage() + " already exists for recipient " + recipient.toString());
|
||||
alreadyPresent = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
// Save only if message doesn't already exist
|
||||
if (!alreadyPresent) {
|
||||
this.messageStorage.get(recipient).add(this.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
this.msg = new Message();
|
||||
|
||||
@ -157,6 +157,9 @@ public class TransferServer implements ITransferServer, Runnable {
|
||||
logger.info("Queue not empty. Processing message...");
|
||||
Message msg = blockingQueue.take();
|
||||
logger.info("Took message " + msg.toString() + " from queue");
|
||||
HashMap<String, Boolean> sent = new HashMap<>();
|
||||
sent.put("earth.planet", false);
|
||||
sent.put("univer.ze", false);
|
||||
for (Email recipient : msg.getTo()) {
|
||||
logger.info("msg.getTo() contains: " + msg.getTo().toString());
|
||||
logger.info("Trying to send message to " + recipient.toString());
|
||||
@ -164,7 +167,10 @@ public class TransferServer implements ITransferServer, Runnable {
|
||||
try {
|
||||
port = domainLookup(recipient);
|
||||
logger.info("Domain lookup successful. Port is: " + port);
|
||||
replayMessage(msg, port);
|
||||
if (!sent.get(recipient.getDomain())) {
|
||||
replayMessage(msg, port);
|
||||
sent.put(recipient.getDomain(), true);
|
||||
}
|
||||
} catch (UnknownDomain e) {
|
||||
sendErrorMail(msg, e.getMessage());
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user