2008-11-01 17:32:06 -04:00
|
|
|
|
2009-12-14 21:50:53 -05:00
|
|
|
package com.fsck.k9.mail;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2010-03-03 23:00:30 -05:00
|
|
|
import com.fsck.k9.Account;
|
2009-12-14 21:50:53 -05:00
|
|
|
import com.fsck.k9.mail.transport.SmtpTransport;
|
|
|
|
import com.fsck.k9.mail.transport.WebDavTransport;
|
2008-11-01 17:32:06 -04:00
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public abstract class Transport {
|
2008-11-01 17:32:06 -04:00
|
|
|
protected static final int SOCKET_CONNECT_TIMEOUT = 10000;
|
|
|
|
|
2009-04-09 13:48:05 -04:00
|
|
|
// RFC 1047
|
|
|
|
protected static final int SOCKET_READ_TIMEOUT = 300000;
|
|
|
|
|
2011-02-06 17:09:48 -05:00
|
|
|
public synchronized static Transport getInstance(Account account) throws MessagingException {
|
2010-03-03 23:00:30 -05:00
|
|
|
String uri = account.getTransportUri();
|
2011-02-06 17:09:48 -05:00
|
|
|
if (uri.startsWith("smtp")) {
|
2008-11-01 17:32:06 -04:00
|
|
|
return new SmtpTransport(uri);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else if (uri.startsWith("webdav")) {
|
2010-03-03 23:00:30 -05:00
|
|
|
return new WebDavTransport(account);
|
2011-02-06 17:09:48 -05:00
|
|
|
} else {
|
2008-11-01 17:32:06 -04:00
|
|
|
throw new MessagingException("Unable to locate an applicable Transport for " + uri);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:39:41 -04:00
|
|
|
/**
|
|
|
|
* Decodes the contents of transport-specific URIs and puts them into a {@link ServerSettings}
|
|
|
|
* object.
|
|
|
|
*
|
|
|
|
* @param uri
|
|
|
|
* the transport-specific URI to decode
|
|
|
|
*
|
|
|
|
* @return A {@link ServerSettings} object holding the settings contained in the URI.
|
|
|
|
*
|
|
|
|
* @see SmtpTransport#decodeUri(String)
|
|
|
|
* @see WebDavTransport#decodeUri(String)
|
|
|
|
*/
|
|
|
|
public static ServerSettings decodeTransportUri(String uri) {
|
|
|
|
if (uri.startsWith("smtp")) {
|
|
|
|
return SmtpTransport.decodeUri(uri);
|
|
|
|
} else if (uri.startsWith("webdav")) {
|
|
|
|
return WebDavTransport.decodeUri(uri);
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Not a valid transport URI");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-08 23:50:43 -04:00
|
|
|
/**
|
|
|
|
* Creates a transport URI from the information supplied in the {@link ServerSettings} object.
|
|
|
|
*
|
|
|
|
* @param server
|
|
|
|
* The {@link ServerSettings} object that holds the server settings.
|
|
|
|
*
|
|
|
|
* @return A transport URI that holds the same information as the {@code server} parameter.
|
|
|
|
*
|
|
|
|
* @see SmtpTransport#createUri(ServerSettings)
|
|
|
|
* @see WebDavTransport#createUri(ServerSettings)
|
|
|
|
*/
|
|
|
|
public static String createTransportUri(ServerSettings server) {
|
|
|
|
if (SmtpTransport.TRANSPORT_TYPE.equals(server.type)) {
|
|
|
|
return SmtpTransport.createUri(server);
|
|
|
|
} else if (WebDavTransport.TRANSPORT_TYPE.equals(server.type)) {
|
|
|
|
return WebDavTransport.createUri(server);
|
|
|
|
} else {
|
|
|
|
throw new IllegalArgumentException("Not a valid transport URI");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-06-07 10:39:41 -04:00
|
|
|
|
2008-11-01 17:32:06 -04:00
|
|
|
public abstract void open() throws MessagingException;
|
|
|
|
|
|
|
|
public abstract void sendMessage(Message message) throws MessagingException;
|
|
|
|
|
2010-11-30 22:02:13 -05:00
|
|
|
public abstract void close();
|
2008-11-01 17:32:06 -04:00
|
|
|
}
|