Skip to content

Commit

Permalink
#456: MimeMessage.setFrom(null) fails instead of removing the header …
Browse files Browse the repository at this point in the history
…- test

Signed-off-by: Lukas Jungmann <lukas.jungmann@oracle.com>
  • Loading branch information
lukasj committed Jan 12, 2021
1 parent 1c83c79 commit be5c1e3
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 3 deletions.
7 changes: 7 additions & 0 deletions doc/release/CHANGES.txt
Expand Up @@ -20,6 +20,13 @@ Seven digit bug numbers are from the old Sun bug database, which is no
longer available.


CHANGES IN THE 2.0.1 RELEASE
----------------------------
The following bugs have been fixed in the 2.0.1 release.

E 456 MimeMessage.setFrom(null) fails instead of removing the header


CHANGES IN THE 2.0.0 RELEASE
----------------------------
The most important change here is the switch from javax to jakarta namespace.
Expand Down
2 changes: 1 addition & 1 deletion mail/src/main/java/jakarta/mail/internet/MimeMessage.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand Down
32 changes: 30 additions & 2 deletions mail/src/test/java/jakarta/mail/internet/MimeMessageTest.java
@@ -1,5 +1,5 @@
/*
* Copyright (c) 1997, 2020 Oracle and/or its affiliates. All rights reserved.
* Copyright (c) 1997, 2021 Oracle and/or its affiliates. All rights reserved.
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
Expand All @@ -18,7 +18,6 @@

import com.sun.mail.test.AsciiStringInputStream;
import java.io.*;
import java.nio.charset.Charset;
import java.util.Properties;
import java.util.Enumeration;

Expand All @@ -31,6 +30,7 @@
import org.junit.*;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

/**
Expand Down Expand Up @@ -72,6 +72,34 @@ public void testSetRecipientStringNull() throws Exception {
assertArrayEquals("To: is removed", null, m.getRecipients(TO));
}

/**
* Test that setFrom with a null address removes the header.
* (Bug E 456)
*/
@Test
public void testSetFromStringNull() throws Exception {
String addr = "joe@example.com";
MimeMessage m = new MimeMessage(s);
m.setFrom(new InternetAddress(addr));
assertEquals("From: is set", addr, m.getFrom()[0].toString());
m.setFrom((Address) null);
assertArrayEquals("From: is removed", null, m.getFrom());
}

/**
* Test that setSender with a null address removes the header.
* (Bug E 456)
*/
@Test
public void testSetSenderStringNull() throws Exception {
String addr = "joe@example.com";
MimeMessage m = new MimeMessage(s);
m.setSender(new InternetAddress(addr));
assertEquals("Sender: is set", addr, m.getSender().toString());
m.setSender((Address) null);
assertNull("Sender: is removed", m.getSender());
}

/**
* Test that setFrom with an address containing a newline is folded
* properly.
Expand Down

0 comments on commit be5c1e3

Please sign in to comment.