Skip to content
This repository was archived by the owner on Aug 20, 2025. It is now read-only.

Commit f7de824

Browse files
committed
Message.setRecipient(type, null) should remove recipients - bug 7536
1 parent ef7e541 commit f7de824

3 files changed

Lines changed: 24 additions & 5 deletions

File tree

doc/release/CHANGES.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ K 7506 MailHandler verify should load additional content handlers
3636
K 7512 NullPointerException if SASL is enabled on Android
3737
K 7513 write timeouts don't work with SSL on Android
3838
K 7529 JavaMail allows injection of unwanted headers
39+
K 7536 Message.setRecipient(type, null) should remove recipients
3940

4041

4142
CHANGES IN THE 1.5.5 RELEASE

mail/src/main/java/javax/mail/Message.java

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 1997-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -374,9 +374,13 @@ public abstract void setRecipients(RecipientType type, Address[] addresses)
374374
*/
375375
public void setRecipient(RecipientType type, Address address)
376376
throws MessagingException {
377-
Address[] a = new Address[1];
378-
a[0] = address;
379-
setRecipients(type, a);
377+
if (address == null)
378+
setRecipients(type, null);
379+
else {
380+
Address[] a = new Address[1];
381+
a[0] = address;
382+
setRecipients(type, a);
383+
}
380384
}
381385

382386
/**

mail/src/test/java/javax/mail/internet/MimeMessageTest.java

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
/*
22
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
33
*
4-
* Copyright (c) 1997-2013 Oracle and/or its affiliates. All rights reserved.
4+
* Copyright (c) 1997-2016 Oracle and/or its affiliates. All rights reserved.
55
*
66
* The contents of this file are subject to the terms of either the GNU
77
* General Public License Version 2 only ("GPL") or the Common Development
@@ -81,6 +81,20 @@ public void testSetRecipientsStringNull() throws Exception {
8181
assertArrayEquals("To: is removed", null, m.getRecipients(TO));
8282
}
8383

84+
/**
85+
* Test that setRecipient with a null string address removes the header.
86+
* (Bug 7536)
87+
*/
88+
@Test
89+
public void testSetRecipientStringNull() throws Exception {
90+
String addr = "joe@example.com";
91+
MimeMessage m = new MimeMessage(s);
92+
m.setRecipient(TO, new InternetAddress(addr));
93+
assertEquals("To: is set", addr, m.getRecipients(TO)[0].toString());
94+
m.setRecipient(TO, (Address)null);
95+
assertArrayEquals("To: is removed", null, m.getRecipients(TO));
96+
}
97+
8498
/**
8599
* Test that copying a DataHandler from one message to another
86100
* has the desired effect.

0 commit comments

Comments
 (0)