MimeMessage message = mail.getMessage();
//Loop through all the patterns
for (int i = 0; i < warrantMark.length; i++) try
{
String headerName = warrantMark[i][0]; //Get the header name
String requiredValue = warrantMark[i][1]; //Get the required value
String headerValue = message.getHeader(headerName, null); //Get the header value(s)
// We want an exact match, so only test the first value.
// If there are multiple values, the header may be
// (illegally) forged. I'll leave it as an exercise to
// others if they want to detect and report potentially
// forged headers.
if (!(requiredValue.equals(headerValue))) return null;
}
catch (Exception e)
{
log(e.toString());
return null; //if we get an exception, don't validate the mark
}
// If we get here, all headers are present and match.
return mail.getRecipients();