Remove knowledge of store URI from :mail:protocols:pop3 module
This commit is contained in:
parent
f046313d98
commit
9cb5c70e4b
7 changed files with 34 additions and 31 deletions
|
@ -10,8 +10,8 @@ import com.fsck.k9.mail.ServerSettings
|
|||
import com.fsck.k9.mail.oauth.OAuth2TokenProvider
|
||||
import com.fsck.k9.mail.ssl.DefaultTrustedSocketFactory
|
||||
import com.fsck.k9.mail.store.pop3.Pop3Store
|
||||
import com.fsck.k9.mail.store.pop3.Pop3StoreUriCreator
|
||||
import com.fsck.k9.mail.store.pop3.Pop3StoreUriDecoder
|
||||
import com.fsck.k9.backend.pop3.Pop3StoreUriCreator
|
||||
import com.fsck.k9.backend.pop3.Pop3StoreUriDecoder
|
||||
import com.fsck.k9.mail.transport.smtp.SmtpTransport
|
||||
import com.fsck.k9.mail.transport.smtp.SmtpTransportUriCreator
|
||||
import com.fsck.k9.mail.transport.smtp.SmtpTransportUriDecoder
|
||||
|
@ -29,7 +29,8 @@ class Pop3BackendFactory(private val context: Context, private val preferences:
|
|||
}
|
||||
|
||||
private fun createPop3Store(account: Account): Pop3Store {
|
||||
return Pop3Store(account, DefaultTrustedSocketFactory(context))
|
||||
val serverSettings = decodeStoreUri(account.storeUri)
|
||||
return Pop3Store(serverSettings, account, DefaultTrustedSocketFactory(context))
|
||||
}
|
||||
|
||||
private fun createSmtpTransport(account: Account): SmtpTransport {
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
package com.fsck.k9.mail.store.pop3;
|
||||
package com.fsck.k9.backend.pop3;
|
||||
|
||||
|
||||
import java.net.URI;
|
|
@ -1,4 +1,4 @@
|
|||
package com.fsck.k9.mail.store.pop3;
|
||||
package com.fsck.k9.backend.pop3;
|
||||
|
||||
|
||||
import java.net.URI;
|
|
@ -1,4 +1,4 @@
|
|||
package com.fsck.k9.mail.store.pop3;
|
||||
package com.fsck.k9.backend.pop3;
|
||||
|
||||
|
||||
import com.fsck.k9.mail.AuthType;
|
|
@ -1,4 +1,4 @@
|
|||
package com.fsck.k9.mail.store.pop3;
|
||||
package com.fsck.k9.backend.pop3;
|
||||
|
||||
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
|
@ -29,23 +29,16 @@ public class Pop3Store extends RemoteStore {
|
|||
|
||||
private Map<String, Pop3Folder> mFolders = new HashMap<String, Pop3Folder>();
|
||||
|
||||
public Pop3Store(StoreConfig storeConfig, TrustedSocketFactory socketFactory) throws MessagingException {
|
||||
public Pop3Store(ServerSettings serverSettings, StoreConfig storeConfig, TrustedSocketFactory socketFactory) {
|
||||
super(storeConfig, socketFactory);
|
||||
|
||||
ServerSettings settings;
|
||||
try {
|
||||
settings = Pop3StoreUriDecoder.decode(storeConfig.getStoreUri());
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new MessagingException("Error while decoding store URI", e);
|
||||
}
|
||||
|
||||
host = settings.host;
|
||||
port = settings.port;
|
||||
connectionSecurity = settings.connectionSecurity;
|
||||
username = settings.username;
|
||||
password = settings.password;
|
||||
clientCertificateAlias = settings.clientCertificateAlias;
|
||||
authType = settings.authenticationType;
|
||||
host = serverSettings.host;
|
||||
port = serverSettings.port;
|
||||
connectionSecurity = serverSettings.connectionSecurity;
|
||||
username = serverSettings.username;
|
||||
password = serverSettings.password;
|
||||
clientCertificateAlias = serverSettings.clientCertificateAlias;
|
||||
authType = serverSettings.authenticationType;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -8,9 +8,13 @@ import java.io.OutputStream;
|
|||
import java.net.Socket;
|
||||
import java.util.List;
|
||||
|
||||
import com.fsck.k9.mail.AuthType;
|
||||
import com.fsck.k9.mail.AuthenticationFailedException;
|
||||
import com.fsck.k9.mail.ConnectionSecurity;
|
||||
import com.fsck.k9.mail.Folder;
|
||||
import com.fsck.k9.mail.MessagingException;
|
||||
import com.fsck.k9.mail.ServerSettings;
|
||||
import com.fsck.k9.mail.ServerSettings.Type;
|
||||
import com.fsck.k9.mail.filter.Base64;
|
||||
import com.fsck.k9.mail.ssl.TrustedSocketFactory;
|
||||
import com.fsck.k9.mail.store.StoreConfig;
|
||||
|
@ -60,21 +64,14 @@ public class Pop3StoreTest {
|
|||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
//Using a SSL socket allows us to mock it
|
||||
when(mockStoreConfig.getStoreUri()).thenReturn("pop3+ssl+://PLAIN:user:password@server:12345");
|
||||
ServerSettings serverSettings = createServerSettings();
|
||||
when(mockStoreConfig.getInboxFolder()).thenReturn(Pop3Folder.INBOX);
|
||||
when(mockTrustedSocketFactory.createSocket(null, "server", 12345, null)).thenReturn(mockSocket);
|
||||
when(mockSocket.isConnected()).thenReturn(true);
|
||||
when(mockSocket.isClosed()).thenReturn(false);
|
||||
|
||||
when(mockSocket.getOutputStream()).thenReturn(mockOutputStream);
|
||||
store = new Pop3Store(mockStoreConfig, mockTrustedSocketFactory);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
public void withInvalidStoreUri_shouldThrowMessagingException() throws MessagingException {
|
||||
when(mockStoreConfig.getStoreUri()).thenReturn("pop3://CRAM_MD5:user:password@[]:12345");
|
||||
store = new Pop3Store(mockStoreConfig, mockTrustedSocketFactory);
|
||||
store = new Pop3Store(serverSettings, mockStoreConfig, mockTrustedSocketFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -176,4 +173,16 @@ public class Pop3StoreTest {
|
|||
|
||||
folder.open(Folder.OPEN_MODE_RW);
|
||||
}
|
||||
|
||||
private ServerSettings createServerSettings() {
|
||||
return new ServerSettings(
|
||||
Type.POP3,
|
||||
"server",
|
||||
12345,
|
||||
ConnectionSecurity.SSL_TLS_REQUIRED,
|
||||
AuthType.PLAIN,
|
||||
"user",
|
||||
"password",
|
||||
null);
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue