jakartaee / jakartaee/mail-api

Duplicated Message-ID

Open
#595 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
285
Forks
109
Avg merge
15h 19m
Merged PRs (30d)
1

Description

**Describe the bug**
Same Message-ID emails are sent from different processes on our Linux server

**To Reproduce**
Steps to reproduce the behavior:
- two crontab entries are configured on Linux crontab, with same date/time entry
- these crontab entries runs Java processes with different java classes created by us
- emails are created by our program and sent to us
- the content / recipient / subject of these emails are slightly different
- when millisecond of these two processes exactly matches with these processes, email's Message-ID will be duplicated

**Expected behavior**
- different Message-ID should be generated from two different processes because it should be globally unique

**Screenshots**
If applicable, add screenshots to help explain your problem.

**Desktop (please complete the following information):**
- OS: [e.g. iOS]
- Browser [e.g. chrome, safari]
- Version [e.g. 22]

**Smartphone (please complete the following information):**
- Device: [e.g. iPhone6]
- OS: [e.g. iOS8.1]
- Browser [e.g. stock browser, safari]
- Version [e.g. 22]

**Mail server:**
SMTP

**Additional context**

Following is the source code that generates Message-ID:
UniqueValue class:
public static String getUniqueMessageIDValue(Session ssn) {
String suffix = null;

InternetAddress addr = InternetAddress.getLocalAddress(ssn);
if (addr != null)
suffix = addr.getAddress();
else {
suffix = "jakartamailuser@localhost"; // worst-case default
}
int at = suffix.lastIndexOf('@');
if (at >= 0)
suffix = suffix.substring(at);

StringBuilder s = new StringBuilder();

// Unique string is ..
s.append(s.hashCode()).append('.').
append(id.getAndIncrement()).append('.').
append(System.currentTimeMillis()).
append(suffix);
return s.toString();
}

It can be modified to followings:
- add "ProcessID" info to hashcode.id.time part
- currentTimeMillis() can be modified to system.nanoTime()
- add md5 value of these text to hsahcode.id.time part: [subject]-[destination]-[body text]

Contributor guide

Open the contributing guide

Research direction

Start with the UniqueValue.getUniqueMessageIDValue method shown in the issue and trace where it is used to generate Message-ID values. Reproduce two concurrent processes with matching millisecond timestamps, then review the existing tests or add a focused regression test. Done means independently running processes no longer produce duplicate Message-ID values under the reported conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
api
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.