in geronimo-mail_2.1_spec/src/main/java/jakarta/mail/internet/InternetAddress.java [392:440]
public static InternetAddress getLocalAddress(final Session session) {
String host = null;
String user = null;
// ok, we have several steps for resolving this. To start with, we could have a from address
// configured already, which will be a full InternetAddress string. If we don't have that, then
// we need to resolve a user and host to compose an address from.
if (session != null) {
final String address = session.getProperty("mail.from");
// if we got this, we can skip out now
if (address != null) {
try {
return new InternetAddress(address);
} catch (final AddressException e) {
// invalid address on the from...treat this as an error and return null.
return null;
}
}
// now try for user and host information. We have both session and system properties to check here.
// we'll just handle the session ones here, and check the system ones below if we're missing information.
user = session.getProperty("mail.user");
host = session.getProperty("mail.host");
}
try {
// if either user or host is null, then we check non-session sources for the information.
if (user == null) {
user = System.getProperty("user.name");
}
if (host == null) {
host = InetAddress.getLocalHost().getHostName();
}
if (user != null && host != null) {
// if we have both a user and host, we can create a local address
return new InternetAddress(user + '@' + host);
}
} catch (final AddressException e) {
// ignore
} catch (final UnknownHostException e) {
// ignore
} catch (final SecurityException e) {
// ignore
}
return null;
}