Move allowrcpt handling up to EmailSender to fix empty envelope
If nobody on the SMTP envelope was actually on the allowrcpt list, we were still trying to push a message into the SMTP server but it had no destinations. All SMTP servers refuse to accept the 'DATA' command in this case, as there was no 'RCPT TO' before it. The breakage occurred when I stopped CC'ing the sender of emails by default. This meant that I was no longer on the RCPT TO list for a message in my test environment, but that was the only valid address in the sendemail.allowrcpt configuration variable. Change-Id: I2e1810d3e2a8e82aa96c93f2cfd9849f7bed6e8a Signed-off-by: Shawn O. Pearce <sop@google.com>
This commit is contained in:
@@ -17,8 +17,6 @@ package org.apache.commons.net.smtp;
|
||||
import com.google.gerrit.util.ssl.BlindSSLSocketFactory;
|
||||
|
||||
import org.apache.commons.codec.binary.Base64;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.io.UnsupportedEncodingException;
|
||||
@@ -26,20 +24,16 @@ import java.net.SocketException;
|
||||
import java.security.InvalidKeyException;
|
||||
import java.security.NoSuchAlgorithmException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.crypto.Mac;
|
||||
import javax.crypto.spec.SecretKeySpec;
|
||||
import javax.net.ssl.SSLSocketFactory;
|
||||
|
||||
public class AuthSMTPClient extends SMTPClient {
|
||||
private static final Logger log = LoggerFactory.getLogger(AuthSMTPClient.class);
|
||||
private static final String UTF_8 = "UTF-8";
|
||||
|
||||
private String authTypes;
|
||||
private Set<String> allowedRcptTo;
|
||||
|
||||
public AuthSMTPClient(final String charset) {
|
||||
super(charset);
|
||||
@@ -68,45 +62,6 @@ public class AuthSMTPClient extends SMTPClient {
|
||||
}
|
||||
}
|
||||
|
||||
public void setAllowRcpt(final String[] allowed) {
|
||||
if (allowed != null && allowed.length > 0) {
|
||||
if (allowedRcptTo == null) {
|
||||
allowedRcptTo = new HashSet<String>();
|
||||
}
|
||||
for (final String addr : allowed) {
|
||||
allowedRcptTo.add(addr);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int rcpt(final String forwardPath) throws IOException {
|
||||
if (allowRcpt(forwardPath)) {
|
||||
return super.rcpt(forwardPath);
|
||||
} else {
|
||||
log.warn("Not emailing " + forwardPath + " (prohibited by allowrcpt)");
|
||||
return SMTPReply.ACTION_OK;
|
||||
}
|
||||
}
|
||||
|
||||
private boolean allowRcpt(String addr) {
|
||||
if (allowedRcptTo == null) {
|
||||
return true;
|
||||
}
|
||||
if (addr.startsWith("<") && addr.endsWith(">")) {
|
||||
addr = addr.substring(1, addr.length() - 1);
|
||||
}
|
||||
if (allowedRcptTo.contains(addr)) {
|
||||
return true;
|
||||
}
|
||||
final int at = addr.indexOf('@');
|
||||
if (at > 0) {
|
||||
return allowedRcptTo.contains(addr.substring(at))
|
||||
|| allowedRcptTo.contains(addr.substring(at + 1));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String[] getReplyStrings() {
|
||||
return _replyLines.toArray(new String[_replyLines.size()]);
|
||||
|
Reference in New Issue
Block a user