recordsColl = new Vector<URLName>(records.length);
for (int i = 0; i < records.length; i++)
{
MXRecord mx = (MXRecord) records[i];
String targetString = mx.getTarget().toString();
URLName uName = new URLName(
SMTP_PROTOCOL_PREFIX +
targetString.substring(0, targetString.length() - 1)
);
recordsColl.add(uName);
}
}else
{
foundOriginalMX = false;
recordsColl = new Vector<URLName>();
}
/*
* If we found no MX record for the original hostname (the upper
* level domains does not matter), then we add the original domain
* name (identified with an A record) to the record collection,
* because the mail exchange server could be the main server too.
*
* We append the A record to the first place of the record
* collection, because the standard says if no MX record found then
* we should to try send email to the server identified by the A
* record.
*/
if( !foundOriginalMX )
{
Record[] recordsTypeA = new Lookup(hostName, Type.A).run();
if (recordsTypeA != null && recordsTypeA.length > 0)
{
recordsColl.add(0, new URLName(SMTP_PROTOCOL_PREFIX + hostName));
}
}
} catch (TextParseException e) {
AspirinInternal.getConfiguration().getLogger().warn("DnsResolver.getMXRecordsForHost(): Failed get MX record for host '"+hostName+"'.",e);