研究这个类看看package javax.mail;import com.sun.mail.util.LineInputStream;
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URL;
import java.util.*;// Referenced classes of package javax.mail:
// Address, Authenticator, MessagingException, NoSuchProviderException,
// PasswordAuthentication, Provider, Service, Store,
// Transport, URLName, Folderpublic final class Session
{ private Session(Properties properties, Authenticator authenticator1)
{
authTable = new Hashtable();
debug = false;
providers = new Vector();
providersByProtocol = new Hashtable();
providersByClassName = new Hashtable();
addressMap = new Properties();
props = properties;
authenticator = authenticator1;
if(Boolean.valueOf(properties.getProperty("mail.debug")).booleanValue())
debug = true;
Class class1;
if(authenticator1 != null)
class1 = authenticator1.getClass();
else
class1 = getClass();
loadProviders(class1);
loadAddressMap(class1);
} public static Session getInstance(Properties properties, Authenticator authenticator1)
{
return new Session(properties, authenticator1);
} public static Session getInstance(Properties properties)
{
return new Session(properties, null);
} public static Session getDefaultInstance(Properties properties, Authenticator authenticator1)
{
if(defaultSession == null)
defaultSession = new Session(properties, authenticator1);
else
if(defaultSession.authenticator != authenticator1 && (defaultSession.authenticator == null || authenticator1 == null || defaultSession.authenticator.getClass().getClassLoader() != authenticator1.getClass().getClassLoader()))
throw new SecurityException("Access to default session denied");
return defaultSession;
} public static Session getDefaultInstance(Properties properties)
{
return getDefaultInstance(properties, null);
} public void setDebug(boolean flag)
{
debug = flag;
} public boolean getDebug()
{
return debug;
} public Provider[] getProviders()
{
Provider aprovider[] = new Provider[providers.size()];
providers.copyInto(aprovider);
return aprovider;
} public Provider getProvider(String s)
throws NoSuchProviderException
{
if(s == null || s.length() <= 0)
throw new NoSuchProviderException("Invalid protocol: null");
Provider provider = null;
String s1 = props.getProperty("mail." + s + ".class");
if(s1 != null)
{
if(debug)
System.out.println("DEBUG: mail." + s + ".class property exists and points to " + s1);
provider = (Provider)providersByClassName.get(s1);
}
if(provider != null)
return provider;
provider = (Provider)providersByProtocol.get(s);
if(provider == null)
throw new NoSuchProviderException("No provider for " + s);
if(debug)
System.out.println("\nDEBUG: getProvider() returning " + provider.toString());
return provider;
} public void setProvider(Provider provider)
throws NoSuchProviderException
{
if(provider == null)
{
throw new NoSuchProviderException("Can't set null provider");
}
else
{
providersByProtocol.put(provider.getProtocol(), provider);
props.put("mail." + provider.getProtocol() + ".class", provider.getClassName());
return;
}
} public Store getStore()
throws NoSuchProviderException
{
return getStore(getProperty("mail.store.protocol"));
} public Store getStore(String s)
throws NoSuchProviderException
{
return getStore(new URLName(s, null, -1, null, null, null));
} public Store getStore(URLName urlname)
throws NoSuchProviderException
{
String s = urlname.getProtocol();
Provider provider = getProvider(s);
return getStore(provider, urlname);
} public Store getStore(Provider provider)
throws NoSuchProviderException
{
return getStore(provider, null);
} private Store getStore(Provider provider, URLName urlname)
throws NoSuchProviderException
{
if(provider == null || provider.getType() != Provider.Type.STORE)
throw new NoSuchProviderException("invalid provider");
try
{
return (Store)getService(provider, urlname);
}
catch(ClassCastException ex)
{
throw new NoSuchProviderException("incorrect class");
}
} public Folder getFolder(URLName urlname)
throws MessagingException
{
Store store = getStore(urlname);
store.connect();
return store.getFolder(urlname);
} public Transport getTransport()
throws NoSuchProviderException
{
return getTransport(getProperty("mail.transport.protocol"));
} public Transport getTransport(String s)
throws NoSuchProviderException
{
return getTransport(new URLName(s, null, -1, null, null, null));
} public Transport getTransport(URLName urlname)
throws NoSuchProviderException
{
String s = urlname.getProtocol();
Provider provider = getProvider(s);
return getTransport(provider, urlname);
} public Transport getTransport(Provider provider)
throws NoSuchProviderException
{
return getTransport(provider, null);
} public Transport getTransport(Address address)
throws NoSuchProviderException
{
String s = (String)addressMap.get(address.getType());
if(s == null)
throw new NoSuchProviderException("No provider for Address type: " + address.getType());
else
return getTransport(s);
} private Transport getTransport(Provider provider, URLName urlname)
throws NoSuchProviderException
{
if(provider == null || provider.getType() != Provider.Type.TRANSPORT)
throw new NoSuchProviderException("invalid provider");
try
{
return (Transport)getService(provider, urlname);
}
catch(ClassCastException ex)
{
throw new NoSuchProviderException("incorrect class");
}
} private Object getService(Provider provider, URLName urlname)
throws NoSuchProviderException
{
if(provider == null)
throw new NoSuchProviderException("null");
if(urlname == null)
urlname = new URLName(provider.getProtocol(), null, -1, null, null, null);
Object obj = null;
ClassLoader classloader;
if(authenticator != null)
classloader = authenticator.getClass().getClassLoader();
else
classloader = getClass().getClassLoader();
Class class1 = null;
try
{
class1 = classloader.loadClass(provider.getClassName());
}
catch(Exception ex)
{
try
{
class1 = Class.forName(provider.getClassName());
}
catch(Exception exception)
{
if(debug)
exception.printStackTrace();
throw new NoSuchProviderException(provider.getProtocol());
}
}
try
{
Class aclass[] = {
class$javax$mail$Session == null ? (class$javax$mail$Session = class$("javax.mail.Session")) : class$javax$mail$Session, class$javax$mail$URLName == null ? (class$javax$mail$URLName = class$("javax.mail.URLName")) : class$javax$mail$URLName
};
Constructor constructor = class1.getConstructor(aclass);
Object aobj[] = {
this, urlname
};
obj = constructor.newInstance(aobj);
}
catch(Exception exception1)
{
if(debug)
exception1.printStackTrace();
throw new NoSuchProviderException(provider.getProtocol());
}
return obj;
} public void setPasswordAuthentication(URLName urlname, PasswordAuthentication passwordauthentication)
{
if(passwordauthentication == null)
{
authTable.remove(urlname);
return;
}
else
{
authTable.put(urlname, passwordauthentication);
return;
}
} public PasswordAuthentication getPasswordAuthentication(URLName urlname)
{
return (PasswordAuthentication)authTable.get(urlname);
} public PasswordAuthentication requestPasswordAuthentication(InetAddress inetaddress, int i, String s, String s1, String s2)
{
if(authenticator != null)
return authenticator.requestPasswordAuthentication(inetaddress, i, s, s1, s2);
else
return null;
} public Properties getProperties()
{
return props;
} public String getProperty(String s)
{
return props.getProperty(s);
} private void loadProviders(Class class1)
{
Object obj = null;
try
{
String s = System.getProperty("java.home") + File.separator + "lib" + File.separator + "javamail.providers";
BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(s));
if(bufferedinputstream != null)
{
loadProvidersFromStream(bufferedinputstream);
bufferedinputstream.close();
if(debug)
pr("DEBUG: loaded providers in <java.home>/lib");
}
else
if(debug)
pr("DEBUG: not loading system providers in <java.home>/lib");
}
catch(FileNotFoundException ex)
{
if(debug)
pr("DEBUG: not loading system providers in <java.home>/lib");
}
catch(IOException ioexception)
{
if(debug)
pr("DEBUG: " + ioexception.getMessage());
}
catch(SecurityException ex)
{
if(debug)
pr("DEBUG: not loading system providers in <java.home>/lib");
}
Object obj1 = null;
String s1 = "META-INF/javamail.providers";
String s2 = "/" + s1;
boolean flag = false;
if(getResources != null)
try
{
ClassLoader classloader = class1.getClassLoader();
Enumeration enumeration;
if(classloader != null)
enumeration = (Enumeration)getResources.invoke(classloader, new String[] {
s1
});
else
enumeration = (Enumeration)getSystemResources.invoke(classloader, new String[] {
s1
});
while(enumeration.hasMoreElements())
{
URL url = (URL)enumeration.nextElement();
InputStream inputstream = url.openStream();
if(inputstream != null)
try
{
loadProvidersFromStream(inputstream);
flag = true;
inputstream.close();
if(debug)
pr("DEBUG: successfully loaded optional custom providers from URL: " + url);
}
catch(IOException ioexception3)
{
if(debug)
pr("DEBUG: " + ioexception3.getMessage());
}
else
if(debug)
pr("DEBUG: not loading optional custom providers from URL: " + url);
} }
catch(Exception exception)
{
if(debug)
pr("DEBUG: " + exception);
}
if(!flag)
{
InputStream inputstream1 = class1.getResourceAsStream(s2);
if(inputstream1 != null)
try
{
loadProvidersFromStream(inputstream1);
inputstream1.close();
if(debug)
pr("DEBUG: successfully loaded optional custom providers: " + s2);
}
catch(IOException ioexception1)
{
if(debug)
pr("DEBUG: " + ioexception1);
}
else
if(debug)
pr("DEBUG: not loading optional custom providers file: " + s2);
}
InputStream inputstream2 = null;
String s3 = "/META-INF/javamail.default.providers";
inputstream2 = class1.getResourceAsStream(s3);
if(inputstream2 != null)
try
{
loadProvidersFromStream(inputstream2);
inputstream2.close();
if(debug)
pr("DEBUG: successfully loaded default providers");
}
catch(IOException ioexception2)
{
if(debug)
pr("DEBUG: " + ioexception2.getMessage());
}
else
if(debug)
pr("DEBUG: can't load default providers file" + s3);
if(debug)
{
System.out.println("\nDEBUG: Tables of loaded providers");
pr("DEBUG: Providers Listed By Class Name: " + providersByClassName.toString());
pr("DEBUG: Providers Listed By Protocol: " + providersByProtocol.toString());
}
} private void loadProvidersFromStream(InputStream inputstream)
throws IOException
{
if(inputstream != null)
{
LineInputStream lineinputstream = new LineInputStream(inputstream);
String s;
while((s = lineinputstream.readLine()) != null)
if(!s.startsWith("#"))
{
Provider.Type type = null;
String s1 = null;
String s2 = null;
String s3 = null;
String s4 = null;
for(StringTokenizer stringtokenizer = new StringTokenizer(s, ";"); stringtokenizer.hasMoreTokens();)
{
String s5 = stringtokenizer.nextToken().trim();
int i = s5.indexOf("=");
if(s5.startsWith("protocol="))
s1 = s5.substring(i + 1);
else
if(s5.startsWith("type="))
{
String s6 = s5.substring(i + 1);
if(s6.equalsIgnoreCase("store"))
type = Provider.Type.STORE;
else
if(s6.equalsIgnoreCase("transport"))
type = Provider.Type.TRANSPORT;
}
else
if(s5.startsWith("class="))
s2 = s5.substring(i + 1);
else
if(s5.startsWith("vendor="))
s3 = s5.substring(i + 1);
else
if(s5.startsWith("version="))
s4 = s5.substring(i + 1);
} if(type == null || s1 == null || s2 == null || s1.length() <= 0 || s2.length() <= 0)
{
if(debug)
System.out.println("DEBUG: Bad provider entry: " + s);
}
else
{
Provider provider = new Provider(type, s1, s2, s3, s4);
providers.addElement(provider);
providersByClassName.put(s2, provider);
if(!providersByProtocol.containsKey(s1))
providersByProtocol.put(s1, provider);
}
} }
} private void loadAddressMap(Class class1)
{
InputStream inputstream = null;
String s = "/META-INF/javamail.default.address.map";
inputstream = class1.getResourceAsStream(s);
if(inputstream != null)
try
{
addressMap.load(inputstream);
inputstream.close();
}
catch(IOException ex) {}
catch(SecurityException ex) {}
Object obj = null;
String s1 = "META-INF/javamail.address.map";
String s2 = "/" + s1;
boolean flag = false;
if(getResources != null)
try
{
ClassLoader classloader = class1.getClassLoader();
Enumeration enumeration;
if(classloader != null)
enumeration = (Enumeration)getResources.invoke(classloader, new String[] {
s1
});
else
enumeration = (Enumeration)getSystemResources.invoke(classloader, new String[] {
s1
});
while(enumeration.hasMoreElements())
{
URL url = (URL)enumeration.nextElement();
InputStream inputstream1 = url.openStream();
if(inputstream1 != null)
try
{
addressMap.load(inputstream1);
flag = true;
inputstream1.close();
if(debug)
pr("DEBUG: successfully loaded optional address map from URL: " + url);
}
catch(IOException ioexception1)
{
if(debug)
pr("DEBUG: " + ioexception1.getMessage());
}
else
if(debug)
pr("DEBUG: not loading optional address map from URL: " + url);
} }
catch(Exception exception)
{
if(debug)
pr("DEBUG: " + exception);
}
if(!flag)
{
InputStream inputstream2 = class1.getResourceAsStream(s2);
if(inputstream2 != null)
try
{
addressMap.load(inputstream2);
inputstream2.close();
if(debug)
pr("DEBUG: successfully loaded optional address map: " + s2);
}
catch(IOException ioexception)
{
if(debug)
pr("DEBUG: " + ioexception);
}
else
if(debug)
pr("DEBUG: not loading optional address map file: " + s2);
}
BufferedInputStream bufferedinputstream = null;
try
{
String s3 = System.getProperty("java.home") + File.separator + "lib" + File.separator + "javamail.address.map";
bufferedinputstream = new BufferedInputStream(new FileInputStream(s3));
}
catch(FileNotFoundException ex) {}
catch(SecurityException ex) {}
if(bufferedinputstream != null)
try
{
addressMap.load(bufferedinputstream);
bufferedinputstream.close();
return;
}
catch(IOException ex)
{
return;
}
else
return;
} private static void pr(String s)
{
System.out.println(s);
} static Class class$(String s)
{
try
{
return Class.forName(s);
}
catch(ClassNotFoundException classnotfoundexception)
{
throw new NoClassDefFoundError(classnotfoundexception.getMessage());
}
} private Properties props;
private Authenticator authenticator;
private Hashtable authTable;
private boolean debug;
private Vector providers;
private Hashtable providersByProtocol;
private Hashtable providersByClassName;
private Properties addressMap;
private static Method getResources = null;
private static Method getSystemResources = null;
private static Session defaultSession = null;
static Class class$java$lang$ClassLoader; /* synthetic field */
static Class class$java$lang$String; /* synthetic field */
static Class class$javax$mail$Session; /* synthetic field */
static Class class$javax$mail$URLName; /* synthetic field */ static
{
try
{
Class class1 = class$java$lang$ClassLoader == null ? (class$java$lang$ClassLoader = class$("java.lang.ClassLoader")) : class$java$lang$ClassLoader;
getResources = class1.getMethod("getResources", new Class[] {
class$java$lang$String == null ? (class$java$lang$String = class$("java.lang.String")) : class$java$lang$String
});
getSystemResources = class1.getMethod("getSystemResources", new Class[] {
class$java$lang$String == null ? (class$java$lang$String = class$("java.lang.String")) : class$java$lang$String
});
}
catch(Throwable ex) {}
}
}
import java.io.*;
import java.lang.reflect.Constructor;
import java.lang.reflect.Method;
import java.net.InetAddress;
import java.net.URL;
import java.util.*;// Referenced classes of package javax.mail:
// Address, Authenticator, MessagingException, NoSuchProviderException,
// PasswordAuthentication, Provider, Service, Store,
// Transport, URLName, Folderpublic final class Session
{ private Session(Properties properties, Authenticator authenticator1)
{
authTable = new Hashtable();
debug = false;
providers = new Vector();
providersByProtocol = new Hashtable();
providersByClassName = new Hashtable();
addressMap = new Properties();
props = properties;
authenticator = authenticator1;
if(Boolean.valueOf(properties.getProperty("mail.debug")).booleanValue())
debug = true;
Class class1;
if(authenticator1 != null)
class1 = authenticator1.getClass();
else
class1 = getClass();
loadProviders(class1);
loadAddressMap(class1);
} public static Session getInstance(Properties properties, Authenticator authenticator1)
{
return new Session(properties, authenticator1);
} public static Session getInstance(Properties properties)
{
return new Session(properties, null);
} public static Session getDefaultInstance(Properties properties, Authenticator authenticator1)
{
if(defaultSession == null)
defaultSession = new Session(properties, authenticator1);
else
if(defaultSession.authenticator != authenticator1 && (defaultSession.authenticator == null || authenticator1 == null || defaultSession.authenticator.getClass().getClassLoader() != authenticator1.getClass().getClassLoader()))
throw new SecurityException("Access to default session denied");
return defaultSession;
} public static Session getDefaultInstance(Properties properties)
{
return getDefaultInstance(properties, null);
} public void setDebug(boolean flag)
{
debug = flag;
} public boolean getDebug()
{
return debug;
} public Provider[] getProviders()
{
Provider aprovider[] = new Provider[providers.size()];
providers.copyInto(aprovider);
return aprovider;
} public Provider getProvider(String s)
throws NoSuchProviderException
{
if(s == null || s.length() <= 0)
throw new NoSuchProviderException("Invalid protocol: null");
Provider provider = null;
String s1 = props.getProperty("mail." + s + ".class");
if(s1 != null)
{
if(debug)
System.out.println("DEBUG: mail." + s + ".class property exists and points to " + s1);
provider = (Provider)providersByClassName.get(s1);
}
if(provider != null)
return provider;
provider = (Provider)providersByProtocol.get(s);
if(provider == null)
throw new NoSuchProviderException("No provider for " + s);
if(debug)
System.out.println("\nDEBUG: getProvider() returning " + provider.toString());
return provider;
} public void setProvider(Provider provider)
throws NoSuchProviderException
{
if(provider == null)
{
throw new NoSuchProviderException("Can't set null provider");
}
else
{
providersByProtocol.put(provider.getProtocol(), provider);
props.put("mail." + provider.getProtocol() + ".class", provider.getClassName());
return;
}
} public Store getStore()
throws NoSuchProviderException
{
return getStore(getProperty("mail.store.protocol"));
} public Store getStore(String s)
throws NoSuchProviderException
{
return getStore(new URLName(s, null, -1, null, null, null));
} public Store getStore(URLName urlname)
throws NoSuchProviderException
{
String s = urlname.getProtocol();
Provider provider = getProvider(s);
return getStore(provider, urlname);
} public Store getStore(Provider provider)
throws NoSuchProviderException
{
return getStore(provider, null);
} private Store getStore(Provider provider, URLName urlname)
throws NoSuchProviderException
{
if(provider == null || provider.getType() != Provider.Type.STORE)
throw new NoSuchProviderException("invalid provider");
try
{
return (Store)getService(provider, urlname);
}
catch(ClassCastException ex)
{
throw new NoSuchProviderException("incorrect class");
}
} public Folder getFolder(URLName urlname)
throws MessagingException
{
Store store = getStore(urlname);
store.connect();
return store.getFolder(urlname);
} public Transport getTransport()
throws NoSuchProviderException
{
return getTransport(getProperty("mail.transport.protocol"));
} public Transport getTransport(String s)
throws NoSuchProviderException
{
return getTransport(new URLName(s, null, -1, null, null, null));
} public Transport getTransport(URLName urlname)
throws NoSuchProviderException
{
String s = urlname.getProtocol();
Provider provider = getProvider(s);
return getTransport(provider, urlname);
} public Transport getTransport(Provider provider)
throws NoSuchProviderException
{
return getTransport(provider, null);
} public Transport getTransport(Address address)
throws NoSuchProviderException
{
String s = (String)addressMap.get(address.getType());
if(s == null)
throw new NoSuchProviderException("No provider for Address type: " + address.getType());
else
return getTransport(s);
} private Transport getTransport(Provider provider, URLName urlname)
throws NoSuchProviderException
{
if(provider == null || provider.getType() != Provider.Type.TRANSPORT)
throw new NoSuchProviderException("invalid provider");
try
{
return (Transport)getService(provider, urlname);
}
catch(ClassCastException ex)
{
throw new NoSuchProviderException("incorrect class");
}
} private Object getService(Provider provider, URLName urlname)
throws NoSuchProviderException
{
if(provider == null)
throw new NoSuchProviderException("null");
if(urlname == null)
urlname = new URLName(provider.getProtocol(), null, -1, null, null, null);
Object obj = null;
ClassLoader classloader;
if(authenticator != null)
classloader = authenticator.getClass().getClassLoader();
else
classloader = getClass().getClassLoader();
Class class1 = null;
try
{
class1 = classloader.loadClass(provider.getClassName());
}
catch(Exception ex)
{
try
{
class1 = Class.forName(provider.getClassName());
}
catch(Exception exception)
{
if(debug)
exception.printStackTrace();
throw new NoSuchProviderException(provider.getProtocol());
}
}
try
{
Class aclass[] = {
class$javax$mail$Session == null ? (class$javax$mail$Session = class$("javax.mail.Session")) : class$javax$mail$Session, class$javax$mail$URLName == null ? (class$javax$mail$URLName = class$("javax.mail.URLName")) : class$javax$mail$URLName
};
Constructor constructor = class1.getConstructor(aclass);
Object aobj[] = {
this, urlname
};
obj = constructor.newInstance(aobj);
}
catch(Exception exception1)
{
if(debug)
exception1.printStackTrace();
throw new NoSuchProviderException(provider.getProtocol());
}
return obj;
} public void setPasswordAuthentication(URLName urlname, PasswordAuthentication passwordauthentication)
{
if(passwordauthentication == null)
{
authTable.remove(urlname);
return;
}
else
{
authTable.put(urlname, passwordauthentication);
return;
}
} public PasswordAuthentication getPasswordAuthentication(URLName urlname)
{
return (PasswordAuthentication)authTable.get(urlname);
} public PasswordAuthentication requestPasswordAuthentication(InetAddress inetaddress, int i, String s, String s1, String s2)
{
if(authenticator != null)
return authenticator.requestPasswordAuthentication(inetaddress, i, s, s1, s2);
else
return null;
} public Properties getProperties()
{
return props;
} public String getProperty(String s)
{
return props.getProperty(s);
} private void loadProviders(Class class1)
{
Object obj = null;
try
{
String s = System.getProperty("java.home") + File.separator + "lib" + File.separator + "javamail.providers";
BufferedInputStream bufferedinputstream = new BufferedInputStream(new FileInputStream(s));
if(bufferedinputstream != null)
{
loadProvidersFromStream(bufferedinputstream);
bufferedinputstream.close();
if(debug)
pr("DEBUG: loaded providers in <java.home>/lib");
}
else
if(debug)
pr("DEBUG: not loading system providers in <java.home>/lib");
}
catch(FileNotFoundException ex)
{
if(debug)
pr("DEBUG: not loading system providers in <java.home>/lib");
}
catch(IOException ioexception)
{
if(debug)
pr("DEBUG: " + ioexception.getMessage());
}
catch(SecurityException ex)
{
if(debug)
pr("DEBUG: not loading system providers in <java.home>/lib");
}
Object obj1 = null;
String s1 = "META-INF/javamail.providers";
String s2 = "/" + s1;
boolean flag = false;
if(getResources != null)
try
{
ClassLoader classloader = class1.getClassLoader();
Enumeration enumeration;
if(classloader != null)
enumeration = (Enumeration)getResources.invoke(classloader, new String[] {
s1
});
else
enumeration = (Enumeration)getSystemResources.invoke(classloader, new String[] {
s1
});
while(enumeration.hasMoreElements())
{
URL url = (URL)enumeration.nextElement();
InputStream inputstream = url.openStream();
if(inputstream != null)
try
{
loadProvidersFromStream(inputstream);
flag = true;
inputstream.close();
if(debug)
pr("DEBUG: successfully loaded optional custom providers from URL: " + url);
}
catch(IOException ioexception3)
{
if(debug)
pr("DEBUG: " + ioexception3.getMessage());
}
else
if(debug)
pr("DEBUG: not loading optional custom providers from URL: " + url);
} }
catch(Exception exception)
{
if(debug)
pr("DEBUG: " + exception);
}
if(!flag)
{
InputStream inputstream1 = class1.getResourceAsStream(s2);
if(inputstream1 != null)
try
{
loadProvidersFromStream(inputstream1);
inputstream1.close();
if(debug)
pr("DEBUG: successfully loaded optional custom providers: " + s2);
}
catch(IOException ioexception1)
{
if(debug)
pr("DEBUG: " + ioexception1);
}
else
if(debug)
pr("DEBUG: not loading optional custom providers file: " + s2);
}
InputStream inputstream2 = null;
String s3 = "/META-INF/javamail.default.providers";
inputstream2 = class1.getResourceAsStream(s3);
if(inputstream2 != null)
try
{
loadProvidersFromStream(inputstream2);
inputstream2.close();
if(debug)
pr("DEBUG: successfully loaded default providers");
}
catch(IOException ioexception2)
{
if(debug)
pr("DEBUG: " + ioexception2.getMessage());
}
else
if(debug)
pr("DEBUG: can't load default providers file" + s3);
if(debug)
{
System.out.println("\nDEBUG: Tables of loaded providers");
pr("DEBUG: Providers Listed By Class Name: " + providersByClassName.toString());
pr("DEBUG: Providers Listed By Protocol: " + providersByProtocol.toString());
}
} private void loadProvidersFromStream(InputStream inputstream)
throws IOException
{
if(inputstream != null)
{
LineInputStream lineinputstream = new LineInputStream(inputstream);
String s;
while((s = lineinputstream.readLine()) != null)
if(!s.startsWith("#"))
{
Provider.Type type = null;
String s1 = null;
String s2 = null;
String s3 = null;
String s4 = null;
for(StringTokenizer stringtokenizer = new StringTokenizer(s, ";"); stringtokenizer.hasMoreTokens();)
{
String s5 = stringtokenizer.nextToken().trim();
int i = s5.indexOf("=");
if(s5.startsWith("protocol="))
s1 = s5.substring(i + 1);
else
if(s5.startsWith("type="))
{
String s6 = s5.substring(i + 1);
if(s6.equalsIgnoreCase("store"))
type = Provider.Type.STORE;
else
if(s6.equalsIgnoreCase("transport"))
type = Provider.Type.TRANSPORT;
}
else
if(s5.startsWith("class="))
s2 = s5.substring(i + 1);
else
if(s5.startsWith("vendor="))
s3 = s5.substring(i + 1);
else
if(s5.startsWith("version="))
s4 = s5.substring(i + 1);
} if(type == null || s1 == null || s2 == null || s1.length() <= 0 || s2.length() <= 0)
{
if(debug)
System.out.println("DEBUG: Bad provider entry: " + s);
}
else
{
Provider provider = new Provider(type, s1, s2, s3, s4);
providers.addElement(provider);
providersByClassName.put(s2, provider);
if(!providersByProtocol.containsKey(s1))
providersByProtocol.put(s1, provider);
}
} }
} private void loadAddressMap(Class class1)
{
InputStream inputstream = null;
String s = "/META-INF/javamail.default.address.map";
inputstream = class1.getResourceAsStream(s);
if(inputstream != null)
try
{
addressMap.load(inputstream);
inputstream.close();
}
catch(IOException ex) {}
catch(SecurityException ex) {}
Object obj = null;
String s1 = "META-INF/javamail.address.map";
String s2 = "/" + s1;
boolean flag = false;
if(getResources != null)
try
{
ClassLoader classloader = class1.getClassLoader();
Enumeration enumeration;
if(classloader != null)
enumeration = (Enumeration)getResources.invoke(classloader, new String[] {
s1
});
else
enumeration = (Enumeration)getSystemResources.invoke(classloader, new String[] {
s1
});
while(enumeration.hasMoreElements())
{
URL url = (URL)enumeration.nextElement();
InputStream inputstream1 = url.openStream();
if(inputstream1 != null)
try
{
addressMap.load(inputstream1);
flag = true;
inputstream1.close();
if(debug)
pr("DEBUG: successfully loaded optional address map from URL: " + url);
}
catch(IOException ioexception1)
{
if(debug)
pr("DEBUG: " + ioexception1.getMessage());
}
else
if(debug)
pr("DEBUG: not loading optional address map from URL: " + url);
} }
catch(Exception exception)
{
if(debug)
pr("DEBUG: " + exception);
}
if(!flag)
{
InputStream inputstream2 = class1.getResourceAsStream(s2);
if(inputstream2 != null)
try
{
addressMap.load(inputstream2);
inputstream2.close();
if(debug)
pr("DEBUG: successfully loaded optional address map: " + s2);
}
catch(IOException ioexception)
{
if(debug)
pr("DEBUG: " + ioexception);
}
else
if(debug)
pr("DEBUG: not loading optional address map file: " + s2);
}
BufferedInputStream bufferedinputstream = null;
try
{
String s3 = System.getProperty("java.home") + File.separator + "lib" + File.separator + "javamail.address.map";
bufferedinputstream = new BufferedInputStream(new FileInputStream(s3));
}
catch(FileNotFoundException ex) {}
catch(SecurityException ex) {}
if(bufferedinputstream != null)
try
{
addressMap.load(bufferedinputstream);
bufferedinputstream.close();
return;
}
catch(IOException ex)
{
return;
}
else
return;
} private static void pr(String s)
{
System.out.println(s);
} static Class class$(String s)
{
try
{
return Class.forName(s);
}
catch(ClassNotFoundException classnotfoundexception)
{
throw new NoClassDefFoundError(classnotfoundexception.getMessage());
}
} private Properties props;
private Authenticator authenticator;
private Hashtable authTable;
private boolean debug;
private Vector providers;
private Hashtable providersByProtocol;
private Hashtable providersByClassName;
private Properties addressMap;
private static Method getResources = null;
private static Method getSystemResources = null;
private static Session defaultSession = null;
static Class class$java$lang$ClassLoader; /* synthetic field */
static Class class$java$lang$String; /* synthetic field */
static Class class$javax$mail$Session; /* synthetic field */
static Class class$javax$mail$URLName; /* synthetic field */ static
{
try
{
Class class1 = class$java$lang$ClassLoader == null ? (class$java$lang$ClassLoader = class$("java.lang.ClassLoader")) : class$java$lang$ClassLoader;
getResources = class1.getMethod("getResources", new Class[] {
class$java$lang$String == null ? (class$java$lang$String = class$("java.lang.String")) : class$java$lang$String
});
getSystemResources = class1.getMethod("getSystemResources", new Class[] {
class$java$lang$String == null ? (class$java$lang$String = class$("java.lang.String")) : class$java$lang$String
});
}
catch(Throwable ex) {}
}
}
package com.sun.mail.pop3;import java.io.EOFException;
import java.io.IOException;
import java.lang.reflect.Constructor;
import java.util.Vector;
import javax.mail.*;
import javax.mail.event.ConnectionEvent;
import javax.mail.internet.MimeMessage;// Referenced classes of package com.sun.mail.pop3:
// DefaultFolder, POP3Message, POP3Store, Protocol,
// Statuspublic class POP3Folder extends Folder
{ POP3Folder(POP3Store pop3store, String s)
{
super(pop3store);
exists = false;
opened = false;
doneUidl = false;
name = s;
if(s.equalsIgnoreCase("INBOX"))
exists = true;
} public String getName()
{
return name;
} public String getFullName()
{
return name;
} public Folder getParent()
{
return new DefaultFolder((POP3Store)store);
} public boolean exists()
{
return exists;
} public Folder[] list(String s)
throws MessagingException
{
throw new MessagingException("not a directory");
} public char getSeparator()
{
return 0;
} public int getType()
{
return 1;
} public boolean create(int i)
throws MessagingException
{
return false;
} public boolean hasNewMessages()
throws MessagingException
{
return false;
} public Folder getFolder(String s)
throws MessagingException
{
throw new MessagingException("not a directory");
} public boolean delete(boolean flag)
throws MessagingException
{
throw new MethodNotSupportedException("delete");
} public boolean renameTo(Folder folder)
throws MessagingException
{
throw new MethodNotSupportedException("renameTo");
} public synchronized void open(int i)
throws MessagingException
{
checkClosed();
if(!exists)
throw new FolderNotFoundException(this, "folder is not INBOX");
try
{
port = ((POP3Store)store).getPort(this);
mode = i;
opened = true;
total = port.stat().total;
}
catch(IOException ioexception)
{
throw new MessagingException("Open failed", ioexception);
}
message_cache = new Vector(total);
message_cache.setSize(total);
doneUidl = false;
notifyConnectionListeners(1);
} public synchronized void close(boolean flag)
throws MessagingException
{
checkOpen();
try
{
if(((POP3Store)store).rsetBeforeQuit)
port.rset();
if(flag && mode == 2)
{
for(int i = 0; i < message_cache.size(); i++)
{
POP3Message pop3message;
if((pop3message = (POP3Message)message_cache.elementAt(i)) != null && pop3message.isSet(javax.mail.Flags.Flag.DELETED))
try
{
port.dele(i + 1);
}
catch(IOException ex)
{
throw new MessagingException();
}
} }
port.quit();
}
catch(IOException ex) {}
finally
{
port = null;
((POP3Store)store).closePort(this);
message_cache = null;
opened = false;
notifyConnectionListeners(3);
}
} public boolean isOpen()
{
return opened;
} public Flags getPermanentFlags()
{
return new Flags();
} public int getMessageCount()
throws MessagingException
{
if(!opened)
{
return -1;
}
else
{
checkReadable();
return total;
}
} public synchronized Message getMessage(int i)
throws MessagingException
{
checkOpen();
POP3Message pop3message;
if((pop3message = (POP3Message)message_cache.elementAt(i - 1)) == null)
{
pop3message = createMessage(this, i);
message_cache.setElementAt(pop3message, i - 1);
}
return pop3message;
} protected POP3Message createMessage(Folder folder, int i)
throws MessagingException
{
POP3Message pop3message = null;
Constructor constructor = ((POP3Store)store).messageConstructor;
if(constructor != null)
try
{
Object aobj[] = {
this, new Integer(i)
};
pop3message = (POP3Message)constructor.newInstance(aobj);
}
catch(Exception ex) {}
if(pop3message == null)
pop3message = new POP3Message(this, i);
return pop3message;
} public void appendMessages(Message amessage[])
throws MessagingException
{
throw new MethodNotSupportedException("Append not supported");
} public Message[] expunge()
throws MessagingException
{
throw new MethodNotSupportedException("Expunge not supported");
} public synchronized void fetch(Message amessage[], FetchProfile fetchprofile)
throws MessagingException
{
checkReadable();
if(!doneUidl && fetchprofile.contains(javax.mail.UIDFolder.FetchProfileItem.UID))
{
String as[] = new String[message_cache.size()];
try
{
if(!port.uidl(as))
return;
}
catch(EOFException eofexception)
{
close(false);
throw new FolderClosedException(this, eofexception.toString());
}
catch(IOException ioexception)
{
throw new MessagingException("error getting UIDL", ioexception);
}
for(int j = 0; j < as.length; j++)
if(as[j] != null)
{
POP3Message pop3message1 = (POP3Message)getMessage(j + 1);
pop3message1.uid = as[j];
} doneUidl = true;
}
if(fetchprofile.contains(javax.mail.FetchProfile.Item.ENVELOPE))
{
for(int i = 0; i < amessage.length; i++)
{
POP3Message pop3message = (POP3Message)amessage[i];
pop3message.getHeader("");
pop3message.getSize();
} }
} public synchronized String getUID(Message message)
throws MessagingException
{
checkOpen();
POP3Message pop3message = (POP3Message)message;
try
{
if(pop3message.uid == "UNKNOWN")
pop3message.uid = port.uidl(pop3message.getMessageNumber());
return pop3message.uid;
}
catch(EOFException eofexception)
{
close(false);
throw new FolderClosedException(this, eofexception.toString());
}
catch(IOException ioexception)
{
throw new MessagingException("error getting UIDL", ioexception);
}
} protected void finalize()
throws Throwable
{
close(false);
} void checkOpen()
throws IllegalStateException
{
if(!opened)
throw new IllegalStateException("Folder is not Open");
else
return;
} void checkClosed()
throws IllegalStateException
{
if(opened)
throw new IllegalStateException("Folder is Open");
else
return;
} void checkReadable()
throws IllegalStateException
{
if(!opened || mode != 1 && mode != 2)
throw new IllegalStateException("Folder is not Readable");
else
return;
} void checkWritable()
throws IllegalStateException
{
if(!opened || mode != 2)
throw new IllegalStateException("Folder is not Writable");
else
return;
} Protocol getProtocol()
throws MessagingException
{
checkOpen();
return port;
} protected void notifyMessageChangedListeners(int i, Message message)
{
super.notifyMessageChangedListeners(i, message);
} private String name;
private Protocol port;
private int total;
private boolean exists;
private boolean opened;
private Vector message_cache;
private boolean doneUidl;
}
2>Session.java
public Store getStore(URLName urlname)
throws NoSuchProviderException
{
String s = urlname.getProtocol();
Provider provider = getProvider(s);
return getStore(provider, urlname);
}
public Provider getProvider(String s)
throws NoSuchProviderException
{
if(s == null || s.length() <= 0)
throw new NoSuchProviderException("Invalid protocol: null");
Provider provider = null;
String s1 = props.getProperty("mail." + s + ".class");
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
if(s1 != null)
{
if(debug)
System.out.println("DEBUG: mail." + s + ".class property exists and points to " + s1);
provider = (Provider)providersByClassName.get(s1);
}
if(provider != null)
return provider;
provider = (Provider)providersByProtocol.get(s);
if(provider == null)
throw new NoSuchProviderException("No provider for " + s);
if(debug)
System.out.println("\nDEBUG: getProvider() returning " + provider.toString());
return provider;
}