in javamail-api-1.4/src/main/java/javax/mail/Session.java [704:801]
private static Map loadAddressMap(ClassLoader cl) {
// we create a merged map from reading all of the potential address map entries. The locations
// searched are:
// 1. java.home/lib/javamail.address.map
// 2. META-INF/javamail.address.map
// 3. META-INF/javamail.default.address.map
//
// if all of the above searches fail, we just set up some "default" defaults.
// the format of the address.map file is defined as a property file. We can cheat and
// just use Properties.load() to read in the files.
Properties addressMap = new Properties();
// add this to the tracking map.
addressMapsByClassLoader.put(cl, addressMap);
// NOTE: We are reading these resources in reverse order of what's cited above. This allows
// user defined entries to overwrite default entries if there are similarly named items.
try {
Enumeration e = cl.getResources("META-INF/javamail.default.address.map");
while (e.hasMoreElements()) {
URL url = (URL) e.nextElement();
InputStream is = url.openStream();
try {
// load as a property file
addressMap.load(is);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
try {
Enumeration e = cl.getResources("META-INF/javamail.address.map");
while (e.hasMoreElements()) {
URL url = (URL) e.nextElement();
InputStream is = url.openStream();
try {
// load as a property file
addressMap.load(is);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
try {
File file = new File(System.getProperty("java.home"), "lib/javamail.address.map");
InputStream is = new FileInputStream(file);
try {
// load as a property file
addressMap.load(is);
} finally{
is.close();
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
try {
Enumeration e = cl.getResources("META-INF/javamail.address.map");
while (e.hasMoreElements()) {
URL url = (URL) e.nextElement();
InputStream is = url.openStream();
try {
// load as a property file
addressMap.load(is);
} finally{
is.close();
}
}
} catch (SecurityException e) {
// ignore
} catch (IOException e) {
// ignore
}
// if unable to load anything, at least create the MimeMessage-smtp protocol mapping.
if (addressMap.isEmpty()) {
addressMap.put("rfc822", "smtp");
}
return addressMap;
}