(mail.getSender() == null ? "<>" : "<" + mail.getSender()
+ ">"));
}
Enumeration headers;
InternetHeaders deliveredTo = new InternetHeaders();
if (deliveryHeader != null) {
// Copy any Delivered-To headers from the message
headers = message
.getMatchingHeaders(new String[] { deliveryHeader });
while (headers.hasMoreElements()) {
Header header = (Header) headers.nextElement();
deliveredTo.addHeader(header.getName(), header.getValue());
}
}
for (Iterator<MailAddress> i = recipients.iterator(); i.hasNext();) {
MailAddress recipient = i.next();
try {
if (deliveryHeader != null) {
// Add qmail's de facto standard Delivered-To header
message.addHeader(deliveryHeader, recipient.toString());
}
storeMail(mail.getSender(), recipient, mail);
if (deliveryHeader != null) {
if (i.hasNext()) {
// Remove headers but leave all placeholders
message.removeHeader(deliveryHeader);
headers = deliveredTo.getAllHeaders();
// And restore any original Delivered-To headers
while (headers.hasMoreElements()) {
Header header = (Header) headers.nextElement();
message.addHeader(header.getName(), header
.getValue());